Skip to content

Instantly share code, notes, and snippets.

@cameroncowden
Created October 16, 2018 17:55
Show Gist options
  • Save cameroncowden/23bf2e2260a1a818e5db49365511f948 to your computer and use it in GitHub Desktop.
Save cameroncowden/23bf2e2260a1a818e5db49365511f948 to your computer and use it in GitHub Desktop.
A liquid snippet to sort products which are on sale and out of stock to the end of a shopify collection (per page)
{% assign remaining = products_per_page %}
{% for product in collection.products limit: products_per_page %}
{% if product.available and product.price >= product.compare_at_price_max %}
{% include 'partial--product' %}
{% assign remaining = remaining | minus: 1 %}
{% endif %}
{% endfor %}
{% for product in collection.products limit: products_per_page %}
{% if product.compare_at_price > product.price %}
{% if remaining > 0 %}
{% include 'partial--product' %}
{% assign remaining = remaining | minus: 1 %}
{% endif %}
{% endif %}
{% endfor %}
{% for product in collection.products limit: products_per_page %}
{% if product.available == false %}
{% if remaining > 0 %}
{% include 'partial--product' %}
{% assign remaining = remaining | minus: 1 %}
{% endif %}
{% endif %}
{% endfor %}
@audreysurfin
Copy link

Hi @cameroncowden,
Thank you for this snippet. I only have one problem with pagination. The snippet works but by page and not on the entire collection.
Do you have a solution for this situation?

Thank you very much
Audrey C.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment