Hide empty featured collections

Highlighted
New Member
5 0 0

Hi there,

I am wondering if there's any way I could hide an empty featured collection automatically when it does not have any items?

My collection is automated so I figured that I should do the same to the featured collection too.

Any help is appreciated. :]

Cheers and stay safe,

0 Likes
Highlighted
Shopify Partner
2294 116 353

If the collection needs to be automated to unpublish it from a channel try usemechanic.com for programatically scripting such events.

If the collection needs to just be hidden on the frontend with theme code then logic similar to the following can control whether pieces of code run or not in different areas of a theme.

Basically you will have to wrap it around larger pieces of display code with the {% if ...%} at the start and the {% endif %} at the end.

{% if collection.products_count  != 0 %}
 ...display  code....
{% endif %}

 

For loops such as menus, or collect lists the following can be used to skip empty collections

{% if collection.products_count  == 0 %}
 {{ continue}}
{% endif %}

 

Problem Solved? ✔️Accept and ? Like the solution so you can help others.
Buy me a coffee ☕ paypal.me/paulnewton or donate to eff.org
Confused? Busy? Buy a custom solution paull.newton+shopifyforum@gmail.com
0 Likes
Highlighted
New Member
5 0 0

Hi Paul,

If I want the code to apply to the featured collection, which file should I head to and wrap the code?

cheers,

0 Likes
Highlighted
Shopify Partner
2294 116 353

Where and how you add that logic varies wildly by theme

Problem Solved? ✔️Accept and ? Like the solution so you can help others.
Buy me a coffee ☕ paypal.me/paulnewton or donate to eff.org
Confused? Busy? Buy a custom solution paull.newton+shopifyforum@gmail.com
0 Likes
Highlighted
New Member
5 0 0

 

Your method worked!

Thanks!

0 Likes
Highlighted
Shopify Partner
2294 116 353

Your welcome, consider sharing the high level steps you took to fix it and marking that as the solution.

Especially if your using a shopify free theme that will help other merchants.

Problem Solved? ✔️Accept and ? Like the solution so you can help others.
Buy me a coffee ☕ paypal.me/paulnewton or donate to eff.org
Confused? Busy? Buy a custom solution paull.newton+shopifyforum@gmail.com
0 Likes