Show a banner based on cart contents
Show a promo message only when the cart contains a certain product, or once the cart total reaches an amount, with Custom HTML.
Last updated
Show a message in the cart only when it's relevant: "Buy a second pair of jeans and get 15% off" when exactly one denim item is in the cart, or "Your order ships with free express delivery" once the cart passes an amount. This recipe uses Custom HTML (Professional plan), and the AI generator can write it for you.
Add the banner with the AI generator
Pick a position
Go to Cart designerCustom HTML. Above line items or Top of cart summary work well for promo messages. Tick Enable on that card.
Describe the banner and the condition
In Generate custom HTML by prompting our AI, describe the text, the look and exactly when to show it. Examples:
- "Show a black banner with white text 'Buy a second denim and get 15% off.' only when the cart contains exactly one item with 'denim' in the product title and its quantity is 1."
- "Show 'Your order ships with free express delivery' in a green box when the cart total is 200 or more."
- "Show 'Free care kit with every sofa' when any item in the cart has the product type 'Sofa'."
Tick Extended thinking (for complex tasks), then click Generate HTML.
Save and test
Click Save. On your store, add and remove matching products and check that the banner appears and disappears as you expect.
Example code: one denim item in the cart
If you prefer to paste code, this version works with Shadow DOM on or off and keeps working when the cart is emptied and refilled:
<div id="denim-promo-banner" class="tw-hidden tw-bg-black tw-text-white tw-text-center tw-py-3 tw-px-4 tw-mb-4 tw-rounded-md">
<p class="tw-m-0">Buy a second denim and get 15% off.</p>
</div>
<script>
(function () {
var KEYWORD = "denim";
function updateDenimBanner(cart) {
var root = window.eliteCartDocumentOrShadowRoot || document;
var banner = root.querySelector("#denim-promo-banner");
if (!banner) return;
if (!cart || !cart.items) {
banner.classList.add("tw-hidden");
return;
}
var denimLines = cart.items.filter(function (item) {
return item.quantity === 1 && item.title && item.title.toLowerCase().indexOf(KEYWORD) !== -1;
});
banner.classList.toggle("tw-hidden", denimLines.length !== 1);
}
updateDenimBanner(window.EliteCart.getCurrentCart());
if (!window.__denimPromoBound) {
window.__denimPromoBound = true;
window.EliteCart.onCartChange(updateDenimBanner);
}
})();
</script>
To adapt it:
- Another product: change
KEYWORD. Matching on the product type (item.product_type) is more reliable than the title, because a renamed product silently breaks a title match. - Several keywords: ask the AI generator to "match denim, jeans or jean".
- Another look: change the
tw-classes, or ask the AI to "make it blue with larger text".
Variant: a banner once the cart total reaches an amount
Replace the condition with the cart total. Cart amounts are in cents, so 2000.00 is 200000:
banner.classList.toggle("tw-hidden", cart.total_price < 200000);
The total is in the currency the customer is shopping in. If you sell in several currencies, one fixed number means different amounts per market; ask the AI generator to use a different amount per currency, or use Rewards, which converts thresholds for you.
Good to know
- Keep the
window.__...Boundline when you edit the code: it stops the listener from being added twice. - Keep
window.eliteCartDocumentOrShadowRoot.document.getElementByIdcan't find the banner when Use Shadow DOM for CSS isolation is on, which is the default for new stores. - Background: Custom HTML for developers.
Still stuck?
Chat with us and we'll help you get your cart live. Or email contact@elitecart.app.