How to add external product url to woocommerce from a metadata by function.php

I’m using Woocommerce for products. All products are imported automatically by a plugin.
now i input external product url for affilliate shop and change in the source product link

affilliate link format is:

external product url= website address + metadata

i need in function get meta key and add to website address then input in product url in woocommerce

Note: I have all of the above and it is a fixed link

But I don’t know where and how to do it