GTIN / EAN problem with product variations on structured data

#57660
  • Resolved Artur S
    Rank Math free

    Hello. i still get problem with product variations on structured data. Google show warning even every product variation show gtin in google structured data.

    • This topic was modified 3 years, 10 months ago by Artur S.
Viewing 14 replies - 1 through 14 (of 14 total)
  • Todd
    Rank Math free

    Hi Artus,

    Thanks for getting in touch with us.

    You can use this filter in your theme’s functions.php file to fix the GTIN issue for variable products:

    /**
     * Filter to add GTIN to Variable Products.
     *
     * @param array $entity Snippet Data
     * @return array
     */
    add_filter( 'rank_math/snippet/rich_snippet_product_entity', function( $entity ) {
        $product = new WC_Product( get_the_ID() );
        if( $product->is_type( 'simple' ) ){
             $gtin_value = get_post_meta($product->get_id(),'_gtin', true);
             $entity['gtin8'] = $gtin_value;
             return $entity;
        }elseif($product->is_type( 'variable' )){
             $variation = new WC_Product_Variation(get_the_ID());
             $gtin_value = get_post_meta($variation->get_id(),'_gtin', true);
             $entity['gtin8'] = $gtin_value;
             return $entity;
        }else{
             return $entity;
        }
        
    });

    Hope that helps and please do not hesitate to let us know if you need our assistance with anything else.

    i have allready this in functions.php do i need to add your as extra ?
    add_filter( ‘rank_math/snippet/rich_snippet_product_entity’, function( $entity ) {
    global $product;
    if ( $product->is_type( ‘variable’ ) ) {
    $variations = $product->get_available_variations();
    foreach ( $variations as $key => $variation ) {
    $entity[‘offers’][ $key ][‘gtin13’] = get_post_meta( $variation[‘variation_id’], ‘_wpm_gtin_code’, true );
    }
    } else {
    $entity[‘gtin13’] = $product->get_meta( ‘_wpm_gtin_code’ );
    }

    return $entity;
    });

    Hello,

    Thank you for contacting Rank Math today.

    Please replace the function you currently have with the one provided above and let us know how it goes.

    Looking forward to helping you. Thank you.

    ​​​​​​

    1. i did replace code
    2. i did purge the product page
    3 i did test with google structured data testing tool

    ——-problem still there ——–
    *This Product is missing a global identifier (e.g. isbn, mpn or gtin8). Please see documentation for valid identifiers.*

    second thing. it was gtin 13 . in your new code gtin 8. wont it affect my products ?

    Hello,

    Thank you for the follow up.

    The access credentials you have provided don’t see to work for me. Please update so we can look into this issue further.

    Looking forward to helping you. Thank you.

    ​​​​​​

    Hello,

    I have updated the sensitive data as requested. Can you please check further?

    Thank you.

    Hello,

    Thank you for contacting Rank Math today.

    The access you provided has no access to your theme and editor.

    I’ve modified the code to the following since you have an EAN(13 digit) number:

    /**
     * Filter to add GTIN to Variable Products.
     *
     * @param array $entity Snippet Data
     * @return array
     */
    add_filter( 'rank_math/snippet/rich_snippet_product_entity', function( $entity ) {
        $product = new WC_Product( get_the_ID() );
        if( $product->is_type( 'simple' ) ){
             $gtin_value = get_post_meta($product->get_id(),'_wpm_gtin_code', true);
             $entity['gtin13'] = $gtin_value;
             return $entity;
        }elseif($product->is_type( 'variable' )){
             $variation = new WC_Product_Variation(get_the_ID());
             $gtin_value = get_post_meta($variation->get_id(),'_wpm_gtin_code', true);
             $entity['gtin13'] = $gtin_value;
             return $entity;
        }else{
             return $entity;
        }
        
    });

    Hope that helps and please do not hesitate to let us know if you need our assistance with anything else.

    Please check it . I gave you administrator role

    Hello,

    Thank you for contacting Rank Math today.

    I have updated the code on your site. Please check and confirm if the issue is still there. If so, please share some of the affected URLs so we can look into it.

    Looking forward to helping you. Thank you.

    ​​​​​​

    Thank you very much. Now google search console happy and accepting to fix warnings with GTIN. as i see you deleted GTIN from product variations and made for main product. In real world it was logic like it was before but if google wants like this let it be.
    Do i need to ask you for changing code every time i update theme ?

    Hello, after you change code main sitemap /sitemap_index.xml show 404 error. undersitemaps works ok.

    Hello,

    Thank you for contacting Rank Math today.

    To keep any filters you have added to your theme, you can create a child theme and include all your hooks & filters there.

    To solve the 404 on sitemap issue, could you please do the following:

    1. Head over to WordPress Dashboard > Settings > Permalinks

    Hit the save button once.

    2. Go to WordPress Dashboard > Rank Math > Sitemap Settings

    Hit the save button once.

    That should fix the issue.

    If it doesn’t, please do let us know so we can look at this further.

    Just updated to newest version ( today’s release) solved it self )

    Todd
    Rank Math free

    Hello,

    We are super happy that this resolved your issue. If you have any other questions in the future, know that we are here to help you.

    If you don’t mind me asking, could you please leave us a review (if you haven’t already) on https://wordpress.org/support/plugin/seo-by-rank-math/reviews/#new-post about your overall experience with Rank Math? We appreciate your time and patience.

    If you do have another question in the future, please feel free to create a new forum topic, and it will be our pleasure to assist you again.

    Thank you.

Viewing 14 replies - 1 through 14 (of 14 total)

The ticket ‘GTIN / EAN problem with product variations on structured data’ is closed to new replies.