How can I change the logic of my filters in Shopify by availability?

128 Views Asked by At

For example, when I select Out of stock, I need to display products that have no sizes in stock at all. At the moment the products that have one size out of stock are displayed.

Can you please tell me if this is possible? If yes, then in theory how ?

I tried looking for the filtering logic in my theme code, but it seems to be handled through the shopify API.

1

There are 1 best solutions below

0
João Gervas On

Yes, it is possible to filter out products that are completely out of stock in Shopify. Here’s some overview points of how you could approach this:

  • Product Availability: You can use the availability attribute of a product or variant to check if it’s in stock1.

  • Liquid Code: In your theme’s Liquid code, you can add a conditional statement to check if a product is available before displaying it2.

Here is an example, where the {% if product.available %} line checks if the product is in stock. If it is, the product is displayed. If not, the product is skipped.

{% for product in collections.all.products %}
  {% if product.available %}
    <!-- Your code to display the product -->
  {% endif %}
{% endfor %}
  • Shopify API: If the filtering logic is handled through the Shopify API, you might need to modify the API calls to include the availability status. The Shopify API provides a status field that can be used to identify, filter, and manage products based on their current status: draft, active, or archived3.

  • Apps: There are also apps available, like “Nada: Sort & Hide Out Of Stock”, that can automatically hide sold-out products4.

These are just general guidelines. The exact implementation might vary depending on your specific theme and setup.