Answer the question
In order to leave comments, you need to log in
How to reduce the stock of goods in woocommerce when the status is "pending"?
It is required that upon receiving the status of the order - "pending payment", the stock of the goods changed in the system.
At the moment, stocks change only after payment is received, but this option does not suit me, since the payment link can be active during the day. In this case, the product will hang in the catalog and it will be possible to add it to the basket, but when you go to the basket, it gives an error.
I tried this code, but nothing changes:
add_filter( 'woocommerce_can_reduce_order_stock', 'order_stock_reduction_based_on_status');
function order_stock_reduction_based_on_status( $reduce_stock, $order ) {
if ( ! $order->has_status( 'pending' ) ) {
$reduce_stock = true;
}
return $reduce_stock;
}
Answer the question
In order to leave comments, you need to log in
So, let's first determine why your orders are in the status pending
?
Because pending is an intermediate, "technical" status between the creation of an order and its payment, followed by a transition to the status processing
(in case of successful payment) or failed
(in case of an error with payment or refusal).
Payment methods with "deferred payment" (bank transfer, cash / cash on delivery) can use the status on-hold
- if the payment needs to be confirmed (the order will not start processing until the payment is confirmed), or immediately processing
if confirmation is not required (cash on delivery). Both processing
, and on-hold
reduce the stock, because these are just the statuses that you need to work with - they are created for this. BUTpending
- it's a little bit about something else.
Read more: https://docs.woocommerce.com/document/managing-ord...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question