NEW: Boost your store with Customer Ray's powerful insights – Join our FREE early preview today!🚀🔓
WooCommerce is finally getting a real solution to reserving product stock for customers, but it’s not what you might think. Let me explain.
To understand the new
wc_reserved_stock database table (mentioned in the 4.3 beta post) and what its features will do for your store, I first need you to understand the current state of stock and orders. Here is the simple version step by step.
The current stock handling & issues that you are facing!
Customers have to be fast & decisive or miss out.
For example, let us say we have 10 x Air Fryers in stock (I just got one, they are awesome.)
100 people want the Air Fryer too! Each of them adds 1 Air Fryer to their cart. Yes, unlimited people can add Air Fryers to their cart, but one person cannot add more than 10.
Our grandmother Gladis is one of those people. Gladis goes to checkout and starts filling out her information. She is blind as a bat, so it takes her a little while. Sadly when she’s ready and tries to purchase the Air Fryer, she’s greeted with a WooCommerce notice “Unable to complete order, the product is out of stock“. Sadly Grandma Gladis missed out.
WooCommerce will only reduce the product’s stock quantity once the cart has turned into a pending order. 90 people were left disappointed in this example. It’s a race to who can pay first, without knowing that you are in a race. One person could have purchased all 10 items in one go as well.
It’s a compute race too
Another issue with the current setup is something called ‘race conditions’. These conditions aren’t people racing each other to pay for the product, but rather the server racing to reduce stock as soon as orders have been placed.
Lets say we have 100 people again trying to purchase the 10 stock. They all place their orders at the same time. What happens is that the server might freak out while processing all 100 orders and reduce the stock by more than 10. All of a sudden we have -39 Air Fryers and 39 people that won’t get their Air Fryer!
Introducing “semi” fix with WC 4.3!
WooCommerce 4.3 brings some interesting solutions to the problems. The WooCommerce team is mainly focused on keeping stock quantity correct when orders are placed. Therefore, they are creating a new database table called
wc_reserved_stock. You can read the development conversations on GitHub.
Don’t worry if you aren’t familiar with the database, I’ll explain.
wc_reserved_stock table is basically an extra layer in the database to ensure data consistency. The table is used to keep track of the customer’s draft order, the product, & stock quantity. Most exciting, it also tracks how long the products are reserved for each draft order! Now Grandma Gladis from our first example can take her sweet time to check out. She knows that she has claimed her stock for 60 minutes (60 minutes is the default reservation time).
There’s a catch
Gladis can still miss out of getting an Air Fryer if she doesn’t go to the checkout page quickly enough. Even though she has the product in her cart!
Okay, so let’s dive in. WooCommerce does not reserve stock when products are added to the cart. It only reserves stock and creates a draft order when Gladis visits the checkout. Why? I’ll show you how the reserving stock works with this graphic. We are referring to the “Block Checkout”. The features will only be available while using the new WooCommerce Checkout Block.
WooCommerce is only making this happen when customers show an intent to follow through with the purchase by going to the checkout page. WooCommerce tries not to be too opinionated. After all, WooCommerce is focused on being flexible for all kinds of eCommerce stores. But this doesn’t help poor Gladis.
Our Solution #AIRFRYER4GLADIS
I applaud WooCommerce for the progress on this issue. I’m excited about it and I want extend the reserving stock features to make sure Gladis will be able to reserve her Air Fryer as soon as she has added it to the cart.
We were already building a plugin ( Reserved Stock Pro for WooCommerce ) to reserve stock in customers’ carts. However, that was before I knew about the new changes in WC 4.3.
So we’ve decided to change the direction of the plugin from our own stock reservation system to use the new built-in WooCommerce
wc_reserved_stock database table.
Update: I ended up taking a similar approach to maximize the flexibility and performance of Reserved Stock Pro without the dependencies of draft orders and the WooCommerce Block Checkout. You can read more about the Reserved Stock Pro technical explanation in our documentation.
Reserved Stock Pro is production-ready and tested by over 100+ WooCommerce stores.
Just bought this – it appears it’s still not using the wc_reserved_stock table. is there an update coming?
Hi Jason! Sorry for the confusion, I’ll update this post shortly. I attempted to use the
wc_reserved_stock, but we ran into technical/performance limitations, mostly due to how WC wants to create “draft orders” and required the block plugin. Therefore Reserved Stock Pro uses it’s own (similar) DB table
rsp_reserved_stockfor maximum performance and flexibility. You can read more in the technical explanation.