Custom message in order confirmation email based on product variant

Highlighted
Tourist
16 0 1

I would like to be able to add some liquid code to the order confirmation email that displays a sentence of text with a link when a certain product variant is ordered. I have an eBook variant and when it's ordered, I want to include a link insturcting how to view the different formats.

Can someone point me in the direction of the correct liquid formula/variable for this? Once I get a start, I can usually figure out the Liquid code and where to insert it.

It would be something like this:

If ebook variant is ordered, display xxxxxlink

end if

 

0 Likes
Highlighted
Shopify Partner
1838 176 675

Hi David,

If your variant title is "Ebook" then you'd need to edit the Settings > Notifications > Order confirmation email template and inside the line items loop, add this bit of code with whatever you see fit in between the condition:

{% if line.variant.title == 'Ebook' %}
  Display download instructions here...
{% endif %}

It is important this be added within the line items loop because a customer could order several e-books and each line should display download instruction links.

In case you do not want to display this on the line item level I can provide you with another code bit that would achieve the same but outside of the line ite loop.

Hope this helps.

I turn coffee in to code - since 1998
0 Likes
Highlighted
Tourist
16 0 1

Thanks I tried this and it displayed on all my orders, even without the eBook. I also tried it using variant SKU. Maybe I'm inserting in the wrong place. Can you describe what you mean by the "line item loop?" I actually don't want this to be next to the item toward the bottom of confirmation where the products are listed as line items for fear they will not see it. I want it listed in the top part of the confirmation after the "Thank you" and the contingent shipping text. I want it above the line where the "Order Summary" starts. Look below:

{% capture email_title %}Thank you for your purchase! {% endcapture %}
{% capture email_body %}
  {% if requires_shipping %}
    Hi {{ customer.first_name }}, we're getting your order ready. We will notify you when it ships.
  {% endif %} 

<br />
<br />

{% if line.variant.title == ‘Ebook’ %}
eBook Install/Viewing Instructions: https://www.amandavernon.com/ebookinstructions
{% endif %}

{% endif %}
{% endcapture %}

When I did this or used the SKU code or even used the "contains" operator, it always displayed this even when someone only ordered paperback book.

Do you see any issues? I'd love to customize several products' confirmation messages.

0 Likes
Highlighted
Shopify Partner
1838 176 675

Okay, in that case you want to find the line

<p>{{ email_body }}</p>

And right beneath that add this

{% assign includes_ebook = false %}
{% for line in subtotal_line_items %}
  {% if line.variant.title == 'Ebook' %}{% assign includes_ebook = true %}{% endif %}
{% endfor %}

{% if includes_ebook == true %}
  <p>Display download instructions.</p>
{% endif %}

Now I say below the line I mention above because you were adding it too soon above the HTML document.

Hope this helps!

I turn coffee in to code - since 1998
0 Likes
Highlighted
Tourist
16 0 1

I think I'm confused by this sentence: Now I say below the line I mention above because you were adding it too soon above the HTML document.

But I do want the link above the body...I want it below the line about shipping. See image below:

https://drive.google.com/open?id=1uKCk4cad7GKzmXtDJCiSurhWcMnM0SvC

From what you listed it seems like it would be down below in the summary.

Also, why doesn't your original code work? it seems simple...if this...display that. Why is the false part necessary? Why do you also have to say what happens if false.

0 Likes
Highlighted
Shopify Partner
1838 176 675

That's where it will be following the instructions of my previous post.

I turn coffee in to code - since 1998
0 Likes
Highlighted
Tourist
16 0 1

I'm sorry, I'm still confused. Are you saying to enter the first code above (in the location I had it) and the 2nd code you gave beneath this line: <p>{{ email_body }}</p>

 

0 Likes
Highlighted
Shopify Partner
1838 176 675

No, do not add the first code at all - it won't work in that location. And no worries if it's confusing - it is 1AM here and I am probably confusing everyone by now ;-)

Only add the second code in the location I mention in my second post which is right after the

<p>{{ email_body }}</p>

Above bit is already in the template so you can Ctrl+F to find it.

I turn coffee in to code - since 1998
0 Likes
Highlighted
Tourist
16 0 1

But entering the code in that body location will put the instruction link down in the body right? I want it in the top location under the shipping line that I showed you (above the view your order button.

 

 

0 Likes
Highlighted
Shopify Partner
1838 176 675

It will be here...

I turn coffee in to code - since 1998
0 Likes