DinhCode
DinhCode

Reputation: 120

Get product attributes label name by its slug in WooCommerce

I have create product_attributes as: Color have slug color / Size has slug size

In Product: how to show color Name/Label by slug.

i try wc_get_product_terms but it's attributes value of color / size not var_dup(color / size) infomation.

Upvotes: 2

Views: 2836

Answers (1)

LoicTheAztec
LoicTheAztec

Reputation: 253784

You can get product_attributes label name by its slug in using wc_attribute_label() like:

$attr_slug       = 'color';
$attr_taxonomy   = 'pa_' . $attr_slug; 

echo wc_attribute_label( $attr_taxonomy );

and

$attr_slug       = 'size';
$attr_taxonomy   = 'pa_' . $attr_slug; 

echo wc_attribute_label( $attr_taxonomy );

Upvotes: 4

Related Questions