Reputation: 76
I am replicating the colorpicker filter in woocommerce:
I have been searching but I am not finding the color value in HTML or in RGB. This is the attribute objetct:
WP_Term Object ( [term_id] => 242 [name] => Amarillo [slug] => amarillo [term_group] => 0 [term_taxonomy_id] => 242 [taxonomy] => pa_rasan-monocolor [description] => [parent] => 0 [count] => 1 [filter] => raw [meta_value] => 0 )
Where can this field be?
with the
get_term_meta($attribute_value->term_id))
Tt is showing all colors:
array(3) { ["order_pa_rasan-monocolor"]=> array(1) { [0]=> string(1) "0" } ["pa_monocolor_yith_wccl_value"]=> array(1) { [0]=> string(7) "#d4be16" }
How can I relate one attribute with its color?
Upvotes: 2
Views: 5767
Reputation: 436
Well, the comments helped me, but here is some code more detailed on how to get the color code of the variations :
$terms = get_terms([
'taxonomy' => 'pa_nameofthevariation',
'hide_empty' => false,
]);
foreach ($terms as $term) {
echo get_term_meta($term->term_id)["color"][0]; // Ex: #d4be16
}
Upvotes: 4