Free Shipping Script

Solved
rdecker2
Tourist
5 1 0

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

Accepted Solution (1)
rdecker2
Tourist
5 1 0

This is an accepted solution.

I figure out that I don't need a cart script to perform this free shipping offer. I just used the shipping configuration available as described here:
 

View solution in original post

Replies 3 (3)
WhiteWater_Web
Shopify Expert
440 16 37

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

A certified Shopify Partner and Expert, WhiteWater Web (WWW) is a premium digital solutions company specializing in advanced Shopify Dev, Usability/Design, and Online Strategy. WWW has been working with the Shopify platform since 2006.
info@whitewatersolutions.com
rdecker2
Tourist
5 1 0

This is an accepted solution.

I figure out that I don't need a cart script to perform this free shipping offer. I just used the shipping configuration available as described here:
 
EnquiringMind
Excursionist
11 0 4

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.