• I have really stuggled with this and i cant seem to find a good answer. Im trying to echo the products attrubute lables inside a class in a woocommerce loop. To echo just the attribute slug would have been even better. I have tried:

    class="<?php echo wc_attribute_label( $name ); ?>"

    but it dosent work. What am I doing wrong?

    Thansk for any help possible!

    Kind regards, Richard

    https://www.ads-software.com/plugins/woocommerce/

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hello there,

    Could you please try the following?

    global $product;
    $attribute = $product->get_attributes();
    
    $attribute_arr = array();
    
    if( count($attribute) > 0 ){
    	foreach ($attribute as $key => $value) {
    		$attribute_arr[] = $key;
    	}
    }
    
    $attributes = implode($attribute_arr, ' ');
    
    /* Print as class value */
    class="<?php echo esc_attr($attributes); ?>";

    Let me know how it goes.

    Regards

    Thread Starter Skaerby

    (@skaerby)

    Thanks a lot Kharis!! It works absolutley perfect! ??

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to echo a attribute label in woocommerce?’ is closed to new replies.