How can I include Metafield data into the Shopify product.description property?

How can I include Metafield data into the Shopify product.description property?

iwogujek
Visitor
1 0 0

I am working with a shopify 2.0 theme and I would like to include relevant product datapoints (meta fields) in the product.description property.

Examples—

  • Condition: New
  • Brand: Hester & Orchard
  • Department: Womens
  • Size: M
  • Size Type: Regular
  • Color: Blue
  • Pattern: Solid
  • Closure: Pullover
  • Sleeve Length: Short Sleeve
  • Chest Size: 42 in
  • Length: 23 in
  • Material: Cotton Blend
  • Country: China

I need these rendered specifically in the description property so that each key:value are available and readable for outside listings.

I am currently producing this list on my store product page using a snippet right under the description, but my ultimate goal is to make these meta fields the product.description content inclusion.

Reply 1 (1)

Kani
Shopify Partner
468 125 230

Hi @iwogujek 

 

you can try it in this way

 

admin editor

Kani_0-1660385925433.png

product page preview

Kani_1-1660385934320.png

demo code

// get all metafields here
{% capture metafields_for_description %}
    <ul>
     <li>Product Type : {{ product.metafields.custom.product_type }}</li>
    </ul>
{% endcapture %}
// replace mark with metafields html content
{% capture description_with_metafield %}
    {{ product.description | replace: "$[metafield_mark]", metafields_for_description }}
{% endcapture %}
// replace product.description with description_with_metafield 
{{ description_with_metafield }}

 

Hey!! ʕ ᵔᴥᵔ ʔ
Please click 'Like' and ' Accept as Solution' to encourage me to continue sharing my expertise. ♡
If you need any technical assistance, feel free to send me a DM. You no longer have to search for answers without getting a response. 🙂