Shopify Scripts amount off total.

Chris_Gerringer
Shopify Partner
10 0 1

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.

Jason
Shopify Expert
10277 144 1945

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.

I jump on these forums to help and share some insights. Not looking to be hired, and not looking for work.

Don't hand out staff invites or give admin password to forum members unless absolutely needed. In most cases the help you need can be handled without that.


★ http://freakdesign.com.au ★
0 Likes
rickydazla
Shopify Expert
690 0 73

Here’s an idea: Shopify Checkout Scripts. Yeah! They also do what their name suggests (smart arse;)

I'm a million different people
0 Likes
Chris_Gerringer
Shopify Partner
10 0 1

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."

0 Likes
Patrick_Hughes
Shopify Expert
21 0 5

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:

https://smooth.ie/blogs/news/shopify-scripts-spend-save

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.