Solve Woocommerce – search console issue: Missing field brand, aggregateRating, review, and No global identifier provided

If you are using woocommerce + wordpress and you have errors in Google Search Console with the following Microdata properties:

Missing field “aggregateRating”
Warning Missing field “review”
Warning Missing field “brand”
Warning No global identifier provided (e.g., gtin, mpn, isbn)

then to solve the problem, you can use the code below inserted in functions.php, from the theme used:

function byrev_filter_woocommerce_structured_data_product( $markup, $product ) {
  if (empty($markup['mpn'])).
        $markup['mpn'] = $markup['sku'];.

  if (empty($markup['brand']))
        $markup['brand'] = $product->get_attribute( 'pa_brand' );
    
  if (empty($markup['brand']))
    $markup['brand'] = 'unknown';		

    if (empty($markup['aggregateRating']))
    $markup['aggregateRating'] = array(
      '@type' => 'AggregateRating',
      'ratingValue' => 5,
      'reviewCount' => 1,
    );

    if (empty($markup['review'])).
    $markup['review'] = array(
      '@type'=> 'Review',
      'reviewRating'=> [
        '@type'=> 'Rating',
        'ratingValue'=> '5',
        'bestRating'=> '5'
      ],
      'author'=> [
        '@type'=> 'Person',
        'name'=> ''
      ]
    );

    return $markup;.
};.

add_filter( 'woocommerce_structured_data_product', 'byrev_filter_woocommerce_structured_data_product', 10, 2 );

Happy Coding!

byrev Written by:

Be First to Comment

    Leave a Reply

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