Passing custom data to Discount Function

Gingi
Shopify Partner
2 0 0

Hi all,

I'm trying to understand if there's an ability to pass custom data to a Discount Function securely?

I'd like to grant a discount based on some parameters for certain customers (guest and registered).

How can I achieve that with Functions? Should I use the deprecated Scripts instead?

 

Thanks in advance! 🙂

Replies 2 (2)

Liam
Shopify Staff
2731 302 783

Hi Gingi,

You should be able to achieve this functionality with Shopify Functions, specifically using the Product Discount API or Order Discount API depending on your needs.

 

If you want to pass custom data to a discount function securely, one way to do this is through the use of metafields. Metafields act as custom fields on an object, allowing you to store extra information for products, customers, orders, etc. in your Shopify store.

 

You can create a metafield for your app where you store the parameter you want to use for granting discounts. Then in your discount function, you can access this metafield and apply a discount accordingly.

 

I hope this helps! 

Liam | Developer Advocate @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

Gingi
Shopify Partner
2 0 0

Hi @Liam ,

 

First of all - thanks for the answer!

 

If I want to pass custom data to the Cart context, it's only through Cart attributes, right?