├── CSVLoaderForWoocommerce.php ├── README ├── admin └── CSVLoader.php ├── example.csv └── languages ├── wc_csvl.mo └── wc_csvl.po /CSVLoaderForWoocommerce.php: -------------------------------------------------------------------------------- 1 | . 26 | */ 27 | 28 | class CSVLoaderForWoocommerce { 29 | function __construct() { 30 | add_action( 'init', array( $this, 'init' ) ); 31 | if ( is_admin() ) { 32 | add_action( 'admin_menu', array( $this, 'admin_menu' ), 99 ); 33 | } 34 | } 35 | 36 | function init() { 37 | if ( function_exists( 'load_plugin_textdomain' ) ) 38 | load_plugin_textdomain( 'tcp_csvl', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' ); 39 | } 40 | 41 | function admin_menu() { 42 | 43 | if (function_exists('add_menu_page')) 44 | { 45 | add_menu_page('Csv Loader', 'Csv Loader', 'administrator', dirname( __FILE__ ) . '/admin/CSVLoader.php'); 46 | } 47 | } 48 | } 49 | 50 | new CSVLoaderForWoocommerce(); 51 | ?> 52 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | I am not plugin author. All credits goes to Colin and great JigoShop community. I just edit few lines. 2 | 3 | Share, contribute and live long opensourced! 4 | 5 | === Installation === 6 | 7 | 1. Download latest version from GIT 8 | 2. Extract to wp-content/plugins 9 | 3. Rename to "Woocommerce-CSV-import"(optional) 10 | 4. Enable plugin in your Wordpress Administration > Plugins 11 | 5. If is everything allright new menu "CSV Loader" appear in your Administration 12 | 13 | === Usage === 14 | 15 | Example CSV is included within plugin - "example.csv" 16 | 17 | - Just open "example.csv" with your favourite editor (Libre Office, Open Office... maybe MS office i did not try). 18 | - Separation symbol is dash: "," Language should be UTF-8 if you want use special symbols. 19 | - Edit and Save 20 | 21 | Use CSV Loader Administration menu to load your CSV. Page is self explayning... 22 | 23 | === Changelog === 24 | 25 | Version 0.1 26 | - Estabilished GIT 27 | Version 0.11 28 | - If product's name exists don't make duplication 29 | Version 0.12 30 | - Fixing duplication error ($upost['ID'] instead $upost->ID) -------------------------------------------------------------------------------- /admin/CSVLoader.php: -------------------------------------------------------------------------------- 1 | get_row("SELECT * FROM $wpdb->posts WHERE post_title = '" . $title_str . "'", 'ARRAY_A'); 10 | } 11 | 12 | if ( ! session_id() ) session_start(); 13 | $post_type = isset( $_REQUEST['post_type'] ) ? $_REQUEST['post_type'] : 'product'; 14 | $separator = isset( $_REQUEST['separator'] ) ? $_REQUEST['separator'] : ','; 15 | $titeled = isset( $_REQUEST['titeled'] ); 16 | $taxonomy = isset( $_REQUEST['taxonomy'] ) ? $_REQUEST['taxonomy'] : 'taxonomy'; 17 | $hierarchical_multicat = isset( $_REQUEST['hierarchical_multicat'] ); 18 | 19 | $cat = isset( $_REQUEST['wc_cat'] ) ? $_REQUEST['wc_cat'] : ''; 20 | $wc_status = isset( $_REQUEST['wc_status'] ) ? $_REQUEST['wc_status'] : ''; 21 | $data = array(); 22 | $titles = array(); 23 | if ( isset( $_REQUEST['wc_load_csv'] ) && isset( $_FILES['upload_file'] ) ) { 24 | if ( ( $handle = fopen( $_FILES['upload_file']['tmp_name'], 'r' ) ) !== FALSE ) { 25 | while ( ( $line = fgetcsv($handle, 1024, $separator ) ) !== FALSE ) 26 | $data[] = $line; 27 | fclose( $handle ); 28 | if ( $titeled ) { 29 | $titles = $data[0]; 30 | unset( $data[0] ); 31 | } else { 32 | for( $i = 0; $i < count( $data[0] ); $i++ ) 33 | $titles[] = 'col_' . $i; 34 | } 35 | } 36 | $_SESSION['wc_csv_titles'] = $titles; 37 | $_SESSION['wc_csv_data'] = $data; 38 | } elseif ( isset( $_REQUEST['wc_load_products_from_csv'] ) && isset( $_SESSION['wc_csv_titles'] ) ) { 39 | $titles = $_SESSION['wc_csv_titles']; 40 | $data = $_SESSION['wc_csv_data']; 41 | unset( $_SESSION['wc_csv_titles'] ); 42 | unset( $_SESSION['wc_csv_data'] ); 43 | if ( is_array( $data ) ) { 44 | $taxonomies = get_object_taxonomies( $post_type ); 45 | $count = 0; 46 | $i = 0; 47 | 48 | foreach( $data as $cols ) { 49 | $i++; 50 | $name = ''; 51 | $content = ''; 52 | $excerpt = ''; 53 | $price = 0; 54 | $order = ''; 55 | $weight = 0; 56 | $sku = ''; 57 | $stock = ''; 58 | $tax = 0; 59 | $attachments = array(); 60 | $thumbnail = ''; 61 | $custom_values = array(); 62 | $taxo_values = array(); 63 | // 64 | $multi_cat_value = array(); 65 | $taxo_attribs = array(); 66 | // 67 | foreach( $cols as $i => $col ) { 68 | $col_name = isset( $_REQUEST['col_' . $i] ) ? $_REQUEST['col_' . $i] : ''; 69 | if ( $col_name == 'wc_name' ) { 70 | $name = $col; 71 | } elseif ( $col_name == 'wc_content' ) { 72 | $content = $col; 73 | } elseif ( $col_name == 'wc_excerpt' ) { 74 | $excerpt = $col; 75 | } elseif ( $col_name == 'wc_price' ) { 76 | $price = $col; 77 | } elseif ( $col_name == 'wc_order' ) { 78 | $order = $col; 79 | } elseif ( $col_name == 'wc_weight' ) { 80 | $weight = (float)$col; 81 | } elseif ( $col_name == 'wc_sku' ) { 82 | $sku = $col; 83 | } elseif ( $col_name == 'wc_stock' ) { 84 | $stock = (int)$col; 85 | } elseif ( $col_name == 'wc_tax' ) { 86 | $tax = (int)$col; 87 | // 88 | } elseif ( $col_name == 'multi_cat' ) { 89 | $multi_cat = $col; 90 | // 91 | } elseif ( $col_name == 'wc_attachment' ) { 92 | $attachments[] = $col; 93 | } elseif ( $col_name == 'wc_thumbnail' ) { 94 | $thumbnail = $col; 95 | // 96 | } elseif ( $col_name == 'attribs' ) { 97 | $taxo_attribs = $col; 98 | // 99 | } else { 100 | $break = false; 101 | if ( is_array( $custom_field_defs ) && count( $custom_field_defs ) > 0 ) { 102 | foreach( $custom_field_defs as $custom_field_def ) { 103 | if ( $col_name == $custom_field_def['id'] ) { 104 | $custom_values[$col_name] = $col; 105 | $break = true; 106 | break; 107 | } 108 | } 109 | } 110 | if ( ! $break && is_array( $taxonomies ) && count( $taxonomies ) > 0 ) { 111 | foreach( $taxonomies as $taxmy ) { 112 | if ( $col_name == 'wc_tax_' . $taxmy ) { 113 | $taxo_values[$taxmy] = $col; 114 | $break = true; 115 | break; 116 | } 117 | } 118 | } 119 | } 120 | } 121 | $post = array( 122 | 'comment_status'=> 'open', 123 | 'post_content' => $content, 124 | 'post_excerpt' => $excerpt, 125 | 'post_status' => $wc_status, 126 | 'post_title' => $name, 127 | 'post_type' => $post_type, 128 | ); 129 | if ( wp_exist_post_by_title($name) ) { 130 | //ID for post we want update 131 | $upost = array(); 132 | $upost = $wpdb->get_row("SELECT * FROM $wpdb->posts WHERE post_title = '" . $name . "'", 'ARRAY_A'); 133 | $idpost = $upost['ID']; 134 | $post['ID'] = $idpost; 135 | $post_id = wp_update_post( $post ); 136 | $count--; //For update count 137 | } else { 138 | $post_id = wp_insert_post( $post ); 139 | } 140 | if ( $cat > 0 ) { 141 | wp_set_object_terms( $post_id, (int)$cat, $taxonomy, false ); 142 | } 143 | 144 | update_post_meta( $post_id, '_visibility', 'visible' ); 145 | update_post_meta( $post_id, '_sku', $sku ); 146 | update_post_meta( $post_id, '_price', $price ); 147 | update_post_meta( $post_id, '_weight', $weight ); 148 | update_post_meta( $post_id, '_stock', $stock ); 149 | update_post_meta( $post_id, '_featured', '' ); 150 | update_post_meta( $post_id, '_regular_price', $price ); 151 | update_post_meta( $post_id, '_sale_price', '' ); 152 | update_post_meta( $post_id, '_sale_price_dates_from', '' ); 153 | update_post_meta( $post_id, '_sale_price_dates_to', '' ); 154 | 155 | //****** need to make a product_data and variation post insert ******// 156 | //update_post_meta( $post_id, 'wc_tax_id', $tax ); 157 | //update_post_meta( $post_id, 'wc_is_downloadable', false ); 158 | //update_post_meta( $post_id, 'wc_max_downloads', 0 ); 159 | //update_post_meta( $post_id, 'wc_days_to_expire', 0 ); 160 | //update_post_meta( $post_id, 'wc_type', 'SIMPLE' ); 161 | //update_post_meta( $post_id, 'wc_weight', $weight ); 162 | //update_post_meta( $post_id, 'wc_order', $order ); 163 | 164 | //// 165 | 166 | $pdata=array(); 167 | $pdata['sku'] = $sku; 168 | $pdata['regular_price'] = $price; 169 | $pdata['sale_price'] = ''; 170 | $pdata['featured'] = ''; 171 | $pdata['weight'] = $weight; 172 | $pdata['tax_status'] = $taxable; 173 | $pdata['tax_class'] = ''; 174 | $pdata['stock_status'] = 'instock'; 175 | $pdata['manage_stock'] = 'no'; 176 | $pdata['backorders'] = 'no'; 177 | update_post_meta( $post_id, 'product_data', $pdata ); 178 | 179 | 180 | 181 | 182 | // 183 | $field= $taxo_attribs; 184 | if((!empty($field)) && (explode(',',$field) !=FALSE)) 185 | { 186 | $datas=explode(',',$field); 187 | $attrib=array(); 188 | for($i=0;$i false, 'label' => 'pa_'.sanitize_title($value[0]) ) ); 198 | 199 | $wpdb->insert( $wpdb->prefix . "woocommerce_attribute_taxonomies", array( 'attribute_name' => $value[0], 'attribute_type' => 'text' ), array( '%s', '%s' ) ); 200 | } 201 | 202 | 203 | 204 | if(term_exists($value[1], 'pa_'.sanitize_title($value[0]))) 205 | { } 206 | else { 207 | wp_insert_term( $value[1], 'pa_'.sanitize_title($value[0]), array( 'slug' => $value[1] ) ); 208 | } 209 | wp_set_object_terms( $post_id, $value[1], 'pa_'.sanitize_title($value[0]), true ); 210 | 211 | /* 212 | $term = $value[1]; 213 | $tax = 'pa_'.sanitize_title($value[0]); 214 | $new_term = term_exists($term, $tax); 215 | if ( ! is_array( $new_term ) ) 216 | $new_term = wp_insert_term( $term , 'pa_'.sanitize_title($value[0]), array( 'slug' => $term ) ); 217 | wp_set_object_terms( $post_id, $term, $tax, true ); 218 | */ 219 | 220 | 221 | $value_sanitized = sanitize_title($value[0]); 222 | $attrib[$value_sanitized]= 223 | array('name' => htmlspecialchars(stripslashes($value[0])), 224 | 'value' => $value[1], 225 | 'position' => '0', 226 | 'visible' => 'yes', 227 | 'variation' => 'no', 228 | 'is_taxonomy' => 'yes' 229 | ); 230 | } 231 | update_post_meta($post_id, 'product_attributes', $attrib); 232 | } 233 | 234 | 235 | foreach( $custom_values as $id => $custom_value ) { 236 | update_post_meta( $post_id, $id, $custom_value ); 237 | } 238 | } 239 | /////// explode field multicat ',' separator 240 | 241 | $prod_cats = explode(',',$multi_cat); 242 | for($i=0;$i $prod_cats[$i], 'parent'=> $parent) ); 247 | $new_cat = term_exists( $prod_cats[$i], 'product_cat' ); 248 | } 249 | 250 | if($hierarchical_multicat) { 251 | $parent = $new_cat['term_id']; 252 | } 253 | 254 | wp_set_object_terms( $post_id, (int)$new_cat['term_id'], 'product_cat', true ); 255 | 256 | // Remove the cache: http://wordpress.stackexchange.com/questions/24498/wp-insert-term-parent-child-problem 257 | delete_option("product_cat_children"); 258 | } 259 | unset($parent); 260 | 261 | foreach( $taxo_values as $tax => $term ) { 262 | $new_term = term_exists( $term, $tax ); 263 | if ( ! is_array( $new_term ) ) 264 | $new_term = wp_insert_term( $term, $tax, array( 'slug' => $term ) ); 265 | wp_set_object_terms( $post_id, (int)$new_term['term_id'], $tax, true ); 266 | } 267 | 268 | 269 | foreach( $attachments as $url ) { 270 | //$url = urldecode( $url ); 271 | $base = basename( $url ); 272 | $path = wp_upload_dir(); 273 | $path = $path['path']; 274 | $dest = $path . '/' . $base; 275 | copy( $url, $dest ); 276 | $wp_filetype = wp_check_filetype( basename( $dest ), null ); 277 | $attachment = array( 278 | 'post_mime_type' => $wp_filetype['type'], 279 | 'post_title' => preg_replace('/\.[^.]+$/', '', basename( $dest ) ), 280 | 'post_content' => '', 281 | 'post_status' => 'inherit', 282 | ); 283 | $attach_id = wp_insert_attachment( $attachment, $dest, $post_id ); 284 | // you must first include the image.php file for the function wp_generate_attachment_metadata() to work 285 | require_once(ABSPATH . "wp-admin" . '/includes/image.php'); 286 | $attach_data = wp_generate_attachment_metadata( $attach_id, $dest ); 287 | wp_update_attachment_metadata( $attach_id, $attach_data ); 288 | } 289 | 290 | if ( strlen( $thumbnail ) > 0 ) { 291 | $base = basename( $thumbnail ); 292 | $path = wp_upload_dir(); 293 | $path = $path['path']; 294 | $dest = $path . '/' . $base; 295 | copy( $thumbnail, $dest ); 296 | $wp_filetype = wp_check_filetype( basename( $dest ), null ); 297 | $attachment = array( 298 | 'post_mime_type' => $wp_filetype['type'], 299 | 'post_title' => preg_replace('/\.[^.]+$/', '', basename( $dest ) ), 300 | 'post_content' => '', 301 | 'post_status' => 'inherit', 302 | ); 303 | $attach_id = wp_insert_attachment( $attachment, $dest, $post_id ); 304 | // you must first include the image.php file for the function wp_generate_attachment_metadata() to work 305 | require_once(ABSPATH . "wp-admin" . '/includes/image.php'); 306 | $attach_data = wp_generate_attachment_metadata( $attach_id, $dest ); 307 | wp_update_attachment_metadata( $attach_id, $attach_data ); 308 | update_post_meta( $post_id, '_thumbnail_id', $attach_id ); 309 | } 310 | $count++; 311 | $uploaded++; 312 | } 313 | ?> 314 |

315 | 316 |

318 |

319 | 320 |

324 |
325 | 326 |

327 |

Wait! Wait! Wait! It's a very alpha version, just to test NOT USE IN YOUR SITE, JUST TEST!

328 |

To use a hierarchical categorie (parent/children) make a column multi_cat and writing in the fields the hierarchical category, ie: hardware,memory,sodimm,ddr3

329 |

I don't know why but if you use hierarchicals categories you need to edit and save a categorie one time to see the childrens (???)

330 |

******** pfff hierarchical categorie does not work. I do not know why. I'm tired, I go to bed.********

331 |

To import attibuts, make a column attribs, use this format in the fields ie: size:128,kit:yes,cas:7

332 |

Actualy just simple type product, no variation,virtual...

333 |

Sorry for my bad english, i'm french... ;)

334 |

Choice the original, choice Jigoshop!

335 |

colin

336 |

for information: the original plugin i hacked is TheCartPress CSV Loader, license GPL.

337 | 338 |
    339 |
340 | 341 |
342 | 343 |
344 | 345 | 346 | 347 | 350 | 358 | 359 | 360 | 363 | 372 | 373 | 374 | 377 | 382 | 383 | 384 | 385 | 388 | 392 | 393 | 394 | 395 | 398 | 401 | 402 | 403 |
348 | 349 | 351 | 356 | 357 |
361 | 362 | 364 | 371 |
375 | 376 | 378 | 379 | 380 | size="2" maxlenght="4" checked /> 381 |
386 | 387 | 389 | 390 | size="2" maxlenght="4" checked /> 391 |
396 | 397 | 399 | 400 |
404 | 405 | 406 |
407 | 0 ) : ?> 408 |

409 | 410 | 0 ) :?> 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 419 | 420 | 421 | 422 | 423 | 424 | 425 | 426 | 427 | $cols ) : 428 | if ( $i > 4 ) : 429 | break; 430 | else : ?> 431 | 432 | 433 | 434 | 435 | 436 | 437 | 438 | 439 | 440 |
 
 
441 |

442 |
443 | 444 | 445 | 446 | 447 | 448 | 449 | 450 | 451 | 452 | 453 | 454 | 455 | 456 | 457 | 458 | 459 | 460 | 461 | 462 | 463 | 464 | 465 | 466 | 0 ) : ?> 467 | $col ) : ?> 468 | 469 | 470 | 496 | 497 | 498 | 499 | 500 |
471 | 495 |
501 | 502 |

503 | 504 | 508 |

509 | 510 | 511 | 512 | 513 |
514 | 515 |
516 | 517 | -------------------------------------------------------------------------------- /example.csv: -------------------------------------------------------------------------------- 1 | Name,Content,Price,Weight,sku,Multi_cat,Thumbnail 2 | "Astrotek Audio RCA Socket to Mini 1/8"", 25cm","Astrotek Audio RCA Socket to Mini 1/8"", 25cm",2,0.01,AT-AUDIO-RCA-MINI,"Cables & Connectors,Audio",http://www.advertiseme.com.au/images/logo_advertiseme.gif 3 | -------------------------------------------------------------------------------- /languages/wc_csvl.mo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xube/Woocommerce-CSV-import/6ca11110c4550ee5f8acec6fd9f47c577ae0a136/languages/wc_csvl.mo -------------------------------------------------------------------------------- /languages/wc_csvl.po: -------------------------------------------------------------------------------- 1 | msgid "" 2 | msgstr "" 3 | "Project-Id-Version: tcp_csvl\n" 4 | "Report-Msgid-Bugs-To: \n" 5 | "POT-Creation-Date: 2011-04-20 11:49+0100\n" 6 | "PO-Revision-Date: \n" 7 | "Last-Translator: sensei \n" 8 | "Language-Team: \n" 9 | "Language: \n" 10 | "MIME-Version: 1.0\n" 11 | "Content-Type: text/plain; charset=UTF-8\n" 12 | "Content-Transfer-Encoding: 8bit\n" 13 | "X-Poedit-KeywordsList: __;_e\n" 14 | "X-Poedit-Basepath: ../\n" 15 | "X-Poedit-SearchPath-0: .\n" 16 | 17 | #: CSVLoaderForTheCartPress.class.php:45 18 | #: admin/CSVLoader.php:158 19 | msgid "CSV Loader" 20 | msgstr "" 21 | 22 | #: admin/CSVLoader.php:144 23 | #, php-format 24 | msgid "%s products have been uploaded" 25 | msgstr "" 26 | 27 | #: admin/CSVLoader.php:148 28 | msgid "No product has been uploaded" 29 | msgstr "" 30 | 31 | #: admin/CSVLoader.php:169 32 | msgid "Separator" 33 | msgstr "" 34 | 35 | #: admin/CSVLoader.php:173 36 | msgid "Columns title in first line" 37 | msgstr "" 38 | 39 | #: admin/CSVLoader.php:179 40 | msgid "file" 41 | msgstr "" 42 | 43 | #: admin/CSVLoader.php:187 44 | msgid "Load" 45 | msgstr "" 46 | 47 | #: admin/CSVLoader.php:188 48 | msgid "This action helps you to test if the file is correct." 49 | msgstr "" 50 | 51 | #: admin/CSVLoader.php:191 52 | msgid "These lines are the four first products loaded from the CSV file. If you think they are correct continue with the process." 53 | msgstr "" 54 | 55 | #: admin/CSVLoader.php:224 56 | msgid "Assign the columns of the CSV file (left column) to the fields of the products (right column)." 57 | msgstr "" 58 | 59 | #: admin/CSVLoader.php:233 60 | msgid "Imported columns" 61 | msgstr "" 62 | 63 | #: admin/CSVLoader.php:234 64 | #: admin/CSVLoader.php:240 65 | msgid "Woocommerce columns" 66 | msgstr "" 67 | 68 | #: admin/CSVLoader.php:239 69 | msgid "CSV columns" 70 | msgstr "" 71 | 72 | #: admin/CSVLoader.php:250 73 | msgid "None" 74 | msgstr "" 75 | 76 | #: admin/CSVLoader.php:251 77 | msgid "Title" 78 | msgstr "" 79 | 80 | #: admin/CSVLoader.php:252 81 | msgid "Content" 82 | msgstr "" 83 | 84 | #: admin/CSVLoader.php:253 85 | msgid "Excerpt" 86 | msgstr "" 87 | 88 | #: admin/CSVLoader.php:254 89 | msgid "Price" 90 | msgstr "" 91 | 92 | #: admin/CSVLoader.php:255 93 | msgid "Stock" 94 | msgstr "" 95 | 96 | #: admin/CSVLoader.php:256 97 | msgid "Weight" 98 | msgstr "" 99 | 100 | #: admin/CSVLoader.php:257 101 | msgid "SKU" 102 | msgstr "" 103 | 104 | #: admin/CSVLoader.php:258 105 | msgid "Order" 106 | msgstr "" 107 | 108 | #: admin/CSVLoader.php:259 109 | msgid "Tax" 110 | msgstr "" 111 | 112 | #: admin/CSVLoader.php:260 113 | msgid "Attachment" 114 | msgstr "" 115 | 116 | #: admin/CSVLoader.php:261 117 | msgid "Thumbnail" 118 | msgstr "" 119 | 120 | #: admin/CSVLoader.php:270 121 | msgid "Attach this products to the Category" 122 | msgstr "" 123 | 124 | #: admin/CSVLoader.php:279 125 | msgid "Set products status to" 126 | msgstr "" 127 | 128 | #: admin/CSVLoader.php:281 129 | msgid "publish" 130 | msgstr "" 131 | 132 | #: admin/CSVLoader.php:282 133 | msgid "dratf" 134 | msgstr "" 135 | 136 | #: admin/CSVLoader.php:286 137 | msgid "Upload" 138 | msgstr "" 139 | 140 | #: admin/CSVLoader.php:287 141 | msgid "This action will load the products in the eCommerce. Be patient." 142 | msgstr "" 143 | 144 | --------------------------------------------------------------------------------