How to get attribute name instead of slug in variation?

I need to get an attribute from a product change in woocommerce.

$terms = get_post_meta($value['variation_id'], 'attribute_pa_color', true); 

This code gives me the slug attribute instead of the name. How to get attribute name?

Thank you so much in advance!

+8
variables php attributes slug woocommerce
source share
2 answers

What you get is a slug of taxonomy ... In WooCommerce attribute_pa_color without attribute_ is a taxonomy.

So, you can try something like this .. to get this term in a way. And get his name.

 $taxonomy = 'pa_color'; $meta = get_post_meta($value['variation_id'], 'attribute_'.$taxonomy, true); $term = get_term_by('slug', $meta, $taxonomy); echo $term->name; 
+8
source share

You can try the following code.

 $terms = get_the_terms( $value['variation_id'] , 'attribute_pa_color'); foreach ( $terms as $term ) { echo $term->name; } 

Let me know if this helped. Additionally, you can get an explanation given in this link for more information and alternative solutions.

0
source share

All Articles