eo_get_remaining_tickets_count
Pro
eo_get_remaining_tickets_count( $event_id, $occurrence_id = null )
Get the number of tickets available for an event.
If you are selling tickets for entire event series (i.e. not by date) then you should not specify an occurrence ID.
If you are selling tickets by date then you should specify the occurrence for which you want
the number of remaining tickets.
If there are tickets which are not yet on sale, these are not counted.
Example
The following example - for booking by series - displays the number of tickets remaining.
$remaining = eo_get_remaining_tickets_count( get_the_ID() );
if( $remaining > 1 ){
printf( 'Hurry, only %d tickets remaining', $remaining );
}elseif( $remaining == 1 ){
echo 'Only one ticket remaining!';
}else{
echo 'Sorry, there are not tickets available';
}
The following example - for booking by dates - displays a list of dates which fewer than 5 tickets
$future_occurrences = eo_get_the_future_occurrences_of( get_the_ID() );
if( $future_occurrences ){
echo '<ul>';
foreach( $future_occurrences as $occurrence_id => $dates ){
$remaining = eo_get_remaining_tickets_count( get_the_ID(), $occurrence_id );
if( $remaining < 5 ){
printf( '<li> %s (Tickets remaining: %d)</li>', eo_format_datetime( $dates['start'], 'jS F' ), $remaining );
}
}
echo '</ul>';
}
Parameters
int
|
$event_id |
Event ID
|
int
|
$occurrence_id = null |
Occurrence ID. Use only when selling tickets by date
|
Return value
int
|
The number of tickets currently available
|