Skip to content

Instantly share code, notes, and snippets.

@Pebblo

Pebblo/example.php Secret

Created Aug 10, 2018
Embed
What would you like to do?
Example of how to pull only the required tickets from an event, loop over them all and add their 'remaining' sale values together, then output that value.
<?php
// EE_Event Object, you should one already but to demo I'm pulling one directly
$event = EEM_Event::instance()->get_one_by_ID(1111);
// Pull the required tickets for the event.
$required_tickets = $event->tickets( array(
array('TKT_required' => true)
)
);
// Initialize $remaining_spaces as 0.
$remaining_spaces = 0;
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();
}
}
}
//Output the number of remaining spaces.
echo $remaining_spaces;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.