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 %}
Solved! Go to the solution
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
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 %}
User | Count |
---|---|
681 | |
138 | |
104 | |
63 | |
36 |