WooCommerce:如何向产品添加模式项条件标记?

WooCommerce:如何向产品添加模式项条件标记?,woocommerce,schema,Woocommerce,Schema,谷歌购物报告错误,因为没有与我的产品相关的商品条件。如何将项目条件模式添加到我的产品模式JSON中 我知道我可以打印这个HTML: <div itemprop="offers" itemscope itemtype="http://schema.org/Offer"> <meta itemprop="itemCondition" itemtype="http://schema.org/OfferItemCondition" content="http://schema.or

谷歌购物报告错误,因为没有与我的产品相关的商品条件。如何将项目条件模式添加到我的产品模式JSON中

我知道我可以打印这个HTML:

<div itemprop="offers" itemscope itemtype="http://schema.org/Offer">
  <meta itemprop="itemCondition" itemtype="http://schema.org/OfferItemCondition" content="http://schema.org/NewCondition" />
</div>

但我认为它应该位于Schema.org/Product中,在当前的WC版本中,它位于JSON中。

根据这一点: 在以下位置修改
$markup\u offer

wp-content\plugins\woocommerce\includes\class-wc-structured-data.php

'itemCondition' => 'http://schema.org/NewCondition',
据此: 在以下位置修改
$markup\u offer

wp-content\plugins\woocommerce\includes\class-wc-structured-data.php

'itemCondition' => 'http://schema.org/NewCondition',

若要动态应用命令,必须遍历WooCommerce中定义的类

当您使用WooCommerce插件建立在线商店时,内置的数据命令会自动执行。要更改这些命令,请转到为其定义的类。如果要动态生成的变量可能不存在,请为其设置条件。要设置新值,请按如下方式编写代码

$markup['your_item']       ='your_value';
比如说

if($product->get_attribute( 'pa_gtin-code' )){
   $markup['gtin13']       = $product->get_attribute( 'pa_gtin-code' );
}

若要动态应用命令,必须遍历WooCommerce中定义的类

当您使用WooCommerce插件建立在线商店时,内置的数据命令会自动执行。要更改这些命令,请转到为其定义的类。如果要动态生成的变量可能不存在,请为其设置条件。要设置新值,请按如下方式编写代码

$markup['your_item']       ='your_value';
比如说

if($product->get_attribute( 'pa_gtin-code' )){
   $markup['gtin13']       = $product->get_attribute( 'pa_gtin-code' );
}

将以下代码添加到主题的functions.php文件:

add_filter( 'woocommerce_structured_data_product_offer', 'my_woocommerce_structured_data_product_offer', 10, 2 );
function my_woocommerce_structured_data_product_offer( $markup, $product ) {    
    if ( empty( $markup[ 'itemCondition' ] ) ) {
        $markup[ 'itemCondition' ] = 'http://schema.org/NewCondition';
    }
    return $markup;
}
  • 损坏=>
  • 新=>
  • 翻新=>
  • 使用=>

将此代码添加到主题的functions.php文件中:

add_filter( 'woocommerce_structured_data_product_offer', 'my_woocommerce_structured_data_product_offer', 10, 2 );
function my_woocommerce_structured_data_product_offer( $markup, $product ) {    
    if ( empty( $markup[ 'itemCondition' ] ) ) {
        $markup[ 'itemCondition' ] = 'http://schema.org/NewCondition';
    }
    return $markup;
}
  • 损坏=>
  • 新=>
  • 翻新=>
  • 使用=>