Hello,
Thank you for contacting Rank Math and sorry for any inconvenience that might have been caused due to that.
Could you please replace the previous code with the following and let us know how this goes:
add_filter( 'rank_math/snippet/rich_snippet_product_entity', function( $entity ) {
global $product;
if(is_single()){
$entity['gtin13'] = $product->get_meta( '_wpm_gtin_code' );
return $entity;
}elseif($product->is_type( 'variable' )){
$variations = $product->get_available_variations();
foreach ( $variations as $variation ) {
$entity['gtin13'] = $variation->get_meta( '_wpm_gtin_code' );
return $entity;
}
}
return $entity;
});
Looking forward to helping you. Thank you.
I have replaced the code but the issue with variable products exists.
Hello,
Thanks for the reply.
We might need to take a closer look at the settings. Please edit the first post on this ticket and include your WP logins in the designated Sensitive Data section.
It is completely secure and only our support staff has access to that section. If you want, you can use the below plugin to generate a temporary login URL to your website and share that with us instead:
https://wordpress.org/plugins/temporary-login-without-password/
You can use the above plugin in conjunction with the WP Security Audit Log to monitor what changes our staff might make on your website (if any):
https://wordpress.org/plugins/wp-security-audit-log/
We really look forward to helping you.
Hello,
I have updated the sensitive data as requested. Can you please check further?
Thank you.
Hi there,
I am consulting our dev team about this and we will be in touch shortly.
We appreciate your patience. Thank you.
Hello,
Please try adding the following code:
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'] = $variation->get_meta( '_wpm_gtin_code' );
}
} else {
$entity['gtin13'] = $product->get_meta( '_wpm_gtin_code' );
}
return $entity;
});
I wanted to add it in your functions.php file but your login access is not working anymore.
I hope that helps.
Hello,
I have updated the sensitive data as requested. Can you please check further?
Thank you.
We are using gtin14 so i amended gtin13 with gtin14 in the code.
After adding the code to themefunctions.php Variable product stopped working. Error stating”There was some problem with your wordpress site”. Simple products do work though.
So i removed the code for now.
Also i updated the login access for your usage.
Thanks
Hello,
Thank you for contacting Rank Math today and sorry for the delay.
We are checking this and we will be in touch in a short while.
Looking forward to helping you. Thank you.
Hello,
Your login link has expired. Please create a new link with access to at least 3 days.
Looking forward to helping you.
I have extended the same to 6 days. Please use the same Login URL.
Hello,
I logged into your site and I added following code in your theme’s functions.php file:
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;
});
This seemed to have fixed the issue. Can you please confirm?
Thank you.
Hello:
That does solve the problem for Variable products. Thanks for that.
Although since Google sees the Master product as container of these variable product, it still shows one error for sku & gtin for the master product which carries these variable products. Is there any way to remove that information from schema so google reads it all right and warnings are also fixed?
Regards
Hello,
Sorry for not following up quickly and any inconvenience that might have been caused due to that.
The warning which you see in the Google Structured Data Testing tool is a false positive. You can add the SKU and gtin for Master product in Woocommerce Product >> Inventory >> SKU field. But since your master product is just a holder which contains variable products, the SKU and gtin is not needed. You can ignore those warnings.
I hope that helps.