woocommerce_order_status_completed not triggered

后端 未结 6 1522
甜味超标
甜味超标 2020-12-10 04:19

I want to write a custom plugin that does some action after woocommerce order is completed, but I can\'t get this hook to work. I can see this question asked many times.

6条回答
  •  醉酒成梦
    2020-12-10 04:57

    woocommerce_order_status_changed and woocommerce_order_status_completed actually work for me. After struggling for 2 days i realized that you just can't var_dump or var_export or print_r or whatever in the admin panel, it just won't work.

    So if you are a newbie like me and thought those actions weren't working, just try triggering another action like sending a mail for example.

    This code works:

    function your_function( $order_id ){
       $order = new WC_Order( $order_id );
        $to_email = 'testing_mail@sample.com';
        $payment = $order->get_payment_method_title();
        $headers = 'From: Your Name ' . "\r\n";
        wp_mail($to_email, 'subject', $payment, $headers );
    }
    
    add_action( 'woocommerce_order_status_completed', 'your_function');
    

提交回复
热议问题