I am having trouble with my COD payment method, when a customer orders... The order becomes processing and it reduces the items stock.
Based on this answer thread: Reduce stock only for specific order statuses and payment method in Woocommerce, I've customized the code and tried this script:
add_filter( 'woocommerce_can_reduce_order_stock', 'wcs_do_not_reduce_processing_stock', 10, 2 );
function wcs_do_not_reduce_processing_stock( $reduce_stock, $order ) {
if ( $order->has_status( 'processing' ) && $order->get_payment_method() == 'cod' ) {
$reduce_stock = false;
}
return $reduce_stock;
}
But it doesn't work.
How can I avoid stock reduction on order items for orders using "Cash on delivery" payment method with a "processing" status?