上一期通过修改源码的方式解决了Missing field "aggregateRating"和Missing field "review"两项,后来在谷歌后台检测网站时又发现Missing field "hasMerchantReturnPolicy" (in "offers")和Missing field "shippingDetails" (in "offers"),总是修改源码不是好的办法,今天把woocommerce网站翻了个遍,终于找到了可以修改Structured Data的hooks了。
1、修改系统现有的Structured Data
1 2 3 4 5 6
add_filter( 'woocommerce_structured_data_product', function( $schema, $product ) { $schema['name'] = 'Your new products name here'; $schema['description'] = 'Your new products description here'; $schema['image'] = 'Link to your new product image here'; return $schema; }, $priority = 20, $accepted_args = 2 );