Wrong $product_id available in

Home Forums Ticket Products Event Tickets Plus Wrong $product_id available in

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #1177676
    robert
    Participant

    Hi folks,

    So I’m trying to add a validation which will generate an error message if necessary.

    I’m trying to add an extra validation to the ‘woocommerce_add_to_cart_validation’ filter it passes the wrong $product_id for events that have more than one ticket shown.

    I.e. say I select the ticket “second item” or “test attendance”, it will allows give the $product_id of the TOP ticket “yellow team” when it comes to executing the ‘woocommerce_add_to_cart_validation’ filter. See attached picture for how it looks.

    You can replicate the error with the following instructions:

    Create an event with two or more Wootickets.

    Then use the following code:

    add_filter( 'woocommerce_add_to_cart_validation', 'woocommerce_add_to_cart_validation_CB', 30, 3);
    function woocommerce_add_to_cart_validation_CB( $bool, $product_id, $quantity  )
    {
    	var_dump($product_id); exit();
         return $bool;
    }

    And click add to cart for

    Turned off all plugins except your event and ticket plugin, tested using standard WordPress theme and still this happens.

    Please advise.

    Many thanks,
    Jack

    #1178360
    Brook
    Participant

    Howdy Jack,

    Thanks for the clear explanation and testing you’ve done so far!

    I think I know the issue you’re hitting here. That filter will get called once for each ticket available for the event. The $quantity variable will be 0 for any ticket that was not purchased.

    Since your code exits, it does so the first time this filter gets called, which will always be the “top” ticket. If you remove the exit you will see the filter fire multiple times. If you only wish to validate tickets which were purchased, check that the quantity is greater than zero.

    Does that all make sense? Will that work for you? Please let me know.

    Cheers!

    – Brook

    #1189655
    Support Droid
    Keymaster

    Hey there! This thread has been pretty quiet for the last three weeks, so we’re going to go ahead and close it to avoid confusion with other topics. If you’re still looking for help with this, please do open a new thread, reference this one and we’d be more than happy to continue the conversation over there.

    Thanks so much!
    The Events Calendar Support Team

Viewing 3 posts - 1 through 3 (of 3 total)
  • The topic ‘Wrong $product_id available in’ is closed to new replies.