Disabling Auto Restocking for Cancelled Orders
-
When we cancel an order, Woocommerce automatically restocking the products. But we do not want auto restocking so I’ve tried this hook:
function filter_woocommerce_can_reduce_order_stock( $true, $order ) { $stat = $order->get_status(); if($stat == 'cancelled'){ // We want only disable restocking when status is cancelled. $note = 'order stat is '.$stat.' so we do NOT updated the item stock.'; $order->add_order_note( $note ); // To be make sure what happened. return false; // Do not restock the product. }else{ $note = 'order stat is '.$stat.' so we UPDATED the item stock.'; $order->add_order_note( $note ); return true; // Restock the product. } } add_filter( 'woocommerce_can_reduce_order_stock','filter_woocommerce_can_reduce_order_stock', 10, 2 );
Also tried this hook too:
add_filter( 'woocommerce_can_restore_order_stock', 'ts_do_not_restock', 10, 2 ); function ts_do_not_restock( $true, $order ){ $stat = $order->get_status(); if($stat == 'cancelled'){ $note = 'order stat is '.$stat.' so we do not updated the item stock.'; $order->add_order_note( $note ); // To be make sure what happened. return false; }else{ return true; } }
But both not worked for me, any ideas to disabling auto restocking?
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Disabling Auto Restocking for Cancelled Orders’ is closed to new replies.