Search code examples
phpwordpresswoocommerceattributescustom-taxonomy

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.


Solution

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