tribe_tickets_rsvp_send_mail_stati
Filters the attendee order stati that should trigger an attendance confirmation. Any attendee order status not listed here will trigger a non attendance email. Filters the attendee order statuses that trigger attendance confirmation emails.
add_filter( 'tribe_tickets_rsvp_send_mail_stati', $callback, 10, 4 );
Description
Filter the array of attendee order statuses that trigger an attendance confirmation email for Tribe Event Tickets RSVPs. By default, only 'yes' triggers an attendance email. Modify this array to include other statuses that should send attendance confirmations.
Usage
add_filter( 'tribe_tickets_rsvp_send_mail_stati', 'your_function_name', 10, 4 );
Parameters
-
$send_mail_stati(array) - An array of default stati triggering an attendance email.
-
$order_id(int) - ID of the RSVP order
-
$post_id(int) - ID of the post the order was placed for
-
$attendee_order_status(string) - 'yes' if the user indicated they will attend
Return Value
The filtered value.
Examples
/**
* Modify the default attendee statuses that trigger an attendance email.
*
* In this example, we'll add a custom status 'confirmed' to the list
* of statuses that trigger an attendance email, in addition to the default 'yes'.
* This might be useful if your system has an intermediate step where an order
* is marked as 'confirmed' before the final 'yes' status.
*
* @param array $send_mail_stati An array of default stati triggering an attendance email.
* @param int $order_id ID of the RSVP order.
* @param int $post_id ID of the post the order was placed for.
* @param string $attendee_order_status 'yes' if the user indicated they will attend.
* @return array Modified array of statuses triggering attendance emails.
*/
add_filter( 'tribe_tickets_rsvp_send_mail_stati', function( $send_mail_stati, $order_id, $post_id, $attendee_order_status ) {
// If the attendee order status is already 'yes', we don't need to do anything.
if ( $attendee_order_status === 'yes' ) {
return $send_mail_stati;
}
// Add a custom status 'confirmed' to the list of statuses that trigger an attendance email.
// You would typically check if this status exists for the given order and post.
// For demonstration, we're simply adding it if the current status is not 'yes'.
// In a real-world scenario, you might fetch the actual order status from the database.
if ( ! in_array( 'confirmed', $send_mail_stati, true ) ) {
$send_mail_stati[] = 'confirmed';
}
return $send_mail_stati;
}, 10, 4 );
Placement
This code should be placed in the functions.php file of your active theme, a custom plugin, or using a code snippets plugin.
Source Code
uncanny-automator-pro/src/integrations/event-tickets/actions/ec-rsvp-attendee-event.php:173
protected function process_action( $user_id, $action_data, $recipe_id, $args, $parsed ) {
$event_id = isset( $parsed[ $this->get_action_meta() ] ) ? absint( wp_strip_all_tags( $parsed[ $this->get_action_meta() ] ) ) : 0;
$ticket_id = isset( $parsed['RSVPEVENTTICKET'] ) ? absint( wp_strip_all_tags( $parsed['RSVPEVENTTICKET'] ) ) : 0;
$attendee_name = isset( $parsed['RSVPATTENDEENAME'] ) ? sanitize_text_field( $parsed['RSVPATTENDEENAME'] ) : '';
$attendee_email = isset( $parsed['RSVPATTENDEEEMAIL'] ) ? sanitize_email( $parsed['RSVPATTENDEEEMAIL'] ) : '';
$attendee_qty = isset( $parsed['RSVPATTENDEEQTY'] ) ? absint( wp_strip_all_tags( $parsed['RSVPATTENDEEQTY'] ) ) : 1;
/** @var Tribe__Tickets__RSVP $rsvp */
$rsvp = tribe( 'tickets.rsvp' );
$post_id = $event_id;
$order_id = Tribe__Tickets__RSVP::generate_order_id();
$product_id = $ticket_id;
$attendee_details = array(
'full_name' => $attendee_name,
'email' => $attendee_email,
'order_status' => 'yes',
'optout' => false,
'order_id' => $order_id,
);
$has_tickets = $rsvp->generate_tickets_for( $product_id, $attendee_qty, $attendee_details, false );
if ( is_wp_error( $has_tickets ) ) {
$action_data['do-nothing'] = true;
$action_data['complete_with_errors'] = true;
$message = $has_tickets->get_error_message();
Automator()->complete->action( $user_id, $action_data, $recipe_id, $message );
return;
}
/**
* Fires when an RSVP attendee tickets have been generated.
*
* @param int $order_id ID of the RSVP order
* @param int $post_id ID of the post the order was placed for
* @param string $attendee_order_status 'yes' if the user indicated they will attend
*/
do_action( 'event_tickets_rsvp_tickets_generated', $order_id, $post_id, 'yes' );
$send_mail_stati = array( 'yes' );
/**
* Filters whether a confirmation email should be sent or not for RSVP tickets.
*
* This applies to attendance and non attendance emails.
*
* @param bool $send_mail Defaults to `true`.
*/
$send_mail = apply_filters( 'tribe_tickets_rsvp_send_mail', true );
if ( $send_mail && $has_tickets ) {
/**
* Filters the attendee order stati that should trigger an attendance confirmation.
*
* Any attendee order status not listed here will trigger a non attendance email.
*
* @param array $send_mail_stati An array of default stati triggering an attendance email.
* @param int $order_id ID of the RSVP order
* @param int $post_id ID of the post the order was placed for
* @param string $attendee_order_status 'yes' if the user indicated they will attend
*/
$send_mail_stati = apply_filters(
'tribe_tickets_rsvp_send_mail_stati',
$send_mail_stati,
$order_id,
$post_id,
'yes'
);
// No point sending tickets if their current intention is not to attend
if ( in_array( 'yes', $send_mail_stati, true ) ) {
$rsvp->send_tickets_email( $order_id, $post_id );
} else {
$rsvp->send_non_attendance_confirmation( $order_id, $post_id );
}
}
Automator()->complete->action( $user_id, $action_data, $recipe_id );
}