I need help adding custom image fields to my Product Variations, same as the default field but with a different name and value or custom meta so I can differentiate default and custom image.
I tried with this plugin
Additional Variation Images Gallery for WooCommerce
but it’s ruined my frontend functionality. I just want this on my backend (see attached image)
I also tried
or some custom code changes as per my knowledge but it’s not working out for me.
2
Answers
By looking at WC source code, I was able to get this working by following php code:
And following js code:
In regards to the JS part in atlantehs’ answer, i think the click event is meant to be added to the button itself. I’ve replaced
$(document).on('click', '.upload_my_custom_field', add_my_custom_field);
with$(document).on('click', '.upload_my_custom_field_button', add_my_custom_field);
and the removal of the image is working as intended, because it wasn’t working for me before the change.This is what i’ve used, all written in functions.php of the child theme: