All questions

Hide the coupon promo banner from carts that already applied a code

Asked by ferdi on

Fferdi

Banner keeps showing "use code SAVE10" to people who already applied it. looks broken to them.

Current audience:

cart's stage is "checkout"

How do I check the applied coupon in the condition

Was this helpful?

2 answers

LMLucas Meier

The cart variable exposes a coupon attribute alongside stage, items, total, subtotal, discount, and currency. So the exclusion is just a negated coupon check:

cart's stage is "checkout" and not cart's coupon is "SAVE10"

One detail worth knowing: undefined values evaluate to false by design in CQL. A cart with no coupon applied simply fails the equality check instead of erroring, so the not flips it to true and those shoppers keep seeing the banner. Exactly the behavior you want here.

If you run several codes at once, swap the equality for a list:

not cart's coupon is in ["SAVE10", "SAVE15"]
Was this helpful?
Ttamar_c

Adding to Lucas's answer since you are on the cart already: if you ever need item-level checks rather than cart-level ones, CQL has quantifiers for that:

some item in cart's items satisfies item's name matches "t-shirt"

Handy when the promo only applies to certain products and you want to hide the banner unless a qualifying item is actually in the cart. For the coupon case the plain attribute check is all you need though.

Was this helpful?
Still have questions?