If you registered your WooCommerce website on Google Search Console for monitoring your SEO efforts and search appearance errors, you probably got this “No global identifier provided (e.g. gtin, brand)” email notification at some stage. I got it too.
Search Console optionally requests you set a unique product GTIN structured data for all your products – I believe in case you wish to sell on Google Shopping – and therefore sends you this error notification whenever a product is missing this.
You could use a WooCommerce GTIN plugin from the WP repo, yes. Or you could be smart, and programmatically set the GTIN to the same value of the product SKU, as long as all your products have a unique SKU value. Today, we will cover the latter. Enjoy!
PHP Snippet: Programmatically Set Product GTIN Based on SKU
/**
* @snippet Set WooCommerce Product GTIN
* @how-to Get CustomizeWoo.com FREE
* @author Rodolfo Melogli
* @compatible WooCommerce 7
* @community https://businessbloomer.com/club/
*/
add_filter( 'woocommerce_structured_data_product', 'bbloomer_set_gtin_from_sku', 9999, 2 );
function bbloomer_set_gtin_from_sku( $markup, $product ) {
$markup['gtin8'] = str_replace( '-', '', $markup['sku'] );
return $markup;
}
FYI – The PHP Error Log is telling me “PHP Warning: Undefined array key “sku” in …../wp-content/themes/flatsome-child/functions.php on line 424″
I’ll comment this out, but if you have a fix I’d love to know it.
Thank you!
I guess the problem is here – in case SKU is not set this may throw a warning:
You could try this alternative: