Description: The following passage mainly focuses on shopify login, which shows you how to create a members only store for your website by adding a simple code to your theme. You will also see how to restrict access to collections, products or pages.
I hope that business is doing good as usual, this week we’ll see how to create a members only store for your website meaning that you want to restrict access to any page on your website, but we’ll see also how to target specific pages like your collection page, your product page or whatever page you want to target and force visitors to log in or create an account if they they’re not already a member on your store.
This is what it will look like, I’m trying to access another page on my website, it always brings me back to the login, wherever you are trying to go, it will always bring you back to the login page, this is what we’ll be showing, here’s what the same page looks without restricting access as we saw earlier.
I want to point out that for you to restrict access to your website, you need to have a good reason and you shouldn’t do this on any store, maybe you’re dealing with distributors or maybe a specific group of businesses, maybe you absolutely need people to have an account or maybe you need to double check their information to make sure they’re that they’re professional or they’re part of a certain group.
That being said let’s see how we can do it, please go in your admin panel, go in settings and check out, we need to make sure that customers need to have an account, the important accounts should not be disabled, they should be required or at least optional.
In my case I keep it optional because I’m not going to always have that restriction on my website, once that is set, we’ll need to modify the team liquid page of your store, go back in online store themes, click on the three dots and edit HTML CSS.
On the left side under layout, look for theme that liquid, this is the main template, the main layout for your whole store, in this first scenario we’re going to target the complete website, any page they want to access they will need to log in first.
In the description you’ll see a link to get the code that we need to add, let me copy and paste it, here’s the code that you’ll need to insert in your team liquid page, you need to see it in two different sections, you have the section up top here, you will have the second section, the code is already on your page.
Your page has a ready code, we will keep all of this and add to it, we’re not modifying anything, we’re not changing anything, we’re adding to it, take the first section of the code up until else, we’re going to paste it over here, the else should end where the doctype starts.
We’ll be missing at the end if because we started an if, we have an else and we need to close the end if, you don’t need to know all of that, copy it and paste it at the bottom of your page, don’t forget to save, if we go back to our page that we had and we refresh, it’s going to redirect you to the login page.
That’s easy, now that I log in, let’s assume that you will block access on the product page, for whatever reason you don’t want your products to show to customers to visitors that don’t have an account yet, in that case what I suggest you to do is to go to any product page.
Do a right click on the page and do inspect element, I’m using Firefox, you can do the same in Chrome, do inspect element, what I want you to do is to scroll at the top and look for the line body, you have your body ID, look at the far you’re looking for something that starts with template.
We have template product, I can see template page, template collection and all of those with target, in this case template product targets all products that have the template product incoming, so we’re going to copy this, the important part is what follows the the template.
In this case it’s product, we can copy product, we go back into the code, we have to modify it a little bit, it only targets the template product, so we have to go here unless we have the first, if the template contains customer, in the case you’ve already logged in, you will have the template.
We have a customer tag added to it, if we’re going to leave it as it is, we’re going to modify the else, we are going to make it an else if, we will use the same logic as what we have over here, I’m going to copy it, don’t forget to copy that product, copy paste over here.
What we want to do is to assign, I need the code to login, only when the template contains product, save it, let’s log out, let’s try to go back to the product, it doesn’t let me, this is perfect, everything else works, that’s good, if you want to do the same thing with collection, I don’t have collection on this website but let’s still access it here.
It will be the same logic, let’s assume I have this closed, right click, inspect element, look for the line body, the template in this case is collection, so we can do exactly the same thing, we can add another one, this should work. Let’s click Save, refresh.
Now collection is also going to redirect to the login page, I hope that this is helpful, if you have any questions, don’t hesitate to ask as usual in the comments below, thank you.