{% if page.handle == ‘wholesale-price-list’ %}
{% if vip %}
{{ page.content }}
{% else %}
Sorry you must be logged into your Trade Account to view this page.
{% else %}
{% endif %}
{{ page.content }}
{% endif %}
Unfortunately the page content is still showing - I need either the page content to show, or the “Sorry…” message, depending on whether the customer has a VIP tag or not.
I added this code but when I go to that page and I’m not logged in to a customer account with the VIP tag, I can still see the page content. Here is a screenshot of what I see when I’m not logged in and go to the page. The “Coming soon” text and box shouldn’t be visible unless I’m logged in as a customer with the VIP tag.
I am getting into some problems right now with this code, For my theme the main content is in theme.liquid and the content such as sections added are still visible even after adding the above code to the main.page.liquid.
So I added the code to my theme,liquid file and changed the main-content code to (placement of code will depend on your theme. I am using Ella Theme)
{% if customerTags contains ‘TEST’ or customerTags contains ‘TEST1’ %}
{% assign vip = true %}
{% endif %}
{% if page.handle == “wholsale-page-main” %}
{% if vip %}
{{ content_for_layout }}
{% else %}
Sorry you must be a Wholesale Member to access this page.
{% endif %}
{% else %}
{{ content_for_layout }}
{% endif %}
I decided to pursue a different route, as this code didn’t work for me. Instead I used a password protected page, and used the name of the page to identify it.
I called the code: Wholesale Price List, and here is the code, pasted on the third line of theme.liquid:
I see the issue with your code - there’s a syntax error in your conditional logic that’s causing the page content to always show. Here’s the corrected version:
Fixed Code:
{% assign vip = false %}
{% if customer and customer.tags contains 'vip' %}
{% assign vip = true %}
{% endif %}
{% if page.handle == 'wholesale-price-list' %}
{% if vip %}
<div class="rte">
{{ page.content }}
</div>
{% else %}
<div class="access-denied">
<h2>Access Restricted</h2>
<p>Sorry, you must be logged into your Trade Account to view this page.</p>
<a href="/account/login" class="button">Login Here</a>
</div>
{% endif %}
{% else %}
<div class="page-content">
{{ page.content }}
</div>
{% endif %}
Key fixes:
Added customer and check to prevent errors when no one is logged in
Fixed the {% else %} placement - you had an extra one that was breaking the logic
Added a login link for better UX
Alternative Simple Version:
{% if page.handle == 'wholesale-price-list' %}
{% if customer and customer.tags contains 'vip' %}
{{ page.content }}
{% else %}
<p>Please log into your Trade Account to access wholesale pricing.</p>
{% endif %}
{% else %}
{{ page.content }}
{% endif %}
App Alternative: I actually developed Latch specifically for this type of VIP page protection - it handles all the logic automatically and can even upsell VIP memberships to non-qualified visitors. Check it out: https://apps.shopify.com/member-lock
The corrected code above should fix your wholesale page access issue right away!