> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.ordergroove.com/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.ordergroove.com/_mcp/server.

# Free shipping on initial orders

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](https://help.ordergroove.com/hc/en-us/articles/4406641707923-Shopify-Shipping-and-Delivery#h_01GSBNF4X0QT5RQ97JG98T5PVB).

#### 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](https://developer.ordergroove.com/docs/copy-of-free-shipping-on-initial-orders). 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](https://shopify.dev/docs/apps/build/functions).

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](https://shopify.dev/docs/apps/build/discounts/build-discount-function?extension=javascript).

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)](/docs/lifecycle/enrollment/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:

   ```graphql
   query DeliveryInput {
     cart {
       lines {
         sellingPlanAllocation {
           sellingPlan {
             id
           }
         }
         merchandise {
           __typename
         }
       }
       deliveryGroups {
         id
         deliveryOptions {
           handle
         }
       }
     }
   }
   ```

8. Edit `ordergroove-discount/src/cart_delivery_options_discounts_generate_run.js` — replace the full file with:

   ```javascript
   /**
    * @typedef {import("../generated/api").Input} Input
    * @typedef {import("../generated/api").CartDeliveryOptionsDiscountsGenerateRunResult} CartDeliveryOptionsDiscountsGenerateRunResult
    */

   /**
    * cartDeliveryOptionsDiscountsGenerateRun
    *
    * If the cart has at least one line with a selling plan (subscription),
    * apply 100% off shipping (free shipping) to all delivery groups.
    *
    * Mixed carts are allowed: as long as there is at least one subscription line,
    * all delivery options are discounted to free.
    *
    * @param {Input} input
    * @returns {CartDeliveryOptionsDiscountsGenerateRunResult}
    */
   export function cartDeliveryOptionsDiscountsGenerateRun(input) {
     const cart = input.cart;

     // No cart or no lines => nothing to do.
     if (!cart || !cart.lines || cart.lines.length === 0) {
       return { operations: [] };
     }

     // 1. Check if there is at least one line with a selling plan allocation.
     const hasSellingPlanLine = cart.lines.some((line) => {
       return Boolean(line.sellingPlanAllocation);
     });

     // If there are no subscription lines, do not discount shipping.
     if (!hasSellingPlanLine) {
       return { operations: [] };
     }

     const message = "Free shipping for subscription orders";

     // 2. Build discount candidates for each delivery group.
     const candidates = [];

     if (Array.isArray(cart.deliveryGroups)) {
       for (const group of cart.deliveryGroups) {
         if (!group || !group.id) continue;

         candidates.push({
           targets: [
             {
               deliveryGroup: {
                 id: group.id
               }
             }
           ],
           message,
           // 100% off shipping => free shipping
           value: {
             percentage: {
               value: 100
             }
           }
         });
       }
     }

     if (candidates.length === 0) {
       return { operations: [] };
     }

     // 3. Wrap candidates in the deliveryDiscountsAdd operation.
     return {
       operations: [
         {
           deliveryDiscountsAdd: {
             candidates,
             selectionStrategy: "ALL"
           }
         }
       ]
     };
   }
   ```

9. Run `shopify app deploy`

***

## Further Customizations

For further customizations, see [Shopify's documentation on the Functions API](https://shopify.dev/docs/api/functions/latest). You'll find [great examples of building Functions](https://shopify.dev/docs/apps/build/discounts/build-discount-function) that you can adapt for your subscription program.