Version Description
- WC 3.5.0 Tested OK.
Download this release
Release Info
Developer | webtoffee |
Plugin | Order Export & Order Import for WooCommerce |
Version | 1.3.7 |
Comparing to | |
See all releases |
Code changes from version 1.3.6 to 1.3.7
- Sample_Coupon.csv +0 -0
- Sample_Order.csv +0 -0
- Sample_Subscription.csv +0 -0
- images/Order-Import-Export-for-WooCommerce-Image.png +0 -0
- images/calendar.png +0 -0
- images/storefrog.png +0 -0
- images/wf-ajax-loader.gif +0 -0
- images/wf-failed.png +0 -0
- images/wf-import.png +0 -0
- images/wf-notice.png +0 -0
- images/wf-success.png +0 -0
- includes/class-wf-cpnimpexpcsv-admin-screen.php +0 -0
- includes/class-wf-cpnimpexpcsv-ajax-handler.php +0 -0
- includes/class-wf-cpnimpexpcsv-system-status-tools.php +0 -0
- includes/class-wf-orderimpexp-plugin-uninstall-feedback.php +0 -0
- includes/class-wf-orderimpexpcsv-admin-screen.php +0 -0
- includes/class-wf-orderimpexpcsv-ajax-handler.php +0 -0
- includes/class-wf-orderimpexpcsv-system-status-tools.php +0 -0
- includes/exporter/class-wf-cpnimpexpcsv-exporter.php +0 -0
- includes/exporter/class-wf-orderimpexpcsv-exporter.php +3 -3
- includes/exporter/data/data-wf-post-columns-coupon.php +0 -0
- includes/exporter/data/data-wf-post-columns.php +0 -0
- includes/importer/class-wf-cpnimpexpcsv-coupon-import.php +5 -5
- includes/importer/class-wf-cpnimpexpcsv-importer.php +0 -0
- includes/importer/class-wf-csv-parser-coupon.php +0 -0
- includes/importer/class-wf-csv-parser.php +4 -0
- includes/importer/class-wf-orderimpexpcsv-importer.php +0 -0
- includes/importer/class-wf-orderimpexpcsv-order-import.php +780 -804
- includes/importer/data-coupon/data-wf-post-defaults.php +0 -0
- includes/importer/data-coupon/data-wf-postmeta-allowed.php +0 -0
- includes/importer/data-coupon/data-wf-postmeta-defaults.php +0 -0
- includes/importer/data-coupon/data-wf-reserved-fields-pair.php +0 -0
- includes/importer/data-coupon/data-wf-reserved-fields.php +0 -0
- includes/importer/data/data-wf-reserved-fields-pair.php +0 -0
- includes/importer/views-coupon/html-wf-import-greeting.php +0 -0
- includes/importer/views-coupon/html-wf-import-options.php +0 -0
- includes/importer/views/html-wf-import-greeting.php +0 -0
- includes/importer/views/html-wf-import-options.php +0 -0
- includes/settings/class-wf-orderimpexpcsv-settings.php +0 -0
- includes/views/export/html-wf-export-coupons.php +0 -0
- includes/views/export/html-wf-export-orders.php +0 -0
- includes/views/html-wf-admin-screen.php +0 -0
- includes/views/html-wf-getting-started-subscription.php +0 -0
- includes/views/import/html-wf-import-coupons.php +0 -0
- includes/views/import/html-wf-import-orders.php +0 -0
- includes/views/market.php +0 -0
- languages/wf_order_import_export-de_DE.mo +0 -0
- languages/wf_order_import_export-de_DE.po +0 -0
- languages/wf_order_import_export-fr_FR.mo +0 -0
- languages/wf_order_import_export-fr_FR.po +0 -0
- license.txt +0 -0
- order-import-export.php +3 -3
- readme.txt +6 -4
- styles/wf-style.css +0 -0
Sample_Coupon.csv
CHANGED
File without changes
|
Sample_Order.csv
CHANGED
File without changes
|
Sample_Subscription.csv
CHANGED
File without changes
|
images/Order-Import-Export-for-WooCommerce-Image.png
CHANGED
File without changes
|
images/calendar.png
CHANGED
File without changes
|
images/storefrog.png
CHANGED
File without changes
|
images/wf-ajax-loader.gif
CHANGED
File without changes
|
images/wf-failed.png
CHANGED
File without changes
|
images/wf-import.png
CHANGED
File without changes
|
images/wf-notice.png
CHANGED
File without changes
|
images/wf-success.png
CHANGED
File without changes
|
includes/class-wf-cpnimpexpcsv-admin-screen.php
CHANGED
File without changes
|
includes/class-wf-cpnimpexpcsv-ajax-handler.php
CHANGED
File without changes
|
includes/class-wf-cpnimpexpcsv-system-status-tools.php
CHANGED
File without changes
|
includes/class-wf-orderimpexp-plugin-uninstall-feedback.php
CHANGED
File without changes
|
includes/class-wf-orderimpexpcsv-admin-screen.php
CHANGED
File without changes
|
includes/class-wf-orderimpexpcsv-ajax-handler.php
CHANGED
File without changes
|
includes/class-wf-orderimpexpcsv-system-status-tools.php
CHANGED
File without changes
|
includes/exporter/class-wf-cpnimpexpcsv-exporter.php
CHANGED
File without changes
|
includes/exporter/class-wf-orderimpexpcsv-exporter.php
CHANGED
@@ -136,7 +136,7 @@ class WF_OrderImpExpCsv_Exporter {
|
|
136 |
if (!is_object($product)) {
|
137 |
$product = new WC_Product(0);
|
138 |
}
|
139 |
-
|
140 |
if(WC()->version < '3.1.0'){
|
141 |
$item_meta = new WC_Order_Item_Meta((defined('WC_VERSION') >= 2.4) ? $item : $item['item_meta'] );
|
142 |
$meta = $item_meta->display(true, true);
|
@@ -162,7 +162,7 @@ class WF_OrderImpExpCsv_Exporter {
|
|
162 |
$meta = str_replace(array(': ', ':', ';', '|'), '=', $meta);
|
163 |
$meta = str_replace( 'meta=', '', $meta);
|
164 |
}
|
165 |
-
|
166 |
$line_item = array(
|
167 |
'name' => html_entity_decode($product->get_title() ? $product->get_title() : $item['name'], ENT_NOQUOTES, 'UTF-8'),
|
168 |
'product_id' => (WC()->version < '2.7.0')?$product->id:$product->get_id(),
|
@@ -170,7 +170,7 @@ class WF_OrderImpExpCsv_Exporter {
|
|
170 |
'quantity' => $item['qty'],
|
171 |
'total' => wc_format_decimal($order->get_line_total($item), 2),
|
172 |
'refunded' => wc_format_decimal($order->get_total_refunded_for_item($item_id), 2),
|
173 |
-
'meta' => html_entity_decode($meta, ENT_NOQUOTES, 'UTF-8'),
|
174 |
);
|
175 |
|
176 |
// add line item tax
|
136 |
if (!is_object($product)) {
|
137 |
$product = new WC_Product(0);
|
138 |
}
|
139 |
+
/*
|
140 |
if(WC()->version < '3.1.0'){
|
141 |
$item_meta = new WC_Order_Item_Meta((defined('WC_VERSION') >= 2.4) ? $item : $item['item_meta'] );
|
142 |
$meta = $item_meta->display(true, true);
|
162 |
$meta = str_replace(array(': ', ':', ';', '|'), '=', $meta);
|
163 |
$meta = str_replace( 'meta=', '', $meta);
|
164 |
}
|
165 |
+
*/
|
166 |
$line_item = array(
|
167 |
'name' => html_entity_decode($product->get_title() ? $product->get_title() : $item['name'], ENT_NOQUOTES, 'UTF-8'),
|
168 |
'product_id' => (WC()->version < '2.7.0')?$product->id:$product->get_id(),
|
170 |
'quantity' => $item['qty'],
|
171 |
'total' => wc_format_decimal($order->get_line_total($item), 2),
|
172 |
'refunded' => wc_format_decimal($order->get_total_refunded_for_item($item_id), 2),
|
173 |
+
//'meta' => html_entity_decode($meta, ENT_NOQUOTES, 'UTF-8'),
|
174 |
);
|
175 |
|
176 |
// add line item tax
|
includes/exporter/data/data-wf-post-columns-coupon.php
CHANGED
File without changes
|
includes/exporter/data/data-wf-post-columns.php
CHANGED
File without changes
|
includes/importer/class-wf-cpnimpexpcsv-coupon-import.php
CHANGED
@@ -777,14 +777,14 @@ class WF_CpnImpExpCsv_Coupon_Import extends WP_Importer {
|
|
777 |
|
778 |
$this->hf_coupon_log_data_change('coupon-csv-import', sprintf(__('> Inserting %s', 'wf_order_import_export'), esc_html($processing_coupon_title)), true);
|
779 |
$postdata = array(
|
780 |
-
'post_author' => $post['post_author'] ? absint($post['post_author']) : get_current_user_id(),
|
781 |
-
'post_date' => ( $post['post_date']
|
782 |
-
'post_date_gmt' => ( $post['post_date_gmt']
|
783 |
'post_content' => $post['post_excerpt'],
|
784 |
'post_excerpt' => $post['post_excerpt'],
|
785 |
'post_title' => $post['post_title'],
|
786 |
-
'post_name' => ( $post['post_name']
|
787 |
-
'post_status' => ( $post['post_status']
|
788 |
'post_type' => 'shop_coupon',
|
789 |
);
|
790 |
|
777 |
|
778 |
$this->hf_coupon_log_data_change('coupon-csv-import', sprintf(__('> Inserting %s', 'wf_order_import_export'), esc_html($processing_coupon_title)), true);
|
779 |
$postdata = array(
|
780 |
+
'post_author' => (isset($post['post_author']) && !empty($post['post_author'])) ? absint($post['post_author']) : get_current_user_id(),
|
781 |
+
'post_date' => (isset($post['post_date']) && !empty($post['post_date'])) ? date('Y-m-d H:i:s', strtotime($post['post_date'])) : '',
|
782 |
+
'post_date_gmt' => (isset($post['post_date_gmt']) && !empty($post['post_date_gmt'])) ? date('Y-m-d H:i:s', strtotime($post['post_date_gmt'])) : '',
|
783 |
'post_content' => $post['post_excerpt'],
|
784 |
'post_excerpt' => $post['post_excerpt'],
|
785 |
'post_title' => $post['post_title'],
|
786 |
+
'post_name' => (isset($post['post_name']) && !empty($post['post_name'])) ? $post['post_name'] : sanitize_title($post['post_title']),
|
787 |
+
'post_status' => (isset($post['post_status']) && !empty($post['post_status'])) ? $post['post_status'] : 'publish',
|
788 |
'post_type' => 'shop_coupon',
|
789 |
);
|
790 |
|
includes/importer/class-wf-cpnimpexpcsv-importer.php
CHANGED
File without changes
|
includes/importer/class-wf-csv-parser-coupon.php
CHANGED
File without changes
|
includes/importer/class-wf-csv-parser.php
CHANGED
@@ -300,6 +300,10 @@ class WF_CSV_Parser {
|
|
300 |
$item['date'] = $item['order_date'];
|
301 |
|
302 |
if (!empty($item['date'])) {
|
|
|
|
|
|
|
|
|
303 |
if (false === ( $item['date'] = strtotime($item['date']) )) {
|
304 |
// invalid date format
|
305 |
$WF_CSV_Order_Import->hf_order_log_data_change('order-csv-import', sprintf(__('> > Skipped. Invalid date format %s.', 'wf_order_import_export'), $item['date']));
|
300 |
$item['date'] = $item['order_date'];
|
301 |
|
302 |
if (!empty($item['date'])) {
|
303 |
+
if(strpos($item['date'], '-') == 2){
|
304 |
+
$item['date'] = date_create_from_format('d-m-y H:i', $item['date']);
|
305 |
+
$item['date'] = date_format($item['date'], 'Y-m-d H:i:s');
|
306 |
+
}
|
307 |
if (false === ( $item['date'] = strtotime($item['date']) )) {
|
308 |
// invalid date format
|
309 |
$WF_CSV_Order_Import->hf_order_log_data_change('order-csv-import', sprintf(__('> > Skipped. Invalid date format %s.', 'wf_order_import_export'), $item['date']));
|
includes/importer/class-wf-orderimpexpcsv-importer.php
CHANGED
File without changes
|
includes/importer/class-wf-orderimpexpcsv-order-import.php
CHANGED
@@ -5,812 +5,792 @@
|
|
5 |
* @package WordPress
|
6 |
* @subpackage Importer
|
7 |
*/
|
8 |
-
if (
|
9 |
-
|
10 |
|
11 |
class WF_OrderImpExpCsv_Order_Import extends WP_Importer {
|
12 |
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
|
19 |
-
|
20 |
-
|
21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
|
23 |
-
|
24 |
-
|
25 |
-
var $imported = 0;
|
26 |
-
var $errored = 0;
|
27 |
-
|
28 |
-
// Results
|
29 |
-
var $import_results = array();
|
30 |
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
|
|
35 |
|
36 |
-
|
37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
} else {
|
39 |
-
|
40 |
-
}
|
41 |
-
$this->import_page = 'woocommerce_wf_order_csv';
|
42 |
-
$this->file_url_import_enabled = apply_filters( 'woocommerce_csv_product_file_url_import_enabled', true );
|
43 |
-
}
|
44 |
-
|
45 |
-
/**
|
46 |
-
* Registered callback function for the WordPress Importer
|
47 |
-
*
|
48 |
-
* Manages the three separate stages of the CSV import process
|
49 |
-
*/
|
50 |
-
public function dispatch() {
|
51 |
-
global $woocommerce, $wpdb;
|
52 |
-
|
53 |
-
if ( ! empty( $_POST['delimiter'] ) ) {
|
54 |
-
$this->delimiter = stripslashes( trim( $_POST['delimiter'] ) );
|
55 |
-
}else if ( ! empty( $_GET['delimiter'] ) ) {
|
56 |
-
$this->delimiter = stripslashes( trim( $_GET['delimiter'] ) );
|
57 |
-
}
|
58 |
-
|
59 |
-
if ( ! $this->delimiter )
|
60 |
-
$this->delimiter = ',';
|
61 |
-
|
62 |
-
if ( ! empty( $_POST['merge_empty_cells'] ) || ! empty( $_GET['merge_empty_cells'] ) ) {
|
63 |
-
$this->merge_empty_cells = 1;
|
64 |
-
} else{
|
65 |
-
$this->merge_empty_cells = 0;
|
66 |
-
}
|
67 |
-
|
68 |
-
$step = empty( $_GET['step'] ) ? 0 : (int) $_GET['step'];
|
69 |
-
|
70 |
-
switch ( $step ) {
|
71 |
-
case 0 :
|
72 |
-
$this->header();
|
73 |
-
$this->greet();
|
74 |
-
break;
|
75 |
-
case 1 :
|
76 |
-
$this->header();
|
77 |
-
|
78 |
-
check_admin_referer( 'import-upload' );
|
79 |
-
|
80 |
-
if(!empty($_GET['file_url']))
|
81 |
-
$this->file_url = esc_attr( $_GET['file_url'] );
|
82 |
-
if(!empty($_GET['file_id']))
|
83 |
-
$this->id = $_GET['file_id'] ;
|
84 |
-
|
85 |
-
if ( !empty($_GET['clearmapping']) || $this->handle_upload() )
|
86 |
-
$this->import_options();
|
87 |
-
else
|
88 |
-
_e( 'Error with handle_upload!', 'wf_order_import_export' );
|
89 |
-
break;
|
90 |
-
case 2 :
|
91 |
-
$this->header();
|
92 |
-
|
93 |
-
check_admin_referer( 'import-woocommerce' );
|
94 |
-
|
95 |
-
$this->id = (int) $_POST['import_id'];
|
96 |
-
|
97 |
-
if ( $this->file_url_import_enabled )
|
98 |
-
$this->file_url = esc_attr( $_POST['import_url'] );
|
99 |
-
|
100 |
-
if ( $this->id )
|
101 |
-
$file = get_attached_file( $this->id );
|
102 |
-
else if ( $this->file_url_import_enabled )
|
103 |
-
$file = ABSPATH . $this->file_url;
|
104 |
-
|
105 |
-
$file = str_replace( "\\", "/", $file );
|
106 |
-
|
107 |
-
if ( $file ) {
|
108 |
-
?>
|
109 |
-
<table id="import-progress" class="widefat_importer widefat">
|
110 |
-
<thead>
|
111 |
-
<tr>
|
112 |
-
<th class="status"> </th>
|
113 |
-
<th class="row"><?php _e( 'Row', 'wf_order_import_export' ); ?></th>
|
114 |
-
<th><?php _e( 'OrderID', 'wf_order_import_export' ); ?></th>
|
115 |
-
<th><?php _e( 'Order Status', 'wf_order_import_export' ); ?></th>
|
116 |
-
<th class="reason"><?php _e( 'Status Msg', 'wf_order_import_export' ); ?></th>
|
117 |
-
</tr>
|
118 |
-
</thead>
|
119 |
-
<tfoot>
|
120 |
-
<tr class="importer-loading">
|
121 |
-
<td colspan="5"></td>
|
122 |
-
</tr>
|
123 |
-
</tfoot>
|
124 |
-
<tbody></tbody>
|
125 |
-
</table>
|
126 |
-
<script type="text/javascript">
|
127 |
-
jQuery(document).ready(function($) {
|
128 |
-
|
129 |
-
if ( ! window.console ) { window.console = function(){}; }
|
130 |
-
|
131 |
-
var processed_terms = [];
|
132 |
-
var processed_posts = [];
|
133 |
-
var i = 1;
|
134 |
-
var done_count = 0;
|
135 |
-
|
136 |
-
function import_rows( start_pos, end_pos ) {
|
137 |
-
|
138 |
-
var data = {
|
139 |
-
action: 'woocommerce_csv_order_import_request',
|
140 |
-
file: '<?php echo addslashes( $file ); ?>',
|
141 |
-
delimiter: '<?php echo $this->delimiter; ?>',
|
142 |
-
merge_empty_cells: '<?php echo $this->merge_empty_cells; ?>',
|
143 |
-
start_pos: start_pos,
|
144 |
-
end_pos: end_pos,
|
145 |
-
};
|
146 |
-
return $.ajax({
|
147 |
-
url: '<?php echo add_query_arg( array( 'import_page' => $this->import_page, 'step' => '3', 'merge' => ! empty( $_GET['merge'] ) ? '1' : '0' ), admin_url( 'admin-ajax.php' ) ); ?>',
|
148 |
-
data: data,
|
149 |
-
type: 'POST',
|
150 |
-
success: function( response ) {
|
151 |
-
if ( response ) {
|
152 |
-
|
153 |
-
try {
|
154 |
-
// Get the valid JSON only from the returned string
|
155 |
-
if ( response.indexOf("<!--WC_START-->") >= 0 )
|
156 |
-
response = response.split("<!--WC_START-->")[1]; // Strip off before after WC_START
|
157 |
-
|
158 |
-
if ( response.indexOf("<!--WC_END-->") >= 0 )
|
159 |
-
response = response.split("<!--WC_END-->")[0]; // Strip off anything after WC_END
|
160 |
-
|
161 |
-
// Parse
|
162 |
-
var results = $.parseJSON( response );
|
163 |
-
|
164 |
-
if ( results.error ) {
|
165 |
-
|
166 |
-
$('#import-progress tbody').append( '<tr id="row-' + i + '" class="error"><td class="status" colspan="5">' + results.error + '</td></tr>' );
|
167 |
-
|
168 |
-
i++;
|
169 |
-
|
170 |
-
} else if ( results.import_results && $( results.import_results ).size() > 0 ) {
|
171 |
-
|
172 |
-
$.each( results.processed_terms, function( index, value ) {
|
173 |
-
processed_terms.push( value );
|
174 |
-
});
|
175 |
-
|
176 |
-
$.each( results.processed_posts, function( index, value ) {
|
177 |
-
processed_posts.push( value );
|
178 |
-
});
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
$( results.import_results ).each(function( index, row ) {
|
183 |
-
$('#import-progress tbody').append( '<tr id="row-' + i + '" class="' + row['status'] + '"><td><mark class="result" title="' + row['status'] + '">' + row['status'] + '</mark></td><td class="row">' + i + '</td><td>' + row['order_number'] + '</td><td>' + row['post_id'] + ' - ' + row['post_title'] + '</td><td class="reason">' + row['reason'] + '</td></tr>' );
|
184 |
-
|
185 |
-
i++;
|
186 |
-
});
|
187 |
-
}
|
188 |
-
|
189 |
-
} catch(err) {}
|
190 |
-
|
191 |
-
} else {
|
192 |
-
$('#import-progress tbody').append( '<tr class="error"><td class="status" colspan="5">' + '<?php _e( 'AJAX Error', 'wf_order_import_export' ); ?>' + '</td></tr>' );
|
193 |
-
}
|
194 |
-
|
195 |
-
var w = $(window);
|
196 |
-
var row = $( "#row-" + ( i - 1 ) );
|
197 |
-
|
198 |
-
if ( row.length ) {
|
199 |
-
w.scrollTop( row.offset().top - (w.height()/2) );
|
200 |
-
}
|
201 |
-
|
202 |
-
done_count++;
|
203 |
-
|
204 |
-
$('body').trigger( 'woocommerce_csv_order_import_request_complete' );
|
205 |
-
}
|
206 |
-
});
|
207 |
-
}
|
208 |
-
|
209 |
-
var rows = [];
|
210 |
-
|
211 |
-
<?php
|
212 |
-
$limit = apply_filters( 'woocommerce_csv_import_limit_per_request', 10 );
|
213 |
-
$enc = mb_detect_encoding( $file, 'UTF-8, ISO-8859-1', true );
|
214 |
-
if ( $enc )
|
215 |
-
setlocale( LC_ALL, 'en_US.' . $enc );
|
216 |
-
@ini_set( 'auto_detect_line_endings', true );
|
217 |
-
|
218 |
-
$count = 0;
|
219 |
-
$previous_position = 0;
|
220 |
-
$position = 0;
|
221 |
-
$import_count = 0;
|
222 |
-
|
223 |
-
// Get CSV positions
|
224 |
-
if ( ( $handle = fopen( $file, "r" ) ) !== FALSE ) {
|
225 |
-
|
226 |
-
while ( ( $postmeta = fgetcsv( $handle, 0, $this->delimiter , '"', '"' ) ) !== FALSE ) {
|
227 |
-
$count++;
|
228 |
-
|
229 |
-
if ( $count >= $limit ) {
|
230 |
-
$previous_position = $position;
|
231 |
-
$position = ftell( $handle );
|
232 |
-
$count = 0;
|
233 |
-
$import_count ++;
|
234 |
-
|
235 |
-
// Import rows between $previous_position $position
|
236 |
-
?>rows.push( [ <?php echo $previous_position; ?>, <?php echo $position; ?> ] ); <?php
|
237 |
-
}
|
238 |
-
}
|
239 |
-
|
240 |
-
// Remainder
|
241 |
-
if ( $count > 0 ) {
|
242 |
-
?>rows.push( [ <?php echo $position; ?>, '' ] ); <?php
|
243 |
-
$import_count ++;
|
244 |
-
}
|
245 |
-
|
246 |
-
fclose( $handle );
|
247 |
-
}
|
248 |
-
?>
|
249 |
-
|
250 |
-
var data = rows.shift();
|
251 |
-
var regen_count = 0;
|
252 |
-
import_rows( data[0], data[1] );
|
253 |
-
|
254 |
-
$('body').on( 'woocommerce_csv_order_import_request_complete', function() {
|
255 |
-
if ( done_count == <?php echo $import_count; ?> ) {
|
256 |
-
|
257 |
-
import_done();
|
258 |
-
} else {
|
259 |
-
// Call next request
|
260 |
-
data = rows.shift();
|
261 |
-
import_rows( data[0], data[1] );
|
262 |
-
}
|
263 |
-
} );
|
264 |
-
|
265 |
-
function import_done() {
|
266 |
-
var data = {
|
267 |
-
action: 'woocommerce_csv_order_import_request',
|
268 |
-
file: '<?php echo $file; ?>',
|
269 |
-
processed_terms: processed_terms,
|
270 |
-
processed_posts: processed_posts,
|
271 |
-
};
|
272 |
-
|
273 |
-
$.ajax({
|
274 |
-
url: '<?php echo add_query_arg( array( 'import_page' => $this->import_page, 'step' => '4', 'merge' => ! empty( $_GET['merge'] ) ? 1 : 0 ), admin_url( 'admin-ajax.php' ) ); ?>',
|
275 |
-
data: data,
|
276 |
-
type: 'POST',
|
277 |
-
success: function( response ) {
|
278 |
-
//console.log( response );
|
279 |
-
$('#import-progress tbody').append( '<tr class="complete"><td colspan="5">' + response + '</td></tr>' );
|
280 |
-
$('.importer-loading').hide();
|
281 |
-
}
|
282 |
-
});
|
283 |
-
}
|
284 |
-
});
|
285 |
-
</script>
|
286 |
-
<?php
|
287 |
-
} else {
|
288 |
-
echo '<p class="error">' . __( 'Error finding uploaded file!', 'wf_order_import_export' ) . '</p>';
|
289 |
-
}
|
290 |
-
break;
|
291 |
-
case 3 :
|
292 |
-
// Check access - cannot use nonce here as it will expire after multiple requests
|
293 |
-
if ( ! current_user_can( 'manage_woocommerce' ) )
|
294 |
-
die();
|
295 |
-
|
296 |
-
add_filter( 'http_request_timeout', array( $this, 'bump_request_timeout' ) );
|
297 |
-
|
298 |
-
if ( function_exists( 'gc_enable' ) )
|
299 |
-
gc_enable();
|
300 |
-
|
301 |
-
@set_time_limit(0);
|
302 |
-
@ob_flush();
|
303 |
-
@flush();
|
304 |
-
$wpdb->hide_errors();
|
305 |
-
|
306 |
-
$file = stripslashes( $_POST['file'] );
|
307 |
-
|
308 |
-
$start_pos = isset( $_POST['start_pos'] ) ? absint( $_POST['start_pos'] ) : 0;
|
309 |
-
$end_pos = isset( $_POST['end_pos'] ) ? absint( $_POST['end_pos'] ) : '';
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
$position = $this->import_start( $file, $start_pos, $end_pos );
|
314 |
-
$this->import();
|
315 |
-
$this->import_end();
|
316 |
-
|
317 |
-
$results = array();
|
318 |
-
$results['import_results'] = $this->import_results;
|
319 |
-
$results['processed_terms'] = $this->processed_terms;
|
320 |
-
$results['processed_posts'] = $this->processed_posts;
|
321 |
-
|
322 |
-
echo "<!--WC_START-->";
|
323 |
-
echo json_encode( $results );
|
324 |
-
echo "<!--WC_END-->";
|
325 |
-
exit;
|
326 |
-
break;
|
327 |
-
case 4 :
|
328 |
-
// Check access - cannot use nonce here as it will expire after multiple requests
|
329 |
-
if ( ! current_user_can( 'manage_woocommerce' ) )
|
330 |
-
die();
|
331 |
-
|
332 |
-
add_filter( 'http_request_timeout', array( $this, 'bump_request_timeout' ) );
|
333 |
-
|
334 |
-
if ( function_exists( 'gc_enable' ) )
|
335 |
-
gc_enable();
|
336 |
-
|
337 |
-
@set_time_limit(0);
|
338 |
-
@ob_flush();
|
339 |
-
@flush();
|
340 |
-
$wpdb->hide_errors();
|
341 |
-
|
342 |
-
$this->processed_terms = isset( $_POST['processed_terms'] ) ? $_POST['processed_terms'] : array();
|
343 |
-
$this->processed_posts = isset( $_POST['processed_posts']) ? $_POST['processed_posts'] : array();
|
344 |
-
|
345 |
-
_e( 'Step 1...', 'wf_order_import_export' ) . ' ';
|
346 |
-
|
347 |
-
wp_defer_term_counting( true );
|
348 |
-
wp_defer_comment_counting( true );
|
349 |
-
|
350 |
-
_e( 'Step 2...', 'wf_order_import_export' ) . ' ';
|
351 |
-
|
352 |
-
echo 'Step 3...' . ' '; // Easter egg
|
353 |
-
|
354 |
-
_e( 'Finalizing...', 'wf_order_import_export' ) . ' ';
|
355 |
-
|
356 |
-
// SUCCESS
|
357 |
-
_e( 'Finished. Import complete.', 'wf_order_import_export' );
|
358 |
-
|
359 |
-
$this->import_end();
|
360 |
-
exit;
|
361 |
-
break;
|
362 |
-
}
|
363 |
-
|
364 |
-
$this->footer();
|
365 |
-
}
|
366 |
-
|
367 |
-
/**
|
368 |
-
* format_data_from_csv
|
369 |
-
*/
|
370 |
-
public function format_data_from_csv( $data, $enc ) {
|
371 |
-
return ( $enc == 'UTF-8' ) ? $data : utf8_encode( $data );
|
372 |
-
}
|
373 |
-
|
374 |
-
/**
|
375 |
-
* Display pre-import options
|
376 |
-
*/
|
377 |
-
public function import_options() {
|
378 |
-
$j = 0;
|
379 |
-
|
380 |
-
if ( $this->id )
|
381 |
-
$file = get_attached_file( $this->id );
|
382 |
-
else if ( $this->file_url_import_enabled )
|
383 |
-
$file = ABSPATH . $this->file_url;
|
384 |
-
else
|
385 |
-
return;
|
386 |
-
|
387 |
-
// Set locale
|
388 |
-
$enc = mb_detect_encoding( $file, 'UTF-8, ISO-8859-1', true );
|
389 |
-
if ( $enc ) setlocale( LC_ALL, 'en_US.' . $enc );
|
390 |
-
@ini_set( 'auto_detect_line_endings', true );
|
391 |
-
|
392 |
-
// Get headers
|
393 |
-
if ( ( $handle = fopen( $file, "r" ) ) !== FALSE ) {
|
394 |
-
|
395 |
-
$row = $raw_headers = array();
|
396 |
-
$header = fgetcsv( $handle, 0, $this->delimiter , '"', '"' );
|
397 |
-
|
398 |
-
while ( ( $postmeta = fgetcsv( $handle, 0, $this->delimiter , '"', '"' ) ) !== FALSE ) {
|
399 |
-
foreach ( $header as $key => $heading ) {
|
400 |
-
if ( ! $heading ) continue;
|
401 |
-
$s_heading = $heading;
|
402 |
-
$row[$s_heading] = ( isset( $postmeta[$key] ) ) ? $this->format_data_from_csv( $postmeta[$key], $enc ) : '';
|
403 |
-
$raw_headers[ $s_heading ] = $heading;
|
404 |
-
}
|
405 |
-
break;
|
406 |
-
}
|
407 |
-
fclose( $handle );
|
408 |
}
|
409 |
-
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
|
416 |
-
|
417 |
-
|
418 |
-
|
419 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
420 |
|
421 |
-
|
422 |
-
|
423 |
-
|
424 |
-
|
425 |
-
|
426 |
-
|
427 |
-
|
428 |
-
|
429 |
-
|
430 |
-
else
|
431 |
-
$this->add_import_result( 'failed', $order->get_error_message(), 'Not parsed', json_encode( $item ), '-' );
|
432 |
-
|
433 |
-
unset( $item, $order );
|
434 |
-
|
435 |
-
}
|
436 |
-
|
437 |
-
$this->hf_order_log_data_change('order-csv-import', __( 'Finished processing Orders.', 'wf_order_import_export' ) );
|
438 |
-
wp_suspend_cache_invalidation( false );
|
439 |
-
}
|
440 |
|
441 |
-
|
442 |
-
* Parses the CSV file and prepares us for the task of processing parsed data
|
443 |
-
*
|
444 |
-
* @param string $file Path to the CSV file for importing
|
445 |
-
*/
|
446 |
-
public function import_start( $file, $start_pos, $end_pos ) {
|
447 |
|
448 |
-
|
449 |
-
|
450 |
|
451 |
-
|
452 |
-
|
|
|
|
|
453 |
|
454 |
-
|
|
|
455 |
|
456 |
-
|
457 |
|
458 |
-
|
|
|
459 |
|
460 |
-
|
461 |
|
462 |
-
|
463 |
-
wp_defer_comment_counting( true );
|
464 |
|
465 |
-
|
466 |
-
}
|
467 |
|
468 |
-
|
469 |
-
|
470 |
-
*/
|
471 |
-
public function import_end() {
|
472 |
|
473 |
-
|
474 |
-
|
475 |
-
|
476 |
-
|
477 |
-
}
|
478 |
|
479 |
-
|
480 |
-
|
481 |
|
482 |
-
|
483 |
-
|
|
|
|
|
|
|
|
|
484 |
|
485 |
-
|
486 |
-
|
487 |
-
|
488 |
-
|
489 |
-
|
490 |
-
|
491 |
-
|
492 |
-
|
|
|
|
|
|
|
|
|
493 |
|
494 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
495 |
|
496 |
-
|
497 |
-
echo '<p><strong>' . __( 'Sorry, there has been an error.', 'wf_order_import_export' ) . '</strong><br />';
|
498 |
-
echo esc_html( $file['error'] ) . '</p>';
|
499 |
-
return false;
|
500 |
-
}
|
501 |
|
502 |
-
|
503 |
-
|
504 |
|
505 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
506 |
|
507 |
-
|
|
|
|
|
508 |
|
509 |
-
|
510 |
-
|
|
|
|
|
|
|
|
|
511 |
|
512 |
-
|
|
|
513 |
|
514 |
-
|
515 |
-
|
516 |
|
517 |
-
|
518 |
|
519 |
-
|
520 |
|
521 |
-
|
522 |
-
}
|
523 |
|
524 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
525 |
global $wpdb;
|
526 |
$query = "SELECT ID FROM $wpdb->posts WHERE post_type = 'shop_order' AND post_status IN ( 'wc-pending', 'wc-processing', 'wc-completed', 'wc-on-hold', 'wc-failed' , 'wc-refunded', 'wc-cancelled')";
|
527 |
$args = array();
|
528 |
$posts_are_exist = @$wpdb->get_col($wpdb->prepare($query, $args));
|
529 |
-
|
530 |
if ($posts_are_exist) {
|
531 |
foreach ($posts_are_exist as $exist_id) {
|
532 |
$found = false;
|
533 |
if ($exist_id == $orderID) {
|
534 |
$found = TRUE;
|
535 |
-
}
|
536 |
-
if($found)
|
|
|
537 |
}
|
538 |
} else {
|
539 |
return FALSE;
|
540 |
}
|
541 |
}
|
542 |
-
|
543 |
-
|
544 |
-
|
545 |
-
|
546 |
-
|
547 |
-
|
548 |
-
|
549 |
-
|
550 |
-
|
551 |
-
|
552 |
-
|
553 |
-
|
554 |
-
|
555 |
-
|
556 |
-
|
557 |
-
|
558 |
-
|
559 |
-
|
560 |
-
|
561 |
-
|
562 |
-
|
563 |
-
|
564 |
-
|
565 |
-
|
566 |
-
|
567 |
-
|
568 |
-
|
569 |
-
|
570 |
-
|
571 |
-
|
572 |
-
|
573 |
-
|
574 |
-
|
575 |
-
|
576 |
-
|
|
|
577 |
// Check if post exists when importing
|
578 |
$new_added = false;
|
579 |
$is_order_exist = $this->order_exists($post['order_number']);
|
580 |
$meta_array = array();
|
581 |
-
|
582 |
-
|
583 |
-
|
|
|
584 |
}
|
585 |
-
|
586 |
-
|
587 |
$user_id = $this->hf_check_customer($meta_array);
|
588 |
-
|
589 |
-
|
590 |
-
|
591 |
-
|
592 |
-
|
593 |
-
|
594 |
-
|
595 |
-
|
596 |
-
|
597 |
-
|
598 |
|
599 |
if (!$merging && $is_order_exist) {
|
600 |
-
|
601 |
-
|
602 |
-
|
603 |
-
|
604 |
-
|
605 |
-
|
606 |
-
|
607 |
-
if($is_order_exist) {
|
608 |
$order_id = $post['order_number'];
|
|
|
609 |
$wp_result = wp_update_post($order_data);
|
610 |
} else {
|
611 |
$order_id = wp_insert_post($order_data);
|
612 |
$new_added = true;
|
613 |
-
if (
|
614 |
-
|
615 |
-
|
616 |
-
|
617 |
-
|
618 |
}
|
619 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
620 |
}
|
621 |
|
622 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
623 |
}
|
624 |
-
|
625 |
-
|
626 |
-
|
627 |
-
|
628 |
-
|
629 |
-
|
630 |
-
|
631 |
-
|
632 |
-
|
633 |
-
|
634 |
-
|
635 |
-
|
636 |
-
|
637 |
-
|
638 |
-
|
639 |
-
|
640 |
-
|
641 |
-
|
642 |
-
|
643 |
-
|
644 |
-
|
645 |
-
|
646 |
-
|
647 |
-
|
648 |
-
|
649 |
-
|
650 |
-
|
651 |
-
|
652 |
-
|
653 |
-
|
654 |
-
update_user_meta( $user_id, "paying_customer", 1 );
|
655 |
-
}
|
656 |
-
}
|
657 |
-
|
658 |
-
|
659 |
-
// handle order items
|
660 |
-
$order_items = array();
|
661 |
-
$order_item_meta = null;
|
662 |
-
|
663 |
-
foreach ( $post['order_items'] as $item ) {
|
664 |
-
|
665 |
-
$product = null;
|
666 |
-
$variation_item_meta = array();
|
667 |
-
|
668 |
-
if ( $item['product_id'] ) {
|
669 |
-
$product = wc_get_product( $item['product_id'] );
|
670 |
-
|
671 |
-
// handle variations
|
672 |
-
if ( $product && ( $product->is_type( 'variable' ) || $product->is_type( 'variation' ) || $product->is_type( 'subscription_variation' ) ) && method_exists( $product, 'get_variation_id' ) ) {
|
673 |
-
foreach ( $product->get_variation_attributes() as $key => $value ) {
|
674 |
-
$variation_item_meta[] = array( 'meta_name' => esc_attr( substr( $key, 10 ) ), 'meta_value' => $value ); // remove the leading 'attribute_' from the name to get 'pa_color' for instance
|
675 |
-
}
|
676 |
-
}
|
677 |
-
}
|
678 |
-
|
679 |
-
// order item
|
680 |
-
$order_items[] = array(
|
681 |
-
'order_item_name' => $product ? $product->get_title() : (!empty($item['unknown_product_name']) ? $item['unknown_product_name'] : __('Unknown Product', 'wf_order_import_export')),
|
682 |
-
'order_item_type' => 'line_item',
|
683 |
-
);
|
684 |
-
|
685 |
-
$var_id = 0;
|
686 |
-
if($product){
|
687 |
-
if (WC()->version < '2.7.0' && method_exists( $product,'get_variation_id' )) {
|
688 |
-
$var_id = $product->get_variation_id();
|
689 |
-
}else{
|
690 |
-
$var_id = $product->get_id();
|
691 |
-
}
|
692 |
-
}
|
693 |
-
// standard order item meta
|
694 |
-
$_order_item_meta = array(
|
695 |
-
'_qty' => (int) $item['qty'],
|
696 |
-
'_tax_class' => '', // Tax class (adjusted by filters)
|
697 |
-
'_product_id' => $item['product_id'],
|
698 |
-
'_variation_id' => $var_id,
|
699 |
-
'_line_subtotal' => number_format( (float) $item['total'], 2, '.', '' ), // Line subtotal (before discounts)
|
700 |
-
'_line_subtotal_tax' => 0, // Line tax (before discounts)
|
701 |
-
'_line_total' => number_format( (float) $item['total'], 2, '.', '' ), // Line total (after discounts)
|
702 |
-
'_line_tax' => 0, // Line Tax (after discounts)
|
703 |
-
);
|
704 |
-
|
705 |
-
// add any product variation meta
|
706 |
-
foreach ( $variation_item_meta as $meta ) {
|
707 |
-
$_order_item_meta[ $meta['meta_name'] ] = $meta['meta_value'];
|
708 |
-
}
|
709 |
-
|
710 |
-
// include any arbitrary order item meta
|
711 |
-
$_order_item_meta = array_merge( $_order_item_meta, $item['meta'] );
|
712 |
-
|
713 |
-
$order_item_meta[] = $_order_item_meta;
|
714 |
-
|
715 |
-
}
|
716 |
-
|
717 |
-
foreach ( $order_items as $key => $order_item ) {
|
718 |
-
$order_item_id = wc_add_order_item( $order_id, $order_item );
|
719 |
-
|
720 |
-
if ( $order_item_id ) {
|
721 |
-
foreach ( $order_item_meta[ $key ] as $meta_key => $meta_value ) {
|
722 |
-
wc_add_order_item_meta( $order_item_id, $meta_key, $meta_value );
|
723 |
-
}
|
724 |
-
}
|
725 |
-
}
|
726 |
-
|
727 |
-
// create the shipping order items
|
728 |
-
foreach ( $post['order_shipping'] as $order_shipping ) {
|
729 |
-
|
730 |
-
$shipping_order_item = array(
|
731 |
-
'order_item_name' => ($order_shipping['title']) ? $order_shipping['title'] : $order_shipping['method_id'],
|
732 |
-
'order_item_type' => 'shipping',
|
733 |
-
);
|
734 |
-
|
735 |
-
$shipping_order_item_id = wc_add_order_item( $order_id, $shipping_order_item );
|
736 |
-
|
737 |
-
if ( $shipping_order_item_id ) {
|
738 |
-
wc_add_order_item_meta( $shipping_order_item_id, 'method_id', $order_shipping['method_id'] );
|
739 |
-
wc_add_order_item_meta( $shipping_order_item_id, 'cost', $order_shipping['cost'] );
|
740 |
-
}
|
741 |
-
}
|
742 |
-
|
743 |
-
// create the tax order items
|
744 |
-
foreach ( $post['tax_items'] as $tax_item ) {
|
745 |
-
|
746 |
-
$tax_order_item = array(
|
747 |
-
'order_item_name' => $tax_item['title'],
|
748 |
-
'order_item_type' => 'tax',
|
749 |
-
);
|
750 |
-
|
751 |
-
$tax_order_item_id = wc_add_order_item( $order_id, $tax_order_item );
|
752 |
-
|
753 |
-
if ( $tax_order_item_id ) {
|
754 |
-
wc_add_order_item_meta( $tax_order_item_id, 'rate_id', $tax_item['rate_id'] );
|
755 |
-
wc_add_order_item_meta( $tax_order_item_id, 'label', $tax_item['label'] );
|
756 |
-
wc_add_order_item_meta( $tax_order_item_id, 'compound', $tax_item['compound'] );
|
757 |
-
wc_add_order_item_meta( $tax_order_item_id, 'tax_amount', $tax_item['tax_amount'] );
|
758 |
-
wc_add_order_item_meta( $tax_order_item_id, 'shipping_tax_amount', $tax_item['shipping_tax_amount'] );
|
759 |
-
}
|
760 |
-
}
|
761 |
-
|
762 |
-
// Grant downloadalbe product permissions
|
763 |
-
if ( $add_download_permissions ) {
|
764 |
-
wc_downloadable_product_permissions( $order_id );
|
765 |
-
}
|
766 |
-
|
767 |
-
// add order notes
|
768 |
-
$order = wc_get_order( $order_id );
|
769 |
-
foreach ( $post['notes'] as $order_note ) {
|
770 |
-
$order->add_order_note( $order_note );
|
771 |
-
}
|
772 |
-
|
773 |
-
// record the product sales
|
774 |
-
if (WC()->version < '2.7.0') {
|
775 |
-
$order->record_product_sales();
|
776 |
-
} else {
|
777 |
-
wc_update_total_sales_counts($order_id);
|
778 |
-
}
|
779 |
-
} // ! dry run
|
780 |
-
|
781 |
-
// was an original order number provided?
|
782 |
-
if ( ! empty( $post['order_number_formatted'] ) ) {
|
783 |
-
if ( ! $dry_run ) {
|
784 |
-
// do our best to provide some custom order number functionality while also allowing 3rd party plugins to provide their own custom order number facilities
|
785 |
-
do_action( 'woocommerce_set_order_number', $order, $post['order_number'], $post['order_number_formatted'] );
|
786 |
-
$order->add_order_note( sprintf( __( "Original order #%s", 'wf_order_import_export' ), $post['order_number_formatted'] ) );
|
787 |
-
|
788 |
-
// get the order so we can display the correct order number
|
789 |
-
$order = wc_get_order( $order_id );
|
790 |
-
}
|
791 |
-
|
792 |
-
$this->processed_posts[ $post['order_number_formatted'] ] = $post['order_number_formatted'];
|
793 |
-
}
|
794 |
-
if($merging && !$new_added)
|
795 |
-
$out_msg = 'Order Successfully updated.';
|
796 |
-
else
|
797 |
-
$out_msg = 'Order Imported Successfully.';
|
798 |
-
|
799 |
-
$this->add_import_result('imported', __($out_msg, 'wf_order_import_export'), $order_id, $order_data['post_title'], $order_id);
|
800 |
-
$this->hf_order_log_data_change('order-csv-import', sprintf(__('> “%s”' . $out_msg, 'wf_order_import_export'), esc_html($order_data['post_title'])), true);
|
801 |
-
$this->imported++;
|
802 |
-
$this->hf_order_log_data_change( 'order-csv-import', sprintf( __( '> Finished importing order %s', 'wf_order_import_export' ), $dry_run ? "" : $order->get_order_number() ) );
|
803 |
|
804 |
// }
|
805 |
|
806 |
-
|
807 |
-
$this->hf_order_log_data_change( 'order-csv-import', __( 'Finished processing orders.', 'wf_order_import_export' ) );
|
808 |
|
809 |
-
|
810 |
-
|
811 |
-
|
812 |
-
|
813 |
-
|
|
|
814 |
|
815 |
$customer_email = (!empty($data['_customer_email']) ) ? $data['_customer_email'] : '';
|
816 |
|
@@ -822,7 +802,7 @@ class WF_OrderImpExpCsv_Order_Import extends WP_Importer {
|
|
822 |
if (is_email($customer_email) && false !== email_exists($customer_email)) {
|
823 |
$found_customer = email_exists($customer_email);
|
824 |
return $found_customer;
|
825 |
-
}
|
826 |
$found_customer = 0;
|
827 |
}
|
828 |
} else {
|
@@ -831,71 +811,67 @@ class WF_OrderImpExpCsv_Order_Import extends WP_Importer {
|
|
831 |
|
832 |
return $found_customer;
|
833 |
}
|
834 |
-
|
835 |
-
|
836 |
-
|
837 |
-
|
838 |
-
|
839 |
-
|
840 |
-
|
841 |
-
|
842 |
-
|
843 |
-
|
844 |
-
|
845 |
-
|
846 |
-
|
847 |
-
|
848 |
-
|
849 |
-
|
850 |
-
|
851 |
-
|
852 |
-
|
853 |
-
|
854 |
-
|
855 |
-
|
856 |
-
|
857 |
-
|
858 |
-
|
859 |
-
|
860 |
-
|
861 |
-
|
862 |
-
|
863 |
-
|
864 |
-
|
865 |
-
|
866 |
-
|
867 |
-
|
868 |
-
|
869 |
-
|
870 |
-
|
871 |
-
|
872 |
-
|
873 |
-
|
874 |
-
|
875 |
-
|
876 |
-
|
877 |
-
|
878 |
-
|
879 |
-
|
880 |
-
|
881 |
-
|
882 |
-
|
883 |
-
|
884 |
-
|
885 |
-
|
886 |
-
|
887 |
-
|
888 |
-
|
889 |
-
|
890 |
-
|
891 |
-
|
892 |
-
|
893 |
-
|
894 |
-
|
895 |
-
|
896 |
-
|
897 |
-
|
898 |
-
$this->log->log("debug", $data ,$context);
|
899 |
-
}
|
900 |
-
}
|
901 |
-
}
|
5 |
* @package WordPress
|
6 |
* @subpackage Importer
|
7 |
*/
|
8 |
+
if (!class_exists('WP_Importer'))
|
9 |
+
return;
|
10 |
|
11 |
class WF_OrderImpExpCsv_Order_Import extends WP_Importer {
|
12 |
|
13 |
+
var $id;
|
14 |
+
var $file_url;
|
15 |
+
var $delimiter;
|
16 |
+
var $merge_empty_cells;
|
17 |
+
// mappings from old information to new
|
18 |
+
var $processed_terms = array();
|
19 |
+
var $processed_posts = array();
|
20 |
+
var $merged = 0;
|
21 |
+
var $skipped = 0;
|
22 |
+
var $imported = 0;
|
23 |
+
var $errored = 0;
|
24 |
+
// Results
|
25 |
+
var $import_results = array();
|
26 |
+
|
27 |
+
/**
|
28 |
+
* Constructor
|
29 |
+
*/
|
30 |
+
public function __construct() {
|
31 |
+
|
32 |
+
if (WC()->version < '2.7.0') {
|
33 |
+
$this->log = new WC_Logger();
|
34 |
+
} else {
|
35 |
+
$this->log = wc_get_logger();
|
36 |
+
}
|
37 |
+
$this->import_page = 'woocommerce_wf_order_csv';
|
38 |
+
$this->file_url_import_enabled = apply_filters('woocommerce_csv_product_file_url_import_enabled', true);
|
39 |
+
}
|
40 |
|
41 |
+
/**
|
42 |
+
* Registered callback function for the WordPress Importer
|
43 |
+
*
|
44 |
+
* Manages the three separate stages of the CSV import process
|
45 |
+
*/
|
46 |
+
public function dispatch() {
|
47 |
+
global $woocommerce, $wpdb;
|
48 |
+
|
49 |
+
if (!empty($_POST['delimiter'])) {
|
50 |
+
$this->delimiter = stripslashes(trim($_POST['delimiter']));
|
51 |
+
} else if (!empty($_GET['delimiter'])) {
|
52 |
+
$this->delimiter = stripslashes(trim($_GET['delimiter']));
|
53 |
+
}
|
54 |
|
55 |
+
if (!$this->delimiter)
|
56 |
+
$this->delimiter = ',';
|
|
|
|
|
|
|
|
|
|
|
57 |
|
58 |
+
if (!empty($_POST['merge_empty_cells']) || !empty($_GET['merge_empty_cells'])) {
|
59 |
+
$this->merge_empty_cells = 1;
|
60 |
+
} else {
|
61 |
+
$this->merge_empty_cells = 0;
|
62 |
+
}
|
63 |
|
64 |
+
$step = empty($_GET['step']) ? 0 : (int) $_GET['step'];
|
65 |
+
|
66 |
+
switch ($step) {
|
67 |
+
case 0 :
|
68 |
+
$this->header();
|
69 |
+
$this->greet();
|
70 |
+
break;
|
71 |
+
case 1 :
|
72 |
+
$this->header();
|
73 |
+
|
74 |
+
check_admin_referer('import-upload');
|
75 |
+
|
76 |
+
if (!empty($_GET['file_url']))
|
77 |
+
$this->file_url = esc_attr($_GET['file_url']);
|
78 |
+
if (!empty($_GET['file_id']))
|
79 |
+
$this->id = $_GET['file_id'];
|
80 |
+
|
81 |
+
if (!empty($_GET['clearmapping']) || $this->handle_upload())
|
82 |
+
$this->import_options();
|
83 |
+
else
|
84 |
+
_e('Error with handle_upload!', 'wf_order_import_export');
|
85 |
+
break;
|
86 |
+
case 2 :
|
87 |
+
$this->header();
|
88 |
+
|
89 |
+
check_admin_referer('import-woocommerce');
|
90 |
+
|
91 |
+
$this->id = (int) $_POST['import_id'];
|
92 |
+
|
93 |
+
if ($this->file_url_import_enabled)
|
94 |
+
$this->file_url = esc_attr($_POST['import_url']);
|
95 |
+
|
96 |
+
if ($this->id)
|
97 |
+
$file = get_attached_file($this->id);
|
98 |
+
else if ($this->file_url_import_enabled)
|
99 |
+
$file = ABSPATH . $this->file_url;
|
100 |
+
|
101 |
+
$file = str_replace("\\", "/", $file);
|
102 |
+
|
103 |
+
if ($file) {
|
104 |
+
?>
|
105 |
+
<table id="import-progress" class="widefat_importer widefat">
|
106 |
+
<thead>
|
107 |
+
<tr> <th class="status"> </th>
|
108 |
+
<th class="row"><?php _e('Row', 'wf_order_import_export'); ?></th>
|
109 |
+
<th><?php _e('OrderID', 'wf_order_import_export'); ?></th>
|
110 |
+
<th><?php _e('Order Status', 'wf_order_import_export'); ?></th>
|
111 |
+
<th class="reason"><?php _e('Status Msg', 'wf_order_import_export'); ?></th>
|
112 |
+
</tr>
|
113 |
+
</thead>
|
114 |
+
<tfoot>
|
115 |
+
<tr class="importer-loading">
|
116 |
+
<td colspan="5"></td>
|
117 |
+
</tr>
|
118 |
+
</tfoot>
|
119 |
+
<tbody></tbody>
|
120 |
+
</table>
|
121 |
+
<script type="text/javascript">
|
122 |
+
jQuery(document).ready(function($) {
|
123 |
+
|
124 |
+
if (! window.console) { window.console = function(){}; }
|
125 |
+
|
126 |
+
var processed_terms = [];
|
127 |
+
var processed_posts = [];
|
128 |
+
var i = 1;
|
129 |
+
var done_count = 0;
|
130 |
+
function import_rows(start_pos, end_pos) {
|
131 |
+
|
132 |
+
var data = {
|
133 |
+
action: 'woocommerce_csv_order_import_request',
|
134 |
+
file: '<?php echo addslashes($file); ?>',
|
135 |
+
delimiter: '<?php echo $this->delimiter; ?>',
|
136 |
+
merge_empty_cells: '<?php echo $this->merge_empty_cells; ?>',
|
137 |
+
start_pos: start_pos,
|
138 |
+
end_pos: end_pos,
|
139 |
+
};
|
140 |
+
return $.ajax({
|
141 |
+
url: '<?php echo add_query_arg(array('import_page' => $this->import_page, 'step' => '3', 'merge' => !empty($_GET['merge']) ? '1' : '0'), admin_url('admin-ajax.php')); ?>',
|
142 |
+
data: data,
|
143 |
+
type: 'POST',
|
144 |
+
success: function(response) {
|
145 |
+
if (response) {
|
146 |
+
try {
|
147 |
+
// Get the valid JSON only from the returned string
|
148 |
+
if (response.indexOf("<!--WC_START-->") >= 0)
|
149 |
+
response = response.split("<!--WC_START-->")[1]; // Strip off before after WC_START
|
150 |
+
|
151 |
+
if (response.indexOf("<!--WC_END-->") >= 0)
|
152 |
+
response = response.split("<!--WC_END-->")[0]; // Strip off anything after WC_END
|
153 |
+
|
154 |
+
// Parse
|
155 |
+
var results = $.parseJSON(response);
|
156 |
+
if (results.error) {
|
157 |
+
|
158 |
+
$('#import-progress tbody').append('<tr id="row-' + i + '" class="error"><td class="status" colspan="5">' + results.error + '</td></tr>');
|
159 |
+
i++;
|
160 |
+
} else if (results.import_results && $(results.import_results).size() > 0) {
|
161 |
+
|
162 |
+
$.each(results.processed_terms, function(index, value) {
|
163 |
+
processed_terms.push(value);
|
164 |
+
});
|
165 |
+
$.each(results.processed_posts, function(index, value) {
|
166 |
+
processed_posts.push(value);
|
167 |
+
});
|
168 |
+
$(results.import_results).each(function(index, row) {
|
169 |
+
$('#import-progress tbody').append('<tr id="row-' + i + '" class="' + row['status'] + '"><td><mark class="result" title="' + row['status'] + '">' + row['status'] + '</mark></td><td class="row">' + i + '</td><td>' + row['order_number'] + '</td><td>' + row['post_id'] + ' - ' + row['post_title'] + '</td><td class="reason">' + row['reason'] + '</td></tr>');
|
170 |
+
i++;
|
171 |
+
});
|
172 |
+
}
|
173 |
+
|
174 |
+
} catch (err) {}
|
175 |
+
|
176 |
+
} else {
|
177 |
+
$('#import-progress tbody').append('<tr class="error"><td class="status" colspan="5">' + '<?php _e('AJAX Error', 'wf_order_import_export'); ?>' + '</td></tr>');
|
178 |
+
}
|
179 |
+
|
180 |
+
var w = $(window);
|
181 |
+
var row = $("#row-" + (i - 1));
|
182 |
+
if (row.length) {
|
183 |
+
w.scrollTop(row.offset().top - (w.height() / 2));
|
184 |
+
}
|
185 |
+
|
186 |
+
done_count++;
|
187 |
+
$('body').trigger('woocommerce_csv_order_import_request_complete');
|
188 |
+
}
|
189 |
+
});
|
190 |
+
}
|
191 |
+
|
192 |
+
var rows = [];
|
193 |
+
|
194 |
+
<?php
|
195 |
+
$limit = apply_filters('woocommerce_csv_import_limit_per_request', 10);
|
196 |
+
$enc = mb_detect_encoding($file, 'UTF-8, ISO-8859-1', true);
|
197 |
+
if ($enc)
|
198 |
+
setlocale(LC_ALL, 'en_US.' . $enc);
|
199 |
+
@ini_set('auto_detect_line_endings', true);
|
200 |
+
|
201 |
+
$count = 0;
|
202 |
+
$previous_position = 0;
|
203 |
+
$position = 0;
|
204 |
+
$import_count = 0;
|
205 |
+
|
206 |
+
// Get CSV positions
|
207 |
+
if (( $handle = fopen($file, "r") ) !== FALSE) {
|
208 |
+
|
209 |
+
while (( $postmeta = fgetcsv($handle, 0, $this->delimiter, '"', '"') ) !== FALSE) {
|
210 |
+
$count++;
|
211 |
+
|
212 |
+
if ($count >= $limit) {
|
213 |
+
$previous_position = $position;
|
214 |
+
$position = ftell($handle);
|
215 |
+
$count = 0;
|
216 |
+
$import_count ++;
|
217 |
+
|
218 |
+
// Import rows between $previous_position $position
|
219 |
+
?>rows.push( [ <?php echo $previous_position; ?>, <?php echo $position; ?> ] ); <?php
|
220 |
+
}
|
221 |
+
}
|
222 |
+
|
223 |
+
// Remainder
|
224 |
+
if ($count > 0) {
|
225 |
+
?>rows.push( [ <?php echo $position; ?>, '' ] ); <?php
|
226 |
+
$import_count ++;
|
227 |
+
}
|
228 |
+
|
229 |
+
fclose($handle);
|
230 |
+
}
|
231 |
+
?>
|
232 |
+
|
233 |
+
var data = rows.shift();
|
234 |
+
var regen_count = 0;
|
235 |
+
import_rows( data[0], data[1] );
|
236 |
+
|
237 |
+
$('body').on( 'woocommerce_csv_order_import_request_complete', function() {
|
238 |
+
if ( done_count == <?php echo $import_count; ?> ) {
|
239 |
+
|
240 |
+
import_done();
|
241 |
+
} else {
|
242 |
+
// Call next request
|
243 |
+
data = rows.shift();
|
244 |
+
import_rows( data[0], data[1] );
|
245 |
+
}
|
246 |
+
} );
|
247 |
+
|
248 |
+
function import_done() {
|
249 |
+
var data = {
|
250 |
+
action: 'woocommerce_csv_order_import_request',
|
251 |
+
file: '<?php echo $file; ?>',
|
252 |
+
processed_terms: processed_terms,
|
253 |
+
processed_posts: processed_posts,
|
254 |
+
};
|
255 |
+
|
256 |
+
$.ajax({
|
257 |
+
url: '<?php echo add_query_arg(array('import_page' => $this->import_page, 'step' => '4', 'merge' => !empty($_GET['merge']) ? 1 : 0), admin_url('admin-ajax.php')); ?>',
|
258 |
+
data: data,
|
259 |
+
type: 'POST',
|
260 |
+
success: function( response ) {
|
261 |
+
//console.log( response );
|
262 |
+
$('#import-progress tbody').append( '<tr class="complete"><td colspan="5">' + response + '</td></tr>' );
|
263 |
+
$('.importer-loading').hide();
|
264 |
+
}
|
265 |
+
});
|
266 |
+
}
|
267 |
+
});
|
268 |
+
</script>
|
269 |
+
<?php
|
270 |
} else {
|
271 |
+
echo '<p class="error">' . __('Error finding uploaded file!', 'wf_order_import_export') . '</p>';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
272 |
}
|
273 |
+
break;
|
274 |
+
case 3 :
|
275 |
+
// Check access - cannot use nonce here as it will expire after multiple requests
|
276 |
+
if (!current_user_can('manage_woocommerce'))
|
277 |
+
die();
|
278 |
+
|
279 |
+
add_filter('http_request_timeout', array($this, 'bump_request_timeout'));
|
280 |
+
|
281 |
+
if (function_exists('gc_enable'))
|
282 |
+
gc_enable();
|
283 |
+
|
284 |
+
@set_time_limit(0);
|
285 |
+
@ob_flush();
|
286 |
+
@flush();
|
287 |
+
$wpdb->hide_errors();
|
288 |
+
|
289 |
+
$file = stripslashes($_POST['file']);
|
290 |
+
|
291 |
+
$start_pos = isset($_POST['start_pos']) ? absint($_POST['start_pos']) : 0;
|
292 |
+
$end_pos = isset($_POST['end_pos']) ? absint($_POST['end_pos']) : '';
|
293 |
+
|
294 |
+
|
295 |
+
|
296 |
+
$position = $this->import_start($file, $start_pos, $end_pos);
|
297 |
+
$this->import();
|
298 |
+
$this->import_end();
|
299 |
+
|
300 |
+
$results = array();
|
301 |
+
$results['import_results'] = $this->import_results;
|
302 |
+
$results['processed_terms'] = $this->processed_terms;
|
303 |
+
$results['processed_posts'] = $this->processed_posts;
|
304 |
|
305 |
+
echo "<!--WC_START-->";
|
306 |
+
echo json_encode($results);
|
307 |
+
echo "<!--WC_END-->";
|
308 |
+
exit;
|
309 |
+
break;
|
310 |
+
case 4 :
|
311 |
+
// Check access - cannot use nonce here as it will expire after multiple requests
|
312 |
+
if (!current_user_can('manage_woocommerce'))
|
313 |
+
die();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
314 |
|
315 |
+
add_filter('http_request_timeout', array($this, 'bump_request_timeout'));
|
|
|
|
|
|
|
|
|
|
|
316 |
|
317 |
+
if (function_exists('gc_enable'))
|
318 |
+
gc_enable();
|
319 |
|
320 |
+
@set_time_limit(0);
|
321 |
+
@ob_flush();
|
322 |
+
@flush();
|
323 |
+
$wpdb->hide_errors();
|
324 |
|
325 |
+
$this->processed_terms = isset($_POST['processed_terms']) ? $_POST['processed_terms'] : array();
|
326 |
+
$this->processed_posts = isset($_POST['processed_posts']) ? $_POST['processed_posts'] : array();
|
327 |
|
328 |
+
_e('Step 1...', 'wf_order_import_export') . ' ';
|
329 |
|
330 |
+
wp_defer_term_counting(true);
|
331 |
+
wp_defer_comment_counting(true);
|
332 |
|
333 |
+
_e('Step 2...', 'wf_order_import_export') . ' ';
|
334 |
|
335 |
+
echo 'Step 3...' . ' '; // Easter egg
|
|
|
336 |
|
337 |
+
_e('Finalizing...', 'wf_order_import_export') . ' ';
|
|
|
338 |
|
339 |
+
// SUCCESS
|
340 |
+
_e('Finished. Import complete.', 'wf_order_import_export');
|
|
|
|
|
341 |
|
342 |
+
$this->import_end();
|
343 |
+
exit;
|
344 |
+
break;
|
345 |
+
}
|
|
|
346 |
|
347 |
+
$this->footer();
|
348 |
+
}
|
349 |
|
350 |
+
/**
|
351 |
+
* format_data_from_csv
|
352 |
+
*/
|
353 |
+
public function format_data_from_csv($data, $enc) {
|
354 |
+
return ( $enc == 'UTF-8' ) ? $data : utf8_encode($data);
|
355 |
+
}
|
356 |
|
357 |
+
/**
|
358 |
+
* Display pre-import options
|
359 |
+
*/
|
360 |
+
public function import_options() {
|
361 |
+
$j = 0;
|
362 |
+
|
363 |
+
if ($this->id)
|
364 |
+
$file = get_attached_file($this->id);
|
365 |
+
else if ($this->file_url_import_enabled)
|
366 |
+
$file = ABSPATH . $this->file_url;
|
367 |
+
else
|
368 |
+
return;
|
369 |
|
370 |
+
// Set locale
|
371 |
+
$enc = mb_detect_encoding($file, 'UTF-8, ISO-8859-1', true);
|
372 |
+
if ($enc)
|
373 |
+
setlocale(LC_ALL, 'en_US.' . $enc);
|
374 |
+
@ini_set('auto_detect_line_endings', true);
|
375 |
+
|
376 |
+
// Get headers
|
377 |
+
if (( $handle = fopen($file, "r") ) !== FALSE) {
|
378 |
+
|
379 |
+
$row = $raw_headers = array();
|
380 |
+
$header = fgetcsv($handle, 0, $this->delimiter, '"', '"');
|
381 |
+
|
382 |
+
while (( $postmeta = fgetcsv($handle, 0, $this->delimiter, '"', '"') ) !== FALSE) {
|
383 |
+
foreach ($header as $key => $heading) {
|
384 |
+
if (!$heading)
|
385 |
+
continue;
|
386 |
+
$s_heading = $heading;
|
387 |
+
$row[$s_heading] = ( isset($postmeta[$key]) ) ? $this->format_data_from_csv($postmeta[$key], $enc) : '';
|
388 |
+
$raw_headers[$s_heading] = $heading;
|
389 |
+
}
|
390 |
+
break;
|
391 |
+
}
|
392 |
+
fclose($handle);
|
393 |
+
}
|
394 |
|
395 |
+
$merge = (!empty($_GET['merge']) && $_GET['merge']) ? 1 : 0;
|
|
|
|
|
|
|
|
|
396 |
|
397 |
+
include( 'views/html-wf-import-options.php' );
|
398 |
+
}
|
399 |
|
400 |
+
/**
|
401 |
+
* The main controller for the actual import stage.
|
402 |
+
*/
|
403 |
+
public function import() {
|
404 |
+
global $woocommerce, $wpdb;
|
405 |
+
|
406 |
+
wp_suspend_cache_invalidation(true);
|
407 |
+
$this->hf_order_log_data_change('order-csv-import', '---');
|
408 |
+
$this->hf_order_log_data_change('order-csv-import', __('Processing orders.', 'wf_order_import_export'));
|
409 |
+
$merging = 1;
|
410 |
+
$record_offset = 0;
|
411 |
+
foreach ($this->parsed_data as $key => &$item) {
|
412 |
+
$order = $this->parser->parse_orders($item, $this->raw_headers, $merging, $record_offset);
|
413 |
+
if (!is_wp_error($order))
|
414 |
+
$this->process_orders($order['shop_order'][0]);
|
415 |
+
else
|
416 |
+
$this->add_import_result('failed', $order->get_error_message(), 'Not parsed', json_encode($item), '-');
|
417 |
+
|
418 |
+
unset($item, $order);
|
419 |
+
}
|
420 |
|
421 |
+
$this->hf_order_log_data_change('order-csv-import', __('Finished processing Orders.', 'wf_order_import_export'));
|
422 |
+
wp_suspend_cache_invalidation(false);
|
423 |
+
}
|
424 |
|
425 |
+
/**
|
426 |
+
* Parses the CSV file and prepares us for the task of processing parsed data
|
427 |
+
*
|
428 |
+
* @param string $file Path to the CSV file for importing
|
429 |
+
*/
|
430 |
+
public function import_start($file, $start_pos, $end_pos) {
|
431 |
|
432 |
+
$memory = size_format((WC()->version < '2.7.0') ? woocommerce_let_to_num(ini_get('memory_limit')) : wc_let_to_num(ini_get('memory_limit')));
|
433 |
+
$wp_memory = size_format((WC()->version < '2.7.0') ? woocommerce_let_to_num(WP_MEMORY_LIMIT) : wc_let_to_num(WP_MEMORY_LIMIT));
|
434 |
|
435 |
+
$this->hf_order_log_data_change('order-csv-import', '---[ New Import ] PHP Memory: ' . $memory . ', WP Memory: ' . $wp_memory);
|
436 |
+
$this->hf_order_log_data_change('order-csv-import', __('Parsing products CSV.', 'wf_order_import_export'));
|
437 |
|
438 |
+
$this->parser = new WF_CSV_Parser('shop_order');
|
439 |
|
440 |
+
list( $this->parsed_data, $this->raw_headers, $position ) = $this->parser->parse_data($file, $this->delimiter, $start_pos, $end_pos);
|
441 |
|
442 |
+
$this->hf_order_log_data_change('order-csv-import', __('Finished parsing products CSV.', 'wf_order_import_export'));
|
|
|
443 |
|
444 |
+
unset($import_data);
|
445 |
+
|
446 |
+
wp_defer_term_counting(true);
|
447 |
+
wp_defer_comment_counting(true);
|
448 |
+
|
449 |
+
return $position;
|
450 |
+
}
|
451 |
+
|
452 |
+
/**
|
453 |
+
* Performs post-import cleanup of files and the cache
|
454 |
+
*/
|
455 |
+
public function import_end() {
|
456 |
+
|
457 |
+
//wp_cache_flush(); Stops output in some hosting environments
|
458 |
+
foreach (get_taxonomies() as $tax) {
|
459 |
+
delete_option("{$tax}_children");
|
460 |
+
_get_term_hierarchy($tax);
|
461 |
+
}
|
462 |
+
|
463 |
+
wp_defer_term_counting(false);
|
464 |
+
wp_defer_comment_counting(false);
|
465 |
+
|
466 |
+
do_action('import_end');
|
467 |
+
}
|
468 |
+
|
469 |
+
/**
|
470 |
+
* Handles the CSV upload and initial parsing of the file to prepare for
|
471 |
+
* displaying author import options
|
472 |
+
*
|
473 |
+
* @return bool False if error uploading or invalid file, true otherwise
|
474 |
+
*/
|
475 |
+
public function handle_upload() {
|
476 |
+
if (empty($_POST['file_url'])) {
|
477 |
+
|
478 |
+
$file = wp_import_handle_upload();
|
479 |
+
|
480 |
+
if (isset($file['error'])) {
|
481 |
+
echo '<p><strong>' . __('Sorry, there has been an error.', 'wf_order_import_export') . '</strong><br />';
|
482 |
+
echo esc_html($file['error']) . '</p>';
|
483 |
+
return false;
|
484 |
+
}
|
485 |
+
|
486 |
+
$this->id = (int) $file['id'];
|
487 |
+
return true;
|
488 |
+
} else {
|
489 |
+
|
490 |
+
if (file_exists(ABSPATH . $_POST['file_url'])) {
|
491 |
+
|
492 |
+
$this->file_url = esc_attr($_POST['file_url']);
|
493 |
+
return true;
|
494 |
+
} else {
|
495 |
+
|
496 |
+
echo '<p><strong>' . __('Sorry, there has been an error.', 'wf_order_import_export') . '</strong></p>';
|
497 |
+
return false;
|
498 |
+
}
|
499 |
+
}
|
500 |
+
|
501 |
+
return false;
|
502 |
+
}
|
503 |
+
|
504 |
+
public function order_exists($orderID) {
|
505 |
global $wpdb;
|
506 |
$query = "SELECT ID FROM $wpdb->posts WHERE post_type = 'shop_order' AND post_status IN ( 'wc-pending', 'wc-processing', 'wc-completed', 'wc-on-hold', 'wc-failed' , 'wc-refunded', 'wc-cancelled')";
|
507 |
$args = array();
|
508 |
$posts_are_exist = @$wpdb->get_col($wpdb->prepare($query, $args));
|
509 |
+
|
510 |
if ($posts_are_exist) {
|
511 |
foreach ($posts_are_exist as $exist_id) {
|
512 |
$found = false;
|
513 |
if ($exist_id == $orderID) {
|
514 |
$found = TRUE;
|
515 |
+
}
|
516 |
+
if ($found)
|
517 |
+
return TRUE;
|
518 |
}
|
519 |
} else {
|
520 |
return FALSE;
|
521 |
}
|
522 |
}
|
523 |
+
|
524 |
+
/**
|
525 |
+
* Create new posts based on import information
|
526 |
+
*/
|
527 |
+
private function process_orders($post) {
|
528 |
+
global $wpdb;
|
529 |
+
$this->imported = $this->merged = 0;
|
530 |
+
$merging = (!empty($_GET['merge'])) ? 1 : 0;
|
531 |
+
|
532 |
+
// plan a dry run
|
533 |
+
//$dry_run = isset( $_POST['dry_run'] ) && $_POST['dry_run'] ? true : false;
|
534 |
+
$dry_run = FALSE;
|
535 |
+
|
536 |
+
$this->hf_order_log_data_change('order-csv-import', '---');
|
537 |
+
$this->hf_order_log_data_change('order-csv-import', __('Processing orders.', 'wf_order_import_export'));
|
538 |
+
|
539 |
+
// check class-wc-checkout.php for reference
|
540 |
+
|
541 |
+
$order_data = array(
|
542 |
+
'import_id' => $post['order_number'], //Suggest import to keep the given ID
|
543 |
+
'post_date' => date('Y-m-d H:i:s', $post['date']),
|
544 |
+
'post_type' => 'shop_order',
|
545 |
+
'post_title' => 'Order – ' . date('F j, Y @ h:i A', $post['date']),
|
546 |
+
'post_status' => 'wc-' . preg_replace('/^wc-/', '', $post['status']),
|
547 |
+
'ping_status' => 'closed',
|
548 |
+
'post_excerpt' => isset($post['order_comments']) ? ($post['order_comments']) : '',
|
549 |
+
'post_author' => 1,
|
550 |
+
'post_password' => uniqid('order_'), // Protects the post just in case
|
551 |
+
);
|
552 |
+
|
553 |
+
|
554 |
+
if (!$dry_run) {
|
555 |
+
// track whether download permissions need to be granted
|
556 |
+
$add_download_permissions = false;
|
557 |
+
|
558 |
+
|
559 |
// Check if post exists when importing
|
560 |
$new_added = false;
|
561 |
$is_order_exist = $this->order_exists($post['order_number']);
|
562 |
$meta_array = array();
|
563 |
+
if (!empty($post['postmeta'])) {
|
564 |
+
foreach ($post['postmeta'] as $meta) {
|
565 |
+
$meta_array[$meta['key']] = $meta['value'];
|
566 |
+
}
|
567 |
}
|
568 |
+
|
|
|
569 |
$user_id = $this->hf_check_customer($meta_array);
|
570 |
+
if (is_wp_error($user_id)) {
|
571 |
+
$this->hf_order_log_data_change('order-csv-import', __($user_id->get_error_message(), 'wf_order_import_export'));
|
572 |
+
$this->add_import_result('skipped', __($user_id->get_error_message(), 'wf_order_import_export'), $post['order_number'], $post['order_number'], $post['order_number']);
|
573 |
+
$skipped++;
|
574 |
+
unset($post);
|
575 |
+
return;
|
576 |
+
} elseif (empty($user_id)) {
|
577 |
+
$user_id = 0;
|
578 |
+
}
|
579 |
+
|
580 |
|
581 |
if (!$merging && $is_order_exist) {
|
582 |
+
$usr_msg = 'Order already exists.';
|
583 |
+
$this->add_import_result('skipped', __($usr_msg, 'wf_order_import_export'), $post['order_number'], $order_data['post_title'], $post['order_number']);
|
584 |
+
$this->hf_order_log_data_change('order-csv-import', sprintf(__('> “%s”' . $usr_msg, 'wf_order_import_export'), esc_html($order_data['post_title'])), true);
|
585 |
+
unset($post);
|
586 |
+
return;
|
587 |
+
} else {
|
588 |
+
if ($is_order_exist) {
|
|
|
589 |
$order_id = $post['order_number'];
|
590 |
+
$order_data['ID'] = $order_id;
|
591 |
$wp_result = wp_update_post($order_data);
|
592 |
} else {
|
593 |
$order_id = wp_insert_post($order_data);
|
594 |
$new_added = true;
|
595 |
+
if (is_wp_error($order_id)) {
|
596 |
+
$this->errored++;
|
597 |
+
$new_added = false;
|
598 |
+
//$this->add_import_result('failed', __($order_id->get_error_message() , 'wf_order_import_export'), $post['order_number'], $order_data['post_title'], $post['order_number']);
|
599 |
+
$this->hf_order_log_data_change('order-csv-import', sprintf(__('> Error inserting %s: %s', 'wf_order_import_export'), $post['order_number'], $order_id->get_error_message()), true);
|
600 |
}
|
601 |
+
}
|
602 |
+
}
|
603 |
+
// empty update to bump up the post_modified date to today's date (otherwise it would match the post_date, which isn't quite right)
|
604 |
+
//wp_update_post( array( 'ID' => $order_id ) );
|
605 |
+
// handle special meta fields
|
606 |
+
$order_currency = (isset($post['order_currency']) && $post['order_currency']) ? $post['order_currency'] : get_woocommerce_currency();
|
607 |
+
update_post_meta($order_id, '_order_key', apply_filters('woocommerce_generate_order_key', uniqid('order_')));
|
608 |
+
update_post_meta($order_id, '_order_currency', $order_currency);
|
609 |
+
update_post_meta($order_id, '_prices_include_tax', get_option('woocommerce_prices_include_tax'));
|
610 |
+
update_post_meta($order_id, '_order_number', $post['order_number']);
|
611 |
+
// add order postmeta
|
612 |
+
foreach ($post['postmeta'] as $meta) {
|
613 |
+
$meta_processed = false;
|
614 |
+
|
615 |
+
// we don't set the "download permissions granted" meta, we call the woocommerce function to take care of this for us
|
616 |
+
if (( 'Download Permissions Granted' == $meta['key'] || '_download_permissions_granted' == $meta['key'] ) && $meta['value']) {
|
617 |
+
$add_download_permissions = true;
|
618 |
+
$meta_processed = true;
|
619 |
}
|
620 |
|
621 |
+
if (( '_customer_user' == $meta['key'])) {
|
622 |
+
update_post_meta($order_id, $meta['key'], $user_id);
|
623 |
+
$meta_processed = true;
|
624 |
+
}
|
625 |
+
|
626 |
+
if (!$meta_processed) {
|
627 |
+
update_post_meta($order_id, $meta['key'], $meta['value']);
|
628 |
+
}
|
629 |
+
|
630 |
+
// set the paying customer flag on the user meta if applicable
|
631 |
+
if ('_customer_id' == $meta['key'] && $user_id && in_array($post['status'], array('processing', 'completed', 'refunded'))) {
|
632 |
+
update_user_meta($user_id, "paying_customer", 1);
|
633 |
+
}
|
634 |
+
}
|
635 |
+
|
636 |
+
if($merging && $is_order_exist){
|
637 |
+
$coup_str = 'coupon';
|
638 |
+
$wpdb->query( $wpdb->prepare( "DELETE FROM itemmeta USING {$wpdb->prefix}woocommerce_order_itemmeta itemmeta INNER JOIN {$wpdb->prefix}woocommerce_order_items items WHERE itemmeta.order_item_id = items.order_item_id and items.order_id = %d and items.order_item_type != %s", $order_id ,$coup_str) );
|
639 |
+
$wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->prefix}woocommerce_order_items WHERE order_id = %d and order_item_type != %s", $order_id ,$coup_str) );
|
640 |
+
}
|
641 |
+
|
642 |
+
// handle order items
|
643 |
+
$order_items = array();
|
644 |
+
$order_item_meta = null;
|
645 |
+
|
646 |
+
foreach ($post['order_items'] as $item) {
|
647 |
+
|
648 |
+
$product = null;
|
649 |
+
$variation_item_meta = array();
|
650 |
+
|
651 |
+
if ($item['product_id']) {
|
652 |
+
$product = wc_get_product($item['product_id']);
|
653 |
+
|
654 |
+
// handle variations
|
655 |
+
if ($product && ( $product->is_type('variable') || $product->is_type('variation') || $product->is_type('subscription_variation') ) && method_exists($product, 'get_variation_id')) {
|
656 |
+
foreach ($product->get_variation_attributes() as $key => $value) {
|
657 |
+
$variation_item_meta[] = array('meta_name' => esc_attr(substr($key, 10)), 'meta_value' => $value); // remove the leading 'attribute_' from the name to get 'pa_color' for instance
|
658 |
+
}
|
659 |
+
}
|
660 |
+
}
|
661 |
+
|
662 |
+
// order item
|
663 |
+
$order_items[] = array(
|
664 |
+
'order_item_name' => $product ? $product->get_title() : (!empty($item['unknown_product_name']) ? $item['unknown_product_name'] : __('Unknown Product', 'wf_order_import_export')),
|
665 |
+
'order_item_type' => 'line_item',
|
666 |
+
);
|
667 |
+
|
668 |
+
$var_id = 0;
|
669 |
+
if ($product) {
|
670 |
+
if (WC()->version < '2.7.0' && method_exists($product, 'get_variation_id')) {
|
671 |
+
$var_id = $product->get_variation_id();
|
672 |
+
} else {
|
673 |
+
$var_id = $product->get_id();
|
674 |
+
}
|
675 |
+
}
|
676 |
+
// standard order item meta
|
677 |
+
$_order_item_meta = array(
|
678 |
+
'_qty' => (int) $item['qty'],
|
679 |
+
'_tax_class' => '', // Tax class (adjusted by filters)
|
680 |
+
'_product_id' => $item['product_id'],
|
681 |
+
'_variation_id' => $var_id,
|
682 |
+
'_line_subtotal' => number_format((float) $item['total'], 2, '.', ''), // Line subtotal (before discounts)
|
683 |
+
'_line_subtotal_tax' => 0, // Line tax (before discounts)
|
684 |
+
'_line_total' => number_format((float) $item['total'], 2, '.', ''), // Line total (after discounts)
|
685 |
+
'_line_tax' => 0, // Line Tax (after discounts)
|
686 |
+
);
|
687 |
+
|
688 |
+
// add any product variation meta
|
689 |
+
foreach ($variation_item_meta as $meta) {
|
690 |
+
$_order_item_meta[$meta['meta_name']] = $meta['meta_value'];
|
691 |
+
}
|
692 |
+
|
693 |
+
// include any arbitrary order item meta
|
694 |
+
$_order_item_meta = array_merge($_order_item_meta, $item['meta']);
|
695 |
+
|
696 |
+
$order_item_meta[] = $_order_item_meta;
|
697 |
+
}
|
698 |
+
|
699 |
+
foreach ($order_items as $key => $order_item) {
|
700 |
+
$order_item_id = wc_add_order_item($order_id, $order_item);
|
701 |
+
|
702 |
+
if ($order_item_id) {
|
703 |
+
foreach ($order_item_meta[$key] as $meta_key => $meta_value) {
|
704 |
+
wc_add_order_item_meta($order_item_id, $meta_key, $meta_value);
|
705 |
+
}
|
706 |
+
}
|
707 |
+
}
|
708 |
+
|
709 |
+
// create the shipping order items
|
710 |
+
foreach ($post['order_shipping'] as $order_shipping) {
|
711 |
+
|
712 |
+
$shipping_order_item = array(
|
713 |
+
'order_item_name' => ($order_shipping['title']) ? $order_shipping['title'] : $order_shipping['method_id'],
|
714 |
+
'order_item_type' => 'shipping',
|
715 |
+
);
|
716 |
+
|
717 |
+
$shipping_order_item_id = wc_add_order_item($order_id, $shipping_order_item);
|
718 |
+
|
719 |
+
if ($shipping_order_item_id) {
|
720 |
+
wc_add_order_item_meta($shipping_order_item_id, 'method_id', $order_shipping['method_id']);
|
721 |
+
wc_add_order_item_meta($shipping_order_item_id, 'cost', $order_shipping['cost']);
|
722 |
+
}
|
723 |
+
}
|
724 |
+
|
725 |
+
// create the tax order items
|
726 |
+
foreach ($post['tax_items'] as $tax_item) {
|
727 |
+
|
728 |
+
$tax_order_item = array(
|
729 |
+
'order_item_name' => $tax_item['title'],
|
730 |
+
'order_item_type' => 'tax',
|
731 |
+
);
|
732 |
+
|
733 |
+
$tax_order_item_id = wc_add_order_item($order_id, $tax_order_item);
|
734 |
+
|
735 |
+
if ($tax_order_item_id) {
|
736 |
+
wc_add_order_item_meta($tax_order_item_id, 'rate_id', $tax_item['rate_id']);
|
737 |
+
wc_add_order_item_meta($tax_order_item_id, 'label', $tax_item['label']);
|
738 |
+
wc_add_order_item_meta($tax_order_item_id, 'compound', $tax_item['compound']);
|
739 |
+
wc_add_order_item_meta($tax_order_item_id, 'tax_amount', $tax_item['tax_amount']);
|
740 |
+
wc_add_order_item_meta($tax_order_item_id, 'shipping_tax_amount', $tax_item['shipping_tax_amount']);
|
741 |
+
}
|
742 |
+
}
|
743 |
+
|
744 |
+
// Grant downloadalbe product permissions
|
745 |
+
if ($add_download_permissions) {
|
746 |
+
wc_downloadable_product_permissions($order_id);
|
747 |
+
}
|
748 |
+
|
749 |
+
// add order notes
|
750 |
+
$order = wc_get_order($order_id);
|
751 |
+
foreach ($post['notes'] as $order_note) {
|
752 |
+
$order->add_order_note($order_note);
|
753 |
}
|
754 |
+
|
755 |
+
// record the product sales
|
756 |
+
if (WC()->version < '2.7.0') {
|
757 |
+
$order->record_product_sales();
|
758 |
+
} else {
|
759 |
+
wc_update_total_sales_counts($order_id);
|
760 |
+
}
|
761 |
+
} // ! dry run
|
762 |
+
// was an original order number provided?
|
763 |
+
if (!empty($post['order_number_formatted'])) {
|
764 |
+
if (!$dry_run) {
|
765 |
+
// do our best to provide some custom order number functionality while also allowing 3rd party plugins to provide their own custom order number facilities
|
766 |
+
do_action('woocommerce_set_order_number', $order, $post['order_number'], $post['order_number_formatted']);
|
767 |
+
$order->add_order_note(sprintf(__("Original order #%s", 'wf_order_import_export'), $post['order_number_formatted']));
|
768 |
+
|
769 |
+
// get the order so we can display the correct order number
|
770 |
+
$order = wc_get_order($order_id);
|
771 |
+
}
|
772 |
+
|
773 |
+
$this->processed_posts[$post['order_number_formatted']] = $post['order_number_formatted'];
|
774 |
+
}
|
775 |
+
if ($merging && !$new_added)
|
776 |
+
$out_msg = 'Order Successfully updated.';
|
777 |
+
else
|
778 |
+
$out_msg = 'Order Imported Successfully.';
|
779 |
+
|
780 |
+
$this->add_import_result('imported', __($out_msg, 'wf_order_import_export'), $order_id, $order_data['post_title'], $order_id);
|
781 |
+
$this->hf_order_log_data_change('order-csv-import', sprintf(__('> “%s”' . $out_msg, 'wf_order_import_export'), esc_html($order_data['post_title'])), true);
|
782 |
+
$this->imported++;
|
783 |
+
$this->hf_order_log_data_change('order-csv-import', sprintf(__('> Finished importing order %s', 'wf_order_import_export'), $dry_run ? "" : $order->get_order_number() ));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
784 |
|
785 |
// }
|
786 |
|
|
|
|
|
787 |
|
788 |
+
$this->hf_order_log_data_change('order-csv-import', __('Finished processing orders.', 'wf_order_import_export'));
|
789 |
+
|
790 |
+
unset($post);
|
791 |
+
}
|
792 |
+
|
793 |
+
public function hf_check_customer($data) {
|
794 |
|
795 |
$customer_email = (!empty($data['_customer_email']) ) ? $data['_customer_email'] : '';
|
796 |
|
802 |
if (is_email($customer_email) && false !== email_exists($customer_email)) {
|
803 |
$found_customer = email_exists($customer_email);
|
804 |
return $found_customer;
|
805 |
+
} else {
|
806 |
$found_customer = 0;
|
807 |
}
|
808 |
} else {
|
811 |
|
812 |
return $found_customer;
|
813 |
}
|
814 |
+
|
815 |
+
/**
|
816 |
+
* Log a row's import status
|
817 |
+
*/
|
818 |
+
protected function add_import_result($status, $reason, $post_id = '', $post_title = '', $order_number = '') {
|
819 |
+
$this->import_results[] = array(
|
820 |
+
'post_title' => $post_title,
|
821 |
+
'post_id' => $post_id,
|
822 |
+
'order_number' => $order_number,
|
823 |
+
'status' => $status,
|
824 |
+
'reason' => $reason
|
825 |
+
);
|
826 |
+
}
|
827 |
+
|
828 |
+
/**
|
829 |
+
* Decide what the maximum file size for downloaded attachments is.
|
830 |
+
* Default is 0 (unlimited), can be filtered via import_attachment_size_limit
|
831 |
+
*
|
832 |
+
* @return int Maximum attachment file size to import
|
833 |
+
*/
|
834 |
+
public function max_attachment_size() {
|
835 |
+
return apply_filters('import_attachment_size_limit', 0);
|
836 |
+
}
|
837 |
+
|
838 |
+
// Display import page title
|
839 |
+
public function header() {
|
840 |
+
echo '<div class="wrap"><div class="icon32" id="icon-woocommerce-importer"><br></div>';
|
841 |
+
echo '<h2>' . ( empty($_GET['merge']) ? __('Import', 'wf_order_import_export') : __('Merge Orders', 'wf_order_import_export') ) . '</h2>';
|
842 |
+
}
|
843 |
+
|
844 |
+
// Close div.wrap
|
845 |
+
public function footer() {
|
846 |
+
echo '</div>';
|
847 |
+
}
|
848 |
+
|
849 |
+
/**
|
850 |
+
* Display introductory text and file upload form
|
851 |
+
*/
|
852 |
+
public function greet() {
|
853 |
+
$action = 'admin.php?import=woocommerce_wf_order_csv&step=1&merge=' . (!empty($_GET['merge']) ? 1 : 0 );
|
854 |
+
$bytes = apply_filters('import_upload_size_limit', wp_max_upload_size());
|
855 |
+
$size = size_format($bytes);
|
856 |
+
$upload_dir = wp_upload_dir();
|
857 |
+
include( 'views/html-wf-import-greeting.php' );
|
858 |
+
}
|
859 |
+
|
860 |
+
/**
|
861 |
+
* Added to http_request_timeout filter to force timeout at 60 seconds during import
|
862 |
+
* @return int 60
|
863 |
+
*/
|
864 |
+
public function bump_request_timeout($val) {
|
865 |
+
return 60;
|
866 |
+
}
|
867 |
+
|
868 |
+
public function hf_order_log_data_change($content = 'order-csv-import', $data = '') {
|
869 |
+
if (WC()->version < '2.7.0') {
|
870 |
+
$this->log->add($content, $data);
|
871 |
+
} else {
|
872 |
+
$context = array('source' => $content);
|
873 |
+
$this->log->log("debug", $data, $context);
|
874 |
+
}
|
875 |
+
}
|
876 |
+
|
877 |
+
}
|
|
|
|
|
|
|
|
includes/importer/data-coupon/data-wf-post-defaults.php
CHANGED
File without changes
|
includes/importer/data-coupon/data-wf-postmeta-allowed.php
CHANGED
File without changes
|
includes/importer/data-coupon/data-wf-postmeta-defaults.php
CHANGED
File without changes
|
includes/importer/data-coupon/data-wf-reserved-fields-pair.php
CHANGED
File without changes
|
includes/importer/data-coupon/data-wf-reserved-fields.php
CHANGED
File without changes
|
includes/importer/data/data-wf-reserved-fields-pair.php
CHANGED
File without changes
|
includes/importer/views-coupon/html-wf-import-greeting.php
CHANGED
File without changes
|
includes/importer/views-coupon/html-wf-import-options.php
CHANGED
File without changes
|
includes/importer/views/html-wf-import-greeting.php
CHANGED
File without changes
|
includes/importer/views/html-wf-import-options.php
CHANGED
File without changes
|
includes/settings/class-wf-orderimpexpcsv-settings.php
CHANGED
File without changes
|
includes/views/export/html-wf-export-coupons.php
CHANGED
File without changes
|
includes/views/export/html-wf-export-orders.php
CHANGED
File without changes
|
includes/views/html-wf-admin-screen.php
CHANGED
File without changes
|
includes/views/html-wf-getting-started-subscription.php
CHANGED
File without changes
|
includes/views/import/html-wf-import-coupons.php
CHANGED
File without changes
|
includes/views/import/html-wf-import-orders.php
CHANGED
File without changes
|
includes/views/market.php
CHANGED
File without changes
|
languages/wf_order_import_export-de_DE.mo
CHANGED
File without changes
|
languages/wf_order_import_export-de_DE.po
CHANGED
File without changes
|
languages/wf_order_import_export-fr_FR.mo
CHANGED
File without changes
|
languages/wf_order_import_export-fr_FR.po
CHANGED
File without changes
|
license.txt
CHANGED
File without changes
|
order-import-export.php
CHANGED
@@ -6,9 +6,9 @@ Plugin URI: https://wordpress.org/plugins/order-import-export-for-woocommerce/
|
|
6 |
Description: Export and Import Order detail including line items, From and To your WooCommerce Store.
|
7 |
Author: WebToffee
|
8 |
Author URI: https://www.webtoffee.com/product/woocommerce-order-coupon-subscription-export-import/
|
9 |
-
Version: 1.3.
|
10 |
Text Domain: wf_order_import_export
|
11 |
-
WC tested up to: 3.
|
12 |
License: GPLv3
|
13 |
License URI: https://www.gnu.org/licenses/gpl-3.0.html
|
14 |
*/
|
@@ -24,7 +24,7 @@ define("WF_CPN_IMP_EXP_ID", "wf_cpn_imp_exp");
|
|
24 |
define("wf_coupon_csv_im_ex", "wf_coupon_csv_im_ex");
|
25 |
|
26 |
if (!defined('WF_ORDERIMPEXP_CURRENT_VERSION')) {
|
27 |
-
define("WF_ORDERIMPEXP_CURRENT_VERSION", "1.3.
|
28 |
}
|
29 |
|
30 |
/**
|
6 |
Description: Export and Import Order detail including line items, From and To your WooCommerce Store.
|
7 |
Author: WebToffee
|
8 |
Author URI: https://www.webtoffee.com/product/woocommerce-order-coupon-subscription-export-import/
|
9 |
+
Version: 1.3.7
|
10 |
Text Domain: wf_order_import_export
|
11 |
+
WC tested up to: 3.5.0
|
12 |
License: GPLv3
|
13 |
License URI: https://www.gnu.org/licenses/gpl-3.0.html
|
14 |
*/
|
24 |
define("wf_coupon_csv_im_ex", "wf_coupon_csv_im_ex");
|
25 |
|
26 |
if (!defined('WF_ORDERIMPEXP_CURRENT_VERSION')) {
|
27 |
+
define("WF_ORDERIMPEXP_CURRENT_VERSION", "1.3.7");
|
28 |
}
|
29 |
|
30 |
/**
|
readme.txt
CHANGED
@@ -4,7 +4,7 @@ Donate link: https://www.webtoffee.com/plugins/
|
|
4 |
Tags: Order Export, Order Import, WooCommerce Export Orders , WooCommerce Import Orders , Export Orders, Import Orders
|
5 |
Requires at least: 3.0.1
|
6 |
Tested up to: 4.9.8
|
7 |
-
Stable tag: 1.3.
|
8 |
License: GPLv3
|
9 |
License URI: http://www.gnu.org/licenses/gpl-3.0.html
|
10 |
|
@@ -21,7 +21,7 @@ This is perfect tool if you are migrating an existing shop on a different eComme
|
|
21 |
🔸 Import Coupons from CSV file.
|
22 |
🔸 Export Subscription Orders to CSV file(Premium Feature).
|
23 |
🔸 Import Subscription Orders from CSV file(Premium Feature).
|
24 |
-
🔸 Tested OK with WooCommerce 3.
|
25 |
|
26 |
<blockquote>
|
27 |
|
@@ -110,6 +110,8 @@ Yes. You can import or export order line item details.
|
|
110 |
|
111 |
== Changelog ==
|
112 |
|
|
|
|
|
113 |
= 1.3.6 =
|
114 |
* Content Update.
|
115 |
= 1.3.5 =
|
@@ -196,5 +198,5 @@ Yes. You can import or export order line item details.
|
|
196 |
* Export /Import WooCommerce Orders.
|
197 |
|
198 |
== Upgrade Notice ==
|
199 |
-
= 1.3.
|
200 |
-
*
|
4 |
Tags: Order Export, Order Import, WooCommerce Export Orders , WooCommerce Import Orders , Export Orders, Import Orders
|
5 |
Requires at least: 3.0.1
|
6 |
Tested up to: 4.9.8
|
7 |
+
Stable tag: 1.3.7
|
8 |
License: GPLv3
|
9 |
License URI: http://www.gnu.org/licenses/gpl-3.0.html
|
10 |
|
21 |
🔸 Import Coupons from CSV file.
|
22 |
🔸 Export Subscription Orders to CSV file(Premium Feature).
|
23 |
🔸 Import Subscription Orders from CSV file(Premium Feature).
|
24 |
+
🔸 Tested OK with WooCommerce 3.5.0
|
25 |
|
26 |
<blockquote>
|
27 |
|
110 |
|
111 |
== Changelog ==
|
112 |
|
113 |
+
= 1.3.7 =
|
114 |
+
* WC 3.5.0 Tested OK.
|
115 |
= 1.3.6 =
|
116 |
* Content Update.
|
117 |
= 1.3.5 =
|
198 |
* Export /Import WooCommerce Orders.
|
199 |
|
200 |
== Upgrade Notice ==
|
201 |
+
= 1.3.7 =
|
202 |
+
* WC 3.5.0 Tested OK.
|
styles/wf-style.css
CHANGED
File without changes
|