Back to Reports

Variable Product Children Cache Incorrectly Set After create_all_product_variations

open Sep 24, 2025 PluginWoocommerce

Summary:

The WC_Product_Data_Store_CPT::create_all_product_variations method contains a bug that causes the children cache on a variable product instance to become stale. The issue arises during an initial check for existing variations, which sets the product's internal children property to an empty array if none are found.

This cached value is not updated after the method proceeds to create new variations. Consequently, any subsequent call to WC_Product_Variable::get_children() on that specific product instance returns the stale, empty array instead of the IDs of the newly created variations. The get_children() method relies on the cached children property being null to trigger a fresh database lookup; once it is set to an array (even empty), the cache is considered valid and the database is not queried again.

This leads to incorrect data being returned for the product's variations immediately after their creation, potentially breaking subsequent logic that depends on an accurate list of children.

How to Replicate:

  1. Instantiate a new WC_Product_Variable object. Its internal $children property is null.
  2. Attach some attributes to the product.
  3. Call $product->get_data_store()->create_all_product_variations( $product ).
  4. After the method runs, the product's internal $children property is now an empty array, set during the initial existence check.
  5. Call $product->get_children(). It will return the empty array from the cache, not the IDs of the newly created variations.