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!
Thanks for the code, I was able to resolve our Rich Results Products warnings from Google Search Console.
Note – there’s a few ;. instances in the code example, were we had to remove the (.) from the PHP code.
Thank you very much!
I’m glad it was useful, I made the corrections for “dots”, wordpress probably got more stupid and changed something in the “code” text!
It worked on my website, It used woocommerce on my pet website.
I am getting same 4 errors, you shown in tutorial.
Thanks once again. Cheers!!!!
I’m glad you found it useful … Have a good life !
Oh God. it’s working :)))
thanke you for code… be happy
Did you made any changes to the code??
Did you made any changes to the code??
Hi, no change until now !
Really helped me to solve the issue
I’m grateful for you, this code solved the problem.
thank you so much