1

I need a product stock to decrease immediately on order creation and it should not increase unless the order is cancelled (it should also not decrease a second time upon payment successful or any other switch).

My problem is I want to use my storefront to invoice and collect local service work. I am using a pay later invoice gateway that drops orders into processing & woo does not decrease stock in this status so the quantities I just sold are still listed as available in my product/catalog pages. However, I found that when a customer goes to add these intangible stock quantities they receive a message like unable to add to cart insufficient stock even though the catalog pages show its available.

I cannot figure out what function this would serve since the quantity is already spoken for in a payment pending order why is it showing in product/catalog pages. I showered every post I could find across 3 search engines trying to find a similar situation with an answer but haven't had much luck.

I found this:

function reduce_stock_processing($order_id) {
     wc_reduce_stock_levels($order_id);
}

In a post with similar issues and tried to implement but it had no effect that I could see.

I then found this:

add_action( 'woocommerce_valid_order_statuses_for_payment', function( $statuses, $order ) {
    $statuses[] = 'on-hold';
    return $statuses;
}, 10, 2 );

But it allowed me to drop orders into an on-hold status where woo does pull stock and it allowed for payment to be made from that status. I thought this is great finally, but when I started another round of testing I found that if I created an order and purchased all the remaining stock of a certain product it would A: pull the stock from inventory correctly leaving product stock at zero, then B: when I sent an email invoice to customer with payable link.

It tells them that the order cannot be paid for since item is out of stock. Frustrating, because it handles orders with abundant stock well; after order completed I'm left with appropriate stock levels.

It seems that woo needs to have extra stock on hand to allow customers to pay.... or at least that is how it seems to me.

Any ideas on how I can achieve my goal? Thanks in advance.

Update-

So I changed the first code to this:

function reduce_stock_pending($order_id) {
    wc_reduce_stock_levels($order_id);
}
add_action('woocommerce_order_status_pending', 'reduce_stock_pending');

and at first I thought it didn't work because the stock levels didn't change upon creating an order and having it drop straight to pending payment status, but after toggling the status to on-hold it reduced stock and when I toggle it back to pending status the stock remains reduced and with payment successful it does not further reduce stock so that seems at least workable considering I'm the moderator I'll know what to do.... but is there a better solution that would allow me to create an order and drop it straight into pending and have it reduce stock right away without having to toggle status back and forth.

-More Info Order notes: everything located above image only pertains to payment

So it seems to be rapidly increasing & then reducing stock on status change to pending. Again any help would be appreciated.

LoicTheAztec
  • 229,944
  • 23
  • 356
  • 399
Cranmoot
  • 51
  • 1
  • 6

0 Answers0