I'm trying to achieve the following:
I have the code working well for the 50% off the product with the highest value but I'm wondering how can I integrate the coupon code and collection part?
high = Input.cart.line_items Input.cart.line_items.each do |line_item| if high.variant.price < line_item.variant.price high = line_item end end Input.cart.line_items.each do |line_item| if high == line_item line_item.change_line_price(high.variant.price * 0.50, message: "50% off") end end Output.cart = Input.cart
Solved! Go to the solution
You can check the existence of a cart discount code and also get the actual code https://help.shopify.com/en/manual/checkout-settings/script-editor/shopify-scripts#cartdiscount-perc...
If the code is the one you need then you would run your existing script.
You can't use the collection in the script api so maybe use tags instead to limit the qualified products.
When you create the discount code it should apply a tiny discount (since the real discount will be offered by your script when the coupon is being used).
For the eligible coupons, the way I have it set up is via a Discount Rule that has multiple coupons in it (created via a private app).
Do you know if the list of eligible codes be can listed that way?
This is an accepted solution.
That is tricky, I guess you could if your codes share a common string, you'd check if the discount code contains that common part, if they are completely different then manually adding 3k codes in a script is not practical so maybe use just one code.