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

    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);