Order confirmation if statement not working

I am looking to edit my order confirmation and have a specific block of text display if the item ordered is for a specific sku. We have one product with two different variants and I am trying to add some text for one of them specifically.

{% if current_variant.sku == 'THE_SKU_IS_HERE %}> text text text> > {% endif %}
For some reason, it’s not working. Any suggestions as to what I am doing wrong here?

{{ current_variant.sku }} isn’t printing anything either.

At minimum, your example code is missing the matching single quote around THE SKU IS HERE. It’s a tiny missing ', hard to see.

If there’s still an issue, how are you defining current_variant?

You’ll need something like this before the logic:

{%- assign current_variant = product.selected_or_first_available_variant -%}

Here’s a good article with a few ways to dig variants out of products.

1 Like

Thank you so much for the reply.

So I adjusted for that article and ended up with the following:

{%- assign current_variant = product.selected_or_first_available_variant -%}

{% if current_variant.sku == ‘G2-SN-102021’ %}
text text text
{% endif %}

But for some reason that still isn’t working.

The next thing I’d do is “assert positive control” and prove to yourself that you’re editing what you think you are.

Setting the if/then aside for a moment, can you get something simple to appear in the place you want, like a pair of H1 tags?

I’m HERE!

If that works, can you replace the message with the SKU, like so?

{%- assign current_variant = product.selected_or_first_available_variant -%}

{{ current_variant.sku }}

Also– just realized you’re on the order confirmation page. The example to lookup the product assumes you have a single product already defined. You might need to dig through the order:

{% for product in order.products %}
  {% for variant in product.variants %}
{% if variant.sku == 'G2-SN-102021' %}
text text text
     {% endif %}
  {% endfor %}
{% endfor %} 

If it’s in customer order, you can use this code:

{% if line_item.sku == 'THE_SKU_IS_HERE %}

text text text {% endif %}

Refer https://github.com/Shopify/dawn/blob/main/templates/customers/order.liquid#L119

Or https://shopify.dev/api/liquid/objects/line_item#line_item-sku

Hope it helps!