• So I found this woo products importer and it free and I was wondering if this my code can be insert to grab url for featured image from the CSV importer

    so from preview.php add '_image' => 'Grab Image Url)', 
    
    then add this for the result.php $new_post_meta['_image'] = 'no';
    
    case '_image':
                            if ( $picture ) {
        		woocsv_add_featured_image ( $post_id , $picture[0] );
    		}
    	}
    }
    
    function woocsv_add_featured_image($post_id,$image_url) {
    
    	$upload_dir = wp_upload_dir();
    	$image_data = file_get_contents($image_url);
    	$filename = basename($image_url);
    	if(wp_mkdir_p($upload_dir['path']))
    		$file = $upload_dir['path'] . '/' . $filename;
    	else
    		$file = $upload_dir['basedir'] . '/' . $filename;
    	if (!file_put_contents($file, $image_data)) die ('file not oke'.$file);
    
    	$wp_filetype = wp_check_filetype($filename, null );
    	$attachment = array(
    		'post_mime_type' => $wp_filetype['type'],
    		'post_title' => sanitize_file_name($filename),
    		'post_content' => '',
    		'post_status' => 'inherit'
    	);
    	$attach_id = wp_insert_attachment( $attachment, $file, $post_id );
    	require_once(ABSPATH . 'wp-admin/includes/image.php');
    	$attach_data = wp_generate_attachment_metadata( $attach_id, $file );
    	wp_update_attachment_metadata( $attach_id, $attach_data );
    	set_post_thumbnail( $post_id, $attach_id );
    
    }
    break;

    can some one change my code so the product upload works …..

Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘[Plugin: Woo Product importer]Add featured image from CSV url grab?’ is closed to new replies.