Example scripts

Scripts are flexible and can be used to create unique and powerful discounts. For example, you can create scripts that change the prices and properties of line items in your store's cart based on the items that a customer adds to it.

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

To help you get started, the following are some common scripts that you can modify according to your requirements.

Script templates

There are three kinds of scripts: line item scripts, shipping scripts, and payment gateway scripts.

Line item scripts

Line item scripts affect items in a cart, and can change their properties and prices. These scripts run each time that a cart attribute is changed, such as adding or removing an item, changing the shipping address, or adding a discount code. The templates included with the app are:

  • Percentage (%) off a product
  • Amount ($) off a product
  • Percentage (%) and amount ($) off a product
  • Bulk discounts
  • Buy one get one free (BOGO)

For more examples of line item scripts, refer to Line item script examples.

Shipping scripts

Shipping scripts interact with shipping rates, and can change a rate's title, visibility, display order, and price. These scripts run each time that your customer accesses the shipping options page at checkout. The templates included with the app are:

  • Modify shipping rate price
  • Modify shipping rate name
  • Hide shipping rates
  • Reorder shipping rates

For more examples of shipping scripts, refer to Shipping rate script examples.

Payment scripts

Payment scripts interact with payment gateways, and can change a gateway's title, visibility, and display position. These scripts run each time that your customer accesses the payment method page at checkout. Payment scripts don't interact with accelerated checkouts, because accelerated checkouts are displayed to your customers before they reach the checkout page. The templates included with the app are:

  • Modify payment gateway name
  • Hide payment gateway
  • Reorder payment gateways

For more examples of payment gateway scripts, refer to Payment gateway script examples.

In this section

Ready to start selling with Shopify?Try it free