Shopify Discount Functions
| 4 mins read timeThere are two types of Shopify functions: server-side and client-side. Server-side functions run on Shopify's servers, while client-side functions run on the customer's browser.
Shopify Functions allow developers to change the backend code that runs some of Shopify. The first area where we will let you manipulate logic is with the discounting function during checkout. In time, you'll be able to control changes for many parts of Shopify.
Whilst Shopify has a reasonable amount of logic available in the standard discount functionality, it was built for the masses and struggles with specific use cases that certain customers may have. Shopify Functions is a good way of implementing this type of required specific logic that the base Shopify does not have by default - allowing for much more customization in the customer's checkout flow and experience.
Platforms like Magento Ecommerce have the ability to implement some very detailed discount logic - Shopify functions if implemented correctly can start to add more complex logic to users' stores whilst maintaining the amazing scalability and reliability of Shopify's servers.
Some of you may be saying there are already a lot of plugins that can add discount logic to your store - that is true. This is the next step however - it does not rely on fancy hacks or storing discount rules on other third party servers - its your stores logic running on Shopify's infastructure.
Shopify Functions take the following to work and can be written in languages like RUST.
Input - a GraphQL query that acts as a subset of the Cart API
Function Logic - Can be written in any language that compiles to WebAssembly to ensure fast operation.
Output - a payload that conforms to a GraphQL schema.
On October 27th 2022 Shopify Functions began rolling out to merchants allowing two types of functions to be created:
Discount the entire cart
with order discounts applying a fixed amount of percentage off.
Discount specific products
with product discounts applying a fixed amount or percentage off.
Essentially how it works is when a product is added to the customer's cart via GraphQL - a developer's own code can be executed changing the behavior of a discount function. This allows developers to greatly extend the functionality of discounts in Shopify. Additionally, Metafields can be utilized and queried by the functions, i.e to retrieve a product-specific variable for a discount.
This is another exciting development for Shopify store owners and will certainly be utilized to develop new marketplace plugins that will offer greater control over the behavior of discounts.
Official Shopify Dev Documentation
If you're not sure whether Shopify functions are right for you, we recommend talking to a Shopify Expert. They can help you determine if Shopify functions can help you achieve your desired results
You can also learn more about Shopify Functions at the official Shopify Dev site.