Implementing a Hidden Collection of Products on Shopify

Implementing a hidden collection of products on your Shopify store is useful in cases where you want to offer free or discounted products to people with a direct link to a specific collection or product page but not viewable or accessible via any other webpage on your site.

Even though each shopify theme is slightly different we will walk you through a generic solution on how to implement a hidden collection of products called freebies.

To get a hidden collection on your Shopify store we will break the implementation into 3 steps:

1. Hide the hidden collection from the sidebar
2. Hide the hidden collection from the list of collections page
3. Hide products in the hidden collection from /collections/all

1. Hide the hidden collection from the sidebar

To hide the hidden freebies collection from the sidebar you will need to edit the sidebar-collection.liquid snippet file.

Find a line that looks like:

{% unless collection.handle == 'frontpage' %}

and change it to include the freebies collection handle like this:

{% unless collection.handle == 'frontpage' or collection.handle == 'freebies' %}

2. Hide the hidden collection from the list of collections page

Hiding the hidden freebies collection from the list of collections page on the /collections page is similar to that in step 1, but instead you will edit the list-collections.liquid template file.

Find a line that looks like:

{% unless collection.handle == 'frontpage' %}

and change it to include the freebies collection handle like this:

{% unless collection.handle == 'frontpage' or collection.handle == 'freebies' %}

3. Hide products in the hidden collection from /collections/all

Now that the hidden freebies collection is not accessible via your website you also want to make sure any products in your freebies collection are also not accessible via other collections. By default the /collections/all collection page displays all of your shopify products.

Unlike the first two steps that were edits to your liquid theme, this third step is adding a code snippet.

To hide products in the hidden freebies collection from the /collections/all webpage (and any other collection pages for that matter) you will need to edit the collection.liquid template file.

Above the code that iterates through products in a collection add the following code:

{% assign in_freebies_collection = false %}
{% for collection in product.collections %}
{% if in_freebies_collection == false and collection.handle == 'freebies' %}
{% assign in_freebies_collection = true %}
{% endif %}
{% endfor %}
{% unless in_freebies_collection and collection.handle != 'freebies' %}

Then remember to close off the unless statement under the code that iterates through products in a collection by adding the following code:

{% endunless %}

Keep in mind that this is a generic walkthrough on how to implement a hidden collection of products in your shopify store. If you are having difficulties following along due to the differences in your Shopify theme then leave a comment below and we will be sure to help.