-
Hi
i have install WooCommerce UPC, EAN, and ISBN for add GTIN code but Rank Math dont add GTIN in the SCHEMA markup
How add GTIN in SCHEMA markup ?
Tnks
-
Hello,
Thank you for contacting Rank Math support, and sorry for any inconvenience that might have been caused due to that.
Kindly follow this guide on how to properly setup GTIN to be included in your schema: https://rankmath.com/kb/gtin-mpn-woocommerce/
If you have further issues with it, just let us know. We are here to help.
Looking forward to helping you.
Hi
this guide is only for PRO Version.In file fuction.php i add this
add_filter( ‘rank_math/snippet/rich_snippet_product_entity’, function( $entity ) {
$entity[‘gtin13’] = get_post_meta( $variation[‘variation_id’], ‘hwp_var_gtin’, 1 );
return $entity;
});get_post_meta( $post_id, ‘hwp_product_gtin’, 1 );
add_filter( ‘rank_math/snippet/rich_snippet_product_entity’, function( $entity ) {
$entity[‘gtin13’] = get_post_meta( $post_id, ‘hwp_product_gtin’, 1 );
return $entity;
});I use WOO Gtin plugin for add GTIN code in admin pannel.
Tnks
Hello,
I apologize for the confusion.
The first filter code you shared should only accept post id but you are passing variation ID. It seems you already fixed that in your second filter code. Can you please confirm?
Also, can you please confirm if you wish to apply the GTIN to each variation of a product?
Please note that Google looks for the GTIN in the main product to pass this Schema markup test successfully and if the GTIN is on all the variations’ offers but not on the main one it will fail, so we first recommend adding the value inside the parent product.
Having said that, if you would also like to add the GTIN for all the variations you can apply the following filter on your website:
add_filter( 'rank_math/snippet/rich_snippet_product_entity', function( $entity ) { if ( ! is_product() ) { return $entity; } $product = wc_get_product( get_the_ID() ); if ( ! $product->is_type( 'variable' ) ) { return $entity; } $variations = $product->get_available_variations(); if ( ! empty( $variations ) ) { $offers = []; foreach ( $variations as $variation ) { $price_valid_until = get_post_meta( $variation['variation_id'], '_sale_price_dates_to', true ); $offers[] = [ '@type' => 'Offer', 'description' => strip_tags( $variation['variation_description'] ), 'price' => $variation['display_price'], 'priceCurrency' => get_woocommerce_currency(), 'availability' => $variation['is_in_stock'] ? 'https://schema.org/InStock' : 'https://schema.org/OutOfStock', 'itemCondition' => 'NewCondition', 'priceValidUntil' => $price_valid_until ? date_i18n( 'Y-m-d', $price_valid_until ) : '2025-12-31', 'url' => $product->get_permalink(), 'sku' => $variation['sku'], 'gtin' => get_post_meta( $product->get_id(), 'hwp_product_gtin', 1 ); ]; } } $entity['offers'] = $offers; return $entity; } );
Let us know how that goes. Looking forward to helping you.
Tnks for reply
The code I have post i found in the community.
at the moment this code does not work for me for the main product, for the variations I should tryHello,
Please keep us in the loop on how this goes. If there are further issues with our plugin, just let us know. We are here to help you.
Thank you.
Hi Jeremy
Your code return critical error.
TnksHello,
Can you please share the error message you receive upon experiencing the critical error?
Looking forward to helping you.
Hello,
I have updated the sensitive data as requested. Can you please check further?
Thank you.
Tnks to reply
I change the script in file fuction with this
add_filter( 'rank_math/snippet/rich_snippet_product_entity', function( $entity ) { $entity['gtin13'] = get_post_meta( $variation['variation_id'], 'hwp_var_gtin', 1 ); return $entity; }); get_post_meta( $post_id, 'hwp_product_gtin', 1 ); add_filter( 'rank_math/snippet/rich_snippet_product_entity', function( $entity ) { $entity['gtin13'] = get_post_meta( $post_id, 'hwp_product_gtin', 1 ); return $entity; }); add_filter( 'rank_math/snippet/rich_snippet_product_entity', function( $entity ) { $entity['gtin'] = get_post_meta( $post_id, 'hwp_product_gtin', 1 ); return $entity; });
but the field GTIN is empty
Do u want check ? I send u sensitive data.
Tnks
Hello,
Thank you for your patience as we look into adding GTINs to your product variations. I tried the FTP credentials you shared but could not log in. Please may you check them and share again.
In the mean time, I also checked the code snippets you shared in the last reply. The snippets you shared will not work for product variations as they are for main product entities, not variation entities. The snippet you received in this reply should work after some modifications: https://support.rankmath.com/ticket/add-gtin/?view=all#post-426079
Looking forward to helping you.
Hello,
I have updated the sensitive data as requested. Can you please check further?
Thank you.
Hi
Tnks for reply. I have correct the sensitive data, i change host ftp with IP server.I’m starting to get confused.
Please can fix the function file for both simple product and variations.Tnks so much
Regards
Hello,
I was able to access the FTP but I was only given an empty folder as you can see in my screenshot in the Sensitive Data section.
Looking forward to helping you on this one.
Hello,
I have updated the sensitive data as requested. Can you please check further?
Thank you.
Excuse me. Try again.
Tnks
The ticket ‘add gtin’ is closed to new replies.