Block discount code on top of shopify script

igolabs
Tourist
5 0 4

Afternoon, i've seen similar questions but i'm really struggling on the implementation.

 

I have experience with HTML, CSS & Javascript but not Ruby so it's rather confusing.

The script for the discount is contained in this link: https://www.pastiebin.com/5cdaa1632079b

 

I have looked and you can indeed reject discount codes using scripts, this is the code i found

 

Input.cart.discount_code.reject({message: "Save 10% with our Sets"})

 

However i cannot place this code inside my existing script without it erroring, can anyone point me in the right direction?

 

 

 

 

 

 

0 Likes
igolabs
Tourist
5 0 4

I worked this out myself, here is the correct code that needs to be added. 

 

if Input.cart.discount_code
  Input.cart.discount_code.reject(
    message: "Discount codes cannot be redeemed with our Sets"
  )
end

The placement of the code is below, add the snippet just above the CAMPAIGNS = [ section and it works.

 

screenie.png

JackTheJack
Tourist
4 0 1

Thanks for the code. This works on my site too. Also is there any chance we could make this only works on the items with the discount. If the cart was mixed with discounted item and one without the discount, it rejects discount from all item even thought there's item without the discount.

Nick_vas
Tourist
3 0 0

Hey thanks for the code!
Works like a charm!

Quick question:
I have a script that applies a discount to a bundle of products.
Can we allow codes but only have them apply a discount on any item added except the bundle that the script will already have applied a discount?

0 Likes
PaulNewton
Shopify Partner
2571 136 454

@Nick_vas wrote:

I have a script that applies a discount to a bundle of products.
Can we allow codes but only have them apply a discount on any item added except the bundle that the script will already have applied a discount?


For regular customer discount codes the easiest solution is to limit that discount code to a collection that the bundle products are NOT in, or some other omission setting.

It can be fast too IF all non-bundle type products are a type, or have a specific tag, or have data that can be used to make an automatic collection.

Otherwise this can be a manual chore however if you have a wide range of products/collections with bundleable products mixed in.

Mainly due to the fact that there will be no 'does not contain tag' setting for automatic collections which would let you tag the bundle products and omit only them from a collection that contains all products.

 

Problem Solved? ✔️Accept and ? Like the solution so you can help others.
Buy me a coffee ☕ paypal.me/paulnewton or donate to eff.org
Confused? Busy? Buy a custom solution paull.newton+shopifyforum@gmail.com
Nick_vas
Tourist
3 0 0

Thanks @PaulNewton ,

I like your idea.

However, in our case, we only have 4 products (one for each size) in total and each has different colors.
We just made a bundle option, which simply allows the customers to add 4, one of each size, and applies a discount.

So, if someone wants to add an extra one, we want to allow the discount coupon to apply only to the extra item.
Adding them into a collection won't work in that case as the discount code won't work.
(Hope I make sense )

0 Likes
PaulNewton
Shopify Partner
2571 136 454

@Nick_vas you'll have to modify your scripts to just keep track of the number of items as a requirement, or carts total value and apply the discount to the extra item.

There's an example script similar to what your describing to get started with

https://help.shopify.com/en/manual/checkout-settings/script-editor/examples/line-item-scripts#buy-a-... 

and tangentially related https://help.shopify.com/en/manual/checkout-settings/script-editor/examples/line-item-scripts#free-g... 

Depending on situation to get automatic discounts working with bundles sometimes you may need two sets of inventory as you need a clean way to distinguish bundled items from non bundled items in the admins discount logic, then need an app to keep inventory properly sync'd if your tracking inventory.

 

 

Problem Solved? ✔️Accept and ? Like the solution so you can help others.
Buy me a coffee ☕ paypal.me/paulnewton or donate to eff.org
Confused? Busy? Buy a custom solution paull.newton+shopifyforum@gmail.com
Nick_vas
Tourist
3 0 0

Thanks @PaulNewton  and sorry for the late reply.
We will try this out.

0 Likes