我需要从 woocommerce 产品变体中获取属性。
$terms = get_post_meta($value['variation_id'], 'attribute_pa_color', true);
此代码为我提供了一个属性 slug 而不是名称。如何获取属性名称?
提前致谢!
最佳答案
你得到的是分类法的 slug...
在 WooCommerce 中,没有 attribute_
的 attribute_pa_color
是一种分类法。
所以你可以尝试这样的事情..通过 slug 获取术语。并得到它的名字。
$taxonomy = 'pa_color';
$meta = get_post_meta($value['variation_id'], 'attribute_'.$taxonomy, true);
$term = get_term_by('slug', $meta, $taxonomy);
echo $term->name;
关于php - 如何获取属性名称而不是变体中的 slug?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35130013/