How to hide empty metafields in product details on the Kalles theme?

Hi.

I have created metafields for origin of production and for the material of the product.

In the theme I have create a text section where I have written Produced in: [Metafield attribute] and it is all good when I write the country in the products metafield, but for some products I don’t have the origin and leave the field empty but then it just says “Produced in:” on the product.

Is there any way for the text box not to show if the input field is empty in the backend?

Right now I am writing the entire sentence and I CAN do that, but I’m so lazy that I don’t want to :slightly_smiling_face:

The theme is Kalles

The link is https://www.rebelcopenhagen.dk/products/8434685482288?variant=49359751545158 (code is copenhagenrebel)

@rebelcopenhagen

are these metafields are custom coded? or you are getting them using dynamic source.

thanks

Hi @rebelcopenhagen ,

To fix this issue, we need to add the condition to check the if the metafield is empty or not.

For example:

{%- if product.metafields.custom.country.value != blank -%}
 {{ product.metafields.custom.country.value }}
{% endif %}

If you require further help to optimize or customize your store, please don’t hesitate to reach out. If you find this information useful, a Like would be greatly appreciated. And if this solves the problem, please Mark it as Solution!

Best Regards,
LuffyOnePiece

Hi.

It is dynamic sourced (meaning I pressed the Add dynamic source in the text field)

Hi.

Thank you, but in what file do I put this code?