I'm working on a bit of custom Woocommerce functionality for a client. They use the BACS payment gateway to handle manual payments.
However, the gateway currently reduces the stock too early for our needs, i.e., when the order is "On Hold". I would like to ONLY reduce the stock when the order is marked "Processing" or "Complete" (avoiding duplicate reductions).
I have manged to prevent the stock from reducing itself while "on hold" with the following snippet:
function wcs_do_not_reduce_onhold_stock( $reduce_stock, $order ) {
if ( $order->has_status( 'on-hold' ) ) {
$reduce_stock = false;
}
return $reduce_stock;
}
add_filter( 'woocommerce_can_reduce_order_stock', 'wcs_do_not_reduce_onhold_stock', 10, 2 );
I'm not too sure how to proceed though. While the above code works, adding the following condition does not:
else if ( $order->has_status( 'processing' ) || $order->has_status( 'completed' ) ) {
$reduce_stock = true;
}
In short, I'd ideally like the stock to change depending on the following stock statuses:
- On Hold - Does nothing
- Completed or Processing - Reduce Stock (Only once)
- Cancelled - Increase Stock (Only if initially reduced)
Any help is much appreciated!