我已将产品属性创建为:Color
有 slug color
/Size
有 slug size
在产品中:如何通过 slug 显示颜色
名称/标签。
我尝试了 wc_get_product_terms,但它是 color/size
的属性值,而不是 var_dup(color/size)
信息。
最佳答案
您可以使用wc_attribute_label()
通过其slug获取product_attributes标签名称,如下所示:
$attr_slug = 'color';
$attr_taxonomy = 'pa_' . $attr_slug;
echo wc_attribute_label( $attr_taxonomy );
和
$attr_slug = 'size';
$attr_taxonomy = 'pa_' . $attr_slug;
echo wc_attribute_label( $attr_taxonomy );
关于php - 在 WooCommerce 中通过其别名获取产品属性标签名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63504790/