I figured this would be simple but apparently not (for me, anyway).

  • I have a product with two variants (orange and yellow).
  • I have a page that lists all the available products.
  • On that page, both variants appear. I really just need one and users can select their variant from a drop-down on the checkout page.

What I've got:

{# get the products from the categories #}
{% set products = craft.commerce.products.type('shirts,shorts') %}

{# show the product main image and link to the product page #}
<a href="{{ product.url }}">
    {% if product|length %}
        {% set asset = product.productHeroImage.first() %}
    <img src="{{ asset.url }}">{% endif %}

I did try {% set products = craft.commerce.products.defaultVariant.type('shirts,shorts') %} but get the same results.

1 Answer 1


OK, so this did have a really simple solution. Just use isDefault.

{% if variant.isDefault %}Show the product{% endif %}

Works like a charm.

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.