【问题标题】:Get product attributes label name by its slug in WooCommerce通过 WooCommerce 中的 slug 获取产品属性标签名称
【发布时间】:2020-08-20 12:10:22
【问题描述】:

我已将 product_attributes 创建为:Color has slug color / Size has slug size

在产品中:如何通过 slug 显示 color 名称/标签。

我尝试使用 wc_get_product_terms,但它的属性值是 color / size 而不是 var_dup(color / size) 信息。

【问题讨论】:

    标签: php wordpress woocommerce attributes custom-taxonomy


    【解决方案1】:

    您可以使用wc_attribute_label() 获取product_attributes 标签名称,例如:

    $attribute_slug       = 'color';
    $attribute_taxonomy   = 'pa_' . $attr_slug; 
    
    echo wc_attribute_label( $attribute_taxonomy );
    

    $attribute_slug       = 'size';
    $attribute_taxonomy   = 'pa_' . $attr_slug; 
    
    echo wc_attribute_label( $attribute_taxonomy );
    

    【讨论】:

      猜你喜欢
      • 2019-04-04
      • 1970-01-01
      • 1970-01-01
      • 2018-10-09
      • 2018-01-31
      • 2020-11-02
      • 2016-12-26
      • 1970-01-01
      • 2016-09-27
      相关资源
      最近更新 更多