Skip to content
Advertisement

Moving custom field images to product Gallery Woocommerce

I’ve several custom image fields (ACF) from an old configuration, and would like to move those images in the Product Gallery (Woocommerce), now I’ve converted all the datas into a Product post type. I tried to set this function (found in a similar post), but nothing happens, and no errors returned neither :

JavaScript

Could someone help or explain me what’s wrong ?

Advertisement

Answer

Depending on where you run this function, you should define the $product_id argument in ACF get_field() function.

Questions to clarify: How do you run this function? are you using a hook?

Update: Hooked the function in woocommerce_process_product_meta, so when a product is created or updated, it will trigger the code.

Also your code can be simplified, optimized and compacted as follow:

JavaScript

Code goes in functions.php file of your active child theme (or active theme). untested it could work.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement