Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save dylanjhunt/a5aa2172cd96997a48dbce375a237404 to your computer and use it in GitHub Desktop.
Save dylanjhunt/a5aa2172cd96997a48dbce375a237404 to your computer and use it in GitHub Desktop.
discounted_product = 12275195905
products_needed = [592406273]
products_seen = []
Input.cart.line_items.each do |line_item|
product = line_item.variant.product
products_seen << product.id if products_needed.include?(product.id)
end
Input.cart.line_items.each do |line_item|
product = line_item.variant.product
next unless product.id == discounted_product
line_item.change_line_price(line_item.line_price * 0.0, message: "Free Product with Purchase") if products_seen.uniq.sort == products_needed.uniq.sort
end
Output.cart = Input.cart
@gelsas
Copy link

gelsas commented Dec 7, 2020

Hi how can I use this?

I have a shopify store and want to automatically add a free gift to the customers cart if customer has more than 30$ in their cart.
Where do I need to place this ?

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