如何调试WooCommerce订单流程/状态更改

时间:2020-03-19 08:54:18

标签: php woocommerce

我正在尝试在订单创建和/或订单状态完成时在WooCommerce的订单流程中构建功能。

我正在努力的是能够调试此新功能的过程。

一旦在数据库中创建了订单,我想从简单的步骤开始。我想使用var_dump或类似的命令将订单输出到屏幕上。

从那时起,如果我能够做到这一点,我将能够在整个过程中跟踪我的功能,但是目前我无法做到这一点。

使用woocommerce_checkout_order_processed钩子时,我可以看到ajax响应,但是顺序为空。参见下面的示例;

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' );
}

上面的钩子似乎是最合适的钩子。任何帮助,我们将不胜感激。

1 个答案:

答案 0 :(得分:0)

我将使用相同的钩子,但使用以下代码:

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" );

}