Happening now! Shopify Community AMA: Building a Marketing Budget with 2H Media | Ask your marketing budget questions now!

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

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

giveitalabel
Shopify Partner
6 0 0

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?

 

Reply 1 (1)

PaulNewton
Shopify Partner
7722 678 1627

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.

 

 

Contact paull.newton+shopifyforum@gmail.com for the solutions you need


Save time & money ,Ask Questions The Smart Way


Problem Solved? ✔Accept and Like solutions to help future merchants

Answers powered by coffee Thank Paul with a Coffee for more answers or donate to eff.org