Unlocking the Full Potential Of Shopify Functions

Author

Christine Hannivan

Date

Reading time

10 mins
Shopify Functions

When everyone is using the same platforms and tools for their ecommerce businesses, how do you stand out in the crowd?

An alternative to Shopify Scripts, Shopify Functions offers easy customization by enabling you to adapt the behavior of your store’s checkout page to meet specific customer preferences and scenarios. These custom bits of code enhance your site's behavior and boost sales with real-time responsiveness.

In this guide, we’ll break down all the capabilities of Shopify Functions, highlighting how they enhance transactions, user experience and, ultimately, increase your store's revenue through real-time, server-side operations.

What are Shopify Functions?

A successor to the more limited and soon-to-be-sunset Shopify Scripts, Shopify Functions are small, isolated bits of code that you can write into Shopify's infrastructure to customize the behavior of a given shopping cart based on specific rules and triggers. They provide a way to hook into native Shopify behaviour, empowering you to define custom business logic that Shopify will execute on your store's behalf. 

One advantage Functions have over Scripts is that stores can have many active Functions affecting the same order and order lines, shipping lines, and payment lines concurrently. This was previously impossible with Scripts, making Functions the clear winner between both customization methods.

It's important to note that Shopify Functions operate exclusively on the server side, meaning changes occur instantaneously and require zero input from your customers. This real-time responsiveness translates to smoother transactions, enhanced user experience, and ultimately increased revenue.

Shopify Function Examples

There are currently nine Shopify Function APIs available for developers to leverage to add additional functionality/logic to their store’s checkout. These APIs cover various use cases across your store’s entire checkout experience, including payment customization, cart and checkout validation, delivery customization, product, order, and shipping discounts, fulfillment constraint logic, and cart transformation. 

Users in the Checkout and Customer Accounts Extensibility developer preview can also access an Order Routing Location Rule API and a Discounts Allocator API. 

Here is a breakdown of each Shopify Function API that is currently available to merchants and what they can be used for:

Order Discount API 

One of the most straightforward APIs, the Order Discount API allows you to add a new type of discount to all items where you can expose custom business logic. Once your new discount type is created, you can define multiple instances based on your needs. 

For example, let’s say your company sells in Canada and the United States, and you want to set up a discount that takes a percentage off of the cart total only in a single market after a certain threshold in the cart. Instead of having to configure a global threshold for this discount as you would with native Shopify functionality, you can set up two separate instances–one for the U.S. market and another for the Canadian market–so that you can accommodate two different currencies without having to rely on the daily conversion rate, making it easier to stay consistent in your marketing and on your website. 

Shopify Functions Discount

Product Discount API

Similar to the Order Discount API, the Product Discount API lets you create a new type of discount for specific individual products in the cart. Like the Order Discount API, this API can expose custom business logic and define multiple instances of your discounts once created. 

Rather than creating a 20% off promotion for everything at your store in a specific market, you could use this API to create 20% off promos for specific items, for example. 

This API is great for promos where you might want to offer a 2 for $22-style promotion in the Canadian market only, where if a customer buys two items with the same tag, they get a reduced price. You could then create a separate version of this promo for your U.S. customers where they get a similar discount (say, 2 for $20) to offer a consistent price in both markets without dealing with a constantly changing exchange rate. 

Shipping Discount API

This API allows you to create discounts that will be applied to one or more of your available shipping rates/options at checkout. You can leverage this to create free shipping offers, add discounts to rates–either monetary value or percentage-wise–or add discounts to specific rates.

For example, you can use this API to add a 25% discount to your express shipping option for orders placed in the last week before the holidays, when customers will need to receive their items quickly.  

Delivery Customization API

This API enables sorting, renaming, and reordering the delivery options available to your customers at checkout. For example, you could use this API to hide certain delivery options in a certain market or if the order contains oversized items. 

You could also use this option to reorder your store’s delivery options based on user preference or even add messaging to delivery option titles to provide additional information to your customers at checkout. 

Payment Customization API

Similar to the Delivery Customization API, the Payment Customization API enables you to rename, reorder, and sort the payment methods available to your customers on your checkout page. For example, you can show/hide certain payment options for customers in specific countries or for carts with totals above or below a value of your choice. 

Cart Transform API

This API is a step above all of the discount APIs we mentioned above as it enables you to change both the pricing as well as the merchandising of cart line items. While we’ll break down a more in-depth example of what this API can do below, the Cart Transform API is essentially the tool you can use to create bundles by automatically merging items together and applying a discount or updating line items to override their price, title, or even product images. 

Cart and Checkout Validation API

The Validation API allows developers to customize cart and checkout validation for their unique needs–express checkout options included. One use case for this API could be specifying quantity limits so scalpers cannot purchase more than a certain amount of a single item (great for limited edition items or products with limited quantities available). 

You could also leverage this API to age-gate certain products so that individuals under a certain age, say 18 or 21, cannot purchase items at your store or even restrict the ability to complete a purchase unless the customer is a logged-in user of your website.  

Fulfillment Constraints Function API

This API gives developers the freedom to provide their own logic for how Shopify should fulfill and allocate an order. Currently, this API doesn’t support local pickup options but allows changes for Checkout, Subscriptions, and Draft Order invoices. 

One use case for this API could be ensuring that certain cart line items are fulfilled from one specific location if you have multiple, or the opposite–ensuring they are fulfilled from any locations on the list. This can satisfy common OMS use cases such as geofencing and limiting split shipping.

Local Pickup Delivery Option Generator API

Still in beta and only available by request, this API enables developers to generate custom local pickup options available during checkout based on custom rules. For example, you can use this API to add a price/extra cost to an otherwise free local pickup option if the cart contains bulky or heavy items that will be difficult for store employees to pack/process. 

Order Routing Location Rule API 

With this API currently in developer preview, developers can provide their own location ranking for each item in the cart during order routing by creating rules that drive how Shopify recommends the admin fulfill orders.

For example, you can rank locations relative to each other, prioritize/deprioritize locations based on specific factors, or fulfill orders from the closest available location. This can typically impact limiting split shipping, maximizing inventory at certain locations during peak periods, and liquidating inventory from certain locations during store closures.

Discounts Allocator API

Lastly, and also still in developer preview, is the Discounts Allocator API, which allows users to provide their own logic for how discounts should be calculated and allocated to a given cart. 

A few use cases here could be setting a maximum discount for a given cart–say, no more than $100, setting the limit for the amount of discounts that can be applied at once, or applying discounts to only the cheapest or most expensive item in the cart. The most requested feature this function solves for, however, is the ability to stack multiple discounts on a single line item, which previously was not possible with Shopify. 

Now that we've covered all the individual APIs let's get into how Shopify Functions actually work.

How do Shopify Functions Work?

First, it’s important to note that access to these Shopify checkout Function APIs is only available to stores that have upgraded to Checkout Extensibility. While any store can install public apps from the Shopify App Store using Functions, Shopify limits the ability to build and install custom apps using their Function APIs to users on the Commerce Components and Shopify Plus Plans. 

Additionally, some APIs, such as the Cart Transform API update operations and the Order Routing Rule API, won't work for any stores below the Plus plan. 

Even though the number of customizations that can be achieved with Functions is almost endless, the underlying concept is relatively simple. Shopify developers can write Functions in any programming language that supports WebAssembly, such as JavaScript, Rust, or TypeScript. As long as they can run in under 5 milliseconds, they can be used anywhere on the checkout for any use case that developers can find that makes use of Shopify’s eleven APIs.

Shopify Functions UI

What’s especially handy about Shopify Functions is that while someone with development skills will need to write them, businesses won’t have to touch any code to interact with them once finished. Everything can be done right in the Shopify admin as long as their developer builds in a Shopify App Bridge UI to allow them to interact with their Function right in their store’s backend.

 For example, let’s say you want to build a Function that automatically bundles specific items in the cart and applies a discount if a certain condition is met. I.e. if you’re a wellness brand and a customer adds a pair of leggings, a sports bra, and ankle weights to your cart, they’ll have met the criteria for the “get started with fitness” bundle. 

Shopify Functions Bundle

A developer could use the Cart Transform Function API to group these items together and add a 20% discount to the total cost of all three items, leaving anything else in the cart untouched. 

With the App Bridge UI set up, the store’s owner can then head into their Shopify Admin and create or remove as many different bundles as they’d like. These bundles will then appear in the customer’s cart without any additional steps needed on their end. All of this happens transparently to the end user, who sees the bundle’s creation in the cart and the discount being applied automatically and clearly. 

Not only is this a great way to create and offer product bundles, but it also helps to build a sense of trust in your company, as it shows that your business cares about helping its customers save money since the products are merged in the cart without them knowing they were building a bundle, to begin with. 

Getting the Most out of Shopify Functions

While every ecommerce business might have a unique selection of products and goals, there are a few universal things to consider when deciding which Functions to implement in a given store. Here’s how to get the most out of these Shopify Function APIs.

Identify Key Opportunities

Always pinpoint areas of your store where improvements would yield significant returns. Common candidates include:

  • Checkout flows: Streamline the purchasing journey to minimize friction and encourage impulse buys.
  • Product recommendations: Boost average order values by suggesting complementary items or bestsellers.
  • Shipping costs: Offer flexible delivery options that cater to diverse budget constraints. This can streamline operations to increase profitability or minimize replenishments

You can optimize your efforts and drive meaningful change by focusing on high-impact touchpoints throughout your checkout process. 

When thinking about Functions, think in terms of Function input and Function output, that is, what needs to happen to trigger your Function to run and what happens when it runs. This will help you mentally build out and visualize what you need your function to do and how. 

Monitor and Update

Don’t just set up and forget your Functions. Instead, continuously assess their effects on your store's performance. Track conversion rates, customer interactions, and other metrics to determine successful implementations and find areas for enhancement.

Periodically reassess and refine your Shopify Functions strategy based on new knowledge and changing industry trends. Experiment with novel approaches and incorporate proven tactics to continue to amplify your store's growth and profitability.

Leverage an Ecommerce Agency 

While Shopify Functions are easier and more intuitive to use than Shopify Scripts, you’ll still need coding skills or a developer on your team to create your own rather than simply installing pre-made apps from the Shopify App Store. 

This is where using a Shopify Plus Partner ecommerce agency comes in handy. Not only do they know all the tips and tricks to get the most out of this feature, but they can also build custom functions and apps tailored specifically for your business, making it easier to stand out in the already overcrowded world of ecommerce.  

Shopify Functions also has its own page in the Partner dashboard where your agency can review its Function’s input/output, see how many times it runs and how long it takes to run. This way, you can trust that if anything goes wrong – or if things aren’t working as expected – they can quickly and easily have a look and fix any issues for you. 

Having someone else available to monitor and fix issues is a great way to stay on top of any problems or updates without taking everything on yourself. 

Conclusion

Leveraging Shopify Functions can ensure smoother transactions and a more personalized, custom shopping experience for your customers, which, as we all know, directly leads to increased revenue and return shoppers. Take this a step further and get a Shopify Plus Partner agency on board to customize your checkout further with custom Functions built specifically for you. 

As a certified Shopify Plus Partner agency, we at Blue Badger have the experience and expertise needed to make your checkout page work harder for you. Whether you need backend customization with Shopify Functions or a custom app or theme, we can ensure that your store’s checkout experience is beautiful and functional. Get in touch with us today to learn more. 

More Blogs

Web Per...
Web Performance Optimization for Black Friday/Cyber Monday: Audit Guide for Ecommerce
As Black Friday and Cyber Monday (BFCM) loom, ecommerce merchants must start prepping for the best shopping season of the year. While planning sale...
Shopify...
Shopify Advanced VS Plus VS Enterprise Commerce Components: All Plans Explained
With so many different plans, tiers, and add-ons available with each Shopify plan, understanding how everything works can be overwhelming and confu...
The Cas...
The Case for AI and Automation in Customer Service
As AI and customer service technologies evolve, so must ecommerce businesses if they want to stay relevant and match the level of support quality a...