Hi, I have a custom liquid field on a product page pulling out a list of features.
{{product.metafields.custom.book_features.value}}
This works absolutely fine.
I’m trying to use the same feature on a Featured Product Section on the homepage, but here it doesn’t pull out, or even recognise it as a metafield. Do you need a different metafield type on the homepage to a product page.
If the Liquid code {{product.metafields.custom.book_features.value}} is not working or recognized as a meta field in the Featured Product Section on the homepage, it’s possible that the product the object is not available in that context
To overcome this limitation, you can try using a different approach to access the metafield value on the homepage:
Customize your Featured Product Section: Edit the code for the Featured Product Section on the homepage.
Retrieve the Product: Within the Featured Product Section code, you’ll need to retrieve the specific product you want to display. This can be done using the Shopify Liquid all_products object or by accessing a specific product by handle, ID, or another identifier.
Access the Metafield: Once you have the product object within the Featured Product Section code, you can access the metafield value using the product.metafields.custom.book_features.value syntax.
Here’s an example of how you can modify the code to retrieve the product and access the metafield value:
{% assign featuredProduct = all_products.first %}
{%- comment -%} Replace 'first' with the appropriate method to retrieve the desired product -%}
{% if featuredProduct %}
{{ featuredProduct.metafields.custom.book_features.value }}
{% endif %}
In the above code, we’re using all_products.first to retrieve the first product in the store’s product list. You can modify this to fit your specific requirements and determine how you want to select the featured product
Hi… if you’re using the Shopify Featured product section, you can reference product metafields in a custom liquid block using the following without any code amendments to the theme itself: