获取属性变体Woocommerce中的颜色代码

时间:2018-11-28 09:11:42

标签: php wordpress woocommerce

我在woocommerce中复制了colorpicker过滤器: enter image description here

我一直在搜索,但是找不到HTML或RGB中的颜色值。这是属性objetct:

WP_Term对象([term_id] => 242 [name] =>阿马里洛[slug] =>阿马里洛[term_group] => 0 [term_taxonomy_id] => 242 [taxonomy] => pa_rasan-monocolor [description] => [父] => 0 [计数] => 1 [过滤器] =>原始[meta_value] => 0)

该字段在哪里?

enter image description here

get_term_meta($attribute_value->term_id))

Tt显示所有颜色:

array(3) { ["order_pa_rasan-monocolor"]=> array(1) { [0]=> string(1) "0" } ["pa_monocolor_yith_wccl_value"]=> array(1) { [0]=> string(7) "#d4be16" } 

如何将一个属性与其颜色相关联?

1 个答案:

答案 0 :(得分:0)

好吧,这些评论对我有所帮助,但是下面的代码更详细地介绍了如何获取版本的颜色代码:

$terms = get_terms([
    'taxonomy' => 'pa_nameofthevariation',
    'hide_empty' => false,
]);
foreach ($terms as $term) {
    echo get_term_meta($term->term_id)["color"][0]; // Ex: #d4be16
}