How to call customer tags with Liquid in Shopify

Last updated:

Home » Articles » Shopify » How to call customer tags with Liquid in Shopify

If you’re running a Shopify store, you might want to display or use customer tags to create personalised experiences. Customer tags are brilliant for segmenting your audience and delivering tailored content. Fortunately, Shopify’s templating language, Liquid, makes it quite straightforward to access and display these tags on your website.

Calling customer tags with Liquid

To display customer tags in your Shopify store, you’ll need to use the customer.tags variable that Liquid provides. This variable contains all the tags associated with the currently logged-in customer as a comma-separated string. You can easily access these tags by adding a simple code snippet to your theme files.

Here’s how you can display a list of customer tags on any page of your Shopify store:

{% if customer %}
  <h2>Customer Tags:</h2>
  <ul>
    {% for tag in customer.tags %}
      <li>{{ tag }}</li>
    {% endfor %}
  </ul>
{% else %}
  <p>No customer is logged in.</p>
{% endif %}

This code first checks if a customer is logged in using the {% if customer %} condition. If someone is logged in, it creates a heading followed by a list of all their tags.

The {% for tag in customer.tags | split: ', ' %} loop correctly splits the string of tags into an array before iterating through them. If no one is logged in, a simple message appears instead.

You can place this code in any Liquid template file where you want the tags to appear. Common places include:

  • snippets/customer-tags.liquid (if you want to reuse this logic in multiple places)
  • customers/account.liquid (for displaying tags on the customer account page)
  • customers/order.liquid (for showing relevant tags on the order history page)
  • sections/custom-section.liquid (for use within custom theme sections)

Practical uses for customer tags

Customer tags are incredibly versatile. You might use them to show special offers to VIP customers, display different content based on a customer’s interests, or hide certain elements from specific customer groups.

For instance, you could extend the code to show special content only to customers with a specific tag:

{% if customer and customer.tags contains 'VIP' %}
  <div class="special-offer">
    <h3>Special VIP offer just for you!</h3>
    <p>As a valued VIP customer, enjoy 15% off your next purchase.</p>
  </div>
{% endif %}

Important note: The contains filter checks for substrings. This means that if a customer has a tag like 'VIP-Member', it will also match 'VIP'. If you want an exact match, use:

{% assign tags_array = customer.tags | split: ', ' %}
{% if tags_array contains 'VIP' %}
  <!-- Special content here -->
{% endif %}

Conclusion

Using Liquid to access and display customer tags in Shopify is a powerful way to create personalised experiences in your online store. With just a few lines of code, you can tailor your site’s content based on customer segments, which can significantly improve engagement and conversion rates. Whether you’re highlighting special offers for loyal customers or displaying different content based on customer preferences, Liquid’s customer.tags variable (when properly split into an array) gives you the flexibility to create these personalised experiences easily.

Wave

Enjoy our articles? Join our free list and get more.

Sign Up

Book Discovery Call