Custom if/else for order confirmation email

Highlighted
New Member
1 0 0

I need to customize the order confirmation email to include a series of instructions if they purchased a particular product. I don't think I have done in the simplest way. I think it would probably be better if I used a product title tag? 

{% if product.variant == '2016BookClub' %}
Welcome and click here to join the conversation

{% endif %}

0 Likes
Shopify Staff
Shopify Staff
77 0 17

Hey Lisa!

Wesley here from the shopify Guru team!

For email notifications, it is better to only use the vairibles that are found in the list of variables specifically for the email templates. 

You can check that list out here: https://docs.shopify.com/manual/sell-online/notifications/email-variables

In this case, I would probably use the {{ line.items }} variable. To put that into a conditional statement it would be:

{% for line in line_items %} 
{% if line.title contains 'Example product' %}
This message is for Example Product
{% endif %}
{% endfor %}

Let us know if you have any questions!

Cheers,

Wesley

1 Like
New Member
6 0 0

I'm looking for something similar, but is it possible to use an else condition as well?

0 Likes
Excursionist
18 0 1

Wesley, what about this link?  The order's line_item.product returns the product of the line item.  The product object should include numerous attributes.  I recently used line.product.tags to loop through each line item's tags and display conditional content (for a shipping delay) under the line item's product title (in the order-confirmation email).

https://help.shopify.com/en/themes/liquid/objects/line_item#line_item-product

0 Likes
Excursionist
18 0 1

Lisa, if this is for only one product, you could check the handle or the product ID.  As I mentioned above, I recently checked for a product tag because I needed to show the content on a handful of products.  I used the admin panel's product search with the checkboxes on the left to apply the tag.

0 Likes