Loading Shopify Product Metafields in snippets

I am trying to edit the default “Dawn” theme in my shopify store. My aim is to output product meta fields through a snippet. To do that, I have created a snippet called “color-swatches.liquid” which has the following code:

    <div class="sw-external-links modification">
        {%- if product.metafields.my_fields.current_product_color -%}
    </div>

When calling this snippet from product-card.liquid, I use the following liquid code:

{% render 'color-swatches', product: product_card_product %}

But I am not able to output the value of current_product_color metafield inside product.

If I paste the snipped code directly in product-card.liquid like this, it works:

{{ product_card_product.metafields.my_fields.current_product_color }}

Can you please tell me what am I doing wrong? I just want the snippet code to output the current_product_color metafield when I pass the product_card_product variable to it.

Hi @noorpari76

Assign a variable and value will be product metafiled.
While rendering other file pass this variable and get variable in rendering file.
Hope this could help you.