Have your say in Community Polls: What was/is your greatest motivation to start your own business?

Re: Reject Discount Code per item

How can I block discount codes for specific items?

Not applicable

Hello,

 

I would like to be able to block the usage of discount scripts on certain items.

 

Since the coupon can only be rejected on cart there is no nice way to do this. The sugestion on all posts related to this (including https://community.shopify.com/c/Script-Editor/Reject-Discount-Code-for-Specific-Items/m-p/500201#M79...) is to reject the coupon and then selectively apply its discount per item in script.

 

That I think is a hacky solution because in the script we cant check the special conditions a discount code might have.

 

However, even if I ignore that issue, the aproach still doesnt work. It works just fine when I run the script in the script editor, the discount is corectly assigned to the items I want. But when I preview the script in the store there is no more discount.

 

Am I right to assume there is no way to do what I am trying to accomplish?

 

Thank You for your time!

Replies 15 (15)

PaulNewton
Shopify Partner
7450 657 1565

To clarify like the post you reference you also are unable to place the conditions on the discounts themselves via the api or in the admin?

And trying to use liquid or javascript to change the discount preemptively is a nonstarter ?

 


@Anonymous wrote:

That I think is a hacky solution because in the script we cant check the special conditions a discount code might have.


Just to mentally untangle that myself : there may be special conditions ,that apply to eligible items, that are uncheckable if the script rejects the discount as part of the technique linked. Which is different than an initial reaction 'what's the point of needing to know discount conditions if you reject the discount?'

 


the aproach still doesnt work. It works just fine when I run the script in the script editor, the discount is corectly assigned to the items I want. But when I preview the script in the store there is no more discount.

Unless you can share the script AND  data(product,discount) to reproduce this, try making 2 reduced test case scripts:

One to reject the cart discount the other applying the line item discounts then bisect against the script you currently have to see if you can isolate an issue.

 

 

Contact paull.newton+shopifyforum@gmail.com for the solutions you need


Save time & money ,Ask Questions The Smart Way


Problem Solved? ✔Accept and Like solutions to help future merchants

Answers powered by coffee Thank Paul with a Coffee for more answers or donate to eff.org


Not applicable

@PaulNewton wrote:

To clarify like the post you reference you also are unable to place the conditions on the discounts themselves via the api or in the admin?

And trying to use liquid or javascript to change the discount preemptively is a nonstarter ?

Yes, when there are tens of thousands of coupons, the solution to edit them via admin or api is not good enough because new ones get created all the time by various apps.

Using js would still allow the customer to change the discount code so that does not work either.


Just to mentally untangle that myself : there may be special conditions ,that apply to eligible items, that are uncheckable if the script rejects the discount as part of the technique linked. Which is different than an initial reaction 'what's the point of needing to know discount conditions if you reject the discount?


Unless you can share the script AND  data(product,discount) to reproduce this, try making 2 reduced test case scripts:

One to reject the cart discount the other applying the line item discounts then bisect against the script you currently have to see if you can isolate an issue.


Here is one scenario.

You have a discount code for a specific collection (Collection A).

You also have lots of others general discount codes or specific ones.

You have another collection (Collection B) where you are running a sale and the prices are discounted to the max.

You dont want discount codes to be applied to product from Collection B.

 

Solutions:

1. Create a new collection that contains all products not in Collection B (Call it Collection C) then edit each and every sales rule to set it to only apply to products in Collection C. This is not optimal for several reasons, some of which I mentioned above.

2. The advice on the forums is to use the shopify script api, save the discount amount/% in a var, reject the coupon, mark the undiscountable products, then iterate trough the other products and apply the discount as line item price reduction. That is what I did, but there are 2 issues:

  a. What about that coupon that its supposed to apply to only Collection A? You dont have that info in the script api so you might end up offering a specific high discount to products that should not have it.

  b. While in the admin script editor tests this solution works, it does not work in the actual checkout. Shopify told me that once the coupon is rejected, the cart refreshes and the rest of the script doesnt execute anymore. And when it runs again on the refreshed cart, there is no more discount code amount/percentage to apply. I kinda but dont fully understand why it works like that, and certainly the fact that it works in admin adds to the confusion.

 

To answear the question for anyone with the same problem, its impossible to do what I was trying to using the script api.

PaulNewton
Shopify Partner
7450 657 1565

@Anonymous wrote:

You have a discount code for a specific collection (Collection A).

You also have lots of others general discount codes or specific ones.

You have another collection (Collection B) where you are running a sale and the prices are discounted to the max.

You dont want discount codes to be applied to product from Collection B.

 


Quickfix: You DO want a discount code applied, your own automatic discount for that collection set to fixed amount off( $0.01), or buy-X-get-Y (add some intangible product to the cart like a pdf catalogue, thank you note,order processing, happiness, stickers,etc) . Though yes this will prevent customers from using any other manual discounts.

 


@Anonymous wrote:

Shopify told me that once the coupon is rejected, the cart refreshes and the rest of the script doesnt execute anymore. And when it runs again on the refreshed cart, there is no more discount code amount/percentage to apply.


Okay that's odd though would explain a few things, i'll have to check that later since you'd think other parts of the script would run again after such a refresh.

Contact paull.newton+shopifyforum@gmail.com for the solutions you need


Save time & money ,Ask Questions The Smart Way


Problem Solved? ✔Accept and Like solutions to help future merchants

Answers powered by coffee Thank Paul with a Coffee for more answers or donate to eff.org


Not applicable

Hmm, I dont understand the proposed quickfix.

PaulNewton
Shopify Partner
7450 657 1565

Set up an automatic discount to apply to items in the collection on sale. Of course ultimately this is the similar to rejecting coupons via the checkout script for ALL items. Just another option till a better solution comes up.

Contact paull.newton+shopifyforum@gmail.com for the solutions you need


Save time & money ,Ask Questions The Smart Way


Problem Solved? ✔Accept and Like solutions to help future merchants

Answers powered by coffee Thank Paul with a Coffee for more answers or donate to eff.org


Not applicable

Do you mean that when products have an automatic discount applied to them the coupons no longer apply to those products?

PaulNewton
Shopify Partner
7450 657 1565

No when a shopify automatic discount is applied to the checkout other discounts can't be used.

So in this situation your just choosing where|how to block all other discounts /shrug

Contact paull.newton+shopifyforum@gmail.com for the solutions you need


Save time & money ,Ask Questions The Smart Way


Problem Solved? ✔Accept and Like solutions to help future merchants

Answers powered by coffee Thank Paul with a Coffee for more answers or donate to eff.org


Not applicable

Ah, ok, I understand now, its an alternative to using the script api but with the same outcome.

 

I think it would be great if shopify would allow us to tag some products as undiscountable.

 

Jason
Shopify Partner
11206 226 2315

Instead of rejecting the discount code, have the discount code do nothing on its own. Use the existence of the discount code as something to trigger your custom code in the Shopify Scripts to run. Shopfiy Scripts can detect if a code was added and what that code is.

 

That Shopify Script could - in theory - then opt to discount some items and opt to not discount others. Depending on complexity of discounts this may be a crazy idea.

★ I jump on these forums in my free time to help and share some insights. Not looking to be hired, and not looking for work. http://freakdesign.com.au ★
Not applicable

How could the discount code do nothing without beeing rejected? If I dont reject it then wont it just apply?

Jason
Shopify Partner
11206 226 2315

A 0% discount code will still apply. Let's say that code is "foo". Shopify Scripts sees that the "foo" code is added then runs its logic to discount some items.

★ I jump on these forums in my free time to help and share some insights. Not looking to be hired, and not looking for work. http://freakdesign.com.au ★
Not applicable

Ah, ok, I understand what you mean, thank you for the sugestion. It doesnt apply to my problem tho because I am treating the discount code as a wildcard not something I could easily control. Controling the discount code behaviour trough the admin or api is the solution, however it isnt practical when you have many existing sales rules and 3rd party apps generate new ones regularly.

carter7
Shopify Partner
1 0 0

Did you ever find a working solution? I'm having the same issue. Shopify REALLY needs to add the ability to mark certain products as undiscountable in the admin. The accepted solution of creating an automatic collection isn't scalable if you have thousands of existing discount codes and dozens of distributed people creating future discount codes.

Not applicable

I did not find a solution unfortunately. I dont think there is a solution at this point. There are some really hacky things I thought might work with the script api but I did not try it -> Like for discountable products, on the first run you would set the discount in line item props, then reject the discount. On the cart refresh you should still have the props, use the info in them to apply a discount (make sure to have this capped since props are editable) and then finally remove the props.

hanshanken
Visitor
1 0 0

Bump! 

 

Are there any updates to this issue or similar ones?

 

I am experiencing the same issue and feel like it's not very safe to do the approach suggested by @Jason  in an earlier comment (instead of rejecting, manually applying the discount to relevant line items only). This could lead to bugs, e.g. if you forget to cover certain types of discounts or another script is added in the future to apply a very custom discount, which could override as well...