If you are using the dawn theme, probably you want to update the code in the main-product.liquid file in the sections folder. Look for the code starting with {%- when ‘collapsible_tab’ -%}. Wrap the code after it in a div tag like this
That will hide the collapsible tab block if the metafield is empty. This will also hide any other collapsible tabs on the page, might not be what you want.
You may want to create a custom snippet file to contain your Liquid code with an extra conditional logic. Then you can simply render that snippet in the same spot you’re currently using to display the metafield content. So this part of the JSON scheme:
However, if you’d like to display or hide the entire collapsible row based on the whether a product has that specific metafield or not, you may want to try out the solution suggested by @Alan15 .
I don’t want all collapsible tabs to be hidden. I have multiple collapsible tabs, each of which I would like to hide or display dependant on whether there is data contained in a metafield.
I was hoping I could just include the condition in the JSON scheme?
4- Now go on your Theme editor and insert your liquid code directly with conditions regarding each product metafields.
It’s the better way I found to do it. Hope it helps.
Can’t find how to put condition on each product metafields at once, knowing that here we must also specify “if content contains a metafield”.
In case this is still relevant, you could do the following: just add an if statement in the liquid code within main-product.liquid right under the “{%- when ‘collapsible_tab’ -%}”:
{%- if block.settings.content != blank -%}
And close it after the with:
{%- endif -%}
That should do the trick and only displays the dropdown if there is a value available in the metafield.