How can I hide a page behind a unique access code

How can I hide a page behind a unique access code

amateurcoder
Visitor
3 0 1

My store is an educational publishing company. We have a page of digital resources that we would like to only be accessible to people who have purchased a product. Right now the idea we have is associating each book with a unique access code (which would likely be attached inside the book) and then the customers enter this code into our website and their account gets tagged with a specific tag (say "abc123"). From there, unless they are an "abc123" customer, they will get a message saying "You do not have access to this page." I have no idea if this is the best way of going about this, though. Additionally, what protections could we have to say "this code has already been used?"

Does anyone here have any experience with anything similar? Would appreciate any tips or advice! Thanks.

Replies 3 (3)

BlackCro
Shopify Partner
81 17 10

You can use the customer object to check if the customer has made a purchase with the orders_count property, then display the page. Alternatively you could use the tag property, but this would require setting up a flow to give customers the abc123 tag once they purchase. 

 

{% if customer.orders_count > 0 %}
    <Page code here>
{%- else -%}
    You do not have access to this page
{%- endif -%}

 

Customer object documentation - https://shopify.dev/docs/api/liquid/objects/customer

 

Hope this helps

Simon

BlackCro.co.uk

CRO & Development Agency

amateurcoder
Visitor
3 0 1

Thanks for the reply! Unfortunately, just using a simple count like this wouldn't work because

  1. many of our customers purchase directly from us using Purchase Orders and so wouldn't have an order history on Shopify, and
  2. we want this page to be restricted to customers of a specific product, not just people who have purchased anything from us.

 

We could theoretically do something along the lines of:

 

{% if customer.orders contains "abc123" %}
   // Show page
{%- else -%}
   <p> You do not have access to this page </p>
{%- endif -%}

 

 

But again this doesn't account for customers who purchased abc123 via a PO. We need some way to grant these people access, as well as give users of the product who had someone else purchase for them (and probably many of their colleagues) access.

 

Hence why we were considering creating unique access codes, but then that adds a whole other layer of complexity re: generating and authenticating the codes.

BlackCro
Shopify Partner
81 17 10

Understood. Given some sales happen off platform I'm not sure Liquid/Shopify accounts provide any benefit. You may be better off using a javascript solution and distributing codes with the products like you mentioned. 

 

Any of the customer checks in Liquid require they have an account and are logged in to it at the time, which is an unnecessary complication especially if you'd like the pages to be shared among friends/colleagues. 

 

Best of luck!

Simon 

BlackCro.co.uk

CRO & Development Agency