Order discount function api not returning deliveryGroups

Topic summary

Order discount function cannot access deliveryGroups at checkout, preventing address-based discounts. Logs show deliveryGroups returns an empty array, and the metafield is null.

Key update:

  • Shopify internal confirmation: for discount functions, deliveryGroups will always be null. This is a current platform limitation; the field is intended to be hidden for certain Function APIs.

Context:

  • Developer’s GraphQL input requests cart.deliveryGroups (address and selectedDeliveryOption) to validate shipping address and apply an order-level percentage discount.
  • Function code and extension logs demonstrate the missing deliveryGroups data, blocking the intended logic.
  • Related community threads report the same behavior.

Implications:

  • Address-based logic for order discounts cannot rely on deliveryGroups in discount functions.
  • Documentation may need clarification to prevent misleading expectations.

Workarounds under exploration:

  • Using a Checkout UI Extension for address validation and signaling the discount function (unclear how to pass state reliably).
  • Using a shipping discount function to set a cart attribute that the order discount function reads, but execution order cannot be controlled.

Status:

  • Limitation acknowledged; no fix or timeline provided. Developer requests guidance on viable alternatives; discussion remains open.
Summarized with AI on January 10. AI used: gpt-5.

Hello Partners community,

My team is building an app that applies an order discount based on shipping address entered at checkout. We have been using an order discount function for this but it seems that there is a bug preventing us from continuing… Since we have tried with Shopify scripts with no success due to checkout.liquid being deprecated. Having explored many workarounds for months now it simply doesn’t seem possible for us to implement our desired discount functionality based on the input.cart.deliveryGroups object returning an empty array.

Here is my input.graphql -

query Input {
  cart {
    deliveryGroups {
      deliveryAddress {
        address1
        address2
        city
        countryCode
        provinceCode
        zip
      }
      selectedDeliveryOption {
        code
        deliveryMethodType
      }
    }
  }
  discountNode {
    metafield(namespace: "budi-discount-order", key: "function-configuration") {
      value
    }
  }
}

Here is my function code:

import {
  InputQuery,
  FunctionResult,
  DiscountApplicationStrategy,
  Discount,
} from "../generated/api";
import { validateBudiDeliveryGroup } from "../../../utils/validateBudiDeliveryGroup";

export default (input: InputQuery): FunctionResult => {
  let discounts: Discount[] = [];
  const eligibleForPercentageDiscount = input.cart.deliveryGroups.find(
    (group) => {
      return (
        group.selectedDeliveryOption?.code === "Standard" &&
        validateBudiDeliveryGroup(group)
      );
    }
  );

  if (eligibleForPercentageDiscount) {
    const discountValue = parseInt(
      input.discountNode?.metafield?.value || "0",
      10
    );

    discounts.push({
      value: {
        percentage: {
          value: discountValue,
        },
      },
      message: `${discountValue}% off from BUDI`,
      targets: [
        {
          orderSubtotal: {
            excludedVariantIds: [],
          },
        },
      ],
    });
  }

  return {
    discountApplicationStrategy: DiscountApplicationStrategy.First,
    discounts,
  };
};

When this function runs successfully at checkout here is the input from the extension logs, where the empty array is evident:

Input (STDIN)

{
  "cart": {
    "deliveryGroups": []
  },
  "discountNode": {
    "metafield": null
  }
}

Here are a few other posts where partners are also facing this issue:

Another partner mentioned they were in touch with support and there is a ticket for this to be fixed, can we please have some clarity around this - whether Shopify is aware and there is a ticket to fix it?

Best regards,
Lucas

2 Likes

Hi Lucas,

Thanks for flagging this, I’ve reached out to our internal team to get more info on this. Will report back here asap.

1 Like

Hi again - I’ve confirmed with our internal functions team that this is a known limit of discount functions - delivery groups will always be null. The intention is to hide this field for certain Function APIs.

Hi Liam - thanks for chasing this up! Ah that’s a shame it will always be null.. When we were exploring the API docs prior to commencing development we believed the deliveryGroups data would be attainable - might be worth clarifying this limitation in the docs for future devs.

Currently exploring a workaround where the address validation is achieved via checkout ui extension, I’m struggling to pass this validation into the order discount function to enable/disable effectively.. Do you know any other way our desired functionality could be achieved?

Previously we’ve tried using the shipping discount function to run our address validation then add/remove an attribute from the cart for which the order discount function would check for. The problem we had here was not being able to control which function runs first.

Thanks again for your help mate.

1 Like