Skip to content

Instantly share code, notes, and snippets.

@ECkurt
Created December 14, 2017 20:02
Show Gist options
  • Save ECkurt/397ff3378bc65e5a2726c4654ec0192e to your computer and use it in GitHub Desktop.
Save ECkurt/397ff3378bc65e5a2726c4654ec0192e to your computer and use it in GitHub Desktop.
If cart >$X, then discount shipping rule by name
min_discount_order_amount = Money.new(cents:100) * 75
total = Input.cart.subtotal_price_was
discount = if total > min_discount_order_amount
1
else
0
end
message = "Free shipping on orders over $75"
Input.shipping_rates.each do |shipping_rate|
next unless shipping_rate.source == "shopify"
next unless shipping_rate.name.upcase.start_with?("FLAT")
shipping_rate.apply_discount(shipping_rate.price * discount, message: message)
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