Congratulations! 😍 As a blog reader, get a 10% OFF on WP Frontend Delete Account PRO. Use coupon code WPFDA10OFF.

Are you looking to do something after the order is processed? Then, the “woocommerce_new_order” hook is what you’re looking for.

Usage:

WooCommerce Customer Journey plugin uses this hook (woocommerce_new_order) to add the customer’s journey map to its database table “_cjforwoo”, which means once the new order is processed, the plugin stores the customer’s journey map from the Cookie to the database. Until the order is processed, the journey map is stored in the customer’s browser in the form of a cookie.

add_action( 'woocommerce_new_order', 'cjforwoo_process' );

/**
 * Process. Save journey to db after the order is processed.
 */
function cjforwoo_process() {

    // Get journey from Cookie.
    $journey = json_decode( wp_unslash( $_COOKIE['_cjforwoo'] ), true );

    // Save journey to database.
    ...
}

While it’s not used in the above example, note that the valuable $order_id parameter can be used in the callback function which provides you with all the order information you might need in the callback using the following:

$order = new WC_Order( $order_id );

In case it helps, here are details on all the order information you could get.

“woocommerce_new_order” – hook after the order is processed
Tagged on:     

Sanjeev Aryal

Don't bury your thoughts, put your vision into reality ~ Bob Marley.

Leave a Reply

Your email address will not be published. Required fields are marked *