How can I create a page visible only for tagged customers?

Hi there! Is it anyhow possible to create a (text) page that would be visible only for tagged customers?

I only found this code:

{% if customer.tags contains ‘vip’ %}

{% section ‘collection’ %}
{% else %}

{{ pages.no-access.content }}

{% endif %}

But how about making a specific page visible when customers are having a specific tag?

Thank you so much for the help and tips in advance already!

It depends on your theme really, but you’re going to be looking in page.liquid in your templates folder. When you open it up, you may see something like this:

{% section 'page-template' %}

In this case you’ll be looking to open page-template.liquid in your sections folder. In either case, you’ll be looking for page.content:


  {{ page.content }}

It’ll look something like that. You can put a condition around that guy and use the handle of your page. Let’s say you wanted to hide the contents of the about us page to all but any customer tagged ‘vip’. You could do so like:

{% assign vip = false %}
{% if customer.tags contains 'vip' %}
  {% assign vip = true %}
{% endif %}

{% if page.handle == 'about-us' %}
  {% if vip %}
  
    {{ page.content }}
  

  {% else %}
    Sorry you must be a VIP to access this content
  {% endif %}
{% else %}

  {{ page.content }}

{% endif %}

Hello @Ninthony

I have tried this and I can see the “Sorry…” text on my page but the other content on the page is still showing. Any ideas why?

Thanks,

Renée

Is it because you have two sets of customer tags, ‘vip’ and ‘non-vip’?

With the above code, if you have any other customer tag that includes the letters ‘vip’ in the tag, the ‘contains’ operator will fire as true. You can get around this by replacing ‘contains’ with ‘==’.

Otherwise, it could be because it’s a page that is not ‘…pages/about-us/’ - as the VIP check code is only called for that page, though I don’t know why you’d be seeing the ‘Sorry’ message as well.

That said, @Ninthony pretty much nailed it.

Try;


{% if customer.tags contains "VIP" %}              
   {%   include 'vip-content'  %}
{% else %}
   
        

Sorry. You must be a VIP to access this content.

   

{% endif %}

 

{% for tag in customer.tags %}
    {% if tag == page.handle %}
       {% include 'vip.content' %}
    {% else %}
        
          

Sorry. You must be a VIP to access this content.

        

    {% endif %}
{% endfor %}

Note - these are two separate use cases. You’d only use the section for a single page, or the section for multiple pages, you wouldn’t use both code sections.

Hope this helps!

This only works if you build your page content manually. If you use a template and add sections, - whatever is added through theme editor will be visible.

Actually, here’s great guide and it doesn’t matter how you build the page: https://www.envision.io/blogs/ecommerce-pulse/80312001-how-to-add-a-wholesale-area-to-your-shopify-store-without-an-app

@LMNTDCO this guide was before sections everywhere was a thing and Shopify started using JSON templates for their template files.