editing customiser in shopify via theme code

How to edit Shopify custom liquid code not in the customiser

This is a quick blog post because I recently encountered a massive problem with Shopify’s customiser while adding liquid code. I wanted to add some code that redirects a user to another page if they are not approved using customer tags. So I came up with the following code:

Shopify Custom Liquid Code for redirecting users if they don’t have the correct tag

{% if customer %}
{% if customer.tags contains 'your-tag-name' %}
<!-- Display content for authorized customers -->
<p>Welcome, authorized customer! You have access to this page.</p>
{% else %}
<!-- Redirect for unauthorized customers -->
<script type="text/javascript">
window.location.href = "/pages/access-denied"; // Replace with your desired URL for unauthorized users
</script>
{% endif %}
{% else %}
<!-- Redirect if the user is not logged in -->
<script type="text/javascript">
window.location.href = "/account/login"; // Replace with your login page URL
</script>
{% endif %}

This worked perfectly, if the customer did not have the correct customer tag, it would redirect them to the login page. I made this code so that if a user was not approved on a wholesale/trade website they wouldn’t be able to access the product pages.

However this worked too well, and it meant that I couldn’t edit the page anymore because, as an admin, I did not have the correct tags.

  • I tried to add myself as a customer and change the tags, but this didn’t work.
  • I tried to add customer tags as an admin, but this also doesn’t work.
  • I tried reverting back to an old version, didn’t work
  • I tried overriding this code in the browser, nope
  • I tried a number of other things, none of them worked.

I needed to gain access to this template because I made some more code on this page that I really needed and put hours of work into.

How to edit the Shopify Customiser via theme code

Finally just as I was about to give up and create a new template, I found the json files of the templates. It turns out you can edit the custom liquid code within these json files.

When you find the correct template, you can go into these files and find the custom_liquid, from here you can edit the code. I was able to delete the code causing the redirect.

And just like that I regained access to my template page!

I’ve made this blog post because it was such a pain to figure out how to do this, hopefully if you’ve had the same issue this blog post has help you.