In my woocommerce 2.4.8 when changing order status in admin panel

if ( 'completed' == $order_status && ( 'on-hold' == $order->status || 'completed' == $order->status || 'failed' == $order->status ) ) { function my_func(); } 

a certain function should be performed, but I don’t understand where it is better to register it ... in woocommerce files or in functions.php. If in functions.php, then how will the logic be built ???

 add_action('woocommerce_order_status_completed', 'my_compl'); function my_compl_2() { .............. } 

It would be nice to make woocommerce in the files themselves so that it does not depend on the templates.

    1 answer 1

    Found a solution, but only on intercepting an event through the functions.php file. Once again about the task, when changing the Order Status, you need to output an event, in effect the execution of its function. functions.php into functions.php :

     // Если заказ Выполнен add_action('woocommerce_order_status_completed', 'my_compl_2'); function my_compl_2( $order_id ) { error_log( "Order complete for order $order_id", 0 ); } 

    Then everything is simple, we change the add_action construction to the one you need.

    • woocommerce_order_status_pending
    • woocommerce_order_status_failed
    • woocommerce_order_status_on-hold
    • woocommerce_order_status_processing
    • woocommerce_order_status_completed
    • woocommerce_order_status_refunded
    • woocommerce_order_status_cancelled

    Naturally, we change the name of our function or refer to it again.