是否有可能在WooCommerce产品模式中添加有关产品品牌的信息?
我曾尝试使用产品架构插件,但它们不符合我的需求,破坏了现有的架构或在产品代码中添加了第二个,因此最好的解决方案是手动修改它。我尝试使用此代码段,但它没有创建正确的标记结构:
add_filter( 'woocommerce_structured_data_product_offer', 'nt_woocommerce_structured_data_product_offer', 10, 2 );
function nt_woocommerce_structured_data_product_offer( $markup, $product ) {
$markup[ 'brand' ] = wc_get_product()->get_attribute('pa_brand');
return $markup;
}
我需要此代码段来创建类似这样的内容:
"brand": {
"@type": "Thing",
"name": "ACME"
}
但是它创建了这样的标记,未经Google验证:
"brand":"ACME"
您对如何使用php代码段创建正确的标记有任何想法吗?
您需要使用其他过滤器woocommerce_structured_data_product并使用数组设置品牌。
add_filter( 'woocommerce_structured_data_product', 'nt_woocommerce_structured_data_product_offer', 10, 2 );
function nt_woocommerce_structured_data_product_offer( $markup, $product ) {
$markup[ 'brand' ] = array(
'@type' => 'Thing',
'name' => wc_get_product()->get_attribute('pa_brand'),
);
return $markup;
}