Last active
April 18, 2019 21:42
Example of how to remove a ticket from the ticket selector is the current use already has a registration on that ticket linked to their contact.
This file contains 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( 'FHEE__ticket_selector_chart_template__do_ticket_entire_row', 'tw_remove_ticket_with_previous_registration', 10, 2 ); | |
function tw_remove_ticket_with_previous_registration( $ticket_row_html, EE_Ticket $ticket ) { | |
// pull the ticket capability set on the ticket. | |
//$cap_required = $ticket->get_extra_meta('ee_ticket_cap_required', true); | |
//if (empty($cap_required)) { | |
// no cap required so user has access by default | |
//return $ticket_row_html; | |
//} | |
// Check the user is logged in | |
if ( is_user_logged_in() ) { | |
$user = wp_get_current_user(); | |
if ( ! $user instanceof WP_User ) { | |
return $ticket_row_html; | |
} | |
// is there an attached EE_Attendee? | |
$att_id = get_user_option( 'EE_Attendee_ID', $user->ID ); | |
if ( empty( $att_id ) ) { | |
return $ticket_row_html; //bail, no attached attendee_id. | |
} | |
// grab contact | |
$contact = EEM_Attendee::instance()->get_one_by_ID( $att_id ); | |
// if no contact then bail | |
if ( ! $contact instanceof EE_Attendee ) { | |
return $ticket_row_html; | |
} | |
// does the user have a registration for this ticket? | |
$registration = $contact->get_first_related( | |
'Registration', | |
array( | |
array( | |
//'EVT_ID' => $post->ID, | |
'REG_deleted' => false, | |
'TKT_ID' => $ticket->ID() | |
), | |
'order_by' => array('REG_date' => 'DESC') | |
) | |
); | |
// if they already have a registration on this ticket, remove the ticket from the ticket selector. | |
if( $registration instanceof EE_Registration ) { | |
return ''; | |
} | |
} | |
return $ticket_row_html; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment