Re: How can I modify the order confirmation email based on product's variant?

How can I modify the order confirmation email based on product's variant?

danny0103
Tourist
5 1 2

E.g 
I have products with two variants
Auto and Manual
When someone purchase the Auto variant, he should receive a certificate, and when someone purchase the Manual variant they should receive another certificate.
How can I make this work? 
Do I need some "if" code to place in the email?
I suppose there could be a workaround similar to this one ?!
https://community.shopify.com/c/technical-q-a/how-can-i-modify-the-order-confirmation-email-based-on...

Replies 3 (3)

tomnguyen1
Visitor
3 0 0

Yes, you can modify the order confirmation email based on the product's variant using an "if" statement or a similar conditional logic. Here are the general steps involved:

Identify the product variant: Determine how the product variant is stored in your system. This could be a custom field, a product attribute, or part of the product SKU.
Access the variant in your email template: In your order confirmation email template, use Liquid template language or a similar templating engine to access the product variant.
Implement conditional logic: Use an "if" statement or a similar conditional expression to check the product variant. Based on the variant, include the appropriate certificate information in the email.
Test your changes: Send a test order for each product variant to ensure that the correct certificate is included in the email.
Here's a simplified example using Liquid template language:

{% if product.variant.name == "Auto" %}
<p>You have purchased the Auto variant. Your certificate is attached.</p>
{% else %}
<p>You have purchased the Manual variant. Your certificate is attached.</p>
{% endif %}

In this example, product.variant.name is assumed to be the property that stores the product variant. You can replace it with the actual property used in your system.

Remember to replace the placeholder comments with the actual code or HTML to include the certificates in the email. You may also need to adjust the conditional logic based on how product variants are stored and accessed in your specific platform or system.

By following these steps and customizing the conditional logic to your specific requirements, you can effectively modify the order confirmation email based on the product's variant.

danny0103
Tourist
5 1 2

So, until now I was using this, depending on the product's name and it was working


{% assign certificate = false %}

{% for line in line_items %}
{% if line.title contains "Auto" %}
{% assign certificate = true %}
{% endif %}
{% endfor %}
{% if certificate %}
Here you can see the certificate
{% endif %}

However, now, that I have to change this depending on variants I tried this one but it seems I missed something because it's not working


{% assign certificate = false %}

{% for line in line.variant.title %}
{% if line.variant.title contains "Auto" %}
{% assign certificate = true %}
{% endif %}
{% endfor %}
{% if certificate %}
Here you can see the certificate
{% endif %}

So, I changed line.title with line.variant.title

Any idea or example I can use, using the variant name?

danny0103
Tourist
5 1 2

Tried this but it always sends the Manual variant email
{% if product.variant.name == "Auto" %}
<p>You have purchased the Auto variant. Your certificate is attached.</p>
{% else %}
<p>You have purchased the Manual variant. Your certificate is attached.</p>
{% endif %}