首页 > 解决方案 > 通过 WooCommerce 中的 slug 获取产品属性标签名称

问题描述

我已将 product_attributes 创建为:Colorhave slug color/ Sizehas slugsize

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

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

标签: phpwordpresswoocommerceattributescustom-taxonomy

解决方案


您可以通过它的 slug 获取 product_attributes 标签名称,wc_attribute_label()如下所示:

$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 );

推荐阅读