Home › Forums › Add-ons › Repeater Field › Repeater field images to woocommerce gallery › Reply To: Repeater field images to woocommerce gallery
You need to add an acf/save_post filter which is documented here http://www.advancedcustomfields.com/resources/acfsave_post/
The WooCommerce custom field stores a serialized array of image ID values. In the your save post filter you need to loop through your repeater field and add them to an array and then store this array into the WC custom field.
// priority of 20 so it runs after ACF
add_action('acf/save_post', 'my_acf_save_post', 20);
function my_acf_save_post($post_id) {
$repeater = 'other_images';
$subfield = 'image';
// using get_post_meta because that way
// we're sure to get the image ID
$count = intval(get_post_meta($post_id, $repeater, true));
$images = array();
for ($i=0; $i<$count; $i++) {
$field = $repeater.'_'.$i.'_'.$subfield;
$images[] = intval(get_post_meta($post_id, $field, true));
}
update_post_meta($post_id, '_product_image_gallery', $images);
}
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.