Main issue: Empty product metafield sections (ingredients/shipping/how-to) reappeared after a JS-based hide script stopped working.
Key context: Store uses Dawn theme. Metafields are linked via the Theme Editor (collapsible tabs). Initial approach injected a script in theme.liquid to remove empty accordion content; it worked briefly, then failed.
Proposed resolution: Use Liquid (server-side) instead of JavaScript. Wrap the collapsible_tab block output in main-product.liquid with a conditional so empty content doesnât render.
Implementation details:
In main-product.liquid, within the case for collapsible_tab, surround the block with:
{% if block.settings.content != ââ %} ⌠{% endif %}
The earlier suggestion using != null didnât work because the setting exists even when the metafield is empty. Checking for an empty string did.
Ensure the {% endif %} is placed before the next when block (e.g., quantity_selector).
Outcome: OP confirmed the Liquid solution works reliably. Guidance given that Liquid avoids load-time flicker and JS-disabled issues.
Open items: Follow-up questions on handling blocks with multiple metafields (use OR conditions) and hiding a multicolumn section based on empty metafields; no final answer provided yet.
Notes: Code snippets are central to understanding the fix.
Summarized with AI on December 28.
AI used: gpt-5.
iam using Meta fields to show ingredients, shipping details and how to use the product. But for some there are no such informations i looked for a solution to hide the empty meta fields in the frontend. From a different Disscusion i found this code from this discussion Solved: How to hide blank metafields. - Shopify Community
I implemented the code and it worked perfectly fine but one day later it didnt worked but i didnt changed anthing on the code.
Can I ask why youâre using javascript and not liquid?
With liquid, you can wrap the html that you donât want to show if itâs empty with an if statement -
eg:
{% if product.metafield.namespace.key != blank %}
Here is a metafield bit
{{ product.metafield.namespace.key }}
{% endif %}
If itâs one block containing multiple metafield references and you want to remove it if there is nothing there, you can just use or in the if statement
eg
{% if product.metafield.namespace.key != blank or product.metafield.namespace2.key2 != blank%}
Here is a metafield bit
{{ product.metafield.namespace.key }}
{{ product.metafield.namespace2.key2 }}
{% endif %}
This means it will only show if metafield 1 or metafield 2 (or both) exists.
Hi Mellowsilcbd,
No, sorry I mean in the main-product.liquid (or similar, not sure what theme youâre using)
The bit on your product page where you reference the ingredients metafield
Hey i think iam pretty stupid right now haha but this is the only thing i can find with {{product.metafields but rating isnt what my ingridents metafield is called
Iam pretty desperate. Iam sorry iam acting so stupid right now haha