Why are my hidden empty meta fields showing again?

Hey

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.

do you have any idea why this is happening?

1 Like

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.

First of all thank you for the Reply.

i copied the code from another solution. but i paste it into the theme.liquid area

where and how do i have ti implement ur code to check?

@Mellowsilcbd where you this code added ?

where you create the meta filed ?

I will suggest to when you rener the metafiled that time you can check with

{% if product.meta.  %} {% endif %}

Hi Mellowsilcbd,
Could you show us in your liquid file where the metafields are referenced - ie the bit where you show the ingredients
Thanks
Rhianna :slightly_smiling_face:

The code is added in the theme.liquid section

the meta field is created in products.

the script is added above the

Hi Mellowsilcbd,
No, sorry I mean in the main-product.liquid (or similar, not sure what theme you’re using) :slightly_smiling_face:
The bit on your product page where you reference the ingredients metafield :+1:

Hi Rhianna,

do you mean on the “Frontend” of the Store what the Customer sees or in the Backend in the Section Products?

if it helps iam using the Dawn Theme

Hi Mellowsilcbd,

I mean the code in shopify, not what the customer sees :slightly_smiling_face:

Not important right now, but this is all classed as ‘Frontend’ in web development haha :grinning_face_with_smiling_eyes:

That does help, thank you.
I just need to see in your code where it says {{ product.metafields. (and then what your metafield is called) }}

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

i added the metafields in the admin settings

maybe this helps

Ah okay - do you link to them in the theme editor then?

(And not stupid at all!)

yes thats exactly how i do it. the shopif support advised me to do so

Ohh yes great, so in the liquid file if you search for

{%- when ‘collapsible_tab’ -%}
I’m not sure exactly what yours will look like, as we use dawn but have made a lot of changes over time

{%- when ‘collapsible_tab’ -%}

{% if block.settings.content != null %}

*more code ..*
**{% endif %}** {%- when 'reviews-io' -%} - This might not be your next block, but you'll just want the endif before the next 'when'

You will want to add these bold bits in :slightly_smiling_face:

First Thank you very much.

i just have to ask which liquid file exactly do you mean?

Hi Mellowsilcbd,

In the main-product.liquid file :slightly_smiling_face:

Thank you very much so now it should look like this?

Just move that {% endif %} down two lines, so it is above the {% when ‘quantity_selector’ %} :slightly_smiling_face:

i changed it but sadly it isnt working :disappointed_face: