WooCommerce 9.7: Fixing Variable Products Going Out of Stock

TL;DR: WooCommerce has implemented validation for cached variation data. When invalid data is detected, the system now automatically rebuilds it from the database, eliminating the need for manual intervention by merchants. Will be released in WC 9.7.0

A challenging issue (which has over 130 comments!) I encountered was the mysterious case of products incorrectly showing as “out of stock” despite having available inventory. This bug was particularly frustrating for merchants as it directly impacted their sales and required manual intervention to temporarily fix.

Understanding the Problem

The issue manifested when variable products would suddenly display “This product is currently out of stock and unavailable” despite having stock available. Through video calls with two merchants, I discovered this was happening across different setups and environments. These conversations were invaluable – they helped me understand the real-world impact and various scenarios where the bug appeared.

The merchants shared that:

  • Products would randomly show as out of stock
  • Manually updating the product (without changes) would temporarily fix it
  • The issue would return after some time
  • It affected both frequently and rarely accessed products

The Root Cause

After investigation, we found the issue stemmed from corrupted transient data. WooCommerce uses transients to cache product variation data for performance, storing two key pieces of information:

  • Child variation IDs and visibility status
  • Variation prices (regular, sale, and current)

When this cached data became corrupted or malformed, WooCommerce would fail to properly determine the product’s stock status.

The Solution: Data Validation

The fix involved implementing validation checks for both children and price transient data. We check the data structure and content each time we read from or write to these transients. When validation fails, the system automatically clears the invalid data and rebuilds it fresh from the database. This self-healing approach ensures data integrity without requiring merchant intervention.

For those interested in the nitty-gritty here are the PRs that fixed the issue:

I wrote a related post here on the importance of cache validation. Cache 22: The Importance of Validating Transient Data.

Lessons Learned

  1. Direct user feedback is invaluable. The video calls with merchants provided insights that weren’t apparent from bug reports alone.
  2. Always validate data you’re reading or writing, especially cached data.
  3. When building caching systems, plan for data validation and recovery.

This fix not only resolved the immediate issue but also made the system more robust against similar problems in the future.

2 responses to “WooCommerce 9.7: Fixing Variable Products Going Out of Stock”

  1. I’m still having the problem after updating WC.

    1. Tom Cafferkey Avatar
      Tom Cafferkey

      Can you please open a Github Issue or ticket on the support forums with your system report so we can look into this further? Thank you!

Leave a Reply to Tom Cafferkey Cancel reply

Your email address will not be published. Required fields are marked *