Advanced Order Export For WooCommerce - Version 2.0.1

Version Description

  • 2018-11-14 =
  • Fixed bug - "total weight" and "count of unique products" were empty
  • Fixed bug - message "wrong Select2 loaded"
  • Fixed bug - UI issues after switching formats (CSV-XML-CSV)
  • Shows some instructions if user gets popup with empty error message
  • Shows warning if XML can not be built (PHP extension is not installed)
Download this release

Release Info

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

Code changes from version 2.0.0 to 2.0.1

assets/css/export.css CHANGED
@@ -583,13 +583,15 @@ input.date{
583
}
584
585
#d-schedule-3 .block,
586
- #d-schedule-4 .block {
587
margin-left: 20px;
588
margin-right: 5px;
589
}
590
591
#d-schedule-3 .block.disabled,
592
- #d-schedule-4 .block.disabled {
593
pointer-events: none;
594
opacity: 0.7;
595
}
583
}
584
585
#d-schedule-3 .block,
586
+ #d-schedule-4 .block,
587
+ #d-schedule-5 .block {
588
margin-left: 20px;
589
margin-right: 5px;
590
}
591
592
#d-schedule-3 .block.disabled,
593
+ #d-schedule-4 .block.disabled,
594
+ #d-schedule-5 .block.disabled {
595
pointer-events: none;
596
opacity: 0.7;
597
}
assets/js/settings-form.js CHANGED
@@ -155,42 +155,47 @@ jQuery( document ).ready( function( $ ) {
155
}
156
157
158
- $( '#schedule-1,#schedule-2,#schedule-3,#schedule-4' ).change( function() {
159
if ( $( '#schedule-1' ).is( ':checked' ) && $( '#schedule-1' ).val() == 'schedule-1' ) {
160
$( '#d-schedule-2 input:not(input[type=radio])' ).attr( 'disabled', true )
161
$( '#d-schedule-2 select' ).attr( 'disabled', true )
162
$( '#d-schedule-1 input:not(input[type=radio])' ).attr( 'disabled', false )
163
$( '#d-schedule-1 select' ).attr( 'disabled', false )
164
$( '#d-schedule-3 .block' ).addClass( 'disabled' );
165
- $( '#d-schedule-4 .block' ).addClass( 'disabled' );
166
} else if( $( '#schedule-2' ).is( ':checked' ) && $( '#schedule-2' ).val() == 'schedule-2' ) {
167
$( '#d-schedule-1 input:not(input[type=radio])' ).attr( 'disabled', true )
168
$( '#d-schedule-1 select' ).attr( 'disabled', true )
169
$( '#d-schedule-2 select' ).attr( 'disabled', false )
170
$( '#d-schedule-2 input:not(input[type=radio]) ' ).attr( 'disabled', false )
171
$( '#d-schedule-3 .block' ).addClass( 'disabled' );
172
- $( '#d-schedule-4 .block' ).addClass( 'disabled' );
173
} else if( $( '#schedule-3' ).is( ':checked' ) && $( '#schedule-3' ).val() == 'schedule-3' ) {
174
$( '#d-schedule-1 input:not(input[type=radio])' ).attr( 'disabled', true )
175
$( '#d-schedule-1 select' ).attr( 'disabled', true )
176
-
177
$( '#d-schedule-2 input:not(input[type=radio])' ).attr( 'disabled', true )
178
$( '#d-schedule-2 select' ).attr( 'disabled', true )
179
-
180
$( '#d-schedule-3 .block' ).removeClass( 'disabled' );
181
-
182
- $( '#d-schedule-4 .block' ).addClass( 'disabled' );
183
} else if( $( '#schedule-4' ).is( ':checked' ) && $( '#schedule-4' ).val() == 'schedule-4' ) {
184
-
185
- $( '#d-schedule-1 input:not(input[type=radio])' ).attr( 'disabled', true )
186
$( '#d-schedule-1 select' ).attr( 'disabled', true )
187
-
188
$( '#d-schedule-2 input:not(input[type=radio])' ).attr( 'disabled', true )
189
$( '#d-schedule-2 select' ).attr( 'disabled', true )
190
-
191
- $( '#d-schedule-3 .block' ).addClass( 'disabled' );
192
-
193
$( '#d-schedule-4 .block' ).removeClass( 'disabled' );
194
}
195
} );
196
$( '#schedule-1' ).change()
@@ -290,7 +295,8 @@ jQuery( document ).ready( function( $ ) {
290
if (window.location.hash.indexOf('segment') !== -1) {
291
$('.segment_choice[href="'+ window.location.hash +'"]').click()
292
} else {
293
- $('.segment_choice').first().click()
294
}
295
}, 1000 );
296
@@ -334,7 +340,8 @@ function make_repeat_options( index ) {
334
});
335
336
var duplicate_settings = window.duplicated_fields_settings[index] || {};
337
- repeat_select.val(duplicate_settings.repeat);
338
339
// rows options
340
if ( index === 'products' ) {
@@ -813,12 +820,16 @@ jQuery( document ).ready( function( $ ) {
813
var data = 'json=' + makeJsonVar( $( '#export_job_settings' ) );
814
var estimate_data = data + "&action=order_exporter&method=estimate&mode=" + mode + "&id=" + job_id;
815
$.post( ajaxurl, estimate_data, function( response ) {
816
- if ( response.total !== undefined ) {
817
- jQuery( '#output_preview_total' ).find( 'span' ).html( response.total );
818
- jQuery( '#preview_actions' ).removeClass( 'hide' );
819
}
820
}, "json"
821
- );
822
823
function showPreview( response ) {
824
var id = 'output_preview';
@@ -889,12 +900,14 @@ jQuery( document ).ready( function( $ ) {
889
url: ajaxurl,
890
dataType: "json",
891
error: function( xhr, status, error ) {
892
- alert( xhr.responseText );
893
progress( 100, jQuery( '#progressBar' ) );
894
},
895
success: function( response ) {
896
- if ( typeof response.error !== 'undefined') {
897
- alert( response.error );
898
} else {
899
get_all( response.start, ( response.start / window.count ) * 100, method )
900
}
@@ -1052,9 +1065,13 @@ jQuery( document ).ready( function( $ ) {
1052
url: ajaxurl,
1053
dataType: "json",
1054
error: function( xhr, status, error ) {
1055
- alert( xhr.responseText.replace(/<\/?[^>]+(>|$)/g, "") );
1056
},
1057
success: function( response ) {
1058
window.count = response['total'];
1059
window.file_id = response['file_id'];
1060
console.log( window.count );
@@ -1177,8 +1194,12 @@ jQuery( document ).ready( function( $ ) {
1177
1178
// show product fields starts with 'line' and 'qty'
1179
$( '#products_unselected_segment input, #order_fields input' ).map( function () {
1180
- var matches = $( this ).attr( 'value' ).match( /plain_products_(line|qty).*/ );
1181
- if ( matches ) {
1182
$( this ).closest( '.mapping_row' ).show();
1183
}
1184
} );
@@ -1640,4 +1661,10 @@ function synch_selected_fields (old_format, new_format) {
1640
return;
1641
}
1642
1643
}
155
}
156
157
158
+ $( '#schedule-1,#schedule-2,#schedule-3,#schedule-4,#schedule-5' ).change( function() {
159
if ( $( '#schedule-1' ).is( ':checked' ) && $( '#schedule-1' ).val() == 'schedule-1' ) {
160
$( '#d-schedule-2 input:not(input[type=radio])' ).attr( 'disabled', true )
161
$( '#d-schedule-2 select' ).attr( 'disabled', true )
162
$( '#d-schedule-1 input:not(input[type=radio])' ).attr( 'disabled', false )
163
$( '#d-schedule-1 select' ).attr( 'disabled', false )
164
$( '#d-schedule-3 .block' ).addClass( 'disabled' );
165
+ $( '#d-schedule-4 .block' ).addClass( 'disabled' );
166
+ $( '#d-schedule-5 .block' ).addClass( 'disabled' );
167
} else if( $( '#schedule-2' ).is( ':checked' ) && $( '#schedule-2' ).val() == 'schedule-2' ) {
168
$( '#d-schedule-1 input:not(input[type=radio])' ).attr( 'disabled', true )
169
$( '#d-schedule-1 select' ).attr( 'disabled', true )
170
$( '#d-schedule-2 select' ).attr( 'disabled', false )
171
$( '#d-schedule-2 input:not(input[type=radio]) ' ).attr( 'disabled', false )
172
$( '#d-schedule-3 .block' ).addClass( 'disabled' );
173
+ $( '#d-schedule-4 .block' ).addClass( 'disabled' );
174
+ $( '#d-schedule-5 .block' ).addClass( 'disabled' );
175
} else if( $( '#schedule-3' ).is( ':checked' ) && $( '#schedule-3' ).val() == 'schedule-3' ) {
176
$( '#d-schedule-1 input:not(input[type=radio])' ).attr( 'disabled', true )
177
$( '#d-schedule-1 select' ).attr( 'disabled', true )
178
$( '#d-schedule-2 input:not(input[type=radio])' ).attr( 'disabled', true )
179
$( '#d-schedule-2 select' ).attr( 'disabled', true )
180
$( '#d-schedule-3 .block' ).removeClass( 'disabled' );
181
+ $( '#d-schedule-4 .block' ).addClass( 'disabled' );
182
+ $( '#d-schedule-5 .block' ).addClass( 'disabled' );
183
} else if( $( '#schedule-4' ).is( ':checked' ) && $( '#schedule-4' ).val() == 'schedule-4' ) {
184
+ $( '#d-schedule-1 input:not(input[type=radio])' ).attr( 'disabled', true )
185
$( '#d-schedule-1 select' ).attr( 'disabled', true )
186
$( '#d-schedule-2 input:not(input[type=radio])' ).attr( 'disabled', true )
187
$( '#d-schedule-2 select' ).attr( 'disabled', true )
188
+ $( '#d-schedule-3 .block' ).addClass( 'disabled' );
189
$( '#d-schedule-4 .block' ).removeClass( 'disabled' );
190
+ $( '#d-schedule-5 .block' ).addClass( 'disabled' );
191
+ } else if( $( '#schedule-5' ).is( ':checked' ) && $( '#schedule-5' ).val() == 'schedule-5' ) {
192
+ $( '#d-schedule-1 input:not(input[type=radio])' ).attr( 'disabled', true )
193
+ $( '#d-schedule-1 select' ).attr( 'disabled', true )
194
+ $( '#d-schedule-2 input:not(input[type=radio])' ).attr( 'disabled', true )
195
+ $( '#d-schedule-2 select' ).attr( 'disabled', true )
196
+ $( '#d-schedule-3 .block' ).addClass( 'disabled' );
197
+ $( '#d-schedule-4 .block' ).addClass( 'disabled' );
198
+ $( '#d-schedule-5 .block' ).removeClass( 'disabled' );
199
}
200
} );
201
$( '#schedule-1' ).change()
295
if (window.location.hash.indexOf('segment') !== -1) {
296
$('.segment_choice[href="'+ window.location.hash +'"]').click()
297
} else {
298
+ $('.segment_choice').first().addClass('active');
299
+ $('.settings-segment').first().addClass('active');
300
}
301
}, 1000 );
302
340
});
341
342
var duplicate_settings = window.duplicated_fields_settings[index] || {};
343
+ var repeat_value = ( typeof( duplicate_settings.repeat ) !== 'undefined' ) ? duplicate_settings.repeat : "rows";
344
+ repeat_select.val( repeat_value );
345
346
// rows options
347
if ( index === 'products' ) {
820
var data = 'json=' + makeJsonVar( $( '#export_job_settings' ) );
821
var estimate_data = data + "&action=order_exporter&method=estimate&mode=" + mode + "&id=" + job_id;
822
$.post( ajaxurl, estimate_data, function( response ) {
823
+ if (!response || typeof response.total == 'undefined') {
824
+ woe_show_error_message(response);
825
+ return;
826
}
827
+ jQuery( '#output_preview_total' ).find( 'span' ).html( response.total );
828
+ jQuery( '#preview_actions' ).removeClass( 'hide' );
829
}, "json"
830
+ ).fail( function( xhr, textStatus, errorThrown ) {
831
+ woe_show_error_message( xhr.responseText );
832
+ });
833
834
function showPreview( response ) {
835
var id = 'output_preview';
900
url: ajaxurl,
901
dataType: "json",
902
error: function( xhr, status, error ) {
903
+ woe_show_error_message( xhr.responseText );
904
progress( 100, jQuery( '#progressBar' ) );
905
},
906
success: function( response ) {
907
+ if ( !response) {
908
+ woe_show_error_message(response);
909
+ } else if ( typeof response.error !== 'undefined') {
910
+ woe_show_error_message( response.error );
911
} else {
912
get_all( response.start, ( response.start / window.count ) * 100, method )
913
}
1065
url: ajaxurl,
1066
dataType: "json",
1067
error: function( xhr, status, error ) {
1068
+ woe_show_error_message( xhr.responseText.replace(/<\/?[^>]+(>|$)/g, "") );
1069
},
1070
success: function( response ) {
1071
+ if (!response || typeof response['total'] == 'undefined') {
1072
+ woe_show_error_message(response);
1073
+ return;
1074
+ }
1075
window.count = response['total'];
1076
window.file_id = response['file_id'];
1077
console.log( window.count );
1194
1195
// show product fields starts with 'line' and 'qty'
1196
$( '#products_unselected_segment input, #order_fields input' ).map( function () {
1197
+ var $value = $( this ).attr( 'value' );
1198
+ if ( typeof $value === 'undefined' ) {
1199
+ return;
1200
+ }
1201
+
1202
+ if ( $value.match( /plain_products_(line|qty).*/ ) ) {
1203
$( this ).closest( '.mapping_row' ).show();
1204
}
1205
} );
1661
return;
1662
}
1663
1664
+ }
1665
+
1666
+ function woe_show_error_message(text) {
1667
+ if (!text)
1668
+ text = "Please, open section 'Misc Settings' and \n mark checkbox 'Enable debug output' \n to see exact error message";
1669
+ alert(text);
1670
}
classes/admin/class-wc-order-export-labels.php CHANGED
@@ -8,8 +8,8 @@ class WC_Order_Export_Labels {
8
9
private $labels;
10
11
- public function __get($key) {
12
- if ( ! $key || empty($this->labels) ) {
13
return false;
14
}
15
@@ -22,8 +22,8 @@ class WC_Order_Export_Labels {
22
return false;
23
}
24
25
- public function __isset($key) {
26
- if ( ! $key || empty($this->labels) ) {
27
return false;
28
}
29
@@ -36,18 +36,18 @@ class WC_Order_Export_Labels {
36
return false;
37
}
38
39
- public function __unset($key) {
40
- if ( ! $key || empty($this->labels) ) {
41
return false;
42
}
43
44
foreach ( $this->labels as $num_index => $label_data ) {
45
if ( $label_data['key'] === $key || $label_data['parent_key'] === $key ) {
46
- unset($this->labels[$num_index]);
47
}
48
}
49
50
- $this->labels = array_values($this->labels);
51
}
52
53
public function __set( $key, $label ) {
@@ -72,23 +72,23 @@ class WC_Order_Export_Labels {
72
}
73
74
public function get_keys() {
75
- return array_map( function($label_data) {
76
return $label_data['key'];
77
}, $this->labels );
78
}
79
80
public function is_not_empty() {
81
- return (boolean)$this->labels;
82
}
83
84
public function to_Array() {
85
return array_combine(
86
- array_map(function ($label_data){
87
return $label_data['key'];
88
- }, $this->labels),
89
- array_map(function ($label_data){
90
return $label_data['label'];
91
- }, $this->labels)
92
);
93
}
94
@@ -103,7 +103,7 @@ class WC_Order_Export_Labels {
103
return $unique_keys;
104
}
105
106
- public function get_childs($key) {
107
$child_labels = array();
108
foreach ( $this->labels as $label_data ) {
109
if ( $label_data['parent_key'] == $key ) {
@@ -114,7 +114,7 @@ class WC_Order_Export_Labels {
114
return $child_labels;
115
}
116
117
- public function get_parent($key) {
118
foreach ( $this->labels as $label_data ) {
119
if ( $label_data['key'] == $key ) {
120
return $label_data['parent_key'];
@@ -124,8 +124,8 @@ class WC_Order_Export_Labels {
124
return false;
125
}
126
127
- public function replace_label($key, $new_label) {
128
- if ( ! $key || empty($this->labels) ) {
129
return;
130
}
131
@@ -136,7 +136,7 @@ class WC_Order_Export_Labels {
136
}
137
}
138
139
- public function get_labels(){
140
return $this->labels;
141
}
142
@@ -151,7 +151,7 @@ class WC_Order_Export_Labels {
151
152
return $fetch_fields;
153
}
154
-
155
public function get_legacy_labels() {
156
$unique_keys = array();
157
foreach ( $this->labels as $label_data ) {
@@ -161,5 +161,5 @@ class WC_Order_Export_Labels {
161
}
162
163
return $unique_keys;
164
- }
165
}
8
9
private $labels;
10
11
+ public function __get( $key ) {
12
+ if ( ! $key || empty( $this->labels ) ) {
13
return false;
14
}
15
22
return false;
23
}
24
25
+ public function __isset( $key ) {
26
+ if ( ! $key || empty( $this->labels ) ) {
27
return false;
28
}
29
36
return false;
37
}
38
39
+ public function __unset( $key ) {
40
+ if ( ! $key || empty( $this->labels ) ) {
41
return false;
42
}
43
44
foreach ( $this->labels as $num_index => $label_data ) {
45
if ( $label_data['key'] === $key || $label_data['parent_key'] === $key ) {
46
+ unset( $this->labels[ $num_index ] );
47
}
48
}
49
50
+ $this->labels = array_values( $this->labels );
51
}
52
53
public function __set( $key, $label ) {
72
}
73
74
public function get_keys() {
75
+ return array_map( function ( $label_data ) {
76
return $label_data['key'];
77
}, $this->labels );
78
}
79
80
public function is_not_empty() {
81
+ return (boolean) $this->labels;
82
}
83
84
public function to_Array() {
85
return array_combine(
86
+ array_map( function ( $label_data ) {
87
return $label_data['key'];
88
+ }, $this->labels ),
89
+ array_map( function ( $label_data ) {
90
return $label_data['label'];
91
+ }, $this->labels )
92
);
93
}
94
103
return $unique_keys;
104
}
105
106
+ public function get_childs( $key ) {
107
$child_labels = array();
108
foreach ( $this->labels as $label_data ) {
109
if ( $label_data['parent_key'] == $key ) {
114
return $child_labels;
115
}
116
117
+ public function get_parent( $key ) {
118
foreach ( $this->labels as $label_data ) {
119
if ( $label_data['key'] == $key ) {
120
return $label_data['parent_key'];
124
return false;
125
}
126
127
+ public function replace_label( $key, $new_label ) {
128
+ if ( ! $key || empty( $this->labels ) ) {
129
return;
130
}
131
136
}
137
}
138
139
+ public function get_labels() {
140
return $this->labels;
141
}
142
151
152
return $fetch_fields;
153
}
154
+
155
public function get_legacy_labels() {
156
$unique_keys = array();
157
foreach ( $this->labels as $label_data ) {
161
}
162
163
return $unique_keys;
164
+ }
165
}
classes/admin/class-wc-order-export-manage.php CHANGED
@@ -14,7 +14,7 @@ class WC_Order_Export_Manage {
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(
@@ -92,7 +92,7 @@ class WC_Order_Export_Manage {
92
'shipping_methods',
93
'user_roles',
94
'user_names',
95
- 'user_custom_fields',
96
'coupons',
97
'billing_locations',
98
'payment_methods',
@@ -108,8 +108,8 @@ class WC_Order_Export_Manage {
108
}
109
}
110
111
- $settings = self::get( $in['mode'], $in['id'] );
112
- $settings['id'] = $in['id'];
113
$settings['duplicated_fields_settings'] = isset( $in['duplicated_fields_settings'] ) ? $in['duplicated_fields_settings'] : array();
114
115
// setup new values for same keys
@@ -118,17 +118,17 @@ class WC_Order_Export_Manage {
118
}
119
120
$sections = array(
121
- 'orders' => 'order_fields',
122
);
123
124
$flat_formats = array( 'XLS', 'CSV', 'TSV' );
125
- if ( ! in_array($new_settings['format'], $flat_formats) ) {
126
- $sections[ 'products' ] = 'order_product_fields';
127
- $sections[ 'coupons' ] = 'order_coupon_fields';
128
}
129
130
foreach ( $sections as $section => $fieldset ) {
131
- $section_fields = isset( $in[ $section ] ) ? $in[ $section ] : array();
132
$settings[ $fieldset ] = $section_fields;
133
}
134
@@ -137,12 +137,13 @@ class WC_Order_Export_Manage {
137
138
static function get( $mode, $id = false ) {
139
140
- $all_jobs = self::get_export_settings_collection( $mode );
141
142
if ( $mode == self::EXPORT_NOW ) { // one job
143
- if ( ! isset( $all_jobs['version'] ) ) {
144
- $all_jobs = self::convert_settings_to_version_2($mode, $all_jobs);
145
- }
146
return self::apply_defaults( $mode, $all_jobs );
147
} elseif ( $id === false ) {
148
if ( empty( $all_jobs ) OR ! is_array( $all_jobs ) ) {
@@ -151,9 +152,9 @@ class WC_Order_Export_Manage {
151
152
return array_map( function ( $item ) use ( $mode ) {
153
154
- if ( ! isset( $item['version'] ) ) {
155
- $item = self::convert_settings_to_version_2($mode, $item);
156
- }
157
158
return WC_Order_Export_Manage::apply_defaults( $mode, $item );
159
}, $all_jobs );
@@ -161,90 +162,90 @@ class WC_Order_Export_Manage {
161
162
$settings = isset( $all_jobs[ $id ] ) ? $all_jobs[ $id ] : array();
163
164
- if ( ! isset( $settings['version'] ) ) {
165
- $settings = self::convert_settings_to_version_2($mode, $settings);
166
- }
167
168
return self::apply_defaults( $mode, $settings );
169
}
170
171
private static function get_defaults( $mode ) {
172
return array(
173
- 'version' => '2.0',
174
- 'mode' => $mode,
175
- 'title' => '',
176
- 'skip_empty_file' => true,
177
- 'log_results' => false,
178
- 'from_status' => array(),
179
- 'to_status' => array(),
180
- 'change_order_status_to' => '',
181
- 'statuses' => array(),
182
- 'from_date' => '',
183
- 'to_date' => '',
184
- 'shipping_locations' => array(),
185
- 'shipping_methods' => array(),
186
- 'item_names' => array(),
187
- 'item_metadata' => array(),
188
- 'user_roles' => array(),
189
- 'user_names' => array(),
190
- 'user_custom_fields' => array(),
191
- 'billing_locations' => array(),
192
- 'payment_methods' => array(),
193
- 'any_coupon_used' => 0,
194
- 'coupons' => array(),
195
- 'order_custom_fields' => array(),
196
- 'product_categories' => array(),
197
- 'product_vendors' => array(),
198
- 'products' => array(),
199
- 'product_taxonomies' => array(),
200
- 'product_custom_fields' => array(),
201
- 'product_attributes' => array(),
202
- 'product_itemmeta' => array(),
203
- 'format' => 'XLS',
204
- 'format_xls_use_xls_format' => 0,
205
- 'format_xls_sheet_name' => __( 'Orders', 'woo-order-export-lite' ),
206
- 'format_xls_display_column_names' => 1,
207
- 'format_xls_auto_width' => 1,
208
- 'format_xls_direction_rtl' => 0,
209
- 'format_csv_enclosure' => '"',
210
- 'format_csv_delimiter' => ',',
211
- 'format_csv_linebreak' => '\r\n',
212
- 'format_csv_display_column_names' => 1,
213
- 'format_csv_add_utf8_bom' => 0,
214
- 'format_csv_item_rows_start_from_new_line' => 0,
215
- 'format_csv_encoding' => 'UTF-8',
216
- 'format_csv_delete_linebreaks' => 0,
217
- 'format_tsv_linebreak' => '\r\n',
218
- 'format_tsv_display_column_names' => 1,
219
- 'format_tsv_add_utf8_bom' => 0,
220
- 'format_tsv_encoding' => 'UTF-8',
221
- 'format_xml_root_tag' => 'Orders',
222
- 'format_xml_order_tag' => 'Order',
223
- 'format_xml_product_tag' => 'Product',
224
- 'format_xml_coupon_tag' => 'Coupon',
225
- 'format_xml_prepend_raw_xml' => '',
226
- 'format_xml_append_raw_xml' => '',
227
- 'format_xml_self_closing_tags' => 1,
228
- 'all_products_from_order' => 1,
229
- 'skip_refunded_items' => 1,
230
- 'skip_suborders' => 0,
231
- 'export_refunds' => 0,
232
- 'date_format' => 'Y-m-d',
233
- 'time_format' => 'H:i',
234
- 'sort_direction' => 'DESC',
235
- 'sort' => 'order_id',
236
- 'format_number_fields' => 0,
237
- 'export_all_comments' => 0,
238
- 'export_refund_notes' => 0,
239
- 'strip_tags_product_fields' => 0,
240
- 'cleanup_phone' => 0,
241
- 'enable_debug' => 0,
242
- 'format_json_start_tag' => '[',
243
- 'format_json_end_tag' => ']',
244
- 'custom_php' => 0,
245
- 'custom_php_code' => '',
246
- 'mark_exported_orders' => 0,
247
- 'export_unmarked_orders' => 0,
248
249
'summary_report_by_products' => 0,
250
'duplicated_fields_settings' => array(
@@ -283,19 +284,19 @@ class WC_Order_Export_Manage {
283
foreach ( array( 'order_fields', 'order_product_fields', 'order_coupon_fields' ) as $index ) {
284
if ( ! isset( $settings[ $index ] ) ) {
285
$additional_fields = self::move_fields_key( self::get_default_fields( $index, $settings['format'] ) );
286
- self::remove_unchecked_fields($additional_fields);
287
$settings[ $index ] = $additional_fields;
288
if ( 'order_fields' !== $index ) {
289
$map_segment = array(
290
'order_product_fields' => 'products',
291
- 'order_coupon_fields' => 'coupons',
292
);
293
294
$settings['order_fields'] = array_merge(
295
$settings['order_fields'],
296
array_map( function ( $value ) use ( $map_segment, $index ) {
297
$value['segment'] = $map_segment[ $index ];
298
- $value['key'] = 'plain_' . $map_segment[ $index ] . '_' . $value['key'];
299
300
return $value;
301
}, $additional_fields )
@@ -307,9 +308,9 @@ class WC_Order_Export_Manage {
307
return array_merge( $defaults, $settings );
308
}
309
310
- private static function get_default_fields($index, $format) {
311
$result = array();
312
- switch ($index) {
313
case 'order_fields':
314
$result = WC_Order_Export_Data_Extractor_UI::get_order_fields( $format );
315
break;
@@ -324,15 +325,15 @@ class WC_Order_Export_Manage {
324
return $result;
325
}
326
327
- private static function remove_unchecked_fields(&$fields) {
328
foreach ( $fields as $key => $field ) {
329
- if (empty($field['checked'])){
330
- unset($fields[$key]);
331
- } elseif ( isset($field['checked']) ) {
332
- unset($fields[$key]['checked']);
333
}
334
}
335
- $fields = array_values($fields);
336
}
337
338
private static function move_fields_key( $fields ) {
@@ -348,8 +349,8 @@ class WC_Order_Export_Manage {
348
349
static function merge_settings_and_default_new( &$opt, $defaults ) {
350
351
- $opt = self::move_fields_key($opt);
352
- $defaults = self::move_fields_key($defaults);
353
354
355
foreach ( $defaults as $v ) {
@@ -396,20 +397,20 @@ class WC_Order_Export_Manage {
396
} else {
397
$method = "get_order_fields_" . $segment;
398
$filter = "woe_get_order_fields_" . $segment;
399
- }
400
-
401
if ( method_exists( 'WC_Order_Export_Data_Extractor_UI', $method ) ) {
402
// woe_get_order_fields_common filter
403
- $segment_fields = array();
404
$default_segment_fields = array_merge(
405
- WC_Order_Export_Data_Extractor_UI::$method( $format ),
406
apply_filters( $filter, array(), $format )
407
);
408
foreach ( $default_segment_fields as $key => $value ) {
409
$order_field = $value;
410
$order_field['colname'] = $value['label'];
411
$order_field['key'] = $key;
412
- $order_field['default'] = 1;
413
unset( $order_field['checked'] );
414
$segment_fields[] = $order_field;
415
}
@@ -608,205 +609,205 @@ class WC_Order_Export_Manage {
608
}
609
610
//backup only existing settings
611
- private static function backup_settings_before_version_2( $mode ){
612
- $name = self::get_settings_name_for_mode( $mode );
613
$current_settings = get_option( $name, array() );
614
- $new_settings = get_option( $name."-V1", array() );
615
// backup only once!
616
- if( !empty($current_settings) AND empty($new_settings) ) {
617
- update_option( $name."-V1", $current_settings, false );
618
}
619
}
620
-
621
- protected static function convert_settings_to_version_2 ( $mode, $settings ) {
622
-
623
- if ( ! $settings ) {
624
- return $settings;
625
- }
626
- self::backup_settings_before_version_2($mode);
627
-
628
- $flat_formats = array( 'XLS', 'CSV', 'TSV' );
629
- $is_flat_format = in_array($settings['format'], $flat_formats);
630
- $is_json_format = $settings['format'] === 'JSON';
631
-
632
- $order_fields = array();
633
- $order_coupon_fields = array();
634
- $order_product_fields = array();
635
- $duplicated_fields_settings = array();
636
-
637
- if ( ! empty($settings['order_fields']['products']['checked']) ) {
638
- if (isset($settings['order_product_fields'])) {
639
-
640
- foreach ($settings['order_product_fields'] as $key => $values) {
641
-
642
- if ( ! $values['checked'] ) {
643
- continue;
644
- }
645
-
646
- $field = array(
647
- 'key' => $key,
648
- 'label' => $values['label'],
649
- 'colname' => $values['colname'],
650
- 'format' => isset($values['format']) ? $values['format'] : 'string',
651
- );
652
-
653
- if ( $is_flat_format ) {
654
- $field['key'] = 'plain_products_' . $key;
655
- $field['segment'] = 'products';
656
- }
657
-
658
- // start FOR STATIC FIELDS
659
- if ( isset( $values['value'] ) ) {
660
- $field['value'] = $values['value'];
661
- }
662
- // end FOR STATIC FIELDS
663
-
664
-
665
- $order_product_fields[] = $field;
666
- }
667
- }
668
- } else {
669
- $order_fields[] = array(
670
- 'key' => 'products',
671
- 'label' => __( 'Products', 'woo-order-export-lite' ),
672
- 'colname' => $is_json_format ? 'products' : 'Products',
673
- 'segment' => 'product',
674
- 'format' => 'string',
675
- );
676
- }
677
-
678
-
679
- if ( ! empty($settings['order_fields']['coupons']['checked']) ) {
680
- if ( isset( $settings['order_coupon_fields'] ) ) {
681
- foreach ($settings['order_coupon_fields'] as $key => $values) {
682
-
683
- if ( ! $values['checked'] ) {
684
- continue;
685
- }
686
-
687
- $field = array(
688
- 'key' => $key,
689
- 'label' => $values['label'],
690
- 'colname' => $values['colname'],
691
- 'format' => isset($values['format']) ? $values['format'] : 'string',
692
- );
693
-
694
- if ( $is_flat_format ) {
695
- $field['key'] = 'plain_coupons_' . $key;
696
- $field['segment'] = 'coupons';
697
- }
698
-
699
- // start FOR STATIC FIELDS
700
- if ( isset( $values['value'] ) ) {
701
- $field['value'] = $values['value'];
702
- }
703
- if ( preg_match( '/^custom_field_(\d+)/', $key, $matches ) ) {
704
- $field['key'] = "static_field_" . $matches[1];
705
- }
706
- // end FOR STATIC FIELDS
707
-
708
- $order_coupon_fields[] = $field;
709
- }
710
- }
711
- } else {
712
- $order_fields[] = array(
713
- 'key' => 'coupons',
714
- 'label' => __( 'Coupons', 'woo-order-export-lite' ),
715
- 'colname' => $is_json_format ? 'coupons' : 'Coupons',
716
- 'segment' => 'coupon',
717
- 'format' => 'string',
718
- );
719
- }
720
-
721
-
722
- if ( isset( $settings['format'] ) ) {
723
- $old_populate_option_values = array(
724
- isset( $settings['format_xls_populate_other_columns_product_rows'] ) && $settings['format_xls_populate_other_columns_product_rows'] == '1' && $settings['format'] == 'XLS',
725
- isset( $settings['format_csv_populate_other_columns_product_rows'] ) && $settings['format_csv_populate_other_columns_product_rows'] == '1' && $settings['format'] == 'CSV',
726
- isset( $settings['format_tsv_populate_other_columns_product_rows'] ) && $settings['format_tsv_populate_other_columns_product_rows'] == '1' && $settings['format'] == 'TSV',
727
- );
728
-
729
- $old_populate_option_values = array_filter( $old_populate_option_values );
730
-
731
- $populate = ! empty( $old_populate_option_values );
732
- } else {
733
- // by default
734
- $populate = true;
735
- }
736
-
737
- if (isset($settings['order_fields'])) {
738
- foreach ($settings['order_fields'] as $key => $values) {
739
-
740
- if ( ! $values['checked'] ) {
741
- continue;
742
- }
743
- if ( ! isset($values['segment']) ) {
744
- $values['segment'] = 'common';
745
- }
746
- $order_field = array(
747
- 'key' => $key,
748
- 'label' => $values['label'],
749
- 'colname' => $values['colname'],
750
- 'segment' => $values['segment'],
751
- 'format' => isset($values['format']) ? $values['format'] : 'string',
752
- );
753
-
754
- // start FOR STATIC FIELDS
755
- if ( isset( $values['value'] ) ) {
756
- $order_field['value'] = $values['value'];
757
- }
758
- if ( $is_flat_format ) {
759
- if ( preg_match( '/^custom_field_(\d+)/', $key, $matches ) ) {
760
- $order_field['key'] = "static_field_" . $matches[1];
761
- }
762
- }
763
- // end FOR STATIC FIELDS
764
-
765
- $order_fields[] = $order_field;
766
-
767
-
768
- if ( $key === 'products' && $is_flat_format) {
769
- $order_fields = array_merge($order_fields, $order_product_fields);
770
- }
771
-
772
- if ( $key === 'coupons' && $is_flat_format) {
773
- $order_fields = array_merge($order_fields, $order_coupon_fields);
774
- }
775
-
776
- if ( in_array( $key, array( 'products', 'coupons' ) ) ) {
777
- $duplicated_fields_settings[$key] = array(
778
- 'repeat' => isset($values['repeat']) ? $values['repeat'] : 'rows',
779
- 'max_cols' => isset($values['max_cols']) ? $values['max_cols'] : '10',
780
- 'line_delimiter' => '\\n',
781
- );
782
- if ( $key == 'products' ) {
783
- $duplicated_fields_settings[$key]['populate_other_columns'] = $populate ? '1' : '0';
784
- }
785
- }
786
- }
787
- }
788
-
789
- if ( $duplicated_fields_settings ) {
790
- $settings['duplicated_fields_settings'] = $duplicated_fields_settings;
791
- }
792
-
793
- $defaults = self::get_defaults( $settings['mode'] );
794
- if ( ! isset( $duplicated_fields_settings['products'] ) ) {
795
- $settings['duplicated_fields_settings']['products'] = $defaults['duplicated_fields_settings']['products'];
796
- }
797
- if ( ! isset( $duplicated_fields_settings['coupons'] ) ) {
798
- $settings['duplicated_fields_settings']['coupons'] = $defaults['duplicated_fields_settings']['coupons'];
799
- }
800
-
801
- $settings['order_fields'] = $order_fields;
802
-
803
- $settings['order_product_fields'] = $is_flat_format ? array() : $order_product_fields;
804
- $settings['order_coupon_fields'] = $is_flat_format ? array() : $order_coupon_fields;
805
-
806
- unset($duplicated_fields_settings, $order_coupon_fields, $order_product_fields, $order_fields);
807
-
808
- return $settings;
809
- }
810
811
812
}
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(
92
'shipping_methods',
93
'user_roles',
94
'user_names',
95
+ 'user_custom_fields',
96
'coupons',
97
'billing_locations',
98
'payment_methods',
108
}
109
}
110
111
+ $settings = self::get( $in['mode'], $in['id'] );
112
+ $settings['id'] = $in['id'];
113
$settings['duplicated_fields_settings'] = isset( $in['duplicated_fields_settings'] ) ? $in['duplicated_fields_settings'] : array();
114
115
// setup new values for same keys
118
}
119
120
$sections = array(
121
+ 'orders' => 'order_fields',
122
);
123
124
$flat_formats = array( 'XLS', 'CSV', 'TSV' );
125
+ if ( ! in_array( $new_settings['format'], $flat_formats ) ) {
126
+ $sections['products'] = 'order_product_fields';
127
+ $sections['coupons'] = 'order_coupon_fields';
128
}
129
130
foreach ( $sections as $section => $fieldset ) {
131
+ $section_fields = isset( $in[ $section ] ) ? $in[ $section ] : array();
132
$settings[ $fieldset ] = $section_fields;
133
}
134
137
138
static function get( $mode, $id = false ) {
139
140
+ $all_jobs = self::get_export_settings_collection( $mode );
141
142
if ( $mode == self::EXPORT_NOW ) { // one job
143
+ if ( ! isset( $all_jobs['version'] ) ) {
144
+ $all_jobs = self::convert_settings_to_version_2( $mode, $all_jobs );
145
+ }
146
+
147
return self::apply_defaults( $mode, $all_jobs );
148
} elseif ( $id === false ) {
149
if ( empty( $all_jobs ) OR ! is_array( $all_jobs ) ) {
152
153
return array_map( function ( $item ) use ( $mode ) {
154
155
+ if ( ! isset( $item['version'] ) ) {
156
+ $item = self::convert_settings_to_version_2( $mode, $item );
157
+ }
158
159
return WC_Order_Export_Manage::apply_defaults( $mode, $item );
160
}, $all_jobs );
162
163
$settings = isset( $all_jobs[ $id ] ) ? $all_jobs[ $id ] : array();
164
165
+ if ( ! isset( $settings['version'] ) ) {
166
+ $settings = self::convert_settings_to_version_2( $mode, $settings );
167
+ }
168
169
return self::apply_defaults( $mode, $settings );
170
}
171
172
private static function get_defaults( $mode ) {
173
return array(
174
+ 'version' => '2.0',
175
+ 'mode' => $mode,
176
+ 'title' => '',
177
+ 'skip_empty_file' => true,
178
+ 'log_results' => false,
179
+ 'from_status' => array(),
180
+ 'to_status' => array(),
181
+ 'change_order_status_to' => '',
182
+ 'statuses' => array(),
183
+ 'from_date' => '',
184
+ 'to_date' => '',
185
+ 'shipping_locations' => array(),
186
+ 'shipping_methods' => array(),
187
+ 'item_names' => array(),
188
+ 'item_metadata' => array(),
189
+ 'user_roles' => array(),
190
+ 'user_names' => array(),
191
+ 'user_custom_fields' => array(),
192
+ 'billing_locations' => array(),
193
+ 'payment_methods' => array(),
194
+ 'any_coupon_used' => 0,
195
+ 'coupons' => array(),
196
+ 'order_custom_fields' => array(),
197
+ 'product_categories' => array(),
198
+ 'product_vendors' => array(),
199
+ 'products' => array(),
200
+ 'product_taxonomies' => array(),
201
+ 'product_custom_fields' => array(),
202
+ 'product_attributes' => array(),
203
+ 'product_itemmeta' => array(),
204
+ 'format' => 'XLS',
205
+ 'format_xls_use_xls_format' => 0,
206
+ 'format_xls_sheet_name' => __( 'Orders', 'woo-order-export-lite' ),
207
+ 'format_xls_display_column_names' => 1,
208
+ 'format_xls_auto_width' => 1,
209
+ 'format_xls_direction_rtl' => 0,
210
+ 'format_csv_enclosure' => '"',
211
+ 'format_csv_delimiter' => ',',
212
+ 'format_csv_linebreak' => '\r\n',
213
+ 'format_csv_display_column_names' => 1,
214
+ 'format_csv_add_utf8_bom' => 0,
215
+ 'format_csv_item_rows_start_from_new_line' => 0,
216
+ 'format_csv_encoding' => 'UTF-8',
217
+ 'format_csv_delete_linebreaks' => 0,
218
+ 'format_tsv_linebreak' => '\r\n',
219
+ 'format_tsv_display_column_names' => 1,
220
+ 'format_tsv_add_utf8_bom' => 0,
221
+ 'format_tsv_encoding' => 'UTF-8',
222
+ 'format_xml_root_tag' => 'Orders',
223
+ 'format_xml_order_tag' => 'Order',
224
+ 'format_xml_product_tag' => 'Product',
225
+ 'format_xml_coupon_tag' => 'Coupon',
226
+ 'format_xml_prepend_raw_xml' => '',
227
+ 'format_xml_append_raw_xml' => '',
228
+ 'format_xml_self_closing_tags' => 1,
229
+ 'all_products_from_order' => 1,
230
+ 'skip_refunded_items' => 1,
231
+ 'skip_suborders' => 0,
232
+ 'export_refunds' => 0,
233
+ 'date_format' => 'Y-m-d',
234
+ 'time_format' => 'H:i',
235
+ 'sort_direction' => 'DESC',
236
+ 'sort' => 'order_id',
237
+ 'format_number_fields' => 0,
238
+ 'export_all_comments' => 0,
239
+ 'export_refund_notes' => 0,
240
+ 'strip_tags_product_fields' => 0,
241
+ 'cleanup_phone' => 0,
242
+ 'enable_debug' => 0,
243
+ 'format_json_start_tag' => '[',
244
+ 'format_json_end_tag' => ']',
245
+ 'custom_php' => 0,
246
+ 'custom_php_code' => '',
247
+ 'mark_exported_orders' => 0,
248
+ 'export_unmarked_orders' => 0,
249
250
'summary_report_by_products' => 0,
251
'duplicated_fields_settings' => array(
284
foreach ( array( 'order_fields', 'order_product_fields', 'order_coupon_fields' ) as $index ) {
285
if ( ! isset( $settings[ $index ] ) ) {
286
$additional_fields = self::move_fields_key( self::get_default_fields( $index, $settings['format'] ) );
287
+ self::remove_unchecked_fields( $additional_fields );
288
$settings[ $index ] = $additional_fields;
289
if ( 'order_fields' !== $index ) {
290
$map_segment = array(
291
'order_product_fields' => 'products',
292
+ 'order_coupon_fields' => 'coupons',
293
);
294
295
$settings['order_fields'] = array_merge(
296
$settings['order_fields'],
297
array_map( function ( $value ) use ( $map_segment, $index ) {
298
$value['segment'] = $map_segment[ $index ];
299
+ $value['key'] = 'plain_' . $map_segment[ $index ] . '_' . $value['key'];
300
301
return $value;
302
}, $additional_fields )
308
return array_merge( $defaults, $settings );
309
}
310
311
+ private static function get_default_fields( $index, $format ) {
312
$result = array();
313
+ switch ( $index ) {
314
case 'order_fields':
315
$result = WC_Order_Export_Data_Extractor_UI::get_order_fields( $format );
316
break;
325
return $result;
326
}
327
328
+ private static function remove_unchecked_fields( &$fields ) {
329
foreach ( $fields as $key => $field ) {
330
+ if ( empty( $field['checked'] ) ) {
331
+ unset( $fields[ $key ] );
332
+ } elseif ( isset( $field['checked'] ) ) {
333
+ unset( $fields[ $key ]['checked'] );
334
}
335
}
336
+ $fields = array_values( $fields );
337
}
338
339
private static function move_fields_key( $fields ) {
349
350
static function merge_settings_and_default_new( &$opt, $defaults ) {
351
352
+ $opt = self::move_fields_key( $opt );
353
+ $defaults = self::move_fields_key( $defaults );
354
355
356
foreach ( $defaults as $v ) {
397
} else {
398
$method = "get_order_fields_" . $segment;
399
$filter = "woe_get_order_fields_" . $segment;
400
+ }
401
+
402
if ( method_exists( 'WC_Order_Export_Data_Extractor_UI', $method ) ) {
403
// woe_get_order_fields_common filter
404
+ $segment_fields = array();
405
$default_segment_fields = array_merge(
406
+ WC_Order_Export_Data_Extractor_UI::$method( $format ),
407
apply_filters( $filter, array(), $format )
408
);
409
foreach ( $default_segment_fields as $key => $value ) {
410
$order_field = $value;
411
$order_field['colname'] = $value['label'];
412
$order_field['key'] = $key;
413
+ $order_field['default'] = 1;
414
unset( $order_field['checked'] );
415
$segment_fields[] = $order_field;
416
}
609
}
610
611
//backup only existing settings
612
+ private static function backup_settings_before_version_2( $mode ) {
613
+ $name = self::get_settings_name_for_mode( $mode );
614
$current_settings = get_option( $name, array() );
615
+ $new_settings = get_option( $name . "-V1", array() );
616
// backup only once!
617
+ if ( ! empty( $current_settings ) AND empty( $new_settings ) ) {
618
+ update_option( $name . "-V1", $current_settings, false );
619
+ }
620
+ }
621
+
622
+ protected static function convert_settings_to_version_2( $mode, $settings ) {
623
+
624
+ if ( ! $settings ) {
625
+ return $settings;
626
+ }
627
+ self::backup_settings_before_version_2( $mode );
628
+
629
+ $flat_formats = array( 'XLS', 'CSV', 'TSV' );
630
+ $is_flat_format = in_array( $settings['format'], $flat_formats );
631
+ $is_json_format = $settings['format'] === 'JSON';
632
+
633
+ $order_fields = array();
634
+ $order_coupon_fields = array();
635
+ $order_product_fields = array();
636
+ $duplicated_fields_settings = array();
637
+
638
+ if ( ! empty( $settings['order_fields']['products']['checked'] ) ) {
639
+ if ( isset( $settings['order_product_fields'] ) ) {
640
+
641
+ foreach ( $settings['order_product_fields'] as $key => $values ) {
642
+
643
+ if ( ! $values['checked'] ) {
644
+ continue;
645
+ }
646
+
647
+ $field = array(
648
+ 'key' => $key,
649
+ 'label' => $values['label'],
650
+ 'colname' => $values['colname'],
651
+ 'format' => isset( $values['format'] ) ? $values['format'] : 'string',
652
+ );
653
+
654
+ if ( $is_flat_format ) {
655
+ $field['key'] = 'plain_products_' . $key;
656
+ $field['segment'] = 'products';
657
+ }
658
+
659
+ // start FOR STATIC FIELDS
660
+ if ( isset( $values['value'] ) ) {
661
+ $field['value'] = $values['value'];
662
+ }
663
+ // end FOR STATIC FIELDS
664
+
665
+
666
+ $order_product_fields[] = $field;
667
+ }
668
+ }
669
+ } else {
670
+ $order_fields[] = array(
671
+ 'key' => 'products',
672
+ 'label' => __( 'Products', 'woo-order-export-lite' ),
673
+ 'colname' => $is_json_format ? 'products' : 'Products',
674
+ 'segment' => 'product',
675
+ 'format' => 'string',
676
+ );
677
}
678
+
679
+
680
+ if ( ! empty( $settings['order_fields']['coupons']['checked'] ) ) {
681
+ if ( isset( $settings['order_coupon_fields'] ) ) {
682
+ foreach ( $settings['order_coupon_fields'] as $key => $values ) {
683
+
684
+ if ( ! $values['checked'] ) {
685
+ continue;
686
+ }
687
+
688
+ $field = array(
689
+ 'key' => $key,
690
+ 'label' => $values['label'],
691
+ 'colname' => $values['colname'],
692
+ 'format' => isset( $values['format'] ) ? $values['format'] : 'string',
693
+ );
694
+
695
+ if ( $is_flat_format ) {
696
+ $field['key'] = 'plain_coupons_' . $key;
697
+ $field['segment'] = 'coupons';
698
+ }
699
+
700
+ // start FOR STATIC FIELDS
701
+ if ( isset( $values['value'] ) ) {
702
+ $field['value'] = $values['value'];
703
+ }
704
+ if ( preg_match( '/^custom_field_(\d+)/', $key, $matches ) ) {
705
+ $field['key'] = "static_field_" . $matches[1];
706
+ }
707
+ // end FOR STATIC FIELDS
708
+
709
+ $order_coupon_fields[] = $field;
710
+ }
711
+ }
712
+ } else {
713
+ $order_fields[] = array(
714
+ 'key' => 'coupons',
715
+ 'label' => __( 'Coupons', 'woo-order-export-lite' ),
716
+ 'colname' => $is_json_format ? 'coupons' : 'Coupons',
717
+ 'segment' => 'coupon',
718
+ 'format' => 'string',
719
+ );
720
+ }
721
+
722
+
723
+ if ( isset( $settings['format'] ) ) {
724
+ $old_populate_option_values = array(
725
+ isset( $settings['format_xls_populate_other_columns_product_rows'] ) && $settings['format_xls_populate_other_columns_product_rows'] == '1' && $settings['format'] == 'XLS',
726
+ isset( $settings['format_csv_populate_other_columns_product_rows'] ) && $settings['format_csv_populate_other_columns_product_rows'] == '1' && $settings['format'] == 'CSV',
727
+ isset( $settings['format_tsv_populate_other_columns_product_rows'] ) && $settings['format_tsv_populate_other_columns_product_rows'] == '1' && $settings['format'] == 'TSV',
728
+ );
729
+
730
+ $old_populate_option_values = array_filter( $old_populate_option_values );
731
+
732
+ $populate = ! empty( $old_populate_option_values );
733
+ } else {
734
+ // by default
735
+ $populate = true;
736
+ }
737
+
738
+ if ( isset( $settings['order_fields'] ) ) {
739
+ foreach ( $settings['order_fields'] as $key => $values ) {
740
+
741
+ if ( ! $values['checked'] ) {
742
+ continue;
743
+ }
744
+ if ( ! isset( $values['segment'] ) ) {
745
+ $values['segment'] = 'common';
746
+ }
747
+ $order_field = array(
748
+ 'key' => $key,
749
+ 'label' => $values['label'],
750
+ 'colname' => $values['colname'],
751
+ 'segment' => $values['segment'],
752
+ 'format' => isset( $values['format'] ) ? $values['format'] : 'string',
753
+ );
754
+
755
+ // start FOR STATIC FIELDS
756
+ if ( isset( $values['value'] ) ) {
757
+ $order_field['value'] = $values['value'];
758
+ }
759
+ if ( $is_flat_format ) {
760
+ if ( preg_match( '/^custom_field_(\d+)/', $key, $matches ) ) {
761
+ $order_field['key'] = "static_field_" . $matches[1];
762
+ }
763
+ }
764
+ // end FOR STATIC FIELDS
765
+
766
+ $order_fields[] = $order_field;
767
+
768
+
769
+ if ( $key === 'products' && $is_flat_format ) {
770
+ $order_fields = array_merge( $order_fields, $order_product_fields );
771
+ }
772
+
773
+ if ( $key === 'coupons' && $is_flat_format ) {
774
+ $order_fields = array_merge( $order_fields, $order_coupon_fields );
775
+ }
776
+
777
+ if ( in_array( $key, array( 'products', 'coupons' ) ) ) {
778
+ $duplicated_fields_settings[ $key ] = array(
779
+ 'repeat' => isset( $values['repeat'] ) ? $values['repeat'] : 'rows',
780
+ 'max_cols' => isset( $values['max_cols'] ) ? $values['max_cols'] : '10',
781
+ 'line_delimiter' => '\\n',
782
+ );
783
+ if ( $key == 'products' ) {
784
+ $duplicated_fields_settings[ $key ]['populate_other_columns'] = $populate ? '1' : '0';
785
+ }
786
+ }
787
+ }
788
+ }
789
+
790
+ if ( $duplicated_fields_settings ) {
791
+ $settings['duplicated_fields_settings'] = $duplicated_fields_settings;
792
+ }
793
+
794
+ $defaults = self::get_defaults( $settings['mode'] );
795
+ if ( ! isset( $duplicated_fields_settings['products'] ) ) {
796
+ $settings['duplicated_fields_settings']['products'] = $defaults['duplicated_fields_settings']['products'];
797
+ }
798
+ if ( ! isset( $duplicated_fields_settings['coupons'] ) ) {
799
+ $settings['duplicated_fields_settings']['coupons'] = $defaults['duplicated_fields_settings']['coupons'];
800
+ }
801
+
802
+ $settings['order_fields'] = $order_fields;
803
+
804
+ $settings['order_product_fields'] = $is_flat_format ? array() : $order_product_fields;
805
+ $settings['order_coupon_fields'] = $is_flat_format ? array() : $order_coupon_fields;
806
+
807
+ unset( $duplicated_fields_settings, $order_coupon_fields, $order_product_fields, $order_fields );
808
+
809
+ return $settings;
810
}
811
812
813
}
classes/class-wc-order-export-admin.php CHANGED
@@ -24,7 +24,7 @@ class WC_Order_Export_Admin {
24
// load scripts on our pages only
25
if ( isset( $_GET['page'] ) && $_GET['page'] == 'wc-order-export' ) {
26
add_action( 'admin_enqueue_scripts', array( $this, 'thematic_enqueue_scripts' ) );
27
- add_filter( 'script_loader_src', array( $this, 'script_loader_src' ), 10, 2 );
28
}
29
add_action( 'wp_ajax_order_exporter', array( $this, 'ajax_gate' ) );
30
@@ -134,7 +134,7 @@ class WC_Order_Export_Admin {
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 ) {
@@ -570,34 +570,34 @@ class WC_Order_Export_Admin {
570
WOE_VERSION );
571
572
$localize_settings_form = array(
573
- 'add_fields_to_export' => __('Add %s fields', 'woo-order-export-lite'),
574
- 'repeats' => array(
575
- 'rows' => __( 'rows', 'woo-order-export-lite' ),
576
- 'columns' => __( 'columns', 'woo-order-export-lite' ),
577
- 'inside_one_cell' => __( 'one row', 'woo-order-export-lite' ),
578
- ),
579
- 'js_tpl_popup' => array(
580
- 'add' => __( 'Add', 'woo-order-export-lite' ),
581
- 'as' => __( 'as', 'woo-order-export-lite' ),
582
- 'split_values_by' => __( 'Split values by', 'woo-order-export-lite' ),
583
- 'fill_order_columns_label' => __( 'Fill order columns for', 'woo-order-export-lite' ),
584
- 'for_all_rows_label' => __( 'all rows', 'woo-order-export-lite' ),
585
- 'for_first_row_only_label' => __( '1st row only', 'woo-order-export-lite' ),
586
- 'grouping_by' => array(
587
- 'products' => __( 'Grouping by product', 'woo-order-export-lite' ),
588
- 'coupons' => __( 'Grouping by coupon', 'woo-order-export-lite' ),
589
- ),
590
- ),
591
- 'index' => array(
592
- 'product_pop_up_title' => __('Set up product fields', 'woo-order-export-lite'),
593
- 'coupon_pop_up_title' => __('Set up coupon fields', 'woo-order-export-lite'),
594
- 'products' => __('products', 'woo-order-export-lite'),
595
- 'coupons' => __('coupons', 'woo-order-export-lite'),
596
- ),
597
- 'remove_all_fields_confirm' => __('Remove all fields?', 'woo-order-export-lite'),
598
599
);
600
- wp_localize_script( 'settings-form', 'localize_settings_form', $localize_settings_form );
601
602
603
$settings_form = array(
@@ -651,9 +651,9 @@ class WC_Order_Export_Admin {
651
wp_localize_script( 'export', 'export_messages', $translation_array );
652
653
$script_data = array(
654
- 'locale'=> get_locale(),
655
- 'select2_locale'=> $this->get_select2_locale(),
656
- );
657
658
wp_localize_script( 'export', 'script_data', $script_data );
659
}
@@ -672,7 +672,7 @@ class WC_Order_Export_Admin {
672
);
673
674
return isset( $select2_locales[ $locale ] ) ? $select2_locales[ $locale ] : 'en';
675
- }
676
677
private function enqueue_select2_scripts() {
678
wp_enqueue_script( 'select22', $this->url_plugin . 'assets/js/select2/select2.full.js',
@@ -680,11 +680,11 @@ class WC_Order_Export_Admin {
680
681
682
if ( $select2_locale = $this->get_select2_locale() ) {
683
- // enable by default
684
- if ( $select2_locale !== 'en' ) {
685
- wp_enqueue_script( "select22-i18n-{$select2_locale}",
686
- $this->url_plugin . "assets/js/select2/i18n/{$select2_locale}.js", array( 'jquery', 'select22' ) );
687
- }
688
}
689
690
wp_enqueue_style( 'select2-css', $this->url_plugin . 'assets/css/select2/select2.min.css',
@@ -699,6 +699,8 @@ class WC_Order_Export_Admin {
699
) {
700
return $src;
701
}
702
}
703
704
public function render( $view, $params = array(), $path_views = null ) {
24
// load scripts on our pages only
25
if ( isset( $_GET['page'] ) && $_GET['page'] == 'wc-order-export' ) {
26
add_action( 'admin_enqueue_scripts', array( $this, 'thematic_enqueue_scripts' ) );
27
+ add_filter( 'script_loader_src', array( $this, 'script_loader_src' ), 999, 2 );
28
}
29
add_action( 'wp_ajax_order_exporter', array( $this, 'ajax_gate' ) );
30
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 ) {
570
WOE_VERSION );
571
572
$localize_settings_form = array(
573
+ 'add_fields_to_export' => __( 'Add %s fields', 'woo-order-export-lite' ),
574
+ 'repeats' => array(
575
+ 'rows' => __( 'rows', 'woo-order-export-lite' ),
576
+ 'columns' => __( 'columns', 'woo-order-export-lite' ),
577
+ 'inside_one_cell' => __( 'one row', 'woo-order-export-lite' ),
578
+ ),
579
+ 'js_tpl_popup' => array(
580
+ 'add' => __( 'Add', 'woo-order-export-lite' ),
581
+ 'as' => __( 'as', 'woo-order-export-lite' ),
582
+ 'split_values_by' => __( 'Split values by', 'woo-order-export-lite' ),
583
+ 'fill_order_columns_label' => __( 'Fill order columns for', 'woo-order-export-lite' ),
584
+ 'for_all_rows_label' => __( 'all rows', 'woo-order-export-lite' ),
585
+ 'for_first_row_only_label' => __( '1st row only', 'woo-order-export-lite' ),
586
+ 'grouping_by' => array(
587
+ 'products' => __( 'Grouping by product', 'woo-order-export-lite' ),
588
+ 'coupons' => __( 'Grouping by coupon', 'woo-order-export-lite' ),
589
+ ),
590
+ ),
591
+ 'index' => array(
592
+ 'product_pop_up_title' => __( 'Set up product fields', 'woo-order-export-lite' ),
593
+ 'coupon_pop_up_title' => __( 'Set up coupon fields', 'woo-order-export-lite' ),
594
+ 'products' => __( 'products', 'woo-order-export-lite' ),
595
+ 'coupons' => __( 'coupons', 'woo-order-export-lite' ),
596
+ ),
597
+ 'remove_all_fields_confirm' => __( 'Remove all fields?', 'woo-order-export-lite' ),
598
599
);
600
+ wp_localize_script( 'settings-form', 'localize_settings_form', $localize_settings_form );
601
602
603
$settings_form = array(
651
wp_localize_script( 'export', 'export_messages', $translation_array );
652
653
$script_data = array(
654
+ 'locale' => get_locale(),
655
+ 'select2_locale' => $this->get_select2_locale(),
656
+ );
657
658
wp_localize_script( 'export', 'script_data', $script_data );
659
}
672
);
673
674
return isset( $select2_locales[ $locale ] ) ? $select2_locales[ $locale ] : 'en';
675
+ }
676
677
private function enqueue_select2_scripts() {
678
wp_enqueue_script( 'select22', $this->url_plugin . 'assets/js/select2/select2.full.js',
680
681
682
if ( $select2_locale = $this->get_select2_locale() ) {
683
+ // enable by default
684
+ if ( $select2_locale !== 'en' ) {
685
+ wp_enqueue_script( "select22-i18n-{$select2_locale}",
686
+ $this->url_plugin . "assets/js/select2/i18n/{$select2_locale}.js", array( 'jquery', 'select22' ) );
687
+ }
688
}
689
690
wp_enqueue_style( 'select2-css', $this->url_plugin . 'assets/css/select2/select2.min.css',
699
) {
700
return $src;
701
}
702
+
703
+ return "";
704
}
705
706
public function render( $view, $params = array(), $path_views = null ) {
classes/core/class-wc-order-export-data-extractor-ui.php CHANGED
@@ -141,8 +141,8 @@ class WC_Order_Export_Data_Extractor_UI extends WC_Order_Export_Data_Extractor {
141
142
public static function get_products_like( $like, $limit ) {
143
global $wpdb;
144
- $like = $wpdb->esc_like( $like );
145
- $query = "
146
SELECT post.ID as id,post.post_title as text,att.ID as photo_id,att.guid as photo_url
147
FROM " . $wpdb->posts . " as post
148
LEFT JOIN " . $wpdb->posts . " AS att ON post.ID=att.post_parent AND att.post_type='attachment'
@@ -151,8 +151,8 @@ class WC_Order_Export_Data_Extractor_UI extends WC_Order_Export_Data_Extractor {
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 ) {
@@ -340,201 +340,210 @@ class WC_Order_Export_Data_Extractor_UI extends WC_Order_Export_Data_Extractor {
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
- 'format' => 'number',
347
),
348
- 'line_id' => array(
349
- 'label' => __( 'Item #', 'woo-order-export-lite' ),
350
'checked' => 1,
351
- 'format' => 'number',
352
),
353
- 'sku' => array(
354
- 'label' => __( 'SKU', 'woo-order-export-lite' ),
355
'checked' => 1,
356
- 'format' =>'string',
357
),
358
- 'name' => array(
359
'label' => __( 'Item Name', 'woo-order-export-lite' ),
360
'checked' => 1,
361
- 'format' =>'string',
362
),
363
- 'product_id' => array(
364
'label' => __( 'Product Id', 'woo-order-export-lite' ),
365
'checked' => 0,
366
- 'format' => 'number',
367
),
368
- 'product_name' => array(
369
'label' => __( 'Product Name', 'woo-order-export-lite' ),
370
'checked' => 0,
371
- 'format' =>'string',
372
),
373
- 'variation_id' => array(
374
'label' => __( 'Variation Id', 'woo-order-export-lite' ),
375
'checked' => 0,
376
- 'format' =>'number',
377
),
378
- 'product_variation' => array(
379
'label' => __( 'Product Variation', 'woo-order-export-lite' ),
380
'checked' => 0,
381
- 'format' =>'string',
382
),
383
- 'seller' => array(
384
'label' => __( 'Item Seller', 'woo-order-export-lite' ),
385
'checked' => 0,
386
- 'format' =>'string',
387
),
388
- 'qty' => array(
389
'label' => __( 'Quantity', 'woo-order-export-lite' ),
390
'checked' => 1,
391
- 'format' =>'number',
392
),
393
- 'qty_minus_refund' => array(
394
'label' => __( 'Quantity (- Refund)', 'woo-order-export-lite' ),
395
'checked' => 0,
396
- 'format' =>'number',
397
),
398
- 'item_price' => array(
399
'label' => __( 'Item Cost', 'woo-order-export-lite' ),
400
'checked' => 1,
401
'format' => 'money',
402
),
403
- 'price' => array(
404
'label' => __( 'Product Current Price', 'woo-order-export-lite' ),
405
'checked' => 0,
406
'format' => 'money',
407
),
408
- 'line_no_tax' => array(
409
'label' => __( 'Order Line (w/o tax)', 'woo-order-export-lite' ),
410
'checked' => 0,
411
'format' => 'money',
412
),
413
- 'line_tax' => array(
414
'label' => __( 'Order Line Tax', 'woo-order-export-lite' ),
415
'checked' => 0,
416
'format' => 'money',
417
),
418
- 'line_tax_refunded' => array(
419
'label' => __( 'Order Line Tax Refunded', 'woo-order-export-lite' ),
420
'checked' => 0,
421
'format' => 'money',
422
),
423
- 'line_tax_minus_refund' => array(
424
'label' => __( 'Order Line Tax (- Refund)', 'woo-order-export-lite' ),
425
'checked' => 0,
426
'format' => 'money',
427
),
428
- 'line_subtotal' => array(
429
'label' => __( 'Order Line Subtotal', 'woo-order-export-lite' ),
430
'checked' => 0,
431
'format' => 'money',
432
),
433
- 'line_subtotal_tax' => array(
434
'label' => __( 'Order Line Subtotal Tax', 'woo-order-export-lite' ),
435
'checked' => 0,
436
'format' => 'money',
437
),
438
- 'line_total' => array(
439
'label' => __( 'Order Line Total', 'woo-order-export-lite' ),
440
'checked' => 0,
441
'format' => 'money',
442
),
443
- 'line_total_plus_tax' => array(
444
'label' => __( 'Order Line Total (include tax)', 'woo-order-export-lite' ),
445
'checked' => 0,
446
'format' => 'money',
447
),
448
- 'line_total_refunded' => array(
449
'label' => __( 'Order Line Total Refunded', 'woo-order-export-lite' ),
450
'checked' => 0,
451
'format' => 'money',
452
),
453
- 'line_total_minus_refund' => array(
454
'label' => __( 'Order Line Total (- Refund)', 'woo-order-export-lite' ),
455
'checked' => 0,
456
'format' => 'money',
457
),
458
- 'discount_amount' => array(
459
'label' => __( 'Item Discount Amount', 'woo-order-export-lite' ),
460
'checked' => 0,
461
'format' => 'money',
462
),
463
- 'tax_rate' => array(
464
'label' => __( 'Item Tax Rate', 'woo-order-export-lite' ),
465
'checked' => 0,
466
'format' => 'number',
467
),
468
- 'type' => array( 'label' => __( 'Type', 'woo-order-export-lite' ), 'checked' => 0 ),
469
- 'category' => array(
470
'label' => __( 'Category', 'woo-order-export-lite' ),
471
'checked' => 0,
472
),
473
- 'tags' => array( 'label' => __( 'Tags', 'woo-order-export-lite' ), 'checked' => 0 ),
474
- 'width' => array(
475
'label' => __( 'Width', 'woo-order-export-lite' ),
476
'checked' => 0,
477
'format' => 'number',
478
),
479
- 'length' => array(
480
'label' => __( 'Length', 'woo-order-export-lite' ),
481
'checked' => 0,
482
'format' => 'number',
483
),
484
- 'height' => array(
485
'label' => __( 'Height', 'woo-order-export-lite' ),
486
'checked' => 0,
487
'format' => 'number',
488
),
489
- 'weight' => array(
490
'label' => __( 'Weight', 'woo-order-export-lite' ),
491
'checked' => 0,
492
'format' => 'number',
493
),
494
- 'product_url' => array(
495
'label' => __( 'Product URL', 'woo-order-export-lite' ),
496
'checked' => 0,
497
- 'format' =>'string',
498
),
499
- 'download_url' => array(
500
'label' => __( 'Download URL', 'woo-order-export-lite' ),
501
'checked' => 0,
502
- 'format' =>'string',
503
),
504
- 'image_url' => array(
505
'label' => __( 'Image URL', 'woo-order-export-lite' ),
506
'checked' => 0,
507
- 'format' =>'string',
508
),
509
- 'product_shipping_class' => array(
510
'label' => __( 'Product Shipping Class', 'woo-order-export-lite' ),
511
'checked' => 0,
512
- 'format' =>'string',
513
),
514
- 'post_content' => array(
515
'label' => __( 'Description', 'woo-order-export-lite' ),
516
'checked' => 0,
517
- 'format' =>'string',
518
),
519
- 'post_excerpt' => array(
520
'label' => __( 'Short Description', 'woo-order-export-lite' ),
521
'checked' => 0,
522
- 'format' =>'string',
523
),
524
- 'full_category_names' => array(
525
'label' => __( 'Full names for categories', 'woo-order-export-lite' ),
526
'checked' => 0,
527
- 'format' =>'string',
528
),
529
- 'summary_report_total_qty' => array(
530
'label' => __( 'Summary Report Total Quantity', 'woo-order-export-lite' ),
531
'checked' => 0,
532
- 'format' =>'number',
533
),
534
- 'summary_report_total_amount' => array(
535
'label' => __( 'Summary Report Total Amount', 'woo-order-export-lite' ),
536
'checked' => 0,
537
- 'format' =>'money',
538
),
539
);
540
@@ -551,7 +560,7 @@ class WC_Order_Export_Data_Extractor_UI extends WC_Order_Export_Data_Extractor {
551
'code' => array(
552
'label' => __( 'Coupon Code', 'woo-order-export-lite' ),
553
'checked' => 1,
554
- 'format' =>'string',
555
),
556
'discount_amount' => array(
557
'label' => __( 'Discount Amount', 'woo-order-export-lite' ),
@@ -575,7 +584,7 @@ class WC_Order_Export_Data_Extractor_UI extends WC_Order_Export_Data_Extractor {
575
'discount_type' => array(
576
'label' => __( 'Coupon Type', 'woo-order-export-lite' ),
577
'checked' => 0,
578
- 'format' =>'string',
579
),
580
'coupon_amount' => array(
581
'label' => __( 'Coupon Amount', 'woo-order-export-lite' ),
@@ -595,7 +604,20 @@ class WC_Order_Export_Data_Extractor_UI extends WC_Order_Export_Data_Extractor {
595
596
public static function get_order_fields( $format ) {
597
$map = array();
598
- foreach ( array( 'common', 'user', 'billing', 'shipping', 'product', 'coupon', 'cart', 'ship_calc', 'totals', 'misc' ) as $segment ) {
599
$method = "get_order_fields_" . $segment;
600
$map_segment = self::$method();
601
@@ -614,23 +636,23 @@ class WC_Order_Export_Data_Extractor_UI extends WC_Order_Export_Data_Extractor {
614
615
public static function get_order_fields_common() {
616
return array(
617
- 'line_number' => array(
618
- 'label' => __( 'Line number', 'woo-order-export-lite' ),
619
'checked' => 0,
620
'format' => 'number',
621
),
622
- 'order_id' => array(
623
- 'label' => __( 'Order ID', 'woo-order-export-lite' ),
624
'checked' => 0,
625
'format' => 'number',
626
),
627
- 'order_number' => array(
628
- 'label' => __( 'Order Number', 'woo-order-export-lite' ),
629
'checked' => 1,
630
'format' => 'string',
631
),
632
- 'order_status' => array(
633
- 'label' => __( 'Order Status', 'woo-order-export-lite' ),
634
'checked' => 1,
635
'format' => 'string',
636
),
@@ -649,7 +671,7 @@ class WC_Order_Export_Data_Extractor_UI extends WC_Order_Export_Data_Extractor {
649
'checked' => 0,
650
'format' => 'string',
651
),
652
- 'order_currency' => array(
653
'label' => __( 'Currency', 'woo-order-export-lite' ),
654
'checked' => 0,
655
'format' => 'string',
@@ -699,7 +721,7 @@ class WC_Order_Export_Data_Extractor_UI extends WC_Order_Export_Data_Extractor {
699
'checked' => 0,
700
'format' => 'string',
701
),
702
- 'user_url' => array(
703
'label' => __( 'User Website', 'woo-order-export-lite' ),
704
'checked' => 0,
705
'format' => 'string',
@@ -908,69 +930,69 @@ class WC_Order_Export_Data_Extractor_UI extends WC_Order_Export_Data_Extractor {
908
909
public static function get_order_fields_cart() {
910
return array(
911
- 'shipping_method_title' => array(
912
'label' => __( 'Shipping Method Title', 'woo-order-export-lite' ),
913
'checked' => 1,
914
'format' => 'string',
915
),
916
- 'shipping_method' => array(
917
'label' => __( 'Shipping Method', 'woo-order-export-lite' ),
918
'checked' => 0,
919
'format' => 'string',
920
),
921
- 'payment_method_title' => array(
922
'label' => __( 'Payment Method Title', 'woo-order-export-lite' ),
923
'checked' => 1,
924
'format' => 'string',
925
),
926
- 'payment_method' => array(
927
'label' => __( 'Payment Method', 'woo-order-export-lite' ),
928
'checked' => 0,
929
'format' => 'string',
930
),
931
- 'coupons_used' => array(
932
'label' => __( 'Coupons Used', 'woo-order-export-lite' ),
933
'checked' => 0,
934
'format' => 'string',
935
),
936
- 'cart_discount' => array(
937
'label' => __( 'Cart Discount Amount', 'woo-order-export-lite' ),
938
'checked' => 1,
939
'format' => 'money',
940
),
941
- 'cart_discount_tax' => array(
942
'label' => __( 'Cart Discount Amount Tax', 'woo-order-export-lite' ),
943
'checked' => 0,
944
'format' => 'money',
945
),
946
- 'order_subtotal' => array(
947
'label' => __( 'Order Subtotal Amount', 'woo-order-export-lite' ),
948
'checked' => 1,
949
'format' => 'money',
950
),
951
- 'order_subtotal_minus_discount' => array(
952
'label' => __( 'Order Subtotal - Cart Discount', 'woo-order-export-lite' ),
953
'checked' => 0,
954
'format' => 'money',
955
),
956
- 'order_subtotal_refunded' => array(
957
'label' => __( 'Order Subtotal Amount Refunded', 'woo-order-export-lite' ),
958
'checked' => 0,
959
'format' => 'money',
960
),
961
- 'order_subtotal_minus_refund' => array(
962
'label' => __( 'Order Subtotal Amount (- Refund)', 'woo-order-export-lite' ),
963
'checked' => 0,
964
'format' => 'money',
965
),
966
- 'order_tax' => array(
967
'label' => __( 'Order Tax Amount', 'woo-order-export-lite' ),
968
'checked' => 0,
969
'format' => 'money',
970
),
971
);
972
}
973
-
974
public static function get_order_fields_ship_calc() {
975
return array(
976
'order_shipping' => array(
@@ -978,7 +1000,7 @@ class WC_Order_Export_Data_Extractor_UI extends WC_Order_Export_Data_Extractor {
978
'checked' => 1,
979
'format' => 'money',
980
),
981
- 'order_shipping_plus_tax' => array(
982
'label' => __( 'Order Shipping + Tax Amount', 'woo-order-export-lite' ),
983
'checked' => 0,
984
'format' => 'money',
@@ -1010,45 +1032,45 @@ class WC_Order_Export_Data_Extractor_UI extends WC_Order_Export_Data_Extractor {
1010
),
1011
);
1012
}
1013
-
1014
public static function get_order_fields_totals() {
1015
return array(
1016
- 'order_total_fee' => array(
1017
'label' => __( 'Order Total Fee', 'woo-order-export-lite' ),
1018
'checked' => 0,
1019
'format' => 'money',
1020
),
1021
- 'order_refund' => array(
1022
'label' => __( 'Order Refund Amount', 'woo-order-export-lite' ),
1023
'checked' => 1,
1024
'format' => 'money',
1025
),
1026
- 'order_total_inc_refund' => array(
1027
'label' => __( 'Order Total Amount (- Refund)', 'woo-order-export-lite' ),
1028
'checked' => 0,
1029
'format' => 'money',
1030
),
1031
- 'order_total' => array(
1032
'label' => __( 'Order Total Amount', 'woo-order-export-lite' ),
1033
'checked' => 1,
1034
'format' => 'money',
1035
),
1036
- 'order_total_no_tax' => array(
1037
'label' => __( 'Order Total Amount without Tax', 'woo-order-export-lite' ),
1038
'checked' => 0,
1039
'format' => 'money',
1040
),
1041
- 'order_total_tax' => array(
1042
'label' => __( 'Order Total Tax Amount', 'woo-order-export-lite' ),
1043
'checked' => 1,
1044
'format' => 'money',
1045
),
1046
- 'order_total_tax_refunded' => array(
1047
'label' => __( 'Order Total Tax Amount Refunded', 'woo-order-export-lite' ),
1048
'checked' => 0,
1049
'format' => 'money',
1050
),
1051
- 'order_total_tax_minus_refund' => array(
1052
'label' => __( 'Order Total Tax Amount (- Refund)', 'woo-order-export-lite' ),
1053
'checked' => 0,
1054
'format' => 'money',
@@ -1095,16 +1117,16 @@ class WC_Order_Export_Data_Extractor_UI extends WC_Order_Export_Data_Extractor {
1095
1096
public static function get_order_segments() {
1097
return array(
1098
- 'common' => __( 'Common', 'woo-order-export-lite' ),
1099
- 'user' => __( 'User', 'woo-order-export-lite' ),
1100
- 'billing' => __( 'Billing Address', 'woo-order-export-lite' ),
1101
- 'shipping' => __( 'Shipping Address', 'woo-order-export-lite' ),
1102
- 'products' => __( 'Products', 'woo-order-export-lite' ),
1103
- 'coupons' => __( 'Coupons', 'woo-order-export-lite' ),
1104
- 'cart' => __( 'Cart', 'woo-order-export-lite'),
1105
- 'ship_calc'=> __( 'Shipping', 'woo-order-export-lite'),
1106
- 'totals' => __( 'Totals', 'woo-order-export-lite'),
1107
- 'misc' => __( 'Others', 'woo-order-export-lite' )
1108
);
1109
}
1110
141
142
public static function get_products_like( $like, $limit ) {
143
global $wpdb;
144
+ $like = $wpdb->esc_like( $like );
145
+ $query = "
146
SELECT post.ID as id,post.post_title as text,att.ID as photo_id,att.guid as photo_url
147
FROM " . $wpdb->posts . " as post
148
LEFT JOIN " . $wpdb->posts . " AS att ON post.ID=att.post_parent AND att.post_type='attachment'
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 ) {
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
+ 'format' => 'number',
347
),
348
+ 'line_id' => array(
349
+ 'label' => __( 'Item #', 'woo-order-export-lite' ),
350
'checked' => 1,
351
+ 'format' => 'number',
352
),
353
+ 'sku' => array(
354
+ 'label' => __( 'SKU', 'woo-order-export-lite' ),
355
'checked' => 1,
356
+ 'format' => 'string',
357
),
358
+ 'name' => array(
359
'label' => __( 'Item Name', 'woo-order-export-lite' ),
360
'checked' => 1,
361
+ 'format' => 'string',
362
),
363
+ 'product_id' => array(
364
'label' => __( 'Product Id', 'woo-order-export-lite' ),
365
'checked' => 0,
366
+ 'format' => 'number',
367
),
368
+ 'product_name' => array(
369
'label' => __( 'Product Name', 'woo-order-export-lite' ),
370
'checked' => 0,
371
+ 'format' => 'string',
372
),
373
+ 'variation_id' => array(
374
'label' => __( 'Variation Id', 'woo-order-export-lite' ),
375
'checked' => 0,
376
+ 'format' => 'number',
377
),
378
+ 'product_variation' => array(
379
'label' => __( 'Product Variation', 'woo-order-export-lite' ),
380
'checked' => 0,
381
+ 'format' => 'string',
382
),
383
+ 'seller' => array(
384
'label' => __( 'Item Seller', 'woo-order-export-lite' ),
385
'checked' => 0,
386
+ 'format' => 'string',
387
),
388
+ 'qty' => array(
389
'label' => __( 'Quantity', 'woo-order-export-lite' ),
390
'checked' => 1,
391
+ 'format' => 'number',
392
),
393
+ 'qty_minus_refund' => array(
394
'label' => __( 'Quantity (- Refund)', 'woo-order-export-lite' ),
395
'checked' => 0,
396
+ 'format' => 'number',
397
),
398
+ 'item_price' => array(
399
'label' => __( 'Item Cost', 'woo-order-export-lite' ),
400
'checked' => 1,
401
'format' => 'money',
402
),
403
+ 'price' => array(
404
'label' => __( 'Product Current Price', 'woo-order-export-lite' ),
405
'checked' => 0,
406
'format' => 'money',
407
),
408
+ 'line_no_tax' => array(
409
'label' => __( 'Order Line (w/o tax)', 'woo-order-export-lite' ),
410
'checked' => 0,
411
'format' => 'money',
412
),
413
+ 'line_tax' => array(
414
'label' => __( 'Order Line Tax', 'woo-order-export-lite' ),
415
'checked' => 0,
416
'format' => 'money',
417
),
418
+ 'line_tax_refunded' => array(
419
'label' => __( 'Order Line Tax Refunded', 'woo-order-export-lite' ),
420
'checked' => 0,
421
'format' => 'money',
422
),
423
+ 'line_tax_minus_refund' => array(
424
'label' => __( 'Order Line Tax (- Refund)', 'woo-order-export-lite' ),
425
'checked' => 0,
426
'format' => 'money',
427
),
428
+ 'line_subtotal' => array(
429
'label' => __( 'Order Line Subtotal', 'woo-order-export-lite' ),
430
'checked' => 0,
431
'format' => 'money',
432
),
433
+ 'line_subtotal_tax' => array(
434
'label' => __( 'Order Line Subtotal Tax', 'woo-order-export-lite' ),
435
'checked' => 0,
436
'format' => 'money',
437
),
438
+ 'line_total' => array(
439
'label' => __( 'Order Line Total', 'woo-order-export-lite' ),
440
'checked' => 0,
441
'format' => 'money',
442
),
443
+ 'line_total_plus_tax' => array(
444
'label' => __( 'Order Line Total (include tax)', 'woo-order-export-lite' ),
445
'checked' => 0,
446
'format' => 'money',
447
),
448
+ 'line_total_refunded' => array(
449
'label' => __( 'Order Line Total Refunded', 'woo-order-export-lite' ),
450
'checked' => 0,
451
'format' => 'money',
452
),
453
+ 'line_total_minus_refund' => array(
454
'label' => __( 'Order Line Total (- Refund)', 'woo-order-export-lite' ),
455
'checked' => 0,
456
'format' => 'money',
457
),
458
+ 'discount_amount' => array(
459
'label' => __( 'Item Discount Amount', 'woo-order-export-lite' ),
460
'checked' => 0,
461
'format' => 'money',
462
),
463
+ 'tax_rate' => array(
464
'label' => __( 'Item Tax Rate', 'woo-order-export-lite' ),
465
'checked' => 0,
466
'format' => 'number',
467
),
468
+ 'type' => array(
469
+ 'label' => __( 'Type', 'woo-order-export-lite' ),
470
+ 'checked' => 0,
471
+ 'format' => 'string',
472
+ ),
473
+ 'category' => array(
474
'label' => __( 'Category', 'woo-order-export-lite' ),
475
'checked' => 0,
476
+ 'format' => 'string',
477
+ ),
478
+ 'tags' => array(
479
+ 'label' => __( 'Tags', 'woo-order-export-lite' ),
480
+ 'checked' => 0,
481
+ 'format' => 'string',
482
),
483
+ 'width' => array(
484
'label' => __( 'Width', 'woo-order-export-lite' ),
485
'checked' => 0,
486
'format' => 'number',
487
),
488
+ 'length' => array(
489
'label' => __( 'Length', 'woo-order-export-lite' ),
490
'checked' => 0,
491
'format' => 'number',
492
),
493
+ 'height' => array(
494
'label' => __( 'Height', 'woo-order-export-lite' ),
495
'checked' => 0,
496
'format' => 'number',
497
),
498
+ 'weight' => array(
499
'label' => __( 'Weight', 'woo-order-export-lite' ),
500
'checked' => 0,
501
'format' => 'number',
502
),
503
+ 'product_url' => array(
504
'label' => __( 'Product URL', 'woo-order-export-lite' ),
505
'checked' => 0,
506
+ 'format' => 'string',
507
),
508
+ 'download_url' => array(
509
'label' => __( 'Download URL', 'woo-order-export-lite' ),
510
'checked' => 0,
511
+ 'format' => 'string',
512
),
513
+ 'image_url' => array(
514
'label' => __( 'Image URL', 'woo-order-export-lite' ),
515
'checked' => 0,
516
+ 'format' => 'string',
517
),
518
+ 'product_shipping_class' => array(
519
'label' => __( 'Product Shipping Class', 'woo-order-export-lite' ),
520
'checked' => 0,
521
+ 'format' => 'string',
522
),
523
+ 'post_content' => array(
524
'label' => __( 'Description', 'woo-order-export-lite' ),
525
'checked' => 0,
526
+ 'format' => 'string',
527
),
528
+ 'post_excerpt' => array(
529
'label' => __( 'Short Description', 'woo-order-export-lite' ),
530
'checked' => 0,
531
+ 'format' => 'string',
532
),
533
+ 'full_category_names' => array(
534
'label' => __( 'Full names for categories', 'woo-order-export-lite' ),
535
'checked' => 0,
536
+ 'format' => 'string',
537
),
538
+ 'summary_report_total_qty' => array(
539
'label' => __( 'Summary Report Total Quantity', 'woo-order-export-lite' ),
540
'checked' => 0,
541
+ 'format' => 'number',
542
),
543
+ 'summary_report_total_amount' => array(
544
'label' => __( 'Summary Report Total Amount', 'woo-order-export-lite' ),
545
'checked' => 0,
546
+ 'format' => 'money',
547
),
548
);
549
560
'code' => array(
561
'label' => __( 'Coupon Code', 'woo-order-export-lite' ),
562
'checked' => 1,
563
+ 'format' => 'string',
564
),
565
'discount_amount' => array(
566
'label' => __( 'Discount Amount', 'woo-order-export-lite' ),
584
'discount_type' => array(
585
'label' => __( 'Coupon Type', 'woo-order-export-lite' ),
586
'checked' => 0,
587
+ 'format' => 'string',
588
),
589
'coupon_amount' => array(
590
'label' => __( 'Coupon Amount', 'woo-order-export-lite' ),
604
605
public static function get_order_fields( $format ) {
606
$map = array();
607
+ foreach (
608
+ array(
609
+ 'common',
610
+ 'user',
611
+ 'billing',
612
+ 'shipping',
613
+ 'product',
614
+ 'coupon',
615
+ 'cart',
616
+ 'ship_calc',
617
+ 'totals',
618
+ 'misc',
619
+ ) as $segment
620
+ ) {
621
$method = "get_order_fields_" . $segment;
622
$map_segment = self::$method();
623
636
637
public static function get_order_fields_common() {
638
return array(
639
+ 'line_number' => array(
640
+ 'label' => __( 'Line number', 'woo-order-export-lite' ),
641
'checked' => 0,
642
'format' => 'number',
643
),
644
+ 'order_id' => array(
645
+ 'label' => __( 'Order ID', 'woo-order-export-lite' ),
646
'checked' => 0,
647
'format' => 'number',
648
),
649
+ 'order_number' => array(
650
+ 'label' => __( 'Order Number', 'woo-order-export-lite' ),
651
'checked' => 1,
652
'format' => 'string',
653
),
654
+ 'order_status' => array(
655
+ 'label' => __( 'Order Status', 'woo-order-export-lite' ),
656
'checked' => 1,
657
'format' => 'string',
658
),
671
'checked' => 0,
672
'format' => 'string',
673
),
674
+ 'order_currency' => array(
675
'label' => __( 'Currency', 'woo-order-export-lite' ),
676
'checked' => 0,
677
'format' => 'string',
721
'checked' => 0,
722
'format' => 'string',
723
),
724
+ 'user_url' => array(
725
'label' => __( 'User Website', 'woo-order-export-lite' ),
726
'checked' => 0,
727
'format' => 'string',
930
931
public static function get_order_fields_cart() {
932
return array(
933
+ 'shipping_method_title' => array(
934
'label' => __( 'Shipping Method Title', 'woo-order-export-lite' ),
935
'checked' => 1,
936
'format' => 'string',
937
),
938
+ 'shipping_method' => array(
939
'label' => __( 'Shipping Method', 'woo-order-export-lite' ),
940
'checked' => 0,
941
'format' => 'string',
942
),
943
+ 'payment_method_title' => array(
944
'label' => __( 'Payment Method Title', 'woo-order-export-lite' ),
945
'checked' => 1,
946
'format' => 'string',
947
),
948
+ 'payment_method' => array(
949
'label' => __( 'Payment Method', 'woo-order-export-lite' ),
950
'checked' => 0,
951
'format' => 'string',
952
),
953
+ 'coupons_used' => array(
954
'label' => __( 'Coupons Used', 'woo-order-export-lite' ),
955
'checked' => 0,
956
'format' => 'string',
957
),
958
+ 'cart_discount' => array(
959
'label' => __( 'Cart Discount Amount', 'woo-order-export-lite' ),
960
'checked' => 1,
961
'format' => 'money',
962
),
963
+ 'cart_discount_tax' => array(
964
'label' => __( 'Cart Discount Amount Tax', 'woo-order-export-lite' ),
965
'checked' => 0,
966
'format' => 'money',
967
),
968
+ 'order_subtotal' => array(
969
'label' => __( 'Order Subtotal Amount', 'woo-order-export-lite' ),
970
'checked' => 1,
971
'format' => 'money',
972
),
973
+ 'order_subtotal_minus_discount' => array(
974
'label' => __( 'Order Subtotal - Cart Discount', 'woo-order-export-lite' ),
975
'checked' => 0,
976
'format' => 'money',
977
),
978
+ 'order_subtotal_refunded' => array(
979
'label' => __( 'Order Subtotal Amount Refunded', 'woo-order-export-lite' ),
980
'checked' => 0,
981
'format' => 'money',
982
),
983
+ 'order_subtotal_minus_refund' => array(
984
'label' => __( 'Order Subtotal Amount (- Refund)', 'woo-order-export-lite' ),
985
'checked' => 0,
986
'format' => 'money',
987
),
988
+ 'order_tax' => array(
989
'label' => __( 'Order Tax Amount', 'woo-order-export-lite' ),
990
'checked' => 0,
991
'format' => 'money',
992
),
993
);
994
}
995
+
996
public static function get_order_fields_ship_calc() {
997
return array(
998
'order_shipping' => array(
1000
'checked' => 1,
1001
'format' => 'money',
1002
),
1003
+ 'order_shipping_plus_tax' => array(
1004
'label' => __( 'Order Shipping + Tax Amount', 'woo-order-export-lite' ),
1005
'checked' => 0,
1006
'format' => 'money',
1032
),
1033
);
1034
}
1035
+
1036
public static function get_order_fields_totals() {
1037
return array(
1038
+ 'order_total_fee' => array(
1039
'label' => __( 'Order Total Fee', 'woo-order-export-lite' ),
1040
'checked' => 0,
1041
'format' => 'money',
1042
),
1043
+ 'order_refund' => array(
1044
'label' => __( 'Order Refund Amount', 'woo-order-export-lite' ),
1045
'checked' => 1,
1046
'format' => 'money',
1047
),
1048
+ 'order_total_inc_refund' => array(
1049
'label' => __( 'Order Total Amount (- Refund)', 'woo-order-export-lite' ),
1050
'checked' => 0,
1051
'format' => 'money',
1052
),
1053
+ 'order_total' => array(
1054
'label' => __( 'Order Total Amount', 'woo-order-export-lite' ),
1055
'checked' => 1,
1056
'format' => 'money',
1057
),
1058
+ 'order_total_no_tax' => array(
1059
'label' => __( 'Order Total Amount without Tax', 'woo-order-export-lite' ),
1060
'checked' => 0,
1061
'format' => 'money',
1062
),
1063
+ 'order_total_tax' => array(
1064
'label' => __( 'Order Total Tax Amount', 'woo-order-export-lite' ),
1065
'checked' => 1,
1066
'format' => 'money',
1067
),
1068
+ 'order_total_tax_refunded' => array(
1069
'label' => __( 'Order Total Tax Amount Refunded', 'woo-order-export-lite' ),
1070
'checked' => 0,
1071
'format' => 'money',
1072
),
1073
+ 'order_total_tax_minus_refund' => array(
1074
'label' => __( 'Order Total Tax Amount (- Refund)', 'woo-order-export-lite' ),
1075
'checked' => 0,
1076
'format' => 'money',
1117
1118
public static function get_order_segments() {
1119
return array(
1120
+ 'common' => __( 'Common', 'woo-order-export-lite' ),
1121
+ 'user' => __( 'User', 'woo-order-export-lite' ),
1122
+ 'billing' => __( 'Billing Address', 'woo-order-export-lite' ),
1123
+ 'shipping' => __( 'Shipping Address', 'woo-order-export-lite' ),
1124
+ 'products' => __( 'Products', 'woo-order-export-lite' ),
1125
+ 'coupons' => __( 'Coupons', 'woo-order-export-lite' ),
1126
+ 'cart' => __( 'Cart', 'woo-order-export-lite' ),
1127
+ 'ship_calc' => __( 'Shipping', 'woo-order-export-lite' ),
1128
+ 'totals' => __( 'Totals', 'woo-order-export-lite' ),
1129
+ 'misc' => __( 'Others', 'woo-order-export-lite' ),
1130
);
1131
}
1132
classes/core/class-wc-order-export-data-extractor.php CHANGED
@@ -429,8 +429,10 @@ class WC_Order_Export_Data_Extractor {
429
$product_where = join( " AND ", $product_where );
430
$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 ";
431
$settings['products'] = $wpdb->get_col( $sql );
432
- if( empty($settings['products']) ) // failed condition!
433
- $settings['products'] = array(0);
434
}
435
436
// we have to use variations , if user sets product attributes
@@ -438,8 +440,10 @@ class WC_Order_Export_Data_Extractor {
438
$values = self::sql_subset( $settings['products'] );
439
$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)";
440
$settings['products'] = $wpdb->get_col( $sql );
441
- if( empty($settings['products']) ) // failed condition!
442
- $settings['products'] = array(0);
443
}
444
if ( ! empty( $sql ) AND self::$track_sql_queries ) {
445
self::$sql_queries[] = $sql;
@@ -741,7 +745,7 @@ class WC_Order_Export_Data_Extractor {
741
}
742
}
743
}
744
- if ( ! empty($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;
@@ -754,7 +758,7 @@ class WC_Order_Export_Data_Extractor {
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();
@@ -762,7 +766,7 @@ class WC_Order_Export_Data_Extractor {
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 ++;
@@ -798,36 +802,36 @@ class WC_Order_Export_Data_Extractor {
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
@@ -1174,8 +1178,8 @@ class WC_Order_Export_Data_Extractor {
1174
global $wpdb;
1175
$coupons = array();
1176
foreach ( $order->get_items( 'coupon' ) as $item ) {
1177
- $coupon_meta = array();
1178
- $get_coupon_meta = ( array_diff( $labels->get_keys(),
1179
array( 'code', 'discount_amount', 'discount_amount_tax', 'excerpt' ) ) );
1180
if ( $get_coupon_meta ) {
1181
$recs = $wpdb->get_results( $wpdb->prepare( "SELECT meta_value,meta_key FROM {$wpdb->postmeta} AS meta
@@ -1216,15 +1220,16 @@ class WC_Order_Export_Data_Extractor {
1216
}
1217
}
1218
1219
- return apply_filters( "woe_fetch_order_coupons", $coupons, $order, $labels->get_legacy_labels(), $format="", $static_vals );
1220
}
1221
1222
1223
/**
1224
- * @param WC_Order $order
1225
* @param WC_Order_Export_Labels $labels
1226
- * @param array $static_vals
1227
- * @param array $options
1228
*
1229
* @return array
1230
*/
@@ -1234,7 +1239,7 @@ class WC_Order_Export_Data_Extractor {
1234
$static_vals,
1235
$options
1236
) {
1237
- $export_only_products = $options['include_products'];
1238
$product_fields_with_tags = array( 'product_variation', 'post_content', 'post_excerpt' );
1239
$products = array();
1240
$i = 0;
@@ -1306,10 +1311,14 @@ class WC_Order_Export_Data_Extractor {
1306
$row[ $field ] = implode( ', ', $taxonomies );
1307
} else if ( $field == 'product_shipping_class' ) {
1308
$taxonomies = array();
1309
- if( !empty($item['variation_id']) )// try get from variation at first!
1310
- $taxonomies = wc_get_product_terms( $item['variation_id'], $field,array( 'fields' => 'names' ) );
1311
- if( !$taxonomies )
1312
- $taxonomies = wc_get_product_terms( $item['product_id'], $field,array( 'fields' => 'names' ) );
1313
//done
1314
$row[ $field ] = implode( ', ', $taxonomies );
1315
} elseif ( $field == 'line_total_plus_tax' ) {
@@ -1465,8 +1474,9 @@ class WC_Order_Export_Data_Extractor {
1465
$products[ $item_id ] = $row;
1466
}
1467
}
1468
-
1469
- return apply_filters( "woe_fetch_order_products", $products, $order, $labels->get_legacy_labels(), $format="", $static_vals );
1470
}
1471
1472
@@ -1526,12 +1536,12 @@ class WC_Order_Export_Data_Extractor {
1526
global $wp_roles;
1527
1528
// $extra_rows = array();
1529
- $row = array();
1530
1531
// get order meta
1532
$order_meta = array();
1533
- if ( $order_post_meta = get_post_meta( $order_id )) {
1534
- foreach ( $order_post_meta as $meta_key=>$meta_values ) {
1535
$order_meta[ $meta_key ] = join( self::$export_custom_fields_separator, $meta_values );
1536
}
1537
}
@@ -1557,7 +1567,7 @@ class WC_Order_Export_Data_Extractor {
1557
$overwrite_child_order_meta = apply_filters( 'woe_overwrite_child_order_meta', $is_refund );
1558
1559
if ( $parent_order_meta = get_post_meta( $parent_order_id ) ) {
1560
- foreach ( $parent_order_meta as $meta_key=>$meta_values ) {
1561
if ( $overwrite_child_order_meta OR ! isset( $order_meta[ $meta_key ] ) ) {
1562
$order_meta[ $meta_key ] = join( self::$export_custom_fields_separator, $meta_values );
1563
}
@@ -1585,23 +1595,30 @@ class WC_Order_Export_Data_Extractor {
1585
}
1586
1587
// we know parent!
1588
- if ( ( $export['products'] || isset( $labels['order']->count_unique_products ) || isset( $labels['order']->total_weight_items ) || $options['include_products'] ) && ! empty( $labels['products'] ) ) {
1589
- $tmp_labels = clone $labels['products'];
1590
- // need qty and weight?
1591
- if( isset( $labels['order']->total_weight_items ) ) {
1592
- if( !isset($tmp_labels->qty) )
1593
$tmp_labels->qty = "";
1594
- if( !isset($tmp_labels->weight) )
1595
$tmp_labels->weight = "";
1596
}
1597
$data['products'] = self::fetch_order_products(
1598
$order,
1599
$tmp_labels,
1600
- isset($static_vals['products']) ? $static_vals['products'] : array(),
1601
$options
1602
);
1603
- if ( $options['include_products'] AND empty( $data['products'] ) AND apply_filters( "woe_skip_order_without_products",
1604
- false ) ) {
1605
return array();
1606
}
1607
} else {
@@ -1612,7 +1629,7 @@ class WC_Order_Export_Data_Extractor {
1612
$data['coupons'] = self::fetch_order_coupons(
1613
$parent_order ? $parent_order : $order,
1614
$labels['coupons'],
1615
- isset($static_vals['coupons']) ? $static_vals['coupons'] : array(),
1616
$options
1617
);
1618
} else {
@@ -1676,7 +1693,7 @@ class WC_Order_Export_Data_Extractor {
1676
} elseif ( $field == 'order_shipping' ) {
1677
$row[ $field ] = $order->get_shipping_total();
1678
} elseif ( $field == 'order_shipping_plus_tax' ) {
1679
- $row[ $field ] = $order->get_shipping_total()+$order->get_shipping_tax();
1680
} elseif ( $field == 'order_shipping_refunded' ) {
1681
$row[ $field ] = $order->get_total_shipping_refunded();
1682
} elseif ( $field == 'order_shipping_minus_refund' ) {
@@ -1700,13 +1717,13 @@ class WC_Order_Export_Data_Extractor {
1700
} elseif ( $field == 'order_total_tax_minus_refund' ) {
1701
$row[ $field ] = wc_round_tax_total( $order->get_total_tax() - $order->get_total_tax_refunded() );
1702
} elseif ( $field == 'order_status' ) {
1703
- $status = empty( $order_status ) ? $order->get_status() : $order_status;
1704
- $status = 'wc-' === substr( $status, 0, 3 ) ? substr( $status, 3 ) : $status;
1705
$row[ $field ] = isset( self::$statuses[ 'wc-' . $status ] ) ? self::$statuses[ 'wc-' . $status ] : $status;
1706
- } elseif ( $field == 'user_login' OR $field == 'user_email' OR $field == 'user_url') {
1707
$row[ $field ] = $user ? $user->$field : "";
1708
} elseif ( $field == 'user_role' ) {
1709
- $roles = $wp_roles->roles;
1710
$row[ $field ] = ( isset( $user->roles[0] ) && isset( $roles[ $user->roles[0] ] ) ) ? $roles[ $user->roles[0] ]['name'] : ""; // take first role Name
1711
} elseif ( $field == 'customer_total_orders' ) {
1712
$row[ $field ] = ( isset( $user->ID ) ) ? wc_get_customer_order_count( $user->ID ) : 0;
@@ -1835,7 +1852,16 @@ class WC_Order_Export_Data_Extractor {
1835
} //if order field set
1836
}
1837
1838
$row = apply_filters( "woe_fetch_order", $row, $order );
1839
return $row;
1840
}
1841
@@ -1918,7 +1944,7 @@ class WC_Order_Export_Data_Extractor {
1918
if ( taxonomy_exists( wc_sanitize_taxonomy_name( $meta['meta_key'] ) ) ) {
1919
$term = get_term_by( 'slug', $meta['meta_value'],
1920
wc_sanitize_taxonomy_name( $meta['meta_key'] ) );
1921
- $meta['meta_key'] = wc_attribute_label( wc_sanitize_taxonomy_name( $meta['meta_key'] ), $product);
1922
$meta['meta_value'] = isset( $term->name ) ? $term->name : $meta['meta_value'];
1923
} else {
1924
$meta['meta_key'] = wc_attribute_label( $meta['meta_key'], $product );
<
429
$product_where = join( " AND ", $product_where );
430
$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 ";
431
$settings['products'] = $wpdb->get_col( $sql );
432
+ if ( empty( $settings['products'] ) ) // failed condition!
433
+ {
434
+ $settings['products'] = array( 0 );
435
+ }
436
}
437
438
// we have to use variations , if user sets 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
+ if ( empty( $settings['products'] ) ) // failed condition!
444
+ {
445
+ $settings['products'] = array( 0 );
446
+ }
447
}
448
if ( ! empty( $sql ) AND self::$track_sql_queries ) {
449
self::$sql_queries[] = $sql;
745
}
746
}
747
}
748
+ if ( ! empty( $settings['user_custom_fields'] ) ) {
749
$cf_names = self::get_user_custom_fields();
750
$filters = self::parse_complex_pairs( $settings['user_custom_fields'], $cf_names );
751
$pos = 1;
758
} elseif ( $operator == 'IS SET' ) {
759
$user_meta_where[] = " ( usermeta_cf_{$pos}.meta_value IS NOT NULL ) ";
760
} elseif ( $operator == 'IN' OR $operator == 'NOT IN' ) {
761
+ $values = self::sql_subset( $values );
762
$user_meta_where[] = " ( usermeta_cf_{$pos}.meta_value $operator ($values) ) ";
763
} elseif ( in_array( $operator, self::$operator_must_check_values ) ) {
764
$pairs = array();
766
$pairs[] = self::operator_compare_field_and_value( "`usermeta_cf_{$pos}`.meta_value",
767
$operator, $v );
768
}
769
+ $pairs = join( "OR", $pairs );
770
$user_meta_where[] = " ( $pairs ) ";
771
}
772
$pos ++;
802
}
803
804
// users
805
+ $user_ids = array();
806
$user_ids_ui_filters_applied = false;
807
if ( ! empty( $settings['user_names'] ) ) {
808
+ $user_ids = array_filter( array_map( "intval", $settings['user_names'] ) );
809
+ $values = self::sql_subset( $user_ids );
810
$user_meta_where[] = "( {$wpdb->users}.ID IN ($values) )";
811
}
812
//roles
813
if ( ! empty( $settings['user_roles'] ) ) {
814
+ $metakey = $wpdb->get_blog_prefix() . 'capabilities';
815
$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'";
816
817
$roles_where = array();
818
foreach ( $settings['user_roles'] as $role ) {
819
$roles_where[] = "( usermeta_cf_role.meta_value LIKE '%$role%' )";
820
}
821
+ $user_meta_where[] = "(" . join( ' OR ', $roles_where ) . ")";
822
}
823
if ( ! empty( $user_meta_where ) AND ! empty( $inner_join_user_meta ) ) {
824
$user_meta_where = join( ' AND ', $user_meta_where );
825
$inner_join_user_meta = join( ' ', $inner_join_user_meta );
826
+ $sql = "SELECT DISTINCT ID FROM {$wpdb->users} $inner_join_user_meta WHERE $user_meta_where";
827
if ( self::$track_sql_queries ) {
828
self::$sql_queries[] = $sql;
829
}
830
+ $user_ids = $wpdb->get_col( $sql );
831
$user_ids_ui_filters_applied = true;
832
}
833
$user_ids = apply_filters( "woe_sql_get_customer_ids", $user_ids, $settings );
834
+ if ( empty( $user_ids ) AND $user_ids_ui_filters_applied ) {
835
$order_meta_where [] = "0"; // user filters failed
836
}
837
1178
global $wpdb;
1179
$coupons = array();
1180
foreach ( $order->get_items( 'coupon' ) as $item ) {
1181
+ $coupon_meta = array();
1182
+ $get_coupon_meta = ( array_diff( $labels->get_keys(),
1183
array( 'code', 'discount_amount', 'discount_amount_tax', 'excerpt' ) ) );
1184
if ( $get_coupon_meta ) {
1185
$recs = $wpdb->get_results( $wpdb->prepare( "SELECT meta_value,meta_key FROM {$wpdb->postmeta} AS meta
1220
}
1221
}
1222
1223
+ return apply_filters( "woe_fetch_order_coupons", $coupons, $order, $labels->get_legacy_labels(), $format = "",
1224
+ $static_vals );
1225
}
1226
1227
1228
/**
1229
+ * @param WC_Order $order
1230
* @param WC_Order_Export_Labels $labels
1231
+ * @param array $static_vals
1232
+ * @param array $options
1233
*
1234
* @return array
1235
*/
1239
$static_vals,
1240
$options
1241
) {
1242
+ $export_only_products = $options['include_products'];