I’m working on something on wordpress + woocommerce.
I’ve inputed some ‘filter’ attributes value for some products.
So if the value of the attribute for this product includes a “Wood Grains” value, i want to echo an Woodgrains.jpg on the front end.
Therefore if the value = Texture, i want to echo Texture.jpg icon.
the code below is what i’ve mustered so far, but this only echoes out all the values tagged to a product, i can’t figure out what to change to get the ‘if’ statement in it.
$terms = get_the_terms( $product->id, 'pa_filter');
foreach ( $terms as $term ) {
echo $term->name;
}
here’s a screenshot of what the code above does on the front end:
http://edleuro.com/new/wp-content/themes/mystile/img/1.png
If this returns an array of terms for the said product:
You can check if the returned result array has what you are looking for by doing this:
Update
Based in your reply to my answer, I have came up with the following:
Create a helper function like this:
Then you use it like this:
i found a better way to resolve my problem. i had this in my content-product.php woocommerce template.
do take note that the term name is case sensitive.
foreach prints Warning: invalid argument supplied for foreach()â¦
This works for me “on a purely”: