【问题标题】:WooCommerce: How to add Schema Item Condition Markup to Products?WooCommerce:如何向产品添加模式项目条件标记?
【发布时间】:2022-02-04 03:15:15
【问题描述】:

Google 购物报告错误,因为没有与我的商品相关的商品状况。如何将商品条件架构添加到我的产品架构 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 中。

【问题讨论】:

    标签: woocommerce schema


    【解决方案1】:

    据此: https://support.google.com/merchants/answer/7353427?hl=en 修改$markup_offer中:

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

    并添加

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

    【讨论】:

      【解决方案2】:

      将此代码添加到主题的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;
      }
      

      【讨论】:

        【解决方案3】:

        要动态应用命令,您必须通过 WooCommerce 中定义的类

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

        $markup['your_item']       ='your_value';
        

        例如

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

        阿米尔·塔赫卡尼

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2019-08-10
          • 1970-01-01
          • 2018-12-10
          • 2016-09-13
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2022-08-19
          相关资源
          最近更新 更多