Collection Loop limit and skipping out of stock product items

Solved
Highlighted
Shopify Partner
12 0 0

Hi - 

 

I have a collection on my home page with the loop limited to 4 and set to show only available products.

 

This collection contains 6 products, and is set to order manually.  

 

Here is the issue:

 

If the 4th product is out of stock then only 3 products show.  I really want it to skip any out of stock products and display the next available product.

 

This is the simple loop I have set up:

{% for product in collections.stocktestmanual.products limit:4 %}
{% if product.available %}
{{ product.title }}<br>
{% endif %}
{% endfor %}

 

Any ideas?

0 Likes
Highlighted

Success.

Shopify Partner
194 11 20
{% assign count = 0 %}
{% for product in collections.stocktestmanual.products %}
  {% if product.available %}
    {{ product.title }}<br>
    {% assign count = count | plus: 1 %}
  {% endif %}
  {% if count == 4 %}
    {% break %}
  {% endif %}
{% endfor %}
If helpful then please Like and Accept Solution.
Email: suhagiyajivan1992@gmail.com
Skype: jivan.suhagiya
Give a try to Shopify APP: https://apps.shopify.com/short-track
1 Like
Highlighted
Shopify Partner
12 0 0

Nice and simple - thanks!

0 Likes