tribe_eb_get_ticket_count( int $post_id = null, bool $only_count_available_tickets = false )

Get ticket count for event


Parameters #

$post_id

(int) (Optional) the event ID (optional if used in the loop)

Default value: null

$only_count_available_tickets

(bool) (Optional)

Default value: false


Top ↑

Return #

(int) the number of tickets for an event


Top ↑

Source #

File: src/functions/template-tags.php

function tribe_eb_get_ticket_count( $post_id = null, $only_count_available_tickets = false ) {
	$api = tribe( 'eventbrite.event' );
	$post_id = Tribe__Events__Main::postIdHelper( $post_id );
	$event = $api->get_event( $post_id );
	$count = 0;

	// If we are interested in *all* tickets regardless of availability, we can take a shortcut
	if ( ! empty( $event->ticket_classes ) && ! $only_count_available_tickets ) {
		$count = count( $event->ticket_classes );
	} elseif ( ! empty( $event->ticket_classes ) ) {
		// Otherwise we need to iterate through the tickets and count those that are definitely availalbe
		foreach ( $event->ticket_classes as $ticket ) {
			if ( 'UNAVAILABLE' !== $ticket->on_sale_status ) {
				$count++;
			}
		}
	}

	/**
	 * Count of Eventbrite tickets for the specified event.
	 *
	 * @since 4.4.6 added $post_id and $only_count_availalbe_tickets parameters
	 *
	 * @param int  $count
	 * @param int  $post_id
	 * @param bool $only_count_available_tickets
	 */
	return apply_filters( 'tribe_eb_get_ticket_count', $count, $post_id, $only_count_available_tickets );
}

Top ↑

Changelog #

Changelog
Version Description
4.4.6 added $only_count_available_tickets parameter
1.0 Introduced.