Hide Empty Collections

Nik_K_
Shopify Partner
10 0 2

In regards to the main collections page (www.domain.com/collections/) I want to hide all of the collections that have 0 items available. Now, those collections may have products associated with it, but they are not visible on the site. Having some trouble with the liquid code to make these collections with 0 items to be hidden on the main collections page. Right now it shows all 20 collections, regardless of whether or not items are turned on.

So if there are only 3 collections that have visible products, this main collections page should only display those three.

Nik_K_
Shopify Partner
10 0 2

I know that I can simply "HIDE" the collections via the collections page in the CMS, but was checking to see if there was another way to do it programatically.

0 Likes
Alex135
Astronaut
1889 1 462

You can use a conditional statement to check the number of products in the collection.  I can't give any specifics since you didn't specify a theme.  You might end up with something like this:

{% for collection in collections %}
  {% unless collection.products.count < 1 %}
    {% include 'collection-grid-item' %}
  {% endunless %}
{% endfor %}

 

pranjaljanrao
Tourist
5 0 1

hi, m new to shopify , n also want to hide collections if there is no products in it.. I had installed 
FURNIMART SHOPIFY THEME and m using quikify app for nevigation as we had lots of menus... 

Above you suggested the code for it.. can you please mention where to add it ?

It will be really heplfull for us.

Thank you

0 Likes
emi_mtm
Tourist
3 0 2

hey @pranjaljanrao, i'm not familiar with furnimart and quikify, but i was able to use this post from @Lixon_Louis to edit my code!

you might also try reaching out to support for your theme (if it exists) or hiring a Shopify Expert if that doesn't work!

0 Likes
wilsoff
New Member
2 0 1

Thank you, this worked well in 'Debut' theme, editing the 'list-collections-template.liquid' file.  I added these two lines three times, wrapped around the appropriate existing lines

  • {% unless collection.products.count < 1 %}
  • {% endunless %}

There might be more efficient places to put this, but it worked for me.

Final code here:

  <ul class="grid grid--uniform">
    {% if section.settings.display_type == 'all' %}
      {% case section.settings.sort %}
        {% when 'products_high' or 'products_low' %}
          {%- assign collections = collections | sort: 'all_products_count' -%}
        {% when 'date' or 'date_reversed' %}
          {%- assign collections = collections | sort: 'published_at' -%}
      {% endcase %}
      {% if section.settings.sort == 'products_low' or section.settings.sort == 'date' or section.settings.sort == 'alphabetical' %}
        {% for collection in collections %}
          {% unless collection.products.count < 1 %}
        	<li class="grid__item {{ grid_item_width }}">
            	{% include 'collection-grid-item', collection: collection %}
        	</li>
          {% endunless %}
        {% endfor %}
      {% else %}
        {% for collection in collections reversed %}
          {% unless collection.products.count < 1 %}
        	<li class="grid__item {{ grid_item_width }}">
            	{% include 'collection-grid-item', collection: collection %}
        	</li>
          {% endunless %}
        {% endfor %}
      {% endif %}
    {% else %}
      {% for block in section.blocks %}
        {% unless collection.products.count < 1 %}
        	<li class="grid__item {{ grid_item_width }}">
          		{%- assign collection = collections[block.settings.collection] -%}
          		{% include 'collection-grid-item', collection: collection %}
        	</li>
        {% endunless %}
      {% endfor %}
    {% endif %}
  </ul>

 

Hi, 

I'm using Simple Theme.

I'd like to hide a collection on sidebar if the collection is empty.

I'm just wondering if you can help me.

Thank you!

0 Likes
suyash1
Shopify Partner
3007 327 502

@partpartpart - you can check if , collection.products_count > 0 , if yes then only display that collection, this will need some code settings, but you can try it

You are welcome to contact me, my email - suyash.patankar@gmail.com
Free Shopify solutions/tutorials on youtube
#1 page builder app on Shopify - for FREE! PageFly
0 Likes

Hello @suyash1 this is the code from  list-collections-template.liquid

Which part do I need to add the code?

<div class="grid grid--uniform">
{% if section.settings.display_type == 'all' %}
{% case section.settings.sort %}
{% when 'products_high' or 'products_low' %}
{%- assign collections = collections | sort: 'all_products_count' -%}
{% when 'date' or 'date_reversed' %}
{%- assign collections = collections | sort: 'published_at' -%}
{% endcase %}
{% if section.settings.sort == 'products_low' or section.settings.sort == 'date' or section.settings.sort == 'alphabetical' %}
{% for collection in collections %}
<div class="grid__item {{ grid_item_width }}">
{% include 'collection-grid-item' %}
</div>
{% endfor %}
{% else %}
{% for collection in collections reversed %}
<div class="grid__item {{ grid_item_width }}">
{% include 'collection-grid-item' %}
</div>
{% endfor %}
{% endif %}
{% else %}
{% for block in section.blocks %}
<div class="grid__item {{ grid_item_width }}">
{%- assign collection = collections[block.settings.collection] -%}
{% include 'collection-grid-item' %}
</div>
{% endfor %}
{% endif %}
</div>

0 Likes
suyash1
Shopify Partner
3007 327 502

@partpartpart - please take backup first then try this  code

<div class="grid grid--uniform">
{% if section.settings.display_type == 'all' %}
{% case section.settings.sort %}
{% when 'products_high' or 'products_low' %}
{%- assign collections = collections | sort: 'all_products_count' -%}
{% when 'date' or 'date_reversed' %}
{%- assign collections = collections | sort: 'published_at' -%}
{% endcase %}
{% if section.settings.sort == 'products_low' or section.settings.sort == 'date' or section.settings.sort == 'alphabetical' %}
{% for collection in collections %}
<div class="grid__item {{ grid_item_width }}">
{% include 'collection-grid-item' %}
</div>
{% endfor %}
{% else %}
{% for collection in collections reversed %}
<div class="grid__item {{ grid_item_width }}">
{% include 'collection-grid-item' %}
</div>
{% endfor %}
{% endif %}
{% else %}
{% for block in section.blocks %}
<div class="grid__item {{ grid_item_width }}">
{%- assign collection = collections[block.settings.collection] -%}

{% if collection.products_count > 0 %}
{% include 'collection-grid-item' %}
{% endif %}

</div>
{% endfor %}
{% endif %}
</div>
You are welcome to contact me, my email - suyash.patankar@gmail.com
Free Shopify solutions/tutorials on youtube
#1 page builder app on Shopify - for FREE! PageFly