Docs Menu

Output Based on Product Collections

This code will output different text based on what collection your product is in. This code works by checking the handle of collections.

Please note: Using these code snippets may require some knowledge of HTML, CSS and Liquid. If you need assistance getting the code examples to work or meet your more specific needs, consider hiring a developer to help. These code snippets may not work in all themes or store configurations, so be sure to test everything thoroughly.

Add this Code to My Content

Change the values in bold to fit your needs. Be sure the "use Liquid" checkbox is checked.

{% assign collection_handles = product.collections | map: 'handle' %}
{% if collection_handles contains 'Collection 1' %}
Collection 1 Text
{% elsif collection_handles contains 'Collection 2' %}
Collection 2 Text
{% else %}
Fallback Text
{% endif %}

The code above will only output the first text match it finds. If you want to output multiple messages for multiple collections, use this variation:

{% assign collection_handles = product.collections | map: 'handle' %} {% if collection_handles contains 'Collection 1' %} Collection 1 Text {% endif %} {% if collection_handles contains 'Collection 2' %} Collection 2 Text {% endif %}
arrow-up