WooCommerce: Fix Google Search Console “No global identifier provided” Error

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!

Google Search Central documentation screenshot, where they show an example of product structured data, which includes the GTIN value.

PHP Snippet: Programmatically Set Product GTIN Based on SKU

/**
 * @snippet       Set WooCommerce Product GTIN
 * @how-to        businessbloomer.com/woocommerce-customization
 * @author        Rodolfo Melogli, Business Bloomer
 * @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;
}

Where to add custom code?

You should place custom PHP in functions.php and custom CSS in style.css of your child theme: where to place WooCommerce customization?

This code still works, unless you report otherwise. To exclude conflicts, temporarily switch to the Storefront theme, disable all plugins except WooCommerce, and test the snippet again: WooCommerce troubleshooting 101

Related content

Rodolfo Melogli

Business Bloomer Founder

Author, WooCommerce expert and WordCamp speaker, Rodolfo has worked as an independent WooCommerce freelancer since 2011. His goal is to help entrepreneurs and developers overcome their WooCommerce nightmares. Rodolfo loves travelling, chasing tennis & soccer balls and, of course, wood fired oven pizza. Follow @rmelogli

2 thoughts on “WooCommerce: Fix Google Search Console “No global identifier provided” Error

  1. 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!

    1. I guess the problem is here – in case SKU is not set this may throw a warning:

      $markup['gtin8'] = str_replace( '-', '', $markup['sku'] );

      You could try this alternative:

      $markup['gtin8'] = isset( $markup['sku'] ) ? str_replace( '-', '', $markup['sku'] ) : '';
Questions? Feedback? Customization? Leave your comment now!
_____

If you are writing code, please wrap it like so: [php]code_here[/php]. Failure to complying with this, as well as going off topic or not using the English language will result in comment disapproval. You should expect a reply in about 2 weeks - this is a popular blog but I need to get paid work done first. Please consider joining the Business Bloomer Club to get quick WooCommerce support. Thank you!

Your email address will not be published. Required fields are marked *