Order confirmation if statement not working

Doug29
New Member
2 0 0
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.
0 Likes
cyclic_science
Tourist
6 0 1

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.

Doug29
New Member
2 0 0

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.

0 Likes
cyclic_science
Tourist
6 0 1

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? <h1>I'm HERE!</h1> If that works, can you replace the message with the SKU, like so?

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

<h1>{{ current_variant.sku }}</h1>

0 Likes
cyclic_science
Tourist
6 0 1

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 %} 

 

0 Likes

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!

Start to sell on Amazon, Etsy, eBay, Facebook... quickly with bulk listing tool, real-time sync & smart order management. Use LitCommerce free for 1-year!
0 Likes