Personalized checkout and custom promotions with Shopify Scripts
Hi.
I have created shopify promo script that adds a free gift if you buy a certain product.
The number of free gifts depends on the number of promotional items.
The script contains such a condition
Input.cart.line_items.each do |line_item| product = line_item.variant if economy_seen && product.id == 26758977847360 && economy_gift_ready if line_item.quantity > economy_frames new_line_item = line_item.split(take: economy_frames) new_line_item.change_line_price(Money.zero, message: "Economy Standing Desk Gift") Input.cart.line_items << new_line_item next else line_item.change_line_price(Money.zero, message: "Economy Standing Desk Gift") end economy_gift_ready = false end ....
economy_seen - promotional product;
product.id == 26758977847360 - free gift;
economy_frames - number of promotional products in cart..
script works but I have errors - "take must be between 1 and 0 script' ...
new_line_item = line_item.split(take: economy_frames) - here I split how many gifts in cart with zero price.
Why is there an error? Thanks
HI I have same problem did you find solution ?
no. I didn't find a solution. But despite the errors, the script works correctly and provides a discount. According to my observations, errors did not affect performance
Discover how to increase customer engagement on your store with articles from Shopify A...
By Jacqui Apr 23, 2025Hey Community 👋 Did you know that March 15th is National Everything You Think Is W...
By JasonH Apr 1, 2025Discover how to increase the efficiency of commerce operations with Shopify Academy's l...
By Jacqui Mar 26, 2025