G
G
Genri_Rus2020-01-03 18:56:47
WordPress
Genri_Rus, 2020-01-03 18:56:47

How to get the attribute name of a simple product in the cart?

I get attributes like this:

$attributes  = $cart_item['data'];
$attributes_items = $attributes->get_attributes();
foreach ( $attributes_items as $attributes_key => $attributes_item ) {
  if ( $attributes_item['name'] == 'pa_tsveta' ) {
  
  $terms = get_term_by( 'slug', $attributes_item, $attributes_key );
                      
  echo 'Цвет: ' . $terms ->name;
  }						
}

But I get an error:
Object of class WC_Product_Attribute could not be converted to string

I need to somehow get the attribute name in the loop itself

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
WP Panda, 2020-01-03
@Genri_Rus

9514a4aa05.jpg

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question