Order Export & Order Import for WooCommerce - Version 1.4.8

Version Description

  • Tested OK with WP 5.2.2 and WC 3.6.4
  • Bug fix: Orders getting imported to new IDs when import ID conflicts with existing post IDs.
  • Issue with using the plugin in multi-site setup.
  • Help tab modification.
Download this release

Release Info

Developer webtoffee
Plugin Icon 128x128 Order Export & Order Import for WooCommerce
Version 1.4.8
Comparing to
See all releases

Code changes from version 1.4.7 to 1.4.8

Sample_Subscription.csv CHANGED
@@ -1,3 +1,3 @@
1
  subscription_id,subscription_status,customer_id,customer_username,customer_email,start_date,trial_end_date,next_payment_date,last_payment_date,end_date,post_parent,billing_period,billing_interval,order_shipping,order_shipping_tax,fee_total,fee_tax_total,order_tax,cart_discount,cart_discount_tax,order_total,order_currency,payment_method,payment_method_title,payment_method_post_meta,payment_method_user_meta,shipping_method,billing_first_name,billing_last_name,billing_email,billing_phone,billing_address_1,billing_address_2,billing_postcode,billing_city,billing_state,billing_country,billing_company,shipping_first_name,shipping_last_name,shipping_address_1,shipping_address_2,shipping_postcode,shipping_city,shipping_state,shipping_country,shipping_company,customer_note,order_items,order_notes,coupon_items,fee_items,tax_items,download_permissions
2
- 87,wc-active,2,mark,mark@xadapter.com,2016-08-30 07:22:27,2016-09-04 07:22:27,2016-09-04 07:22:27,2016-08-30 07:22:32,2016-12-04 07:22:27,86,month,1,0,0,0,0,0,0,0,9,USD,stripe,Credit card (Stripe),,,,Mark,Wough,mark@xadapter.com,74747474,1st Ave,San Deigo,90001,Naples,AL,US,MarkCO LTD,Steve,Wough,1st Ave,San Deigo,90001,Naples,AL,US,MarkCO LTD,,product_id:10|name:Test Subscription Prdocut|quantity:1|total:9.00|meta:|tax:0.00,Payment received.,Status changed from Pending to Active.,,,1
3
  89,wc-on-hold,9,elvin,elvin@wooforce.com,2016-08-25 19:28:19,2016-08-30 19:28:19,2016-08-30 19:28:19,2016-08-31 06:18:25,2016-11-30 19:28:19,88,month,1,0,0,0,0,0,0,0,9,USD,stripe,Credit card (Stripe),,,,Elvin,j,elvin@xadapter.com,74747474,1st Ave,Naples,90001,Naples,AL,US,MarkCO LTD,Mark,Wough,1st Ave,Naples,90001,Naples,AL,US,ElvinCO LTD,Just checking Elvin Placed the Order,product_id:10|name:Test Subscription Prdocut|quantity:1|total:9.00|meta:|tax:0.00,"Payment failed.;Order <a href=""http://localhost/latestpress/wp-admin/post.php?post=233&#038;action=edit"">#233</a> created to record renewal.;Subscription renewal payment due: Status changed from Active to On hold.;Payment received.;Status changed from Pending to Active.",code:|description:|amount:0.00,,,0
1
  subscription_id,subscription_status,customer_id,customer_username,customer_email,start_date,trial_end_date,next_payment_date,last_payment_date,end_date,post_parent,billing_period,billing_interval,order_shipping,order_shipping_tax,fee_total,fee_tax_total,order_tax,cart_discount,cart_discount_tax,order_total,order_currency,payment_method,payment_method_title,payment_method_post_meta,payment_method_user_meta,shipping_method,billing_first_name,billing_last_name,billing_email,billing_phone,billing_address_1,billing_address_2,billing_postcode,billing_city,billing_state,billing_country,billing_company,shipping_first_name,shipping_last_name,shipping_address_1,shipping_address_2,shipping_postcode,shipping_city,shipping_state,shipping_country,shipping_company,customer_note,order_items,order_notes,coupon_items,fee_items,tax_items,download_permissions
2
+ 87,wc-active,2,mark,mark@xadapter.com,2016-08-30 07:22:27,2016-09-04 07:22:27,2016-09-04 07:22:27,2016-08-30 07:22:32,2016-12-04 07:22:27,86,month,1,0,0,0,0,0,0,0,9,USD,stripe,Credit card (Stripe),,,,Mark,Wough,mark@xadapter.com,74747474,1st Ave,San Deigo,90001,Naples,AL,US,MarkCO LTD,Steve,Wough,1st Ave,San Deigo,90001,Naples,AL,US,MarkCO LTD,,product_id:10|name:Test Subscription Prdocut|quantity:1|total:9.00|meta:|tax:0.00,Payment received.,,,,1
3
  89,wc-on-hold,9,elvin,elvin@wooforce.com,2016-08-25 19:28:19,2016-08-30 19:28:19,2016-08-30 19:28:19,2016-08-31 06:18:25,2016-11-30 19:28:19,88,month,1,0,0,0,0,0,0,0,9,USD,stripe,Credit card (Stripe),,,,Elvin,j,elvin@xadapter.com,74747474,1st Ave,Naples,90001,Naples,AL,US,MarkCO LTD,Mark,Wough,1st Ave,Naples,90001,Naples,AL,US,ElvinCO LTD,Just checking Elvin Placed the Order,product_id:10|name:Test Subscription Prdocut|quantity:1|total:9.00|meta:|tax:0.00,"Payment failed.;Order <a href=""http://localhost/latestpress/wp-admin/post.php?post=233&#038;action=edit"">#233</a> created to record renewal.;Subscription renewal payment due: Status changed from Active to On hold.;Payment received.;Status changed from Pending to Active.",code:|description:|amount:0.00,,,0
images/csv.png ADDED
Binary file
images/documentation.png ADDED
Binary file
includes/exporter/class-wf-orderimpexpcsv-exporter.php CHANGED
@@ -12,16 +12,12 @@ class WF_OrderImpExpCsv_Exporter {
12
 
13
  public static function do_export($post_type = 'shop_order') {
14
  global $wpdb;
15
-
16
  $limit = !empty($_POST['limit']) ? intval($_POST['limit']) : 999999999;
17
-
18
  $export_offset = !empty($_POST['offset']) ? intval($_POST['offset']) : 0;
19
  $csv_columns = include( 'data/data-wf-post-columns.php' );
20
  $user_columns_name = ! empty( $_POST['columns_name'] ) ? $_POST['columns_name'] : $csv_columns;
21
  $export_columns = ! empty( $_POST['columns'] ) ? $_POST['columns'] : array();
22
-
23
  $export_order_statuses = !empty($_POST['order_status']) ? $_POST['order_status'] : 'any';
24
-
25
  $delimiter = !empty($_POST['delimiter']) ? $_POST['delimiter'] : ',';
26
 
27
  $wpdb->hide_errors();
@@ -38,31 +34,26 @@ class WF_OrderImpExpCsv_Exporter {
38
 
39
  $fp = fopen('php://output', 'w');
40
 
41
-
42
  // Headers
43
 
44
-
45
-
46
  $query_args = array(
47
  'fields' => 'ids',
48
  'post_type' => 'shop_order',
49
  'post_status' => $export_order_statuses,
50
  'posts_per_page' => $limit,
51
- 'offset' => $export_offset,
52
  );
53
 
54
  $query = new WP_Query($query_args);
55
  $order_ids = $query->posts;
56
 
57
-
58
  // Variable to hold the CSV data we're exporting
59
  $row = array();
60
  // Export header rows
61
  foreach ($csv_columns as $column => $value) {
62
-
63
- $temp_head = esc_attr( $user_columns_name[$column] );
64
- if ( ! $export_columns || in_array( $column, $export_columns ) )
65
- $row[] = $temp_head;
66
  }
67
  $max_line_items = WF_OrderImpExpCsv_Exporter::get_max_line_items($order_ids);
68
  for ($i = 1; $i <= $max_line_items; $i++) {
@@ -105,34 +96,24 @@ class WF_OrderImpExpCsv_Exporter {
105
  }
106
 
107
  public static function get_max_line_items($order_ids) {
108
-
109
  $max_line_items = 0;
110
-
111
  foreach ($order_ids as $order_id) {
112
-
113
  $order = wc_get_order($order_id);
114
-
115
  $line_items_count = count($order->get_items());
116
-
117
  if ($line_items_count >= $max_line_items) {
118
  $max_line_items = $line_items_count;
119
  }
120
  }
121
-
122
  return $max_line_items;
123
  }
124
 
125
  public static function get_orders_csv_row($order_id , $export_columns) {
126
-
127
  $order = wc_get_order($order_id);
128
-
129
  $line_items = $shipping_items = $fee_items = $tax_items = $coupon_items = array();
130
 
131
  // get line items
132
  foreach ($order->get_items() as $item_id => $item) {
133
-
134
  $product = $order->get_product_from_item($item);
135
-
136
  if (!is_object($product)) {
137
  $product = new WC_Product(0);
138
  }
@@ -157,11 +138,10 @@ class WF_OrderImpExpCsv_Exporter {
157
  }
158
 
159
  foreach ($order->get_shipping_methods() as $_ => $shipping_item) {
160
-
161
  $shipping_items[] = implode('|', array(
162
  'method:' . $shipping_item['name'],
163
  'total:' . wc_format_decimal($shipping_item['cost'], 2),
164
- ));
165
  }
166
 
167
  // get fee items & total
@@ -169,95 +149,88 @@ class WF_OrderImpExpCsv_Exporter {
169
  $fee_tax_total = 0;
170
 
171
  foreach ($order->get_fees() as $fee_id => $fee) {
172
-
173
  $fee_items[] = implode('|', array(
174
  'name:' . $fee['name'],
175
  'total:' . wc_format_decimal($fee['line_total'], 2),
176
  'tax:' . wc_format_decimal($fee['line_tax'], 2),
177
- ));
178
-
179
  $fee_total += $fee['line_total'];
180
  $fee_tax_total += $fee['line_tax'];
181
  }
182
 
183
  // get tax items
184
  foreach ($order->get_tax_totals() as $tax_code => $tax) {
185
-
186
  $tax_items[] = implode('|', array(
187
  'rate_id:'.$tax->rate_id,
188
  'code:' . $tax_code,
189
  'total:' . wc_format_decimal($tax->amount, 2),
190
  'label:'.$tax->label,
191
  'tax_rate_compound:'.$tax->is_compound,
192
- ));
193
  }
194
 
195
  // add coupons
196
  foreach ($order->get_items('coupon') as $_ => $coupon_item) {
197
-
198
  $coupon = new WC_Coupon($coupon_item['name']);
199
-
200
  $coupon_post = get_post((WC()->version < '2.7.0')?$coupon->id:$coupon->get_id());
201
-
202
  $coupon_items[] = implode('|', array(
203
  'code:' . $coupon_item['name'],
204
  'description:' . ( is_object($coupon_post) ? $coupon_post->post_excerpt : '' ),
205
  'amount:' . wc_format_decimal($coupon_item['discount_amount'], 2),
206
- ));
207
  }
208
 
209
  if (version_compare(WC_VERSION, '2.7', '<')) {
210
- $order_data = array(
211
- 'order_id' => $order->id,
212
- 'order_number' => $order->get_order_number(),
213
- 'order_date' => date('Y-m-d H:i:s', strtotime(get_post($order->id)->post_date)),
214
- 'status' => $order->get_status(),
215
- 'shipping_total' => $order->get_total_shipping(),
216
- 'shipping_tax_total' => wc_format_decimal($order->get_shipping_tax(), 2),
217
- 'fee_total' => wc_format_decimal($fee_total, 2),
218
- 'fee_tax_total' => wc_format_decimal($fee_tax_total, 2),
219
- 'tax_total' => wc_format_decimal($order->get_total_tax(), 2),
220
- 'cart_discount' => (defined( 'WC_VERSION' ) && (WC_VERSION >= 2.3)) ? wc_format_decimal($order->get_total_discount(), 2) : wc_format_decimal($order->get_cart_discount(), 2),
221
- 'order_discount' => (defined( 'WC_VERSION' ) && (WC_VERSION >= 2.3)) ? wc_format_decimal($order->get_total_discount(), 2) : wc_format_decimal($order->get_order_discount(), 2),
222
- 'discount_total' => wc_format_decimal($order->get_total_discount(), 2),
223
- 'order_total' => wc_format_decimal($order->get_total(), 2),
224
- 'refunded_total' => wc_format_decimal($order->get_total_refunded(), 2),
225
- 'order_currency' => $order->get_order_currency(),
226
- 'payment_method' => $order->payment_method,
227
- 'shipping_method' => $order->get_shipping_method(),
228
- 'customer_id' => $order->get_user_id(),
229
- 'customer_user' => $order->get_user_id(),
230
- 'customer_email' => ($a = get_userdata($order->get_user_id() )) ? $a->user_email : '',
231
- 'billing_first_name' => $order->billing_first_name,
232
- 'billing_last_name' => $order->billing_last_name,
233
- 'billing_company' => $order->billing_company,
234
- 'billing_email' => $order->billing_email,
235
- 'billing_phone' => $order->billing_phone,
236
- 'billing_address_1' => $order->billing_address_1,
237
- 'billing_address_2' => $order->billing_address_2,
238
- 'billing_postcode' => $order->billing_postcode,
239
- 'billing_city' => $order->billing_city,
240
- 'billing_state' => $order->billing_state,
241
- 'billing_country' => $order->billing_country,
242
- 'shipping_first_name' => $order->shipping_first_name,
243
- 'shipping_last_name' => $order->shipping_last_name,
244
- 'shipping_company' => $order->shipping_company,
245
- 'shipping_address_1' => $order->shipping_address_1,
246
- 'shipping_address_2' => $order->shipping_address_2,
247
- 'shipping_postcode' => $order->shipping_postcode,
248
- 'shipping_city' => $order->shipping_city,
249
- 'shipping_state' => $order->shipping_state,
250
- 'shipping_country' => $order->shipping_country,
251
- 'customer_note' => $order->customer_note,
252
- 'shipping_items' => implode(';', $shipping_items),
253
- 'fee_items' => implode(';', $fee_items),
254
- 'tax_items' => implode(';', $tax_items),
255
- 'coupon_items' => implode(';', $coupon_items),
256
- 'order_notes' => implode('||', WF_OrderImpExpCsv_Exporter::get_order_notes($order)),
257
- 'download_permissions' => $order->download_permissions_granted ? $order->download_permissions_granted : 0,
258
- );
259
  }else{
260
-
261
  $order_data = array(
262
  'order_id' => $order->get_id(),
263
  'order_number' => $order->get_order_number(),
@@ -306,15 +279,14 @@ class WF_OrderImpExpCsv_Exporter {
306
  'coupon_items' => implode(';', $coupon_items),
307
  'order_notes' => implode('||', (defined('WC_VERSION') && (WC_VERSION >= 3.2)) ? WF_OrderImpExpCsv_Exporter::get_order_notes_new($order) : WF_OrderImpExpCsv_Exporter::get_order_notes($order)),
308
  'download_permissions' => $order->is_download_permitted() ? $order->is_download_permitted() : 0,
309
- );
310
-
311
  }
312
  foreach ($order_data as $key => $value) {
313
- if (!$export_columns || in_array( $key, $export_columns ) ){
314
- // need to modify code
315
- }else{
316
- unset($order_data[$key]);
317
- }
318
  }
319
  $li = 1;
320
  foreach ($line_items as $line_item) {
@@ -329,9 +301,7 @@ class WF_OrderImpExpCsv_Exporter {
329
  }
330
 
331
  public static function get_order_notes($order) {
332
-
333
  $callback = array('WC_Comments', 'exclude_order_comments');
334
-
335
  $args = array(
336
  'post_id' => (WC()->version < '2.7.0')?$order->id:$order->get_id(),
337
  'approve' => 'approve',
@@ -339,12 +309,9 @@ class WF_OrderImpExpCsv_Exporter {
339
  );
340
 
341
  remove_filter('comments_clauses', $callback);
342
-
343
  $notes = get_comments($args);
344
-
345
  add_filter('comments_clauses', $callback);
346
  $notes = array_reverse($notes);
347
-
348
  $order_notes = array();
349
 
350
  foreach ($notes as $note) {
@@ -374,5 +341,4 @@ class WF_OrderImpExpCsv_Exporter {
374
  }
375
  return $order_notes;
376
  }
377
-
378
- }
12
 
13
  public static function do_export($post_type = 'shop_order') {
14
  global $wpdb;
 
15
  $limit = !empty($_POST['limit']) ? intval($_POST['limit']) : 999999999;
 
16
  $export_offset = !empty($_POST['offset']) ? intval($_POST['offset']) : 0;
17
  $csv_columns = include( 'data/data-wf-post-columns.php' );
18
  $user_columns_name = ! empty( $_POST['columns_name'] ) ? $_POST['columns_name'] : $csv_columns;
19
  $export_columns = ! empty( $_POST['columns'] ) ? $_POST['columns'] : array();
 
20
  $export_order_statuses = !empty($_POST['order_status']) ? $_POST['order_status'] : 'any';
 
21
  $delimiter = !empty($_POST['delimiter']) ? $_POST['delimiter'] : ',';
22
 
23
  $wpdb->hide_errors();
34
 
35
  $fp = fopen('php://output', 'w');
36
 
 
37
  // Headers
38
 
 
 
39
  $query_args = array(
40
  'fields' => 'ids',
41
  'post_type' => 'shop_order',
42
  'post_status' => $export_order_statuses,
43
  'posts_per_page' => $limit,
44
+ 'offset' => $export_offset
45
  );
46
 
47
  $query = new WP_Query($query_args);
48
  $order_ids = $query->posts;
49
 
 
50
  // Variable to hold the CSV data we're exporting
51
  $row = array();
52
  // Export header rows
53
  foreach ($csv_columns as $column => $value) {
54
+ $temp_head = esc_attr( $user_columns_name[$column] );
55
+ if ( ! $export_columns || in_array( $column, $export_columns ) )
56
+ $row[] = $temp_head;
 
57
  }
58
  $max_line_items = WF_OrderImpExpCsv_Exporter::get_max_line_items($order_ids);
59
  for ($i = 1; $i <= $max_line_items; $i++) {
96
  }
97
 
98
  public static function get_max_line_items($order_ids) {
 
99
  $max_line_items = 0;
 
100
  foreach ($order_ids as $order_id) {
 
101
  $order = wc_get_order($order_id);
 
102
  $line_items_count = count($order->get_items());
 
103
  if ($line_items_count >= $max_line_items) {
104
  $max_line_items = $line_items_count;
105
  }
106
  }
 
107
  return $max_line_items;
108
  }
109
 
110
  public static function get_orders_csv_row($order_id , $export_columns) {
 
111
  $order = wc_get_order($order_id);
 
112
  $line_items = $shipping_items = $fee_items = $tax_items = $coupon_items = array();
113
 
114
  // get line items
115
  foreach ($order->get_items() as $item_id => $item) {
 
116
  $product = $order->get_product_from_item($item);
 
117
  if (!is_object($product)) {
118
  $product = new WC_Product(0);
119
  }
138
  }
139
 
140
  foreach ($order->get_shipping_methods() as $_ => $shipping_item) {
 
141
  $shipping_items[] = implode('|', array(
142
  'method:' . $shipping_item['name'],
143
  'total:' . wc_format_decimal($shipping_item['cost'], 2),
144
+ ));
145
  }
146
 
147
  // get fee items & total
149
  $fee_tax_total = 0;
150
 
151
  foreach ($order->get_fees() as $fee_id => $fee) {
 
152
  $fee_items[] = implode('|', array(
153
  'name:' . $fee['name'],
154
  'total:' . wc_format_decimal($fee['line_total'], 2),
155
  'tax:' . wc_format_decimal($fee['line_tax'], 2),
156
+ ));
 
157
  $fee_total += $fee['line_total'];
158
  $fee_tax_total += $fee['line_tax'];
159
  }
160
 
161
  // get tax items
162
  foreach ($order->get_tax_totals() as $tax_code => $tax) {
 
163
  $tax_items[] = implode('|', array(
164
  'rate_id:'.$tax->rate_id,
165
  'code:' . $tax_code,
166
  'total:' . wc_format_decimal($tax->amount, 2),
167
  'label:'.$tax->label,
168
  'tax_rate_compound:'.$tax->is_compound,
169
+ ));
170
  }
171
 
172
  // add coupons
173
  foreach ($order->get_items('coupon') as $_ => $coupon_item) {
 
174
  $coupon = new WC_Coupon($coupon_item['name']);
 
175
  $coupon_post = get_post((WC()->version < '2.7.0')?$coupon->id:$coupon->get_id());
 
176
  $coupon_items[] = implode('|', array(
177
  'code:' . $coupon_item['name'],
178
  'description:' . ( is_object($coupon_post) ? $coupon_post->post_excerpt : '' ),
179
  'amount:' . wc_format_decimal($coupon_item['discount_amount'], 2),
180
+ ));
181
  }
182
 
183
  if (version_compare(WC_VERSION, '2.7', '<')) {
184
+ $order_data = array(
185
+ 'order_id' => $order->id,
186
+ 'order_number' => $order->get_order_number(),
187
+ 'order_date' => date('Y-m-d H:i:s', strtotime(get_post($order->id)->post_date)),
188
+ 'status' => $order->get_status(),
189
+ 'shipping_total' => $order->get_total_shipping(),
190
+ 'shipping_tax_total' => wc_format_decimal($order->get_shipping_tax(), 2),
191
+ 'fee_total' => wc_format_decimal($fee_total, 2),
192
+ 'fee_tax_total' => wc_format_decimal($fee_tax_total, 2),
193
+ 'tax_total' => wc_format_decimal($order->get_total_tax(), 2),
194
+ 'cart_discount' => (defined( 'WC_VERSION' ) && (WC_VERSION >= 2.3)) ? wc_format_decimal($order->get_total_discount(), 2) : wc_format_decimal($order->get_cart_discount(), 2),
195
+ 'order_discount' => (defined( 'WC_VERSION' ) && (WC_VERSION >= 2.3)) ? wc_format_decimal($order->get_total_discount(), 2) : wc_format_decimal($order->get_order_discount(), 2),
196
+ 'discount_total' => wc_format_decimal($order->get_total_discount(), 2),
197
+ 'order_total' => wc_format_decimal($order->get_total(), 2),
198
+ 'refunded_total' => wc_format_decimal($order->get_total_refunded(), 2),
199
+ 'order_currency' => $order->get_order_currency(),
200
+ 'payment_method' => $order->payment_method,
201
+ 'shipping_method' => $order->get_shipping_method(),
202
+ 'customer_id' => $order->get_user_id(),
203
+ 'customer_user' => $order->get_user_id(),
204
+ 'customer_email' => ($a = get_userdata($order->get_user_id() )) ? $a->user_email : '',
205
+ 'billing_first_name' => $order->billing_first_name,
206
+ 'billing_last_name' => $order->billing_last_name,
207
+ 'billing_company' => $order->billing_company,
208
+ 'billing_email' => $order->billing_email,
209
+ 'billing_phone' => $order->billing_phone,
210
+ 'billing_address_1' => $order->billing_address_1,
211
+ 'billing_address_2' => $order->billing_address_2,
212
+ 'billing_postcode' => $order->billing_postcode,
213
+ 'billing_city' => $order->billing_city,
214
+ 'billing_state' => $order->billing_state,
215
+ 'billing_country' => $order->billing_country,
216
+ 'shipping_first_name' => $order->shipping_first_name,
217
+ 'shipping_last_name' => $order->shipping_last_name,
218
+ 'shipping_company' => $order->shipping_company,
219
+ 'shipping_address_1' => $order->shipping_address_1,
220
+ 'shipping_address_2' => $order->shipping_address_2,
221
+ 'shipping_postcode' => $order->shipping_postcode,
222
+ 'shipping_city' => $order->shipping_city,
223
+ 'shipping_state' => $order->shipping_state,
224
+ 'shipping_country' => $order->shipping_country,
225
+ 'customer_note' => $order->customer_note,
226
+ 'shipping_items' => implode(';', $shipping_items),
227
+ 'fee_items' => implode(';', $fee_items),
228
+ 'tax_items' => implode(';', $tax_items),
229
+ 'coupon_items' => implode(';', $coupon_items),
230
+ 'order_notes' => implode('||', WF_OrderImpExpCsv_Exporter::get_order_notes($order)),
231
+ 'download_permissions' => $order->download_permissions_granted ? $order->download_permissions_granted : 0,
232
+ );
233
  }else{
 
234
  $order_data = array(
235
  'order_id' => $order->get_id(),
236
  'order_number' => $order->get_order_number(),
279
  'coupon_items' => implode(';', $coupon_items),
280
  'order_notes' => implode('||', (defined('WC_VERSION') && (WC_VERSION >= 3.2)) ? WF_OrderImpExpCsv_Exporter::get_order_notes_new($order) : WF_OrderImpExpCsv_Exporter::get_order_notes($order)),
281
  'download_permissions' => $order->is_download_permitted() ? $order->is_download_permitted() : 0,
282
+ );
 
283
  }
284
  foreach ($order_data as $key => $value) {
285
+ if (!$export_columns || in_array( $key, $export_columns ) ){
286
+ // need to modify code
287
+ }else{
288
+ unset($order_data[$key]);
289
+ }
290
  }
291
  $li = 1;
292
  foreach ($line_items as $line_item) {
301
  }
302
 
303
  public static function get_order_notes($order) {
 
304
  $callback = array('WC_Comments', 'exclude_order_comments');
 
305
  $args = array(
306
  'post_id' => (WC()->version < '2.7.0')?$order->id:$order->get_id(),
307
  'approve' => 'approve',
309
  );
310
 
311
  remove_filter('comments_clauses', $callback);
 
312
  $notes = get_comments($args);
 
313
  add_filter('comments_clauses', $callback);
314
  $notes = array_reverse($notes);
 
315
  $order_notes = array();
316
 
317
  foreach ($notes as $note) {
341
  }
342
  return $order_notes;
343
  }
344
+ }
 
includes/importer/class-wf-cpnimpexpcsv-coupon-import.php CHANGED
@@ -476,8 +476,8 @@ class WF_CpnImpExpCsv_Coupon_Import extends WP_Importer {
476
  }
477
 
478
  if ( $processing_coupon_id && is_string( get_post_status( $processing_coupon_id ) ) && ($is_post_exist_in_db !== $post['post_type'] ) ) {
479
- $this->add_import_result( 'skipped', __( 'Importing coupon(ID) conflicts with an existing post.', 'wf_order_import_export' ), $processing_coupon_id, get_the_title( $processing_coupon_id ) );
480
- $this->hf_coupon_log_data_change( 'coupon-csv-import', sprintf( __('> &#8220;%s&#8221; ID already exists.', 'wf_order_import_export'), esc_html( $processing_coupon_id ) ), true );
481
  unset( $post );
482
  return;
483
  }
@@ -617,7 +617,7 @@ class WF_CpnImpExpCsv_Coupon_Import extends WP_Importer {
617
 
618
  // Display import page title
619
  public function header() {
620
- echo '<div class="wrap"><div class="icon32" id="icon-woocommerce-importer"><br></div>';
621
  echo '<h2>' . ( empty( $_GET['merge'] ) ? __( 'Import', 'order-import-export-for-woocommerce' ) : __( 'Merge Coupons', 'order-import-export-for-woocommerce' ) ) . '</h2>';
622
  }
623
 
476
  }
477
 
478
  if ( $processing_coupon_id && is_string( get_post_status( $processing_coupon_id ) ) && ($is_post_exist_in_db !== $post['post_type'] ) ) {
479
+ $this->add_import_result( 'skipped', __( 'Importing coupon(ID) conflicts with an existing post.', 'order-import-export-for-woocommerce' ), $processing_coupon_id, get_the_title( $processing_coupon_id ) );
480
+ $this->hf_coupon_log_data_change( 'coupon-csv-import', sprintf( __('> &#8220;%s&#8221; ID already exists.', 'order-import-export-for-woocommerce'), esc_html( $processing_coupon_id ) ), true );
481
  unset( $post );
482
  return;
483
  }
617
 
618
  // Display import page title
619
  public function header() {
620
+ echo '<div><div class="icon32" id="icon-woocommerce-importer"><br></div>';
621
  echo '<h2>' . ( empty( $_GET['merge'] ) ? __( 'Import', 'order-import-export-for-woocommerce' ) : __( 'Merge Coupons', 'order-import-export-for-woocommerce' ) ) . '</h2>';
622
  }
623
 
includes/importer/class-wf-csv-parser.php CHANGED
@@ -24,7 +24,6 @@ class WF_CSV_Parser {
24
  */
25
  public function __construct($post_type = 'shop_order') {
26
  $this->post_type = $post_type;
27
-
28
  $this->order_meta_fields = array(
29
  "order_tax",
30
  "order_shipping",
@@ -87,45 +86,32 @@ class WF_CSV_Parser {
87
  * @return array
88
  */
89
  public function parse_data($file, $delimiter, $start_pos = 0, $end_pos = null) {
90
- // Set locale
91
  $enc = mb_detect_encoding($file, 'UTF-8, ISO-8859-1', true);
92
  if ($enc)
93
  setlocale(LC_ALL, 'en_US.' . $enc);
94
  @ini_set('auto_detect_line_endings', true);
95
-
96
  $parsed_data = array();
97
  $raw_headers = array();
98
-
99
  // Put all CSV data into an associative array
100
  if (( $handle = fopen($file, "r") ) !== FALSE) {
101
-
102
  $header = fgetcsv($handle, 0, $delimiter);
103
  if ($start_pos != 0)
104
  fseek($handle, $start_pos);
105
-
106
  while (( $postmeta = fgetcsv($handle, 0, $delimiter) ) !== FALSE) {
107
  $row = array();
108
-
109
  foreach ($header as $key => $heading) {
110
  $s_heading = $heading;
111
-
112
-
113
-
114
  if ($s_heading == '')
115
  continue;
116
-
117
  // Add the heading to the parsed data
118
  $row[$s_heading] = ( isset($postmeta[$key]) ) ? $this->format_data_from_csv($postmeta[$key], $enc) : '';
119
-
120
  // Raw Headers stores the actual column name in the CSV
121
  $raw_headers[$s_heading] = $heading;
122
  }
123
  $parsed_data[] = $row;
124
-
125
  unset($postmeta, $row);
126
-
127
  $position = ftell($handle);
128
-
129
  if ($end_pos && $position >= $end_pos)
130
  break;
131
  }
@@ -146,56 +132,40 @@ class WF_CSV_Parser {
146
  //$allow_unknown_products = isset( $_POST['allow_unknown_products'] ) && $_POST['allow_unknown_products'] ? true : false;
147
  $allow_unknown_products = true;
148
  $results = array();
149
-
150
  // Count row
151
  $row = 0;
152
-
153
  // skipped records
154
  $skipped = 0;
155
-
156
  $csv_export_file = true;
157
-
158
  $available_methods = WC()->shipping()->load_shipping_methods();
159
  $available_gateways = WC()->payment_gateways->payment_gateways();
160
  $shop_order_status = $this->wc_get_order_statuses_neat();
161
-
162
  $tax_rates = array();
163
  foreach ($wpdb->get_results("SELECT * FROM {$wpdb->prefix}woocommerce_tax_rates") as $_row) {
164
  $tax_rates[$_row->tax_rate_id] = $_row;
165
  }
166
-
167
  $row++;
168
-
169
  if ($row <= $record_offset) {
170
  $WF_CSV_Order_Import->hf_order_log_data_change('order-csv-import', sprintf(__('> Row %s - skipped due to record offset.', 'order-import-export-for-woocommerce'), $row));
171
  unset($item);
172
  return;
173
  }
174
-
175
  $postmeta = $order = array();
176
-
177
  if (!$csv_export_file) {
178
  // standard format: optional integer order number and formatted order number
179
  $order_number = (!empty($item['order_number']) ) ? $item['order_number'] : null;
180
  $order_number_formatted = (!empty($item['order_number_formatted']) ) ? $item['order_number_formatted'] : $order_number;
181
-
182
  $WF_CSV_Order_Import->hf_order_log_data_change('order-csv-import', sprintf(__('> Row %s - preparing for import.', 'order-import-export-for-woocommerce'), $row));
183
-
184
-
185
  // validate the supplied formatted order number/order number
186
  if (is_numeric($order_number_formatted) && !$order_number)
187
  $order_number = $order_number_formatted; // use formatted for underlying order number if possible
188
-
189
  if ($order_number && !is_numeric($order_number)) {
190
-
191
  $WF_CSV_Order_Import->hf_order_log_data_change('order-csv-import', sprintf(__('> > Skipped. Order number field must be an integer: %s.', 'order-import-export-for-woocommerce'), $order_number));
192
  $skipped++;
193
  unset($item);
194
  return;
195
  }
196
-
197
  if ($order_number_formatted && !$order_number) {
198
-
199
  $WF_CSV_Order_Import->hf_order_log_data_change('order-csv-import', __('> > Skipped. Formatted order number provided but no numerical order number, see the documentation for further details.', 'order-import-export-for-woocommerce'));
200
  $skipped++;
201
  unset($item);
@@ -205,7 +175,6 @@ class WF_CSV_Parser {
205
  $order_number_formatted = !empty($item['order_id']) ? $item['order_id'] : 0;
206
  $order_number = (!empty($item['order_number']) ? $item['order_number'] : ( is_numeric($order_number_formatted) ? $order_number_formatted : 0 ) );
207
  }
208
-
209
  if ($order_number_formatted) {
210
  // verify that this order number isn't already in use
211
  $query_args = array(
@@ -216,15 +185,12 @@ class WF_CSV_Parser {
216
  'post_status' => array_keys(wc_get_order_statuses()),
217
  'fields' => 'ids',
218
  );
219
-
220
  $order_id = 0;
221
  $orders = get_posts($query_args);
222
  if (!empty($orders)) {
223
  list( $order_id ) = get_posts($query_args);
224
  }
225
-
226
  $order_id = apply_filters('woocommerce_find_order_by_order_number', $order_id, $order_number_formatted);
227
-
228
  if ($order_id) {
229
  // skip if order ID already exist.
230
  $WF_CSV_Order_Import->hf_order_log_data_change('order-csv-import', sprintf(__('> > Skipped. Order %s already exists.', 'order-import-export-for-woocommerce'), $order_number_formatted));
@@ -238,11 +204,8 @@ class WF_CSV_Parser {
238
  // attempt to find the customer user
239
  $found_customer = false;
240
  if (is_int($item['customer_id'])) {
241
-
242
  $found_customer = get_user_by('id', $item['customer_id']);
243
-
244
  if (!$found_customer) {
245
-
246
  $WF_CSV_Order_Import->hf_order_log_data_change('order-csv-import', sprintf(__('> > Skipped. Cannot find customer with id %s.', 'order-import-export-for-woocommerce'), $item['customer_id']));
247
  $skipped++;
248
  unset($item);
@@ -253,11 +216,9 @@ class WF_CSV_Parser {
253
  // check by email
254
  $found_customer = email_exists($item['customer_id']);
255
  }
256
-
257
  if (!$found_customer) {
258
  $found_customer = username_exists($item['customer_id']);
259
  }
260
-
261
  if (!$found_customer) {
262
  // guest checkout
263
  $item['customer_id'] = 0;
@@ -275,8 +236,6 @@ class WF_CSV_Parser {
275
  // guest checkout
276
  $item['customer_id'] = 0;
277
  }
278
-
279
-
280
  if (!empty($item['status'])) {
281
  $order['status'] = $item['status'];
282
  $found_status = false;
@@ -286,7 +245,6 @@ class WF_CSV_Parser {
286
  $found_status = true;
287
  $available_statuses[] = $status_slug;
288
  }
289
-
290
  if (!$found_status) {
291
  $WF_CSV_Order_Import->hf_order_log_data_change('order-csv-import', sprintf(__('> > Skipped. Unknown order status %s (%s).', 'order-import-export-for-woocommerce'), $item['status'], implode($available_statuses, ', ')));
292
  $skipped++;
@@ -294,7 +252,6 @@ class WF_CSV_Parser {
294
  return;
295
  }
296
  }
297
-
298
  if (!empty($item['order_date'])){
299
  $item['date'] = $item['order_date'];
300
  } elseif (isset($item['order_date'])) {
@@ -314,13 +271,10 @@ class WF_CSV_Parser {
314
  }
315
  $order['date'] = $item['date'];
316
  }
317
-
318
-
319
  $order_notes = array();
320
  if (!empty($item['order_notes'])) {
321
  $order_notes = explode("||", $item['order_notes']);
322
  }
323
-
324
  // build the order data object
325
  $order['order_id'] = !empty($item['order_id']) ? $item['order_id'] : null;
326
  $order['order_comments'] = !empty($item['customer_note']) ? $item['customer_note'] : null;
@@ -329,23 +283,17 @@ class WF_CSV_Parser {
329
  $order['order_number'] = $order_number; // optional order number, for convenience
330
  if ($order_number_formatted)
331
  $order['order_number_formatted'] = $order_number_formatted;
332
-
333
  // totals
334
  $order_tax = $order_shipping_tax = null;
335
-
336
  // Get any known order meta fields, and default any missing ones to 0/null
337
  // the provided shipping/payment method will be used as-is, and if found in the list of available ones, the respective titles will also be set
338
  foreach ($this->order_meta_fields as $column) {
339
-
340
  switch ($column) {
341
-
342
  case 'shipping_method':
343
  if(isset($item[$column])){
344
  $value = $item[$column];
345
-
346
  // look up shipping method by id or title
347
  $shipping_method = isset($available_methods[$value]) ? $value : null;
348
-
349
  if (!$shipping_method) {
350
  // try by title
351
  foreach ($available_methods as $method) {
@@ -355,7 +303,6 @@ class WF_CSV_Parser {
355
  }
356
  }
357
  }
358
-
359
  if ($shipping_method) {
360
  //known shipping method found
361
  $postmeta[] = array('key' => '_shipping_method', 'value' => $shipping_method);
@@ -375,11 +322,9 @@ class WF_CSV_Parser {
375
  }
376
  }
377
  break;
378
-
379
  case 'payment_method':
380
  if (isset($item[$column])) {
381
  $value = $item[$column];
382
-
383
  // look up shipping method by id or title
384
  $payment_method = isset($available_gateways[$value]) ? $value : null;
385
  if (!$payment_method) {
@@ -391,7 +336,6 @@ class WF_CSV_Parser {
391
  }
392
  }
393
  }
394
-
395
  if ($payment_method) {
396
  //Known payment method found
397
  $postmeta[] = array('key' => '_payment_method', 'value' => $payment_method);
@@ -411,7 +355,6 @@ class WF_CSV_Parser {
411
  }
412
  }
413
  break;
414
-
415
  // handle numerics
416
  case 'order_shipping': // legacy
417
  case 'shipping_total':
@@ -454,7 +397,6 @@ class WF_CSV_Parser {
454
  $postmeta[] = array('key' => '_' . $column, 'value' => $value);
455
  }
456
  break;
457
-
458
  case 'Download Permissions Granted':
459
  case 'download_permissions_granted':
460
  if (isset($item['download_permissions_granted'])) {
@@ -467,21 +409,16 @@ class WF_CSV_Parser {
467
  $postmeta[] = array('key' => '_download_permissions', 'value' => $item['download_permissions']);
468
  }
469
  break;
470
-
471
  default:
472
-
473
  if (isset($item[$column])){
474
  $postmeta[] = array('key' => '_' . $column, 'value' => $item[$column]);
475
  }
476
  }
477
  }
478
-
479
  if (!empty($item['customer_id']))
480
  $postmeta[] = array('key' => '_customer_user', 'value' => $item['customer_id']);
481
-
482
  $order_shipping_methods = array();
483
  $_shipping_methods = array();
484
-
485
  // pre WC 2.1 format of a single shipping method, left for backwards compatibility of import files
486
  if (isset($item['shipping_method']) && $item['shipping_method']) {
487
  // collect the shipping method id/cost
@@ -490,7 +427,6 @@ class WF_CSV_Parser {
490
  isset($item['shipping_cost']) ? $item['shipping_cost'] : null
491
  );
492
  }
493
-
494
  // collect any additional shipping methods
495
  $i = null;
496
  if (isset($item['shipping_method_1'])) {
@@ -498,10 +434,8 @@ class WF_CSV_Parser {
498
  } elseif (isset($item['shipping_method_2'])) {
499
  $i = 2;
500
  }
501
-
502
  if (!is_null($i)) {
503
  while (!empty($item['shipping_method_' . $i])) {
504
-
505
  $_shipping_methods[] = array(
506
  $item['shipping_method_' . $i],
507
  isset($item['shipping_cost_' . $i]) ? $item['shipping_cost_' . $i] : null
@@ -512,7 +446,6 @@ class WF_CSV_Parser {
512
 
513
  // if the order shipping total wasn't set, calculate it
514
  if (!isset($order_shipping)) {
515
-
516
  $order_shipping = 0;
517
  foreach ($_shipping_methods as $_shipping_method) {
518
  $order_shipping += $_shipping_method[1];
@@ -522,12 +455,9 @@ class WF_CSV_Parser {
522
  // special case: if there was a total order shipping but no cost for the single shipping method, use the total shipping for the order shipping line item
523
  $_shipping_methods[0][1] = $order_shipping;
524
  }
525
-
526
  foreach ($_shipping_methods as $_shipping_method) {
527
-
528
  // look up shipping method by id or title
529
  $shipping_method = isset($available_methods[$_shipping_method[0]]) ? $_shipping_method[0] : null;
530
-
531
  if (!$shipping_method) {
532
  // try by title
533
  foreach ($available_methods as $method) {
@@ -537,7 +467,6 @@ class WF_CSV_Parser {
537
  }
538
  }
539
  }
540
-
541
  if ($shipping_method) {
542
  //Known shipping method found
543
  $order_shipping_methods[] = array('method_id' => $shipping_method, 'cost' => $_shipping_method[1], 'title' => $available_methods[$shipping_method]->title);
@@ -549,7 +478,6 @@ class WF_CSV_Parser {
549
  $order_shipping_methods[] = array('method_id' => $_shipping_method[0], 'cost' => $_shipping_method[1], 'title' => '');
550
  }
551
  }
552
-
553
  $order_items = array();
554
  if ($csv_export_file) {
555
  // standard format
@@ -557,7 +485,6 @@ class WF_CSV_Parser {
557
  // one or more order items
558
  $i = 1;
559
  while (isset($item['line_item_' . $i]) && !empty($item['line_item_' . $i])) {
560
-
561
  // $_item_meta = preg_split("~\\\\.(*SKIP)(*FAIL)|\|~s", $item['line_item_' . $i]);
562
  $_item_meta = array();
563
  if ($item['line_item_' . $i] && empty($_item_meta)) {
@@ -568,7 +495,6 @@ class WF_CSV_Parser {
568
  $unknown_product_name = $name;
569
  $product_identifier_by_id = array_shift($_item_meta); // product_id:id
570
  $product_identifier_by_sku = array_shift($_item_meta); // sku
571
-
572
  $qty = array_shift($_item_meta);
573
  $qty = substr($qty, strpos($qty, ":") + 1);
574
  $total = array_shift($_item_meta);
@@ -577,8 +503,6 @@ class WF_CSV_Parser {
577
  $tax = substr($tax, strpos($tax, ":") + 1);
578
  $tax_data = array_shift($_item_meta);
579
  $tax_data = substr($tax_data, strpos($tax_data, ":") + 1);
580
-
581
-
582
  // find by id
583
  if (false !== strpos($product_identifier_by_id, 'product_id:')) {
584
  // product by product_id
@@ -588,8 +512,7 @@ class WF_CSV_Parser {
588
  if (!in_array(get_post_type($product_id), array('product', 'product_variation'))) {
589
  $product_id = '';
590
  }
591
- }
592
-
593
  if (!$product_id) {
594
  // find by sku
595
  $product_sku = substr($product_identifier_by_sku, strpos($product_identifier_by_sku, ":") + 1);
@@ -598,7 +521,6 @@ class WF_CSV_Parser {
598
  else
599
  $product_id = '';
600
  }
601
-
602
  if (!$allow_unknown_products && !$product_id) {
603
  // unknown product
604
  $WF_CSV_Order_Import->hf_order_log_data_change('order-csv-import', sprintf(__('> > Skipped. Unknown order item: %s.', 'order-import-export-for-woocommerce'), $product_identifier));
@@ -606,23 +528,18 @@ class WF_CSV_Parser {
606
  $i++;
607
  continue; // break outer loop
608
  }
609
-
610
  // get any additional item meta
611
  $item_meta = array();
612
  foreach ($_item_meta as $pair) {
613
-
614
  // replace any escaped pipes
615
  $pair = str_replace('\|', '|', $pair);
616
-
617
  // find the first ':' and split into name-value
618
  $split = strpos($pair, ':');
619
  $name = substr($pair, 0, $split);
620
  $value = substr($pair, $split + 1);
621
-
622
  $item_meta[$name] = $value;
623
  }
624
  $order_items[] = array('product_id' => $product_id, 'qty' => $qty, 'total' => $total,'tax' => $tax, 'tax_data' => $tax_data, 'meta' => $item_meta, 'unknown_product_name' => $unknown_product_name);
625
-
626
  $i++;
627
  }
628
  }
@@ -631,7 +548,6 @@ class WF_CSV_Parser {
631
  $sku = $item['item_sku'];
632
  $qty = $item['item_amount'];
633
  $total = $item['row_price'];
634
-
635
  if (!$sku || !$qty || !is_numeric($total)) {
636
  // invalid item
637
  $WF_CSV_Order_Import->hf_order_log_data_change('order-csv-import', sprintf(__('> > Row %d - %s - skipped. Missing SKU, quantity or total', 'order-import-export-for-woocommerce'), $row, $item['order_id']));
@@ -639,10 +555,8 @@ class WF_CSV_Parser {
639
  unset($item);
640
  return; // break outer loop
641
  }
642
-
643
  // find by sku
644
  $product_id = $wpdb->get_var($wpdb->prepare("SELECT post_id FROM $wpdb->postmeta WHERE meta_key='_sku' AND meta_value=%s LIMIT 1", $sku));
645
-
646
  if (!$product_id) {
647
  // unknown product
648
  $WF_CSV_Order_Import->hf_order_log_data_change('order-csv-import', sprintf(__('> > Row %d - %s - skipped. Unknown order item: %s.', 'order-import-export-for-woocommerce'), $row, $item['order_id'], $sku));
@@ -650,12 +564,9 @@ class WF_CSV_Parser {
650
  unset($item);
651
  return; // break outer loop
652
  }
653
-
654
  $order_items[] = array('product_id' => $product_id, 'qty' => $qty, 'total' => $total);
655
  }
656
-
657
  $tax_items = array();
658
-
659
  // standard tax item format which supports multiple tax items in numbered columns containing a pipe-delimated, colon-labeled format
660
  if (isset($item['tax_items']) && !empty($item['tax_items'])) {
661
  // one or more order tax items
@@ -663,26 +574,21 @@ class WF_CSV_Parser {
663
  $tax_item = explode(';', $item['tax_items']);
664
  // $tax_amount_sum = $shipping_tax_amount_sum = 0;
665
  foreach ($tax_item as $tax) {
666
-
667
  $tax_item_data = array();
668
-
669
  // turn "label: Tax | tax_amount: 10" into an associative array
670
  foreach (explode('|', $tax) as $piece) {
671
  list( $name, $value ) = explode(':', $piece);
672
  $tax_item_data[trim($name)] = trim($value);
673
  }
674
-
675
  // default rate id to 0 if not set
676
  if (!isset($tax_item_data['rate_id'])) {
677
  $tax_item_data['rate_id'] = 0;
678
  }
679
-
680
  // have a tax amount or shipping tax amount
681
  if (isset($tax_item_data['total']) || isset($tax_item_data['shipping_tax_amount'])) {
682
  // try and look up rate id by label if needed
683
  if (isset($tax_item_data['label']) && $tax_item_data['label'] && !$tax_item_data['rate_id']) {
684
  foreach ($tax_rates as $tax_rate) {
685
-
686
  if (0 === strcasecmp($tax_rate->tax_rate_name, $tax_item_data['label'])) {
687
  // found the tax by label
688
  $tax_item_data['rate_id'] = $tax_rate->tax_rate_id;
@@ -690,17 +596,14 @@ class WF_CSV_Parser {
690
  }
691
  }
692
  }
693
-
694
  // check for a rate being specified which does not exist, and clear it out (technically an error?)
695
  if ($tax_item_data['rate_id'] && !isset($tax_rates[$tax_item_data['rate_id']])) {
696
  $tax_item_data['rate_id'] = 0;
697
  }
698
-
699
  // default label of 'Tax' if not provided
700
  if (!isset($tax_item_data['label']) || !$tax_item_data['label']) {
701
  $tax_item_data['label'] = 'Tax';
702
  }
703
-
704
  // default tax amounts to 0 if not set
705
  if (!isset($tax_item_data['total'])) {
706
  $tax_item_data['total'] = 0;
@@ -708,7 +611,6 @@ class WF_CSV_Parser {
708
  if (!isset($tax_item_data['shipping_tax_amount'])) {
709
  $tax_item_data['shipping_tax_amount'] = 0;
710
  }
711
-
712
  // handle compound flag by using the defined tax rate value (if any)
713
  if (!isset($tax_item_data['tax_rate_compound'])) {
714
  $tax_item_data['tax_rate_compound'] = '';
@@ -716,7 +618,6 @@ class WF_CSV_Parser {
716
  $tax_item_data['tax_rate_compound'] = $tax_rates[$tax_item_data['rate_id']]->tax_rate_compound;
717
  }
718
  }
719
-
720
  $tax_items[] = array(
721
  'title' => $tax_item_data['code'],
722
  'rate_id' => $tax_item_data['rate_id'],
@@ -725,51 +626,17 @@ class WF_CSV_Parser {
725
  'tax_amount' => $tax_item_data['total'],
726
  'shipping_tax_amount' => $tax_item_data['shipping_tax_amount'],
727
  );
728
-
729
- // sum up the order totals, in case it wasn't part of the import
730
- // $tax_amount_sum += $tax_item_data['total'];
731
- // $shipping_tax_amount_sum += $tax_item_data['shipping_tax_amount'];
732
  }
733
  }
734
-
735
- // if (!is_numeric($order_tax)) {
736
- // $order_tax = $tax_amount_sum;
737
- // }
738
- // if (!is_numeric($order_shipping_tax)) {
739
- // $order_shipping_tax = $shipping_tax_amount_sum;
740
- // }
741
  }
742
-
743
- // default to zero if not set
744
- // if (!is_numeric($order_tax)) {
745
- // $order_tax = 0;
746
- // }
747
- // if (!is_numeric($order_shipping_tax)) {
748
- // $order_shipping_tax = 0;
749
- // }
750
- // no tax items specified, so create a default one using the tax totals
751
- // if (0 == count($tax_items)) {
752
- //
753
- // $tax_items[] = array(
754
- // 'title' => '',
755
- // 'rate_id' => 0,
756
- // 'label' => 'Tax',
757
- // 'compound' => '',
758
- // 'tax_amount' => $order_tax,
759
- // 'shipping_tax_amount' => $order_shipping_tax,
760
- // );
761
- // }
762
-
763
  // add the order tax totals to the order meta
764
  $postmeta[] = array('key' => '_order_tax', 'value' => number_format((float) $order_tax, 2, '.', ''));
765
  $postmeta[] = array('key' => '_order_shipping_tax', 'value' => number_format((float) $order_shipping_tax, 2, '.', ''));
766
-
767
  if ($order) {
768
  $order['postmeta'] = $postmeta;
769
  $order['order_items'] = $order_items;
770
  $order['order_shipping'] = $order_shipping_methods;
771
  $order['tax_items'] = $tax_items;
772
-
773
  // the order array will now contain the necessary name-value pairs for the wp_posts table, and also any meta data in the 'postmeta' array
774
  $results[] = $order;
775
  }
@@ -781,14 +648,10 @@ class WF_CSV_Parser {
781
  }
782
 
783
  private function wc_get_order_statuses_neat() {
784
-
785
  $order_statuses = array();
786
-
787
  foreach (wc_get_order_statuses() as $slug => $name) {
788
  $order_statuses[preg_replace('/^wc-/', '', $slug)] = $name;
789
  }
790
-
791
  return $order_statuses;
792
  }
793
-
794
  }
24
  */
25
  public function __construct($post_type = 'shop_order') {
26
  $this->post_type = $post_type;
 
27
  $this->order_meta_fields = array(
28
  "order_tax",
29
  "order_shipping",
86
  * @return array
87
  */
88
  public function parse_data($file, $delimiter, $start_pos = 0, $end_pos = null) {
89
+ // Set locale
90
  $enc = mb_detect_encoding($file, 'UTF-8, ISO-8859-1', true);
91
  if ($enc)
92
  setlocale(LC_ALL, 'en_US.' . $enc);
93
  @ini_set('auto_detect_line_endings', true);
 
94
  $parsed_data = array();
95
  $raw_headers = array();
 
96
  // Put all CSV data into an associative array
97
  if (( $handle = fopen($file, "r") ) !== FALSE) {
 
98
  $header = fgetcsv($handle, 0, $delimiter);
99
  if ($start_pos != 0)
100
  fseek($handle, $start_pos);
 
101
  while (( $postmeta = fgetcsv($handle, 0, $delimiter) ) !== FALSE) {
102
  $row = array();
 
103
  foreach ($header as $key => $heading) {
104
  $s_heading = $heading;
 
 
 
105
  if ($s_heading == '')
106
  continue;
 
107
  // Add the heading to the parsed data
108
  $row[$s_heading] = ( isset($postmeta[$key]) ) ? $this->format_data_from_csv($postmeta[$key], $enc) : '';
 
109
  // Raw Headers stores the actual column name in the CSV
110
  $raw_headers[$s_heading] = $heading;
111
  }
112
  $parsed_data[] = $row;
 
113
  unset($postmeta, $row);
 
114
  $position = ftell($handle);
 
115
  if ($end_pos && $position >= $end_pos)
116
  break;
117
  }
132
  //$allow_unknown_products = isset( $_POST['allow_unknown_products'] ) && $_POST['allow_unknown_products'] ? true : false;
133
  $allow_unknown_products = true;
134
  $results = array();
 
135
  // Count row
136
  $row = 0;
 
137
  // skipped records
138
  $skipped = 0;
 
139
  $csv_export_file = true;
 
140
  $available_methods = WC()->shipping()->load_shipping_methods();
141
  $available_gateways = WC()->payment_gateways->payment_gateways();
142
  $shop_order_status = $this->wc_get_order_statuses_neat();
 
143
  $tax_rates = array();
144
  foreach ($wpdb->get_results("SELECT * FROM {$wpdb->prefix}woocommerce_tax_rates") as $_row) {
145
  $tax_rates[$_row->tax_rate_id] = $_row;
146
  }
 
147
  $row++;
 
148
  if ($row <= $record_offset) {
149
  $WF_CSV_Order_Import->hf_order_log_data_change('order-csv-import', sprintf(__('> Row %s - skipped due to record offset.', 'order-import-export-for-woocommerce'), $row));
150
  unset($item);
151
  return;
152
  }
 
153
  $postmeta = $order = array();
 
154
  if (!$csv_export_file) {
155
  // standard format: optional integer order number and formatted order number
156
  $order_number = (!empty($item['order_number']) ) ? $item['order_number'] : null;
157
  $order_number_formatted = (!empty($item['order_number_formatted']) ) ? $item['order_number_formatted'] : $order_number;
 
158
  $WF_CSV_Order_Import->hf_order_log_data_change('order-csv-import', sprintf(__('> Row %s - preparing for import.', 'order-import-export-for-woocommerce'), $row));
 
 
159
  // validate the supplied formatted order number/order number
160
  if (is_numeric($order_number_formatted) && !$order_number)
161
  $order_number = $order_number_formatted; // use formatted for underlying order number if possible
 
162
  if ($order_number && !is_numeric($order_number)) {
 
163
  $WF_CSV_Order_Import->hf_order_log_data_change('order-csv-import', sprintf(__('> > Skipped. Order number field must be an integer: %s.', 'order-import-export-for-woocommerce'), $order_number));
164
  $skipped++;
165
  unset($item);
166
  return;
167
  }
 
168
  if ($order_number_formatted && !$order_number) {
 
169
  $WF_CSV_Order_Import->hf_order_log_data_change('order-csv-import', __('> > Skipped. Formatted order number provided but no numerical order number, see the documentation for further details.', 'order-import-export-for-woocommerce'));
170
  $skipped++;
171
  unset($item);
175
  $order_number_formatted = !empty($item['order_id']) ? $item['order_id'] : 0;
176
  $order_number = (!empty($item['order_number']) ? $item['order_number'] : ( is_numeric($order_number_formatted) ? $order_number_formatted : 0 ) );
177
  }
 
178
  if ($order_number_formatted) {
179
  // verify that this order number isn't already in use
180
  $query_args = array(
185
  'post_status' => array_keys(wc_get_order_statuses()),
186
  'fields' => 'ids',
187
  );
 
188
  $order_id = 0;
189
  $orders = get_posts($query_args);
190
  if (!empty($orders)) {
191
  list( $order_id ) = get_posts($query_args);
192
  }
 
193
  $order_id = apply_filters('woocommerce_find_order_by_order_number', $order_id, $order_number_formatted);
 
194
  if ($order_id) {
195
  // skip if order ID already exist.
196
  $WF_CSV_Order_Import->hf_order_log_data_change('order-csv-import', sprintf(__('> > Skipped. Order %s already exists.', 'order-import-export-for-woocommerce'), $order_number_formatted));
204
  // attempt to find the customer user
205
  $found_customer = false;
206
  if (is_int($item['customer_id'])) {
 
207
  $found_customer = get_user_by('id', $item['customer_id']);
 
208
  if (!$found_customer) {
 
209
  $WF_CSV_Order_Import->hf_order_log_data_change('order-csv-import', sprintf(__('> > Skipped. Cannot find customer with id %s.', 'order-import-export-for-woocommerce'), $item['customer_id']));
210
  $skipped++;
211
  unset($item);
216
  // check by email
217
  $found_customer = email_exists($item['customer_id']);
218
  }
 
219
  if (!$found_customer) {
220
  $found_customer = username_exists($item['customer_id']);
221
  }
 
222
  if (!$found_customer) {
223
  // guest checkout
224
  $item['customer_id'] = 0;
236
  // guest checkout
237
  $item['customer_id'] = 0;
238
  }
 
 
239
  if (!empty($item['status'])) {
240
  $order['status'] = $item['status'];
241
  $found_status = false;
245
  $found_status = true;
246
  $available_statuses[] = $status_slug;
247
  }
 
248
  if (!$found_status) {
249
  $WF_CSV_Order_Import->hf_order_log_data_change('order-csv-import', sprintf(__('> > Skipped. Unknown order status %s (%s).', 'order-import-export-for-woocommerce'), $item['status'], implode($available_statuses, ', ')));
250
  $skipped++;
252
  return;
253
  }
254
  }
 
255
  if (!empty($item['order_date'])){
256
  $item['date'] = $item['order_date'];
257
  } elseif (isset($item['order_date'])) {
271
  }
272
  $order['date'] = $item['date'];
273
  }
 
 
274
  $order_notes = array();
275
  if (!empty($item['order_notes'])) {
276
  $order_notes = explode("||", $item['order_notes']);
277
  }
 
278
  // build the order data object
279
  $order['order_id'] = !empty($item['order_id']) ? $item['order_id'] : null;
280
  $order['order_comments'] = !empty($item['customer_note']) ? $item['customer_note'] : null;
283
  $order['order_number'] = $order_number; // optional order number, for convenience
284
  if ($order_number_formatted)
285
  $order['order_number_formatted'] = $order_number_formatted;
 
286
  // totals
287
  $order_tax = $order_shipping_tax = null;
 
288
  // Get any known order meta fields, and default any missing ones to 0/null
289
  // the provided shipping/payment method will be used as-is, and if found in the list of available ones, the respective titles will also be set
290
  foreach ($this->order_meta_fields as $column) {
 
291
  switch ($column) {
 
292
  case 'shipping_method':
293
  if(isset($item[$column])){
294
  $value = $item[$column];
 
295
  // look up shipping method by id or title
296
  $shipping_method = isset($available_methods[$value]) ? $value : null;
 
297
  if (!$shipping_method) {
298
  // try by title
299
  foreach ($available_methods as $method) {
303
  }
304
  }
305
  }
 
306
  if ($shipping_method) {
307
  //known shipping method found
308
  $postmeta[] = array('key' => '_shipping_method', 'value' => $shipping_method);
322
  }
323
  }
324
  break;
 
325
  case 'payment_method':
326
  if (isset($item[$column])) {
327
  $value = $item[$column];
 
328
  // look up shipping method by id or title
329
  $payment_method = isset($available_gateways[$value]) ? $value : null;
330
  if (!$payment_method) {
336
  }
337
  }
338
  }
 
339
  if ($payment_method) {
340
  //Known payment method found
341
  $postmeta[] = array('key' => '_payment_method', 'value' => $payment_method);
355
  }
356
  }
357
  break;
 
358
  // handle numerics
359
  case 'order_shipping': // legacy
360
  case 'shipping_total':
397
  $postmeta[] = array('key' => '_' . $column, 'value' => $value);
398
  }
399
  break;
 
400
  case 'Download Permissions Granted':
401
  case 'download_permissions_granted':
402
  if (isset($item['download_permissions_granted'])) {
409
  $postmeta[] = array('key' => '_download_permissions', 'value' => $item['download_permissions']);
410
  }
411
  break;
 
412
  default:
 
413
  if (isset($item[$column])){
414
  $postmeta[] = array('key' => '_' . $column, 'value' => $item[$column]);
415
  }
416
  }
417
  }
 
418
  if (!empty($item['customer_id']))
419
  $postmeta[] = array('key' => '_customer_user', 'value' => $item['customer_id']);
 
420
  $order_shipping_methods = array();
421
  $_shipping_methods = array();
 
422
  // pre WC 2.1 format of a single shipping method, left for backwards compatibility of import files
423
  if (isset($item['shipping_method']) && $item['shipping_method']) {
424
  // collect the shipping method id/cost
427
  isset($item['shipping_cost']) ? $item['shipping_cost'] : null
428
  );
429
  }
 
430
  // collect any additional shipping methods
431
  $i = null;
432
  if (isset($item['shipping_method_1'])) {
434
  } elseif (isset($item['shipping_method_2'])) {
435
  $i = 2;
436
  }
 
437
  if (!is_null($i)) {
438
  while (!empty($item['shipping_method_' . $i])) {
 
439
  $_shipping_methods[] = array(
440
  $item['shipping_method_' . $i],
441
  isset($item['shipping_cost_' . $i]) ? $item['shipping_cost_' . $i] : null
446
 
447
  // if the order shipping total wasn't set, calculate it
448
  if (!isset($order_shipping)) {
 
449
  $order_shipping = 0;
450
  foreach ($_shipping_methods as $_shipping_method) {
451
  $order_shipping += $_shipping_method[1];
455
  // special case: if there was a total order shipping but no cost for the single shipping method, use the total shipping for the order shipping line item
456
  $_shipping_methods[0][1] = $order_shipping;
457
  }
 
458
  foreach ($_shipping_methods as $_shipping_method) {
 
459
  // look up shipping method by id or title
460
  $shipping_method = isset($available_methods[$_shipping_method[0]]) ? $_shipping_method[0] : null;
 
461
  if (!$shipping_method) {
462
  // try by title
463
  foreach ($available_methods as $method) {
467
  }
468
  }
469
  }
 
470
  if ($shipping_method) {
471
  //Known shipping method found
472
  $order_shipping_methods[] = array('method_id' => $shipping_method, 'cost' => $_shipping_method[1], 'title' => $available_methods[$shipping_method]->title);
478
  $order_shipping_methods[] = array('method_id' => $_shipping_method[0], 'cost' => $_shipping_method[1], 'title' => '');
479
  }
480
  }
 
481
  $order_items = array();
482
  if ($csv_export_file) {
483
  // standard format
485
  // one or more order items
486
  $i = 1;
487
  while (isset($item['line_item_' . $i]) && !empty($item['line_item_' . $i])) {
 
488
  // $_item_meta = preg_split("~\\\\.(*SKIP)(*FAIL)|\|~s", $item['line_item_' . $i]);
489
  $_item_meta = array();
490
  if ($item['line_item_' . $i] && empty($_item_meta)) {
495
  $unknown_product_name = $name;
496
  $product_identifier_by_id = array_shift($_item_meta); // product_id:id
497
  $product_identifier_by_sku = array_shift($_item_meta); // sku
 
498
  $qty = array_shift($_item_meta);
499
  $qty = substr($qty, strpos($qty, ":") + 1);
500
  $total = array_shift($_item_meta);
503
  $tax = substr($tax, strpos($tax, ":") + 1);
504
  $tax_data = array_shift($_item_meta);
505
  $tax_data = substr($tax_data, strpos($tax_data, ":") + 1);
 
 
506
  // find by id
507
  if (false !== strpos($product_identifier_by_id, 'product_id:')) {
508
  // product by product_id
512
  if (!in_array(get_post_type($product_id), array('product', 'product_variation'))) {
513
  $product_id = '';
514
  }
515
+ }
 
516
  if (!$product_id) {
517
  // find by sku
518
  $product_sku = substr($product_identifier_by_sku, strpos($product_identifier_by_sku, ":") + 1);
521
  else
522
  $product_id = '';
523
  }
 
524
  if (!$allow_unknown_products && !$product_id) {
525
  // unknown product
526
  $WF_CSV_Order_Import->hf_order_log_data_change('order-csv-import', sprintf(__('> > Skipped. Unknown order item: %s.', 'order-import-export-for-woocommerce'), $product_identifier));
528
  $i++;
529
  continue; // break outer loop
530
  }
 
531
  // get any additional item meta
532
  $item_meta = array();
533
  foreach ($_item_meta as $pair) {
 
534
  // replace any escaped pipes
535
  $pair = str_replace('\|', '|', $pair);
 
536
  // find the first ':' and split into name-value
537
  $split = strpos($pair, ':');
538
  $name = substr($pair, 0, $split);
539
  $value = substr($pair, $split + 1);
 
540
  $item_meta[$name] = $value;
541
  }
542
  $order_items[] = array('product_id' => $product_id, 'qty' => $qty, 'total' => $total,'tax' => $tax, 'tax_data' => $tax_data, 'meta' => $item_meta, 'unknown_product_name' => $unknown_product_name);
 
543
  $i++;
544
  }
545
  }
548
  $sku = $item['item_sku'];
549
  $qty = $item['item_amount'];
550
  $total = $item['row_price'];
 
551
  if (!$sku || !$qty || !is_numeric($total)) {
552
  // invalid item
553
  $WF_CSV_Order_Import->hf_order_log_data_change('order-csv-import', sprintf(__('> > Row %d - %s - skipped. Missing SKU, quantity or total', 'order-import-export-for-woocommerce'), $row, $item['order_id']));
555
  unset($item);
556
  return; // break outer loop
557
  }
 
558
  // find by sku
559
  $product_id = $wpdb->get_var($wpdb->prepare("SELECT post_id FROM $wpdb->postmeta WHERE meta_key='_sku' AND meta_value=%s LIMIT 1", $sku));
 
560
  if (!$product_id) {
561
  // unknown product
562
  $WF_CSV_Order_Import->hf_order_log_data_change('order-csv-import', sprintf(__('> > Row %d - %s - skipped. Unknown order item: %s.', 'order-import-export-for-woocommerce'), $row, $item['order_id'], $sku));
564
  unset($item);
565
  return; // break outer loop
566
  }
 
567
  $order_items[] = array('product_id' => $product_id, 'qty' => $qty, 'total' => $total);
568
  }
 
569
  $tax_items = array();
 
570
  // standard tax item format which supports multiple tax items in numbered columns containing a pipe-delimated, colon-labeled format
571
  if (isset($item['tax_items']) && !empty($item['tax_items'])) {
572
  // one or more order tax items
574
  $tax_item = explode(';', $item['tax_items']);
575
  // $tax_amount_sum = $shipping_tax_amount_sum = 0;
576
  foreach ($tax_item as $tax) {
 
577
  $tax_item_data = array();
 
578
  // turn "label: Tax | tax_amount: 10" into an associative array
579
  foreach (explode('|', $tax) as $piece) {
580
  list( $name, $value ) = explode(':', $piece);
581
  $tax_item_data[trim($name)] = trim($value);
582
  }
 
583
  // default rate id to 0 if not set
584
  if (!isset($tax_item_data['rate_id'])) {
585
  $tax_item_data['rate_id'] = 0;
586
  }
 
587
  // have a tax amount or shipping tax amount
588
  if (isset($tax_item_data['total']) || isset($tax_item_data['shipping_tax_amount'])) {
589
  // try and look up rate id by label if needed
590
  if (isset($tax_item_data['label']) && $tax_item_data['label'] && !$tax_item_data['rate_id']) {
591
  foreach ($tax_rates as $tax_rate) {
 
592
  if (0 === strcasecmp($tax_rate->tax_rate_name, $tax_item_data['label'])) {
593
  // found the tax by label
594
  $tax_item_data['rate_id'] = $tax_rate->tax_rate_id;
596
  }
597
  }
598
  }
 
599
  // check for a rate being specified which does not exist, and clear it out (technically an error?)
600
  if ($tax_item_data['rate_id'] && !isset($tax_rates[$tax_item_data['rate_id']])) {
601
  $tax_item_data['rate_id'] = 0;
602
  }
 
603
  // default label of 'Tax' if not provided
604
  if (!isset($tax_item_data['label']) || !$tax_item_data['label']) {
605
  $tax_item_data['label'] = 'Tax';
606
  }
 
607
  // default tax amounts to 0 if not set
608
  if (!isset($tax_item_data['total'])) {
609
  $tax_item_data['total'] = 0;
611
  if (!isset($tax_item_data['shipping_tax_amount'])) {
612
  $tax_item_data['shipping_tax_amount'] = 0;
613
  }
 
614
  // handle compound flag by using the defined tax rate value (if any)
615
  if (!isset($tax_item_data['tax_rate_compound'])) {
616
  $tax_item_data['tax_rate_compound'] = '';
618
  $tax_item_data['tax_rate_compound'] = $tax_rates[$tax_item_data['rate_id']]->tax_rate_compound;
619
  }
620
  }
 
621
  $tax_items[] = array(
622
  'title' => $tax_item_data['code'],
623
  'rate_id' => $tax_item_data['rate_id'],
626
  'tax_amount' => $tax_item_data['total'],
627
  'shipping_tax_amount' => $tax_item_data['shipping_tax_amount'],
628
  );
 
 
 
 
629
  }
630
  }
 
 
 
 
 
 
 
631
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
632
  // add the order tax totals to the order meta
633
  $postmeta[] = array('key' => '_order_tax', 'value' => number_format((float) $order_tax, 2, '.', ''));
634
  $postmeta[] = array('key' => '_order_shipping_tax', 'value' => number_format((float) $order_shipping_tax, 2, '.', ''));
 
635
  if ($order) {
636
  $order['postmeta'] = $postmeta;
637
  $order['order_items'] = $order_items;
638
  $order['order_shipping'] = $order_shipping_methods;
639
  $order['tax_items'] = $tax_items;
 
640
  // the order array will now contain the necessary name-value pairs for the wp_posts table, and also any meta data in the 'postmeta' array
641
  $results[] = $order;
642
  }
648
  }
649
 
650
  private function wc_get_order_statuses_neat() {
 
651
  $order_statuses = array();
 
652
  foreach (wc_get_order_statuses() as $slug => $name) {
653
  $order_statuses[preg_replace('/^wc-/', '', $slug)] = $name;
654
  }
 
655
  return $order_statuses;
656
  }
 
657
  }
includes/importer/class-wf-orderimpexpcsv-order-import.php CHANGED
@@ -28,7 +28,6 @@ class WF_OrderImpExpCsv_Order_Import extends WP_Importer {
28
  * Constructor
29
  */
30
  public function __construct() {
31
-
32
  if (WC()->version < '2.7.0') {
33
  $this->log = new WC_Logger();
34
  } else {
@@ -102,169 +101,144 @@ class WF_OrderImpExpCsv_Order_Import extends WP_Importer {
102
 
103
  if ($file) {
104
  ?>
105
- <table id="import-progress" class="widefat_importer widefat">
106
  <thead>
107
- <tr> <th class="status">&nbsp;</th>
108
- <th class="row"><?php _e('Row', 'order-import-export-for-woocommerce'); ?></th>
109
- <th><?php _e('OrderID', 'order-import-export-for-woocommerce'); ?></th>
110
- <th><?php _e('Order Status', 'order-import-export-for-woocommerce'); ?></th>
111
- <th class="reason"><?php _e('Status Msg', 'order-import-export-for-woocommerce'); ?></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', 'order-import-export-for-woocommerce'); ?>' + '</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 {
@@ -275,33 +249,23 @@ class WF_OrderImpExpCsv_Order_Import extends WP_Importer {
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-->";
@@ -311,17 +275,13 @@ class WF_OrderImpExpCsv_Order_Import extends WP_Importer {
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
 
@@ -343,7 +303,6 @@ class WF_OrderImpExpCsv_Order_Import extends WP_Importer {
343
  exit;
344
  break;
345
  }
346
-
347
  $this->footer();
348
  }
349
 
@@ -359,25 +318,21 @@ class WF_OrderImpExpCsv_Order_Import extends WP_Importer {
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
  $row = $raw_headers = array();
379
  $header = fgetcsv($handle, 0, $this->delimiter);
380
-
381
  while (( $postmeta = fgetcsv($handle, 0, $this->delimiter) ) !== FALSE) {
382
  foreach ($header as $key => $heading) {
383
  if (!$heading)
@@ -390,9 +345,7 @@ class WF_OrderImpExpCsv_Order_Import extends WP_Importer {
390
  }
391
  fclose($handle);
392
  }
393
-
394
  $merge = (!empty($_GET['merge']) && $_GET['merge']) ? 1 : 0;
395
-
396
  include( 'views/html-wf-import-options.php' );
397
  }
398
 
@@ -401,7 +354,6 @@ class WF_OrderImpExpCsv_Order_Import extends WP_Importer {
401
  */
402
  public function import() {
403
  global $woocommerce, $wpdb;
404
-
405
  wp_suspend_cache_invalidation(true);
406
  $this->hf_order_log_data_change('order-csv-import', '---');
407
  $this->hf_order_log_data_change('order-csv-import', __('Processing orders.', 'order-import-export-for-woocommerce'));
@@ -413,38 +365,27 @@ class WF_OrderImpExpCsv_Order_Import extends WP_Importer {
413
  $this->process_orders($order['shop_order'][0]);
414
  else
415
  $this->add_import_result('failed', $order->get_error_message(), 'Not parsed', json_encode($item), '-');
416
-
417
  unset($item, $order);
418
  }
419
-
420
  $this->hf_order_log_data_change('order-csv-import', __('Finished processing Orders.', 'order-import-export-for-woocommerce'));
421
  wp_suspend_cache_invalidation(false);
422
  }
423
 
424
  /**
425
  * Parses the CSV file and prepares us for the task of processing parsed data
426
- *
427
  * @param string $file Path to the CSV file for importing
428
  */
429
  public function import_start($file, $start_pos, $end_pos) {
430
-
431
  $memory = size_format((WC()->version < '2.7.0') ? woocommerce_let_to_num(ini_get('memory_limit')) : wc_let_to_num(ini_get('memory_limit')));
432
  $wp_memory = size_format((WC()->version < '2.7.0') ? woocommerce_let_to_num(WP_MEMORY_LIMIT) : wc_let_to_num(WP_MEMORY_LIMIT));
433
-
434
  $this->hf_order_log_data_change('order-csv-import', '---[ New Import ] PHP Memory: ' . $memory . ', WP Memory: ' . $wp_memory);
435
  $this->hf_order_log_data_change('order-csv-import', __('Parsing products CSV.', 'order-import-export-for-woocommerce'));
436
-
437
  $this->parser = new WF_CSV_Parser('shop_order');
438
-
439
  list( $this->parsed_data, $this->raw_headers, $position ) = $this->parser->parse_data($file, $this->delimiter, $start_pos, $end_pos);
440
-
441
  $this->hf_order_log_data_change('order-csv-import', __('Finished parsing products CSV.', 'order-import-export-for-woocommerce'));
442
-
443
  unset($import_data);
444
-
445
  wp_defer_term_counting(true);
446
  wp_defer_comment_counting(true);
447
-
448
  return $position;
449
  }
450
 
@@ -452,51 +393,40 @@ class WF_OrderImpExpCsv_Order_Import extends WP_Importer {
452
  * Performs post-import cleanup of files and the cache
453
  */
454
  public function import_end() {
455
-
456
  //wp_cache_flush(); Stops output in some hosting environments
457
  foreach (get_taxonomies() as $tax) {
458
  delete_option("{$tax}_children");
459
  _get_term_hierarchy($tax);
460
  }
461
-
462
  wp_defer_term_counting(false);
463
  wp_defer_comment_counting(false);
464
-
465
  do_action('import_end');
466
  }
467
 
468
  /**
469
  * Handles the CSV upload and initial parsing of the file to prepare for
470
  * displaying author import options
471
- *
472
  * @return bool False if error uploading or invalid file, true otherwise
473
  */
474
  public function handle_upload() {
475
  if (empty($_POST['file_url'])) {
476
-
477
  $file = wp_import_handle_upload();
478
-
479
  if (isset($file['error'])) {
480
  echo '<p><strong>' . __('Sorry, there has been an error.', 'order-import-export-for-woocommerce') . '</strong><br />';
481
  echo esc_html($file['error']) . '</p>';
482
  return false;
483
  }
484
-
485
  $this->id = (int) $file['id'];
486
  return true;
487
  } else {
488
-
489
  if (file_exists(ABSPATH . $_POST['file_url'])) {
490
-
491
  $this->file_url = esc_attr($_POST['file_url']);
492
  return true;
493
  } else {
494
-
495
  echo '<p><strong>' . __('Sorry, there has been an error.', 'order-import-export-for-woocommerce') . '</strong></p>';
496
  return false;
497
  }
498
  }
499
-
500
  return false;
501
  }
502
 
@@ -536,7 +466,6 @@ class WF_OrderImpExpCsv_Order_Import extends WP_Importer {
536
  $this->hf_order_log_data_change('order-csv-import', __('Processing orders.', 'order-import-export-for-woocommerce'));
537
 
538
  // check class-wc-checkout.php for reference
539
-
540
  $order_data = array(
541
  'import_id' => $post['order_id'], //Suggest import to keep the given ID
542
  'post_type' => 'shop_order',
@@ -556,22 +485,20 @@ class WF_OrderImpExpCsv_Order_Import extends WP_Importer {
556
  $order_data['post_excerpt'] = $post['order_comments'];
557
  }
558
 
559
-
560
  if (!$dry_run) {
561
  // track whether download permissions need to be granted
562
  $add_download_permissions = false;
563
 
564
-
565
  // Check if post exists when importing
566
  $new_added = false;
567
- $is_order_exist = $this->order_exists($post['order_id']);
 
568
  $meta_array = array();
569
  if (!empty($post['postmeta'])) {
570
  foreach ($post['postmeta'] as $meta) {
571
  $meta_array[$meta['key']] = $meta['value'];
572
  }
573
  }
574
-
575
  $user_id = $this->hf_check_customer($meta_array);
576
  if (is_wp_error($user_id)) {
577
  $this->hf_order_log_data_change('order-csv-import', __($user_id->get_error_message(), 'order-import-export-for-woocommerce'));
@@ -582,17 +509,21 @@ class WF_OrderImpExpCsv_Order_Import extends WP_Importer {
582
  } elseif (empty($user_id)) {
583
  $user_id = 0;
584
  }
585
-
586
-
 
 
 
 
 
587
  if (!$merging && $is_order_exist) {
588
- $usr_msg = 'Order already exists.';
589
- $this->add_import_result('skipped', __($usr_msg, 'order-import-export-for-woocommerce'), $post['order_number'], $order_data['post_title'], $post['order_number']);
590
  $this->hf_order_log_data_change('order-csv-import', sprintf(__('> &#8220;%s&#8221;' . $usr_msg, 'order-import-export-for-woocommerce'), esc_html($order_data['post_title'])), true);
591
  unset($post);
592
  return;
593
  } else {
594
  if ($is_order_exist) {
595
- $order_id = $post['order_id'];
596
  $order_data['ID'] = $order_id;
597
  $wp_result = wp_update_post($order_data);
598
  } else {
@@ -617,28 +548,23 @@ class WF_OrderImpExpCsv_Order_Import extends WP_Importer {
617
  // add order postmeta
618
  foreach ($post['postmeta'] as $meta) {
619
  $meta_processed = false;
620
-
621
  // we don't set the "download permissions granted" meta, we call the woocommerce function to take care of this for us
622
  if (( 'Download Permissions Granted' == $meta['key'] || '_download_permissions_granted' == $meta['key'] ) && $meta['value']) {
623
  $add_download_permissions = true;
624
  $meta_processed = true;
625
  }
626
-
627
  if (( '_customer_user' == $meta['key'])) {
628
  update_post_meta($order_id, $meta['key'], $user_id);
629
  $meta_processed = true;
630
  }
631
-
632
  if (!$meta_processed) {
633
  update_post_meta($order_id, $meta['key'], $meta['value']);
634
  }
635
-
636
  // set the paying customer flag on the user meta if applicable
637
  if ('_customer_id' == $meta['key'] && $user_id && in_array($post['status'], array('processing', 'completed', 'refunded'))) {
638
  update_user_meta($user_id, "paying_customer", 1);
639
  }
640
  }
641
-
642
 
643
  // handle order items
644
  $order_items = array();
@@ -652,13 +578,10 @@ class WF_OrderImpExpCsv_Order_Import extends WP_Importer {
652
  $order = wc_get_order($order_id);
653
 
654
  foreach ($post['order_items'] as $item) {
655
-
656
  $product = null;
657
  $variation_item_meta = array();
658
-
659
  if ($item['product_id']) {
660
  $product = wc_get_product($item['product_id']);
661
-
662
  // handle variations
663
  if ($product && ( $product->is_type('variable') || $product->is_type('variation') || $product->is_type('subscription_variation') ) && method_exists($product, 'get_variation_id')) {
664
  foreach ($product->get_variation_attributes() as $key => $value) {
@@ -693,21 +616,17 @@ class WF_OrderImpExpCsv_Order_Import extends WP_Importer {
693
  '_line_tax' => number_format((float) $item['tax'], 2, '.', ''), // Line Tax (after discounts)
694
  '_line_tax_data' => $item['tax_data'],
695
  );
696
-
697
  // add any product variation meta
698
  foreach ($variation_item_meta as $meta) {
699
  $_order_item_meta[$meta['meta_name']] = $meta['meta_value'];
700
  }
701
-
702
  // include any arbitrary order item meta
703
  $_order_item_meta = array_merge($_order_item_meta, $item['meta']);
704
-
705
  $order_item_meta[] = $_order_item_meta;
706
  }
707
 
708
  foreach ($order_items as $key => $order_item) {
709
  $order_item_id = wc_add_order_item($order_id, $order_item);
710
-
711
  if ($order_item_id) {
712
  foreach ($order_item_meta[$key] as $meta_key => $meta_value) {
713
  wc_add_order_item_meta($order_item_id, $meta_key, $meta_value);
@@ -717,14 +636,11 @@ class WF_OrderImpExpCsv_Order_Import extends WP_Importer {
717
 
718
  // create the shipping order items
719
  foreach ($post['order_shipping'] as $order_shipping) {
720
-
721
  $shipping_order_item = array(
722
  'order_item_name' => ($order_shipping['title']) ? $order_shipping['title'] : $order_shipping['method_id'],
723
  'order_item_type' => 'shipping',
724
  );
725
-
726
  $shipping_order_item_id = wc_add_order_item($order_id, $shipping_order_item);
727
-
728
  if ($shipping_order_item_id) {
729
  wc_add_order_item_meta($shipping_order_item_id, 'method_id', $order_shipping['method_id']);
730
  wc_add_order_item_meta($shipping_order_item_id, 'cost', $order_shipping['cost']);
@@ -738,7 +654,6 @@ class WF_OrderImpExpCsv_Order_Import extends WP_Importer {
738
  $wpdb->query($wpdb->prepare("DELETE items,itemmeta FROM {$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, $tax_str));
739
  }
740
  foreach ($post['tax_items'] as $tax_item) {
741
-
742
  $tax_order_item = array(
743
  'order_item_name' => $tax_item['title'],
744
  'order_item_type' => 'tax',
@@ -812,24 +727,17 @@ class WF_OrderImpExpCsv_Order_Import extends WP_Importer {
812
  $this->hf_order_log_data_change('order-csv-import', sprintf(__('> &#8220;%s&#8221;' . $out_msg, 'order-import-export-for-woocommerce'), esc_html($order_id)), true);
813
  $this->imported++;
814
  $this->hf_order_log_data_change('order-csv-import', sprintf(__('> Finished importing order %s', 'order-import-export-for-woocommerce'), $dry_run ? "" : $order->get_order_number() ));
815
-
816
  // }
817
-
818
-
819
  $this->hf_order_log_data_change('order-csv-import', __('Finished processing orders.', 'order-import-export-for-woocommerce'));
820
 
821
  unset($post);
822
  }
823
 
824
  public function hf_check_customer($data) {
825
-
826
  $customer_email = (!empty($data['_customer_email']) ) ? $data['_customer_email'] : '';
827
-
828
  $found_customer = false;
829
  $username = '';
830
-
831
  if (!empty($customer_email)) {
832
-
833
  if (is_email($customer_email) && false !== email_exists($customer_email)) {
834
  $found_customer = email_exists($customer_email);
835
  return $found_customer;
@@ -839,7 +747,6 @@ class WF_OrderImpExpCsv_Order_Import extends WP_Importer {
839
  } else {
840
  $found_customer = 0;
841
  }
842
-
843
  return $found_customer;
844
  }
845
 
@@ -868,7 +775,7 @@ class WF_OrderImpExpCsv_Order_Import extends WP_Importer {
868
 
869
  // Display import page title
870
  public function header() {
871
- echo '<div class="wrap"><div class="icon32" id="icon-woocommerce-importer"><br></div>';
872
  echo '<h2>' . ( empty($_GET['merge']) ? __('Import', 'order-import-export-for-woocommerce') : __('Merge Orders', 'order-import-export-for-woocommerce') ) . '</h2>';
873
  }
874
 
@@ -904,5 +811,4 @@ class WF_OrderImpExpCsv_Order_Import extends WP_Importer {
904
  $this->log->log("debug", $data, $context);
905
  }
906
  }
907
-
908
  }
28
  * Constructor
29
  */
30
  public function __construct() {
 
31
  if (WC()->version < '2.7.0') {
32
  $this->log = new WC_Logger();
33
  } else {
101
 
102
  if ($file) {
103
  ?>
104
+ <table id="import-progress" class="widefat_importer widefat">
105
  <thead>
106
+ <tr>
107
+ <th class="status">&nbsp;</th>
108
+ <th class="row"><?php _e('Row', 'order-import-export-for-woocommerce'); ?></th>
109
+ <th><?php _e('OrderID', 'order-import-export-for-woocommerce'); ?></th>
110
+ <th><?php _e('Order Status', 'order-import-export-for-woocommerce'); ?></th>
111
+ <th class="reason"><?php _e('Status Msg', 'order-import-export-for-woocommerce'); ?></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
+ if (! window.console) { window.console = function(){}; }
124
+ var processed_terms = [];
125
+ var processed_posts = [];
126
+ var i = 1;
127
+ var done_count = 0;
128
+ function import_rows(start_pos, end_pos) {
129
+ var data = {
130
+ action: 'woocommerce_csv_order_import_request',
131
+ file: '<?php echo addslashes($file); ?>',
132
+ delimiter: '<?php echo $this->delimiter; ?>',
133
+ merge_empty_cells: '<?php echo $this->merge_empty_cells; ?>',
134
+ start_pos: start_pos,
135
+ end_pos: end_pos,
136
+ };
137
+ return $.ajax({
138
+ 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')); ?>',
139
+ data: data,
140
+ type: 'POST',
141
+ success: function(response) {
142
+ if (response) {
143
+ try {
144
+ // Get the valid JSON only from the returned string
145
+ if (response.indexOf("<!--WC_START-->") >= 0)
146
+ response = response.split("<!--WC_START-->")[1]; // Strip off before after WC_START
147
+ if (response.indexOf("<!--WC_END-->") >= 0)
148
+ response = response.split("<!--WC_END-->")[0]; // Strip off anything after WC_END
 
 
 
 
 
149
  // Parse
150
  var results = $.parseJSON(response);
151
  if (results.error) {
152
+ $('#import-progress tbody').append('<tr id="row-' + i + '" class="error"><td class="status" colspan="5">' + results.error + '</td></tr>');
153
+ i++;
154
+ } else if (results.import_results && $(results.import_results).size() > 0) {
155
+ $.each(results.processed_terms, function(index, value) {
156
+ processed_terms.push(value);
157
+ });
158
+ $.each(results.processed_posts, function(index, value) {
159
+ processed_posts.push(value);
160
+ });
161
+ $(results.import_results).each(function(index, row) {
162
+ $('#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>');
163
+ i++;
164
+ });
165
+ }
166
+ } catch (err) {}
167
+ } else {
168
+ $('#import-progress tbody').append('<tr class="error"><td class="status" colspan="5">' + '<?php _e('AJAX Error', 'order-import-export-for-woocommerce'); ?>' + '</td></tr>');
169
+ }
170
+ var w = $(window);
171
+ var row = $("#row-" + (i - 1));
172
+ if (row.length) {
173
+ w.scrollTop(row.offset().top - (w.height() / 2));
174
+ }
175
+ done_count++;
176
+ $('body').trigger('woocommerce_csv_order_import_request_complete');
177
+ }
178
+ });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
179
  }
180
+ var rows = [];
181
+ <?php
182
+ $limit = apply_filters('woocommerce_csv_import_limit_per_request', 10);
183
+ $enc = mb_detect_encoding($file, 'UTF-8, ISO-8859-1', true);
184
+ if ($enc)
185
+ setlocale(LC_ALL, 'en_US.' . $enc);
186
+ @ini_set('auto_detect_line_endings', true);
187
+ $count = 0;
188
+ $previous_position = 0;
189
+ $position = 0;
190
+ $import_count = 0;
191
+ // Get CSV positions
192
+ if (( $handle = fopen($file, "r") ) !== FALSE) {
193
+ while (( $postmeta = fgetcsv($handle, 0, $this->delimiter) ) !== FALSE) {
194
+ $count++;
195
+ if ($count >= $limit) {
196
+ $previous_position = $position;
197
+ $position = ftell($handle);
198
+ $count = 0;
199
+ $import_count ++;
200
+ // Import rows between $previous_position $position
201
+ ?>rows.push( [ <?php echo $previous_position; ?>, <?php echo $position; ?> ] ); <?php
202
+ }
203
+ }
204
+ // Remainder
205
+ if ($count > 0) {
206
+ ?>rows.push( [ <?php echo $position; ?>, '' ] ); <?php
207
+ $import_count ++;
208
+ }
209
+ fclose($handle);
210
+ }
211
+ ?>
212
+ var data = rows.shift();
213
+ var regen_count = 0;
214
+ import_rows( data[0], data[1] );
215
+ $('body').on( 'woocommerce_csv_order_import_request_complete', function() {
216
+ if ( done_count == <?php echo $import_count; ?> ) {
217
+ import_done();
218
+ } else {
219
+ // Call next request
220
+ data = rows.shift();
221
  import_rows( data[0], data[1] );
222
+ }
223
+ } );
224
+ function import_done() {
225
+ var data = {
226
+ action: 'woocommerce_csv_order_import_request',
227
+ file: '<?php echo $file; ?>',
228
+ processed_terms: processed_terms,
229
+ processed_posts: processed_posts,
230
+ };
231
+ $.ajax({
232
+ 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')); ?>',
233
+ data: data,
234
+ type: 'POST',
235
+ success: function( response ) {
236
+ $('#import-progress tbody').append( '<tr class="complete"><td colspan="5">' + response + '</td></tr>' );
237
+ $('.importer-loading').hide();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
238
  }
239
+ });
240
+ }
241
+ });
242
  </script>
243
  <?php
244
  } else {
249
  // Check access - cannot use nonce here as it will expire after multiple requests
250
  if (!current_user_can('manage_woocommerce'))
251
  die();
 
252
  add_filter('http_request_timeout', array($this, 'bump_request_timeout'));
 
253
  if (function_exists('gc_enable'))
254
  gc_enable();
 
255
  @set_time_limit(0);
256
  @ob_flush();
257
  @flush();
258
  $wpdb->hide_errors();
 
259
  $file = stripslashes($_POST['file']);
 
260
  $start_pos = isset($_POST['start_pos']) ? absint($_POST['start_pos']) : 0;
261
  $end_pos = isset($_POST['end_pos']) ? absint($_POST['end_pos']) : '';
 
 
 
262
  $position = $this->import_start($file, $start_pos, $end_pos);
263
  $this->import();
264
  $this->import_end();
 
265
  $results = array();
266
  $results['import_results'] = $this->import_results;
267
  $results['processed_terms'] = $this->processed_terms;
268
  $results['processed_posts'] = $this->processed_posts;
 
269
  echo "<!--WC_START-->";
270
  echo json_encode($results);
271
  echo "<!--WC_END-->";
275
  // Check access - cannot use nonce here as it will expire after multiple requests
276
  if (!current_user_can('manage_woocommerce'))
277
  die();
 
278
  add_filter('http_request_timeout', array($this, 'bump_request_timeout'));
 
279
  if (function_exists('gc_enable'))
280
  gc_enable();
 
281
  @set_time_limit(0);
282
  @ob_flush();
283
  @flush();
284
  $wpdb->hide_errors();
 
285
  $this->processed_terms = isset($_POST['processed_terms']) ? $_POST['processed_terms'] : array();
286
  $this->processed_posts = isset($_POST['processed_posts']) ? $_POST['processed_posts'] : array();
287
 
303
  exit;
304
  break;
305
  }
 
306
  $this->footer();
307
  }
308
 
318
  */
319
  public function import_options() {
320
  $j = 0;
 
321
  if ($this->id)
322
  $file = get_attached_file($this->id);
323
  else if ($this->file_url_import_enabled)
324
  $file = ABSPATH . $this->file_url;
325
  else
326
  return;
 
327
  // Set locale
328
  $enc = mb_detect_encoding($file, 'UTF-8, ISO-8859-1', true);
329
  if ($enc)
330
  setlocale(LC_ALL, 'en_US.' . $enc);
331
  @ini_set('auto_detect_line_endings', true);
 
332
  // Get headers
333
  if (( $handle = fopen($file, "r") ) !== FALSE) {
334
  $row = $raw_headers = array();
335
  $header = fgetcsv($handle, 0, $this->delimiter);
 
336
  while (( $postmeta = fgetcsv($handle, 0, $this->delimiter) ) !== FALSE) {
337
  foreach ($header as $key => $heading) {
338
  if (!$heading)
345
  }
346
  fclose($handle);
347
  }
 
348
  $merge = (!empty($_GET['merge']) && $_GET['merge']) ? 1 : 0;
 
349
  include( 'views/html-wf-import-options.php' );
350
  }
351
 
354
  */
355
  public function import() {
356
  global $woocommerce, $wpdb;
 
357
  wp_suspend_cache_invalidation(true);
358
  $this->hf_order_log_data_change('order-csv-import', '---');
359
  $this->hf_order_log_data_change('order-csv-import', __('Processing orders.', 'order-import-export-for-woocommerce'));
365
  $this->process_orders($order['shop_order'][0]);
366
  else
367
  $this->add_import_result('failed', $order->get_error_message(), 'Not parsed', json_encode($item), '-');
 
368
  unset($item, $order);
369
  }
 
370
  $this->hf_order_log_data_change('order-csv-import', __('Finished processing Orders.', 'order-import-export-for-woocommerce'));
371
  wp_suspend_cache_invalidation(false);
372
  }
373
 
374
  /**
375
  * Parses the CSV file and prepares us for the task of processing parsed data
 
376
  * @param string $file Path to the CSV file for importing
377
  */
378
  public function import_start($file, $start_pos, $end_pos) {
 
379
  $memory = size_format((WC()->version < '2.7.0') ? woocommerce_let_to_num(ini_get('memory_limit')) : wc_let_to_num(ini_get('memory_limit')));
380
  $wp_memory = size_format((WC()->version < '2.7.0') ? woocommerce_let_to_num(WP_MEMORY_LIMIT) : wc_let_to_num(WP_MEMORY_LIMIT));
 
381
  $this->hf_order_log_data_change('order-csv-import', '---[ New Import ] PHP Memory: ' . $memory . ', WP Memory: ' . $wp_memory);
382
  $this->hf_order_log_data_change('order-csv-import', __('Parsing products CSV.', 'order-import-export-for-woocommerce'));
 
383
  $this->parser = new WF_CSV_Parser('shop_order');
 
384
  list( $this->parsed_data, $this->raw_headers, $position ) = $this->parser->parse_data($file, $this->delimiter, $start_pos, $end_pos);
 
385
  $this->hf_order_log_data_change('order-csv-import', __('Finished parsing products CSV.', 'order-import-export-for-woocommerce'));
 
386
  unset($import_data);
 
387
  wp_defer_term_counting(true);
388
  wp_defer_comment_counting(true);
 
389
  return $position;
390
  }
391
 
393
  * Performs post-import cleanup of files and the cache
394
  */
395
  public function import_end() {
 
396
  //wp_cache_flush(); Stops output in some hosting environments
397
  foreach (get_taxonomies() as $tax) {
398
  delete_option("{$tax}_children");
399
  _get_term_hierarchy($tax);
400
  }
 
401
  wp_defer_term_counting(false);
402
  wp_defer_comment_counting(false);
 
403
  do_action('import_end');
404
  }
405
 
406
  /**
407
  * Handles the CSV upload and initial parsing of the file to prepare for
408
  * displaying author import options
 
409
  * @return bool False if error uploading or invalid file, true otherwise
410
  */
411
  public function handle_upload() {
412
  if (empty($_POST['file_url'])) {
 
413
  $file = wp_import_handle_upload();
 
414
  if (isset($file['error'])) {
415
  echo '<p><strong>' . __('Sorry, there has been an error.', 'order-import-export-for-woocommerce') . '</strong><br />';
416
  echo esc_html($file['error']) . '</p>';
417
  return false;
418
  }
 
419
  $this->id = (int) $file['id'];
420
  return true;
421
  } else {
 
422
  if (file_exists(ABSPATH . $_POST['file_url'])) {
 
423
  $this->file_url = esc_attr($_POST['file_url']);
424
  return true;
425
  } else {
 
426
  echo '<p><strong>' . __('Sorry, there has been an error.', 'order-import-export-for-woocommerce') . '</strong></p>';
427
  return false;
428
  }
429
  }
 
430
  return false;
431
  }
432
 
466
  $this->hf_order_log_data_change('order-csv-import', __('Processing orders.', 'order-import-export-for-woocommerce'));
467
 
468
  // check class-wc-checkout.php for reference
 
469
  $order_data = array(
470
  'import_id' => $post['order_id'], //Suggest import to keep the given ID
471
  'post_type' => 'shop_order',
485
  $order_data['post_excerpt'] = $post['order_comments'];
486
  }
487
 
 
488
  if (!$dry_run) {
489
  // track whether download permissions need to be granted
490
  $add_download_permissions = false;
491
 
 
492
  // Check if post exists when importing
493
  $new_added = false;
494
+ $order_id = $post['order_id'];
495
+ $is_order_exist = $this->order_exists($order_id);
496
  $meta_array = array();
497
  if (!empty($post['postmeta'])) {
498
  foreach ($post['postmeta'] as $meta) {
499
  $meta_array[$meta['key']] = $meta['value'];
500
  }
501
  }
 
502
  $user_id = $this->hf_check_customer($meta_array);
503
  if (is_wp_error($user_id)) {
504
  $this->hf_order_log_data_change('order-csv-import', __($user_id->get_error_message(), 'order-import-export-for-woocommerce'));
509
  } elseif (empty($user_id)) {
510
  $user_id = 0;
511
  }
512
+ if ($order_id && is_string(get_post_status($order_id)) && (get_post_type($order_id) !== 'shop_order' )){
513
+ $usr_msg = 'Importing order(ID) conflicts with an existing post.';
514
+ $this->add_import_result('skipped', __($usr_msg, 'order-import-export-for-woocommerce'), $order_id, get_the_title($order_id));
515
+ $this->hf_order_log_data_change('order-csv-import', __('> &#8220;%s&#8221;' . $usr_msg, 'order-import-export-for-woocommerce'), esc_html($order_id), true);
516
+ unset($post);
517
+ return;
518
+ }
519
  if (!$merging && $is_order_exist) {
520
+ $usr_msg = 'Order with same ID already exists.';
521
+ $this->add_import_result('skipped', __($usr_msg, 'order-import-export-for-woocommerce'), $order_id, $order_data['post_title'], $order_id);
522
  $this->hf_order_log_data_change('order-csv-import', sprintf(__('> &#8220;%s&#8221;' . $usr_msg, 'order-import-export-for-woocommerce'), esc_html($order_data['post_title'])), true);
523
  unset($post);
524
  return;
525
  } else {
526
  if ($is_order_exist) {
 
527
  $order_data['ID'] = $order_id;
528
  $wp_result = wp_update_post($order_data);
529
  } else {
548
  // add order postmeta
549
  foreach ($post['postmeta'] as $meta) {
550
  $meta_processed = false;
 
551
  // we don't set the "download permissions granted" meta, we call the woocommerce function to take care of this for us
552
  if (( 'Download Permissions Granted' == $meta['key'] || '_download_permissions_granted' == $meta['key'] ) && $meta['value']) {
553
  $add_download_permissions = true;
554
  $meta_processed = true;
555
  }
 
556
  if (( '_customer_user' == $meta['key'])) {
557
  update_post_meta($order_id, $meta['key'], $user_id);
558
  $meta_processed = true;
559
  }
 
560
  if (!$meta_processed) {
561
  update_post_meta($order_id, $meta['key'], $meta['value']);
562
  }
 
563
  // set the paying customer flag on the user meta if applicable
564
  if ('_customer_id' == $meta['key'] && $user_id && in_array($post['status'], array('processing', 'completed', 'refunded'))) {
565
  update_user_meta($user_id, "paying_customer", 1);
566
  }
567
  }
 
568
 
569
  // handle order items
570
  $order_items = array();
578
  $order = wc_get_order($order_id);
579
 
580
  foreach ($post['order_items'] as $item) {
 
581
  $product = null;
582
  $variation_item_meta = array();
 
583
  if ($item['product_id']) {
584
  $product = wc_get_product($item['product_id']);
 
585
  // handle variations
586
  if ($product && ( $product->is_type('variable') || $product->is_type('variation') || $product->is_type('subscription_variation') ) && method_exists($product, 'get_variation_id')) {
587
  foreach ($product->get_variation_attributes() as $key => $value) {
616
  '_line_tax' => number_format((float) $item['tax'], 2, '.', ''), // Line Tax (after discounts)
617
  '_line_tax_data' => $item['tax_data'],
618
  );
 
619
  // add any product variation meta
620
  foreach ($variation_item_meta as $meta) {
621
  $_order_item_meta[$meta['meta_name']] = $meta['meta_value'];
622
  }
 
623
  // include any arbitrary order item meta
624
  $_order_item_meta = array_merge($_order_item_meta, $item['meta']);
 
625
  $order_item_meta[] = $_order_item_meta;
626
  }
627
 
628
  foreach ($order_items as $key => $order_item) {
629
  $order_item_id = wc_add_order_item($order_id, $order_item);
 
630
  if ($order_item_id) {
631
  foreach ($order_item_meta[$key] as $meta_key => $meta_value) {
632
  wc_add_order_item_meta($order_item_id, $meta_key, $meta_value);
636
 
637
  // create the shipping order items
638
  foreach ($post['order_shipping'] as $order_shipping) {
 
639
  $shipping_order_item = array(
640
  'order_item_name' => ($order_shipping['title']) ? $order_shipping['title'] : $order_shipping['method_id'],
641
  'order_item_type' => 'shipping',
642
  );
 
643
  $shipping_order_item_id = wc_add_order_item($order_id, $shipping_order_item);
 
644
  if ($shipping_order_item_id) {
645
  wc_add_order_item_meta($shipping_order_item_id, 'method_id', $order_shipping['method_id']);
646
  wc_add_order_item_meta($shipping_order_item_id, 'cost', $order_shipping['cost']);
654
  $wpdb->query($wpdb->prepare("DELETE items,itemmeta FROM {$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, $tax_str));
655
  }
656
  foreach ($post['tax_items'] as $tax_item) {
 
657
  $tax_order_item = array(
658
  'order_item_name' => $tax_item['title'],
659
  'order_item_type' => 'tax',
727
  $this->hf_order_log_data_change('order-csv-import', sprintf(__('> &#8220;%s&#8221;' . $out_msg, 'order-import-export-for-woocommerce'), esc_html($order_id)), true);
728
  $this->imported++;
729
  $this->hf_order_log_data_change('order-csv-import', sprintf(__('> Finished importing order %s', 'order-import-export-for-woocommerce'), $dry_run ? "" : $order->get_order_number() ));
 
730
  // }
 
 
731
  $this->hf_order_log_data_change('order-csv-import', __('Finished processing orders.', 'order-import-export-for-woocommerce'));
732
 
733
  unset($post);
734
  }
735
 
736
  public function hf_check_customer($data) {
 
737
  $customer_email = (!empty($data['_customer_email']) ) ? $data['_customer_email'] : '';
 
738
  $found_customer = false;
739
  $username = '';
 
740
  if (!empty($customer_email)) {
 
741
  if (is_email($customer_email) && false !== email_exists($customer_email)) {
742
  $found_customer = email_exists($customer_email);
743
  return $found_customer;
747
  } else {
748
  $found_customer = 0;
749
  }
 
750
  return $found_customer;
751
  }
752
 
775
 
776
  // Display import page title
777
  public function header() {
778
+ echo '<div><div class="icon32" id="icon-woocommerce-importer"><br></div>';
779
  echo '<h2>' . ( empty($_GET['merge']) ? __('Import', 'order-import-export-for-woocommerce') : __('Merge Orders', 'order-import-export-for-woocommerce') ) . '</h2>';
780
  }
781
 
811
  $this->log->log("debug", $data, $context);
812
  }
813
  }
 
814
  }
includes/importer/views-coupon/html-wf-import-greeting.php CHANGED
@@ -9,7 +9,7 @@
9
  </h2>
10
  <div class="orderimpexp-main-box">
11
  <div class="tool-box bg-white p-20p orderimpexp-view">
12
- <p><?php _e( 'You can import coupons (in CSV format) in to the shop using below methods.', 'order-import-export-for-woocommerce' ); ?></p>
13
 
14
  <?php if ( ! empty( $upload_dir['error'] ) ) : ?>
15
  <div class="error"><p><?php _e('Before you can upload your import file, you will need to fix the following error:'); ?></p>
@@ -25,8 +25,8 @@
25
  <td>
26
  <input type="file" id="upload" name="import" size="25" />
27
  <input type="hidden" name="action" value="save" />
28
- <input type="hidden" name="max_file_size" value="<?php echo $bytes; ?>" />
29
- <small><?php printf( __('Maximum size: %s' ), $size ); ?></small>
30
  </td>
31
  </tr>
32
 
9
  </h2>
10
  <div class="orderimpexp-main-box">
11
  <div class="tool-box bg-white p-20p orderimpexp-view">
12
+ <p><?php _e( 'You can import coupons (in CSV format) in to the shop by uploading a CSV file.', 'order-import-export-for-woocommerce' ); ?></p>
13
 
14
  <?php if ( ! empty( $upload_dir['error'] ) ) : ?>
15
  <div class="error"><p><?php _e('Before you can upload your import file, you will need to fix the following error:'); ?></p>
25
  <td>
26
  <input type="file" id="upload" name="import" size="25" />
27
  <input type="hidden" name="action" value="save" />
28
+ <input type="hidden" name="max_file_size" value="<?php echo $bytes; ?>" /><br>
29
+ <small><?php _e('Please upload UTF-8 encoded CSV', 'order-import-export-for-woocommerce'); ?> &nbsp; -- &nbsp; <?php printf( __('Maximum size: %s' ), $size ); ?></small>
30
  </td>
31
  </tr>
32
 
includes/importer/views/html-wf-import-greeting.php CHANGED
@@ -1,4 +1,4 @@
1
- <div class="wrap woocommerce">
2
  <div class="icon32" id="icon-woocommerce-importer"><br></div>
3
  <h2 class="nav-tab-wrapper woo-nav-tab-wrapper">
4
  <a href="<?php echo admin_url('admin.php?page=wf_woocommerce_order_im_ex') ?>" class="nav-tab nav-tab-active"><?php _e('Order Import / Export', 'order-import-export-for-woocommerce'); ?></a>
@@ -9,7 +9,7 @@
9
  </h2>
10
  <div class="orderimpexp-main-box">
11
  <div class="tool-box bg-white p-20p orderimpexp-view">
12
- <p><?php _e('You can import orders (in CSV format) in to the shop using below methods.', 'order-import-export-for-woocommerce'); ?></p>
13
 
14
  <?php if (!empty($upload_dir['error'])) : ?>
15
  <div class="error"><p><?php _e('Before you can upload your import file, you will need to fix the following error:'); ?></p>
@@ -25,11 +25,10 @@
25
  <td>
26
  <input type="file" id="upload" name="import" size="25" />
27
  <input type="hidden" name="action" value="save" />
28
- <input type="hidden" name="max_file_size" value="<?php echo $bytes; ?>" />
29
- <small><?php printf(__('Maximum size: %s'), $size); ?></small>
30
  </td>
31
  </tr>
32
-
33
  </tbody>
34
  </table>
35
  <p class="submit">
1
+ <div class="woocommerce">
2
  <div class="icon32" id="icon-woocommerce-importer"><br></div>
3
  <h2 class="nav-tab-wrapper woo-nav-tab-wrapper">
4
  <a href="<?php echo admin_url('admin.php?page=wf_woocommerce_order_im_ex') ?>" class="nav-tab nav-tab-active"><?php _e('Order Import / Export', 'order-import-export-for-woocommerce'); ?></a>
9
  </h2>
10
  <div class="orderimpexp-main-box">
11
  <div class="tool-box bg-white p-20p orderimpexp-view">
12
+ <p><?php _e('You can import orders (in CSV format) in to the shop by uploading a CSV file.', 'order-import-export-for-woocommerce'); ?></p>
13
 
14
  <?php if (!empty($upload_dir['error'])) : ?>
15
  <div class="error"><p><?php _e('Before you can upload your import file, you will need to fix the following error:'); ?></p>
25
  <td>
26
  <input type="file" id="upload" name="import" size="25" />
27
  <input type="hidden" name="action" value="save" />
28
+ <input type="hidden" name="max_file_size" value="<?php echo $bytes; ?>" /><br>
29
+ <small><?php _e('Please upload UTF-8 encoded CSV', 'order-import-export-for-woocommerce'); ?> &nbsp; -- &nbsp; <?php printf(__('Maximum size: %s'), $size); ?></small>
30
  </td>
31
  </tr>
 
32
  </tbody>
33
  </table>
34
  <p class="submit">
includes/importer/views/html-wf-import-options.php CHANGED
@@ -1,5 +1,5 @@
1
  <?php $tab = (isset($_GET['tab'])?$_GET['tab']:'import'); ?>
2
- <div class="wrap woocommerce">
3
  <div class="icon32" id="icon-woocommerce-importer"><br></div>
4
  <h2 class="nav-tab-wrapper woo-nav-tab-wrapper">
5
  <a href="<?php echo admin_url('admin.php?page=wf_woocommerce_order_im_ex') ?>" class="nav-tab <?php echo ($tab == 'import') ? 'nav-tab-active' : ''; ?>"><?php _e('Order Import / Export', 'order-import-export-for-woocommerce'); ?></a>
1
  <?php $tab = (isset($_GET['tab'])?$_GET['tab']:'import'); ?>
2
+ <div class="woocommerce">
3
  <div class="icon32" id="icon-woocommerce-importer"><br></div>
4
  <h2 class="nav-tab-wrapper woo-nav-tab-wrapper">
5
  <a href="<?php echo admin_url('admin.php?page=wf_woocommerce_order_im_ex') ?>" class="nav-tab <?php echo ($tab == 'import') ? 'nav-tab-active' : ''; ?>"><?php _e('Order Import / Export', 'order-import-export-for-woocommerce'); ?></a>
includes/views/html-wf-help-guide.php CHANGED
@@ -1,20 +1,65 @@
1
- <div class="tool-box bg-white p-20p">
2
- <div id="message" class="woocommerce-message wc-connect rTable">
3
- <div class="rTableRow">
4
- <div class="rTableCell">
5
- <h4><?php _e('<strong>WooCommerce Order CSV</strong>', 'order-import-export-for-woocommerce'); ?></h4>
6
- <p class="submit">
7
- <a target="_blank" href="https://www.webtoffee.com/setting-up-order-import-export-plugin-for-woocommerce/" class="button-primary"><?php _e('Documentation', 'order-import-export-for-woocommerce'); ?></a>
8
- <a class="docs button-primary" href="<?php echo WF_OrderImpExpCsv_FILE_Url.'Sample_Order.csv'; ?>"><?php _e('Sample Order CSV', 'order-import-export-for-woocommerce'); ?></a>
9
- </p>
10
- </div>
11
- <div class="rTableCell">
12
- <h4><?php _e('<strong>WooCommerce Coupon CSV</strong>', 'order-import-export-for-woocommerce'); ?></h4>
13
- <p class="submit">
14
- <a target="_blank" href="https://www.webtoffee.com/how-to-import-and-export-woocommerce-coupons-using-order-coupon-subscription-export-import-plugin/" class="button-primary"><?php _e( 'Documentation', 'order-import-export-for-woocommerce' ); ?></a>
15
- <a class="docs button-primary" href="<?php echo WF_OrderImpExpCsv_FILE_Url.'Sample_Coupon.csv'; ?>"><?php _e('Sample Coupon CSV', 'order-import-export-for-woocommerce'); ?></a></p>
16
- <p>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
  </div>
18
  </div>
19
- </div>
 
20
  </div>
1
+ <style>
2
+ .help-guide .cols {
3
+ display: flex;
4
+ }
5
+ .help-guide .inner-panel {
6
+ padding: 10px 11px 20px 11px;
7
+ background-color: #FFF;
8
+ margin: 15px 10px;
9
+ box-shadow: 1px 1px 5px 1px rgba(0,0,0,.1);
10
+ text-align: center;
11
+ width: 50%;
12
+ }
13
+ .help-guide .inner-panel p{
14
+ margin-bottom: 20px;
15
+ }
16
+ .help-guide .inner-panel img{
17
+ margin:12px 15px 0;
18
+ height: 90px;
19
+ width: 90px;
20
+ }
21
+ </style>
22
+ <div class="orderimpexp-main-box">
23
+ <div class="tool-box bg-white p-20p orderimpexp-view">
24
+ <div id="tab-help" class="coltwo-col panel help-guide">
25
+ <h4 class="title"><?php _e('<strong>WooCommerce Order</strong>', 'order-import-export-for-woocommerce'); ?></h4>
26
+ <div class="cols wt-border">
27
+ <div class="inner-panel">
28
+ <img src="<?php echo plugins_url(basename(plugin_dir_path(WF_OrderImpExpCsv_FILE))) . '/images/documentation.png'; ?>"/>
29
+ <h3><?php _e('Documentation', 'order-import-export-for-woocommerce'); ?></h3>
30
+ <p style=""><?php _e('Read the set-up guide to get started with the plugin', 'order-import-export-for-woocommerce'); ?></p>
31
+ <a href="https://www.webtoffee.com/setting-up-order-import-export-plugin-for-woocommerce/" target="_blank" class="button button-primary">
32
+ <?php _e('Setup Guide', 'order-import-export-for-woocommerce'); ?></a>
33
+ </div>
34
+
35
+ <div class="inner-panel">
36
+ <img src="<?php echo plugins_url(basename(plugin_dir_path(WF_OrderImpExpCsv_FILE))) . '/images/csv.png'; ?>"/>
37
+ <h3><?php _e('Sample-CSV', 'order-import-export-for-woocommerce'); ?></h3>
38
+ <p style=""><?php _e('Familiarize yourself with the CSV format', 'order-import-export-for-woocommerce'); ?></p>
39
+ <a href="<?php echo plugins_url('Sample_Order.csv', WF_OrderImpExpCsv_FILE); ?>" class="button button-primary">
40
+ <?php _e('Get Sample CSV', 'order-import-export-for-woocommerce'); ?></a>
41
+ </div>
42
+ </div>
43
+ <h4 class="title"><?php _e('<strong>WooCommerce Coupon</strong>', 'order-import-export-for-woocommerce'); ?></h4>
44
+ <div class="cols wt-border">
45
+ <div class="inner-panel">
46
+ <img src="<?php echo plugins_url(basename(plugin_dir_path(WF_OrderImpExpCsv_FILE))) . '/images/documentation.png'; ?>"/>
47
+ <h3><?php _e('Documentation', 'order-import-export-for-woocommerce'); ?></h3>
48
+ <p style=""><?php _e('Read the set-up guide to get started with the plugin', 'order-import-export-for-woocommerce'); ?></p>
49
+ <a href="https://www.webtoffee.com/import-and-export-woocommerce-coupons/" target="_blank" class="button button-primary">
50
+ <?php _e('Setup Guide', 'order-import-export-for-woocommerce'); ?></a>
51
+ </div>
52
+
53
+ <div class="inner-panel">
54
+ <img src="<?php echo plugins_url(basename(plugin_dir_path(WF_OrderImpExpCsv_FILE))) . '/images/csv.png'; ?>"/>
55
+ <h3><?php _e('Sample-CSV', 'order-import-export-for-woocommerce'); ?></h3>
56
+ <p style=""><?php _e('Familiarize yourself with the CSV format', 'order-import-export-for-woocommerce'); ?></p>
57
+ <a href="<?php echo plugins_url('Sample_Coupon.csv', WF_OrderImpExpCsv_FILE); ?>" class="button button-primary">
58
+ <?php _e('Get Sample CSV', 'order-import-export-for-woocommerce'); ?></a>
59
+ </div>
60
+ </div>
61
  </div>
62
  </div>
63
+ <?php include_once('market.php'); ?>
64
+ <div class="clearfix"></div>
65
  </div>
includes/views/import/html-wf-import-coupons.php CHANGED
@@ -2,7 +2,6 @@
2
  <div class="orderimpexp-view" style="width:68%;">
3
  <div class="tool-box bg-white p-20p" style="margin-bottom: 20px;">
4
  <h3 class="title"><?php _e('Import Coupons in CSV Format:', 'order-import-export-for-woocommerce'); ?></h3>
5
- <p><?php _e('Import coupons in CSV format from different sources ( from your computer OR from another server via FTP )', 'order-import-export-for-woocommerce'); ?></p>
6
  <p class="submit">
7
  <?php
8
  $merge_url = admin_url('admin.php?import=coupon_csv&merge=1');
2
  <div class="orderimpexp-view" style="width:68%;">
3
  <div class="tool-box bg-white p-20p" style="margin-bottom: 20px;">
4
  <h3 class="title"><?php _e('Import Coupons in CSV Format:', 'order-import-export-for-woocommerce'); ?></h3>
 
5
  <p class="submit">
6
  <?php
7
  $merge_url = admin_url('admin.php?import=coupon_csv&merge=1');
includes/views/import/html-wf-import-orders.php CHANGED
@@ -2,7 +2,6 @@
2
  <div class="orderimpexp-view" style="width:68%;">
3
  <div class="tool-box bg-white p-20p" style="margin-bottom: 20px;">
4
  <h3 class="title"><?php _e('Import Orders in CSV Format:', 'order-import-export-for-woocommerce'); ?></h3>
5
- <p><?php _e('Import Orders in CSV format from different sources ( from your computer OR from another server via FTP )', 'order-import-export-for-woocommerce'); ?></p>
6
  <p class="submit">
7
  <?php
8
  $merge_url = admin_url('admin.php?import=woocommerce_wf_order_csv&merge=1');
2
  <div class="orderimpexp-view" style="width:68%;">
3
  <div class="tool-box bg-white p-20p" style="margin-bottom: 20px;">
4
  <h3 class="title"><?php _e('Import Orders in CSV Format:', 'order-import-export-for-woocommerce'); ?></h3>
 
5
  <p class="submit">
6
  <?php
7
  $merge_url = admin_url('admin.php?import=woocommerce_wf_order_csv&merge=1');
order-import-export-for-woocommerce.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.4.7
10
  Text Domain: order-import-export-for-woocommerce
11
- WC tested up to: 3.6.3
12
  License: GPLv3
13
  License URI: https://www.gnu.org/licenses/gpl-3.0.html
14
  */
@@ -24,13 +24,26 @@ 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.4.7");
28
  }
29
 
30
  /**
31
  * Check if WooCommerce is active
32
  */
33
- if (in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) )) {
 
 
 
 
 
 
 
 
 
 
 
 
 
34
 
35
  if ( ! class_exists( 'WF_Order_Import_Export_CSV' ) ) :
36
 
@@ -286,7 +299,7 @@ if (in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', ge
286
 
287
  new WF_Coupon_Import_Export_CSV();
288
 
289
- }
290
 
291
 
292
 
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.4.8
10
  Text Domain: order-import-export-for-woocommerce
11
+ WC tested up to: 3.6.4
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.4.8");
28
  }
29
 
30
  /**
31
  * Check if WooCommerce is active
32
  */
33
+ register_activation_hook(__FILE__, 'wt_order_basic_register_activation_hook_callback');
34
+
35
+ function wt_order_basic_register_activation_hook_callback() {
36
+ if(!class_exists( 'WooCommerce' )){
37
+ deactivate_plugins(basename(__FILE__));
38
+ wp_die(__("WooCommerce is not installed/actived. it is required for this plugin to work properly. Please activate WooCommerce.", "order-import-export-for-woocommerce"), "", array('back_link' => 1));
39
+ }
40
+ if (is_plugin_active('order-import-export-for-woocommerce-pro/order-import-export.php')) {
41
+ deactivate_plugins(basename(__FILE__));
42
+ wp_die(__("Looks like you have both free and premium version installed on your site! Prior to activating premium, deactivate and delete the free version. For any issue kindly contact our support team here: <a target='_blank' href='https://www.webtoffee.com/support/'>support</a>", "order-import-export-for-woocommerce"), "", array('back_link' => 1));
43
+ }
44
+ update_option('wt_ord_plugin_installed_date', date('Y-m-d H:i:s'));
45
+ }
46
+ //if (in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) )) {
47
 
48
  if ( ! class_exists( 'WF_Order_Import_Export_CSV' ) ) :
49
 
299
 
300
  new WF_Coupon_Import_Export_CSV();
301
 
302
+ //}
303
 
304
 
305
 
readme.txt CHANGED
@@ -1,10 +1,10 @@
1
  === Order Export & Order Import for WooCommerce ===
2
  Contributors: webtoffee
3
  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: 5.2
7
- Stable tag: 1.4.7
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
  &#128312; Import Coupons from CSV file.
22
  &#128312; Export Subscription Orders to CSV file(Premium Feature).
23
  &#128312; Import Subscription Orders from CSV file(Premium Feature).
24
- &#128312; Tested OK with WooCommerce 3.6.3
25
  &#128312; Tested OK with PHP 7.3.5
26
 
27
  <blockquote>
@@ -100,6 +100,10 @@ WebToffee creates quality WordPress/WooCommerce plugins that are easy to use and
100
 
101
  Yes. You can import or export order line item details.
102
 
 
 
 
 
103
 
104
  == Screenshots ==
105
 
@@ -111,6 +115,11 @@ Yes. You can import or export order line item details.
111
 
112
  == Changelog ==
113
 
 
 
 
 
 
114
  = 1.4.7 =
115
  * Tested OK with WP 5.2.1 and WC 3.6.3
116
  * Bug Fix:- Order fields getting blank on updating when the fields are not present in CSV.
@@ -237,7 +246,8 @@ Yes. You can import or export order line item details.
237
  * Export /Import WooCommerce Orders.
238
 
239
  == Upgrade Notice ==
240
- = 1.4.7 =
241
- * Tested OK with WP 5.2.1 and WC 3.6.3
242
- * Bug Fix:- Order fields getting blank on updating when the fields are not present in CSV.
243
- * Coupon import optimisation.
 
1
  === Order Export & Order Import for WooCommerce ===
2
  Contributors: webtoffee
3
  Donate link: https://www.webtoffee.com/plugins/
4
+ Tags: Order Export, Order Import, WooCommerce Export Orders , WooCommerce Import Orders , Export Orders, Import Orders , order, export, import, woocommerce, csv, coupon, coupon export, coupon import, woocommerce export coupon , woocommerce import coupon , export coupons, import coupons,
5
  Requires at least: 3.0.1
6
  Tested up to: 5.2
7
+ Stable tag: 1.4.8
8
  License: GPLv3
9
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
10
 
21
  &#128312; Import Coupons from CSV file.
22
  &#128312; Export Subscription Orders to CSV file(Premium Feature).
23
  &#128312; Import Subscription Orders from CSV file(Premium Feature).
24
+ &#128312; Tested OK with WooCommerce 3.6.4
25
  &#128312; Tested OK with PHP 7.3.5
26
 
27
  <blockquote>
100
 
101
  Yes. You can import or export order line item details.
102
 
103
+ = Are you redirected to dashboard or login page while exporting? =
104
+
105
+ By default, admin and store manager are given access to export orders from your store.
106
+
107
 
108
  == Screenshots ==
109
 
115
 
116
  == Changelog ==
117
 
118
+ = 1.4.8 =
119
+ * Tested OK with WP 5.2.2 and WC 3.6.4
120
+ * Bug fix: Orders getting imported to new IDs when import ID conflicts with existing post IDs.
121
+ * Issue with using the plugin in multi-site setup.
122
+ * Help tab modification.
123
  = 1.4.7 =
124
  * Tested OK with WP 5.2.1 and WC 3.6.3
125
  * Bug Fix:- Order fields getting blank on updating when the fields are not present in CSV.
246
  * Export /Import WooCommerce Orders.
247
 
248
  == Upgrade Notice ==
249
+ = 1.4.8 =
250
+ * Tested OK with WP 5.2.2 and WC 3.6.4
251
+ * Bug fix: Orders getting imported to new IDs when import ID conflicts with existing post IDs.
252
+ * Issue with using the plugin in multi-site setup.
253
+ * Help tab modification.
styles/wf-style.css CHANGED
@@ -280,4 +280,13 @@
280
  }
281
  .xa-ocsie-rating-link{
282
  color: #ffc600;
 
 
 
 
 
 
 
 
 
283
  }
280
  }
281
  .xa-ocsie-rating-link{
282
  color: #ffc600;
283
+ }
284
+ .wt-title{
285
+ border-bottom: 1px solid #eee;
286
+ }
287
+ .wt-border{
288
+ border-bottom: 1px solid #f1f1f1;
289
+ border-top:1px solid #f1f1f1;
290
+ border-left: 1px solid #f1f1f1;
291
+ border-right: 1px solid #f1f1f1;
292
  }