Shopify Functions apply discount based on variant metafields

Hello,

Is it possible to offer free shipping based on a product variant’s metafield value? Specifically, can this be achieved using Shopify Functions? If so, how can I apply a free shipping discount when a variant’s metafield value is set to true?

Thank you.

Hi @techticarti1
This can be done through shopify liquid. In cart, you can create a liquid rule if metafield exists or has a specific value to automatically apply discount at checkout.

In the shipping discount function, you can access the metafield of the product variant on the function’s input:

https://shopify.dev/docs/api/functions/reference/shipping-discounts/graphql/common-objects/productvariant

Then it’s just a matter of checking the metafield value and setting the right targets as part of the function’s output:

https://shopify.dev/docs/api/functions/reference/shipping-discounts/graphql#functionrunresult

Should be straightforward, but feel free to ping in case of additional questions.