Home › Forums › Ticket Products › Event Tickets Plus › Detect Ticket Type RSVP or WooCommerce
- This topic has 7 replies, 2 voices, and was last updated 9 years, 11 months ago by
Cliff.
-
AuthorPosts
-
May 6, 2016 at 11:42 am #1111630
John Osmond
ParticipantIs there a function to detect the ticket type? (RSVP or WooCommerce) I’m working on a template file and would like to echo either “Make your reservation now” or “Purchase tickets now”.
May 6, 2016 at 2:05 pm #1111697Cliff
MemberHi John.
Could you please be more specific about the context of your code (a PHP file or looking for a JS solution) and any existing code you already have?
Thank you.
May 7, 2016 at 7:03 am #1111828John Osmond
ParticipantSure Cliff, and thanks for the reply. I run a comedy club and sometimes we do fundraiser events. Some of those are for pay and some are free. When they are for pay I add a ticket and select the ‘WooCommerce’ radio button. When they are free I add a ticket using ‘RSVP’.
In the event template file (a php file, which I have located in my own theme and in the proper place) I echo out a link at the top that says ‘Purchase Tickets’. The link points to the bottom of the page where the ticket order form is.
Here is one such event: https://snappersgrill.com/event/hard2guard/
It would be nice if I could detect the type of event and if ‘RSVP’ then echo out a more appropriate link, maybe ‘Make your reservations now’, instead of ‘Purchase tickets’.
Here is an event like that: https://snappersgrill.com/event/first-responders-night/
The code I’m using now:
<?php if( tribe_events_has_tickets($event_id) ): ?> <p><a href="#purchase_tickets">Purchase Tickets</a></p> <?php endif; ?>I would like something like (and I’m making this function name up myself):
<?php if( tribe_events_has_tickets($event_id) ): ?> <?php if( tribe_events_ticket_type == 'rsvp' ): ?> <p><a href="#purchase_tickets">Make your reservation now.</a></p> <?php else: ?> <p><a href="#purchase_tickets">Purchase Tickets</a></p> <?php endif; ?> <?php endif; ?>May 8, 2016 at 2:08 am #1111991John Osmond
ParticipantI realize now that since it is possible for an event to have a mixed set of ticket types, my requested function would not make sense. It would be nice to test if an event “has” one type or another.
So my code might look like:
<?php if( tribe_events_event_has_ticket_type_rsvp($event_id) ): ?> <p><a href="#rsvp_tickets">Make your reservation now.</a></p> <?php endif; ?> <?php if( tribe_events_event_has_ticket_type_woocommerce($event_id) ): ?> <p><a href="#purchase_tickets">Purchase tickets here.</a></p> <?php endif; ?>May 9, 2016 at 3:06 pm #1112405Cliff
MemberThanks for your thoroughness.
https://snappersgrill.com/event/first-responders-night/ does not seem to have any tickets, and https://snappersgrill.com/event/hard2guard/ has “Purchase tickets” in the upper-left of the event (so you’re talking about a custom display and not modifying something Event Tickets already displays, right?), but I still think I understand your question…
I believe I understand what you’re asking for, but we’re limited in helping with customizations, per our Scope of Support / Terms. However, I can try to help point you in the right direction.
You might want to check out the get_event_tickets function and see if that helps you.
May 9, 2016 at 3:14 pm #1112411John Osmond
ParticipantHi Cliff. Sorry about the inconsistency. I had to remove the rsvp tickets from the first responders night because this is a live site and it was confusing people.
However, if I may boil my question down: Is there a php function I can call (passing in the $event_id) to determine whether or not an event has any tickets of the ‘RSVP’ type?
Thanks
May 9, 2016 at 3:47 pm #1112426John Osmond
ParticipantOk, thanks for pointing me in the direction of the get_event_tickets function. It was exactly what I needed. Here are two functions that you might share with other users.
function event_has_ticket_type_rsvp($event_id) { $breturn = FALSE; //init if ( class_exists( 'Tribe__Tickets__Tickets' ) ) { $tickets = Tribe__Tickets__Tickets::get_event_tickets($event_id); foreach( $tickets as $ticket ) { if( strpos(strtolower($ticket->provider_class), 'rsvp') !== FALSE ) $breturn = TRUE; } } return $breturn; }function jt10_event_has_ticket_type_woocommerce($event_id) { $breturn = FALSE; //init if ( class_exists( 'Tribe__Tickets__Tickets' ) ) { $tickets = Tribe__Tickets__Tickets::get_event_tickets($event_id); foreach( $tickets as $ticket ) { if( strpos(strtolower($ticket->provider_class), 'woocommerce') !== FALSE ) $breturn = TRUE; } } return $breturn; }Thanks for the help!
May 9, 2016 at 4:18 pm #1112436Cliff
MemberExcellent. Thank you for sharing your code too!
-
AuthorPosts
- The topic ‘Detect Ticket Type RSVP or WooCommerce’ is closed to new replies.
