Skip to content

WordPress WooCommerce inventory sync issues — multi-channel, ERP, POS

WordPress WooCommerce inventory sync between POS, ERP, and marketplaces drifts under load. The diagnosis tree — race conditions, batch lag, stock-status vs stock-quantity, and the audit.

A WordPress WooCommerce store with an external ERP, an in-store POS (Square or Lightspeed), and presence on Amazon and Etsy has four systems trying to own inventory. The reconciliation runs every five minutes — except when it does not, or when two simultaneous orders fire on different channels and one ends up oversold. Inventory drift is the highest-cost silent failure in WooCommerce operations: refunds, support tickets, and goodwill all leak from the same wound.

What’s happening

WooCommerce stores stock data in two places that are easy to confuse:

  1. _stock (stock quantity). Integer. The number of units in stock. Set on the product, or on the variation for variable products.
  2. _stock_status (in_stock / out_of_stock / on_backorder). String. Derived from _stock by default, but can be overridden.

Plugins update one or the other or both. Inconsistency between the two is the most common root cause of “product is showing in stock but cannot be purchased” (or the reverse).

Sync between WooCommerce and an external system goes through one of:

  • WooCommerce REST API. External system polls /wp-json/wc/v3/products or /wp-json/wc/v3/products/{id}/variations and updates. Push from external to WC is similarly via PUT.
  • WP-CLI from a cron job. External system writes a JSON file, a WP-CLI script reads it and applies.
  • Plugin-managed. WooCommerce Square, WooCommerce Lightspeed, WooCommerce Amazon Marketplaces all manage their own sync via the gateway-specific webhooks and Action Scheduler.

The five common failure modes:

  • Race condition on simultaneous decrement. Two orders fire at the same time for the same product with one unit in stock. Both pass the _stock > 0 check, both decrement. The product is now at -1.
  • Batch lag. External ERP syncs every 15 minutes. In those 15 minutes, WooCommerce sells past the ERP’s known stock level.
  • _stock and _stock_status divergence. Plugin updates _stock to 0 but does not update _stock_status to out_of_stock. The product shows in stock but cannot be added to cart.
  • Variation stock vs parent product stock. Variable product has “Manage stock at parent level” off. Stock is managed per variation. External system updates the parent and the variations stay stale.
  • Reservation hold on cart. Plugins that “reserve” stock during cart sessions (CartFlows, some bookings plugins) and never release on session expiry. Stock looks committed when it is not.

How to verify

# Total stock-managed products
wp db query "SELECT COUNT(*) FROM wp_postmeta
  WHERE meta_key='_manage_stock' AND meta_value='yes'"

# Products with negative stock — usually a race-condition artifact
wp db query "SELECT pm.post_id, p.post_title, pm.meta_value AS stock
  FROM wp_postmeta pm
  JOIN wp_posts p ON pm.post_id=p.ID
  WHERE pm.meta_key='_stock' AND CAST(pm.meta_value AS SIGNED) < 0"

# Products with stock=0 but status=in_stock (the divergence case)
wp db query "SELECT p.ID, p.post_title
  FROM wp_posts p
  JOIN wp_postmeta pm_qty ON p.ID=pm_qty.post_id AND pm_qty.meta_key='_stock'
  JOIN wp_postmeta pm_status ON p.ID=pm_status.post_id AND pm_status.meta_key='_stock_status'
  WHERE p.post_type IN ('product','product_variation')
    AND pm_qty.meta_value = '0'
    AND pm_status.meta_value = 'instock'"

# Products with stock>0 but status=out_of_stock (the other divergence)
wp db query "SELECT p.ID, p.post_title
  FROM wp_posts p
  JOIN wp_postmeta pm_qty ON p.ID=pm_qty.post_id AND pm_qty.meta_key='_stock'
  JOIN wp_postmeta pm_status ON p.ID=pm_status.post_id AND pm_status.meta_key='_stock_status'
  WHERE p.post_type IN ('product','product_variation')
    AND CAST(pm_qty.meta_value AS SIGNED) > 0
    AND pm_status.meta_value = 'outofstock'"

# Recent stock changes — from the audit log if you have one
wp db query "SELECT * FROM wp_woocommerce_log WHERE source LIKE '%inventory%' ORDER BY timestamp DESC LIMIT 30"

# REST API rate limit hits (look for 429s)
grep " 429 " /var/log/nginx/access_log | grep wc/v3 | tail -20

# Action Scheduler queue for inventory sync hooks
wp action-scheduler list --status=pending --hook=wc_inventory_sync_batch --per_page=20

The first two divergence queries are the audit that finds the silent failures. A healthy store returns zero rows from both. A store with sync issues returns dozens.

The fix

  1. Eliminate the race condition. WooCommerce 7+ ships proper stock-reservation logic when “Hold stock (minutes)” is set in WooCommerce → Settings → Products → Inventory. Set this to 60 minutes for typical stores. For high-concurrency flash sales, set lower (15 min) and rely on Redis-based locking — the existing wc-scale-redis-sessions article covers session-state in Redis; pair with the Object Cache Pro layer for atomic decrements.
  2. Reconcile _stock and _stock_status periodically. A nightly WP-CLI script:
    wp eval '
    $offenders = get_posts(["post_type" => ["product","product_variation"], "posts_per_page" => -1, "fields" => "ids", "meta_query" => [["key" => "_manage_stock", "value" => "yes"]]]);
    foreach ($offenders as $id) {
      $qty = (int) get_post_meta($id, "_stock", true);
      $status = get_post_meta($id, "_stock_status", true);
      $expected = $qty > 0 ? "instock" : "outofstock";
      if ($status !== $expected) {
        update_post_meta($id, "_stock_status", $expected);
        echo "fixed $id: $qty -> $expected\n";
      }
    }
    '
  3. Decide one source of truth, write to it only. If the ERP is authoritative, WooCommerce should never decrement stock at the order level — it should only read what the ERP set. Disable WooCommerce’s auto-decrement via add_filter('woocommerce_can_reduce_order_stock', '__return_false') and let the ERP webhook push the new level after the order is acknowledged.
  4. Cap REST API rate limits when external systems poll. A misconfigured polling sync can hit /wp-json/wc/v3/products once per minute per SKU, which is a load problem. Cache the responses at the CDN or via a transient layer. Use Webhooks (push) instead of polling.
  5. Audit reservation plugins. For each “stock reservation” plugin active, confirm the reservation TTL. CartFlows and similar plugins should release on session expiry. If reservations linger past session expiry, contact the plugin vendor for a fix or write a cron that releases stale reservations:
    wp eval 'wc_release_stock_for_order(0, time() - 3600);'  # release reservations older than 1h
  6. Monitor divergence. A daily check using the two SQL divergence queries above, alerting if either returns more than 5 rows. Wire into your monitoring (Netdata, Uptime Kuma, your own).

For the underlying queue plumbing, the Action Scheduler audit article covers the AS hygiene. Pair with enterprise WordPress operations for the long-term monitoring posture.


Stack Harbor runs WordPress WooCommerce inventory operations end-to-end through enterprise WordPress operations — the source-of-truth decision, the race-condition prevention, and the daily divergence audit. If your stock keeps showing wrong numbers between channels, we can find and fix the root cause.