Advanced Order Export For WooCommerce - Version 1.5.6

Version Description

  • 2018-08-30 =
  • Added filter by user custom fields
  • Added order fields "Count of exported items", "User Website"
  • Added product fields "Product Id", "Variation Id", "Order Line Subtotal Tax"
  • Multiple custom fields with same title are exported as list (for order)
  • Format Shipping/Billing fields as string (Excel only)
  • Fixed compatibility issue with WP Redis cache
  • Fixed bug - "Progressbar" shows error message correctly
  • Fixed bug - "Progressbar" doesn't miss orders if both "Mark exported" and "Export unmarked only" are ON
  • Reduced memory footprint (options are not autoloaded)
Download this release

Release Info

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

Code changes from version 1.5.5 to 1.5.6

assets/css/export.css CHANGED
@@ -636,4 +636,62 @@ input.date{
636
  height: 28px;
637
  vertical-align: middle;
638
  background: url("../img/calendar.png") 98px 5px no-repeat;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
639
  }
636
  height: 28px;
637
  vertical-align: middle;
638
  background: url("../img/calendar.png") 98px 5px no-repeat;
639
+ }
640
+
641
+ .woe-row-sort-handle {
642
+ width: 20px;
643
+ height: 20px;
644
+ color: black;
645
+ cursor: move;
646
+ }
647
+
648
+ #reorder_section {
649
+ display: inline-block;
650
+ margin-top: 10px;
651
+ }
652
+
653
+ #reorder_section #apply_reorder, #reorder_section #cancel_reorder {
654
+ display: none;
655
+ }
656
+
657
+ .wp-wrap .column-order {
658
+ width: 2.2em;
659
+ }
660
+
661
+ .wp-wrap .pipe {
662
+ font-size: x-large;
663
+ vertical-align: middle;
664
+ }
665
+
666
+ .section_choice {
667
+ cursor: pointer;
668
+ }
669
+
670
+ .section_choice.active {
671
+ font-weight: bold;
672
+ color: #000;
673
+ }
674
+
675
+ .section:not(.active) {
676
+ display: none;
677
+ }
678
+
679
+ .license_paragraph {
680
+ margin : 15px 0 15px 0;
681
+ }
682
+
683
+ #license_help_text {
684
+ background-color: white;
685
+ border: 1px #b2b2b2 solid;
686
+ border-radius: 5px;
687
+ padding:10px;
688
+ margin: 15px 0 15px 0;
689
+ }
690
+
691
+ #my-shedule-days .wc_oe-select-interval {
692
+ width: 55%;
693
+ }
694
+
695
+ #my-shedule-days .input-mins-custom-interval {
696
+ max-width: 100px;
697
  }
assets/js/export.js CHANGED
@@ -130,6 +130,9 @@ function bind_events() {
130
  });
131
  //end of change
132
 
 
 
 
133
  //PRODUCT ATTRIBUTES BEGIN
134
  jQuery( '#attributes' ).change( function() {
135
 
@@ -855,6 +858,101 @@ function bind_events() {
855
  }
856
  }
857
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
858
  function add_bind_for_custom_fields( prefix, output_format, $to ) {
859
  jQuery( '#button_custom_field_' + prefix + '' ).off();
860
  jQuery( '#button_custom_field_' + prefix + '' ).click( function() {
@@ -1030,7 +1128,10 @@ function select2_inits()
1030
  } );
1031
  jQuery( "#product_custom_fields_check" ).select2(select2WODropdownOpts);
1032
 
1033
-
 
 
 
1034
 
1035
  jQuery( "#taxonomies" ).select2( {
1036
  width: 150
@@ -1250,4 +1351,68 @@ function try_color_date_filter() {
1250
  if( jQuery( "#from_date" ).val() || jQuery( "#to_date" ).val() )
1251
  color = 'red';
1252
  jQuery( "#my-date-filter" ).css('color', color);
1253
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
130
  });
131
  //end of change
132
 
133
+ // for filter by USER custom fields
134
+ bind_events_users();
135
+
136
  //PRODUCT ATTRIBUTES BEGIN
137
  jQuery( '#attributes' ).change( function() {
138
 
858
  }
859
  }
860
 
861
+ function bind_events_users() {
862
+ // for filter by ORDER custom fields
863
+ jQuery( '#user_custom_fields' ).change( function () {
864
+
865
+ jQuery( '#select_user_custom_fields' ).attr( 'disabled', 'disabled' );
866
+ var data = {
867
+ 'cf_name': jQuery( this ).val(),
868
+ method: "get_user_custom_fields_values",
869
+ action: "order_exporter"
870
+ };
871
+ var val_op = jQuery( '#select_user_custom_fields' ).val();
872
+ jQuery( '#text_user_custom_fields' ).val( '' );
873
+ jQuery.post( ajaxurl, data, function ( response ) {
874
+ jQuery( '#select_user_custom_fields' ).remove();
875
+ jQuery( '#select_user_custom_fields--select2 select' ).select2( 'destroy' );
876
+ jQuery( '#select_user_custom_fields, #select_user_custom_fields--select2' ).remove();
877
+ if ( response ) {
878
+ var options = '<option>' + export_messages.empty + '</option>';
879
+ jQuery.each( response, function ( index, value ) {
880
+ options += '<option>' + value + '</option>';
881
+ } );
882
+ var $select = jQuery( '<div id="select_user_custom_fields--select2" style="margin-top: 0px;margin-right: 6px; vertical-align: top;'
883
+ + 'display: ' + (
884
+ (
885
+ 'LIKE' === val_op || 'NOT SET' === val_op || 'IS SET' === val_op
886
+ ) ? 'none' : 'inline-block'
887
+ ) + ';">'
888
+ + '<select id="select_user_custom_fields">' + options + '</select></div>' );
889
+ $select.insertBefore( jQuery( '#add_user_custom_fields' ) )
890
+ $select.find( 'select' ).select2( {tags: true} );
891
+ }
892
+ else {
893
+ jQuery( '<input type="text" id="select_user_custom_fields" style="margin-right: 8px;">' ).insertBefore(
894
+ jQuery( '#add_user_custom_fields' ) );
895
+ }
896
+ }, 'json' );
897
+ } );
898
+ jQuery( '#add_user_custom_fields' ).click( function () {
899
+
900
+ var val = ! jQuery( "#select_user_custom_fields" ).is( ':disabled' ) ? jQuery(
901
+ "#select_user_custom_fields" ).val() : jQuery( "#text_user_custom_fields" ).val();
902
+ var val2 = jQuery( '#user_custom_fields' ).val();
903
+ var val_op = jQuery( '#user_custom_fields_compare' ).val();
904
+ if ( val != null && val2 != null && val.length && val2.length ) {
905
+ var result = val2 + ' ' + val_op + ' ' + val;
906
+
907
+ var f = true;
908
+ jQuery( '#user_custom_fields_check' ).next().find( 'ul li' ).each( function () {
909
+ if ( jQuery( this ).attr( 'title' ) == val ) {
910
+ f = false;
911
+ }
912
+ } );
913
+
914
+ if ( f ) {
915
+ if ( export_messages.empty === val ) {
916
+ result = val2 + ' ' + val_op + ' empty';
917
+ jQuery(
918
+ '#user_custom_fields_check' ).append( '<option selected="selected" value="' + result + '">' + result + '</option>' );
919
+ } else {
920
+ jQuery(
921
+ '#user_custom_fields_check' ).append( '<option selected="selected" value="' + result + '">' + result + '</option>' );
922
+ }
923
+
924
+ jQuery( '#user_custom_fields_check' ).select2();
925
+
926
+ jQuery( '#user_custom_fields_check option' ).each( function () {
927
+ jQuery( '#user_custom_fields_check option[value=\"' + jQuery( this ).val() + '\"]:not(:last)' ).remove();
928
+ } );
929
+
930
+ jQuery( "input#select_user_custom_fields" ).val( '' );
931
+ }
932
+ }
933
+ return false;
934
+ } );
935
+
936
+ jQuery( '#user_custom_fields_compare').change(function() {
937
+ var val_op = jQuery( '#user_custom_fields_compare' ).val();
938
+ if ( 'LIKE' === val_op ) {
939
+ jQuery( "#select_user_custom_fields" ).css( 'display', 'none' ).attr( 'disabled', 'disabled' );
940
+ jQuery( "#select_user_custom_fields--select2" ).hide();
941
+ jQuery( "#text_user_custom_fields" ).css('display', 'inline' ).attr( 'disabled', false );
942
+ }
943
+ else if ( 'NOT SET' === val_op || 'IS SET' === val_op ) {
944
+ jQuery( "#select_user_custom_fields" ).css( 'display', 'none' ).attr( 'disabled', 'disabled' ) . val(' ');
945
+ jQuery( "#select_user_custom_fields--select2" ).hide();
946
+ jQuery( "#text_user_custom_fields" ).css('display', 'none' ).attr( 'disabled', false ). val(' ');
947
+ }
948
+ else {
949
+ jQuery( "#select_user_custom_fields" ).css( 'display', 'inline-block' ).attr( 'disabled', false );
950
+ jQuery( '#select_user_custom_fields--select2' ).css('display', 'inline' );
951
+ jQuery( "#text_user_custom_fields" ).css( 'display', 'none' ).attr( 'disabled', 'disabled' );
952
+ }
953
+ });
954
+ }
955
+
956
  function add_bind_for_custom_fields( prefix, output_format, $to ) {
957
  jQuery( '#button_custom_field_' + prefix + '' ).off();
958
  jQuery( '#button_custom_field_' + prefix + '' ).click( function() {
1128
  } );
1129
  jQuery( "#product_custom_fields_check" ).select2(select2WODropdownOpts);
1130
 
1131
+ jQuery( "#user_custom_fields" ).select2( {
1132
+ width: 150
1133
+ } );
1134
+ jQuery( "#user_custom_fields_check" ).select2();
1135
 
1136
  jQuery( "#taxonomies" ).select2( {
1137
  width: 150
1351
  if( jQuery( "#from_date" ).val() || jQuery( "#to_date" ).val() )
1352
  color = 'red';
1353
  jQuery( "#my-date-filter" ).css('color', color);
1354
+ }
1355
+
1356
+ jQuery( document ).ready( function ($) {
1357
+
1358
+ $( "#the-list" ).sortable( { handle: '.woe-row-sort-handle' } );
1359
+
1360
+ $( '.wp-wrap .column-order' ).hide();
1361
+
1362
+ $start_reorder_button = $( '#start_reorder' );
1363
+ $apply_reorder_button = $( '#apply_reorder' );
1364
+ $cancel_reorder_button = $( '#cancel_reorder' );
1365
+ $start_reorder_button.click( function ( e ) {
1366
+ $order_ids = $( "#the-list" ).sortable( "toArray", {attribute: 'data-job_id'} );
1367
+
1368
+ $start_reorder_button.hide();
1369
+ $apply_reorder_button.show();
1370
+ $cancel_reorder_button.show();
1371
+
1372
+ $( '.wp-wrap .check-column' ).hide();
1373
+ $( '.wp-wrap .column-order' ).show();
1374
+ } );
1375
+
1376
+ $apply_reorder_button.click( function ( e ) {
1377
+ $start_reorder_button.show();
1378
+ $apply_reorder_button.hide();
1379
+ $cancel_reorder_button.hide();
1380
+
1381
+ $( '.wp-wrap .check-column' ).show();
1382
+ $( '.wp-wrap .column-order' ).hide();
1383
+
1384
+ jQuery.ajax({
1385
+ url: ajaxurl,
1386
+ data: {
1387
+ 'action': "order_exporter",
1388
+ 'method': 'reorder_jobs',
1389
+ 'new_jobs_order': $( "#the-list" ).sortable( "toArray", {attribute: 'data-job_id'} ),
1390
+ 'tab_name': $tab_name,
1391
+ },
1392
+ error: function ( response ) {},
1393
+ dataType: 'json',
1394
+ type: 'POST',
1395
+ success: function() {
1396
+
1397
+ }
1398
+ });
1399
+
1400
+ } );
1401
+
1402
+ $cancel_reorder_button.click( function ( e ) {
1403
+ $start_reorder_button.show();
1404
+ $apply_reorder_button.hide();
1405
+ $cancel_reorder_button.hide();
1406
+
1407
+ $( '.wp-wrap .check-column' ).show();
1408
+ $( '.wp-wrap .column-order' ).hide();
1409
+
1410
+ $( $order_ids ).each( function ( $key, $job_id ) {
1411
+ $element = $( '[data-job_id="' + $job_id + '"' ).detach();
1412
+ $( "#the-list" ).append( $element );
1413
+ } );
1414
+ } );
1415
+
1416
+
1417
+
1418
+ } );
assets/js/settings-form.js CHANGED
@@ -503,6 +503,7 @@ jQuery( document ).ready( function( $ ) {
503
  jQuery( '#itemmeta' ).change();
504
  jQuery( '#custom_fields' ).change();
505
  jQuery( '#product_custom_fields' ).change();
 
506
  jQuery( '#shipping_locations' ).change();
507
  jQuery( '#billing_locations' ).change();
508
  jQuery( '#item_names' ).change();
@@ -601,7 +602,7 @@ jQuery( document ).ready( function( $ ) {
601
  } );
602
 
603
  $( 'input[type="checkbox"][name="settings[custom_php]"]' ).change( function() {
604
- $( 'textarea[name="settings[custom_php_code]"]' ).toggle( $( this ).is( ':checked' ) );
605
  } );
606
 
607
  $( '#order_fields input[type=checkbox]' ).change( function() {
@@ -727,7 +728,11 @@ jQuery( document ).ready( function( $ ) {
727
  progress( 100, jQuery( '#progressBar' ) );
728
  },
729
  success: function( response ) {
730
- get_all( response.start, ( response.start / window.count ) * 100, method )
 
 
 
 
731
  }
732
  } );
733
  }
503
  jQuery( '#itemmeta' ).change();
504
  jQuery( '#custom_fields' ).change();
505
  jQuery( '#product_custom_fields' ).change();
506
+ jQuery( '#user_custom_fields' ).change();
507
  jQuery( '#shipping_locations' ).change();
508
  jQuery( '#billing_locations' ).change();
509
  jQuery( '#item_names' ).change();
602
  } );
603
 
604
  $( 'input[type="checkbox"][name="settings[custom_php]"]' ).change( function() {
605
+ $( 'div#custom_php_code_textarea' ).toggle( $( this ).is( ':checked' ) );
606
  } );
607
 
608
  $( '#order_fields input[type=checkbox]' ).change( function() {
728
  progress( 100, jQuery( '#progressBar' ) );
729
  },
730
  success: function( response ) {
731
+ if ( typeof response.error !== 'undefined') {
732
+ alert( response.error );
733
+ } else {
734
+ get_all( response.start, ( response.start / window.count ) * 100, method )
735
+ }
736
  }
737
  } );
738
  }
classes/admin/class-wc-order-export-ajax.php CHANGED
@@ -10,82 +10,86 @@ class WC_Order_Export_Ajax {
10
 
11
  public function save_settings() {
12
  $settings = WC_Order_Export_Manage::make_new_settings( $_POST );
13
- $id = WC_Order_Export_Manage::save_export_settings( $_POST['mode'], $_POST['id'], $settings );
14
  echo json_encode( array( 'id' => $id ) );
15
  }
16
-
17
  public function validate_url_key() {
18
  $main_settings = WC_Order_Export_Admin::load_main_settings();
19
- if( !isset( $_REQUEST['key'] ) OR $_REQUEST['key'] != $main_settings['cron_key'] ) {
20
- _e( 'Wrong key for cron url!', 'woo-order-export-lite' ) ;
21
  die();
22
  }
23
- }
24
 
25
  //called from UI
26
  public function run_one_job() {
27
- if( !empty( $_REQUEST[ 'schedule' ] ) )
28
- $settings = WC_Order_Export_Manage::get( WC_Order_Export_Manage::EXPORT_SCHEDULE, $_REQUEST[ 'schedule' ] );
29
- elseif($_REQUEST[ 'profile' ] == 'now')
30
  $settings = WC_Order_Export_Manage::get( WC_Order_Export_Manage::EXPORT_NOW );
31
- else
32
- $settings = WC_Order_Export_Manage::get( WC_Order_Export_Manage::EXPORT_PROFILE, $_REQUEST[ 'profile' ] );
 
33
  $filename = WC_Order_Export_Engine::build_file_full( $settings );
34
  WC_Order_Export_Manage::set_correct_file_ext( $settings );
35
- $this->send_headers( $settings[ 'format' ], WC_Order_Export_Engine::make_filename( $settings['export_filename'] ) );
36
- $this->send_contents_delete_file($filename);
 
37
  }
38
 
39
  public function run_one_scheduled_job() {
40
  WC_Order_Export_Cron::run_one_scheduled_job();
41
  }
42
-
43
  public function run_cron_jobs() {
44
  WC_Order_Export_Cron::wc_export_cron_global_f();
45
  }
46
-
47
- public function save_tools() {
48
- $data = json_decode($_POST['tools-import'], true);
49
- if ( $data )
50
  WC_Order_Export_Manage::import_settings( $data );
 
51
  }
52
 
53
- public function save_settings_tab() {
54
  WC_Order_Export_Admin::save_main_settings();
55
  }
56
 
57
  public function get_products() {
58
- echo json_encode( WC_Order_Export_Data_Extractor_UI::get_products_like($_REQUEST['q']) );
 
59
  }
60
 
61
  public function get_users() {
62
- echo json_encode( WC_Order_Export_Data_Extractor_UI::get_users_like($_REQUEST['q']) );
63
  }
64
 
65
  public function get_coupons() {
66
- echo json_encode( WC_Order_Export_Data_Extractor_UI::get_coupons_like($_REQUEST['q']) );
67
  }
68
 
69
  public function get_used_custom_order_meta() {
70
  $settings = WC_Order_Export_Manage::make_new_settings( $_POST );
71
- $sql = WC_Order_Export_Data_Extractor::sql_get_order_ids( $settings );
72
- $ret = WC_Order_Export_Data_Extractor_UI::get_all_order_custom_meta_fields( $sql );
73
  echo json_encode( $ret );
74
  }
75
 
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
 
@@ -95,7 +99,7 @@ class WC_Order_Export_Ajax {
95
  }
96
 
97
  public function get_categories() {
98
- echo json_encode( WC_Order_Export_Data_Extractor_UI::get_categories_like($_REQUEST['q']) );
99
  }
100
 
101
  public function get_vendors() {
@@ -105,8 +109,8 @@ class WC_Order_Export_Ajax {
105
  public function test_destination() {
106
  $settings = WC_Order_Export_Manage::make_new_settings( $_POST );
107
 
108
- unset( $settings[ 'destination' ][ 'type' ] );
109
- $settings[ 'destination' ][ 'type' ][ ] = $_POST[ 'destination' ];
110
 
111
  // use unsaved settings
112
 
@@ -115,7 +119,7 @@ class WC_Order_Export_Ajax {
115
  $main_settings = WC_Order_Export_Admin::load_main_settings();
116
 
117
  $result = WC_Order_Export_Engine::build_files_and_export( $settings, '', $main_settings['limit_button_test'] );
118
- echo str_replace("<br>", "\r\n", $result);
119
  }
120
 
121
  public function preview() {
@@ -137,84 +141,94 @@ class WC_Order_Export_Ajax {
137
  }
138
 
139
  public function get_order_custom_fields_values() {
140
- echo json_encode( WC_Order_Export_Data_Extractor_UI::get_order_custom_fields_values($_POST['cf_name']) );
 
 
 
 
141
  }
142
 
143
  public function get_product_custom_fields_values() {
144
- echo json_encode( WC_Order_Export_Data_Extractor_UI::get_product_custom_fields_values($_POST['cf_name']) );
145
  }
146
 
147
  public function get_products_taxonomies_values() {
148
- echo json_encode( WC_Order_Export_Data_Extractor_UI::get_products_taxonomies_values($_POST['tax']) );
149
  }
150
 
151
  public function get_products_attributes_values() {
152
- echo json_encode( WC_Order_Export_Data_Extractor_UI::get_products_attributes_values($_POST['attr']) );
153
  }
154
 
155
- public function get_products_itemmeta_values() {
156
- echo json_encode( WC_Order_Export_Data_Extractor_UI::get_products_itemmeta_values($_POST['item']) );
157
  }
158
 
159
  public function get_order_shipping_values() {
160
- echo json_encode( WC_Order_Export_Data_Extractor_UI::get_order_meta_values('_shipping_', $_POST['item']) );
 
 
 
 
161
  }
162
 
163
- public function get_order_billing_values() {
164
- echo json_encode( WC_Order_Export_Data_Extractor_UI::get_order_meta_values('_billing_', $_POST['item']) );
165
- }
166
-
167
  public function get_order_item_names() {
168
- echo json_encode( WC_Order_Export_Data_Extractor_UI::get_order_item_names($_POST['item_type']) );
169
  }
 
170
  public function get_order_item_meta_key_values() {
171
- echo json_encode( WC_Order_Export_Data_Extractor_UI::get_order_item_meta_key_values($_POST['meta_key']) );
172
  }
173
-
174
-
175
 
176
- public function send_headers( $format, $download_name = '') {
 
177
  WC_Order_Export_Engine::kill_buffers();
178
  switch ( $format ) {
179
  case 'XLSX':
180
- if( empty( $download_name ) )
181
- $download_name = "orders.xlsx";
 
182
  header( 'Content-type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' );
183
  break;
184
  case 'XLS':
185
- if( empty( $download_name ) )
186
- $download_name = "orders.xls";
 
187
  header( 'Content-type: application/vnd.ms-excel; charset=utf-8' );
188
  break;
189
  case 'CSV':
190
- if( empty( $download_name ) )
191
- $download_name = "orders.csv";
 
192
  header( 'Content-type: text/csv' );
193
  break;
194
  case 'TSV':
195
- if( empty( $download_name ) )
196
  $download_name = "orders.tsv";
 
197
  header( 'Content-type: text/csv' );
198
  break;
199
  case 'JSON':
200
- if( empty( $download_name ) )
201
- $download_name = "orders.json";
 
202
  header( 'Content-type: application/json' );
203
  break;
204
  case 'XML':
205
- if( empty( $download_name ) )
206
- $download_name = "orders.xml";
 
207
  header( 'Content-type: text/xml' );
208
  break;
209
  }
210
- header( 'Content-Disposition: attachment; filename="' . $download_name .'"' );
211
  }
212
 
213
  public function start_prevent_object_cache() {
214
  global $_wp_using_ext_object_cache;
215
 
216
- $this->_wp_using_ext_object_cache_previous = $_wp_using_ext_object_cache;
217
- $_wp_using_ext_object_cache = false;
218
  }
219
 
220
  public function stop_prevent_object_cache() {
@@ -228,16 +242,16 @@ class WC_Order_Export_Ajax {
228
  $settings = WC_Order_Export_Manage::make_new_settings( $_POST );
229
 
230
  $filename = WC_Order_Export_Engine::tempnam( sys_get_temp_dir(), "orders" );
231
- if( !$filename ) {
232
- die( __( 'Can\'t create temporary file', 'woo-order-export-lite' ) ) ;
233
  }
234
-
235
  //no free space or other file system errors?
236
- try {
237
  file_put_contents( $filename, '' );
238
  do_action( 'woe_start_export_job', $_POST['id'], $settings );
239
  $total = WC_Order_Export_Engine::build_file( $settings, 'start_estimate', 'file', 0, 0, $filename );
240
- } catch (Exception $e) {
241
  die( $e->getMessage() );
242
  }
243
  // file created
@@ -256,6 +270,7 @@ class WC_Order_Export_Ajax {
256
  }
257
  set_transient( $this->tempfile_prefix . $_REQUEST['file_id'], $filename, 60 );
258
  $this->stop_prevent_object_cache();
 
259
  return $filename;
260
  }
261
 
@@ -264,7 +279,7 @@ class WC_Order_Export_Ajax {
264
  $filename = get_transient( $this->tempfile_prefix . $_REQUEST['file_id'] );
265
  if ( $filename !== false ) {
266
  delete_transient( $this->tempfile_prefix . $_REQUEST['file_id'] );
267
- unlink($filename);
268
  }
269
  $this->stop_prevent_object_cache();
270
  }
@@ -276,10 +291,11 @@ class WC_Order_Export_Ajax {
276
  }
277
 
278
  public function export_part() {
279
- $settings = WC_Order_Export_Manage::make_new_settings( $_POST );
280
  $main_settings = WC_Order_Export_Admin::load_main_settings();
281
 
282
- WC_Order_Export_Engine::build_file( $settings, 'partial', 'file', intval( $_POST['start'] ), $main_settings['ajax_orders_per_step'],
 
283
  $this->get_temp_file_name() );
284
  echo json_encode( array( 'start' => $_POST['start'] + $main_settings['ajax_orders_per_step'] ) );
285
  }
@@ -289,7 +305,9 @@ class WC_Order_Export_Ajax {
289
  WC_Order_Export_Engine::build_file( $settings, 'finish', 'file', 0, 0, $this->get_temp_file_name() );
290
 
291
  $filename = WC_Order_Export_Engine::make_filename( $settings['export_filename'] );
 
292
  set_transient( $this->tempfile_prefix . 'download_filename', $filename, 60 );
 
293
  echo json_encode( array( 'done' => true ) );
294
  }
295
 
@@ -298,9 +316,9 @@ class WC_Order_Export_Ajax {
298
  $format = basename( $_GET['format'] );
299
  $filename = $this->get_temp_file_name();
300
  delete_transient( $this->tempfile_prefix . $_GET['file_id'] );
301
-
302
- $download_name = get_transient( $this->tempfile_prefix . 'download_filename');
303
- $this->send_headers( $format ,$download_name);
304
  $this->send_contents_delete_file( $filename );
305
  $this->stop_prevent_object_cache();
306
  }
@@ -311,8 +329,9 @@ class WC_Order_Export_Ajax {
311
  do_action( 'woe_start_export_job', $_POST['id'], $settings );
312
 
313
  // custom export worked for plain
314
- if( apply_filters( 'woe_plain_export_custom_func', false, $_POST['id'], $settings ) )
315
- return ;
 
316
 
317
  $file = WC_Order_Export_Engine::build_file_full( $settings );
318
 
@@ -324,11 +343,13 @@ class WC_Order_Export_Ajax {
324
 
325
  WC_Order_Export_Manage::set_correct_file_ext( $settings );
326
 
327
- $_GET['format'] = $settings[ 'format' ];
328
  $_GET['file_id'] = $_REQUEST['file_id'] = $file_id;
329
 
330
  $filename = WC_Order_Export_Engine::make_filename( $settings['export_filename'] );
 
331
  set_transient( $this->tempfile_prefix . 'download_filename', $filename, 60 );
 
332
 
333
  $this->export_download();
334
  } else {
@@ -337,21 +358,51 @@ class WC_Order_Export_Ajax {
337
  }
338
 
339
  function export_download_bulk_file() {
340
- if($_REQUEST[ 'export_bulk_profile' ] == 'now')
341
- $settings = WC_Order_Export_Manage::get( WC_Order_Export_Manage::EXPORT_NOW );
342
- else
343
- $settings = WC_Order_Export_Manage::get( WC_Order_Export_Manage::EXPORT_PROFILE, $_REQUEST[ 'export_bulk_profile' ] );
344
- $filename = WC_Order_Export_Engine::build_file_full( $settings, '', 0, explode(",",$_REQUEST[ 'ids' ]) );
 
 
345
  WC_Order_Export_Manage::set_correct_file_ext( $settings );
346
- $this->send_headers( $settings[ 'format' ], WC_Order_Export_Engine::make_filename( $settings['export_filename'] ) );
 
347
  $this->send_contents_delete_file( $filename );
348
  }
349
-
350
  private function send_contents_delete_file( $filename ) {
351
- if( !empty($filename) ) {
352
  readfile( $filename );
353
  unlink( $filename );
354
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
355
  }
356
  }
 
357
  ?>
10
 
11
  public function save_settings() {
12
  $settings = WC_Order_Export_Manage::make_new_settings( $_POST );
13
+ $id = WC_Order_Export_Manage::save_export_settings( $_POST['mode'], $_POST['id'], $settings );
14
  echo json_encode( array( 'id' => $id ) );
15
  }
16
+
17
  public function validate_url_key() {
18
  $main_settings = WC_Order_Export_Admin::load_main_settings();
19
+ if ( ! isset( $_REQUEST['key'] ) OR $_REQUEST['key'] != $main_settings['cron_key'] ) {
20
+ _e( 'Wrong key for cron url!', 'woo-order-export-lite' );
21
  die();
22
  }
23
+ }
24
 
25
  //called from UI
26
  public function run_one_job() {
27
+ if ( ! empty( $_REQUEST['schedule'] ) ) {
28
+ $settings = WC_Order_Export_Manage::get( WC_Order_Export_Manage::EXPORT_SCHEDULE, $_REQUEST['schedule'] );
29
+ } elseif ( $_REQUEST['profile'] == 'now' ) {
30
  $settings = WC_Order_Export_Manage::get( WC_Order_Export_Manage::EXPORT_NOW );
31
+ } else {
32
+ $settings = WC_Order_Export_Manage::get( WC_Order_Export_Manage::EXPORT_PROFILE, $_REQUEST['profile'] );
33
+ }
34
  $filename = WC_Order_Export_Engine::build_file_full( $settings );
35
  WC_Order_Export_Manage::set_correct_file_ext( $settings );
36
+ $this->send_headers( $settings['format'],
37
+ WC_Order_Export_Engine::make_filename( $settings['export_filename'] ) );
38
+ $this->send_contents_delete_file( $filename );
39
  }
40
 
41
  public function run_one_scheduled_job() {
42
  WC_Order_Export_Cron::run_one_scheduled_job();
43
  }
44
+
45
  public function run_cron_jobs() {
46
  WC_Order_Export_Cron::wc_export_cron_global_f();
47
  }
48
+
49
+ public function save_tools() {
50
+ $data = json_decode( $_POST['tools-import'], true );
51
+ if ( $data ) {
52
  WC_Order_Export_Manage::import_settings( $data );
53
+ }
54
  }
55
 
56
+ public function save_settings_tab() {
57
  WC_Order_Export_Admin::save_main_settings();
58
  }
59
 
60
  public function get_products() {
61
+ $main_settings = WC_Order_Export_Admin::load_main_settings();
62
+ echo json_encode( WC_Order_Export_Data_Extractor_UI::get_products_like( $_REQUEST['q'], $main_settings['autocomplete_products_max'] ) );
63
  }
64
 
65
  public function get_users() {
66
+ echo json_encode( WC_Order_Export_Data_Extractor_UI::get_users_like( $_REQUEST['q'] ) );
67
  }
68
 
69
  public function get_coupons() {
70
+ echo json_encode( WC_Order_Export_Data_Extractor_UI::get_coupons_like( $_REQUEST['q'] ) );
71
  }
72
 
73
  public function get_used_custom_order_meta() {
74
  $settings = WC_Order_Export_Manage::make_new_settings( $_POST );
75
+ $sql = WC_Order_Export_Data_Extractor::sql_get_order_ids( $settings );
76
+ $ret = WC_Order_Export_Data_Extractor_UI::get_all_order_custom_meta_fields( $sql );
77
  echo json_encode( $ret );
78
  }
79
 
80
  public function get_used_custom_products_meta() {
81
  $settings = WC_Order_Export_Manage::make_new_settings( $_POST );
82
+ $sql = WC_Order_Export_Data_Extractor::sql_get_order_ids( $settings );
83
+ $ret = WC_Order_Export_Data_Extractor_UI::get_product_custom_meta_fields_for_orders( $sql );
84
+ sort( $ret );
85
  echo json_encode( $ret );
86
  }
87
 
88
  public function get_used_custom_order_items_meta() {
89
  $settings = WC_Order_Export_Manage::make_new_settings( $_POST );
90
+ $sql = WC_Order_Export_Data_Extractor::sql_get_order_ids( $settings );
91
+ $ret = WC_Order_Export_Data_Extractor_UI::get_order_item_custom_meta_fields_for_orders( $sql );
92
+ sort( $ret );
93
  echo json_encode( $ret );
94
  }
95
 
99
  }
100
 
101
  public function get_categories() {
102
+ echo json_encode( WC_Order_Export_Data_Extractor_UI::get_categories_like( $_REQUEST['q'] ) );
103
  }
104
 
105
  public function get_vendors() {
109
  public function test_destination() {
110
  $settings = WC_Order_Export_Manage::make_new_settings( $_POST );
111
 
112
+ unset( $settings['destination']['type'] );
113
+ $settings['destination']['type'][] = $_POST['destination'];
114
 
115
  // use unsaved settings
116
 
119
  $main_settings = WC_Order_Export_Admin::load_main_settings();
120
 
121
  $result = WC_Order_Export_Engine::build_files_and_export( $settings, '', $main_settings['limit_button_test'] );
122
+ echo str_replace( "<br>", "\r\n", $result );
123
  }
124
 
125
  public function preview() {
141
  }
142
 
143
  public function get_order_custom_fields_values() {
144
+ echo json_encode( WC_Order_Export_Data_Extractor_UI::get_order_custom_fields_values( $_POST['cf_name'] ) );
145
+ }
146
+
147
+ public function get_user_custom_fields_values() {
148
+ echo json_encode( WC_Order_Export_Data_Extractor_UI::get_user_custom_fields_values( $_POST['cf_name'] ) );
149
  }
150
 
151
  public function get_product_custom_fields_values() {
152
+ echo json_encode( WC_Order_Export_Data_Extractor_UI::get_product_custom_fields_values( $_POST['cf_name'] ) );
153
  }
154
 
155
  public function get_products_taxonomies_values() {
156
+ echo json_encode( WC_Order_Export_Data_Extractor_UI::get_products_taxonomies_values( $_POST['tax'] ) );
157
  }
158
 
159
  public function get_products_attributes_values() {
160
+ echo json_encode( WC_Order_Export_Data_Extractor_UI::get_products_attributes_values( $_POST['attr'] ) );
161
  }
162
 
163
+ public function get_products_itemmeta_values() {
164
+ echo json_encode( WC_Order_Export_Data_Extractor_UI::get_products_itemmeta_values( $_POST['item'] ) );
165
  }
166
 
167
  public function get_order_shipping_values() {
168
+ echo json_encode( WC_Order_Export_Data_Extractor_UI::get_order_meta_values( '_shipping_', $_POST['item'] ) );
169
+ }
170
+
171
+ public function get_order_billing_values() {
172
+ echo json_encode( WC_Order_Export_Data_Extractor_UI::get_order_meta_values( '_billing_', $_POST['item'] ) );
173
  }
174
 
 
 
 
 
175
  public function get_order_item_names() {
176
+ echo json_encode( WC_Order_Export_Data_Extractor_UI::get_order_item_names( $_POST['item_type'] ) );
177
  }
178
+
179
  public function get_order_item_meta_key_values() {
180
+ echo json_encode( WC_Order_Export_Data_Extractor_UI::get_order_item_meta_key_values( $_POST['meta_key'] ) );
181
  }
 
 
182
 
183
+
184
+ public function send_headers( $format, $download_name = '' ) {
185
  WC_Order_Export_Engine::kill_buffers();
186
  switch ( $format ) {
187
  case 'XLSX':
188
+ if ( empty( $download_name ) ) {
189
+ $download_name = "orders.xlsx";
190
+ }
191
  header( 'Content-type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' );
192
  break;
193
  case 'XLS':
194
+ if ( empty( $download_name ) ) {
195
+ $download_name = "orders.xls";
196
+ }
197
  header( 'Content-type: application/vnd.ms-excel; charset=utf-8' );
198
  break;
199
  case 'CSV':
200
+ if ( empty( $download_name ) ) {
201
+ $download_name = "orders.csv";
202
+ }
203
  header( 'Content-type: text/csv' );
204
  break;
205
  case 'TSV':
206
+ if ( empty( $download_name ) ) {
207
  $download_name = "orders.tsv";
208
+ }
209
  header( 'Content-type: text/csv' );
210
  break;
211
  case 'JSON':
212
+ if ( empty( $download_name ) ) {
213
+ $download_name = "orders.json";
214
+ }
215
  header( 'Content-type: application/json' );
216
  break;
217
  case 'XML':
218
+ if ( empty( $download_name ) ) {
219
+ $download_name = "orders.xml";
220
+ }
221
  header( 'Content-type: text/xml' );
222
  break;
223
  }
224
+ header( 'Content-Disposition: attachment; filename="' . $download_name . '"' );
225
  }
226
 
227
  public function start_prevent_object_cache() {
228
  global $_wp_using_ext_object_cache;
229
 
230
+ $this->_wp_using_ext_object_cache_previous = $_wp_using_ext_object_cache;
231
+ $_wp_using_ext_object_cache = false;
232
  }
233
 
234
  public function stop_prevent_object_cache() {
242
  $settings = WC_Order_Export_Manage::make_new_settings( $_POST );
243
 
244
  $filename = WC_Order_Export_Engine::tempnam( sys_get_temp_dir(), "orders" );
245
+ if ( ! $filename ) {
246
+ die( __( 'Can\'t create temporary file', 'woo-order-export-lite' ) );
247
  }
248
+
249
  //no free space or other file system errors?
250
+ try {
251
  file_put_contents( $filename, '' );
252
  do_action( 'woe_start_export_job', $_POST['id'], $settings );
253
  $total = WC_Order_Export_Engine::build_file( $settings, 'start_estimate', 'file', 0, 0, $filename );
254
+ } catch ( Exception $e ) {
255
  die( $e->getMessage() );
256
  }
257
  // file created
270
  }
271
  set_transient( $this->tempfile_prefix . $_REQUEST['file_id'], $filename, 60 );
272
  $this->stop_prevent_object_cache();
273
+
274
  return $filename;
275
  }
276
 
279
  $filename = get_transient( $this->tempfile_prefix . $_REQUEST['file_id'] );
280
  if ( $filename !== false ) {
281
  delete_transient( $this->tempfile_prefix . $_REQUEST['file_id'] );
282
+ unlink( $filename );
283
  }
284
  $this->stop_prevent_object_cache();
285
  }
291
  }
292
 
293
  public function export_part() {
294
+ $settings = WC_Order_Export_Manage::make_new_settings( $_POST );
295
  $main_settings = WC_Order_Export_Admin::load_main_settings();
296
 
297
+ WC_Order_Export_Engine::build_file( $settings, 'partial', 'file', intval( $_POST['start'] ),
298
+ $main_settings['ajax_orders_per_step'],
299
  $this->get_temp_file_name() );
300
  echo json_encode( array( 'start' => $_POST['start'] + $main_settings['ajax_orders_per_step'] ) );
301
  }
305
  WC_Order_Export_Engine::build_file( $settings, 'finish', 'file', 0, 0, $this->get_temp_file_name() );
306
 
307
  $filename = WC_Order_Export_Engine::make_filename( $settings['export_filename'] );
308
+ $this->start_prevent_object_cache();
309
  set_transient( $this->tempfile_prefix . 'download_filename', $filename, 60 );
310
+ $this->stop_prevent_object_cache();
311
  echo json_encode( array( 'done' => true ) );
312
  }
313
 
316
  $format = basename( $_GET['format'] );
317
  $filename = $this->get_temp_file_name();
318
  delete_transient( $this->tempfile_prefix . $_GET['file_id'] );
319
+
320
+ $download_name = get_transient( $this->tempfile_prefix . 'download_filename' );
321
+ $this->send_headers( $format, $download_name );
322
  $this->send_contents_delete_file( $filename );
323
  $this->stop_prevent_object_cache();
324
  }
329
  do_action( 'woe_start_export_job', $_POST['id'], $settings );
330
 
331
  // custom export worked for plain
332
+ if ( apply_filters( 'woe_plain_export_custom_func', false, $_POST['id'], $settings ) ) {
333
+ return;
334
+ }
335
 
336
  $file = WC_Order_Export_Engine::build_file_full( $settings );
337
 
343
 
344
  WC_Order_Export_Manage::set_correct_file_ext( $settings );
345
 
346
+ $_GET['format'] = $settings['format'];
347
  $_GET['file_id'] = $_REQUEST['file_id'] = $file_id;
348
 
349
  $filename = WC_Order_Export_Engine::make_filename( $settings['export_filename'] );
350
+ $this->start_prevent_object_cache();
351
  set_transient( $this->tempfile_prefix . 'download_filename', $filename, 60 );
352
+ $this->stop_prevent_object_cache();
353
 
354
  $this->export_download();
355
  } else {
358
  }
359
 
360
  function export_download_bulk_file() {
361
+ if ( $_REQUEST['export_bulk_profile'] == 'now' ) {
362
+ $settings = WC_Order_Export_Manage::get( WC_Order_Export_Manage::EXPORT_NOW );
363
+ } else {
364
+ $settings = WC_Order_Export_Manage::get( WC_Order_Export_Manage::EXPORT_PROFILE,
365
+ $_REQUEST['export_bulk_profile'] );
366
+ }
367
+ $filename = WC_Order_Export_Engine::build_file_full( $settings, '', 0, explode( ",", $_REQUEST['ids'] ) );
368
  WC_Order_Export_Manage::set_correct_file_ext( $settings );
369
+ $this->send_headers( $settings['format'],
370
+ WC_Order_Export_Engine::make_filename( $settings['export_filename'] ) );
371
  $this->send_contents_delete_file( $filename );
372
  }
373
+
374
  private function send_contents_delete_file( $filename ) {
375
+ if ( ! empty( $filename ) ) {
376
  readfile( $filename );
377
  unlink( $filename );
378
+ }
379
+ }
380
+
381
+ public function reorder_jobs() {
382
+ if ( ! empty( $_REQUEST['new_jobs_order'] ) AND ! empty( $_REQUEST['tab_name'] ) ) {
383
+
384
+ if ( $_REQUEST['tab_name'] == 'schedule' ) {
385
+ $mode = WC_Order_Export_Manage::EXPORT_SCHEDULE;
386
+ } elseif ( $_REQUEST['tab_name'] == 'profile' ) {
387
+ $mode = WC_Order_Export_Manage::EXPORT_PROFILE;
388
+ } elseif ( $_REQUEST['tab_name'] == 'order_action' ) {
389
+ $mode = WC_Order_Export_Manage::EXPORT_ORDER_ACTION;
390
+ } else {
391
+ echo json_encode( array( 'result' => false ) );
392
+ die();
393
+ }
394
+
395
+ //skip zero ids
396
+ foreach ( array_filter( $_REQUEST['new_jobs_order'] ) as $index => $job_id ) {
397
+ $job = WC_Order_Export_Manage::get( $mode, $job_id );
398
+ $job['priority'] = $index + 1;
399
+ WC_Order_Export_Manage::save_export_settings( $mode, $job_id, $job );
400
+ }
401
+ echo json_encode( array( 'result' => true ) );
402
+ } else {
403
+ echo json_encode( array( 'result' => false ) );
404
+ }
405
  }
406
  }
407
+
408
  ?>
classes/admin/class-wc-order-export-manage.php CHANGED
@@ -13,18 +13,18 @@ class WC_Order_Export_Manage {
13
  const EXPORT_PROFILE = 'profiles';
14
  const EXPORT_SCHEDULE = 'cron';
15
  const EXPORT_ORDER_ACTION = 'order-action';
16
-
17
  public static $edit_existing_job = false;
18
-
19
  static function get_days() {
20
  return array(
21
- 'Sun'=>__( 'Sun', 'woo-order-export-lite' ),
22
- 'Mon'=>__( 'Mon', 'woo-order-export-lite' ),
23
- 'Tue'=>__( 'Tue', 'woo-order-export-lite' ),
24
- 'Wed'=>__( 'Wed', 'woo-order-export-lite' ),
25
- 'Thu'=>__( 'Thu', 'woo-order-export-lite' ),
26
- 'Fri'=>__( 'Fri', 'woo-order-export-lite' ),
27
- 'Sat'=>__( 'Sat', 'woo-order-export-lite' ),
28
  );
29
  }
30
 
@@ -39,37 +39,42 @@ class WC_Order_Export_Manage {
39
  } elseif ( $mode == self::EXPORT_ORDER_ACTION ) {
40
  $name = self::settings_name_actions;
41
  }
 
42
  return $name;
43
  }
44
-
45
  static function remove_settings() {
46
  $options = array(
47
  self::settings_name_now,
48
  self::settings_name_cron,
49
  self::settings_name_profiles,
50
  self::settings_name_actions,
51
- );
52
-
53
- foreach($options as $option)
54
  delete_option( $option );
 
55
  }
56
 
57
  // arrays
58
  static function get_export_settings_collection( $mode ) {
59
  $name = self::get_settings_name_for_mode( $mode );
 
60
  return get_option( $name, array() );
61
  }
 
62
  static function save_export_settings_collection( $mode, $jobs ) {
63
  $name = self::get_settings_name_for_mode( $mode );
64
- return update_option( $name, $jobs );
 
65
  }
66
 
67
  static function make_new_settings( $in ) {
68
  $new_settings = $in['settings'];
69
-
70
  // use old PHP code if no permissions, just to stop trcky persons ;)
71
- if( !WC_Order_Export_Admin::user_can_add_custom_php() ) {
72
- unset($new_settings['custom_php_code']);
73
  }
74
 
75
  // UI don't pass empty multiselects
@@ -86,11 +91,12 @@ class WC_Order_Export_Manage {
86
  'shipping_methods',
87
  'user_roles',
88
  'user_names',
 
89
  'coupons',
90
- 'billing_locations',
91
  'payment_methods',
92
  'product_attributes',
93
- 'product_itemmeta',
94
  'product_taxonomies',
95
  'item_names',
96
  'item_metadata',
@@ -101,8 +107,8 @@ class WC_Order_Export_Manage {
101
  }
102
  }
103
 
104
- $settings = self::get( $in['mode'], $in['id'] );
105
- $settings['id'] = $in['id'];
106
  // setup new values for same keys
107
  foreach ( $new_settings as $key => $val ) {
108
  $settings[ $key ] = $val;
@@ -111,7 +117,7 @@ class WC_Order_Export_Manage {
111
  $sections = array(
112
  'orders' => 'order_fields',
113
  'products' => 'order_product_fields',
114
- 'coupons' => 'order_coupon_fields'
115
  );
116
  foreach ( $sections as $section => $fieldset ) {
117
  $new_order_fields = array();
@@ -122,7 +128,7 @@ class WC_Order_Export_Manage {
122
  $opts = array(
123
  "checked" => $in_sec['exported'][ $field ],
124
  "colname" => $colname,
125
- "label" => $in_sec['label'][ $field ]
126
  );
127
  // for products & coupons
128
  if ( isset( $in_sec['repeat'][ $field ] ) ) {
@@ -152,24 +158,27 @@ class WC_Order_Export_Manage {
152
  static function get( $mode, $id = false ) {
153
  $all_jobs = self::get_export_settings_collection( $mode );
154
 
155
- if ( $mode == self::EXPORT_NOW) { // one job
156
  return self::apply_defaults( $mode, $all_jobs );
157
  } elseif ( $id === false ) {
158
- if ( empty( $all_jobs ) OR !is_array($all_jobs) )
159
  return array();
160
- return array_map( function( $item ) use( $mode ) {
 
 
161
  return WC_Order_Export_Manage::apply_defaults( $mode, $item );
162
  }, $all_jobs );
163
  }
164
 
165
  $settings = isset( $all_jobs[ $id ] ) ? $all_jobs[ $id ] : array();
 
166
  return self::apply_defaults( $mode, $settings );
167
  }
168
 
169
  static function apply_defaults( $mode, $settings ) {
170
-
171
- $settings = apply_filters( "woe_before_apply_default_settings", $settings , $mode);
172
-
173
  $defaults = array(
174
  'mode' => $mode,
175
  'title' => '',
@@ -187,7 +196,8 @@ class WC_Order_Export_Manage {
187
  'item_metadata' => array(),
188
  'user_roles' => array(),
189
  'user_names' => array(),
190
- 'billing_locations' => array(),
 
191
  'payment_methods' => array(),
192
  'any_coupon_used' => 0,
193
  'coupons' => array(),
@@ -198,14 +208,14 @@ class WC_Order_Export_Manage {
198
  'product_taxonomies' => array(),
199
  'product_custom_fields' => array(),
200
  'product_attributes' => array(),
201
- 'product_itemmeta' => array(),
202
  'format' => 'XLS',
203
- 'format_xls_use_xls_format' => 0,
204
- 'format_xls_sheet_name' => __( 'Orders', 'woo-order-export-lite' ),
205
  'format_xls_display_column_names' => 1,
206
- 'format_xls_auto_width' => 1,
207
  'format_xls_populate_other_columns_product_rows' => 1,
208
- 'format_xls_direction_rtl' => 0,
209
  'format_csv_enclosure' => '"',
210
  'format_csv_delimiter' => ',',
211
  'format_csv_linebreak' => '\r\n',
@@ -229,10 +239,10 @@ class WC_Order_Export_Manage {
229
  'format_xml_self_closing_tags' => 1,
230
  'all_products_from_order' => 1,
231
  'skip_refunded_items' => 1,
232
- 'skip_suborders' => 0,
233
- 'export_refunds' => 0,
234
- 'date_format' => 'Y-m-d',
235
- 'time_format' => 'H:i',
236
  'sort_direction' => 'DESC',
237
  'sort' => 'order_id',
238
  'format_number_fields' => 0,
@@ -241,14 +251,14 @@ class WC_Order_Export_Manage {
241
  'strip_tags_product_fields' => 0,
242
  'cleanup_phone' => 0,
243
  'enable_debug' => 0,
244
- 'format_json_start_tag' => '[',
245
- 'format_json_end_tag' => ']',
246
  'custom_php' => 0,
247
  'custom_php_code' => '',
248
  'mark_exported_orders' => 0,
249
  'export_unmarked_orders' => 0,
250
-
251
- 'summary_report_by_products' => 0,
252
  );
253
 
254
  if ( ! isset( $settings['format'] ) ) {
@@ -262,54 +272,63 @@ class WC_Order_Export_Manage {
262
  if ( ! isset( $settings['order_fields'] ) ) {
263
  $settings['order_fields'] = array();
264
  }
265
- self::merge_settings_and_default( $settings['order_fields'], WC_Order_Export_Data_Extractor_UI::get_order_fields( $settings['format'] ) );
 
266
 
267
  if ( ! isset( $settings['order_product_fields'] ) ) {
268
  $settings['order_product_fields'] = array();
269
  }
270
- self::merge_settings_and_default( $settings['order_product_fields'], WC_Order_Export_Data_Extractor_UI::get_order_product_fields( $settings['format'] ) );
 
271
 
272
  if ( ! isset( $settings['order_coupon_fields'] ) ) {
273
  $settings['order_coupon_fields'] = array();
274
  }
275
- self::merge_settings_and_default( $settings['order_coupon_fields'], WC_Order_Export_Data_Extractor_UI::get_order_coupon_fields( $settings['format'] ) );
 
 
276
  return array_merge( $defaults, $settings );
277
  }
278
 
279
- static function merge_settings_and_default(&$opt, $defaults) {
280
- foreach( $defaults as $k=>$v ) {
281
- if( isset($opt[$k]) ) {
282
  //set default attribute OR add to option
283
- if( isset($v['default']) )
284
- $opt[$k]['default'] = $v['default'];
 
285
  //set default format OR add to option
286
- if( isset($v['format']) )
287
- $opt[$k]['format'] = $v['format'];
 
288
  // overwrite labels for localization
289
- $opt[$k]['label'] = $v['label'];
290
  } else {
291
- if( self::$edit_existing_job AND $v['checked']=="1" )
292
  $v['checked'] = "0";
293
- $opt[$k] = $v;
294
- }
 
295
  }
296
  }
297
 
298
  static function save_export_settings( $mode, $id, $options ) {
299
- $all_jobs = self::get_export_settings_collection( $mode);
300
  if ( $mode == self::EXPORT_NOW ) {
301
  $all_jobs = $options;// just replace
302
  } elseif ( $mode == self::EXPORT_SCHEDULE ) {
303
  if ( $id ) {
304
- $options['schedule']['last_run'] = isset($all_jobs[ $id ]) ? $all_jobs[ $id ]['schedule']['last_run'] : current_time("timestamp",0);
305
- $options['schedule']['next_run'] = WC_Order_Export_Cron::next_event_timestamp_for_schedule( $options['schedule'], $id );
 
 
306
  $all_jobs[ $id ] = $options;
307
  } else {
308
- $options['schedule']['last_run'] = current_time("timestamp",0);
309
  $options['schedule']['next_run'] = WC_Order_Export_Cron::next_event_timestamp_for_schedule( $options['schedule'] );
310
  $all_jobs[] = $options; // new job
311
- end( $all_jobs );
312
- $id = key( $all_jobs );
313
  }
314
  } elseif ( $mode == self::EXPORT_PROFILE OR $mode == self::EXPORT_ORDER_ACTION ) {
315
  if ( $id ) {
@@ -321,10 +340,12 @@ class WC_Order_Export_Manage {
321
  }
322
  }
323
 
324
- self::save_export_settings_collection( $mode, $all_jobs);
325
 
326
- if( $mode == self::EXPORT_SCHEDULE )
327
  WC_Order_Export_Cron::install_job();
 
 
328
  return $id;
329
  }
330
 
@@ -332,22 +353,25 @@ class WC_Order_Export_Manage {
332
  return self::advanced_clone_export_settings( $id, $mode, $mode );
333
  }
334
 
335
- static function advanced_clone_export_settings( $id, $mode_in = self::EXPORT_SCHEDULE, $mode_out = self::EXPORT_SCHEDULE ) {
 
 
 
 
336
  $all_jobs_in = self::get_export_settings_collection( $mode_in );
337
  //new settings
338
- $settings = $all_jobs_in[ $id ];
339
- $settings['mode'] = $mode_out;
340
 
341
  if ( $mode_in !== $mode_out ) {
342
  $all_jobs_out = self::get_export_settings_collection( $mode_out );
343
- }
344
- else {
345
- $mode_out = $mode_in;
346
- $all_jobs_out = $all_jobs_in;
347
  $settings['title'] .= " [cloned]"; //add note
348
  }
349
 
350
- if ( $mode_in === self::EXPORT_PROFILE && $mode_out === self::EXPORT_SCHEDULE) {
351
  if ( ! isset( $settings['destination'] ) ) {
352
  $settings['destination'] = array(
353
  'type' => 'folder',
@@ -365,8 +389,8 @@ class WC_Order_Export_Manage {
365
 
366
  if ( ! isset( $settings['schedule'] ) ) {
367
  $settings['schedule'] = array(
368
- 'type' => 'schedule-1',
369
- 'run_at' => '00:00',
370
  );
371
  }
372
 
@@ -374,10 +398,11 @@ class WC_Order_Export_Manage {
374
  }
375
 
376
  end( $all_jobs_out );
377
- $next_id = key( $all_jobs_out ) + 1;
378
  $all_jobs_out[ $next_id ] = $settings;
379
 
380
- self::save_export_settings_collection( $mode_out, $all_jobs_out );
 
381
  return $next_id;
382
  }
383
 
@@ -395,7 +420,7 @@ class WC_Order_Export_Manage {
395
  self::EXPORT_PROFILE,
396
  self::EXPORT_ORDER_ACTION,
397
  );
398
- if( isset( $data[ self::EXPORT_NOW ] ) ) { // import ALL
399
  foreach ( $allowed_options as $key ) {
400
  if ( isset( $data[ $key ] ) ) {
401
  $setting_name = self::get_settings_name_for_mode( $key );
@@ -404,28 +429,28 @@ class WC_Order_Export_Manage {
404
  $data[ $key ] = self::edit_import_data( $data[ $key ] );
405
  } else {
406
  foreach ( $data[ $key ] as $index => $import_single_data ) {
407
- $data[$key][$index] = self::edit_import_data( $import_single_data );
408
  }
409
  }
410
 
411
- update_option( $setting_name, $data[ $key ] );
412
  }
413
  }
414
- }
415
- elseif( isset( $data["mode"] ) AND in_array( $data["mode"], $allowed_options ) ) { // OR import single ?
416
- $setting_name = self::get_settings_name_for_mode( $data["mode"] );
417
- if( $setting_name == self::settings_name_now ) {
418
- update_option( $setting_name, self::edit_import_data( $data ) ); // rewrite
419
- } else { // append!
420
- $items = get_option( $setting_name, array() );
421
-
422
- if( empty($items) )
423
- $items[ 1 ] = self::edit_import_data( $data );
424
- else
425
- $items[] = self::edit_import_data( $data );
426
-
427
- update_option( $setting_name, $items );
428
  }
 
 
 
429
  }// if modes
430
  }
431
 
13
  const EXPORT_PROFILE = 'profiles';
14
  const EXPORT_SCHEDULE = 'cron';
15
  const EXPORT_ORDER_ACTION = 'order-action';
16
+
17
  public static $edit_existing_job = false;
18
+
19
  static function get_days() {
20
  return array(
21
+ 'Sun' => __( 'Sun', 'woo-order-export-lite' ),
22
+ 'Mon' => __( 'Mon', 'woo-order-export-lite' ),
23
+ 'Tue' => __( 'Tue', 'woo-order-export-lite' ),
24
+ 'Wed' => __( 'Wed', 'woo-order-export-lite' ),
25
+ 'Thu' => __( 'Thu', 'woo-order-export-lite' ),
26
+ 'Fri' => __( 'Fri', 'woo-order-export-lite' ),
27
+ 'Sat' => __( 'Sat', 'woo-order-export-lite' ),
28
  );
29
  }
30
 
39
  } elseif ( $mode == self::EXPORT_ORDER_ACTION ) {
40
  $name = self::settings_name_actions;
41
  }
42
+
43
  return $name;
44
  }
45
+
46
  static function remove_settings() {
47
  $options = array(
48
  self::settings_name_now,
49
  self::settings_name_cron,
50
  self::settings_name_profiles,
51
  self::settings_name_actions,
52
+ );
53
+
54
+ foreach ( $options as $option ) {
55
  delete_option( $option );
56
+ }
57
  }
58
 
59
  // arrays
60
  static function get_export_settings_collection( $mode ) {
61
  $name = self::get_settings_name_for_mode( $mode );
62
+
63
  return get_option( $name, array() );
64
  }
65
+
66
  static function save_export_settings_collection( $mode, $jobs ) {
67
  $name = self::get_settings_name_for_mode( $mode );
68
+
69
+ return update_option( $name, $jobs, false );
70
  }
71
 
72
  static function make_new_settings( $in ) {
73
  $new_settings = $in['settings'];
74
+
75
  // use old PHP code if no permissions, just to stop trcky persons ;)
76
+ if ( ! WC_Order_Export_Admin::user_can_add_custom_php() ) {
77
+ unset( $new_settings['custom_php_code'] );
78
  }
79
 
80
  // UI don't pass empty multiselects
91
  'shipping_methods',
92
  'user_roles',
93
  'user_names',
94
+ 'user_custom_fields',
95
  'coupons',
96
+ 'billing_locations',
97
  'payment_methods',
98
  'product_attributes',
99
+ 'product_itemmeta',
100
  'product_taxonomies',
101
  'item_names',
102
  'item_metadata',
107
  }
108
  }
109
 
110
+ $settings = self::get( $in['mode'], $in['id'] );
111
+ $settings['id'] = $in['id'];
112
  // setup new values for same keys
113
  foreach ( $new_settings as $key => $val ) {
114
  $settings[ $key ] = $val;
117
  $sections = array(
118
  'orders' => 'order_fields',
119
  'products' => 'order_product_fields',
120
+ 'coupons' => 'order_coupon_fields',
121
  );
122
  foreach ( $sections as $section => $fieldset ) {
123
  $new_order_fields = array();
128
  $opts = array(
129
  "checked" => $in_sec['exported'][ $field ],
130
  "colname" => $colname,
131
+ "label" => $in_sec['label'][ $field ],
132
  );
133
  // for products & coupons
134
  if ( isset( $in_sec['repeat'][ $field ] ) ) {
158
  static function get( $mode, $id = false ) {
159
  $all_jobs = self::get_export_settings_collection( $mode );
160
 
161
+ if ( $mode == self::EXPORT_NOW ) { // one job
162
  return self::apply_defaults( $mode, $all_jobs );
163
  } elseif ( $id === false ) {
164
+ if ( empty( $all_jobs ) OR ! is_array( $all_jobs ) ) {
165
  return array();
166
+ }
167
+
168
+ return array_map( function ( $item ) use ( $mode ) {
169
  return WC_Order_Export_Manage::apply_defaults( $mode, $item );
170
  }, $all_jobs );
171
  }
172
 
173
  $settings = isset( $all_jobs[ $id ] ) ? $all_jobs[ $id ] : array();
174
+
175
  return self::apply_defaults( $mode, $settings );
176
  }
177
 
178
  static function apply_defaults( $mode, $settings ) {
179
+
180
+ $settings = apply_filters( "woe_before_apply_default_settings", $settings, $mode );
181
+
182
  $defaults = array(
183
  'mode' => $mode,
184
  'title' => '',
196
  'item_metadata' => array(),
197
  'user_roles' => array(),
198
  'user_names' => array(),
199
+ 'user_custom_fields' => array(),
200
+ 'billing_locations' => array(),
201
  'payment_methods' => array(),
202
  'any_coupon_used' => 0,
203
  'coupons' => array(),
208
  'product_taxonomies' => array(),
209
  'product_custom_fields' => array(),
210
  'product_attributes' => array(),
211
+ 'product_itemmeta' => array(),
212
  'format' => 'XLS',
213
+ 'format_xls_use_xls_format' => 0,
214
+ 'format_xls_sheet_name' => __( 'Orders', 'woo-order-export-lite' ),
215
  'format_xls_display_column_names' => 1,
216
+ 'format_xls_auto_width' => 1,
217
  'format_xls_populate_other_columns_product_rows' => 1,
218
+ 'format_xls_direction_rtl' => 0,
219
  'format_csv_enclosure' => '"',
220
  'format_csv_delimiter' => ',',
221
  'format_csv_linebreak' => '\r\n',
239
  'format_xml_self_closing_tags' => 1,
240
  'all_products_from_order' => 1,
241
  'skip_refunded_items' => 1,
242
+ 'skip_suborders' => 0,
243
+ 'export_refunds' => 0,
244
+ 'date_format' => 'Y-m-d',
245
+ 'time_format' => 'H:i',
246
  'sort_direction' => 'DESC',
247
  'sort' => 'order_id',
248
  'format_number_fields' => 0,
251
  'strip_tags_product_fields' => 0,
252
  'cleanup_phone' => 0,
253
  'enable_debug' => 0,
254
+ 'format_json_start_tag' => '[',
255
+ 'format_json_end_tag' => ']',
256
  'custom_php' => 0,
257
  'custom_php_code' => '',
258
  'mark_exported_orders' => 0,
259
  'export_unmarked_orders' => 0,
260
+
261
+ 'summary_report_by_products' => 0,
262
  );
263
 
264
  if ( ! isset( $settings['format'] ) ) {
272
  if ( ! isset( $settings['order_fields'] ) ) {
273
  $settings['order_fields'] = array();
274
  }
275
+ self::merge_settings_and_default( $settings['order_fields'],
276
+ WC_Order_Export_Data_Extractor_UI::get_order_fields( $settings['format'] ) );
277
 
278
  if ( ! isset( $settings['order_product_fields'] ) ) {
279
  $settings['order_product_fields'] = array();
280
  }
281
+ self::merge_settings_and_default( $settings['order_product_fields'],
282
+ WC_Order_Export_Data_Extractor_UI::get_order_product_fields( $settings['format'] ) );
283
 
284
  if ( ! isset( $settings['order_coupon_fields'] ) ) {
285
  $settings['order_coupon_fields'] = array();
286
  }
287
+ self::merge_settings_and_default( $settings['order_coupon_fields'],
288
+ WC_Order_Export_Data_Extractor_UI::get_order_coupon_fields( $settings['format'] ) );
289
+
290
  return array_merge( $defaults, $settings );
291
  }
292
 
293
+ static function merge_settings_and_default( &$opt, $defaults ) {
294
+ foreach ( $defaults as $k => $v ) {
295
+ if ( isset( $opt[ $k ] ) ) {
296
  //set default attribute OR add to option
297
+ if ( isset( $v['default'] ) ) {
298
+ $opt[ $k ]['default'] = $v['default'];
299
+ }
300
  //set default format OR add to option
301
+ if ( isset( $v['format'] ) ) {
302
+ $opt[ $k ]['format'] = $v['format'];
303
+ }
304
  // overwrite labels for localization
305
+ $opt[ $k ]['label'] = $v['label'];
306
  } else {
307
+ if ( self::$edit_existing_job AND $v['checked'] == "1" ) {
308
  $v['checked'] = "0";
309
+ }
310
+ $opt[ $k ] = $v;
311
+ }
312
  }
313
  }
314
 
315
  static function save_export_settings( $mode, $id, $options ) {
316
+ $all_jobs = self::get_export_settings_collection( $mode );
317
  if ( $mode == self::EXPORT_NOW ) {
318
  $all_jobs = $options;// just replace
319
  } elseif ( $mode == self::EXPORT_SCHEDULE ) {
320
  if ( $id ) {
321
+ $options['schedule']['last_run'] = isset( $all_jobs[ $id ] ) ? $all_jobs[ $id ]['schedule']['last_run'] : current_time( "timestamp",
322
+ 0 );
323
+ $options['schedule']['next_run'] = WC_Order_Export_Cron::next_event_timestamp_for_schedule( $options['schedule'],
324
+ $id );
325
  $all_jobs[ $id ] = $options;
326
  } else {
327
+ $options['schedule']['last_run'] = current_time( "timestamp", 0 );
328
  $options['schedule']['next_run'] = WC_Order_Export_Cron::next_event_timestamp_for_schedule( $options['schedule'] );
329
  $all_jobs[] = $options; // new job
330
+ end( $all_jobs );
331
+ $id = key( $all_jobs );
332
  }
333
  } elseif ( $mode == self::EXPORT_PROFILE OR $mode == self::EXPORT_ORDER_ACTION ) {
334
  if ( $id ) {
340
  }
341
  }
342
 
343
+ self::save_export_settings_collection( $mode, $all_jobs );
344
 
345
+ if ( $mode == self::EXPORT_SCHEDULE ) {
346
  WC_Order_Export_Cron::install_job();
347
+ }
348
+
349
  return $id;
350
  }
351
 
353
  return self::advanced_clone_export_settings( $id, $mode, $mode );
354
  }
355
 
356
+ static function advanced_clone_export_settings(
357
+ $id,
358
+ $mode_in = self::EXPORT_SCHEDULE,
359
+ $mode_out = self::EXPORT_SCHEDULE
360
+ ) {
361
  $all_jobs_in = self::get_export_settings_collection( $mode_in );
362
  //new settings
363
+ $settings = $all_jobs_in[ $id ];
364
+ $settings['mode'] = $mode_out;
365
 
366
  if ( $mode_in !== $mode_out ) {
367
  $all_jobs_out = self::get_export_settings_collection( $mode_out );
368
+ } else {
369
+ $mode_out = $mode_in;
370
+ $all_jobs_out = $all_jobs_in;
 
371
  $settings['title'] .= " [cloned]"; //add note
372
  }
373
 
374
+ if ( $mode_in === self::EXPORT_PROFILE && $mode_out === self::EXPORT_SCHEDULE ) {
375
  if ( ! isset( $settings['destination'] ) ) {
376
  $settings['destination'] = array(
377
  'type' => 'folder',
389
 
390
  if ( ! isset( $settings['schedule'] ) ) {
391
  $settings['schedule'] = array(
392
+ 'type' => 'schedule-1',
393
+ 'run_at' => '00:00',
394
  );
395
  }
396
 
398
  }
399
 
400
  end( $all_jobs_out );
401
+ $next_id = key( $all_jobs_out ) + 1;
402
  $all_jobs_out[ $next_id ] = $settings;
403
 
404
+ self::save_export_settings_collection( $mode_out, $all_jobs_out );
405
+
406
  return $next_id;
407
  }
408
 
420
  self::EXPORT_PROFILE,
421
  self::EXPORT_ORDER_ACTION,
422
  );
423
+ if ( isset( $data[ self::EXPORT_NOW ] ) ) { // import ALL
424
  foreach ( $allowed_options as $key ) {
425
  if ( isset( $data[ $key ] ) ) {
426
  $setting_name = self::get_settings_name_for_mode( $key );
429
  $data[ $key ] = self::edit_import_data( $data[ $key ] );
430
  } else {
431
  foreach ( $data[ $key ] as $index => $import_single_data ) {
432
+ $data[ $key ][ $index ] = self::edit_import_data( $import_single_data );
433
  }
434
  }
435
 
436
+ update_option( $setting_name, $data[ $key ], false );
437
  }
438
  }
439
+ } elseif ( isset( $data["mode"] ) AND in_array( $data["mode"], $allowed_options ) ) { // OR import single ?
440
+ $setting_name = self::get_settings_name_for_mode( $data["mode"] );
441
+ if ( $setting_name == self::settings_name_now ) {
442
+ update_option( $setting_name, self::edit_import_data( $data ), false ); // rewrite
443
+ } else { // append!
444
+ $items = get_option( $setting_name, array() );
445
+
446
+ if ( empty( $items ) ) {
447
+ $items[1] = self::edit_import_data( $data );
448
+ } else {
449
+ $items[] = self::edit_import_data( $data );
 
 
 
450
  }
451
+
452
+ update_option( $setting_name, $items, false );
453
+ }
454
  }// if modes
455
  }
456
 
classes/class-wc-order-export-admin.php CHANGED
@@ -30,65 +30,70 @@ class WC_Order_Export_Admin {
30
 
31
  //Add custom bulk export action in Woocomerce orders Table, modified for WP 4.7
32
  add_filter( 'bulk_actions-edit-shop_order', array( $this, 'export_orders_bulk_action' ) );
33
- add_filter( 'handle_bulk_actions-edit-shop_order', array( $this, 'export_orders_bulk_action_process' ), 10, 3 );
34
- add_action( 'admin_notices', array( $this,'export_orders_bulk_action_notices'));
 
35
  //do once
36
- if( !get_option( $this->activation_notice_option ) )
37
- add_action('admin_notices', array( $this,'display_plugin_activated_message'));
38
-
 
39
  //extra links in >Plugins
40
- add_filter( 'plugin_action_links_' . WOE_PLUGIN_BASENAME, array($this,'add_action_links') );
41
-
42
  // Add 'Export Status' orders page column header
43
  add_filter( 'manage_edit-shop_order_columns', array( $this, 'add_order_status_column_header' ), 20 );
44
 
45
  // Add 'Export Status' orders page column content
46
  add_action( 'manage_shop_order_posts_custom_column', array( $this, 'add_order_status_column_content' ) );
47
 
48
- if ( isset( $_GET[ 'post_type' ] ) && $_GET[ 'post_type' ] == 'shop_order' ) {
49
  add_action( 'admin_print_styles', array( $this, 'add_order_status_column_style' ) );
50
  }
51
  }
52
 
53
- $this->settings = self::load_main_settings();
54
 
55
  //Pro active ?
56
- if( self::is_full_version() ) {
57
- new WC_Order_Export_Zapier_Engine( $this->settings );
58
  add_action( 'plugins_loaded', array( $this, 'load_textdomain' ) );
59
- add_filter( 'cron_schedules', array( 'WC_Order_Export_Cron', 'create_custom_schedules' ), 10, 1 );
60
  add_action( 'wc_export_cron_global', array( 'WC_Order_Export_Cron', 'wc_export_cron_global_f' ) );
61
 
62
  //for direct calls
63
  add_action( 'wp_ajax_order_exporter_run', array( $this, 'ajax_gate_guest' ) );
64
  add_action( 'wp_ajax_nopriv_order_exporter_run', array( $this, 'ajax_gate_guest' ) );
65
- $this->methods_allowed_for_guests = array('run_cron_jobs','run_one_job','run_one_scheduled_job');
66
 
67
  // order actions
68
- add_action( 'woocommerce_order_status_changed', array( $this, 'wc_order_status_changed' ), 10, 3);
69
  // activate CRON hook if it was removed
70
- add_action( 'wp_loaded', function() {
71
  $all_jobs = WC_Order_Export_Manage::get_export_settings_collection( WC_Order_Export_Manage::EXPORT_SCHEDULE );
72
- if ( $all_jobs )
73
  WC_Order_Export_Cron::install_job();
 
74
  } );
75
  }
76
 
77
  }
78
 
79
  public function add_order_status_column_header( $columns ) {
80
-
81
- if( ! $this->settings['show_export_status_column'] )
82
  return $columns;
83
-
 
84
  $new_columns = array();
85
  foreach ( $columns as $column_name => $column_info ) {
86
- if ( 'order_actions' === $column_name OR 'wc_actions' === $column_name) { // Woocommerce uses wc_actions since 3.3.0
87
- $label = __( 'Export Status', 'woo-order-export-lite' );
88
  $new_columns['woe_export_status'] = $label;
89
  }
90
  $new_columns[ $column_name ] = $column_info;
91
  }
 
92
  return $new_columns;
93
  }
94
 
@@ -102,7 +107,7 @@ class WC_Order_Export_Admin {
102
  $is_exported = true;
103
  }
104
 
105
- if( $is_exported ) {
106
  echo '<span class="dashicons dashicons-yes" style="color: #2ea2cc"></span>';
107
  } else {
108
  echo '<span class="dashicons dashicons-minus"></span>';
@@ -117,37 +122,43 @@ class WC_Order_Export_Admin {
117
 
118
  public function install() {
119
  //wp_clear_scheduled_hook( "wc_export_cron_global" ); //debug
120
- if( self::is_full_version() )
121
  WC_Order_Export_Cron::install_job();
 
122
  }
123
 
124
  public function display_plugin_activated_message() {
125
  ?>
126
- <div class="notice notice-success is-dismissible">
127
- <p><?php _e( 'Advanced Order Export For WooCommerce is available <a href="admin.php?page=wc-order-export">on this page</a>.', 'woo-order-export-lite' ); ?></p>
128
- </div>
 
129
  <?php
130
- update_option( $this->activation_notice_option, true );
131
  }
132
 
133
  public function add_action_links( $links ) {
134
- $mylinks = array(
135
- '<a href="admin.php?page=wc-order-export">'. __('Settings', 'woo-order-export-lite'). '</a>',
136
- '<a href="https://algolplus.com/plugins/documentation-order-export-woocommerce/" target="_blank">'. __('Docs', 'woo-order-export-lite'). '</a>',
137
- '<a href="https://algolplus.freshdesk.com" target="_blank">'. __('Support', 'woo-order-export-lite'). '</a>'
 
 
138
  );
139
- return array_merge( $mylinks, $links);
 
140
  }
141
 
142
  public function deactivate() {
143
  wp_clear_scheduled_hook( "wc_export_cron_global" );
144
  delete_option( $this->activation_notice_option );
145
 
146
- if( self::is_full_version() ) {
147
  //don't do it! updater call this function!
148
  // WC_Order_Export_EDD::getInstance()->edd_woe_force_deactivate_license();
149
  }
150
  }
 
151
  public static function uninstall() {
152
  //delete_option( self::settings_name_common );
153
  //WC_Order_Export_Manage::remove_settings();
@@ -156,62 +167,74 @@ class WC_Order_Export_Admin {
156
  static function load_main_settings() {
157
  return array_merge(
158
  array(
159
- 'cron_tasks_active' => '1',
160
- 'show_export_status_column' => '1',
161
- 'show_export_actions_in_bulk' => '1',
162
- 'show_export_in_status_change_job' => '0',
163
- 'ajax_orders_per_step' => '30',
164
- 'limit_button_test' => '1',
165
- 'cron_key' => '1234',
166
- 'ipn_url' => '',
167
- 'zapier_api_key' => '12345678',
168
- 'zapier_file_timeout' => 60,
 
 
169
  ),
170
  get_option( self::settings_name_common, array() )
171
  );
172
  }
 
173
  static function save_main_settings() {
174
  // update main settings here!
175
- $settings = filter_input_array(INPUT_POST, array(
176
- 'cron_tasks_active' => FILTER_VALIDATE_BOOLEAN,
177
- 'show_export_status_column' => FILTER_VALIDATE_BOOLEAN,
178
- 'show_export_actions_in_bulk' => FILTER_VALIDATE_BOOLEAN,
 
179
  'show_export_in_status_change_job' => FILTER_VALIDATE_BOOLEAN,
180
- 'ajax_orders_per_step' => FILTER_VALIDATE_INT,
181
- 'limit_button_test' => FILTER_SANITIZE_STRING,
182
- 'cron_key' => FILTER_SANITIZE_STRING,
183
- 'ipn_url' => FILTER_SANITIZE_STRING,
184
- 'zapier_api_key' => FILTER_SANITIZE_STRING,
185
- 'zapier_file_timeout' => FILTER_SANITIZE_NUMBER_INT,
 
186
  ) );
187
- update_option( self::settings_name_common, $settings );
188
 
189
  if ( isset( $settings['ipn_url'] ) ) {
190
- update_option( WOE_IPN_URL_OPTION_KEY, $settings['ipn_url'] );
191
  }
192
  }
193
 
194
 
195
  function load_textdomain() {
196
  $locale = apply_filters( 'plugin_locale', get_locale(), 'woo-order-export-lite' );
197
- load_textdomain( 'woo-order-export-lite', WP_LANG_DIR . '/woocommerce-order-export/woocommerce-order-export-' . $locale . '.mo' );
 
198
 
199
  load_plugin_textdomain( 'woo-order-export-lite', false,
200
  plugin_basename( dirname( dirname( __FILE__ ) ) ) . '/i18n/languages' );
201
  }
202
 
203
  public function add_menu() {
204
- if( apply_filters('woe_current_user_can_export', true) ) {
205
- if ( current_user_can( 'manage_woocommerce' ) )
206
- add_submenu_page( 'woocommerce', __( 'Export Orders', 'woo-order-export-lite' ),__( 'Export Orders', 'woo-order-export-lite' ), 'view_woocommerce_reports', 'wc-order-export', array( $this, 'render_menu' ) );
207
- else // add after Sales Report!
208
- add_menu_page( __( 'Export Orders', 'woo-order-export-lite' ),__( 'Export Orders', 'woo-order-export-lite' ), 'view_woocommerce_reports', 'wc-order-export', array( $this, 'render_menu' ) , null, '55.7');
 
 
 
 
 
 
209
  }
210
  }
211
 
212
  public function render_menu() {
213
  $this->render( 'main', array( 'WC_Order_Export' => $this, 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) );
214
- $active_tab = isset( $_REQUEST['tab'] ) ? $_REQUEST['tab'] : 'export';
215
  if ( method_exists( $this, 'render_tab_' . $active_tab ) ) {
216
  $this->{'render_tab_' . $active_tab}();
217
  }
@@ -221,40 +244,41 @@ class WC_Order_Export_Admin {
221
  $this->render( 'tab/export', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ), 'WC_Order_Export' => $this ) );
222
  }
223
 
224
- public function render_tab_tools() {
225
  $this->render( 'tab/tools', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ), 'WC_Order_Export' => $this ) );
226
  }
227
 
228
- public function render_tab_settings() {
229
- $this->render( 'tab/settings', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ), 'settings' => $this->settings ) );
 
230
  }
231
 
232
  public function render_tab_license() {
233
  $this->render( 'tab/license', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ), 'WC_Order_Export' => $this ) );
234
  }
235
 
236
- public function render_tab_help() {
237
  $this->render( 'tab/help', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ), 'WC_Order_Export' => $this ) );
238
  }
239
 
240
  public function render_tab_order_actions() {
241
  $wc_oe = isset( $_REQUEST['wc_oe'] ) ? $_REQUEST['wc_oe'] : '';
242
  $ajaxurl = admin_url( 'admin-ajax.php' );
243
- $mode = WC_Order_Export_Manage::EXPORT_ORDER_ACTION;
244
  $all_items = WC_Order_Export_Manage::get_export_settings_collection( $mode );
245
  $show = array(
246
- 'date_filter' => $this->settings['show_export_in_status_change_job'],
247
- 'export_button' => $this->settings['show_export_in_status_change_job'],
248
  'export_button_plain' => $this->settings['show_export_in_status_change_job'],
249
- 'preview_actions' => false,
250
- 'destinations' => true,
251
- 'schedule' => false,
252
- 'sort_orders' => false,
253
- 'order_filters' => true,
254
- 'product_filters' => true,
255
- 'customer_filters' => true,
256
- 'billing_filters' => true,
257
- 'shipping_filters' => true,
258
  );
259
  switch ( $wc_oe ) {
260
  case 'add_action':
@@ -265,15 +289,17 @@ class WC_Order_Export_Admin {
265
  'id' => $next_id,
266
  'WC_Order_Export' => $this,
267
  'ajaxurl' => $ajaxurl,
268
- 'show' => $show
269
  ) );
 
270
  return;
271
  case 'edit_action':
272
- if( !isset( $_REQUEST[ 'action_id' ] ) )
273
  break;
274
- $item_id = $_REQUEST[ 'action_id' ];
 
275
  WC_Order_Export_Manage::$edit_existing_job = true;
276
- $clone = isset( $_REQUEST[ 'clone' ] ) ? $_REQUEST[ 'clone' ] : '';
277
  if ( $clone ) {
278
  $item_id = WC_Order_Export_Manage::clone_export_settings( $mode, $item_id );
279
  }
@@ -282,30 +308,34 @@ class WC_Order_Export_Admin {
282
  'id' => $item_id,
283
  'WC_Order_Export' => $this,
284
  'ajaxurl' => $ajaxurl,
285
- 'show' => $show
286
  ) );
 
287
  return;
288
  case 'delete':
289
- if( !isset( $_REQUEST[ 'action_id' ] ) )
290
  break;
291
- $item_id = $_REQUEST[ 'action_id' ];
 
292
  unset( $all_items[ $item_id ] );
293
  WC_Order_Export_Manage::save_export_settings_collection( $mode, $all_items );
294
  break;
295
  case 'change_status':
296
- if( !isset( $_REQUEST[ 'action_id' ] ) )
297
  break;
298
- $item_id = $_REQUEST[ 'action_id' ];
 
299
  $all_items[ $item_id ]['active'] = $_REQUEST['status'];
300
  WC_Order_Export_Manage::save_export_settings_collection( $mode, $all_items );
301
  $url = remove_query_arg( array( 'wc_oe', 'action_id', 'status' ) );
302
  wp_redirect( $url );
303
  break;
304
  case 'change_statuses':
305
- if( !isset( $_REQUEST['chosen_order_actions'] ) AND !isset( $_REQUEST['doaction'] ) AND -1 == $_REQUEST['doaction'] )
306
  break;
307
- $chosen_order_actions = explode(',' , $_REQUEST['chosen_order_actions'] );
308
- $doaction = $_REQUEST['doaction'];
 
309
 
310
  foreach ( $chosen_order_actions as $order_action_id ) {
311
  if ( 'activate' == $doaction ) {
@@ -321,20 +351,21 @@ class WC_Order_Export_Admin {
321
  wp_redirect( $url );
322
  break;
323
  }
324
- $this->render( 'tab/order-actions', array( 'ajaxurl' => $ajaxurl, 'WC_Order_Export' => $this, 'tab' => 'order_actions' ) );
 
325
  }
326
 
327
  public function render_tab_schedules() {
328
  $wc_oe = isset( $_REQUEST['wc_oe'] ) ? $_REQUEST['wc_oe'] : '';
329
  $ajaxurl = admin_url( 'admin-ajax.php' );
330
- $mode = WC_Order_Export_Manage::EXPORT_SCHEDULE;
331
  $all_jobs = WC_Order_Export_Manage::get_export_settings_collection( $mode );
332
- $show = array(
333
- 'date_filter' => true,
334
- 'export_button' => true,
335
  'export_button_plain' => true,
336
- 'destinations' => true,
337
- 'schedule' => true,
338
  );
339
  switch ( $wc_oe ) {
340
  case 'add_schedule':
@@ -345,15 +376,17 @@ class WC_Order_Export_Admin {
345
  'id' => $next_id,
346
  'WC_Order_Export' => $this,
347
  'ajaxurl' => $ajaxurl,
348
- 'show' => $show
349
  ) );
 
350
  return;
351
  case 'edit_schedule':
352
- if( !isset( $_REQUEST[ 'schedule_id' ] ) )
353
  break;
354
- $schedule_id = $_REQUEST[ 'schedule_id' ];
 
355
  WC_Order_Export_Manage::$edit_existing_job = true;
356
- $clone = isset( $_REQUEST[ 'clone' ] ) ? $_REQUEST[ 'clone' ] : '';
357
  if ( $clone ) {
358
  $schedule_id = WC_Order_Export_Manage::clone_export_settings( $mode, $schedule_id );
359
  }
@@ -362,40 +395,44 @@ class WC_Order_Export_Admin {
362
  'id' => $schedule_id,
363
  'WC_Order_Export' => $this,
364
  'ajaxurl' => $ajaxurl,
365
- 'show' => $show
366
  ) );
 
367
  return;
368
  case 'delete_schedule':
369
- if( !isset( $_REQUEST[ 'schedule_id' ] ) )
370
  break;
371
- $schedule_id = $_REQUEST[ 'schedule_id' ];
 
372
  unset( $all_jobs[ $schedule_id ] );
373
  WC_Order_Export_Manage::save_export_settings_collection( $mode, $all_jobs );
374
  break;
375
  case 'change_status_schedule':
376
- if( !isset( $_REQUEST[ 'schedule_id' ] ) )
377
  break;
378
- $schedule_id = $_REQUEST[ 'schedule_id' ];
 
379
  $all_jobs[ $schedule_id ]['active'] = $_REQUEST['status'];
380
  WC_Order_Export_Manage::save_export_settings_collection( $mode, $all_jobs );
381
  $url = remove_query_arg( array( 'wc_oe', 'schedule_id', 'status' ) );
382
  wp_redirect( $url );
383
  break;
384
  case 'change_status_schedules':
385
- if( !isset( $_REQUEST['chosen_schedules'] ) AND !isset( $_REQUEST['doaction'] ) AND -1 == $_REQUEST['doaction'] )
386
  break;
387
- $chosen_schedules = explode(',' , $_REQUEST['chosen_schedules'] );
388
- $doaction = $_REQUEST['doaction'];
 
389
 
390
  foreach ( $chosen_schedules as $schedule_id ) {
391
- if ( 'activate' == $doaction ) {
392
- $all_jobs[ $schedule_id ]['active'] = 1;
393
- } elseif ( 'deactivate' == $doaction ) {
394
- $all_jobs[ $schedule_id ]['active'] = 0;
395
- } elseif ( 'delete' == $doaction ) {
396
- unset( $all_jobs[ $schedule_id ] );
397
- }
398
- }
399
  WC_Order_Export_Manage::save_export_settings_collection( $mode, $all_jobs );
400
  $url = remove_query_arg( array( 'wc_oe', 'chosen_schedules', 'doaction' ) );
401
  wp_redirect( $url );
@@ -405,16 +442,16 @@ class WC_Order_Export_Admin {
405
  }
406
 
407
  public function render_tab_profiles() {
408
- $wc_oe = isset( $_REQUEST['wc_oe'] ) ? $_REQUEST['wc_oe'] : '';
409
- $ajaxurl = admin_url( 'admin-ajax.php' );
410
- $mode = WC_Order_Export_Manage::EXPORT_PROFILE;
411
  $all_items = WC_Order_Export_Manage::get_export_settings_collection( $mode );
412
- $show = array(
413
- 'date_filter' => true,
414
- 'export_button' => true,
415
  'export_button_plain' => true,
416
- 'destinations' => true,
417
- 'schedule' => false,
418
  );
419
  switch ( $wc_oe ) {
420
  case 'add_profile':
@@ -425,15 +462,17 @@ class WC_Order_Export_Admin {
425
  'id' => $next_id,
426
  'WC_Order_Export' => $this,
427
  'ajaxurl' => $ajaxurl,
428
- 'show' => $show
429
  ) );
 
430
  return;
431
  case 'edit_profile':
432
- if( !isset( $_REQUEST['profile_id'] ) )
433
  break;
434
- $profile_id = $_REQUEST['profile_id'];
 
435
  WC_Order_Export_Manage::$edit_existing_job = true;
436
- $clone = isset( $_REQUEST[ 'clone' ] ) ? $_REQUEST[ 'clone' ] : '';
437
  if ( $clone ) {
438
  $profile_id = WC_Order_Export_Manage::clone_export_settings( $mode, $profile_id );
439
  }
@@ -442,49 +481,54 @@ class WC_Order_Export_Admin {
442
  'id' => $profile_id,
443
  'WC_Order_Export' => $this,
444
  'ajaxurl' => $ajaxurl,
445
- 'show' => $show
446
  ) );
 
447
  return;
448
  case 'copy_profile_to_scheduled':
449
  $profile_id = isset( $_REQUEST['profile_id'] ) ? $_REQUEST['profile_id'] : '';
450
- $schedule_id = WC_Order_Export_Manage::advanced_clone_export_settings( $profile_id, $mode, WC_Order_Export_Manage::EXPORT_SCHEDULE );
451
- $url = remove_query_arg( 'profile_id' );
452
- $url = add_query_arg( 'tab', 'schedules', $url );
453
- $url = add_query_arg( 'wc_oe', 'edit_schedule', $url );
454
- $url = add_query_arg( 'schedule_id', $schedule_id, $url );
 
455
  wp_redirect( $url );
456
  break;
457
  case 'copy_profile_to_actions':
458
  $profile_id = isset( $_REQUEST['profile_id'] ) ? $_REQUEST['profile_id'] : '';
459
- $schedule_id = WC_Order_Export_Manage::advanced_clone_export_settings( $profile_id, $mode, WC_Order_Export_Manage::EXPORT_ORDER_ACTION );
460
- $url = remove_query_arg( 'profile_id' );
461
- $url = add_query_arg( 'tab', 'order_actions', $url );
462
- $url = add_query_arg( 'wc_oe', 'edit_action', $url );
463
- $url = add_query_arg( 'action_id', $schedule_id, $url );
 
464
  wp_redirect( $url );
465
  break;
466
  case 'delete_profile':
467
- if( !isset( $_REQUEST['profile_id'] ) )
468
  break;
 
469
  $profile_id = $_REQUEST['profile_id'];
470
  unset( $all_items[ $profile_id ] );
471
  WC_Order_Export_Manage::save_export_settings_collection( $mode, $all_items );
472
  break;
473
  case 'change_profile_statuses':
474
- if( !isset( $_REQUEST['chosen_profiles'] ) AND !isset( $_REQUEST['doaction'] ) AND -1 == $_REQUEST['doaction'] )
475
  break;
476
- $chosen_profiles = explode(',' , $_REQUEST['chosen_profiles'] );
477
- $doaction = $_REQUEST['doaction'];
 
478
 
479
  foreach ( $chosen_profiles as $profile_id ) {
480
- if ( 'activate' == $doaction ) {
481
- $all_items[ $profile_id ][ 'use_as_bulk' ] = 'on';
482
- } elseif ( 'deactivate' == $doaction ) {
483
- unset( $all_items[ $profile_id ][ 'use_as_bulk' ] );
484
- } elseif ( 'delete' == $doaction ) {
485
- unset( $all_items[ $profile_id ] );
486
- }
487
- }
488
  WC_Order_Export_Manage::save_export_settings_collection( $mode, $all_items );
489
  $url = remove_query_arg( array( 'wc_oe', 'chosen_profiles', 'doaction' ) );
490
  wp_redirect( $url );
@@ -493,12 +537,12 @@ class WC_Order_Export_Admin {
493
 
494
  //code to copy default settings as profile
495
  $profiles = WC_Order_Export_Manage::get_export_settings_collection( $mode );
496
- $free_job = WC_Order_Export_Manage::get_export_settings_collection( WC_Order_Export_Manage::EXPORT_NOW);
497
- if(empty( $profiles ) AND !empty( $free_job ) ) {
498
- $free_job['title'] = __('Copied from "Export now"', 'woo-order-export-lite' );
499
- $free_job['mode'] = $mode;
500
- $profiles[1] = $free_job;
501
- update_option( WC_Order_Export_Manage::settings_name_profiles, $profiles);
502
  }
503
 
504
  $this->render( 'tab/profiles', array( 'ajaxurl' => $ajaxurl, 'WC_Order_Export' => $this ) );
@@ -511,20 +555,23 @@ class WC_Order_Export_Admin {
511
  wp_enqueue_style( 'jquery-style',
512
  '//ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/smoothness/jquery-ui.css' );
513
  $this->enqueue_select2_scripts();
514
-
515
  wp_enqueue_script( 'export', $this->url_plugin . 'assets/js/export.js', array(), WOE_VERSION );
516
- wp_enqueue_script( 'serializejson', $this->url_plugin . 'assets/js/jquery.serializejson.js', array('jquery'), WOE_VERSION );
 
517
  wp_enqueue_style( 'export', $this->url_plugin . 'assets/css/export.css', array(), WOE_VERSION );
518
  wp_enqueue_style( 'woocommerce_admin_styles', WC()->plugin_url() . '/assets/css/admin.css', array() );
519
 
520
- $_REQUEST['tab'] = isset( $_REQUEST['tab'] ) ? $_REQUEST['tab'] : 'export';
521
- if ( isset( $_REQUEST['wc_oe'] ) AND ( strpos($_REQUEST['wc_oe'], 'add_') === 0 OR strpos($_REQUEST['wc_oe'], 'edit_') === 0 ) OR $_REQUEST['tab'] == 'export') {
522
- wp_enqueue_script( 'settings-form', $this->url_plugin . 'assets/js/settings-form.js', array(), WOE_VERSION );
 
 
523
 
524
  $localize_settings_form = array(
525
- 'set_up_fields_to_export' => __( 'Set up fields to export', 'woo-order-export-lite' ),
526
- 'js_tpl_popup' => __( 'Add %s as %s columns %s as rows', 'woo-order-export-lite' )
527
- );
528
  wp_localize_script( 'settings-form', 'localize_settings_form', $localize_settings_form );
529
 
530
 
@@ -554,7 +601,7 @@ class WC_Order_Export_Admin {
554
  'object_formats' => array( 'XML', 'JSON' ),
555
  'xml_formats' => array( 'XML' ),
556
 
557
- 'day_names' => WC_Order_Export_Manage::get_days(),
558
 
559
  );
560
 
@@ -564,17 +611,19 @@ class WC_Order_Export_Admin {
564
 
565
  // Localize the script with new data
566
  $translation_array = array(
567
- 'empty_column_name' => __( 'empty column name', 'woo-order-export-lite' ),
568
- 'empty_meta_key' => __( 'empty meta key', 'woo-order-export-lite' ),
569
- 'empty_meta_key_and_taxonomy' => __( 'select product field or item field or taxonomy', 'woo-order-export-lite' ),
570
- 'empty_value' => __( 'empty value', 'woo-order-export-lite' ),
571
- 'empty_title' => __( 'title is empty', 'woo-order-export-lite' ),
572
- 'wrong_date_range' => __( 'Date From is greater than Date To', 'woo-order-export-lite' ),
573
- 'no_fields' => __( 'Please, set up fields to export', 'woo-order-export-lite' ),
574
- 'no_results' => __( 'Nothing to export. Please, adjust your filters', 'woo-order-export-lite' ),
575
- 'empty' => __( 'empty', 'woo-order-export-lite' ),
 
 
576
  );
577
- wp_localize_script( 'export', 'export_messages', $translation_array );
578
  }
579
 
580
  private function enqueue_select2_scripts() {
@@ -600,10 +649,11 @@ class WC_Order_Export_Admin {
600
  array(), WC_VERSION );
601
  }
602
 
603
- public function script_loader_src($src, $handle) {
604
  // don't load ANY select2.js / select2.min.js and OUTDATED select2.full.js
605
- if (!preg_match('/\/select2\.full\.js\?ver=[1-3]/', $src) && !preg_match('/\/select2\.min\.js/', $src) && !preg_match('/\/select2\.js/', $src)
606
- && !preg_match('#jquery\.serialize-object\.#', $src) /*this script breaks our json!*/
 
607
  ) {
608
  return $src;
609
  }
@@ -611,8 +661,8 @@ class WC_Order_Export_Admin {
611
 
612
  public function render( $view, $params = array(), $path_views = null ) {
613
  $params = apply_filters( 'woe_render_params', $params );
614
- $params = apply_filters( 'woe_render_params_'.$view, $params );
615
-
616
  extract( $params );
617
  if ( $path_views ) {
618
  include $path_views . "$view.php";
@@ -627,6 +677,7 @@ class WC_Order_Export_Admin {
627
  if ( substr( $name, 0, 1 ) == '[' ) {
628
  $name = substr( $name, 1 );
629
  }
 
630
  return trim( $name );
631
  }, $arr_name );
632
  $arr_name = array_filter( $arr_name );
@@ -634,6 +685,7 @@ class WC_Order_Export_Admin {
634
  foreach ( $arr_name as $value ) {
635
  $arr = isset( $arr[ $value ] ) ? $arr[ $value ] : "";
636
  }
 
637
  return $arr;
638
  }
639
 
@@ -647,36 +699,39 @@ class WC_Order_Export_Admin {
647
  $new_status = is_string( $new_status ) && strpos( $new_status, 'wc-' ) !== 0 ? "wc-{$new_status}" : $new_status;
648
 
649
  $this->changed_order_id = $order_id;
650
- add_filter( 'woe_sql_get_order_ids_where', array($this, "filter_by_changed_order"), 10, 2 );
651
 
652
- $logger = function_exists( "wc_get_logger" ) ? wc_get_logger() : false; //new logger in 3.0+
653
  $logger_context = array( 'source' => 'woo-order-export-lite' );
654
 
655
- foreach ( $all_items as $key=>$item ) {
656
  $item = WC_Order_Export_Manage::get( WC_Order_Export_Manage::EXPORT_ORDER_ACTION, $key );
657
  if ( isset( $item['active'] ) && ! $item['active'] ) {
658
  continue;
659
  }
660
  // use empty for ANY status
661
- if ( ( empty( $item['from_status'] ) OR in_array( $old_status, $item['from_status'] ) )
662
  AND
663
  ( empty( $item['to_status'] ) OR in_array( $new_status, $item['to_status'] ) )
664
- ) {
665
- do_action('woe_order_action_started', $order_id, $item );
666
  $result = WC_Order_Export_Engine::build_files_and_export( $item );
667
- $output = sprintf( __('Status change job #%s for order #%s. Result: %s', 'woo-order-export-lite' ), $key, $order_id, $result);
 
668
  // log if required
669
- if( $logger AND !empty($item['log_results']) )
670
  $logger->info( $output, $logger_context );
 
671
 
672
- do_action('woe_order_action_completed', $order_id, $item , $result );
673
  }
674
  }
675
- remove_filter( 'woe_sql_get_order_ids_where', array($this, "filter_by_changed_order"), 10 );
676
  }
677
 
678
- public function filter_by_changed_order ( $where, $settings ) {
679
  $where[] = "orders.ID = " . $this->changed_order_id;
 
680
  return $where;
681
  }
682
 
@@ -686,11 +741,11 @@ class WC_Order_Export_Admin {
686
  if ( isset( $_REQUEST['method'] ) ) {
687
  $method = $_REQUEST['method'];
688
  if ( method_exists( 'WC_Order_Export_Ajax', $method ) ) {
689
- $_POST = stripslashes_deep($_POST);
690
  // parse json to arrays?
691
- if ( !empty($_POST['json']) ) {
692
- $json = json_decode( $_POST['json'], true );
693
- if( is_array($json) ) {
694
  // add $_POST['settings'],$_POST['orders'],$_POST['products'],$_POST['coupons']
695
  $_POST = $_POST + $json;
696
  unset( $_POST['json'] );
@@ -705,75 +760,81 @@ class WC_Order_Export_Admin {
705
 
706
  //TODO: debug!
707
  public function ajax_gate_guest() {
708
- if ( isset( $_REQUEST['method'] ) AND in_array($_REQUEST['method'],$this->methods_allowed_for_guests) ) {
709
  $method = $_REQUEST['method'];
710
  if ( method_exists( 'WC_Order_Export_Ajax', $method ) ) {
711
- $_POST = array_map('stripslashes_deep', $_POST);
712
- $ajax = new WC_Order_Export_Ajax();
713
  $ajax->validate_url_key();
714
  $ajax->$method();
715
  }
716
  }
717
  die();
718
  }
719
-
720
  //Works since Wordpress 4.7
721
  function export_orders_bulk_action( $actions ) {
722
  $settings = WC_Order_Export_Manage::get( WC_Order_Export_Manage::EXPORT_NOW );
723
  WC_Order_Export_Manage::set_correct_file_ext( $settings );
724
-
725
  // default
726
- if( ! empty($settings['format']) ) {
727
- $actions['woe_export_selected_orders'] = sprintf( __( 'Export as %s', 'woo-order-export-lite' ), $settings['format'] );
 
728
  }
729
-
730
  // mark/unmark
731
- if( $this->settings['show_export_actions_in_bulk'] ) {
732
- $actions['woe_mark_exported'] = __( 'Mark exported', 'woo-order-export-lite' );
733
  $actions['woe_unmark_exported'] = __( 'Unmark exported', 'woo-order-export-lite' );
734
- }
735
 
736
  $all_items = WC_Order_Export_Manage::get_export_settings_collection( WC_Order_Export_Manage::EXPORT_PROFILE );
737
  foreach ( $all_items as $job_id => $job ) {
738
- if ( isset( $job['use_as_bulk'] ) )
739
- $actions['woe_export_selected_orders_profile_' . $job_id] = sprintf( __( "Export as profile '%s'", 'woo-order-export-lite' ), $job['title'] );
 
 
740
  }
741
-
742
  return $actions;
743
  }
744
 
745
- function export_orders_bulk_action_process($redirect_to, $action, $ids) {
746
  switch ( $action ) {
747
  case 'woe_export_selected_orders':
748
- $redirect_to = add_query_arg( array( 'export_bulk_profile' => 'now', 'ids' => join( ',', $ids ) ), $redirect_to );
 
749
  break;
750
  case 'woe_mark_exported':
751
- foreach( $ids as $post_id ) {
752
  update_post_meta( $post_id, 'woe_order_exported', 1 );
753
  }
754
- $redirect_to = add_query_arg( array(
755
  'woe_bulk_mark_exported' => count( $ids ),
756
  'woe_bulk_unmark_exported' => false,
757
  ), $redirect_to );
758
  break;
759
  case 'woe_unmark_exported':
760
- foreach( $ids as $post_id ) {
761
- delete_post_meta( $post_id, 'woe_order_exported');
762
  }
763
  $redirect_to = add_query_arg( array(
764
  'woe_bulk_mark_exported' => false,
765
- 'woe_bulk_unmark_exported' => count( $ids )
766
  ), $redirect_to );
767
  break;
768
  default:
769
  if ( preg_match( '/woe_export_selected_orders_profile_(\d+)/', $action, $matches ) ) {
770
  if ( isset( $matches[1] ) ) {
771
- $id = $matches[1];
772
- $redirect_to = add_query_arg( array( 'export_bulk_profile' => $id, 'ids' => join( ',', $ids ) ), $redirect_to );
 
773
  break;
774
- }
775
  }
776
- //do nothing
 
777
  return $redirect_to;
778
  }
779
 
@@ -785,9 +846,9 @@ class WC_Order_Export_Admin {
785
 
786
  global $post_type, $pagenow;
787
 
788
- if ( $pagenow == 'edit.php' && $post_type == 'shop_order' && isset( $_REQUEST[ 'export_bulk_profile' ] ) ) {
789
- $url = admin_url( 'admin-ajax.php' ) . "?action=order_exporter&method=export_download_bulk_file&export_bulk_profile=" . $_REQUEST[ 'export_bulk_profile' ] . "&ids=" . $_REQUEST[ 'ids' ];
790
- wp_redirect($url);
791
  exit();
792
  /* unused code
793
  //$message = sprintf( __( 'Orders exported. <a href="%s">Download report.</a>' ,'woo-order-export-lite'), $url );
@@ -798,8 +859,8 @@ class WC_Order_Export_Admin {
798
  // must remove this arg from pagination url
799
  add_filter('removable_query_args', array($this, 'fix_table_links') );
800
  */
801
- } else if ( $pagenow == 'edit.php' && $post_type == 'shop_order' && isset( $_REQUEST[ 'woe_bulk_mark_exported' ] ) ) {
802
- $count = intval( $_REQUEST[ 'woe_bulk_mark_exported' ] );
803
  printf(
804
  '<div id="message" class="updated fade">' .
805
  _n( '%s order marked.', '%s orders marked.', $count, 'woo-order-export-lite' )
@@ -807,8 +868,8 @@ class WC_Order_Export_Admin {
807
  $count
808
  );
809
 
810
- } else if ( $pagenow == 'edit.php' && $post_type == 'shop_order' && isset( $_REQUEST[ 'woe_bulk_unmark_exported' ] ) ) {
811
- $count = intval( $_REQUEST[ 'woe_bulk_unmark_exported' ] );
812
  printf(
813
  '<div id="message" class="updated fade">' .
814
  _n( '%s order unmarked.', '%s orders unmarked.', $count, 'woo-order-export-lite' )
@@ -821,24 +882,27 @@ class WC_Order_Export_Admin {
821
  function fix_table_links( $args ) {
822
  $args[] = 'export_bulk_profile';
823
  $args[] = 'ids';
 
824
  return $args;
825
  }
826
 
827
  function must_run_ajax_methods() {
828
  // wait admin ajax!
829
- $script_name = !empty($_SERVER['SCRIPT_NAME']) ? $_SERVER['SCRIPT_NAME'] : $_SERVER['PHP_SELF'];
830
- if ( basename( $script_name ) != "admin-ajax.php" )
831
- return false;
 
 
832
  // our method MUST BE called
833
- return isset($_REQUEST['action']) AND ($_REQUEST['action'] == "order_exporter" OR $_REQUEST['action'] == "order_exporter_run" );
834
  }
835
 
836
  public static function is_full_version() {
837
  return defined( 'WOE_STORE_URL' );
838
- }
839
-
840
  public static function user_can_add_custom_php() {
841
- return apply_filters('woe_user_can_add_custom_php', current_user_can('edit_themes') );
842
- }
843
-
844
  }
30
 
31
  //Add custom bulk export action in Woocomerce orders Table, modified for WP 4.7
32
  add_filter( 'bulk_actions-edit-shop_order', array( $this, 'export_orders_bulk_action' ) );
33
+ add_filter( 'handle_bulk_actions-edit-shop_order', array( $this, 'export_orders_bulk_action_process' ), 10,
34
+ 3 );
35
+ add_action( 'admin_notices', array( $this, 'export_orders_bulk_action_notices' ) );
36
  //do once
37
+ if ( ! get_option( $this->activation_notice_option ) ) {
38
+ add_action( 'admin_notices', array( $this, 'display_plugin_activated_message' ) );
39
+ }
40
+
41
  //extra links in >Plugins
42
+ add_filter( 'plugin_action_links_' . WOE_PLUGIN_BASENAME, array( $this, 'add_action_links' ) );
43
+
44
  // Add 'Export Status' orders page column header
45
  add_filter( 'manage_edit-shop_order_columns', array( $this, 'add_order_status_column_header' ), 20 );
46
 
47
  // Add 'Export Status' orders page column content
48
  add_action( 'manage_shop_order_posts_custom_column', array( $this, 'add_order_status_column_content' ) );
49
 
50
+ if ( isset( $_GET['post_type'] ) && $_GET['post_type'] == 'shop_order' ) {
51
  add_action( 'admin_print_styles', array( $this, 'add_order_status_column_style' ) );
52
  }
53
  }
54
 
55
+ $this->settings = self::load_main_settings();
56
 
57
  //Pro active ?
58
+ if ( self::is_full_version() ) {
59
+ new WC_Order_Export_Zapier_Engine( $this->settings );
60
  add_action( 'plugins_loaded', array( $this, 'load_textdomain' ) );
61
+ add_filter( 'cron_schedules', array( 'WC_Order_Export_Cron', 'create_custom_schedules' ), 999, 1 );
62
  add_action( 'wc_export_cron_global', array( 'WC_Order_Export_Cron', 'wc_export_cron_global_f' ) );
63
 
64
  //for direct calls
65
  add_action( 'wp_ajax_order_exporter_run', array( $this, 'ajax_gate_guest' ) );
66
  add_action( 'wp_ajax_nopriv_order_exporter_run', array( $this, 'ajax_gate_guest' ) );
67
+ $this->methods_allowed_for_guests = array( 'run_cron_jobs', 'run_one_job', 'run_one_scheduled_job' );
68
 
69
  // order actions
70
+ add_action( 'woocommerce_order_status_changed', array( $this, 'wc_order_status_changed' ), 10, 3 );
71
  // activate CRON hook if it was removed
72
+ add_action( 'wp_loaded', function () {
73
  $all_jobs = WC_Order_Export_Manage::get_export_settings_collection( WC_Order_Export_Manage::EXPORT_SCHEDULE );
74
+ if ( $all_jobs ) {
75
  WC_Order_Export_Cron::install_job();
76
+ }
77
  } );
78
  }
79
 
80
  }
81
 
82
  public function add_order_status_column_header( $columns ) {
83
+
84
+ if ( ! $this->settings['show_export_status_column'] ) {
85
  return $columns;
86
+ }
87
+
88
  $new_columns = array();
89
  foreach ( $columns as $column_name => $column_info ) {
90
+ if ( 'order_actions' === $column_name OR 'wc_actions' === $column_name ) { // Woocommerce uses wc_actions since 3.3.0
91
+ $label = __( 'Export Status', 'woo-order-export-lite' );
92
  $new_columns['woe_export_status'] = $label;
93
  }
94
  $new_columns[ $column_name ] = $column_info;
95
  }
96
+
97
  return $new_columns;
98
  }
99
 
107
  $is_exported = true;
108
  }
109
 
110
+ if ( $is_exported ) {
111
  echo '<span class="dashicons dashicons-yes" style="color: #2ea2cc"></span>';
112
  } else {
113
  echo '<span class="dashicons dashicons-minus"></span>';
122
 
123
  public function install() {
124
  //wp_clear_scheduled_hook( "wc_export_cron_global" ); //debug
125
+ if ( self::is_full_version() ) {
126
  WC_Order_Export_Cron::install_job();
127
+ }
128
  }
129
 
130
  public function display_plugin_activated_message() {
131
  ?>
132
+ <div class="notice notice-success is-dismissible">
133
+ <p><?php _e( 'Advanced Order Export For WooCommerce is available <a href="admin.php?page=wc-order-export">on this page</a>.',
134
+ 'woo-order-export-lite' ); ?></p>
135
+ </div>
136
  <?php
137
+ update_option( $this->activation_notice_option, true, false);
138
  }
139
 
140
  public function add_action_links( $links ) {
141
+ $mylinks = array(
142
+ '<a href="admin.php?page=wc-order-export">' . __( 'Settings', 'woo-order-export-lite' ) . '</a>',
143
+ '<a href="https://algolplus.com/plugins/documentation-order-export-woocommerce/" target="_blank">' . __( 'Docs',
144
+ 'woo-order-export-lite' ) . '</a>',
145
+ '<a href="https://algolplus.freshdesk.com" target="_blank">' . __( 'Support',
146
+ 'woo-order-export-lite' ) . '</a>',
147
  );
148
+
149
+ return array_merge( $mylinks, $links );
150
  }
151
 
152
  public function deactivate() {
153
  wp_clear_scheduled_hook( "wc_export_cron_global" );
154
  delete_option( $this->activation_notice_option );
155
 
156
+ if ( self::is_full_version() ) {
157
  //don't do it! updater call this function!
158
  // WC_Order_Export_EDD::getInstance()->edd_woe_force_deactivate_license();
159
  }
160
  }
161
+
162
  public static function uninstall() {
163
  //delete_option( self::settings_name_common );
164
  //WC_Order_Export_Manage::remove_settings();
167
  static function load_main_settings() {
168
  return array_merge(
169
  array(
170
+ 'default_tab' => 'export',
171
+ 'cron_tasks_active' => '1',
172
+ 'show_export_status_column' => '1',
173
+ 'show_export_actions_in_bulk' => '1',
174
+ 'show_export_in_status_change_job' => '0',
175
+ 'autocomplete_products_max' => '10',
176
+ 'ajax_orders_per_step' => '30',
177
+ 'limit_button_test' => '1',
178
+ 'cron_key' => '1234',
179
+ 'ipn_url' => '',
180
+ 'zapier_api_key' => '12345678',
181
+ 'zapier_file_timeout' => 60,
182
  ),
183
  get_option( self::settings_name_common, array() )
184
  );
185
  }
186
+
187
  static function save_main_settings() {
188
  // update main settings here!
189
+ $settings = filter_input_array( INPUT_POST, array(
190
+ 'default_tab' => FILTER_SANITIZE_STRING,
191
+ 'cron_tasks_active' => FILTER_VALIDATE_BOOLEAN,
192
+ 'show_export_status_column' => FILTER_VALIDATE_BOOLEAN,
193
+ 'show_export_actions_in_bulk' => FILTER_VALIDATE_BOOLEAN,
194
  'show_export_in_status_change_job' => FILTER_VALIDATE_BOOLEAN,
195
+ 'autocomplete_products_max' => FILTER_VALIDATE_INT,
196
+ 'ajax_orders_per_step' => FILTER_VALIDATE_INT,
197
+ 'limit_button_test' => FILTER_SANITIZE_STRING,
198
+ 'cron_key' => FILTER_SANITIZE_STRING,
199
+ 'ipn_url' => FILTER_SANITIZE_STRING,
200
+ 'zapier_api_key' => FILTER_SANITIZE_STRING,
201
+ 'zapier_file_timeout' => FILTER_SANITIZE_NUMBER_INT,
202
  ) );
203
+ update_option( self::settings_name_common, $settings, false );
204
 
205
  if ( isset( $settings['ipn_url'] ) ) {
206
+ update_option( WOE_IPN_URL_OPTION_KEY, $settings['ipn_url'], false );
207
  }
208
  }
209
 
210
 
211
  function load_textdomain() {
212
  $locale = apply_filters( 'plugin_locale', get_locale(), 'woo-order-export-lite' );
213
+ load_textdomain( 'woo-order-export-lite',
214
+ WP_LANG_DIR . '/woocommerce-order-export/woocommerce-order-export-' . $locale . '.mo' );
215
 
216
  load_plugin_textdomain( 'woo-order-export-lite', false,
217
  plugin_basename( dirname( dirname( __FILE__ ) ) ) . '/i18n/languages' );
218
  }
219
 
220
  public function add_menu() {
221
+ if ( apply_filters( 'woe_current_user_can_export', true ) ) {
222
+ if ( current_user_can( 'manage_woocommerce' ) ) {
223
+ add_submenu_page( 'woocommerce', __( 'Export Orders', 'woo-order-export-lite' ),
224
+ __( 'Export Orders', 'woo-order-export-lite' ), 'view_woocommerce_reports', 'wc-order-export',
225
+ array( $this, 'render_menu' ) );
226
+ } else // add after Sales Report!
227
+ {
228
+ add_menu_page( __( 'Export Orders', 'woo-order-export-lite' ),
229
+ __( 'Export Orders', 'woo-order-export-lite' ), 'view_woocommerce_reports', 'wc-order-export',
230
+ array( $this, 'render_menu' ), null, '55.7' );
231
+ }
232
  }
233
  }
234
 
235
  public function render_menu() {
236
  $this->render( 'main', array( 'WC_Order_Export' => $this, 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) );
237
+ $active_tab = isset( $_REQUEST['tab'] ) ? $_REQUEST['tab'] : $this->settings['default_tab'];
238
  if ( method_exists( $this, 'render_tab_' . $active_tab ) ) {
239
  $this->{'render_tab_' . $active_tab}();
240
  }
244
  $this->render( 'tab/export', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ), 'WC_Order_Export' => $this ) );
245
  }
246
 
247
+ public function render_tab_tools() {
248
  $this->render( 'tab/tools', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ), 'WC_Order_Export' => $this ) );
249
  }
250
 
251
+ public function render_tab_settings() {
252
+ $this->render( 'tab/settings',
253
+ array( 'ajaxurl' => admin_url( 'admin-ajax.php' ), 'settings' => $this->settings ) );
254
  }
255
 
256
  public function render_tab_license() {
257
  $this->render( 'tab/license', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ), 'WC_Order_Export' => $this ) );
258
  }
259
 
260
+ public function render_tab_help() {
261
  $this->render( 'tab/help', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ), 'WC_Order_Export' => $this ) );
262
  }
263
 
264
  public function render_tab_order_actions() {
265
  $wc_oe = isset( $_REQUEST['wc_oe'] ) ? $_REQUEST['wc_oe'] : '';
266
  $ajaxurl = admin_url( 'admin-ajax.php' );
267
+ $mode = WC_Order_Export_Manage::EXPORT_ORDER_ACTION;
268
  $all_items = WC_Order_Export_Manage::get_export_settings_collection( $mode );
269
  $show = array(
270
+ 'date_filter' => $this->settings['show_export_in_status_change_job'],
271
+ 'export_button' => $this->settings['show_export_in_status_change_job'],
272
  'export_button_plain' => $this->settings['show_export_in_status_change_job'],
273
+ 'preview_actions' => false,
274
+ 'destinations' => true,
275
+ 'schedule' => false,
276
+ 'sort_orders' => false,
277
+ 'order_filters' => true,
278
+ 'product_filters' => true,
279
+ 'customer_filters' => true,
280
+ 'billing_filters' => true,
281
+ 'shipping_filters' => true,
282
  );
283
  switch ( $wc_oe ) {
284
  case 'add_action':
289
  'id' => $next_id,
290
  'WC_Order_Export' => $this,
291
  'ajaxurl' => $ajaxurl,
292
+ 'show' => $show,
293
  ) );
294
+
295
  return;
296
  case 'edit_action':
297
+ if ( ! isset( $_REQUEST['action_id'] ) ) {
298
  break;
299
+ }
300
+ $item_id = $_REQUEST['action_id'];
301
  WC_Order_Export_Manage::$edit_existing_job = true;
302
+ $clone = isset( $_REQUEST['clone'] ) ? $_REQUEST['clone'] : '';
303
  if ( $clone ) {
304
  $item_id = WC_Order_Export_Manage::clone_export_settings( $mode, $item_id );
305
  }
308
  'id' => $item_id,
309
  'WC_Order_Export' => $this,
310
  'ajaxurl' => $ajaxurl,
311
+ 'show' => $show,
312
  ) );
313
+
314
  return;
315
  case 'delete':
316
+ if ( ! isset( $_REQUEST['action_id'] ) ) {
317
  break;
318
+ }
319
+ $item_id = $_REQUEST['action_id'];
320
  unset( $all_items[ $item_id ] );
321
  WC_Order_Export_Manage::save_export_settings_collection( $mode, $all_items );
322
  break;
323
  case 'change_status':
324
+ if ( ! isset( $_REQUEST['action_id'] ) ) {
325
  break;
326
+ }
327
+ $item_id = $_REQUEST['action_id'];
328
  $all_items[ $item_id ]['active'] = $_REQUEST['status'];
329
  WC_Order_Export_Manage::save_export_settings_collection( $mode, $all_items );
330
  $url = remove_query_arg( array( 'wc_oe', 'action_id', 'status' ) );
331
  wp_redirect( $url );
332
  break;
333
  case 'change_statuses':
334
+ if ( ! isset( $_REQUEST['chosen_order_actions'] ) AND ! isset( $_REQUEST['doaction'] ) AND - 1 == $_REQUEST['doaction'] ) {
335
  break;
336
+ }
337
+ $chosen_order_actions = explode( ',', $_REQUEST['chosen_order_actions'] );
338
+ $doaction = $_REQUEST['doaction'];
339
 
340
  foreach ( $chosen_order_actions as $order_action_id ) {
341
  if ( 'activate' == $doaction ) {
351
  wp_redirect( $url );
352
  break;
353
  }
354
+ $this->render( 'tab/order-actions',
355
+ array( 'ajaxurl' => $ajaxurl, 'WC_Order_Export' => $this, 'tab' => 'order_actions' ) );
356
  }
357
 
358
  public function render_tab_schedules() {
359
  $wc_oe = isset( $_REQUEST['wc_oe'] ) ? $_REQUEST['wc_oe'] : '';
360
  $ajaxurl = admin_url( 'admin-ajax.php' );
361
+ $mode = WC_Order_Export_Manage::EXPORT_SCHEDULE;
362
  $all_jobs = WC_Order_Export_Manage::get_export_settings_collection( $mode );
363
+ $show = array(
364
+ 'date_filter' => true,
365
+ 'export_button' => true,
366
  'export_button_plain' => true,
367
+ 'destinations' => true,
368
+ 'schedule' => true,
369
  );
370
  switch ( $wc_oe ) {
371
  case 'add_schedule':
376
  'id' => $next_id,
377
  'WC_Order_Export' => $this,
378
  'ajaxurl' => $ajaxurl,
379
+ 'show' => $show,
380
  ) );
381
+
382
  return;
383
  case 'edit_schedule':
384
+ if ( ! isset( $_REQUEST['schedule_id'] ) ) {
385
  break;
386
+ }
387
+ $schedule_id = $_REQUEST['schedule_id'];
388
  WC_Order_Export_Manage::$edit_existing_job = true;
389
+ $clone = isset( $_REQUEST['clone'] ) ? $_REQUEST['clone'] : '';
390
  if ( $clone ) {
391
  $schedule_id = WC_Order_Export_Manage::clone_export_settings( $mode, $schedule_id );
392
  }
395
  'id' => $schedule_id,
396
  'WC_Order_Export' => $this,
397
  'ajaxurl' => $ajaxurl,
398
+ 'show' => $show,
399
  ) );
400
+
401
  return;
402
  case 'delete_schedule':
403
+ if ( ! isset( $_REQUEST['schedule_id'] ) ) {
404
  break;
405
+ }
406
+ $schedule_id = $_REQUEST['schedule_id'];
407
  unset( $all_jobs[ $schedule_id ] );
408
  WC_Order_Export_Manage::save_export_settings_collection( $mode, $all_jobs );
409
  break;
410
  case 'change_status_schedule':
411
+ if ( ! isset( $_REQUEST['schedule_id'] ) ) {
412
  break;
413
+ }
414
+ $schedule_id = $_REQUEST['schedule_id'];
415
  $all_jobs[ $schedule_id ]['active'] = $_REQUEST['status'];
416
  WC_Order_Export_Manage::save_export_settings_collection( $mode, $all_jobs );
417
  $url = remove_query_arg( array( 'wc_oe', 'schedule_id', 'status' ) );
418
  wp_redirect( $url );
419
  break;
420
  case 'change_status_schedules':
421
+ if ( ! isset( $_REQUEST['chosen_schedules'] ) AND ! isset( $_REQUEST['doaction'] ) AND - 1 == $_REQUEST['doaction'] ) {
422
  break;
423
+ }
424
+ $chosen_schedules = explode( ',', $_REQUEST['chosen_schedules'] );
425
+ $doaction = $_REQUEST['doaction'];
426
 
427
  foreach ( $chosen_schedules as $schedule_id ) {
428
+ if ( 'activate' == $doaction ) {
429
+ $all_jobs[ $schedule_id ]['active'] = 1;
430
+ } elseif ( 'deactivate' == $doaction ) {
431
+ $all_jobs[ $schedule_id ]['active'] = 0;
432
+ } elseif ( 'delete' == $doaction ) {
433
+ unset( $all_jobs[ $schedule_id ] );
434
+ }
435
+ }
436
  WC_Order_Export_Manage::save_export_settings_collection( $mode, $all_jobs );
437
  $url = remove_query_arg( array( 'wc_oe', 'chosen_schedules', 'doaction' ) );
438
  wp_redirect( $url );
442
  }
443
 
444
  public function render_tab_profiles() {
445
+ $wc_oe = isset( $_REQUEST['wc_oe'] ) ? $_REQUEST['wc_oe'] : '';
446
+ $ajaxurl = admin_url( 'admin-ajax.php' );
447
+ $mode = WC_Order_Export_Manage::EXPORT_PROFILE;
448
  $all_items = WC_Order_Export_Manage::get_export_settings_collection( $mode );
449
+ $show = array(
450
+ 'date_filter' => true,
451
+ 'export_button' => true,
452
  'export_button_plain' => true,
453
+ 'destinations' => true,
454
+ 'schedule' => false,
455
  );
456
  switch ( $wc_oe ) {
457
  case 'add_profile':
462
  'id' => $next_id,
463
  'WC_Order_Export' => $this,
464
  'ajaxurl' => $ajaxurl,
465
+ 'show' => $show,
466
  ) );
467
+
468
  return;
469
  case 'edit_profile':
470
+ if ( ! isset( $_REQUEST['profile_id'] ) ) {
471
  break;
472
+ }
473
+ $profile_id = $_REQUEST['profile_id'];
474
  WC_Order_Export_Manage::$edit_existing_job = true;
475
+ $clone = isset( $_REQUEST['clone'] ) ? $_REQUEST['clone'] : '';
476
  if ( $clone ) {
477
  $profile_id = WC_Order_Export_Manage::clone_export_settings( $mode, $profile_id );
478
  }
481
  'id' => $profile_id,
482
  'WC_Order_Export' => $this,
483
  'ajaxurl' => $ajaxurl,
484
+ 'show' => $show,
485
  ) );
486
+
487
  return;
488
  case 'copy_profile_to_scheduled':
489
  $profile_id = isset( $_REQUEST['profile_id'] ) ? $_REQUEST['profile_id'] : '';
490
+ $schedule_id = WC_Order_Export_Manage::advanced_clone_export_settings( $profile_id, $mode,
491
+ WC_Order_Export_Manage::EXPORT_SCHEDULE );
492
+ $url = remove_query_arg( 'profile_id' );
493
+ $url = add_query_arg( 'tab', 'schedules', $url );
494
+ $url = add_query_arg( 'wc_oe', 'edit_schedule', $url );
495
+ $url = add_query_arg( 'schedule_id', $schedule_id, $url );
496
  wp_redirect( $url );
497
  break;
498
  case 'copy_profile_to_actions':
499
  $profile_id = isset( $_REQUEST['profile_id'] ) ? $_REQUEST['profile_id'] : '';
500
+ $schedule_id = WC_Order_Export_Manage::advanced_clone_export_settings( $profile_id, $mode,
501
+ WC_Order_Export_Manage::EXPORT_ORDER_ACTION );
502
+ $url = remove_query_arg( 'profile_id' );
503
+ $url = add_query_arg( 'tab', 'order_actions', $url );
504
+ $url = add_query_arg( 'wc_oe', 'edit_action', $url );
505
+ $url = add_query_arg( 'action_id', $schedule_id, $url );
506
  wp_redirect( $url );
507
  break;
508
  case 'delete_profile':
509
+ if ( ! isset( $_REQUEST['profile_id'] ) ) {
510
  break;
511
+ }
512
  $profile_id = $_REQUEST['profile_id'];
513
  unset( $all_items[ $profile_id ] );
514
  WC_Order_Export_Manage::save_export_settings_collection( $mode, $all_items );
515
  break;
516
  case 'change_profile_statuses':
517
+ if ( ! isset( $_REQUEST['chosen_profiles'] ) AND ! isset( $_REQUEST['doaction'] ) AND - 1 == $_REQUEST['doaction'] ) {
518
  break;
519
+ }
520
+ $chosen_profiles = explode( ',', $_REQUEST['chosen_profiles'] );
521
+ $doaction = $_REQUEST['doaction'];
522
 
523
  foreach ( $chosen_profiles as $profile_id ) {
524
+ if ( 'activate' == $doaction ) {
525
+ $all_items[ $profile_id ]['use_as_bulk'] = 'on';
526
+ } elseif ( 'deactivate' == $doaction ) {
527
+ unset( $all_items[ $profile_id ]['use_as_bulk'] );
528
+ } elseif ( 'delete' == $doaction ) {
529
+ unset( $all_items[ $profile_id ] );
530
+ }
531
+ }
532
  WC_Order_Export_Manage::save_export_settings_collection( $mode, $all_items );
533
  $url = remove_query_arg( array( 'wc_oe', 'chosen_profiles', 'doaction' ) );
534
  wp_redirect( $url );
537
 
538
  //code to copy default settings as profile
539
  $profiles = WC_Order_Export_Manage::get_export_settings_collection( $mode );
540
+ $free_job = WC_Order_Export_Manage::get_export_settings_collection( WC_Order_Export_Manage::EXPORT_NOW );
541
+ if ( empty( $profiles ) AND ! empty( $free_job ) ) {
542
+ $free_job['title'] = __( 'Copied from "Export now"', 'woo-order-export-lite' );
543
+ $free_job['mode'] = $mode;
544
+ $profiles[1] = $free_job;
545
+ update_option( WC_Order_Export_Manage::settings_name_profiles, $profiles, false );
546
  }
547
 
548
  $this->render( 'tab/profiles', array( 'ajaxurl' => $ajaxurl, 'WC_Order_Export' => $this ) );
555
  wp_enqueue_style( 'jquery-style',
556
  '//ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/smoothness/jquery-ui.css' );
557
  $this->enqueue_select2_scripts();
558
+
559
  wp_enqueue_script( 'export', $this->url_plugin . 'assets/js/export.js', array(), WOE_VERSION );
560
+ wp_enqueue_script( 'serializejson', $this->url_plugin . 'assets/js/jquery.serializejson.js', array( 'jquery' ),
561
+ WOE_VERSION );
562
  wp_enqueue_style( 'export', $this->url_plugin . 'assets/css/export.css', array(), WOE_VERSION );
563
  wp_enqueue_style( 'woocommerce_admin_styles', WC()->plugin_url() . '/assets/css/admin.css', array() );
564
 
565
+ $_REQUEST['tab'] = isset( $_REQUEST['tab'] ) ? $_REQUEST['tab'] : $this->settings['default_tab'];
566
+ if ( isset( $_REQUEST['wc_oe'] ) AND ( strpos( $_REQUEST['wc_oe'], 'add_' ) === 0 OR strpos( $_REQUEST['wc_oe'],
567
+ 'edit_' ) === 0 ) OR $_REQUEST['tab'] == 'export' ) {
568
+ wp_enqueue_script( 'settings-form', $this->url_plugin . 'assets/js/settings-form.js', array(),
569
+ WOE_VERSION );
570
 
571
  $localize_settings_form = array(
572
+ 'set_up_fields_to_export' => __( 'Set up fields to export', 'woo-order-export-lite' ),
573
+ 'js_tpl_popup' => __( 'Add %s as %s columns %s as rows', 'woo-order-export-lite' ),
574
+ );
575
  wp_localize_script( 'settings-form', 'localize_settings_form', $localize_settings_form );
576
 
577
 
601
  'object_formats' => array( 'XML', 'JSON' ),
602
  'xml_formats' => array( 'XML' ),
603
 
604
+ 'day_names' => WC_Order_Export_Manage::get_days(),
605
 
606
  );
607
 
611
 
612
  // Localize the script with new data
613
  $translation_array = array(
614
+ 'empty_column_name' => __( 'empty column name', 'woo-order-export-lite' ),
615
+ 'empty_meta_key' => __( 'empty meta key', 'woo-order-export-lite' ),
616
+ 'empty_meta_key_and_taxonomy' => __( 'select product field or item field or taxonomy',
617
+ 'woo-order-export-lite' ),
618
+ 'empty_value' => __( 'empty value', 'woo-order-export-lite' ),
619
+ 'empty_title' => __( 'title is empty', 'woo-order-export-lite' ),
620
+ 'wrong_date_range' => __( 'Date From is greater than Date To', 'woo-order-export-lite' ),
621
+ 'no_fields' => __( 'Please, set up fields to export', 'woo-order-export-lite' ),
622
+ 'no_results' => __( 'Nothing to export. Please, adjust your filters',
623
+ 'woo-order-export-lite' ),
624
+ 'empty' => __( 'empty', 'woo-order-export-lite' ),
625
  );
626
+ wp_localize_script( 'export', 'export_messages', $translation_array );
627
  }
628
 
629
  private function enqueue_select2_scripts() {
649
  array(), WC_VERSION );
650
  }
651
 
652
+ public function script_loader_src( $src, $handle ) {
653
  // don't load ANY select2.js / select2.min.js and OUTDATED select2.full.js
654
+ if ( ! preg_match( '/\/select2\.full\.js\?ver=[1-3]/', $src ) && ! preg_match( '/\/select2\.min\.js/',
655
+ $src ) && ! preg_match( '/\/select2\.js/', $src )
656
+ && ! preg_match( '#jquery\.serialize-object\.#', $src ) /*this script breaks our json!*/
657
  ) {
658
  return $src;
659
  }
661
 
662
  public function render( $view, $params = array(), $path_views = null ) {
663
  $params = apply_filters( 'woe_render_params', $params );
664
+ $params = apply_filters( 'woe_render_params_' . $view, $params );
665
+
666
  extract( $params );
667
  if ( $path_views ) {
668
  include $path_views . "$view.php";
677
  if ( substr( $name, 0, 1 ) == '[' ) {
678
  $name = substr( $name, 1 );
679
  }
680
+
681
  return trim( $name );
682
  }, $arr_name );
683
  $arr_name = array_filter( $arr_name );
685
  foreach ( $arr_name as $value ) {
686
  $arr = isset( $arr[ $value ] ) ? $arr[ $value ] : "";
687
  }
688
+
689
  return $arr;
690
  }
691
 
699
  $new_status = is_string( $new_status ) && strpos( $new_status, 'wc-' ) !== 0 ? "wc-{$new_status}" : $new_status;
700
 
701
  $this->changed_order_id = $order_id;
702
+ add_filter( 'woe_sql_get_order_ids_where', array( $this, "filter_by_changed_order" ), 10, 2 );
703
 
704
+ $logger = function_exists( "wc_get_logger" ) ? wc_get_logger() : false; //new logger in 3.0+
705
  $logger_context = array( 'source' => 'woo-order-export-lite' );
706
 
707
+ foreach ( $all_items as $key => $item ) {
708
  $item = WC_Order_Export_Manage::get( WC_Order_Export_Manage::EXPORT_ORDER_ACTION, $key );
709
  if ( isset( $item['active'] ) && ! $item['active'] ) {
710
  continue;
711
  }
712
  // use empty for ANY status
713
+ if ( ( empty( $item['from_status'] ) OR in_array( $old_status, $item['from_status'] ) )
714
  AND
715
  ( empty( $item['to_status'] ) OR in_array( $new_status, $item['to_status'] ) )
716
+ ) {
717
+ do_action( 'woe_order_action_started', $order_id, $item );
718
  $result = WC_Order_Export_Engine::build_files_and_export( $item );
719
+ $output = sprintf( __( 'Status change job #%s for order #%s. Result: %s', 'woo-order-export-lite' ),
720
+ $key, $order_id, $result );
721
  // log if required
722
+ if ( $logger AND ! empty( $item['log_results'] ) ) {
723
  $logger->info( $output, $logger_context );
724
+ }
725
 
726
+ do_action( 'woe_order_action_completed', $order_id, $item, $result );
727
  }
728
  }
729
+ remove_filter( 'woe_sql_get_order_ids_where', array( $this, "filter_by_changed_order" ), 10 );
730
  }
731
 
732
+ public function filter_by_changed_order( $where, $settings ) {
733
  $where[] = "orders.ID = " . $this->changed_order_id;
734
+
735
  return $where;
736
  }
737
 
741
  if ( isset( $_REQUEST['method'] ) ) {
742
  $method = $_REQUEST['method'];
743
  if ( method_exists( 'WC_Order_Export_Ajax', $method ) ) {
744
+ $_POST = stripslashes_deep( $_POST );
745
  // parse json to arrays?
746
+ if ( ! empty( $_POST['json'] ) ) {
747
+ $json = json_decode( $_POST['json'], true );
748
+ if ( is_array( $json ) ) {
749
  // add $_POST['settings'],$_POST['orders'],$_POST['products'],$_POST['coupons']
750
  $_POST = $_POST + $json;
751
  unset( $_POST['json'] );
760
 
761
  //TODO: debug!
762
  public function ajax_gate_guest() {
763
+ if ( isset( $_REQUEST['method'] ) AND in_array( $_REQUEST['method'], $this->methods_allowed_for_guests ) ) {
764
  $method = $_REQUEST['method'];
765
  if ( method_exists( 'WC_Order_Export_Ajax', $method ) ) {
766
+ $_POST = array_map( 'stripslashes_deep', $_POST );
767
+ $ajax = new WC_Order_Export_Ajax();
768
  $ajax->validate_url_key();
769
  $ajax->$method();
770
  }
771
  }
772
  die();
773
  }
774
+
775
  //Works since Wordpress 4.7
776
  function export_orders_bulk_action( $actions ) {
777
  $settings = WC_Order_Export_Manage::get( WC_Order_Export_Manage::EXPORT_NOW );
778
  WC_Order_Export_Manage::set_correct_file_ext( $settings );
779
+
780
  // default
781
+ if ( ! empty( $settings['format'] ) ) {
782
+ $actions['woe_export_selected_orders'] = sprintf( __( 'Export as %s', 'woo-order-export-lite' ),
783
+ $settings['format'] );
784
  }
785
+
786
  // mark/unmark
787
+ if ( $this->settings['show_export_actions_in_bulk'] ) {
788
+ $actions['woe_mark_exported'] = __( 'Mark exported', 'woo-order-export-lite' );
789
  $actions['woe_unmark_exported'] = __( 'Unmark exported', 'woo-order-export-lite' );
790
+ }
791
 
792
  $all_items = WC_Order_Export_Manage::get_export_settings_collection( WC_Order_Export_Manage::EXPORT_PROFILE );
793
  foreach ( $all_items as $job_id => $job ) {
794
+ if ( isset( $job['use_as_bulk'] ) ) {
795
+ $actions[ 'woe_export_selected_orders_profile_' . $job_id ] = sprintf( __( "Export as profile '%s'",
796
+ 'woo-order-export-lite' ), $job['title'] );
797
+ }
798
  }
799
+
800
  return $actions;
801
  }
802
 
803
+ function export_orders_bulk_action_process( $redirect_to, $action, $ids ) {
804
  switch ( $action ) {
805
  case 'woe_export_selected_orders':
806
+ $redirect_to = add_query_arg( array( 'export_bulk_profile' => 'now', 'ids' => join( ',', $ids ) ),
807
+ $redirect_to );
808
  break;
809
  case 'woe_mark_exported':
810
+ foreach ( $ids as $post_id ) {
811
  update_post_meta( $post_id, 'woe_order_exported', 1 );
812
  }
813
+ $redirect_to = add_query_arg( array(
814
  'woe_bulk_mark_exported' => count( $ids ),
815
  'woe_bulk_unmark_exported' => false,
816
  ), $redirect_to );
817
  break;
818
  case 'woe_unmark_exported':
819
+ foreach ( $ids as $post_id ) {
820
+ delete_post_meta( $post_id, 'woe_order_exported' );
821
  }
822
  $redirect_to = add_query_arg( array(
823
  'woe_bulk_mark_exported' => false,
824
+ 'woe_bulk_unmark_exported' => count( $ids ),
825
  ), $redirect_to );
826
  break;
827
  default:
828
  if ( preg_match( '/woe_export_selected_orders_profile_(\d+)/', $action, $matches ) ) {
829
  if ( isset( $matches[1] ) ) {
830
+ $id = $matches[1];
831
+ $redirect_to = add_query_arg( array( 'export_bulk_profile' => $id, 'ids' => join( ',', $ids ) ),
832
+ $redirect_to );
833
  break;
834
+ }
835
  }
836
+
837
+ //do nothing
838
  return $redirect_to;
839
  }
840
 
846
 
847
  global $post_type, $pagenow;
848
 
849
+ if ( $pagenow == 'edit.php' && $post_type == 'shop_order' && isset( $_REQUEST['export_bulk_profile'] ) ) {
850
+ $url = admin_url( 'admin-ajax.php' ) . "?action=order_exporter&method=export_download_bulk_file&export_bulk_profile=" . $_REQUEST['export_bulk_profile'] . "&ids=" . $_REQUEST['ids'];
851
+ wp_redirect( $url );
852
  exit();
853
  /* unused code
854
  //$message = sprintf( __( 'Orders exported. <a href="%s">Download report.</a>' ,'woo-order-export-lite'), $url );
859
  // must remove this arg from pagination url
860
  add_filter('removable_query_args', array($this, 'fix_table_links') );
861
  */
862
+ } else if ( $pagenow == 'edit.php' && $post_type == 'shop_order' && isset( $_REQUEST['woe_bulk_mark_exported'] ) ) {
863
+ $count = intval( $_REQUEST['woe_bulk_mark_exported'] );
864
  printf(
865
  '<div id="message" class="updated fade">' .
866
  _n( '%s order marked.', '%s orders marked.', $count, 'woo-order-export-lite' )
868
  $count
869
  );
870
 
871
+ } else if ( $pagenow == 'edit.php' && $post_type == 'shop_order' && isset( $_REQUEST['woe_bulk_unmark_exported'] ) ) {
872
+ $count = intval( $_REQUEST['woe_bulk_unmark_exported'] );
873
  printf(
874
  '<div id="message" class="updated fade">' .
875
  _n( '%s order unmarked.', '%s orders unmarked.', $count, 'woo-order-export-lite' )
882
  function fix_table_links( $args ) {
883
  $args[] = 'export_bulk_profile';
884
  $args[] = 'ids';
885
+
886
  return $args;
887
  }
888
 
889
  function must_run_ajax_methods() {
890
  // wait admin ajax!
891
+ $script_name = ! empty( $_SERVER['SCRIPT_NAME'] ) ? $_SERVER['SCRIPT_NAME'] : $_SERVER['PHP_SELF'];
892
+ if ( basename( $script_name ) != "admin-ajax.php" ) {
893
+ return false;
894
+ }
895
+
896
  // our method MUST BE called
897
+ return isset( $_REQUEST['action'] ) AND ( $_REQUEST['action'] == "order_exporter" OR $_REQUEST['action'] == "order_exporter_run" );
898
  }
899
 
900
  public static function is_full_version() {
901
  return defined( 'WOE_STORE_URL' );
902
+ }
903
+
904
  public static function user_can_add_custom_php() {
905
+ return apply_filters( 'woe_user_can_add_custom_php', current_user_can( 'edit_themes' ) );
906
+ }
907
+
908
  }
classes/core/class-wc-order-export-data-extractor-ui.php CHANGED
@@ -8,40 +8,43 @@ class WC_Order_Export_Data_Extractor_UI extends WC_Order_Export_Data_Extractor {
8
  const HUGE_SHOP_CUSTOMERS = 1000;// more than 1000 customers
9
 
10
  // ADD custom fields for export
11
- public static function get_all_order_custom_meta_fields( $sql_order_ids='' ) {
12
  global $wpdb;
13
 
14
- $transient_key = 'woe_get_all_order_custom_meta_fields_results_'.md5( json_encode( $sql_order_ids ) ); // complex key
15
- $fields = get_transient( $transient_key );
16
- if($fields === false) {
17
  $sql_in_orders = '';
18
- if( $sql_order_ids )
19
- $sql_in_orders = " AND ID IN ($sql_order_ids) ";
 
20
 
21
  // must show all
22
- if( !$sql_in_orders ) {
23
  //rewrite for huge # of users
24
  $total_users = $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->users}" );
25
- if( $total_users >= self::HUGE_SHOP_CUSTOMERS ) {
26
- $user_ids = $wpdb->get_col( "SELECT ID FROM {$wpdb->users} ORDER BY ID DESC LIMIT 1000"); // take last 1000
27
- $user_ids = join( ",", $user_ids);
28
  $where_users = "WHERE user_id IN ($user_ids)";
29
- }
30
- else
31
  $where_users = '';
 
32
  $user_fields = $wpdb->get_col( "SELECT DISTINCT meta_key FROM {$wpdb->usermeta} $where_users" );
33
- $fields = self::get_order_custom_fields();
34
- } else {
35
  $user_fields = $wpdb->get_col( "SELECT DISTINCT meta_key FROM {$wpdb->posts} INNER JOIN {$wpdb->usermeta} ON {$wpdb->posts}.post_author = {$wpdb->usermeta}.user_id WHERE post_type = '" . self::$object_type . "' {$sql_in_orders}" );
36
- $fields = $wpdb->get_col( "SELECT DISTINCT meta_key FROM {$wpdb->posts} INNER JOIN {$wpdb->postmeta} ON {$wpdb->posts}.ID = {$wpdb->postmeta}.post_id WHERE post_type = '" . self::$object_type . "' {$sql_in_orders}" );
37
  }
38
 
39
- foreach($user_fields as $k=>$v)
40
- $user_fields[$k] = 'USER_'.$v;
41
- $fields = array_unique( array_merge( $fields, $user_fields ) );
 
42
  sort( $fields );
43
  //debug set_transient( $transient_key, $fields, 60 ); //valid for a 1 min
44
  }
 
45
  return apply_filters( 'woe_get_all_order_custom_meta_fields', $fields );
46
  }
47
 
@@ -65,7 +68,7 @@ class WC_Order_Export_Data_Extractor_UI extends WC_Order_Export_Data_Extractor {
65
  $wp_fields = $wpdb->get_col( "SELECT DISTINCT meta_key FROM {$wpdb->postmeta} WHERE post_id IN
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 );
@@ -82,9 +85,8 @@ class WC_Order_Export_Data_Extractor_UI extends WC_Order_Export_Data_Extractor {
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 );
@@ -99,7 +101,7 @@ class WC_Order_Export_Data_Extractor_UI extends WC_Order_Export_Data_Extractor {
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
  }
@@ -118,7 +120,7 @@ class WC_Order_Export_Data_Extractor_UI extends WC_Order_Export_Data_Extractor {
118
  // WP internal table , skip hidden and attributes
119
  $wp_fields = self::get_product_custom_fields();
120
 
121
- $fields = array_unique( array_merge( $wp_fields, $wc_fields ) );
122
  sort( $fields );
123
 
124
  return apply_filters( 'woe_get_all_product_custom_meta_fields', $fields );
@@ -137,7 +139,7 @@ class WC_Order_Export_Data_Extractor_UI extends WC_Order_Export_Data_Extractor {
137
 
138
  //for FILTERS
139
 
140
- public static function get_products_like( $like ) {
141
  global $wpdb;
142
  $like = $wpdb->esc_like( $like );
143
  $query = "
@@ -149,17 +151,18 @@ class WC_Order_Export_Data_Extractor_UI extends WC_Order_Export_Data_Extractor {
149
  AND post.post_status <> 'trash'
150
  GROUP BY post.ID
151
  ORDER BY post.post_title
152
- LIMIT 0,5
153
- ";
154
  $products = $wpdb->get_results( $query );
155
  foreach ( $products as $key => $product ) {
156
  if ( $product->photo_id ) {
157
  $photo = wp_get_attachment_image_src( $product->photo_id, 'thumbnail' );
158
  $products[ $key ]->photo_url = $photo[0];
159
- }
160
- else
161
  unset( $products[ $key ]->photo_url );
 
162
  }
 
163
  return $products;
164
  }
165
 
@@ -168,14 +171,15 @@ class WC_Order_Export_Data_Extractor_UI extends WC_Order_Export_Data_Extractor {
168
  $ret = array();
169
 
170
  $like = '*' . $wpdb->esc_like( $like ) . '*';
171
- $users = get_users( array( 'search' => $like , 'orderby' => 'display_name' ) );
172
 
173
  foreach ( $users as $key => $user ) {
174
  $ret[] = array(
175
- 'id' => $user->ID,
176
- 'text' => $user->display_name
177
  );
178
  }
 
179
  return $ret;
180
  }
181
 
@@ -192,61 +196,81 @@ class WC_Order_Export_Data_Extractor_UI extends WC_Order_Export_Data_Extractor {
192
  ORDER BY post.post_title
193
  LIMIT 0,10
194
  ";
 
195
  return $wpdb->get_results( $query );
196
  }
197
 
198
  public static function get_categories_like( $like ) {
199
  $cat = array();
200
- foreach (get_terms( 'product_cat','hide_empty=0&hierarchical=1&name__like=' . $like . '&number=10' ) as $term ) {
 
 
201
  $cat[] = array( "id" => $term->term_id, "text" => $term->name );
202
  }
 
203
  return $cat;
204
  }
205
 
206
  public static function get_order_custom_fields_values( $key ) {
207
  global $wpdb;
208
- $values = $wpdb->get_col( $wpdb->prepare( "SELECT DISTINCT meta_value FROM {$wpdb->postmeta} WHERE meta_key = %s AND post_id IN (SELECT DISTINCT ID FROM {$wpdb->posts} WHERE post_type = '" . self::$object_type . "' )" , $key ) );
 
 
 
 
 
 
 
 
 
 
209
  sort( $values );
 
210
  return $values;
211
  }
212
 
213
  public static function get_product_custom_fields_values( $key ) {
214
  global $wpdb;
215
- $values = $wpdb->get_col( $wpdb->prepare( "SELECT DISTINCT meta_value FROM {$wpdb->postmeta} WHERE meta_key = %s AND post_id IN (SELECT DISTINCT ID FROM {$wpdb->posts} WHERE post_type = 'product_variation' OR post_type = 'product')" , $key ) );
 
216
  sort( $values );
 
217
  return $values;
218
  }
219
 
220
  public static function get_products_taxonomies_values( $key ) {
221
  $values = array();
222
- $terms = get_terms( array( 'taxonomy' => $key ) );
223
  if ( ! empty( $terms ) ) {
224
  $values = array_map( function ( $term ) {
225
  return $term->name;
226
  }, $terms );
227
  }
228
  sort( $values );
 
229
  return $values;
230
  }
231
 
232
  public static function get_products_itemmeta_values( $key ) {
233
- global $wpdb;
234
- $max_len = apply_filters( 'woe_itemmeta_values_max_length', 50 );
235
- $limit = apply_filters( 'woe_itemmeta_values_max_records', 200 );
236
- $meta_key_ent = esc_html($key);
237
- $metas = $wpdb->get_col( $wpdb->prepare("SELECT DISTINCT meta_value FROM {$wpdb->prefix}woocommerce_order_itemmeta where (meta_key = '%s' OR meta_key='%s') AND LENGTH(meta_value) <= $max_len LIMIT $limit", $key, $meta_key_ent ));
 
238
  sort( $metas );
 
239
  return $metas;
240
  }
241
 
242
  public static function get_products_attributes_values( $key ) {
243
- $data = array();
244
  $attrs = wc_get_attribute_taxonomies();
245
  foreach ( $attrs as $item ) {
246
  if ( $item->attribute_label == $key && $item->attribute_type != 'select' ) {
247
  break;
248
  } elseif ( $item->attribute_label == $key ) {
249
- $name = wc_attribute_taxonomy_name( $item->attribute_name );
250
  $values = get_terms( $name, array( 'hide_empty' => false ) );
251
  if ( is_array( $values ) ) {
252
  $data = array_map( function ( $elem ) {
@@ -257,95 +281,227 @@ class WC_Order_Export_Data_Extractor_UI extends WC_Order_Export_Data_Extractor {
257
  }
258
  }
259
  sort( $data );
 
260
  return $data;
261
  }
262
 
263
  public static function get_order_meta_values( $type, $key ) {
264
  global $wpdb;
265
- $query = $wpdb->prepare( 'SELECT DISTINCT meta_value FROM ' . $wpdb->postmeta . ' WHERE meta_key = %s',array( $type . strtolower( $key ) ) );
 
266
  $results = $wpdb->get_col( $query );
267
  $data = array_filter( $results );
268
  sort( $data );
 
269
  return $data;
270
  }
271
-
272
  public static function get_order_item_names( $type ) {
273
- global $wpdb;
274
-
275
- $names = $wpdb->get_col( $wpdb->prepare("SELECT DISTINCT order_item_name FROM {$wpdb->prefix}woocommerce_order_items WHERE order_item_type = %s ORDER BY order_item_id DESC LIMIT 1000", $type) );
276
- sort($names);
 
 
277
  return $names;
278
  }
279
-
280
  public static function get_item_meta_keys() {
281
- global $wpdb;
282
-
283
  $names = $wpdb->get_results( "SELECT distinct order_item_type,meta_key FROM {$wpdb->prefix}woocommerce_order_items AS items
284
  INNER JOIN (SELECT ID AS order_id FROM {$wpdb->prefix}posts WHERE post_type='shop_order' ORDER BY ID DESC LIMIT 1000) AS orders ON orders.order_id = items.order_id
285
  JOIN {$wpdb->prefix}woocommerce_order_itemmeta AS meta ON meta.order_item_id = items.order_item_id
286
  ORDER BY order_item_type,meta_key" );
287
-
288
  $keys = array();
289
- foreach($names as $n)
290
- $keys[$n->order_item_type][$n->meta_key] = $n->meta_key;
 
 
291
  return $keys;
292
  }
293
-
294
  public static function get_order_item_meta_key_values( $meta_key ) {
295
- global $wpdb;
296
-
297
- self::extract_item_type_and_key( $meta_key , $type, $key );
298
-
299
- //we skip serialized and long values!
300
  $values = $wpdb->get_col( $wpdb->prepare( "SELECT distinct meta_value FROM {$wpdb->prefix}woocommerce_order_items AS items
301
  JOIN {$wpdb->prefix}woocommerce_order_itemmeta AS meta ON meta.order_item_id = items.order_item_id
302
  WHERE items.order_item_type = %s AND meta.meta_key=%s
303
  AND meta_value NOT LIKE 'a:%' AND LENGTH(meta_value)<20
304
- ORDER BY meta_value", $type,$key ) );
 
305
  return $values;
306
  }
307
 
308
-
309
-
310
 
311
  public static function get_order_product_fields( $format ) {
312
  $map = array(
313
- 'item_id' => array( 'label' => __( 'Item ID', 'woo-order-export-lite' ), 'checked' => 0 ),
314
- 'line_id' => array( 'label' => __( 'Item #', 'woo-order-export-lite' ), 'checked' => 1 ),
315
- 'sku' => array( 'label' => __( 'SKU', 'woo-order-export-lite' ), 'checked' => 1 ),
316
- 'name' => array( 'label' => __( 'Item Name', 'woo-order-export-lite' ), 'checked' => 1 ),
317
- 'product_name'=> array( 'label' => __( 'Product Name', 'woo-order-export-lite' ), 'checked' => 0 ),
318
- 'product_variation' => array( 'label' => __( 'Product Variation', 'woo-order-export-lite' ), 'checked' => 0 ),
319
- 'seller' => array( 'label' => __( 'Item Seller', 'woo-order-export-lite' ), 'checked' => 0 ),
320
- 'qty' => array( 'label' => __( 'Quantity', 'woo-order-export-lite' ), 'checked' => 1 ),
321
- 'qty_minus_refund' => array( 'label' => __( 'Quantity (- Refund)', 'woo-order-export-lite' ), 'checked' => 0 ),
322
- 'item_price' => array( 'label' => __( 'Item Cost', 'woo-order-export-lite' ), 'checked' => 1, 'format'=>'money' ),
323
- 'price' => array( 'label' => __( 'Product Current Price', 'woo-order-export-lite' ), 'checked' => 0, 'format'=>'money' ),
324
- 'line_no_tax' => array( 'label' => __( 'Order Line (w/o tax)', 'woo-order-export-lite' ), 'checked' => 0, 'format'=>'money' ),
325
- 'line_tax' => array( 'label' => __( 'Order Line Tax', 'woo-order-export-lite' ), 'checked' => 0, 'format'=>'money' ),
326
- 'line_tax_refunded'=> array( 'label' => __( 'Order Line Tax Refunded', 'woo-order-export-lite' ), 'checked' => 0, 'format'=>'money' ),
327
- 'line_tax_minus_refund'=> array( 'label' => __( 'Order Line Tax (- Refund)', 'woo-order-export-lite' ), 'checked' => 0, 'format'=>'money' ),
328
- 'line_subtotal'=>array( 'label' => __( 'Order Line Subtotal', 'woo-order-export-lite' ), 'checked' => 0, 'format'=>'money' ),
329
- 'line_total' => array( 'label' => __( 'Order Line Total', 'woo-order-export-lite' ), 'checked' => 0, 'format'=>'money' ),
330
- 'line_total_plus_tax' => array( 'label' => __( 'Order Line Total (include tax)', 'woo-order-export-lite' ), 'checked' => 0, 'format'=>'money' ),
331
- 'line_total_refunded' => array( 'label' => __( 'Order Line Total Refunded', 'woo-order-export-lite' ), 'checked' => 0, 'format'=>'money' ),
332
- 'line_total_minus_refund' => array( 'label' => __( 'Order Line Total (- Refund)', 'woo-order-export-lite' ), 'checked' => 0, 'format'=>'money' ),
333
- 'discount_amount' => array( 'label' => __( 'Item Discount Amount', 'woo-order-export-lite'), 'checked' => 0, 'format'=>'money' ),
334
- 'tax_rate' => array( 'label' => __( 'Item Tax Rate', 'woo-order-export-lite' ), 'checked' => 0, 'format'=>'number' ),
335
- 'type' => array( 'label' => __( 'Type', 'woo-order-export-lite' ), 'checked' => 0 ),
336
- 'category' => array( 'label' => __( 'Category', 'woo-order-export-lite' ), 'checked' => 0 ),
337
- 'tags' => array( 'label' => __( 'Tags', 'woo-order-export-lite' ), 'checked' => 0 ),
338
- 'width' => array( 'label' => __( 'Width', 'woo-order-export-lite' ), 'checked' => 0, 'format'=>'number' ),
339
- 'length' => array( 'label' => __( 'Length', 'woo-order-export-lite' ), 'checked' => 0, 'format'=>'number' ),
340
- 'height' => array( 'label' => __( 'Height', 'woo-order-export-lite' ), 'checked' => 0, 'format'=>'number' ),
341
- 'weight' => array( 'label' => __( 'Weight', 'woo-order-export-lite' ), 'checked' => 0, 'format'=>'number' ),
342
- 'product_url' => array( 'label' => __( 'Product URL', 'woo-order-export-lite' ), 'checked' => 0 ),
343
- 'download_url' => array( 'label' => __( 'Download URL', 'woo-order-export-lite' ), 'checked' => 0 ),
344
- 'image_url' => array( 'label' => __( 'Image URL', 'woo-order-export-lite' ), 'checked' => 0 ),
345
- 'product_shipping_class' => array( 'label' => __( 'Product Shipping Class', 'woo-order-export-lite' ), 'checked' => 0 ),
346
- 'post_content'=> array( 'label' => __( 'Description', 'woo-order-export-lite' ), 'checked' => 0 ),
347
- 'post_excerpt'=> array( 'label' => __( 'Short Description', 'woo-order-export-lite' ), 'checked' => 0 ),
348
- 'full_category_names' => array( 'label' => __( 'Full names for categories', 'woo-order-export-lite' ), 'checked' => 0 )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
349
  );
350
 
351
  foreach ( $map as $key => $value ) {
@@ -358,13 +514,37 @@ class WC_Order_Export_Data_Extractor_UI extends WC_Order_Export_Data_Extractor {
358
 
359
  public static function get_order_coupon_fields( $format ) {
360
  $map = array(
361
- 'code' => array( 'label' => __( 'Coupon Code', 'woo-order-export-lite' ), 'checked' => 1 ),
362
- 'discount_amount' => array( 'label' => __( 'Discount Amount', 'woo-order-export-lite' ), 'checked' => 1, 'format'=>'money' ),
363
- 'discount_amount_tax' => array( 'label' => __( 'Discount Amount Tax', 'woo-order-export-lite' ), 'checked' => 1, 'format'=>'money' ),
364
- 'discount_amount_plus_tax' => array( 'label' => __( 'Discount Amount + Tax', 'woo-order-export-lite' ), 'checked' => 0 ),
365
- 'excerpt' => array( 'label' => __( 'Coupon Description', 'woo-order-export-lite' ), 'checked' => 0 ),
366
- 'discount_type' => array( 'label' => __( 'Coupon Type', 'woo-order-export-lite' ), 'checked'=> 0 ),
367
- 'coupon_amount' => array( 'label' => __( 'Coupon Amount', 'woo-order-export-lite' ), 'checked'=> 0, 'format'=>'money' ),
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
368
  );
369
 
370
  foreach ( $map as $key => $value ) {
@@ -401,118 +581,419 @@ class WC_Order_Export_Data_Extractor_UI extends WC_Order_Export_Data_Extractor {
401
  'order_id' => array( 'label' => __( 'Order ID', 'woo-order-export-lite' ), 'checked' => 0 ),
402
  'order_number' => array( 'label' => __( 'Order Number', 'woo-order-export-lite' ), 'checked' => 1 ),
403
  'order_status' => array( 'label' => __( 'Order Status', 'woo-order-export-lite' ), 'checked' => 1 ),
404
- 'order_date' => array( 'label' => __( 'Order Date', 'woo-order-export-lite' ), 'checked' => 1, 'format'=>'date' ),
405
- 'modified_date' => array( 'label' => __( 'Modification Date', 'woo-order-export-lite' ), 'checked' => 0, 'format'=>'date' ),
406
- 'transaction_id' => array( 'label' => __( 'Transaction ID', 'woo-order-export-lite' ), 'checked' => 0 ),
407
- 'completed_date' => array( 'label' => __( 'Completed Date', 'woo-order-export-lite' ), 'checked' => 0, 'format'=>'date' ),
408
- 'paid_date' => array( 'label' => __( 'Paid Date', 'woo-order-export-lite' ), 'checked' => 0, 'format'=>'date' ),
409
- 'first_refund_date' => array( 'label' => __( 'Date of first refund', 'woo-order-export-lite' ), 'checked' => 0, 'format'=>'date' ),
410
- 'customer_note' => array( 'label' => __( 'Customer Note', 'woo-order-export-lite' ), 'checked' => 1, 'format'=>'string' ),
411
- 'order_notes' => array( 'label' => __( 'Order Notes', 'woo-order-export-lite' ), 'checked' => 0, 'format'=>'string' ),
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
412
  );
413
  }
414
 
415
  public static function get_order_fields_user() {
416
  return array(
417
- 'customer_ip_address' => array( 'label' => __( 'Customer IP address', 'woo-order-export-lite' ), 'checked' => 0 ),
418
- 'customer_user' => array( 'label' => __( 'Customer User ID', 'woo-order-export-lite' ), 'checked' => 0 ),
419
- 'user_login' => array( 'label' => __( 'Customer Username', 'woo-order-export-lite' ), 'checked' => 0 ),
420
- 'user_email' => array( 'label' => __( 'Customer User Email', 'woo-order-export-lite' ), 'checked' => 0 ),
421
- 'user_role' => array( 'label' => __( 'Customer Role', 'woo-order-export-lite' ), 'checked' => 0 ),
422
- 'customer_total_orders' => array( 'label' => __( 'Customer Total Orders', 'woo-order-export-lite' ), 'checked' => 0 ),
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
423
  );
424
  }
425
 
426
  public static function get_order_fields_billing() {
427
  return array(
428
- 'billing_first_name' => array( 'label' => __( 'First Name (Billing)', 'woo-order-export-lite' ), 'checked' => 1 ),
429
- 'billing_last_name' => array( 'label' => __( 'Last Name (Billing)', 'woo-order-export-lite' ), 'checked' => 1 ),
430
- 'billing_full_name' => array( 'label' => __( 'Full Name (Billing)', 'woo-order-export-lite' ), 'checked' => 0 ),
431
- 'billing_company' => array( 'label' => __( 'Company (Billing)', 'woo-order-export-lite' ), 'checked' => 1 ),
432
- 'billing_address' => array( 'label' => __( 'Address 1&2 (Billing)', 'woo-order-export-lite' ), 'checked' => 1 ),
433
- 'billing_address_1' => array( 'label' => __( 'Address 1 (Billing)', 'woo-order-export-lite' ), 'checked' => 0 ),
434
- 'billing_address_2' => array( 'label' => __( 'Address 2 (Billing)', 'woo-order-export-lite' ), 'checked' => 0 ),
435
- 'billing_city' => array( 'label' => __( 'City (Billing)', 'woo-order-export-lite' ), 'checked' => 1 ),
436
- 'billing_state' => array( 'label' => __( 'State Code (Billing)', 'woo-order-export-lite' ), 'checked' => 1 ),
437
- 'billing_citystatezip' => array( 'label' => __( 'City, State, Zip (Billing)', 'woo-order-export-lite' ), 'checked' => 0 ),
438
- 'billing_state_full' => array( 'label' => __( 'State Name (Billing)', 'woo-order-export-lite' ), 'checked' => 0 ),
439
- 'billing_postcode' => array( 'label' => __( 'Postcode (Billing)', 'woo-order-export-lite' ), 'checked' => 1 ),
440
- 'billing_country' => array( 'label' => __( 'Country Code (Billing)', 'woo-order-export-lite' ), 'checked' => 1 ),
441
- 'billing_country_full' => array( 'label' => __( 'Country Name (Billing)', 'woo-order-export-lite' ), 'checked' => 0 ),
442
- 'billing_email' => array( 'label' => __( 'Email (Billing)', 'woo-order-export-lite' ), 'checked' => 1 ),
443
- 'billing_phone' => array( 'label' => __( 'Phone (Billing)', 'woo-order-export-lite' ), 'checked' => 1, 'format'=>'string' ),
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
444
  );
445
  }
446
 
447
  public static function get_order_fields_shipping() {
448
  return array(
449
- 'shipping_first_name' => array( 'label' => __( 'First Name (Shipping)', 'woo-order-export-lite' ), 'checked' => 1 ),
450
- 'shipping_last_name' => array( 'label' => __( 'Last Name (Shipping)', 'woo-order-export-lite' ), 'checked' => 1 ),
451
- 'shipping_full_name' => array( 'label' => __( 'Full Name (Shipping)', 'woo-order-export-lite' ), 'checked' => 0 ),
452
- 'shipping_company' => array( 'label' => __( 'Company (Shipping)', 'woo-order-export-lite' ), 'checked' => 0 ),
453
- 'shipping_address' => array( 'label' => __( 'Address 1&2 (Shipping)', 'woo-order-export-lite' ), 'checked' => 1 ),
454
- 'shipping_address_1' => array( 'label' => __( 'Address 1 (Shipping)', 'woo-order-export-lite' ), 'checked' => 0 ),
455
- 'shipping_address_2' => array( 'label' => __( 'Address 2 (Shipping)', 'woo-order-export-lite' ), 'checked' => 0 ),
456
- 'shipping_city' => array( 'label' => __( 'City (Shipping)', 'woo-order-export-lite' ), 'checked' => 1 ),
457
- 'shipping_state' => array( 'label' => __( 'State Code (Shipping)', 'woo-order-export-lite' ), 'checked' => 1 ),
458
- 'shipping_citystatezip' => array( 'label' => __( 'City, State, Zip (Shipping)', 'woo-order-export-lite' ), 'checked' => 0 ),
459
- 'shipping_state_full' => array( 'label' => __( 'State Name (Shipping)', 'woo-order-export-lite' ), 'checked' => 0 ),
460
- 'shipping_postcode' => array( 'label' => __( 'Postcode (Shipping)', 'woo-order-export-lite' ), 'checked' => 1 ),
461
- 'shipping_country' => array( 'label' => __( 'Country Code (Shipping)', 'woo-order-export-lite' ), 'checked' => 1 ),
462
- 'shipping_country_full' => array( 'label' => __( 'Country Name (Shipping)', 'woo-order-export-lite' ), 'checked' => 0 ),
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
463
  );
464
  }
465
 
466
  // meta
467
  public static function get_order_fields_product() {
468
  return array(
469
- 'products' => array( 'label' => __( 'Products', 'woo-order-export-lite' ), 'checked' => 1, 'repeat' => 'rows' , 'max_cols'=>10 ),
 
 
 
 
 
470
  );
471
  }
472
 
473
  // meta
474
  public static function get_order_fields_coupon() {
475
  return array(
476
- 'coupons' => array( 'label' => __( 'Coupons', 'woo-order-export-lite' ), 'checked' => 1, 'repeat' => 'rows' , 'max_cols'=>10 ),
 
 
 
 
 
477
  );
478
  }
479
 
480
  public static function get_order_fields_cart() {
481
  return array(
482
- 'shipping_method_title' => array( 'label' => __( 'Shipping Method Title', 'woo-order-export-lite' ), 'checked' => 1 ),
483
- 'shipping_method' => array( 'label' => __( 'Shipping Method', 'woo-order-export-lite' ), 'checked' => 0 ),
484
- 'payment_method_title' => array( 'label' => __( 'Payment Method Title', 'woo-order-export-lite' ), 'checked' => 1 ),
485
- 'payment_method' => array( 'label' => __( 'Payment Method', 'woo-order-export-lite' ), 'checked' => 0 ),
486
- 'coupons_used' => array( 'label' => __( 'Coupons Used', 'woo-order-export-lite' ), 'checked' => 0 ),
487
- 'cart_discount' => array( 'label' => __( 'Cart Discount Amount', 'woo-order-export-lite' ), 'checked' => 1, 'format'=>'money' ),
488
- 'cart_discount_tax' => array( 'label' => __( 'Cart Discount Amount Tax', 'woo-order-export-lite' ), 'checked' => 0, 'format'=>'money' ),
489
- 'order_subtotal' => array( 'label' => __( 'Order Subtotal Amount', 'woo-order-export-lite' ), 'checked' => 1, 'format'=>'money' ),
490
- 'order_subtotal_minus_discount' => array( 'label' => 'Order Subtotal - Cart Discount', 'colname' => 'Order Subtotal - Cart Discount', 'checked' => 0 ),
491
- 'order_subtotal_refunded'=> array( 'label' => __( 'Order Subtotal Amount Refunded', 'woo-order-export-lite' ), 'checked' => 0, 'format'=>'money' ),
492
- 'order_subtotal_minus_refund'=> array( 'label' => __( 'Order Subtotal Amount (- Refund)', 'woo-order-export-lite' ), 'checked' => 0, 'format'=>'money' ),
493
- 'order_tax' => array( 'label' => __( 'Order Tax Amount', 'woo-order-export-lite' ), 'checked' => 0, 'format'=>'money' ),
494
- 'order_shipping' => array( 'label' => __( 'Order Shipping Amount', 'woo-order-export-lite' ), 'checked' => 1, 'format'=>'money' ),
495
- 'order_shipping_refunded' => array( 'label' => __( 'Order Shipping Amount Refunded', 'woo-order-export-lite' ), 'checked' => 0, 'format'=>'money' ),
496
- 'order_shipping_minus_refund' => array( 'label' => __( 'Order Shipping Amount (- Refund)', 'woo-order-export-lite' ), 'checked' => 0, 'format'=>'money' ),
497
- 'order_shipping_tax' => array( 'label' => __( 'Order Shipping Tax Amount', 'woo-order-export-lite' ), 'checked' => 0, 'format'=>'money' ),
498
- 'order_shipping_tax_refunded' => array( 'label' => __( 'Order Shipping Tax Refunded', 'woo-order-export-lite' ), 'checked' => 0, 'format'=>'money' ),
499
- 'order_shipping_tax_minus_refund' => array( 'label' => __( 'Order Shipping Tax Amount (- Refund)', 'woo-order-export-lite' ), 'checked' => 0 , 'format'=>'money'),
500
- 'order_refund' => array( 'label' => __( 'Order Refund Amount', 'woo-order-export-lite' ), 'checked' => 1, 'format'=>'money' ),
501
- 'order_total_inc_refund'=> array( 'label' => __( 'Order Total Amount (- Refund)', 'woo-order-export-lite' ), 'checked' => 0, 'format'=>'money' ),
502
- 'order_total' => array( 'label' => __( 'Order Total Amount', 'woo-order-export-lite' ), 'checked' => 1, 'format'=>'money' ),
503
- 'order_total_no_tax' => array( 'label' => __( 'Order Total Amount without Tax', 'woo-order-export-lite' ), 'checked' => 0, 'format'=>'money' ),
504
- 'order_total_tax' => array( 'label' => __( 'Order Total Tax Amount', 'woo-order-export-lite' ), 'checked' => 1, 'format'=>'money' ),
505
- 'order_total_tax_refunded' => array( 'label' => __( 'Order Total Tax Amount Refunded', 'woo-order-export-lite' ), 'checked' => 0, 'format'=>'money' ),
506
- 'order_total_tax_minus_refund' => array( 'label' => __( 'Order Total Tax Amount (- Refund)', 'woo-order-export-lite' ), 'checked' => 0, 'format'=>'money' ),
507
- 'order_currency' => array( 'label' => __( 'Currency', 'woo-order-export-lite' ), 'checked' => 0 ),
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
508
  );
509
  }
510
 
511
  public static function get_order_fields_misc() {
512
  return array(
513
- 'total_weight_items' => array( 'label' => __( 'Total weight', 'woo-order-export-lite' ), 'checked' => 0, 'format'=>'number' ),
514
- 'count_total_items' => array( 'label' => __( 'Total items', 'woo-order-export-lite' ), 'checked' => 0 ),
515
- 'count_unique_products' => array( 'label' => __( 'Total products', 'woo-order-export-lite' ), 'checked' => 0 ),
 
 
 
 
 
 
 
 
 
 
 
 
 
 
516
  );
517
  }
518
 
@@ -536,8 +1017,8 @@ class WC_Order_Export_Data_Extractor_UI extends WC_Order_Export_Data_Extractor {
536
  'shipping' => __( 'Shipping', 'woo-order-export-lite' ),
537
  'product' => __( 'Products', 'woo-order-export-lite' ),
538
  'coupon' => __( 'Coupons', 'woo-order-export-lite' ),
539
- 'cart' => __( 'Cart', 'woo-order-export-lite'),
540
- 'misc' => __( 'Others', 'woo-order-export-lite' )
541
  );
542
  }
543
 
8
  const HUGE_SHOP_CUSTOMERS = 1000;// more than 1000 customers
9
 
10
  // ADD custom fields for export
11
+ public static function get_all_order_custom_meta_fields( $sql_order_ids = '' ) {
12
  global $wpdb;
13
 
14
+ $transient_key = 'woe_get_all_order_custom_meta_fields_results_' . md5( json_encode( $sql_order_ids ) ); // complex key
15
+ $fields = get_transient( $transient_key );
16
+ if ( $fields === false ) {
17
  $sql_in_orders = '';
18
+ if ( $sql_order_ids ) {
19
+ $sql_in_orders = " AND ID IN ($sql_order_ids) ";
20
+ }
21
 
22
  // must show all
23
+ if ( ! $sql_in_orders ) {
24
  //rewrite for huge # of users
25
  $total_users = $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->users}" );
26
+ if ( $total_users >= self::HUGE_SHOP_CUSTOMERS ) {
27
+ $user_ids = $wpdb->get_col( "SELECT ID FROM {$wpdb->users} ORDER BY ID DESC LIMIT 1000" ); // take last 1000
28
+ $user_ids = join( ",", $user_ids );
29
  $where_users = "WHERE user_id IN ($user_ids)";
30
+ } else {
 
31
  $where_users = '';
32
+ }
33
  $user_fields = $wpdb->get_col( "SELECT DISTINCT meta_key FROM {$wpdb->usermeta} $where_users" );
34
+ $fields = self::get_order_custom_fields();
35
+ } else {
36
  $user_fields = $wpdb->get_col( "SELECT DISTINCT meta_key FROM {$wpdb->posts} INNER JOIN {$wpdb->usermeta} ON {$wpdb->posts}.post_author = {$wpdb->usermeta}.user_id WHERE post_type = '" . self::$object_type . "' {$sql_in_orders}" );
37
+ $fields = $wpdb->get_col( "SELECT DISTINCT meta_key FROM {$wpdb->posts} INNER JOIN {$wpdb->postmeta} ON {$wpdb->posts}.ID = {$wpdb->postmeta}.post_id WHERE post_type = '" . self::$object_type . "' {$sql_in_orders}" );
38
  }
39
 
40
+ foreach ( $user_fields as $k => $v ) {
41
+ $user_fields[ $k ] = 'USER_' . $v;
42
+ }
43
+ $fields = array_unique( array_merge( $fields, $user_fields ) );
44
  sort( $fields );
45
  //debug set_transient( $transient_key, $fields, 60 ); //valid for a 1 min
46
  }
47
+
48
  return apply_filters( 'woe_get_all_order_custom_meta_fields', $fields );
49
  }
50
 
68
  $wp_fields = $wpdb->get_col( "SELECT DISTINCT meta_key FROM {$wpdb->postmeta} WHERE post_id IN
69
  (SELECT DISTINCT ID FROM {$wpdb->posts} WHERE post_type IN ('product','product_variation') AND ID IN ($sql_products))" );
70
 
71
+ $fields = array_unique( array_merge( $wp_fields, $wc_fields ) );
72
  $fields = sort( $fields );
73
 
74
  return apply_filters( 'get_all_product_custom_meta_fields_for_orders', $fields );
85
  $wc_fields[] = 'pa_' . $f->attribute_name;
86
  }
87
 
88
+ $wc_fields = array_unique( $wc_fields );
89
+ sort( $wc_fields );
 
90
 
91
 
92
  return apply_filters( 'get_order_item_custom_meta_fields_for_orders', $wc_fields );
101
  $wp_fields = $wpdb->get_col( "SELECT DISTINCT meta_key FROM {$wpdb->postmeta} WHERE post_id IN
102
  (SELECT DISTINCT ID FROM {$wpdb->posts} WHERE post_type IN ('product','product_variation') AND ID IN ($sql_products))" );
103
 
104
+ sort( $wp_fields );
105
 
106
  return apply_filters( 'get_product_custom_meta_fields_for_orders', $wp_fields );
107
  }
120
  // WP internal table , skip hidden and attributes
121
  $wp_fields = self::get_product_custom_fields();
122
 
123
+ $fields = array_unique( array_merge( $wp_fields, $wc_fields ) );
124
  sort( $fields );
125
 
126
  return apply_filters( 'woe_get_all_product_custom_meta_fields', $fields );
139
 
140
  //for FILTERS
141
 
142
+ public static function get_products_like( $like, $limit ) {
143
  global $wpdb;
144
  $like = $wpdb->esc_like( $like );
145
  $query = "
151
  AND post.post_status <> 'trash'
152
  GROUP BY post.ID
153
  ORDER BY post.post_title
154
+ LIMIT " . intval($limit);
155
+
156
  $products = $wpdb->get_results( $query );
157
  foreach ( $products as $key => $product ) {
158
  if ( $product->photo_id ) {
159
  $photo = wp_get_attachment_image_src( $product->photo_id, 'thumbnail' );
160
  $products[ $key ]->photo_url = $photo[0];
161
+ } else {
 
162
  unset( $products[ $key ]->photo_url );
163
+ }
164
  }
165
+
166
  return $products;
167
  }
168
 
171
  $ret = array();
172
 
173
  $like = '*' . $wpdb->esc_like( $like ) . '*';
174
+ $users = get_users( array( 'search' => $like, 'orderby' => 'display_name' ) );
175
 
176
  foreach ( $users as $key => $user ) {
177
  $ret[] = array(
178
+ 'id' => $user->ID,
179
+ 'text' => $user->display_name,
180
  );
181
  }
182
+
183
  return $ret;
184
  }
185
 
196
  ORDER BY post.post_title
197
  LIMIT 0,10
198
  ";
199
+
200
  return $wpdb->get_results( $query );
201
  }
202
 
203
  public static function get_categories_like( $like ) {
204
  $cat = array();
205
+ foreach (
206
+ get_terms( 'product_cat', 'hide_empty=0&hierarchical=1&name__like=' . $like . '&number=10' ) as $term
207
+ ) {
208
  $cat[] = array( "id" => $term->term_id, "text" => $term->name );
209
  }
210
+
211
  return $cat;
212
  }
213
 
214
  public static function get_order_custom_fields_values( $key ) {
215
  global $wpdb;
216
+ $values = $wpdb->get_col( $wpdb->prepare( "SELECT DISTINCT meta_value FROM {$wpdb->postmeta} WHERE meta_key = %s AND post_id IN (SELECT DISTINCT ID FROM {$wpdb->posts} WHERE post_type = '" . self::$object_type . "' )",
217
+ $key ) );
218
+ sort( $values );
219
+
220
+ return $values;
221
+ }
222
+
223
+ public static function get_user_custom_fields_values( $key ) {
224
+ global $wpdb;
225
+ $values = $wpdb->get_col( $wpdb->prepare( "SELECT DISTINCT meta_value FROM {$wpdb->usermeta} WHERE meta_key = %s",
226
+ $key ) );
227
  sort( $values );
228
+
229
  return $values;
230
  }
231
 
232
  public static function get_product_custom_fields_values( $key ) {
233
  global $wpdb;
234
+ $values = $wpdb->get_col( $wpdb->prepare( "SELECT DISTINCT meta_value FROM {$wpdb->postmeta} WHERE meta_key = %s AND post_id IN (SELECT DISTINCT ID FROM {$wpdb->posts} WHERE post_type = 'product_variation' OR post_type = 'product')",
235
+ $key ) );
236
  sort( $values );
237
+
238
  return $values;
239
  }
240
 
241
  public static function get_products_taxonomies_values( $key ) {
242
  $values = array();
243
+ $terms = get_terms( array( 'taxonomy' => $key ) );
244
  if ( ! empty( $terms ) ) {
245
  $values = array_map( function ( $term ) {
246
  return $term->name;
247
  }, $terms );
248
  }
249
  sort( $values );
250
+
251
  return $values;
252
  }
253
 
254
  public static function get_products_itemmeta_values( $key ) {
255
+ global $wpdb;
256
+ $max_len = apply_filters( 'woe_itemmeta_values_max_length', 50 );
257
+ $limit = apply_filters( 'woe_itemmeta_values_max_records', 200 );
258
+ $meta_key_ent = esc_html( $key );
259
+ $metas = $wpdb->get_col( $wpdb->prepare( "SELECT DISTINCT meta_value FROM {$wpdb->prefix}woocommerce_order_itemmeta where (meta_key = '%s' OR meta_key='%s') AND LENGTH(meta_value) <= $max_len LIMIT $limit",
260
+ $key, $meta_key_ent ) );
261
  sort( $metas );
262
+
263
  return $metas;
264
  }
265
 
266
  public static function get_products_attributes_values( $key ) {
267
+ $data = array();
268
  $attrs = wc_get_attribute_taxonomies();
269
  foreach ( $attrs as $item ) {
270
  if ( $item->attribute_label == $key && $item->attribute_type != 'select' ) {
271
  break;
272
  } elseif ( $item->attribute_label == $key ) {
273
+ $name = wc_attribute_taxonomy_name( $item->attribute_name );
274
  $values = get_terms( $name, array( 'hide_empty' => false ) );
275
  if ( is_array( $values ) ) {
276
  $data = array_map( function ( $elem ) {
281
  }
282
  }
283
  sort( $data );
284
+
285
  return $data;
286
  }
287
 
288
  public static function get_order_meta_values( $type, $key ) {
289
  global $wpdb;
290
+ $query = $wpdb->prepare( 'SELECT DISTINCT meta_value FROM ' . $wpdb->postmeta . ' WHERE meta_key = %s',
291
+ array( $type . strtolower( $key ) ) );
292
  $results = $wpdb->get_col( $query );
293
  $data = array_filter( $results );
294
  sort( $data );
295
+
296
  return $data;
297
  }
298
+
299
  public static function get_order_item_names( $type ) {
300
+ global $wpdb;
301
+
302
+ $names = $wpdb->get_col( $wpdb->prepare( "SELECT DISTINCT order_item_name FROM {$wpdb->prefix}woocommerce_order_items WHERE order_item_type = %s ORDER BY order_item_id DESC LIMIT 1000",
303
+ $type ) );
304
+ sort( $names );
305
+
306
  return $names;
307
  }
308
+
309
  public static function get_item_meta_keys() {
310
+ global $wpdb;
311
+
312
  $names = $wpdb->get_results( "SELECT distinct order_item_type,meta_key FROM {$wpdb->prefix}woocommerce_order_items AS items
313
  INNER JOIN (SELECT ID AS order_id FROM {$wpdb->prefix}posts WHERE post_type='shop_order' ORDER BY ID DESC LIMIT 1000) AS orders ON orders.order_id = items.order_id
314
  JOIN {$wpdb->prefix}woocommerce_order_itemmeta AS meta ON meta.order_item_id = items.order_item_id
315
  ORDER BY order_item_type,meta_key" );
316
+
317
  $keys = array();
318
+ foreach ( $names as $n ) {
319
+ $keys[ $n->order_item_type ][ $n->meta_key ] = $n->meta_key;
320
+ }
321
+
322
  return $keys;
323
  }
324
+
325
  public static function get_order_item_meta_key_values( $meta_key ) {
326
+ global $wpdb;
327
+
328
+ self::extract_item_type_and_key( $meta_key, $type, $key );
329
+
330
+ //we skip serialized and long values!
331
  $values = $wpdb->get_col( $wpdb->prepare( "SELECT distinct meta_value FROM {$wpdb->prefix}woocommerce_order_items AS items
332
  JOIN {$wpdb->prefix}woocommerce_order_itemmeta AS meta ON meta.order_item_id = items.order_item_id
333
  WHERE items.order_item_type = %s AND meta.meta_key=%s
334
  AND meta_value NOT LIKE 'a:%' AND LENGTH(meta_value)<20
335
+ ORDER BY meta_value", $type, $key ) );
336
+
337
  return $values;
338
  }
339
 
 
 
340
 
341
  public static function get_order_product_fields( $format ) {
342
  $map = array(
343
+ 'item_id' => array(
344
+ 'label' => __( 'Item ID', 'woo-order-export-lite' ),
345
+ 'checked' => 0,
346
+ ),
347
+ 'line_id' => array( 'label' => __( 'Item #', 'woo-order-export-lite' ), 'checked' => 1 ),
348
+ 'sku' => array( 'label' => __( 'SKU', 'woo-order-export-lite' ), 'checked' => 1 ),
349
+ 'name' => array(
350
+ 'label' => __( 'Item Name', 'woo-order-export-lite' ),
351
+ 'checked' => 1,
352
+ ),
353
+ 'product_id' => array(
354
+ 'label' => __( 'Product Id', 'woo-order-export-lite' ),
355
+ 'checked' => 0,
356
+ ),
357
+ 'product_name' => array(
358
+ 'label' => __( 'Product Name', 'woo-order-export-lite' ),
359
+ 'checked' => 0,
360
+ ),
361
+ 'variation_id' => array(
362
+ 'label' => __( 'Variation Id', 'woo-order-export-lite' ),
363
+ 'checked' => 0,
364
+ ),
365
+ 'product_variation' => array(
366
+ 'label' => __( 'Product Variation', 'woo-order-export-lite' ),
367
+ 'checked' => 0,
368
+ ),
369
+ 'seller' => array(
370
+ 'label' => __( 'Item Seller', 'woo-order-export-lite' ),
371
+ 'checked' => 0,
372
+ ),
373
+ 'qty' => array(
374
+ 'label' => __( 'Quantity', 'woo-order-export-lite' ),
375
+ 'checked' => 1,
376
+ ),
377
+ 'qty_minus_refund' => array(
378
+ 'label' => __( 'Quantity (- Refund)', 'woo-order-export-lite' ),
379
+ 'checked' => 0,
380
+ ),
381
+ 'item_price' => array(
382
+ 'label' => __( 'Item Cost', 'woo-order-export-lite' ),
383
+ 'checked' => 1,
384
+ 'format' => 'money',
385
+ ),
386
+ 'price' => array(
387
+ 'label' => __( 'Product Current Price', 'woo-order-export-lite' ),
388
+ 'checked' => 0,
389
+ 'format' => 'money',
390
+ ),
391
+ 'line_no_tax' => array(
392
+ 'label' => __( 'Order Line (w/o tax)', 'woo-order-export-lite' ),
393
+ 'checked' => 0,
394
+ 'format' => 'money',
395
+ ),
396
+ 'line_tax' => array(
397
+ 'label' => __( 'Order Line Tax', 'woo-order-export-lite' ),
398
+ 'checked' => 0,
399
+ 'format' => 'money',
400
+ ),
401
+ 'line_tax_refunded' => array(
402
+ 'label' => __( 'Order Line Tax Refunded', 'woo-order-export-lite' ),
403
+ 'checked' => 0,
404
+ 'format' => 'money',
405
+ ),
406
+ 'line_tax_minus_refund' => array(
407
+ 'label' => __( 'Order Line Tax (- Refund)', 'woo-order-export-lite' ),
408
+ 'checked' => 0,
409
+ 'format' => 'money',
410
+ ),
411
+ 'line_subtotal' => array(
412
+ 'label' => __( 'Order Line Subtotal', 'woo-order-export-lite' ),
413
+ 'checked' => 0,
414
+ 'format' => 'money',
415
+ ),
416
+ 'line_subtotal_tax' => array(
417
+ 'label' => __( 'Order Line Subtotal Tax', 'woo-order-export-lite' ),
418
+ 'checked' => 0,
419
+ 'format' => 'money',
420
+ ),
421
+ 'line_total' => array(
422
+ 'label' => __( 'Order Line Total', 'woo-order-export-lite' ),
423
+ 'checked' => 0,
424
+ 'format' => 'money',
425
+ ),
426
+ 'line_total_plus_tax' => array(
427
+ 'label' => __( 'Order Line Total (include tax)', 'woo-order-export-lite' ),
428
+ 'checked' => 0,
429
+ 'format' => 'money',
430
+ ),
431
+ 'line_total_refunded' => array(
432
+ 'label' => __( 'Order Line Total Refunded', 'woo-order-export-lite' ),
433
+ 'checked' => 0,
434
+ 'format' => 'money',
435
+ ),
436
+ 'line_total_minus_refund' => array(
437
+ 'label' => __( 'Order Line Total (- Refund)', 'woo-order-export-lite' ),
438
+ 'checked' => 0,
439
+ 'format' => 'money',
440
+ ),
441
+ 'discount_amount' => array(
442
+ 'label' => __( 'Item Discount Amount', 'woo-order-export-lite' ),
443
+ 'checked' => 0,
444
+ 'format' => 'money',
445
+ ),
446
+ 'tax_rate' => array(
447
+ 'label' => __( 'Item Tax Rate', 'woo-order-export-lite' ),
448
+ 'checked' => 0,
449
+ 'format' => 'number',
450
+ ),
451
+ 'type' => array( 'label' => __( 'Type', 'woo-order-export-lite' ), 'checked' => 0 ),
452
+ 'category' => array(
453
+ 'label' => __( 'Category', 'woo-order-export-lite' ),
454
+ 'checked' => 0,
455
+ ),
456
+ 'tags' => array( 'label' => __( 'Tags', 'woo-order-export-lite' ), 'checked' => 0 ),
457
+ 'width' => array(
458
+ 'label' => __( 'Width', 'woo-order-export-lite' ),
459
+ 'checked' => 0,
460
+ 'format' => 'number',
461
+ ),
462
+ 'length' => array(
463
+ 'label' => __( 'Length', 'woo-order-export-lite' ),
464
+ 'checked' => 0,
465
+ 'format' => 'number',
466
+ ),
467
+ 'height' => array(
468
+ 'label' => __( 'Height', 'woo-order-export-lite' ),
469
+ 'checked' => 0,
470
+ 'format' => 'number',
471
+ ),
472
+ 'weight' => array(
473
+ 'label' => __( 'Weight', 'woo-order-export-lite' ),
474
+ 'checked' => 0,
475
+ 'format' => 'number',
476
+ ),
477
+ 'product_url' => array(
478
+ 'label' => __( 'Product URL', 'woo-order-export-lite' ),
479
+ 'checked' => 0,
480
+ ),
481
+ 'download_url' => array(
482
+ 'label' => __( 'Download URL', 'woo-order-export-lite' ),
483
+ 'checked' => 0,
484
+ ),
485
+ 'image_url' => array(
486
+ 'label' => __( 'Image URL', 'woo-order-export-lite' ),
487
+ 'checked' => 0,
488
+ ),
489
+ 'product_shipping_class' => array(
490
+ 'label' => __( 'Product Shipping Class', 'woo-order-export-lite' ),
491
+ 'checked' => 0,
492
+ ),
493
+ 'post_content' => array(
494
+ 'label' => __( 'Description', 'woo-order-export-lite' ),
495
+ 'checked' => 0,
496
+ ),
497
+ 'post_excerpt' => array(
498
+ 'label' => __( 'Short Description', 'woo-order-export-lite' ),
499
+ 'checked' => 0,
500
+ ),
501
+ 'full_category_names' => array(
502
+ 'label' => __( 'Full names for categories', 'woo-order-export-lite' ),
503
+ 'checked' => 0,
504
+ ),
505
  );
506
 
507
  foreach ( $map as $key => $value ) {
514
 
515
  public static function get_order_coupon_fields( $format ) {
516
  $map = array(
517
+ 'code' => array(
518
+ 'label' => __( 'Coupon Code', 'woo-order-export-lite' ),
519
+ 'checked' => 1,
520
+ ),
521
+ 'discount_amount' => array(
522
+ 'label' => __( 'Discount Amount', 'woo-order-export-lite' ),
523
+ 'checked' => 1,
524
+ 'format' => 'money',
525
+ ),
526
+ 'discount_amount_tax' => array(
527
+ 'label' => __( 'Discount Amount Tax', 'woo-order-export-lite' ),
528
+ 'checked' => 1,
529
+ 'format' => 'money',
530
+ ),
531
+ 'discount_amount_plus_tax' => array(
532
+ 'label' => __( 'Discount Amount + Tax', 'woo-order-export-lite' ),
533
+ 'checked' => 0,
534
+ ),
535
+ 'excerpt' => array(
536
+ 'label' => __( 'Coupon Description', 'woo-order-export-lite' ),
537
+ 'checked' => 0,
538
+ ),
539
+ 'discount_type' => array(
540
+ 'label' => __( 'Coupon Type', 'woo-order-export-lite' ),
541
+ 'checked' => 0,
542
+ ),
543
+ 'coupon_amount' => array(
544
+ 'label' => __( 'Coupon Amount', 'woo-order-export-lite' ),
545
+ 'checked' => 0,
546
+ 'format' => 'money',
547
+ ),
548
  );
549
 
550
  foreach ( $map as $key => $value ) {
581
  'order_id' => array( 'label' => __( 'Order ID', 'woo-order-export-lite' ), 'checked' => 0 ),
582
  'order_number' => array( 'label' => __( 'Order Number', 'woo-order-export-lite' ), 'checked' => 1 ),
583
  'order_status' => array( 'label' => __( 'Order Status', 'woo-order-export-lite' ), 'checked' => 1 ),
584
+ 'order_date' => array(
585
+ 'label' => __( 'Order Date', 'woo-order-export-lite' ),
586
+ 'checked' => 1,
587
+ 'format' => 'date',
588
+ ),
589
+ 'modified_date' => array(
590
+ 'label' => __( 'Modification Date', 'woo-order-export-lite' ),
591
+ 'checked' => 0,
592
+ 'format' => 'date',
593
+ ),
594
+ 'transaction_id' => array(
595
+ 'label' => __( 'Transaction ID', 'woo-order-export-lite' ),
596
+ 'checked' => 0,
597
+ ),
598
+ 'completed_date' => array(
599
+ 'label' => __( 'Completed Date', 'woo-order-export-lite' ),
600
+ 'checked' => 0,
601
+ 'format' => 'date',
602
+ ),
603
+ 'paid_date' => array(
604
+ 'label' => __( 'Paid Date', 'woo-order-export-lite' ),
605
+ 'checked' => 0,
606
+ 'format' => 'date',
607
+ ),
608
+ 'first_refund_date' => array(
609
+ 'label' => __( 'Date of first refund', 'woo-order-export-lite' ),
610
+ 'checked' => 0,
611
+ 'format' => 'date',
612
+ ),
613
+ 'customer_note' => array(
614
+ 'label' => __( 'Customer Note', 'woo-order-export-lite' ),
615
+ 'checked' => 1,
616
+ 'format' => 'string',
617
+ ),
618
+ 'order_notes' => array(
619
+ 'label' => __( 'Order Notes', 'woo-order-export-lite' ),
620
+ 'checked' => 0,
621
+ 'format' => 'string',
622
+ ),
623
  );
624
  }
625
 
626
  public static function get_order_fields_user() {
627
  return array(
628
+ 'customer_ip_address' => array(
629
+ 'label' => __( 'Customer IP address', 'woo-order-export-lite' ),
630
+ 'checked' => 0,
631
+ ),
632
+ 'customer_user' => array(
633
+ 'label' => __( 'Customer User ID', 'woo-order-export-lite' ),
634
+ 'checked' => 0,
635
+ ),
636
+ 'user_login' => array(
637
+ 'label' => __( 'Customer Username', 'woo-order-export-lite' ),
638
+ 'checked' => 0,
639
+ ),
640
+ 'user_url' => array(
641
+ 'label' => __( 'User Website', 'woo-order-export-lite' ),
642
+ 'checked' => 0,
643
+ ),
644
+ 'user_email' => array(
645
+ 'label' => __( 'Customer User Email', 'woo-order-export-lite' ),
646
+ 'checked' => 0,
647
+ ),
648
+ 'user_role' => array(
649
+ 'label' => __( 'Customer Role', 'woo-order-export-lite' ),
650
+ 'checked' => 0,
651
+ ),
652
+ 'customer_total_orders' => array(
653
+ 'label' => __( 'Customer Total Orders', 'woo-order-export-lite' ),
654
+ 'checked' => 0,
655
+ ),
656
  );
657
  }
658
 
659
  public static function get_order_fields_billing() {
660
  return array(
661
+ 'billing_first_name' => array(
662
+ 'label' => __( 'First Name (Billing)', 'woo-order-export-lite' ),
663
+ 'checked' => 1,
664
+ 'format' => 'string',
665
+ ),
666
+ 'billing_last_name' => array(
667
+ 'label' => __( 'Last Name (Billing)', 'woo-order-export-lite' ),
668
+ 'checked' => 1,
669
+ 'format' => 'string',
670
+ ),
671
+ 'billing_full_name' => array(
672
+ 'label' => __( 'Full Name (Billing)', 'woo-order-export-lite' ),
673
+ 'checked' => 0,
674
+ 'format' => 'string',
675
+ ),
676
+ 'billing_company' => array(
677
+ 'label' => __( 'Company (Billing)', 'woo-order-export-lite' ),
678
+ 'checked' => 1,
679
+ 'format' => 'string',
680
+ ),
681
+ 'billing_address' => array(
682
+ 'label' => __( 'Address 1&2 (Billing)', 'woo-order-export-lite' ),
683
+ 'checked' => 1,
684
+ 'format' => 'string',
685
+ ),
686
+ 'billing_address_1' => array(
687
+ 'label' => __( 'Address 1 (Billing)', 'woo-order-export-lite' ),
688
+ 'checked' => 0,
689
+ 'format' => 'string',
690
+ ),
691
+ 'billing_address_2' => array(
692
+ 'label' => __( 'Address 2 (Billing)', 'woo-order-export-lite' ),
693
+ 'checked' => 0,
694
+ 'format' => 'string',
695
+ ),
696
+ 'billing_city' => array(
697
+ 'label' => __( 'City (Billing)', 'woo-order-export-lite' ),
698
+ 'checked' => 1,
699
+ 'format' => 'string',
700
+ ),
701
+ 'billing_state' => array(
702
+ 'label' => __( 'State Code (Billing)', 'woo-order-export-lite' ),
703
+ 'checked' => 1,
704
+ 'format' => 'string',
705
+ ),
706
+ 'billing_citystatezip' => array(
707
+ 'label' => __( 'City, State, Zip (Billing)', 'woo-order-export-lite' ),
708
+ 'checked' => 0,
709
+ 'format' => 'string',
710
+ ),
711
+ 'billing_state_full' => array(
712
+ 'label' => __( 'State Name (Billing)', 'woo-order-export-lite' ),
713
+ 'checked' => 0,
714
+ 'format' => 'string',
715
+ ),
716
+ 'billing_postcode' => array(
717
+ 'label' => __( 'Postcode (Billing)', 'woo-order-export-lite' ),
718
+ 'checked' => 1,
719
+ 'format' => 'string',
720
+ ),
721
+ 'billing_country' => array(
722
+ 'label' => __( 'Country Code (Billing)', 'woo-order-export-lite' ),
723
+ 'checked' => 1,
724
+ 'format' => 'string',
725
+ ),
726
+ 'billing_country_full' => array(
727
+ 'label' => __( 'Country Name (Billing)', 'woo-order-export-lite' ),
728
+ 'checked' => 0,
729
+ 'format' => 'string',
730
+ ),
731
+ 'billing_email' => array(
732
+ 'label' => __( 'Email (Billing)', 'woo-order-export-lite' ),
733
+ 'checked' => 1,
734
+ 'format' => 'string',
735
+ ),
736
+ 'billing_phone' => array(
737
+ 'label' => __( 'Phone (Billing)', 'woo-order-export-lite' ),
738
+ 'checked' => 1,
739
+ 'format' => 'string',
740
+ ),
741
  );
742
  }
743
 
744
  public static function get_order_fields_shipping() {
745
  return array(
746
+ 'shipping_first_name' => array(
747
+ 'label' => __( 'First Name (Shipping)', 'woo-order-export-lite' ),
748
+ 'checked' => 1,
749
+ 'format' => 'string',
750
+ ),
751
+ 'shipping_last_name' => array(
752
+ 'label' => __( 'Last Name (Shipping)', 'woo-order-export-lite' ),
753
+ 'checked' => 1,
754
+ 'format' => 'string',
755
+ ),
756
+ 'shipping_full_name' => array(
757
+ 'label' => __( 'Full Name (Shipping)', 'woo-order-export-lite' ),
758
+ 'checked' => 0,
759
+ 'format' => 'string',
760
+ ),
761
+ 'shipping_company' => array(
762
+ 'label' => __( 'Company (Shipping)', 'woo-order-export-lite' ),
763
+ 'checked' => 0,
764
+ 'format' => 'string',
765
+ ),
766
+ 'shipping_address' => array(
767
+ 'label' => __( 'Address 1&2 (Shipping)', 'woo-order-export-lite' ),
768
+ 'checked' => 1,
769
+ 'format' => 'string',
770
+ ),
771
+ 'shipping_address_1' => array(
772
+ 'label' => __( 'Address 1 (Shipping)', 'woo-order-export-lite' ),
773
+ 'checked' => 0,
774
+ 'format' => 'string',
775
+ ),
776
+ 'shipping_address_2' => array(
777
+ 'label' => __( 'Address 2 (Shipping)', 'woo-order-export-lite' ),
778
+ 'checked' => 0,
779
+ 'format' => 'string',
780
+ ),
781
+ 'shipping_city' => array(
782
+ 'label' => __( 'City (Shipping)', 'woo-order-export-lite' ),
783
+ 'checked' => 1,
784
+ 'format' => 'string',
785
+ ),
786
+ 'shipping_state' => array(
787
+ 'label' => __( 'State Code (Shipping)', 'woo-order-export-lite' ),
788
+ 'checked' => 1,
789
+ 'format' => 'string',
790
+ ),
791
+ 'shipping_citystatezip' => array(
792
+ 'label' => __( 'City, State, Zip (Shipping)', 'woo-order-export-lite' ),
793
+ 'checked' => 0,
794
+ 'format' => 'string',
795
+ ),
796
+ 'shipping_state_full' => array(
797
+ 'label' => __( 'State Name (Shipping)', 'woo-order-export-lite' ),
798
+ 'checked' => 0,
799
+ 'format' => 'string',
800
+ ),
801
+ 'shipping_postcode' => array(
802
+ 'label' => __( 'Postcode (Shipping)', 'woo-order-export-lite' ),
803
+ 'checked' => 1,
804
+ 'format' => 'string',
805
+ ),
806
+ 'shipping_country' => array(
807
+ 'label' => __( 'Country Code (Shipping)', 'woo-order-export-lite' ),
808
+ 'checked' => 1,
809
+ 'format' => 'string',
810
+ ),
811
+ 'shipping_country_full' => array(
812
+ 'label' => __( 'Country Name (Shipping)', 'woo-order-export-lite' ),
813
+ 'checked' => 0,
814
+ 'format' => 'string',
815
+ ),
816
  );
817
  }
818
 
819
  // meta
820
  public static function get_order_fields_product() {
821
  return array(
822
+ 'products' => array(
823
+ 'label' => __( 'Products', 'woo-order-export-lite' ),
824
+ 'checked' => 1,
825
+ 'repeat' => 'rows',
826
+ 'max_cols' => 10,
827
+ ),
828
  );
829
  }
830
 
831
  // meta
832
  public static function get_order_fields_coupon() {
833
  return array(
834
+ 'coupons' => array(
835
+ 'label' => __( 'Coupons', 'woo-order-export-lite' ),
836
+ 'checked' => 1,
837
+ 'repeat' => 'rows',
838
+ 'max_cols' => 10,
839
+ ),
840
  );
841
  }
842
 
843
  public static function get_order_fields_cart() {
844
  return array(
845
+ 'shipping_method_title' => array(
846
+ 'label' => __( 'Shipping Method Title', 'woo-order-export-lite' ),
847
+ 'checked' => 1,
848
+ 'format' => 'string',
849
+ ),
850
+ 'shipping_method' => array(
851
+ 'label' => __( 'Shipping Method', 'woo-order-export-lite' ),
852
+ 'checked' => 0,
853
+ 'format' => 'string',
854
+ ),
855
+ 'payment_method_title' => array(
856
+ 'label' => __( 'Payment Method Title', 'woo-order-export-lite' ),
857
+ 'checked' => 1,
858
+ 'format' => 'string',
859
+ ),
860
+ 'payment_method' => array(
861
+ 'label' => __( 'Payment Method', 'woo-order-export-lite' ),
862
+ 'checked' => 0,
863
+ 'format' => 'string',
864
+ ),
865
+ 'coupons_used' => array(
866
+ 'label' => __( 'Coupons Used', 'woo-order-export-lite' ),
867
+ 'checked' => 0,
868
+ 'format' => 'string',
869
+ ),
870
+ 'cart_discount' => array(
871
+ 'label' => __( 'Cart Discount Amount', 'woo-order-export-lite' ),
872
+ 'checked' => 1,
873
+ 'format' => 'money',
874
+ ),
875
+ 'cart_discount_tax' => array(
876
+ 'label' => __( 'Cart Discount Amount Tax', 'woo-order-export-lite' ),
877
+ 'checked' => 0,
878
+ 'format' => 'money',
879
+ ),
880
+ 'order_subtotal' => array(
881
+ 'label' => __( 'Order Subtotal Amount', 'woo-order-export-lite' ),
882
+ 'checked' => 1,
883
+ 'format' => 'money',
884
+ ),
885
+ 'order_subtotal_minus_discount' => array(
886
+ 'label' => 'Order Subtotal - Cart Discount',
887
+ 'colname' => 'Order Subtotal - Cart Discount',
888
+ 'checked' => 0,
889
+ ),
890
+ 'order_subtotal_refunded' => array(
891
+ 'label' => __( 'Order Subtotal Amount Refunded', 'woo-order-export-lite' ),
892
+ 'checked' => 0,
893
+ 'format' => 'money',
894
+ ),
895
+ 'order_subtotal_minus_refund' => array(
896
+ 'label' => __( 'Order Subtotal Amount (- Refund)', 'woo-order-export-lite' ),
897
+ 'checked' => 0,
898
+ 'format' => 'money',
899
+ ),
900
+ 'order_tax' => array(
901
+ 'label' => __( 'Order Tax Amount', 'woo-order-export-lite' ),
902
+ 'checked' => 0,
903
+ 'format' => 'money',
904
+ ),
905
+ 'order_shipping' => array(
906
+ 'label' => __( 'Order Shipping Amount', 'woo-order-export-lite' ),
907
+ 'checked' => 1,
908
+ 'format' => 'money',
909
+ ),
910
+ 'order_shipping_refunded' => array(
911
+ 'label' => __( 'Order Shipping Amount Refunded', 'woo-order-export-lite' ),
912
+ 'checked' => 0,
913
+ 'format' => 'money',
914
+ ),
915
+ 'order_shipping_minus_refund' => array(
916
+ 'label' => __( 'Order Shipping Amount (- Refund)', 'woo-order-export-lite' ),
917
+ 'checked' => 0,
918
+ 'format' => 'money',
919
+ ),
920
+ 'order_shipping_tax' => array(
921
+ 'label' => __( 'Order Shipping Tax Amount', 'woo-order-export-lite' ),
922
+ 'checked' => 0,
923
+ 'format' => 'money',
924
+ ),
925
+ 'order_shipping_tax_refunded' => array(
926
+ 'label' => __( 'Order Shipping Tax Refunded', 'woo-order-export-lite' ),
927
+ 'checked' => 0,
928
+ 'format' => 'money',
929
+ ),
930
+ 'order_shipping_tax_minus_refund' => array(
931
+ 'label' => __( 'Order Shipping Tax Amount (- Refund)', 'woo-order-export-lite' ),
932
+ 'checked' => 0,
933
+ 'format' => 'money',
934
+ ),
935
+ 'order_refund' => array(
936
+ 'label' => __( 'Order Refund Amount', 'woo-order-export-lite' ),
937
+ 'checked' => 1,
938
+ 'format' => 'money',
939
+ ),
940
+ 'order_total_inc_refund' => array(
941
+ 'label' => __( 'Order Total Amount (- Refund)', 'woo-order-export-lite' ),
942
+ 'checked' => 0,
943
+ 'format' => 'money',
944
+ ),
945
+ 'order_total' => array(
946
+ 'label' => __( 'Order Total Amount', 'woo-order-export-lite' ),
947
+ 'checked' => 1,
948
+ 'format' => 'money',
949
+ ),
950
+ 'order_total_no_tax' => array(
951
+ 'label' => __( 'Order Total Amount without Tax', 'woo-order-export-lite' ),
952
+ 'checked' => 0,
953
+ 'format' => 'money',
954
+ ),
955
+ 'order_total_tax' => array(
956
+ 'label' => __( 'Order Total Tax Amount', 'woo-order-export-lite' ),
957
+ 'checked' => 1,
958
+ 'format' => 'money',
959
+ ),
960
+ 'order_total_tax_refunded' => array(
961
+ 'label' => __( 'Order Total Tax Amount Refunded', 'woo-order-export-lite' ),
962
+ 'checked' => 0,
963
+ 'format' => 'money',
964
+ ),
965
+ 'order_total_tax_minus_refund' => array(
966
+ 'label' => __( 'Order Total Tax Amount (- Refund)', 'woo-order-export-lite' ),
967
+ 'checked' => 0,
968
+ 'format' => 'money',
969
+ ),
970
+ 'order_currency' => array(
971
+ 'label' => __( 'Currency', 'woo-order-export-lite' ),
972
+ 'checked' => 0,
973
+ 'format' => 'string',
974
+ ),
975
  );
976
  }
977
 
978
  public static function get_order_fields_misc() {
979
  return array(
980
+ 'total_weight_items' => array(
981
+ 'label' => __( 'Total weight', 'woo-order-export-lite' ),
982
+ 'checked' => 0,
983
+ 'format' => 'number',
984
+ ),
985
+ 'count_total_items' => array(
986
+ 'label' => __( 'Total items', 'woo-order-export-lite' ),
987
+ 'checked' => 0,
988
+ ),
989
+ 'count_exported_items' => array(
990
+ 'label' => __( 'Exported items', 'woo-order-export-lite' ),
991
+ 'checked' => 0,
992
+ ),
993
+ 'count_unique_products' => array(
994
+ 'label' => __( 'Total products', 'woo-order-export-lite' ),
995
+ 'checked' => 0,
996
+ ),
997
  );
998
  }
999
 
1017
  'shipping' => __( 'Shipping', 'woo-order-export-lite' ),
1018
  'product' => __( 'Products', 'woo-order-export-lite' ),
1019
  'coupon' => __( 'Coupons', 'woo-order-export-lite' ),
1020
+ 'cart' => __( 'Cart', 'woo-order-export-lite' ),
1021
+ 'misc' => __( 'Others', 'woo-order-export-lite' ),
1022
  );
1023
  }
1024
 
classes/core/class-wc-order-export-data-extractor.php CHANGED
@@ -16,20 +16,22 @@ class WC_Order_Export_Data_Extractor {
16
  static $export_subcategories_separator;
17
  static $export_line_categories_separator;
18
  static $export_itemmeta_values_separator;
 
19
  static $track_sql_queries = false;
20
  static $sql_queries;
21
  static $operator_must_check_values = array( 'LIKE', '>', '<', '>=', '<=' );
22
- const HUGE_SHOP_ORDERS = 1000;// more than 1000 orders
23
- const HUGE_SHOP_PRODUCTS = 1000;// more than 1000 products
 
24
 
25
 
26
  //Common
27
-
28
  // to parse "item_type:meta_key" strings
29
  public static function extract_item_type_and_key( $meta_key, &$type, &$key ) {
30
- $t = explode( ":", $meta_key);
31
- $type = array_shift($t);
32
- $key = join( ":", $t);
33
  }
34
 
35
  public static function get_order_custom_fields() {
@@ -37,23 +39,45 @@ class WC_Order_Export_Data_Extractor {
37
  $transient_key = 'woe_get_order_custom_fields_result';
38
 
39
  $fields = get_transient( $transient_key );
40
- if($fields === false) {
41
  $total_orders = $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->posts} WHERE post_type = '" . self::$object_type . "'" );
42
  //small shop , take all orders
43
- if( $total_orders < self::HUGE_SHOP_ORDERS )
44
  $fields = $wpdb->get_col( "SELECT DISTINCT meta_key FROM {$wpdb->posts} INNER JOIN {$wpdb->postmeta} ON {$wpdb->posts}.ID = {$wpdb->postmeta}.post_id WHERE post_type = '" . self::$object_type . "'" );
45
- else { // we have a lot of orders, take last good orders, upto 1000
46
- $order_ids = $wpdb->get_col( "SELECT ID FROM {$wpdb->posts} WHERE post_type = '" . self::$object_type . "' AND post_status IN('wc-on-hold','wc-processing','wc-completed') ORDER BY post_date DESC LIMIT 1000");
47
  $order_ids[] = 0; // add fake zero
48
- $order_ids = join( ",", $order_ids);
49
- $fields = $wpdb->get_col( "SELECT DISTINCT meta_key FROM {$wpdb->postmeta} WHERE post_id IN ($order_ids)" );
50
  }
51
  sort( $fields );
52
  set_transient( $transient_key, $fields, 60 ); //valid for a minute
53
  }
 
54
  return apply_filters( 'woe_get_order_custom_fields', $fields );
55
  }
56
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
57
  public static function get_product_attributes() {
58
  global $wpdb;
59
 
@@ -84,17 +108,18 @@ class WC_Order_Export_Data_Extractor {
84
  return apply_filters( 'woe_get_product_attributes', $attrs );
85
  }
86
 
87
- public static function get_product_itemmeta() {
88
  global $wpdb;
89
  $transient_key = 'woe_get_product_itemmeta_result';
90
 
91
  $metas = get_transient( $transient_key );
92
- if($metas === false) {
93
  // WP internal table, take all metas
94
  $metas = $wpdb->get_col( "SELECT DISTINCT meta.meta_key FROM {$wpdb->prefix}woocommerce_order_itemmeta meta inner join {$wpdb->prefix}woocommerce_order_items item on item.order_item_id=meta.order_item_id and item.order_item_type = 'line_item' " );
95
- sort($metas);
96
  set_transient( $transient_key, $metas, 60 ); //valid for a minute
97
  }
 
98
  return apply_filters( 'woe_get_product_itemmeta', $metas );
99
  }
100
 
@@ -103,8 +128,14 @@ class WC_Order_Export_Data_Extractor {
103
 
104
  $attrs = array();
105
 
 
 
 
 
 
 
 
106
  // WP internal table, take all taxonomies for products
107
- $wpdb->show_errors( true );
108
  $wp_fields = $wpdb->get_col( "SELECT DISTINCT taxonomy FROM {$wpdb->term_relationships}
109
  JOIN {$wpdb->term_taxonomy} ON {$wpdb->term_taxonomy}.term_taxonomy_id = {$wpdb->term_relationships}.term_taxonomy_id
110
  WHERE {$wpdb->term_relationships}.object_id IN (SELECT DISTINCT ID FROM {$wpdb->posts} WHERE post_type = 'product' OR post_type='product_variation')" );
@@ -121,21 +152,22 @@ class WC_Order_Export_Data_Extractor {
121
  $transient_key = 'woe_get_product_custom_fields_result';
122
 
123
  $fields = get_transient( $transient_key );
124
- if($fields === false) {
125
  //rewrite for huge # of products
126
  $total_products = $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->posts} WHERE post_type = 'product' OR post_type='product_variation' " );
127
  //small shop , take all orders
128
- if( $total_products < self::HUGE_SHOP_PRODUCTS )
129
  $fields = $wpdb->get_col( "SELECT DISTINCT meta_key FROM {$wpdb->posts} INNER JOIN {$wpdb->postmeta} ON {$wpdb->posts}.ID = {$wpdb->postmeta}.post_id WHERE post_type = 'product' OR post_type='product_variation' " );
130
- else { // we have a lot of orders, take last good orders, upto 1000
131
- $product_ids = $wpdb->get_col( "SELECT ID FROM {$wpdb->posts} WHERE post_type IN('product','product_variation') ORDER BY post_date DESC LIMIT 1000");
132
  $product_ids[] = 0; // add fake zero
133
- $product_ids = join( ",", $product_ids);
134
- $fields = $wpdb->get_col( "SELECT DISTINCT meta_key FROM {$wpdb->postmeta} WHERE post_id IN ($product_ids)" );
135
  }
136
  sort( $fields );
137
  set_transient( $transient_key, $fields, 60 ); //valid for a minute
138
  }
 
139
  return apply_filters( 'woe_get_product_custom_fields', $fields );
140
  }
141
 
@@ -163,35 +195,37 @@ class WC_Order_Export_Data_Extractor {
163
  $pair_types = array();
164
  $delimiters = array(
165
  'NOT SET' => 'NOT SET',
166
- 'IS SET' => 'IS SET',
167
- 'LIKE' => 'LIKE',
168
- '<>' => 'NOT IN',
169
- '>=' => '>=',
170
- '<=' => '<=',
171
- '>' => '>',
172
- '<' => '<',
173
- '=' => 'IN',
174
  );
175
- $single_ops = array('NOT SET', 'IS SET');
176
-
177
  foreach ( $pairs as $pair ) {
178
- $pair = trim( $pair );
179
- $op = '';
180
  $single_op = false;
181
- foreach($delimiters as $delim=>$op_seek) {
182
- $t = explode( $delim, $pair );
183
- $single_op = in_array($delim,$single_ops);
184
- if( count($t) == 2 ) {
185
  $op = $op_seek;
186
  break;
187
  }
188
  }
189
- if( !$op )
190
  continue;
191
- if( $single_op )
 
192
  $t[1] = '';
 
193
 
194
- list( $filter_type, $filter_value ) = array_map("trim", $t);
195
  $empty = __( 'empty', 'woo-order-export-lite' );
196
  if ( $empty == $filter_value ) {
197
  $filter_value = '';
@@ -200,20 +234,21 @@ class WC_Order_Export_Data_Extractor {
200
  if ( $mode == 'lower_filter_label' ) {
201
  $filter_type = strtolower( $filter_type );
202
  } // Country=>country for locations
203
-
204
- if ( $valid_types AND !in_array( $filter_type, $valid_types ) ) {
205
  continue;
206
  }
207
-
208
- $filter_type = addslashes($filter_type);
209
  if ( ! isset( $pair_types[ $op ] ) ) {
210
  $pair_types[ $op ] = array();
211
  }
212
  if ( ! isset( $pair_types[ $op ] [ $filter_type ] ) ) {
213
  $pair_types[ $op ] [ $filter_type ] = array();
214
  }
215
- $pair_types[ $op ][ $filter_type ][] = addslashes($filter_value);
216
  }
 
217
  return $pair_types;
218
  }
219
 
@@ -238,7 +273,7 @@ class WC_Order_Export_Data_Extractor {
238
  public static function sql_get_product_ids( $settings ) {
239
  global $wpdb;
240
 
241
- $product_where = self::sql_build_product_filter($settings);
242
 
243
  $wc_order_items_meta = "{$wpdb->prefix}woocommerce_order_itemmeta";
244
  $left_join_order_items_meta = $order_items_meta_where = array();
@@ -246,7 +281,7 @@ class WC_Order_Export_Data_Extractor {
246
  // filter by product
247
  if ( $product_where ) {
248
  $left_join_order_items_meta[] = "LEFT JOIN $wc_order_items_meta AS orderitemmeta_product ON orderitemmeta_product.order_item_id = order_items.order_item_id";
249
- $order_items_meta_where[] = " (orderitemmeta_product.meta_key IN ('_variation_id', '_product_id') $product_where)";
250
  } else {
251
  $left_join_order_items_meta[] = "LEFT JOIN $wc_order_items_meta AS orderitemmeta_product ON orderitemmeta_product.order_item_id = order_items.order_item_id";
252
  $order_items_meta_where[] = " orderitemmeta_product.meta_key IN ('_variation_id', '_product_id')";
@@ -257,47 +292,52 @@ class WC_Order_Export_Data_Extractor {
257
  $attrs = self::get_product_attributes();
258
  $names2fields = array_flip( $attrs );
259
  $filters = self::parse_complex_pairs( $settings['product_attributes'], $attrs );
260
- foreach ( $filters as $operator => $fields) {
261
  foreach ( $fields as $field => $values ) {
262
- $field = $names2fields[ $field ];
263
  if ( $values ) {
264
  $left_join_order_items_meta[] = "LEFT JOIN $wc_order_items_meta AS `orderitemmeta_{$field}` ON `orderitemmeta_{$field}`.order_item_id = order_items.order_item_id";
265
- if( $operator == 'IN' OR $operator == 'NOT IN' ) {
266
- $values = self::sql_subset( $values );
267
- $order_items_meta_where[] = " (`orderitemmeta_{$field}`.meta_key='$field' AND `orderitemmeta_{$field}`.meta_value $operator ($values) ) ";
268
- } elseif( in_array($operator, self::$operator_must_check_values) ) {
269
  $pairs = array();
270
- foreach($values as $v)
271
- $pairs[] = self::operator_compare_field_and_value( "`orderitemmeta_{$field}`.meta_value", $operator ,$v);
272
- $pairs = join("OR", $pairs);
273
- $order_items_meta_where[] = " (`orderitemmeta_{$field}`.meta_key='$field' AND ($pairs) ) ";
 
 
274
  }
275
  }
276
  }// values
277
  }// operators
278
  }
279
 
280
- //by attrbutes in woocommerce_order_itemmeta
281
  if ( $settings['product_itemmeta'] ) {
282
- foreach($settings['product_itemmeta'] as $value) {
283
- $settings['product_itemmeta'][] = esc_html($value);
284
- }
285
-
286
- $itemmeta = self::get_product_itemmeta();
287
- $filters = self::parse_complex_pairs( $settings['product_itemmeta'], $itemmeta );
288
- foreach ( $filters as $operator => $fields) {
289
- foreach ( $fields as $field => $values ) {;
 
290
  if ( $values ) {
291
  $left_join_order_items_meta[] = "LEFT JOIN $wc_order_items_meta AS `orderitemmeta_{$field}` ON `orderitemmeta_{$field}`.order_item_id = order_items.order_item_id";
292
- if( $operator == 'IN' OR $operator == 'NOT IN' ) {
293
- $values = self::sql_subset( $values );
294
- $order_items_meta_where[] = " (`orderitemmeta_{$field}`.meta_key='$field' AND `orderitemmeta_{$field}`.meta_value $operator ($values) ) ";
295
- } elseif( in_array($operator, self::$operator_must_check_values) ) {
296
  $pairs = array();
297
- foreach($values as $v)
298
- $pairs[] = self::operator_compare_field_and_value( "`orderitemmeta_{$field}`.meta_value", $operator ,$v);
299
- $pairs = join("OR", $pairs);
300
- $order_items_meta_where[] = " (`orderitemmeta_{$field}`.meta_key='$field' AND ($pairs) ) ";
 
 
301
  }
302
  }// values
303
  }
@@ -306,9 +346,9 @@ class WC_Order_Export_Data_Extractor {
306
 
307
  $orders_where = array();
308
  self::apply_order_filters_to_sql( $orders_where, $settings );
309
- if( $orders_where ) {
310
  $left_join_order_items_meta[] = "LEFT JOIN {$wpdb->posts} AS `orders` ON `orders`.ID = order_items.order_id";
311
- $order_items_meta_where[] = "( " . join(" AND ", $orders_where) . " )";
312
  }
313
 
314
  $order_items_meta_where = join( " AND ", $order_items_meta_where );
@@ -319,16 +359,19 @@ class WC_Order_Export_Data_Extractor {
319
 
320
 
321
  // final sql from WC tables
322
- if ( !$order_items_meta_where )
323
  return false;
 
324
 
325
- $sql= "SELECT DISTINCT p_id FROM
326
  (SELECT order_items.order_item_id as order_item_id, MAX(CONVERT(orderitemmeta_product.meta_value ,UNSIGNED INTEGER)) as p_id FROM {$wpdb->prefix}woocommerce_order_items as order_items
327
  $left_join_order_items_meta
328
  WHERE order_item_type='line_item' $order_items_meta_where GROUP BY order_item_id
329
  ) AS temp";
330
- if( self::$track_sql_queries )
331
  self::$sql_queries[] = $sql;
 
 
332
  return $sql;
333
  }
334
 
@@ -337,68 +380,72 @@ class WC_Order_Export_Data_Extractor {
337
  global $wpdb;
338
 
339
  // has exact products?
340
- if( $settings['products'] ) {
341
  ;// do nothing
342
- } elseif( empty( $settings['product_vendors'] ) AND empty( $settings['product_custom_fields'] ) ) {
343
  $settings['products'] = array();
344
- } else {
345
- $product_where = array("1");
346
 
347
  //by owners
348
- $settings['product_vendors'] = apply_filters('woe_sql_get_product_vendor_ids', $settings['product_vendors'], $settings);
 
349
  if ( $settings['product_vendors'] ) {
350
- $values = self::sql_subset( $settings['product_vendors'] );
351
- $product_where[] =" products.post_author in ($values)";
352
  }
353
 
354
  //by custom fields in Product
355
- $product_meta_where = "";
356
  $left_join_product_meta = "";
357
  if ( $settings['product_custom_fields'] ) {
358
  $left_join_product_meta = $product_meta_where = array();
359
- $cf_names = self::get_product_custom_fields();
360
- $filters = self::parse_complex_pairs( $settings['product_custom_fields'], $cf_names);
361
- $pos=1;
362
- foreach ( $filters as $operator => $fields) {
363
  foreach ( $fields as $field => $values ) {
364
  if ( $values ) {
365
  $left_join_product_meta[] = "LEFT JOIN {$wpdb->postmeta} AS productmeta_cf_{$pos} ON productmeta_cf_{$pos}.post_id = products.ID";
366
- if( $operator == 'IN' OR $operator == 'NOT IN' ) {
367
- $values = self::sql_subset( $values );
368
- $product_meta_where[] = " (productmeta_cf_{$pos}.meta_key='$field' AND productmeta_cf_{$pos}.meta_value $operator ($values)) ";
369
- } elseif( in_array($operator, self::$operator_must_check_values) ) {
370
  $pairs = array();
371
- foreach($values as $v)
372
- $pairs[] = self::operator_compare_field_and_value( "`productmeta_cf_{$pos}`.meta_value", $operator ,$v);
373
- $pairs = join("OR", $pairs);
374
- $product_meta_where[] = " (productmeta_cf_{$pos}.meta_key='$field' AND ($pairs) ) ";
 
 
375
  }
376
- $pos++;
377
  }//if values
378
  }
379
  }
380
 
381
- if( $filters ) {
382
- $product_where[] = join(" AND ", $product_meta_where);
383
  $left_join_product_meta = join( " ", $left_join_product_meta );
384
  }
385
  }
386
  //done
387
- $product_where = join(" AND ", $product_where);
388
- $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 ";
389
- $settings['products'] = $wpdb->get_col($sql);
390
  }
391
-
392
  // we have to use variations , if user sets product attributes
393
  if ( $settings['products'] AND $settings['product_attributes'] ) {
394
- $values = self::sql_subset( $settings['products'] );
395
- $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)";
396
- $settings['products'] = $wpdb->get_col($sql);
397
  }
398
- if( !empty($sql) AND self::$track_sql_queries )
399
  self::$sql_queries[] = $sql;
400
-
401
- return apply_filters('woe_sql_adjust_products', $settings['products'] , $settings);
 
402
  }
403
 
404
 
@@ -412,18 +459,18 @@ class WC_Order_Export_Data_Extractor {
412
  $names2fields = array_flip( $attrs );
413
  $filters = self::parse_complex_pairs( $settings['product_taxonomies'], $attrs );
414
  //print_r($filters );die();
415
- foreach ( $filters as $operator => $fields) {
416
  foreach ( $fields as $label => $values ) {
417
  $field = $names2fields[ $label ];
418
  $values = self::sql_subset( $values );
419
  if ( $values ) {
420
- $label = esc_sql($label);
421
- $taxonomy_where .= " AND orderitemmeta_product.meta_value $operator (SELECT object_id FROM {$wpdb->term_relationships} AS `{$field}_rel`
422
  INNER JOIN {$wpdb->term_taxonomy} AS `{$field}_cat` ON `{$field}_cat`.term_taxonomy_id = `{$field}_rel`.term_taxonomy_id
423
  WHERE `{$field}_cat`.taxonomy='$label' AND `{$field}_cat`.term_id IN (SELECT term_id FROM {$wpdb->terms} WHERE name IN ($values) ) )";
424
  }
425
  }
426
- }
427
  }
428
 
429
  $product_category_where = "";
@@ -435,8 +482,8 @@ class WC_Order_Export_Data_Extractor {
435
  $cat_ids[] = $child_id;
436
  }
437
  }
438
- $cat_ids = join( ',', $cat_ids );
439
- $product_category_where = "SELECT DISTINCT object_id FROM {$wpdb->term_relationships} AS product_in_cat
440
  LEFT JOIN {$wpdb->term_taxonomy} AS product_category ON product_category.term_taxonomy_id = product_in_cat.term_taxonomy_id
441
  WHERE product_category.term_id IN ($cat_ids)
442
  ";
@@ -450,38 +497,42 @@ class WC_Order_Export_Data_Extractor {
450
  ";
451
  }
452
 
453
- $settings['products'] = self::sql_get_filtered_product_list($settings);
454
 
455
  // deep level still
456
  $exact_product_where = '';
457
  if ( $settings['products'] ) {
458
  $values = self::sql_subset( $settings['products'] );
459
  if ( $values ) {
460
- $exact_product_where = "AND orderitemmeta_product.meta_value IN ($values)";
461
  }
462
  }
463
- $product_where = join( " ", array_filter( array( $taxonomy_where, $product_category_where, $exact_product_where) ) );
464
-
 
465
  //skip empty values
466
- if( $product_where )
467
- $product_where = "AND orderitemmeta_product.meta_value<>'0' " . $product_where ;
468
- return $product_where ;
 
 
469
  }
470
 
471
- static function operator_compare_field_and_value( $field, $operator, $value) {
472
- if($operator == "LIKE") {
473
  $value = "'%$value%'";
474
  } else { // compare numbers!
475
- $field = "cast($field as signed)";
476
- }
 
477
  return " $field $operator $value ";
478
  }
479
-
480
  public static function sql_get_order_ids_Ver1( $settings ) {
481
  global $wpdb;
482
 
483
  // deep level !
484
- $product_where = self::sql_build_product_filter($settings);
485
 
486
  $wc_order_items_meta = "{$wpdb->prefix}woocommerce_order_itemmeta";
487
  $left_join_order_items_meta = $order_items_meta_where = array();
@@ -498,47 +549,52 @@ class WC_Order_Export_Data_Extractor {
498
  $attrs = self::get_product_attributes();
499
  $names2fields = @array_flip( $attrs );
500
  $filters = self::parse_complex_pairs( $settings['product_attributes'], $attrs );
501
- foreach ( $filters as $operator => $fields) {
502
  foreach ( $fields as $field => $values ) {
503
- $field = $names2fields[ $field ];
504
  if ( $values ) {
505
  $left_join_order_items_meta[] = "LEFT JOIN $wc_order_items_meta AS `orderitemmeta_{$field}` ON `orderitemmeta_{$field}`.order_item_id = order_items.order_item_id";
506
- if( $operator == 'IN' OR $operator == 'NOT IN' ) {
507
- $values = self::sql_subset( $values );
508
- $order_items_meta_where[] = " (`orderitemmeta_{$field}`.meta_key='$field' AND `orderitemmeta_{$field}`.meta_value $operator ($values) ) ";
509
- } elseif( in_array($operator, self::$operator_must_check_values) ) {
510
  $pairs = array();
511
- foreach($values as $v)
512
- $pairs[] = self::operator_compare_field_and_value( "`orderitemmeta_{$field}`.meta_value", $operator ,$v);
513
- $pairs = join("OR", $pairs);
514
- $order_items_meta_where[] = " (`orderitemmeta_{$field}`.meta_key='$field' AND ($pairs) ) ";
 
 
515
  }
516
  }// values
517
  }
518
  }// operators
519
  }
520
 
521
- //by attrbutes in woocommerce_order_itemmeta
522
  if ( $settings['product_itemmeta'] ) {
523
- foreach($settings['product_itemmeta'] as $value) {
524
- $settings['product_itemmeta'][] = esc_html($value);
525
- }
526
-
527
- $itemmeta = self::get_product_itemmeta();
528
- $filters = self::parse_complex_pairs( $settings['product_itemmeta'], $itemmeta );
529
- foreach ( $filters as $operator => $fields) {
530
- foreach ( $fields as $field => $values ) {;
 
531
  if ( $values ) {
532
  $left_join_order_items_meta[] = "LEFT JOIN $wc_order_items_meta AS `orderitemmeta_{$field}` ON `orderitemmeta_{$field}`.order_item_id = order_items.order_item_id";
533
- if( $operator == 'IN' OR $operator == 'NOT IN' ) {
534
- $values = self::sql_subset( $values );
535
- $order_items_meta_where[] = " (`orderitemmeta_{$field}`.meta_key='$field' AND `orderitemmeta_{$field}`.meta_value $operator ($values) ) ";
536
- } elseif( in_array($operator, self::$operator_must_check_values) ) {
537
  $pairs = array();
538
- foreach($values as $v)
539
- $pairs[] = self::operator_compare_field_and_value( "`orderitemmeta_{$field}`.meta_value", $operator ,$v);
540
- $pairs = join("OR", $pairs);
541
- $order_items_meta_where[] = " (`orderitemmeta_{$field}`.meta_key='$field' AND ($pairs) ) ";
 
 
542
  }
543
  }// values
544
  }
@@ -564,130 +620,160 @@ class WC_Order_Export_Data_Extractor {
564
  if ( ! empty( $settings['any_coupon_used'] ) ) {
565
  $order_items_where .= " AND orders.ID IN (SELECT DISTINCT order_coupons.order_id FROM {$wpdb->prefix}woocommerce_order_items as order_coupons
566
  WHERE order_coupons.order_item_type='coupon')";
567
- }
568
- elseif ( ! empty( $settings['coupons'] ) ) {
569
- $values = self::sql_subset( $settings['coupons'] );
570
  $order_items_where .= " AND orders.ID IN (SELECT DISTINCT order_coupons.order_id FROM {$wpdb->prefix}woocommerce_order_items as order_coupons
571
  WHERE order_coupons.order_item_type='coupon' AND order_coupons.order_item_name in ($values) )";
572
  }
573
  // shipping methods
574
  if ( ! empty( $settings['shipping_methods'] ) ) {
575
  $zone_values = $zone_instance_values = $itemname_values = array();
576
- foreach($settings['shipping_methods'] as $value) {
577
- if( preg_match('#^order_item_name:(.+)#',$value, $m) )
578
- $itemname_values[] = $m[1];
579
- else {
580
  $zone_values[] = $value;
581
  // for zones -- take instance_id!
582
- $m = explode(":", $value);
583
- if( count($m) > 1) {
584
  $zone_instance_values[] = $m[1];
585
- }
586
- }
587
- }
588
-
589
  // where by type!
590
  $ship_where = array();
591
- if( $zone_values ) {
592
- $zone_values = self::sql_subset( $zone_values );
593
  $ship_where[] = " (shipping_itemmeta.meta_key='method_id' AND shipping_itemmeta.meta_value IN ($zone_values) ) ";
594
  }
595
- if( $zone_instance_values ) { //since WooCommerce 3.4+ instead of $zone_values
596
  $zone_instance_values = self::sql_subset( $zone_instance_values );
597
- $ship_where[] = " (shipping_itemmeta.meta_key='instance_id' AND shipping_itemmeta.meta_value IN ($zone_instance_values ) ) ";
598
  }
599
- if( $itemname_values ) {
600
  $itemname_values = self::sql_subset( $itemname_values );
601
- $ship_where[] = " (order_shippings.order_item_name IN ( $itemname_values ) ) ";
602
  }
603
- $ship_where = join( ' OR ', $ship_where);
604
-
605
  //done
606
  $order_items_where .= " AND orders.ID IN (SELECT order_shippings.order_id FROM {$wpdb->prefix}woocommerce_order_items as order_shippings
607
  LEFT JOIN {$wpdb->prefix}woocommerce_order_itemmeta AS shipping_itemmeta ON shipping_itemmeta.order_item_id = order_shippings.order_item_id
608
  WHERE order_shippings.order_item_type='shipping' AND $ship_where )";
609
  }
610
-
611
  // check item names ?
612
  if ( ! empty( $settings['item_names'] ) ) {
613
- $filters = self::parse_complex_pairs( $settings['item_names'],
614
- array( 'coupon', 'fee', 'line_item', 'shipping', 'tax' ) );
615
- foreach ( $filters as $operator => $fields) {
616
  foreach ( $fields as $field => $values ) {
617
  if ( $values ) {
618
- if( $operator == 'IN' OR $operator == 'NOT IN' ) {
619
- $values = self::sql_subset( $values );
620
- $where_item_names = " SELECT order_id FROM {$wpdb->prefix}woocommerce_order_items WHERE order_item_type='$field' AND order_item_name $operator ($values) ";
621
  $order_items_where .= " AND orders.ID IN ($where_item_names)";
622
  }
623
  }//if values
624
  }
625
  }
626
  }
627
-
628
  // check item metadata
629
  if ( ! empty( $settings['item_metadata'] ) ) {
630
- $filters = self::parse_complex_pairs( $settings['item_metadata'] );
631
- foreach ( $filters as $operator => $fields) {
632
  foreach ( $fields as $field => $values ) {
633
  if ( $values ) {
634
- self::extract_item_type_and_key($field, $type, $key);
635
- $key = esc_sql($key);
636
- if( $operator == 'IN' OR $operator == 'NOT IN' ) {
637
- $values = self::sql_subset( $values );
638
  $where_item_metadata = " SELECT order_id FROM {$wpdb->prefix}woocommerce_order_items AS items
639
  JOIN {$wpdb->prefix}woocommerce_order_itemmeta AS meta ON meta.order_item_id = items.order_item_id
640
  WHERE order_item_type='$type' AND meta_key='$key' AND meta_value $operator ($values) ";
641
- $order_items_where .= " AND orders.ID IN ($where_item_metadata)";
642
  }
643
  }//if values
644
  }
645
  }
646
  }
647
-
648
 
649
  // pre top
650
- $left_join_order_meta = $order_meta_where = array();
651
  //add filter by custom fields in order
652
-
653
- if( $settings[ 'export_unmarked_orders' ] ) {
654
- $pos = "export_unmarked_orders";
655
- $field = "woe_order_exported";
656
  $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'";
657
  $order_meta_where [] = " ( ordermeta_cf_{$pos}.meta_value IS NULL ) ";
658
  }
659
 
660
  if ( $settings['order_custom_fields'] ) {
661
  $cf_names = self::get_order_custom_fields();
662
- $filters = self::parse_complex_pairs( $settings['order_custom_fields'], $cf_names);
663
- $pos=1;
664
- foreach ( $filters as $operator => $fields) {
665
  foreach ( $fields as $field => $values ) {
666
  if ( $values ) {
667
  $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'";
668
- if( $operator == 'IN' OR $operator == 'NOT IN' ) {
669
- $values = self::sql_subset( $values );
670
- $order_meta_where [] = " ( ordermeta_cf_{$pos}.meta_value $operator ($values) ) ";
671
- } elseif( $operator == 'NOT SET' ) {
672
- $order_meta_where [] = " ( ordermeta_cf_{$pos}.meta_value IS NULL ) ";
673
- } elseif( $operator == 'IS SET' ) {
674
- $order_meta_where [] = " ( ordermeta_cf_{$pos}.meta_value IS NOT NULL ) ";
675
- } elseif( in_array($operator, self::$operator_must_check_values) ) {
676
  $pairs = array();
677
- foreach($values as $v)
678
- $pairs[] = self::operator_compare_field_and_value( "`ordermeta_cf_{$pos}`.meta_value", $operator ,$v);
679
- $pairs = join("OR", $pairs);
680
- $order_meta_where[] = " ( $pairs ) ";
 
 
681
  }
682
- $pos++;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
683
  }//if values
684
  }
685
  }
686
  }
687
  if ( $settings['shipping_locations'] ) {
688
- $filters = self::parse_complex_pairs( $settings['shipping_locations'],
689
  array( 'city', 'state', 'postcode', 'country' ), 'lower_filter_label' );
690
- foreach ( $filters as $operator => $fields) {
691
  foreach ( $fields as $field => $values ) {
692
  $values = self::sql_subset( $values );
693
  if ( $values ) {
@@ -697,39 +783,59 @@ class WC_Order_Export_Data_Extractor {
697
  }
698
  }
699
  }
700
- if ( $settings['billing_locations'] ) {
701
- $filters = self::parse_complex_pairs( $settings['billing_locations'],
702
- array( 'city', 'state', 'postcode', 'country' ), 'lower_filter_label' );
703
- foreach ( $filters as $operator => $fields) {
704
- foreach ( $fields as $field => $values ) {
705
- $values = self::sql_subset( $values );
706
- if ( $values ) {
707
- $left_join_order_meta[] = "LEFT JOIN {$wpdb->postmeta} AS ordermeta_{$field} ON ordermeta_{$field}.post_id = orders.ID";
708
- $order_meta_where [] = " (ordermeta_{$field}.meta_key='_billing_$field' AND ordermeta_{$field}.meta_value $operator ($values)) ";
709
- }
710
- }
711
- }
712
- }
713
 
714
  // users
715
  $user_ids = array();
716
- if ( !empty($settings['user_names'] ) )
 
717
  $user_ids = array_filter( array_map( "intval", $settings['user_names'] ) );
 
 
 
718
  //roles
719
- if ( !empty($settings['user_roles'] ) ) {
720
- foreach( $settings['user_roles'] as $role) {
721
- //seek by role
722
- foreach( get_users( 'fields=ID&role=' . $role ) as $user_id )
723
- $user_ids[] = intval( $user_id );
724
- $user_ids = array_unique( $user_ids );
 
 
 
 
 
 
 
 
 
 
725
  }
 
 
726
  }
727
- $user_ids = apply_filters("woe_sql_get_customer_ids", $user_ids, $settings);
 
 
 
 
728
  //apply filter
729
  if ( $user_ids ) {
730
- $field = 'customer_user';
731
  $values = self::sql_subset( $user_ids );
732
- if( $values ) {
733
  $left_join_order_meta[] = "LEFT JOIN {$wpdb->postmeta} AS ordermeta_{$field} ON ordermeta_{$field}.post_id = orders.ID";
734
  $order_meta_where [] = " (ordermeta_{$field}.meta_key='_customer_user' AND ordermeta_{$field}.meta_value in ($values)) ";
735
  }
@@ -743,12 +849,14 @@ class WC_Order_Export_Data_Extractor {
743
  $left_join_order_meta[] = "LEFT JOIN {$wpdb->postmeta} AS ordermeta_{$field} ON ordermeta_{$field}.post_id = orders.ID";
744
  $order_meta_where [] = " (ordermeta_{$field}.meta_key='_{$field}' AND ordermeta_{$field}.meta_value in ($values)) ";
745
  }
 
 
746
 
747
- $order_meta_where = join( " AND ", apply_filters( "woe_sql_get_order_ids_order_meta_where" , $order_meta_where ) );
748
- if ( $order_meta_where ) {
749
  $order_meta_where = " AND " . $order_meta_where;
750
  }
751
- $left_join_order_meta = join( " ", apply_filters( "woe_sql_get_order_ids_left_joins" , $left_join_order_meta ) );
 
752
 
753
 
754
  //top_level
@@ -759,50 +867,58 @@ class WC_Order_Export_Data_Extractor {
759
 
760
  //setup order types to work with
761
  $order_types = array( "'" . self::$object_type . "'" );
762
- if($settings['export_refunds'])
763
- $order_types[] = "'shop_order_refund'";
764
- $order_types = join( ",", apply_filters( "woe_sql_order_types", $order_types ) );
 
765
 
766
  $sql = "SELECT " . apply_filters( "woe_sql_get_order_ids_fields", "ID AS order_id" ) . " FROM {$wpdb->posts} AS orders
767
  {$left_join_order_meta}
768
  WHERE orders.post_type in ( $order_types) AND $order_sql $order_meta_where $order_items_where";
769
-
770
- if( self::$track_sql_queries )
771
  self::$sql_queries[] = $sql;
 
 
772
  //die($sql);
773
  return $sql;
774
  }
775
 
776
- private static function add_date_filter(&$where, &$where_meta, $date_field, $value) {
777
- if( $date_field == 'date_paid' OR $date_field == 'date_completed') // 3.0+ uses timestamp
 
778
  $where_meta[] = "(order_$date_field.meta_value>0 AND order_$date_field.meta_value $value )";
779
- elseif( $date_field == 'paid_date' OR $date_field == 'completed_date') // previous versions use mysql datetime
780
- $where_meta[] = "(order_$date_field.meta_value<>'' AND order_$date_field.meta_value " . $value.")";
781
- else
 
782
  $where[] = "orders.post_" . $date_field . $value;
 
783
  }
784
 
785
- private static function apply_order_filters_to_sql(&$where,$settings) {
786
  global $wpdb;
787
  //default filter by date
788
- if( ! isset($settings[ 'export_rule_field' ]) )
789
- $settings[ 'export_rule_field' ] = 'modified';
 
790
 
791
- $date_field = $settings[ 'export_rule_field' ];
792
- $use_timestamps = ( $date_field == 'date_paid' OR $date_field == 'date_completed' );
793
  //rename this field for 2.6 and less
794
- if( !method_exists( 'WC_Order', "get_date_completed") ) {
795
  $use_timestamps = false;
796
- if( $date_field == 'date_paid' )
797
  $date_field = 'paid_date';
798
- elseif( $date_field == 'date_completed' )
799
  $date_field = 'completed_date';
 
800
  }
801
  $where_meta = array();
802
 
803
  // export and date rule
804
 
805
- foreach (self::get_date_range( $settings, true, $use_timestamps ) as $date ) {
806
  self::add_date_filter( $where, $where_meta, $date_field, $date );
807
  }
808
 
@@ -816,37 +932,40 @@ class WC_Order_Export_Data_Extractor {
816
  }
817
 
818
  //for date_paid or date_completed
819
- if( $where_meta ) {
820
- $where_meta = join( " AND ", $where_meta );
821
- $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)";
822
  }
823
-
824
  // skip child orders?
825
- if( $settings['skip_suborders'] AND !$settings['export_refunds'])
826
  $where[] = "orders.post_parent=0";
 
827
 
828
  // Skip drafts and deleted
829
  $where[] = "orders.post_status NOT in ('auto-draft','trash')";
830
  }
831
-
832
- public static function is_datetime_timestamp($ts) {
833
- return $ts % (24*3600) > 0;
834
  }
835
 
836
- public static function get_date_range( $settings, $is_for_sql, $use_timestamps=false ) {
837
  $result = array();
838
 
839
  // fixed date range
840
- if ( !empty( $settings['from_date'] ) OR !empty( $settings['to_date'] ) ) {
841
  if ( $settings['from_date'] ) {
842
  $ts = strtotime( $settings['from_date'] );
843
- if( self::is_datetime_timestamp($ts) )
844
  $from_date = date( 'Y-m-d H:i:s', $ts );
845
- else
846
  $from_date = date( 'Y-m-d', $ts ) . " 00:00:00";
 
847
  if ( $is_for_sql ) {
848
- if( $use_timestamps )
849
  $from_date = mysql2date( 'U', $from_date );
 
850
  $from_date = sprintf( ">='%s'", $from_date );
851
  }
852
  $result['from_date'] = $from_date;
@@ -854,17 +973,20 @@ class WC_Order_Export_Data_Extractor {
854
 
855
  if ( $settings['to_date'] ) {
856
  $ts = strtotime( $settings['to_date'] );
857
- if( self::is_datetime_timestamp($ts) )
858
  $to_date = date( 'Y-m-d H:i:s', $ts );
859
- else
860
  $to_date = date( 'Y-m-d', $ts ) . " 23:59:59";
 
861
  if ( $is_for_sql ) {
862
- if( $use_timestamps )
863
  $to_date = mysql2date( 'U', $to_date );
 
864
  $to_date = sprintf( "<='%s'", $to_date );
865
  }
866
  $result['to_date'] = $to_date;
867
  }
 
868
  return $result;
869
  }
870
 
@@ -963,8 +1085,9 @@ class WC_Order_Export_Data_Extractor {
963
 
964
  if ( isset( $from_date ) AND $from_date ) {
965
  if ( $is_for_sql ) {
966
- if( $use_timestamps )
967
  $from_date = mysql2date( 'U', $from_date );
 
968
  $from_date = sprintf( ">='%s'", $from_date );
969
  }
970
  $result['from_date'] = $from_date;
@@ -972,8 +1095,9 @@ class WC_Order_Export_Data_Extractor {
972
 
973
  if ( isset( $to_date ) AND $to_date ) {
974
  if ( $is_for_sql ) {
975
- if( $use_timestamps )
976
  $to_date = mysql2date( 'U', $to_date );
 
977
  $to_date = sprintf( "<='%s'", $to_date );
978
  }
979
  $result['to_date'] = $to_date;
@@ -984,34 +1108,38 @@ class WC_Order_Export_Data_Extractor {
984
 
985
  public static function get_quarter_month( $time ) {
986
  $month = date( "m", $time );
987
- if ( $month <= 3 )
988
  return 1;
989
- if ( $month <= 6 )
 
990
  return 4;
991
- if ( $month <= 9 )
 
992
  return 7;
 
993
 
994
  return 10;
995
  }
996
 
997
  public static function prepare_for_export() {
998
- self::$statuses = wc_get_order_statuses();
999
- self::$countries = WC()->countries->countries;
1000
- self::$prices_include_tax = get_option('woocommerce_prices_include_tax') == 'yes' ? true : false;
1001
- self::$decimal_separator = wc_get_price_decimal_separator();
1002
- self::$thousands_separator = apply_filters( 'woe_thousands_separator', '' );
1003
- self::$decimals = wc_get_price_decimals();
1004
- self::$export_subcategories_separator = apply_filters( 'woe_export_subcategories_separator', ">" );
1005
  self::$export_line_categories_separator = apply_filters( 'woe_export_line_categories_separator', ",\n" );
1006
  self::$export_itemmeta_values_separator = apply_filters( 'woe_export_itemmeta_values_separator', ", " );
 
1007
  }
1008
-
1009
  //for debug
1010
  public static function start_track_queries() {
1011
  self::$track_sql_queries = true;
1012
- self::$sql_queries = array();
1013
- }
1014
-
1015
  public static function get_sql_queries() {
1016
  return self::$sql_queries;
1017
  }
@@ -1069,7 +1197,7 @@ class WC_Order_Export_Data_Extractor {
1069
  } elseif ( $field == 'code' ) {
1070
  $row['code'] = $item["name"];
1071
  } elseif ( $field == 'discount_amount_plus_tax' ) {
1072
- $row['discount_amount_plus_tax'] = $item["discount_amount"] + $item["discount_amount_tax"];
1073
  } elseif ( isset( $coupon_meta[ $field ] ) ) {
1074
  $row[ $field ] = $coupon_meta[ $field ];
1075
  } elseif ( isset( $static_vals[ $field ] ) ) {
@@ -1078,20 +1206,24 @@ class WC_Order_Export_Data_Extractor {
1078
  $row[ $field ] = '';
1079
  }
1080
  if ( isset( $filters_active[ $field ] ) ) {
1081
- $row[ $field ] = apply_filters( "woe_get_order_coupon_value_{$field}", $row[ $field ], $order, $item );
1082
- $row[ $field ] = apply_filters( "woe_get_order_coupon_{$format}_value_{$field}", $row[ $field ], $order, $item );
 
 
1083
  }
1084
 
1085
- if ($field == 'excerpt') {
1086
- $post = get_page_by_title( $item['name'], OBJECT, 'shop_' . $item['type'] );
1087
- $row[ $field ] = $post? $post->post_excerpt : '';
1088
- }
1089
- if( $format_number_fields )
1090
- $row[ $field ] = self::format_numbers('order_coupon', $row[ $field ], $field);
 
1091
  }
1092
- $row = apply_filters('woe_fetch_order_coupon', $row, $item, $coupon_meta);
1093
- if( $row )
1094
  $coupons[] = $row;
 
1095
  }
1096
 
1097
  return apply_filters( "woe_fetch_order_coupons", $coupons, $order, $labels, $format, $static_vals );
@@ -1100,83 +1232,107 @@ class WC_Order_Export_Data_Extractor {
1100
 
1101
  /**
1102
  * @param WC_Order $order
1103
- * @param $labels
1104
- * @param $format
1105
- * @param $filters_active
1106
- * @param $static_vals
1107
- * @param $export_only_products
1108
- * @param $export_refunds
1109
  *
1110
  * @return array
1111
  */
1112
- public static function fetch_order_products( $order, $labels, $format, $filters_active, $static_vals , $export_only_products, $export_refunds, $skip_refunded_items, $strip_tags_product_fields, $format_number_fields ) {
1113
- $product_fields_with_tags = array( 'product_variation', 'post_content', 'post_excerpt');
1114
- $products = array();
1115
- $i = 0;
1116
- foreach ( $order->get_items('line_item') as $item_id=>$item ) {
 
 
 
 
 
 
 
 
 
 
 
1117
  do_action( "woe_get_order_product_item", $item );
1118
- if( $export_refunds AND $item['qty'] == 0 ) // skip zero items, when export refunds
 
1119
  continue;
 
1120
  // we export only matched products?
1121
- if( $export_only_products AND
1122
- !in_array($item['product_id'], $export_only_products ) AND // not product
1123
- ( !$item['variation_id'] OR !in_array($item['variation_id'], $export_only_products ) ) // not variation
1124
- )
 
1125
  continue;
 
1126
  $product = $order->get_product_from_item( $item );
1127
- $product = apply_filters( "woe_get_order_product", $product );
1128
  $item_meta = get_metadata( 'order_item', $item_id );
1129
- foreach($item_meta as $key=>$value) {
1130
- $clear_key = wc_sanitize_taxonomy_name( $key );
1131
- if ( taxonomy_exists( $clear_key ) ) {
1132
- $term = get_term_by( 'slug', $value[0], $clear_key );
1133
- $item_meta[$key][0] = isset( $term->name ) ? $term->name : $value[0];
1134
- if (strpos($key, 'attribute_') === false)
1135
- $item_meta['attribute_' . $key][0] = isset( $term->name ) ? $term->name : $value[0];
 
1136
  }
1137
- }
1138
  $item_meta = apply_filters( "woe_get_order_product_item_meta", $item_meta );
1139
- $product = apply_filters( "woe_get_order_product_and_item_meta", $product , $item_meta );
1140
- if( $product ) {
1141
- if( method_exists($product,'get_id') ) {
1142
- if ( $product->is_type( 'variation' ) )
1143
- $product_id = method_exists($product,'get_parent_id') ? $product->get_parent_id() : $product->parent->id;
1144
- else
 
1145
  $product_id = $product->get_id();
 
1146
  $post = get_post( $product_id );
1147
- } else { // legacy
1148
- $product_id = $product->id;
1149
- $post = $product->post;
1150
  }
1151
  } else {
1152
  $product_id = 0;
1153
- $post = false;
1154
  }
1155
 
1156
  // skip based on products/items/meta
1157
- if( apply_filters('woe_skip_order_item', false, $product, $item, $item_meta, $post) )
1158
  continue;
 
1159
 
1160
- if( $skip_refunded_items ) {
1161
  $qty_minus_refund = $item_meta["_qty"][0] + $order->get_qty_refunded_for_item( $item_id ); // Yes we add negative! qty
1162
- if( $qty_minus_refund <= 0 )
1163
  continue;
 
1164
  }
1165
 
1166
- $i++;
1167
- $row = array();
1168
  foreach ( $labels as $field => $label ) {
1169
  if ( strpos( $field, '__' ) !== false && $taxonomies = wc_get_product_terms( $item['product_id'],
1170
  substr( $field, 2 ), array( 'fields' => 'names' ) )
1171
  ) {
1172
  $row[ $field ] = implode( ', ', $taxonomies );
1173
  } else if ( $field == 'product_shipping_class' ) {
1174
- if( $taxonomies = wc_get_product_terms( $item['product_id'], $field, array( 'fields' => 'names' ) ) )
 
1175
  $row[ $field ] = implode( ', ', $taxonomies );
1176
- else
1177
- $row[ $field ] = ""; // unknown class
 
1178
  } elseif ( $field == 'line_total_plus_tax' ) {
1179
  $row[ $field ] = $item_meta["_line_total"][0] + $item_meta["_line_tax"][0];
 
 
1180
  } elseif ( $field == 'name' ) {
1181
  $row[ $field ] = $item["name"];
1182
  } elseif ( $field == 'product_name' ) {
@@ -1185,20 +1341,22 @@ class WC_Order_Export_Data_Extractor {
1185
  $row[ $field ] = self::get_product_variation( $item, $order, $item_id, $product );
1186
  } elseif ( $field == 'seller' ) {
1187
  $row[ $field ] = '';
1188
- if( $post ) {
1189
- $user = get_userdata( $post->post_author );
1190
  $row[ $field ] = ! empty( $user->display_name ) ? $user->display_name : '';
1191
  }
1192
  } elseif ( $field == 'post_content' ) {
1193
  $row[ $field ] = $post ? $post->post_content : '';
1194
  } elseif ( $field == 'post_excerpt' ) {
1195
- $row[ $field ] = $post ? $post->post_excerpt: '';
1196
  } elseif ( $field == 'type' ) {
1197
  $row[ $field ] = '';
1198
- if( $product )
1199
- $row[ $field ] = method_exists($product,'get_type') ? $product->get_type() : $product->product_type;
 
 
1200
  } elseif ( $field == 'tags' ) {
1201
- $terms = get_the_terms( $product_id, 'product_tag' );
1202
  $row[ $field ] = array();
1203
  if ( $terms ) {
1204
  foreach ( $terms as $term ) {
@@ -1207,7 +1365,7 @@ class WC_Order_Export_Data_Extractor {
1207
  }
1208
  $row[ $field ] = join( ",", $row[ $field ] );
1209
  } elseif ( $field == 'category' ) {
1210
- $terms = get_the_terms( $product_id, 'product_cat' );
1211
  $row[ $field ] = array();
1212
  if ( $terms ) {
1213
  foreach ( $terms as $term ) {
@@ -1217,18 +1375,18 @@ class WC_Order_Export_Data_Extractor {
1217
  $row[ $field ] = join( ",", $row[ $field ] );// hierarhy ???
1218
  } elseif ( $field == 'line_no_tax' ) {
1219
  $row[ $field ] = $item_meta["_line_total"][0];
1220
- //item refund
1221
  } elseif ( $field == 'line_total_refunded' ) {
1222
  $row[ $field ] = $order->get_total_refunded_for_item( $item_id );
1223
  } elseif ( $field == 'line_total_minus_refund' ) {
1224
  $row[ $field ] = $item_meta["_line_total"][0] - $order->get_total_refunded_for_item( $item_id );
1225
  } elseif ( $field == 'qty_minus_refund' ) {
1226
  $row[ $field ] = $item_meta["_qty"][0] + $order->get_qty_refunded_for_item( $item_id ); // Yes we add negative! qty
1227
- //tax refund
1228
  } elseif ( $field == 'line_tax_refunded' ) {
1229
- $row[ $field ] = self::get_order_item_taxes_refund($order, $item_id );
1230
  } elseif ( $field == 'line_tax_minus_refund' ) {
1231
- $row[ $field ] = $item_meta["_line_tax"][0] - self::get_order_item_taxes_refund($order, $item_id );
1232
  } elseif ( $field == 'line_id' ) {
1233
  $row[ $field ] = $i;
1234
  } elseif ( $field == 'item_id' ) {
@@ -1236,37 +1394,44 @@ class WC_Order_Export_Data_Extractor {
1236
  } elseif ( $field == 'item_price' ) {
1237
  $row[ $field ] = $order->get_item_total( $item, false, true ); // YES we have to calc item price
1238
  } elseif ( $field == 'discount_amount' ) {
1239
- if( method_exists($item, "get_subtotal"))
1240
- $row[ $field ] = $item->get_subtotal() - $item->get_total() ;
1241
- else //2.6
 
1242
  $row[ $field ] = $item['line_subtotal'] - $item['line_total'];
 
1243
  } elseif ( $field == 'tax_rate' ) {
1244
- if( method_exists($item, "get_subtotal")) {
1245
  $subtotal_amount = $item->get_subtotal();
1246
- $subtotal_tax = $item->get_subtotal_tax();
1247
  } else {
1248
  $subtotal_amount = $item['line_subtotal'];
1249
- $subtotal_tax = $item['line_subtotal_tax'];
1250
- }
1251
- $row[ $field ] = ($subtotal_amount>0) ? round( 100*$subtotal_tax/$subtotal_amount, 2) : 0;
1252
  } elseif ( $field == 'product_url' ) {
1253
  $row[ $field ] = get_permalink( $product_id );
1254
  } elseif ( $field == 'sku' ) {
1255
- $row[ $field ] = method_exists($product,'get_'.$field) ? $product->{'get_'.$field}() : get_post_meta( $product_id, '_' . $field, true );
 
 
1256
  } elseif ( $field == 'download_url' ) {
1257
  $row[ $field ] = '';
1258
  if ( $product AND $product->is_downloadable() ) {
1259
  $files = get_post_meta( $product_id, '_downloadable_files', true );
1260
  $links = array();
1261
- if( $files ) {
1262
- foreach ( $files as $file )
1263
  $links[] = $file['file'];
 
1264
  }
1265
  $row[ $field ] = implode( "\n", $links );
1266
  }
1267
  } elseif ( $field == 'image_url' ) {
1268
- $row[ $field ] = ( is_object( $product ) AND $product->get_image_id() ) ? current( wp_get_attachment_image_src( $product->get_image_id(),
1269
- 'full' ) ) : ''; // make full url
 
 
1270
  } elseif ( $field == 'full_category_names' ) {
1271
  $row[ $field ] = self::get_product_category_full( $product );
1272
  } elseif ( isset( $static_vals[ $field ] ) ) {
@@ -1278,35 +1443,50 @@ class WC_Order_Export_Data_Extractor {
1278
  } elseif ( isset( $item['item_meta'][ $field ] ) ) { // meta from item line
1279
  $row[ $field ] = join( self::$export_itemmeta_values_separator, $item['item_meta'][ $field ] );
1280
  } elseif ( isset( $item['item_meta'][ "_" . $field ] ) ) { // or hidden field
1281
- $row[ $field ] = join( self::$export_itemmeta_values_separator, $item['item_meta'][ "_" . $field ] );
 
1282
  } else {
1283
- $row[ $field ] = '';
1284
- if( !empty( $item['variation_id'] ) )
1285
  $row[ $field ] = get_post_meta( $item['variation_id'], $field, true );
1286
- if($row[ $field ] === '' ) // empty value ? try get custom!
 
 
1287
  $row[ $field ] = get_post_meta( $product_id, $field, true );
1288
- if($row[ $field ] === '' ) // empty value ?
1289
- $row[ $field ] = method_exists($product,'get_'.$field) ? $product->{'get_'.$field}() : get_post_meta( $product_id, '_' . $field, true );
1290
- if($row[ $field ] === '' AND empty( $item['variation_id'] ) ) // empty value ? try get attribute for !variaton
 
 
 
 
 
 
1291
  $row[ $field ] = $product ? $product->get_attribute( $field ) : '';
 
 
 
 
 
1292
  }
1293
-
1294
- if($strip_tags_product_fields AND in_array($field,$product_fields_with_tags) ) {
1295
- $row[$field] = strip_tags( $row[$field] );
1296
  }
1297
-
1298
- if( $format_number_fields )
1299
- $row[ $field ] = self::format_numbers('order_product', $row[ $field ], $field);
1300
-
1301
- if ( isset($row[ $field ] ) ) {
1302
- $row[ $field ] = apply_filters( "woe_get_order_product_value_{$field}", $row[ $field ] , $order, $item, $product, $item_meta);
1303
- $row[ $field ] = apply_filters( "woe_get_order_product_{$format}_value_{$field}", $row[ $field ] , $order, $item, $product, $item_meta);
1304
  }
1305
  }
1306
- $row = apply_filters( 'woe_fetch_order_product', $row, $order, $item, $product, $item_meta);
1307
- if( $row )
1308
  $products[ $item_id ] = $row;
 
1309
  }
 
1310
  return apply_filters( "woe_fetch_order_products", $products, $order, $labels, $format, $static_vals );
1311
  }
1312
 
@@ -1333,13 +1513,14 @@ class WC_Order_Export_Data_Extractor {
1333
  return join( self::$export_line_categories_separator, $full_names );
1334
  }
1335
 
1336
- public static function get_order_item_taxes_refund($order, $item_id) {
1337
- $tax_refund = 0;
1338
  $order_taxes = $order->get_taxes();
1339
  foreach ( $order_taxes as $tax_item ) {
1340
- $tax_item_id = $tax_item['rate_id'];
1341
- $tax_refund += $order->get_tax_refunded_for_item( $item_id, $tax_item_id );
1342
  }
 
1343
  return $tax_refund;
1344
  }
1345
 
@@ -1364,9 +1545,9 @@ class WC_Order_Export_Data_Extractor {
1364
 
1365
  // get order meta
1366
  $order_meta = array();
1367
- $recs = $wpdb->get_results( "SELECT meta_value,meta_key FROM {$wpdb->postmeta} WHERE post_id=$order_id" );
1368
- foreach ( $recs as $rec ) {
1369
- $order_meta[ $rec->meta_key ] = $rec->meta_value;
1370
  }
1371
 
1372
  // take order
@@ -1375,89 +1556,116 @@ class WC_Order_Export_Data_Extractor {
1375
  self::$date_format = trim( $options['date_format'] . ' ' . $options['time_format'] );
1376
 
1377
  // add fields for WC 3.0
1378
- foreach( array( "billing_country","billing_state","shipping_country","shipping_state") as $field_30 ) {
1379
- $$field_30 = method_exists($order,'get_'.$field_30) ? $order->{'get_'.$field_30}() : $order->$field_30;
 
1380
  }
1381
 
1382
- $parent_order_id = method_exists($order,'get_parent_id') ? $order->get_parent_id() : $order->post->post_parent;
1383
- $parent_order = $parent_order_id ? new WC_Order($parent_order_id) : false;
1384
- $post = method_exists($order,'get_id') ? get_post($order->get_id()) : $order->post;
 
1385
 
1386
  // correct meta for child orders
1387
- if( $parent_order_id ) {
1388
  // overwrite child values for refunds
1389
- $is_refund = ($post->post_type == 'shop_order_refund') ;
1390
- $overwrite_child_order_meta = apply_filters( 'woe_overwrite_child_order_meta', $is_refund ) ;
1391
- $recs = $wpdb->get_results( "SELECT meta_value,meta_key FROM {$wpdb->postmeta} WHERE post_id=$parent_order_id" );
1392
- foreach ( $recs as $rec ) {
1393
- if( $overwrite_child_order_meta OR !isset( $order_meta[ $rec->meta_key ] ) )
1394
- $order_meta[ $rec->meta_key ] = $rec->meta_value;
 
1395
  }
1396
 
1397
  //refund rewrites it
1398
  if ( $overwrite_child_order_meta ) {
1399
- foreach( array( "billing_country","billing_state","shipping_country","shipping_state") as $field_30 ) {
1400
- $$field_30 = method_exists($parent_order,'get_'.$field_30) ? $parent_order->{'get_'.$field_30}() : $parent_order->$field_30;
 
 
 
 
 
 
 
 
1401
  }
1402
  }
1403
  //refund status
1404
- if( $is_refund )
1405
  $order_status = 'refunded';
 
1406
  }
1407
 
1408
  // we know parent!
1409
  if ( $export['products'] OR isset( $labels['order']['count_unique_products'] ) OR isset( $labels['order']['total_weight_items'] ) OR $options['include_products'] ) {
1410
- $temp = $labels['products'];
1411
- $temp['qty'] = '';
1412
- $temp['weight'] = '';
1413
  $data['products'] = self::fetch_order_products( $order, $temp, $format,
1414
  $filters_active['products'], $static_vals['products'], $options['include_products'],
1415
- $options['export_refunds'] , $options['skip_refunded_items'], $options['strip_tags_product_fields'], $options['format_number_fields'] );
1416
- if( $options['include_products'] AND empty($data['products']) AND apply_filters("woe_skip_order_without_products", false) )
 
 
1417
  return array();
 
1418
  }
1419
  if ( $export['coupons'] OR isset( $labels['order']['coupons_used'] ) ) {
1420
  // get coupons from main order
1421
- $data['coupons'] = self::fetch_order_coupons( $parent_order ? $parent_order : $order, $labels['coupons'], $format,
1422
- $filters_active['coupons'], $get_coupon_meta, $static_vals['coupons'],$options['format_number_fields'] );
 
 
1423
  }
1424
 
1425
  // extra WP_User
1426
  $user = ! empty( $order_meta['_customer_user'] ) ? get_userdata( $order_meta['_customer_user'] ) : false;
1427
  // setup missed fields for full addresses
1428
- foreach( array( '_billing_address_2', '_shipping_address_2' ) as $optional_field) {
1429
- if( !isset($order_meta[$optional_field]) )
1430
- $order_meta[$optional_field] = '';
1431
- }
 
1432
 
1433
 
1434
  $order_fields = array();
1435
  // fill as it must
1436
  foreach ( $labels['order'] as $field => $label ) {
1437
- if(substr($field,0,5) == "USER_") { //user field
1438
- $key = substr($field,5);
1439
- $row[ $field ] = $user ? $user->get($key) : '';
1440
  } elseif ( $field == 'order_id' ) {
1441
  $row['order_id'] = $order_id;
1442
  } elseif ( $field == 'order_date' ) {
1443
- $row['order_date'] = !method_exists( $order, "get_date_created") ? $order->order_date : ( $order->get_date_created() ? gmdate( 'Y-m-d H:i:s', $order->get_date_created()->getOffsetTimestamp() ) : '' ) ;
 
 
1444
  } elseif ( $field == 'modified_date' ) {
1445
- $row['modified_date'] = !method_exists( $order, "get_date_modified") ? $order->modified_date : ( $order->get_date_modified() ? gmdate( 'Y-m-d H:i:s', $order->get_date_modified()->getOffsetTimestamp() ) : '' ) ;
 
 
1446
  } elseif ( $field == 'completed_date' ) {
1447
- $row['completed_date'] = !method_exists( $order, "get_date_completed") ? $order->completed_date : ( $order->get_date_completed() ? gmdate( 'Y-m-d H:i:s', $order->get_date_completed()->getOffsetTimestamp() ) : '' ) ;
 
 
1448
  } elseif ( $field == 'paid_date' ) {
1449
- $row['paid_date'] = !method_exists( $order, "get_date_paid") ? $order->paid_date : ( $order->get_date_paid() ? gmdate( 'Y-m-d H:i:s', $order->get_date_paid()->getOffsetTimestamp() ) : '' ) ;
 
 
1450
  } elseif ( $field == 'order_number' ) {
1451
  $row['order_number'] = $parent_order ? $parent_order->get_order_number() : $order->get_order_number(); // use parent order number
1452
  } elseif ( $field == 'order_subtotal' ) {
1453
- $row['order_subtotal'] = wc_format_decimal( $order->get_subtotal(), 2);
1454
  } elseif ( $field == 'order_subtotal_minus_discount' ) {
1455
  $row[ $field ] = $order->get_subtotal() - $order->get_total_discount();
1456
  } elseif ( $field == 'order_subtotal_refunded' ) {
1457
- $row['order_subtotal_refunded'] = wc_format_decimal( self::get_order_subtotal_refunded($order), 2);
1458
  } elseif ( $field == 'order_subtotal_minus_refund' ) {
1459
- $row['order_subtotal_minus_refund'] = wc_format_decimal( $order->get_subtotal() - self::get_order_subtotal_refunded($order), 2);
1460
- //order total
 
1461
  } elseif ( $field == 'order_total' ) {
1462
  $row['order_total'] = $order->get_total();
1463
  } elseif ( $field == 'order_total_no_tax' ) {
@@ -1466,19 +1674,19 @@ class WC_Order_Export_Data_Extractor {
1466
  $row['order_refund'] = $order->get_total_refunded();
1467
  } elseif ( $field == 'order_total_inc_refund' ) {
1468
  $row['order_total_inc_refund'] = $order->get_total() - $order->get_total_refunded();
1469
- //shipping
1470
  } elseif ( $field == 'order_shipping' ) {
1471
  $row['order_shipping'] = $order->get_total_shipping();
1472
  } elseif ( $field == 'order_shipping_refunded' ) {
1473
  $row['order_shipping_refunded'] = $order->get_total_shipping_refunded();
1474
  } elseif ( $field == 'order_shipping_minus_refund' ) {
1475
  $row['order_shipping_minus_refund'] = $order->get_total_shipping() - $order->get_total_shipping_refunded();
1476
- //shipping tax
1477
  } elseif ( $field == 'order_shipping_tax_refunded' ) {
1478
  $row['order_shipping_tax_refunded'] = self::get_order_shipping_tax_refunded( $order_id );
1479
  } elseif ( $field == 'order_shipping_tax_minus_refund' ) {
1480
  $row['order_shipping_tax_minus_refund'] = $order->get_shipping_tax() - self::get_order_shipping_tax_refunded( $order_id );
1481
- //order tax
1482
  } elseif ( $field == 'order_tax' ) {
1483
  $row['order_tax'] = wc_round_tax_total( $order->get_cart_tax() );
1484
  } elseif ( $field == 'order_total_tax' ) {
@@ -1488,19 +1696,21 @@ class WC_Order_Export_Data_Extractor {
1488
  } elseif ( $field == 'order_total_tax_minus_refund' ) {
1489
  $row['order_total_tax_minus_refund'] = wc_round_tax_total( $order->get_total_tax() - $order->get_total_tax_refunded() );
1490
  } elseif ( $field == 'order_status' ) {
1491
- $status = empty($order_status) ? $order->get_status() : $order_status ;
1492
  $status = 'wc-' === substr( $status, 0, 3 ) ? substr( $status, 3 ) : $status;
1493
  $row['order_status'] = isset( self::$statuses[ 'wc-' . $status ] ) ? self::$statuses[ 'wc-' . $status ] : $status;
1494
- } elseif ( $field == 'user_login' OR $field == 'user_email' ) {
1495
  $row[ $field ] = $user ? $user->$field : "";
1496
  } elseif ( $field == 'user_role' ) {
1497
- $row[ $field ] = ( isset($user->roles[0]) && isset($wp_roles->roles[$user->roles[0]]) ) ? $wp_roles->roles[$user->roles[0]]['name'] : ""; // take first role Name
1498
  } elseif ( $field == 'customer_total_orders' ) {
1499
  $row[ $field ] = ( isset( $user->ID ) ) ? wc_get_customer_order_count( $user->ID ) : 0;
1500
  } elseif ( $field == 'billing_address' ) {
1501
- $row[ $field ] = join(", ", array_filter( array( $order_meta["_billing_address_1"] , $order_meta["_billing_address_2"] ) ) );
 
1502
  } elseif ( $field == 'shipping_address' ) {
1503
- $row[ $field ] = join(", ", array_filter( array( $order_meta["_shipping_address_1"] , $order_meta["_shipping_address_2"] ) ) );
 
1504
  } elseif ( $field == 'billing_full_name' ) {
1505
  $row[ $field ] = trim( $order_meta["_billing_first_name"] . ' ' . $order_meta["_billing_last_name"] );
1506
  } elseif ( $field == 'shipping_full_name' ) {
@@ -1511,23 +1721,26 @@ class WC_Order_Export_Data_Extractor {
1511
  $row[ $field ] = isset( self::$countries[ $shipping_country ] ) ? self::$countries[ $shipping_country ] : $shipping_country;
1512
  } elseif ( $field == 'billing_state_full' ) {
1513
  $country_states = WC()->countries->get_states( $billing_country );
1514
- $row[ $field ] = isset( $country_states[ $billing_state ]) ? html_entity_decode( $country_states[ $billing_state ] ) : $billing_state;
1515
  } elseif ( $field == 'shipping_state_full' ) {
1516
  $country_states = WC()->countries->get_states( $shipping_country );
1517
- $row[ $field ] = isset( $country_states[ $shipping_state ]) ? html_entity_decode( $country_states[ $shipping_state ] ) : $shipping_state;
1518
  } elseif ( $field == 'billing_citystatezip' ) {
1519
- $row[ $field ] = self::get_city_state_postcode_field_value($order, 'billing');
1520
  } elseif ( $field == 'shipping_citystatezip' ) {
1521
- $row[ $field ] = self::get_city_state_postcode_field_value($order, 'shipping');
1522
  } elseif ( $field == 'products' OR $field == 'coupons' ) {
1523
  if ( $format == 'xls' OR $format == 'csv' OR $format == 'tsv' ) {
1524
  if ( $options[ $field . '_mode' ] == 'rows' ) {
1525
  //print_r(array_values($row));die();
1526
  //echo count($row)."-".(count($row)+count($labels[$field])-1)."|";
1527
- $items = apply_filters('woe_get_'. $field .'_items_for_' . $format.'_rows', array_values( $data[ $field ] ), $order); // remove keys for items in merge
1528
- self::csv_process_multi_rows( $field, $row, $extra_rows, $items, $labels[ $field ], $options['item_rows_start_from_new_line'] );
 
 
1529
  } else {
1530
- $items = apply_filters('woe_get_'. $field .'_items_for_' . $format.'_cols', array_values( $data[ $field ] ), $order);
 
1531
  self::csv_process_multi_cols( $field, $row, $items, $labels[ $field ], $csv_max[ $field ] );
1532
  }
1533
  } else {
@@ -1537,42 +1750,45 @@ class WC_Order_Export_Data_Extractor {
1537
  $row[ $field ] = $order->get_shipping_method();
1538
  } elseif ( $field == 'shipping_method' ) {
1539
  $shipping_methods = $order->get_items( 'shipping' );
1540
- $shipping_method = reset($shipping_methods); // take first entry
1541
- if ( ! empty( $shipping_method ) ) {
1542
- $row[ $field ] = $shipping_method['method_id'] . ':' . $shipping_method['instance_id'];
1543
- }
1544
  } elseif ( $field == 'coupons_used' ) {
1545
  $row[ $field ] = count( $data['coupons'] );
1546
  } elseif ( $field == 'total_weight_items' ) {
1547
- $row[$field] = 0;
1548
- foreach($data['products'] as $product) {
1549
- $row[$field] += $product['qty'] * $product['weight'];
1550
  }
1551
  } elseif ( $field == 'count_total_items' ) {
1552
  $row[ $field ] = $order->get_item_count();
1553
  } elseif ( $field == 'count_exported_items' ) {
1554
- $row[$field] = 0; // count only exported!
1555
- if( $export['products'] ) {
1556
- foreach($data['products'] as $product) {
1557
- $row[$field] += $product['qty'];
1558
  }
1559
- }
1560
  } elseif ( $field == 'count_unique_products' ) { // speed! replace with own counter ?
1561
  $row[ $field ] = count( $data['products'] );
1562
  } elseif ( $field == 'customer_note' ) {
1563
- $notes = array( $post->post_excerpt );
1564
- if( $options['export_refund_notes'] ) {
1565
- $refunds = $order->get_refunds();
1566
- foreach($refunds as $refund) {
1567
- // added get_reason for WC 3.0
1568
- $notes[] = method_exists($refund, 'get_reason') ? $refund->get_reason() : $refund->get_refund_reason();
1569
- }
 
1570
  }
1571
- $row[ $field ] = implode("\n", array_filter($notes) );
1572
  } elseif ( $field == 'first_refund_date' ) {
1573
  $value = '';
1574
- foreach( $order->get_refunds() as $refund) {
1575
- $value = !method_exists( $refund, "get_date_created") ? $refund->date : ( $refund->get_date_created() ? gmdate( 'Y-m-d H:i:s', $refund->get_date_created()->getOffsetTimestamp() ) : '' ) ;
 
 
1576
  break;// take only first
1577
  }
1578
  $row[ $field ] = $value;
@@ -1580,22 +1796,23 @@ class WC_Order_Export_Data_Extractor {
1580
  $row[ $field ] = $static_vals['order'][ $field ];
1581
  } elseif ( $field == 'order_notes' ) {
1582
  remove_filter( 'comments_clauses', array( 'WC_Comments', 'exclude_order_comments' ), 10 );
1583
- $args = array(
1584
- 'post_id' => $order_id,
1585
- 'approve' => 'approve',
1586
- 'type' => 'order_note',
1587
  );
1588
  $notes = get_comments( $args );
1589
  add_filter( 'comments_clauses', array( 'WC_Comments', 'exclude_order_comments' ), 10, 1 );
1590
  $comments = array();
1591
  if ( $notes ) {
1592
- foreach( $notes as $note ) {
1593
- if ( ! empty( $options['export_all_comments'] ) || $note->comment_author !== __( 'WooCommerce', 'woocommerce' ) ) { // skip system notes by default
1594
- $comments[] = apply_filters( 'woe_get_order_notes', $note->comment_content, $note, $order);
 
1595
  }
1596
  }
1597
  }
1598
- $row[ $field ] = implode("\n", $comments);
1599
  } elseif ( isset( $order_meta[ $field ] ) ) {
1600
  $field_data = array();
1601
  do_action( 'woocommerce_order_export_add_field_data', $field_data, $order_meta[ $field ], $field );
@@ -1606,42 +1823,49 @@ class WC_Order_Export_Data_Extractor {
1606
  } elseif ( isset( $order_meta[ "_" . $field ] ) ) { // or hidden field
1607
  $row[ $field ] = $order_meta[ "_" . $field ];
1608
  } else { // order_date...
1609
- $row[ $field ] = method_exists($order,'get_'.$field) ? $order->{'get_'.$field}() : get_post_meta( $order_id, '_' . $field, true );
 
1610
  //print_r($field."=".$label); echo "debug static!\n\n";
1611
  }
1612
 
1613
  //use empty value for missed field
1614
- if( $field != 'products' AND $field != 'coupons' ) {
1615
- if( !isset($row[ $field ]) )
1616
  $row[ $field ] = '';
1617
- if( is_array($row[ $field ]) )
 
1618
  $row[ $field ] = json_encode( $row[ $field ] );
1619
- }
1620
-
1621
- if( isset($row[ $field ]) ) {
1622
- if( $options['format_number_fields'] )
1623
- $row[ $field ] = self::format_numbers('order', $row[ $field ], $field);
1624
-
1625
- $row[ $field ] = apply_filters( "woe_get_order_value_{$field}", $row[ $field ] , $order, $field);
1626
- $row[ $field ] = apply_filters( "woe_get_order_{$format}_value_{$field}", $row[ $field ] , $order, $field);
1627
-
 
 
 
1628
  // must add empty column to extra rows
1629
- if( $field != 'products' AND $field != 'coupons' AND $extra_rows ) {
1630
- foreach($extra_rows as $idx=>$extra_row)
1631
- $extra_rows[$idx][$field] = "";
 
1632
  }
1633
  $order_fields[] = $field;
1634
  } //if order field set
1635
  }
1636
 
1637
- $row = apply_filters("woe_fetch_order", $row, $order);
1638
-
1639
  // Must fill child cells?
1640
- if ( empty($options['item_rows_start_from_new_line']) AND !empty($options['populate_other_columns_product_rows']) AND $extra_rows ) {
1641
- foreach ( $extra_rows as $idx=> $extra_row ) {
1642
- foreach ( $row as $key=> $val ) {
1643
- if ( in_array( $key, $order_fields) )
1644
- $extra_rows[ $idx ][ $key ] = $val;// copy main row values to new rows
 
1645
  }
1646
  }
1647
  }
@@ -1653,46 +1877,58 @@ class WC_Order_Export_Data_Extractor {
1653
  $extra_rows = array( $row );
1654
  }
1655
 
1656
- //don't encode products& coupons
1657
- foreach($extra_rows as $k => $extra_row) {
1658
- if($k != 'products' AND $k != 'coupons')
1659
- $extra_rows[$k] = array_map( function( $elem ) {
1660
- return is_array( $elem ) ? json_encode( $elem ) : $elem;
1661
- }, $extra_row );
 
 
1662
  }
1663
 
1664
- return apply_filters("woe_fetch_order_data",$extra_rows);
1665
  }
1666
 
1667
  public static function get_city_state_postcode_field_value( $order, $type ) {
1668
- if ( $type != 'shipping' && $type != 'billing') {
1669
  return null;
1670
  }
1671
  $citystatepostcode_fields_name = array(
1672
- $type.'_city',
1673
- $type.'_state',
1674
- $type.'_postcode'
1675
  );
1676
- $citystatepostcode = array();
1677
- foreach ($citystatepostcode_fields_name as $field_name){
1678
- $citystatepostcode[ $field_name ] = method_exists($order,'get_'.$field_name) ? $order->{'get_'.$field_name}() : $order->{$field_name};
 
1679
  }
1680
- return join( ", ", $citystatepostcode);
 
1681
  }
1682
 
1683
- public static function csv_process_multi_rows( $type, &$row, &$extra_rows, $items, $labels, $item_rows_start_from_new_line ) {
 
 
 
 
 
 
 
1684
  // to support
1685
  // order row
1686
  // item1 row
1687
  // item1 row
1688
- if( $item_rows_start_from_new_line ) {
1689
- foreach($items as $item) {
1690
  $new_row = array();
1691
  foreach ( $labels as $field => $label ) {
1692
- $new_row[ $type."_".$field ] = $item[ $field ];
1693
  }
1694
  $extra_rows[] = $new_row;
1695
- }
 
1696
  return;//done
1697
  }
1698
 
@@ -1700,36 +1936,40 @@ class WC_Order_Export_Data_Extractor {
1700
  // must add one record at least, if no coupons for example!
1701
  if ( empty( $items ) ) {
1702
  $item = array();
1703
- foreach ( $labels as $field => $label )
1704
  $item[ $field ] = "";
 
1705
  $items = array( $item );
1706
  }
1707
-
1708
  $pos = 0;
1709
  foreach ( $items as $data ) {
1710
  if ( $pos == 0 ) { //current row
1711
  foreach ( $labels as $field => $label ) {
1712
- $row[ $type."_".$field ] = $data[ $field ];
1713
  }
1714
  } else {
1715
  if ( ! isset( $extra_rows[ $pos - 1 ] ) ) {
1716
- $extra_rows[ $pos - 1 ] = array() ;
1717
  //add empty row with correct keys
1718
- foreach($row as $key=>$value)
1719
- $extra_rows[ $pos - 1 ][$key] = "";
 
1720
  }
1721
  //set columns with values
1722
- foreach ( $labels as $field => $label )
1723
- $extra_rows[ $pos - 1 ][ $type."_".$field ] = $data[ $field ];
 
1724
  }
1725
- $pos++;
1726
  }
1727
-
1728
  // Have we added new columns to ALL existing extra_rows ??
1729
- while( $pos <= count($extra_rows) ) {
1730
- foreach ( $labels as $field => $label )
1731
- $extra_rows[ $pos-1 ][ $type."_".$field ] = "";
1732
- $pos++;
 
1733
  }
1734
  }
1735
 
@@ -1737,19 +1977,19 @@ class WC_Order_Export_Data_Extractor {
1737
  for ( $i = 0; $i < $csv_max; $i ++ ) {
1738
  if ( empty( $data[ $i ] ) ) {
1739
  foreach ( $labels as $field => $label ) {
1740
- $row[ $type."_".$field."_".$i ] = "";
1741
  }
1742
  } else {
1743
  foreach ( $labels as $field => $label ) {
1744
- $row[ $type."_".$field."_".$i ] = $data[ $i ][ $field ];
1745
  }
1746
  }
1747
  }
1748
  }
1749
 
1750
- public static function get_order_shipping_tax_refunded($order_id) {
1751
  global $wpdb;
1752
- $refund_ship_taxes = $wpdb->get_var( $wpdb->prepare( "
1753
  SELECT SUM( order_itemmeta.meta_value )
1754
  FROM {$wpdb->prefix}woocommerce_order_itemmeta AS order_itemmeta
1755
  INNER JOIN $wpdb->posts AS posts ON ( posts.post_type = 'shop_order_refund' AND posts.post_parent = %d )
@@ -1758,15 +1998,16 @@ class WC_Order_Export_Data_Extractor {
1758
  AND order_itemmeta.meta_key IN ( 'shipping_tax_amount')
1759
  ", $order_id ) );
1760
 
1761
- return abs( $refund_ship_taxes );
1762
  }
1763
-
1764
- public static function get_order_subtotal_refunded($order) {
1765
- $subtotal_refund = 0 ;
1766
- foreach($order->get_refunds() as $refund){
1767
  $subtotal_refund += $refund->get_subtotal();
1768
  }
1769
- return abs($subtotal_refund);
 
1770
  }
1771
 
1772
  /**
@@ -1775,46 +2016,51 @@ class WC_Order_Export_Data_Extractor {
1775
  public static function get_product_variation( $item, $order, $item_id, $product ) {
1776
  global $wpdb;
1777
  $hidden_order_itemmeta = apply_filters( 'woocommerce_hidden_order_itemmeta', array(
1778
- '_qty',
1779
- '_tax_class',
1780
- '_product_id',
1781
- '_variation_id',
1782
- '_line_subtotal',
1783
- '_line_subtotal_tax',
1784
- '_line_total',
1785
- '_line_tax',
1786
- 'method_id',
1787
- 'cost',
1788
  ) );
1789
 
1790
  $result = array();
1791
 
1792
- $value_delimiter = apply_filters('woe_fetch_item_meta_value_delimiter', ': ');
1793
 
1794
  // pull meta directly
1795
  $meta_data = $wpdb->get_results( $wpdb->prepare( "SELECT meta_key, meta_value, meta_id, order_item_id
1796
  FROM {$wpdb->prefix}woocommerce_order_itemmeta WHERE order_item_id = %d
1797
  ORDER BY meta_id", $item_id ), ARRAY_A );
1798
- foreach( $meta_data as $meta) {
1799
- if ( in_array( $meta['meta_key'], $hidden_order_itemmeta ) )
1800
  continue;
1801
- if ( is_serialized( $meta['meta_value'] ) )
 
1802
  continue;
 
1803
 
1804
  //known attribute?
1805
  if ( taxonomy_exists( wc_sanitize_taxonomy_name( $meta['meta_key'] ) ) ) {
1806
- $term = get_term_by( 'slug', $meta['meta_value'], wc_sanitize_taxonomy_name( $meta['meta_key'] ) );
 
1807
  $meta['meta_key'] = wc_attribute_label( wc_sanitize_taxonomy_name( $meta['meta_key'] ) );
1808
  $meta['meta_value'] = isset( $term->name ) ? $term->name : $meta['meta_value'];
1809
  } else {
1810
- $meta['meta_key'] = apply_filters( 'woocommerce_attribute_label', wc_attribute_label( $meta['meta_key'], $product ), $meta['meta_key'] );
 
1811
  }
1812
 
1813
- $value = wp_kses_post( $meta['meta_key'] ) . $value_delimiter . wp_kses_post( force_balance_tags( $meta['meta_value'] ) );
1814
- $result[] = apply_filters('woe_fetch_item_meta', $value, $meta, $item , $product );
1815
  }
 
1816
  //list to string!
1817
- return join( apply_filters('woe_fetch_item_meta_lines_delimiter', ' | '), array_filter($result) );
1818
  }
1819
 
1820
  /**
@@ -1822,45 +2068,51 @@ class WC_Order_Export_Data_Extractor {
1822
  */
1823
  public static function get_shipping_methods() {
1824
  global $wpdb;
1825
-
1826
  $shipping_methods = array();
1827
-
1828
  // get raw names
1829
  $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" );
1830
- foreach($raw_methods as $method)
1831
  $shipping_methods[ 'order_item_name:' . $method ] = $method;
1832
-
 
1833
  // try get methods for zones
1834
- if( !class_exists("WC_Shipping_Zone") )
1835
  return $shipping_methods;
 
1836
 
1837
- if( !method_exists("WC_Shipping_Zone", "get_shipping_methods") )
1838
  return $shipping_methods;
 
1839
 
1840
  foreach ( WC_Shipping_Zones::get_zones() as $zone ) {
1841
  $methods = $zone['shipping_methods'];
1842
  /** @var WC_Shipping_Method $method */
1843
  foreach ( $methods as $method ) {
1844
- $shipping_methods[ $method->get_rate_id() ] = '[' . $zone['zone_name'] . '] ' . $method->get_title();
1845
  }
1846
  }
1847
-
1848
  $zone = new WC_Shipping_Zone( 0 );
1849
  $methods = $zone->get_shipping_methods();
1850
  /** @var WC_Shipping_Method $method */
1851
  foreach ( $methods as $method ) {
1852
- $shipping_methods[ $method->get_rate_id() ] = __('[Rest of the World]', 'woo-order-export-lite' ) .' '. $method->get_title();
 
1853
  }
1854
-
1855
  return $shipping_methods;
1856
  }
1857
-
1858
- public static function format_numbers($object, $value, $field) {
1859
- $option = WC_Order_Export_Engine::$current_job_settings[$object.'_fields'][$field];
1860
- if( isset($option['format']) AND ($option['format']=='money' OR $option['format']=='number' ) ) {
1861
- $new_value = number_format( floatval($value), self::$decimals, self::$decimal_separator, self::$thousands_separator );
1862
- $value = apply_filters( 'woe_format_numbers', $new_value, $value);
 
1863
  }
 
1864
  return $value;
1865
  }
1866
 
16
  static $export_subcategories_separator;
17
  static $export_line_categories_separator;
18
  static $export_itemmeta_values_separator;
19
+ static $export_custom_fields_separator;
20
  static $track_sql_queries = false;
21
  static $sql_queries;
22
  static $operator_must_check_values = array( 'LIKE', '>', '<', '>=', '<=' );
23
+ const HUGE_SHOP_ORDERS = 1000;// more than 1000 orders
24
+ const HUGE_SHOP_PRODUCTS = 1000;// more than 1000 products
25
+ const HUGE_SHOP_CUSTOMERS = 1000;// more than 1000 users
26
 
27
 
28
  //Common
29
+
30
  // to parse "item_type:meta_key" strings
31
  public static function extract_item_type_and_key( $meta_key, &$type, &$key ) {
32
+ $t = explode( ":", $meta_key );
33
+ $type = array_shift( $t );
34
+ $key = join( ":", $t );
35
  }
36
 
37
  public static function get_order_custom_fields() {
39
  $transient_key = 'woe_get_order_custom_fields_result';
40
 
41
  $fields = get_transient( $transient_key );
42
+ if ( $fields === false ) {
43
  $total_orders = $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->posts} WHERE post_type = '" . self::$object_type . "'" );
44
  //small shop , take all orders
45
+ if ( $total_orders < self::HUGE_SHOP_ORDERS ) {
46
  $fields = $wpdb->get_col( "SELECT DISTINCT meta_key FROM {$wpdb->posts} INNER JOIN {$wpdb->postmeta} ON {$wpdb->posts}.ID = {$wpdb->postmeta}.post_id WHERE post_type = '" . self::$object_type . "'" );
47
+ } else { // we have a lot of orders, take last good orders, upto 1000
48
+ $order_ids = $wpdb->get_col( "SELECT ID FROM {$wpdb->posts} WHERE post_type = '" . self::$object_type . "' AND post_status IN('wc-on-hold','wc-processing','wc-completed') ORDER BY post_date DESC LIMIT 1000" );
49
  $order_ids[] = 0; // add fake zero
50
+ $order_ids = join( ",", $order_ids );
51
+ $fields = $wpdb->get_col( "SELECT DISTINCT meta_key FROM {$wpdb->postmeta} WHERE post_id IN ($order_ids)" );
52
  }
53
  sort( $fields );
54
  set_transient( $transient_key, $fields, 60 ); //valid for a minute
55
  }
56
+
57
  return apply_filters( 'woe_get_order_custom_fields', $fields );
58
  }
59
+
60
+ public static function get_user_custom_fields() {
61
+ global $wpdb;
62
+ $transient_key = 'woe_get_user_custom_fields_result';
63
+
64
+ $fields = get_transient( $transient_key );
65
+ if ( $fields === false ) {
66
+ $total_users = $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->users}" );
67
+ if ( $total_users < self::HUGE_SHOP_CUSTOMERS ) {
68
+ $fields = $wpdb->get_col( "SELECT DISTINCT meta_key FROM {$wpdb->usermeta}" );
69
+ } else { // we have a lot of users, so take last users, upto 1000
70
+ $user_ids = $wpdb->get_col( "SELECT ID FROM {$wpdb->users} ORDER BY ID DESC LIMIT 1000" );
71
+ $user_ids = join( ",", $user_ids );
72
+ $fields = $wpdb->get_col( "SELECT DISTINCT meta_key FROM {$wpdb->usermeta} WHERE user_id IN ($user_ids)" );
73
+ }
74
+ sort( $fields );
75
+ set_transient( $transient_key, $fields, 60 ); //valid for a minute
76
+ }
77
+
78
+ return apply_filters( 'woe_get_user_custom_fields', $fields );
79
+ }
80
+
81
  public static function get_product_attributes() {
82
  global $wpdb;
83
 
108
  return apply_filters( 'woe_get_product_attributes', $attrs );
109
  }
110
 
111
+ public static function get_product_itemmeta() {
112
  global $wpdb;
113
  $transient_key = 'woe_get_product_itemmeta_result';
114
 
115
  $metas = get_transient( $transient_key );
116
+ if ( $metas === false ) {
117
  // WP internal table, take all metas
118
  $metas = $wpdb->get_col( "SELECT DISTINCT meta.meta_key FROM {$wpdb->prefix}woocommerce_order_itemmeta meta inner join {$wpdb->prefix}woocommerce_order_items item on item.order_item_id=meta.order_item_id and item.order_item_type = 'line_item' " );
119
+ sort( $metas );
120
  set_transient( $transient_key, $metas, 60 ); //valid for a minute
121
  }
122
+
123
  return apply_filters( 'woe_get_product_itemmeta', $metas );
124
  }
125
 
128
 
129
  $attrs = array();
130
 
131
+ if ( function_exists( "wc_get_attribute_taxonomies" ) ) {
132
+ $wc_attrs = wc_get_attribute_taxonomies();
133
+ foreach ( $wc_attrs as $attr ) {
134
+ $attrs[ "pa_" . $attr->attribute_name ] = "pa_" . $attr->attribute_name;
135
+ }
136
+ }
137
+
138
  // WP internal table, take all taxonomies for products
 
139
  $wp_fields = $wpdb->get_col( "SELECT DISTINCT taxonomy FROM {$wpdb->term_relationships}
140
  JOIN {$wpdb->term_taxonomy} ON {$wpdb->term_taxonomy}.term_taxonomy_id = {$wpdb->term_relationships}.term_taxonomy_id
141
  WHERE {$wpdb->term_relationships}.object_id IN (SELECT DISTINCT ID FROM {$wpdb->posts} WHERE post_type = 'product' OR post_type='product_variation')" );
152
  $transient_key = 'woe_get_product_custom_fields_result';
153
 
154
  $fields = get_transient( $transient_key );
155
+ if ( $fields === false ) {
156
  //rewrite for huge # of products
157
  $total_products = $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->posts} WHERE post_type = 'product' OR post_type='product_variation' " );
158
  //small shop , take all orders
159
+ if ( $total_products < self::HUGE_SHOP_PRODUCTS ) {
160
  $fields = $wpdb->get_col( "SELECT DISTINCT meta_key FROM {$wpdb->posts} INNER JOIN {$wpdb->postmeta} ON {$wpdb->posts}.ID = {$wpdb->postmeta}.post_id WHERE post_type = 'product' OR post_type='product_variation' " );
161
+ } else { // we have a lot of orders, take last good orders, upto 1000
162
+ $product_ids = $wpdb->get_col( "SELECT ID FROM {$wpdb->posts} WHERE post_type IN('product','product_variation') ORDER BY post_date DESC LIMIT 1000" );
163
  $product_ids[] = 0; // add fake zero
164
+ $product_ids = join( ",", $product_ids );
165
+ $fields = $wpdb->get_col( "SELECT DISTINCT meta_key FROM {$wpdb->postmeta} WHERE post_id IN ($product_ids)" );
166
  }
167
  sort( $fields );
168
  set_transient( $transient_key, $fields, 60 ); //valid for a minute
169
  }
170
+
171
  return apply_filters( 'woe_get_product_custom_fields', $fields );
172
  }
173
 
195
  $pair_types = array();
196
  $delimiters = array(
197
  'NOT SET' => 'NOT SET',
198
+ 'IS SET' => 'IS SET',
199
+ 'LIKE' => 'LIKE',
200
+ '<>' => 'NOT IN',
201
+ '>=' => '>=',
202
+ '<=' => '<=',
203
+ '>' => '>',
204
+ '<' => '<',
205
+ '=' => 'IN',
206
  );
207
+ $single_ops = array( 'NOT SET', 'IS SET' );
208
+
209
  foreach ( $pairs as $pair ) {
210
+ $pair = trim( $pair );
211
+ $op = '';
212
  $single_op = false;
213
+ foreach ( $delimiters as $delim => $op_seek ) {
214
+ $t = explode( $delim, $pair );
215
+ $single_op = in_array( $delim, $single_ops );
216
+ if ( count( $t ) == 2 ) {
217
  $op = $op_seek;
218
  break;
219
  }
220
  }
221
+ if ( ! $op ) {
222
  continue;
223
+ }
224
+ if ( $single_op ) {
225
  $t[1] = '';
226
+ }
227
 
228
+ list( $filter_type, $filter_value ) = array_map( "trim", $t );
229
  $empty = __( 'empty', 'woo-order-export-lite' );
230
  if ( $empty == $filter_value ) {
231
  $filter_value = '';
234
  if ( $mode == 'lower_filter_label' ) {
235
  $filter_type = strtolower( $filter_type );
236
  } // Country=>country for locations
237
+
238
+ if ( $valid_types AND ! in_array( $filter_type, $valid_types ) ) {
239
  continue;
240
  }
241
+
242
+ $filter_type = addslashes( $filter_type );
243
  if ( ! isset( $pair_types[ $op ] ) ) {
244
  $pair_types[ $op ] = array();
245
  }
246
  if ( ! isset( $pair_types[ $op ] [ $filter_type ] ) ) {
247
  $pair_types[ $op ] [ $filter_type ] = array();
248
  }
249
+ $pair_types[ $op ][ $filter_type ][] = addslashes( $filter_value );
250
  }
251
+
252
  return $pair_types;
253
  }
254
 
273
  public static function sql_get_product_ids( $settings ) {
274
  global $wpdb;
275
 
276
+ $product_where = self::sql_build_product_filter( $settings );
277
 
278
  $wc_order_items_meta = "{$wpdb->prefix}woocommerce_order_itemmeta";
279
  $left_join_order_items_meta = $order_items_meta_where = array();
281
  // filter by product
282
  if ( $product_where ) {
283
  $left_join_order_items_meta[] = "LEFT JOIN $wc_order_items_meta AS orderitemmeta_product ON orderitemmeta_product.order_item_id = order_items.order_item_id";
284
+ $order_items_meta_where[] = " (orderitemmeta_product.meta_key IN ('_variation_id', '_product_id') $product_where)";
285
  } else {
286
  $left_join_order_items_meta[] = "LEFT JOIN $wc_order_items_meta AS orderitemmeta_product ON orderitemmeta_product.order_item_id = order_items.order_item_id";
287
  $order_items_meta_where[] = " orderitemmeta_product.meta_key IN ('_variation_id', '_product_id')";
292
  $attrs = self::get_product_attributes();
293
  $names2fields = array_flip( $attrs );
294
  $filters = self::parse_complex_pairs( $settings['product_attributes'], $attrs );
295
+ foreach ( $filters as $operator => $fields ) {
296
  foreach ( $fields as $field => $values ) {
297
+ $field = $names2fields[ $field ];
298
  if ( $values ) {
299
  $left_join_order_items_meta[] = "LEFT JOIN $wc_order_items_meta AS `orderitemmeta_{$field}` ON `orderitemmeta_{$field}`.order_item_id = order_items.order_item_id";
300
+ if ( $operator == 'IN' OR $operator == 'NOT IN' ) {
301
+ $values = self::sql_subset( $values );
302
+ $order_items_meta_where[] = " (`orderitemmeta_{$field}`.meta_key='$field' AND `orderitemmeta_{$field}`.meta_value $operator ($values) ) ";
303
+ } elseif ( in_array( $operator, self::$operator_must_check_values ) ) {
304
  $pairs = array();
305
+ foreach ( $values as $v ) {
306
+ $pairs[] = self::operator_compare_field_and_value( "`orderitemmeta_{$field}`.meta_value",
307
+ $operator, $v );
308
+ }
309
+ $pairs = join( "OR", $pairs );
310
+ $order_items_meta_where[] = " (`orderitemmeta_{$field}`.meta_key='$field' AND ($pairs) ) ";
311
  }
312
  }
313
  }// values
314
  }// operators
315
  }
316
 
317
+ //by attrbutes in woocommerce_order_itemmeta
318
  if ( $settings['product_itemmeta'] ) {
319
+ foreach ( $settings['product_itemmeta'] as $value ) {
320
+ $settings['product_itemmeta'][] = esc_html( $value );
321
+ }
322
+
323
+ $itemmeta = self::get_product_itemmeta();
324
+ $filters = self::parse_complex_pairs( $settings['product_itemmeta'], $itemmeta );
325
+ foreach ( $filters as $operator => $fields ) {
326
+ foreach ( $fields as $field => $values ) {
327
+ ;
328
  if ( $values ) {
329
  $left_join_order_items_meta[] = "LEFT JOIN $wc_order_items_meta AS `orderitemmeta_{$field}` ON `orderitemmeta_{$field}`.order_item_id = order_items.order_item_id";
330
+ if ( $operator == 'IN' OR $operator == 'NOT IN' ) {
331
+ $values = self::sql_subset( $values );
332
+ $order_items_meta_where[] = " (`orderitemmeta_{$field}`.meta_key='$field' AND `orderitemmeta_{$field}`.meta_value $operator ($values) ) ";
333
+ } elseif ( in_array( $operator, self::$operator_must_check_values ) ) {
334
  $pairs = array();
335
+ foreach ( $values as $v ) {
336
+ $pairs[] = self::operator_compare_field_and_value( "`orderitemmeta_{$field}`.meta_value",
337
+ $operator, $v );
338
+ }
339
+ $pairs = join( "OR", $pairs );
340
+ $order_items_meta_where[] = " (`orderitemmeta_{$field}`.meta_key='$field' AND ($pairs) ) ";
341
  }
342
  }// values
343
  }
346
 
347
  $orders_where = array();
348
  self::apply_order_filters_to_sql( $orders_where, $settings );
349
+ if ( $orders_where ) {
350
  $left_join_order_items_meta[] = "LEFT JOIN {$wpdb->posts} AS `orders` ON `orders`.ID = order_items.order_id";
351
+ $order_items_meta_where[] = "( " . join( " AND ", $orders_where ) . " )";
352
  }
353
 
354
  $order_items_meta_where = join( " AND ", $order_items_meta_where );
359
 
360
 
361
  // final sql from WC tables
362
+ if ( ! $order_items_meta_where ) {
363
  return false;
364
+ }
365
 
366
+ $sql = "SELECT DISTINCT p_id FROM
367
  (SELECT order_items.order_item_id as order_item_id, MAX(CONVERT(orderitemmeta_product.meta_value ,UNSIGNED INTEGER)) as p_id FROM {$wpdb->prefix}woocommerce_order_items as order_items
368
  $left_join_order_items_meta
369
  WHERE order_item_type='line_item' $order_items_meta_where GROUP BY order_item_id
370
  ) AS temp";
371
+ if ( self::$track_sql_queries ) {
372
  self::$sql_queries[] = $sql;
373
+ }
374
+
375
  return $sql;
376
  }
377
 
380
  global $wpdb;
381
 
382
  // has exact products?
383
+ if ( $settings['products'] ) {
384
  ;// do nothing
385
+ } elseif ( empty( $settings['product_vendors'] ) AND empty( $settings['product_custom_fields'] ) ) {
386
  $settings['products'] = array();
387
+ } else {
388
+ $product_where = array( "1" );
389
 
390
  //by owners
391
+ $settings['product_vendors'] = apply_filters( 'woe_sql_get_product_vendor_ids',
392
+ $settings['product_vendors'], $settings );
393
  if ( $settings['product_vendors'] ) {
394
+ $values = self::sql_subset( $settings['product_vendors'] );
395
+ $product_where[] = " products.post_author in ($values)";
396
  }
397
 
398
  //by custom fields in Product
399
+ $product_meta_where = "";
400
  $left_join_product_meta = "";
401
  if ( $settings['product_custom_fields'] ) {
402
  $left_join_product_meta = $product_meta_where = array();
403
+ $cf_names = self::get_product_custom_fields();
404
+ $filters = self::parse_complex_pairs( $settings['product_custom_fields'], $cf_names );
405
+ $pos = 1;
406
+ foreach ( $filters as $operator => $fields ) {
407
  foreach ( $fields as $field => $values ) {
408
  if ( $values ) {
409
  $left_join_product_meta[] = "LEFT JOIN {$wpdb->postmeta} AS productmeta_cf_{$pos} ON productmeta_cf_{$pos}.post_id = products.ID";
410
+ if ( $operator == 'IN' OR $operator == 'NOT IN' ) {
411
+ $values = self::sql_subset( $values );
412
+ $product_meta_where[] = " (productmeta_cf_{$pos}.meta_key='$field' AND productmeta_cf_{$pos}.meta_value $operator ($values)) ";
413
+ } elseif ( in_array( $operator, self::$operator_must_check_values ) ) {
414
  $pairs = array();
415
+ foreach ( $values as $v ) {
416
+ $pairs[] = self::operator_compare_field_and_value( "`productmeta_cf_{$pos}`.meta_value",
417
+ $operator, $v );
418
+ }
419
+ $pairs = join( "OR", $pairs );
420
+ $product_meta_where[] = " (productmeta_cf_{$pos}.meta_key='$field' AND ($pairs) ) ";
421
  }
422
+ $pos ++;
423
  }//if values
424
  }
425
  }
426
 
427
+ if ( $filters ) {
428
+ $product_where[] = join( " AND ", $product_meta_where );
429
  $left_join_product_meta = join( " ", $left_join_product_meta );
430
  }
431
  }
432
  //done
433
+ $product_where = join( " AND ", $product_where );
434
+ $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 ";
435
+ $settings['products'] = $wpdb->get_col( $sql );
436
  }
437
+
438
  // we have to use variations , if user sets product attributes
439
  if ( $settings['products'] AND $settings['product_attributes'] ) {
440
+ $values = self::sql_subset( $settings['products'] );
441
+ $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)";
442
+ $settings['products'] = $wpdb->get_col( $sql );
443
  }
444
+ if ( ! empty( $sql ) AND self::$track_sql_queries ) {
445
  self::$sql_queries[] = $sql;
446
+ }
447
+
448
+ return apply_filters( 'woe_sql_adjust_products', $settings['products'], $settings );
449
  }
450
 
451
 
459
  $names2fields = array_flip( $attrs );
460
  $filters = self::parse_complex_pairs( $settings['product_taxonomies'], $attrs );
461
  //print_r($filters );die();
462
+ foreach ( $filters as $operator => $fields ) {
463
  foreach ( $fields as $label => $values ) {
464
  $field = $names2fields[ $label ];
465
  $values = self::sql_subset( $values );
466
  if ( $values ) {
467
+ $label = esc_sql( $label );
468
+ $taxonomy_where .= " AND orderitemmeta_product.meta_value $operator (SELECT object_id FROM {$wpdb->term_relationships} AS `{$field}_rel`
469
  INNER JOIN {$wpdb->term_taxonomy} AS `{$field}_cat` ON `{$field}_cat`.term_taxonomy_id = `{$field}_rel`.term_taxonomy_id
470
  WHERE `{$field}_cat`.taxonomy='$label' AND `{$field}_cat`.term_id IN (SELECT term_id FROM {$wpdb->terms} WHERE name IN ($values) ) )";
471
  }
472
  }
473
+ }
474
  }
475
 
476
  $product_category_where = "";
482
  $cat_ids[] = $child_id;
483
  }
484
  }
485
+ $cat_ids = join( ',', $cat_ids );
486
+ $product_category_where = "SELECT DISTINCT object_id FROM {$wpdb->term_relationships} AS product_in_cat
487
  LEFT JOIN {$wpdb->term_taxonomy} AS product_category ON product_category.term_taxonomy_id = product_in_cat.term_taxonomy_id
488
  WHERE product_category.term_id IN ($cat_ids)
489
  ";
497
  ";
498
  }
499
 
500
+ $settings['products'] = self::sql_get_filtered_product_list( $settings );
501
 
502
  // deep level still
503
  $exact_product_where = '';
504
  if ( $settings['products'] ) {
505
  $values = self::sql_subset( $settings['products'] );
506
  if ( $values ) {
507
+ $exact_product_where = "AND orderitemmeta_product.meta_value IN ($values)";
508
  }
509
  }
510
+ $product_where = join( " ",
511
+ array_filter( array( $taxonomy_where, $product_category_where, $exact_product_where ) ) );
512
+
513
  //skip empty values
514
+ if ( $product_where ) {
515
+ $product_where = "AND orderitemmeta_product.meta_value<>'0' " . $product_where;
516
+ }
517
+
518
+ return $product_where;
519
  }
520
 
521
+ static function operator_compare_field_and_value( $field, $operator, $value ) {
522
+ if ( $operator == "LIKE" ) {
523
  $value = "'%$value%'";
524
  } else { // compare numbers!
525
+ $field = "cast($field as signed)";
526
+ }
527
+
528
  return " $field $operator $value ";
529
  }
530
+
531
  public static function sql_get_order_ids_Ver1( $settings ) {
532
  global $wpdb;
533
 
534
  // deep level !
535
+ $product_where = self::sql_build_product_filter( $settings );
536
 
537
  $wc_order_items_meta = "{$wpdb->prefix}woocommerce_order_itemmeta";
538
  $left_join_order_items_meta = $order_items_meta_where = array();
549
  $attrs = self::get_product_attributes();
550
  $names2fields = @array_flip( $attrs );
551
  $filters = self::parse_complex_pairs( $settings['product_attributes'], $attrs );
552
+ foreach ( $filters as $operator => $fields ) {
553
  foreach ( $fields as $field => $values ) {
554
+ $field = $names2fields[ $field ];
555
  if ( $values ) {
556
  $left_join_order_items_meta[] = "LEFT JOIN $wc_order_items_meta AS `orderitemmeta_{$field}` ON `orderitemmeta_{$field}`.order_item_id = order_items.order_item_id";
557
+ if ( $operator == 'IN' OR $operator == 'NOT IN' ) {
558
+ $values = self::sql_subset( $values );
559
+ $order_items_meta_where[] = " (`orderitemmeta_{$field}`.meta_key='$field' AND `orderitemmeta_{$field}`.meta_value $operator ($values) ) ";
560
+ } elseif ( in_array( $operator, self::$operator_must_check_values ) ) {
561
  $pairs = array();
562
+ foreach ( $values as $v ) {
563
+ $pairs[] = self::operator_compare_field_and_value( "`orderitemmeta_{$field}`.meta_value",
564
+ $operator, $v );
565
+ }
566
+ $pairs = join( "OR", $pairs );
567
+ $order_items_meta_where[] = " (`orderitemmeta_{$field}`.meta_key='$field' AND ($pairs) ) ";
568
  }
569
  }// values
570
  }
571
  }// operators
572
  }
573
 
574
+ //by attrbutes in woocommerce_order_itemmeta
575
  if ( $settings['product_itemmeta'] ) {
576
+ foreach ( $settings['product_itemmeta'] as $value ) {
577
+ $settings['product_itemmeta'][] = esc_html( $value );
578
+ }
579
+
580
+ $itemmeta = self::get_product_itemmeta();
581
+ $filters = self::parse_complex_pairs( $settings['product_itemmeta'], $itemmeta );
582
+ foreach ( $filters as $operator => $fields ) {
583
+ foreach ( $fields as $field => $values ) {
584
+ ;
585
  if ( $values ) {
586
  $left_join_order_items_meta[] = "LEFT JOIN $wc_order_items_meta AS `orderitemmeta_{$field}` ON `orderitemmeta_{$field}`.order_item_id = order_items.order_item_id";
587
+ if ( $operator == 'IN' OR $operator == 'NOT IN' ) {
588
+ $values = self::sql_subset( $values );
589
+ $order_items_meta_where[] = " (`orderitemmeta_{$field}`.meta_key='$field' AND `orderitemmeta_{$field}`.meta_value $operator ($values) ) ";
590
+ } elseif ( in_array( $operator, self::$operator_must_check_values ) ) {
591
  $pairs = array();
592
+ foreach ( $values as $v ) {
593
+ $pairs[] = self::operator_compare_field_and_value( "`orderitemmeta_{$field}`.meta_value",
594
+ $operator, $v );
595
+ }
596
+ $pairs = join( "OR", $pairs );
597
+ $order_items_meta_where[] = " (`orderitemmeta_{$field}`.meta_key='$field' AND ($pairs) ) ";
598
  }
599
  }// values
600
  }
620
  if ( ! empty( $settings['any_coupon_used'] ) ) {
621
  $order_items_where .= " AND orders.ID IN (SELECT DISTINCT order_coupons.order_id FROM {$wpdb->prefix}woocommerce_order_items as order_coupons
622
  WHERE order_coupons.order_item_type='coupon')";
623
+ } elseif ( ! empty( $settings['coupons'] ) ) {
624
+ $values = self::sql_subset( $settings['coupons'] );
 
625
  $order_items_where .= " AND orders.ID IN (SELECT DISTINCT order_coupons.order_id FROM {$wpdb->prefix}woocommerce_order_items as order_coupons
626
  WHERE order_coupons.order_item_type='coupon' AND order_coupons.order_item_name in ($values) )";
627
  }
628
  // shipping methods
629
  if ( ! empty( $settings['shipping_methods'] ) ) {
630
  $zone_values = $zone_instance_values = $itemname_values = array();
631
+ foreach ( $settings['shipping_methods'] as $value ) {
632
+ if ( preg_match( '#^order_item_name:(.+)#', $value, $m ) ) {
633
+ $itemname_values[] = $m[1];
634
+ } else {
635
  $zone_values[] = $value;
636
  // for zones -- take instance_id!
637
+ $m = explode( ":", $value );
638
+ if ( count( $m ) > 1 ) {
639
  $zone_instance_values[] = $m[1];
640
+ }
641
+ }
642
+ }
643
+
644
  // where by type!
645
  $ship_where = array();
646
+ if ( $zone_values ) {
647
+ $zone_values = self::sql_subset( $zone_values );
648
  $ship_where[] = " (shipping_itemmeta.meta_key='method_id' AND shipping_itemmeta.meta_value IN ($zone_values) ) ";
649
  }
650
+ if ( $zone_instance_values ) { //since WooCommerce 3.4+ instead of $zone_values
651
  $zone_instance_values = self::sql_subset( $zone_instance_values );
652
+ $ship_where[] = " (shipping_itemmeta.meta_key='instance_id' AND shipping_itemmeta.meta_value IN ($zone_instance_values ) ) ";
653
  }
654
+ if ( $itemname_values ) {
655
  $itemname_values = self::sql_subset( $itemname_values );
656
+ $ship_where[] = " (order_shippings.order_item_name IN ( $itemname_values ) ) ";
657
  }
658
+ $ship_where = join( ' OR ', $ship_where );
659
+
660
  //done
661
  $order_items_where .= " AND orders.ID IN (SELECT order_shippings.order_id FROM {$wpdb->prefix}woocommerce_order_items as order_shippings
662
  LEFT JOIN {$wpdb->prefix}woocommerce_order_itemmeta AS shipping_itemmeta ON shipping_itemmeta.order_item_id = order_shippings.order_item_id
663
  WHERE order_shippings.order_item_type='shipping' AND $ship_where )";
664
  }
665
+
666
  // check item names ?
667
  if ( ! empty( $settings['item_names'] ) ) {
668
+ $filters = self::parse_complex_pairs( $settings['item_names'],
669
+ array( 'coupon', 'fee', 'line_item', 'shipping', 'tax' ) );
670
+ foreach ( $filters as $operator => $fields ) {
671
  foreach ( $fields as $field => $values ) {
672
  if ( $values ) {
673
+ if ( $operator == 'IN' OR $operator == 'NOT IN' ) {
674
+ $values = self::sql_subset( $values );
675
+ $where_item_names = " SELECT order_id FROM {$wpdb->prefix}woocommerce_order_items WHERE order_item_type='$field' AND order_item_name $operator ($values) ";
676
  $order_items_where .= " AND orders.ID IN ($where_item_names)";
677
  }
678
  }//if values
679
  }
680
  }
681
  }
682
+
683
  // check item metadata
684
  if ( ! empty( $settings['item_metadata'] ) ) {
685
+ $filters = self::parse_complex_pairs( $settings['item_metadata'] );
686
+ foreach ( $filters as $operator => $fields ) {
687
  foreach ( $fields as $field => $values ) {
688
  if ( $values ) {
689
+ self::extract_item_type_and_key( $field, $type, $key );
690
+ $key = esc_sql( $key );
691
+ if ( $operator == 'IN' OR $operator == 'NOT IN' ) {
692
+ $values = self::sql_subset( $values );
693
  $where_item_metadata = " SELECT order_id FROM {$wpdb->prefix}woocommerce_order_items AS items
694
  JOIN {$wpdb->prefix}woocommerce_order_itemmeta AS meta ON meta.order_item_id = items.order_item_id
695
  WHERE order_item_type='$type' AND meta_key='$key' AND meta_value $operator ($values) ";
696
+ $order_items_where .= " AND orders.ID IN ($where_item_metadata)";
697
  }
698
  }//if values
699
  }
700
  }
701
  }
702
+
703
 
704
  // pre top
705
+ $left_join_order_meta = $order_meta_where = $user_meta_where = $inner_join_user_meta = array();
706
  //add filter by custom fields in order
707
+
708
+ if ( $settings['export_unmarked_orders'] ) {
709
+ $pos = "export_unmarked_orders";
710
+ $field = "woe_order_exported";
711
  $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'";
712
  $order_meta_where [] = " ( ordermeta_cf_{$pos}.meta_value IS NULL ) ";
713
  }
714
 
715
  if ( $settings['order_custom_fields'] ) {
716
  $cf_names = self::get_order_custom_fields();
717
+ $filters = self::parse_complex_pairs( $settings['order_custom_fields'], $cf_names );
718
+ $pos = 1;
719
+ foreach ( $filters as $operator => $fields ) {
720
  foreach ( $fields as $field => $values ) {
721
  if ( $values ) {
722
  $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'";
723
+ if ( $operator == 'IN' OR $operator == 'NOT IN' ) {
724
+ $values = self::sql_subset( $values );
725
+ $order_meta_where [] = " ( ordermeta_cf_{$pos}.meta_value $operator ($values) ) ";
726
+ } elseif ( $operator == 'NOT SET' ) {
727
+ $order_meta_where [] = " ( ordermeta_cf_{$pos}.meta_value IS NULL ) ";
728
+ } elseif ( $operator == 'IS SET' ) {
729
+ $order_meta_where [] = " ( ordermeta_cf_{$pos}.meta_value IS NOT NULL ) ";
730
+ } elseif ( in_array( $operator, self::$operator_must_check_values ) ) {
731
  $pairs = array();
732
+ foreach ( $values as $v ) {
733
+ $pairs[] = self::operator_compare_field_and_value( "`ordermeta_cf_{$pos}`.meta_value",
734
+ $operator, $v );
735
+ }
736
+ $pairs = join( "OR", $pairs );
737
+ $order_meta_where[] = " ( $pairs ) ";
738
  }
739
+ $pos ++;
740
+ }//if values
741
+ }
742
+ }
743
+ }
744
+ if ( $settings['user_custom_fields'] ) {
745
+ $cf_names = self::get_user_custom_fields();
746
+ $filters = self::parse_complex_pairs( $settings['user_custom_fields'], $cf_names );
747
+ $pos = 1;
748
+ foreach ( $filters as $operator => $fields ) {
749
+ foreach ( $fields as $field => $values ) {
750
+ $inner_join_user_meta[] = "INNER JOIN {$wpdb->usermeta} AS usermeta_cf_{$pos} ON usermeta_cf_{$pos}.user_id = {$wpdb->users}.ID AND usermeta_cf_{$pos}.meta_key='$field'";
751
+ if ( $values ) {
752
+ if ( $operator == 'NOT SET' ) {
753
+ $user_meta_where[] = " ( usermeta_cf_{$pos}.meta_value IS NULL ) ";
754
+ } elseif ( $operator == 'IS SET' ) {
755
+ $user_meta_where[] = " ( usermeta_cf_{$pos}.meta_value IS NOT NULL ) ";
756
+ } elseif ( $operator == 'IN' OR $operator == 'NOT IN' ) {
757
+ $values = self::sql_subset( $values );
758
+ $user_meta_where[] = " ( usermeta_cf_{$pos}.meta_value $operator ($values) ) ";
759
+ } elseif ( in_array( $operator, self::$operator_must_check_values ) ) {
760
+ $pairs = array();
761
+ foreach ( $values as $v ) {
762
+ $pairs[] = self::operator_compare_field_and_value( "`usermeta_cf_{$pos}`.meta_value",
763
+ $operator, $v );
764
+ }
765
+ $pairs = join( "OR", $pairs );
766
+ $user_meta_where[] = " ( $pairs ) ";
767
+ }
768
+ $pos ++;
769
  }//if values
770
  }
771
  }
772
  }
773
  if ( $settings['shipping_locations'] ) {
774
+ $filters = self::parse_complex_pairs( $settings['shipping_locations'],
775
  array( 'city', 'state', 'postcode', 'country' ), 'lower_filter_label' );
776
+ foreach ( $filters as $operator => $fields ) {
777
  foreach ( $fields as $field => $values ) {
778
  $values = self::sql_subset( $values );
779
  if ( $values ) {
783
  }
784
  }
785
  }
786
+ if ( $settings['billing_locations'] ) {
787
+ $filters = self::parse_complex_pairs( $settings['billing_locations'],
788
+ array( 'city', 'state', 'postcode', 'country' ), 'lower_filter_label' );
789
+ foreach ( $filters as $operator => $fields ) {
790
+ foreach ( $fields as $field => $values ) {
791
+ $values = self::sql_subset( $values );
792
+ if ( $values ) {
793
+ $left_join_order_meta[] = "LEFT JOIN {$wpdb->postmeta} AS ordermeta_{$field} ON ordermeta_{$field}.post_id = orders.ID";
794
+ $order_meta_where [] = " (ordermeta_{$field}.meta_key='_billing_$field' AND ordermeta_{$field}.meta_value $operator ($values)) ";
795
+ }
796
+ }
797
+ }
798
+ }
799
 
800
  // users
801
  $user_ids = array();
802
+ $user_ids_ui_filters_applied = false;
803
+ if ( ! empty( $settings['user_names'] ) ) {
804
  $user_ids = array_filter( array_map( "intval", $settings['user_names'] ) );
805
+ $values = self::sql_subset( $user_ids );
806
+ $user_meta_where[] = "( {$wpdb->users}.ID IN ($values) )";
807
+ }
808
  //roles
809
+ if ( ! empty( $settings['user_roles'] ) ) {
810
+ $metakey = $wpdb->get_blog_prefix() . 'capabilities';
811
+ $inner_join_user_meta[] = "INNER JOIN {$wpdb->usermeta} AS usermeta_cf_role ON usermeta_cf_role.user_id = {$wpdb->users}.ID AND usermeta_cf_role.meta_key='$metakey'";
812
+
813
+ $roles_where = array();
814
+ foreach ( $settings['user_roles'] as $role ) {
815
+ $roles_where[] = "( usermeta_cf_role.meta_value LIKE '%$role%' )";
816
+ }
817
+ $user_meta_where[] = "(" . join(' OR ', $roles_where) . ")";
818
+ }
819
+ if ( ! empty( $user_meta_where ) AND ! empty( $inner_join_user_meta ) ) {
820
+ $user_meta_where = join( ' AND ', $user_meta_where );
821
+ $inner_join_user_meta = join( ' ', $inner_join_user_meta );
822
+ $sql = "SELECT DISTINCT ID FROM {$wpdb->users} $inner_join_user_meta WHERE $user_meta_where";
823
+ if ( self::$track_sql_queries ) {
824
+ self::$sql_queries[] = $sql;
825
  }
826
+ $user_ids = $wpdb->get_col( $sql );
827
+ $user_ids_ui_filters_applied = true;
828
  }
829
+ $user_ids = apply_filters( "woe_sql_get_customer_ids", $user_ids, $settings );
830
+ if( empty($user_ids) AND $user_ids_ui_filters_applied ) {
831
+ $order_meta_where [] = "0"; // user filters failed
832
+ }
833
+
834
  //apply filter
835
  if ( $user_ids ) {
836
+ $field = 'customer_user';
837
  $values = self::sql_subset( $user_ids );
838
+ if ( $values ) {
839
  $left_join_order_meta[] = "LEFT JOIN {$wpdb->postmeta} AS ordermeta_{$field} ON ordermeta_{$field}.post_id = orders.ID";
840
  $order_meta_where [] = " (ordermeta_{$field}.meta_key='_customer_user' AND ordermeta_{$field}.meta_value in ($values)) ";
841
  }
849
  $left_join_order_meta[] = "LEFT JOIN {$wpdb->postmeta} AS ordermeta_{$field} ON ordermeta_{$field}.post_id = orders.ID";
850
  $order_meta_where [] = " (ordermeta_{$field}.meta_key='_{$field}' AND ordermeta_{$field}.meta_value in ($values)) ";
851
  }
852
+ $order_meta_where = join( " AND ",
853
+ apply_filters( "woe_sql_get_order_ids_order_meta_where", $order_meta_where ) );
854
 
855
+ if ( $order_meta_where !== '' ) {
 
856
  $order_meta_where = " AND " . $order_meta_where;
857
  }
858
+ $left_join_order_meta = join( " ",
859
+ apply_filters( "woe_sql_get_order_ids_left_joins", $left_join_order_meta ) );
860
 
861
 
862
  //top_level
867
 
868
  //setup order types to work with
869
  $order_types = array( "'" . self::$object_type . "'" );
870
+ if ( $settings['export_refunds'] ) {
871
+ $order_types[] = "'shop_order_refund'";
872
+ }
873
+ $order_types = join( ",", apply_filters( "woe_sql_order_types", $order_types ) );
874
 
875
  $sql = "SELECT " . apply_filters( "woe_sql_get_order_ids_fields", "ID AS order_id" ) . " FROM {$wpdb->posts} AS orders
876
  {$left_join_order_meta}
877
  WHERE orders.post_type in ( $order_types) AND $order_sql $order_meta_where $order_items_where";
878
+
879
+ if ( self::$track_sql_queries ) {
880
  self::$sql_queries[] = $sql;
881
+ }
882
+
883
  //die($sql);
884
  return $sql;
885
  }
886
 
887
+ private static function add_date_filter( &$where, &$where_meta, $date_field, $value ) {
888
+ if ( $date_field == 'date_paid' OR $date_field == 'date_completed' ) // 3.0+ uses timestamp
889
+ {
890
  $where_meta[] = "(order_$date_field.meta_value>0 AND order_$date_field.meta_value $value )";
891
+ } elseif ( $date_field == 'paid_date' OR $date_field == 'completed_date' ) // previous versions use mysql datetime
892
+ {
893
+ $where_meta[] = "(order_$date_field.meta_value<>'' AND order_$date_field.meta_value " . $value . ")";
894
+ } else {
895
  $where[] = "orders.post_" . $date_field . $value;
896
+ }
897
  }
898
 
899
+ private static function apply_order_filters_to_sql( &$where, $settings ) {
900
  global $wpdb;
901
  //default filter by date
902
+ if ( ! isset( $settings['export_rule_field'] ) ) {
903
+ $settings['export_rule_field'] = 'modified';
904
+ }
905
 
906
+ $date_field = $settings['export_rule_field'];
907
+ $use_timestamps = ( $date_field == 'date_paid' OR $date_field == 'date_completed' );
908
  //rename this field for 2.6 and less
909
+ if ( ! method_exists( 'WC_Order', "get_date_completed" ) ) {
910
  $use_timestamps = false;
911
+ if ( $date_field == 'date_paid' ) {
912
  $date_field = 'paid_date';
913
+ } elseif ( $date_field == 'date_completed' ) {
914
  $date_field = 'completed_date';
915
+ }
916
  }
917
  $where_meta = array();
918
 
919
  // export and date rule
920
 
921
+ foreach ( self::get_date_range( $settings, true, $use_timestamps ) as $date ) {
922
  self::add_date_filter( $where, $where_meta, $date_field, $date );
923
  }
924
 
932
  }
933
 
934
  //for date_paid or date_completed
935
+ if ( $where_meta ) {
936
+ $where_meta = join( " AND ", $where_meta );
937
+ $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)";
938
  }
939
+
940
  // skip child orders?
941
+ if ( $settings['skip_suborders'] AND ! $settings['export_refunds'] ) {
942
  $where[] = "orders.post_parent=0";
943
+ }
944
 
945
  // Skip drafts and deleted
946
  $where[] = "orders.post_status NOT in ('auto-draft','trash')";
947
  }
948
+
949
+ public static function is_datetime_timestamp( $ts ) {
950
+ return $ts % ( 24 * 3600 ) > 0;
951
  }
952
 
953
+ public static function get_date_range( $settings, $is_for_sql, $use_timestamps = false ) {
954
  $result = array();
955
 
956
  // fixed date range
957
+ if ( ! empty( $settings['from_date'] ) OR ! empty( $settings['to_date'] ) ) {
958
  if ( $settings['from_date'] ) {
959
  $ts = strtotime( $settings['from_date'] );
960
+ if ( self::is_datetime_timestamp( $ts ) ) {
961
  $from_date = date( 'Y-m-d H:i:s', $ts );
962
+ } else {
963
  $from_date = date( 'Y-m-d', $ts ) . " 00:00:00";
964
+ }
965
  if ( $is_for_sql ) {
966
+ if ( $use_timestamps ) {
967
  $from_date = mysql2date( 'U', $from_date );
968
+ }
969
  $from_date = sprintf( ">='%s'", $from_date );
970
  }
971
  $result['from_date'] = $from_date;
973
 
974
  if ( $settings['to_date'] ) {
975
  $ts = strtotime( $settings['to_date'] );
976
+ if ( self::is_datetime_timestamp( $ts ) ) {
977
  $to_date = date( 'Y-m-d H:i:s', $ts );
978
+ } else {
979
  $to_date = date( 'Y-m-d', $ts ) . " 23:59:59";
980
+ }
981
  if ( $is_for_sql ) {
982
+ if ( $use_timestamps ) {
983
  $to_date = mysql2date( 'U', $to_date );
984
+ }
985
  $to_date = sprintf( "<='%s'", $to_date );
986
  }
987
  $result['to_date'] = $to_date;
988
  }
989
+
990
  return $result;
991
  }
992
 
1085
 
1086
  if ( isset( $from_date ) AND $from_date ) {
1087
  if ( $is_for_sql ) {
1088
+ if ( $use_timestamps ) {
1089
  $from_date = mysql2date( 'U', $from_date );
1090
+ }
1091
  $from_date = sprintf( ">='%s'", $from_date );
1092
  }
1093
  $result['from_date'] = $from_date;
1095
 
1096
  if ( isset( $to_date ) AND $to_date ) {
1097
  if ( $is_for_sql ) {
1098
+ if ( $use_timestamps ) {
1099
  $to_date = mysql2date( 'U', $to_date );
1100
+ }
1101
  $to_date = sprintf( "<='%s'", $to_date );
1102
  }
1103
  $result['to_date'] = $to_date;
1108
 
1109
  public static function get_quarter_month( $time ) {
1110
  $month = date( "m", $time );
1111
+ if ( $month <= 3 ) {
1112
  return 1;
1113
+ }
1114
+ if ( $month <= 6 ) {
1115
  return 4;
1116
+ }
1117
+ if ( $month <= 9 ) {
1118
  return 7;
1119
+ }
1120
 
1121
  return 10;
1122
  }
1123
 
1124
  public static function prepare_for_export() {
1125
+ self::$statuses = wc_get_order_statuses();
1126
+ self::$countries = WC()->countries->countries;
1127
+ self::$prices_include_tax = get_option( 'woocommerce_prices_include_tax' ) == 'yes' ? true : false;
1128
+ self::$decimal_separator = wc_get_price_decimal_separator();
1129
+ self::$thousands_separator = apply_filters( 'woe_thousands_separator', '' );
1130
+ self::$decimals = wc_get_price_decimals();
1131
+ self::$export_subcategories_separator = apply_filters( 'woe_export_subcategories_separator', ">" );
1132
  self::$export_line_categories_separator = apply_filters( 'woe_export_line_categories_separator', ",\n" );
1133
  self::$export_itemmeta_values_separator = apply_filters( 'woe_export_itemmeta_values_separator', ", " );
1134
+ self::$export_custom_fields_separator = apply_filters( 'woe_export_custom_fields_separator', ", " );
1135
  }
1136
+
1137
  //for debug
1138
  public static function start_track_queries() {
1139
  self::$track_sql_queries = true;
1140
+ self::$sql_queries = array();
1141
+ }
1142
+
1143
  public static function get_sql_queries() {
1144
  return self::$sql_queries;
1145
  }
1197
  } elseif ( $field == 'code' ) {
1198
  $row['code'] = $item["name"];
1199
  } elseif ( $field == 'discount_amount_plus_tax' ) {
1200
+ $row['discount_amount_plus_tax'] = $item["discount_amount"] + $item["discount_amount_tax"];
1201
  } elseif ( isset( $coupon_meta[ $field ] ) ) {
1202
  $row[ $field ] = $coupon_meta[ $field ];
1203
  } elseif ( isset( $static_vals[ $field ] ) ) {
1206
  $row[ $field ] = '';
1207
  }
1208
  if ( isset( $filters_active[ $field ] ) ) {
1209
+ $row[ $field ] = apply_filters( "woe_get_order_coupon_value_{$field}", $row[ $field ], $order,
1210
+ $item );
1211
+ $row[ $field ] = apply_filters( "woe_get_order_coupon_{$format}_value_{$field}", $row[ $field ],
1212
+ $order, $item );
1213
  }
1214
 
1215
+ if ( $field == 'excerpt' ) {
1216
+ $post = get_page_by_title( $item['name'], OBJECT, 'shop_' . $item['type'] );
1217
+ $row[ $field ] = $post ? $post->post_excerpt : '';
1218
+ }
1219
+ if ( $format_number_fields ) {
1220
+ $row[ $field ] = self::format_numbers( 'order_coupon', $row[ $field ], $field );
1221
+ }
1222
  }
1223
+ $row = apply_filters( 'woe_fetch_order_coupon', $row, $item, $coupon_meta );
1224
+ if ( $row ) {
1225
  $coupons[] = $row;
1226
+ }
1227
  }
1228
 
1229
  return apply_filters( "woe_fetch_order_coupons", $coupons, $order, $labels, $format, $static_vals );
1232
 
1233
  /**
1234
  * @param WC_Order $order
1235
+ * @param $labels
1236
+ * @param $format
1237
+ * @param $filters_active
1238
+ * @param $static_vals
1239
+ * @param $export_only_products
1240
+ * @param $export_refunds
1241
  *
1242
  * @return array
1243
  */
1244
+ public static function fetch_order_products(
1245
+ $order,
1246
+ $labels,
1247
+ $format,
1248
+ $filters_active,
1249
+ $static_vals,
1250
+ $export_only_products,
1251
+ $export_refunds,
1252
+ $skip_refunded_items,
1253
+ $strip_tags_product_fields,
1254
+ $format_number_fields
1255
+ ) {
1256
+ $product_fields_with_tags = array( 'product_variation', 'post_content', 'post_excerpt' );
1257
+ $products = array();
1258
+ $i = 0;
1259
+ foreach ( $order->get_items( 'line_item' ) as $item_id => $item ) {
1260
  do_action( "woe_get_order_product_item", $item );
1261
+ if ( $export_refunds AND $item['qty'] == 0 ) // skip zero items, when export refunds
1262
+ {
1263
  continue;
1264
+ }
1265
  // we export only matched products?
1266
+ if ( $export_only_products AND
1267
+ ! in_array( $item['product_id'], $export_only_products ) AND // not product
1268
+ ( ! $item['variation_id'] OR ! in_array( $item['variation_id'],
1269
+ $export_only_products ) ) // not variation
1270
+ ) {
1271
  continue;
1272
+ }
1273
  $product = $order->get_product_from_item( $item );
1274
+ $product = apply_filters( "woe_get_order_product", $product );
1275
  $item_meta = get_metadata( 'order_item', $item_id );
1276
+ foreach ( $item_meta as $key => $value ) {
1277
+ $clear_key = wc_sanitize_taxonomy_name( $key );
1278
+ if ( taxonomy_exists( $clear_key ) ) {
1279
+ $term = get_term_by( 'slug', $value[0], $clear_key );
1280
+ $item_meta[ $key ][0] = isset( $term->name ) ? $term->name : $value[0];
1281
+ if ( strpos( $key, 'attribute_' ) === false ) {
1282
+ $item_meta[ 'attribute_' . $key ][0] = isset( $term->name ) ? $term->name : $value[0];
1283
+ }
1284
  }
1285
+ }
1286
  $item_meta = apply_filters( "woe_get_order_product_item_meta", $item_meta );
1287
+ $product = apply_filters( "woe_get_order_product_and_item_meta", $product, $item_meta );
1288
+ if ( $product ) {
1289
+ if ( method_exists( $product, 'get_id' ) ) {
1290
+ if ( $product->is_type( 'variation' ) ) {
1291
+ $product_id = method_exists( $product,
1292
+ 'get_parent_id' ) ? $product->get_parent_id() : $product->parent->id;
1293
+ } else {
1294
  $product_id = $product->get_id();
1295
+ }
1296
  $post = get_post( $product_id );
1297
+ } else { // legacy
1298
+ $product_id = $product->id;
1299
+ $post = $product->post;
1300
  }
1301
  } else {
1302
  $product_id = 0;
1303
+ $post = false;
1304
  }
1305
 
1306
  // skip based on products/items/meta
1307
+ if ( apply_filters( 'woe_skip_order_item', false, $product, $item, $item_meta, $post ) ) {
1308
  continue;
1309
+ }
1310
 
1311
+ if ( $skip_refunded_items ) {
1312
  $qty_minus_refund = $item_meta["_qty"][0] + $order->get_qty_refunded_for_item( $item_id ); // Yes we add negative! qty
1313
+ if ( $qty_minus_refund <= 0 ) {
1314
  continue;
1315
+ }
1316
  }
1317
 
1318
+ $i ++;
1319
+ $row = array();
1320
  foreach ( $labels as $field => $label ) {
1321
  if ( strpos( $field, '__' ) !== false && $taxonomies = wc_get_product_terms( $item['product_id'],
1322
  substr( $field, 2 ), array( 'fields' => 'names' ) )
1323
  ) {
1324
  $row[ $field ] = implode( ', ', $taxonomies );
1325
  } else if ( $field == 'product_shipping_class' ) {
1326
+ if ( $taxonomies = wc_get_product_terms( $item['product_id'], $field,
1327
+ array( 'fields' => 'names' ) ) ) {
1328
  $row[ $field ] = implode( ', ', $taxonomies );
1329
+ } else {
1330
+ $row[ $field ] = "";
1331
+ } // unknown class
1332
  } elseif ( $field == 'line_total_plus_tax' ) {
1333
  $row[ $field ] = $item_meta["_line_total"][0] + $item_meta["_line_tax"][0];
1334
+ } elseif ( $field == 'line_subtotal_tax' ) {
1335
+ $row[ $field ] = $item_meta["_line_subtotal_tax"][0];
1336
  } elseif ( $field == 'name' ) {
1337
  $row[ $field ] = $item["name"];
1338
  } elseif ( $field == 'product_name' ) {
1341
  $row[ $field ] = self::get_product_variation( $item, $order, $item_id, $product );
1342
  } elseif ( $field == 'seller' ) {
1343
  $row[ $field ] = '';
1344
+ if ( $post ) {
1345
+ $user = get_userdata( $post->post_author );
1346
  $row[ $field ] = ! empty( $user->display_name ) ? $user->display_name : '';
1347
  }
1348
  } elseif ( $field == 'post_content' ) {
1349
  $row[ $field ] = $post ? $post->post_content : '';
1350
  } elseif ( $field == 'post_excerpt' ) {
1351
+ $row[ $field ] = $post ? $post->post_excerpt : '';
1352
  } elseif ( $field == 'type' ) {
1353
  $row[ $field ] = '';
1354
+ if ( $product ) {
1355
+ $row[ $field ] = method_exists( $product,
1356
+ 'get_type' ) ? $product->get_type() : $product->product_type;
1357
+ }
1358
  } elseif ( $field == 'tags' ) {
1359
+ $terms = get_the_terms( $product_id, 'product_tag' );
1360
  $row[ $field ] = array();
1361
  if ( $terms ) {
1362
  foreach ( $terms as $term ) {
1365
  }
1366
  $row[ $field ] = join( ",", $row[ $field ] );
1367
  } elseif ( $field == 'category' ) {
1368
+ $terms = get_the_terms( $product_id, 'product_cat' );
1369
  $row[ $field ] = array();
1370
  if ( $terms ) {
1371
  foreach ( $terms as $term ) {
1375
  $row[ $field ] = join( ",", $row[ $field ] );// hierarhy ???
1376
  } elseif ( $field == 'line_no_tax' ) {
1377
  $row[ $field ] = $item_meta["_line_total"][0];
1378
+ //item refund
1379
  } elseif ( $field == 'line_total_refunded' ) {
1380
  $row[ $field ] = $order->get_total_refunded_for_item( $item_id );
1381
  } elseif ( $field == 'line_total_minus_refund' ) {
1382
  $row[ $field ] = $item_meta["_line_total"][0] - $order->get_total_refunded_for_item( $item_id );
1383
  } elseif ( $field == 'qty_minus_refund' ) {
1384
  $row[ $field ] = $item_meta["_qty"][0] + $order->get_qty_refunded_for_item( $item_id ); // Yes we add negative! qty
1385
+ //tax refund
1386
  } elseif ( $field == 'line_tax_refunded' ) {
1387
+ $row[ $field ] = self::get_order_item_taxes_refund( $order, $item_id );
1388
  } elseif ( $field == 'line_tax_minus_refund' ) {
1389
+ $row[ $field ] = $item_meta["_line_tax"][0] - self::get_order_item_taxes_refund( $order, $item_id );
1390
  } elseif ( $field == 'line_id' ) {
1391
  $row[ $field ] = $i;
1392
  } elseif ( $field == 'item_id' ) {
1394
  } elseif ( $field == 'item_price' ) {
1395
  $row[ $field ] = $order->get_item_total( $item, false, true ); // YES we have to calc item price
1396
  } elseif ( $field == 'discount_amount' ) {
1397
+ if ( method_exists( $item, "get_subtotal" ) ) {
1398
+ $row[ $field ] = $item->get_subtotal() - $item->get_total();
1399
+ } else //2.6
1400
+ {
1401
  $row[ $field ] = $item['line_subtotal'] - $item['line_total'];
1402
+ }
1403
  } elseif ( $field == 'tax_rate' ) {
1404
+ if ( method_exists( $item, "get_subtotal" ) ) {
1405
  $subtotal_amount = $item->get_subtotal();
1406
+ $subtotal_tax = $item->get_subtotal_tax();
1407
  } else {
1408
  $subtotal_amount = $item['line_subtotal'];
1409
+ $subtotal_tax = $item['line_subtotal_tax'];
1410
+ }
1411
+ $row[ $field ] = ( $subtotal_amount > 0 ) ? round( 100 * $subtotal_tax / $subtotal_amount, 2 ) : 0;
1412
  } elseif ( $field == 'product_url' ) {
1413
  $row[ $field ] = get_permalink( $product_id );
1414
  } elseif ( $field == 'sku' ) {
1415
+ $row[ $field ] = method_exists( $product,
1416
+ 'get_' . $field ) ? $product->{'get_' . $field}() : get_post_meta( $product_id, '_' . $field,
1417
+ true );
1418
  } elseif ( $field == 'download_url' ) {
1419
  $row[ $field ] = '';
1420
  if ( $product AND $product->is_downloadable() ) {
1421
  $files = get_post_meta( $product_id, '_downloadable_files', true );
1422
  $links = array();
1423
+ if ( $files ) {
1424
+ foreach ( $files as $file ) {
1425
  $links[] = $file['file'];
1426
+ }
1427
  }
1428
  $row[ $field ] = implode( "\n", $links );
1429
  }
1430
  } elseif ( $field == 'image_url' ) {
1431
+ // make full url, wp_get_attachment_image_src can return false
1432
+ $images_src = ( is_object( $product ) AND $product->get_image_id() ) ? wp_get_attachment_image_src( $product->get_image_id(),
1433
+ 'full' ) : false;
1434
+ $row[ $field ] = is_array( $images_src ) ? current( $images_src ) : '';
1435
  } elseif ( $field == 'full_category_names' ) {
1436
  $row[ $field ] = self::get_product_category_full( $product );
1437
  } elseif ( isset( $static_vals[ $field ] ) ) {
1443
  } elseif ( isset( $item['item_meta'][ $field ] ) ) { // meta from item line
1444
  $row[ $field ] = join( self::$export_itemmeta_values_separator, $item['item_meta'][ $field ] );
1445
  } elseif ( isset( $item['item_meta'][ "_" . $field ] ) ) { // or hidden field
1446
+ $row[ $field ] = join( self::$export_itemmeta_values_separator,
1447
+ $item['item_meta'][ "_" . $field ] );
1448
  } else {
1449
+ $row[ $field ] = '';
1450
+ if ( ! empty( $item['variation_id'] ) ) {
1451
  $row[ $field ] = get_post_meta( $item['variation_id'], $field, true );
1452
+ }
1453
+ if ( $row[ $field ] === '' ) // empty value ? try get custom!
1454
+ {
1455
  $row[ $field ] = get_post_meta( $product_id, $field, true );
1456
+ }
1457
+ if ( $row[ $field ] === '' ) // empty value ?
1458
+ {
1459
+ $row[ $field ] = method_exists( $product,
1460
+ 'get_' . $field ) ? $product->{'get_' . $field}() : get_post_meta( $product_id,
1461
+ '_' . $field, true );
1462
+ }
1463
+ if ( $row[ $field ] === '' AND empty( $item['variation_id'] ) ) // empty value ? try get attribute for !variaton
1464
+ {
1465
  $row[ $field ] = $product ? $product->get_attribute( $field ) : '';
1466
+ }
1467
+ }
1468
+
1469
+ if ( $strip_tags_product_fields AND in_array( $field, $product_fields_with_tags ) ) {
1470
+ $row[ $field ] = strip_tags( $row[ $field ] );
1471
  }
1472
+
1473
+ if ( $format_number_fields ) {
1474
+ $row[ $field ] = self::format_numbers( 'order_product', $row[ $field ], $field );
1475
  }
1476
+
1477
+ if ( isset( $row[ $field ] ) ) {
1478
+ $row[ $field ] = apply_filters( "woe_get_order_product_value_{$field}", $row[ $field ], $order,
1479
+ $item, $product, $item_meta );
1480
+ $row[ $field ] = apply_filters( "woe_get_order_product_{$format}_value_{$field}", $row[ $field ],
1481
+ $order, $item, $product, $item_meta );
 
1482
  }
1483
  }
1484
+ $row = apply_filters( 'woe_fetch_order_product', $row, $order, $item, $product, $item_meta );
1485
+ if ( $row ) {
1486
  $products[ $item_id ] = $row;
1487
+ }
1488
  }
1489
+
1490
  return apply_filters( "woe_fetch_order_products", $products, $order, $labels, $format, $static_vals );
1491
  }
1492
 
1513
  return join( self::$export_line_categories_separator, $full_names );
1514
  }
1515
 
1516
+ public static function get_order_item_taxes_refund( $order, $item_id ) {
1517
+ $tax_refund = 0;
1518
  $order_taxes = $order->get_taxes();
1519
  foreach ( $order_taxes as $tax_item ) {
1520
+ $tax_item_id = $tax_item['rate_id'];
1521
+ $tax_refund += $order->get_tax_refunded_for_item( $item_id, $tax_item_id );
1522
  }
1523
+
1524
  return $tax_refund;
1525
  }
1526
 
1545
 
1546
  // get order meta
1547
  $order_meta = array();
1548
+ $recs = get_post_meta( $order_id );
1549
+ foreach ( $recs as $meta_key=>$meta_values ) {
1550
+ $order_meta[ $meta_key ] = join( self::$export_custom_fields_separator, $meta_values );
1551
  }
1552
 
1553
  // take order
1556
  self::$date_format = trim( $options['date_format'] . ' ' . $options['time_format'] );
1557
 
1558
  // add fields for WC 3.0
1559
+ foreach ( array( "billing_country", "billing_state", "shipping_country", "shipping_state" ) as $field_30 ) {
1560
+ $$field_30 = method_exists( $order,
1561
+ 'get_' . $field_30 ) ? $order->{'get_' . $field_30}() : $order->$field_30;
1562
  }
1563
 
1564
+ $parent_order_id = method_exists( $order,
1565
+ 'get_parent_id' ) ? $order->get_parent_id() : $order->post->post_parent;
1566
+ $parent_order = $parent_order_id ? new WC_Order( $parent_order_id ) : false;
1567
+ $post = method_exists( $order, 'get_id' ) ? get_post( $order->get_id() ) : $order->post;
1568
 
1569
  // correct meta for child orders
1570
+ if ( $parent_order_id ) {
1571
  // overwrite child values for refunds
1572
+ $is_refund = ( $post->post_type == 'shop_order_refund' );
1573
+ $overwrite_child_order_meta = apply_filters( 'woe_overwrite_child_order_meta', $is_refund );
1574
+ $recs = get_post_meta( $parent_order_id );
1575
+ foreach ( $recs as $meta_key=>$meta_values ) {
1576
+ if ( $overwrite_child_order_meta OR ! isset( $order_meta[ $meta_key ] ) ) {
1577
+ $order_meta[ $meta_key ] = join( self::$export_custom_fields_separator, $meta_values );
1578
+ }
1579
  }
1580
 
1581
  //refund rewrites it
1582
  if ( $overwrite_child_order_meta ) {
1583
+ foreach (
1584
+ array(
1585
+ "billing_country",
1586
+ "billing_state",
1587
+ "shipping_country",
1588
+ "shipping_state",
1589
+ ) as $field_30
1590
+ ) {
1591
+ $$field_30 = method_exists( $parent_order,
1592
+ 'get_' . $field_30 ) ? $parent_order->{'get_' . $field_30}() : $parent_order->$field_30;
1593
  }
1594
  }
1595
  //refund status
1596
+ if ( $is_refund ) {
1597
  $order_status = 'refunded';
1598
+ }
1599
  }
1600
 
1601
  // we know parent!
1602
  if ( $export['products'] OR isset( $labels['order']['count_unique_products'] ) OR isset( $labels['order']['total_weight_items'] ) OR $options['include_products'] ) {
1603
+ $temp = $labels['products'];
1604
+ $temp['qty'] = '';
1605
+ $temp['weight'] = '';
1606
  $data['products'] = self::fetch_order_products( $order, $temp, $format,
1607
  $filters_active['products'], $static_vals['products'], $options['include_products'],
1608
+ $options['export_refunds'], $options['skip_refunded_items'], $options['strip_tags_product_fields'],
1609
+ $options['format_number_fields'] );
1610
+ if ( $options['include_products'] AND empty( $data['products'] ) AND apply_filters( "woe_skip_order_without_products",
1611
+ false ) ) {
1612
  return array();
1613
+ }
1614
  }
1615
  if ( $export['coupons'] OR isset( $labels['order']['coupons_used'] ) ) {
1616
  // get coupons from main order
1617
+ $data['coupons'] = self::fetch_order_coupons( $parent_order ? $parent_order : $order, $labels['coupons'],
1618
+ $format,
1619
+ $filters_active['coupons'], $get_coupon_meta, $static_vals['coupons'],
1620
+ $options['format_number_fields'] );
1621
  }
1622
 
1623
  // extra WP_User
1624
  $user = ! empty( $order_meta['_customer_user'] ) ? get_userdata( $order_meta['_customer_user'] ) : false;
1625
  // setup missed fields for full addresses
1626
+ foreach ( array( '_billing_address_2', '_shipping_address_2' ) as $optional_field ) {
1627
+ if ( ! isset( $order_meta[ $optional_field ] ) ) {
1628
+ $order_meta[ $optional_field ] = '';
1629
+ }
1630
+ }
1631
 
1632
 
1633
  $order_fields = array();
1634
  // fill as it must
1635
  foreach ( $labels['order'] as $field => $label ) {
1636
+ if ( substr( $field, 0, 5 ) == "USER_" ) { //user field
1637
+ $key = substr( $field, 5 );
1638
+ $row[ $field ] = $user ? $user->get( $key ) : '';
1639
  } elseif ( $field == 'order_id' ) {
1640
  $row['order_id'] = $order_id;
1641
  } elseif ( $field == 'order_date' ) {
1642
+ $row['order_date'] = ! method_exists( $order,
1643
+ "get_date_created" ) ? $order->order_date : ( $order->get_date_created() ? gmdate( 'Y-m-d H:i:s',
1644
+ $order->get_date_created()->getOffsetTimestamp() ) : '' );
1645
  } elseif ( $field == 'modified_date' ) {
1646
+ $row['modified_date'] = ! method_exists( $order,
1647
+ "get_date_modified" ) ? $order->modified_date : ( $order->get_date_modified() ? gmdate( 'Y-m-d H:i:s',
1648
+ $order->get_date_modified()->getOffsetTimestamp() ) : '' );
1649
  } elseif ( $field == 'completed_date' ) {
1650
+ $row['completed_date'] = ! method_exists( $order,
1651
+ "get_date_completed" ) ? $order->completed_date : ( $order->get_date_completed() ? gmdate( 'Y-m-d H:i:s',
1652
+ $order->get_date_completed()->getOffsetTimestamp() ) : '' );
1653
  } elseif ( $field == 'paid_date' ) {
1654
+ $row['paid_date'] = ! method_exists( $order,
1655
+ "get_date_paid" ) ? $order->paid_date : ( $order->get_date_paid() ? gmdate( 'Y-m-d H:i:s',
1656
+ $order->get_date_paid()->getOffsetTimestamp() ) : '' );
1657
  } elseif ( $field == 'order_number' ) {
1658
  $row['order_number'] = $parent_order ? $parent_order->get_order_number() : $order->get_order_number(); // use parent order number
1659
  } elseif ( $field == 'order_subtotal' ) {
1660
+ $row['order_subtotal'] = wc_format_decimal( $order->get_subtotal(), 2 );
1661
  } elseif ( $field == 'order_subtotal_minus_discount' ) {
1662
  $row[ $field ] = $order->get_subtotal() - $order->get_total_discount();
1663
  } elseif ( $field == 'order_subtotal_refunded' ) {
1664
+ $row['order_subtotal_refunded'] = wc_format_decimal( self::get_order_subtotal_refunded( $order ), 2 );
1665
  } elseif ( $field == 'order_subtotal_minus_refund' ) {
1666
+ $row['order_subtotal_minus_refund'] = wc_format_decimal( $order->get_subtotal() - self::get_order_subtotal_refunded( $order ),
1667
+ 2 );
1668
+ //order total
1669
  } elseif ( $field == 'order_total' ) {
1670
  $row['order_total'] = $order->get_total();
1671
  } elseif ( $field == 'order_total_no_tax' ) {
1674
  $row['order_refund'] = $order->get_total_refunded();
1675
  } elseif ( $field == 'order_total_inc_refund' ) {
1676
  $row['order_total_inc_refund'] = $order->get_total() - $order->get_total_refunded();
1677
+ //shipping
1678
  } elseif ( $field == 'order_shipping' ) {
1679
  $row['order_shipping'] = $order->get_total_shipping();
1680
  } elseif ( $field == 'order_shipping_refunded' ) {
1681
  $row['order_shipping_refunded'] = $order->get_total_shipping_refunded();
1682
  } elseif ( $field == 'order_shipping_minus_refund' ) {
1683
  $row['order_shipping_minus_refund'] = $order->get_total_shipping() - $order->get_total_shipping_refunded();
1684
+ //shipping tax
1685
  } elseif ( $field == 'order_shipping_tax_refunded' ) {
1686
  $row['order_shipping_tax_refunded'] = self::get_order_shipping_tax_refunded( $order_id );
1687
  } elseif ( $field == 'order_shipping_tax_minus_refund' ) {
1688
  $row['order_shipping_tax_minus_refund'] = $order->get_shipping_tax() - self::get_order_shipping_tax_refunded( $order_id );
1689
+ //order tax
1690
  } elseif ( $field == 'order_tax' ) {
1691
  $row['order_tax'] = wc_round_tax_total( $order->get_cart_tax() );
1692
  } elseif ( $field == 'order_total_tax' ) {
1696
  } elseif ( $field == 'order_total_tax_minus_refund' ) {
1697
  $row['order_total_tax_minus_refund'] = wc_round_tax_total( $order->get_total_tax() - $order->get_total_tax_refunded() );
1698
  } elseif ( $field == 'order_status' ) {
1699
+ $status = empty( $order_status ) ? $order->get_status() : $order_status;
1700
  $status = 'wc-' === substr( $status, 0, 3 ) ? substr( $status, 3 ) : $status;
1701
  $row['order_status'] = isset( self::$statuses[ 'wc-' . $status ] ) ? self::$statuses[ 'wc-' . $status ] : $status;
1702
+ } elseif ( $field == 'user_login' OR $field == 'user_email' OR $field == 'user_url') {
1703
  $row[ $field ] = $user ? $user->$field : "";
1704
  } elseif ( $field == 'user_role' ) {
1705
+ $row[ $field ] = ( isset( $user->roles[0] ) && isset( $wp_roles->roles[ $user->roles[0] ] ) ) ? $wp_roles->roles[ $user->roles[0] ]['name'] : ""; // take first role Name
1706
  } elseif ( $field == 'customer_total_orders' ) {
1707
  $row[ $field ] = ( isset( $user->ID ) ) ? wc_get_customer_order_count( $user->ID ) : 0;
1708
  } elseif ( $field == 'billing_address' ) {
1709
+ $row[ $field ] = join( ", ",
1710
+ array_filter( array( $order_meta["_billing_address_1"], $order_meta["_billing_address_2"] ) ) );
1711
  } elseif ( $field == 'shipping_address' ) {
1712
+ $row[ $field ] = join( ", ",
1713
+ array_filter( array( $order_meta["_shipping_address_1"], $order_meta["_shipping_address_2"] ) ) );
1714
  } elseif ( $field == 'billing_full_name' ) {
1715
  $row[ $field ] = trim( $order_meta["_billing_first_name"] . ' ' . $order_meta["_billing_last_name"] );
1716
  } elseif ( $field == 'shipping_full_name' ) {
1721
  $row[ $field ] = isset( self::$countries[ $shipping_country ] ) ? self::$countries[ $shipping_country ] : $shipping_country;
1722
  } elseif ( $field == 'billing_state_full' ) {
1723
  $country_states = WC()->countries->get_states( $billing_country );
1724
+ $row[ $field ] = isset( $country_states[ $billing_state ] ) ? html_entity_decode( $country_states[ $billing_state ] ) : $billing_state;
1725
  } elseif ( $field == 'shipping_state_full' ) {
1726
  $country_states = WC()->countries->get_states( $shipping_country );
1727
+ $row[ $field ] = isset( $country_states[ $shipping_state ] ) ? html_entity_decode( $country_states[ $shipping_state ] ) : $shipping_state;
1728
  } elseif ( $field == 'billing_citystatezip' ) {
1729
+ $row[ $field ] = self::get_city_state_postcode_field_value( $order, 'billing' );
1730
  } elseif ( $field == 'shipping_citystatezip' ) {
1731
+ $row[ $field ] = self::get_city_state_postcode_field_value( $order, 'shipping' );
1732
  } elseif ( $field == 'products' OR $field == 'coupons' ) {
1733
  if ( $format == 'xls' OR $format == 'csv' OR $format == 'tsv' ) {
1734
  if ( $options[ $field . '_mode' ] == 'rows' ) {
1735
  //print_r(array_values($row));die();
1736
  //echo count($row)."-".(count($row)+count($labels[$field])-1)."|";
1737
+ $items = apply_filters( 'woe_get_' . $field . '_items_for_' . $format . '_rows',
1738
+ array_values( $data[ $field ] ), $order ); // remove keys for items in merge
1739
+ self::csv_process_multi_rows( $field, $row, $extra_rows, $items, $labels[ $field ],
1740
+ $options['item_rows_start_from_new_line'] );
1741
  } else {
1742
+ $items = apply_filters( 'woe_get_' . $field . '_items_for_' . $format . '_cols',
1743
+ array_values( $data[ $field ] ), $order );
1744
  self::csv_process_multi_cols( $field, $row, $items, $labels[ $field ], $csv_max[ $field ] );
1745
  }
1746
  } else {
1750
  $row[ $field ] = $order->get_shipping_method();
1751
  } elseif ( $field == 'shipping_method' ) {
1752
  $shipping_methods = $order->get_items( 'shipping' );
1753
+ $shipping_method = reset( $shipping_methods ); // take first entry
1754
+ if ( ! empty( $shipping_method ) ) {
1755
+ $row[ $field ] = $shipping_method['method_id'] . ':' . $shipping_method['instance_id'];
1756
+ }
1757
  } elseif ( $field == 'coupons_used' ) {
1758
  $row[ $field ] = count( $data['coupons'] );
1759
  } elseif ( $field == 'total_weight_items' ) {
1760
+ $row[ $field ] = 0;
1761
+ foreach ( $data['products'] as $product ) {
1762
+ $row[ $field ] += (float) $product['qty'] * (float) $product['weight'];
1763
  }
1764
  } elseif ( $field == 'count_total_items' ) {
1765
  $row[ $field ] = $order->get_item_count();
1766
  } elseif ( $field == 'count_exported_items' ) {
1767
+ $row[ $field ] = 0; // count only exported!
1768
+ if ( $export['products'] ) {
1769
+ foreach ( $data['products'] as $product ) {
1770
+ $row[ $field ] += $product['qty'];
1771
  }
1772
+ }
1773
  } elseif ( $field == 'count_unique_products' ) { // speed! replace with own counter ?
1774
  $row[ $field ] = count( $data['products'] );
1775
  } elseif ( $field == 'customer_note' ) {
1776
+ $notes = array( $post->post_excerpt );
1777
+ if ( $options['export_refund_notes'] ) {
1778
+ $refunds = $order->get_refunds();
1779
+ foreach ( $refunds as $refund ) {
1780
+ // added get_reason for WC 3.0
1781
+ $notes[] = method_exists( $refund,
1782
+ 'get_reason' ) ? $refund->get_reason() : $refund->get_refund_reason();
1783
+ }
1784
  }
1785
+ $row[ $field ] = implode( "\n", array_filter( $notes ) );
1786
  } elseif ( $field == 'first_refund_date' ) {
1787
  $value = '';
1788
+ foreach ( $order->get_refunds() as $refund ) {
1789
+ $value = ! method_exists( $refund,
1790
+ "get_date_created" ) ? $refund->date : ( $refund->get_date_created() ? gmdate( 'Y-m-d H:i:s',
1791
+ $refund->get_date_created()->getOffsetTimestamp() ) : '' );
1792
  break;// take only first
1793
  }
1794
  $row[ $field ] = $value;
1796
  $row[ $field ] = $static_vals['order'][ $field ];
1797
  } elseif ( $field == 'order_notes' ) {
1798
  remove_filter( 'comments_clauses', array( 'WC_Comments', 'exclude_order_comments' ), 10 );
1799
+ $args = array(
1800
+ 'post_id' => $order_id,
1801
+ 'approve' => 'approve',
1802
+ 'type' => 'order_note',
1803
  );
1804
  $notes = get_comments( $args );
1805
  add_filter( 'comments_clauses', array( 'WC_Comments', 'exclude_order_comments' ), 10, 1 );
1806
  $comments = array();
1807
  if ( $notes ) {
1808
+ foreach ( $notes as $note ) {
1809
+ if ( ! empty( $options['export_all_comments'] ) || $note->comment_author !== __( 'WooCommerce',
1810
+ 'woocommerce' ) ) { // skip system notes by default
1811
+ $comments[] = apply_filters( 'woe_get_order_notes', $note->comment_content, $note, $order );
1812
  }
1813
  }
1814
  }
1815
+ $row[ $field ] = implode( "\n", $comments );
1816
  } elseif ( isset( $order_meta[ $field ] ) ) {
1817
  $field_data = array();
1818
  do_action( 'woocommerce_order_export_add_field_data', $field_data, $order_meta[ $field ], $field );
1823
  } elseif ( isset( $order_meta[ "_" . $field ] ) ) { // or hidden field
1824
  $row[ $field ] = $order_meta[ "_" . $field ];
1825
  } else { // order_date...
1826
+ $row[ $field ] = method_exists( $order,
1827
+ 'get_' . $field ) ? $order->{'get_' . $field}() : get_post_meta( $order_id, '_' . $field, true );
1828
  //print_r($field."=".$label); echo "debug static!\n\n";
1829
  }
1830
 
1831
  //use empty value for missed field
1832
+ if ( $field != 'products' AND $field != 'coupons' ) {
1833
+ if ( ! isset( $row[ $field ] ) ) {
1834
  $row[ $field ] = '';
1835
+ }
1836
+ if ( is_array( $row[ $field ] ) ) {
1837
  $row[ $field ] = json_encode( $row[ $field ] );
1838
+ }
1839
+ }
1840
+
1841
+ if ( isset( $row[ $field ] ) ) {
1842
+ if ( $options['format_number_fields'] ) {
1843
+ $row[ $field ] = self::format_numbers( 'order', $row[ $field ], $field );
1844
+ }
1845
+
1846
+ $row[ $field ] = apply_filters( "woe_get_order_value_{$field}", $row[ $field ], $order, $field );
1847
+ $row[ $field ] = apply_filters( "woe_get_order_{$format}_value_{$field}", $row[ $field ], $order,
1848
+ $field );
1849
+
1850
  // must add empty column to extra rows
1851
+ if ( $field != 'products' AND $field != 'coupons' AND $extra_rows ) {
1852
+ foreach ( $extra_rows as $idx => $extra_row ) {
1853
+ $extra_rows[ $idx ][ $field ] = "";
1854
+ }
1855
  }
1856
  $order_fields[] = $field;
1857
  } //if order field set
1858
  }
1859
 
1860
+ $row = apply_filters( "woe_fetch_order", $row, $order );
1861
+
1862
  // Must fill child cells?
1863
+ if ( empty( $options['item_rows_start_from_new_line'] ) AND ! empty( $options['populate_other_columns_product_rows'] ) AND $extra_rows ) {
1864
+ foreach ( $extra_rows as $idx => $extra_row ) {
1865
+ foreach ( $row as $key => $val ) {
1866
+ if ( in_array( $key, $order_fields ) ) {
1867
+ $extra_rows[ $idx ][ $key ] = $val;
1868
+ }// copy main row values to new rows
1869
  }
1870
  }
1871
  }
1877
  $extra_rows = array( $row );
1878
  }
1879
 
1880
+ //json for complex structures, don't encode nested products&coupons
1881
+ foreach ( $extra_rows as $idx => $extra_row ) {
1882
+ foreach( $extra_row as $key => $val ) {
1883
+ if ( $key === 'products' OR $key === 'coupons' )
1884
+ continue;
1885
+ if ( is_array( $val ) )
1886
+ $extra_rows[ $idx ][ $key ] = json_encode( $val );
1887
+ }
1888
  }
1889
 
1890
+ return apply_filters( "woe_fetch_order_data", $extra_rows );
1891
  }
1892
 
1893
  public static function get_city_state_postcode_field_value( $order, $type ) {
1894
+ if ( $type != 'shipping' && $type != 'billing' ) {
1895
  return null;
1896
  }
1897
  $citystatepostcode_fields_name = array(
1898
+ $type . '_city',
1899
+ $type . '_state',
1900
+ $type . '_postcode',
1901
  );
1902
+ $citystatepostcode = array();
1903
+ foreach ( $citystatepostcode_fields_name as $field_name ) {
1904
+ $citystatepostcode[ $field_name ] = method_exists( $order,
1905
+ 'get_' . $field_name ) ? $order->{'get_' . $field_name}() : $order->{$field_name};
1906
  }
1907
+
1908
+ return join( ", ", $citystatepostcode );
1909
  }
1910
 
1911
+ public static function csv_process_multi_rows(
1912
+ $type,
1913
+ &$row,
1914
+ &$extra_rows,
1915
+ $items,
1916
+ $labels,
1917
+ $item_rows_start_from_new_line
1918
+ ) {
1919
  // to support
1920
  // order row
1921
  // item1 row
1922
  // item1 row
1923
+ if ( $item_rows_start_from_new_line ) {
1924
+ foreach ( $items as $item ) {
1925
  $new_row = array();
1926
  foreach ( $labels as $field => $label ) {
1927
+ $new_row[ $type . "_" . $field ] = $item[ $field ];
1928
  }
1929
  $extra_rows[] = $new_row;
1930
+ }
1931
+
1932
  return;//done
1933
  }
1934
 
1936
  // must add one record at least, if no coupons for example!
1937
  if ( empty( $items ) ) {
1938
  $item = array();
1939
+ foreach ( $labels as $field => $label ) {
1940
  $item[ $field ] = "";
1941
+ }
1942
  $items = array( $item );
1943
  }
1944
+
1945
  $pos = 0;
1946
  foreach ( $items as $data ) {
1947
  if ( $pos == 0 ) { //current row
1948
  foreach ( $labels as $field => $label ) {
1949
+ $row[ $type . "_" . $field ] = $data[ $field ];
1950
  }
1951
  } else {
1952
  if ( ! isset( $extra_rows[ $pos - 1 ] ) ) {
1953
+ $extra_rows[ $pos - 1 ] = array();
1954
  //add empty row with correct keys
1955
+ foreach ( $row as $key => $value ) {
1956
+ $extra_rows[ $pos - 1 ][ $key ] = "";
1957
+ }
1958
  }
1959
  //set columns with values
1960
+ foreach ( $labels as $field => $label ) {
1961
+ $extra_rows[ $pos - 1 ][ $type . "_" . $field ] = $data[ $field ];
1962
+ }
1963
  }
1964
+ $pos ++;
1965
  }
1966
+
1967
  // Have we added new columns to ALL existing extra_rows ??
1968
+ while ( $pos <= count( $extra_rows ) ) {
1969
+ foreach ( $labels as $field => $label ) {
1970
+ $extra_rows[ $pos - 1 ][ $type . "_" . $field ] = "";
1971
+ }
1972
+ $pos ++;
1973
  }
1974
  }
1975
 
1977
  for ( $i = 0; $i < $csv_max; $i ++ ) {
1978
  if ( empty( $data[ $i ] ) ) {
1979
  foreach ( $labels as $field => $label ) {
1980
+ $row[ $type . "_" . $field . "_" . $i ] = "";
1981
  }
1982
  } else {
1983
  foreach ( $labels as $field => $label ) {
1984
+ $row[ $type . "_" . $field . "_" . $i ] = $data[ $i ][ $field ];
1985
  }
1986
  }
1987
  }
1988
  }
1989
 
1990
+ public static function get_order_shipping_tax_refunded( $order_id ) {
1991
  global $wpdb;
1992
+ $refund_ship_taxes = $wpdb->get_var( $wpdb->prepare( "
1993
  SELECT SUM( order_itemmeta.meta_value )
1994
  FROM {$wpdb->prefix}woocommerce_order_itemmeta AS order_itemmeta
1995
  INNER JOIN $wpdb->posts AS posts ON ( posts.post_type = 'shop_order_refund' AND posts.post_parent = %d )
1998
  AND order_itemmeta.meta_key IN ( 'shipping_tax_amount')
1999
  ", $order_id ) );
2000
 
2001
+ return abs( $refund_ship_taxes );
2002
  }
2003
+
2004
+ public static function get_order_subtotal_refunded( $order ) {
2005
+ $subtotal_refund = 0;
2006
+ foreach ( $order->get_refunds() as $refund ) {
2007
  $subtotal_refund += $refund->get_subtotal();
2008
  }
2009
+
2010
+ return abs( $subtotal_refund );
2011
  }
2012
 
2013
  /**
2016
  public static function get_product_variation( $item, $order, $item_id, $product ) {
2017
  global $wpdb;
2018
  $hidden_order_itemmeta = apply_filters( 'woocommerce_hidden_order_itemmeta', array(
2019
+ '_qty',
2020
+ '_tax_class',
2021
+ '_product_id',
2022
+ '_variation_id',
2023
+ '_line_subtotal',
2024
+ '_line_subtotal_tax',
2025
+ '_line_total',
2026
+ '_line_tax',
2027
+ 'method_id',
2028
+ 'cost',
2029
  ) );
2030
 
2031
  $result = array();
2032
 
2033
+ $value_delimiter = apply_filters( 'woe_fetch_item_meta_value_delimiter', ': ' );
2034
 
2035
  // pull meta directly
2036
  $meta_data = $wpdb->get_results( $wpdb->prepare( "SELECT meta_key, meta_value, meta_id, order_item_id
2037
  FROM {$wpdb->prefix}woocommerce_order_itemmeta WHERE order_item_id = %d
2038
  ORDER BY meta_id", $item_id ), ARRAY_A );
2039
+ foreach ( $meta_data as $meta ) {
2040
+ if ( in_array( $meta['meta_key'], $hidden_order_itemmeta ) ) {
2041
  continue;
2042
+ }
2043
+ if ( is_serialized( $meta['meta_value'] ) ) {
2044
  continue;
2045
+ }
2046
 
2047
  //known attribute?
2048
  if ( taxonomy_exists( wc_sanitize_taxonomy_name( $meta['meta_key'] ) ) ) {
2049
+ $term = get_term_by( 'slug', $meta['meta_value'],
2050
+ wc_sanitize_taxonomy_name( $meta['meta_key'] ) );
2051
  $meta['meta_key'] = wc_attribute_label( wc_sanitize_taxonomy_name( $meta['meta_key'] ) );
2052
  $meta['meta_value'] = isset( $term->name ) ? $term->name : $meta['meta_value'];
2053
  } else {
2054
+ $meta['meta_key'] = apply_filters( 'woocommerce_attribute_label',
2055
+ wc_attribute_label( $meta['meta_key'], $product ), $meta['meta_key'] );
2056
  }
2057
 
2058
+ $value = wp_kses_post( $meta['meta_key'] ) . $value_delimiter . wp_kses_post( force_balance_tags( $meta['meta_value'] ) );
2059
+ $result[] = apply_filters( 'woe_fetch_item_meta', $value, $meta, $item, $product );
2060
  }
2061
+
2062
  //list to string!
2063
+ return join( apply_filters( 'woe_fetch_item_meta_lines_delimiter', ' | ' ), array_filter( $result ) );
2064
  }
2065
 
2066
  /**
2068
  */
2069
  public static function get_shipping_methods() {
2070
  global $wpdb;
2071
+
2072
  $shipping_methods = array();
2073
+
2074
  // get raw names
2075
  $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" );
2076
+ foreach ( $raw_methods as $method ) {
2077
  $shipping_methods[ 'order_item_name:' . $method ] = $method;
2078
+ }
2079
+
2080
  // try get methods for zones
2081
+ if ( ! class_exists( "WC_Shipping_Zone" ) ) {
2082
  return $shipping_methods;
2083
+ }
2084
 
2085
+ if ( ! method_exists( "WC_Shipping_Zone", "get_shipping_methods" ) ) {
2086
  return $shipping_methods;
2087
+ }
2088
 
2089
  foreach ( WC_Shipping_Zones::get_zones() as $zone ) {
2090
  $methods = $zone['shipping_methods'];
2091
  /** @var WC_Shipping_Method $method */
2092
  foreach ( $methods as $method ) {
2093
+ $shipping_methods[ $method->get_rate_id() ] = '[' . $zone['zone_name'] . '] ' . $method->get_title();
2094
  }
2095
  }
2096
+
2097
  $zone = new WC_Shipping_Zone( 0 );
2098
  $methods = $zone->get_shipping_methods();
2099
  /** @var WC_Shipping_Method $method */
2100
  foreach ( $methods as $method ) {
2101
+ $shipping_methods[ $method->get_rate_id() ] = __( '[Rest of the World]',
2102
+ 'woo-order-export-lite' ) . ' ' . $method->get_title();
2103
  }
2104
+
2105
  return $shipping_methods;
2106
  }
2107
+
2108
+ public static function format_numbers( $object, $value, $field ) {
2109
+ $option = WC_Order_Export_Engine::$current_job_settings[ $object . '_fields' ][ $field ];
2110
+ if ( isset( $option['format'] ) AND ( $option['format'] == 'money' OR $option['format'] == 'number' ) ) {
2111
+ $new_value = number_format( floatval( $value ), self::$decimals, self::$decimal_separator,
2112
+ self::$thousands_separator );
2113
+ $value = apply_filters( 'woe_format_numbers', $new_value, $value );
2114
  }
2115
+
2116
  return $value;
2117
  }
2118
 
classes/core/class-wc-order-export-engine.php CHANGED
@@ -12,17 +12,18 @@ class WC_Order_Export_Engine {
12
  public static $order_id = '';
13
  public static $orders_exported = 0;
14
  public static $make_separate_orders = false;
 
15
  //
16
  public static function export( $settings, $filepath ) {
17
- if( empty($settings['destination']['type']) ) {
18
  return __( "No destination selected", 'woo-order-export-lite' );
19
  }
20
-
21
- if( !is_array( $settings[ 'destination' ][ 'type' ] ) ) {
22
- $settings[ 'destination' ][ 'type' ] = array( $settings[ 'destination' ][ 'type' ] );
23
  }
24
- $results = array( );
25
- foreach( $settings[ 'destination' ][ 'type' ] as $export_type ) {
26
  $export_type = strtolower( $export_type );
27
  if ( ! in_array( strtoupper( $export_type ), WC_Order_Export_Admin::$export_types ) ) {
28
  return __( "Wrong format", 'woo-order-export-lite' );
@@ -33,102 +34,109 @@ class WC_Order_Export_Engine {
33
  $class = 'WOE_Export_' . $export_type;
34
  $exporter = new $class( $settings['destination'] );
35
 
36
- $filename = self::make_filename( $settings['export_filename'] );
37
- $custom_export = apply_filters('woe_custom_export_to_'.$export_type,false, $filename, $filepath, $exporter);
38
- if( !$custom_export ) {
 
39
  // try many times?
40
  $num_retries = 0;
41
- while( $num_retries < $exporter->get_num_of_retries() ) {
42
- $num_retries++;
43
  $results[] = $exporter->run_export( $filename, $filepath );
44
- if( $exporter->finished_successfully )
45
  break;
46
- }
 
47
  } else {
48
  $results[] = $custom_export;
49
  }
50
  }
 
51
  return implode( "<br>\r\n", $results );
52
  }
53
 
54
- public static function prepare( $settings, $filepath ) {
55
- if( empty($settings['destination']['type']) ) {
56
- return __( "No destination selected", 'woo-order-export-lite' );
57
- }
58
-
59
- if( !is_array( $settings[ 'destination' ][ 'type' ] ) ) {
60
- $settings[ 'destination' ][ 'type' ] = array( $settings[ 'destination' ][ 'type' ] );
61
- }
62
- $results = array( );
63
- foreach( $settings[ 'destination' ][ 'type' ] as $export_type ) {
64
- $export_type = strtolower( $export_type );
65
- if ( ! in_array( strtoupper( $export_type ), WC_Order_Export_Admin::$export_types ) ) {
66
- return __( "Wrong export type", 'woo-order-export-lite' );
67
- }
68
-
69
- include_once dirname( dirname( __FILE__ ) ) . "/exports/abstract-class-woe-export.php";
70
- include_once dirname( dirname( __FILE__ ) ) . "/exports/class-woe-export-{$export_type}.php";
71
- $class = 'WOE_Export_' . $export_type;
72
- $exporter = new $class( $settings['destination'] );
73
-
74
- $filename = self::make_filename( $settings['export_filename'] );
75
- $custom_prepare = apply_filters('woe_custom_prepare_to_'.$export_type,false, $filename, $filepath, $exporter);
76
- if( !$custom_prepare ) {
77
- if ( method_exists($exporter, 'prepare') ) {
78
- $results[] = $exporter->prepare( $filename, $filepath );
79
- }
80
- } else {
81
- $results[] = $custom_prepare;
82
- }
83
- }
84
- return $results;
85
- }
 
 
86
 
87
  public static function make_filename( $mask ) {
88
  if ( self::$make_separate_orders && strpos( $mask, '%order_id' ) === false ) {
89
- $mask_parts = explode( '.', $mask );
90
- $before_prefix = count( $mask_parts ) >1 ? 2 : 1;
91
  $mask_parts[ count( $mask_parts ) - $before_prefix ] .= '-%order_id';
92
- $mask = implode( '.', $mask_parts );
93
  }
94
  $time = apply_filters( 'woe_make_filename_current_time', current_time( 'timestamp' ) );
95
 
96
- $date = WC_Order_Export_Data_Extractor::get_date_range( self::$current_job_settings, false );
97
 
98
  $subst = apply_filters( 'woe_make_filename_replacements', array(
99
- '%d' => date( 'd',$time ),
100
- '%m' => date( 'm',$time ),
101
- '%y' => date( 'Y',$time ),
102
- '%h' => date( 'H',$time ),
103
- '%i' => date( 'i',$time ),
104
- '%s' => date( 's',$time ),
105
- '%order_id' => self::$order_id,
106
- '%orderid' => self::$order_id,
107
- '%id' => self::$order_id,
108
  '{from_date}' => isset( $date['from_date'] ) ? date( "Y-m-d", strtotime( $date['from_date'] ) ) : '',
109
- '{to_date}' => isset( $date['to_date'] ) ? date( "Y-m-d", strtotime( $date['to_date'] ) ) : '',
110
  ) );
111
 
112
  return apply_filters( 'woe_make_filename', strtr( $mask, $subst ) );
113
  }
114
-
115
  public static function kill_buffers() {
116
- while ( ob_get_level() )
117
  ob_end_clean();
 
118
  }
119
 
120
  public static function tempnam( $folder, $prefix ) {
121
  $filename = @tempnam( $folder, $prefix );
122
- if(! $filename ) {
123
- $tmp_folder = dirname( dirname( dirname ( __FILE__ ) ) ) . '/tmp';
124
  // kill expired tmp file
125
- foreach( glob( $tmp_folder."/*" ) as $f) {
126
- if( time() - filemtime($f) > 24*3600 ) {
127
  unlink( $f );
128
- }
129
  }
130
  $filename = tempnam( $tmp_folder, $prefix );
131
  }
 
132
  return $filename;
133
  }
134
 
@@ -138,15 +146,17 @@ class WC_Order_Export_Engine {
138
  $labels = array();
139
  foreach ( $fields as $key => $field ) {
140
  if ( preg_match( '#^custom_field_#', $key ) ) { // for static fields
141
- $static_vals[ $key ] = isset($field['value']) ? $field['value'] : $field['colname'];// FIX BUG here
142
  }
143
  if ( $field['checked'] ) {
144
  $labels[ $key ] = apply_filters( "woe_get_{$format}_label_{$key}", $field['colname'] );
145
-
146
- if( isset($field['format']) )
147
  $field_formats[ $field['format'] ][] = $key;
 
148
  }
149
  }
 
150
  return $labels;
151
  }
152
 
@@ -164,18 +174,19 @@ class WC_Order_Export_Engine {
164
 
165
  /**
166
  * @param string $mode
167
- * @param array $settings
168
  * @param string $fname
169
- * @param null $labels
170
- * @param null $static_vals
171
  *
172
  * @return WOE_Formatter
173
  */
174
  private static function init_formater( $mode, $settings, $fname, &$labels, &$static_vals ) {
175
  $format = strtolower( $settings['format'] );
176
  include_once dirname( dirname( __FILE__ ) ) . "/formats/abstract-class-woe-formatter.php";
177
- if( !apply_filters('woe_load_custom_formatter_'.$format, false) )
178
  include_once dirname( dirname( __FILE__ ) ) . "/formats/class-woe-formatter-$format.php";
 
179
 
180
  $format_settings = array( 'global_job_settings' => $settings );
181
  foreach ( $settings as $key => $val ) {
@@ -188,20 +199,23 @@ class WC_Order_Export_Engine {
188
 
189
  $class = 'WOE_Formatter_' . $format;
190
 
191
- do_action( 'woe_init_custom_formatter', $mode, $fname, $format_settings, $format, $labels, $field_formats, self::$date_format, $settings );
 
192
 
193
- return new $class( $mode, $fname, $format_settings, $format, $labels, $field_formats, self::$date_format );
194
  }
195
 
196
  private static function init_labels( $settings, &$labels, &$static_vals, &$field_formats ) {
197
  $format = strtolower( $settings['format'] );
198
 
199
- $static_vals = array( 'order' => array(), 'products' => array(), 'coupons' => array() );
200
  $field_formats = array( 'money' => array(), 'number' => array(), 'date' => array(), 'string' => array() );
201
- $labels = array(
202
  'order' => self::get_labels( $settings['order_fields'], $format, $static_vals['order'], $field_formats ),
203
- 'products' => self::get_labels( $settings['order_product_fields'], $format, $static_vals['products'], $field_formats ),
204
- 'coupons' => self::get_labels( $settings['order_coupon_fields'], $format, $static_vals['coupons'], $field_formats ),
 
 
205
  );
206
  }
207
 
@@ -211,16 +225,19 @@ class WC_Order_Export_Engine {
211
  $csv_max['coupons'] = $csv_max['products'] = 1;
212
  if ( $format == 'xls' OR $format == 'csv' OR $format == 'tsv' ) {
213
  if ( @$settings['order_fields']['products']['repeat'] == 'columns' ) {
214
- if(@$settings['order_fields']['products']['max_cols'])
215
  $csv_max['products'] = $settings['order_fields']['products']['max_cols'];
216
- else
217
- $csv_max['products'] = WC_Order_Export_Data_Extractor::get_max_order_items( "line_item", $order_ids );
 
 
218
  }
219
  if ( @$settings['order_fields']['coupons']['repeat'] == 'columns' ) {
220
- if(@$settings['order_fields']['coupons']['max_cols'])
221
  $csv_max['coupons'] = $settings['order_fields']['coupons']['max_cols'];
222
- else
223
  $csv_max['coupons'] = WC_Order_Export_Data_Extractor::get_max_order_items( "coupon", $order_ids );
 
224
  }
225
  }
226
 
@@ -231,9 +248,9 @@ class WC_Order_Export_Engine {
231
  $format = strtolower( $settings['format'] );
232
 
233
  $filters_active = array(
234
- 'order' => self::check_filters( $settings['order_fields'], $format, 'order' ),
235
- 'products' => self::check_filters( $settings['order_product_fields'], $format, 'order_product' ),
236
- 'coupons' => self::check_filters( $settings['order_coupon_fields'], $format, 'order_coupon' ),
237
  );
238
 
239
  return $filters_active;
@@ -243,7 +260,7 @@ class WC_Order_Export_Engine {
243
  $export['products'] = $settings['order_fields']['products']['checked'];
244
  $export['coupons'] = $settings['order_fields']['coupons']['checked'];
245
  $get_coupon_meta = ( $export['coupons'] AND array_diff( array_keys( $labels['coupons'] ),
246
- array( 'code', 'discount_amount', 'discount_amount_tax', 'excerpt' ) ) );
247
  if ( empty( $labels['products'] ) ) {
248
  $export['products'] = 0;
249
  unset( $labels['order']['products'] );
@@ -255,8 +272,9 @@ class WC_Order_Export_Engine {
255
  }
256
 
257
  private static function _make_header( $format, $labels, $csv_max ) {
258
- $header = ( $format == 'xls' OR $format == 'csv' OR $format == 'tsv' ) ? self::_make_header_csv( $labels, $csv_max ) : '';
259
- do_action( 'woe_make_header_custom_formatter', $format, $labels, $csv_max );
 
260
 
261
  return $header;
262
  }
@@ -276,7 +294,7 @@ class WC_Order_Export_Engine {
276
  $field_header[] = $label;
277
  }
278
  $field_header = apply_filters( 'woe_add_csv_headers', $field_header, $field );
279
- $header = array_merge( $header, $field_header );
280
  }
281
 
282
  return $header;
@@ -288,36 +306,39 @@ class WC_Order_Export_Engine {
288
  $format = strtolower( $settings['format'] );
289
 
290
  $options = array();
291
-
292
  if ( $format == 'xls' AND @$settings['format_xls_populate_other_columns_product_rows']
293
  OR $format == 'csv' AND @$settings['format_csv_populate_other_columns_product_rows']
294
  OR $format == 'tsv' AND @$settings['format_tsv_populate_other_columns_product_rows'] ) {
295
  $options['populate_other_columns_product_rows'] = 1;
296
  }
297
  $options['item_rows_start_from_new_line'] = ( $format == 'csv' AND @$settings['format_csv_item_rows_start_from_new_line'] );
298
- $options['products_mode'] = isset($settings['order_fields']['products']['repeat']) ? $settings['order_fields']['products']['repeat'] : "";
299
- $options['coupons_mode'] = isset($settings['order_fields']['coupons']['repeat']) ? $settings['order_fields']['coupons']['repeat'] : "";
300
 
301
- if( !empty($settings['all_products_from_order']) )
302
  $options['include_products'] = false;
303
- else
304
- $options['include_products'] = $wpdb->get_col( WC_Order_Export_Data_Extractor::sql_get_product_ids( $settings ) );
 
305
 
306
- if ( isset( $settings['date_format'] ) )
307
  $options['date_format'] = $settings['date_format'];
308
- else
309
  $options['date_format'] = 'Y-m-d';
 
310
 
311
- if ( isset( $settings['time_format'] ) )
312
  $options['time_format'] = $settings['time_format'];
313
- else
314
  $options['time_format'] = 'H:i';
 
315
 
316
  //as is
317
- $options['export_refunds'] = $settings['export_refunds'];
318
- $options['skip_refunded_items'] = $settings['skip_refunded_items'];
319
- $options['export_all_comments'] = $settings['export_all_comments'];
320
- $options['export_refund_notes'] = $settings['export_refund_notes'];
321
  $options['format_number_fields'] = $settings['format_number_fields'];
322
 
323
  if ( $settings['enable_debug'] AND ! ini_get( 'display_errors' ) ) {
@@ -333,33 +354,38 @@ class WC_Order_Export_Engine {
333
  foreach ( array( "billing_phone", "USER_billing_phone" ) as $field ) {
334
  add_filter( 'woe_get_order_value_' . $field, function ( $value, $order, $fieldname ) {
335
  $value = preg_replace( "#[^\d]+#", "", $value );
 
336
  return $value;
337
  }, 10, 3 );
338
  }
339
  }
340
 
341
- $options['strip_tags_product_fields'] = !empty($settings['strip_tags_product_fields']);
342
 
343
  return $options;
344
  }
345
 
346
- private static function validate_defaults( $settings ) {
347
- if( empty($settings['sort']) )
348
  $settings['sort'] = 'order_id';
349
- if( empty($settings['sort_direction']) )
 
350
  $settings['sort_direction'] = 'DESC';
351
- if( !isset($settings['skip_empty_file']) )
 
352
  $settings['skip_empty_file'] = true;
353
- if( $settings[ 'custom_php' ] ) {
 
354
  ob_start( array( 'WC_Order_Export_Engine', 'code_error_callback' ) );
355
- $result = eval( $settings[ 'custom_php_code' ] );
356
  ob_end_clean();
357
  }
358
  // This report works with products!
359
- if( $settings[ 'summary_report_by_products' ] )
360
  $settings['order_fields']['products']['checked'] = 1;
361
-
362
- return apply_filters('woe_settings_validate_defaults', $settings);
 
363
  }
364
 
365
  private static function code_error_callback( $out ) {
@@ -370,22 +396,23 @@ class WC_Order_Export_Engine {
370
  }
371
 
372
  $m = '<h2>' . __( "Don't Panic", 'woo-order-export-lite' ) . '</h2>';
373
- $m .= '<p>' . sprintf( __( 'The code you are trying to save produced a fatal error on line %d:', 'woo-order-export-lite' ), $error['line'] ) . '</p>';
 
374
  $m .= '<strong>' . $error['message'] . '</strong>';
375
 
376
  return $m;
377
  }
378
 
379
- private static function try_modify_status( $order_id, $settings ) {
380
  if ( isset( $settings['change_order_status_to'] ) && wc_is_order_status( $settings['change_order_status_to'] ) ) {
381
  $order = new WC_Order( $order_id );
382
  $order->update_status( $settings['change_order_status_to'] );
383
  }
384
  }
385
 
386
- private static function try_mark_order( $order_id, $settings ) {
387
- if ( $settings[ 'mark_exported_orders' ] ) {
388
- update_post_meta( $order_id, 'woe_order_exported', current_time('timestamp') );
389
  }
390
  }
391
 
@@ -400,15 +427,16 @@ class WC_Order_Export_Engine {
400
  global $wpdb;
401
 
402
  self::kill_buffers();
403
- $settings = self::validate_defaults( $settings );
404
- self::$current_job_settings = $settings;
405
  self::$current_job_build_mode = $make_mode;
406
- self::$date_format = trim( $settings['date_format'] . ' ' . $settings['time_format'] );
407
  //debug sql?
408
- if ( $make_mode == 'preview' AND $settings['enable_debug'] )
409
- WC_Order_Export_Data_Extractor::start_track_queries( );
 
410
  // might run sql!
411
- self::$extractor_options = self::_install_options( $settings );
412
 
413
  if ( $output_mode == 'browser' ) {
414
  $filename = 'php://output';
@@ -416,28 +444,32 @@ class WC_Order_Export_Engine {
416
  $filename = ( ! empty( $filename ) ? $filename : self::tempnam( sys_get_temp_dir(), $settings['format'] ) );
417
  }
418
 
419
- if ( $make_mode !== 'estimate' )
420
  $formater = self::init_formater( $make_mode, $settings, $filename, $labels, $static_vals );
421
- $format = strtolower( $settings['format'] );
 
422
 
423
  if ( $make_mode == 'finish' ) {
424
  self::maybe_output_summary_report( $formater );
425
  $formater->finish();
 
426
  return $filename;
427
  }
428
 
429
-
430
  //get IDs
431
  $sql = WC_Order_Export_Data_Extractor::sql_get_order_ids( $settings );
432
  if ( $make_mode == 'estimate' ) { //if estimate return total count
433
  return $wpdb->get_var( str_replace( 'ID AS order_id', 'COUNT(ID) AS order_count', $sql ) );
434
  } elseif ( $make_mode == 'preview' ) {
435
- $sql .= apply_filters ( "woe_sql_get_order_ids_order_by", " ORDER BY " . $settings[ 'sort' ] . " " . $settings[ 'sort_direction' ] ). " LIMIT " . ($limit !== false ? $limit : 1);
 
436
  } elseif ( $make_mode == 'partial' ) {
437
- $sql .= apply_filters ( "woe_sql_get_order_ids_order_by", " ORDER BY " . $settings[ 'sort' ] . " " . $settings[ 'sort_direction' ] );
438
- $offset = intval( $offset );
 
439
  $limit = intval( $limit );
440
- $sql .= " LIMIT $offset,$limit";
441
  }
442
 
443
  $order_ids = $wpdb->get_col( $sql );
@@ -468,79 +500,85 @@ class WC_Order_Export_Engine {
468
  WC_Order_Export_Data_Extractor::prepare_for_export();
469
  self::$orders_exported = 0;// incorrect value
470
  foreach ( $order_ids as $order_id ) {
471
- $order_id = apply_filters( "woe_order_export_started", $order_id);
472
- if( !$order_id )
473
  continue;
 
474
  self::$order_id = $order_id;
475
- $rows = WC_Order_Export_Data_Extractor::fetch_order_data( $order_id, $labels, $format, $filters_active,
 
476
  $csv_max, $export, $get_coupon_meta, $static_vals, self::$extractor_options );
477
  foreach ( $rows as $row ) {
478
- $row = apply_filters( "woe_fetch_order_row", $row, $order_id);
479
- if ($row) {
480
  $formater->output( $row );
481
- do_action( "woe_order_row_exported", $row, $order_id);
482
  }
483
  }
484
  if ( $make_mode != 'preview' ) {
485
- do_action( "woe_order_exported", $order_id);
486
  self::try_mark_order( $order_id, $settings );
 
 
487
  }
488
- else
489
- do_action( "woe_order_previewed", $order_id);
490
  }
491
 
492
  // for modes
493
- if ( $make_mode == 'partial')
494
  $formater->finish_partial();
495
- elseif ( $make_mode == 'preview') {
496
  self::maybe_output_summary_report( $formater );
497
  $flat_formats = array( 'XLS', 'CSV', 'TSV' );//limit debug output
498
- if( $settings['enable_debug'] AND in_array( $settings['format'], $flat_formats ) ) {
499
  echo "<b>" . __( 'Main SQL queries are listed below', 'woo-order-export-lite' ) . "</b>";
500
  echo '<textarea rows=5 style="width:100%">';
501
  $s = array();
502
- foreach(WC_Order_Export_Data_Extractor::get_sql_queries() as $sql) {
503
- $s[] = preg_replace("#\s+#"," ",$sql);
504
- }
505
- echo join("\n\n", $s);
506
  echo '</textarea>';
507
- }
508
  $formater->finish();
509
- }
510
 
511
  // no action woe_export_finished here!
512
  return $filename;
513
  }
514
 
515
- public static function build_file_full( $settings, $filename = '', $limit = 0, $order_ids = array( ) ) {
516
  global $wpdb;
517
-
518
  //no need self::kill_buffers();
519
- $settings = self::validate_defaults( $settings );
520
- self::$current_job_settings = $settings;
521
  self::$current_job_build_mode = 'full';
522
- self::$date_format = trim( $settings['date_format'] . ' ' . $settings['time_format'] );
523
- self::$extractor_options = self::_install_options( $settings );
524
 
525
  $filename = ( ! empty( $filename ) ? $filename : self::tempnam( sys_get_temp_dir(), $settings['format'] ) );
526
 
527
  $formater = self::init_formater( '', $settings, $filename, $labels, $static_vals );
528
  $format = strtolower( $settings['format'] );
529
-
530
  self::maybe_init_summary_report( $labels );
531
- self::maybe_start_summary_report();
532
 
533
  //get IDs
534
  $sql = WC_Order_Export_Data_Extractor::sql_get_order_ids( $settings );
535
- $sql .= apply_filters ( "woe_sql_get_order_ids_order_by", " ORDER BY " . $settings[ 'sort' ] . " ". $settings[ 'sort_direction' ] );
 
536
 
537
  if ( $limit ) {
538
  $sql .= " LIMIT " . intval( $limit );
539
  }
540
- if ( !$order_ids )
541
  $order_ids = $wpdb->get_col( $sql );
 
542
 
543
- if ( empty( $order_ids ) AND apply_filters( 'woe_schedule_job_skip_empty_file', (bool) $settings['skip_empty_file'] ) ) {
 
 
544
  return false;
545
  }
546
 
@@ -562,62 +600,72 @@ class WC_Order_Export_Engine {
562
  WC_Order_Export_Data_Extractor::prepare_for_export();
563
  self::$orders_exported = 0;
564
  foreach ( $order_ids as $order_id ) {
565
- $order_id = apply_filters( "woe_order_export_started", $order_id);
566
- if( !$order_id )
567
  continue;
 
568
  self::$order_id = $order_id;
569
- $rows = WC_Order_Export_Data_Extractor::fetch_order_data( $order_id, $labels, $format, $filters_active,
 
570
  $csv_max, $export, $get_coupon_meta, $static_vals, self::$extractor_options );
571
  foreach ( $rows as $row ) {
572
- $row=apply_filters( "woe_fetch_order_row", $row, $order_id);
573
- if ($row) {
574
  $formater->output( $row );
575
- do_action( "woe_order_row_exported", $row, $order_id);
576
  }
577
  }
578
- do_action( "woe_order_exported", $order_id);
579
 
580
- do_action( 'woe_formatter_output_custom_formatter', $order_id, $labels, $format, $filters_active,
581
- $csv_max, $export, $get_coupon_meta, $static_vals, self::$extractor_options );
582
 
583
- self::$orders_exported++;
584
  self::try_modify_status( $order_id, $settings );
585
  self::try_mark_order( $order_id, $settings );
586
  }
587
-
588
  self::maybe_output_summary_report( $formater );
589
  $formater->finish();
590
- do_action( 'woe_finish_custom_formatter' );
 
 
591
 
592
- do_action( 'woe_export_finished');
593
  return $filename;
594
  }
595
 
596
- public static function build_separate_files_and_export( $settings, $filename = '', $limit = 0, $order_ids = array( ) ) {
 
 
 
 
 
597
  global $wpdb;
598
-
599
  self::kill_buffers();
600
- $settings = self::validate_defaults( $settings );
601
- self::$current_job_settings = $settings;
602
  self::$current_job_build_mode = 'full';
603
- self::$date_format = trim( $settings['date_format'] . ' ' . $settings['time_format'] );
604
- self::$extractor_options = self::_install_options( $settings );
605
 
606
  $filename = ( ! empty( $filename ) ? $filename : self::tempnam( sys_get_temp_dir(), $settings['format'] ) );
607
 
608
  self::init_labels( $settings, $labels, $static_vals, $field_formats );
609
- $format = strtolower( $settings['format'] );
610
 
611
  //get IDs
612
  $sql = WC_Order_Export_Data_Extractor::sql_get_order_ids( $settings );
613
- $sql .= apply_filters ( "woe_sql_get_order_ids_order_by", " ORDER BY " . $settings[ 'sort' ] . " ". $settings[ 'sort_direction' ] );
 
614
 
615
  if ( $limit ) {
616
  $sql .= " LIMIT " . intval( $limit );
617
  }
618
 
619
- if ( !$order_ids )
620
  $order_ids = $wpdb->get_col( $sql );
 
621
 
622
  if ( empty( $order_ids ) ) {
623
  return false;
@@ -639,24 +687,25 @@ class WC_Order_Export_Engine {
639
  WC_Order_Export_Data_Extractor::prepare_for_export();
640
  self::$make_separate_orders = true;
641
  foreach ( $order_ids as $order_id ) {
642
- $order_id = apply_filters( "woe_order_export_started", $order_id);
643
- if( !$order_id )
644
  continue;
 
645
  self::$order_id = $order_id;
646
  $formater = self::init_formater( '', $settings, $filename, $_labels, $_static_vals );
647
 
648
  $formater->truncate();
649
  $formater->start( $header );
650
  $rows = WC_Order_Export_Data_Extractor::fetch_order_data( $order_id, $labels, $format, $filters_active,
651
- $csv_max, $export, $get_coupon_meta, $static_vals, self::$extractor_options );
652
  foreach ( $rows as $row ) {
653
- $row=apply_filters( "woe_fetch_order_row", $row, $order_id);
654
- if ($row) {
655
  $formater->output( $row );
656
- do_action( "woe_order_row_exported", $row, $order_id);
657
  }
658
  }
659
- do_action( "woe_order_exported", $order_id);
660
  self::$orders_exported = 1;
661
  self::try_modify_status( $order_id, $settings );
662
  self::try_mark_order( $order_id, $settings );
@@ -670,126 +719,156 @@ class WC_Order_Export_Engine {
670
  }
671
  self::$order_id = '';
672
  }
673
-
674
- do_action( 'woe_export_finished');
 
675
  return $result; //return last result
676
  }
677
 
678
 
679
- public static function build_files_and_export( $settings, $filename = '', $limit = 0, $order_ids = array( ) ) {
680
- if (!empty($settings['destination']['separate_files'])) {
681
  $result = self::build_separate_files_and_export( $settings, $filename, $limit, $order_ids );
682
- }
683
- else {
684
  $file = self::build_file_full( $settings, $filename, $limit, $order_ids );
685
- if ( $file !== false )
686
- $result = self::export( $settings, $file );
687
- else
 
 
 
 
 
 
688
  $result = false;
 
 
 
 
 
689
  }
690
 
691
- if ( $result === false )
692
- $result = __( 'Nothing to export. Please, adjust your filters', 'woo-order-export-lite' );
693
  return $result;
694
  }
695
 
696
- public static function build_files_and_prepare( $settings, $filename = '', $limit = 0, $order_ids = array( ) ) {
697
- $file = self::build_file_full( $settings, $filename, $limit, $order_ids );
698
- if ( $file !== false ) {
699
- $result = self::prepare( $settings, $file );
700
- return $result;
701
- } else {
702
- return __( 'Nothing to export. Please, adjust your filters', 'woo-order-export-lite' );
703
- }
704
- }
 
705
 
706
 
707
  //SUMMARY report starts here
708
  private static function check_create_session() {
709
- if(!session_id()) {
710
- session_start();
711
- }
712
  }
 
713
  //reset data
714
  private static function maybe_init_summary_report( $labels ) {
715
- if( !self::$current_job_settings['summary_report_by_products'] )
716
- return;
717
- self::check_create_session();
718
-
 
719
  //make new header
720
- add_filter('woe_' . strtolower(self::$current_job_settings['format']) . '_header_filter', function() use ($labels) {
721
- $header = array();
722
- foreach( $labels['products'] as $k=>$v) {
723
- if( !preg_match('#^(line_|qty)#',$k) )
724
- $header[$k] = $v;
725
- }
726
- $_SESSION['woe_summary_columns'] = $header;
727
-
728
- // prepare output
729
- $header = array_values( $header );
730
- // extra columns
731
- $summary_headers = array( __( "Total Quantity", 'woo-order-export-lite'), __( "Total Amount", 'woo-order-export-lite') );
732
- $header = apply_filters("woe_summary_headers", array_merge( $header, $summary_headers ) );
733
- return $header;
734
- });
735
- $_SESSION['woe_summary_products'] = array();
 
 
 
 
 
 
736
  }
737
-
738
  //get ready to accept data
739
  private static function maybe_start_summary_report() {
740
- if( !self::$current_job_settings['summary_report_by_products'] )
741
- return;
 
742
  self::check_create_session();
743
-
744
  //don't output orders
745
- add_filter( 'woe_fetch_order_row', '__return_false');
746
  // gather details
747
- add_filter( "woe_fetch_order_products", array('WC_Order_Export_Engine', 'summary_report_add_order_products'), 10, 5 );
 
748
  }
749
-
750
- public static function summary_report_add_order_products($products, $order, $labels, $format, $static_vals ) {
751
- foreach($order->get_items( ) as $item_id=>$item) {
752
- if( !isset($products[$item_id]) )
753
  continue;
754
- $prepared_product = $products[$item_id];
755
- $product = $order->get_product_from_item( $item );
756
-
 
757
  //ok can process this product
758
- $product_id = !empty($item['variation_id']) ? $item['variation_id'] : $item['product_id'];
759
- $key = !empty($product_id) ? $product_id : $item['name'];
760
- $key = apply_filters( "woe_summary_products_adjust_key", $key, $product, $item, $order );
761
- if( !isset($_SESSION['woe_summary_products'][$key]) ) {
762
  //take only exported fields to match columns
763
  $summary_product = array_intersect_key( $prepared_product, $_SESSION['woe_summary_columns'] );
764
  //extra columns
765
- $summary_rows = apply_filters("woe_summary_column_keys", array( 'qty'=>0, 'total'=>0 ) );
766
- foreach($summary_rows as $k=>$default)
767
  $summary_product[ $k ] = $default;
768
- $summary_product = apply_filters( "woe_summary_products_prepare_product", $summary_product, $key, $product, $item, $order );
769
- $_SESSION['woe_summary_products'][$key] = $summary_product;
770
- }
 
 
771
  //sum items
772
- $total = method_exists($item, 'get_total') ? $item->get_total() : $item['line_total'];
773
- $_SESSION['woe_summary_products'][$key]['total'] += wc_round_tax_total( $total );
774
- $_SESSION['woe_summary_products'][$key]['qty'] += $item['qty'];
775
- do_action('woe_summary_products_add_item', $key, $item, $order);
 
776
  }
 
777
  return $products;
778
  }
779
-
780
- private static function maybe_output_summary_report($formatter) {
781
- if( !self::$current_job_settings['summary_report_by_products'] )
782
- return ;
 
783
  self::check_create_session();
784
 
785
  //possible formatting
786
  self::$current_job_settings['summary_fields']['total'] = array( 'format' => 'money' );
787
-
788
  ksort( $_SESSION['woe_summary_products'] );// by Name+Id
789
- foreach($_SESSION['woe_summary_products'] as $data) {
790
- if( self::$extractor_options['format_number_fields'] and isset($data[ 'total' ]) )
791
- $data[ 'total' ] = WC_Order_Export_Data_Extractor::format_numbers('summary', $data[ 'total' ], 'total');
792
- $formatter->output( $data);
 
 
 
 
793
  }
794
  }
795
  }
12
  public static $order_id = '';
13
  public static $orders_exported = 0;
14
  public static $make_separate_orders = false;
15
+
16
  //
17
  public static function export( $settings, $filepath ) {
18
+ if ( empty( $settings['destination']['type'] ) ) {
19
  return __( "No destination selected", 'woo-order-export-lite' );
20
  }
21
+
22
+ if ( ! is_array( $settings['destination']['type'] ) ) {
23
+ $settings['destination']['type'] = array( $settings['destination']['type'] );
24
  }
25
+ $results = array();
26
+ foreach ( $settings['destination']['type'] as $export_type ) {
27
  $export_type = strtolower( $export_type );
28
  if ( ! in_array( strtoupper( $export_type ), WC_Order_Export_Admin::$export_types ) ) {
29
  return __( "Wrong format", 'woo-order-export-lite' );
34
  $class = 'WOE_Export_' . $export_type;
35
  $exporter = new $class( $settings['destination'] );
36
 
37
+ $filename = self::make_filename( $settings['export_filename'] );
38
+ $custom_export = apply_filters( 'woe_custom_export_to_' . $export_type, false, $filename, $filepath,
39
+ $exporter );
40
+ if ( ! $custom_export ) {
41
  // try many times?
42
  $num_retries = 0;
43
+ while ( $num_retries < $exporter->get_num_of_retries() ) {
44
+ $num_retries ++;
45
  $results[] = $exporter->run_export( $filename, $filepath );
46
+ if ( $exporter->finished_successfully ) {
47
  break;
48
+ }
49
+ }
50
  } else {
51
  $results[] = $custom_export;
52
  }
53
  }
54
+
55
  return implode( "<br>\r\n", $results );
56
  }
57
 
58
+ public static function prepare( $settings, $filepath ) {
59
+ if ( empty( $settings['destination']['type'] ) ) {
60
+ return __( "No destination selected", 'woo-order-export-lite' );
61
+ }
62
+
63
+ if ( ! is_array( $settings['destination']['type'] ) ) {
64
+ $settings['destination']['type'] = array( $settings['destination']['type'] );
65
+ }
66
+ $results = array();
67
+ foreach ( $settings['destination']['type'] as $export_type ) {
68
+ $export_type = strtolower( $export_type );
69
+ if ( ! in_array( strtoupper( $export_type ), WC_Order_Export_Admin::$export_types ) ) {
70
+ return __( "Wrong export type", 'woo-order-export-lite' );
71
+ }
72
+
73
+ include_once dirname( dirname( __FILE__ ) ) . "/exports/abstract-class-woe-export.php";
74
+ include_once dirname( dirname( __FILE__ ) ) . "/exports/class-woe-export-{$export_type}.php";
75
+ $class = 'WOE_Export_' . $export_type;
76
+ $exporter = new $class( $settings['destination'] );
77
+
78
+ $filename = self::make_filename( $settings['export_filename'] );
79
+ $custom_prepare = apply_filters( 'woe_custom_prepare_to_' . $export_type, false, $filename, $filepath,
80
+ $exporter );
81
+ if ( ! $custom_prepare ) {
82
+ if ( method_exists( $exporter, 'prepare' ) ) {
83
+ $results[] = $exporter->prepare( $filename, $filepath );
84
+ }
85
+ } else {
86
+ $results[] = $custom_prepare;
87
+ }
88
+ }
89
+
90
+ return $results;
91
+ }
92
 
93
  public static function make_filename( $mask ) {
94
  if ( self::$make_separate_orders && strpos( $mask, '%order_id' ) === false ) {
95
+ $mask_parts = explode( '.', $mask );
96
+ $before_prefix = count( $mask_parts ) > 1 ? 2 : 1;
97
  $mask_parts[ count( $mask_parts ) - $before_prefix ] .= '-%order_id';
98
+ $mask = implode( '.', $mask_parts );
99
  }
100
  $time = apply_filters( 'woe_make_filename_current_time', current_time( 'timestamp' ) );
101
 
102
+ $date = WC_Order_Export_Data_Extractor::get_date_range( self::$current_job_settings, false );
103
 
104
  $subst = apply_filters( 'woe_make_filename_replacements', array(
105
+ '%d' => date( 'd', $time ),
106
+ '%m' => date( 'm', $time ),
107
+ '%y' => date( 'Y', $time ),
108
+ '%h' => date( 'H', $time ),
109
+ '%i' => date( 'i', $time ),
110
+ '%s' => date( 's', $time ),
111
+ '%order_id' => self::$order_id,
112
+ '%orderid' => self::$order_id,
113
+ '%id' => self::$order_id,
114
  '{from_date}' => isset( $date['from_date'] ) ? date( "Y-m-d", strtotime( $date['from_date'] ) ) : '',
115
+ '{to_date}' => isset( $date['to_date'] ) ? date( "Y-m-d", strtotime( $date['to_date'] ) ) : '',
116
  ) );
117
 
118
  return apply_filters( 'woe_make_filename', strtr( $mask, $subst ) );
119
  }
120
+
121
  public static function kill_buffers() {
122
+ while ( ob_get_level() ) {
123
  ob_end_clean();
124
+ }
125
  }
126
 
127
  public static function tempnam( $folder, $prefix ) {
128
  $filename = @tempnam( $folder, $prefix );
129
+ if ( ! $filename ) {
130
+ $tmp_folder = dirname( dirname( dirname( __FILE__ ) ) ) . '/tmp';
131
  // kill expired tmp file
132
+ foreach ( glob( $tmp_folder . "/*" ) as $f ) {
133
+ if ( time() - filemtime( $f ) > 24 * 3600 ) {
134
  unlink( $f );
135
+ }
136
  }
137
  $filename = tempnam( $tmp_folder, $prefix );
138
  }
139
+
140
  return $filename;
141
  }
142
 
146
  $labels = array();
147
  foreach ( $fields as $key => $field ) {
148
  if ( preg_match( '#^custom_field_#', $key ) ) { // for static fields
149
+ $static_vals[ $key ] = isset( $field['value'] ) ? $field['value'] : $field['colname'];// FIX BUG here
150
  }
151
  if ( $field['checked'] ) {
152
  $labels[ $key ] = apply_filters( "woe_get_{$format}_label_{$key}", $field['colname'] );
153
+
154
+ if ( isset( $field['format'] ) ) {
155
  $field_formats[ $field['format'] ][] = $key;
156
+ }
157
  }
158
  }
159
+
160
  return $labels;
161
  }
162
 
174
 
175
  /**
176
  * @param string $mode
177
+ * @param array $settings
178
  * @param string $fname
179
+ * @param null $labels
180
+ * @param null $static_vals
181
  *
182
  * @return WOE_Formatter
183
  */
184
  private static function init_formater( $mode, $settings, $fname, &$labels, &$static_vals ) {
185
  $format = strtolower( $settings['format'] );
186
  include_once dirname( dirname( __FILE__ ) ) . "/formats/abstract-class-woe-formatter.php";
187
+ if ( ! apply_filters( 'woe_load_custom_formatter_' . $format, false ) ) {
188
  include_once dirname( dirname( __FILE__ ) ) . "/formats/class-woe-formatter-$format.php";
189
+ }
190
 
191
  $format_settings = array( 'global_job_settings' => $settings );
192
  foreach ( $settings as $key => $val ) {
199
 
200
  $class = 'WOE_Formatter_' . $format;
201
 
202
+ do_action( 'woe_init_custom_formatter', $mode, $fname, $format_settings, $format, $labels, $field_formats,
203
+ self::$date_format, $settings );
204
 
205
+ return new $class( $mode, $fname, $format_settings, $format, $labels, $field_formats, self::$date_format );
206
  }
207
 
208
  private static function init_labels( $settings, &$labels, &$static_vals, &$field_formats ) {
209
  $format = strtolower( $settings['format'] );
210
 
211
+ $static_vals = array( 'order' => array(), 'products' => array(), 'coupons' => array() );
212
  $field_formats = array( 'money' => array(), 'number' => array(), 'date' => array(), 'string' => array() );
213
+ $labels = array(
214
  'order' => self::get_labels( $settings['order_fields'], $format, $static_vals['order'], $field_formats ),
215
+ 'products' => self::get_labels( $settings['order_product_fields'], $format, $static_vals['products'],
216
+ $field_formats ),
217
+ 'coupons' => self::get_labels( $settings['order_coupon_fields'], $format, $static_vals['coupons'],
218
+ $field_formats ),
219
  );
220
  }
221
 
225
  $csv_max['coupons'] = $csv_max['products'] = 1;
226
  if ( $format == 'xls' OR $format == 'csv' OR $format == 'tsv' ) {
227
  if ( @$settings['order_fields']['products']['repeat'] == 'columns' ) {
228
+ if ( @$settings['order_fields']['products']['max_cols'] ) {
229
  $csv_max['products'] = $settings['order_fields']['products']['max_cols'];
230
+ } else {
231
+ $csv_max['products'] = WC_Order_Export_Data_Extractor::get_max_order_items( "line_item",
232
+ $order_ids );
233
+ }
234
  }
235
  if ( @$settings['order_fields']['coupons']['repeat'] == 'columns' ) {
236
+ if ( @$settings['order_fields']['coupons']['max_cols'] ) {
237
  $csv_max['coupons'] = $settings['order_fields']['coupons']['max_cols'];
238
+ } else {
239
  $csv_max['coupons'] = WC_Order_Export_Data_Extractor::get_max_order_items( "coupon", $order_ids );
240
+ }
241
  }
242
  }
243
 
248
  $format = strtolower( $settings['format'] );
249
 
250
  $filters_active = array(
251
+ 'order' => self::check_filters( $settings['order_fields'], $format, 'order' ),
252
+ 'products' => self::check_filters( $settings['order_product_fields'], $format, 'order_product' ),
253
+ 'coupons' => self::check_filters( $settings['order_coupon_fields'], $format, 'order_coupon' ),
254
  );
255
 
256
  return $filters_active;
260
  $export['products'] = $settings['order_fields']['products']['checked'];
261
  $export['coupons'] = $settings['order_fields']['coupons']['checked'];
262
  $get_coupon_meta = ( $export['coupons'] AND array_diff( array_keys( $labels['coupons'] ),
263
+ array( 'code', 'discount_amount', 'discount_amount_tax', 'excerpt' ) ) );
264
  if ( empty( $labels['products'] ) ) {
265
  $export['products'] = 0;
266
  unset( $labels['order']['products'] );
272
  }
273
 
274
  private static function _make_header( $format, $labels, $csv_max ) {
275
+ $header = ( $format == 'xls' OR $format == 'csv' OR $format == 'tsv' ) ? self::_make_header_csv( $labels,
276
+ $csv_max ) : '';
277
+ do_action( 'woe_make_header_custom_formatter', $format, $labels, $csv_max );
278
 
279
  return $header;
280
  }
294
  $field_header[] = $label;
295
  }
296
  $field_header = apply_filters( 'woe_add_csv_headers', $field_header, $field );
297
+ $header = array_merge( $header, $field_header );
298
  }
299
 
300
  return $header;
306
  $format = strtolower( $settings['format'] );
307
 
308
  $options = array();
309
+
310
  if ( $format == 'xls' AND @$settings['format_xls_populate_other_columns_product_rows']
311
  OR $format == 'csv' AND @$settings['format_csv_populate_other_columns_product_rows']
312
  OR $format == 'tsv' AND @$settings['format_tsv_populate_other_columns_product_rows'] ) {
313
  $options['populate_other_columns_product_rows'] = 1;
314
  }
315
  $options['item_rows_start_from_new_line'] = ( $format == 'csv' AND @$settings['format_csv_item_rows_start_from_new_line'] );
316
+ $options['products_mode'] = isset( $settings['order_fields']['products']['repeat'] ) ? $settings['order_fields']['products']['repeat'] : "";
317
+ $options['coupons_mode'] = isset( $settings['order_fields']['coupons']['repeat'] ) ? $settings['order_fields']['coupons']['repeat'] : "";
318
 
319
+ if ( ! empty( $settings['all_products_from_order'] ) ) {
320
  $options['include_products'] = false;
321
+ } else {
322
+ $options['include_products'] = $wpdb->get_col( WC_Order_Export_Data_Extractor::sql_get_product_ids( $settings ) );
323
+ }
324
 
325
+ if ( isset( $settings['date_format'] ) ) {
326
  $options['date_format'] = $settings['date_format'];
327
+ } else {
328
  $options['date_format'] = 'Y-m-d';
329
+ }
330
 
331
+ if ( isset( $settings['time_format'] ) ) {
332
  $options['time_format'] = $settings['time_format'];
333
+ } else {
334
  $options['time_format'] = 'H:i';
335
+ }
336
 
337
  //as is
338
+ $options['export_refunds'] = $settings['export_refunds'];
339
+ $options['skip_refunded_items'] = $settings['skip_refunded_items'];
340
+ $options['export_all_comments'] = $settings['export_all_comments'];
341
+ $options['export_refund_notes'] = $settings['export_refund_notes'];
342
  $options['format_number_fields'] = $settings['format_number_fields'];
343
 
344
  if ( $settings['enable_debug'] AND ! ini_get( 'display_errors' ) ) {
354
  foreach ( array( "billing_phone", "USER_billing_phone" ) as $field ) {
355
  add_filter( 'woe_get_order_value_' . $field, function ( $value, $order, $fieldname ) {
356
  $value = preg_replace( "#[^\d]+#", "", $value );
357
+
358
  return $value;
359
  }, 10, 3 );
360
  }
361
  }
362
 
363
+ $options['strip_tags_product_fields'] = ! empty( $settings['strip_tags_product_fields'] );
364
 
365
  return $options;
366
  }
367
 
368
+ private static function validate_defaults( $settings ) {
369
+ if ( empty( $settings['sort'] ) ) {
370
  $settings['sort'] = 'order_id';
371
+ }
372
+ if ( empty( $settings['sort_direction'] ) ) {
373
  $settings['sort_direction'] = 'DESC';
374
+ }
375
+ if ( ! isset( $settings['skip_empty_file'] ) ) {
376
  $settings['skip_empty_file'] = true;
377
+ }
378
+ if ( $settings['custom_php'] ) {
379
  ob_start( array( 'WC_Order_Export_Engine', 'code_error_callback' ) );
380
+ $result = eval( $settings['custom_php_code'] );
381
  ob_end_clean();
382
  }
383
  // This report works with products!
384
+ if ( $settings['summary_report_by_products'] ) {
385
  $settings['order_fields']['products']['checked'] = 1;
386
+ }
387
+
388
+ return apply_filters( 'woe_settings_validate_defaults', $settings );
389
  }
390
 
391
  private static function code_error_callback( $out ) {
396
  }
397
 
398
  $m = '<h2>' . __( "Don't Panic", 'woo-order-export-lite' ) . '</h2>';
399
+ $m .= '<p>' . sprintf( __( 'The code you are trying to save produced a fatal error on line %d:',
400
+ 'woo-order-export-lite' ), $error['line'] ) . '</p>';
401
  $m .= '<strong>' . $error['message'] . '</strong>';
402
 
403
  return $m;
404
  }
405
 
406
+ private static function try_modify_status( $order_id, $settings ) {
407
  if ( isset( $settings['change_order_status_to'] ) && wc_is_order_status( $settings['change_order_status_to'] ) ) {
408
  $order = new WC_Order( $order_id );
409
  $order->update_status( $settings['change_order_status_to'] );
410
  }
411
  }
412
 
413
+ private static function try_mark_order( $order_id, $settings ) {
414
+ if ( $settings['mark_exported_orders'] ) {
415
+ update_post_meta( $order_id, 'woe_order_exported', current_time( 'timestamp' ) );
416
  }
417
  }
418
 
427
  global $wpdb;
428
 
429
  self::kill_buffers();
430
+ $settings = self::validate_defaults( $settings );
431
+ self::$current_job_settings = $settings;
432
  self::$current_job_build_mode = $make_mode;
433
+ self::$date_format = trim( $settings['date_format'] . ' ' . $settings['time_format'] );
434
  //debug sql?
435
+ if ( $make_mode == 'preview' AND $settings['enable_debug'] ) {
436
+ WC_Order_Export_Data_Extractor::start_track_queries();
437
+ }
438
  // might run sql!
439
+ self::$extractor_options = self::_install_options( $settings );
440
 
441
  if ( $output_mode == 'browser' ) {
442
  $filename = 'php://output';
444
  $filename = ( ! empty( $filename ) ? $filename : self::tempnam( sys_get_temp_dir(), $settings['format'] ) );
445
  }
446
 
447
+ if ( $make_mode !== 'estimate' ) {
448
  $formater = self::init_formater( $make_mode, $settings, $filename, $labels, $static_vals );
449
+ }
450
+ $format = strtolower( $settings['format'] );
451
 
452
  if ( $make_mode == 'finish' ) {
453
  self::maybe_output_summary_report( $formater );
454
  $formater->finish();
455
+
456
  return $filename;
457
  }
458
 
459
+
460
  //get IDs
461
  $sql = WC_Order_Export_Data_Extractor::sql_get_order_ids( $settings );
462
  if ( $make_mode == 'estimate' ) { //if estimate return total count
463
  return $wpdb->get_var( str_replace( 'ID AS order_id', 'COUNT(ID) AS order_count', $sql ) );
464
  } elseif ( $make_mode == 'preview' ) {
465
+ $sql .= apply_filters( "woe_sql_get_order_ids_order_by",
466
+ " ORDER BY " . $settings['sort'] . " " . $settings['sort_direction'] ) . " LIMIT " . ( $limit !== false ? $limit : 1 );
467
  } elseif ( $make_mode == 'partial' ) {
468
+ $sql .= apply_filters( "woe_sql_get_order_ids_order_by",
469
+ " ORDER BY " . $settings['sort'] . " " . $settings['sort_direction'] );
470
+ $offset = ($settings['mark_exported_orders'] && $settings['export_unmarked_orders']) ? 0 : intval( $offset );
471
  $limit = intval( $limit );
472
+ $sql .= " LIMIT $offset,$limit";
473
  }
474
 
475
  $order_ids = $wpdb->get_col( $sql );
500
  WC_Order_Export_Data_Extractor::prepare_for_export();
501
  self::$orders_exported = 0;// incorrect value
502
  foreach ( $order_ids as $order_id ) {
503
+ $order_id = apply_filters( "woe_order_export_started", $order_id );
504
+ if ( ! $order_id ) {
505
  continue;
506
+ }
507
  self::$order_id = $order_id;
508
+ $rows = WC_Order_Export_Data_Extractor::fetch_order_data( $order_id, $labels, $format,
509
+ $filters_active,
510
  $csv_max, $export, $get_coupon_meta, $static_vals, self::$extractor_options );
511
  foreach ( $rows as $row ) {
512
+ $row = apply_filters( "woe_fetch_order_row", $row, $order_id );
513
+ if ( $row ) {
514
  $formater->output( $row );
515
+ do_action( "woe_order_row_exported", $row, $order_id );
516
  }
517
  }
518
  if ( $make_mode != 'preview' ) {
519
+ do_action( "woe_order_exported", $order_id );
520
  self::try_mark_order( $order_id, $settings );
521
+ } else {
522
+ do_action( "woe_order_previewed", $order_id );
523
  }
 
 
524
  }
525
 
526
  // for modes
527
+ if ( $make_mode == 'partial' ) {
528
  $formater->finish_partial();
529
+ } elseif ( $make_mode == 'preview' ) {
530
  self::maybe_output_summary_report( $formater );
531
  $flat_formats = array( 'XLS', 'CSV', 'TSV' );//limit debug output
532
+ if ( $settings['enable_debug'] AND in_array( $settings['format'], $flat_formats ) ) {
533
  echo "<b>" . __( 'Main SQL queries are listed below', 'woo-order-export-lite' ) . "</b>";
534
  echo '<textarea rows=5 style="width:100%">';
535
  $s = array();
536
+ foreach ( WC_Order_Export_Data_Extractor::get_sql_queries() as $sql ) {
537
+ $s[] = preg_replace( "#\s+#", " ", $sql );
538
+ }
539
+ echo join( "\n\n", $s );
540
  echo '</textarea>';
541
+ }
542
  $formater->finish();
543
+ }
544
 
545
  // no action woe_export_finished here!
546
  return $filename;
547
  }
548
 
549
+ public static function build_file_full( $settings, $filename = '', $limit = 0, $order_ids = array() ) {
550
  global $wpdb;
551
+
552
  //no need self::kill_buffers();
553
+ $settings = self::validate_defaults( $settings );
554
+ self::$current_job_settings = $settings;
555
  self::$current_job_build_mode = 'full';
556
+ self::$date_format = trim( $settings['date_format'] . ' ' . $settings['time_format'] );
557
+ self::$extractor_options = self::_install_options( $settings );
558
 
559
  $filename = ( ! empty( $filename ) ? $filename : self::tempnam( sys_get_temp_dir(), $settings['format'] ) );
560
 
561
  $formater = self::init_formater( '', $settings, $filename, $labels, $static_vals );
562
  $format = strtolower( $settings['format'] );
563
+
564
  self::maybe_init_summary_report( $labels );
565
+ self::maybe_start_summary_report();
566
 
567
  //get IDs
568
  $sql = WC_Order_Export_Data_Extractor::sql_get_order_ids( $settings );
569
+ $sql .= apply_filters( "woe_sql_get_order_ids_order_by",
570
+ " ORDER BY " . $settings['sort'] . " " . $settings['sort_direction'] );
571
 
572
  if ( $limit ) {
573
  $sql .= " LIMIT " . intval( $limit );
574
  }
575
+ if ( ! $order_ids ) {
576
  $order_ids = $wpdb->get_col( $sql );
577
+ }
578
 
579
+ if ( empty( $order_ids ) AND apply_filters( 'woe_schedule_job_skip_empty_file',
580
+ (bool) $settings['skip_empty_file'] ) ) {
581
+ unlink($filename);
582
  return false;
583
  }
584
 
600
  WC_Order_Export_Data_Extractor::prepare_for_export();
601
  self::$orders_exported = 0;
602
  foreach ( $order_ids as $order_id ) {
603
+ $order_id = apply_filters( "woe_order_export_started", $order_id );
604
+ if ( ! $order_id ) {
605
  continue;
606
+ }
607
  self::$order_id = $order_id;
608
+ $rows = WC_Order_Export_Data_Extractor::fetch_order_data( $order_id, $labels, $format,
609
+ $filters_active,
610
  $csv_max, $export, $get_coupon_meta, $static_vals, self::$extractor_options );
611
  foreach ( $rows as $row ) {
612
+ $row = apply_filters( "woe_fetch_order_row", $row, $order_id );
613
+ if ( $row ) {
614
  $formater->output( $row );
615
+ do_action( "woe_order_row_exported", $row, $order_id );
616
  }
617
  }
618
+ do_action( "woe_order_exported", $order_id );
619
 
620
+ do_action( 'woe_formatter_output_custom_formatter', $order_id, $labels, $format, $filters_active,
621
+ $csv_max, $export, $get_coupon_meta, $static_vals, self::$extractor_options );
622
 
623
+ self::$orders_exported ++;
624
  self::try_modify_status( $order_id, $settings );
625
  self::try_mark_order( $order_id, $settings );
626
  }
627
+
628
  self::maybe_output_summary_report( $formater );
629
  $formater->finish();
630
+ do_action( 'woe_finish_custom_formatter' );
631
+
632
+ do_action( 'woe_export_finished' );
633
 
 
634
  return $filename;
635
  }
636
 
637
+ public static function build_separate_files_and_export(
638
+ $settings,
639
+ $filename = '',
640
+ $limit = 0,
641
+ $order_ids = array()
642
+ ) {
643
  global $wpdb;
644
+
645
  self::kill_buffers();
646
+ $settings = self::validate_defaults( $settings );
647
+ self::$current_job_settings = $settings;
648
  self::$current_job_build_mode = 'full';
649
+ self::$date_format = trim( $settings['date_format'] . ' ' . $settings['time_format'] );
650
+ self::$extractor_options = self::_install_options( $settings );
651
 
652
  $filename = ( ! empty( $filename ) ? $filename : self::tempnam( sys_get_temp_dir(), $settings['format'] ) );
653
 
654
  self::init_labels( $settings, $labels, $static_vals, $field_formats );
655
+ $format = strtolower( $settings['format'] );
656
 
657
  //get IDs
658
  $sql = WC_Order_Export_Data_Extractor::sql_get_order_ids( $settings );
659
+ $sql .= apply_filters( "woe_sql_get_order_ids_order_by",
660
+ " ORDER BY " . $settings['sort'] . " " . $settings['sort_direction'] );
661
 
662
  if ( $limit ) {
663
  $sql .= " LIMIT " . intval( $limit );
664
  }
665
 
666
+ if ( ! $order_ids ) {
667
  $order_ids = $wpdb->get_col( $sql );
668
+ }
669
 
670
  if ( empty( $order_ids ) ) {
671
  return false;
687
  WC_Order_Export_Data_Extractor::prepare_for_export();
688
  self::$make_separate_orders = true;
689
  foreach ( $order_ids as $order_id ) {
690
+ $order_id = apply_filters( "woe_order_export_started", $order_id );
691
+ if ( ! $order_id ) {
692
  continue;
693
+ }
694
  self::$order_id = $order_id;
695
  $formater = self::init_formater( '', $settings, $filename, $_labels, $_static_vals );
696
 
697
  $formater->truncate();
698
  $formater->start( $header );
699
  $rows = WC_Order_Export_Data_Extractor::fetch_order_data( $order_id, $labels, $format, $filters_active,
700
+ $csv_max, $export, $get_coupon_meta, $static_vals, self::$extractor_options );
701
  foreach ( $rows as $row ) {
702
+ $row = apply_filters( "woe_fetch_order_row", $row, $order_id );
703
+ if ( $row ) {
704
  $formater->output( $row );
705
+ do_action( "woe_order_row_exported", $row, $order_id );
706
  }
707
  }
708
+ do_action( "woe_order_exported", $order_id );
709
  self::$orders_exported = 1;
710
  self::try_modify_status( $order_id, $settings );
711
  self::try_mark_order( $order_id, $settings );
719
  }
720
  self::$order_id = '';
721
  }
722
+
723
+ do_action( 'woe_export_finished' );
724
+
725
  return $result; //return last result
726
  }
727
 
728
 
729
+ public static function build_files_and_export( $settings, $filename = '', $limit = 0, $order_ids = array() ) {
730
+ if ( ! empty( $settings['destination']['separate_files'] ) ) {
731
  $result = self::build_separate_files_and_export( $settings, $filename, $limit, $order_ids );
732
+ } else {
 
733
  $file = self::build_file_full( $settings, $filename, $limit, $order_ids );
734
+ if ( $file !== false ) {
735
+
736
+ $result = self::export( $settings, $file );
737
+
738
+ if (file_exists($file)) {
739
+ unlink($file);
740
+ }
741
+
742
+ } else {
743
  $result = false;
744
+ }
745
+ }
746
+
747
+ if ( $result === false ) {
748
+ $result = __( 'Nothing to export. Please, adjust your filters', 'woo-order-export-lite' );
749
  }
750
 
 
 
751
  return $result;
752
  }
753
 
754
+ public static function build_files_and_prepare( $settings, $filename = '', $limit = 0, $order_ids = array() ) {
755
+ $file = self::build_file_full( $settings, $filename, $limit, $order_ids );
756
+ if ( $file !== false ) {
757
+ $result = self::prepare( $settings, $file );
758
+
759
+ return $result;
760
+ } else {
761
+ return __( 'Nothing to export. Please, adjust your filters', 'woo-order-export-lite' );
762
+ }
763
+ }
764
 
765
 
766
  //SUMMARY report starts here
767
  private static function check_create_session() {
768
+ if ( ! session_id() ) {
769
+ @session_start();
770
+ }
771
  }
772
+
773
  //reset data
774
  private static function maybe_init_summary_report( $labels ) {
775
+ if ( ! self::$current_job_settings['summary_report_by_products'] ) {
776
+ return;
777
+ }
778
+ self::check_create_session();
779
+
780
  //make new header
781
+ add_filter( 'woe_' . strtolower( self::$current_job_settings['format'] ) . '_header_filter',
782
+ function () use ( $labels ) {
783
+ $header = array();
784
+ foreach ( $labels['products'] as $k => $v ) {
785
+ if ( ! preg_match( '#^(line_|qty)#', $k ) ) {
786
+ $header[ $k ] = $v;
787
+ }
788
+ }
789
+ $_SESSION['woe_summary_columns'] = $header;
790
+
791
+ // prepare output
792
+ $header = array_values( $header );
793
+ // extra columns
794
+ $summary_headers = array(
795
+ __( "Total Quantity", 'woo-order-export-lite' ),
796
+ __( "Total Amount", 'woo-order-export-lite' ),
797
+ );
798
+ $header = apply_filters( "woe_summary_headers", array_merge( $header, $summary_headers ) );
799
+
800
+ return $header;
801
+ } );
802
+ $_SESSION['woe_summary_products'] = array();
803
  }
804
+
805
  //get ready to accept data
806
  private static function maybe_start_summary_report() {
807
+ if ( ! self::$current_job_settings['summary_report_by_products'] ) {
808
+ return;
809
+ }
810
  self::check_create_session();
811
+
812
  //don't output orders
813
+ add_filter( 'woe_fetch_order_row', '__return_false' );
814
  // gather details
815
+ add_filter( "woe_fetch_order_products", array( 'WC_Order_Export_Engine', 'summary_report_add_order_products' ),
816
+ 10, 5 );
817
  }
818
+
819
+ public static function summary_report_add_order_products( $products, $order, $labels, $format, $static_vals ) {
820
+ foreach ( $order->get_items() as $item_id => $item ) {
821
+ if ( ! isset( $products[ $item_id ] ) ) {
822
  continue;
823
+ }
824
+ $prepared_product = $products[ $item_id ];
825
+ $product = $order->get_product_from_item( $item );
826
+
827
  //ok can process this product
828
+ $product_id = ! empty( $item['variation_id'] ) ? $item['variation_id'] : $item['product_id'];
829
+ $key = ! empty( $product_id ) ? $product_id : $item['name'];
830
+ $key = apply_filters( "woe_summary_products_adjust_key", $key, $product, $item, $order );
831
+ if ( ! isset( $_SESSION['woe_summary_products'][ $key ] ) ) {
832
  //take only exported fields to match columns
833
  $summary_product = array_intersect_key( $prepared_product, $_SESSION['woe_summary_columns'] );
834
  //extra columns
835
+ $summary_rows = apply_filters( "woe_summary_column_keys", array( 'qty' => 0, 'total' => 0 ) );
836
+ foreach ( $summary_rows as $k => $default ) {
837
  $summary_product[ $k ] = $default;
838
+ }
839
+ $summary_product = apply_filters( "woe_summary_products_prepare_product",
840
+ $summary_product, $key, $product, $item, $order );
841
+ $_SESSION['woe_summary_products'][ $key ] = $summary_product;
842
+ }
843
  //sum items
844
+ $total = method_exists( $item,
845
+ 'get_total' ) ? $item->get_total() : $item['line_total'];
846
+ $_SESSION['woe_summary_products'][ $key ]['total'] += wc_round_tax_total( $total );
847
+ $_SESSION['woe_summary_products'][ $key ]['qty'] += $item['qty'];
848
+ do_action( 'woe_summary_products_add_item', $key, $item, $order );
849
  }
850
+
851
  return $products;
852
  }
853
+
854
+ private static function maybe_output_summary_report( $formatter ) {
855
+ if ( ! self::$current_job_settings['summary_report_by_products'] ) {
856
+ return;
857
+ }
858
  self::check_create_session();
859
 
860
  //possible formatting
861
  self::$current_job_settings['summary_fields']['total'] = array( 'format' => 'money' );
862
+
863
  ksort( $_SESSION['woe_summary_products'] );// by Name+Id
864
+
865
+ do_action( 'woe_summary_before_output' );
866
+
867
+ foreach ( $_SESSION['woe_summary_products'] as $data ) {
868
+ if ( self::$extractor_options['format_number_fields'] and isset( $data['total'] ) ) {
869
+ $data['total'] = WC_Order_Export_Data_Extractor::format_numbers( 'summary', $data['total'], 'total' );
870
+ }
871
+ $formatter->output( $data );
872
  }
873
  }
874
  }
classes/formats/abstract-class-woe-formatter-sv.php CHANGED
@@ -38,19 +38,20 @@ abstract class WOE_Formatter_sv extends WOE_Formatter {
38
  fwrite( $this->handle, chr( 239 ) . chr( 187 ) . chr( 191 ) );
39
  }
40
 
41
- if ( $this->settings['display_column_names'] AND $data) {
42
  if ( $this->mode == 'preview' ) {
43
  $this->rows[] = $data;
44
  } else {
45
- do_action( "woe_before_{$this->format}_print_header", $this->handle, $data, $this);
46
- if( !apply_filters("woe_{$this->format}_custom_output_func",false, $this->handle, $data, $this->delimiter, $this->linebreak, $this->enclosure, true ) ) {
 
47
  if ( $this->enclosure !== '' ) {
48
  fputcsv( $this->handle, $data, $this->delimiter, $this->enclosure );
49
  } else {
50
  fwrite( $this->handle, implode( $this->delimiter, $data ) . $this->linebreak );
51
  }
52
  }
53
- do_action( "woe_{$this->format}_print_header", $this->handle, $data, $this);
54
  }
55
  }
56
  }
@@ -60,15 +61,17 @@ abstract class WOE_Formatter_sv extends WOE_Formatter {
60
  $rec = parent::output( $rec );
61
 
62
  if ( $this->has_output_filter ) {
63
- $rec = apply_filters( "woe_{$this->format}_output_filter", $rec, $rec );
64
- if( !$rec )
65
  return;
 
66
  }
67
 
68
  if ( $this->mode == 'preview' ) {
69
  $this->rows[] = $rec;
70
  } else {
71
- if( ! apply_filters("woe_{$this->format}_custom_output_func",false, $this->handle, $rec, $this->delimiter, $this->linebreak, $this->enclosure, false ) ) {
 
72
  if ( $this->enclosure !== '' ) {
73
  fputcsv( $this->handle, $rec, $this->delimiter, $this->enclosure );
74
  } else {
@@ -99,22 +102,24 @@ abstract class WOE_Formatter_sv extends WOE_Formatter {
99
  }
100
 
101
  protected function prepare_array( &$arr ) {
102
- if( apply_filters("woe_stop_csv_injection", true) ) {
103
  $arr = array_map( array( $this, 'stop_csv_injection' ), $arr );
104
- }
105
-
106
  if ( ! in_array( $this->encoding, array( '', 'utf-8', 'UTF-8' ) ) ) {
107
  $arr = array_map( array( $this, 'encode_value' ), $arr );
108
  }
109
  }
110
 
111
  protected function stop_csv_injection( $value ) {
112
- $formula_chars = array( "=","+","-","@" );
113
- if ( in_array( substr($value,0,1), $formula_chars) )
114
  $value = " " . $value;
 
 
115
  return $value;
116
  }
117
-
118
  protected function encode_value( $value ) {
119
  return iconv( 'UTF-8', $this->encoding, $value );
120
  }
@@ -132,7 +137,7 @@ class WOE_Formatter_sv_crlf_filter extends php_user_filter {
132
  while ( $bucket = stream_bucket_make_writeable( $in ) ) {
133
  // make sure the line endings aren't already CRLF
134
  $bucket->data = preg_replace( "/(?<!\r)\n/", self::$linebreak, $bucket->data );
135
- $consumed += $bucket->datalen;
136
  stream_bucket_append( $out, $bucket );
137
  }
138
 
38
  fwrite( $this->handle, chr( 239 ) . chr( 187 ) . chr( 191 ) );
39
  }
40
 
41
+ if ( $this->settings['display_column_names'] AND $data ) {
42
  if ( $this->mode == 'preview' ) {
43
  $this->rows[] = $data;
44
  } else {
45
+ do_action( "woe_before_{$this->format}_print_header", $this->handle, $data, $this );
46
+ if ( ! apply_filters( "woe_{$this->format}_custom_output_func", false, $this->handle, $data,
47
+ $this->delimiter, $this->linebreak, $this->enclosure, true ) ) {
48
  if ( $this->enclosure !== '' ) {
49
  fputcsv( $this->handle, $data, $this->delimiter, $this->enclosure );
50
  } else {
51
  fwrite( $this->handle, implode( $this->delimiter, $data ) . $this->linebreak );
52
  }
53
  }
54
+ do_action( "woe_{$this->format}_print_header", $this->handle, $data, $this );
55
  }
56
  }
57
  }
61
  $rec = parent::output( $rec );
62
 
63
  if ( $this->has_output_filter ) {
64
+ $rec = apply_filters( "woe_{$this->format}_output_filter", $rec, $this );
65
+ if ( ! $rec ) {
66
  return;
67
+ }
68
  }
69
 
70
  if ( $this->mode == 'preview' ) {
71
  $this->rows[] = $rec;
72
  } else {
73
+ if ( ! apply_filters( "woe_{$this->format}_custom_output_func", false, $this->handle, $rec,
74
+ $this->delimiter, $this->linebreak, $this->enclosure, false ) ) {
75
  if ( $this->enclosure !== '' ) {
76
  fputcsv( $this->handle, $rec, $this->delimiter, $this->enclosure );
77
  } else {
102
  }
103
 
104
  protected function prepare_array( &$arr ) {
105
+ if ( apply_filters( "woe_stop_csv_injection", true ) ) {
106
  $arr = array_map( array( $this, 'stop_csv_injection' ), $arr );
107
+ }
108
+
109
  if ( ! in_array( $this->encoding, array( '', 'utf-8', 'UTF-8' ) ) ) {
110
  $arr = array_map( array( $this, 'encode_value' ), $arr );
111
  }
112
  }
113
 
114
  protected function stop_csv_injection( $value ) {
115
+ $formula_chars = array( "=", "+", "-", "@" );
116
+ if ( in_array( substr( $value, 0, 1 ), $formula_chars ) ) {
117
  $value = " " . $value;
118
+ }
119
+
120
  return $value;
121
  }
122
+
123
  protected function encode_value( $value ) {
124
  return iconv( 'UTF-8', $this->encoding, $value );
125
  }
137
  while ( $bucket = stream_bucket_make_writeable( $in ) ) {
138
  // make sure the line endings aren't already CRLF
139
  $bucket->data = preg_replace( "/(?<!\r)\n/", self::$linebreak, $bucket->data );
140
+ $consumed += $bucket->datalen;
141
  stream_bucket_append( $out, $bucket );
142
  }
143
 
classes/formats/abstract-class-woe-formatter.php CHANGED
@@ -14,7 +14,7 @@ abstract class WOE_Formatter {
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" );
20
  $this->mode = $mode;
@@ -25,17 +25,17 @@ abstract class WOE_Formatter {
25
  if ( ! $this->handle ) {
26
  throw new Exception( $filename . __( 'can not open for output', 'woo-order-export-lite' ) );
27
  }
28
- $this->format = $format;
29
-
30
  // format for cells
31
- $this->field_formats = $field_formats;
32
- $this->string_format_force = apply_filters( "woe_{$format}_string_format_force", false );
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
  }
@@ -46,33 +46,35 @@ abstract class WOE_Formatter {
46
  }
47
 
48
  public function start( $data = '' ) {
49
- do_action("woe_formatter_start", $data);
50
- do_action("woe_formatter_" .$this->format. "_start", $data);
51
  }
52
 
53
  public function output( $rec ) {
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
  }
70
-
71
  public function finish_partial() {
72
  // child must fully implement this method
73
  fclose( $this->handle );
74
- do_action("woe_formatter_finish_partial", $this);
75
- do_action("woe_formatter_" .$this->format. "_finished_partially", $this);
76
  }
77
 
78
  public function truncate() {
@@ -86,23 +88,25 @@ abstract class WOE_Formatter {
86
 
87
  return $s;
88
  }
89
-
90
  protected function format_dates( $rec ) {
91
- foreach($rec as $field=>$value) {
92
- if( in_array($field,$this->field_formats['date']) ) {
93
- $ts = strtotime($value);
94
- if( $ts )
95
- $rec[$field] = date($this->date_format, $ts);
 
96
  }
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
  }
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" );
20
  $this->mode = $mode;
25
  if ( ! $this->handle ) {
26
  throw new Exception( $filename . __( 'can not open for output', 'woo-order-export-lite' ) );
27
  }
28
+ $this->format = $format;
29
+
30
  // format for cells
31
+ $this->field_formats = $field_formats;
32
+ $this->string_format_force = apply_filters( "woe_{$format}_string_format_force", false );
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
  }
46
  }
47
 
48
  public function start( $data = '' ) {
49
+ do_action( "woe_formatter_start", $data );
50
+ do_action( "woe_formatter_" . $this->format . "_start", $data );
51
  }
52
 
53
  public function output( $rec ) {
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
+ }
58
  if ( isset( $rec['line_number'] ) ) {
59
  $rec['line_number'] = $this->counter_value;
60
+ $this->counter_value ++;
61
  }
62
+
63
  return $rec;
64
  }
65
 
66
  public function finish() {
67
  fclose( $this->handle );
68
  $this->delete_counter();
69
+ do_action( "woe_formatter_finish", $this );
70
+ do_action( "woe_formatter_" . $this->format . "_finished", $this );
71
  }
72
+
73
  public function finish_partial() {
74
  // child must fully implement this method
75
  fclose( $this->handle );
76
+ do_action( "woe_formatter_finish_partial", $this );
77
+ do_action( "woe_formatter_" . $this->format . "_finished_partially", $this );
78
  }
79
 
80
  public function truncate() {
88
 
89
  return $s;
90
  }
91
+
92
  protected function format_dates( $rec ) {
93
+ foreach ( $rec as $field => $value ) {
94
+ if ( in_array( $field, $this->field_formats['date'] ) ) {
95
+ $ts = strtotime( $value );
96
+ if ( $ts ) {
97
+ $rec[ $field ] = date( $this->date_format, $ts );
98
+ }
99
  }
100
  }
101
+
102
  return $rec;
103
  }
104
+
105
+
106
  protected function generate_key() {
107
  return $this->mode . '+' . $this->filename;
108
  }
109
+
110
  protected function delete_counter() {
111
  delete_transient( $this->generate_key() );
112
  }
classes/formats/class-woe-formatter-csv.php CHANGED
@@ -14,13 +14,15 @@ class WOE_Formatter_Csv extends WOE_Formatter_sv {
14
  // show linebreaks as literals
15
  $value = str_replace( "\n", '\n', $value );
16
  $value = str_replace( "\r", '\r', $value );
 
17
  return $value;
18
  }
19
 
20
  protected function prepare_array( &$arr ) {
21
- if( $this->settings['delete_linebreaks'] )
22
  $this->delete_linebreaks_from_array( $arr );
 
23
  parent::prepare_array( $arr );
24
  }
25
-
26
  }
14
  // show linebreaks as literals
15
  $value = str_replace( "\n", '\n', $value );
16
  $value = str_replace( "\r", '\r', $value );
17
+
18
  return $value;
19
  }
20
 
21
  protected function prepare_array( &$arr ) {
22
+ if ( $this->settings['delete_linebreaks'] ) {
23
  $this->delete_linebreaks_from_array( $arr );
24
+ }
25
  parent::prepare_array( $arr );
26
  }
27
+
28
  }
classes/formats/class-woe-formatter-json.php CHANGED
@@ -9,9 +9,9 @@ class WOE_Formatter_Json extends WOE_Formatter {
9
  public function start( $data = '' ) {
10
  parent::start( $data );
11
 
12
- $start_text = $this->convert_literals( $this->settings[ 'start_tag' ] );
13
 
14
- fwrite( $this->handle, apply_filters( "woe_json_start_text", $start_text) );
15
  }
16
 
17
  public function output( $rec ) {
@@ -19,8 +19,9 @@ class WOE_Formatter_Json extends WOE_Formatter {
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();
@@ -40,8 +41,9 @@ class WOE_Formatter_Json extends WOE_Formatter {
40
  foreach ( $value as $child_elements ) {
41
  $child = array();
42
  foreach ( $child_elements as $field_child => $value_child ) {
43
- if( isset( $child_labels[ $field_child ] ) )
44
  $child[ $child_labels[ $field_child ] ] = $value_child;
 
45
  }
46
  $rec_out[ $labels[ $field ] ][] = $child;
47
  }
@@ -57,7 +59,7 @@ class WOE_Formatter_Json extends WOE_Formatter {
57
  }
58
 
59
  if ( $this->has_output_filter ) {
60
- $json = apply_filters( "woe_json_output_filter", $json, $rec_out);
61
  }
62
  fwrite( $this->handle, $json );
63
 
@@ -68,11 +70,12 @@ class WOE_Formatter_Json extends WOE_Formatter {
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
  }
78
  }
9
  public function start( $data = '' ) {
10
  parent::start( $data );
11
 
12
+ $start_text = $this->convert_literals( $this->settings['start_tag'] );
13
 
14
+ fwrite( $this->handle, apply_filters( "woe_json_start_text", $start_text ) );
15
  }
16
 
17
  public function output( $rec ) {
19
  if ( $this->prev_added ) {
20
  fwrite( $this->handle, "," );
21
  }
22
+ if ( $this->mode == 'preview' ) {
23
  fwrite( $this->handle, "\n" );
24
+ }
25
 
26
  //rename fields in array
27
  $rec_out = array();
41
  foreach ( $value as $child_elements ) {
42
  $child = array();
43
  foreach ( $child_elements as $field_child => $value_child ) {
44
+ if ( isset( $child_labels[ $field_child ] ) ) {
45
  $child[ $child_labels[ $field_child ] ] = $value_child;
46
+ }
47
  }
48
  $rec_out[ $labels[ $field ] ][] = $child;
49
  }
59
  }
60
 
61
  if ( $this->has_output_filter ) {
62
+ $json = apply_filters( "woe_json_output_filter", $json, $rec_out, $this );
63
  }
64
  fwrite( $this->handle, $json );
65
 
70
  }
71
 
72
  public function finish( $data = '' ) {
73
+ if ( $this->mode == 'preview' ) {
74
  fwrite( $this->handle, "\n" );
75
+ }
76
 
77
+ $end_text = $this->convert_literals( $this->settings['end_tag'] );
78
+ fwrite( $this->handle, apply_filters( "woe_json_end_text", $end_text ) );
79
  parent::finish();
80
  }
81
  }
classes/formats/class-woe-formatter-tsv.php CHANGED
@@ -21,6 +21,7 @@ class WOE_Formatter_Tsv extends WOE_Formatter_sv {
21
  // show linebreaks as literals
22
  $value = str_replace( "\n", '\n', $value );
23
  $value = str_replace( "\r", '\r', $value );
 
24
  return str_replace( $this->delimiter, '', $value );
25
  }
26
 
21
  // show linebreaks as literals
22
  $value = str_replace( "\n", '\n', $value );
23
  $value = str_replace( "\r", '\r', $value );
24
+
25
  return str_replace( $this->delimiter, '', $value );
26
  }
27
 
classes/formats/class-woe-formatter-xls.php CHANGED
@@ -18,10 +18,11 @@ class WOE_Formatter_Xls extends WOE_Formatter {
18
 
19
  if ( $mode != 'preview' ) {
20
  //more memory for XLS?
21
- ini_set('memory_limit', '512M');
22
  //fallback to PCLZip
23
- if( !class_exists('ZipArchive') )
24
- PHPExcel_Settings::setZipClass(PHPExcel_Settings::PCLZIP);
 
25
  fclose( $this->handle );
26
  $this->filename = $filename;
27
  if ( filesize( $this->filename ) > 0 ) {
@@ -31,14 +32,15 @@ class WOE_Formatter_Xls extends WOE_Formatter {
31
  }
32
  $this->objPHPExcel->setActiveSheetIndex( 0 );
33
 
34
- do_action('woe_xls_PHPExcel_setup', $this->objPHPExcel, $settings);
35
 
36
  $this->last_row = $this->objPHPExcel->getActiveSheet()->getHighestRow();
37
 
38
  //fix bug, row=1 if we have 0 records
39
- if( $this->last_row == 1 AND $this->objPHPExcel->getActiveSheet()->getHighestColumn() == "A" )
40
  $this->last_row = 0;
41
-
 
42
  // Excel uses another format!
43
  $this->date_format = apply_filters( 'woe_xls_date_format', $this->convert_php_date_format( $date_format ) );
44
  }
@@ -50,11 +52,12 @@ class WOE_Formatter_Xls extends WOE_Formatter {
50
 
51
  if ( $this->mode == 'preview' ) {
52
  $this->rows[] = $data;
 
53
  return;
54
  }
55
 
56
  if ( $this->settings['display_column_names'] AND $data ) {
57
- $this->last_row++;
58
  foreach ( $data as $pos => $text ) {
59
  $this->objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow( $pos, $this->last_row, $text );
60
  }
@@ -68,19 +71,22 @@ class WOE_Formatter_Xls extends WOE_Formatter {
68
  }
69
 
70
  //rename Sheet1
71
- if( empty($this->settings['sheet_name']) )
72
  $this->settings['sheet_name'] = __( 'Orders', 'woo-order-export-lite' );
 
73
  $sheet_name = WC_Order_Export_Engine::make_filename( $this->settings['sheet_name'] );
74
  $this->objPHPExcel->getActiveSheet()->setTitle( $sheet_name );
75
 
76
  // right-to-left worksheet?
77
- if( $this->settings['direction_rtl'] )
78
- $this->objPHPExcel->getActiveSheet()->setRightToLeft(true);
 
79
 
80
- do_action ( 'woe_xls_print_header', $this->objPHPExcel, $this );
81
 
82
  //save only header or empty file on init
83
- $objWriter = PHPExcel_IOFactory::createWriter($this->objPHPExcel, $this->settings['use_xls_format'] ? 'Excel5' : 'Excel2007');
 
84
  $objWriter->save( $this->filename );
85
  }
86
 
@@ -88,54 +94,61 @@ class WOE_Formatter_Xls extends WOE_Formatter {
88
  $rec = parent::output( $rec );
89
  if ( $this->has_output_filter ) {
90
  $rec = apply_filters( "woe_xls_output_filter", $rec, $this );
91
- if( !$rec )
92
  return;
 
93
  }
94
 
95
  if ( $this->mode == 'preview' ) {
96
- $rec = $this->format_dates( $rec );
97
  $this->rows[] = $rec;
98
  } else {
99
  $this->last_row ++;
100
  $pos = 0;
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 ) );
108
  }
109
- $text = PHPExcel_Shared_Date::PHPToExcel( new DateTime($text) );
110
- $this->objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow( $pos, $this->last_row, $text );
111
- }
112
- $this->objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($pos, $this->last_row)->getNumberFormat()->setFormatCode( $this->date_format );
 
 
113
  } else {
114
  $this->objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow( $pos, $this->last_row, $text );
115
  }
116
- $pos++;
 
117
  }
118
  }
119
  }
120
 
121
  public function finish() {
122
  if ( $this->mode == 'preview' ) {
123
- $max_columns = 0;
124
  fwrite( $this->handle, '<table>' );
125
  if ( count( $this->rows ) < 2 ) {
126
  $this->rows[] = array( __( '<td colspan=10><b>No results</b></td>', 'woo-order-export-lite' ) );
127
  }
128
  foreach ( $this->rows as $num => $rec ) {
129
- $max_columns = max( $max_columns , count($rec) );
130
 
131
  //adds extra space for RTL
132
- if( $this->settings['direction_rtl'] ) {
133
- while( count($rec) < $max_columns )
134
  $rec[] = '';
 
135
  $rec = array_reverse( $rec );
136
  }
137
  if ( $num == 0 AND $this->settings['display_column_names'] ) {
138
- fwrite( $this->handle, '<tr style="font-weight:bold"><td>' . join( '</td><td>', $rec ) . "</td><tr>\n" );
 
139
  } else {
140
  fwrite( $this->handle, '<tr><td>' . join( '</td><td>', $rec ) . "</td><tr>\n" );
141
  }
@@ -144,26 +157,28 @@ class WOE_Formatter_Xls extends WOE_Formatter {
144
  } else {
145
  if ( $this->settings['auto_width'] ) {
146
  try {
147
- $sheet = $this->objPHPExcel->getActiveSheet();
148
  $cellIterator = $sheet->getRowIterator()->current()->getCellIterator();
149
- $cellIterator->setIterateOnlyExistingCells(true);
150
- foreach ($cellIterator as $cell) {
151
- $sheet->getColumnDimension($cell->getColumn())->setAutoSize(true);
152
  }
153
  $sheet->calculateColumnWidths();
154
- } catch (Exception $e) {
155
  //do nothing here , adjustment failed gracefully
156
  }
157
  }
158
- do_action ( 'woe_xls_print_footer', $this->objPHPExcel, $this );
159
- $objWriter = PHPExcel_IOFactory::createWriter($this->objPHPExcel, $this->settings['use_xls_format'] ? 'Excel5' : 'Excel2007');
 
160
  $objWriter->save( $this->filename );
161
  }
162
  }
163
-
164
  //just save Excel file
165
  public function finish_partial() {
166
- $objWriter = PHPExcel_IOFactory::createWriter($this->objPHPExcel, $this->settings['use_xls_format'] ? 'Excel5' : 'Excel2007');
 
167
  $objWriter->save( $this->filename );
168
  }
169
 
@@ -172,33 +187,34 @@ class WOE_Formatter_Xls extends WOE_Formatter {
172
  $this->objPHPExcel->createSheet();
173
  $this->last_row = 0;
174
  }
175
-
176
  public function convert_php_date_format( $date_format ) {
177
  $replacements = array(
178
  //Day
179
- 'd'=>'dd',
180
- 'D'=>'ddd',
181
- 'j'=>'d',
182
- 'l'=>'dddd',
183
  //Month
184
- 'F'=>'mmmm',
185
- 'm'=>'mm',
186
- 'M'=>'mmm',
187
- 'n'=>'m',
188
  //Year
189
- 'Y'=>'yyyy',
190
- 'y'=>'yy',
191
  // Time
192
- 'A'=>'am/pm',
193
- 'a'=>'am/pm',
194
- 'G'=>'hh',
195
- 'g'=>'h',//1-12
196
- 'H'=>'hh',
197
- 'h'=>'h',//1-12
198
- 'i'=>'mm',
199
- 's'=>'ss',
200
  );
201
- return strtr($date_format, $replacements);
 
202
  }
203
 
204
  }
18
 
19
  if ( $mode != 'preview' ) {
20
  //more memory for XLS?
21
+ ini_set( 'memory_limit', '512M' );
22
  //fallback to PCLZip
23
+ if ( ! class_exists( 'ZipArchive' ) ) {
24
+ PHPExcel_Settings::setZipClass( PHPExcel_Settings::PCLZIP );
25
+ }
26
  fclose( $this->handle );
27
  $this->filename = $filename;
28
  if ( filesize( $this->filename ) > 0 ) {
32
  }
33
  $this->objPHPExcel->setActiveSheetIndex( 0 );
34
 
35
+ do_action( 'woe_xls_PHPExcel_setup', $this->objPHPExcel, $settings );
36
 
37
  $this->last_row = $this->objPHPExcel->getActiveSheet()->getHighestRow();
38
 
39
  //fix bug, row=1 if we have 0 records
40
+ if ( $this->last_row == 1 AND $this->objPHPExcel->getActiveSheet()->getHighestColumn() == "A" ) {
41
  $this->last_row = 0;
42
+ }
43
+
44
  // Excel uses another format!
45
  $this->date_format = apply_filters( 'woe_xls_date_format', $this->convert_php_date_format( $date_format ) );
46
  }
52
 
53
  if ( $this->mode == 'preview' ) {
54
  $this->rows[] = $data;
55
+
56
  return;
57
  }
58
 
59
  if ( $this->settings['display_column_names'] AND $data ) {
60
+ $this->last_row ++;
61
  foreach ( $data as $pos => $text ) {
62
  $this->objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow( $pos, $this->last_row, $text );
63
  }
71
  }
72
 
73
  //rename Sheet1
74
+ if ( empty( $this->settings['sheet_name'] ) ) {
75
  $this->settings['sheet_name'] = __( 'Orders', 'woo-order-export-lite' );
76
+ }
77
  $sheet_name = WC_Order_Export_Engine::make_filename( $this->settings['sheet_name'] );
78
  $this->objPHPExcel->getActiveSheet()->setTitle( $sheet_name );
79
 
80
  // right-to-left worksheet?
81
+ if ( $this->settings['direction_rtl'] ) {
82
+ $this->objPHPExcel->getActiveSheet()->setRightToLeft( true );
83
+ }
84
 
85
+ do_action( 'woe_xls_print_header', $this->objPHPExcel, $this );
86
 
87
  //save only header or empty file on init
88
+ $objWriter = PHPExcel_IOFactory::createWriter( $this->objPHPExcel,
89
+ $this->settings['use_xls_format'] ? 'Excel5' : 'Excel2007' );
90
  $objWriter->save( $this->filename );
91
  }
92
 
94
  $rec = parent::output( $rec );
95
  if ( $this->has_output_filter ) {
96
  $rec = apply_filters( "woe_xls_output_filter", $rec, $this );
97
+ if ( ! $rec ) {
98
  return;
99
+ }
100
  }
101
 
102
  if ( $this->mode == 'preview' ) {
103
+ $rec = $this->format_dates( $rec );
104
  $this->rows[] = $rec;
105
  } else {
106
  $this->last_row ++;
107
  $pos = 0;
108
  foreach ( $rec as $field => $text ) {
109
+ if ( $this->string_format_force OR in_array( $field, $this->string_format_fields ) ) {
110
+ $this->objPHPExcel->getActiveSheet()->setCellValueExplicitByColumnAndRow( $pos, $this->last_row,
111
+ $text );
112
+ } elseif ( in_array( $field, $this->date_format_fields ) ) {// DATE!
113
+ if ( $text ) {
114
+ if ( empty( $this->settings['global_job_settings']['time_format'] ) ) { // must remove time!
115
  $text = date( "Y-m-d", strtotime( $text ) );
116
  }
117
+ $text = PHPExcel_Shared_Date::PHPToExcel( new DateTime( $text ) );
118
+ $this->objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow( $pos, $this->last_row,
119
+ $text );
120
+ }
121
+ $this->objPHPExcel->getActiveSheet()->getStyleByColumnAndRow( $pos,
122
+ $this->last_row )->getNumberFormat()->setFormatCode( $this->date_format );
123
  } else {
124
  $this->objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow( $pos, $this->last_row, $text );
125
  }
126
+ do_action( "woe_xls_format_cell", $this, $field, $text, $rec, $pos );
127
+ $pos ++;
128
  }
129
  }
130
  }
131
 
132
  public function finish() {
133
  if ( $this->mode == 'preview' ) {
134
+ $max_columns = 0;
135
  fwrite( $this->handle, '<table>' );
136
  if ( count( $this->rows ) < 2 ) {
137
  $this->rows[] = array( __( '<td colspan=10><b>No results</b></td>', 'woo-order-export-lite' ) );
138
  }
139
  foreach ( $this->rows as $num => $rec ) {
140
+ $max_columns = max( $max_columns, count( $rec ) );
141
 
142
  //adds extra space for RTL
143
+ if ( $this->settings['direction_rtl'] ) {
144
+ while ( count( $rec ) < $max_columns ) {
145
  $rec[] = '';
146
+ }
147
  $rec = array_reverse( $rec );
148
  }
149
  if ( $num == 0 AND $this->settings['display_column_names'] ) {
150
+ fwrite( $this->handle,
151
+ '<tr style="font-weight:bold"><td>' . join( '</td><td>', $rec ) . "</td><tr>\n" );
152
  } else {
153
  fwrite( $this->handle, '<tr><td>' . join( '</td><td>', $rec ) . "</td><tr>\n" );
154
  }
157
  } else {
158
  if ( $this->settings['auto_width'] ) {
159
  try {
160
+ $sheet = $this->objPHPExcel->getActiveSheet();
161
  $cellIterator = $sheet->getRowIterator()->current()->getCellIterator();
162
+ $cellIterator->setIterateOnlyExistingCells( true );
163
+ foreach ( $cellIterator as $cell ) {
164
+ $sheet->getColumnDimension( $cell->getColumn() )->setAutoSize( true );
165
  }
166
  $sheet->calculateColumnWidths();
167
+ } catch ( Exception $e ) {
168
  //do nothing here , adjustment failed gracefully
169
  }
170
  }
171
+ do_action( 'woe_xls_print_footer', $this->objPHPExcel, $this );
172
+ $objWriter = PHPExcel_IOFactory::createWriter( $this->objPHPExcel,
173
+ $this->settings['use_xls_format'] ? 'Excel5' : 'Excel2007' );
174
  $objWriter->save( $this->filename );
175
  }
176
  }
177
+
178
  //just save Excel file
179
  public function finish_partial() {
180
+ $objWriter = PHPExcel_IOFactory::createWriter( $this->objPHPExcel,
181
+ $this->settings['use_xls_format'] ? 'Excel5' : 'Excel2007' );
182
  $objWriter->save( $this->filename );
183
  }
184
 
187
  $this->objPHPExcel->createSheet();
188
  $this->last_row = 0;
189
  }
190
+
191
  public function convert_php_date_format( $date_format ) {
192
  $replacements = array(
193
  //Day
194
+ 'd' => 'dd',
195
+ 'D' => 'ddd',
196
+ 'j' => 'd',
197
+ 'l' => 'dddd',
198
  //Month
199
+ 'F' => 'mmmm',
200
+ 'm' => 'mm',
201
+ 'M' => 'mmm',
202
+ 'n' => 'm',
203
  //Year
204
+ 'Y' => 'yyyy',
205
+ 'y' => 'yy',
206
  // Time
207
+ 'A' => 'am/pm',
208
+ 'a' => 'am/pm',
209
+ 'G' => 'hh',
210
+ 'g' => 'h',//1-12
211
+ 'H' => 'hh',
212
+ 'h' => 'h',//1-12
213
+ 'i' => 'mm',
214
+ 's' => 'ss',
215
  );
216
+
217
+ return strtr( $date_format, $replacements );
218
  }
219
 
220
  }
classes/formats/class-woe-formatter-xml.php CHANGED
@@ -7,25 +7,28 @@ class WOE_Formatter_Xml extends WOE_Formatter {
7
 
8
  public function __construct( $mode, $filename, $settings, $format, $labels, $field_formats, $date_format ) {
9
  parent::__construct( $mode, $filename, $settings, $format, $labels, $field_formats, $date_format );
10
-
11
- $this->linebreak = apply_filters( "woe_xml_output_linebreak", "\n");
12
  }
13
-
14
  public function start( $data = '' ) {
15
  parent::start( $data );
16
-
17
- fwrite( $this->handle, apply_filters( "woe_xml_output_header", '<?xml version="1.0" encoding="UTF-8"?>') . $this->linebreak );
18
-
19
- if(@$this->settings['prepend_raw_xml'])
 
20
  fwrite( $this->handle, $this->settings['prepend_raw_xml'] . $this->linebreak );
21
-
22
- fwrite( $this->handle, apply_filters( "woe_xml_output_before_root_tag", ''));
23
-
24
- if($this->settings['root_tag'])
 
25
  fwrite( $this->handle, "<" . $this->settings['root_tag'] . ">" . $this->linebreak );
26
-
27
- fwrite( $this->handle, apply_filters( "woe_xml_output_after_root_tag", ''));
28
-
 
29
  }
30
 
31
  public function output( $rec ) {
@@ -33,9 +36,9 @@ class WOE_Formatter_Xml extends WOE_Formatter {
33
  $xml = new SimpleXMLElement( "<" . $this->settings['order_tag'] . "></" . $this->settings['order_tag'] . ">" );
34
 
35
  $labels = $this->labels['order'];
36
- $rec = apply_filters('woe_xml_prepare_record', $rec);
37
  foreach ( $rec as $field => $value ) {
38
- $value = apply_filters('woe_xml_prepare_field_'.$field, $value, $rec);
39
  if ( is_array( $value ) ) {
40
  $childs = $xml->addChild( $labels[ $field ] ); // add Products
41
  if ( $field == "products" ) {
@@ -46,53 +49,59 @@ class WOE_Formatter_Xml extends WOE_Formatter {
46
  $child_labels = $this->labels['coupons'];
47
  } else {
48
  // array was created by hook!
49
- $child_tag = '';
50
- $child_labels = array() ;
51
  }
52
  // modify children using filters
53
- $child_tag = apply_filters('woe_xml_child_tagname_'.$field, $child_tag, $value, $rec );
54
- $child_labels = apply_filters('woe_xml_child_labels_'.$field, $child_labels, $value, $rec );
55
-
56
- foreach ( $value as $child_key=>$child_elements ) {
57
  $tag_name = $child_tag ? $child_tag : $child_key;
58
  // add nested Product if array!
59
- $child = $childs->addChild( $tag_name, is_array($child_elements) ? NULL : $this->prepare_string($child_elements) );
 
60
  // products/coupons
61
- if( is_array($child_elements) ) {
62
  foreach ( $child_elements as $field_child => $value_child ) {
63
- if( isset( $child_labels[ $field_child ] ) )
64
- $child->addChild( $child_labels[ $field_child ], $this->prepare_string($value_child) );
 
 
65
  }
66
- }
67
  }
68
  } else {
69
- $xml->addChild( $labels[ $field ] , $this->prepare_string($value) );
70
  }
71
  }
72
 
73
  //format it!
74
  $dom = dom_import_simplexml( $xml );
75
  $dom->ownerDocument->formatOutput = ( $this->mode == 'preview' );
76
- $output_flags = !empty($this->settings['self_closing_tags']) ? NULL : LIBXML_NOEMPTYTAG;
77
- $xml = $dom->ownerDocument->saveXML( $dom->ownerDocument->documentElement, $output_flags );
 
78
 
79
  if ( $this->has_output_filter ) {
80
- $xml = apply_filters( "woe_xml_output_filter", $xml, $rec );
81
  }
82
 
83
  fwrite( $this->handle, $xml . $this->linebreak );
84
  }
85
 
86
  public function finish( $data = '' ) {
87
- if($this->settings['root_tag'])
88
  fwrite( $this->handle, "</" . $this->settings['root_tag'] . ">" . $this->linebreak );
89
- if(@$this->settings['append_raw_xml'])
 
90
  fwrite( $this->handle, $this->settings['append_raw_xml'] . $this->linebreak );
91
- do_action( "woe_xml_print_footer", $this->handle, $this);
 
92
  parent::finish();
93
  }
94
-
95
- private function prepare_string($value) {
96
- return htmlspecialchars($value);
97
- }
98
  }
7
 
8
  public function __construct( $mode, $filename, $settings, $format, $labels, $field_formats, $date_format ) {
9
  parent::__construct( $mode, $filename, $settings, $format, $labels, $field_formats, $date_format );
10
+
11
+ $this->linebreak = apply_filters( "woe_xml_output_linebreak", "\n" );
12
  }
13
+
14
  public function start( $data = '' ) {
15
  parent::start( $data );
16
+
17
+ fwrite( $this->handle,
18
+ apply_filters( "woe_xml_output_header", '<?xml version="1.0" encoding="UTF-8"?>' ) . $this->linebreak );
19
+
20
+ if ( @$this->settings['prepend_raw_xml'] ) {
21
  fwrite( $this->handle, $this->settings['prepend_raw_xml'] . $this->linebreak );
22
+ }
23
+
24
+ fwrite( $this->handle, apply_filters( "woe_xml_output_before_root_tag", '' ) );
25
+
26
+ if ( $this->settings['root_tag'] ) {
27
  fwrite( $this->handle, "<" . $this->settings['root_tag'] . ">" . $this->linebreak );
28
+ }
29
+
30
+ fwrite( $this->handle, apply_filters( "woe_xml_output_after_root_tag", '' ) );
31
+
32
  }
33
 
34
  public function output( $rec ) {
36
  $xml = new SimpleXMLElement( "<" . $this->settings['order_tag'] . "></" . $this->settings['order_tag'] . ">" );
37
 
38
  $labels = $this->labels['order'];
39
+ $rec = apply_filters( 'woe_xml_prepare_record', $rec );
40
  foreach ( $rec as $field => $value ) {
41
+ $value = apply_filters( 'woe_xml_prepare_field_' . $field, $value, $rec );
42
  if ( is_array( $value ) ) {
43
  $childs = $xml->addChild( $labels[ $field ] ); // add Products
44
  if ( $field == "products" ) {
49
  $child_labels = $this->labels['coupons'];
50
  } else {
51
  // array was created by hook!
52
+ $child_tag = '';
53
+ $child_labels = array();
54
  }
55
  // modify children using filters
56
+ $child_tag = apply_filters( 'woe_xml_child_tagname_' . $field, $child_tag, $value, $rec );
57
+ $child_labels = apply_filters( 'woe_xml_child_labels_' . $field, $child_labels, $value, $rec );
58
+
59
+ foreach ( $value as $child_key => $child_elements ) {
60
  $tag_name = $child_tag ? $child_tag : $child_key;
61
  // add nested Product if array!
62
+ $child = $childs->addChild( $tag_name,
63
+ is_array( $child_elements ) ? null : $this->prepare_string( $child_elements ) );
64
  // products/coupons
65
+ if ( is_array( $child_elements ) ) {
66
  foreach ( $child_elements as $field_child => $value_child ) {
67
+ if ( isset( $child_labels[ $field_child ] ) ) {
68
+ $child->addChild( $child_labels[ $field_child ],
69
+ $this->prepare_string( $value_child ) );
70
+ }
71
  }
72
+ }
73
  }
74
  } else {
75
+ $xml->addChild( $labels[ $field ], $this->prepare_string( $value ) );
76
  }
77
  }
78
 
79
  //format it!
80
  $dom = dom_import_simplexml( $xml );
81
  $dom->ownerDocument->formatOutput = ( $this->mode == 'preview' );
82
+ $output_flags = ! empty( $this->settings['self_closing_tags'] ) ? null : LIBXML_NOEMPTYTAG;
83
+ $xml = $dom->ownerDocument->saveXML( $dom->ownerDocument->documentElement,
84
+ $output_flags );
85
 
86
  if ( $this->has_output_filter ) {
87
+ $xml = apply_filters( "woe_xml_output_filter", $xml, $rec, $this );
88
  }
89
 
90
  fwrite( $this->handle, $xml . $this->linebreak );
91
  }
92
 
93
  public function finish( $data = '' ) {
94
+ if ( $this->settings['root_tag'] ) {
95
  fwrite( $this->handle, "</" . $this->settings['root_tag'] . ">" . $this->linebreak );
96
+ }
97
+ if ( @$this->settings['append_raw_xml'] ) {
98
  fwrite( $this->handle, $this->settings['append_raw_xml'] . $this->linebreak );
99
+ }
100
+ do_action( "woe_xml_print_footer", $this->handle, $this );
101
  parent::finish();
102
  }
103
+
104
+ private function prepare_string( $value ) {
105
+ return htmlspecialchars( $value );
106
+ }
107
  }
i18n/languages/woo-order-export-lite.pot CHANGED
@@ -3,7 +3,7 @@ msgid ""
3
  msgstr ""
4
  "Project-Id-Version: PACKAGE VERSION\n"
5
  "Report-Msgid-Bugs-To: \n"
6
- "POT-Creation-Date: 2018-06-08 11:21+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"
@@ -25,22 +25,22 @@ msgid "Filter orders by"
25
  msgstr ""
26
 
27
  #: view/settings-form.php:59 view/settings-form.php:228
28
- #: classes/core/class-wc-order-export-data-extractor-ui.php:404
29
  msgid "Order Date"
30
  msgstr ""
31
 
32
  #: view/settings-form.php:64 view/settings-form.php:229
33
- #: classes/core/class-wc-order-export-data-extractor-ui.php:405
34
  msgid "Modification Date"
35
  msgstr ""
36
 
37
  #: view/settings-form.php:69
38
- #: classes/core/class-wc-order-export-data-extractor-ui.php:408
39
  msgid "Paid Date"
40
  msgstr ""
41
 
42
  #: view/settings-form.php:74
43
- #: classes/core/class-wc-order-export-data-extractor-ui.php:407
44
  msgid "Completed Date"
45
  msgstr ""
46
 
@@ -203,7 +203,7 @@ msgid "Time"
203
  msgstr ""
204
 
205
  #: view/settings-form.php:227
206
- #: classes/core/class-wc-order-export-data-extractor-ui.php:401
207
  msgid "Order ID"
208
  msgstr ""
209
 
@@ -260,213 +260,219 @@ msgstr ""
260
  msgid "Custom PHP code to modify output"
261
  msgstr ""
262
 
263
- #: view/settings-form.php:297
 
 
 
 
 
 
264
  msgid "Use only unnamed functions!"
265
  msgstr ""
266
 
267
- #: view/settings-form.php:310
268
  msgid "Filter by order"
269
  msgstr ""
270
 
271
- #: view/settings-form.php:313
272
  msgid "Don't export child orders"
273
  msgstr ""
274
 
275
- #: view/settings-form.php:314
276
  msgid "Export refunds"
277
  msgstr ""
278
 
279
- #: view/settings-form.php:315
280
  msgid "Mark exported orders"
281
  msgstr ""
282
 
283
- #: view/settings-form.php:316
284
  msgid "Export unmarked orders only"
285
  msgstr ""
286
 
287
- #: view/settings-form.php:317
288
  msgid "Order statuses"
289
  msgstr ""
290
 
291
- #: view/settings-form.php:324
292
  msgid "Custom fields"
293
  msgstr ""
294
 
295
- #: view/settings-form.php:363
296
  msgid ""
297
  "The filters won't work correctly.<br>Another plugin(or theme) has loaded "
298
  "outdated Select2.js"
299
  msgstr ""
300
 
301
- #: view/settings-form.php:364
302
  msgid "Filter by product"
303
  msgstr ""
304
 
305
- #: view/settings-form.php:367
306
- msgid "Export all products from a order"
307
  msgstr ""
308
 
309
- #: view/settings-form.php:368
310
  msgid "Skip fully refunded items"
311
  msgstr ""
312
 
313
- #: view/settings-form.php:369
314
  msgid "Product categories"
315
  msgstr ""
316
 
317
- #: view/settings-form.php:379
318
  msgid "Vendor/creator"
319
  msgstr ""
320
 
321
- #: view/settings-form.php:392
322
  msgid "Product"
323
  msgstr ""
324
 
325
- #: view/settings-form.php:404
326
  msgid "Product taxonomies"
327
  msgstr ""
328
 
329
- #: view/settings-form.php:430
330
  msgid "Product custom fields"
331
  msgstr ""
332
 
333
- #: view/settings-form.php:461
334
  msgid "Variable product attributes"
335
  msgstr ""
336
 
337
- #: view/settings-form.php:488
338
  msgid "Item meta data"
339
  msgstr ""
340
 
341
- #: view/settings-form.php:525
342
  msgid "Filter by customers"
343
  msgstr ""
344
 
345
- #: view/settings-form.php:528
346
- msgid "User roles"
347
  msgstr ""
348
 
349
- #: view/settings-form.php:537
350
- msgid "Usernames"
351
  msgstr ""
352
 
353
- #: view/settings-form.php:553
354
  msgid "Filter by coupons"
355
  msgstr ""
356
 
357
- #: view/settings-form.php:558
358
  msgid "Any coupon used"
359
  msgstr ""
360
 
361
- #: view/settings-form.php:560
362
- #: classes/core/class-wc-order-export-data-extractor-ui.php:476
363
- #: classes/core/class-wc-order-export-data-extractor-ui.php:538
364
  msgid "Coupons"
365
  msgstr ""
366
 
367
- #: view/settings-form.php:575
368
  msgid "Filter by billing"
369
  msgstr ""
370
 
371
- #: view/settings-form.php:578
372
  msgid "Billing locations"
373
  msgstr ""
374
 
375
- #: view/settings-form.php:602
376
  msgid "Payment methods"
377
  msgstr ""
378
 
379
- #: view/settings-form.php:614
380
  msgid "Filter by shipping"
381
  msgstr ""
382
 
383
- #: view/settings-form.php:617
384
  msgid "Shipping locations"
385
  msgstr ""
386
 
387
- #: view/settings-form.php:641
388
  msgid "Shipping methods"
389
  msgstr ""
390
 
391
- #: view/settings-form.php:653
392
  msgid "Filter by item and metadata"
393
  msgstr ""
394
 
395
- #: view/settings-form.php:656
396
  msgid "Item names"
397
  msgstr ""
398
 
399
- #: view/settings-form.php:680
400
  msgid "Item metadata"
401
  msgstr ""
402
 
403
- #: view/settings-form.php:714 classes/class-wc-order-export-admin.php:525
404
  msgid "Set up fields to export"
405
  msgstr ""
406
 
407
- #: view/settings-form.php:720 view/modal-controls.php:36
408
  msgid "Meta key"
409
  msgstr ""
410
 
411
- #: view/settings-form.php:728 view/settings-form.php:740
412
  #: view/modal-controls.php:20 view/modal-controls.php:26
413
  #: view/modal-controls.php:43 view/modal-controls.php:49
414
  msgid "Column name"
415
  msgstr ""
416
 
417
- #: view/settings-form.php:731
418
  msgid "or type meta key here"
419
  msgstr ""
420
 
421
- #: view/settings-form.php:732 view/settings-form.php:760
422
  #: view/modal-controls.php:4 view/modal-controls.php:39
423
  msgid "Hide unused fields"
424
  msgstr ""
425
 
426
- #: view/settings-form.php:735 view/settings-form.php:743
427
  msgid "Confirm"
428
  msgstr ""
429
 
430
- #: view/settings-form.php:736 view/settings-form.php:744
431
  msgid "Cancel"
432
  msgstr ""
433
 
434
- #: view/settings-form.php:741 view/modal-controls.php:27
435
  #: view/modal-controls.php:50
436
  msgid "Value"
437
  msgstr ""
438
 
439
- #: view/settings-form.php:747
440
  msgid "Use sections"
441
  msgstr ""
442
 
443
- #: view/settings-form.php:754
444
  msgid "Actions"
445
  msgstr ""
446
 
447
- #: view/settings-form.php:755 view/modal-controls.php:22
448
  #: view/modal-controls.php:45
449
  msgid "Add field"
450
  msgstr ""
451
 
452
- #: view/settings-form.php:757 view/modal-controls.php:29
453
  #: view/modal-controls.php:52
454
  msgid "Add static field"
455
  msgstr ""
456
 
457
- #: view/settings-form.php:761
458
  msgid "Show unused fields"
459
  msgstr ""
460
 
461
- #: view/settings-form.php:769
462
  msgid "Select all"
463
  msgstr ""
464
 
465
- #: view/settings-form.php:772
466
  msgid "Drag rows to reorder exported fields"
467
  msgstr ""
468
 
469
- #: view/settings-form.php:783
470
  #, php-format
471
  msgid ""
472
  "If you see this message after page load, user interface won't work correctly!"
@@ -474,48 +480,48 @@ msgid ""
474
  "it). Probably, it's a conflict with another plugin or active theme."
475
  msgstr ""
476
 
477
- #: view/settings-form.php:785
478
  msgid "Preview"
479
  msgstr ""
480
 
481
- #: view/settings-form.php:785
482
  msgid "Might be different from actual export!"
483
  msgstr ""
484
 
485
- #: view/settings-form.php:786
486
  msgid "Save settings"
487
  msgstr ""
488
 
489
- #: view/settings-form.php:788
490
  msgid "Export"
491
  msgstr ""
492
 
493
- #: view/settings-form.php:791
494
  msgid "Export [w/o progressbar]"
495
  msgstr ""
496
 
497
- #: view/settings-form.php:791
498
  msgid "It might not work for huge datasets!"
499
  msgstr ""
500
 
501
- #: view/settings-form.php:794
502
  msgid "Save as a profile"
503
  msgstr ""
504
 
505
- #: view/settings-form.php:797
506
  #, php-format
507
  msgid "Export total: %s orders"
508
  msgstr ""
509
 
510
- #: view/settings-form.php:798
511
  msgid "Preview size"
512
  msgstr ""
513
 
514
- #: view/settings-form.php:806
515
  msgid "Press 'Esc' to cancel the export"
516
  msgstr ""
517
 
518
- #: view/settings-form.php:807
519
  msgid "Click here to download"
520
  msgstr ""
521
 
@@ -567,114 +573,115 @@ msgstr ""
567
  msgid "All meta"
568
  msgstr ""
569
 
570
- #: classes/class-wc-order-export-admin.php:87
571
  msgid "Export Status"
572
  msgstr ""
573
 
574
- #: classes/class-wc-order-export-admin.php:127
575
  msgid ""
576
  "Advanced Order Export For WooCommerce is available <a href=\"admin.php?"
577
  "page=wc-order-export\">on this page</a>."
578
  msgstr ""
579
 
580
- #: classes/class-wc-order-export-admin.php:135
581
  msgid "Settings"
582
  msgstr ""
583
 
584
- #: classes/class-wc-order-export-admin.php:136
585
  msgid "Docs"
586
  msgstr ""
587
 
588
- #: classes/class-wc-order-export-admin.php:137
589
  msgid "Support"
590
  msgstr ""
591
 
592
- #: classes/class-wc-order-export-admin.php:206
593
- #: classes/class-wc-order-export-admin.php:208
594
- #: classes/class-wc-order-export-admin.php:208
 
595
  msgid "Export Orders"
596
  msgstr ""
597
 
598
- #: classes/class-wc-order-export-admin.php:498
599
  msgid "Copied from \"Export now\""
600
  msgstr ""
601
 
602
- #: classes/class-wc-order-export-admin.php:526
603
  #, php-format
604
  msgid "Add %s as %s columns %s as rows"
605
  msgstr ""
606
 
607
- #: classes/class-wc-order-export-admin.php:567
608
  msgid "empty column name"
609
  msgstr ""
610
 
611
- #: classes/class-wc-order-export-admin.php:568
612
  msgid "empty meta key"
613
  msgstr ""
614
 
615
- #: classes/class-wc-order-export-admin.php:569
616
  msgid "select product field or item field or taxonomy"
617
  msgstr ""
618
 
619
- #: classes/class-wc-order-export-admin.php:570
620
  msgid "empty value"
621
  msgstr ""
622
 
623
- #: classes/class-wc-order-export-admin.php:571
624
  msgid "title is empty"
625
  msgstr ""
626
 
627
- #: classes/class-wc-order-export-admin.php:572
628
  msgid "Date From is greater than Date To"
629
  msgstr ""
630
 
631
- #: classes/class-wc-order-export-admin.php:573
632
  msgid "Please, set up fields to export"
633
  msgstr ""
634
 
635
- #: classes/class-wc-order-export-admin.php:574
636
- #: classes/admin/class-wc-order-export-ajax.php:335
637
- #: classes/core/class-wc-order-export-engine.php:692
638
- #: classes/core/class-wc-order-export-engine.php:702
639
  msgid "Nothing to export. Please, adjust your filters"
640
  msgstr ""
641
 
642
- #: classes/class-wc-order-export-admin.php:575
643
- #: classes/core/class-wc-order-export-data-extractor.php:195
644
  msgid "empty"
645
  msgstr ""
646
 
647
- #: classes/class-wc-order-export-admin.php:667
648
  #, php-format
649
  msgid "Status change job #%s for order #%s. Result: %s"
650
  msgstr ""
651
 
652
- #: classes/class-wc-order-export-admin.php:727
653
  #, php-format
654
  msgid "Export as %s"
655
  msgstr ""
656
 
657
- #: classes/class-wc-order-export-admin.php:732
658
  msgid "Mark exported"
659
  msgstr ""
660
 
661
- #: classes/class-wc-order-export-admin.php:733
662
  msgid "Unmark exported"
663
  msgstr ""
664
 
665
- #: classes/class-wc-order-export-admin.php:739
666
  #, php-format
667
  msgid "Export as profile '%s'"
668
  msgstr ""
669
 
670
- #: classes/class-wc-order-export-admin.php:805
671
  #, php-format
672
  msgid "%s order marked."
673
  msgid_plural "%s orders marked."
674
  msgstr[0] ""
675
  msgstr[1] ""
676
 
677
- #: classes/class-wc-order-export-admin.php:814
678
  #, php-format
679
  msgid "%s order unmarked."
680
  msgid_plural "%s orders unmarked."
@@ -776,8 +783,8 @@ msgstr ""
776
  msgid "Buy %s to get access to Scheduled jobs"
777
  msgstr ""
778
 
779
- #: classes/formats/abstract-class-woe-formatter-sv.php:86
780
- #: classes/formats/class-woe-formatter-xls.php:126
781
  msgid "<td colspan=10><b>No results</b></td>"
782
  msgstr ""
783
 
@@ -785,8 +792,8 @@ msgstr ""
785
  msgid "can not open for output"
786
  msgstr ""
787
 
788
- #: classes/formats/class-woe-formatter-xls.php:72
789
- #: classes/admin/class-wc-order-export-manage.php:204
790
  msgid "Orders"
791
  msgstr ""
792
 
@@ -822,534 +829,554 @@ msgstr ""
822
  msgid "Wrong key for cron url!"
823
  msgstr ""
824
 
825
- #: classes/admin/class-wc-order-export-ajax.php:232
826
  msgid "Can't create temporary file"
827
  msgstr ""
828
 
829
- #: classes/admin/class-wc-order-export-ajax.php:254
830
  msgid "Can't find exported file"
831
  msgstr ""
832
 
833
- #: classes/core/class-wc-order-export-data-extractor-ui.php:313
834
  msgid "Item ID"
835
  msgstr ""
836
 
837
- #: classes/core/class-wc-order-export-data-extractor-ui.php:314
838
  msgid "Item #"
839
  msgstr ""
840
 
841
- #: classes/core/class-wc-order-export-data-extractor-ui.php:315
842
  msgid "SKU"
843
  msgstr ""
844
 
845
- #: classes/core/class-wc-order-export-data-extractor-ui.php:316
846
  msgid "Item Name"
847
  msgstr ""
848
 
849
- #: classes/core/class-wc-order-export-data-extractor-ui.php:317
 
 
 
 
850
  msgid "Product Name"
851
  msgstr ""
852
 
853
- #: classes/core/class-wc-order-export-data-extractor-ui.php:318
 
 
 
 
854
  msgid "Product Variation"
855
  msgstr ""
856
 
857
- #: classes/core/class-wc-order-export-data-extractor-ui.php:319
858
  msgid "Item Seller"
859
  msgstr ""
860
 
861
- #: classes/core/class-wc-order-export-data-extractor-ui.php:320
862
  msgid "Quantity"
863
  msgstr ""
864
 
865
- #: classes/core/class-wc-order-export-data-extractor-ui.php:321
866
  msgid "Quantity (- Refund)"
867
  msgstr ""
868
 
869
- #: classes/core/class-wc-order-export-data-extractor-ui.php:322
870
  msgid "Item Cost"
871
  msgstr ""
872
 
873
- #: classes/core/class-wc-order-export-data-extractor-ui.php:323
874
  msgid "Product Current Price"
875
  msgstr ""
876
 
877
- #: classes/core/class-wc-order-export-data-extractor-ui.php:324
878
  msgid "Order Line (w/o tax)"
879
  msgstr ""
880
 
881
- #: classes/core/class-wc-order-export-data-extractor-ui.php:325
882
  msgid "Order Line Tax"
883
  msgstr ""
884
 
885
- #: classes/core/class-wc-order-export-data-extractor-ui.php:326
886
  msgid "Order Line Tax Refunded"
887
  msgstr ""
888
 
889
- #: classes/core/class-wc-order-export-data-extractor-ui.php:327
890
  msgid "Order Line Tax (- Refund)"
891
  msgstr ""
892
 
893
- #: classes/core/class-wc-order-export-data-extractor-ui.php:328
894
  msgid "Order Line Subtotal"
895
  msgstr ""
896
 
897
- #: classes/core/class-wc-order-export-data-extractor-ui.php:329
 
 
 
 
898
  msgid "Order Line Total"
899
  msgstr ""
900
 
901
- #: classes/core/class-wc-order-export-data-extractor-ui.php:330
902
  msgid "Order Line Total (include tax)"
903
  msgstr ""
904
 
905
- #: classes/core/class-wc-order-export-data-extractor-ui.php:331
906
  msgid "Order Line Total Refunded"
907
  msgstr ""
908
 
909
- #: classes/core/class-wc-order-export-data-extractor-ui.php:332
910
  msgid "Order Line Total (- Refund)"
911
  msgstr ""
912
 
913
- #: classes/core/class-wc-order-export-data-extractor-ui.php:333
914
  msgid "Item Discount Amount"
915
  msgstr ""
916
 
917
- #: classes/core/class-wc-order-export-data-extractor-ui.php:334
918
  msgid "Item Tax Rate"
919
  msgstr ""
920
 
921
- #: classes/core/class-wc-order-export-data-extractor-ui.php:335
922
  msgid "Type"
923
  msgstr ""
924
 
925
- #: classes/core/class-wc-order-export-data-extractor-ui.php:336
926
  msgid "Category"
927
  msgstr ""
928
 
929
- #: classes/core/class-wc-order-export-data-extractor-ui.php:337
930
  msgid "Tags"
931
  msgstr ""
932
 
933
- #: classes/core/class-wc-order-export-data-extractor-ui.php:338
934
  msgid "Width"
935
  msgstr ""
936
 
937
- #: classes/core/class-wc-order-export-data-extractor-ui.php:339
938
  msgid "Length"
939
  msgstr ""
940
 
941
- #: classes/core/class-wc-order-export-data-extractor-ui.php:340
942
  msgid "Height"
943
  msgstr ""
944
 
945
- #: classes/core/class-wc-order-export-data-extractor-ui.php:341
946
  msgid "Weight"
947
  msgstr ""
948
 
949
- #: classes/core/class-wc-order-export-data-extractor-ui.php:342
950
  msgid "Product URL"
951
  msgstr ""
952
 
953
- #: classes/core/class-wc-order-export-data-extractor-ui.php:343
954
  msgid "Download URL"
955
  msgstr ""
956
 
957
- #: classes/core/class-wc-order-export-data-extractor-ui.php:344
958
  msgid "Image URL"
959
  msgstr ""
960
 
961
- #: classes/core/class-wc-order-export-data-extractor-ui.php:345
962
  msgid "Product Shipping Class"
963
  msgstr ""
964
 
965
- #: classes/core/class-wc-order-export-data-extractor-ui.php:346
966
  msgid "Description"
967
  msgstr ""
968
 
969
- #: classes/core/class-wc-order-export-data-extractor-ui.php:347
970
  msgid "Short Description"
971
  msgstr ""
972
 
973
- #: classes/core/class-wc-order-export-data-extractor-ui.php:348
974
  msgid "Full names for categories"
975
  msgstr ""
976
 
977
- #: classes/core/class-wc-order-export-data-extractor-ui.php:361
978
  msgid "Coupon Code"
979
  msgstr ""
980
 
981
- #: classes/core/class-wc-order-export-data-extractor-ui.php:362
982
  msgid "Discount Amount"
983
  msgstr ""
984
 
985
- #: classes/core/class-wc-order-export-data-extractor-ui.php:363
986
  msgid "Discount Amount Tax"
987
  msgstr ""
988
 
989
- #: classes/core/class-wc-order-export-data-extractor-ui.php:364
990
  msgid "Discount Amount + Tax"
991
  msgstr ""
992
 
993
- #: classes/core/class-wc-order-export-data-extractor-ui.php:365
994
  msgid "Coupon Description"
995
  msgstr ""
996
 
997
- #: classes/core/class-wc-order-export-data-extractor-ui.php:366
998
  msgid "Coupon Type"
999
  msgstr ""
1000
 
1001
- #: classes/core/class-wc-order-export-data-extractor-ui.php:367
1002
  msgid "Coupon Amount"
1003
  msgstr ""
1004
 
1005
- #: classes/core/class-wc-order-export-data-extractor-ui.php:400
1006
  msgid "Line number"
1007
  msgstr ""
1008
 
1009
- #: classes/core/class-wc-order-export-data-extractor-ui.php:402
1010
  msgid "Order Number"
1011
  msgstr ""
1012
 
1013
- #: classes/core/class-wc-order-export-data-extractor-ui.php:403
1014
  msgid "Order Status"
1015
  msgstr ""
1016
 
1017
- #: classes/core/class-wc-order-export-data-extractor-ui.php:406
1018
  msgid "Transaction ID"
1019
  msgstr ""
1020
 
1021
- #: classes/core/class-wc-order-export-data-extractor-ui.php:409
1022
  msgid "Date of first refund"
1023
  msgstr ""
1024
 
1025
- #: classes/core/class-wc-order-export-data-extractor-ui.php:410
1026
  msgid "Customer Note"
1027
  msgstr ""
1028
 
1029
- #: classes/core/class-wc-order-export-data-extractor-ui.php:411
1030
  msgid "Order Notes"
1031
  msgstr ""
1032
 
1033
- #: classes/core/class-wc-order-export-data-extractor-ui.php:417
1034
  msgid "Customer IP address"
1035
  msgstr ""
1036
 
1037
- #: classes/core/class-wc-order-export-data-extractor-ui.php:418
1038
  msgid "Customer User ID"
1039
  msgstr ""
1040
 
1041
- #: classes/core/class-wc-order-export-data-extractor-ui.php:419
1042
  msgid "Customer Username"
1043
  msgstr ""
1044
 
1045
- #: classes/core/class-wc-order-export-data-extractor-ui.php:420
 
 
 
 
1046
  msgid "Customer User Email"
1047
  msgstr ""
1048
 
1049
- #: classes/core/class-wc-order-export-data-extractor-ui.php:421
1050
  msgid "Customer Role"
1051
  msgstr ""
1052
 
1053
- #: classes/core/class-wc-order-export-data-extractor-ui.php:422
1054
  msgid "Customer Total Orders"
1055
  msgstr ""
1056
 
1057
- #: classes/core/class-wc-order-export-data-extractor-ui.php:428
1058
  msgid "First Name (Billing)"
1059
  msgstr ""
1060
 
1061
- #: classes/core/class-wc-order-export-data-extractor-ui.php:429
1062
  msgid "Last Name (Billing)"
1063
  msgstr ""
1064
 
1065
- #: classes/core/class-wc-order-export-data-extractor-ui.php:430
1066
  msgid "Full Name (Billing)"
1067
  msgstr ""
1068
 
1069
- #: classes/core/class-wc-order-export-data-extractor-ui.php:431
1070
  msgid "Company (Billing)"
1071
  msgstr ""
1072
 
1073
- #: classes/core/class-wc-order-export-data-extractor-ui.php:432
1074
  msgid "Address 1&2 (Billing)"
1075
  msgstr ""
1076
 
1077
- #: classes/core/class-wc-order-export-data-extractor-ui.php:433
1078
  msgid "Address 1 (Billing)"
1079
  msgstr ""
1080
 
1081
- #: classes/core/class-wc-order-export-data-extractor-ui.php:434
1082
  msgid "Address 2 (Billing)"
1083
  msgstr ""
1084
 
1085
- #: classes/core/class-wc-order-export-data-extractor-ui.php:435
1086
  msgid "City (Billing)"
1087
  msgstr ""
1088
 
1089
- #: classes/core/class-wc-order-export-data-extractor-ui.php:436
1090
  msgid "State Code (Billing)"
1091
  msgstr ""
1092
 
1093
- #: classes/core/class-wc-order-export-data-extractor-ui.php:437
1094
  msgid "City, State, Zip (Billing)"
1095
  msgstr ""
1096
 
1097
- #: classes/core/class-wc-order-export-data-extractor-ui.php:438
1098
  msgid "State Name (Billing)"
1099
  msgstr ""
1100
 
1101
- #: classes/core/class-wc-order-export-data-extractor-ui.php:439
1102
  msgid "Postcode (Billing)"
1103
  msgstr ""
1104
 
1105
- #: classes/core/class-wc-order-export-data-extractor-ui.php:440
1106
  msgid "Country Code (Billing)"
1107
  msgstr ""
1108
 
1109
- #: classes/core/class-wc-order-export-data-extractor-ui.php:441
1110
  msgid "Country Name (Billing)"
1111
  msgstr ""
1112
 
1113
- #: classes/core/class-wc-order-export-data-extractor-ui.php:442
1114
  msgid "Email (Billing)"
1115
  msgstr ""
1116
 
1117
- #: classes/core/class-wc-order-export-data-extractor-ui.php:443
1118
  msgid "Phone (Billing)"
1119
  msgstr ""
1120
 
1121
- #: classes/core/class-wc-order-export-data-extractor-ui.php:449
1122
  msgid "First Name (Shipping)"
1123
  msgstr ""
1124
 
1125
- #: classes/core/class-wc-order-export-data-extractor-ui.php:450
1126
  msgid "Last Name (Shipping)"
1127
  msgstr ""
1128
 
1129
- #: classes/core/class-wc-order-export-data-extractor-ui.php:451
1130
  msgid "Full Name (Shipping)"
1131
  msgstr ""
1132
 
1133
- #: classes/core/class-wc-order-export-data-extractor-ui.php:452
1134
  msgid "Company (Shipping)"
1135
  msgstr ""
1136
 
1137
- #: classes/core/class-wc-order-export-data-extractor-ui.php:453
1138
  msgid "Address 1&2 (Shipping)"
1139
  msgstr ""
1140
 
1141
- #: classes/core/class-wc-order-export-data-extractor-ui.php:454
1142
  msgid "Address 1 (Shipping)"
1143
  msgstr ""
1144
 
1145
- #: classes/core/class-wc-order-export-data-extractor-ui.php:455
1146
  msgid "Address 2 (Shipping)"
1147
  msgstr ""
1148
 
1149
- #: classes/core/class-wc-order-export-data-extractor-ui.php:456
1150
  msgid "City (Shipping)"
1151
  msgstr ""
1152
 
1153
- #: classes/core/class-wc-order-export-data-extractor-ui.php:457
1154
  msgid "State Code (Shipping)"
1155
  msgstr ""
1156
 
1157
- #: classes/core/class-wc-order-export-data-extractor-ui.php:458
1158
  msgid "City, State, Zip (Shipping)"
1159
  msgstr ""
1160
 
1161
- #: classes/core/class-wc-order-export-data-extractor-ui.php:459
1162
  msgid "State Name (Shipping)"
1163
  msgstr ""
1164
 
1165
- #: classes/core/class-wc-order-export-data-extractor-ui.php:460
1166
  msgid "Postcode (Shipping)"
1167
  msgstr ""
1168
 
1169
- #: classes/core/class-wc-order-export-data-extractor-ui.php:461
1170
  msgid "Country Code (Shipping)"
1171
  msgstr ""
1172
 
1173
- #: classes/core/class-wc-order-export-data-extractor-ui.php:462
1174
  msgid "Country Name (Shipping)"
1175
  msgstr ""
1176
 
1177
- #: classes/core/class-wc-order-export-data-extractor-ui.php:469
1178
- #: classes/core/class-wc-order-export-data-extractor-ui.php:537
1179
  msgid "Products"
1180
  msgstr ""
1181
 
1182
- #: classes/core/class-wc-order-export-data-extractor-ui.php:482
1183
  msgid "Shipping Method Title"
1184
  msgstr ""
1185
 
1186
- #: classes/core/class-wc-order-export-data-extractor-ui.php:483
1187
  msgid "Shipping Method"
1188
  msgstr ""
1189
 
1190
- #: classes/core/class-wc-order-export-data-extractor-ui.php:484
1191
  msgid "Payment Method Title"
1192
  msgstr ""
1193
 
1194
- #: classes/core/class-wc-order-export-data-extractor-ui.php:485
1195
  msgid "Payment Method"
1196
  msgstr ""
1197
 
1198
- #: classes/core/class-wc-order-export-data-extractor-ui.php:486
1199
  msgid "Coupons Used"
1200
  msgstr ""
1201
 
1202
- #: classes/core/class-wc-order-export-data-extractor-ui.php:487
1203
  msgid "Cart Discount Amount"
1204
  msgstr ""
1205
 
1206
- #: classes/core/class-wc-order-export-data-extractor-ui.php:488
1207
  msgid "Cart Discount Amount Tax"
1208
  msgstr ""
1209
 
1210
- #: classes/core/class-wc-order-export-data-extractor-ui.php:489
1211
  msgid "Order Subtotal Amount"
1212
  msgstr ""
1213
 
1214
- #: classes/core/class-wc-order-export-data-extractor-ui.php:491
1215
  msgid "Order Subtotal Amount Refunded"
1216
  msgstr ""
1217
 
1218
- #: classes/core/class-wc-order-export-data-extractor-ui.php:492
1219
  msgid "Order Subtotal Amount (- Refund)"
1220
  msgstr ""
1221
 
1222
- #: classes/core/class-wc-order-export-data-extractor-ui.php:493
1223
  msgid "Order Tax Amount"
1224
  msgstr ""
1225
 
1226
- #: classes/core/class-wc-order-export-data-extractor-ui.php:494
1227
  msgid "Order Shipping Amount"
1228
  msgstr ""
1229
 
1230
- #: classes/core/class-wc-order-export-data-extractor-ui.php:495
1231
  msgid "Order Shipping Amount Refunded"
1232
  msgstr ""
1233
 
1234
- #: classes/core/class-wc-order-export-data-extractor-ui.php:496
1235
  msgid "Order Shipping Amount (- Refund)"
1236
  msgstr ""
1237
 
1238
- #: classes/core/class-wc-order-export-data-extractor-ui.php:497
1239
  msgid "Order Shipping Tax Amount"
1240
  msgstr ""
1241
 
1242
- #: classes/core/class-wc-order-export-data-extractor-ui.php:498
1243
  msgid "Order Shipping Tax Refunded"
1244
  msgstr ""
1245
 
1246
- #: classes/core/class-wc-order-export-data-extractor-ui.php:499
1247
  msgid "Order Shipping Tax Amount (- Refund)"
1248
  msgstr ""
1249
 
1250
- #: classes/core/class-wc-order-export-data-extractor-ui.php:500
1251
  msgid "Order Refund Amount"
1252
  msgstr ""
1253
 
1254
- #: classes/core/class-wc-order-export-data-extractor-ui.php:501
1255
  msgid "Order Total Amount (- Refund)"
1256
  msgstr ""
1257
 
1258
- #: classes/core/class-wc-order-export-data-extractor-ui.php:502
1259
  msgid "Order Total Amount"
1260
  msgstr ""
1261
 
1262
- #: classes/core/class-wc-order-export-data-extractor-ui.php:503
1263
  msgid "Order Total Amount without Tax"
1264
  msgstr ""
1265
 
1266
- #: classes/core/class-wc-order-export-data-extractor-ui.php:504
1267
  msgid "Order Total Tax Amount"
1268
  msgstr ""
1269
 
1270
- #: classes/core/class-wc-order-export-data-extractor-ui.php:505
1271
  msgid "Order Total Tax Amount Refunded"
1272
  msgstr ""
1273
 
1274
- #: classes/core/class-wc-order-export-data-extractor-ui.php:506
1275
  msgid "Order Total Tax Amount (- Refund)"
1276
  msgstr ""
1277
 
1278
- #: classes/core/class-wc-order-export-data-extractor-ui.php:507
1279
  msgid "Currency"
1280
  msgstr ""
1281
 
1282
- #: classes/core/class-wc-order-export-data-extractor-ui.php:513
1283
  msgid "Total weight"
1284
  msgstr ""
1285
 
1286
- #: classes/core/class-wc-order-export-data-extractor-ui.php:514
1287
  msgid "Total items"
1288
  msgstr ""
1289
 
1290
- #: classes/core/class-wc-order-export-data-extractor-ui.php:515
 
 
 
 
1291
  msgid "Total products"
1292
  msgstr ""
1293
 
1294
- #: classes/core/class-wc-order-export-data-extractor-ui.php:533
1295
  msgid "Common"
1296
  msgstr ""
1297
 
1298
- #: classes/core/class-wc-order-export-data-extractor-ui.php:534
1299
  msgid "User"
1300
  msgstr ""
1301
 
1302
- #: classes/core/class-wc-order-export-data-extractor-ui.php:535
1303
  msgid "Billing"
1304
  msgstr ""
1305
 
1306
- #: classes/core/class-wc-order-export-data-extractor-ui.php:536
1307
  msgid "Shipping"
1308
  msgstr ""
1309
 
1310
- #: classes/core/class-wc-order-export-data-extractor-ui.php:539
1311
  msgid "Cart"
1312
  msgstr ""
1313
 
1314
- #: classes/core/class-wc-order-export-data-extractor-ui.php:540
1315
  msgid "Others"
1316
  msgstr ""
1317
 
1318
- #: classes/core/class-wc-order-export-data-extractor.php:1848
1319
  msgid "[Rest of the World]"
1320
  msgstr ""
1321
 
1322
- #: classes/core/class-wc-order-export-engine.php:18
1323
- #: classes/core/class-wc-order-export-engine.php:56
1324
  msgid "No destination selected"
1325
  msgstr ""
1326
 
1327
- #: classes/core/class-wc-order-export-engine.php:28
1328
  msgid "Wrong format"
1329
  msgstr ""
1330
 
1331
- #: classes/core/class-wc-order-export-engine.php:66
1332
  msgid "Wrong export type"
1333
  msgstr ""
1334
 
1335
- #: classes/core/class-wc-order-export-engine.php:372
1336
  msgid "Don't Panic"
1337
  msgstr ""
1338
 
1339
- #: classes/core/class-wc-order-export-engine.php:373
1340
  #, php-format
1341
  msgid "The code you are trying to save produced a fatal error on line %d:"
1342
  msgstr ""
1343
 
1344
- #: classes/core/class-wc-order-export-engine.php:499
1345
  msgid "Main SQL queries are listed below"
1346
  msgstr ""
1347
 
1348
- #: classes/core/class-wc-order-export-engine.php:731
1349
  msgid "Total Quantity"
1350
  msgstr ""
1351
 
1352
- #: classes/core/class-wc-order-export-engine.php:731
1353
  msgid "Total Amount"
1354
  msgstr ""
1355
 
3
  msgstr ""
4
  "Project-Id-Version: PACKAGE VERSION\n"
5
  "Report-Msgid-Bugs-To: \n"
6
+ "POT-Creation-Date: 2018-08-30 10:27+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"
25
  msgstr ""
26
 
27
  #: view/settings-form.php:59 view/settings-form.php:228
28
+ #: classes/core/class-wc-order-export-data-extractor-ui.php:585
29
  msgid "Order Date"
30
  msgstr ""
31
 
32
  #: view/settings-form.php:64 view/settings-form.php:229
33
+ #: classes/core/class-wc-order-export-data-extractor-ui.php:590
34
  msgid "Modification Date"
35
  msgstr ""
36
 
37
  #: view/settings-form.php:69
38
+ #: classes/core/class-wc-order-export-data-extractor-ui.php:604
39
  msgid "Paid Date"
40
  msgstr ""
41
 
42
  #: view/settings-form.php:74
43
+ #: classes/core/class-wc-order-export-data-extractor-ui.php:599
44
  msgid "Completed Date"
45
  msgstr ""
46
 
203
  msgstr ""
204
 
205
  #: view/settings-form.php:227
206
+ #: classes/core/class-wc-order-export-data-extractor-ui.php:581
207
  msgid "Order ID"
208
  msgstr ""
209
 
260
  msgid "Custom PHP code to modify output"
261
  msgstr ""
262
 
263
+ #: view/settings-form.php:300
264
+ msgid ""
265
+ "Please check permissions for your role. You must have capability "
266
+ "“edit_themes” to use this box."
267
+ msgstr ""
268
+
269
+ #: view/settings-form.php:303
270
  msgid "Use only unnamed functions!"
271
  msgstr ""
272
 
273
+ #: view/settings-form.php:317
274
  msgid "Filter by order"
275
  msgstr ""
276
 
277
+ #: view/settings-form.php:320
278
  msgid "Don't export child orders"
279
  msgstr ""
280
 
281
+ #: view/settings-form.php:321
282
  msgid "Export refunds"
283
  msgstr ""
284
 
285
+ #: view/settings-form.php:322
286
  msgid "Mark exported orders"
287
  msgstr ""
288
 
289
+ #: view/settings-form.php:323
290
  msgid "Export unmarked orders only"
291
  msgstr ""
292
 
293
+ #: view/settings-form.php:324
294
  msgid "Order statuses"
295
  msgstr ""
296
 
297
+ #: view/settings-form.php:331 view/settings-form.php:556
298
  msgid "Custom fields"
299
  msgstr ""
300
 
301
+ #: view/settings-form.php:370
302
  msgid ""
303
  "The filters won't work correctly.<br>Another plugin(or theme) has loaded "
304
  "outdated Select2.js"
305
  msgstr ""
306
 
307
+ #: view/settings-form.php:371
308
  msgid "Filter by product"
309
  msgstr ""
310
 
311
+ #: view/settings-form.php:374
312
+ msgid "Export all products from the order"
313
  msgstr ""
314
 
315
+ #: view/settings-form.php:375
316
  msgid "Skip fully refunded items"
317
  msgstr ""
318
 
319
+ #: view/settings-form.php:376
320
  msgid "Product categories"
321
  msgstr ""
322
 
323
+ #: view/settings-form.php:386
324
  msgid "Vendor/creator"
325
  msgstr ""
326
 
327
+ #: view/settings-form.php:399
328
  msgid "Product"
329
  msgstr ""
330
 
331
+ #: view/settings-form.php:411
332
  msgid "Product taxonomies"
333
  msgstr ""
334
 
335
+ #: view/settings-form.php:437
336
  msgid "Product custom fields"
337
  msgstr ""
338
 
339
+ #: view/settings-form.php:468
340
  msgid "Variable product attributes"
341
  msgstr ""
342
 
343
+ #: view/settings-form.php:495
344
  msgid "Item meta data"
345
  msgstr ""
346
 
347
+ #: view/settings-form.php:532
348
  msgid "Filter by customers"
349
  msgstr ""
350
 
351
+ #: view/settings-form.php:536
352
+ msgid "Usernames"
353
  msgstr ""
354
 
355
+ #: view/settings-form.php:547
356
+ msgid "User roles"
357
  msgstr ""
358
 
359
+ #: view/settings-form.php:593
360
  msgid "Filter by coupons"
361
  msgstr ""
362
 
363
+ #: view/settings-form.php:598
364
  msgid "Any coupon used"
365
  msgstr ""
366
 
367
+ #: view/settings-form.php:600
368
+ #: classes/core/class-wc-order-export-data-extractor-ui.php:835
369
+ #: classes/core/class-wc-order-export-data-extractor-ui.php:1019
370
  msgid "Coupons"
371
  msgstr ""
372
 
373
+ #: view/settings-form.php:615
374
  msgid "Filter by billing"
375
  msgstr ""
376
 
377
+ #: view/settings-form.php:618
378
  msgid "Billing locations"
379
  msgstr ""
380
 
381
+ #: view/settings-form.php:642
382
  msgid "Payment methods"
383
  msgstr ""
384
 
385
+ #: view/settings-form.php:654
386
  msgid "Filter by shipping"
387
  msgstr ""
388
 
389
+ #: view/settings-form.php:657
390
  msgid "Shipping locations"
391
  msgstr ""
392
 
393
+ #: view/settings-form.php:681
394
  msgid "Shipping methods"
395
  msgstr ""
396
 
397
+ #: view/settings-form.php:693
398
  msgid "Filter by item and metadata"
399
  msgstr ""
400
 
401
+ #: view/settings-form.php:696
402
  msgid "Item names"
403
  msgstr ""
404
 
405
+ #: view/settings-form.php:720
406
  msgid "Item metadata"
407
  msgstr ""
408
 
409
+ #: view/settings-form.php:754 classes/class-wc-order-export-admin.php:572
410
  msgid "Set up fields to export"
411
  msgstr ""
412
 
413
+ #: view/settings-form.php:760 view/modal-controls.php:36
414
  msgid "Meta key"
415
  msgstr ""
416
 
417
+ #: view/settings-form.php:768 view/settings-form.php:780
418
  #: view/modal-controls.php:20 view/modal-controls.php:26
419
  #: view/modal-controls.php:43 view/modal-controls.php:49
420
  msgid "Column name"
421
  msgstr ""
422
 
423
+ #: view/settings-form.php:771
424
  msgid "or type meta key here"
425
  msgstr ""
426
 
427
+ #: view/settings-form.php:772 view/settings-form.php:800
428
  #: view/modal-controls.php:4 view/modal-controls.php:39
429
  msgid "Hide unused fields"
430
  msgstr ""
431
 
432
+ #: view/settings-form.php:775 view/settings-form.php:783
433
  msgid "Confirm"
434
  msgstr ""
435
 
436
+ #: view/settings-form.php:776 view/settings-form.php:784
437
  msgid "Cancel"
438
  msgstr ""
439
 
440
+ #: view/settings-form.php:781 view/modal-controls.php:27
441
  #: view/modal-controls.php:50
442
  msgid "Value"
443
  msgstr ""
444
 
445
+ #: view/settings-form.php:787
446
  msgid "Use sections"
447
  msgstr ""
448
 
449
+ #: view/settings-form.php:794
450
  msgid "Actions"
451
  msgstr ""
452
 
453
+ #: view/settings-form.php:795 view/modal-controls.php:22
454
  #: view/modal-controls.php:45
455
  msgid "Add field"
456
  msgstr ""
457
 
458
+ #: view/settings-form.php:797 view/modal-controls.php:29
459
  #: view/modal-controls.php:52
460
  msgid "Add static field"
461
  msgstr ""
462
 
463
+ #: view/settings-form.php:801
464
  msgid "Show unused fields"
465
  msgstr ""
466
 
467
+ #: view/settings-form.php:809
468
  msgid "Select all"
469
  msgstr ""
470
 
471
+ #: view/settings-form.php:812
472
  msgid "Drag rows to reorder exported fields"
473
  msgstr ""
474
 
475
+ #: view/settings-form.php:823
476
  #, php-format
477
  msgid ""
478
  "If you see this message after page load, user interface won't work correctly!"
480
  "it). Probably, it's a conflict with another plugin or active theme."
481
  msgstr ""
482
 
483
+ #: view/settings-form.php:825
484
  msgid "Preview"
485
  msgstr ""
486
 
487
+ #: view/settings-form.php:825
488
  msgid "Might be different from actual export!"
489
  msgstr ""
490
 
491
+ #: view/settings-form.php:826
492
  msgid "Save settings"
493
  msgstr ""
494
 
495
+ #: view/settings-form.php:828
496
  msgid "Export"
497
  msgstr ""
498
 
499
+ #: view/settings-form.php:831
500
  msgid "Export [w/o progressbar]"
501
  msgstr ""
502
 
503
+ #: view/settings-form.php:831
504
  msgid "It might not work for huge datasets!"
505
  msgstr ""
506
 
507
+ #: view/settings-form.php:834
508
  msgid "Save as a profile"
509
  msgstr ""
510
 
511
+ #: view/settings-form.php:837
512
  #, php-format
513
  msgid "Export total: %s orders"
514
  msgstr ""
515
 
516
+ #: view/settings-form.php:838
517
  msgid "Preview size"
518
  msgstr ""
519
 
520
+ #: view/settings-form.php:846
521
  msgid "Press 'Esc' to cancel the export"
522
  msgstr ""
523
 
524
+ #: view/settings-form.php:847
525
  msgid "Click here to download"
526
  msgstr ""
527
 
573
  msgid "All meta"
574
  msgstr ""
575
 
576
+ #: classes/class-wc-order-export-admin.php:91
577
  msgid "Export Status"
578
  msgstr ""
579
 
580
+ #: classes/class-wc-order-export-admin.php:133
581
  msgid ""
582
  "Advanced Order Export For WooCommerce is available <a href=\"admin.php?"
583
  "page=wc-order-export\">on this page</a>."
584
  msgstr ""
585
 
586
+ #: classes/class-wc-order-export-admin.php:142
587
  msgid "Settings"
588
  msgstr ""
589
 
590
+ #: classes/class-wc-order-export-admin.php:143
591
  msgid "Docs"
592
  msgstr ""
593
 
594
+ #: classes/class-wc-order-export-admin.php:145
595
  msgid "Support"
596
  msgstr ""
597
 
598
+ #: classes/class-wc-order-export-admin.php:223
599
+ #: classes/class-wc-order-export-admin.php:224
600
+ #: classes/class-wc-order-export-admin.php:228
601
+ #: classes/class-wc-order-export-admin.php:229
602
  msgid "Export Orders"
603
  msgstr ""
604
 
605
+ #: classes/class-wc-order-export-admin.php:542
606
  msgid "Copied from \"Export now\""
607
  msgstr ""
608
 
609
+ #: classes/class-wc-order-export-admin.php:573
610
  #, php-format
611
  msgid "Add %s as %s columns %s as rows"
612
  msgstr ""
613
 
614
+ #: classes/class-wc-order-export-admin.php:614
615
  msgid "empty column name"
616
  msgstr ""
617
 
618
+ #: classes/class-wc-order-export-admin.php:615
619
  msgid "empty meta key"
620
  msgstr ""
621
 
622
+ #: classes/class-wc-order-export-admin.php:616
623
  msgid "select product field or item field or taxonomy"
624
  msgstr ""
625
 
626
+ #: classes/class-wc-order-export-admin.php:618
627
  msgid "empty value"
628
  msgstr ""
629
 
630
+ #: classes/class-wc-order-export-admin.php:619
631
  msgid "title is empty"
632
  msgstr ""
633
 
634
+ #: classes/class-wc-order-export-admin.php:620
635
  msgid "Date From is greater than Date To"
636
  msgstr ""
637
 
638
+ #: classes/class-wc-order-export-admin.php:621
639
  msgid "Please, set up fields to export"
640
  msgstr ""
641
 
642
+ #: classes/class-wc-order-export-admin.php:622
643
+ #: classes/admin/class-wc-order-export-ajax.php:356
644
+ #: classes/core/class-wc-order-export-engine.php:748
645
+ #: classes/core/class-wc-order-export-engine.php:761
646
  msgid "Nothing to export. Please, adjust your filters"
647
  msgstr ""
648
 
649
+ #: classes/class-wc-order-export-admin.php:624
650
+ #: classes/core/class-wc-order-export-data-extractor.php:229
651
  msgid "empty"
652
  msgstr ""
653
 
654
+ #: classes/class-wc-order-export-admin.php:719
655
  #, php-format
656
  msgid "Status change job #%s for order #%s. Result: %s"
657
  msgstr ""
658
 
659
+ #: classes/class-wc-order-export-admin.php:782
660
  #, php-format
661
  msgid "Export as %s"
662
  msgstr ""
663
 
664
+ #: classes/class-wc-order-export-admin.php:788
665
  msgid "Mark exported"
666
  msgstr ""
667
 
668
+ #: classes/class-wc-order-export-admin.php:789
669
  msgid "Unmark exported"
670
  msgstr ""
671
 
672
+ #: classes/class-wc-order-export-admin.php:795
673
  #, php-format
674
  msgid "Export as profile '%s'"
675
  msgstr ""
676
 
677
+ #: classes/class-wc-order-export-admin.php:866
678
  #, php-format
679
  msgid "%s order marked."
680
  msgid_plural "%s orders marked."
681
  msgstr[0] ""
682
  msgstr[1] ""
683
 
684
+ #: classes/class-wc-order-export-admin.php:875
685
  #, php-format
686
  msgid "%s order unmarked."
687
  msgid_plural "%s orders unmarked."
783
  msgid "Buy %s to get access to Scheduled jobs"
784
  msgstr ""
785
 
786
+ #: classes/formats/abstract-class-woe-formatter-sv.php:89
787
+ #: classes/formats/class-woe-formatter-xls.php:137
788
  msgid "<td colspan=10><b>No results</b></td>"
789
  msgstr ""
790
 
792
  msgid "can not open for output"
793
  msgstr ""
794
 
795
+ #: classes/formats/class-woe-formatter-xls.php:75
796
+ #: classes/admin/class-wc-order-export-manage.php:214
797
  msgid "Orders"
798
  msgstr ""
799
 
829
  msgid "Wrong key for cron url!"
830
  msgstr ""
831
 
832
+ #: classes/admin/class-wc-order-export-ajax.php:246
833
  msgid "Can't create temporary file"
834
  msgstr ""
835
 
836
+ #: classes/admin/class-wc-order-export-ajax.php:268
837
  msgid "Can't find exported file"
838
  msgstr ""
839
 
840
+ #: classes/core/class-wc-order-export-data-extractor-ui.php:344
841
  msgid "Item ID"
842
  msgstr ""
843
 
844
+ #: classes/core/class-wc-order-export-data-extractor-ui.php:347
845
  msgid "Item #"
846
  msgstr ""
847
 
848
+ #: classes/core/class-wc-order-export-data-extractor-ui.php:348
849
  msgid "SKU"
850
  msgstr ""
851
 
852
+ #: classes/core/class-wc-order-export-data-extractor-ui.php:350
853
  msgid "Item Name"
854
  msgstr ""
855
 
856
+ #: classes/core/class-wc-order-export-data-extractor-ui.php:354
857
+ msgid "Product Id"
858
+ msgstr ""
859
+
860
+ #: classes/core/class-wc-order-export-data-extractor-ui.php:358
861
  msgid "Product Name"
862
  msgstr ""
863
 
864
+ #: classes/core/class-wc-order-export-data-extractor-ui.php:362
865
+ msgid "Variation Id"
866
+ msgstr ""
867
+
868
+ #: classes/core/class-wc-order-export-data-extractor-ui.php:366
869
  msgid "Product Variation"
870
  msgstr ""
871
 
872
+ #: classes/core/class-wc-order-export-data-extractor-ui.php:370
873
  msgid "Item Seller"
874
  msgstr ""
875
 
876
+ #: classes/core/class-wc-order-export-data-extractor-ui.php:374
877
  msgid "Quantity"
878
  msgstr ""
879
 
880
+ #: classes/core/class-wc-order-export-data-extractor-ui.php:378
881
  msgid "Quantity (- Refund)"
882
  msgstr ""
883
 
884
+ #: classes/core/class-wc-order-export-data-extractor-ui.php:382
885
  msgid "Item Cost"
886
  msgstr ""
887
 
888
+ #: classes/core/class-wc-order-export-data-extractor-ui.php:387
889
  msgid "Product Current Price"
890
  msgstr ""
891
 
892
+ #: classes/core/class-wc-order-export-data-extractor-ui.php:392
893
  msgid "Order Line (w/o tax)"
894
  msgstr ""
895
 
896
+ #: classes/core/class-wc-order-export-data-extractor-ui.php:397
897
  msgid "Order Line Tax"
898
  msgstr ""
899
 
900
+ #: classes/core/class-wc-order-export-data-extractor-ui.php:402
901
  msgid "Order Line Tax Refunded"
902
  msgstr ""
903
 
904
+ #: classes/core/class-wc-order-export-data-extractor-ui.php:407
905
  msgid "Order Line Tax (- Refund)"
906
  msgstr ""
907
 
908
+ #: classes/core/class-wc-order-export-data-extractor-ui.php:412
909
  msgid "Order Line Subtotal"
910
  msgstr ""
911
 
912
+ #: classes/core/class-wc-order-export-data-extractor-ui.php:417
913
+ msgid "Order Line Subtotal Tax"
914
+ msgstr ""
915
+
916
+ #: classes/core/class-wc-order-export-data-extractor-ui.php:422
917
  msgid "Order Line Total"
918
  msgstr ""
919
 
920
+ #: classes/core/class-wc-order-export-data-extractor-ui.php:427
921
  msgid "Order Line Total (include tax)"
922
  msgstr ""
923
 
924
+ #: classes/core/class-wc-order-export-data-extractor-ui.php:432
925
  msgid "Order Line Total Refunded"
926
  msgstr ""
927
 
928
+ #: classes/core/class-wc-order-export-data-extractor-ui.php:437
929
  msgid "Order Line Total (- Refund)"
930
  msgstr ""
931
 
932
+ #: classes/core/class-wc-order-export-data-extractor-ui.php:442
933
  msgid "Item Discount Amount"
934
  msgstr ""
935
 
936
+ #: classes/core/class-wc-order-export-data-extractor-ui.php:447
937
  msgid "Item Tax Rate"
938
  msgstr ""
939
 
940
+ #: classes/core/class-wc-order-export-data-extractor-ui.php:451
941
  msgid "Type"
942
  msgstr ""
943
 
944
+ #: classes/core/class-wc-order-export-data-extractor-ui.php:453
945
  msgid "Category"
946
  msgstr ""
947
 
948
+ #: classes/core/class-wc-order-export-data-extractor-ui.php:456
949
  msgid "Tags"
950
  msgstr ""
951
 
952
+ #: classes/core/class-wc-order-export-data-extractor-ui.php:458
953
  msgid "Width"
954
  msgstr ""
955
 
956
+ #: classes/core/class-wc-order-export-data-extractor-ui.php:463
957
  msgid "Length"
958
  msgstr ""
959
 
960
+ #: classes/core/class-wc-order-export-data-extractor-ui.php:468
961
  msgid "Height"
962
  msgstr ""
963
 
964
+ #: classes/core/class-wc-order-export-data-extractor-ui.php:473
965
  msgid "Weight"
966
  msgstr ""
967
 
968
+ #: classes/core/class-wc-order-export-data-extractor-ui.php:478
969
  msgid "Product URL"
970
  msgstr ""
971
 
972
+ #: classes/core/class-wc-order-export-data-extractor-ui.php:482
973
  msgid "Download URL"
974
  msgstr ""
975
 
976
+ #: classes/core/class-wc-order-export-data-extractor-ui.php:486
977
  msgid "Image URL"
978
  msgstr ""
979
 
980
+ #: classes/core/class-wc-order-export-data-extractor-ui.php:490
981
  msgid "Product Shipping Class"
982
  msgstr ""
983
 
984
+ #: classes/core/class-wc-order-export-data-extractor-ui.php:494
985
  msgid "Description"
986
  msgstr ""
987
 
988
+ #: classes/core/class-wc-order-export-data-extractor-ui.php:498
989
  msgid "Short Description"
990
  msgstr ""
991
 
992
+ #: classes/core/class-wc-order-export-data-extractor-ui.php:502
993
  msgid "Full names for categories"
994
  msgstr ""
995
 
996
+ #: classes/core/class-wc-order-export-data-extractor-ui.php:518
997
  msgid "Coupon Code"
998
  msgstr ""
999
 
1000
+ #: classes/core/class-wc-order-export-data-extractor-ui.php:522
1001
  msgid "Discount Amount"
1002
  msgstr ""
1003
 
1004
+ #: classes/core/class-wc-order-export-data-extractor-ui.php:527
1005
  msgid "Discount Amount Tax"
1006
  msgstr ""
1007
 
1008
+ #: classes/core/class-wc-order-export-data-extractor-ui.php:532
1009
  msgid "Discount Amount + Tax"
1010
  msgstr ""
1011
 
1012
+ #: classes/core/class-wc-order-export-data-extractor-ui.php:536
1013
  msgid "Coupon Description"
1014
  msgstr ""
1015
 
1016
+ #: classes/core/class-wc-order-export-data-extractor-ui.php:540
1017
  msgid "Coupon Type"
1018
  msgstr ""
1019
 
1020
+ #: classes/core/class-wc-order-export-data-extractor-ui.php:544
1021
  msgid "Coupon Amount"
1022
  msgstr ""
1023
 
1024
+ #: classes/core/class-wc-order-export-data-extractor-ui.php:580
1025
  msgid "Line number"
1026
  msgstr ""
1027
 
1028
+ #: classes/core/class-wc-order-export-data-extractor-ui.php:582
1029
  msgid "Order Number"
1030
  msgstr ""
1031
 
1032
+ #: classes/core/class-wc-order-export-data-extractor-ui.php:583
1033
  msgid "Order Status"
1034
  msgstr ""
1035
 
1036
+ #: classes/core/class-wc-order-export-data-extractor-ui.php:595
1037
  msgid "Transaction ID"
1038
  msgstr ""
1039
 
1040
+ #: classes/core/class-wc-order-export-data-extractor-ui.php:609
1041
  msgid "Date of first refund"
1042
  msgstr ""
1043
 
1044
+ #: classes/core/class-wc-order-export-data-extractor-ui.php:614
1045
  msgid "Customer Note"
1046
  msgstr ""
1047
 
1048
+ #: classes/core/class-wc-order-export-data-extractor-ui.php:619
1049
  msgid "Order Notes"
1050
  msgstr ""
1051
 
1052
+ #: classes/core/class-wc-order-export-data-extractor-ui.php:629
1053
  msgid "Customer IP address"
1054
  msgstr ""
1055
 
1056
+ #: classes/core/class-wc-order-export-data-extractor-ui.php:633
1057
  msgid "Customer User ID"
1058
  msgstr ""
1059
 
1060
+ #: classes/core/class-wc-order-export-data-extractor-ui.php:637
1061
  msgid "Customer Username"
1062
  msgstr ""
1063
 
1064
+ #: classes/core/class-wc-order-export-data-extractor-ui.php:641
1065
+ msgid "User Website"
1066
+ msgstr ""
1067
+
1068
+ #: classes/core/class-wc-order-export-data-extractor-ui.php:645
1069
  msgid "Customer User Email"
1070
  msgstr ""
1071
 
1072
+ #: classes/core/class-wc-order-export-data-extractor-ui.php:649
1073
  msgid "Customer Role"
1074
  msgstr ""
1075
 
1076
+ #: classes/core/class-wc-order-export-data-extractor-ui.php:653
1077
  msgid "Customer Total Orders"
1078
  msgstr ""
1079
 
1080
+ #: classes/core/class-wc-order-export-data-extractor-ui.php:662
1081
  msgid "First Name (Billing)"
1082
  msgstr ""
1083
 
1084
+ #: classes/core/class-wc-order-export-data-extractor-ui.php:667
1085
  msgid "Last Name (Billing)"
1086
  msgstr ""
1087
 
1088
+ #: classes/core/class-wc-order-export-data-extractor-ui.php:672
1089
  msgid "Full Name (Billing)"
1090
  msgstr ""
1091
 
1092
+ #: classes/core/class-wc-order-export-data-extractor-ui.php:677
1093
  msgid "Company (Billing)"
1094
  msgstr ""
1095
 
1096
+ #: classes/core/class-wc-order-export-data-extractor-ui.php:682
1097
  msgid "Address 1&2 (Billing)"
1098
  msgstr ""
1099
 
1100
+ #: classes/core/class-wc-order-export-data-extractor-ui.php:687
1101
  msgid "Address 1 (Billing)"
1102
  msgstr ""
1103
 
1104
+ #: classes/core/class-wc-order-export-data-extractor-ui.php:692
1105
  msgid "Address 2 (Billing)"
1106
  msgstr ""
1107
 
1108
+ #: classes/core/class-wc-order-export-data-extractor-ui.php:697
1109
  msgid "City (Billing)"
1110
  msgstr ""
1111
 
1112
+ #: classes/core/class-wc-order-export-data-extractor-ui.php:702
1113
  msgid "State Code (Billing)"
1114
  msgstr ""
1115
 
1116
+ #: classes/core/class-wc-order-export-data-extractor-ui.php:707
1117
  msgid "City, State, Zip (Billing)"
1118
  msgstr ""
1119
 
1120
+ #: classes/core/class-wc-order-export-data-extractor-ui.php:712
1121
  msgid "State Name (Billing)"
1122
  msgstr ""
1123
 
1124
+ #: classes/core/class-wc-order-export-data-extractor-ui.php:717
1125
  msgid "Postcode (Billing)"
1126
  msgstr ""
1127
 
1128
+ #: classes/core/class-wc-order-export-data-extractor-ui.php:722
1129
  msgid "Country Code (Billing)"
1130
  msgstr ""
1131
 
1132
+ #: classes/core/class-wc-order-export-data-extractor-ui.php:727
1133
  msgid "Country Name (Billing)"
1134
  msgstr ""
1135
 
1136
+ #: classes/core/class-wc-order-export-data-extractor-ui.php:732
1137
  msgid "Email (Billing)"
1138
  msgstr ""
1139
 
1140
+ #: classes/core/class-wc-order-export-data-extractor-ui.php:737
1141
  msgid "Phone (Billing)"
1142
  msgstr ""
1143
 
1144
+ #: classes/core/class-wc-order-export-data-extractor-ui.php:747
1145
  msgid "First Name (Shipping)"
1146
  msgstr ""
1147
 
1148
+ #: classes/core/class-wc-order-export-data-extractor-ui.php:752
1149
  msgid "Last Name (Shipping)"
1150
  msgstr ""
1151
 
1152
+ #: classes/core/class-wc-order-export-data-extractor-ui.php:757
1153
  msgid "Full Name (Shipping)"
1154
  msgstr ""
1155
 
1156
+ #: classes/core/class-wc-order-export-data-extractor-ui.php:762
1157
  msgid "Company (Shipping)"
1158
  msgstr ""
1159
 
1160
+ #: classes/core/class-wc-order-export-data-extractor-ui.php:767
1161
  msgid "Address 1&2 (Shipping)"
1162
  msgstr ""
1163
 
1164
+ #: classes/core/class-wc-order-export-data-extractor-ui.php:772
1165
  msgid "Address 1 (Shipping)"
1166
  msgstr ""
1167
 
1168
+ #: classes/core/class-wc-order-export-data-extractor-ui.php:777
1169
  msgid "Address 2 (Shipping)"
1170
  msgstr ""
1171
 
1172
+ #: classes/core/class-wc-order-export-data-extractor-ui.php:782
1173
  msgid "City (Shipping)"
1174
  msgstr ""
1175
 
1176
+ #: classes/core/class-wc-order-export-data-extractor-ui.php:787
1177
  msgid "State Code (Shipping)"
1178
  msgstr ""
1179
 
1180
+ #: classes/core/class-wc-order-export-data-extractor-ui.php:792
1181
  msgid "City, State, Zip (Shipping)"
1182
  msgstr ""
1183
 
1184
+ #: classes/core/class-wc-order-export-data-extractor-ui.php:797
1185
  msgid "State Name (Shipping)"
1186
  msgstr ""
1187
 
1188
+ #: classes/core/class-wc-order-export-data-extractor-ui.php:802
1189
  msgid "Postcode (Shipping)"
1190
  msgstr ""
1191
 
1192
+ #: classes/core/class-wc-order-export-data-extractor-ui.php:807
1193
  msgid "Country Code (Shipping)"
1194
  msgstr ""
1195
 
1196
+ #: classes/core/class-wc-order-export-data-extractor-ui.php:812
1197
  msgid "Country Name (Shipping)"
1198
  msgstr ""
1199
 
1200
+ #: classes/core/class-wc-order-export-data-extractor-ui.php:823
1201
+ #: classes/core/class-wc-order-export-data-extractor-ui.php:1018
1202
  msgid "Products"
1203
  msgstr ""
1204
 
1205
+ #: classes/core/class-wc-order-export-data-extractor-ui.php:846
1206
  msgid "Shipping Method Title"
1207
  msgstr ""
1208
 
1209
+ #: classes/core/class-wc-order-export-data-extractor-ui.php:851
1210
  msgid "Shipping Method"
1211
  msgstr ""
1212
 
1213
+ #: classes/core/class-wc-order-export-data-extractor-ui.php:856
1214
  msgid "Payment Method Title"
1215
  msgstr ""
1216
 
1217
+ #: classes/core/class-wc-order-export-data-extractor-ui.php:861
1218
  msgid "Payment Method"
1219
  msgstr ""
1220
 
1221
+ #: classes/core/class-wc-order-export-data-extractor-ui.php:866
1222
  msgid "Coupons Used"
1223
  msgstr ""
1224
 
1225
+ #: classes/core/class-wc-order-export-data-extractor-ui.php:871
1226
  msgid "Cart Discount Amount"
1227
  msgstr ""
1228
 
1229
+ #: classes/core/class-wc-order-export-data-extractor-ui.php:876
1230
  msgid "Cart Discount Amount Tax"
1231
  msgstr ""
1232
 
1233
+ #: classes/core/class-wc-order-export-data-extractor-ui.php:881
1234
  msgid "Order Subtotal Amount"
1235
  msgstr ""
1236
 
1237
+ #: classes/core/class-wc-order-export-data-extractor-ui.php:891
1238
  msgid "Order Subtotal Amount Refunded"
1239
  msgstr ""
1240
 
1241
+ #: classes/core/class-wc-order-export-data-extractor-ui.php:896
1242
  msgid "Order Subtotal Amount (- Refund)"
1243
  msgstr ""
1244
 
1245
+ #: classes/core/class-wc-order-export-data-extractor-ui.php:901
1246
  msgid "Order Tax Amount"
1247
  msgstr ""
1248
 
1249
+ #: classes/core/class-wc-order-export-data-extractor-ui.php:906
1250
  msgid "Order Shipping Amount"
1251
  msgstr ""
1252
 
1253
+ #: classes/core/class-wc-order-export-data-extractor-ui.php:911
1254
  msgid "Order Shipping Amount Refunded"
1255
  msgstr ""
1256
 
1257
+ #: classes/core/class-wc-order-export-data-extractor-ui.php:916
1258
  msgid "Order Shipping Amount (- Refund)"
1259
  msgstr ""
1260
 
1261
+ #: classes/core/class-wc-order-export-data-extractor-ui.php:921
1262
  msgid "Order Shipping Tax Amount"
1263
  msgstr ""
1264
 
1265
+ #: classes/core/class-wc-order-export-data-extractor-ui.php:926
1266
  msgid "Order Shipping Tax Refunded"
1267
  msgstr ""
1268
 
1269
+ #: classes/core/class-wc-order-export-data-extractor-ui.php:931
1270
  msgid "Order Shipping Tax Amount (- Refund)"
1271
  msgstr ""
1272
 
1273
+ #: classes/core/class-wc-order-export-data-extractor-ui.php:936
1274
  msgid "Order Refund Amount"
1275
  msgstr ""
1276
 
1277
+ #: classes/core/class-wc-order-export-data-extractor-ui.php:941
1278
  msgid "Order Total Amount (- Refund)"
1279
  msgstr ""
1280
 
1281
+ #: classes/core/class-wc-order-export-data-extractor-ui.php:946
1282
  msgid "Order Total Amount"
1283
  msgstr ""
1284
 
1285
+ #: classes/core/class-wc-order-export-data-extractor-ui.php:951
1286
  msgid "Order Total Amount without Tax"
1287
  msgstr ""
1288
 
1289
+ #: classes/core/class-wc-order-export-data-extractor-ui.php:956
1290
  msgid "Order Total Tax Amount"
1291
  msgstr ""
1292
 
1293
+ #: classes/core/class-wc-order-export-data-extractor-ui.php:961
1294
  msgid "Order Total Tax Amount Refunded"
1295
  msgstr ""
1296
 
1297
+ #: classes/core/class-wc-order-export-data-extractor-ui.php:966
1298
  msgid "Order Total Tax Amount (- Refund)"
1299
  msgstr ""
1300
 
1301
+ #: classes/core/class-wc-order-export-data-extractor-ui.php:971
1302
  msgid "Currency"
1303
  msgstr ""
1304
 
1305
+ #: classes/core/class-wc-order-export-data-extractor-ui.php:981
1306
  msgid "Total weight"
1307
  msgstr ""
1308
 
1309
+ #: classes/core/class-wc-order-export-data-extractor-ui.php:986
1310
  msgid "Total items"
1311
  msgstr ""
1312
 
1313
+ #: classes/core/class-wc-order-export-data-extractor-ui.php:990
1314
+ msgid "Exported items"
1315
+ msgstr ""
1316
+
1317
+ #: classes/core/class-wc-order-export-data-extractor-ui.php:994
1318
  msgid "Total products"
1319
  msgstr ""
1320
 
1321
+ #: classes/core/class-wc-order-export-data-extractor-ui.php:1014
1322
  msgid "Common"
1323
  msgstr ""
1324
 
1325
+ #: classes/core/class-wc-order-export-data-extractor-ui.php:1015
1326
  msgid "User"
1327
  msgstr ""
1328
 
1329
+ #: classes/core/class-wc-order-export-data-extractor-ui.php:1016
1330
  msgid "Billing"
1331
  msgstr ""
1332
 
1333
+ #: classes/core/class-wc-order-export-data-extractor-ui.php:1017
1334
  msgid "Shipping"
1335
  msgstr ""
1336
 
1337
+ #: classes/core/class-wc-order-export-data-extractor-ui.php:1020
1338
  msgid "Cart"
1339
  msgstr ""
1340
 
1341
+ #: classes/core/class-wc-order-export-data-extractor-ui.php:1021
1342
  msgid "Others"
1343
  msgstr ""
1344
 
1345
+ #: classes/core/class-wc-order-export-data-extractor.php:2101
1346
  msgid "[Rest of the World]"
1347
  msgstr ""
1348
 
1349
+ #: classes/core/class-wc-order-export-engine.php:19
1350
+ #: classes/core/class-wc-order-export-engine.php:60
1351
  msgid "No destination selected"
1352
  msgstr ""
1353
 
1354
+ #: classes/core/class-wc-order-export-engine.php:29
1355
  msgid "Wrong format"
1356
  msgstr ""
1357
 
1358
+ #: classes/core/class-wc-order-export-engine.php:70
1359
  msgid "Wrong export type"
1360
  msgstr ""
1361
 
1362
+ #: classes/core/class-wc-order-export-engine.php:398
1363
  msgid "Don't Panic"
1364
  msgstr ""
1365
 
1366
+ #: classes/core/class-wc-order-export-engine.php:399
1367
  #, php-format
1368
  msgid "The code you are trying to save produced a fatal error on line %d:"
1369
  msgstr ""
1370
 
1371
+ #: classes/core/class-wc-order-export-engine.php:533
1372
  msgid "Main SQL queries are listed below"
1373
  msgstr ""
1374
 
1375
+ #: classes/core/class-wc-order-export-engine.php:795
1376
  msgid "Total Quantity"
1377
  msgstr ""
1378
 
1379
+ #: classes/core/class-wc-order-export-engine.php:796
1380
  msgid "Total Amount"
1381
  msgstr ""
1382
 
readme.txt CHANGED
@@ -5,7 +5,7 @@ Tags: woocommerce,export,order,xls,csv,xml,woo export lite,export orders,orders
5
  Requires PHP: 5.3.0
6
  Requires at least: 4.7
7
  Tested up to: 4.9
8
- Stable tag: 1.5.5
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
@@ -103,6 +103,17 @@ Yes, you can email a request to aprokaev@gmail.com. We intensively develop this
103
 
104
  == Changelog ==
105
 
 
 
 
 
 
 
 
 
 
 
 
106
  = 1.5.5 - 2018-06-08 =
107
  * Added filter by item name
108
  * Added filter by item metadata
5
  Requires PHP: 5.3.0
6
  Requires at least: 4.7
7
  Tested up to: 4.9
8
+ Stable tag: 1.5.6
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
103
 
104
  == Changelog ==
105
 
106
+ = 1.5.6 - 2018-08-30 =
107
+ * Added filter by user custom fields
108
+ * Added order fields "Count of exported items", "User Website"
109
+ * Added product fields "Product Id", "Variation Id", "Order Line Subtotal Tax"
110
+ * Multiple custom fields with same title are exported as list (for order)
111
+ * Format Shipping/Billing fields as string (Excel only)
112
+ * Fixed compatibility issue with WP Redis cache
113
+ * Fixed bug - "Progressbar" shows error message correctly
114
+ * Fixed bug - "Progressbar" doesn't miss orders if both "Mark exported" and "Export unmarked only" are ON
115
+ * Reduced memory footprint (options are not autoloaded)
116
+
117
  = 1.5.5 - 2018-06-08 =
118
  * Added filter by item name
119
  * Added filter by item metadata
view/settings-form.php CHANGED
@@ -294,7 +294,14 @@ $readonly_php = WC_Order_Export_Admin::user_can_add_custom_php() ? '' : 'readonl
294
  <div>
295
  <input type="hidden" name="settings[custom_php]" value="0"/>
296
  <label><input type="checkbox" name="settings[custom_php]" value="1" <?php checked($settings['custom_php']) ?>/><?php _e( 'Custom PHP code to modify output', 'woo-order-export-lite' ) ?></label>
297
- <textarea placeholder="<?php _e( 'Use only unnamed functions!', 'woo-order-export-lite' ) ?>" name="settings[custom_php_code]" <?php echo $readonly_php?> class="width-100" rows="10" <?php echo $settings['custom_php'] ? '' : 'style="display: none"' ?>><?php echo $settings['custom_php_code'] ?></textarea>
 
 
 
 
 
 
 
298
  </div>
299
  </div>
300
  </div>
@@ -364,7 +371,7 @@ $readonly_php = WC_Order_Export_Admin::user_can_add_custom_php() ? '' : 'readonl
364
  <span class="my-hide-next "><?php _e( 'Filter by product', 'woo-order-export-lite' ) ?>
365
  <span class="ui-icon ui-icon-triangle-1-s my-icon-triangle"></span></span>
366
  <div id="my-products" hidden="hidden">
367
- <div><input type="hidden" name="settings[all_products_from_order]" value="0"/><label><input type="checkbox" name="settings[all_products_from_order]" value="1" <?php checked($settings[ 'all_products_from_order' ]) ?> /> <?php _e( 'Export all products from a order', 'woo-order-export-lite' ) ?></label></div>
368
  <div><input type="hidden" name="settings[skip_refunded_items]" value="0"/><label><input type="checkbox" name="settings[skip_refunded_items]" value="1" <?php checked($settings[ 'skip_refunded_items' ]) ?> /> <?php _e( 'Skip fully refunded items', 'woo-order-export-lite' ) ?></label></div>
369
  <span class="wc-oe-header"><?php _e( 'Product categories', 'woo-order-export-lite' ) ?></span>
370
  <select id="product_categories" name="settings[product_categories][]" multiple="multiple" style="width: 100%; max-width: 25%;">
@@ -525,14 +532,6 @@ $readonly_php = WC_Order_Export_Admin::user_can_add_custom_php() ? '' : 'readonl
525
  <span class="my-hide-next "><?php _e( 'Filter by customers', 'woo-order-export-lite' ) ?>
526
  <span class="ui-icon ui-icon-triangle-1-s my-icon-triangle"></span></span>
527
  <div id="my-users" hidden="hidden">
528
- <span class="wc-oe-header"><?php _e( 'User roles', 'woo-order-export-lite' ) ?></span>
529
- <select id="user_roles" name="settings[user_roles][]" multiple="multiple" style="width: 100%; max-width: 25%;">
530
- <?php
531
- global $wp_roles;
532
- foreach ( $wp_roles->role_names as $k => $v ) { ?>
533
- <option value="<?php echo $k ?>" <?php echo ( in_array($k, $settings[ 'user_roles' ] ) ? selected(true) : '') ?>> <?php echo $v ?></option>
534
- <?php } ?>
535
- </select>
536
 
537
  <span class="wc-oe-header"><?php _e( 'Usernames', 'woo-order-export-lite' ) ?></span>
538
  <select id="user_names" name="settings[user_names][]" multiple="multiple" style="width: 100%; max-width: 25%;">
@@ -544,6 +543,47 @@ $readonly_php = WC_Order_Export_Admin::user_can_add_custom_php() ? '' : 'readonl
544
  <option selected value="<?php echo $user_id ?>"> <?php echo $user->display_name; ?></option>
545
  <?php } ?>
546
  </select>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
547
  </div>
548
  </div>
549
 
294
  <div>
295
  <input type="hidden" name="settings[custom_php]" value="0"/>
296
  <label><input type="checkbox" name="settings[custom_php]" value="1" <?php checked($settings['custom_php']) ?>/><?php _e( 'Custom PHP code to modify output', 'woo-order-export-lite' ) ?></label>
297
+ <div id="custom_php_code_textarea" <?php echo $settings['custom_php'] ? '' : 'style="display: none"' ?>>
298
+ <?php if ($readonly_php == 'readonly'):?>
299
+ <strong>
300
+ <?php _e('Please check permissions for your role. You must have capability “edit_themes” to use this box.', 'woo-order-export-lite');?>
301
+ </strong>
302
+ <?php endif; ?>
303
+ <textarea placeholder="<?php _e( 'Use only unnamed functions!', 'woo-order-export-lite' ) ?>" name="settings[custom_php_code]" <?php echo $readonly_php?> class="width-100" rows="10" ><?php echo $settings['custom_php_code'] ?></textarea>
304
+ </div>
305
  </div>
306
  </div>
307
  </div>
371
  <span class="my-hide-next "><?php _e( 'Filter by product', 'woo-order-export-lite' ) ?>
372
  <span class="ui-icon ui-icon-triangle-1-s my-icon-triangle"></span></span>
373
  <div id="my-products" hidden="hidden">
374
+ <div><input type="hidden" name="settings[all_products_from_order]" value="0"/><label><input type="checkbox" name="settings[all_products_from_order]" value="1" <?php checked($settings[ 'all_products_from_order' ]) ?> /> <?php _e( 'Export all products from the order', 'woo-order-export-lite' ) ?></label></div>
375
  <div><input type="hidden" name="settings[skip_refunded_items]" value="0"/><label><input type="checkbox" name="settings[skip_refunded_items]" value="1" <?php checked($settings[ 'skip_refunded_items' ]) ?> /> <?php _e( 'Skip fully refunded items', 'woo-order-export-lite' ) ?></label></div>
376
  <span class="wc-oe-header"><?php _e( 'Product categories', 'woo-order-export-lite' ) ?></span>
377
  <select id="product_categories" name="settings[product_categories][]" multiple="multiple" style="width: 100%; max-width: 25%;">
532
  <span class="my-hide-next "><?php _e( 'Filter by customers', 'woo-order-export-lite' ) ?>
533
  <span class="ui-icon ui-icon-triangle-1-s my-icon-triangle"></span></span>
534
  <div id="my-users" hidden="hidden">
 
 
 
 
 
 
 
 
535
 
536
  <span class="wc-oe-header"><?php _e( 'Usernames', 'woo-order-export-lite' ) ?></span>
537
  <select id="user_names" name="settings[user_names][]" multiple="multiple" style="width: 100%; max-width: 25%;">
543
  <option selected value="<?php echo $user_id ?>"> <?php echo $user->display_name; ?></option>
544
  <?php } ?>
545
  </select>
546
+
547
+ <span class="wc-oe-header"><?php _e( 'User roles', 'woo-order-export-lite' ) ?></span>
548
+ <select id="user_roles" name="settings[user_roles][]" multiple="multiple" style="width: 100%; max-width: 25%;">
549
+ <?php
550
+ global $wp_roles;
551
+ foreach ( $wp_roles->role_names as $k => $v ) { ?>
552
+ <option value="<?php echo $k ?>" <?php echo ( in_array($k, $settings[ 'user_roles' ] ) ? selected(true) : '') ?>> <?php echo $v ?></option>
553
+ <?php } ?>
554
+ </select>
555
+
556
+ <span class="wc-oe-header"><?php _e( 'Custom fields', 'woo-order-export-lite' ) ?></span>
557
+ <br>
558
+ <select id="user_custom_fields" style="width: auto;">
559
+ <?php foreach ( WC_Order_Export_Data_Extractor_UI::get_user_custom_fields() as $cf_name ) { ?>
560
+ <option><?php echo $cf_name; ?></option>
561
+ <?php } ?>
562
+ </select>
563
+ <select id="user_custom_fields_compare" class="select_compare">
564
+ <option>=</option>
565
+ <option>&lt;&gt;</option>
566
+ <option>LIKE</option>
567
+ <option>&gt;</option>
568
+ <option>&gt;=</option>
569
+ <option>&lt;</option>
570
+ <option>&lt;=</option>
571
+ <option>NOT SET</option>
572
+ <option>IS SET</option>
573
+ </select>
574
+
575
+ <input type="text" id="text_user_custom_fields" disabled class="like-input" style="display: none;">
576
+
577
+ <button id="add_user_custom_fields" class="button-secondary"><span class="dashicons dashicons-plus-alt"></span></button>
578
+ <br>
579
+ <select id="user_custom_fields_check" multiple name="settings[user_custom_fields][]" style="width: 100%; max-width: 25%;">
580
+ <?php
581
+ if ( $settings[ 'user_custom_fields' ] )
582
+ foreach ( $settings[ 'user_custom_fields' ] as $value ) {
583
+ ?>
584
+ <option selected value="<?php echo $value; ?>"> <?php echo $value; ?></option>
585
+ <?php } ?>
586
+ </select>
587
  </div>
588
  </div>
589
 
woo-order-export-lite.php CHANGED
@@ -5,7 +5,7 @@
5
  * Description: Export orders from WooCommerce with ease (Excel/CSV/XML/JSON supported)
6
  * Author: AlgolPlus
7
  * Author URI: https://algolplus.com/
8
- * Version: 1.5.5
9
  * Text Domain: woo-order-export-lite
10
  * Domain Path: /i18n/languages/
11
  * WC requires at least: 2.6.0
@@ -73,7 +73,7 @@ include 'classes/core/class-wc-order-export-engine.php';
73
  include 'classes/core/class-wc-order-export-data-extractor.php';
74
  include 'classes/core/class-wc-order-export-data-extractor-ui.php';
75
 
76
- define( 'WOE_VERSION', '1.5.5' );
77
  define( 'WOE_PLUGIN_BASENAME', plugin_basename(__FILE__) );
78
  define( 'WOE_PLUGIN_BASEPATH', dirname(__FILE__) );
79
  $wc_order_export = new WC_Order_Export_Admin();
5
  * Description: Export orders from WooCommerce with ease (Excel/CSV/XML/JSON supported)
6
  * Author: AlgolPlus
7
  * Author URI: https://algolplus.com/
8
+ * Version: 1.5.6
9
  * Text Domain: woo-order-export-lite
10
  * Domain Path: /i18n/languages/
11
  * WC requires at least: 2.6.0
73
  include 'classes/core/class-wc-order-export-data-extractor.php';
74
  include 'classes/core/class-wc-order-export-data-extractor-ui.php';
75
 
76
+ define( 'WOE_VERSION', '1.5.6' );
77
  define( 'WOE_PLUGIN_BASENAME', plugin_basename(__FILE__) );
78
  define( 'WOE_PLUGIN_BASEPATH', dirname(__FILE__) );
79
  $wc_order_export = new WC_Order_Export_Admin();