Skip to content
Scripts examples

Migrating a flat rate shipping script

Setting a rate TO a price and taking an amount OFF a rate need different information: the second needs only the discount, the first needs the rate’s own cost. That difference is the whole entry.

Not supported yet
What the Script did

It rewrote every delivery rate to one flat price.

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

Danger pair D4. This file and its partner look almost identical and behave differently, so read both before you decide which one you have.

The original Ruby

# GENERATED BY THE SHOPIFY SCRIPT CREATOR APP

class FixedPriceDiscount
  def initialize(amount, message)
    @amount = Money.new(cents: 100) * amount
    @message = message
  end

  def apply(rate)
    rate_discount = @amount > rate.price ? rate.price : rate.price - @amount
    rate.apply_discount(rate_discount, { message: @message })
  end
end

CAMPAIGNS = [
  ShippingDiscount.new(:all, nil, nil, FixedPriceDiscount.new(5, "Flat rate shipping $5")),
].freeze

CAMPAIGNS.each do |campaign|
  campaign.run(Input.shipping_rates, Input.cart)
end

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

We have not built this yet

Your Script set shipping to a fixed price. We can take an amount or a percentage off shipping, but setting a rate to a price needs the rate's own cost, which we do not read yet.

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.shippingFixedPrice

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

Two files that look the same

Each pair below is one Script shape written two ways. They differ by a line or two and they do different things, so read both before deciding which one you have.

Danger pair D4

Shipping fixed price (D4)

Not supported yet

Not rebuilt. We have not built this yet

Lines that differ
class FixedPriceDiscount
    rate_discount = @amount > rate.price ? rate.price : rate.price - @amount
  ShippingDiscount.new(:all, nil, nil, FixedPriceDiscount.new(5, "Flat rate shipping $5")),
Read Flat rate shipping

Shipping fixed amount off (D4)

Rebuilt

Rebuilt as a free_shipping offer.

Delivery saving on its own cart: $5.00

Lines that differ
class FixedDiscount
    rate_discount = rate.price - @amount < Money.zero ? rate.price : @amount
  ShippingDiscount.new(:all, nil, nil, FixedDiscount.new(5, "$5 off shipping")),
Read Amount off shipping

Common questions

Will Stackable rebuild this script?
No, and the reason is stated rather than hidden: Your Script set shipping to a fixed price. We can take an amount or a percentage off shipping, but setting a rate to a price needs the rate's own cost, which we do not read yet.

Related Script shapes

Amount off shipping

A flat sum off the delivery charge, floored at free.

Percentage off shipping

A share taken off every delivery rate at checkout.

Free shipping over a threshold

Delivery drops to free once the cart is worth enough.

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.