Varying 'Order Confirmation' email based on product title and variation

New Member
3 0 0

I'm trying to achieve a seemingly simple task and following the Liquid documentation, but am running into a brick wall: all I want to do is generate a different "Order Confirmation" email depending on which product variant a user purchases from my store (based on the nature of my products, a user would only ever be purchasing one product/variant combination at once). Here's the code I'm using:

{% if line.title == 'PRODUCT1' %}

<HTML EMAIL MESSAGE 1>

{% elsif line.title == 'PRODUCT2' %}

<HTML EMAIL MESSAGE 2>

{% else %}

<HTML EMAIL MESSAGE 3>

{% endif %}

My understanding from the documentation is that line.title should give me the product title with a " - " and the variant title. But regardless of which 'product - variant' I do a test order for, I end up with the email for the ELSE condition. Is something wrong in my code?

0 Likes
Highlighted
Tourist
9 0 1

Hi Vanessa,

If I'm reading it correctly, you would want customers to get specific order confirmations for a specific product? 

so you could use 

{% if item.product.type == 'dinosaur' %}
  ... email content for dinosaur product types here ...
{% else %}
  ... email content for other product types here ...
{% endif %}

Additional information pertaining your topic of different email templates for different products can be found here: 

https://ecommerce.shopify.com/c/shopify-discussion/t/different-confirmation-emails-based-on-product-...

https://ecommerce.shopify.com/c/ecommerce-design/t/adding-product-specific-logic-to-order-confirmati...

Hope that helps,

Alan

 

0 Likes
New Member
3 0 0

Thanks Alan! I managed to figure out a working solution with a friend in the meantime, so I haven't tested your approach, but what I'm using now (and is working quite nicely) is:

{% for line in line_items %}
{% if line.title == 'Product - Variant1' %}
...email message 1...
{% elsif line.title == 'Product - Variant2' %}
...email message 2...
{% else %}
...email message 3...
{% endif %}
{% endfor %}

 

0 Likes
New Member
2 0 0

I am trying to achieve the same results as Vanessa and I tried that code with no luck. Any suggestions on what could work?

0 Likes
Shopify Partner
2 0 0

I can confirm Vanessa's method works for changing the order confirmation email based on the product. I tweaked it a little to use logical operator contains but remember Keyword is case-sensitive.

 

{% for line in line_items %}
{% if line.title contains "Keyword" %}
...email message 1...
{% else %}
...email message 2...
{% endif %}
{% endfor %}

 

0 Likes