Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Woocommerce 如何加上「;品牌;元素到模式标记(微数据)_Woocommerce_Google Search - Fatal编程技术网

Woocommerce 如何加上「;品牌;元素到模式标记(微数据)

Woocommerce 如何加上「;品牌;元素到模式标记(微数据),woocommerce,google-search,Woocommerce,Google Search,是否有可能在WooCommerce产品模式中添加有关产品品牌的信息 我尝试使用产品模式插件,但它们不符合我的需要,并破坏现有模式或在产品代码中添加第二个模式,因此最好的解决方案是手动修改它。我尝试使用此代码段,但它没有创建正确的标记结构: add_filter( 'woocommerce_structured_data_product_offer', 'nt_woocommerce_structured_data_product_offer', 10, 2 ); function nt_woo

是否有可能在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"
  }
但它创建了这样一个标记,而谷歌并未对此进行验证:

"brand":"ACME"

关于如何使用php代码段创建正确的标记,您有什么想法吗?

您需要使用不同的过滤器woocommerce\u structured\u data\u 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;
}