I am trying to get the images from two separate places to a single field in ACF.
I have found two working codes for getting the Woo Product Image to an ACF field and the Woo Product Gallery to another ACF field.
Basically I need help with the code to make it combine the two.
I want to get them to populate the same ACF field, so that the whole Product Imagery is combined to be used for a slider. (I couldn’t find any information on how WooCommerce does this natively on the product page…) This is the source website: https://cfxdesign.com/how-to-use-acf-fields-for-woocommerce-product-photos/
This is the code I found for getting the Product Image:
function load_existing_product_photo_into_acf_image_field($field) {
global $post;
$field['value'] = get_post_meta($post->ID, '_thumbnail_id', true);
return $field;
}
add_filter('acf/load_field/name=product_photo', 'load_existing_product_photo_into_acf_image_field');
And here is the second one for getting the Product Gallery:
function load_existing_product_gallery_into_acf_gallery_field($field) {
global $post;
$field['value'] = explode(',', get_post_meta($post->ID, '_product_image_gallery', true));
return $field;
}
add_filter('acf/load_field/name=product_gallery', 'load_existing_product_gallery_into_acf_gallery_field');
I have tried all I could with my non-existent knowledge of PHP but I just can’t find information how to combine the two results into one.
It’s a really dumb problem but here I am, I spent way too many hours looking for a solution myself.
Thanks in advance
Misho Vasilev is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.