Re: Maximum number of items a discount can be applied to

Maximum number of items a discount can be applied to

SteveKaran
Shopify Partner
21 0 5

Shopify's native discounts have a minimum number of items, but no MAXIMUM. For example, I want to apply a discount for up to 5 items, and no more. There seems to be a function called "split" with Shopify Scripts (Shopify Plus plans only), but scripts will be deprecated in place of Functions. Short of writing a custom function using the Discounts API, anyone know how apply a maximum number of items a discount can be applied to? Or some way to minic the "split" feature from Shopify Scripts?

Replies 6 (6)

Liam
Community Manager
3108 340 871

Hi SteveKaran,

 

There's currently no native functionality in Shopify to limit the maximum number of items a discount can be applied to. However, you could use functions via the Product Discount API or Order Discount API to create a discount that applies only to a specific number of items. For your use case you could modify the price of each of the first 5 items of a particular product in the cart, and then leave the price of any additional items unchanged.

 

I'd recommend exploring the docs linked above and seeing if this will work for you!

Liam | Developer Advocate @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

SteveKaran
Shopify Partner
21 0 5

Thanks Liam,

 

Already looked into this a bit, which is why I mentioned the "split" command with Shopify Scripts. I'll be writing my own Function using the Product Discount API to test how it behaves. If I have a line item with 6+ items, and my criteria (if condition) is <= 5, the criteria will fail, and a discount probably won't apply. I'll probably have to apply some additional logic to split a cart line into two lines; one with qty 5, the other with qty 1, so that the line with qty 5 qualifies for the discount, and the line with qty does not. Hmmm....

SteveKaran
Shopify Partner
21 0 5

So I did some testing last night by building my own function using the Discount API. As I had anticipated, simply setting a condition of quantity <=5 will apply the discount correctly, but as soon as I increase the quantity to 6+, the discount is removed. Scripts provided a "simple" way to split the line in order to ensure a discount would still apply. With Functions, it's going to be a bit trickier. I have some ideas, and I'm open to suggestions.

ccsachs
Excursionist
35 0 9

Did you find a solution for this? 
I am hoping to do the same, offer a discount but limit it to a maximum number of items in the cart.

SteveKaran
Shopify Partner
21 0 5

Unfortunately I did not investigate this further as my customer's requirements had changed. As I think of it now, one approach would be to use unique hidden line item properties (starting with "_") so that cart lines can be treated independently (even if it's the same product/variant).

 

You'll probably also have to write/update/modify a custom cart update method (front-end JS) in order to split the cart lines once the "maximum" quantity has been reached. For example, if the discount applies for up to 5 items, then split the cart lines into two separate lines when the 6th item is added to the cart. This would be similar behaviour to the "split" function from Scripts.

Hirano_00
Shopify Partner
76 10 13

Hi @SteveKaran, @ccsachs 

 

Steppun Discount is a discount application that allows you to limit the maximum quantity.
Please check it out.

https://apps.shopify.com/steppun-discount