Creating and enabling scripts

You write scripts in theShopify Scripts API. This API is a version of the Ruby programming language, so you need experience in programming with Ruby. Use theScript Editorto create, edit, test, and publish your scripts.

Before you start writing a script, you should review the differenttypes (line item, shipping, and payment) of scriptsso that you are aware of the methods that each script type supports. For example, a line item script cannot use shipping methods.

Only one script per script type can be published at one time. For example, you can publish a line items script and a shipping rates script, but you can't publish two line items scripts at the same time.

Supported channels

When you create (or edit) a script, you choose whether it will run in your online store only or in your online store and in the following apps:

You can find examples of common scripts in thescript templatesthat are provided in the Script Editor. To view these templates, you need to create a script.

Create a script

To create a script:

Review theShopify Scripts APIfor a reference on writing code for scripts.

  1. Open theScript Editor. TheScriptsoverview page shows a list of scripts for your store.
  2. ClickCreate scriptto begin creating a new script.
  3. In theSelect script templatedialog:
    1. Choose the type of script that you want to create.
    2. Choose an example template as a starting point, or chooseBlank templateto start writing a script from scratch.
    3. ClickCreate scriptto create a script with the type that you have chosen.
  4. In theTitlebox, enter a name for the script. Use a descriptive name so you can tell what the script does at a glance.
  5. ClickCodeto open theRuby source codeconsole.
  6. Enter the code for your script. Use theShopify脚本API文档作为参考。
  7. ClickRun scriptto run the script.
  8. When you are finished:
    • clickSave draftto save an unpublished draft of the script
    • clickSave and publishto create and publish the script.

Next steps

After you have written a script, you shouldtest and debugit before youpublishit. You can also canupdate your Liquid template filesso that your storefront responds to the changes that your scripts make.

Ready to start selling with Shopify?

Try it free