Hide Sold-Out Products On Shopify Collection Page

Tanz - Tanz

Why Hide Sold-Out Products?

Displaying out-of-stock items clutters collections, frustrates buyers, and risks SEO issues like 404s. Hiding them improves user experience, boosts conversion, and keeps your storefront fresh and professional.

⚠️ Heads-up Before You Start

Editing your Shopify theme code requires a basic understanding of HTML, CSS, and JavaScript. Always duplicate your theme to create a backup before making any changes.

Method 1: Use Shopify’s Smart Collection Inventory Filter

From your Shopify admin:

  • Go to → Products → Collections
  • Open or create an Smart Collection
  • Under Conditions, select: Inventory stock > 0
  • Click Save

Now any sold-out product is automatically removed from the collection and reappears when restocked. But Only works for smart/automated collections—not manual ones.

Method 2: Use Liquid Code In Collection Template

From your Shopify admin:

  • Go to → Themes → Actions → Edit code
  • Open sections/main-collection-product-grid.liquid file
  • Locate the product loop:
Copy

{%- for product in collection.products -%}
  • Replace it with the code block below 
  • Save and preview the collection page
Copy

{%- for product in collection.products -%}
  {% assign total_stock = 0 %}
  {% for variant in product.variants %}
    {% assign total_stock = total_stock | plus: variant.inventory_quantity %}
  {% endfor %}

  {%- if total_stock > 0 -%}
    {% assign lazy_load = false %}
    {%- if forloop.index > 2 -%}
      {%- assign lazy_load = true -%}
    {%- endif -%}
    <li
      class="grid__item
      {% if settings.animations_reveal_on_scroll %} 
        scroll-trigger animate--slide-in
        data-cascade
        style="--animation-order: {{ forloop.index }};"
      {% endif %}
    >
      {% render 'card-product',
        card_product: product,
        media_aspect_ratio: section.settings.image_ratio,
        image_shape: section.settings.image_shape,
        show_secondary_image: section.settings.show_secondary_image,
        show_vendor: section.settings.show_vendor,
        show_rating: section.settings.show_rating,
        lazy_load: lazy_load,
        skip_styles: skip_card_product_styles,
        quick_add: section.settings.quick_add,
        section_id: section.id
      %}
    </li>
    {%- assign skip_card_product_styles = true -%}
  {%- endif -%}
{%- endfor -%}

This sums inventory across variants and only displays products with stock. Nested loops can slow down very large catalogs. Use Method 1 if you have thousands of products.

Real-World Insight

Merchants report that using inventory filters or Liquid tweaks to hide sold-out products keeps their storefronts clean and improved UX—without relying on apps or risking SEO.

Final Thoughts

Choose Smart Collection filters for quick, no-code results, or Liquid code tweaks for nuanced control. Both approaches keep your storefront polished, inventory-accurate, and SEO-safe—no 3rd-party apps needed.

Back to blog