Home › Forums › Ticket Products › Event Tickets Plus › Wrong $product_id available in
- This topic has 3 replies, 4 voices, and was last updated 9 years, 5 months ago by
robert.
-
AuthorPosts
-
October 17, 2016 at 7:54 am #1177676
robert
ParticipantHi 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,
JackOctober 18, 2016 at 8:56 am #1178360Brook
ParticipantHowdy 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
November 9, 2016 at 8:35 am #1189655Support Droid
KeymasterHey 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 -
AuthorPosts
- The topic ‘Wrong $product_id available in’ is closed to new replies.
