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:
- Custom apps built with theStorefront API,JavaScript Buy SDK,Mobile Buy SDKs(Android and iOS)
- Custom apps that generate checkouts
- Tapcart,Plobal Apps, andVajromobile app builders
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.
- Open theScript Editor. TheScriptsoverview page shows a list of scripts for your store.
- ClickCreate scriptto begin creating a new script.
- In theSelect script templatedialog:
- Choose the type of script that you want to create.
- Choose an example template as a starting point, or chooseBlank templateto start writing a script from scratch.
- ClickCreate scriptto create a script with the type that you have chosen.
- In theTitlebox, enter a name for the script. Use a descriptive name so you can tell what the script does at a glance.
- ClickCodeto open theRuby source codeconsole.
- Enter the code for your script. Use theShopify脚本API文档作为参考。
- ClickRun scriptto run the script.
- 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.