• Resolved isarisar

    (@isarisar)


    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;
    }
Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter isarisar

    (@isarisar)

    Seems you already had a check like that in mind? Considering line 1611

    $prod_type = $product->get_type();

    … but that variable is never used.

    Hi,

    Thanks for using our plugin and reaching out to us.

    The structured data fix feature is a feature of our paid Elite plugin. Unfortunately, per the WordPress forum guidelines, we’re not allowed to discuss our paid Elite plugin here so for any questions about our paid plugins, please contact our support team directly.

    Thread Starter isarisar

    (@isarisar)

    I understand. Though I don’t think more input is needed from us to require further discussion as we’ve probably found the cause. From the past two occurrences:

    The issue reproducibly happens when a

    • grouped product page
    • is called with any parameter, so far ?epik=… (pinterest?) or ?pp=… (Youtube?)

    Our grouped products consist/reference only variable products. We added a try&catch block with some logging — prior to it, the function failed after trying to process the first VP reference, now it tries & fails with each VP the GP references.

    [The reason this hasn’t been a pressing issue for us yet is our GPs are not exported into feeds, and so no recipient tries to check their bugged SD.]

    Thread Starter isarisar

    (@isarisar)

    Ah, I see now that the plugin doesn’t support Grouped Products anyway.

    So to at least get rid of the errors, I just changed the…

    if ($nr_get > 0)

    … in woosea_product_fix_structured_data to:

    if ($nr_get > 0 && $product->get_type() !== "grouped")

    Note that the minimum price reported by…

    $product_price = wc_get_price_including_tax($product)

    … at the end of woosea_product_delete_meta_price doesn’t match for Grouped Products. Woocommerce’s own solution is in the first dozen+ lines of get_price_html, but it seems fixing this just adds pointless overhead.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘[Structured Data Fix] Uncaught WC_Data_Exception: Invalid product type’ is closed to new replies.