I want to use woocommerce hook woocommerce_order_status_changed. I want to fire something when new status of order is trash.
I used this function, which is working good for rest order statuses, except trash.
This is my code:
function custom_order_actions ( $order_id, $old_status, $new_status ){
$order = new WC_Order($order_id);
if ($new_status == 'trash') {
// Do something
}
}
add_action( 'woocommerce_order_status_changed', 'custom_order_actions', 99, 3 );
CodePudding user response:
woocommerce_order_status_changed
can not pick up the trash
status since it's not one of the registered statuses on woocommerce according to their github page.
However, you could use wp_trash_post
action hook instead!
add_action('wp_trash_post', 'custom_order_actions');
function custom_order_actions($order_id)
{
if ('shop_order' == get_post_type($order_id)) {
$order = new WC_Order($order_id);
// Do something
}
}
Let me know if it works for you!