A WooCommerce store with stock management enabled can still sell the same last unit twice, because “is a unit available?” and “take a unit off the stock” are two separate operations with a gap between them. Stock is not decremented when a shopper adds to cart; it is decremented when the order reaches a paid or actionable status, which on a card checkout happens only after the gateway comes back. Since WooCommerce 4.0 a reservation row in wp_wc_reserved_stock narrows that gap — but the reservation exists only when stock management is on and woocommerce_hold_stock_minutes is greater than zero, and it covers only orders that travel the normal checkout path. A cached in-stock badge, a plugin writing _stock directly, MyISAM tables where the guarding transaction is a no-op, or an order created through the REST API all walk straight past it.
What you’ll accomplish
- Prove from the order records — not from a customer complaint — that a unit was sold twice, and name the exact orders and product.
- Read the store’s real reservation settings and decide whether the reserved-stock guard is active at all.
- Identify the contributing layer: page or object cache, a direct
_stockwriter, a storage engine without row locking, or a gateway callback that arrived after the hold expired. - Apply fixes in the order where each one changes the outcome, and leave behind an audit query you can re-run after the next drop.
Prerequisites
WooCommerce 8.0 or later on WordPress 6.4+, PHP 8.1+. The wp_wc_reserved_stock table has shipped since WooCommerce 4.0; on anything older the reservation half of this article does not apply, and the window is as wide as your gateway is slow.
Shell access with WP-CLI available as wp, run as the site user from the WordPress root, plus wp db query or a database client. Commands that use wp wc subcommands need a --user= flag naming an administrator, because the REST controllers behind them run capability checks; --user=1 is used throughout, so substitute your own admin ID.
Two schema facts decide which queries you run. High-Performance Order Storage moves orders into wp_wc_orders and order meta into wp_wc_orders_meta; without it, orders stay in wp_posts and wp_postmeta. Products are unaffected either way — _stock and _stock_status remain product post meta in wp_postmeta. Order line items are also unaffected: wp_woocommerce_order_items and wp_woocommerce_order_itemmeta are the same tables in both modes, which is why the forensic query below works on any store. Confirm where you are before you start.
wp option get woocommerce_custom_orders_table_enabled
wp config get table_prefix
yes
wp_
Substitute your prefix everywhere wp_ appears below. If the store is mid-migration and running in compatibility mode, read the HPOS migration guide before you draw conclusions from either order table.
How it works
Stock has exactly one authoritative number, _stock on the product (or on the variation, when the variation manages its own stock). Adding to cart does not touch it. The cart is session data. The product page’s in-stock badge is a read of _stock rendered at whatever moment that page was generated.
The write happens later. wc_maybe_reduce_stock_levels() is hooked to woocommerce_payment_complete and to the processing, completed and on-hold status transitions. It calls wc_reduce_stock_levels(), which for each line item calls wc_update_product_stock( $product, $qty, 'decrease' ) and records _reduced_stock as item meta so the same order can never be reduced twice.
That decrement is a single SQL statement of the form meta_value = meta_value - n, so it is atomic at the database level. This matters more than it sounds: concurrent decrements are not lost, they stack. Two orders that both passed the availability check produce -1, not 0. The negative value is the fingerprint, and it is the reason a store can oversell without a single error in any log.
The reservation table closes most of that window. When a checkout is submitted, WooCommerce inserts a row into wp_wc_reserved_stock (order_id, product_id, stock_quantity, timestamp, expires) using a conditional INSERT ... SELECT ... WHERE inside a transaction. The WHERE clause sums the unexpired reservations held by other orders and refuses the insert when that sum plus the requested quantity would exceed available stock. Because the check and the write are one statement under InnoDB, two simultaneous submissions cannot both succeed. The loser gets the “not enough in stock” error at checkout instead of a receipt.
Three conditions have to hold for that to protect anything. Stock management must be on globally (woocommerce_manage_stock). woocommerce_hold_stock_minutes must be greater than zero — this is the same setting that drives the scheduled woocommerce_cancel_unpaid_orders job for bank transfer and cash-on-delivery orders, and stores that disable unpaid-order cancellation by setting it to zero silently disable reservations at the same time. And the tables must be InnoDB, because on MyISAM the transaction is accepted and ignored.
What reservation never covers: orders created through /wp-json/wc/v3/orders, orders keyed in by staff, CSV imports, subscription renewals, and any plugin that writes _stock with update_post_meta() or raw SQL rather than wc_update_product_stock(). Those last ones also skip WooCommerce’s cache invalidation, so the object cache keeps serving the pre-write number.
Step-by-step
1. Confirm the oversell from the line-item record. _reduced_stock is written per line item at the moment stock was taken, which makes it the only trustworthy record of what actually left inventory. Sum it per product across a time window and compare with what you had on hand.
wp db query "SELECT pid.meta_value AS product_id, oi.order_id, red.meta_value AS reduced, o.status, o.date_created_gmt
FROM wp_woocommerce_order_items oi
JOIN wp_woocommerce_order_itemmeta pid ON pid.order_item_id = oi.order_item_id AND pid.meta_key = '_product_id'
JOIN wp_woocommerce_order_itemmeta red ON red.order_item_id = oi.order_item_id AND red.meta_key = '_reduced_stock'
JOIN wp_wc_orders o ON o.id = oi.order_id
WHERE pid.meta_value = '4821' AND o.date_created_gmt >= '2026-08-23 00:00:00'
ORDER BY o.date_created_gmt"
product_id order_id reduced status date_created_gmt
4821 18422 1 wc-processing 2026-08-23 14:00:07
4821 18423 1 wc-processing 2026-08-23 14:00:07
Two orders, same second, one unit each, on a product that had one unit. That is the oversell, established from records rather than from a phone call. On a store without HPOS, replace the last join with JOIN wp_posts o ON o.ID = oi.order_id and read o.post_status and o.post_date_gmt instead. For variable products, _product_id holds the parent; add a join on _variation_id when the variation manages its own stock.
2. Read what the product holds now. Negative stock survives until someone edits the product, so it is often still sitting there.
wp wc product get 4821 --user=1 --fields=id,name,manage_stock,stock_quantity,stock_status
wp db query "SELECT post_id, meta_value FROM wp_postmeta WHERE meta_key = '_stock' AND CAST(meta_value AS SIGNED) < 0"
+-----------------+--------------------+
| Field | Value |
+-----------------+--------------------+
| id | 4821 |
| name | Limited Hoodie |
| manage_stock | 1 |
| stock_quantity | -1 |
| stock_status | outofstock |
+-----------------+--------------------+
post_id meta_value
4821 -1
A store-wide list of negatives is the fastest census of how often this happens. An empty list on a store that clearly oversold means something is clamping the value — usually an inventory sync that pushes its own number back in afterwards, which erases the evidence.
3. Check whether the reservation guard is switched on. Three options decide it.
wp option get woocommerce_manage_stock
wp option get woocommerce_hold_stock_minutes
wp eval '$r = new \Automattic\WooCommerce\Checkout\Helpers\ReserveStock(); echo "reserved now: " . $r->get_reserved_stock( wc_get_product( 4821 ) ) . "\n";'
yes
0
reserved now: 0
woocommerce_hold_stock_minutes at 0 — or empty — is the single most common cause of an oversell on an otherwise correctly configured store. Someone turned off unpaid-order cancellation because bank-transfer customers were losing their orders overnight, and turned off checkout reservations as a side effect. Set it to a value that covers your slowest gateway round trip with margin, typically 15 to 60 minutes.
wp option update woocommerce_hold_stock_minutes 30
Success: Updated 'woocommerce_hold_stock_minutes' option.
Then confirm the table exists and is actually being written during a checkout.
wp db query "SELECT product_id, order_id, stock_quantity, expires FROM wp_wc_reserved_stock WHERE expires > NOW() ORDER BY product_id"
product_id order_id stock_quantity expires
4821 18461 1 2026-08-24 15:12:44
4. Check the storage engine. A conditional insert inside a transaction is only a guard if the engine honours transactions and row locks.
wp db query "SELECT TABLE_NAME, ENGINE FROM information_schema.TABLES
WHERE TABLE_SCHEMA = DATABASE()
AND TABLE_NAME IN ('wp_postmeta','wp_options','wp_wc_reserved_stock','wp_wc_orders')"
TABLE_NAME ENGINE
wp_options InnoDB
wp_postmeta MyISAM
wp_wc_orders InnoDB
wp_wc_reserved_stock InnoDB
wp_postmeta on MyISAM is a legacy migration artifact and it is a real contributor here: MyISAM has no row locking and no transactions, so concurrent writers serialise on a full table lock or interleave badly under load. Convert it during a maintenance window, after a verified backup, and expect the operation to lock the table for its duration on a large store.
wp db query "ALTER TABLE wp_postmeta ENGINE=InnoDB"
Query OK, 1842219 rows affected
Lock contention on wp_postmeta under checkout load is its own failure mode; if you see it as deadlocks rather than as overselling, InnoDB deadlock detection covers reading them.
5. Find writers that bypass wc_update_product_stock(). Anything writing _stock directly skips both the reservation check and the cache flush.
grep -rnE "update_post_meta\s*\([^,]+,\s*['\"]_stock['\"]" wp-content/plugins/ --include=*.php | head -n 20
grep -rniE "UPDATE\s+.{0,30}postmeta" wp-content/plugins/ --include=*.php | head -n 20
wp-content/plugins/erp-connector/includes/class-sync.php:214: update_post_meta( $product_id, '_stock', (int) $remote_qty );
wp-content/plugins/erp-connector/includes/class-sync.php:219: update_post_meta( $product_id, '_stock_status', $remote_qty > 0 ? 'instock' : 'outofstock' );
A hit here is not automatically a bug, but it is a plugin holding a private opinion about stock. The correction is to ask the vendor to route through wc_update_product_stock(), which performs the arithmetic in SQL and clears the product caches afterwards.
6. Check the cache layer. A shopper cannot reserve what a stale page told them was available, and the reservation error at checkout is a poor moment to learn that.
curl -sI https://example.com/product/limited-hoodie/ | grep -iE 'x-cache|cf-cache-status|age:'
wp eval 'echo wp_using_ext_object_cache() ? "external object cache active\n" : "no persistent object cache\n";'
cf-cache-status: HIT
age: 812
external object cache active
A 13-minute-old cached product page during a drop is a queue of shoppers all being told the same stale number. Cart, checkout and account pages must never be cached, and the standard WooCommerce cookies — woocommerce_items_in_cart, woocommerce_cart_hash and wp_woocommerce_session_* — must trigger a bypass. Product pages for stock-limited items want a short TTL during a drop, or the stock figure pulled from an uncached fragment.
7. Measure the gateway callback delay. The reservation hold has to outlast it. Compare order creation with the note recording payment.
wp eval 'foreach ( array( 18422, 18423 ) as $id ) { $o = wc_get_order( $id ); $notes = wc_get_order_notes( array( "order_id" => $id, "orderby" => "date_created", "order" => "ASC" ) ); $last = end( $notes ); echo $id . " created " . $o->get_date_created()->date( "H:i:s" ) . " last note " . ( $last ? $last->date_created->date( "H:i:s" ) : "none" ) . "\n"; }'
18422 created 14:00:07 last note 14:00:19
18423 created 14:00:07 last note 14:47:31
Forty-seven minutes between order creation and the payment note means the reservation had already expired when stock was finally reduced. If your gateway routinely does this — offline payment methods and some bank redirects do — the hold has to be longer than the worst case you observe, not the average. Slow checkouts widen every one of these windows at once, so a store that is also throwing 504s during a drop has two problems feeding each other.
Validate it works
Set a test product to exactly one unit with stock management on, then fire two checkouts against it at the same moment from two browsers or two logged-in sessions. One should complete. The other should stop at checkout with the “not enough in stock” notice rather than reaching a thank-you page.
While both are mid-checkout, look at the reservation table.
wp db query "SELECT order_id, product_id, stock_quantity, expires FROM wp_wc_reserved_stock WHERE product_id = 4821 AND expires > NOW()"
order_id product_id stock_quantity expires
18499 4821 1 2026-08-24 16:04:02
Exactly one row for a one-unit product is the guard doing its job. Two rows means the conditional insert is not being enforced — go back to step 4 and check the engine.
Afterwards, run the step 1 audit query for the test window. It should show one order with _reduced_stock = 1 and no second row. Keep that query; running it the morning after every drop turns overselling from a customer-service surprise into a number you already have.
Troubleshooting
The audit query returns nothing on a store you know oversold. _reduced_stock is only written when stock was reduced through WooCommerce. If an external system decremented its own inventory and pushed the result in, there is no line-item record. Fall back to comparing order line quantities against the stock value logged before the drop, and treat the absence of _reduced_stock as evidence that the reduction happened outside WooCommerce.
Reservations exist but overselling continues. Check whether the orders involved came through checkout at all. Orders created via the REST API, the admin screen, an import, or a subscription renewal never reserve — they reduce stock at the status transition and can take a unit a reserved shopper was counting on. Segment the audit output by created_via.
wp db query "SELECT id, status, created_via, date_created_gmt FROM wp_wc_orders WHERE id IN (18422,18423)"
id status created_via date_created_gmt
18422 wc-processing checkout 2026-08-23 14:00:07
18423 wc-processing rest-api 2026-08-23 14:00:07
Stock goes negative, then silently corrects itself. An inventory sync is overwriting _stock on a schedule and erasing the record. That is worse than the oversell, because you lose the ability to detect it. Pause the sync while investigating, or log its writes.
Backorders are on and nobody noticed. _backorders set to yes or notify means WooCommerce is supposed to sell past zero, and what looks like an oversell is configuration. Check the product before assuming a race.
wp db query "SELECT post_id, meta_value FROM wp_postmeta WHERE meta_key = '_backorders' AND post_id = 4821"
The checkout now rejects legitimate customers. Reservations from abandoned checkouts hold stock until expires passes. A very long woocommerce_hold_stock_minutes on a low-stock product will show items as unavailable to everyone while a handful of abandoned sessions sit on them. Rows expire on their own; the fix is a shorter hold, not manual deletion, and the tension between the two is real — a longer hold protects against slow gateways, a shorter one keeps stock circulating.
When this is the wrong approach
None of this makes overselling impossible, and any vendor who says otherwise is selling something. On a store whose inventory is owned by an external system — an ERP, a POS, a marketplace listing — the authoritative number lives elsewhere and arrives on a delay. WooCommerce can only guard the units it believes it has. Two channels selling the same physical shelf will eventually oversell, and the operational answer is a safety buffer held back from the online channel plus a rehearsed cancellation-and-apology path, not a configuration change.
Reservations are also the wrong tool for a genuinely high-contention drop — thousands of shoppers, tens of units. There, every checkout after the first few is a rejection, and rejecting people at the payment step is the most expensive place to do it. That workload wants a queue or a lottery in front of the store, so the contention is resolved before anyone reaches checkout at all.
The references worth keeping open are the WooCommerce settings documentation for the Inventory tab, and the WooCommerce developer portal for the stock functions and reservation helper named above.
Running WordPress that earns real money deserves an operator — Stack Harbor runs that stack under Enterprise WordPress; book an infrastructure consult.