How to get the name attribute from the common item in the shopping cart?

Get the 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 'Color:' . $terms ->name;
 } 
}

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

I need to get the name of the attribute in the loop
April 4th 20 at 00:40
1 answer
April 4th 20 at 00:42
Solution
9514a4aa05.jpg
slug to replace the 'name' ? - Prince_Larson commented on April 4th 20 at 00:45
That is, even so, do not bother? if the error text to compare?

Tip. - What is in the black box $attributes_item? - shyanne.Grimes commented on April 4th 20 at 00:48
@laurie.Bartell, if so, it is empty:

$terms = get_term_by('slug', $attributes_item['name'], $attributes_key);
- Prince_Larson commented on April 4th 20 at 00:51
That is, you are not seeing what is there?
**********************************
35151823d5.jpg - shyanne.Grimes commented on April 4th 20 at 00:54
@laurie.Bartell, of $attributes_item stored this:

WC_Product_Attribute Object ( [data:protected] => Array ( [id] => 1 [name] => pa_brendy [options] => Array ( [0] => 30 ) [position] => 0 [visible] => [variation] => ) ) WC_Product_Attribute Object ( [data:protected] => Array ( [id] => 2 [name] => pa_tsveta [options] => Array ( [0] => 32 ) [position] => 1 [visible] => [variation] => ) )
- Prince_Larson commented on April 4th 20 at 00:57
All right. That came to the most important, where to store the object taxonomy, and we have to work with him as with an object taxonomy.

Approximately
if ( ! empty( $attributes_items ) ) :

 foreach ( $attributes_items as $attributes_item ) {

 if ( $attributes_item->get_variation() || $attributes_item->get_name() !== 'pa_tsveta' || ! $attributes_item->is_taxonomy() ) {
continue;
}

 $terms = wp_get_post_terms( $cart_item->get_id(), $attributes_item->get_name(), 'all' );

 $atts = [];
 foreach ( $terms as $term ) {
 $single_term = esc_html( $term->name );
 array_push( $atts, $single_term );
}
 printf( 'Color: %s', implode( ',', $atts ) );

}
 endif;
- shyanne.Grimes commented on April 4th 20 at 01:00
@laurie.Bartell, thank you, and wp_get_post_terms is a copy get_term_by or equivalent get_the_terms ? - Prince_Larson commented on April 4th 20 at 01:03
the analogue of the second - shyanne.Grimes commented on April 4th 20 at 01:06
@laurie.Bartell, got it, thanks - Prince_Larson commented on April 4th 20 at 01:09

Find more questions by tags WordPressWooCommerce