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?
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?
Share Improve this question asked Apr 16, 2020 at 11:36 exspetexspet 11 bronze badge 01 Answer
Reset to default 0I've received my answer from Woocommerce support. It's working like a charm:
add_action( 'after_setup_theme', 'my_stop_cancelled_restock', 0 );
function my_stop_cancelled_restock() {
remove_action('woocommerce_order_status_cancelled', 'wc_maybe_increase_stock_levels');
}