Site access - Create a members-only store

Highlighted
Community Manager
Community Manager
314 12 292

Caution: This is an advanced tutorial and is not supported by Shopify. Knowledge of web design languages such as HTML, CSS, JavaScript, and Liquid is required. We suggest hiring a Shopify Expert if you are not comfortable proceeding with the following tutorial.


You can create a members-only store by showing a login or register page when customers navigate to your website. To make your store accessible only to registered customers, you need to edit your Customer accounts settings in the admin, and add some Liquid code to your theme.

 

Note: If you want only certain pages to be members-only, then you need to install an access management app from the Shopify App Store.

 

Enable customer accounts

 

  1. From your Shopify admin, go to Settings > Checkout.
  2. In the Customer accounts section, click Accounts are required:

    members-01.jpg

  3. Click Save.

Edit your theme.liquid file

 

  1. From your Shopify admin, go to Online Store > Themes.
  2. Find the theme you want to edit, and then click Actions > Edit code.
  3. In the Layout directory, click theme.liquid.
  4. Find the opening <head> tag in the code. On a new line below the opening <head> tag, paste the following code:

    {% unless customer %}
        {% if template contains 'customers' %}
            {% assign send_to_login = false %}
        {% else %}
            {% assign send_to_login = true %}
        {% endif %}
    {% endunless %}
    
    {% if send_to_login and request.path != "/challenge" %}
    <meta content="0; url=/account/login?checkout_url=/" http-equiv="refresh" />
    {% else %}

     

  5. Find the closing </body> tag in the code. On a new line below the closing </body> tag, paste the following code:

    {% endif %}

     

  6. Click Save.

Change the page that logged-in customers are redirected to (optional)

 

Customers that log in are automatically redirected to the home page of the shop. You can edit where customers are redirected by editing the meta refresh tag URL in the code you just pasted.

 

  1. Find the following <meta> tag in the file:

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

     

  2. Add the URL path you'd like to use just after checkout_url=/. For example, if you want your logged-in customers to go to your catalog page when they navigate to your site, add collections/all to the URL path. Your code should look like this:

    <meta content="0; url=/account/login?checkout_url=/collections/all" http-equiv="refresh" />

     

  3. Click Save.

TyW | Community Manager @ Shopify
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Click Accept as Solution 

0 Likes
Highlighted
New Member
1 0 0

What would be the code if I wanted to restrict a specific site page to only logged in users with a specific tag?

 

Thanks for your help!

0 Likes
Highlighted

This should help: https://help.shopify.com/en/themes/liquid/objects/customer#customer-tags

 

Here is an example:

{% for tag in customer.tags %}
  {% if tag contains 'newsletter' %}
     Show Heyyy! Your are customer with tag including word newsletter
  {% endif %}
{% endfor %}
0 Likes
Highlighted

I also suggest disabling the account registration page, so people can't just create their own account and browse your store. 

0 Likes
Highlighted
Tourist
4 0 0

Stuck on how to do this if you could help.

0 Likes

Where are you stuck?

0 Likes
Highlighted
Tourist
4 0 0

Stuck at disabling the create an account page. I have everything else working, but I need to remove that page so I can get customers to email to request an account.

0 Likes
Highlighted
Pathfinder
93 6 14

Just an Idea....

 

At the top of the page, add 

 

{% if customer %}

At the Bottom of that area, add

{% endif %}

This will make it only show to people who are already logged in.  Which ironically then won't show it because they are logged in so they do not need to create an account.

 

You can then make a section on the page, or a specific page with a Contact list about creating accounts.  You can even set it up to TAG the customer as a Lead when they email you.

 

Best Regards.

1 Like
Highlighted

Yes, the above method will work too.

The easiest solution for this is to go into your theme's code and copy the contents of the customers/login.liquid file and paste them/copy them over to the customers/register.liquid file. This will replace the registration page with a login form.

Good luck!

1 Like
Highlighted
Tourist
4 0 0

Thank you. Got it working now.

0 Likes