Reject Discount Code for Specific Items

New Member
1 0 0

We used the code below as a reference to reject discount codes if a specific item matched a certain criteria.  What we'd like to do is use a code but exclude individual items from it if they have a specific tag. I know that you can put criteria on the discount codes themselves, be we have apps that generate unique codes to perform case by case discounts, so that wouldn't work here.


From what I can tell, "discount_code.reject" rejects the code from the whole cart. Is this correct? Is there a way to exclude only specific line items from a discount code's application in a cart?


CART_REJECTION_MESSAGE = "Cannot Use Discount Code on Sale Items"

condition_is_met = false

if Input.cart.discount_code != nil
  Input.cart.line_items.each do |line_item|
    product =
    if product.key?("_saleitem")
      condition_is_met = true

if condition_is_met

Output.cart = Input.cart
Shopify Partner
132 1 19

Hi Ampsy,


You can apply the discount code to each item individually using scripts but it means you'll need to reject the code from the cart which can get a little confusing. This is because you end up with each line item showing the discount code applied to it but a 'code rejected' message at the bottom of the checkout.


You can certainly achieve the functionality that you're looking for, it's just a matter of finding the most graceful way to do it.


Using scripts, you could tag customers and reduce their prices based on tag. You could apply the discount automatically in the checkout and remove the discount code completely. You could even also ask the app dev if they would be willing to add a 'by customer' functionality to their app!


If you shoot through the exact details of the discount functionality you're trying to achieve I could help out, or you can get me at






Feeling a bit lost? Contact for help with theme setup, alterations, custom functionality, and app development.