Skip to content

Instantly share code, notes, and snippets.

@kmeister2000
Last active November 9, 2018 18:31
Show Gist options
  • Save kmeister2000/3137ebbe6a12c9eb535b0ba23c8bc6e4 to your computer and use it in GitHub Desktop.
Save kmeister2000/3137ebbe6a12c9eb535b0ba23c8bc6e4 to your computer and use it in GitHub Desktop.
Apply free shipping if the address is in the US and the cart total is over $100
# Free US shipping when cart total exceeds $100
free_shipping_threshold = 100
if Input.cart.total >= Money.new(cents: (100 * free_shipping_threshold)) && Input.cart.shipping_address.country.include?("United States")
Input.shipping_rates.each do |shipping_rate|
next unless shipping_rate.source == "shopify"
shipping_rate.apply_discount(shipping_rate.price, message: "Free shipping")
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