2
votes

I am replicating the colorpicker filter in woocommerce: enter image description here

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?

enter image description here

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?

1
check to see if it is in the terms meta - var_dump(get_term_meta($yourObject->term_id)); - OR var_dump(get_term_meta( get_queried_object_id())); - Stender
or does the meta value change, if you don't select the first color? - Stender
Okey, with the get_term_meta($attribute_value->term_id)) it 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? Any idea? Thanks - Diego Montagud
Add that to the question - Now you just need to figure out, how to see which one is selected - Stender
Okey, for each value I receipt this ` array(3) { ["order_pa_rasan-monocolor"]=> array(1) { [0]=> string(1) "0" } ["pa_monocolor_yith_wccl_value"]=> array(1) { [0]=> string(7) "#d4be16" } ["pa_rasan-monocolor_yith_wccl_value"]=> array(1) { [0]=> string(7) "#eeee22" } } ` . Is the second one (pa_rasan-monocolor_yith_wccl_value). I don't know what is the pa_monocolor_yith_wccl_value color value but, okey. I think is solved - Diego Montagud

1 Answers

3
votes

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
}