Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Shopify Script - Free Shipping with purchase of a specific product
# This is the product you need to buy to get free shipping
PRODUCT_ID = 000000000000
# This is the name of the shipping rate you want to discount (you can probably ad more options here and loop over them or soemthing
SHIPPING_NAME = "Standard Shipping"
# This is updated shipping name
UPDATED_SHIPPING_NAME = "FREE Standard Shipping"
# This is the message that will appear next to the doiscounted shipping rate option
MSG = "Buy X get Free Delivery offer"
is_in_cart = false
# Test if the item is in the cart
Input.cart.line_items.select do |line_item|
product = line_item.variant.product
if product.id == PRODUCT_ID
is_in_cart = true
end
end
# It is so make shipping free
if is_in_cart
Input.shipping_rates.each do |shipping_rate|
next unless shipping_rate.name == SHIPPING_NAME
shipping_rate.change_name(UPDATED_SHIPPING_NAME, { message: "" })
shipping_rate.apply_discount(shipping_rate.price, message: MSG)
end
end
@EJS00102
Copy link

EJS00102 commented May 9, 2022

Hi, hope it’s going well. Do you know if this code is still working? Where would I install this script?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment