How can I count products in a filtered collection to hide empty ones?

I am using the url of a collection with filters in my navigation. I want to hide empty collections. Does anyone know how to get a count of a collection with filters so I can hide ones with less than 1?

For example I have this url which filters my jerseys collection. My jerseys collection has items in it but when I filter by women it is empty.

https://itsaparty.com/collections/jerseys?filter.p.m.my_fields.shop_for=Women

Thank you! Also, does anyone know if there is any issue with using this type of URL in the navigation regarding duplicate content and being counted as a separate page from the main collection page?

I like it better than filtering by tags because it shows the filters on the collection page while the filter by tag collections do not show filters.

Hi @TheThisThat ,

You can add the filter.v.availability=0 in your link. Please see link below for reference

https://itsaparty.com/collections/jerseys?filter.p.m.my_fields.shop_for=Women&filter.v.availability=0

Thank you for your response! I am probably being dense here but not understanding how to use this filter to determine availability from a preexisting navigation link.

If there is no availability it doesn’t change the url to filter.v.availability=0. It just shows an empty collection.

Is there a way using liquid code to test whether it is empty or not?

I think I am looking for how I could use the filter_value object. But not sure of the syntax when looping over links. If collection is empty OR filter_availability.count = 0 then don’t show is the logic I’m trying to write.

@TheThisThat ,

You can use the code below. You can read more about the code here.

{%- if product.selected_or_first_available_variant.available -%}
....
{% endif %}

Thanks for your response but not working with the product obj

Hi @TheThisThat ,

it would be best to share your website since every website is written differently. Thank you