Last active
February 26, 2018 13:42
-
-
Save Pebblo/f07d5515180b363864160d90ca41ec0f to your computer and use it in GitHub Desktop.
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 | |
function ee_print_number_of_tickets_shortcode( $attributes ) { | |
$event = null; | |
if( !empty( $attributes['event_id'] ) ) { | |
$event = EEM_Event::instance()->get_one_by_ID($attributes['event_id']); | |
} | |
if( !$event instanceof EE_Event ){ | |
$event = EEH_Event_View::get_event(); | |
} | |
if ( $event instanceof EE_Event ) { | |
if ( ! $event->is_sold_out() && $event->is_upcoming() ) { | |
//get total approved registrations count | |
$spots_taken = EEM_Registration::instance()->count(array( | |
array( | |
'EVT_ID' => $event->ID(), | |
'STS_ID' => EEM_Registration::status_id_approved, | |
), | |
), 'REG_ID', true); | |
$html = '<div class="total-tickets">'; | |
$html .= $spots_taken; | |
$html .= ' sold of '; | |
$html .= $event->total_available_spaces(); | |
$html .= ' total available</div>'; | |
return $html; | |
} | |
} | |
} | |
add_shortcode( 'EE_NUMBER_OF_TICKETS', 'ee_print_number_of_tickets_shortcode' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment