How to get custom data in Shopify Cart & Checkout Validation Function.

Solved

How to get custom data in Shopify Cart & Checkout Validation Function.

Rohan007
Shopify Partner
9 2 2

I am new to Shopify app development and have created an app with the following features:

  • Admins can define rules to validate the cart based on quantity and amount.
  • If a rule is enabled and its criteria are met, the checkout button will be restricted, preventing users from proceeding.

As per Shopify’s documentation, Shopify Functions must be implemented for cart and checkout validation to enforce these rules on the server side. However, I am unable to retrieve rule data from the database, as Shopify Functions do not support API requests.

In Liquid, we can simply call an API to fetch data, but that approach does not work here.

If anyone knows an alternative way to retrieve and use rule data within Shopify Functions, please help.
Thanks in advance!

Accepted Solution (1)
Rohan007
Shopify Partner
9 2 2

This is an accepted solution.

Yes of course,
To pass your database data to the cart and checkout validation function, you need to use metafields.
Refer to Shopify's official guide here: https://shopify.dev/docs/apps/build/custom-data
If you have any questions, feel free to ask!

View solution in original post

Replies 5 (5)

irzum
Shopify Partner
6 0 3

were you able to get custom data from DB?

Rohan007
Shopify Partner
9 2 2

yes Irzum i have get it.

 

irzum
Shopify Partner
6 0 3

can you help me out in it, am trying to do the same thing, get data from the server by calling an api

Rohan007
Shopify Partner
9 2 2

This is an accepted solution.

Yes of course,
To pass your database data to the cart and checkout validation function, you need to use metafields.
Refer to Shopify's official guide here: https://shopify.dev/docs/apps/build/custom-data
If you have any questions, feel free to ask!

irzum
Shopify Partner
6 0 3

thanks, i just dm you, can you please look into it thanks.