Last active
October 14, 2021 21:45
-
-
Save Pebblo/42a6755ac618e2f3b88c6b945c08ff53 to your computer and use it in GitHub Desktop.
Here is an example of how to add the 'next' 3 events in the same category as the event linked to the current ticket into the cart. This will only work as expected with the Multi Event Registration add-on de-activated.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php // Please do not include the opening PHP tag if you already have one | |
add_action('AHEE__EE_Ticket_Selector__process_ticket_selections__after_tickets_added_to_cart', 'tw_ee_add_additional_regs_to_cart', 10, 2); | |
function tw_ee_add_additional_regs_to_cart( $cart, $ProcessTicketSelector) { | |
// Check we have an instance of EE_Cart. | |
if( ! $cart instanceof EE_Cart ) { | |
return; | |
} | |
// First, pull the 'first' ticket line item from the cart. | |
$ticket_line_item = reset($cart->get_tickets()); | |
// Confirm we have an EE_Line_Item object before moving forward. | |
if($ticket_line_item instanceof EE_Line_Item) { | |
// Now pull the event linked to that ticket. | |
$event = $ticket_line_item->ticket_event(); | |
// Confirm we have a EE_Event from above. | |
if($event instanceof EE_Event) { | |
// Get the first category assigned to the event. | |
$category = $event->first_event_category(); | |
// Get the first datetime from the event. | |
$datetime = $event->first_datetime(); | |
// Confirm we have both an EE_Term (category) and EE_Datetime from above. | |
if( | |
$category instanceof EE_Term | |
&& $datetime instanceof EE_Datetime | |
) { | |
// Now pull another 3 events in the same category where the Datetime start date is greater than the current events datetime. | |
$additional_events = EEM_Event::instance()->get_all( | |
array( | |
array( | |
'Term_Taxonomy.term_id' => $category->ID(), | |
'Datetime.DTT_EVT_start' => array('>', $datetime->start() ) | |
), | |
'order_by' => array('Datetime.DTT_EVT_start' => 'ASC'), | |
'limit' => 3 | |
) | |
); | |
// Loop over each event and pull the active tickets from that event. | |
foreach($additional_events as $additional_event) { | |
$tickets = $additional_event->tickets( | |
array( | |
array( | |
'TKT_end_date' => array('>=', EEM_Ticket::instance()->current_time_for_query('TKT_end_date')), | |
'TKT_deleted' => false, | |
), | |
'limit' => 1 | |
) | |
); | |
// Use the 'first' we foudn for the event. | |
$ticket = reset($tickets); | |
// Check we have a valid EE_Ticket before using it. | |
if( $ticket instanceof EE_Ticket ) { | |
// Add the ticket to the current cart. | |
$cart->add_ticket_to_cart($ticket); | |
} | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment