Using Shopify Scripts Automation to Create More Personalized Ecommerce Experiences

In Shopify’s own words, custom Shopify Scripts are small pieces of code that let you create personalized experiences for your online store customers in their cart and at checkout. They are available only for Shopify Plus merchants, and they can be used to build greater functionality, including automation, into any Shopify Plus site.

In this episode of Recommerce, Sara talks with Tiffany, Command C’s Tech Lead, about creative applications for Shopify Scripts, including setting up automatic processes for discounts, shipping, payment methods, and more.

You’ll learn:

  • Ways in which Shopify Plus’ core functionality gives developers lots of room for custom problem solving
  • The various types of Shopify Scripts, including those for shipping and payment applications
  • Concrete suggestions for applying discounts and free gift promotions with Shopify Scripts
  • How to use Script logic and product tags to create backend efficiency
  • Ideas for using custom Shopify Scripts to address a specific business need, such as applying a shipping surcharge. For example, maybe you sell unusually large items, like elephants. (OK, maybe not elephants, but you get the idea!)

Full Episode Transcript

Sara: Hello and welcome to another episode of Recommerce. I am Sara, the founder of Command C, and I’m here with Tiffany, our Tech Lead. Hi, Tif.

Tiffany: Good morning.

Sara: Good morning. Today, we are going to do demystify Shopify Scripts. Shopify Scripts are a Shopify Plus only feature, but what are they?

Tiffany: So, Shopify Scripts are a tool that’s provided to Plus merchants that allows us to programmatically modify the price of line items in the shopping cart object.

Sara: But what does that mean?

Tiffany: What that means is that rather than passing through a product at full price that we discount later with a coupon code or passing through a product at a reduced price that gets recorded as that reduced price, we are actually taking a discount off of the line item. With Scripts, we also have the ability to modify shipping method, presentation, and payment method presentation.

But one of the biggest, most powerful things that Scripts does is allows you to add discounts with either simple or complicated logic that the user can see right on the front end of the site. Shopify has a pretty good toolset for coupons, which I mentioned earlier. The idea of discounting an item when you enter a coupon code at checkout is a pretty common ecommerce thing. You can set up per product sale pricing.

With custom Shopify Scripts, we have the ability to modify shipping method, presentation, payment method presentation, and more.

Tiffany: The way Shopify does this is interesting. You actually change the product price to be the sale’s price, and the way that you identify that it’s on sale is by supplying the original price as what’s called a “compare at price”. This is not all that different from a front end user’s perspective. But from a backend perspective, it’s very different because we are not providing the product at a discounted price at this point. We’re actually providing the product at a price that we let everybody know is a discount, so it’s a little bit different than a true discount.

It also is not percentage based and there is no way to apply any kind of logic to it. The other problem with setting up your promotions in this way is that it can be very manual. So, let’s say you have a group of products that you’d like to offer at 25% off. So, all graphic tee shirts. We’re going to offer 25% off of all graphic tee shirts. You have a few options. You can add the compare at price for every single tee shirt in the whole store, making it what you want to be – 25% of the original price – but you’re still adding in a total number.

The products are going to show up as on sale in the store, so you have any logic or any frontend tools in place to watch for compare at pricing and to show sale pricing, those are all going to get triggered, and that may or may not be what you actually want. This promo may be something that you want to feel like it has an air of exclusivity, even though technically, it’s applied for everybody. And again, we’re editing every single product, so that can be a bit of a pain to manage. Assuming you have some tools that help you with it, it could also be alright.

The second way you could accomplish this would be to give everyone a code. Maybe you put it in a welcome banner on the homepage. Use “25graphictee” to get 25% off at checkout. But even if we pre-enter the code for the customer, so they arrive at checkout with a code already applied, they still don’t actually see their discount until checkout, unless we’ve used an app or some other theme modification to show it to them. In that case, you’re really limiting your options because those are all very specific use cases that require very specific programming.

So again, now the customer is not seeing their discount until checkout, they’ve added their item to the cart, they’re very excited that they’re going to get 25% off when they get to check out, but they have to remember to copy the code. We’re now encouraging them to move all around on the site instead of stay in the checkout funnel, and it’s not as effective as it wouldn’t be if they could see it right away as soon as they added the item to their cart.

Custom Shopify Scripts actually solve both of those problems, both the manual work problem and the problem of giving the customer instant gratification on their discount. First, we can define the products to which the discount should be applied with the logic in the Script itself. Scripts are a subset of Ruby. We get some cool real programming language stuff that we can do, and we apply the logic directly there. We say, “Ah, anything that’s tagged as graphic tees, we’re just going to go ahead and apply this discount on.”

Shopify Scripts solves both the manual work problem and the problem of giving the customer instant gratification on their discount.

Tiffany: We walk through all the line items in the cart. If one of them is tagged graphic tees, it gets the discount. We didn’t have to modify any of our product data whatsoever in order to apply that. Secondly, when the promo is done, we just shut the Script off. Or if we’ve set the Script up to be really smart and it has variables at the top that let you define what categories or tags get the discount, you just undo that in one place. You only edit the Script in that one place or you turn it off completely and now, you’re no longer offering that discount. Your customer service, and marketing folks rather, they only had to uncheck one box to shut this discount down and to open up a new promo potentially. So, Shopify Scripts are a really valuable tool for that.

Sara: Yeah, just listening to you talk, I’m hearing the time savings and efficiency that this creates. I know that Shopify has some constraints with using multiple discounts or discount codes at the same time. Does Scripts address this at all?

Tiffany: It really helps. It’s not a pure solution, but you can apply a discount in checkout on top of a line item discount that’s been added by Shopify Scripts. So, you would be able to, for example, offer this 25% off graphic tees and then, I as a customer, could still use my $10 off coupon that I got for my birthday in checkout.

There are a few caveats to this. There are some interesting ways that shipping Scripts work in particular with discount codes that require a little creative thinking, but nothing that we haven’t been able to work around.

Interlude: You are listening to Recommerce, a podcast for ecommerce wearable brands navigating technical complexity and change. Brought to you by Command C, a development team that saves ecommerce retailers from outdated tech and ineffective operations with a strong focus on Magento and Shopify Plus. You can learn more about how we help at

Sara: So, there are a few different kinds of Scripts. Can you talk through what those are and how they might be used?

Tiffany: Sure. In the first segment, we really focused a lot on line item Scripts and applying discounts to products that are in your cart. There are also shipping and payment methods Scripts. Shipping Scripts are really a way to control the presentation of shipping. So, we can hide and show different methods depending on cart attributes or depending on customer attributes.

We can also modify pricing. So if we ever wanted to offer a promotion where we’re offering free shipping in a specific method, then we could use Scripts to do that. And again, the power that comes with that is all the logic that we can apply. So, does the product meet the requirement for free ground shipping? If the product set does, let’s go ahead and apply a discount down to zero for the ground shipping method.

Shopify Scripts can give Shopify Plus merchants all sorts of flexibility in product discounts, shipping, and payments presentation.

Tiffany: Again, there are some limitations here and mostly where we see this used is in showing and hiding shipping methods as opposed to modifying the pricing of them, but that capability exists for you. A similar thing exists for payments. I think the use cases for this one or even smaller, but I can see a world in which you would want to restrict the payments that are available to specific cart types.

I think that once you reach that point, those decisions have to be entered into with a whole lot of understanding of how reducing payment methods impacts your conversion rate, but it does give you the opportunity to limit those things based on a set of logic, based on the information that comes into the cart, and some customer information.

Sara: I guess what I’m hearing, or at least what I’m thinking about, is kind of this perspective or approach of Shopify has apps and then Shopify has its core functionality. Well, Shopify doesn’t necessarily have apps, but there’s the app, ecosystem that apps tend to address very specific needs.

When Shopify introduces a new feature, it seems to me like they’re offering us tools that let developers get creative with how to use those tools. It seems like apps really kind of come in to solve this one specific problem, but the Shopify tools are more open-ended, and Scripts are really about that.

Shopify Plus’ core functionality tools are more open-ended – and Scripts are really about that.

Tiffany: Yeah. And funny and enough, editing Shopify Scripts is actually an app; it’s an app from Shopify though. But, that’s absolutely the case. There is an app, there are several actually, that will sort of, I don’t want to say fake accomplish, but they kind of fake accomplish discount stacking. There are pros and cons to using something like that, and if you don’t have Plus, that’s a great way to look at creating a promo ruleset that fits your marketing needs.

But with Plus, we have this feature. It’s not really that prescriptive in its use, so we can do a lot with it. One of my favorite examples of this is I don’t think I mentioned free gifts, but free gifts is another good way that we can use Scripts. Basically, we just take the price down to zero for if I buy two of these and I want to give you a free gift and you put this in your cart, the price for it goes down to zero. And that’s a really cool promo.

It’s common with sort of brick and mortar retailers to do buy one, get one, buy one, get one 50% off, or buy one and get a free gift, but it’s less common in ecommerce because it’s harder to accomplish. With Scripts, we can accomplish it. The only thing it doesn’t do is it doesn’t automatically add the item to the user’s cart for them.

So, we can do that programmatically with all of the other toolsets that Shopify gives us with liquid templating, with our ability to use the AJAX cart and JavaScript to add items to the cart to modify the cart on the front end. So, we can control how that free gift gets added with our traditional Shopify development, and then use Scripts to discount that free gift down to zero.

Sara: Are there any other creative ways in which we’ve used Scripts that we can leave our listeners with?

Tiffany: Sure. A recent one that comes to mind, it’s exactly like creating a free gift actually, except what we’re doing, instead of creating a free gift that we’re giving to the customer for checking out, we’re using it to satisfy a business operations need. So, an order, for example, needs to have a surcharge. Let’s say the item in that order weighs 6,000 pounds or is otherwise, really oddly shaped.

Sara: An elephant?

Tiffany: An elephant.

Sara: We have elephants here.

Tiffany: You have ordered an elephant and so, I will need to charge you a $100 surcharge on your order.

Sara: Not that bad.

Tiffany: Yeah, no. I mean, elephants are, it’s easy. I think I ordered a credenza that costs more in shipping than that recently. I should have just gotten an elephant.

Sara: Yeah. Come on, Tif.

Tiffany: But the need to apply that surcharge, and in particular, if that surcharge needs to be a line item in the order so that your ERP reads it as a line item and not a shipping charge, this becomes a really clever way to accomplish that goal.

Tiffany: The solution is that you create a product in your store that houses the surcharge, and then you use Scripts to effect the logic to set the fee for that product so that it is set correctly. And then if I ordered two elephants, it’s going to charge me $200 in surcharges, for example, if that’s the business logic that I want to apply. So, there are creative ways to leverage Scripts for business operations needs as well as for customer promotions and marketing means.

Sara: That’s really cool. Well, as always, it’s been a pleasure speaking with you and thank you so much for your time.

Tiffany: Thanks, Sara.