Add age verification to your online store

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.

If you sell products such as wine, cigarettes, or dangerous goods, then you might want to discourage visitors under a certain age from browsing your website. You can do this by adding an age selection form to your storefront.

Caution

This method does not meet the age-verification requirements associated with current FDA regulations that govern the sale of e-cigarettes, cigars, and tobacco products.

Keep in mind that age verification is not the best way to prevent visitors from browsing your website, as there's nothing preventing them from lying about their age. It might even be a nuisance to regular visitors, who will have to make an additional click to access your store.

An age verification dialog overlaid on an image of a red squirrel

Create and include an age-check snippet

  1. From your Shopify admin, click Online Store, and then click Themes (or press G W T).

  2. Find the theme you want to edit, click the ... button, and then click Edit HTML/CSS.

  3. Click on the Snippets folder to expand and view its content.

  4. Under the Snippets folder, click on Add a new snippet.

  5. Name your new snippet age-check, and click Create snippet. Your age-check snippet will open in the online code editor.

    The "Add a new snippet" dialog box, with a highlighted entry field containing the text "age-check"
  6. In a new browser tab, open the following file.

  7. Copy all of the code you see there and return to your Themes page.

  8. In the online code editor, paste the code you copied into your age-check.liquid snippet.

  9. Save your changes.

  10. In the Layouts folder, locate and click on your theme.liquid file to open it in the online code editor.

  11. In the online code editor, scroll down a bit until you see the opening <body> tag.

  12. Right after the opening <body> tag, paste the following code:

    
    {% include 'age-check' %}
    
    

    This will include the age-check.liquid snippet at the very beginning of the body content of your theme file.

  13. Click Save to save your changes.

To see the age verification in action, take a look at this demo store.

What if I want to show an image in the background?

Upload a large JPG image (at least 1024 by 1024 pixels) to your theme assets on the Edit HTML/CSS page. Rename that file so that its name is exactly:

age-check-background.jpg

Changing the age limit

In your age-check.liquid snippet, change the following code on line number 2:


{% assign age = 18 %}

to:


{% assign age = 21 %}

You can also edit the text on lines 6 and 10.

What if I want to add a date of birth picker?

In your age-check.liquid snippet, change the following code on line number 1:


{% assign enter_date_of_birth = false %}

to:


{% assign enter_date_of_birth = true %}

Testing the functionality

Once you have clicked on the Enter link, you are not prompted about your age again for another 2 weeks. To bring on the age verification again, you need to manually delete a cookie called isAnAdult. To delete cookies, you can use the following extension in Google Chrome.

If customers disable JavaScript

If you want to keep out customers that have JavaScript disabled, add the following to the head section of your theme.liquid file in the Edit HTML/CSS page:

<noscript>
<meta http-equiv="refresh" content="1; url=/pages/age-check" />
</noscript>

Replace 'age-check' with the handle of the page you want to redirect to on your website.

Want to discuss this page?

Visit the Shopify Community