Advanced Order Export For WooCommerce - Version 1.5.4

Version Description

  • 2018-04-25 =
  • Prompting to save changes if user modifies settings
  • Product fields and order item fields were separated in popup "Setup fields"
  • Allow to filter by raw shipping methods (not assigned to shipping zones)
  • Record time of last export for the order (option "mark exported orders" must be ON)
  • Added order fields "Line number", "Order Subtotal - Cart Discount"
  • Added product field "Full names for categories"
  • Added operators "Is set", "Not is set" for custom fields
  • Added option "Enable debug output" to section "Misc Settings"
  • Added option "Cleanup phone" to section "Misc Settings"
  • Tags {from_date} and {to_date} can be used in filename
  • Fixed bug in UI if order item meta has many values
Download this release

Release Info

Developer algol.plus
Plugin Icon 128x128 Advanced Order Export For WooCommerce
Version 1.5.4
Comparing to
See all releases

Code changes from version 1.5.3 to 1.5.4

assets/css/export.css CHANGED
@@ -16,6 +16,20 @@
16
width: 80%;
17
}
18
19
20
.fields_control_style {
21
padding: 10px;
16
width: 80%;
17
}
18
19
+ .tablenav.top {
20
+ margin-bottom: 10px;
21
+ }
22
+
23
+ .tablenav.top select {
24
+ margin: 0 6px 0 0;
25
+ width: 100%;
26
+ height: 32px;
27
+ }
28
+
29
+ .tablenav.top #doaction {
30
+ margin: 0 6px 0 0;
31
+ height: 32px;
32
+ }
33
34
.fields_control_style {
35
padding: 10px;
assets/js/export.js CHANGED
@@ -1,8 +1,41 @@
1
var select2WODropdownOpts = {
2
containerCssClass : 'without-dropdown',
3
dropdownCssClass: 'without-dropdown',
4
- }
5
-
6
7
function bind_events() {
8
@@ -22,12 +55,12 @@ function bind_events() {
22
jQuery( '#select_custom_fields--select2 select' ).select2('destroy');
23
jQuery( '#select_custom_fields, #select_custom_fields--select2' ).remove();
24
if ( response ) {
25
- var options = '';
26
jQuery.each( response, function( index, value ) {
27
options += '<option>' + value + '</option>';
28
} );
29
var $select = jQuery( '<div id="select_custom_fields--select2" style="margin-top: 0px;margin-right: 6px; vertical-align: top;'
30
- + 'display: ' + (('LIKE' === val_op) ? 'none' : 'inline-block') + ';">'
31
+ '<select id="select_custom_fields">' + options + '</select></div>' );
32
$select.insertBefore( jQuery( '#add_custom_fields' ) )
33
$select.find('select').select2({ tags: true });
@@ -43,7 +76,7 @@ function bind_events() {
43
var val2 = jQuery( '#custom_fields' ).val();
44
var val_op = jQuery( '#custom_fields_compare' ).val();
45
if ( val != null && val2 != null && val.length && val2.length ) {
46
- val = val2 + ' ' + val_op + ' ' + val;
47
48
var f = true;
49
jQuery( '#custom_fields_check' ).next().find( 'ul li' ).each( function() {
@@ -53,8 +86,13 @@ function bind_events() {
53
} );
54
55
if ( f ) {
56
57
- jQuery( '#custom_fields_check' ).append( '<option selected="selected" value="' + val + '">' + val + '</option>' );
58
jQuery( '#custom_fields_check' ).select2();
59
60
jQuery( '#custom_fields_check option' ).each( function() {
@@ -75,6 +113,11 @@ function bind_events() {
75
jQuery( "#select_custom_fields--select2" ).hide();
76
jQuery( "#text_custom_fields" ).css('display', 'inline' ).attr( 'disabled', false );
77
}
78
else {
79
jQuery( "#select_custom_fields" ).css( 'display', 'inline-block' ).attr( 'disabled', false );
80
jQuery( '#select_custom_fields--select2' ).css('display', 'inline' );
@@ -462,30 +505,55 @@ function bind_events() {
462
});
463
464
jQuery('input[name=custom_meta_products_mode]').change(function() {
465
if ( !jQuery( this ).is( ':checked' ) ) {
466
var options = '<option></option>';
467
jQuery.each( window.order_products_custom_meta_fields, function( index, value ) {
468
- options += '<option value="' + escapeStr(value) + '">' + value + '</option>';
469
} );
470
jQuery( '#select_custom_meta_products' ).html( options );
471
}
472
else {
473
jQuery('#modal-manage-products').html(jQuery('#TB_ajaxContent').html());
474
- var data = jQuery( '#export_job_settings' ).serialize();
475
- data = data + "&action=order_exporter&method=get_used_custom_products_meta&mode=" + mode + "&id=" + job_id;
476
477
- jQuery.post( ajaxurl, data, function( response ) {
478
if ( response ) {
479
var options = '<option></option>';
480
jQuery.each( response, function( index, value ) {
481
options += '<option value="' + escapeStr(value) + '">' + value + '</option>';
482
} );
483
jQuery( '#select_custom_meta_products' ).html( options );
484
}
485
}, 'json' );
486
jQuery('#modal-manage-products').html('');
487
}
488
});
489
490
jQuery('input[name=custom_meta_coupons_mode]').change(function() {
491
if (jQuery(this).val() == 'all') {
@@ -652,10 +720,16 @@ function bind_events() {
652
}
653
return false;
654
} )
655
}
656
657
function add_bind_for_custom_fields( prefix, output_format, $to ) {
658
- jQuery( '#button_custom_meta_' + prefix + '' ).off();
659
jQuery( '#button_custom_field_' + prefix + '' ).off();
660
jQuery( '#button_custom_field_' + prefix + '' ).click( function() {
661
var colname = jQuery( '#colname_custom_field_' + prefix + '' ).val();
@@ -666,7 +740,7 @@ function add_bind_for_custom_fields( prefix, output_format, $to ) {
666
jQuery( '#colname_custom_field_' + prefix + '' ).focus();
667
return false
668
}
669
- if ( !value )
670
{
671
alert( export_messages.empty_value );
672
jQuery( '#value_custom_field_' + prefix + '' ).focus();
@@ -678,24 +752,41 @@ function add_bind_for_custom_fields( prefix, output_format, $to ) {
678
return false;
679
} );
680
681
- jQuery( '#button_custom_meta_' + prefix + '' ).click( function() {
682
- var type = jQuery( '#select_custom_meta_' + prefix + '' ).val() != '' ? 'meta' : 'taxonomies';
683
- type = type + '_' + prefix;
684
- var label = jQuery( '#select_custom_' + type + '' ).val();
685
- var colname = jQuery( '#colname_custom_meta_' + prefix + '' ).val();
686
- if ( colname == undefined || colname == '' ) {
687
- colname = label;
688
}
689
- if ( !colname )
690
- {
691
- alert( export_messages.empty_column_name );
692
- return false
693
- }
694
- add_custom_meta( $to, prefix, output_format, label, colname );
695
- jQuery( '#select_custom_' + type + '' ).val( "" );
696
- jQuery( '#colname_custom_meta_' + prefix + '' ).val( "" );
697
- return false;
698
- } );
699
}
700
701
function reset_field_contorls() {
1
var select2WODropdownOpts = {
2
containerCssClass : 'without-dropdown',
3
dropdownCssClass: 'without-dropdown',
4
+ };
5
+
6
+ String.prototype.hashCode = function() {
7
+ var hash = 0, i, chr;
8
+ if (this.length === 0) return hash;
9
+ for (i = 0; i < this.length; i++) {
10
+ chr = this.charCodeAt(i);
11
+ hash = ((hash << 5) - hash) + chr;
12
+ hash |= 0; // Convert to 32bit integer
13
+ }
14
+ return hash;
15
+ };
16
+ var formSubmitting = false;
17
+
18
+ var setFormSubmitting = function() { formSubmitting = true; };
19
+
20
+ window.onload = function () {
21
+ var form = jQuery( '#export_job_settings' );
22
+ var on_load_form_data = form.serialize();
23
+
24
+ var isDirty = function ( on_load_form_data ) {
25
+ return on_load_form_data.hashCode() !== form.serialize().hashCode()
26
+ };
27
+
28
+ window.addEventListener( "beforeunload", function ( e ) {
29
+ if ( isDirty( on_load_form_data ) && ! formSubmitting ) {
30
+ (
31
+ e || window.event
32
+ ).returnValue = false; //Gecko + IE
33
+ return false; //Gecko + Webkit, Safari, Chrome etc.
34
+ } else {
35
+ return undefined;
36
+ }
37
+ } );
38
+ };
39
40
function bind_events() {
41
55
jQuery( '#select_custom_fields--select2 select' ).select2('destroy');
56
jQuery( '#select_custom_fields, #select_custom_fields--select2' ).remove();
57
if ( response ) {
58
+ var options = '<option>' + export_messages.empty + '</option>';
59
jQuery.each( response, function( index, value ) {
60
options += '<option>' + value + '</option>';
61
} );
62
var $select = jQuery( '<div id="select_custom_fields--select2" style="margin-top: 0px;margin-right: 6px; vertical-align: top;'
63
+ + 'display: ' + (('LIKE' === val_op || 'NOT SET' === val_op|| 'IS SET' === val_op) ? 'none' : 'inline-block') + ';">'
64
+ '<select id="select_custom_fields">' + options + '</select></div>' );
65
$select.insertBefore( jQuery( '#add_custom_fields' ) )
66
$select.find('select').select2({ tags: true });
76
var val2 = jQuery( '#custom_fields' ).val();
77
var val_op = jQuery( '#custom_fields_compare' ).val();
78
if ( val != null && val2 != null && val.length && val2.length ) {
79
+ var result = val2 + ' ' + val_op + ' ' + val;
80
81
var f = true;
82
jQuery( '#custom_fields_check' ).next().find( 'ul li' ).each( function() {
86
} );
87
88
if ( f ) {
89
+ if ( export_messages.empty === val ) {
90
+ result = val2 + ' ' + val_op + ' empty';
91
+ jQuery( '#custom_fields_check' ).append( '<option selected="selected" value="' + result + '">' + result + '</option>' );
92
+ } else {
93
+ jQuery( '#custom_fields_check' ).append( '<option selected="selected" value="' + result + '">' + result + '</option>' );
94
+ }
95
96
jQuery( '#custom_fields_check' ).select2();
97
98
jQuery( '#custom_fields_check option' ).each( function() {
113
jQuery( "#select_custom_fields--select2" ).hide();
114
jQuery( "#text_custom_fields" ).css('display', 'inline' ).attr( 'disabled', false );
115
}
116
+ else if ( 'NOT SET' === val_op || 'IS SET' === val_op ) {
117
+ jQuery( "#select_custom_fields" ).css( 'display', 'none' ).attr( 'disabled', 'disabled' ) . val(' ');
118
+ jQuery( "#select_custom_fields--select2" ).hide();
119
+ jQuery( "#text_custom_fields" ).css('display', 'none' ).attr( 'disabled', false ). val(' ');
120
+ }
121
else {
122
jQuery( "#select_custom_fields" ).css( 'display', 'inline-block' ).attr( 'disabled', false );
123
jQuery( '#select_custom_fields--select2' ).css('display', 'inline' );
505
});
506
507
jQuery('input[name=custom_meta_products_mode]').change(function() {
508
+ jQuery( '#select_custom_meta_products' ).prop( "disabled", true );
509
+ jQuery( '#select_custom_meta_order_items' ).prop( "disabled", true );
510
if ( !jQuery( this ).is( ':checked' ) ) {
511
var options = '<option></option>';
512
jQuery.each( window.order_products_custom_meta_fields, function( index, value ) {
513
+ options += '<option value="' + escapeStr(value) + '">' + value + '</option>';
514
} );
515
jQuery( '#select_custom_meta_products' ).html( options );
516
+ jQuery( '#select_custom_meta_products' ).prop( "disabled", false );
517
+
518
+ options = '<option></option>';
519
+ jQuery.each( window.order_order_item_custom_meta_fields, function( index, value ) {
520
+ options += '<option value="' + escapeStr(value) + '">' + value + '</option>';
521
+ } );
522
+ jQuery( '#select_custom_meta_order_items' ).html( options );
523
+ jQuery( '#select_custom_meta_order_items' ).prop( "disabled", false );
524
}
525
else {
526
jQuery('#modal-manage-products').html(jQuery('#TB_ajaxContent').html());
527
+ var data = jQuery( '#export_job_settings' ).serialize(),
528
+ data_products = data + "&action=order_exporter&method=get_used_custom_products_meta&mode=" + mode + "&id=" + job_id,
529
+ data_order_items = data + "&action=order_exporter&method=get_used_custom_order_items_meta&mode=" + mode + "&id=" + job_id;
530
531
+ jQuery.post( ajaxurl, data_products, function( response ) {
532
if ( response ) {
533
var options = '<option></option>';
534
jQuery.each( response, function( index, value ) {
535
options += '<option value="' + escapeStr(value) + '">' + value + '</option>';
536
} );
537
jQuery( '#select_custom_meta_products' ).html( options );
538
+ jQuery( '#select_custom_meta_products' ).prop( "disabled", false );
539
}
540
}, 'json' );
541
+
542
+ jQuery.post( ajaxurl, data_order_items, function( response ) {
543
+ if ( response ) {
544
+ var options = '<option></option>';
545
+ jQuery.each( response, function( index, value ) {
546
+ options += '<option value="' + escapeStr(value) + '">' + value + '</option>';
547
+ } );
548
+ jQuery( '#select_custom_meta_order_items' ).html( options );
549
+ jQuery( '#select_custom_meta_order_items' ).prop( "disabled", false );
550
+ }
551
+ }, 'json' );
552
+
553
jQuery('#modal-manage-products').html('');
554
}
555
});
556
+ jQuery('input[name=custom_meta_products_mode]').trigger('change');
557
558
jQuery('input[name=custom_meta_coupons_mode]').change(function() {
559
if (jQuery(this).val() == 'all') {
720
}
721
return false;
722
} )
723
+
724
+ jQuery( '#summary_report_by_products_checkbox' ).on('change', function() {
725
+ jQuery('#manage_fields').parent().toggle(jQuery('#summary_report_by_products_checkbox').val());
726
+ } );
727
+ if( jQuery('#summary_report_by_products_checkbox').prop('checked') ) {
728
+ jQuery('#manage_fields').parent().hide();
729
+ }
730
}
731
732
function add_bind_for_custom_fields( prefix, output_format, $to ) {
733
jQuery( '#button_custom_field_' + prefix + '' ).off();
734
jQuery( '#button_custom_field_' + prefix + '' ).click( function() {
735
var colname = jQuery( '#colname_custom_field_' + prefix + '' ).val();
740
jQuery( '#colname_custom_field_' + prefix + '' ).focus();
741
return false
742
}
743
+ if ( !value && 'products' !== prefix )
744
{
745
alert( export_messages.empty_value );
746
jQuery( '#value_custom_field_' + prefix + '' ).focus();
752
return false;
753
} );
754
755
+ jQuery( '#button_custom_meta_' + prefix + '' ).off();
756
+ jQuery( '#button_custom_meta_' + prefix + '' ).click( function() {
757
+ var prefix_items = 'order_items',
758
+ original_prefix = prefix,
759
+ prefix_items_select = jQuery( '#select_custom_meta_' + prefix_items + '' ),
760
+ prefix_product_select = jQuery( '#select_custom_meta_' + prefix + '' );
761
+
762
+ var type = ( prefix_items_select.val() || prefix_product_select.val() ) ? 'meta' : 'taxonomies';
763
+ if ( 'meta' === type ) {
764
+ original_prefix = prefix_product_select.val() ? prefix : prefix_items;
765
+ } else {
766
+ original_prefix = prefix;
767
}
768
+ type = type + '_' + original_prefix;
769
+ var label = jQuery( '#select_custom_' + type + '' ).val();
770
+ var colname = jQuery( '#colname_custom_meta_' + prefix + '' ).val();
771
+ if ( !label )
772
+ {
773
+ alert( export_messages.empty_meta_key_and_taxonomy );
774
+ return false
775
+ }
776
+ if ( colname == undefined || colname == '' ) {
777
+ colname = label;
778
+ }
779
+ if ( !colname )
780
+ {
781
+ alert( export_messages.empty_column_name );
782
+ return false
783
+ }
784
+ add_custom_meta( $to, prefix, output_format, label, colname );
785
+ jQuery( '#select_custom_' + type + '' ).val( "" );
786
+ jQuery( '#colname_custom_meta_' + prefix + '' ).val( "" );
787
+ return false;
788
+ } );
789
+
790
}
791
792
function reset_field_contorls() {
classes/admin/class-wc-order-export-ajax.php CHANGED
@@ -76,7 +76,16 @@ class WC_Order_Export_Ajax {
76
public function get_used_custom_products_meta() {
77
$settings = WC_Order_Export_Manage::make_new_settings( $_POST );
78
$sql = WC_Order_Export_Data_Extractor::sql_get_order_ids( $settings );
79
- $ret = WC_Order_Export_Data_Extractor_UI::get_all_product_custom_meta_fields_for_orders( $sql );
80
echo json_encode( $ret );
81
}
82
@@ -213,12 +222,16 @@ class WC_Order_Export_Ajax {
213
if( !$filename ) {
214
die( __( 'Can\'t create temporary file', 'woo-order-export-lite' ) ) ;
215
}
216
-
217
- file_put_contents( $filename, '' );
218
-
219
- do_action( 'woe_start_export_job', $_POST['id'], $settings );
220
-
221
- $total = WC_Order_Export_Engine::build_file( $settings, 'start_estimate', 'file', 0, 0, $filename );
222
$file_id = current_time( 'timestamp' );
223
set_transient( $this->tempfile_prefix . $file_id, $filename, 60 );
224
$this->stop_prevent_object_cache();
76
public function get_used_custom_products_meta() {
77
$settings = WC_Order_Export_Manage::make_new_settings( $_POST );
78
$sql = WC_Order_Export_Data_Extractor::sql_get_order_ids( $settings );
79
+ $ret = WC_Order_Export_Data_Extractor_UI::get_product_custom_meta_fields_for_orders( $sql );
80
+ sort($ret);
81
+ echo json_encode( $ret );
82
+ }
83
+
84
+ public function get_used_custom_order_items_meta() {
85
+ $settings = WC_Order_Export_Manage::make_new_settings( $_POST );
86
+ $sql = WC_Order_Export_Data_Extractor::sql_get_order_ids( $settings );
87
+ $ret = WC_Order_Export_Data_Extractor_UI::get_order_item_custom_meta_fields_for_orders( $sql );
88
+ sort($ret);
89
echo json_encode( $ret );
90
}
91
222
if( !$filename ) {
223
die( __( 'Can\'t create temporary file', 'woo-order-export-lite' ) ) ;
224
}
225
+
226
+ //no free space or other file system errors?
227
+ try {
228
+ file_put_contents( $filename, '' );
229
+ do_action( 'woe_start_export_job', $_POST['id'], $settings );
230
+ $total = WC_Order_Export_Engine::build_file( $settings, 'start_estimate', 'file', 0, 0, $filename );
231
+ } catch (Exception $e) {
232
+ die( $e->getMessage() );
233
+ }
234
+ // file created
235
$file_id = current_time( 'timestamp' );
236
set_transient( $this->tempfile_prefix . $file_id, $filename, 60 );
237
$this->stop_prevent_object_cache();
classes/admin/class-wc-order-export-manage.php CHANGED
@@ -166,7 +166,9 @@ class WC_Order_Export_Manage {
166
static function apply_defaults( $mode, $settings ) {
167
$defaults = array(
168
'mode' => $mode,
169
'skip_empty_file' => true,
170
'from_status' => array(),
171
'to_status' => array(),
172
'change_order_status_to' => '',
@@ -225,12 +227,14 @@ class WC_Order_Export_Manage {
225
'time_format' => 'H:i',
226
'sort_direction' => 'DESC',
227
'sort' => 'order_id',
228
- 'format_number_fields' => 0,
229
'export_all_comments' => 0,
230
'export_refund_notes' => 0,
231
'strip_tags_product_fields' => 0,
232
'format_json_start_tag' => '[',
233
- 'format_json_end_tag' => '\n]',
234
'custom_php' => 0,
235
'custom_php_code' => '',
236
'mark_exported_orders' => 0,
@@ -243,6 +247,10 @@ class WC_Order_Export_Manage {
243
$settings['format'] = 'XLS';
244
}
245
246
if ( ! isset( $settings['order_fields'] ) ) {
247
$settings['order_fields'] = array();
248
}
@@ -285,7 +293,7 @@ class WC_Order_Export_Manage {
285
$all_jobs = $options;// just replace
286
} elseif ( $mode == self::EXPORT_SCHEDULE ) {
287
if ( $id ) {
288
- $options['schedule']['last_run'] = $all_jobs[ $id ]['schedule']['last_run'];
289
$options['schedule']['next_run'] = WC_Order_Export_Cron::next_event_timestamp_for_schedule( $options['schedule'], $id );
290
$all_jobs[ $id ] = $options;
291
} else {
@@ -382,23 +390,45 @@ class WC_Order_Export_Manage {
382
if( isset( $data[ self::EXPORT_NOW ] ) ) { // import ALL
383
foreach ( $allowed_options as $key ) {
384
if ( isset( $data[ $key ] ) ) {
385
- $setting_name = self::get_settings_name_for_mode( $key );
386
update_option( $setting_name, $data[ $key ] );
387
}
388
}
389
}
390
elseif( isset( $data["mode"] ) AND in_array( $data["mode"], $allowed_options ) ) { // OR import single ?
391
- $setting_name = self::get_settings_name_for_mode( $data["mode"] );
392
if( $setting_name == self::settings_name_now ) {
393
- update_option( $setting_name, $data ); // rewrite
394
} else { // append!
395
$items = get_option( $setting_name, array() );
396
if( empty($items) )
397
- $items[ 1 ] = $data;
398
else
399
- $items[] = $data;
400
update_option( $setting_name, $items );
401
}
402
}// if modes
403
}
404
}
166
static function apply_defaults( $mode, $settings ) {
167
$defaults = array(
168
'mode' => $mode,
169
+ 'title' => '',
170
'skip_empty_file' => true,
171
+ 'log_results' => false,
172
'from_status' => array(),
173
'to_status' => array(),
174
'change_order_status_to' => '',
227
'time_format' => 'H:i',
228
'sort_direction' => 'DESC',
229
'sort' => 'order_id',
230
+ 'format_number_fields' => 0,
231
'export_all_comments' => 0,
232
'export_refund_notes' => 0,
233
'strip_tags_product_fields' => 0,
234
+ 'cleanup_phone' => 0,
235
+ 'enable_debug' => 0,
236
'format_json_start_tag' => '[',
237
+ 'format_json_end_tag' => ']',
238
'custom_php' => 0,
239
'custom_php_code' => '',
240
'mark_exported_orders' => 0,
247
$settings['format'] = 'XLS';
248
}
249
250
+ if ( ! isset( $settings['export_rule_field'] ) AND $mode == WC_Order_Export_Manage::EXPORT_SCHEDULE ) {
251
+ $settings['export_rule_field'] = 'modified';
252
+ }
253
+
254
if ( ! isset( $settings['order_fields'] ) ) {
255
$settings['order_fields'] = array();
256
}
293
$all_jobs = $options;// just replace
294
} elseif ( $mode == self::EXPORT_SCHEDULE ) {
295
if ( $id ) {
296
+ $options['schedule']['last_run'] = isset($all_jobs[ $id ]) ? $all_jobs[ $id ]['schedule']['last_run'] : current_time("timestamp",0);
297
$options['schedule']['next_run'] = WC_Order_Export_Cron::next_event_timestamp_for_schedule( $options['schedule'], $id );
298
$all_jobs[ $id ] = $options;
299
} else {
390
if( isset( $data[ self::EXPORT_NOW ] ) ) { // import ALL
391
foreach ( $allowed_options as $key ) {
392
if ( isset( $data[ $key ] ) ) {
393
+ $setting_name = self::get_settings_name_for_mode( $key );
394
+
395
+ if ( isset( $data[ $key ]['mode'] ) ) {
396
+ $data[ $key ] = self::edit_import_data( $data[ $key ] );
397
+ } else {
398
+ foreach ( $data[ $key ] as $index => $import_single_data ) {
399
+ $data[$key][$index] = self::edit_import_data( $import_single_data );
400
+ }
401
+ }
402
+
403
update_option( $setting_name, $data[ $key ] );
404
}
405
}
406
}
407
elseif( isset( $data["mode"] ) AND in_array( $data["mode"], $allowed_options ) ) { // OR import single ?
408
+ $setting_name = self::get_settings_name_for_mode( $data["mode"] );
409
if( $setting_name == self::settings_name_now ) {
410
+ update_option( $setting_name, self::edit_import_data( $data ) ); // rewrite
411
} else { // append!
412
$items = get_option( $setting_name, array() );
413
+
414
if( empty($items) )
415
+ $items[ 1 ] = self::edit_import_data( $data );
416
else
417
+ $items[] = self::edit_import_data( $data );
418
+
419
update_option( $setting_name, $items );
420
}
421
}// if modes
422
}
423
+
424
+ private static function edit_import_data( $data ) {
425
+
426
+ $mode = $data['mode'];
427
+ if ( $mode != self::EXPORT_SCHEDULE ) {
428
+ unset( $data['export_rule'] );
429
+ unset( $data['schedule'] );
430
+ }
431
+
432
+ return $data;
433
+ }
434
}
classes/class-wc-order-export-admin.php CHANGED
@@ -155,6 +155,7 @@ class WC_Order_Export_Admin {
155
'ajax_orders_per_step' => '30',
156
'limit_button_test' => '1',
157
'cron_key' => '1234',
158
),
159
get_option( self::settings_name_common, array() )
160
);
@@ -165,9 +166,14 @@ class WC_Order_Export_Admin {
165
'cron_tasks_active' => FILTER_VALIDATE_BOOLEAN,
166
'ajax_orders_per_step' => FILTER_VALIDATE_INT,
167
'limit_button_test' => FILTER_SANITIZE_STRING,
168
- 'cron_key' => FILTER_SANITIZE_STRING
169
) );
170
update_option( self::settings_name_common, $settings );
171
}
172
173
@@ -280,6 +286,25 @@ class WC_Order_Export_Admin {
280
$url = remove_query_arg( array( 'wc_oe', 'action_id', 'status' ) );
281
wp_redirect( $url );
282
break;
283
}
284
$this->render( 'tab/order-actions', array( 'ajaxurl' => $ajaxurl, 'WC_Order_Export' => $this, 'tab' => 'order_actions' ) );
285
}
@@ -341,6 +366,25 @@ class WC_Order_Export_Admin {
341
$url = remove_query_arg( array( 'wc_oe', 'schedule_id', 'status' ) );
342
wp_redirect( $url );
343
break;
344
}
345
$this->render( 'tab/schedules', array( 'ajaxurl' => $ajaxurl, 'WC_Order_Export' => $this ) );
346
}
@@ -411,17 +455,23 @@ class WC_Order_Export_Admin {
411
unset( $all_items[ $profile_id ] );
412
WC_Order_Export_Manage::save_export_settings_collection( $mode, $all_items );
413
break;
414
- case 'change_profile_bulk_action':
415
- if( !isset( $_REQUEST['profile_id'] ) )
416
break;
417
- $profile_id = $_REQUEST['profile_id'];
418
- if( $_REQUEST['status'] ) {
419
- $all_items[ $profile_id ][ 'use_as_bulk' ] = 'on';
420
- } else {
421
- unset( $all_items[ $profile_id ][ 'use_as_bulk' ] );
422
- }
423
WC_Order_Export_Manage::save_export_settings_collection( $mode, $all_items );
424
- $url = remove_query_arg( array( 'wc_oe', 'profile_id', 'status' ) );
425
wp_redirect( $url );
426
break;
427
}
@@ -450,16 +500,20 @@ class WC_Order_Export_Admin {
450
wp_enqueue_script( 'export', $this->url_plugin . 'assets/js/export.js', array(), WOE_VERSION );
451
wp_enqueue_script( 'serializejson', $this->url_plugin . 'assets/js/jquery.serializejson.js', array('jquery'), WOE_VERSION );
452
wp_enqueue_style( 'export', $this->url_plugin . 'assets/css/export.css', array(), WOE_VERSION );
453
-
454
// Localize the script with new data
455
$translation_array = array(
456
'empty_column_name' => __( 'empty column name', 'woo-order-export-lite' ),
457
'empty_meta_key' => __( 'empty meta key', 'woo-order-export-lite' ),
458
'empty_value' => __( 'empty value', 'woo-order-export-lite' ),
459
'empty_title' => __( 'title is empty', 'woo-order-export-lite' ),
460
'wrong_date_range' => __( 'Date From is greater than Date To', 'woo-order-export-lite' ),
461
'no_fields' => __( 'Please, set up fields to export', 'woo-order-export-lite' ),
462
'no_results' => __( 'Nothing to export. Please, adjust your filters', 'woo-order-export-lite' ),
463
);
464
wp_localize_script( 'export', 'export_messages', $translation_array );
465
}
@@ -489,7 +543,9 @@ class WC_Order_Export_Admin {
489
490
public function script_loader_src($src, $handle) {
491
// don't load ANY select2.js / select2.min.js and OUTDATED select2.full.js
492
- if (!preg_match('/\/select2\.full\.js\?ver=[1-3]/', $src) && !preg_match('/\/select2\.min\.js/', $src) && !preg_match('/\/select2\.js/', $src) ) {
493
return $src;
494
}
495
}
@@ -571,11 +627,12 @@ class WC_Order_Export_Admin {
571
if ( isset( $_REQUEST['method'] ) ) {
572
$method = $_REQUEST['method'];
573
if ( method_exists( 'WC_Order_Export_Ajax', $method ) ) {
574
- $_POST = array_map('stripslashes_deep', $_POST);
575
// parse json to arrays?
576
if ( !empty($_POST['json']) ) {
577
$json = json_decode( $_POST['json'], true );
578
if( is_array($json) ) {
579
$_POST = $_POST + $json;
580
unset( $_POST['json'] );
581
}
@@ -616,7 +673,7 @@ class WC_Order_Export_Admin {
616
617
$all_items = WC_Order_Export_Manage::get_export_settings_collection( WC_Order_Export_Manage::EXPORT_PROFILE );
618
foreach ( $all_items as $job_id => $job ) {
619
- if ( isset( $job['use_as_bulk'] ) )
620
$actions['woe_export_selected_orders_profile_' . $job_id] = sprintf( __( "Export as profile '%s'", 'woo-order-export-lite' ), $job['title'] );
621
}
622
155
'ajax_orders_per_step' => '30',
156
'limit_button_test' => '1',
157
'cron_key' => '1234',
158
+ 'ipn_url' => '',
159
),
160
get_option( self::settings_name_common, array() )
161
);
166
'cron_tasks_active' => FILTER_VALIDATE_BOOLEAN,
167
'ajax_orders_per_step' => FILTER_VALIDATE_INT,
168
'limit_button_test' => FILTER_SANITIZE_STRING,
169
+ 'cron_key' => FILTER_SANITIZE_STRING,
170
+ 'ipn_url' => FILTER_SANITIZE_STRING,
171
) );
172
update_option( self::settings_name_common, $settings );
173
+
174
+ if ( isset( $settings['ipn_url'] ) ) {
175
+ update_option( WOE_IPN_URL_OPTION_KEY, $settings['ipn_url'] );
176
+ }
177
}
178
179
286
$url = remove_query_arg( array( 'wc_oe', 'action_id', 'status' ) );
287
wp_redirect( $url );
288
break;
289
+ case 'change_statuses':
290
+ if( !isset( $_REQUEST['chosen_order_actions'] ) AND !isset( $_REQUEST['doaction'] ) AND -1 == $_REQUEST['doaction'] )
291
+ break;
292
+ $chosen_order_actions = explode(',' , $_REQUEST['chosen_order_actions'] );
293
+ $doaction = $_REQUEST['doaction'];
294
+
295
+ foreach ( $chosen_order_actions as $order_action_id ) {
296
+ if ( 'activate' == $doaction ) {
297
+ $all_items[ $order_action_id ]['active'] = 1;
298
+ } elseif ( 'deactivate' == $doaction ) {
299
+ $all_items[ $order_action_id ]['active'] = 0;
300
+ } elseif ( 'delete' == $doaction ) {
301
+ unset( $all_items[ $order_action_id ] );
302
+ }
303
+ }
304
+ WC_Order_Export_Manage::save_export_settings_collection( $mode, $all_items );
305
+ $url = remove_query_arg( array( 'wc_oe', 'chosen_order_actions', 'doaction' ) );
306
+ wp_redirect( $url );
307
+ break;
308
}
309
$this->render( 'tab/order-actions', array( 'ajaxurl' => $ajaxurl, 'WC_Order_Export' => $this, 'tab' => 'order_actions' ) );
310
}
366
$url = remove_query_arg( array( 'wc_oe', 'schedule_id', 'status' ) );
367
wp_redirect( $url );
368
break;
369
+ case 'change_status_schedules':
370
+ if( !isset( $_REQUEST['chosen_schedules'] ) AND !isset( $_REQUEST['doaction'] ) AND -1 == $_REQUEST['doaction'] )
371
+ break;
372
+ $chosen_schedules = explode(',' , $_REQUEST['chosen_schedules'] );
373
+ $doaction = $_REQUEST['doaction'];
374
+
375
+ foreach ( $chosen_schedules as $schedule_id ) {
376
+ if ( 'activate' == $doaction ) {
377
+ $all_jobs[ $schedule_id ]['active'] = 1;
378
+ } elseif ( 'deactivate' == $doaction ) {
379
+ $all_jobs[ $schedule_id ]['active'] = 0;
380
+ } elseif ( 'delete' == $doaction ) {
381
+ unset( $all_jobs[ $schedule_id ] );
382
+ }
383
+ }
384
+ WC_Order_Export_Manage::save_export_settings_collection( $mode, $all_jobs );
385
+ $url = remove_query_arg( array( 'wc_oe', 'chosen_schedules', 'doaction' ) );
386
+ wp_redirect( $url );
387
+ break;
388
}
389
$this->render( 'tab/schedules', array( 'ajaxurl' => $ajaxurl, 'WC_Order_Export' => $this ) );
390
}
455
unset( $all_items[ $profile_id ] );
456
WC_Order_Export_Manage::save_export_settings_collection( $mode, $all_items );
457
break;
458
+ case 'change_profile_statuses':
459
+ if( !isset( $_REQUEST['chosen_profiles'] ) AND !isset( $_REQUEST['doaction'] ) AND -1 == $_REQUEST['doaction'] )
460
break;
461
+ $chosen_profiles = explode(',' , $_REQUEST['chosen_profiles'] );
462
+ $doaction = $_REQUEST['doaction'];
463
+
464
+ foreach ( $chosen_profiles as $profile_id ) {
465
+ if ( 'activate' == $doaction ) {
466
+ $all_items[ $profile_id ][ 'use_as_bulk' ] = 'on';
467
+ } elseif ( 'deactivate' == $doaction ) {
468
+ unset( $all_items[ $profile_id ][ 'use_as_bulk' ] );
469
+ } elseif ( 'delete' == $doaction ) {
470
+ unset( $all_items[ $profile_id ] );
471
+ }
472
+ }
473
WC_Order_Export_Manage::save_export_settings_collection( $mode, $all_items );
474
+ $url = remove_query_arg( array( 'wc_oe', 'chosen_profiles', 'doaction' ) );
475
wp_redirect( $url );
476
break;
477
}
500
wp_enqueue_script( 'export', $this->url_plugin . 'assets/js/export.js', array(), WOE_VERSION );
501
wp_enqueue_script( 'serializejson', $this->url_plugin . 'assets/js/jquery.serializejson.js', array('jquery'), WOE_VERSION );
502
wp_enqueue_style( 'export', $this->url_plugin . 'assets/css/export.css', array(), WOE_VERSION );
503
+ wp_enqueue_style( 'woocommerce_admin_styles', WC()->plugin_url() . '/assets/css/admin.css', array() );
504
+
505
+
506
// Localize the script with new data
507
$translation_array = array(
508
'empty_column_name' => __( 'empty column name', 'woo-order-export-lite' ),
509
'empty_meta_key' => __( 'empty meta key', 'woo-order-export-lite' ),
510
+ 'empty_meta_key_and_taxonomy' => __( 'select product field or item field or taxonomy', 'woo-order-export-lite' ),
511
'empty_value' => __( 'empty value', 'woo-order-export-lite' ),
512
'empty_title' => __( 'title is empty', 'woo-order-export-lite' ),
513
'wrong_date_range' => __( 'Date From is greater than Date To', 'woo-order-export-lite' ),
514
'no_fields' => __( 'Please, set up fields to export', 'woo-order-export-lite' ),
515
'no_results' => __( 'Nothing to export. Please, adjust your filters', 'woo-order-export-lite' ),
516
+ 'empty' => __( 'empty', 'woo-order-export-lite' ),
517
);
518
wp_localize_script( 'export', 'export_messages', $translation_array );
519
}
543
544
public function script_loader_src($src, $handle) {
545
// don't load ANY select2.js / select2.min.js and OUTDATED select2.full.js
546
+ if (!preg_match('/\/select2\.full\.js\?ver=[1-3]/', $src) && !preg_match('/\/select2\.min\.js/', $src) && !preg_match('/\/select2\.js/', $src)
547
+ && !preg_match('#jquery\.serialize-object\.#', $src) /*this script breaks our json!*/
548
+ ) {
549
return $src;
550
}
551
}
627
if ( isset( $_REQUEST['method'] ) ) {
628
$method = $_REQUEST['method'];
629
if ( method_exists( 'WC_Order_Export_Ajax', $method ) ) {
630
+ $_POST = stripslashes_deep($_POST);
631
// parse json to arrays?
632
if ( !empty($_POST['json']) ) {
633
$json = json_decode( $_POST['json'], true );
634
if( is_array($json) ) {
635
+ // add $_POST['settings'],$_POST['orders'],$_POST['products'],$_POST['coupons']
636
$_POST = $_POST + $json;
637
unset( $_POST['json'] );
638
}
673
674
$all_items = WC_Order_Export_Manage::get_export_settings_collection( WC_Order_Export_Manage::EXPORT_PROFILE );
675
foreach ( $all_items as $job_id => $job ) {
676
+ if ( isset( $job['use_as_bulk'] ) )
677
$actions['woe_export_selected_orders_profile_' . $job_id] = sprintf( __( "Export as profile '%s'", 'woo-order-export-lite' ), $job['title'] );
678
}
679
classes/core/class-wc-order-export-data-extractor-ui.php CHANGED
@@ -66,11 +66,44 @@ class WC_Order_Export_Data_Extractor_UI extends WC_Order_Export_Data_Extractor {
66
(SELECT DISTINCT ID FROM {$wpdb->posts} WHERE post_type IN ('product','product_variation') AND ID IN ($sql_products))" );
67
68
$fields = array_unique( array_merge( $wp_fields, $wc_fields ) );
69
- sort( $fields );
70
71
return apply_filters( 'get_all_product_custom_meta_fields_for_orders', $fields );
72
}
73
74
public static function get_all_product_custom_meta_fields() {
75
global $wpdb;
76
@@ -199,7 +232,7 @@ class WC_Order_Export_Data_Extractor_UI extends WC_Order_Export_Data_Extractor {
199
public static function get_products_itemmeta_values( $key ) {
200
global $wpdb;
201
$meta_key_ent = esc_html($key);
202
- $metas = $wpdb->get_col( $wpdb->prepare("SELECT DISTINCT meta_value FROM {$wpdb->prefix}woocommerce_order_itemmeta where meta_key = '%s' OR meta_key='%s'", $key, $meta_key_ent ));
203
sort( $metas );
204
return $metas;
205
}
@@ -271,6 +304,7 @@ class WC_Order_Export_Data_Extractor_UI extends WC_Order_Export_Data_Extractor {
271
'product_shipping_class' => array( 'label' => __( 'Product Shipping Class', 'woo-order-export-lite' ), 'checked' => 0 ),
272
'post_content'=> array( 'label' => __( 'Description', 'woo-order-export-lite' ), 'checked' => 0 ),
273
'post_excerpt'=> array( 'label' => __( 'Short Description', 'woo-order-export-lite' ), 'checked' => 0 ),
274
);
275
276
foreach ( $map as $key => $value ) {
@@ -322,6 +356,7 @@ class WC_Order_Export_Data_Extractor_UI extends WC_Order_Export_Data_Extractor {
322
323
public static function get_order_fields_common() {
324
return array(
325
'order_id' => array( 'label' => __( 'Order ID', 'woo-order-export-lite' ), 'checked' => 0 ),
326
'order_number' => array( 'label' => __( 'Order Number', 'woo-order-export-lite' ), 'checked' => 1 ),
327
'order_status' => array( 'label' => __( 'Order Status', 'woo-order-export-lite' ), 'checked' => 1 ),
@@ -410,6 +445,7 @@ class WC_Order_Export_Data_Extractor_UI extends WC_Order_Export_Data_Extractor {
410
'cart_discount' => array( 'label' => __( 'Cart Discount Amount', 'woo-order-export-lite' ), 'checked' => 1, 'format'=>'money' ),
411
'cart_discount_tax' => array( 'label' => __( 'Cart Discount Amount Tax', 'woo-order-export-lite' ), 'checked' => 0, 'format'=>'money' ),
412
'order_subtotal' => array( 'label' => __( 'Order Subtotal Amount', 'woo-order-export-lite' ), 'checked' => 1, 'format'=>'money' ),
413
'order_subtotal_refunded'=> array( 'label' => __( 'Order Subtotal Amount Refunded', 'woo-order-export-lite' ), 'checked' => 0, 'format'=>'money' ),
414
'order_subtotal_minus_refund'=> array( 'label' => __( 'Order Subtotal Amount (- Refund)', 'woo-order-export-lite' ), 'checked' => 0, 'format'=>'money' ),
415
'order_tax' => array( 'label' => __( 'Order Tax Amount', 'woo-order-export-lite' ), 'checked' => 0, 'format'=>'money' ),
66
(SELECT DISTINCT ID FROM {$wpdb->posts} WHERE post_type IN ('product','product_variation') AND ID IN ($sql_products))" );
67
68
$fields = array_unique( array_merge( $wp_fields, $wc_fields ) );
69
+ $fields = sort( $fields );
70
71
return apply_filters( 'get_all_product_custom_meta_fields_for_orders', $fields );
72
}
73
74
+ public static function get_order_item_custom_meta_fields_for_orders( $sql_order_ids ) {
75
+ global $wpdb;
76
+
77
+ $wc_fields = $wpdb->get_col( "SELECT DISTINCT meta_key FROM {$wpdb->prefix}woocommerce_order_itemmeta WHERE order_item_id IN
78
+ (SELECT DISTINCT order_item_id FROM {$wpdb->prefix}woocommerce_order_items WHERE order_item_type = 'line_item' AND order_id IN ($sql_order_ids))" );
79
+ // WC internal table add attributes
80
+ $wc_attr_fields = $wpdb->get_results( "SELECT DISTINCT attribute_name FROM {$wpdb->prefix}woocommerce_attribute_taxonomies" );
81
+ foreach ( $wc_attr_fields as $f ) {
82
+ $wc_fields[] = 'pa_' . $f->attribute_name;
83
+ }
84
+
85
+ $wc_fields = array_unique($wc_fields);
86
+ sort($wc_fields);
87
+
88
+
89
+
90
+ return apply_filters( 'get_order_item_custom_meta_fields_for_orders', $wc_fields );
91
+ }
92
+
93
+ public static function get_product_custom_meta_fields_for_orders( $sql_order_ids ) {
94
+ global $wpdb;
95
+
96
+ $sql_products = "SELECT DISTINCT meta_value FROM {$wpdb->prefix}woocommerce_order_itemmeta WHERE meta_key ='_product_id' AND order_item_id IN
97
+ (SELECT DISTINCT order_item_id FROM {$wpdb->prefix}woocommerce_order_items WHERE order_item_type = 'line_item' AND order_id IN ($sql_order_ids))";
98
+
99
+ $wp_fields = $wpdb->get_col( "SELECT DISTINCT meta_key FROM {$wpdb->postmeta} WHERE post_id IN
100
+ (SELECT DISTINCT ID FROM {$wpdb->posts} WHERE post_type IN ('product','product_variation') AND ID IN ($sql_products))" );
101
+
102
+ sort($wp_fields);
103
+
104
+ return apply_filters( 'get_product_custom_meta_fields_for_orders', $wp_fields );
105
+ }
106
+
107
public static function get_all_product_custom_meta_fields() {
108
global $wpdb;
109
232
public static function get_products_itemmeta_values( $key ) {
233
global $wpdb;
234
$meta_key_ent = esc_html($key);
235
+ $metas = $wpdb->get_col( $wpdb->prepare("SELECT DISTINCT meta_value FROM {$wpdb->prefix}woocommerce_order_itemmeta where meta_key = '%s' OR meta_key='%s' LIMIT 100", $key, $meta_key_ent ));
236
sort( $metas );
237
return $metas;
238
}
304
'product_shipping_class' => array( 'label' => __( 'Product Shipping Class', 'woo-order-export-lite' ), 'checked' => 0 ),
305
'post_content'=> array( 'label' => __( 'Description', 'woo-order-export-lite' ), 'checked' => 0 ),
306
'post_excerpt'=> array( 'label' => __( 'Short Description', 'woo-order-export-lite' ), 'checked' => 0 ),
307
+ 'full_category_names' => array( 'label' => __( 'Full names for categories', 'woo-order-export-lite' ), 'checked' => 0 )
308
);
309
310
foreach ( $map as $key => $value ) {
356
357
public static function get_order_fields_common() {
358
return array(
359
+ 'line_number' => array( 'label' => __( 'Line number', 'woo-order-export-lite' ), 'checked' => 0 ),
360
'order_id' => array( 'label' => __( 'Order ID', 'woo-order-export-lite' ), 'checked' => 0 ),
361
'order_number' => array( 'label' => __( 'Order Number', 'woo-order-export-lite' ), 'checked' => 1 ),
362
'order_status' => array( 'label' => __( 'Order Status', 'woo-order-export-lite' ), 'checked' => 1 ),
445
'cart_discount' => array( 'label' => __( 'Cart Discount Amount', 'woo-order-export-lite' ), 'checked' => 1, 'format'=>'money' ),
446
'cart_discount_tax' => array( 'label' => __( 'Cart Discount Amount Tax', 'woo-order-export-lite' ), 'checked' => 0, 'format'=>'money' ),
447
'order_subtotal' => array( 'label' => __( 'Order Subtotal Amount', 'woo-order-export-lite' ), 'checked' => 1, 'format'=>'money' ),
448
+ 'order_subtotal_minus_discount' => array( 'label' => 'Order Subtotal - Cart Discount', 'colname' => 'Order Subtotal - Cart Discount', 'checked' => 0 ),
449
'order_subtotal_refunded'=> array( 'label' => __( 'Order Subtotal Amount Refunded', 'woo-order-export-lite' ), 'checked' => 0, 'format'=>'money' ),
450
'order_subtotal_minus_refund'=> array( 'label' => __( 'Order Subtotal Amount (- Refund)', 'woo-order-export-lite' ), 'checked' => 0, 'format'=>'money' ),
451
'order_tax' => array( 'label' => __( 'Order Tax Amount', 'woo-order-export-lite' ), 'checked' => 0, 'format'=>'money' ),
classes/core/class-wc-order-export-data-extractor.php CHANGED
@@ -13,6 +13,10 @@ class WC_Order_Export_Data_Extractor {
13
static $current_order;
14
static $date_format;
15
static $object_type = 'shop_order';
16
const HUGE_SHOP_ORDERS = 1000;// more than 1000 orders
17
const HUGE_SHOP_PRODUCTS = 1000;// more than 1000 products
18
@@ -151,21 +155,33 @@ class WC_Order_Export_Data_Extractor {
151
'=' => 'IN',
152
'<>' => 'NOT IN',
153
'LIKE' => 'LIKE',
154
);
155
foreach ( $pairs as $pair ) {
156
$pair = trim( $pair );
157
$op = '';
158
foreach($delimiters as $delim=>$op_seek) {
159
$t = explode( $delim, $pair );
160
- if(count($t) == 2) {
161
$op = $op_seek;
162
break;
163
}
164
}
165
if( !$op )
166
continue;
167
168
list( $filter_type, $filter_value ) = array_map("trim", $t);
169
170
if ( $mode == 'lower_filter_label' ) {
171
$filter_type = strtolower( $filter_type );
@@ -349,7 +365,6 @@ class WC_Order_Export_Data_Extractor {
349
$left_join_product_meta = join( " ", $left_join_product_meta );
350
}
351
}
352
-
353
//done
354
$product_where = join(" AND ", $product_where);
355
$sql = "SELECT DISTINCT ID FROM {$wpdb->posts} AS products $left_join_product_meta WHERE products.post_type in ('product','product_variation') AND products.post_status<>'trash' AND $product_where ";
@@ -362,7 +377,9 @@ class WC_Order_Export_Data_Extractor {
362
$sql = "SELECT DISTINCT ID FROM {$wpdb->posts} AS products WHERE products.post_type in ('product','product_variation') AND products.post_status<>'trash' AND post_parent IN ($values)";
363
$settings['products'] = $wpdb->get_col($sql);
364
}
365
-
366
return apply_filters('woe_sql_adjust_products', $settings['products'] , $settings);
367
}
368
@@ -375,19 +392,21 @@ class WC_Order_Export_Data_Extractor {
375
if ( $settings['product_taxonomies'] ) {
376
$attrs = self::get_product_taxonomies();
377
$names2fields = array_flip( $attrs );
378
- $filters = self::parse_pairs( $settings['product_taxonomies'], $attrs );
379
//print_r($filters );die();
380
- foreach ( $filters as $label => $values ) {
381
- $field = $names2fields[ $label ];
382
- $values = self::sql_subset( $values );
383
- if ( $values ) {
384
- $taxonomy_where_object_id = $taxonomy_where ? "AND object_id IN ($taxonomy_where)" : "";
385
- $taxonomy_where = "(SELECT object_id FROM {$wpdb->term_relationships} AS `{$field}_rel`
386
- INNER JOIN {$wpdb->term_taxonomy} AS `{$field}_cat` ON `{$field}_cat`.term_taxonomy_id = `{$field}_rel`.term_taxonomy_id
387
- WHERE `{$field}_cat`.term_id IN (SELECT term_id FROM {$wpdb->terms} WHERE name IN($values) ) $taxonomy_where_object_id
388
- )";
389
}
390
- }
391
}
392
393
$product_category_where = $taxonomy_where;
@@ -527,13 +546,30 @@ class WC_Order_Export_Data_Extractor {
527
}
528
// shipping methods
529
if ( ! empty( $settings['shipping_methods'] ) ) {
530
- $like_values = array();
531
- foreach($settings['shipping_methods'] as $value)
532
- $like_values[] = "(shipping_itemmeta.meta_value LIKE '$value%') ";
533
- $like_values = join( " OR ", $like_values);
534
$order_items_where .= " AND orders.ID IN (SELECT order_shippings.order_id FROM {$wpdb->prefix}woocommerce_order_items as order_shippings
535
LEFT JOIN {$wpdb->prefix}woocommerce_order_itemmeta AS shipping_itemmeta ON shipping_itemmeta.order_item_id = order_shippings.order_item_id
536
- WHERE order_shippings.order_item_type='shipping' AND shipping_itemmeta.meta_key='method_id' AND ( $like_values ) )";
537
}
538
539
// pre top
@@ -554,16 +590,20 @@ class WC_Order_Export_Data_Extractor {
554
foreach ( $filters as $operator => $fields) {
555
foreach ( $fields as $field => $values ) {
556
if ( $values ) {
557
- $left_join_order_meta[] = "LEFT JOIN {$wpdb->postmeta} AS ordermeta_cf_{$pos} ON ordermeta_cf_{$pos}.post_id = orders.ID";
558
if( $operator == 'IN' OR $operator == 'NOT IN' ) {
559
$values = self::sql_subset( $values );
560
- $order_meta_where [] = " (ordermeta_cf_{$pos}.meta_key='$field' AND ordermeta_cf_{$pos}.meta_value $operator ($values)) ";
561
} elseif( $operator =='LIKE' ) {
562
$pairs = array();
563
foreach($values as $v)
564
$pairs[] = " ordermeta_cf_{$pos}.meta_value LIKE '$v' ";
565
$pairs = join("OR", $pairs);
566
- $order_meta_where[] = " (ordermeta_cf_{$pos}.meta_key='$field' AND ($pairs) ) ";
567
}
568
$pos++;
569
}//if values
@@ -652,13 +692,16 @@ class WC_Order_Export_Data_Extractor {
652
$sql = "SELECT " . apply_filters( "woe_sql_get_order_ids_fields", "ID AS order_id" ) . " FROM {$wpdb->posts} AS orders
653
{$left_join_order_meta}
654
WHERE orders.post_type in ( $order_types) AND $order_sql $order_meta_where $order_items_where";
655
//die($sql);
656
return $sql;
657
}
658
659
private static function add_date_filter(&$where, &$where_meta, $date_field, $value) {
660
if( $date_field == 'date_paid' OR $date_field == 'date_completed') // 3.0+ uses timestamp
661
- $where_meta[] = "(order_$date_field.meta_value>0 AND FROM_UNIXTIME(order_$date_field.meta_value) " . $value.")";
662
elseif( $date_field == 'paid_date' OR $date_field == 'completed_date') // previous versions use mysql datetime
663
$where_meta[] = "(order_$date_field.meta_value<>'' AND order_$date_field.meta_value " . $value.")";
664
else
@@ -672,28 +715,25 @@ class WC_Order_Export_Data_Extractor {
672
$settings[ 'export_rule_field' ] = 'modified';
673
674
$date_field = $settings[ 'export_rule_field' ];
675
//rename this field for 2.6 and less
676
if( !method_exists( 'WC_Order', "get_date_completed") ) {
677
- if( $date_field == 'date_paid')
678
$date_field = 'paid_date';
679
- elseif( $date_field == 'date_completed')
680
$date_field = 'completed_date';
681
}
682
$where_meta = array();
683
684
685
- if ( $settings['from_date'] ) {
686
- $from_date = date( 'Y-m-d', strtotime( $settings['from_date'] ) );
687
- if ( $from_date ) {
688
- self::add_date_filter($where, $where_meta, $date_field, ">='$from_date 00:00:00'" );
689
- }
690
- }
691
- if ( $settings['to_date'] ) {
692
- $to_date = date( 'Y-m-d', strtotime( $settings['to_date'] ) );
693
- if ( $to_date ) {
694
- self::add_date_filter($where, $where_meta, $date_field, "<='$to_date 23:59:59'" );
695
- }
696
}
697
if ( $settings['statuses'] ) {
698
$values = self::sql_subset( $settings['statuses'] );
699
if ( $values ) {
@@ -701,99 +741,159 @@ class WC_Order_Export_Data_Extractor {
701
}
702
}
703
704
- //export rule
705
$_time = current_time( "timestamp", 0 );
706
707
- //skip rules if data range defined
708
- if( ! isset($settings[ 'export_rule' ])/* OR $settings['from_date'] OR $settings['to_date']*/ )
709
- $settings[ 'export_rule' ] = '';
710
711
- switch ( $settings[ 'export_rule' ] ) {
712
case "last_run":
713
- if ( !empty( $settings[ 'schedule' ][ 'last_run' ] ) ) {
714
- self::add_date_filter($where, $where_meta, $date_field, ' >= "' . date( 'Y-m-d H:i:s', $settings[ 'schedule' ][ 'last_run' ] ) . '"' );
715
}
716
break;
717
case "today":
718
- $_date = date( 'Y-m-d', $_time );
719
- self::add_date_filter($where, $where_meta, $date_field, ">='$_date 00:00:00'" );
720
- self::add_date_filter($where, $where_meta, $date_field, "<='$_date 23:59:59'" );
721
break;
722
case "this_week":
723
- $day = date( 'w', $_time );
724
- $_date = date( 'Y-m-d', $_time );
725
- $week_start = date( 'Y-m-d', strtotime( $_date . ' -' . $day . ' days' ) );
726
- $week_end = date( 'Y-m-d', strtotime( $_date . ' +' . (6 - $day) . ' days' ) );
727
- self::add_date_filter($where, $where_meta, $date_field, ">='$week_start 00:00:00'" );
728
- self::add_date_filter($where, $where_meta, $date_field, "<='$week_end 23:59:59'" );
729
break;
730
case "this_month":
731
$month_start = date( 'Y-m-01', $_time );
732
- $month_end = date( 'Y-m-t', $_time );
733
- self::add_date_filter($where, $where_meta, $date_field, ">='$month_start 00:00:00'" );
734
- self::add_date_filter($where, $where_meta, $date_field, "<='$month_end 23:59:59'" );
735
break;
736
case "last_day":
737
- $_date = date( 'Y-m-d', $_time );
738
- $last_day = strtotime($_date." -1 day");
739
- $_date = date( 'Y-m-d', $last_day );
740
- self::add_date_filter($where, $where_meta, $date_field, ">='$_date 00:00:00'" );
741
- self::add_date_filter($where, $where_meta, $date_field, "<='$_date 23:59:59'" );
742
break;
743
case "last_week":
744
- $day = date( 'w', $_time );
745
- $_date = date( 'Y-m-d', $_time );
746
- $last_week = strtotime($_date." -1 week");
747
- $week_start = date( 'Y-m-d', strtotime( date( 'Y-m-d', $last_week ) . ' -' . $day . ' days' ) );
748
- $week_end = date( 'Y-m-d', strtotime( date( 'Y-m-d', $last_week ) . ' +' . (6 - $day) . ' days' ) );
749
- self::add_date_filter($where, $where_meta, $date_field, ">='$week_start 00:00:00'" );
750
- self::add_date_filter($where, $where_meta, $date_field, "<='$week_end 23:59:59'" );
751
break;
752
case "last_month":
753
- $_date = date( 'Y-m-d', $_time );
754
- $last_month = strtotime($_date." -1 month");
755
$month_start = date( 'Y-m-01', $last_month );
756
- $month_end = date( 'Y-m-t', $last_month );
757
- self::add_date_filter($where, $where_meta, $date_field, ">='$month_start 00:00:00'" );
758
- self::add_date_filter($where, $where_meta, $date_field, "<='$month_end 23:59:59'" );
759
break;
760
case "last_quarter":
761
- $_date = date( 'Y-m-d', $_time );
762
- $last_month = strtotime($_date." -3 month");
763
- $quarter_start = date( 'Y-'. self::get_quarter_month($last_month).'-01', $last_month );
764
- $quarter_end = date( 'Y-'. (self::get_quarter_month($last_month)+2).'-31', $last_month );
765
- self::add_date_filter($where, $where_meta, $date_field, ">='$quarter_start 00:00:00'" );
766
- self::add_date_filter($where, $where_meta, $date_field, "<='$quarter_end 23:59:59'" );
767
break;
768
case "this_year":
769
- $year_start = date( 'Y-01-01', $_time );
770
- self::add_date_filter($where, $where_meta, $date_field, ">='$year_start 00:00:00'" );
771
break;
772
case "custom":
773
- if ( isset( $settings[ 'export_rule_custom' ] ) && ($settings[ 'export_rule_custom' ]) ) {
774
- $day_start = date( 'Y-m-d', strtotime( date( 'Y-m-d', $_time ) . ' -' . intval( $settings[ 'export_rule_custom' ] ) . ' days' ) );
775
- $day_end = date( 'Y-m-d', $_time );
776
- self::add_date_filter($where, $where_meta, $date_field, ">='$day_start 00:00:00'" );
777
- self::add_date_filter($where, $where_meta, $date_field, "<='$day_end 23:59:59'" );
778
}
779
break;
780
default:
781
break;
782
}
783
- //end export rule
784
785
- //for date_paid or date_completed
786
- if( $where_meta ) {
787
- $where_meta = join( " AND ", $where_meta );
788
- $where[] = "orders.id IN ( SELECT post_id FROM {$wpdb->postmeta} AS order_$date_field WHERE order_$date_field.meta_key ='_$date_field' AND $where_meta)";
789
}
790
-
791
- // skip child orders?
792
- if( $settings['skip_suborders'] AND !$settings['export_refunds'])
793
- $where[] = "orders.post_parent=0";
794
795
- // Skip drafts and deleted
796
- $where[] = "orders.post_status NOT in ('auto-draft','trash')";
797
}
798
799
public static function get_quarter_month( $time ) {
@@ -815,8 +915,21 @@ class WC_Order_Export_Data_Extractor {
815
self::$decimal_separator = wc_get_price_decimal_separator();
816
self::$thousands_separator = apply_filters( 'woe_thousands_separator', '' );
817
self::$decimals = wc_get_price_decimals();
818
}
819
820
public static function get_max_order_items( $type, $ids ) {
821
global $wpdb;
822
@@ -877,7 +990,6 @@ class WC_Order_Export_Data_Extractor {
877
} else {
878
$row[ $field ] = '';
879
}
880
-
881
if ( isset( $filters_active[ $field ] ) ) {
882
$row[ $field ] = apply_filters( "woe_get_order_coupon_value_{$field}", $row[ $field ], $order, $item );
883
$row[ $field ] = apply_filters( "woe_get_order_coupon_{$format}_value_{$field}", $row[ $field ], $order, $item );
@@ -976,14 +1088,6 @@ class WC_Order_Export_Data_Extractor {
976
$row[ $field ] = ""; // unknown class
977
} elseif ( $field == 'line_total_plus_tax' ) {
978
$row[ $field ] = $item_meta["_line_total"][0] + $item_meta["_line_tax"][0];
979
- } elseif ( isset( $item_meta[ $field ] ) ) { //meta from order
980
- $row[ $field ] = $item_meta[ $field ][0];
981
- } elseif ( isset( $item_meta[ "_" . $field ] ) ) {// or hidden field
982
- $row[ $field ] = $item_meta[ "_" . $field ][0];
983
- } elseif ( isset( $item['item_meta'][ $field ] ) ) { // meta from item line
984
- $row[ $field ] = $item['item_meta'][ $field ][0];
985
- } elseif ( isset( $item['item_meta'][ "_" . $field ] ) ) { // or hidden field
986
- $row[ $field ] = $item['item_meta'][ "_" . $field ][0];
987
} elseif ( $field == 'name' ) {
988
$row['name'] = $item["name"];
989
} elseif ( $field == 'product_variation' ) {
@@ -1055,7 +1159,9 @@ class WC_Order_Export_Data_Extractor {
1055
}
1056
$row[ $field ] = ($subtotal_amount>0) ? round( 100*$subtotal_tax/$subtotal_amount, 2) : 0;
1057
} elseif ( $field == 'product_url' ) {
1058
- $row[ $field ] = get_permalink( $product_id );
1059
} elseif ( $field == 'download_url' ) {
1060
$row[ $field ] = '';
1061
if ( $product AND $product->is_downloadable() ) {
@@ -1068,9 +1174,20 @@ class WC_Order_Export_Data_Extractor {
1068
$row[ $field ] = implode( "\n", $links );
1069
}
1070
} elseif ( $field == 'image_url' ) {
1071
- $row[ $field ] = ($product AND $product->get_image_id() ) ? current( wp_get_attachment_image_src( $product->get_image_id(), 'full') ) : ''; // make full url
1072
} elseif ( isset( $static_vals[ $field ] ) ) {
1073
$row[ $field ] = $static_vals[ $field ];
1074
} else {
1075
$row[ $field ] = '';
1076
if( !empty( $item['variation_id'] ) )
@@ -1102,6 +1219,29 @@ class WC_Order_Export_Data_Extractor {
1102
return apply_filters( "woe_fetch_order_products", $products, $order, $labels, $format, $static_vals );
1103
}
1104
1105
public static function get_order_item_taxes_refund($order, $item_id) {
1106
$tax_refund = 0;
1107
$order_taxes = $order->get_taxes();
@@ -1218,6 +1358,8 @@ class WC_Order_Export_Data_Extractor {
1218
$row['order_number'] = $parent_order ? $parent_order->get_order_number() : $order->get_order_number(); // use parent order number
1219
} elseif ( $field == 'order_subtotal' ) {
1220
$row['order_subtotal'] = wc_format_decimal( $order->get_subtotal(), 2);
1221
} elseif ( $field == 'order_subtotal_refunded' ) {
1222
$row['order_subtotal_refunded'] = wc_format_decimal( self::get_order_subtotal_refunded($order), 2);
1223
} elseif ( $field == 'order_subtotal_minus_refund' ) {
@@ -1389,7 +1531,7 @@ class WC_Order_Export_Data_Extractor {
1389
}
1390
1391
// Must fill child cells?
1392
- if ( !$options['item_rows_start_from_new_line'] AND @$options['populate_other_columns_product_rows'] AND $extra_rows ) {
1393
foreach ( $extra_rows as $idx=> $extra_row ) {
1394
foreach ( $row as $key=> $val ) {
1395
if ( in_array( $key, $order_fields) )
@@ -1416,7 +1558,7 @@ class WC_Order_Export_Data_Extractor {
1416
return apply_filters("woe_fetch_order_data",$extra_rows);
1417
}
1418
1419
- private static function get_city_state_postcode_field_value( $order, $type ) {
1420
if ( $type != 'shipping' && $type != 'billing') {
1421
return null;
1422
}
@@ -1573,21 +1715,21 @@ class WC_Order_Export_Data_Extractor {
1573
* @return array
1574
*/
1575
public static function get_shipping_methods() {
1576
-
1577
if( !class_exists("WC_Shipping_Zone") )
1578
- return array();
1579
1580
if( !method_exists("WC_Shipping_Zone", "get_shipping_methods") )
1581
- return array();
1582
-
1583
- $shipping_methods = array();
1584
-
1585
- $zone = new WC_Shipping_Zone( 0 );
1586
- $methods = $zone->get_shipping_methods();
1587
- /** @var WC_Shipping_Method $method */
1588
- foreach ( $methods as $method ) {
1589
- $shipping_methods[ $method->get_rate_id() ] = __('[Rest of the World]', 'woo-order-export-lite' ) .' '. $method->get_title();
1590
- }
1591
1592
foreach ( WC_Shipping_Zones::get_zones() as $zone ) {
1593
$methods = $zone['shipping_methods'];
@@ -1596,6 +1738,14 @@ class WC_Order_Export_Data_Extractor {
1596
$shipping_methods[ $method->get_rate_id() ] = '[' . $zone['zone_name'] . '] ' . $method->get_title();
1597
}
1598
}
1599
return $shipping_methods;
1600
}
1601
13
static $current_order;
14
static $date_format;
15
static $object_type = 'shop_order';
16
+ static $export_subcategories_separator;
17
+ static $export_line_categories_separator;
18
+ static $track_sql_queries = false;
19
+ static $sql_queries;
20
const HUGE_SHOP_ORDERS = 1000;// more than 1000 orders
21
const HUGE_SHOP_PRODUCTS = 1000;// more than 1000 products
22
155
'=' => 'IN',
156
'<>' => 'NOT IN',
157
'LIKE' => 'LIKE',
158
+ 'NOT SET' => 'NOT SET',
159
+ 'IS SET' => 'IS SET',
160
);
161
+ $single_ops = array('NOT SET', 'IS SET');
162
+
163
foreach ( $pairs as $pair ) {
164
$pair = trim( $pair );
165
$op = '';
166
+ $single_op = false;
167
foreach($delimiters as $delim=>$op_seek) {
168
$t = explode( $delim, $pair );
169
+ $single_op = in_array($delim,$single_ops);
170
+ if( count($t) == 2 ) {
171
$op = $op_seek;
172
break;
173
}
174
}
175
if( !$op )
176
continue;
177
+ if( $single_op )
178
+ $t[1] = '';
179
180
list( $filter_type, $filter_value ) = array_map("trim", $t);
181
+ $empty = __( 'empty', 'woo-order-export-lite' );
182
+ if ( $empty == $filter_value ) {
183
+ $filter_value = '';
184
+ }
185
186
if ( $mode == 'lower_filter_label' ) {
187
$filter_type = strtolower( $filter_type );
365
$left_join_product_meta = join( " ", $left_join_product_meta );
366
}
367
}
368
//done
369
$product_where = join(" AND ", $product_where);
370
$sql = "SELECT DISTINCT ID FROM {$wpdb->posts} AS products $left_join_product_meta WHERE products.post_type in ('product','product_variation') AND products.post_status<>'trash' AND $product_where ";
377
$sql = "SELECT DISTINCT ID FROM {$wpdb->posts} AS products WHERE products.post_type in ('product','product_variation') AND products.post_status<>'trash' AND post_parent IN ($values)";
378
$settings['products'] = $wpdb->get_col($sql);
379
}
380
+ if( !empty($sql) AND self::$track_sql_queries )
381
+ self::$sql_queries[] = $sql;
382
+
383
return apply_filters('woe_sql_adjust_products', $settings['products'] , $settings);
384
}
385
392
if ( $settings['product_taxonomies'] ) {
393
$attrs = self::get_product_taxonomies();
394
$names2fields = array_flip( $attrs );
395
+ $filters = self::parse_complex_pairs( $settings['product_taxonomies'], $attrs );
396
//print_r($filters );die();
397
+ foreach ( $filters as $operator => $fields) {
398
+ foreach ( $fields as $label => $values ) {
399
+ $field = $names2fields[ $label ];
400
+ $values = self::sql_subset( $values );
401
+ if ( $values ) {
402
+ $taxonomy_where_object_id = $taxonomy_where ? "AND object_id IN ($taxonomy_where)" : "";
403
+ $taxonomy_where = "(SELECT object_id FROM {$wpdb->term_relationships} AS `{$field}_rel`
404
+ INNER JOIN {$wpdb->term_taxonomy} AS `{$field}_cat` ON `{$field}_cat`.term_taxonomy_id = `{$field}_rel`.term_taxonomy_id
405
+ WHERE `{$field}_cat`.term_id IN (SELECT term_id FROM {$wpdb->terms} WHERE name $operator ($values) ) $taxonomy_where_object_id
406
+ )";
407
+ }
408
}
409
+ }
410
}
411
412
$product_category_where = $taxonomy_where;
546
}
547
// shipping methods
548
if ( ! empty( $settings['shipping_methods'] ) ) {
549
+ $zone_values = $itemname_values = array();
550
+ foreach($settings['shipping_methods'] as $value) {
551
+ if( preg_match('#^order_item_name:(.+)#',$value, $m) )
552
+ $itemname_values[] = "'" . esc_sql($m[1]) . "'";
553
+ else
554
+ $zone_values[] = "(shipping_itemmeta.meta_value LIKE '$value%') ";
555
+ }
556
+
557
+ // where by type!
558
+ $ship_where = array();
559
+ if( $zone_values ) {
560
+ $zone_values = join( " OR ", $zone_values);
561
+ $ship_where[] = " (shipping_itemmeta.meta_key='method_id' AND ( $zone_values ) ) ";
562
+ }
563
+ if( $itemname_values ) {
564
+ $itemname_values = join(",", $itemname_values );
565
+ $ship_where[] = " (order_shippings.order_item_name IN ( $itemname_values ) ) ";
566
+ }
567
+ $ship_where = join( ' OR ', $ship_where);
568
+
569
+ //done
570
$order_items_where .= " AND orders.ID IN (SELECT order_shippings.order_id FROM {$wpdb->prefix}woocommerce_order_items as order_shippings
571
LEFT JOIN {$wpdb->prefix}woocommerce_order_itemmeta AS shipping_itemmeta ON shipping_itemmeta.order_item_id = order_shippings.order_item_id
572
+ WHERE order_shippings.order_item_type='shipping' AND $ship_where )";
573
}
574
575
// pre top
590
foreach ( $filters as $operator => $fields) {
591
foreach ( $fields as $field => $values ) {
592
if ( $values ) {
593
+ $left_join_order_meta[] = "LEFT JOIN {$wpdb->postmeta} AS ordermeta_cf_{$pos} ON ordermeta_cf_{$pos}.post_id = orders.ID AND ordermeta_cf_{$pos}.meta_key='$field'";
594
if( $operator == 'IN' OR $operator == 'NOT IN' ) {
595
$values = self::sql_subset( $values );
596
+ $order_meta_where [] = " ( ordermeta_cf_{$pos}.meta_value $operator ($values) ) ";
597
+ } elseif( $operator == 'NOT SET' ) {
598
+ $order_meta_where [] = " ( ordermeta_cf_{$pos}.meta_value IS NULL ) ";
599
+ } elseif( $operator == 'IS SET' ) {
600
+ $order_meta_where [] = " ( ordermeta_cf_{$pos}.meta_value IS NOT NULL ) ";
601
} elseif( $operator =='LIKE' ) {
602
$pairs = array();
603
foreach($values as $v)
604
$pairs[] = " ordermeta_cf_{$pos}.meta_value LIKE '$v' ";
605
$pairs = join("OR", $pairs);
606
+ $order_meta_where[] = " ( $pairs ) ";
607
}
608
$pos++;
609
}//if values
692
$sql = "SELECT " . apply_filters( "woe_sql_get_order_ids_fields", "ID AS order_id" ) . " FROM {$wpdb->posts} AS orders
693
{$left_join_order_meta}
694
WHERE orders.post_type in ( $order_types) AND $order_sql $order_meta_where $order_items_where";
695
+
696
+ if( self::$track_sql_queries )
697
+ self::$sql_queries[] = $sql;
698
//die($sql);
699
return $sql;
700
}
701
702
private static function add_date_filter(&$where, &$where_meta, $date_field, $value) {
703
if( $date_field == 'date_paid' OR $date_field == 'date_completed') // 3.0+ uses timestamp
704
+ $where_meta[] = "(order_$date_field.meta_value>0 AND order_$date_field.meta_value $value )";
705
elseif( $date_field == 'paid_date' OR $date_field == 'completed_date') // previous versions use mysql datetime
706
$where_meta[] = "(order_$date_field.meta_value<>'' AND order_$date_field.meta_value " . $value.")";
707
else
715
$settings[ 'export_rule_field' ] = 'modified';
716
717
$date_field = $settings[ 'export_rule_field' ];
718
+ $use_timestamps = ( $date_field == 'date_paid' OR $date_field == 'date_completed' );
719
//rename this field for 2.6 and less
720
if( !method_exists( 'WC_Order', "get_date_completed") ) {
721
+ $use_timestamps = false;
722
+ if( $date_field == 'date_paid' )
723
$date_field = 'paid_date';
724
+ elseif( $date_field == 'date_completed' )
725
$date_field = 'completed_date';
726
}
727
$where_meta = array();
728
729
+ // export and date rule
730
731
+ foreach (self::get_date_range( $settings, true, $use_timestamps ) as $date ) {
732
+ self::add_date_filter( $where, $where_meta, $date_field, $date );
733
}
734
+
735
+ // end export and date rule
736
+
737
if ( $settings['statuses'] ) {
738
$values = self::sql_subset( $settings['statuses'] );
739
if ( $values ) {
741
}
742
}
743
744
+ //for date_paid or date_completed
745
+ if( $where_meta ) {
746
+ $where_meta = join( " AND ", $where_meta );
747
+ $where[] = "orders.id IN ( SELECT post_id FROM {$wpdb->postmeta} AS order_$date_field WHERE order_$date_field.meta_key ='_$date_field' AND $where_meta)";
748
+ }
749
+
750
+ // skip child orders?
751
+ if( $settings['skip_suborders'] AND !$settings['export_refunds'])
752
+ $where[] = "orders.post_parent=0";
753
+
754
+ // Skip drafts and deleted
755
+ $where[] = "orders.post_status NOT in ('auto-draft','trash')";
756
+ }
757
+
758
+ public static function get_date_range( $settings, $is_for_sql, $use_timestamps=false ) {
759
+ $result = array();
760
+
761
+ // fixed date range
762
+ if ( !empty( $settings['from_date'] ) OR !empty( $settings['to_date'] ) ) {
763
+ if ( $settings['from_date'] ) {
764
+ $from_date = date( 'Y-m-d', strtotime( $settings['from_date'] ) ) . " 00:00:00";
765
+ if ( $is_for_sql ) {
766
+ if( $use_timestamps )
767
+ $from_date = mysql2date( 'U', $from_date );
768
+ $from_date = sprintf( ">='%s'", $from_date );
769
+ }
770
+ $result['from_date'] = $from_date;
771
+ }
772
+
773
+ if ( $settings['to_date'] ) {
774
+ $to_date = date( 'Y-m-d', strtotime( $settings['to_date'] ) ) . " 23:59:59";
775
+ if ( $is_for_sql ) {
776
+ if( $use_timestamps )
777
+ $to_date = mysql2date( 'U', $to_date );
778
+ $to_date = sprintf( "<='%s'", $to_date );
779
+ }
780
+ $result['to_date'] = $to_date;
781
+ }
782
+ return $result;
783
+ }
784
+
785
$_time = current_time( "timestamp", 0 );
786
787
+ $export_rule = isset( $settings['export_rule'] ) ? $settings['export_rule'] : '';
788
789
+ switch ( $export_rule ) {
790
+ case "none":
791
+ unset( $from_date );
792
+ unset( $to_date );
793
+ break;
794
case "last_run":
795
+ $last_run = isset( $settings['schedule']['last_run'] ) ? $settings['schedule']['last_run'] : '';
796
+ if ( isset( $last_run ) AND $last_run ) {
797
+ $from_date = date( 'Y-m-d H:i:s', $last_run );
798
}
799
break;
800
case "today":
801
+ $_date = date( 'Y-m-d', $_time );
802
+
803
+ $from_date = sprintf( '%s %s', $_date, '00:00:00' );
804
+ $to_date = sprintf( '%s %s', $_date, '23:59:59' );
805
break;
806
case "this_week":
807
+ $day = ( date( 'w', $_time ) + 6 ) % 7;// 0 - Sun , must be Mon = 0
808
+ $_date = date( 'Y-m-d', $_time );
809
+ $week_start = date( 'Y-m-d', strtotime( $_date . ' -' . $day . ' days' ) );
810
+ $week_end = date( 'Y-m-d', strtotime( $_date . ' +' . ( 6 - $day ) . ' days' ) );
811
+
812
+ $from_date = sprintf( '%s %s', $week_start, '00:00:00' );
813
+ $to_date = sprintf( '%s %s', $week_end, '23:59:59' );
814
break;
815
case "this_month":
816
$month_start = date( 'Y-m-01', $_time );
817
+ $month_end = date( 'Y-m-t', $_time );
818
+
819
+ $from_date = sprintf( '%s %s', $month_start, '00:00:00' );
820
+ $to_date = sprintf( '%s %s', $month_end, '23:59:59' );
821
break;
822
case "last_day":
823
+ $_date = date( 'Y-m-d', $_time );
824
+ $last_day = strtotime( $_date . " -1 day" );
825
+ $_date = date( 'Y-m-d', $last_day );
826
+
827
+ $from_date = sprintf( '%s %s', $_date, '00:00:00' );
828
+ $to_date = sprintf( '%s %s', $_date, '23:59:59' );
829
break;
830
case "last_week":
831
+ $day = ( date( 'w', $_time ) + 6 ) % 7;// 0 - Sun , must be Mon = 0
832
+ $_date = date( 'Y-m-d', $_time );
833
+ $last_week = strtotime( $_date . " -1 week" );
834
+ $week_start = date( 'Y-m-d', strtotime( date( 'Y-m-d', $last_week ) . ' -' . $day . ' days' ) );
835
+ $week_end = date( 'Y-m-d', strtotime( date( 'Y-m-d', $last_week ) . ' +' . ( 6 - $day ) . ' days' ) );
836
+
837
+ $from_date = sprintf( '%s %s', $week_start, '00:00:00' );
838
+ $to_date = sprintf( '%s %s', $week_end, '23:59:59' );
839
break;
840
case "last_month":
841
+ $_date = date( 'Y-m-d', $_time );
842
+ $last_month = strtotime( $_date . " -1 month" );
843
$month_start = date( 'Y-m-01', $last_month );
844
+ $month_end = date( 'Y-m-t', $last_month );
845
+
846
+ $from_date = sprintf( '%s %s', $month_start, '00:00:00' );
847
+ $to_date = sprintf( '%s %s', $month_end, '23:59:59' );
848
break;
849
case "last_quarter":
850
+ $_date = date( 'Y-m-d', $_time );
851
+ $last_month = strtotime( $_date . " -3 month" );
852
+ $quarter_start = date( 'Y-' . self::get_quarter_month( $last_month ) . '-01', $last_month );
853
+ $quarter_end = date( 'Y-' . ( self::get_quarter_month( $last_month ) + 2 ) . '-31', $last_month );
854
+
855
+ $from_date = sprintf( '%s %s', $quarter_start, '00:00:00' );
856
+ $to_date = sprintf( '%s %s', $quarter_end, '23:59:59' );
857
break;
858
case "this_year":
859
+ $year_start = date( 'Y-01-01', $_time );
860
+
861
+ $from_date = sprintf( '%s %s', $year_start, '00:00:00' );
862
break;
863
case "custom":
864
+ $export_rule_custom = isset( $settings['export_rule_custom'] ) ? $settings['export_rule_custom'] : '';
865
+ if ( isset( $export_rule_custom ) AND $export_rule_custom ) {
866
+ $day_start = date( 'Y-m-d',
867
+ strtotime( date( 'Y-m-d', $_time ) . ' -' . intval( $export_rule_custom ) . ' days' ) );
868
+ $day_end = date( 'Y-m-d', $_time );
869
+
870
+ $from_date = sprintf( '%s %s', $day_start, '00:00:00' );
871
+ $to_date = sprintf( '%s %s', $day_end, '23:59:59' );
872
}
873
break;
874
default:
875
break;
876
}
877
878
+ if ( isset( $from_date ) AND $from_date ) {
879
+ if ( $is_for_sql ) {
880
+ if( $use_timestamps )
881
+ $from_date = mysql2date( 'U', $from_date );
882
+ $from_date = sprintf( ">='%s'", $from_date );
883
+ }
884
+ $result['from_date'] = $from_date;
885
}
886
887
+ if ( isset( $to_date ) AND $to_date ) {
888
+ if ( $is_for_sql ) {
889
+ if( $use_timestamps )
890
+ $to_date = mysql2date( 'U', $to_date );
891
+ $to_date = sprintf( "<='%s'", $to_date );
892
+ }
893
+ $result['to_date'] = $to_date;
894
+ }
895
+
896
+ return $result;
897
}
898
899
public static function get_quarter_month( $time ) {
915
self::$decimal_separator = wc_get_price_decimal_separator();
916
self::$thousands_separator = apply_filters( 'woe_thousands_separator', '' );
917
self::$decimals = wc_get_price_decimals();
918
+ self::$export_subcategories_separator = apply_filters( 'woe_export_subcategories_separator', ">" );
919
+ self::$export_line_categories_separator = apply_filters( 'woe_export_line_categories_separator', ",\n" );
920
+ }
921
+
922
+ //for debug
923
+ public static function start_track_queries() {
924
+ self::$track_sql_queries = true;
925
+ self::$sql_queries = array();
926
+ }
927
+
928
+ public static function get_sql_queries() {
929
+ return self::$sql_queries;
930
}
931
932
+ //for csv/excel
933
public static function get_max_order_items( $type, $ids ) {
934
global $wpdb;
935
990
} else {
991
$row[ $field ] = '';
992
}
993
if ( isset( $filters_active[ $field ] ) ) {
994
$row[ $field ] = apply_filters( "woe_get_order_coupon_value_{$field}", $row[ $field ], $order, $item );
995
$row[ $field ] = apply_filters( "woe_get_order_coupon_{$format}_value_{$field}", $row[ $field ], $order, $item );
1088
$row[ $field ] = ""; // unknown class
1089
} elseif ( $field == 'line_total_plus_tax' ) {
1090
$row[ $field ] = $item_meta["_line_total"][0] + $item_meta["_line_tax"][0];
1091
} elseif ( $field == 'name' ) {
1092
$row['name'] = $item["name"];
1093
} elseif ( $field == 'product_variation' ) {
1159
}
1160
$row[ $field ] = ($subtotal_amount>0) ? round( 100*$subtotal_tax/$subtotal_amount, 2) : 0;
1161
} elseif ( $field == 'product_url' ) {
1162
+ $row[ $field ] = get_permalink( $product_id );
1163
+ } elseif ( $field == 'sku' ) {
1164
+ $row[ $field ] = method_exists($product,'get_'.$field) ? $product->{'get_'.$field}() : get_post_meta( $product_id, '_' . $field, true );
1165
} elseif ( $field == 'download_url' ) {
1166
$row[ $field ] = '';
1167
if ( $product AND $product->is_downloadable() ) {
1174
$row[ $field ] = implode( "\n", $links );
1175
}
1176
} elseif ( $field == 'image_url' ) {
1177
+ $row[ $field ] = ( is_object( $product ) AND $product->get_image_id() ) ? current( wp_get_attachment_image_src( $product->get_image_id(),
1178
+ 'full' ) ) : ''; // make full url
1179
+ } elseif ( $field == 'full_category_names' ) {
1180
+ $row[ $field ] = self::get_product_category_full( $product );
1181
} elseif ( isset( $static_vals[ $field ] ) ) {
1182
$row[ $field ] = $static_vals[ $field ];
1183
+ } elseif ( isset( $item_meta[ $field ] ) ) { //meta from order
1184
+ $row[ $field ] = $item_meta[ $field ][0];
1185
+ } elseif ( isset( $item_meta[ "_" . $field ] ) ) {// or hidden field
1186
+ $row[ $field ] = $item_meta[ "_" . $field ][0];
1187
+ } elseif ( isset( $item['item_meta'][ $field ] ) ) { // meta from item line
1188
+ $row[ $field ] = $item['item_meta'][ $field ][0];
1189
+ } elseif ( isset( $item['item_meta'][ "_" . $field ] ) ) { // or hidden field
1190
+ $row[ $field ] = $item['item_meta'][ "_" . $field ][0];
1191
} else {
1192
$row[ $field ] = '';
1193
if( !empty( $item['variation_id'] ) )
1219
return apply_filters( "woe_fetch_order_products", $products, $order, $labels, $format, $static_vals );
1220
}
1221
1222
+ public static function get_product_category_full( $product ) {
1223
+ $full_names = array();
1224
+ if ( ! $product ) {
1225
+ return '';
1226
+ }
1227
+ $prod_terms = get_the_terms( $product->get_id(), 'product_cat' );
1228
+ if ( ! $prod_terms ) {
1229
+ return '';
1230
+ }
1231
+
1232
+ foreach ( $prod_terms as $prod_term ) {
1233
+ $parts = array( $prod_term->name );
1234
+ $product_parent_categories_all_hierachy = get_ancestors( $prod_term->term_id, 'product_cat' );
1235
+ foreach ( $product_parent_categories_all_hierachy as $id ) {
1236
+ $parent = get_term( $id );
1237
+ $parts[] = $parent->name;
1238
+ }
1239
+ $full_names[] = join( self::$export_subcategories_separator, array_reverse( $parts ) );
1240
+ }
1241
+
1242
+ return join( self::$export_line_categories_separator, $full_names );
1243
+ }
1244
+
1245
public static function get_order_item_taxes_refund($order, $item_id) {
1246
$tax_refund = 0;
1247
$order_taxes = $order->get_taxes();
1358
$row['order_number'] = $parent_order ? $parent_order->get_order_number() : $order->get_order_number(); // use parent order number
1359
} elseif ( $field == 'order_subtotal' ) {
1360
$row['order_subtotal'] = wc_format_decimal( $order->get_subtotal(), 2);
1361
+ } elseif ( $field == 'order_subtotal_minus_discount' ) {
1362
+ $row[ $field ] = $order->get_subtotal() - $order->get_total_discount();
1363
} elseif ( $field == 'order_subtotal_refunded' ) {
1364
$row['order_subtotal_refunded'] = wc_format_decimal( self::get_order_subtotal_refunded($order), 2);
1365
} elseif ( $field == 'order_subtotal_minus_refund' ) {
1531
}
1532
1533
// Must fill child cells?
1534
+ if ( empty($options['item_rows_start_from_new_line']) AND !empty($options['populate_other_columns_product_rows']) AND $extra_rows ) {
1535
foreach ( $extra_rows as $idx=> $extra_row ) {
1536
foreach ( $row as $key=> $val ) {
1537
if ( in_array( $key, $order_fields) )
1558
return apply_filters("woe_fetch_order_data",$extra_rows);
1559
}
1560
1561
+ public static function get_city_state_postcode_field_value( $order, $type ) {
1562
if ( $type != 'shipping' && $type != 'billing') {
1563
return null;
1564
}
1715
* @return array
1716
*/
1717
public static function get_shipping_methods() {
1718
+ global $wpdb;
1719
+
1720
+ $shipping_methods = array();
1721
+
1722
+ // get raw names
1723
+ $raw_methods = $wpdb->get_col( "SELECT DISTINCT order_item_name FROM {$wpdb->prefix}woocommerce_order_items WHERE order_item_type='shipping' ORDER BY order_item_name" );
1724
+ foreach($raw_methods as $method)
1725
+ $shipping_methods[ 'order_item_name:' . $method ] = $method;
1726
+
1727
+ // try get methods for zones
1728
if( !class_exists("WC_Shipping_Zone") )
1729
+ return $shipping_methods;
1730
1731
if( !method_exists("WC_Shipping_Zone", "get_shipping_methods") )
1732
+ return $shipping_methods;
1733
1734
foreach ( WC_Shipping_Zones::get_zones() as $zone ) {
1735
$methods = $zone['shipping_methods'];
1738
$shipping_methods[ $method->get_rate_id() ] = '[' . $zone['zone_name'] . '] ' . $method->get_title();
1739
}
1740
}
1741
+
1742
+ $zone = new WC_Shipping_Zone( 0 );
1743
+ $methods = $zone->get_shipping_methods();
1744
+ /** @var WC_Shipping_Method $method */
1745
+ foreach ( $methods as $method ) {
1746
+ $shipping_methods[ $method->get_rate_id() ] = __('[Rest of the World]', 'woo-order-export-lite' ) .' '. $method->get_title();
1747
+ }
1748
+
1749
return $shipping_methods;
1750
}
1751
classes/core/class-wc-order-export-engine.php CHANGED
@@ -14,7 +14,7 @@ class WC_Order_Export_Engine {
14
//
15
public static function export( $settings, $filepath ) {
16
if( empty($settings['destination']['type']) ) {
17
- return __( "No format selected", 'woo-order-export-lite' );
18
}
19
20
if( !is_array( $settings[ 'destination' ][ 'type' ] ) ) {
@@ -51,6 +51,9 @@ class WC_Order_Export_Engine {
51
$mask = implode( '.', $mask_parts );
52
}
53
$time = apply_filters( 'woe_make_filename_current_time', current_time( 'timestamp' ) );
54
$subst = apply_filters( 'woe_make_filename_replacements', array(
55
'%d' => date( 'd',$time ),
56
'%m' => date( 'm',$time ),
@@ -61,6 +64,8 @@ class WC_Order_Export_Engine {
61
'%order_id' => self::$order_id,
62
'%orderid' => self::$order_id,
63
'%id' => self::$order_id,
64
) );
65
66
return apply_filters( 'woe_make_filename', strtr( $mask, $subst ) );
@@ -268,6 +273,25 @@ class WC_Order_Export_Engine {
268
$options['export_all_comments'] = $settings['export_all_comments'];
269
$options['export_refund_notes'] = $settings['export_refund_notes'];
270
$options['format_number_fields'] = $settings['format_number_fields'];
271
$options['strip_tags_product_fields'] = !empty($settings['strip_tags_product_fields']);
272
273
return $options;
@@ -315,7 +339,7 @@ class WC_Order_Export_Engine {
315
316
private static function try_mark_order( $order_id, $settings ) {
317
if ( $settings[ 'mark_exported_orders' ] ) {
318
- update_post_meta( $order_id, 'woe_order_exported', 1 );
319
}
320
}
321
@@ -342,7 +366,6 @@ class WC_Order_Export_Engine {
342
$filename = ( ! empty( $filename ) ? $filename : self::tempnam( sys_get_temp_dir(), $settings['format'] ) );
343
}
344
345
-
346
if ( $make_mode !== 'estimate' )
347
$formater = self::init_formater( $make_mode, $settings, $filename, $labels, $static_vals );
348
$format = strtolower( $settings['format'] );
@@ -353,6 +376,10 @@ class WC_Order_Export_Engine {
353
return $filename;
354
}
355
356
//get IDs
357
$sql = WC_Order_Export_Data_Extractor::sql_get_order_ids( $settings );
358
if ( $make_mode == 'estimate' ) { //if estimate return total count
@@ -400,7 +427,7 @@ class WC_Order_Export_Engine {
400
$rows = WC_Order_Export_Data_Extractor::fetch_order_data( $order_id, $labels, $format, $filters_active,
401
$csv_max, $export, $get_coupon_meta, $static_vals, self::$extractor_options );
402
foreach ( $rows as $row ) {
403
- $row=apply_filters( "woe_fetch_order_row", $row, $order_id);
404
if ($row) {
405
$formater->output( $row );
406
do_action( "woe_order_row_exported", $row, $order_id);
@@ -419,9 +446,20 @@ class WC_Order_Export_Engine {
419
$formater->finish_partial();
420
elseif ( $make_mode == 'preview') {
421
self::maybe_output_summary_report( $formater );
422
$formater->finish();
423
}
424
425
return $filename;
426
}
427
@@ -494,6 +532,7 @@ class WC_Order_Export_Engine {
494
self::maybe_output_summary_report( $formater );
495
$formater->finish();
496
497
return $filename;
498
}
499
@@ -573,7 +612,8 @@ class WC_Order_Export_Engine {
573
}
574
self::$order_id = '';
575
}
576
-
577
return $result; //return last result
578
}
579
14
//
15
public static function export( $settings, $filepath ) {
16
if( empty($settings['destination']['type']) ) {
17
+ return __( "No destination selected", 'woo-order-export-lite' );
18
}
19
20
if( !is_array( $settings[ 'destination' ][ 'type' ] ) ) {
51
$mask = implode( '.', $mask_parts );
52
}
53
$time = apply_filters( 'woe_make_filename_current_time', current_time( 'timestamp' ) );
54
+
55
+ $date = WC_Order_Export_Data_Extractor::get_date_range( self::$current_job_settings, false );
56
+
57
$subst = apply_filters( 'woe_make_filename_replacements', array(
58
'%d' => date( 'd',$time ),
59
'%m' => date( 'm',$time ),
64
'%order_id' => self::$order_id,
65
'%orderid' => self::$order_id,
66
'%id' => self::$order_id,
67
+ '{from_date}' => isset( $date['from_date'] ) ? date( "Y-m-d", strtotime( $date['from_date'] ) ) : '',
68
+ '{to_date}' => isset( $date['to_date'] ) ? date( "Y-m-d", strtotime( $date['to_date'] ) ) : '',
69
) );
70
71
return apply_filters( 'woe_make_filename', strtr( $mask, $subst ) );
273
$options['export_all_comments'] = $settings['export_all_comments'];
274
$options['export_refund_notes'] = $settings['export_refund_notes'];
275
$options['format_number_fields'] = $settings['format_number_fields'];
276
+
277
+ if ( $settings['enable_debug'] AND ! ini_get( 'display_errors' ) ) {
278
+ ini_set( 'display_errors', 1 );
279
+ $old_error_reporting = error_reporting( E_ALL );
280
+ add_action( 'woe_export_finished', function () use ( $old_error_reporting ) {
281
+ ini_set( 'display_errors', 0 );
282
+ error_reporting( $old_error_reporting );
283
+ } );
284
+ }
285
+
286
+ if ( $settings['cleanup_phone'] ) {
287
+ foreach ( array( "billing_phone", "USER_billing_phone" ) as $field ) {
288
+ add_filter( 'woe_get_order_value_' . $field, function ( $value, $order, $fieldname ) {
289
+ $value = preg_replace( "#[^\d]+#", "", $value );
290
+ return $value;
291
+ }, 10, 3 );
292
+ }
293
+ }
294
+
295
$options['strip_tags_product_fields'] = !empty($settings['strip_tags_product_fields']);
296
297
return $options;
339
340
private static function try_mark_order( $order_id, $settings ) {
341
if ( $settings[ 'mark_exported_orders' ] ) {
342
+ update_post_meta( $order_id, 'woe_order_exported', current_time('timestamp') );
343
}
344
}
345
366
$filename = ( ! empty( $filename ) ? $filename : self::tempnam( sys_get_temp_dir(), $settings['format'] ) );
367
}
368
369
if ( $make_mode !== 'estimate' )
370
$formater = self::init_formater( $make_mode, $settings, $filename, $labels, $static_vals );
371
$format = strtolower( $settings['format'] );
376
return $filename;
377
}
378
379
+ //debug sql!
380
+ if ( $make_mode == 'preview' AND $settings['enable_debug'] )
381
+ WC_Order_Export_Data_Extractor::start_track_queries( );
382
+
383
//get IDs
384
$sql = WC_Order_Export_Data_Extractor::sql_get_order_ids( $settings );
385
if ( $make_mode == 'estimate' ) { //if estimate return total count
427
$rows = WC_Order_Export_Data_Extractor::fetch_order_data( $order_id, $labels, $format, $filters_active,
428
$csv_max, $export, $get_coupon_meta, $static_vals, self::$extractor_options );
429
foreach ( $rows as $row ) {
430
+ $row = apply_filters( "woe_fetch_order_row", $row, $order_id);
431
if ($row) {
432
$formater->output( $row );
433
do_action( "woe_order_row_exported", $row, $order_id);
446
$formater->finish_partial();
447
elseif ( $make_mode == 'preview') {
448
self::maybe_output_summary_report( $formater );
449
+ if( $settings['enable_debug'] ) {
450
+ echo "<b>" . __( 'Main SQL queries are listed below', 'woo-order-export-lite' ) . "</b>";
451
+ echo '<textarea rows=5 style="width:100%">';
452
+ $s = array();
453
+ foreach(WC_Order_Export_Data_Extractor::get_sql_queries() as $sql) {
454
+ $s[] = preg_replace("#\s+#"," ",$sql);
455
+ }
456
+ echo join("\n\n", $s);
457
+ echo '</textarea>';
458
+ }
459
$formater->finish();
460
}
461
462
+ // no action woe_export_finished here!
463
return $filename;
464
}
465
532
self::maybe_output_summary_report( $formater );
533
$formater->finish();
534
535
+ do_action( 'woe_export_finished');
536
return $filename;
537
}
538
612
}
613
self::$order_id = '';
614
}
615
+
616
+ do_action( 'woe_export_finished');
617
return $result; //return last result
618
}
619
classes/formats/abstract-class-woe-formatter.php CHANGED
@@ -13,6 +13,7 @@ abstract class WOE_Formatter {
13
var $field_formats;
14
var $date_format;
15
var $auto_format_dates = true;
16
17
public function __construct( $mode, $filename, $settings, $format, $labels, $field_formats, $date_format ) {
18
$this->has_output_filter = has_filter( "woe_{$format}_output_filter" );
@@ -32,6 +33,16 @@ abstract class WOE_Formatter {
32
$this->string_format_fields = apply_filters( "woe_{$format}_string_format_fields", $field_formats['string'] );
33
$this->date_format_fields = apply_filters( "woe_{$format}_date_format_fields", $field_formats['date'] );
34
$this->date_format = apply_filters( "woe_{$format}_date_format", $date_format );
35
}
36
37
public function start( $data = '' ) {
@@ -43,11 +54,16 @@ abstract class WOE_Formatter {
43
$this->handle = apply_filters( "woe_formatter_set_handler_for_" . $this->format . "_row", $this->handle );
44
if( $this->auto_format_dates )
45
$rec = $this->format_dates( $rec );
46
return $rec;
47
}
48
49
public function finish() {
50
fclose( $this->handle );
51
do_action("woe_formatter_finish", $this);
52
do_action("woe_formatter_" .$this->format. "_finished", $this);
53
}
@@ -81,4 +97,28 @@ abstract class WOE_Formatter {
81
}
82
return $rec;
83
}
84
}
13
var $field_formats;
14
var $date_format;
15
var $auto_format_dates = true;
16
+ var $counter_value;
17
18
public function __construct( $mode, $filename, $settings, $format, $labels, $field_formats, $date_format ) {
19
$this->has_output_filter = has_filter( "woe_{$format}_output_filter" );
33
$this->string_format_fields = apply_filters( "woe_{$format}_string_format_fields", $field_formats['string'] );
34
$this->date_format_fields = apply_filters( "woe_{$format}_date_format_fields", $field_formats['date'] );
35
$this->date_format = apply_filters( "woe_{$format}_date_format", $date_format );
36
+
37
+ $this->counter_value = $this->get_counter();
38
+ if ( !$this->counter_value ) {
39
+ $this->counter_value = 1;
40
+ $this->set_counter( $this->counter_value );
41
+ }
42
+ }
43
+
44
+ function __destruct() {
45
+ $this->set_counter( $this->counter_value );
46
}
47
48
public function start( $data = '' ) {
54
$this->handle = apply_filters( "woe_formatter_set_handler_for_" . $this->format . "_row", $this->handle );
55
if( $this->auto_format_dates )
56
$rec = $this->format_dates( $rec );
57
+ if ( isset( $rec['line_number'] ) ) {
58
+ $rec['line_number'] = $this->counter_value;
59
+ $this->counter_value++;
60
+ }
61
return $rec;
62
}
63
64
public function finish() {
65
fclose( $this->handle );
66
+ $this->delete_counter();
67
do_action("woe_formatter_finish", $this);
68
do_action("woe_formatter_" .$this->format. "_finished", $this);
69
}
97
}
98
return $rec;
99
}
100
+
101
+
102
+ protected function generate_key() {
103
+ return $this->mode . '+' . $this->filename;
104
+ }
105
+
106
+ protected function delete_counter() {
107
+ delete_transient( $this->generate_key() );
108
+ }
109
+
110
+ protected function set_counter( $count_value ) {
111
+ $this->counter_value = $count_value;
112
+ if ( $this->mode != 'preview' ) {
113
+ set_transient( $this->generate_key(), $count_value );
114
+ }
115
+ }
116
+
117
+ protected function get_counter() {
118
+ if ( $this->mode == 'preview' ) {
119
+ return false;
120
+ } else {
121
+ return get_transient( $this->generate_key() );
122
+ }
123
+ }
124
}
classes/formats/class-woe-formatter-json.php CHANGED
@@ -19,7 +19,8 @@ class WOE_Formatter_Json extends WOE_Formatter {
19
if ( $this->prev_added ) {
20
fwrite( $this->handle, "," );
21
}
22
- fwrite( $this->handle, "\n" );
23
24
//rename fields in array
25
$rec_out = array();
@@ -67,8 +68,10 @@ class WOE_Formatter_Json extends WOE_Formatter {
67
}
68
69
public function finish( $data = '' ) {
70
- $end_text = $this->convert_literals( $this->settings[ 'end_tag' ] );
71
72
fwrite( $this->handle, apply_filters( "woe_json_end_text", $end_text) );
73
parent::finish();
74
}
19
if ( $this->prev_added ) {
20
fwrite( $this->handle, "," );
21
}
22
+ if ( $this->mode == 'preview' )
23
+ fwrite( $this->handle, "\n" );
24
25
//rename fields in array
26
$rec_out = array();
68
}
69
70
public function finish( $data = '' ) {
71
+ if ( $this->mode == 'preview' )
72
+ fwrite( $this->handle, "\n" );
73
74
+ $end_text = $this->convert_literals( $this->settings[ 'end_tag' ] );
75
fwrite( $this->handle, apply_filters( "woe_json_end_text", $end_text) );
76
parent::finish();
77
}
classes/formats/class-woe-formatter-xls.php CHANGED
@@ -101,7 +101,7 @@ class WOE_Formatter_Xls extends WOE_Formatter {
101
foreach ( $rec as $field => $text ) {
102
if( $this->string_format_force OR in_array($field, $this->string_format_fields) ) {
103
$this->objPHPExcel->getActiveSheet()->setCellValueExplicitByColumnAndRow( $pos, $this->last_row, $text );
104
- }elseif( in_array($field, $this->date_format_fields) ) {// DATE!
105
if( $text ) {
106
if( empty($this->settings['global_job_settings']['time_format']) ) { // must remove time!
107
$text = date( "Y-m-d", strtotime( $text ) );
101
foreach ( $rec as $field => $text ) {
102
if( $this->string_format_force OR in_array($field, $this->string_format_fields) ) {
103
$this->objPHPExcel->getActiveSheet()->setCellValueExplicitByColumnAndRow( $pos, $this->last_row, $text );
104
+ } elseif( in_array($field, $this->date_format_fields) ) {// DATE!
105
if( $text ) {
106
if( empty($this->settings['global_job_settings']['time_format']) ) { // must remove time!
107
$text = date( "Y-m-d", strtotime( $text ) );
i18n/languages/woo-order-export-lite.pot CHANGED
@@ -3,688 +3,458 @@ msgid ""
3
msgstr ""
4
"Project-Id-Version: PACKAGE VERSION\n"
5
"Report-Msgid-Bugs-To: \n"
6
- "POT-Creation-Date: 2018-02-12 06:52+0000\n"
7
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
8
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
9
"Language-Team: \n"
10
"Language: \n"
11
- "Plural-Forms: nplurals=INTEGER; plural=EXPRESSION\n"
12
"MIME-Version: 1.0\n"
13
"Content-Type: text/plain; charset=UTF-8\n"
14
"Content-Transfer-Encoding: 8bit\n"
15
- "X-Generator: Loco - https://localise.biz/"
16
17
- #: woo-order-export-lite.php:60
18
msgid ""
19
"Please, <a href=\"plugins.php\">deactivate</a> Free version of Advanced "
20
- "Order Export For WooCommerce !"
21
msgstr ""
22
23
- #: view/settings-form.php:41 view/settings-form.php:49
24
- #: view/settings-form.php:84
25
- msgid "Title"
26
- msgstr ""
27
-
28
- #: view/settings-form.php:56 view/settings-form.php:64
29
- msgid "Empty means \"any status\""
30
- msgstr ""
31
-
32
- #: view/settings-form.php:56
33
- msgid "From status"
34
- msgstr ""
35
-
36
- #: view/settings-form.php:64
37
- msgid "To status"
38
- msgstr ""
39
-
40
- #: view/settings-form.php:75 view/settings-form.php:192
41
- msgid "Log results"
42
- msgstr ""
43
-
44
- #: view/settings-form.php:75 view/settings-form.php:192
45
- msgid "View logs"
46
- msgstr ""
47
-
48
- #: view/settings-form.php:91
49
- msgid "Don't send empty file"
50
- msgstr ""
51
-
52
- #: view/settings-form.php:97
53
- msgid "Schedule"
54
- msgstr ""
55
-
56
- #: view/settings-form.php:109
57
- msgid "Run at"
58
- msgstr ""
59
-
60
- #: view/settings-form.php:134
61
- msgid "Choose"
62
- msgstr ""
63
-
64
- #: view/settings-form.php:135
65
- msgid "Custom"
66
- msgstr ""
67
-
68
- #: view/settings-form.php:144
69
- msgid "On the 1st day of the month"
70
- msgstr ""
71
-
72
- #: view/settings-form.php:145
73
- msgid "On the 1st day of the quarter"
74
- msgstr ""
75
-
76
- #: view/settings-form.php:148
77
- msgid "interval (min)"
78
- msgstr ""
79
-
80
- #: view/settings-form.php:185
81
- msgid "Add"
82
- msgstr ""
83
-
84
- #: view/settings-form.php:200
85
- msgid "Export date range"
86
- msgstr ""
87
-
88
- #: view/settings-form.php:204
89
- msgid "Since last run of this job"
90
- msgstr ""
91
-
92
- #: view/settings-form.php:209
93
- msgid "Today"
94
- msgstr ""
95
-
96
- #: view/settings-form.php:214
97
- msgid "Yesterday"
98
- msgstr ""
99
-
100
- #: view/settings-form.php:219
101
- msgid "Current week"
102
- msgstr ""
103
-
104
- #: view/settings-form.php:224
105
- msgid "Current month"
106
- msgstr ""
107
-
108
- #: view/settings-form.php:229
109
- msgid "Last week"
110
- msgstr ""
111
-
112
- #: view/settings-form.php:234
113
- msgid "Last month"
114
- msgstr ""
115
-
116
- #: view/settings-form.php:239
117
- msgid "Last quarter"
118
- msgstr ""
119
-
120
- #: view/settings-form.php:244
121
- msgid "This year"
122
- msgstr ""
123
-
124
- #: view/settings-form.php:253
125
- #, php-format
126
- msgid "Last %s days"
127
- msgstr ""
128
-
129
- #: view/settings-form.php:264
130
msgid "Filter orders by"
131
msgstr ""
132
133
- #: view/settings-form.php:268 view/settings-form.php:437
134
- #: classes/core/class-wc-order-export-data-extractor-ui.php:328
135
msgid "Order Date"
136
msgstr ""
137
138
- #: view/settings-form.php:273 view/settings-form.php:438
139
- #: classes/core/class-wc-order-export-data-extractor-ui.php:329
140
msgid "Modification Date"
141
msgstr ""
142
143
- #: view/settings-form.php:278
144
- #: classes/core/class-wc-order-export-data-extractor-ui.php:332
145
msgid "Paid Date"
146
msgstr ""
147
148
- #: view/settings-form.php:283
149
- #: classes/core/class-wc-order-export-data-extractor-ui.php:331
150
msgid "Completed Date"
151
msgstr ""
152
153
- #: view/settings-form.php:287
154
msgid "This date range should not be saved in the scheduled task"
155
msgstr ""
156
157
- #: view/settings-form.php:289
158
msgid "Date range"
159
msgstr ""
160
161
- #: view/settings-form.php:291
162
msgid "to"
163
msgstr ""
164
165
- #: view/settings-form.php:295
166
msgid "Express export"
167
msgstr ""
168
169
- #: view/settings-form.php:296
170
msgid "Summary Report By Products"
171
msgstr ""
172
173
- #: view/settings-form.php:297
174
msgid "Set up fields"
175
msgstr ""
176
177
- #: view/settings-form.php:305
178
msgid "Export filename"
179
msgstr ""
180
181
- #: view/settings-form.php:315
182
msgid "Format"
183
msgstr ""
184
185
- #: view/settings-form.php:326
186
msgid "XLS options"
187
msgstr ""
188
189
- #: view/settings-form.php:332
190
msgid "Export as .xls (Binary File Format)"
191
msgstr ""
192
193
- #: view/settings-form.php:333
194
msgid "Use sheet name"
195
msgstr ""
196
197
- #: view/settings-form.php:334 view/settings-form.php:346
198
- #: view/settings-form.php:376
199
msgid "Output column titles as first line"
200
msgstr ""
201
202
- #: view/settings-form.php:335
203
msgid "Auto column width"
204
msgstr ""
205
206
- #: view/settings-form.php:336 view/settings-form.php:347
207
- #: view/settings-form.php:377
208
msgid "Populate other columns if products exported as rows"
209
msgstr ""
210
211
- #: view/settings-form.php:337
212
msgid "Right-to-Left direction"
213
msgstr ""
214
215
- #: view/settings-form.php:339
216
msgid "CSV options"
217
msgstr ""
218
219
- #: view/settings-form.php:345 view/settings-form.php:375
220
msgid "Output UTF-8 BOM"
221
msgstr ""
222
223
- #: view/settings-form.php:348
224
msgid "Convert line breaks to literals"
225
msgstr ""
226
227
- #: view/settings-form.php:349
228
msgid "Item rows start from new line"
229
msgstr ""
230
231
- #: view/settings-form.php:350
232
msgid "Enclosure"
233
msgstr ""
234
235
- #: view/settings-form.php:351
236
msgid "Field Delimiter"
237
msgstr ""
238
239
- #: view/settings-form.php:352 view/settings-form.php:378
240
msgid "Line Break"
241
msgstr ""
242
243
- #: view/settings-form.php:354 view/settings-form.php:380
244
msgid "Character encoding"
245
msgstr ""
246
247
- #: view/settings-form.php:357
248
msgid "XML options"
249
msgstr ""
250
251
- #: view/settings-form.php:359
252
msgid "Prepend XML"
253
msgstr ""
254
255
- #: view/settings-form.php:360
256
msgid "Root tag"
257
msgstr ""
258
259
- #: view/settings-form.php:361
260
msgid "Order tag"
261
msgstr ""
262
263
- #: view/settings-form.php:362
264
msgid "Product tag"
265
msgstr ""
266
267
- #: view/settings-form.php:363
268
msgid "Coupon tag"
269
msgstr ""
270
271
- #: view/settings-form.php:364
272
msgid "Append XML"
273
msgstr ""
274
275
- #: view/settings-form.php:365
276
msgid "Self closing tags"
277
msgstr ""
278
279
- #: view/settings-form.php:367
280
msgid "JSON options"
281
msgstr ""
282
283
- #: view/settings-form.php:368
284
msgid "Start tag"
285
msgstr ""
286
287
- #: view/settings-form.php:369
288
msgid "End tag"
289
msgstr ""
290
291
- #: view/settings-form.php:371
292
msgid "TSV options"
293
msgstr ""
294
295
- #: view/settings-form.php:387
296
msgid "Date"
297
msgstr ""
298
299
- #: view/settings-form.php:400 view/settings-form.php:422
300
msgid "-"
301
msgstr ""
302
303
- #: view/settings-form.php:402 view/settings-form.php:424
304
msgid "custom"
305
msgstr ""
306
307
- #: view/settings-form.php:410
308
msgid "Time"
309
msgstr ""
310
311
- #: view/settings-form.php:436
312
- #: classes/core/class-wc-order-export-data-extractor-ui.php:325
313
msgid "Order ID"
314
msgstr ""
315
316
- #: view/settings-form.php:453
317
msgid "Descending"
318
msgstr ""
319
320
- #: view/settings-form.php:454
321
msgid "Ascending"
322
msgstr ""
323
324
- #: view/settings-form.php:459
325
#, php-format
326
msgid "Sort orders by %s in %s order"
327
msgstr ""
328
329
- #: view/settings-form.php:464
330
msgid "Change order status to"
331
msgstr ""
332
333
- #: view/settings-form.php:466
334
msgid "- don't modify -"
335
msgstr ""
336
337
- #: view/settings-form.php:476
338
msgid "Misc settings"
339
msgstr ""
340
341
- #: view/settings-form.php:481
342
msgid "Format numbers (use WC decimal separator)"
343
msgstr ""
344
345
- #: view/settings-form.php:485
346
msgid "Export all order notes"
347
msgstr ""
348
349
- #: view/settings-form.php:489
350
msgid "Export refund notes as Customer Note"
351
msgstr ""
352
353
- #: view/settings-form.php:493
354
msgid "Strip tags from Product Description/Variation"
355
msgstr ""
356
357
- #: view/settings-form.php:497
358
- msgid "Custom PHP code to modify output"
359
- msgstr ""
360
-
361
- #: view/settings-form.php:498
362
- msgid "Use only unnamed functions!"
363
- msgstr ""
364
-
365
- #: view/settings-form.php:507
366
- msgid "Destination"
367
- msgstr ""
368
-
369
- #: view/settings-form.php:515
370
- msgid "Email"
371
- msgstr ""
372
-
373
- #: view/settings-form.php:521
374
- msgid "FTP"
375
- msgstr ""
376
-
377
- #: view/settings-form.php:527
378
- msgid "SFTP"
379
- msgstr ""
380
-
381
- #: view/settings-form.php:533
382
- msgid "HTTP POST"
383
- msgstr ""
384
-
385
- #: view/settings-form.php:539
386
- msgid "Directory"
387
- msgstr ""
388
-
389
- #: view/settings-form.php:544
390
- msgid "Email settings"
391
- msgstr ""
392
-
393
- #: view/settings-form.php:547
394
- msgid "From email"
395
- msgstr ""
396
-
397
- #: view/settings-form.php:554
398
- msgid "From name"
399
- msgstr ""
400
-
401
- #: view/settings-form.php:561
402
- msgid "Recipient(s)"
403
- msgstr ""
404
-
405
- #: view/settings-form.php:568
406
- msgid "CC Recipient(s)"
407
- msgstr ""
408
-
409
- #: view/settings-form.php:575
410
- msgid "Email subject"
411
- msgstr ""
412
-
413
- #: view/settings-form.php:583 view/settings-form.php:592
414
- msgid "Email body"
415
- msgstr ""
416
-
417
- #: view/settings-form.php:584
418
- msgid "Edit email body"
419
- msgstr ""
420
-
421
- #: view/settings-form.php:585
422
- msgid "Append file contents to email body"
423
- msgstr ""
424
-
425
- #: view/settings-form.php:601 view/settings-form.php:656
426
- #: view/settings-form.php:699 view/settings-form.php:718
427
- #: view/settings-form.php:737
428
- msgid "Test"
429
- msgstr ""
430
-
431
- #: view/settings-form.php:601 view/settings-form.php:656
432
- #: view/settings-form.php:718 view/settings-form.php:737
433
- msgid "It sends only last order!"
434
- msgstr ""
435
-
436
- #: view/settings-form.php:608
437
- msgid "FTP settings"
438
- msgstr ""
439
-
440
- #: view/settings-form.php:611 view/settings-form.php:666
441
- msgid "Server name"
442
- msgstr ""
443
-
444
- #: view/settings-form.php:616 view/settings-form.php:671
445
- msgid "Port"
446
- msgstr ""
447
-
448
- #: view/settings-form.php:624 view/settings-form.php:679
449
- msgid "Username"
450
- msgstr ""
451
-
452
- #: view/settings-form.php:629 view/settings-form.php:684
453
- msgid "Password"
454
- msgstr ""
455
-
456
- #: view/settings-form.php:636 view/settings-form.php:691
457
- msgid "Initial path"
458
- msgstr ""
459
-
460
- #: view/settings-form.php:644
461
- msgid "Passive mode"
462
msgstr ""
463
464
- #: view/settings-form.php:649
465
- msgid "Append to existing file (need custom code!)"
466
- msgstr ""
467
-
468
- #: view/settings-form.php:663
469
- msgid "SFTP settings"
470
- msgstr ""
471
-
472
- #: view/settings-form.php:706
473
- msgid "HTTP POST settings"
474
- msgstr ""
475
-
476
- #: view/settings-form.php:710
477
- msgid "URL"
478
- msgstr ""
479
-
480
- #: view/settings-form.php:725
481
- msgid "Directory settings"
482
- msgstr ""
483
-
484
- #: view/settings-form.php:729
485
- msgid "Path"
486
msgstr ""
487
488
- #: view/settings-form.php:744
489
- msgid "Test Results"
490
msgstr ""
491
492
- #: view/settings-form.php:754
493
- msgid "Make separate file for each order"
494
msgstr ""
495
496
- #: view/settings-form.php:764
497
msgid "Filter by order"
498
msgstr ""
499
500
- #: view/settings-form.php:767
501
msgid "Don't export child orders"
502
msgstr ""
503
504
- #: view/settings-form.php:768
505
msgid "Export refunds"
506
msgstr ""
507
508
- #: view/settings-form.php:769
509
msgid "Mark exported orders"
510
msgstr ""
511
512
- #: view/settings-form.php:770
513
msgid "Export unmarked orders only"
514
msgstr ""
515
516
- #: view/settings-form.php:771
517
msgid "Order statuses"
518
msgstr ""
519
520
- #: view/settings-form.php:778
521
msgid "Custom fields"
522
msgstr ""
523
524
- #: view/settings-form.php:811
525
msgid ""
526
"The filters won't work correctly.<br>Another plugin(or theme) has loaded "
527
"outdated Select2.js"
528
msgstr ""
529
530
- #: view/settings-form.php:812
531
msgid "Filter by product"
532
msgstr ""
533
534
- #: view/settings-form.php:815
535
msgid "Export all products from a order"
536
msgstr ""
537
538
- #: view/settings-form.php:816
539
msgid "Skip fully refunded items"
540
msgstr ""
541
542
- #: view/settings-form.php:817
543
msgid "Product categories"
544
msgstr ""
545
546
- #: view/settings-form.php:827
547
msgid "Vendor/creator"
548
msgstr ""
549
550
- #: view/settings-form.php:840
551
msgid "Product"
552
msgstr ""
553
554
- #: view/settings-form.php:852
555
msgid "Product taxonomies"
556
msgstr ""
557
558
- #: view/settings-form.php:877
559
msgid "Product custom fields"
560
msgstr ""
561
562
- #: view/settings-form.php:904
563
msgid "Variable product attributes"
564
msgstr ""
565
566
- #: view/settings-form.php:931
567
msgid "Item meta data"
568
msgstr ""
569
570
- #: view/settings-form.php:964
571
msgid "Filter by customers"
572
msgstr ""
573
574
- #: view/settings-form.php:967
575
msgid "User roles"
576
msgstr ""
577
578
- #: view/settings-form.php:976
579
msgid "Usernames"
580
msgstr ""
581
582
- #: view/settings-form.php:992
583
msgid "Filter by coupons"
584
msgstr ""
585
586
- #: view/settings-form.php:997
587
msgid "Any coupon used"
588
msgstr ""
589
590
- #: view/settings-form.php:999
591
- #: classes/core/class-wc-order-export-data-extractor-ui.php:399
592
- #: classes/core/class-wc-order-export-data-extractor-ui.php:460
593
msgid "Coupons"
594
msgstr ""
595
596
- #: view/settings-form.php:1014
597
msgid "Filter by billing"
598
msgstr ""
599
600
- #: view/settings-form.php:1017
601
msgid "Billing locations"
602
msgstr ""
603
604
- #: view/settings-form.php:1041
605
msgid "Payment methods"
606
msgstr ""
607
608
- #: view/settings-form.php:1053
609
msgid "Filter by shipping"
610
msgstr ""
611
612
- #: view/settings-form.php:1056
613
msgid "Shipping locations"
614
msgstr ""
615
616
-