AgentReadyAI visibility appCaffeine & CommerceShopify agency
Caffeine and Commerce
Caffeine and Commerce
By Dylan HuntDecember 9th, 2021shopifyscriptsguides

Shopify Shipping Scripts to get you started

Shopify Scripts is being retired on June 30, 2026.

The Ruby Scripts and Script Editor used in this tutorial stop running after that date. The replacement is Shopify Functions (also called checkout functions), which is faster, available beyond Shopify Plus, and built for the new checkout. If you run Scripts today, plan your migration now.

Shopify Shipping Scripts to get you started

I wanted to write a few scripts to help people get started with Shipping scripts. Let me know if you have any comments or want to see anything else for how these work.


1. Discounted Shipping if cart is over $X

min_discount_order_amount = Money.new(cents:100) * 50
total = Input.cart.subtotal_price_was
discount = if total > min_discount_order_amount
              0.1
            else
              0
            end
message = "10% off shipping if order is over $50"

Input.shipping_rates.each do |shipping_rate|
  next unless shipping_rate.source == "shopify"
  shipping_rate.apply_discount(shipping_rate.price * discount, message: message)
end

Output.shipping_rates = Input.shipping_rates

2. Free shipping if the cart is over $X

min_discount_order_amount = Money.new(cents:100) * 50
total = Input.cart.subtotal_price_was
discount = if total > min_discount_order_amount
              1
            else
              0
            end
message = "Free shipping if order is over $50"

Input.shipping_rates.each do |shipping_rate|
  next unless shipping_rate.source == "shopify"
  shipping_rate.apply_discount(shipping_rate.price * discount, message: message)
end

Output.shipping_rates = Input.shipping_rates

3. Free shipping on rate based on the name of the rate

discount = 1
message = "Free Standard Shipping"

Input.shipping_rates.each do |shipping_rate|
  next unless shipping_rate.source == "shopify"
  next unless shipping_rate.name == "Standard Shipping"
  shipping_rate.apply_discount(shipping_rate.price * discount, message: message)
end

Output.shipping_rates = Input.shipping_rates

Make your store agent-ready

Get found and recommended by AI shopping assistants.

AgentReady adds Schema.org structured data, an llms.txt directory, and an AI-readability audit to your Shopify store, so ChatGPT, Perplexity, and Google can understand and recommend your products. Free for stores under 500 products.

Comments

Every comment here comes from a verified email. Write yours, confirm from your inbox, and it's live.

Loading comments…

Leave a comment

ShareXLinkedInFacebook

Written by Dylan Hunt, Founder, Caffeine and Commerce. We build Shopify stores that rank and that AI agents can read. Have a project? Get in touch.