Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Shortcode to print a list of ticket types and their number of tickets sold for one event. example usage: [ee_ticket_list_for_event id=40221]
<?php
//* Please do NOT include the opening php tag, except of course if you're starting with a blank file
add_shortcode( 'ee_ticket_list_for_event', 'ee_ticket_list_for_event_shortcode' );
function ee_ticket_list_for_event_shortcode( $atts ) {
$atts = shortcode_atts( array(
'id' => 0
), $atts, 'ee_ticket_list_for_event' );
if($atts['id'] == 0){
return;
}
$EVT_ID = $atts['id'];
$html = '<h3>' . get_the_title($EVT_ID) . '</h3>';
$html .= '<table>';
$event = EEH_Event_View::get_event($EVT_ID);
$tickets = array();
if ($event instanceof EE_Event) {
$tickets = $event->tickets();
}
foreach ( $tickets as $ticket ) {
if ( $ticket instanceof EE_Ticket ) {
$html .= '<tr><td>';
$html .= $ticket->name() . '</td><td> ' . $ticket->tickets_sold();
$html .= '</td></tr>';
}
}
$html .= '</table>';
return $html;
}
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.