Passing custom data to Discount Function

Topic summary

Goal: Pass custom data securely into a discount mechanism to grant customer-specific discounts (for guests and registered users) using Shopify’s modern approach rather than deprecated Scripts.

Guidance: Use Shopify Functions with either the Product Discount API or Order Discount API, depending on whether discounts target items or the whole order. Store the custom parameters as metafields (custom fields on Shopify objects like products, customers, or orders), ideally as app-owned metafields, and read them within the discount function to apply logic.

Key concepts: Metafields = structured custom data attached to Shopify resources; Discount Function = server-side function evaluated at checkout/cart to calculate discounts.

Open question: For passing custom data specifically into the Cart context, the poster asks if Cart attributes are the only option. No confirmation or alternative method was provided yet.

Status: Partially answered (use Functions + metafields). Clarification about Cart context input (Cart attributes vs other options) remains unresolved.

Summarized with AI on January 14. AI used: gpt-5.

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! :slightly_smiling_face:

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!

1 Like

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?