Hiding products with a certain tag in the collection

Tourist
10 1 1

Hi,

 

I use this code to hide items that contain the tag "expired" in my collections page:

 

{% if product.tags contains 'expired' %}{% continue %}
{% else %}
{% include 'collection-product' with collection.handle %}
{% endif %}

 

This works, however, the collection page doesn't correctly list the amount of products I have set to display per page. For example, if my collection page is set to display 30 products, and 15 products have the tag "expired" for that page, then only 15 show instead of the 30 products that don't have the tag. Each page shows a random amount of products based off how many products have that tag.

 

How can I resolve this issue so that the correct amount of products show per page yet hide the products that I choose?

 

Thanks!

 

0 Likes
Shopify Partner
1141 92 139

Hi @Henry_Pham,

 

Could you please share your website URL in order to check further?

Thanks & Regards
Perennial Solution

Problem Solved?✔️Like and Accept the solution that can help others.
Need any help with theme customization or design? Hire us
Email: infoperennialsolution@gmail.com
Skype: infoperennialsolution
0 Likes

Hi @Henry_Pham 

 

If you have automated collections set up you don't need any code to achieve this. I'm happy to send you video showing you how to do this for free. Reach out below and I'll help you out. 

 

https://www.inspiresmallbusiness.com/pages/contact-clayton

 

Cheers 

Clayton Bates 

P.S If you want a awesome , extremely detailed , Free website review that will blow your socks off check out this link HERE or www.inspiresmallbusiness.com

0 Likes
Shopify Partner
1141 92 139
{% for tag in product.tags %}
{% if tag = "expired" %}

{% else %}
{% include 'collection-product' with collection.handle %}

{% endif %}
{% endfor %}

try this  

Thanks & Regards
Perennial Solution

Problem Solved?✔️Like and Accept the solution that can help others.
Need any help with theme customization or design? Hire us
Email: infoperennialsolution@gmail.com
Skype: infoperennialsolution
0 Likes
Tourist
10 1 1

It doesn't seem to work

 

This is the original code for outputting products:

How would I incorporate your code into it?

 

{% for product in collection.products %}
{% include 'collection-product' with collection.handle %}
{% endfor %}

 

 

0 Likes
Shopify Expert
2673 64 664

Henry, this is a well-know problem with "manual" filtering of collection items in liquid.

System gives your code a fixed number of products on every page and if you do not display all of them, then you have different number of products per page, which does not look good.

Unfortunately, automatic collections do not solve your problem because you can't have "does not contain tag" as a condition.

If you can change product type or product vendor (instead of assigning a tag), then this will play good with automatic collections, modifying product title will do too.

if you must use tags, then do opposite -- assign tag "current" on visible products instead of assigning "expired"  -- this will work good with automatic collections too.

You may consider using an app to assign tags/change properties automatically (like an app can assign "current" tag if product has no "expired" tag).

 

If your theme supports Ajax collection loading (aka infinite scrolling), this will also alleviate the problem a bit.

 

 

Want to hire me to tweak a theme? Mail me at tairli@yahoo.com!
My post solved your problem? Like it!
0 Likes
Tourist
10 1 1

Yeah, I was afraid of that. I have 2k+ collections and 10k+ products and it looks like the easiest way is to add your idea of the "current" tag and automated collections. Thanks

0 Likes