June 19, 2013

Woocommerce CSV importer – Resume Feature

Woocommerce CSV importer – Resume Feature

function wce_gallery_resume($post_id){
$files = array();
$check_image = get_post_meta($post_id, '_product_image_gallery', true);
$check_image = is_array($check_image)?$check_image:explode(',',$check_image);
foreach($check_image as $image){
$i = basename(get_post_meta($image, '_wp_attached_file', true));
$files[$i] = $image;
return $files;

How to use this?

  1. Locate this file “include/woocommerce-csvimport-functions.php”
  2. Locate function “woocsv_import_products_from_csv”
  3. Locate this line “if ( isset( $data[13] ))” around line no. 242
  4. And insert this line $images_exist = wce_gallery_resume($post_id);inside IF CONDITION
  5. Update the next line too as woocsv_add_featured_image ( $post_id , $data[13], $dir, $images_exist );
  6. Don’t forget to update this function too for a new parameterfunction woocsv_add_featured_image($post_id,$image_array,$dir, $images_exist)

How does Woocommerce CSV importer Resume Feature work?

In fact whenever you will face directory limit reach issue either on localhost or live so you will get the follow warnings:

Warning: imagejpeg() [function.imagejpeg]: Unable to open 'D:\xampp\htdocs\website.com/wp-content/uploads/2013/06/xyz-64-14-120_03-150x150.jpg' for writing: Permission denied in D:\xampp\htdocs\website.com\wp-includes\class-wp-image-editor.php on line 334

Warning: file_put_contents(D:\xampp\htdocs\website.com/wp-content/uploads/2013/06/xyz-60-9-135.jpg) [function.file-put-contents]: failed to open stream: Permission denied in D:\xampp\htdocs\website.com\wp-content\plugins\woocommerce-csvimport\include\woocommerce-csvimport-functions.php on line 310

So when you will get these warnings, you will notice that you are unable to create any file/folder in that particular folder because of limit reach or permission denied warning.

What to do next?

Follow these steps to use resume feature in this plugin:

  1. Find meta_value in postmeta table with current month no. e.g. June = 06 so your query will be like thisSELECT meta_value FROM wp_postmeta WHERE meta_value LIKE '%06/%'
  2. Now update these values with some other table which should exist e.g. “04” or “05” etc.
  3. Now move all images to that new folder and database is updated as well from current folder to another folder
  4. You can run csvimport again, the good thing about this function is that it will not fetch the existing images again because an extra parameter passed to the function “woocsv_add_featured_image” to compare
  5. It will take around half hour for around 7000+ products to reach the previous crash point to continue further

Suggestions for Plugin Author

  • Whenever you get permission denied warning so create another folder and start writing there
  • Provide an addition checkbox for “resume” feature, if someone will check this box so function will not update whole CSV to MySQL again and will quickly start from that post which has no images in DB but available in CSV column
  • Some timeout settings or status console should be provided because sometimes its hectic to check on hosting server that which ini_get value is not appropriate and should be modified

Woocommerce CSV importer – Support

Last updated: March 19, 2014