I have a question regarding accessing product-level metafield values on a custom page. Currently, I am able to retrieve product metafields only on the product detail page. However, I need to access the same metafield values on a custom page (non-product template), and I am unable to do so.
Could you please advise on the correct approach to retrieve product metafield values on a custom page?
On a product page template there is a predefined global variable product which you can refer to either from Liquid code or use in dynamic source.
On a page you’d need to use a different reference.
And it may also depends on the theme code.
For example, you can use all_products["product-handle"].metafields.namespace.key.value to fetch a product metafield knowing its handle from Liquid code.
The most flexible approach for custom pages is to use a Product Setting in your section schema. This allows you to select a product in the Theme Editor and then access its metafields like this: