I've been trying to find a Shopify script that simply removes a set amount from `Input.cart.subtotal_price`. Every one I've come across seems to remove the set amount from each line item, which doesn't really make a whole lot of sense. For example - https://gist.github.com/dylanjhunt/a0e4352d9f69174b46ef2962574cd7f6
Is this even possible? The only "change" item I see on the API page is .change_line_price. I'm looking for something like .change_subtotal_price. Any help would be appreciated.
Line item scripts work - as the name suggests - on line items.
A discount code can work on the cart total so perhaps you can use a combination of a discount code and Scripts to determine if that code is able to be applied, or rejected.
Cool, thanks. What I'm actually looking for - as my question suggests - is a way to alter the .subtotal_price in the same way that .line_item prices are able to be altered.
So a helpful response would have been something like:
"No, that's not possible with Shopify scripts. You have to force your customers to complete an extra step, adding a discount code, before checkout."
As a workaround for the $X off if cart is over $Y, we distribute the discount across all the eligible line items in a way that is proportional to the price of each line item.
For example, suppose you have 2 line items in the cart where item A is $30 and item B is $20 and you want to apply a $10 discount on the entire cart. You would discount $6 from item A and a $4 from item B. In another scenario, suppose both items A & B have a price of $30, then you would apply a $5 discount to both items.
Here is a Shopify script we wrote that does something similar giving a $10 discount for every $50 spent but only for items with a specific tag:
You just have to remove the tag condition for it to apply to all products. It also handles rounding errors so you don't end up discounting by a cent too much or too little.