Total Coupon vs. Scripted Discount Amount Logic

Shopify Expert
690 0 73

Hi there,

A little background: I created a "buy multiple items, get % off" campaign using the script editor. We wanted to prevent people doubling up discounts by preventing customers from using coupon codes in conjunction with the offer, which I did by using cart.discount_code.reject. However, there are situations where using a coupon code on its own might actually give a larger discount than the campaign. I was thinking about writing some logic for that (i.e. comparing and allowing whichever one would be most advantageous), but I'm having a hard time wrapping my head around which variables I would need to use / calculate to determine which would be greater: the total discount from coupon codes or the total discount from the campaign. Are either of those directly accessible / what would be the easiest way to get them?

Thanks in advance!



I'm a million different people
Shopify Staff
Shopify Staff
81 0 11

Hey Rick,

There's currently no way to know how much a discount code will take off. The reason is that they're calculated after Scripts are applied. For now, the best thing you can do is approximate manually how much it will be worth if it's a FixedAmount or Percentage, but if the discount code applies to a collection that won't really help.