How can I customize metafields for different products?

How can I customize metafields for different products?

GLS3
Tourist
29 0 2

I am using metafields but I don't want all the metafields coming up for all the products. ie measurements for dresses vs measurements for shorts (remove bust measurement).  Is there a way of selecting what metafields appear for different products?

 

Thank you.

Replies 2 (2)

Dascalargo
Shopify Partner
124 8 49

I'm working on something similar. I use a custom liquid block (Turbo Theme) and if statements. So basically, I have a heading called CONTENT & CARE and then two metafields, one for fabric content and one for care instructions. So, in its simplest form, if the fields are single-line text and are called product.metafield.custom.content and product.metafield.custom.care, you have...

 

{% if product.metafield.custom.content %}
<p>Fabric Content: {{ product.metafield.custom.content }}</p>
{% endif %}
{% if product.metafield.custom.care %}
<p>Care Instructions: {{ product.metafield.custom.care }}</p>
{% endif %}

 

It checks to see if there is anything in the fabric content field, and, if so, prints that info. It then checks to see if there is anything in the care instructions field, and, if so, prints that info. You can have either one, both, or nothing, determined by which metafields have text in them.

 

Let me know if any of that isn't clear. Glad to help when I can.

 

One side note: The reason I came here is an issue for which I'll be placing a separate post: While I can conditionalize each piece of data, it doesn't appear that you can clear metafields. So if I fill in the fabric content field accidentally, the clear link doesn't work. Although it clears the field on the product card, the info originally entered continues to show on the customer-facing page.

 

Good luck!

 

Jason Roberts

 

GLS3
Tourist
29 0 2

This is a bit to complicated for me, but thank you for replying.

 

Gwen