Action uncanny-automator-pro

event_tickets_rsvp_tickets_generated

Fires when an RSVP attendee tickets have been generated. Fires after RSVP attendee tickets are generated for a specific post and order.

add_action( 'event_tickets_rsvp_tickets_generated', $callback, 10, 3 );

Description

Fires after RSVP attendee tickets are generated for a post, providing the order ID, post ID, and attendance status. Developers can use this hook to trigger custom logic or integrations when an RSVP attendee's ticket is confirmed, allowing for post-purchase actions or data synchronization.


Usage

add_action( 'event_tickets_rsvp_tickets_generated', 'your_function_name', 10, 3 );

Parameters

$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

Examples

// Example of how to hook into the 'event_tickets_rsvp_tickets_generated' action hook.
// This function will be triggered whenever RSVP tickets are generated for an event.
// We'll use this example to log the order and post IDs to the WordPress debug log.
add_action( 'event_tickets_rsvp_tickets_generated', 'my_custom_rsvp_ticket_handler', 10, 3 );

/**
 * Custom handler for the 'event_tickets_rsvp_tickets_generated' action.
 *
 * Logs information about the generated RSVP tickets to the WordPress debug log.
 *
 * @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.
 */
function my_custom_rsvp_ticket_handler( $order_id, $post_id, $attendee_order_status ) {

	// Only proceed if the user indicated they will attend.
	if ( 'yes' === $attendee_order_status ) {

		// Get the event title for more context.
		$event_title = get_the_title( $post_id );

		// Log the event details to the debug log.
		error_log( sprintf(
			'RSVP Tickets Generated: Order ID %1$d, Event "%2$s" (Post ID %3$d). User confirmed attendance.',
			$order_id,
			$event_title,
			$post_id
		) );

		// Example of how you might further process this:
		// For instance, you could trigger a custom notification,
		// update a user meta field, or integrate with another service.
		//
		// Example: Update a custom post meta field on the event
		// update_post_meta( $post_id, '_rsvp_attendees_count', (int) get_post_meta( $post_id, '_rsvp_attendees_count', true ) + 1 );

	} else {
		// Log that tickets were generated but the user did not confirm attendance.
		error_log( sprintf(
			'RSVP Tickets Generated: Order ID %1$d, Event "%2$s" (Post ID %3$d). User did NOT confirm attendance.',
			$order_id,
			get_the_title( $post_id ),
			$post_id
		) );
	}
}

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

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