Coding condition based on the amount of Product Variants

Hello,

I managed to make sku appear on the product cards. But I need help filtering that a bit.

My goal is to only show the sku on products without variants.

I’ve been trying to work this out with the following code. But It’s not working.

{% if product.has_only_default_variant %} ID nr. {{ card_product.variants[0].sku }} {% endif %}

I would appreciate any help :slightly_smiling_face:

Some things I notice here:

First of all, is no valid HTML element and should be

Second, did you declare card_product as a variable before? If not, this is not an object you have access to and should be changed to product.

Third, if has_only_default_variant is true, then I think product.variants is empty. That means product.variants[0] won’t return anything. (But not 100% sure)