Reject Discount Code per item

Excursionist
18 1 1

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!

0 Likes
Shopify Partner
1704 47 149

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 ?

 


@florinanghel 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.

 

 

Problem Solved? ✔️Accept the solution so you can help others.
Confused? Busy? ? Get me to solve it paull.newton+shopifyforum@gmail.com.
Buy me a coffee? ☕ paypal.me/paulnewton or donate to eff.org
0 Likes
Excursionist
18 1 1

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

0 Likes
Shopify Partner
1704 47 149

@florinanghel 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.

 


@florinanghel 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.

Problem Solved? ✔️Accept the solution so you can help others.
Confused? Busy? ? Get me to solve it paull.newton+shopifyforum@gmail.com.
Buy me a coffee? ☕ paypal.me/paulnewton or donate to eff.org
0 Likes
Excursionist
18 1 1

Hmm, I dont understand the proposed quickfix.

0 Likes
Shopify Partner
1704 47 149

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.

Problem Solved? ✔️Accept the solution so you can help others.
Confused? Busy? ? Get me to solve it paull.newton+shopifyforum@gmail.com.
Buy me a coffee? ☕ paypal.me/paulnewton or donate to eff.org
0 Likes
Excursionist
18 1 1

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

0 Likes
Shopify Partner
1704 47 149

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

Problem Solved? ✔️Accept the solution so you can help others.
Confused? Busy? ? Get me to solve it paull.newton+shopifyforum@gmail.com.
Buy me a coffee? ☕ paypal.me/paulnewton or donate to eff.org
0 Likes
Excursionist
18 1 1

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.

 

0 Likes
Shopify Expert
9922 75 1439

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.

★ Winning Partner of the Build a Business competition. ★ http://freakdesign.com.au
0 Likes