How to hide a product from a collection using liquid?

New Member
4 0 0

Hello, 

I am not an expert in liquid but I just did some research on the forum to find how I could hide products with a certain tag in a collection usiing liquid . I came across this thread. : https://ecommerce.shopify.com/c/ecommerce-design/t/hide-products-from-all-products-but-still-have-th...

I used the same code provided as solution number two in response to this thread and changed it my way .: 

{% for product in collection.products %}
  {% assign displayProduct = true %}

  {% if product.tags contains 'outlet' %}
    {% assign displayProduct = false %}
  {% endif %}

  {% if displayProduct == false %}

  {% endif %}
{% endfor %}

The goal here is to hide products which are tagged "outlet" so they do not show up in "all" collection. 

But I am stuck here what to I need to add after {% if displayProduct === false %} to hide the targeted products  ??

Please someone help me on this one . I think I'm almost there just need a hand:;)

Thank you 

 

0 Likes
Shopify Expert
9800 91 1553

Why not make an all collection with a curated list of products you want to be seen? If you do that, this will replace the default all collection that shows everything.

★ Winning Partner of the Build a Business competition. ★ http://freakdesign.com.au
0 Likes
New Member
4 0 0

Thank you Jason but that is not the solution I am looking for . I already have an all smart collection filtered by price. Smart collections allow to "show products with tags " but don't allow to "exclude products with tags". The other way around of course would be to make a smart collection tagged "all" and not outlet..;;but..

..What I want is to do is leave "outlet"  products visible in my shop but I don't want them to show up in the "all " collection. Now my template shows all the tags to the customers  and that  helps them narrow their search. For this reason I can't create irrelevant tags : tagging "all" wouldn't work because there is already an automatic all tag ( showing all products); " tagging new or else  doesn't look good on the screen either and it means having to un-tag when I want to make them outlets (there could be hundreds of them!). 

For me the simplest way would be to change the liquid code over smart collections (which is not such a bad idea depending on the problem). 

0 Likes
Shopify Expert
9800 91 1553

Using Liquid will mean that your collection will have gaps in the product grid. For example if you show 50 items per page it would be possible to see 0 items if all 50 had the tag. You'll 100% end up seeing a mix of numbers that might be very weird for the customer to see.

The concept would be:

{% for product in collection.products %}
  {% if product.tags contains 'outlet' %}{% continue %}{% endif %}
  <!-- your product grid item -->
{% endfor %}

 

★ Winning Partner of the Build a Business competition. ★ http://freakdesign.com.au
1 Like
New Member
4 0 0

Thank you Jason . I will try this solution but if the result is not so appealing I guess I will stick to using smart collections. 

Cheers

0 Likes
New Member
4 0 0

Hello here is my feedback after implementing the code Jason posted above , it finally worked!!!!! . I figured out I had to implement it in the "collection.liquid" file in the snippet and not the template folder. However, the products tagged outlet don't appear and no ugly gap in my product listing , as I was afraid there would be. 

see the result here : https://njfootwear.com/collections/all

So thank you very much Jason, you were big help shout out. 

 

0 Likes
New Member
4 0 0

Hello!

 

How can I do the same but forcing them to login?

 

I mean I have certain products with a specific tag that I just want to show to people that login , I tried this in theme but it does not work

 

{% if product.tags contains 'password' %}
{% if template contains 'customers' %}
{% assign send_to_login = true %}

{% endif %}

{% endif %}

0 Likes
Shopify Partner
1 0 0

Hi Joiakim. I see you have already solved this issue by filtering out products via liquid so I guess this response is intended for others who end up here with a similar issue and do not want to mess around with the theme.

One way Jason's suggestion can work is if you are able to use product type for this. For example, you can set product type to "Outlet" for all products that are not supposed to display on ../collections/all page. The obvious downside of this approach: you can't have more than one product type per each product so this won't work if you rely on product types for other purposes.

 

This is our version of this issue and what we did to solve it:

On one site we have a few add-on products which do not belong to any collections and customers should only view them inside cart. But ..collections/all page was still featuring these products. So we took the following steps:

1. Give product type "Add-on" to all such products

6917da3f-7be4-42b5-a4ab-fec238348352.png
2. Create a new collection named Products. We use name "Products" for collection, not "All". This allows the page to look the same as default the default ../collections/all page in many themes, with "Products" as page title and main heading.

bMK3DS.png
3. Choose automated collection type, and set the condition to show only products that are not of type Add-on

e9e8efc7-aada-4eb9-b564-ba132704d07f.png

4. Set following values in SEO settings at the bottom:

433649bd-127c-4dd9-8e3f-e5e729bc7a3e.png

0 Likes