How to display cart messages based on specific product tags?

Topic summary

A user encountered an issue where a cart message intended only for products tagged ‘Preorder’ was appearing under all cart items and displaying multiple times. The problem stemmed from a nested {% for item in cart.items %} loop in the cart template code.

Root Cause:
The user had inadvertently created duplicate for loops, causing the conditional check to run multiple times and apply the message to all products regardless of their tags.

Solution Provided:
Multiple respondents identified the issue and recommended removing the extra/nested for loop. Specifically, they advised deleting the redundant {% for item in cart.items %} and {% endfor %} tags surrounding the conditional statement.

Alternative Approach:
One participant suggested using product metafields instead of tags to display cart-specific messages, providing a YouTube tutorial link as reference.

Status: The technical issue was resolved through community troubleshooting, with the nested loop removal being the accepted fix.

Summarized with AI on October 28. AI used: claude-sonnet-4-5-20250929.

Hi everyone,

I have added code to my cart template to display a message if the product has the tag ‘Preorder’:

{% if item.product.tags contains ‘Preorder’%}

*This product is a preorder and will ship in 2-3 weeks - payment due at time of order. All items in cart will ship together*

{% endif %}

Problem is, once a preorder item is added to the cart, every item displays the message, even if that product doesn’t have the preorder tag. It’s also now displaying it multiple times under one product? Where am I going wrong please?

Hello @Nittiyarns ,

Can you please share the code of your cart template file ?

Thanks for your reply!

Show More

<tr>

<th>

</th>

<th colspan="2">

{{ 'cart.label.product' | t }}

</th>

<th>

{{ 'cart.label.price' | t }}

</th>

<th>

{{ 'cart.label.quantity' | t }}

</th>

<th>

{{ 'cart.label.total' | t }}

</th>

</tr>

<tr>

<td>

</td>

<td>

</td>

<td>

{{ item.product.title }} {% if item.quantity > 1 %} {{ 'cart.label.quantity' | t }}(x{{ item.quantity }}) {% endif %} 
{% unless item.variant.title contains 'Default' %}{% for option in item.product.options %} {{ option }}: {{ item.variant.options[forloop.index0] }}
{% endfor %}
{% endunless %} {%- assign property_size = item.properties | size -%} {% if property_size > 0 %}{%- comment -%}{% for p in item.properties %} {% unless p.last == blank %} {{ p.first }}: {% comment %}Check if there was an uploaded file associated{% endcomment %} {% if p.last contains '/uploads/' %} {{ p.last | split: '/' | last }} {% else %}{{ p.last }}{% endif %} {% endunless %} {% endfor %}{%- endcomment -%}{%- for p in item.properties -%} {%- unless p.last == blank -%}- {{ p.first }}: {%- comment -%} Check if there was an uploaded file associated {%- endcomment -%} {%- if p.last contains "uploads" -%} Uploaded File {%- else -%} {{ p.last }} {%- endif -%} {%- endunless -%} {%- endfor -%} 
{% endif %} {% for item in cart.items %} {% if item.product.tags contains 'Preorder'%}

<b>_*This product is a preorder and will ship in 2-3 weeks - payment due at time of order. All items in cart will ship together*_</b>

{% endif %} {% endfor %}
{{ item.price | money }}
{% for discount in item.discounts %}
{{ discount.title }}
{% endfor %}

</td>

<td>

{{ item.price | money }}
{% for discount in item.discounts %}
{{ discount.title }}
{% endfor %}

</td>

<td>

</td>

<td>

{% if item.original_line_price != item.line_price %}
~~{{ item.original_line_price | money }}~~
{% endif %}{{ item.line_price | money }}
{% for discount in item.discounts %}{{ discount.title }}
{% endfor %}

</td>

</tr>

</table>
{{ 'cart.general.continue_shopping' | t}}

{% if settings.show_multiple_currencies and settings.currency_opt == 'script' and section.settings.currency_notes != blank %}{{ section.settings.currency_notes | replace: '[selected.currency]','' | replace: '[shop.currency]',shop.currency }}
{% endif %} {% endcapture %} {% capture cartSummery %}
{{ 'cart.general.subtotal' | t }} {{ cart.total_price | money }}
{% if section.settings.display_saving %} {% assign savings = 0 %} {% for item in cart.items %} {% if item.variant.compare_at_price > item.variant.price %} {% assign difference = item.variant.compare_at_price | minus: item.line_price %} {% assign savings = savings | plus: difference %} {% assign actualSaving = savings | times: item.quantity %} {% elsif item.original_line_price > item.line_price %} {% assign difference = item.original_line_price | minus: item.line_price %} {% assign savings = savings | plus: difference %} {% assign actualSaving = savings | times: item.quantity %} {% endif %} {% endfor %} {% if savings > 0 %}{{ 'cart.general.savings' | t }}: {{ actualSaving | money }}
{% endif %} {% endif %} {%- if settings.free_ship_cartpage and settings.free_ship != blank and settings.free_ship_msg != blank -%} {%- assign shipProd = all_products[settings.free_ship] -%}

{{settings.free_ship_msg | replace: '$','' }}

{{settings.got_free_ship }}

{%- endif -%} {%- if section.settings.shippingTax -%}

{{ 'cart.general.shipping_at_checkout' | t }}

{% include 'zip-cart-widget' %} {%- endif -%} {%- if settings.terms_checkbox -%}

{%- endif -%} {% if section.settings.additionalCheckout and additional_checkout_buttons %}{{ content_for_additional_checkout_buttons }}
{% endif %} {%- if section.settings.payment != blank -%}
{%- endif -%}
{% endcapture %} {%- if settings.breadcrumb_pg -%}{%- include 'breadcrumb' -%}{%- else -%}
{%- endif -%}{% if cart.item_count > 0 %}# {{ 'cart.general.title' | t }}{% else %}#### {{ 'cart.general.empty' | t }}{{ 'cart.general.continue_shopping' | t}} 
{% endif %}
{% if section.settings.shipping_calculator %} {% endif %} {% schema %} { "name": "Cart page", "settings": [ { "type": "select", "id": "layout", "label": "layout Syle", "default": "style1", "options": [ { "value": "style1", "label": "Style 1" }, { "value": "style2", "label": "style 2" } ] }, { "type": "checkbox", "id": "cart_notes_enable", "label": "Enable Cart Notes", "default": true }, { "type": "checkbox", "id": "display_saving", "label": "Display Total Savings?", "default": true }, { "type": "checkbox", "id": "shippingTax", "label": "Display Shipping & Tax Message below Subtotal?", "default": true }, { "type": "checkbox", "id": "additionalCheckout", "label": "Display Additional Checkout Buttons", "default": true }, { "type": "header", "content": "Currency Note" }, { "type": "textarea", "id": "currency_notes", "label": "Notes", "default": "We processes all orders in [shop.currency]. While the content of your cart is currently displayed in [selected.currency], the checkout will use [shop.currency] at the most current exchange rate.", "info": "Use [shop.currency] for default currency and [selected.currency] for adtivated currency on store." }, { "type": "header", "content": "Secure and Payment Badge" }, { "type": "image_picker", "id": "payment", "label": "Image" }, { "type": "header", "content": "Shipping Rates Calculator" }, { "type": "checkbox", "id": "shipping_calculator", "label": "Show the shipping calculator?", "default": true }, { "type": "text", "id": "shipping_calculator_heading", "label": "Heading text", "default": "Get shipping estimates" }, { "type": "text", "id": "shipping_calculator_default_country", "label": "Default country selection", "default": "United States" }, { "type": "paragraph", "content": "If your customer is logged-in, the country in his default shipping address will be selected. If you are not sure about the spelling to use here, refer to the first checkout page." }, { "type": "text", "id": "shipping_calculator_submit_button_label", "label": "Submit button label", "default": "Calculate shipping" }, { "type": "text", "id": "shipping_calculator_submit_button_label_disabled", "label": "Submit button label when calculating", "default": "Calculating..." }, { "type": "header", "content": "Gift Wrapping" }, { "type": "paragraph", "content": "[How to add gift wrapping?](https:/\/\www.adornthemes.com/\knowledge-base/\how-to-add-gift-wrapping)" }, { "type": "checkbox", "id": "enable_giftcard", "label": "Enable gift wrap option", "default": false }, { "type": "product", "id": "gift_product", "label": "Select Gift Wrap Product" }, { "type": "select", "id": "gift_wrap_optin", "label": "Select Gift Rate", "default": "flat-rate", "options": [ { "label": "Flat rate all products", "value": "flat-rate" }, { "label": "Rate per product", "value": "diffrent-rate" } ] }, { "type": "textarea", "id": "gift-wrap-text", "label": "Gift wrapping text 1", "default": "Add a Gift Wrap to your orders" }, { "type": "text", "id": "gift-wrap-msg", "label": "Gift wrapping Message", "default": "Gift Message Note:" } ] } {% endschema %} ```

{% for item in cart.items %} // remove this line

{% if item.product.tags contains ‘Preorder’%}

*This product is a preorder and will ship in 2-3 weeks - payment due at time of order. All items in cart will ship together*

{% endif %}

{% endfor %} // remove this line.

Remove extra for loop that you added and then check.

Hi @Nittiyarns ,

Please remove code: https://i.imgur.com/WaTZPgm.png

You have nested loop and it gives this error.

Hope it clear to you.

hi @Nittiyarns ,

I know its very late posting this to help anyone looking for same solution, we can create metafield at product page and show it at cart page.