How to conditionally display messages in add to cart popup?

We sell two separate categories of products on our store. One has the tag ‘Treatment Couches’ the other doesn’t.

We want to display one message if a customer adds a product with the ‘Treatment Couches’ tag to their cart, and a different one if they don’t.

If they have a Treatment Couch, it should only display the ‘Treatment Couch’ message.

Currently the add to cart pop up is showing a message for each product.

This is the code that is there at the moment:

{% for item in cart.items %}
{% if item.product.tags contains ‘Treatment Couches’ %}
{% if forloop.first %}

A member of the team will contact you to arrange delivery of your couch to suit you. Please refer to the product page for more details.

{%- else -%}

Orders placed before 1pm are dispatched the same day. Orders placed after 1pm on a Friday will be dispatched on the following Monday.

{% endif %}
{%endfor%}

Hi @PortRobot ,

You can try the following code:

{% assign check = 0 %}

{% for item in cart.items %}

{% if item.product.tags contains ‘Treatment Couches’ %}

{% assign check = 1 %}

{% break %}

{% endif %}

{% endfor %}

{% if check == 1 %}

A member of the team will contact you to arrange delivery of your couch to suit you. Please refer to the product page for more details.

{% else %}

Orders placed before 1pm are dispatched the same day. Orders placed after 1pm on a Friday will be dispatched on the following Monday.

{% endif %}

Thanks @LitExtension this worked perfectly!

Another semi-related question, how do I change the title of the cart pop up to “Shopping Basket”, it is currently “Shopping Cart”

Hi @PortRobot ,

Can you send me the name of the theme you are using or your store link. I will check it.

Hi @LitExtension , I managed to find it, but thanks

Hello,

If you want to solve this issue without any changes in the theme try to use

Product Warnings on Checkout . It would be great to show the warning only for products that are different from others. There is also a line item property in the app that is displayed on the cart page after the warning was accepted.