Update: Shopify Scripts stopped running on 30 June 2026
If you’re trying to stop discounts stacking, don’t use the Ruby script below. Shopify Scripts stopped executing on 30 June 2026, so this code no longer runs on stores.
Start with discount combination settings to control which discounts can combine. Check the rules for the particular promotion you’re running, especially Buy X Get Y offers.
If the built-in settings don’t cover your rules, look at apps that use Shopify Functions. Functions are the current route for custom discount logic, but they aren’t a drop-in replacement for this Ruby script. The replacement needs to be designed and tested around the behaviour you want.
Original article
Shopify Scripts is a great (and fun) feature available for Shopify Plus merchants. There's lots of interesting things you can do with Scripts, with one being the ability to remove a discount code from the cart automatically.
A big reason why you'd want to do this is to avoid customers double stacking discount codes when you're already running a BOGO campaign (or any sort of scripted discount).
Let's look at a very simple script for removing any discount code, and see my github repo for more shopify snippets on Scripts.
grabbing the ruby script...