Reduce stock only for specific order statuses and payment method in Woocommerce Reduce stock only for specific order statuses and payment method in Woocommerce wordpress wordpress

Reduce stock only for specific order statuses and payment method in Woocommerce


Using a custom function hooked in woocommerce_order_status_changed you will be able to target 'processing' and 'completed' order statuses change reducing order items stock.

I have added in your function a condition to target only "BACS" payment gateway on orders.

add_filter( 'woocommerce_can_reduce_order_stock', 'wcs_do_not_reduce_onhold_stock', 10, 2 );function wcs_do_not_reduce_onhold_stock( $reduce_stock, $order ) {    if ( $order->has_status( 'on-hold' ) && $order->get_payment_method() == 'bacs' ) {        $reduce_stock = false;    }    return $reduce_stock;}add_action( 'woocommerce_order_status_changed', 'order_stock_reduction_based_on_status', 20, 4 );function order_stock_reduction_based_on_status( $order_id, $old_status, $new_status, $order ){    // Only for 'processing' and 'completed' order statuses change    if ( $new_status == 'processing' || $new_status == 'completed' ){    $stock_reduced = get_post_meta( $order_id, '_order_stock_reduced', true );        if( empty($stock_reduced) && $order->get_payment_method() == 'bacs' ){            wc_reduce_stock_levels($order_id);        }    }}

Code goes in function.php file of the active child theme (or active theme).

Tested and works