Action uncanny-automator-pro

automator_amelia_event_booking_status_updated

Fires after an Amelia booking status is updated for an event, providing access to booking and event data.

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

Description

Fires after an Amelia event booking's status is updated. Developers can use this hook to trigger custom automations or actions based on the booking and its associated event data. This hook is specifically designed for Amelia event bookings.


Usage

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

Parameters

$booking (mixed)
This parameter contains information about the specific Amelia booking that has been updated.
$booking_data (mixed)
This parameter contains the booking object, which holds all the details about the Amelia booking.
$event_data (mixed)
This parameter contains the booking data associated with the Amelia event.

Examples

<?php
/**
 * Example callback function for the automator_amelia_event_booking_status_updated hook.
 * This function will be executed when Amelia event booking status is updated.
 *
 * @param array $booking The booking data.
 * @param array $booking_data The parsed booking data.
 * @param array $event_data The event data associated with the booking.
 */
function my_automator_amelia_event_booking_status_updated_callback( $booking, $booking_data, $event_data ) {
    // Check if the event data is available and is an array
    if ( ! is_array( $event_data ) || empty( $event_data ) ) {
        error_log( 'automator_amelia_event_booking_status_updated: Event data is missing or invalid.' );
        return;
    }

    // Log the booking status update for debugging purposes
    $booking_id = $booking['id'] ?? 'N/A';
    $event_title = $event_data['name'] ?? 'Unknown Event';
    $booking_status = $booking_data['status'] ?? 'Unknown Status';

    $log_message = sprintf(
        'Amelia Event Booking Status Updated: Booking ID %s for Event "%s" has status "%s".',
        $booking_id,
        $event_title,
        $booking_status
    );

    error_log( $log_message );

    // Example: If the booking status is 'approved', you might want to send a custom email.
    if ( isset( $booking_data['status'] ) && 'approved' === $booking_data['status'] ) {
        $user_email = $booking_data['email'] ?? null;
        $user_name = $booking_data['names'] ?? 'Valued Customer';

        if ( $user_email ) {
            $subject = 'Your Event Booking is Confirmed!';
            $message_body = sprintf(
                'Hello %s, nnYour booking for the event "%s" has been confirmed. We look forward to seeing you!',
                $user_name,
                $event_title
            );

            // In a real-world scenario, you would use wp_mail() or a more robust email sending service.
            // For this example, we'll just log the attempt.
            error_log( sprintf(
                'Attempting to send confirmation email to %s for booking ID %s.',
                $user_email,
                $booking_id
            ) );

            // Example of sending the email (uncomment and modify wp_mail() as needed):
            /*
            wp_mail( $user_email, $subject, $message_body );
            */
        }
    }

    // Example: If the booking status is 'cancelled', you might want to log it differently.
    if ( isset( $booking_data['status'] ) && 'cancelled' === $booking_data['status'] ) {
        error_log( sprintf(
            'Amelia Event Booking Cancelled: Booking ID %s for Event "%s".',
            $booking_id,
            $event_title
        ) );
    }
}

// Add the action hook with a priority of 10 and specifying that the callback accepts 3 arguments.
add_action( 'automator_amelia_event_booking_status_updated', 'my_automator_amelia_event_booking_status_updated_callback', 10, 3 );
?>

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/ameliabooking/helpers/ameliabooking-pro-helpers.php:109

public function amelia_event_booking_updated( $booking, $booking_data ) {

		// Get event data using booking ID
		$event_data = $this->get_event_by_booking_id( $booking['id'] );

		if ( ! $event_data ) {
			return;
		}

		// Fire our custom hook with event data included
		do_action( 'automator_amelia_event_booking_status_updated', $booking, $booking_data, $event_data );
	}


Internal Usage

Found in uncanny-automator-pro/src/integrations/ameliabooking/triggers/amelia-user-event-booking-status-updated.php:23:

$this->add_action( 'automator_amelia_event_booking_status_updated', 10, 3 );
Scroll to Top