Case; I need to restrict access to 2 collections which are for professionals only. if a visitor to the store clicks on the the collection they are redirected to a professional only page, with message. if one uses the collection url directly in the browser this redirect message appears. however if a visitor visits the home page and clicks on the collection it is still accessible. I have added code in so many places, but cannot seem to find the correct link. here is the code which i have placed in theme.liquid. I suspect the solution is a simple one. but i need your advice please.
{% comment %} Protect restricted collections {% endcomment %}
{% if request.path contains ‘/collections/professional-podiatry-products’ or request.path contains ‘/collections/podiatry-consumables’ %}
{% if customer %}
{% unless customer.tags contains ‘password-page’ or customer.tags contains ‘pro’ %}
When a visitor clicks an internal link, Shopify swaps in the new page without re-running theme.liquid; typing the URL or refreshing reloads the whole theme.
Because these two paths behave differently, place your access-control code inside the collection template so it always executes.