Sort filter descending order

Highlighted
New Member
21 0 0

Is there a way to have the sort filter return descending order instead of ascending?

Thanks for your time

0 Likes
Highlighted
New Member
1 0 0
            {% assign sorted_variants = product.variants | sort: "inventory_quantity" | reverse  %}
              {% for variant in sorted_variants %}
              {% if variant.inventory_quantity > 1 %}    
              <option value="{{ variant.price | money }}~^~{{ variant.id }}~^~{{ variant.inventory_quantity }}"> {{ variant.title }}</option>
              {% else %}
              {% assign outOfStock=true %}
              <option style="color:red" value="{{ variant.price | money }}~^~{{ variant.id }}~^~{{ variant.inventory_quantity }}"> {{ variant.title }}</option>
              {% endif %}
              {% endfor %}
0 Likes