Can't display badge based on tags

on card-product file I added this code:

{% if product.tags contains "BEST SELLER" %}
<span class="badge_best_seller"> Best Seller </span>
{% endif %}

but it doesn’t seem to be displayed on items that have this tag.

what I’m I doing wrong?

When I remove the “if statement”, it is displayed (on all products), I guess I mean this code is good and in the right location, but something is wrong with the if statement.

https://k09uz89b12603nhi-52839809193.shopifypreview.com

Try a stricter comparison loop instead to account for potential misspellings or other ambiguity

{%-  assign badge_tag = "BEST SELLER" %}
{% liquid
  assign normalized_badge_tag = badge_tag  | downcase | strip

  assign show_badge = false
  for tag in product.tags
    assign downcased_tag = tag | downcase
    if downcased_tag == normalized_badge_tag
      assign show_badge = true
      break
    endif
  endfor
%}
{% if show_badge  %}
  {% comment %} ... insert content here {% endcomment %}
{% endif %}

This also assumes the code is in the context of a product, either on the product page, or in a product loop in collection template etc.

edit: fixed syntax error equal sign instead of double equals for comparison.

I tried your code but it didnt work :disappointed_face:

I want the badge to be displayed based on products with the tag Best seller

Thank you!

Retry the code it had a syntax error and be sure it’s in context that has access to the product

Could you help me with that?

This is what I tried but it doesn’t seem to to anything