How can I get the variant id of refference product in the meta_field?

I’m using the product type meta field as a reference product.

product.metafields.custom.free_product

I want to get the variant of the meta field in the same way I get the variant of the current product on the product page.

Current product variant id:

product.selected_or_first_available_variant.id

output: 43370243719392

My reference product variant id would be: 42897774051552

How can I get this number from Metafield’s product?

Any help would be appreciated

Thanks in Advance

Mir

Hi @abzalali ,
You can extract the free product variant id using the code below:

{% assign free_product = product.metafields.custom.free_product.value %}
{% assign free_product_variant_id = free_product.selected_or_first_available_variant.id %}

The variant id of the free product is stored in variable “free_product_variant_id”
You can rename & use it as per your requirement.
Thanks & regards
KaalTechGeeks