class-wc-customer-order-csv-export-compatibility.php
25.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
<?php
/**
* WooCommerce Customer/Order CSV Export
*
* This source file is subject to the GNU General Public License v3.0
* that is bundled with this package in the file license.txt.
* It is also available through the world-wide-web at this URL:
* http://www.gnu.org/licenses/gpl-3.0.html
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@skyverge.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade WooCommerce Customer/Order CSV Export to newer
* versions in the future. If you wish to customize WooCommerce Customer/Order CSV Export for your
* needs please refer to http://docs.woothemes.com/document/ordercustomer-csv-exporter/
*
* @package WC-Customer-Order-CSV-Export/Generator
* @author SkyVerge
* @copyright Copyright (c) 2012-2016, SkyVerge, Inc.
* @license http://www.gnu.org/licenses/gpl-3.0.html GNU General Public License v3.0
*/
defined( 'ABSPATH' ) or exit;
/**
* Customer/Order CSV Export Compatibility
*
* Class that handles compatibility with legacy export formats
*
* @since 3.0
*/
class WC_Customer_Order_CSV_Export_Compatibility {
/** @var string order export format */
private $order_format;
/** @var string customer export format */
private $customer_format;
/**
* Constructor
*
* Check if using import or legacy export format and add filters as needed
*
* @since 3.0
*/
public function __construct() {
$this->order_format = get_option( 'wc_customer_order_csv_export_order_format' );
$this->customer_format = get_option( 'wc_customer_order_csv_export_customer_format' );
if ( ! in_array( $this->order_format, array( 'default', 'default_one_row_per_item' ) ) ) {
add_filter( 'wc_customer_order_csv_export_order_headers', array( $this, 'modify_order_headers' ), 0, 2 );
add_filter( 'wc_customer_order_csv_export_order_row', array( $this, 'modify_order_row' ), 0, 2 );
}
if ( 'default' !== $this->customer_format ) {
add_filter( 'wc_customer_order_csv_export_customer_headers', array( $this, 'modify_customer_headers' ), 0, 2 );
add_filter( 'wc_customer_order_csv_export_customer_row', array( $this, 'modify_customer_row' ), 0, 2 );
}
}
/**
* Modify the order export column headers to match the chosen format
*
* @since 3.0
* @param array $_ unused
* @param \WC_Customer_Order_CSV_Export_Generator the generator instance
* @return array modified column headers
*/
public function modify_order_headers( $_, $generator ) {
if ( 'import' == $this->order_format ) {
$headers = array(
'order_id' => 'id',
'order_number' => 'order_number',
'order_number_formatted' => 'order_number_formatted',
'order_date' => 'created_at',
'status' => 'status',
'order_total' => 'total',
'shipping_total' => 'total_shipping',
'tax_total' => 'cart_tax',
'shipping_tax_total' => 'shipping_tax',
'discount_total' => 'total_discount',
'refunded_total' => 'total_refunded',
'payment_method' => 'payment_method',
'order_currency' => 'currency',
'customer_id' => 'customer_user',
'billing_first_name' => 'billing_first_name',
'billing_last_name' => 'billing_last_name',
'billing_email' => 'billing_email',
'billing_phone' => 'billing_phone',
'billing_address_1' => 'billing_address_1',
'billing_address_2' => 'billing_address_2',
'billing_postcode' => 'billing_postcode',
'billing_city' => 'billing_city',
'billing_state' => 'billing_state',
'billing_country' => 'billing_country',
'billing_company' => 'billing_company',
'shipping_first_name' => 'shipping_first_name',
'shipping_last_name' => 'shipping_last_name',
'shipping_address_1' => 'shipping_address_1',
'shipping_address_2' => 'shipping_address_2',
'shipping_postcode' => 'shipping_postcode',
'shipping_city' => 'shipping_city',
'shipping_state' => 'shipping_state',
'shipping_country' => 'shipping_country',
'shipping_company' => 'shipping_company',
'customer_note' => 'note',
'line_items' => 'line_items',
'shipping_items' => 'shipping_lines',
'tax_items' => 'tax_lines',
'fee_items' => 'fee_lines',
'coupon_items' => 'coupon_lines',
'refunds' => 'refunds',
'order_notes' => 'order_notes',
'download_permissions' => 'download_permissions_granted',
);
}
else if ( 'legacy_import' == $this->order_format ) {
// Legacy CSV import format
$headers = array(
'order_id' => 'order_id',
'order_number_formatted' => 'order_number_formatted',
'order_number' => 'order_number',
'order_date' => 'date',
'status' => 'status',
'shipping_total' => 'order_shipping',
'shipping_tax_total' => 'order_shipping_tax',
'fee_total' => 'order_fees',
'fee_tax_total' => 'order_fee_tax',
'tax_total' => 'order_tax',
'discount_total' => 'discount_total',
'order_total' => 'order_total',
'payment_method' => 'payment_method',
'shipping_method' => 'shipping_method',
'customer_id' => 'customer_user',
'billing_first_name' => 'billing_first_name',
'billing_last_name' => 'billing_last_name',
'billing_email' => 'billing_email',
'billing_phone' => 'billing_phone',
'billing_address_1' => 'billing_address_1',
'billing_address_2' => 'billing_address_2',
'billing_postcode' => 'billing_postcode',
'billing_city' => 'billing_city',
'billing_state' => 'billing_state',
'billing_country' => 'billing_country',
'billing_company' => 'billing_company',
'shipping_first_name' => 'shipping_first_name',
'shipping_last_name' => 'shipping_last_name',
'shipping_address_1' => 'shipping_address_1',
'shipping_address_2' => 'shipping_address_2',
'shipping_postcode' => 'shipping_postcode',
'shipping_city' => 'shipping_city',
'shipping_state' => 'shipping_state',
'shipping_country' => 'shipping_country',
'shipping_company' => 'shipping_company',
'customer_note' => 'customer_note',
);
// line items
for ( $i = 1; $i <= $this->get_max_line_items( $generator->ids ); $i++ ) {
$headers[ "order_item_{$i}" ] = "order_item_{$i}";
}
$headers['download_permissions'] = 'download_permissions_granted';
$headers['order_notes'] = 'order_notes';
// shipping line items
for ( $i = 1; $i <= $this->get_max_shipping_line_items( $generator->ids ); $i++ ) {
$headers[ "shipping_method_{$i}" ] = "shipping_method_{$i}";
$headers[ "shipping_cost_{$i}" ] = "shipping_cost_{$i}";
}
} else {
// legacy format
$headers = array(
'order_id' => __( 'Order ID', 'woocommerce-customer-order-csv-export' ),
'order_date' => __( 'Date', 'woocommerce-customer-order-csv-export' ),
'status' => __( 'Order Status', 'woocommerce-customer-order-csv-export' ),
'shipping_total' => __( 'Shipping', 'woocommerce-customer-order-csv-export' ),
'shipping_tax_total' => __( 'Shipping Tax', 'woocommerce-customer-order-csv-export' ),
'fee_total' => __( 'Fees', 'woocommerce-customer-order-csv-export' ),
'fee_tax_total' => __( 'Fee Tax', 'woocommerce-customer-order-csv-export' ),
'tax_total' => __( 'Tax', 'woocommerce-customer-order-csv-export' ),
'discount_total' => __( 'Discount Total', 'woocommerce-customer-order-csv-export' ),
'order_total' => __( 'Order Total', 'woocommerce-customer-order-csv-export' ),
'payment_method' => __( 'Payment Method', 'woocommerce-customer-order-csv-export' ),
'shipping_method' => __( 'Shipping Method', 'woocommerce-customer-order-csv-export' ),
'billing_first_name' => __( 'Billing First Name', 'woocommerce-customer-order-csv-export' ),
'billing_last_name' => __( 'Billing Last Name', 'woocommerce-customer-order-csv-export' ),
'billing_email' => __( 'Billing Email', 'woocommerce-customer-order-csv-export' ),
'billing_phone' => __( 'Billing Phone', 'woocommerce-customer-order-csv-export' ),
'billing_address_1' => __( 'Billing Address 1', 'woocommerce-customer-order-csv-export' ),
'billing_address_2' => __( 'Billing Address 2', 'woocommerce-customer-order-csv-export' ),
'billing_postcode' => __( 'Billing Post code', 'woocommerce-customer-order-csv-export' ),
'billing_city' => __( 'Billing City', 'woocommerce-customer-order-csv-export' ),
'billing_state' => __( 'Billing State', 'woocommerce-customer-order-csv-export' ),
'billing_country' => __( 'Billing Country', 'woocommerce-customer-order-csv-export' ),
'billing_company' => __( 'Billing Company', 'woocommerce-customer-order-csv-export' ),
'shipping_first_name' => __( 'Shipping First Name', 'woocommerce-customer-order-csv-export' ),
'shipping_last_name' => __( 'Shipping Last Name', 'woocommerce-customer-order-csv-export' ),
'shipping_address_1' => __( 'Shipping Address 1', 'woocommerce-customer-order-csv-export' ),
'shipping_address_2' => __( 'Shipping Address 2', 'woocommerce-customer-order-csv-export' ),
'shipping_postcode' => __( 'Shipping Post code', 'woocommerce-customer-order-csv-export' ),
'shipping_city' => __( 'Shipping City', 'woocommerce-customer-order-csv-export' ),
'shipping_state' => __( 'Shipping State', 'woocommerce-customer-order-csv-export' ),
'shipping_country' => __( 'Shipping Country', 'woocommerce-customer-order-csv-export' ),
'shipping_company' => __( 'Shipping Company', 'woocommerce-customer-order-csv-export' ),
'customer_note' => __( 'Customer Note', 'woocommerce-customer-order-csv-export' ),
);
// legacy - one row per line item
if ( 'legacy_one_row_per_item' == $this->order_format ) {
$headers['line_item_sku'] = __( 'Item SKU', 'woocommerce-customer-order-csv-export' );
$headers['line_item_name'] = __( 'Item Name', 'woocommerce-customer-order-csv-export' );
$headers['line_item_variation'] = __( 'Item Variation', 'woocommerce-customer-order-csv-export' );
$headers['line_item_amount'] = __( 'Item Amount', 'woocommerce-customer-order-csv-export' );
$headers['line_item_price'] = __( 'Row Price', 'woocommerce-customer-order-csv-export' );
} else {
// legacy - one column for all line items
$headers['order_items'] = __( 'Order Items', 'woocommerce-customer-order-csv-export' );
}
// additional legacy columns that must go after line item
$headers['download_permissions'] = __( 'Download Permissions Granted', 'woocommerce-customer-order-csv-export' );
$headers['order_notes'] = __( 'Order notes', 'woocommerce-customer-order-csv-export' );
$headers['coupon_items'] = __( 'Coupons', 'woocommerce-customer-order-csv-export' );
}
return $headers;
}
/**
* Modify the order export row to match the chosen format
*
* @since 3.0
* @param array $order_data an array of order data for the given order
* @param WC_Order $order the WC_Order object
* @return array modified order data
*/
public function modify_order_row( $order_data, $order ) {
if ( 'import' == $this->order_format ) {
return $this->get_import_columns( $order_data, $order );
} elseif ( 'legacy_import' == $this->order_format ) {
return $this->get_legacy_import_one_column_per_line_item( $order_data, $order );
} elseif ( 'legacy_one_row_per_item' == $this->order_format ) {
return $this->get_legacy_one_row_per_line_item( $order_data, $order );
} else {
return $this->get_legacy_single_column_line_item( $order_data, $order );
}
}
/**
* Get the order data format for CSV Import JSON format
*
* @since 3.12.0
* @param array $order_data an array of order data for the given order
* @param WC_Order $order the WC_Order object
* @return array modified order data
*/
private function get_import_columns( $order_data, WC_Order $order ) {
if ( isset( $order_data['refunded_total'] ) && $order_data['refunded_total'] ) {
$refunds = array();
foreach ( $order->get_refunds() as $refund ) {
$line_items = array();
// add line items
foreach ( $refund->get_items( array( 'line_item', 'fee', 'shipping' ) ) as $item_id => $item ) {
$refund_amount = abs( isset( $item['line_total'] ) ? $item['line_total'] : ( isset( $item['cost'] ) ? $item['cost'] : null ) );
// skip empty refund lines
if ( ! $refund_amount ) {
continue;
}
$refunded_item = array(
'refunded_item_id' => $item['refunded_item_id'],
'refund_total' => $refund_amount,
);
if ( isset( $item['taxes'] ) ) {
$refunded_item['refund_tax'] = maybe_unserialize( $item['taxes'] );
}
if ( isset( $item['line_tax_data'] ) ) {
$tax_data = maybe_unserialize( $item['line_tax_data'] );
$refunded_item['refund_tax'] = $tax_data['total'];
}
if ( isset( $item['qty'] ) ) {
$refunded_item['qty'] = $item['qty'];
}
$line_items[] = $refunded_item;
}
$refund_data = array(
'id' => $refund->id,
'date' => $refund->date,
'amount' => wc_format_decimal( $refund->get_refund_amount(), 2 ),
'reason' => $refund->get_refund_reason(),
'line_items' => $line_items
);
$refunds[] = $refund_data;
}
$order_data['refunds'] = ! empty( $refunds ) ? json_encode( $refunds ) : '';
}
// fix order numbers
$order_data['order_id'] = $order->id;
$order_data['order_number_formatted'] = get_post_meta( $order->id, '_order_number_formatted', true );
$order_data['order_number'] = get_post_meta( $order->id, '_order_number', true );
// fix customer user
$user = new WP_User( $order_data['customer_id'] );
$order_data['customer_id'] = $user->user_email;
return $order_data;
}
/**
* Get the order data format for a single column per line item, compatible with the CSV Import Suite plugin
*
* @since 3.0
* @param array $order_data an array of order data for the given order
* @param WC_Order $order the WC_Order object
* @return array modified order data
*/
private function get_legacy_import_one_column_per_line_item( $order_data, WC_Order $order ) {
$count = 1;
// add line items
foreach ( $order->get_items() as $_ => $item ) {
// sku/qty/price
$product = $order->get_product_from_item( $item );
if ( ! is_object( $product ) ) {
$product = new WC_Product( 0 );
}
$sku = $product->get_sku();
// note that product ID must be prefixed with `product_id:` so the importer can properly parse it vs. the SKU
$product_id = SV_WC_Plugin_Compatibility::product_get_id( $product );
$line_item = array(
$sku ? $sku : "product_id:{$product_id}",
$item['qty'],
$order->get_line_total( $item )
);
// Add item meta
$item_meta = new WC_Order_Item_Meta( $item );
$formatted_meta = $item_meta->get_formatted();
if ( ! empty( $formatted_meta ) ) {
foreach ( $formatted_meta as $meta_key => $meta ) {
// remove newlines
$label = str_replace( array( "\r", "\r\n", "\n" ), '', $meta['label'] );
$value = str_replace( array( "\r", "\r\n", "\n" ), '', $meta['value'] );
// escape reserved chars (:;|)
$label = str_replace( array( ': ', ':', ';', '|' ), array( '\: ', '\:', '\;', '\|' ), $meta['label'] );
$value = str_replace( array( ': ', ':', ';', '|' ), array( '\: ', '\:', '\;', '\|' ), $meta['value'] );
$line_item[] = wp_kses_post( $label . ': ' . $value );
}
}
$order_data[ "order_item_{$count}" ] = implode( '|', $line_item );
$count++;
}
$count = 1;
foreach ( $order->get_items( 'shipping' ) as $_ => $shipping_item ) {
$order_data[ "shipping_method_{$count}" ] = $shipping_item['method_id'];
$order_data[ "shipping_cost_{$count}" ] = wc_format_decimal( $shipping_item['cost'], 2 );
$count++;
}
// fix order numbers
$order_data['order_id'] = $order->id;
$order_data['order_number_formatted'] = get_post_meta( $order->id, '_order_number_formatted', true );
$order_data['order_number'] = get_post_meta( $order->id, '_order_number', true );
// fix customer user
$user = new WP_User( $order_data['customer_id'] );
$order_data['customer_id'] = $user->user_email;
return $order_data;
}
/**
* Get the order data format for a new row per line item, compatible with the legacy (pre 3.0) CSV Export format
*
* Note this code was adapted from the old code to maintain compatibility as close as possible, so it should
* not be modified unless absolutely necessary
*
* @since 3.0
* @param array $order_data an array of order data for the given order
* @param WC_Order $order the WC_Order object
* @return array modified order data
*/
private function get_legacy_one_row_per_line_item( $order_data, WC_Order $order ) {
$data = array();
foreach ( $order->get_items() as $_ => $item ) {
$product = $order->get_product_from_item( $item );
if ( ! is_object( $product ) ) {
$product = new WC_Product( 0 );
}
$item_meta = new WC_Order_Item_Meta( $item );
$variation = $item_meta->display( true, true );
if ( $variation ) {
$variation = str_replace( array( "\r", "\r\n", "\n" ), '', $variation );
}
$order_data['line_item_sku'] = $product->get_sku();
$order_data['line_item_name'] = str_replace( array( '“', '”'), '', $item['name'] );
$order_data['line_item_variation'] = $variation;
$order_data['line_item_amount'] = $item['qty'];
$order_data['line_item_price'] = $order->get_line_total( $item );
// convert country codes to full name
if ( isset( WC()->countries->countries[ $order->billing_country ] ) ) {
$order_data['billing_country'] = WC()->countries->countries[ $order->billing_country ];
}
if ( isset( WC()->countries->countries[ $order->shipping_country ] ) ) {
$order_data['shipping_country'] = WC()->countries->countries[ $order->shipping_country ];
}
// set order ID to order number
$order_data['order_id'] = ltrim( $order->get_order_number(), _x( '#', 'hash before the order number', 'woocommerce-customer-order-csv-export' ) );
$data[] = $order_data;
}
// handle orders with no line items
if ( empty( $data ) ) {
$data = $order_data;
}
return $data;
}
/**
* Get the order data format for a single column for all line items, compatible with the legacy (pre 3.0) CSV Export format
*
* Note this code was adapted from the old code to maintain compatibility as close as possible, so it should
* not be modified unless absolutely necessary
*
* @since 3.0
* @param array $order_data an array of order data for the given order
* @param WC_Order $order the WC_Order object
* @return array modified order data
*/
private function get_legacy_single_column_line_item( $order_data, WC_Order $order ) {
$line_items = array();
foreach ( $order->get_items() as $_ => $item ) {
$product = $order->get_product_from_item( $item );
if ( ! is_object( $product ) ) {
$product = new WC_Product( 0 );
}
$line_item = $item['name'];
if ( $product->get_sku() ) {
$line_item .= ' (' . $product->get_sku() . ')';
}
$line_item .= ' x' . $item['qty'];
$item_meta = new WC_Order_Item_Meta( $item );
$variation = $item_meta->display( true, true );
if ( $variation ) {
$line_item .= ' - ' . str_replace( array( "\r", "\r\n", "\n" ), '', $variation );
}
$line_items[] = str_replace( array( '“', '”' ), '', $line_item );
}
$order_data['order_items'] = implode( '; ', $line_items );
// convert country codes to full name
if ( isset( WC()->countries->countries[ $order->billing_country ] ) ) {
$order_data['billing_country'] = WC()->countries->countries[ $order->billing_country ];
}
if ( isset( WC()->countries->countries[ $order->shipping_country ] ) ) {
$order_data['shipping_country'] = WC()->countries->countries[ $order->shipping_country ];
}
// set order ID to order number
$order_data['order_id'] = ltrim( $order->get_order_number(), _x( '#', 'hash before the order number', 'woocommerce-customer-order-csv-export' ) );
return $order_data;
}
/**
* Get the maximum number of line items for the given set of order IDs in order to generate the proper
* number of order line item columns for use with the CSV Import Suite format
*
* @since 3.0
* @param array $order_ids
* @return array modified order data
*/
private function get_max_line_items( $order_ids ) {
$max_line_items = 0;
foreach ( $order_ids as $order_id ) {
$order = wc_get_order( $order_id );
$line_items_count = count( $order->get_items() );
if ( $line_items_count >= $max_line_items ) {
$max_line_items = $line_items_count;
}
}
return $max_line_items;
}
/**
* Get the maximum number of shipping line items for the given set of order IDs in order to generate the proper
* number of shipping line item columns for use with the CSV Import Suite format
*
* @since 3.0
* @param array $order_ids
* @return array modified order data
*/
private function get_max_shipping_line_items( $order_ids ) {
$max_line_items = 0;
foreach ( $order_ids as $order_id ) {
$order = wc_get_order( $order_id );
$line_items_count = count( $order->get_items( 'shipping' ) );
if ( $line_items_count >= $max_line_items ) {
$max_line_items = $line_items_count;
}
}
return $max_line_items;
}
/**
* Modify the order export column headers to match the chosen format
*
* @since 3.0
* @param array $_ unused
* @param \WC_Customer_Order_CSV_Export_Generator the generator instance
* @return array modified column headers
*/
public function modify_customer_headers( $_, $generator ) {
if ( 'import' == $this->customer_format ) {
$headers = array(
'user_login' => 'username',
'email' => 'email',
'user_pass' => 'password',
'date_registered' => 'date_registered',
'billing_first_name' => 'billing_first_name',
'billing_last_name' => 'billing_last_name',
'billing_company' => 'billing_company',
'billing_address_1' => 'billing_address_1',
'billing_address_2' => 'billing_address_2',
'billing_city' => 'billing_city',
'billing_state' => 'billing_state',
'billing_postcode' => 'billing_postcode',
'billing_country' => 'billing_country',
'billing_email' => 'billing_email',
'billing_phone' => 'billing_phone',
'shipping_first_name' => 'shipping_first_name',
'shipping_last_name' => 'shipping_last_name',
'shipping_company' => 'shipping_company',
'shipping_address_1' => 'shipping_address_1',
'shipping_address_2' => 'shipping_address_2',
'shipping_city' => 'shipping_city',
'shipping_state' => 'shipping_state',
'shipping_postcode' => 'shipping_postcode',
'shipping_country' => 'shipping_country',
);
} else {
// legacy format
$headers = array(
'customer_id' => __( 'ID', 'woocommerce-customer-order-csv-export' ),
'billing_first_name' => __( 'First Name', 'woocommerce-customer-order-csv-export' ),
'billing_last_name' => __( 'Last Name', 'woocommerce-customer-order-csv-export' ),
'billing_email' => __( 'Email', 'woocommerce-customer-order-csv-export' ),
'billing_phone' => __( 'Phone', 'woocommerce-customer-order-csv-export' ),
'billing_address_1' => __( 'Address', 'woocommerce-customer-order-csv-export' ),
'billing_address_2' => __( 'Address 2', 'woocommerce-customer-order-csv-export' ),
'billing_postcode' => __( 'Post code', 'woocommerce-customer-order-csv-export' ),
'billing_city' => __( 'City', 'woocommerce-customer-order-csv-export' ),
'billing_state' => __( 'State', 'woocommerce-customer-order-csv-export' ),
'billing_country' => __( 'Country', 'woocommerce-customer-order-csv-export' ),
'billing_company' => __( 'Company', 'woocommerce-customer-order-csv-export' ),
);
}
return $headers;
}
/**
* Modify the order export row to match the chosen format
*
* @since 3.0
* @param array $customer_data an array of customer data for the given user
* @param WP_User $user the WP User object
* @return array modified customer data
*/
public function modify_customer_row( $customer_data, $user ) {
if ( 'import' == $this->customer_format ) {
$customer_data['user_login'] = isset( $user->user_login ) ? $user->user_login : '';
$customer_data['user_pass'] = isset( $user->user_pass ) ? $user->user_pass : '';
}
return $customer_data;
}
} //end \WC_Customer_Order_CSV_Export_Compatibility class