Skip to content

Instantly share code, notes, and snippets.

@omeome762
Last active February 11, 2020 18:16
Show Gist options
  • Save omeome762/4a4c00f3c4424a00d7a4529a0c3a374e to your computer and use it in GitHub Desktop.
Save omeome762/4a4c00f3c4424a00d7a4529a0c3a374e to your computer and use it in GitHub Desktop.
Free Shipping If Cart Value >$X
MINIMUM_ORDER_AMOUNT = 75 #dollars required in cart to get discount
MESSAGE = "Free shipping if you order 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, 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