How can I display a message for multiple vendor items in a cart?

Hello,

We sell items from multiple vendors and would like to be able to show a message on the cart page if the items in the cart are from different vendors. How would this be possible?

Hello @giveitalabel you can contact me if you need the following customized for you, contact info in sig.

Always backup themes before changing code.

Try something like the following, which may need tweaking

{% assign multiple_vendors = false %}
{% assign current_vendor = cart.items.first.vendor %}
{%- for item in cart.items -%}
 {% if current_vendor != item.vendor %}{% assign multiple_vendors = true%} {%break%}{% endif %}
 {% assign current_vendor = item.vendor %}
{%- endfor -%}

it may be items.first.product.vendor instead of items.first.vendor

You’d place the code in the relevant area in the themes cart template, or for OS2.0 theme use a liquid block|section.

Advanced note: yes it could probably be done cleaner with the map filter and an if condition instead of a forloop but this is simpler for most people.