Is anybody experiencing a message on their shopping cart saying that there is not enough in stock for their products? This has been a pretty popular topic recently and I just wanted to shed some light on a possible, less obvious reason as to why this could be.
A couple people posted in Slack and Facebook looking for help trying to find out why they were not able to checkout. Even though their store says a product is in stock and available.
So this is new to me, may not be new to WooCommerce, but the checkout process is now checking not only the amount of products in stock, but the amount of stock tied to pending orders! So to give you a good idea on what I mean, here is a simple example to help explain.
Not Enough In Stock? Wait.. Lies!
I have Product A in stock with 10 available. I have 9 orders with the 1 of Product A on the order, these orders are waiting for payment. In this situation, I can absolutely checkout and purchase Product A x1. BUT if I wanted to purchase 2, I would get a big message on my cart saying that there is not enough in stock for me to purchase! Even when the product page says there are 10 available. Confusing right? Uhhhhhh…… wtfudge?
So I started debugging to figure it out, found this chunk of code within the WC_Cart->check_cart_item_stock()
What this section is doing is checking if you are holding onto orders for payment. This setting is found in WooCommerce > Settings > Products > Inventory
If this setting is blank, the above code will not fire. If this is set, what this function does is it will reserve the products for the orders that have not been paid for. Preventing orders from being processed and causing you to run out of inventory. Of course backorders must be disabled on the product if you do want to use this handy feature.
So out of the box – this should not be a long lasting issue, but in order for it to keep your system clean – you will need to make sure your WP Cron is running! The cron is scheduled to clean out unpaid for orders, ultimately freeing up products stock.
Resolution
Well, you have a few options – really depends on how you want to move forward and how you want your store to process.
- Disable Hold Stock
- Allow Back Orders on the products
- Clean out Old Orders
Conclusion
This is a great feature, very handy! But without working knowledge of why this is happening, something completely unrelated can cause huge problems for your customers and headaches for your store manager. Nothing is broken, this was by design, high 5 to WC at the end of the day.
I hope this helps answer some questions, freak out moments and enables you to make your next move.
It helps me! Thanks!
Glad it helped! I still to this day see problems pop up on social networks in regards what this is and why their store is saying this.
I get help from your writing. Thank you very much James. You are very kind person always want to help people success.
Thank you and you are welcome!