Product discounts ignored when cart line is in excludedCartLineIds of order discount

Hi everyone,

When using the new Discount Function, I’ve run into an issue when trying to apply both product and order discounts at the same time.

Here’s the scenario:

  1. I apply a product discount to a cart line (e.g., Cart Line A).
  2. In my order discount, I add that same cart line’s ID to excludedCartLineIds.

When I do this, none of my product discounts are applied — only the order discount shows up.

Here’s an example output from my function:

{
  "operations": [
    {
      "productDiscountsAdd": {
        "candidates": [
          {
            "message": "code",
            "targets": [
              {
                "cartLine": {
                  "id": "gid://shopify/CartLine/1",
                  "quantity": 4
                }
              }
            ],
            "value": {
              "fixedAmount": {
                "amount": "99",
                "appliesToEachItem": true
              }
            }
          },
          {
            "message": "code",
            "targets": [
              {
                "cartLine": {
                  "id": "gid://shopify/CartLine/2",
                  "quantity": 1
                }
              }
            ],
            "value": {
              "fixedAmount": {
                "amount": "99",
                "appliesToEachItem": true
              }
            }
          }
        ],
        "selectionStrategy": "ALL"
      }
    },
    {
      "orderDiscountsAdd": {
        "candidates": [
          {
            "message": "DiscountMixer",
            "conditions": [
              {
                "orderMinimumSubtotal": {
                  "excludedCartLineIds": [],
                  "minimumAmount": "5000"
                }
              }
            ],
            "targets": [
              {
                "orderSubtotal": {
                  "excludedCartLineIds": [
                    "gid://shopify/CartLine/2",
                    "gid://shopify/CartLine/3",
                    "gid://shopify/CartLine/4"
                  ]
                }
              }
            ],
            "value": {
              "fixedAmount": {
                "amount": "10"
              }
            }
          }
        ],
        "selectionStrategy": "FIRST"
      }
    }
  ]
}

What happens:

  • If gid://shopify/CartLine/2 exists in both the product discount targets and in the order discount’s excludedCartLineIds, then the product discounts are completely ignored and only the order discount is applied.
  • If I remove that cart line from excludedCartLineIds, both discounts apply and combine as expected.

Question:
Is this intended behavior in the new Discount Function? If so, is there a way to allow product discounts to still apply even if that line is excluded from the order discount’s calculation?

Thanks in advance!

Hi @RorySeka

From digging into this, it does seem that this is intended behavior for the Shopify Discount Function API.

When you add a cart line’s ID to the excludedCartLineIds array in the order discount’s target (or condition), you are telling Shopify to exclude that cart line from the order discount calculation. However, if that same cart line is also targeted by a product discount in the same function response, Shopify will only apply the order discount and ignore the product discount for that line. This is by design: a cart line cannot receive both a product discount and be excluded from the order discount calculation in the same function response.

This is confirmed by the observed behavior:

  • If a cart line is in both the product discount targets and the order discount’s excludedCartLineIds, only the order discount is applied.
  • If you remove the cart line from excludedCartLineIds, both discounts apply and combine as expected.

Is there a workaround?

No, there is currently no way to allow product discounts to apply to a cart line if that line is excluded from the order discount’s calculation in the same function response. This is a limitation of the Discount Function API’s design, and is intended to prevent double-discounting or ambiguous discount stacking.

What should you do?

  • If you want a cart line to receive both a product discount and be included in the order discount calculation, do not add its ID to excludedCartLineIds.
  • If you want to exclude a cart line from the order discount calculation (for example, to prevent double-dipping), you must accept that it will not receive a product discount in the same function response.

Documentation

You can find more about how product and order discounts interact, and the use of excludedCartLineIds, in the official Shopify Functions Discount API documentation:
Shopify Discount Functions Reference

1 Like

Thank you for taking the time to dig into this and provide such a clear explanation. I really appreciate the detail, especially around the reasoning for how excludedCartLineIds interacts with product discounts.

One challenge I’m facing with this behavior is that it doesn’t only remove the product discount from the specific cart line that’s excluded in the order discount — it seems that none of the candidates in productDiscountsAdd are applied at all.

It would be completely understandable if the function prevented applying both a product and an order discount to the same cart line — but fortunately, it does allow that. The scenario that causes an issue is when a cart line receives a product discount but is also excluded from the order discount calculation. In my opinion, this case is actually the opposite of double-discounting, since the order discount doesn’t apply to that line at all. That’s why it feels unexpected that this setup ends up blocking all product discounts in the response.

I can try to work around this by manually calculating the price of eligible lines and applying the order discount as a fixed amount. The problem with that approach is that it wouldn’t handle situations where another discount (outside of my function) applies to the cart — which could result in my function giving a higher order discount than intended.

Again, thank you for clarifying the current intended behavior. I just wanted to highlight this nuance, as it seems to affect more than the specific line in excludedCartLineIds, and it can make certain discount structures harder to implement reliably.