Add note to confirmation email based on vendor

Solved
Highlighted
Tourist
12 0 3

I have 2 vendors in my shop. If products are purchase from Vendor A I need to display message A. Additionally if product(s) are purchased from Vendor B I need to show message B. I almost have this working. Currently my messages are duplicated per items in cart. So if 2 products are purchased from Vendor A, then that message is shown twice. How do I limit it to one display? I'm certain it has to do with my first line, but I don't know enough liquid to figure it out.

 

 

{% for line in line_items %} 
{% if line.product.vendor contains 'Vendor A' %}

Vendor A Message

{% elsif line.product.vendor contains 'Vendor B' %}

Vendor B Message

{% else %}
Thank you for your order!
{% endif %}
{% endfor %}

 

  

0 Likes
Highlighted
Shopify Partner
67 15 16

Hello @webaddict78 , what if order contains line item products with both the vendors A and B?

If it will be one vendor always per order items, then below code will work

{% if line_items.first.product.vendor contains 'Vendor A' %}

Vendor A Message

{% elsif line_items.first.product.vendor contains 'Vendor B' %}

Vendor B Message

{% else %}
Thank you for your order!
{% endif %}

 

Enjoy

0 Likes
Highlighted
Tourist
12 0 3

Orders could be multiple from each vendor. So, an order might be two from A and one from B.

I fee like it needs to be "if any" item contains vendor..., but I'm not sure that's a possibility. I'm still googling.

0 Likes
Highlighted
Shopify Partner
67 15 16

This is an accepted solution.

@webaddict78  You can grab unique list of vendors for all order items and then generate your message by checking on that list

 

{% assign order_vendors = line_items | map: "vendor" | uniq %} 
{% if order_vendors contains 'Vendor A' && order_vendors contains 'Vendor B' %}

Vendor AB Message

{% elsif order_vendors contains 'Vendor A' %}

Vendor A Message

{% elsif order_vendors contains 'Vendor B' %}

Vendor B Message

{% else %}
Thank you for your order!
{% endif %}

  

0 Likes
Highlighted
Tourist
12 0 3

Thank you so much! I was just about to play around with "assign".