Filter uncanny-automator-pro

tribe_tickets_rsvp_send_mail

Filters whether a confirmation email should be sent or not for RSVP tickets. This applies to attendance and non attendance emails. Filters whether attendance or non-attendance RSVP confirmation emails should be sent for Event Tickets.

add_filter( 'tribe_tickets_rsvp_send_mail', $callback, 10, 1 );

Description

This filter allows developers to conditionally prevent RSVP confirmation emails for Tribe Tickets. Hook into `tribe_tickets_rsvp_send_mail` before attendee emails are sent to disable them based on custom logic, overriding the default `true` value.


Usage

add_filter( 'tribe_tickets_rsvp_send_mail', 'your_function_name', 10, 1 );

Parameters

$send_mail (bool)
Defaults to `true`.

Return Value

The filtered value.


Examples

<?php
/**
 * Example: Prevent sending RSVP confirmation emails for specific events.
 *
 * This callback function demonstrates how to conditionally prevent RSVP
 * confirmation emails from being sent based on the event's post ID.
 *
 * @param bool $send_mail The current value of the send_mail flag.
 * @return bool The modified value of the send_mail flag.
 */
add_filter( 'tribe_tickets_rsvp_send_mail', function( $send_mail ) {
	// Assuming we have a global or accessible variable for the current event's ID.
	// In a real-world scenario, you'd get this contextually, perhaps from $_POST,
	// a global variable set by The Events Calendar, or by passing it as an argument
	// if the hook supported it (which this one doesn't directly, so context is key).
	// For this example, let's pretend we have a specific event ID to exclude.
	$event_id_to_exclude = 123; // Replace with a real event ID for testing.

	// Get the current event's ID. This is a crucial part and depends heavily on context.
	// If this filter is fired during a ticket purchase process, the event ID might be
	// available in $_POST or a global variable. For demonstration, we'll use a placeholder.
	// A more robust solution might involve checking if the current request is for a specific event page.
	$current_event_id = isset( $_POST['event_id'] ) ? intval( $_POST['event_id'] ) : 0;

	// If the current event ID matches the one we want to exclude, prevent sending the email.
	if ( $current_event_id === $event_id_to_exclude ) {
		$send_mail = false;
	}

	return $send_mail;
}, 10, 1 );
?>

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:160

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 );
	}


Scroll to Top