[Structured Data Fix] Uncaught WC_Data_Exception: Invalid product type
-
This “suddenly” started ~ 2-3 weeks ago, occurring 1-2x per day:
PHP Fatal error: Uncaught WC_Data_Exception: Invalid product type: passed ID does not correspond to a product variation. in /srv/wp-content/plugins/woocommerce/includes/data-stores/class-wc-product-variation-data-store-cpt.php:58 Stack trace: #0 /srv/wp-content/plugins/woocommerce/includes/class-wc-data-store.php(159): WC_Product_Variation_Data_Store_CPT->read(Object(WC_Product_Variation)) #1 /srv/wp-content/plugins/woocommerce/includes/abstracts/abstract-wc-product.php(138): WC_Data_Store->read(Object(WC_Product_Variation)) #2 /srv/wp-content/plugins/woocommerce/includes/class-wc-product-simple.php(24): WC_Product->__construct(7600) #3 /srv/wp-content/plugins/woocommerce/includes/class-wc-product-variation.php(54): WC_Product_Simple->__construct(7600) #4 /srv/wp-content/plugins/woo-product-feed-pro/woocommerce-sea.php(1614): WC_Product_Variation->__construct(7600) #5 /srv/wp-includes/class-wp-hook.php(307): woosea_product_fix_structured_data(Object(WC_Product_Grouped), Object(WC_Product_Grouped)) #6 /srv/wp-includes/plugin.php(191): WP_Hook->apply_filters(Array, Array) #7 /srv/wp-content/plugins/woocommerce/includes/class-wc-structured-data.php(328): apply_filters('woocommerce_str...', Array, Object(WC_Product_Grouped)) #8 /srv/wp-includes/class-wp-hook.php(307): WC_Structured_Data->generate_product_data(Object(WC_Product_Grouped)) #9 /srv/wp-includes/class-wp-hook.php(331): WP_Hook->apply_filters(NULL, Array) #10 /srv/wp-includes/plugin.php(476): WP_Hook->do_action(Array) #11 /srv/wp-content/plugins/woocommerce/templates/content-single-product.php(60): do_action('woocommerce_sin...') #12 /srv/wp-includes/template.php(772): require('/srv/wp-content...') #13 /srv/wp-content/plugins/woocommerce/includes/wc-core-functions.php(284): load_template('/srv/wp-content...', false) #14 /srv/wp-content/plugins/woocommerce/templates/single-product.php(37): wc_get_template_part('content', 'single-product') #15 /srv/wp-includes/template-loader.php(106): include('/srv/wp-content...') #16 /srv/wp-blog-header.php(19): require_once('/srv/wp-content...') #17 /srv/index.php(17): require('/srv/wp-content...') #18 {main} thrown in /srv/wp-content/plugins/woocommerce/includes/data-stores/class-wc-product-variation-data-store-cpt.php on line 58
The product IDs so far have always been some variable product’s base ID.
Unfortunately I don’t know which update triggered nor how to manually reproduce it, but fortunately I haven’t seen issues with the fixed structured data (well, not *more* issues, that is: every now & then Google Merchant reports mismatches that turn out to be phantoms when I check).
Looking at the code, the line reported is:
$product_variations = new WC_Product_Variation( $child_val );
With
$child_val
being derived from:$children_ids = $product->get_children();
Maybe there should be a check added, similar to this one?:
if ($product->is_type('variable')) { foreach ($product->get_children() as $variation_product_id) { $products[] = wc_get_product($variation_product_id); } } else { $products[] = $product; }
- The topic ‘[Structured Data Fix] Uncaught WC_Data_Exception: Invalid product type’ is closed to new replies.