How to add a custom alert at checkout for multiple vendors?

Hi, wanting to know if there’s anybody who can help around adding some code to create a custom alert at checkout.

We are launching our business and have our range of products, but they are being shipped from 5 separate vendors and locations, we are UK based and 3 products are coming from inside the UK and 2 are coming from outside of the UK.

I want to alert a customer who has put multiple items in their basket, that if they are from separate vendors, their order will arrive separately in two different packages BEFORE they purchase from us.

Is there code I can add to the checkout to bring up this alert before a customer orders from us?

The rules would be:

IF there is products from more than one Product Vendor in the cart, show this message: ‘These items are being shipped from different warehouses and will arrive to you in separate packages.’

and

IF items in the basket are from X & Y Product Vendors ‘These items are being shipped from Europe and will take 5-10 working days to arrive’

Is there some code I can add to the checkout liquid to flag this message when a customer begins checkout and before they pay? It would be great if the text could show up in the colour #e7816d.

Cheers

Are you running a Shopify Plus store? You can only make edits to checkout.liquid if you do.

Not running a Shopify Plus store but using a custom theme

Yeah unfortunately you cannot edit the checkout unless you’re on a Shopify Plus store. You can add some conditions to the Additional Scripts section in Settings > Checkout, but those will only appear on the Order Status page which comes after you complete your purchase.

All stores can do this at the CART phase of the checkout flow

Crudely:

{%- assign vendor_mismatch = false -%}
{%- assign vendor_mismatch_message = "Your cart has items from different vendors, restrictions apply" -%}
{%- assign vendor_mismatch_message_text_color = "#e7816d" -%}

{%- assign current_vendor = "" -%}
{%- for item in cart.items -%}
	{%- if current_vendor != item.product.vendor -%}
		{%- assign vendor_mismatch = true -%}
		{%- break -%}
	{%- endif -%}
	{%- assign current_vendor = item.vendor -%}
{%- endfor -%}

{%- if vendor_mismatch -%}
	

{{ vendor_mismatch_message }}

{%- endif -%}
1 Like

If I wanted to add a custom message to the Cart based on whether or not it contained products in a certain Collection, how would I go about using your code to achieve that? I want to add a specific message with link if the Cart contents include items from a specific Collection. Could also be done via Product Type.

Product type would probably be easiest. When you’re in the forloop for the line items you can assign a variable to be true if any of your products matches your product type:

{% assign display_message = false %}
{% for line_item in cart.line_items %}

    {% if line_item.product.type == "Your Product Type" %}

        {% assign display_message = true %}

    {% endif %}

{% endfor %}

{% if display_message %}

Here's the message you want to show the customer

{% endif %}
1 Like

@Ninthony thanks!

{% assign display_message = false %}
{% for line_item in cart.line_items %}

    {% if line_item.product.type == "Your Product Type" %}

        {% assign display_message = true %}

    {% endif %}

{% endfor %}

{% if display_message %}

Here's the message you want to show the customer

{% endif %}

If anyone is trying to implement this using a Custom Liquid block on the Cart template editor, change all instances of

line_item

to

item

Thanks to @dolby_edmos on this post.

Just so you know, it doesn’t matter what keyword you use as long as it’s referenced further down the file correctly:

{% assign display_message = false %}
{% for spaghetti in cart.line_items %}

    {% if spaghetti.product.type == "Your Product Type" %}

        {% assign display_message = true %}

    {% endif %}

{% endfor %}

In the for loop you’re saying “For every instance in cart.line_items run the loop.” What you use as a keyword before the “in” in the forloop declaration will be associated with the object you’re looping through.

{% for dog in collection.products %}
 {{ dog.title }}
{% endfor %}

//outputs all the titles of your products in the current collection
// it just makes more sense to use a keyword like "products"

{% for product in collection.products %}
 {{ product.title }}
{% endfor %}

// it outputs the same thing
{% assign display_message = false %}
{% for spaghetti in cart.line_items %}

    {% if spaghetti.product.type == "Your Product Type" %}

        {% assign display_message = true %}

    {% endif %}

{% endfor %}

In the for loop you’re saying “For every instance in cart.line_items run the loop.” What you use as a keyword before the “in” in the forloop declaration will be associated with the object you’re looping through.

{% for dog in collection.products %}
 {{ dog.title }}
{% endfor %}

//outputs all the titles of your products in the current collection
// it just makes more sense to use a keyword like "products"

{% for product in collection.products %}
 {{ product.title }}
{% endfor %}

// it outputs the same thing

Good to know. It must have been the edit from cart.line_items to cart.items then. The original code did not work until I made edits. I was obviously not clear on what affected the functionality. Much appreciated.