-
-
Save sc0ttkclark/e670113591b3cf1230dd2b2f6760865c to your computer and use it in GitHub Desktop.
Allow all IAC attendees to view protected content
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_filter( 'tribe_tickets_shortcode_can_see_content', static function( $can_see_content, $filter_args ) { | |
// Only run our logic below if the user is logged in or if they cannot currently see the content. | |
if ( ! is_user_logged_in() || $can_see_content ) { | |
return $can_see_content; | |
} | |
$current_user = wp_get_current_user(); | |
// Check to see if there are any attendees for the ticket ID(s) for this user email. | |
$args = [ | |
// Only get one to improve performance. | |
'per_page' => 1, | |
'by' => [ | |
'ticket' => $filter_args['ticket_ids'], | |
// purchaser_email is actually referencing the meta key which IAC uses too. | |
'purchaser_email' => $current_user->user_email, | |
], | |
]; | |
$attendees = Tribe__Tickets__Tickets::get_event_attendees_by_args( $filter_args['post_id'], $args ); | |
// Return whether they have matching attendee(s). | |
return ! empty( $attendees['attendees'] ); | |
}, 100, 2); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment