I'm writing a script that will apply free shipping if the cart contains a specific item and a discount code is used. Here is my script
if Input.cart.discount_code && Input.cart.discount_code.code == "FREEITEM" ELIGIBLE_SERVICE = "Standard Ground Shipping" ELIGIBLE_ITEM = "424492626116" Input.cart.line_items.each do |line_item| if line_item.variant.product.id == ELIGIBLE_ITEM Input.shipping_rates.each do |shipping_rate| if shipping_rate.name == ELIGIBLE_SERVICES shipping_rate.apply_discount(shipping_rate.price, message: "Free shipping for this product!") end end end end end Output.shipping_rates = Input.shipping_rates
However, it only runs when there are multiple items in the cart. It should work when the specific item is added, even if it's the only item added.
Would you love to unleash the unbridled power of the Google Shopping Channel into your sho...By Gabe Jan 6, 2023
How can you turn a hobby into a career? That’s what Emmanuel did while working as a wa...By Skye Dec 30, 2022