Is it possible to filter a collection by product.available

New Member
1 0 0

Is there anyway to hide items where product.available is falsey

Returns true if a product is available for purchase. Returns false if all of the products variants' inventory_quantity values are zero or less, and their inventory_policy is not set to "Allow users to purchase this item, even if it is no longer in stock."

The following properties are available for filtering on auto collections

Product title
Product type
Product vendor
Product price
Product tag
Compare at price
Inventory stock
Variant’s title
Compare at price

Inventory Stock > 0 doesn't cut it as some products are marked as "Continue selling when out of stock"

It's possible to hide the product in theme whilst iterating products in a collection

    {%- for product in collection.products -%}
      {%- if product.available %}
        {%- include 'product-grid-item' -%}
      {% endif %}
    {%- else -%}
      <div class="grid__item">
        <p>{{ 'collections.general.no_matches' | t }}</p>
    {%- endfor -%}

however that doesn't fix the pagination or collection product counts, e.g. there could be an entire empty page as all products on that page are unavailable.

New Member
3 0 0

Has a solution to this been found? I am looking to hide a product if that variant is out of stock.

39 5 10

Hey @jfigure, what I suggest is creating an automated collection where one of the conditions is that inventory quantity is greater than 0 and using that so you don't encounter pagination issues - or, employing a load more mechanic and bringing in the collection with JS, handling the filtering before it's rendered.

Unfortunately, this won't solve your "Continue selling when out of stock" problem, because those products having that setting will always show up as a available, so both the condition on the collection and the .available conditional in the code won't catch this.

This is a deliberate feature so that people can do exactly what you're doing but include products that are available for selling. I don't know what your other requirements are but I'd suggest aligning your use of "Continue selling when out of stock" with the purpose of the setting.