What's your biggest current challenge? Have your say in Community Polls along the right column.

Re: Disable discount codes for product

How can I disable discount codes for certain tagged products?

mapallones
Shopify Partner
1 0 0

I am using script editor which is made by Shopify.

I want to disable discount codes for products that have "no_discount" tag.

But I have some problem.

For example, if there are 4 products in the cart.

And only one product has "no_discount" tag.

In this case, let's imagine I use a discount code that discount by 10%.

I want to prevent discount for only the product which has "no_discount" tag.

And discount for other three products by 10%.

Is it possible?

Reply 1 (1)

Stephen_Baker
Shopify Partner
7 1 4

If you're using discount codes, you don't even need the script editor.  Create a collection with all the items that are eligible for the discount, and have the discount code only apply to that collection.  (Note that Shopify cannot EXCLUDE items from a smart collection based on tags, so you would need to tag eligible products rather than ineligible products.)

 

If you're apply the discount via line item script, I assume you're looping through each item in the cart.  Before applying the discount to the line item, add an "unless" statement similar to this:
unless line_item.variant.product.tags.include?('no_discount')

Don't forget to end your unless loop!