In Craft Commerce is it possible to order each product variant in the template, I would like to order by price ascending, I've tried the below but nothing is returned?

{% for purchasable in product.variants.order('price asc') %}

Below works but displays in order they were added:

{% for purchasable in product.variants %}

1 Answer 1


product.variants just returns an actual array of the variants, not an ElementCriteriaModel. So you can’t chain on additional params like order.

To get variants using custom parameters, you can do this:

{% set variants = craft.commerce.variants({
    product: product,
    order: 'price asc'
}) %}

{% for purchasable in variants %}
    // ...
{% endfor %}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.