craft.commerce.variants

How to get variants #

Usually you will only want to retrieve products, giving you access to their variants. Sometimes you might want to query for variants directly.

You can access your site’s variants from your templates via craft.commerce.variants It returns an ElementCriteriaModel object.

{% set variants = craft.commerce.variants.id(8376).first() %}

{{ variant.sku }} - {{ variant.salePrice }}

Parameters #

craft.commerce.variants supports the following parameters:

ID #

The variant’s element ID.

productId #

The product ID this variant belongs to.

sku #

The variant’s SKU

default #

Whether the variant is the product’s default variant

Accepts: boolean (true or false)

stock #

The stock amount

Accepts: integer

hasStock #

Whether the variant has unlimited stock or stock greater than zero.

Accepts: boolean (true or false)

Buy Craft Commerce

Craft Commerce site license

Includes

  • Developer support
  • One year of updates ($199/year for updates after that)
  • Craft Pro site license
Buy now for $999
Can I try before buying?

Absolutely. Just download it from the “Download” button in the site header and follow our installation instructions. You’ll have the full feature set to experiment with, without any restrictions, as long as you’re running it from a development, testing, or staging domain.

Will there be recurring/upgrade fees?

Each Commerce license comes with one year of updates. After that, you can unlock additional updates for $199 per year.

Can I use this on an existing Craft site?

Yes! And if you already have a Craft Pro license (or you don’t need one), you can purchase Craft Commerce directly from the Plugin Store or just leave the switch off that says “Include a Craft Pro license” in the purchase form.

Is Craft Pro required?

Craft Commerce does not require Craft Pro; it works perfectly fine on Craft Solo as well!

Can I try before buying?

Absolutely. Just download it from the “Download” button in the site header and follow our installation instructions. You’ll have the full feature set to experiment with, without any restrictions, as long as you’re running it from a development, testing, or staging domain.

Will there be recurring/upgrade fees?

Each Commerce license comes with one year of updates. After that, you can unlock additional updates for $199 per year.

Can I use this on an existing Craft site?

Yes! And if you already have a Craft Pro license (or you don’t need one), you can purchase Craft Commerce directly from the Plugin Store or just leave the switch off that says “Include a Craft Pro license” in the purchase form.

Is Craft Pro required?

Craft Commerce does not require Craft Pro; it works perfectly fine on Craft Solo as well!