Block discount code on top of shopify script

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?

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.

5 Likes

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.

1 Like

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?

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.

1 Like

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 :slightly_smiling_face: )

@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-bundle-get-an-additional-product-at-a-discount

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

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.

1 Like

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

Hi @JackTheJack did you manage to find a solution for this? Thank you!

Hi @igolabs Nice! It looks like you added this code to a theme file. Which file is this?