Action uncanny-automator-pro

automator_pro_woocommerce_order_created

Fires when a new WooCommerce order is successfully created.

add_action( 'automator_pro_woocommerce_order_created', $callback, 10, 4 );

Description

Fired after a WooCommerce order is successfully created. Developers can use this hook to perform custom actions, such as sending notifications, updating meta data, or triggering other processes based on the newly created order and its associated user and arguments. Ensure you handle potential `$order` or `$user_id` null values.


Usage

add_action( 'automator_pro_woocommerce_order_created', 'your_function_name', 10, 4 );

Parameters

$order (mixed)
This parameter contains the WooCommerce order object that was just created.
$user_id (mixed)
This parameter contains the WooCommerce order object that was just created.
$args (mixed)
This parameter contains the ID of the user who placed the WooCommerce order.
$this (mixed)
This parameter contains an array of additional arguments passed during the order creation process.

Examples

add_action( 'automator_pro_woocommerce_order_created', function( $order, $user_id, $args, $this_object ) {
    // This is a realistic example of how to hook into the 'automator_pro_woocommerce_order_created' action.
    // In a real-world scenario, you might use this to log order details, send custom notifications,
    // or trigger other custom logic based on a WooCommerce order being created via Uncanny Automator Pro.

    // Ensure $order is a valid WC_Order object.
    if ( ! $order instanceof WC_Order ) {
        error_log( 'automator_pro_woocommerce_order_created: Invalid $order object received.' );
        return;
    }

    // Get order details.
    $order_id = $order->get_id();
    $order_total = $order->get_total();
    $customer_email = $order->get_billing_email();

    // Log the order creation event.
    error_log( sprintf(
        'Uncanny Automator Pro: New WooCommerce order created. Order ID: %d, Total: %s, Customer Email: %s, User ID: %d',
        $order_id,
        wc_price( $order_total ),
        $customer_email,
        absint( $user_id ) // Ensure user_id is treated as an integer.
    ) );

    // Example: Send a custom email notification if the order total is over a certain amount.
    if ( $order_total > 100 ) {
        $subject = sprintf( 'High Value Order Received: Order #%d', $order_id );
        $message = sprintf(
            'A high value order (over $100) has been placed: Order ID %d. Customer: %s. Total: %s.',
            $order_id,
            $customer_email,
            wc_price( $order_total )
        );
        $headers = array( 'Content-Type: text/html; charset=UTF-8' );

        // In a real plugin, you would likely use wp_mail() or a more sophisticated email sending library.
        // For this example, we'll just log it.
        error_log( sprintf(
            'Sending custom email for high value order. Subject: %s, Message: %s',
            $subject,
            $message
        ) );
        // wp_mail( '[email protected]', $subject, $message, $headers );
    }

    // The $args parameter might contain additional data from Uncanny Automator Pro,
    // such as the specific trigger or recipe data. You would inspect $args here
    // if you needed to perform logic based on specific Automator configurations.
    if ( ! empty( $args ) && is_array( $args ) ) {
        error_log( 'Additional arguments received: ' . print_r( $args, true ) );
    }

    // The $this_object parameter refers to the instance of the Uncanny Automator Pro helper class
    // that fired the action. You could potentially access other methods or properties of that object
    // if needed, but it's generally less common for external hooks unless you're deeply
    // integrating with the plugin's internal workings.
    // Example: error_log( 'Automator Pro object available: ' . get_class( $this_object ) );

}, 10, 4 ); // 10 is the priority, 4 is the number of accepted arguments.

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/woocommerce/helpers/woocommerce-pro-helpers.php:1445

'action_data'    => $action_data,
				'recipe_id'      => $recipe_id,
				'args'           => $args,
				'payment_method' => $payment_method,
				'order_type'     => $order_type,
			);

			do_action( 'automator_pro_woocommerce_order_created', $order, $user_id, $args, $this );

			return $order;

		} else {

			return false;

Scroll to Top