Why aren't collection tags functioning correctly?

Topic summary

A user is experiencing an issue with conditional code that controls the visibility of a BUY button based on product tags and location. The code works correctly on individual product pages but fails to function on collection pages. The code snippet appears to check if the current product has a “HideProduct” tag and if the localization country code equals “US”. The user is seeking help to understand why the same code behaves differently across these two page types and how to fix it for collection pages.

Summarized with AI on November 18. AI used: claude-sonnet-4-5-20250929.

I have this code, it is a condition to show and not show the BUY button. On the product page it works perfectly but it does NOT work in the collection, what’s wrong with it, how can it work well?

Thank you.

class="{% if current_tags contains "HideProduct" and localization.country.iso_code == 'US' %} hideButton {% endif %}