Pup*_*pik 15 php variables attributes slug woocommerce
我需要从woocommerce产品变异获得属性.
$terms = get_post_meta($value['variation_id'], 'attribute_pa_color', true);
Run Code Online (Sandbox Code Playgroud)
这段代码给了我一个属性slug而不是name.我怎样才能获得属性名称?
非常感谢你提前!
Rei*_*gel 22
你得到的是分类学的slu ... ......在WooCommerce中,attribute_pa_color
没有attribute_
分类法.
所以你可以尝试这样的东西..通过slug来获得这个术语.得到它的名字.
$taxonomy = 'pa_color';
$meta = get_post_meta($value['variation_id'], 'attribute_'.$taxonomy, true);
$term = get_term_by('slug', $meta, $taxonomy);
echo $term->name;
Run Code Online (Sandbox Code Playgroud)