Possible to Get "Product Count" minus "Sold Out Products"?

Highlighted
Shopify Partner
8 0 0

I have a custom theme built with a sidebar nav listing all the collections, and the amount of products within each collection.

For example:

  • Shirts (125)
  • Pants (60)
  • Shoes (25)

I'm using `{{ collection.products_count }}` to return the product count of each collection. However, this count returns all products, even sold out products. Since I hide all sold out products on the collection template, ideally I would also like to hide the sold out products from the product_count (so the count matches the products displayed).

I was hoping there was some sort of filter to do this, like: {{ collection.products_count | available }}, but I haven't found a way.

Is there any way to do this?

Here's a simplified version of my current sidenav code:

{% assign menu = linklists.category %}
{% for link in menu.links %}
    <h2>{{ link.title }}</h2>
    <ul class="list">
      {% for sub_link in link.links %}
        <li>
        {% assign c = sub_link.handle %}
        <a href="{{ sub_link.url }}">
          {{ sub_link.title }} <span>{{ collections[c].products_count }}</span>
        </a>
        </li>
      {% endfor %}
    </ul>
{% endfor %}

Of note: These collections are manual collections. I realize I could filter "Inventory < 1" at the collection-level if it was an automated collection, but it's not possible in this case.

0 Likes