Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get attribute name instead of slug in variation?

I need to get attribute from woocommerce product variation.

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

This code is giving me an attribute slug instead of name. How can I get attribute name?

Thank you so much in advance!

like image 465
Pupik Avatar asked Feb 01 '16 12:02

Pupik


1 Answers

What you are getting is the slug of a taxonomy... In WooCommerce, attribute_pa_color without the attribute_ is a taxonomy.

So you can try something like this.. to get the term by slug. And get it's name.

$taxonomy = 'pa_color';
$meta = get_post_meta($value['variation_id'], 'attribute_'.$taxonomy, true);
$term = get_term_by('slug', $meta, $taxonomy);
echo $term->name;
like image 118
Reigel Avatar answered Oct 23 '22 02:10

Reigel