Skip to content

Instantly share code, notes, and snippets.

Last active April 4, 2023 15:29
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
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
# 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 do |line_item|
product = line_item.variant.product
is_in_cart = true
# It is so make shipping free
if is_in_cart
Input.shipping_rates.each do |shipping_rate|
next unless == SHIPPING_NAME
shipping_rate.change_name(UPDATED_SHIPPING_NAME, { message: "" })
shipping_rate.apply_discount(shipping_rate.price, message: MSG)
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?

Copy link

nsbabrah commented Apr 4, 2023

[Error] undefined method 'map' for nil
shopify/std_lib/cart_shipping_rates/output.rb:7:in #Class:0x7faad27081c0.to_hash
shopify/std_lib/core/script_kernel.rb:12:in Object.prepare_output

Gives error to me.

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