Migrating a first order discount script
This appears in Shopify’s own repo, in the Help Center library and in the generator, which is more independent official appearances than almost any other script shape. Note that most versions treat a logged-out shopper as a first-time buyer.
Not supported yetIt compared the customer’s past order count to a number before applying anything.
Paste it into Scripts rescue and watch what it rebuilds
- Copy the Ruby with the button beside any Script on this page.
- In your Shopify admin, open Stackable, then Tools, then Scripts rescue.
- 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 yetDISCOUNT_PERCENTAGE = 20
if Input.cart.customer.nil? || Input.cart.customer.orders_count < 1
Input.cart.line_items.each do |line_item|
line_item.change_line_price(
line_item.line_price * (1.0 - (DISCOUNT_PERCENTAGE / 100.0)),
message: "20% off your first order"
)
end
end
Output.cart = Input.cartWe have not built this yet
Your Script checked how many orders the customer had placed. Shopify can tell us, but our checkout query is already at Shopify's cost limit, so we cannot ask for it today.
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.customerOrderCount
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 checked how many orders the customer had placed. Shopify can tell us, but our checkout query is already at Shopify's cost limit, so we cannot ask for it today.
Related Script shapes
A new-customer gate wrapped around a cheapest-item reward.
A reward for customers who had spent enough over their lifetime.
A discount only tagged customers ever saw.
Paste your Script and see it rebuilt
The rebuild is checked against the money your old Script charged before you can publish it.