I have a Shopify Function (target: cart.lines.discounts.generate.run) that powers both an automatic discount and a code discount. Both discounts use the exact same function and the same metafield configuration.
When I add an item to the cart and go to checkout:
-
The automatic discount applies correctly (25% off).
-
When I enter the discount code, the code discount does NOT apply — even though the function runs successfully and returns the exact same output.
(Error message: “Discount code CODE1 is not valid for the items in your cart”)
Both function runs complete with “status”: “success” and produce identical orderDiscountsAdd operations with the same candidates, same values, and same selection strategy. The only difference in the input is:
-
Automatic: “triggeringDiscountCode”: null
-
Code: “triggeringDiscountCode”: “code1”
I’ve attached both function run logs below. They fire within 2ms of each other for the same cart. Both combinations are enabled. The discount code is active and valid.
What I’ve tried:
-
Adding associatedDiscountCode to the candidates for the code-triggered run — no change.
-
Verifying combination settings — both discounts allow combinations with order discounts.
-
Confirming the code discount is active in Shopify Admin.
My question: Why would Shopify silently ignore a code discount’s output when the automatic discount with the exact same function and output works? Is there a known issue with code discounts on the cart.lines.discounts.generate.run target, or is there an additional output field required for code discounts to be applied?
Environment:
-
Function target: cart.lines.discounts.generate.run
-
Selection strategy: FIRST
-
Two candidates: one with fixedAmount + orderMinimumSubtotal condition, one with percentage (no condition)
-
Cart subtotal: 1600, limit amount: 2000
First one ise the code version, as you can see it has triggeredDiscountCode: “code1”
{
"shopId": x,
"apiClientId": 305876008961,
"payload": {
"export": "cart-lines-discounts-generate-run",
"input": {
"triggeringDiscountCode": "code1",
"cart": {
"attribute": null,
"buyerIdentity": {
"isAuthenticated": true
},
"lines": [
{
"id": "gid://shopify/CartLine/0",
"quantity": 1,
"cost": {
"subtotalAmount": {
"amount": "1600.0"
}
},
"merchandise": {
"__typename": "ProductVariant",
"id": "gid://shopify/ProductVariant/48091615363389",
"product": {
"inAnyCollection": true
}
}
}
]
},
"discount": {
"discountClasses": [
"PRODUCT",
"ORDER"
],
"metafield": {
"value": "{\"discountPercentage\":25,\"limitAmount\":2000,\"collectionIds\":[\"gid://shopify/Collection/510446305597\"],\"requiresLogin\":true,\"platform\":\"all\"}"
}
}
},
"inputBytes": 474,
"output": {
"operations": [
{
"orderDiscountsAdd": {
"candidates": [
{
"targets": [
{
"orderSubtotal": {
"excludedCartLineIds": []
}
}
],
"conditions": [
{
"orderMinimumSubtotal": {
"minimumAmount": "2000",
"excludedCartLineIds": []
}
}
],
"value": {
"fixedAmount": {
"amount": "500.00"
}
}
},
{
"targets": [
{
"orderSubtotal": {
"excludedCartLineIds": []
}
}
],
"value": {
"percentage": {
"value": "25"
}
}
}
],
"selectionStrategy": "FIRST"
}
}
]
},
"outputBytes": 300,
"logs": [],
"functionId": "019c57ab-0413-761c-87a8-11999cf33085",
"fuelConsumed": 510386,
"target": "cart.lines.discounts.generate.run",
"inputQueryVariablesMetafieldValue": {
"discountPercentage": 25,
"limitAmount": 2000,
"collectionIds": [
"gid://shopify/Collection/510446305597"
],
"requiresLogin": true,
"platform": "all"
},
"inputQueryVariablesMetafieldNamespace": "upper-limit-discount",
"inputQueryVariablesMetafieldKey": "function-configuration"
},
"logType": "function_run",
"status": "success",
"source": "upper-limit-discount",
"sourceNamespace": "extensions",
"logTimestamp": "2026-02-19T14:52:28.706869Z",
"localTime": "2026-02-19 17:52:28",
"storeName": "x.myshopify.com"
}
This one is the automatic one:
{
"shopId": xxx,
"apiClientId": 305876008961,
"payload": {
"export": "cart-lines-discounts-generate-run",
"input": {
"triggeringDiscountCode": null,
"cart": {
"attribute": null,
"buyerIdentity": {
"isAuthenticated": true
},
"lines": [
{
"id": "gid://shopify/CartLine/0",
"quantity": 1,
"cost": {
"subtotalAmount": {
"amount": "1600.0"
}
},
"merchandise": {
"__typename": "ProductVariant",
"id": "gid://shopify/ProductVariant/48091615363389",
"product": {
"inAnyCollection": true
}
}
}
]
},
"discount": {
"discountClasses": [
"PRODUCT",
"ORDER"
],
"metafield": {
"value": "{\"discountPercentage\":25,\"limitAmount\":2000,\"collectionIds\":[\"gid://shopify/Collection/510446305597\"],\"requiresLogin\":true,\"platform\":\"all\"}"
}
}
},
"inputBytes": 469,
"output": {
"operations": [
{
"orderDiscountsAdd": {
"candidates": [
{
"targets": [
{
"orderSubtotal": {
"excludedCartLineIds": []
}
}
],
"conditions": [
{
"orderMinimumSubtotal": {
"minimumAmount": "2000",
"excludedCartLineIds": []
}
}
],
"value": {
"fixedAmount": {
"amount": "500.00"
}
}
},
{
"targets": [
{
"orderSubtotal": {
"excludedCartLineIds": []
}
}
],
"value": {
"percentage": {
"value": "25"
}
}
}
],
"selectionStrategy": "FIRST"
}
}
]
},
"outputBytes": 300,
"logs": [],
"functionId": "019c57ab-0413-761c-87a8-11999cf33085",
"fuelConsumed": 509722,
"target": "cart.lines.discounts.generate.run",
"inputQueryVariablesMetafieldValue": {
"discountPercentage": 25,
"limitAmount": 2000,
"collectionIds": [
"gid://shopify/Collection/510446305597"
],
"requiresLogin": true,
"platform": "all"
},
"inputQueryVariablesMetafieldNamespace": "upper-limit-discount",
"inputQueryVariablesMetafieldKey": "function-configuration"
},
"logType": "function_run",
"status": "success",
"source": "upper-limit-discount",
"sourceNamespace": "extensions",
"logTimestamp": "2026-02-19T14:52:28.708198Z",
"localTime": "2026-02-19 17:52:28",
"storeName": "x.myshopify.com"
}






