Access metafields of products and customer in Shopify Functions

Topic summary

Goal: apply a discount when any metafield on products in the cart matches a metafield on the customer.

Context: The app creates custom metafields (stored as multi-line strings) on both products and customers. The author wants to use a Shopify Function (implemented in Rust) to iterate over product metafields and compare them to the customer’s metafields.

Key terms: Metafields = custom key–value fields for storing specialized data on Shopify resources. Shopify Functions = server-side extensions (written in Rust) that can run logic such as discounts.

Questions: 1) Can a Shopify Function directly access and loop through product and customer metafields to perform matching? 2) If not, what alternatives exist to accomplish this logic (e.g., using tags)?

Status: No answers or solutions provided yet; no code snippets or attachments; the request is for feasibility and potential approaches. Discussion open.

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

Good day!

I want to loop through all the metafields of products in the cart and see if they match metafields in the customer. If any of them match I want to apply a discount.
My app creats these custom metafields on the products and customers. They are just multi line strings.

Is it possible to loop through those metafields in the rust code of a shopify function like this?

If it is not possible how would I be able to achieve this in another way? Maybe using tags?