Woocommerce – if selected attribute term equals

I have created an attribute “color” with two terms “black” and “white” and i want to show something when selected term equals to white.

I’ve tried the following code (based on https://stackoverflow.com/a/23622917/10183871) but it seems that it just checks if there is available term “white” and if there is then shows something. I want to show something only when the term “white” is selected

$terms = get_the_terms( $product->id, ‘pa_color’);
foreach($terms as $term){
if($term->name == ‘white’){
echo ‘something’;
}
}

Thanks in advance.

Read more here:: Woocommerce – if selected attribute term equals

Leave a Reply

Your email address will not be published. Required fields are marked *