How to hide collection from linklist if it's product inventory is 0

Not applicable
0 0 54

Right now I do this, 

            {% for link in linklists.jewelry.links %}
                    {% if link.type == 'collection_link' %}
                          {% if link.object.products_count > 0 %}
                            <li class="filter">
                              <a href="{{ link.url }}"{% if link.object.handle == collection.handle %} class="active"{% endif %}>{{ link.title }}</a>
                            </li>
                          {% endif %}
                        {% else %}
                 
                    {% endif %}
           {% endfor %}

But this only accounts for hiding the list item of collections that have products completely removed. It is pretty awkward because I hide the products with 0 inventory but the collection url still exists. 

 

0 Likes
Shopify Expert
9981 84 1492

Try:

{% if link.object.products.size > 0 %}

 

★ Winning Partner of the Build a Business competition. ★ http://freakdesign.com.au
0 Likes
Highlighted
Excursionist
13 2 2

Jason - not exactly my question but sort of related:  

 

our products are pushed to Shopify from a 3rd party app.  Sometimes the number of items in a collection drops to 0, so the collection is empty.  When that happens, the collections page shows the button for it, but it is grayed out and inactive.  Ugly.  It's the nature of our one-of-a-kind products that this will happen frequently.  Is there a way to force the collection into a hidden state automatically?  And then active when new products are pushed up?  I can do it manually but can I set it via code to do it without intervention?

 

Thanks

Ed K

 

0 Likes