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:
- You've installed Shopify CLI.
- You've created a custom app. Shopify Scripts currently only supports custom apps.
- You've installed the custom app on a store.
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:
- In your store's Shopify admin, click Settings.
- Click Shipping and delivery.
- In the Rate customizations section, click Create customization.
- Select the script to enable and update its status to On.
- 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: