Skip to content
Scripts examples

Migrating a discount code pattern script

Worth knowing that Shopify Scripts had no regular expressions at all, so every one of these matched by hand with start_with or a substring check on the code.

Not supported yet
What the Script did

It matched any code beginning with a given prefix and applied one rule to all of them.

Run it against your own store

Paste it into Scripts rescue and watch what it rebuilds

  1. Copy the Ruby with the button beside any Script on this page.
  2. In your Shopify admin, open Stackable, then Tools, then Scripts rescue.
  3. Paste it there, read what the tool says it will build, and compare that with the settings on this page.

Scripts rescue is on the Pro plan. Nothing is published until you tell it what your old Script charged and the two figures match to the cent.

The Script

Not supported yet
The original Ruby

CODE_PREFIX = "STAFF-"
DISCOUNT_PERCENTAGE = 30

code = Input.cart.discount_code

unless code.nil?
  if code.code.upcase.start_with?(CODE_PREFIX)
    Input.cart.line_items.each do |line_item|
      line_item.change_line_price(
        line_item.line_price * (1.0 - (DISCOUNT_PERCENTAGE / 100.0)),
        message: "Staff discount"
      )
    end
  end
end

Output.cart = Input.cart
What happens to this one

We have not built this yet

Your Script matched a whole family of discount codes by prefix or wildcard. Our codes are exact, one at a time.

This is our gap, not Shopify's. Shopify permits it and we have not built it, so there is nothing here to link to and nothing to blame the platform for.

Reason key: unsupported.codePattern

There is no cart to test here, because nothing is built. Pasting this produces the message above and no campaign at all.

Common questions

Will Stackable rebuild this script?
No, and the reason is stated rather than hidden: Your Script matched a whole family of discount codes by prefix or wildcard. Our codes are exact, one at a time.

Related Script shapes

Reject a discount code

A code the shopper typed, turned away at checkout with a message.

Discount code driven

Script logic that only ran when the shopper had typed a particular code.

Paste your Script and see it rebuilt

The rebuild is checked against the money your old Script charged before you can publish it.

We use essential cookies to run this site, and, only with your permission, analytics cookies to understand traffic. Read our Cookie Policy.