Instantly share code, notes, and snippets.

Embed
What would you like to do?
The Events Calendar & Event Tickets Plus (ET+): Disable QR Code if ticket is for an event in a specific category.
<?php
/**
* The Events Calendar & Event Tickets Plus (ET+): Disable QR Code if ticket is for an event in a specific category.
*
* Requires ET+ 4.8.2 or later (when this filter was added).
* Useful for events where there is no physical check-in required, such as an online event or webinar.
*
* @link https://gist.github.com/cliffordp/7a819ccf8343cc19a07fd74b9f9aa762 This snippet.
*
* @param bool $enabled The bool that comes from the options.
* @param array $ticket The ticket.
*
* @return bool
*/
function cliff_disable_qr_if_tickets_event_has_category( $enabled, $ticket ) {
// Avoid fatals if The Events Calendar is not active or if Ticket is not attached to an Event.
if (
! class_exists( 'Tribe__Events__Main' )
|| empty( $ticket['event_id'] )
) {
return $enabled;
}
// !!! CHANGE THIS TO THE ONES YOU WANT !!!
$disabled_event_cat_slugs = [
'no-qr',
'online',
'webinars',
];
// Get the Event Categories from this Ticket's Event ID.
$event_cats = wp_get_post_terms(
$ticket['event_id'],
Tribe__Events__Main::TAXONOMY,
[
'fields' => 'id=>slug',
]
);
// If ANY of the Event's categories are in the disabled list, do NOT display the QR code.
foreach ( $event_cats as $id => $slug ) {
if ( in_array( $slug, $disabled_event_cat_slugs ) ) {
return false;
}
}
// Otherwise, don't change what it originally was.
return $enabled;
}
add_filter( 'tribe_tickets_plus_qr_enabled', 'cliff_disable_qr_if_tickets_event_has_category', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment