Skip to content

Instantly share code, notes, and snippets.

@Pebblo
Last active February 26, 2018 13:42
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/f07d5515180b363864160d90ca41ec0f to your computer and use it in GitHub Desktop.
Save Pebblo/f07d5515180b363864160d90ca41ec0f to your computer and use it in GitHub Desktop.
<?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