Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@Pebblo
Created July 31, 2017 16:23
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 Pebblo/c48f75894b232f405727cf5ebfa4f119 to your computer and use it in GitHub Desktop.
Save Pebblo/c48f75894b232f405727cf5ebfa4f119 to your computer and use it in GitHub Desktop.
This is an example of how to add a Ninja forms form to an event that has any of the ticket types within it sold out.
<?php //Please do not include the opening PHP tag if you already have one
//* Please do NOT include the opening php tag, except of course if you're starting with a blank file
// Display a contact form when the event is sold out
// to be used as a waiting list
function ee_espresso_any_sold_out_tickets( $event ) {
$tickets = $event instanceof EE_Event ? $event->tickets() : null;
if($tickets) {
foreach($tickets as $ticket) {
if($ticket->ticket_status() == EE_Ticket::sold_out){
return true;
}
}
}
return false;
}
function ee_special_sold_out_message( $EVT_ID, $event ) {
//Set the ID of the Ninja Form you wish to call here.
$ninja_forms_id = 1;
//Check if the event is sold out.
if ( ee_espresso_any_sold_out_tickets( $event ) ) {
if( method_exists( 'Ninja_Forms', 'display') ) {
//Using Ninja Forms v3+
Ninja_Forms()->display( $ninja_forms_id );
} elseif( function_exists( 'ninja_forms_display_form' ) ) {
//Using a previous version of Ninja Forms
ninja_forms_display_form( $ninja_forms_id );
}
}
}
add_action( 'AHEE__ticket_selector_chart__template__after_ticket_selector', 'ee_special_sold_out_message', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment