0

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?

0

1 Answer 1

0

I'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');    
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.