*Help* - Restricting access to logged in users for specific pages

zoeevans
Tourist
8 0 3

Hi,

I have 3 pages that I want to restrict access to, so that only customers who are logged in can access. I've found the guide here to restrict access to the whole site https://help.shopify.com/themes/customization/access/create-members-only-store and I'm trying to amend so that customers are only prompted to login if they try to access these 3 pages and they are not already logged in.

I'm using the below code but it is still asking for a login for all pages, where have I gone wrong?

Pasted under <head> tag:

{% unless customer %}

    {% if template contains 'customers' %}

        {% assign send_to_login = false %}

    {% else if page.handle = ‘budget-planner’ or page.handle = ‘planning-checklist’ or page.handle = ‘guest-list' %}

        {% assign send_to_login = true %}

    {% endif %}

{% endunless %}

{% if send_to_login %}

<meta content="0; url=/account/login?checkout_url={{ shop.url }}" http-equiv="refresh" />

{% else %}

... Other theme.liquid contents here ...

Pasted below </body> tag:

{% endif %}

0 Likes
petuniaa
Tourist
22 0 2
michael-helium
Shopify Expert
177 1 107

In addition to locking customers out, you'll also have to think about how to prevent someone from creating an account on your store because anyone who completes your registration form immediately gains access to their account and is logged in, even if they use a fake email. That means locking content for "logged-in users only" is meaningless unless you're also able to restrict who can create an account on your storefront.

One way is to implement customer tags and use Liquid to display member-only content to customers with the appropriate tag (Locksmith offers a nifty way to handle this without coding knowledge).

The Customer Fields app will also come in handy here. You can toggle account creation settings on your registration form(s) such as:

  • Require customers to validate their email address before gaining access to customer account
  • Require admin approval before customer account is created

If you need to manually approve new customers (common for many B2B/wholesalers) you will probably also need to collect additional information from them. Customer Fields allows you to easily add new fields to your registration form, or create a new form that you can install on any page.

Finally, you can enable "auto tag" settings to automatically tag customers after account approval, or once other conditions have been met, which will help you display certain members-only content to specific users.

Michael | Business Development @ Helium
Helium builds apps that merchants depend on:
- Customer Fields
- Meteor Mega Menu
0 Likes