R
R
Roman Govorov2019-08-15 14:24:55
WooCommerce
Roman Govorov, 2019-08-15 14:24:55

How to display LABEL attribute in Woocommerce?

There is a solution for displaying product attribute values:

$attributes = $product->get_attributes();

$content = '<ul class="custom-attributes">';

foreach ( $attributes as $attribute ) {

    if ($attribute['is_taxonomy']) {
        $values = wc_get_product_terms($product->id, $attribute['name'], array('fields' => 'names'));
        $content .= '<li><span class="attribute-label-text">___label___</span> : ';
        $content .= apply_filters('woocommerce_attribute', implode(', ', $values), $attribute, $values);
        $content .= '</li>';
    }

}

$content .= '</ul>';

echo $content;

But I can’t display the label in any way. Tell me how to solve the problem?
There is a similar question on the toaster, but there the answer is not correct either.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman Govorov, 2019-08-15
@RGameShow

$attributes = $product->get_attributes();

$content = '<ul class="custom-attributes">';

foreach ( $attributes as $attribute ) {

    if ($attribute['is_taxonomy']) {
        $values = wc_get_product_terms($product->id, $attribute['name'], array('fields' => 'names'));
        $content .= '<li><span class="attribute-label-text">'.wc_attribute_label( $attribute['name'] ).'</span> : ';
        $content .= apply_filters('woocommerce_attribute', implode(', ', $values), $attribute, $values);
        $content .= '</li>';
    }

}

$content .= '</ul>';

echo $content;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question