The displayed variant metafield doesn't match the selected variant

Hello,

I’m using the Dawn theme and I’m trying to add some informations on the product page when a variant is selected.

I’ve created some metafield for my variants.

I’ve added a custom liquid block on my product page but it always shows the same metafield.

It’s doesn’t change according to the selected variant.

Here is the custom liquid I’ve used :

{% for variant in product.variants %} {% if variant.metafields.custom.size.value != blank %} {% if product.selected_or_first_available_variant.id == variant.id %} {{ variant.metafields.custom.size }} {% endif %} {% endif %} {% endfor %}

How to display only the metafield of the selected variant ?

Thank you in advance for any help.