Skip to content

Instantly share code, notes, and snippets.

@cliffordp
Last active October 4, 2018 15:06
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 cliffordp/7a819ccf8343cc19a07fd74b9f9aa762 to your computer and use it in GitHub Desktop.
Save cliffordp/7a819ccf8343cc19a07fd74b9f9aa762 to your computer and use it in GitHub Desktop.
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