Support

Account

Home Forums Add-ons Repeater Field Repeater field images to woocommerce gallery Reply To: Repeater field images to woocommerce gallery

  • so it appears that woocommerce may be storing a comma separated list of id values? Now that I see the difference in the XML.

    You could try

    
    // 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));
      }
      if (count($images)) {
        // convert to comma separated list
        $images = implode(',' $images);
      } else {
        $images = '';
      }
      update_post_meta($post_id, '_product_image_gallery', $images);
    }