Building a shipping script

In this tutorial, you’ll learn how to create a basic shipping script and deploy it to a custom app.

What you'll learn

After you've finished this tutorial, you'll have accomplish the following:

  • Created a basic shipping script using Shopify CLI
  • Deployed your script to the Shopify platform and associated it with a custom app
  • Enabled the script in a Shopify store
  • Placed a test order in your store to confirm your script is working as expected

The following diagram shows the steps you'll follow to complete the workflow:

A diagram showing the steps involved in building a shipping script

Requirements

Step 1: Create the script

Using Shopify CLI, run the following command:

Update the shipping script

Replace the contents of your shipping script src/script.ts with the code below. shippingMethodsHandler runs when a customer reaches the shipping page at checkout and all shipping rates are returned. The results of this function are the sort order, shipping methods to remove, or shipping methods to rename.

Step 2: Deploy the script

To deploy a script to the Shopify platform and associate it with a custom app, run the following command:

Step 3: Enable the script

By default, scripts are available to be used on a store with the app installed, but they aren't enabled. To alter the behavior of checkout, you need to enable the script:

  1. In your store's Shopify admin, click Settings.
  2. Click Shipping and delivery.
  3. In the Rate customizations section, click Create customization.
  4. Select the script to enable and update its status to On.
  5. Click Save.

Step 4: Place a test order

Place a test order in your store and go through the checkout steps. The first shipping rate shouldn't show at the shipping step:

A screenshot showing the first shipping rate removed at the shipping step

Next steps