Hide section when metafields are empty

Topic summary

Problem: A product page section shows a heading (set in the theme editor) even when its associated product metafields are empty. Request: hide the heading when those metafields have no value.

Proposed solution:

  • Use a Liquid condition to render both the heading and content only if the metafield is not blank:
    {% if product.metafields.namespace.key != blank %} {% endif %}
  • Repeat per metafield as needed, replacing namespace and key with your actual metafield identifiers.

Placement guidance:

  • One participant asked where to put the code. Reply: it depends on how the theme calls the metafield. Wrap the existing metafield output (and the heading) within the if/endif in the relevant product section or template. Example provided showing a metafield (e.g., calories_per_serving) wrapped in an if-not-blank check.

Status:

  • No final, theme-specific steps given; further help offered if the requester shares a URL and details.

Notes:

  • Metafields = custom product fields. Liquid = Shopify’s templating language.
Summarized with AI on January 7. AI used: gpt-5.

Hi, @lana-mukti

Greetings from the Store Watchers Support Team! Happy to help you today.

You can put this condition:

{% if product.metafields.namespace.key != blank %}
 // Put the heading tags within this condition
{% endif %}

Replace namespace with the actual namespace of the metafield and key with the key of the metafield.

You can use this code snippet within the relevant section of your product page template to control the visibility of metafields based on their values. Repeat this code for each metafield you want to conditionally display.

Remember to adjust the code to match the structure and naming of your metafields.

Let me know If need further assistance

Regards,

Store Watchers Support Team

1 Like