Skip to content

Instantly share code, notes, and snippets.

@omeome762
Last active April 2, 2017 13:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save omeome762/47569e8a85d9d4f7c96c9155a22b8e3b to your computer and use it in GitHub Desktop.
Save omeome762/47569e8a85d9d4f7c96c9155a22b8e3b to your computer and use it in GitHub Desktop.
X% Off Shipping If Cart Value =>$Y
MINIMUM_ORDER_AMOUNT = 75 #dollar amount required in cart to get discount
DISCOUNT = 0.2 #percentage discount (in decimal format)
MESSAGE = "20% off on shipping if your order is over $75" #promotional message
if Input.cart.subtotal_price_was => (Money.new(cents:100) * MINIMUM_ORDER_AMOUNT)
Input.shipping_rates.each do |shipping_rate|
next unless shipping_rate.source == "shopify"
shipping_rate.apply_discount(shipping_rate.price * DISCOUNT, message: MESSAGE)
end
end
Output.shipping_rates = Input.shipping_rates
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment