首页 > 解决方案 > 如何根据产品 ID 为 Woocommerce 产品属性定义一个类?

问题描述

我有一个脚本需要基于产品 ID 的动态值。

<script type='text/javascript'>
  var ccs_cc_args = ccs_cc_args || []       
  ccs_cc_args.push(['cpn', 'CPN']);         ///Dynamically replace the CPN text
  ccs_cc_args.push(['mf', 'MFR_NAME']);     //Dynamically replace the MFR_NAME text
  ccs_cc_args.push(['pn', 'MPN']);          //Dynamically replace the MPN text
      ccs_cc_args.push(['market', 'PH']);
     
      (function () {
         var o = ccs_cc_args; o.push(['_SKey', '6ad5831c']); o.push(['_ZoneId', 'hp-auto-pp']);
         var sc = document.createElement('script'); sc.type = 'text/javascript'; sc.async = true;
         sc.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + 'cdn.cnetcontent.com/jsc/h.js';
         var n = document.getElementsByTagName('script')[0]; n.parentNode.insertBefore(sc, n);
      })();
</script>

我找到了一个解决方案,其中将值替换为 PHP 文件中定义的类,例如 this,并将脚本中的值替换为定义的 class.text

<div class="productboxArticlenumber">MLH82N/A</div>

但我无法弄清楚 woocommerce 产品属性术语是什么类,因为它们以这样的表格格式返回,以及如何使其引用产品 ID。

        <tr class="woocommerce-product-attributes-item woocommerce-product-attributes-item--attribute_pa_brand">
        <th class="woocommerce-product-attributes-item__label">Brand</th>
        <td class="woocommerce-product-attributes-item__value"><p>Huawei</p>

标签: javascriptphpwoocommerce

解决方案


推荐阅读