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
Starting a B2B store is a big undertaking that requires careful planning and execution. W...
By JasonH Sep 23, 2024By investing 30 minutes of your time, you can unlock the potential for increased sales,...
By Jacqui Sep 11, 2024We appreciate the diverse ways you participate in and engage with the Shopify Communi...
By JasonH Sep 9, 2024