Free shipping on initial orders

Use Shopify Functions to offer free shipping when customers first purchase a subscription
View as Markdown

If you are on Shopify Plus, you can use Shopify Functions to give customers free shipping when they purchase a subscription from your store. This applies to the initial order when a customer checks out with a subscription. You can also set up free shipping for recurring orders from the Flex Incentives page within Ordergroove.

Note that free shipping configured in Ordergroove only applies to recurring subscription orders, not the initial checkout order. See this article for more information about subscription shipping and delivery for Shopify.

Looking for the legacy Shopify Scripts version?

If you are maintaining an existing implementation or migrating from Shopify Scripts, you can still access the original Scripts-based guide here. Please note that Scripts will stop functioning on June 30, 2026.


Requirements

Shopify Functions require a custom app or a paid app from the Shopify App Store. Custom apps can only be made by Shopify Partners — this guide is intended for developers working with Shopify clients.


Instructions

Shopify Functions allow developers to customize the backend logic of Shopify. Functions are continually being updated, so it is best to first reference Shopify’s official documentation.

At a high level:

  • App developers create and deploy apps that contain functions.
  • Merchants install the app on their Shopify store and configure the function via an API call.
  • Customers interact with the Shopify store and Shopify executes the function.

You can use Shopify apps to generate functions, or create your own for complete control. For free shipping on initial subscription orders you will need a Delivery Discount Function.

Read the full documentation on creating a Shopify Discount Function.

The following is a quick start guide for creating a basic Delivery Discount Function app that provides free shipping on subscription orders. This can be combined with the Initial Offer Incentive (IOI) Product Discount Function.

Note: This guide is accurate as of Shopify Function API version 2026-01.

  1. Use Shopify CLI version 3.69.4+

  2. Use Node version 22.9.9+

  3. Navigate to a local directory where you want to create the app

  4. Run shopify app init to create an app:

    1. Select Build an extension-only app
    2. Select Yes, create it as a new app
    3. Name your app (e.g. ordergroove-discount)
    4. The app will now appear in your Shopify Partner Dashboard
  5. Run cd ordergroove-discount

  6. Run shopify app generate extension:

    1. Select the extension to create
    2. Name your extension
    3. Select a language (the example code below assumes JavaScript)
  7. Edit ordergroove-discount/src/cart_delivery_options_discounts_generate_run.graphql — replace the full file with:

    1query DeliveryInput {
    2 cart {
    3 lines {
    4 sellingPlanAllocation {
    5 sellingPlan {
    6 id
    7 }
    8 }
    9 merchandise {
    10 __typename
    11 }
    12 }
    13 deliveryGroups {
    14 id
    15 deliveryOptions {
    16 handle
    17 }
    18 }
    19 }
    20}
  8. Edit ordergroove-discount/src/cart_delivery_options_discounts_generate_run.js — replace the full file with:

    1/**
    2 * @typedef {import("../generated/api").Input} Input
    3 * @typedef {import("../generated/api").CartDeliveryOptionsDiscountsGenerateRunResult} CartDeliveryOptionsDiscountsGenerateRunResult
    4 */
    5
    6/**
    7 * cartDeliveryOptionsDiscountsGenerateRun
    8 *
    9 * If the cart has at least one line with a selling plan (subscription),
    10 * apply 100% off shipping (free shipping) to all delivery groups.
    11 *
    12 * Mixed carts are allowed: as long as there is at least one subscription line,
    13 * all delivery options are discounted to free.
    14 *
    15 * @param {Input} input
    16 * @returns {CartDeliveryOptionsDiscountsGenerateRunResult}
    17 */
    18export function cartDeliveryOptionsDiscountsGenerateRun(input) {
    19 const cart = input.cart;
    20
    21 // No cart or no lines => nothing to do.
    22 if (!cart || !cart.lines || cart.lines.length === 0) {
    23 return { operations: [] };
    24 }
    25
    26 // 1. Check if there is at least one line with a selling plan allocation.
    27 const hasSellingPlanLine = cart.lines.some((line) => {
    28 return Boolean(line.sellingPlanAllocation);
    29 });
    30
    31 // If there are no subscription lines, do not discount shipping.
    32 if (!hasSellingPlanLine) {
    33 return { operations: [] };
    34 }
    35
    36 const message = "Free shipping for subscription orders";
    37
    38 // 2. Build discount candidates for each delivery group.
    39 const candidates = [];
    40
    41 if (Array.isArray(cart.deliveryGroups)) {
    42 for (const group of cart.deliveryGroups) {
    43 if (!group || !group.id) continue;
    44
    45 candidates.push({
    46 targets: [
    47 {
    48 deliveryGroup: {
    49 id: group.id
    50 }
    51 }
    52 ],
    53 message,
    54 // 100% off shipping => free shipping
    55 value: {
    56 percentage: {
    57 value: 100
    58 }
    59 }
    60 });
    61 }
    62 }
    63
    64 if (candidates.length === 0) {
    65 return { operations: [] };
    66 }
    67
    68 // 3. Wrap candidates in the deliveryDiscountsAdd operation.
    69 return {
    70 operations: [
    71 {
    72 deliveryDiscountsAdd: {
    73 candidates,
    74 selectionStrategy: "ALL"
    75 }
    76 }
    77 ]
    78 };
    79}
  9. Run shopify app deploy


Further Customizations

For further customizations, see Shopify’s documentation on the Functions API. You’ll find great examples of building Functions that you can adapt for your subscription program.