By continuing to use our website, you consent to the use of cookies. Please refer our cookie policy for more details.

    Getting Started with Shopify’s Script Editor

    Get a 50% discount on two t-shirts!

    Buy a pair of jeans and get the second one free

    These sentences can be quite daunting for eCommerce merchants. Offering promotions to customers helps drive both revenue and traffic, but figuring out the most effective and personalized way can be quite a challenge.

    The Shopify script editor lets you create personalized checkout experiences by creating Ruby scripts. These scripts can offer free shipping, automatically discount items, and modify payment gateways on the basis of who the customer is or what they have in their cart.

    The types of discounts and customizations you can make with these scripts include:

    • Discount products with specific tags to offer a percentage (%) or fixed ($) discounts, or a combination of both
    • Promotions with simple or complex logic (buy one, get one free, buy two get 10% off, buy four get 20% off)
    • Dynamic pricing with volume-based price breaks
    • Modifying, hiding, or re-ordering shipping options, prices, or payment gateway methods

    Types of Scripts

    Line item scripts – Affecting line items in a cart, these scripts can change prices and grant discounts. They run every time a product is added, removed, or modified in your cart.

    Shipping scripts – These scripts can change shipping methods and grant discounts on shipping rates. They run every time your customer accesses the shipping options page while checking out.

    Payment scripts – Interacting with payments, these scripts can re-order, rename, and hide payment gateways and run when your customer accesses the payment method page. However, these scripts do not interact with payment gateways such as Apple Pay or PayPal.

    Now, let’s take a look at some sample scripts –

    1. Percentage of all items

    This line item script multiplies the price of each line item in the cart by 0.9, resulting in a 10% discount.

     Input.cart.line_items.each do |item|
          item.change_line_price(item.line_price * 0.9, message: "10% off all items!")
        Output.cart = Input.cart

    2. Percentage of all shipping rates

    This line item script discounts all shipping rates by 0.10, resulting in a 10% discount on shipping.

      Input.shipping_rates.each do |shipping_rate|
          next unless shipping_rate.source == "shopify"
          shipping_rate.apply_discount(shipping_rate.price * 0.10, message: "Discounted shipping")
        Output.shipping_rates = Input.shipping_rates

    3. Free shipping for customers with a VIP tag

    This script offers free shipping to customers with a VIP tag.

    TAG = "vip" #customer tag
    MESSAGE = "VIP Customer Promotion" #additional message
    customer = Input.cart.customer
    if customer
      if customer.tags.include?(TAG)
    	Input.shipping_rates.each do |shipping_rate|
      	if"Insured Shipping and Handling (USPS Priority Express)")
        	shipping_rate.change_name("FREE VIP GROUND SHIPPING (USPS Priority Express)", { message: "" })
        	shipping_rate.apply_discount(shipping_rate.price, message: MESSAGE)
    Output.shipping_rates = Input.shipping_rates

    Scripts are a win-win for you as they let you build powerful promotions and increase conversions. Since the scripts are on Shopify’s servers, this reduces the trouble of having to constantly maintain them.

    Should you need help in using Scripts, send us an email at [email protected] and we’ll take it from there!