├── wpec-to-woo
├── styles.css
└── wpec-to-woo.php
└── README.md
/wpec-to-woo/styles.css:
--------------------------------------------------------------------------------
1 | #glance{ overflow:auto; }
2 | #glance .postbox-container{ width:49%; }
3 | #glance .table{ position:relative; }
4 | #glance .table_content{ border-top:1px solid #ECECEC }
5 | #glance .inside{ font-size:12px; padding-top:30px; padding-bottom:20px; overflow:auto; }
6 | #glance .sub{
7 | color:#8F8F8F;
8 | font-size:14px;
9 | padding:5px 0 15px;
10 | position:absolute;
11 | top:-17px;
12 | left:15px;
13 | }
14 | #glance .sub{ margin:-12px; }
15 | #glance .b{ padding-right:6px; text-align:right; font-size:14px; width:1px; font-family:Georgia,"Times New Roman","Bitstream Charter",Times,serif; }
16 | #glance .t{ padding-right:12px; padding-top:6px; }
17 | #glance a{ text-decoration:none; }
18 | #glance .hndle{ cursor:default; }
19 | #glance .table_content{ float:left; width:45%; }
20 | #glance .table_orders{ float:right; width:45%; }
21 | #glance .pending{ color:#E66F00; }
22 | #glance .onhold{ color:red; }
23 | #glance .complete{ color:green; }
24 | .instruction{ margin-top:0; }
25 | #log .inside{ font-size:12px; padding-bottom:20px; overflow:auto; }
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ** Note: A more recent fork that builds on this plugin was created by @jbeales and has lots of improvements on this plugin. It is recommened you use that one instead. https://github.com/jbeales/wp-e-commerce-to-woocommerce-converter **
2 |
3 | # WPEC to Woocommerce converter
4 |
5 | A Wordpress plugin to help migrating from WP E-Commerce to Woocommerce.
6 |
7 | > USE AT YOUR OWN RISK!
8 |
9 | > This is a developer's plugin. We recommend that you read the code and only use it on a test version of your site.
10 |
11 | ## Installation
12 |
13 | - Install as any WP plugin (copy to `wp-content/plugins`).
14 |
15 | - Make sure Woocommerce plugin is activated.
16 |
17 | - Go to `Tools > wpec to woo` and check the numbers
18 |
19 | - Click `Convert my store` and watch the magic happen
20 |
21 | ## What it does
22 |
23 | The plugin converts **products**, **categories** and **orders** to Woocommerce.
24 |
25 | Product variations and many shop settings will be lost in the process, it also sets all products tax status to 'taxable' and the tax class to 'standard' regardless.
26 |
27 | ## Compatibility
28 |
29 | This has been tested on WP 3.9, using WPEC 3.8.14 and Woocommerce 2.1.8.
30 |
31 | Please let us know if you have any issues or requests.
32 |
--------------------------------------------------------------------------------
/wpec-to-woo/wpec-to-woo.php:
--------------------------------------------------------------------------------
1 | The idea is you run this on a wordpress shop already setup with wp-e-commerce. Then this code will convert as much as it can into a woocommerce a shop. Make sure you have the Woocommerce plugin activated.
';
27 | $help .= 'Currently only converting products and categories, plan to try and convert the orders too. Because the sites i\'m writing this for don\'t have any variations on products i have not taken the time to work out a system for them. It also sets all products tax status to \'taxable\' and the tax class to \'standard\' regardless.
';
28 | $help .= 'One last caveat: i\'m working with version:3.8.6 of wp-e-commerce, things may well have changed with the lastest version but the shops i need to convert are on this version and i\'m not interested in trying to upgrade them because of the many problems i have been having each time i upgrade the wp-e-commerce plugin. I\'ll test the plugin with the latest verion at a later date.
';
29 | get_current_screen( $page, $help );
30 | }// END: plugin_menu
31 |
32 | function admin_styles() {
33 | wp_enqueue_style( 'wpec_to_woo_styles' );
34 | }
35 |
36 | function admin_init() {
37 | wp_register_style( 'wpec_to_woo_styles', plugins_url('styles.css', __FILE__) );
38 | }
39 |
40 | function plugin_options() {
41 | if (!current_user_can('manage_options')) {
42 | wp_die( __('You do not have sufficient permissions to access this page.') );
43 | }
44 |
45 | ?>
46 |
47 |
Wp-e-commerce to woocommerce converter
48 |
Use at your own risk!, still working on it, only use it on a test version of your site. Read the help for more information.
49 | delete_orders();
52 | }
53 | if( $_POST['order'] == 'go_go_go' ){
54 | $this->conversion();
55 | }
56 | $this->at_a_glance();
57 | ?>
58 |
66 | show_log();
69 | }
70 | ?>
71 |
72 |
78 |
281 | post_author = $wpdb->get_var( "SELECT ID FROM $wpdb->users;" );
288 | $this->update_shop_settings();
289 | $this->update_products();
290 | $this->update_categories();
291 | $this->update_coupons();
292 | $this->update_orders();
293 | // tags don't need to be updated as both wpec and woo use the same name for the taxonomy 'product_tag'
294 | // $this->delete_redundant_wpec_datbase_entries();
295 | }// END: conversion
296 |
297 | function show_log(){
298 | ?>
299 |
390 | $this->old_post_type,
401 | 'posts_per_page' => -1,
402 | 'post_status' => array('publish','pending','draft','auto-draft','future','private','trash')
403 | );
404 | $products = new WP_Query( $args );
405 | $count = 0;
406 | // wp-e stores all the featured products in one place
407 | $featured_products = get_option('sticky_products', false);
408 |
409 | while ( $products->have_posts() ) : $products->the_post();
410 | $post_id = get_the_id();
411 | $count ++;
412 |
413 | // ______ POST TYPE ______
414 | set_post_type( $post_id , 'product');
415 | // ______________________________
416 |
417 |
418 | // get the serialized wpec product metadata
419 | $_wpsc_product_metadata = get_post_meta($post_id, '_wpsc_product_metadata', true);
420 |
421 |
422 | // ______ PRICE ______
423 | $regular_price = get_post_meta($post_id, '_wpsc_price', true);
424 | update_post_meta($post_id, '_regular_price', $regular_price);
425 | $sale_price = get_post_meta($post_id, '_wpsc_special_price', true);
426 | if( $sale_price != '' && $sale_price != $regular_price ){
427 | update_post_meta($post_id, '_price', $sale_price);
428 | update_post_meta($post_id, '_sale_price', $sale_price);
429 | }else{
430 | update_post_meta($post_id, '_price', $regular_price);
431 | }
432 | // ______________________________
433 |
434 |
435 | // ______ INVENTORY ______
436 | $stock = get_post_meta($post_id, '_wpsc_stock', true);
437 | if( $stock != '' ){
438 | $manage_stock = 'yes';
439 | $backorders = 'no';
440 | if( (int)$stock > 0 ){
441 | $stock_status = 'instock';
442 | }else{
443 | $stock_status = 'outofstock';
444 | }
445 | }else{
446 | $manage_stock = 'no';
447 | $backorders = 'yes';
448 | $stock_status = 'instock';
449 | }
450 | // stock qty
451 | update_post_meta($post_id, '_stock', $stock);
452 | // stock status
453 | update_post_meta($post_id, '_stock_status', $stock_status);
454 | // manage stock
455 | update_post_meta($post_id, '_manage_stock', $manage_stock);
456 | // backorders
457 | update_post_meta($post_id, '_backorders', $backorders);
458 | // ______________________________
459 |
460 |
461 | // ______ PRODUCT TYPE AND VISIBILITY ______
462 | // setting all products to simple
463 | $product_type = 'simple';
464 | wp_set_object_terms($post_id, $product_type, 'product_type');
465 | if( $stock_status == 'instock' ){
466 | $visibility = 'visible';
467 | }else{
468 | $visibility = 'hidden';
469 | }
470 | // visibility
471 | update_post_meta($post_id, '_visibility', $visibility);
472 | // ______________________________
473 |
474 |
475 | // ______ OTHER PRODUCT DATA ______
476 | // sku code
477 | $sku = get_post_meta($post_id, '_wpsc_sku', true);
478 | if( $sku == null ){
479 | // try the old name
480 | $sku = $_wpsc_product_metadata['_wpsc_sku'];
481 | }
482 | update_post_meta($post_id, '_sku', $sku);
483 |
484 | // tax status
485 | $tax_status = 'taxable';
486 | update_post_meta($post_id, '_tax_status', $sku);
487 | // tax class empty sets it to stndard
488 | $tax_class = '';
489 | update_post_meta($post_id, '_tax_class', $sku);
490 |
491 | // weight
492 | $weight = $_wpsc_product_metadata['weight'];
493 |
494 | update_post_meta($post_id, '_weight', $weight);
495 | /*
496 | * WPEC use to use ['_wpsc_dimensions'] but then changed to use ['dimensions']
497 | * some products may still have the old variable name
498 | */
499 | $dimensions = $_wpsc_product_metadata['dimensions'];
500 | if( $dimensions == null ){
501 | // try the old name
502 | $dimensions = $_wpsc_product_metadata['_wpsc_dimensions'];
503 | }
504 | // height
505 | $height = $dimensions['height'];
506 | update_post_meta($post_id, '_height', $height);
507 | //length
508 | $length = $dimensions['length'];
509 | update_post_meta($post_id, '_length', $length);
510 | //width
511 | $width = $dimensions['width'];
512 | update_post_meta($post_id, '_width', $width);
513 |
514 | /* woocommerce option update, weight unit and dimentions unit */
515 | if( $count == 1 ){
516 | /*
517 | * wpec stores weight unit and dimentions on a per product basis
518 | * as i expect most shops will use the same values for all products we can just take a single product
519 | * and just use those values for the global values used store wide in woocommerce
520 | */
521 | $weight_unit = $_wpsc_product_metadata['weight_unit'];
522 | $dimentions_unit = $dimensions['height_unit'];
523 | if( $weight_unit == "pound" || $weight_unit == "ounce" || $weight_unit == "gram" ){
524 | $weight_unit = "lbs";
525 | }else{
526 | $weight_unit = "kg";
527 | }
528 | if( $dimentions_unit == "cm" || $dimentions_unit == "meter" ){
529 | $dimentions_unit = "cm";
530 | }else{
531 | $dimentions_unit = "in";
532 | }
533 | update_option( 'woocommerce_weight_unit', $weight_unit );
534 | update_option( 'woocommerce_dimension_unit', $dimentions_unit );
535 | }
536 |
537 |
538 | // featured?
539 | if (in_array($post_id, $featured_products)) {
540 | $featured = 'yes';
541 | }else{
542 | $featured = 'no';
543 | }
544 | update_post_meta($post_id, '_featured', $featured);
545 | // ______________________________
546 |
547 |
548 | // ______ PRODUCT IMAGES ______
549 | /*
550 | * if products have multiple images wpec puts those pictures into the post gallery
551 | * because of this those pictures don't need to be ammended and should still be working
552 | * we only need to update the featured image
553 | * wpec uses the first one in the galley as the product image so we just have to set that as
554 | * the featured image
555 | */
556 | $args = array( 'post_type' => 'attachment', 'numberposts' => 1, 'post_status' => null, 'post_parent' => $post_id, 'post_mime_type' => 'image' );
557 | $attachments = get_posts($args);
558 | if ($attachments) {
559 | foreach ( $attachments as $attachment ) {
560 | set_post_thumbnail( $post_id, $attachment->ID );
561 | }
562 | }
563 | // ______________________________
564 |
565 | // add product to log
566 | $this->log["products"][] = array(
567 | "id" => $post_id,
568 | "title" => get_the_title(),
569 | "link" => "?post=". $post_id ."&action=edit"
570 | );
571 | endwhile;
572 |
573 | }// END: update_products
574 |
575 | /*
576 | * update category
577 | */
578 | function update_categories(){
579 | global $wpdb;
580 |
581 | //$wpdb->show_errors();
582 | // count how many categories there are to convert
583 | $category_count = $wpdb->get_var( "
584 | SELECT COUNT(*) FROM $wpdb->term_taxonomy
585 | WHERE taxonomy='wpsc_product_category'"
586 | );
587 | // log the count
588 | $this->log["categories"] = array( "updated" => $category_count );
589 |
590 | // convert the categories
591 | $table = $wpdb->prefix . 'term_taxonomy';
592 | $data = array( 'taxonomy' => 'product_cat' );
593 | $where = array( 'taxonomy' => 'wpsc_product_category' );
594 | $wpdb->update( $table, $data, $where );
595 |
596 | // category stuff inside postmeta
597 | $data = array( 'meta_value' => 'product_cat' );
598 | $where = array( 'meta_value' => 'wpsc_product_category' );
599 | $table = $wpdb->prefix . 'postmeta';
600 | $wpdb->update( $table, $data, $where );
601 |
602 | /* category images !!!!!!!!!!! */
603 | $wpdb->flush();
604 | }// END: update_categories
605 |
606 | function update_shop_settings(){
607 | global $wpdb;
608 | /*
609 | * were only going to update some straight forward options
610 | * most options are not worth updating, these can be done by the user easy enough
611 | */
612 | // ______ GENERAL ______
613 | // Guest checkout
614 | $enable_guest_checkout = get_option('require_register');
615 | if( $enable_guest_checkout == '1' ){
616 | $enable_guest_checkout = 'no';
617 | }else{
618 | $enable_guest_checkout = 'yes';
619 | }
620 | update_option( 'woocommerce_enable_guest_checkout', $enable_guest_checkout );
621 | // ______________________________
622 |
623 | // ______ CATALOG ______
624 | /*
625 | weight unit and dimentions unit are changed in the update_products() function because of the way wpec stores these options
626 | */
627 |
628 | // product thumbnail, width and height
629 | $product_thumb_width = get_option('product_image_width');
630 | update_option('woocommerce_thumbnail_image_width', $product_thumb_width);
631 | $product_thumb_height = get_option('product_image_height');
632 | update_option('woocommerce_thumbnail_image_height', $product_thumb_height);
633 |
634 | // catalog image, width and height
635 | $catalog_thumb_width = get_option('category_image_width');
636 | update_option('woocommerce_catalog_image_width', $catalog_thumb_width);
637 | $catalog_thumb_height = get_option('category_image_height');
638 | update_option('woocommerce_catalog_image_height', $catalog_thumb_height);
639 |
640 | // Single Product, width and height
641 | $single_product_width = get_option('single_view_image_width');
642 | update_option('woocommerce_single_image_width', $single_product_width);
643 | $single_product_height = get_option('single_view_image_height');
644 | update_option('woocommerce_single_image_height', $single_product_height);
645 |
646 | // Crop Thumbnails:
647 | /*
648 | wpec has a setting 'wpsc_crop_thumbnails' when this is set it seems to initiate hard crop for all product images
649 | so we can set all of the woo hard crop options to this single option value
650 | */
651 | $hard_crop = (get_option('wpsc_crop_thumbnails')=='yes') ? 1 : 0;
652 | update_option('woocommerce_catalog_image_crop', $hard_crop);
653 | update_option('woocommerce_single_image_crop', $hard_crop);
654 | update_option('woocommerce_thumbnail_image_crop', $hard_crop);
655 |
656 | // ______________________________
657 |
658 | }
659 |
660 | function update_coupons(){
661 | global $wpdb;
662 | // get all coupons
663 | $wpec_coupon_table = $wpdb->prefix . 'wpsc_coupon_codes';
664 | $coupon_data = $wpdb->get_results( "SELECT * FROM `" . $wpec_coupon_table . "` ", ARRAY_A );
665 |
666 | // get the gmt timezone
667 | $post_date_gmt = date_i18n( 'Y-m-d H:i:s', false, true );
668 | // get the local timezone
669 | $post_date = date_i18n( 'Y-m-d H:i:s' );
670 |
671 | // loop through coupons
672 | foreach ( (array)$coupon_data as $coupon ):
673 |
674 | $post_title = sanitize_title( $coupon['coupon_code'] );
675 | // check to see if coupon has already been added
676 | $coupon_exists = $wpdb->get_var($wpdb->prepare("
677 | SELECT ID FROM $wpdb->posts
678 | WHERE post_title = %s
679 | AND post_type = 'shop_coupon'",
680 | $post_title
681 | ));
682 |
683 | if( !$coupon_exists ):
684 | // create a new post with custom post type 'shop_coupon'
685 | $post = array(
686 | 'comment_status' => 'closed', // 'closed' means no comments.
687 | 'ping_status' => 'closed', // 'closed' means pingbacks or trackbacks turned off
688 | 'post_author' => $this->post_author, //The user ID number of the author.
689 | //'post_content' => '', //The full text of the post.
690 | 'post_date' => $post_date, //The time post was made.
691 | 'post_date_gmt' => $post_date_gmt, //The time post was made, in GMT.
692 | //'post_name' => '', // The name (slug) for your post
693 | 'post_parent' => '0', //Sets the parent of the new post.
694 | 'post_status' => 'publish', //Set the status of the new post.
695 | 'post_title' => $post_title, //The title of your post.
696 | 'post_type' => 'shop_coupon'
697 | );
698 |
699 | $post_id = wp_insert_post( $post, true );
700 |
701 | if( !isset($post_id->errors) ){
702 | // save details of the created coupon into the log
703 | $coupon_log = array(
704 | "title" => $post_title,
705 | "link" => "?post=". $post_id ."&action=edit"
706 | );
707 |
708 | // if coupon is in-active or has conditions set the expiry date to a day in the past
709 | $conditions = unserialize( $coupon['condition'] );
710 | if( $coupon['active'] == "0" || count( $conditions ) > 0 || $coupon['is-percentage'] == "2" ){
711 | if( count( $conditions ) > 0 ){
712 | // if conditions are present we will explain to the user why the coupon is set to unactive
713 | $coupon_log["conditions"] = true;
714 | }
715 | if( $coupon['is-percentage'] == "2" ){
716 | // freeshipping is not supported by woocommerce
717 | // if is free shipping we will explain to the user why the coupon is set to unactive
718 | $coupon_log["free-shipping"] = true;
719 | }
720 | // set expiry in the past
721 | $expiry_date = date_i18n('Y-m-d', strtotime("-1 year") );
722 | }else{
723 | $expiry_date = $coupon['expiry'];
724 | }
725 |
726 | // set expiry date
727 | update_post_meta($post_id, 'expiry_date', $expiry_date);
728 |
729 | // set the discount_type
730 | if( $coupon['is-percentage'] == "0" ){
731 | // fixed
732 | if( $coupon['every_product'] == "1" ){
733 | $discount_type = 'fixed_product';
734 | }else{
735 | $discount_type = 'fixed_cart';
736 | }
737 | }elseif( $coupon['is-percentage'] == "1" ){
738 | // percentage
739 | if( $coupon['every_product'] == "1" ){
740 | $discount_type = 'percent_product';
741 | }else{
742 | $discount_type = 'percent';
743 | }
744 | }
745 | update_post_meta($post_id, 'discount_type', $discount_type);
746 |
747 | // set coupon amount
748 | update_post_meta($post_id, 'coupon_amount', $coupon['value']);
749 |
750 | // wpec does not allow user to use more then one code together anyay so we can set them all to 'yes'
751 | update_post_meta($post_id, 'individual_use', 'yes');
752 |
753 | //set product_ids and exclude_product_ids, feature not available to wpec so just insert blank values
754 | update_post_meta($post_id, 'product_ids', '');
755 | update_post_meta($post_id, 'exclude_product_ids', '');
756 |
757 | //set usage limit
758 | /*
759 | you can't set a useage value in wpec, but you can set a 'use once' bool, so if thats set
760 | and the discount code has not been used yet, we can set the useage limit to 1, otherwise
761 | leave it blank
762 | */
763 | if( $coupon['use-once'] == "1" ){
764 | $usage_limit = '1';
765 | if( $coupon['is-used'] == "1" ){
766 | update_post_meta($post_id, 'usage_count', '1');
767 | }
768 | }else{
769 | $usage_limit = '';
770 | }
771 | update_post_meta($post_id, 'usage_limit', $usage_limit);
772 |
773 | // save coupon info to log
774 | $this->log["coupons"][] = $coupon_log;
775 | }else{
776 | // coupon insertian failed, give feedback to user
777 | }
778 | else:
779 | // tell user this coupon already exists in the database!
780 | endif; // if( !$coupon_exists )
781 |
782 | endforeach;
783 | // end: loop of coupons
784 |
785 | }// END: update_coupons()
786 |
787 | function delete_orders(){
788 | $mycustomposts = get_posts( array( 'post_type' => 'shop_order', 'posts_per_page' => 9999) );
789 | foreach( $mycustomposts as $mypost ){
790 | wp_delete_post( $mypost->ID, true);
791 | }
792 | }
793 |
794 | function update_orders(){
795 | global $wpdb;
796 | // loop through orders
797 | $wpec_order_table = $wpdb->prefix . 'wpsc_purchase_logs';
798 | $wpec_formdata_table = $wpdb->prefix . 'wpsc_submited_form_data';
799 |
800 | $order_data = $wpdb->get_results( "SELECT * FROM `" . $wpec_order_table . "`", ARRAY_A );
801 | foreach ( (array)$order_data as $order ){
802 | $post_title = "WPEC Order - " . $order['id'] . " - " . date( 'Y-m-d H:i:s', $order['date'] );
803 |
804 | // check to see if order has already been added
805 | $order_exists = $wpdb->get_var($wpdb->prepare("
806 | SELECT ID FROM $wpdb->posts
807 | WHERE post_title = %s
808 | AND post_type = 'shop_order'",
809 | $post_title
810 | ));
811 |
812 | if( $order_exists ){
813 | continue;
814 | }
815 |
816 | // create a new post with custom post type 'shop_order'
817 | $post = array(
818 | 'comment_status' => 'closed',
819 | 'ping_status' => 'closed',
820 | 'post_author' => $this->post_author,
821 | 'post_parent' => '0',
822 | 'post_status' => 'publish',
823 | 'post_title' => $post_title,
824 | 'post_type' => 'shop_order'
825 | );
826 | // insert post
827 | $post_id = wp_insert_post( $post, true );
828 |
829 | // wpec tables
830 | $wpsc_cart_contents_table = $wpdb->prefix . 'wpsc_cart_contents';
831 | $wpsc_purchase_logs_table = $wpdb->prefix . 'wpsc_purchase_logs';
832 | $wpsc_submited_form_data_table = $wpdb->prefix . 'wpsc_submited_form_data';
833 | $wpsc_checkout_forms_table = $wpdb->prefix . 'wpsc_checkout_forms';
834 |
835 | /*
836 | CUSTOMER DATA
837 | */
838 | $userinfo = $wpdb->get_results("
839 | SELECT
840 | `" . $wpsc_submited_form_data_table . "`.`value`,
841 | `" . $wpsc_checkout_forms_table . "`.`name`,
842 | `" . $wpsc_checkout_forms_table . "`.`unique_name`
843 | FROM `" . $wpsc_checkout_forms_table . "`
844 | LEFT JOIN `" . $wpsc_submited_form_data_table . "`
845 | ON `" . $wpsc_checkout_forms_table . "`.id = `" . $wpsc_submited_form_data_table . "`.`form_id`
846 | WHERE `" . $wpsc_submited_form_data_table . "`.`log_id`=" . $order['id'] . "
847 | ORDER BY `" . $wpsc_checkout_forms_table . "`.`checkout_order`
848 | ", ARRAY_A );
849 | foreach($userinfo as $info){
850 | $userinfo[$info['unique_name']] = $info['value'];
851 | }
852 |
853 | // ID
854 | update_post_meta( $post_id, '_customer_user', $order['user_ID'] );
855 |
856 | // billing address
857 | update_post_meta( $post_id, '_billing_first_name', $userinfo['billingfirstname'] );
858 | update_post_meta( $post_id, '_billing_last_name', $userinfo['billinglastname'] );
859 | update_post_meta( $post_id, '_billing_address_1', $userinfo['billingaddress'] );
860 | update_post_meta( $post_id, '_billing_address_2', "" );
861 | update_post_meta( $post_id, '_billing_city', $userinfo['billingcity'] );
862 | update_post_meta( $post_id, '_billing_postcode', $userinfo['billingpostcode'] );
863 | update_post_meta( $post_id, '_billing_country', $userinfo['billingcountry'] );
864 | update_post_meta( $post_id, '_billing_email', $userinfo['billingemail'] );
865 | update_post_meta( $post_id, '_billing_phone', $userinfo['billingphone'] );
866 |
867 | // shipping address
868 | update_post_meta( $post_id, '_shipping_first_name', $userinfo['shippingfirstname'] );
869 | update_post_meta( $post_id, '_shipping_last_name', $userinfo['shippinglastname'] );
870 | update_post_meta( $post_id, '_shipping_company', "" );
871 | update_post_meta( $post_id, '_shipping_address_1', $userinfo['shippingaddress'] );
872 | update_post_meta( $post_id, '_shipping_address_2', "" );
873 | update_post_meta( $post_id, '_shipping_city', $userinfo['shippingcity'] );
874 | update_post_meta( $post_id, '_shipping_postcode', $userinfo['shippingpostcode'] );
875 | update_post_meta( $post_id, '_shipping_country', $userinfo['shippingcountry'] );
876 | update_post_meta( $post_id, '_shipping_state', "" );
877 |
878 | /*
879 | ORDER ITEMS
880 | */
881 | $cartcontent = $wpdb->get_results("
882 | SELECT *
883 | FROM `" . $wpsc_cart_contents_table . "`
884 | WHERE `purchaseid`=" . $order['id'] . "
885 | ");
886 | foreach($cartcontent as $item){
887 |
888 | $item_id = wc_add_order_item( $post_id, array(
889 | 'order_item_name' => $item->name,
890 | 'order_item_type' => 'line_item'
891 | ) );
892 |
893 | if ( $item_id ) {
894 | wc_add_order_item_meta( $item_id, '_qty', $item->quantity );
895 | wc_add_order_item_meta( $item_id, '_product_id', $item->prodid );
896 | wc_add_order_item_meta( $item_id, '_variation_id', null );
897 | $subtotal = $item->quantity * $item->price;
898 | wc_add_order_item_meta( $item_id, '_line_subtotal', $subtotal );
899 | wc_add_order_item_meta( $item_id, '_line_subtotal_tax', $subtotal+$item->tax_charged );
900 | wc_add_order_item_meta( $item_id, '_line_total', $subtotal+$item->tax_charged );
901 | wc_add_order_item_meta( $item_id, '_line_tax', $item->tax_charged );
902 | }
903 | }
904 |
905 |
906 | /*
907 | ORDER DATA
908 | */
909 | $extrainfo = $wpdb->get_results("
910 | SELECT DISTINCT `" . $wpsc_purchase_logs_table . "` . *
911 | FROM `" . $wpsc_submited_form_data_table . "`
912 | LEFT JOIN `" . $wpsc_purchase_logs_table . "`
913 | ON `" . $wpsc_submited_form_data_table . "`.`log_id` = `" . $wpsc_purchase_logs_table . "`.`id`
914 | WHERE `" . $wpsc_purchase_logs_table . "`.`id`=" . $order['id'] . "
915 | ");
916 | $extrainfo = $extrainfo[0];
917 | update_post_meta( $post_id, '_payment_method', $extrainfo->gateway );
918 | update_post_meta( $post_id, '_order_shipping', $extrainfo->base_shipping );
919 | update_post_meta( $post_id, '_order_discount', $extrainfo->base_shipping );
920 | update_post_meta( $post_id, '_cart_discount', $extrainfo->base_shipping );
921 | update_post_meta( $post_id, '_order_tax', $extrainfo->base_shipping );
922 | update_post_meta( $post_id, '_order_shipping_tax', $extrainfo->base_shipping );
923 | update_post_meta( $post_id, '_order_total', $extrainfo->totalprice );
924 | update_post_meta( $post_id, '_order_key', uniqid( 'order_' ) );
925 | update_post_meta( $post_id, '_order_currency', "EUR" );
926 | update_post_meta( $post_id, '_prices_include_tax', "no" );
927 |
928 | // order date
929 | wp_update_post(array(
930 | 'ID' => $post_id,
931 | 'post_date' => date_i18n( 'Y-m-d H:i:s', $extrainfo->date ),
932 | 'post_date_gmt' => date_i18n( 'Y-m-d H:i:s', $extrainfo->date, true ),
933 | ));
934 |
935 | // order status
936 | switch( $order['processed'] ){
937 | case "1":
938 | $status = 'failed';
939 | break;
940 | case "2":
941 | $status = 'pending';
942 | break;
943 | case "3":
944 | case "4":
945 | $status = 'processing';
946 | break;
947 | case "5":
948 | $status = 'completed';
949 | break;
950 | case "6":
951 | $status = 'cancelled';
952 | break;
953 | }
954 | wp_set_post_terms( $post_id, $status, 'shop_order_status' );
955 |
956 |
957 | // add to log
958 | $this->log['orders'][] = array(
959 | 'name' => $post_title
960 | );
961 |
962 | }
963 |
964 | }// END: update_orders()
965 |
966 | function delete_redundant_wpec_datbase_entries(){
967 | global $wpdb;
968 | /* delete all wpec database entries */
969 | delete_post_meta($post_id, '_wpsc_price');
970 | delete_post_meta($post_id, '_wpsc_special_price');
971 | delete_post_meta($post_id, '_wpsc_stock');
972 | delete_post_meta($post_id, '_wpsc_is_donation');
973 | delete_post_meta($post_id, '_wpsc_original_id');
974 | delete_post_meta($post_id, '_wpsc_sku');
975 | delete_post_meta($post_id, '_wpsc_product_metadata');
976 | delete_option('sticky_products');
977 | delete_option('require_register');
978 | delete_option('product_image_width');
979 | delete_option('product_image_height');
980 | delete_option('category_image_width');
981 | delete_option('category_image_height');
982 | delete_option('wpsc_crop_thumbnails');
983 |
984 | // delete tables
985 | $table = $wpdb->prefix."wpsc_coupon_codes";
986 | $wpdb->query("DROP TABLE IF EXISTS $table");
987 | }
988 |
989 | } //End Class: ralc_wpec_to_woo
990 |
991 | }
992 |
993 |
994 | // instantiate class
995 | if (class_exists("ralc_wpec_to_woo")) {
996 | $ralc_wpec_to_woo = new ralc_wpec_to_woo();
997 | }
998 |
999 | //Actions and Filters
1000 | if (isset($ralc_wpec_to_woo)) {
1001 | //Actions
1002 | add_action( 'admin_init', array($ralc_wpec_to_woo, 'admin_init') );
1003 | add_action('admin_menu', array($ralc_wpec_to_woo, 'plugin_menu') );
1004 | }
1005 |
--------------------------------------------------------------------------------