Shopify Scripts amount off total.

Shopify Partner
9 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.

1 Like
Shopify Expert
9881 68 1419

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.

★ Winning Partner of the Build a Business competition. ★ http://freakdesign.com.au
0 Likes
Highlighted
Shopify Expert
704 0 65

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
Shopify Partner
9 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
Shopify Partner
16 0 4

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.

0 Likes