Custom Shopify Scripts for Advanced Discounting Logic
Share
Custom Shopify Scripts for Advanced Discounting Logic
Introduction
Discounts are a proven way to boost conversions—but what if your marketing strategy requires more than basic promo codes?
With Shopify Scripts, you can customize the checkout experience like never before. From BOGO offers to complex tiered discounts, Scripts give Shopify Plus merchants the ability to write custom Ruby code to implement advanced logic.
In this blog, we’ll explore what Shopify Scripts are, how they work, and 5 advanced discounting use cases you can create using them.
🧠 What Are Shopify Scripts?
Shopify Scripts are small pieces of code (written in Ruby) that run on the checkout page. They allow you to:
-
Modify prices of items
-
Adjust shipping rates
-
Customize payment options
-
Create complex discount logic that goes beyond Shopify’s standard settings
Note: Scripts are only available on Shopify Plus.
🔧 Where Do Scripts Run?
Shopify has a tool called the Script Editor App, which lets you:
-
Write and test Ruby scripts
-
Deploy price-based or shipping-based changes
-
Roll back to previous versions easily
🛍️ Types of Shopify Scripts
-
Line Item Scripts
Modify the prices of products in the cart. -
Shipping Scripts
Show/hide or adjust shipping rates based on conditions. -
Payment Scripts
Customize which payment gateways appear at checkout.
🧪 5 Advanced Discounting Use Cases (with Shopify Scripts)
1. BOGO (Buy One Get One Free / 50% Off)
Input.cart.line_items.each do |line_item|
if line_item.variant.product.tags.include?("bogo")
line_item.change_line_price(Money.zero, message: "BOGO Discount Applied")
end
end
🎯 Target specific products using tags and reward customers with free or discounted items.
2. Tiered Discounts (Spend More, Save More)
if Input.cart.subtotal_price > Money.new(cents: 10000)
discount = 0.10
elsif Input.cart.subtotal_price > Money.new(cents: 5000)
discount = 0.05
end
Input.cart.line_items.each do |line_item|
new_price = line_item.line_price * (1.0 - discount)
line_item.change_line_price(new_price, message: "Tiered Discount")
end
💰 Automatically apply increasing discounts based on the cart value.
3. Customer Tag-Based Discounts (e.g., VIPs)
if Input.cart.customer && Input.cart.customer.tags.include?("VIP")
Input.cart.line_items.each do |line_item|
line_item.change_line_price(line_item.line_price * 0.9, message: "VIP 10% Off")
end
end
🌟 Give loyal customers exclusive discounts without coupon codes.
4. Bundle Discounts
if Input.cart.line_items.size >= 3
Input.cart.line_items.each do |line_item|
line_item.change_line_price(line_item.line_price * 0.8, message: "Bundle Discount")
end
end
📦 Encourage higher order value by applying discounts when customers buy 3+ items.
5. Free Shipping Over a Threshold
if Input.cart.subtotal_price >= Money.new(cents: 7500)
ShippingRate.adjustments.each do |shipping_rate|
shipping_rate.apply_discount(shipping_rate.price, message: "Free Shipping")
end
end
🚚 Motivate customers to increase their cart value for free shipping rewards.
🛠️ Tips for Working with Shopify Scripts
-
Always test scripts in a staging environment
-
Use tags strategically (products, customers) to simplify logic
-
Combine scripts with Shopify Flow for automation outside checkout
-
Keep an eye on performance—especially during sales or high-traffic events
⚠️ Limitations to Keep in Mind
-
Only available to Shopify Plus users
-
Scripts only affect checkout — not product or cart pages
-
Cannot create dynamic discount codes (use APIs for that)
✅ Conclusion
Shopify Scripts unlock next-level discount strategies that go far beyond what standard discount codes offer. Whether you're rewarding loyal customers, pushing bundles, or personalizing offers, these powerful checkout customizations can help boost AOV and customer loyalty—if you’re on Shopify Plus.