简体   繁体   中英

How to debug WooCommerce order process/status change

I'm attempting to build functionality into the order process of WooCommerce upon order creation and/or the orders status being complete.

What I'm struggling with is being able to debug the process of this new functionality.

I'd like to start off with the simple step of, once the order has been created in the database. I'd like to output the order to the screen with var_dump or similar.

From that point if I can do that, I'll be able to track my functionality through out it's process, but currently I've not been able to do this.

When using the woocommerce_checkout_order_processed hook I can see the ajax response but the order is empty. See example below;

add_action( 'woocommerce_checkout_order_processed', 'my_function', 1, 10 );
function my_function($order_id) {
    $order = new WC_Order( $order_id );

    die(var_dump($order) );

    wc_add_notice( 'stop', 'error' );
}

This above hook seems like the most appropriate to fire my hook upon. Any assistance here would be greatly appreciated.

i would use the same hook but with below code:

function my_function($order) {

    $order_data = $order->get_data(); 
    //if you need any information in the order you can 
    //collect it from this ex. $order_data['billing']['city'].

    $order->add_order_note( "Text you want to att in the note of the order" );

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM