我需要从woocommerce产品变异获得属性。
$terms = get_post_meta($value['variation_id'], 'attribute_pa_color', true);
这段代码给了我一个属性slug而不是name。我怎样才能获得属性名称?
非常感谢你提前!
我需要从woocommerce产品变异获得属性。
$terms = get_post_meta($value['variation_id'], 'attribute_pa_color', true);
这段代码给了我一个属性slug而不是name。我怎样才能获得属性名称?
非常感谢你提前!
你得到的是分类法的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;
你得到的是分类法的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;
您可以尝试以下代码。
$terms = get_the_terms( $value['variation_id'] , 'attribute_pa_color');
foreach ( $terms as $term ) {
echo $term->name;
}
如果有帮助,请告诉我。另外你可以通过给出的解释 这个 链接了解更多信息和替代解决方案。