Get values ​​for a specific attribute from a product identifier

I am trying to get a custom product attribute with option values. This is how I get the normal attribute:

$myproducts['data']['discount'] = $product->get_attribute('pa_discount');

Does anyone know how I get my Size attribute with parameters S, M and L?

thank

+4
source share
1 answer

In your comment, you use an almost correct path, but to get your values, you do not need the php function, since you will only get the first specified value for this attribute. array_shift()

Instead, you can use the foreach loop to get each value:

foreach( wc_get_product_terms( $product->id, 'pa_size' ) as $attribute_value ){
    // Outputting the attibute values one by one
    echo $attribute_value . '<br>';
}

imode() php , , :

echo implode(', ', wc_get_product_terms( $product_id, 'pa_size' )); 

...

+2

Source: https://habr.com/ru/post/1669822/


All Articles