Last active
October 28, 2019 23:19
-
-
Save joshfeck/73e10a9b14bde1805c28896e31b3c6d3 to your computer and use it in GitHub Desktop.
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]
This file contains hidden or 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, 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