Personalized checkout and custom promotions with Shopify Scripts
I want to make shipping free only if the threshold is met AFTER the discounts are applied.
Seems like this script would work perfectly if there was an "Input.cart.total_discount" object, but I can't seem to find one.
# Define the minimum order amount for free shipping
MINIMUM_ORDER_AMOUNT = 75.00
# Calculate the total after all discounts have been applied
total_after_discounts = Input.cart.subtotal_price_was - Input.cart.total_discount
# Check if the total after discounts is greater than the minimum order amount
if total_after_discounts >= MINIMUM_ORDER_AMOUNT
# Apply the free shipping discount
ShippingRate.new(name: "Free Shipping", price: 0.00, minimum_order_amount: MINIMUM_ORDER_AMOUNT)
end
Solved! Go to the solution
This is an accepted solution.
Some tweaking of the following may assist; if the final price is greater than or equal to 100, the shipping is set to 0.
Input.cart.line_items.each do |item|
item_price = item.original_line_price
item_price -= item.line_price
item_total_price = item.line_price
if Input.cart.discount_code
item_total_price = item_total_price * (1 - Input.cart.discount_code.discount_percentage / 100)
end
if item_total_price >= 100
item.change_line_price(0, message: "Free Shipping")
end
end
Output.cart = Input.cart
This is an accepted solution.
Honestly, I am having an issue with this also and don't see a solution in the link you provided.
I'm having the Free shipping default in and then after the customer adds in the discount rate. Even if the total has fallen below the free shipping threshold they can still check out with free shipping.
I just had 2 customers check out with this scenario.
I never noticed this issue before and suspect it may be newly introduced in error.
Yes, the threshold is based on the checkout subtotal (ie. before other discounts).
You can use Advanced Free Shipping and target Checkout Total AFTER other discounts applied.
Discover how to increase the efficiency of commerce operations with Shopify Academy's l...
By Jacqui Mar 26, 2025Shopify and our financial partners regularly review and update verification requiremen...
By Jacqui Mar 14, 2025Unlock the potential of marketing on your business growth with Shopify Academy's late...
By Shopify Mar 12, 2025