Support

Account

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

  • Thank you John
    That worked!

    One comma was missing
    $images = implode(',' , $images);

    I’ll paste my functions.php here if anyone in future is doing the same:
    Transferring product data (featured image, images gallery, price) from ACF to WooCommerce

    function acf_set_featured_image( $value, $post_id, $field  ){   
        if($value != ''){
    	    //Add the value which is the image ID to the _thumbnail_id meta data for the current post
    	    add_post_meta($post_id, '_thumbnail_id', $value);
        }
        return $value;
    }
    add_filter('acf/update_value/name=my_featured_image', 'acf_set_featured_image', 10, 3);
    
    function acf_set_current_price( $value, $post_id, $field  ){    
        if($value != '')	    
    		update_post_meta($post_id, '_price', $value);
        return $value;
    }
    function acf_set_regular_price( $value, $post_id, $field  ){    
        if($value != '')	
    		update_post_meta($post_id, '_regular_price', $value);
        return $value;
    }
    add_filter('acf/update_value/name=my_price', 'acf_set_regular_price', 10, 3);
    
    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)) {
    		$images = implode(',', $images); // convert to comma separated list
    	} else {
    		$images = '';
    	}
    	update_post_meta($post_id, '_product_image_gallery', $images);
    }
    add_action('acf/save_post', 'my_acf_save_post', 20); // priority of 20 so it runs after ACF