hey scott austin here from jade puma in,this video i'm gonna show you how to,restrict access to,any page on your shopify store to people,that are logged in and logged in with a,certain status,right so and by any page i mean we can,do this on an article we can do it on a,page we can do it on blog we can do it,on a product we can do it on a,collection,so in this store that i'm building for a,client right now we have subscriber,content,so they must be a subscriber and if they,are a subscriber that we add a tag to,their customer record and right now,i'm not logged into this store so if i,go to subscriber content and what i want,to look at one of the articles it's,going to take me,to the login page same thing if i want,to go to one of the product downloads,this is a collection page it also takes,me to the product page so step one of,the code that we're going to do,is going to be to verify if someone's,logged in or not and if not logged in,ask them to log in,and this is all going to be done through,liquid code in your theme right so this,is not going to be done with an app,there are apps that do this i like doing,things with liquid when i can,just to reduce the complexity of adding,lots and lots of apps and this way i'm,in control of the code and know exactly,how it's built versus you know having a,developer who i may not be familiar with,their code and i might not have access,to edit their code,so you know there are times you know you,have to use apps but this is one of,those times where you can also just do,it in liquid code on your own,so let's first look at what how we're,getting the customer,to go to the login screen when they're,trying to go elsewhere on the site and,if you see here on the you know you'll,see when i hover over something down,here in the lower right,you know it says this this is trying to,take me to,profitsourceadvisors.com four slash,blogs four slash articles but when i,click on that,link it doesn't take me there instead,i'm going to this account login page,so let's show you how that code works,it's actually fairly simple,so,that first level of let's verify if,they're logged in or not right that code,happens in our,theme.liquids that's under the layout,folder,theme.liquid,and what the code is and it's most of,the code is right here,right so what the code says is,if the template contains subscription so,what i do,for a product for an article for a,collection i make a second set,of templates for each of them so here if,you look at my templates folder you'll,see i have a um,article.liquid and a,article.subscription.liquid,i have a blog.liquid and a,blog.subscription.liquid,i have a collection subscription one in,addition to my collection and if i look,farther down i'll probably see the same,thing for product product subscription,and a normal product,so all you have to do is create a second,subscription template and then just,apply it to that that content so if you,want a collection to be,restricted access to subscribers only,you just change the template from,default to subscription same thing for,an article or for a product,so regardless of what type of content it,is we're creating that dot,subscription.liquid template for each,one of those types of content so that we,can tag them basically at the template,level as a subscription access um,piece of content,so then what we do is if we're on a,subscription template we check to see if,they're logged in and if they're not,logged in that's just unless customer,customer basically means are they logged,in so if they're not logged in then we,set assign you know then we assign the,variable send the login to true,and then what you see down here is if,send to login,is true,and,if,they're not if they didn't go through,this loop here the send to login will be,false right so if we're not on a,subscription template send a login will,not get set to true therefore it is,false therefore this if statement will,be ignored and what will happen is it,will respond to the else statement and,the else all the way down to the bottom,of the end if right here this and if we,added to this page,um,that is the,page temp with the theme.liquid template,that was there before i started editing,it so basically,we added this code right here,and,the end if down at the bottom,so then,back to this logic here,if we have said we want to send them to,the login page because we're on a,subscription template page and they are,not logged in,then there's this html,code here,which basically says all right we're,going to redirect them to this other,page account login which is a page that,exists in all shopify stores regardless,of the theme,and then we also say and checkout url,and that basically says once they're,done logging in bring them back to,and this is a liquid element here the,request.path,and that's basically the path of the,page that we're currently on so the way,that works right,is here i am i want to go to the,subscriber content so i'm gonna go to,this articles,and i get redirected and if you see up,here in the url i'm gonna click it again,um you'll actually see i go to a,different page the article page,and then it quickly redirects me,once that page starts loading up it,redirects me and here it says here's,that checkout url,forward slash blogs forward slash,article so it's going to once i log in,it's going to bring me back to this,location so i'm going to log in,to this page,and now i'm back on blogs articles,and if i want to now access other,subscriber content because i'm logged in,and this is all placeholder still,building the store out now i have access,to this if i had if i log out,right here,and go back to that downloads,you'll see it takes me to that login,page,so,the first level of access is are they,logged in or not and the way we do that,is through the let's bring up the code,again,is through editing theme.liquid,with this code that we just talked about,and then creating those dot subscription,templates for each of the content types,and assigning it to that content type in,your shopify admin,so if all you want to do is restrict,access to people that are logged in,we're now done right but there's a,second level to this that we can add to,it and that is we only we want to,restrict access to people that are,logged in and have a certain tag to them,right that tag could be in the case of,this store for subscription you know you,could have a tag for vip customers and,have vip only content so let's show you,what that content would look like or,that code would look like so let's go to,article subscription right here dot,liquid,and we have to add this in each of those,description templates that we create so,this content,here,is the article,dot liquid content and the rest of this,code below that and above it we add and,it's a simple if statement so what we're,saying is if,now we already know that the customer's,logged in on this page because,we did that check at the theme,dot liquid level right we check to make,sure on a subscription content that,they're logged in so we know they're,logged in,so now we're asking that second question,if the customer.tags contains,and in this store we we are tagging our,subscribers as active subscriber you,could tag your customers as vip or,whatever else you want,um and put that tag up here,so then if the customer,has the tag that they need to access the,content,they get to see the normal content for,the page,if they don't have that tags even if,they log in but they're not an active,subscriber then what they'll see that's,the else statement here,and this is just a little code that i,like,i made up for this theme in this store,that basically says access is not,authorized,um and i actually have a,page that i store some content on that,gives a little brief explanation and and,the nice thing about doing this at the,page level,um storing this in a page content is i,can create that content once and then,just throw the same reference to it in,all of my different subscription,uh templates whether it's for a blog an,article a product or a collection or a,page and all that same content shows up,on all those the same way but this is,basically the you don't have access,to this content warning message and,whatever however i want to handle that,i'm doing in that little section there,so that's the second level of making,sure they have the right tag and of,course you can have different tags you,know maybe you're you know you have vips,and you have subscribers so you can do,different logic between those there but,the the liquid code for these is on the,blog article on the jade puma website,that this video is also on so you'll be,able to look at that and use that as a,starting point for your theme of course,you might have to change things a little,bit the the store that i'm doing this is,in the turbo theme or sorry time,interprets and the flex theme um your,your code may have to be a little bit,different for your theme,all right hopefully that helps thanks,for watching
Congratulation! You bave finally finished reading how to give someone temporary access to shopify and believe you bave enougb understending how to give someone temporary access to shopify
Come on and read the rest of the article!