Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save chikaibeneme/5f9a5f2bec8fce48d53dea372e6fd029 to your computer and use it in GitHub Desktop.

Select an option

Save chikaibeneme/5f9a5f2bec8fce48d53dea372e6fd029 to your computer and use it in GitHub Desktop.
/*The Tribe Events Calendar plugin for WordPress provides several functions to retrieve information about events and their tickets. While there isn't a specific function to differentiate between paid/free tickets and RSVPs, you can use a combination of functions to achieve the desired result.
To determine if an event has tickets or is only based on RSVP, you can use the following approach:
Use the tribe_get_event_meta() function to retrieve the event's ticketing meta information. This function returns an array containing various details about the event, including ticketing information.
Check if the event has any tickets by accessing the 'tribe_tickets' key in the returned array. If it exists and is not empty, it indicates that the event has tickets.
If the event has tickets, you can further examine the ticket types to determine if they are paid or free. You can use the tribe_get_ticket_types() function to retrieve an array of ticket types for the event.
Iterate through the ticket types array and check the price of each ticket. If any ticket has a non-zero price, it indicates that the event has paid tickets. Otherwise, if all ticket prices are zero, it means the event has free tickets.
Here's an example code snippet that demonstrates this approach (this hasn't been tested):*/
// Assuming $event_id holds the ID of the event you want to check
// Step 1: Retrieve event's ticketing meta information
$event_meta = tribe_get_event_meta($event_id);
// Step 2: Check if the event has tickets
if (isset($event_meta['tribe_tickets']) && !empty($event_meta['tribe_tickets'])) {
// Step 3: Retrieve the ticket types
$ticket_types = tribe_get_ticket_types($event_id);
// Step 4: Check if any ticket has a non-zero price
$has_paid_tickets = false;
foreach ($ticket_types as $ticket_type) {
if ($ticket_type['price'] > 0) {
$has_paid_tickets = true;
break;
}
}
if ($has_paid_tickets) {
echo 'The event has paid tickets.';
} else {
echo 'The event has free tickets.';
}
} else {
echo 'The event is based on RSVP.';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment