我需要从woocommerce产品变体获得属性。
$terms = get_post_meta($value['variation_id'], 'attribute_pa_color', true);这段代码给了我一个属性slug而不是name。如何获取属性名称?
提前谢谢你!
发布于 2016-02-01 22:43:42
你得到的是一个分类的弹头...在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;发布于 2021-08-14 11:00:51
您可以通过以下代码轻松查找属性
foreach ($product->attributes as $taxonomy => $attribute) {
foreach ($attribute->get_terms() as $term) {
var_dump($term); // term object data
}
}发布于 2016-02-01 22:17:59
您可以尝试以下代码。
$terms = get_the_terms( $value['variation_id'] , 'attribute_pa_color');
foreach ( $terms as $term ) {
echo $term->name;
}如果有帮助的话请告诉我。此外,您还可以通过this链接中的说明了解更多信息和替代解决方案。
https://stackoverflow.com/questions/35130013
复制相似问题