Skip to content

Instantly share code, notes, and snippets.

@Pebblo
Created November 8, 2019 15:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Pebblo/339e8b993769bedc5bec0f84af943098 to your computer and use it in GitHub Desktop.
Save Pebblo/339e8b993769bedc5bec0f84af943098 to your computer and use it in GitHub Desktop.
Example of how to pull the required tickets on an event, combine the remaining tickets values and return.
<?php // Please do not include the opneing PHP tag if you already have one.
function tw_ee_show_remaining_tickets($atts) {
$EVT_ID = get_the_ID();
$event = EEM_Event::instance()->get_one_by_ID($EVT_ID);
if( $event instanceof EE_Event ) {
$required_tickets = $event->tickets(
array(
array(
'TKT_required' => true
)
)
);
if($required_tickets) {
// Loop over all of the required tickets for the event.
foreach($required_tickets as $required_ticket) {
// Sanity check to make sure we have an EE_Ticket.
if($required_ticket instanceof EE_Ticket) {
// Add the spaces remaining for each required ticket to $spaces_remaining.
$remaining_spaces += $required_ticket->remaining();
}
}
}
return $remaining_spaces;
}
}
add_shortcode('SHOW_REMAINING_TICKETS','tw_ee_show_remaining_tickets');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment