Customizing the Initial Offer Incentive (IOI)
If you are trying to offer your customers an Initial Offer Incentive, you may be able to use our feature in your Ordergroove Admin. However, if you want to customize your customer experience even further, we recommend you use Shopify Functions.
Shopify Functions inject code into the backend logic of Shopify. These allow you to create unique experiences for your customers in their cart and at checkout. Find out more in Shopify's Help Center articles.
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 paid app from the Shopify app store. Custom apps can only be made by Shopify Partners - so this guide is meant for developers working with Shopify clients.
Getting Started
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 at high-level:
- App developers create and deploy apps that contain functions.
- Merchants install the app on their Shopify store and configure the function. An API call is made with the function configuration.
- Customers interact with a Shopify store and Shopify executes the function.
You can use Shopify apps to generate Functions. Or, if you need complete control, you can create your own Function. For an Initial Offer Incentive (IOI) you will need a Discount Function.
You can read the full documentation here on creating a Shopify Discount Function.
Here is a quick start guide on creating a basic Discount Function app to discount subscription line items by 20%. This can be combined with our Free shipping on initial orders Discount Function.
Note: This guide is accurate as of Shopify Function API version 2026-01.
- Use Shopify CLI version 3.69.4+
- Use Node version 22.9.9+
- Navigate to a local directory on your computer where you want to create the app
- Run the command
shopify app initto create an app- Select
Build an extension-only app - Select
Yes, create it as a new app - Name your app (example:
ordergroove-discount) - You can now see your app in your Shopify Partner Dashboard
- Select
- Run
cd ordergroove-discount - Run
shopify app generate extension- Select the extension to create
- Name your extension
- Select Language (the example code below assumes Javascript)
- Edit file:
ordergroove-discount/src/cart_lines_discounts_generate_run.graphql
Replace full file with below code:query CartInput { cart { lines { id quantity sellingPlanAllocation { sellingPlan { id name } } merchandise { __typename ... on ProductVariant { id title } } } } } - Edit file:
ordergroove-discount/src/cart_lines_discounts_generate_run.jsReplace full file with below code:
import { ProductDiscountSelectionStrategy } from '../generated/api';
/**
* @typedef {import('../generated/api').Input} Input
* @typedef {import('../generated/api').CartLinesDiscountsGenerateRunResult} CartLinesDiscountsGenerateRunResult
*/
/**
* cartLinesDiscountsGenerateRun
*
* If a cart line has a sellingPlanAllocation (i.e. it's on a subscription / has a selling plan),
* apply a flat 20% discount to that line.
*
* @param {Input} input
* @returns {CartLinesDiscountsGenerateRunResult}
*/
export function cartLinesDiscountsGenerateRun(input) {
const DISCOUNT_PERCENTAGE = 20; // 20%
const candidates = [];
if (!input.cart?.lines || input.cart.lines.length === 0) {
return { operations: [] };
}
for (const line of input.cart.lines) {
// Only consider product variants with a selling plan allocation
if (
line.merchandise.__typename !== 'ProductVariant' ||
!line.sellingPlanAllocation
) {
continue;
}
const variant = line.merchandise;
const message = variant.title
? `${DISCOUNT_PERCENTAGE}% off subscription for ${variant.title}!`
: `${DISCOUNT_PERCENTAGE}% off this subscription!`;
candidates.push({
value: {
percentage: {
value: 20
},
},
targets: [
{
productVariant: {
id: variant.id,
quantity: line.quantity,
},
},
],
message,
});
}
if (candidates.length === 0) {
return { operations: [] };
}
return {
operations: [
{
productDiscountsAdd: {
candidates,
selectionStrategy: ProductDiscountSelectionStrategy.First,
},
},
],
};
}- Run
shopify app deploy
Further Customizations
For further customizations to the above script, you can reference Shopify's excellent documentation on the Shopify Help Center. You'll find great examples of building Functions that you can adapt and use with your subscription program.
Related Articles
Updated about 7 hours ago
