Skip to main content

Migrating from Shopify Scripts to Shopify Functions

Deprecated

Shopify Scripts was sunset on June 30, 2026. Any Scripts that were still published on your store have been deactivated and no longer function.

Functions availability

This guide shows how to migrate your Shopify Scripts to Shopify Functions and validate the new Functions with tagged test customers before enabling them for everyone. Shopify Scripts allowed you to customize cart behavior, shipping, and payment methods in a store. With Shopify Functions, these customizations are now handled through dedicated Function APIs that offer better performance and flexibility.


In this tutorial, you'll learn how to do the following tasks:

  • Map your Shopify Scripts functionality to the right Shopify Functions.
  • Verify new Functions with tagged test customers in production.
  • Enable your verified Functions for all customers.

  • You have an existing Shopify Script that you want to migrate.
  • You have access to a dev store for initial testing.
  • You're familiar with creating Shopify Functions using Shopify CLI.
  • You can open the Script Editor app in read-only mode to reference your original Script logic. The Script Editor is available until July 30, 2026.

Anchor to Function APIs mappingFunction APIs mapping

Use the following table to map your existing Shopify Script to the appropriate Function API:

Shopify Script typeShopify Function APIUse case
Line item scriptsDiscounts APIApply discounts to products, or the entire cart.
Line item scriptsCart Transform APIModify cart line items (bundle, merge, or add items).
Line item scriptsCart and Checkout Validation APIValidate cart contents and block checkout under specific conditions.
Shipping scriptsDelivery Customization API and Discounts APIHide, rename, or reorder delivery methods, and apply discounts to delivery methods.
Payment scriptsPayment Customization APIHide, rename, or reorder payment methods.

Anchor to Step 1: Add testing logic to your FunctionStep 1: Add testing logic to your Function

In your Shopify Function, add logic to target specific test users. The most reliable method is using customer tags.

  1. In the Shopify admin, go to Customers and add a tag like TESTER to customers who should experience the new Function behavior.

  2. In your Function's input query, include customer tag information:

    src/run.graphql

    query Input {
    cart {
    buyerIdentity {
    customer {
    hasAnyTag(tags: ["TESTER"])
    }
    }
    # ... rest of your query
    }
    }

Anchor to Implement conditional logicImplement conditional logic

Add conditional logic in your Function to only apply new behavior to tagged customers:

File

// Check if the customer has the TESTER tag
let has_tester_tag = input
.cart()
.buyer_identity()
.and_then(|bi| bi.customer())
.map(|customer| customer.has_any_tag())
.unwrap_or(&false);

if *has_tester_tag {
// Apply new Function logic here
// ... your function implementation
} else {
// Untagged customers receive no operations during validation
return Ok(FunctionRunResult { operations: vec![] });
}
const customer = input.cart.buyerIdentity?.customer;
const hasTesterTag = customer?.hasAnyTag ?? false;

if (hasTesterTag) {
// Apply new Function logic here
// ... your function implementation
} else {
// Untagged customers receive no operations during validation
return { operations: [] };
}

Because Shopify Scripts no longer run, untagged customers receive none of this customization while the tag condition is in place. Keep the tagged validation period short, then remove the condition and enable the Function for all customers, as described in Step 3.


Anchor to Step 2: Deploy and test in productionStep 2: Deploy and test in production

You can test your Function in development and production.

  1. Test your Function thoroughly in a dev store:

    Terminal

    shopify app dev

Anchor to Production deployment and testingProduction deployment and testing

Choose one of the following deployment methods:

Anchor to Option A: App with configuration UIOption A: App with configuration UI

If your Function is part of an app with a user interface, then use the app to enable and configure the Function in production.

Anchor to Option B: GraphiQL deploymentOption B: GraphiQL deployment

Note

This method works best for Functions that don't require ongoing merchant configuration.

If you have a custom Function without UI configuration, then complete the following steps:

  1. Use the Shopify GraphiQL App to enable the Function directly.

  2. Retrieve a list of available Functions using this query:

    query.graphql

    query getFunctions {
    shopifyFunctions(first: 100) {
    edges {
    node {
    id
    title
    apiType
    }
    }
    pageInfo {
    hasNextPage
    endCursor
    }
    }
    }
  3. Use the Function's id in the appropriate creation mutation for your Function type (for example, discountAutomaticAppCreate or deliveryCustomizationCreate).


Anchor to Step 3: Complete the migrationStep 3: Complete the migration

After you've verified that the Function works correctly:

  1. Remove testing code: Update your Function to remove the customer tag conditional logic.

  2. Deploy the final version:

    Terminal

    shopify app deploy

  • Always test in a dev store before deploying to production.
  • Keep the testing period short to minimize code complexity.
  • Monitor your store's performance and error logs after migration.
  • Document any differences in behavior between Scripts and Functions.
  • Test edge cases that might behave differently between Scripts and Functions.

You might encounter the following issue during migration:

  • Function not triggering: Verify the Function is properly enabled and configured.
  • Different behavior: Check the input data structure your Function receives.


Was this page helpful?