Order Export & Order Import for WooCommerce - Version 1.3.3

Version Description

  • Sample CSV file updated.
  • WC 3.4.3 Tested OK.
  • Bug fix.
Download this release

Release Info

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

Code changes from version 1.3.2 to 1.3.3

Files changed (41) hide show
  1. Sample_Coupon.csv +2 -2
  2. Sample_Order.csv +7 -4
  3. Sample_Subscription.csv +3 -3
  4. includes/class-wf-cpnimpexpcsv-admin-screen.php +95 -95
  5. includes/class-wf-cpnimpexpcsv-ajax-handler.php +20 -20
  6. includes/class-wf-cpnimpexpcsv-system-status-tools.php +54 -54
  7. includes/class-wf-orderimpexpcsv-admin-screen.php +81 -81
  8. includes/class-wf-orderimpexpcsv-ajax-handler.php +24 -24
  9. includes/class-wf-orderimpexpcsv-system-status-tools.php +63 -63
  10. includes/exporter/class-wf-cpnimpexpcsv-exporter.php +173 -173
  11. includes/exporter/class-wf-orderimpexpcsv-exporter.php +379 -379
  12. includes/exporter/data/data-wf-post-columns-coupon.php +31 -31
  13. includes/exporter/data/data-wf-post-columns.php +55 -55
  14. includes/importer/class-wf-cpnimpexpcsv-coupon-import.php +1050 -1050
  15. includes/importer/class-wf-cpnimpexpcsv-importer.php +40 -40
  16. includes/importer/class-wf-csv-parser-coupon.php +223 -223
  17. includes/importer/class-wf-csv-parser.php +805 -802
  18. includes/importer/class-wf-orderimpexpcsv-importer.php +40 -40
  19. includes/importer/class-wf-orderimpexpcsv-order-import.php +900 -900
  20. includes/importer/data-coupon/data-wf-post-defaults.php +21 -21
  21. includes/importer/data-coupon/data-wf-postmeta-allowed.php +15 -15
  22. includes/importer/data-coupon/data-wf-postmeta-defaults.php +23 -23
  23. includes/importer/data-coupon/data-wf-reserved-fields-pair.php +31 -31
  24. includes/importer/data-coupon/data-wf-reserved-fields.php +34 -34
  25. includes/importer/data/data-wf-reserved-fields-pair.php +52 -52
  26. includes/importer/views-coupon/html-wf-import-greeting.php +42 -42
  27. includes/importer/views-coupon/html-wf-import-options.php +17 -17
  28. includes/importer/views/html-wf-import-greeting.php +42 -42
  29. includes/importer/views/html-wf-import-options.php +27 -27
  30. includes/settings/class-wf-orderimpexpcsv-settings.php +21 -21
  31. includes/views/export/html-wf-export-coupons.php +14 -14
  32. includes/views/export/html-wf-export-orders.php +10 -10
  33. includes/views/html-wf-admin-screen.php +25 -25
  34. includes/views/html-wf-getting-started-subscription.php +17 -18
  35. includes/views/import/html-wf-import-coupons.php +24 -24
  36. includes/views/import/html-wf-import-orders.php +23 -23
  37. includes/views/market.php +58 -60
  38. license.txt +707 -707
  39. order-import-export.php +281 -281
  40. readme.txt +11 -5
  41. styles/wf-style.css +266 -266
Sample_Coupon.csv CHANGED
@@ -1,2 +1,2 @@
1
- post_title,ID,post_excerpt,post_status,post_date,post_author,discount_type,coupon_amount,individual_use,product_ids,exclude_product_ids,usage_limit,usage_limit_per_user,limit_usage_to_x_items,expiry_date,free_shipping,exclude_sale_items,product_categories,exclude_product_categories,minimum_amount,maximum_amount,customer_email
2
- coupon1003,502,Not so dummy,publish,8/26/2016 5:30,1,percent_product,57,yes,,,10,10,3,2/28/2017,no,yes,"8, 9, 6","2, 10, 7",70,80,"patra@gmail.com, patra@hotmail.com, patra@yahoo.co.in"
1
+ post_title,ID,post_excerpt,post_status,post_date,post_author,discount_type,coupon_amount,individual_use,product_ids,exclude_product_ids,usage_limit,usage_limit_per_user,limit_usage_to_x_items,expiry_date,free_shipping,exclude_sale_items,product_categories,exclude_product_categories,minimum_amount,maximum_amount,customer_email
2
+ coupon1003,502,Not so dummy,publish,8/26/2016 5:30,1,percent_product,57,yes,,,10,10,3,2/28/2017,no,yes,"8, 9, 6","2, 10, 7",70,80,"patra@gmail.com, patra@hotmail.com, patra@yahoo.co.in"
Sample_Order.csv CHANGED
@@ -1,4 +1,7 @@
1
- order_id,order_number,order_date,status,shipping_total,shipping_tax_total,fee_total,fee_tax_total,tax_total,cart_discount,order_discount,discount_total,order_total,refunded_total,order_currency,payment_method,shipping_method,customer_id,customer_user,billing_first_name,billing_last_name,billing_company,billing_email,billing_phone,billing_address_1,billing_address_2,billing_postcode,billing_city,billing_state,billing_country,shipping_first_name,shipping_last_name,shipping_company,shipping_address_1,shipping_address_2,shipping_postcode,shipping_city,shipping_state,shipping_country,customer_note,shipping_items,fee_items,tax_items,coupon_items,order_notes,download_permissions,line_item_1,line_item_2,line_item_3
2
- 737,737,6/10/2016 5:56,processing,33.8,1.69,0,0,1.69,0,0,0,135.49,0,USD,cod,2nd Day Air (UPS),1,1,Sam,Jerry,MEGASYSTEMS INC,info@wooforce.com,8088379844,SUITE 5A-120,799 E DRAGRAM,90001,San Francisco,CA,US,Sam,Jerry,MEGASYSTEMS INC,SUITE 5A-120,799 E DRAGRAM,90001,San Francisco,CA,US,,method:2nd Day Air (UPS)|total:33.80,,code:US-V.A.T-1|total:1.69,,Payment to be made upon delivery. Order status changed from Pending Payment to Processing.,1,name:Red Hat|product_id:35|sku:003|quantity:1|total:100.00|refunded:0.00|meta:|tax:0.00,,
3
- 736,736,6/9/2016 14:15,processing,213.28,10.66,0,0,10.66,3,3,3,532.94,0,USD,cod,Ground (UPS),1,1,Sam,Jerry,MEGASYSTEMS INC,info@wooforce.com,8088379844,SUITE 5A-120,799 E DRAGRAM,90001,San Francisco,CA,US,Sam,Jerry,MEGASYSTEMS INC,SUITE 5A-120,799 E DRAGRAM,90001,San Francisco,CA,US,,method:Ground (UPS)|total:213.28,,code:US-V.A.T-1|total:10.66,code:7272ll|description:|amount:3.00,Payment to be made upon delivery. Order status changed from Pending Payment to Processing.,1,name:Men's Cotton T-Shirt|product_id:47|sku:B11V2|quantity:1|total:11.88|refunded:0.00|meta:color=Red|tax:0.00,name:Gift5|product_id:52|sku:006|quantity:1|total:198.08|refunded:0.00|meta:|tax:0.00,name:Red Hat|product_id:35|sku:003|quantity:1|total:99.04|refunded:0.00|meta:|tax:0.00
4
- 519,519,4/22/2016 7:40,processing,24.45,0,0,0,0,0,0,0,274.45,0,USD,cod,FedEx Ground (Delivery - Mon),2,2,John,Smith,ABC,john@example.com,123456789,SUITE 5A-120,799 E DRAGRAM,98102,SEATTLE,WA,US,John,Smith,ABC,SUITE 5A-120,799 E DRAGRAM,98102,SEATTLE,WA,US,,method:FedEx Ground (Delivery - Mon)|total:24.45,,,,Payment to be made upon delivery. Order status changed from Pending Payment to Processing.,1,name:Red Hat|product_id:35|sku:003|quantity:1|total:100.00|refunded:0.00|meta:|tax:0.00,name:Tee Shirt|product_id:36|sku:008|quantity:1|total:150.00|refunded:0.00|meta:|tax:0.00,
 
 
 
1
+ order_id,order_number,order_date,status,shipping_total,shipping_tax_total,fee_total,fee_tax_total,tax_total,cart_discount,order_discount,discount_total,order_total,refunded_total,order_currency,payment_method,shipping_method,customer_id,customer_user,customer_email,billing_first_name,billing_last_name,billing_company,billing_email,billing_phone,billing_address_1,billing_address_2,billing_postcode,billing_city,billing_state,billing_country,shipping_first_name,shipping_last_name,shipping_company,shipping_address_1,shipping_address_2,shipping_postcode,shipping_city,shipping_state,shipping_country,customer_note,shipping_items,fee_items,tax_items,coupon_items,order_notes,download_permissions,line_item_1,line_item_2,line_item_3
2
+ 1001,1001,16-05-2018 07:32,completed,10,1.8,1,0.18,3.42,0,0,0,22.42,0,USD,cod,Express Delivery,3,3,lilly@example.com,Lilly,Gordon,,lilly@example.com,9898989898,20 Maple Avenue,,90731,San Pedro,CA,US,Lilly,Gordon,,20 Maple Avenue,"Door No,16",90731,San Pedro,CA,US,Deliver with a smile!,"item:Items|value:Formal shoe X 1
3
+ ",name:Gift Wrap|total:1.00|tax:0.18,code:GST-1|total:3.42,,Order status changed from Processing to Completed.|Formal shoe (A12) stock reduced from 20 to 19.|Payment to be made upon delivery. Order status changed from Pending payment to Processing.,1,name:Formal shoe||sku:A12|quantity:1|total:8.00|tax:1.44,,
4
+ 1002,1002,16-05-2018 07:25,on-hold,10,1.8,0,0,5.04,0,0,0,33.04,0,USD,paypal,Express Delivery,0,0,,John,Edward,,john@example.com,9999999,300 BOYLSTON AVE E,,98102,Seattle,WA,US,John,Edward,,300 BOYLSTON AVE E,,98102,Seattle,WA,US,,"item:Items|value:Washing machine X 1
5
+ ",,code:GST-1|total:5.04,,Order status changed from Pending payment to Processing.|Washing machine (A15) stock reduced from 30 to 29.|IPN payment completed,1,name:Washing machine|product_id:616773451|sku:A15|quantity:1|total:18.00|tax:3.24,,
6
+ 1003,1003,16-05-2018 07:21,processing,10,1.8,0,0,8.99,10,10,10,58.98,0,USD,eh_stripe_pay,Express Delivery,2,2,mark@example.com,Mark,Xa,Xadapter,mark@example.com,9898989898,20 Maple Avenue,,90731,San Pedro,CA,US,Mark,Xa,Xadapter,20 Maple Avenue,,90731,San Pedro,CA,US,,"item:Items|value:LED TV X 1, Samsung Galaxy Ace Duos X 1, Men's Cotton T-Shirt - Red X 1
7
+ ",,code:GST-1|total:8.99,code:flat20|description:Get flat 20% discount on all purchases|amount:10.00,"Order status changed from Pending payment to Processing.|LED TV (A13) stock reduced from 19 to 18.|Samsung Galaxy Ace Duos (A11) stock reduced from 10 to 9.|Men's Cotton T-Shirt - Red (B11V2)<span class=""description""></span> stock reduced from 9 to 8.|Payment Status : Succeeded [ 2018-05-16 12:51:06 ] . Source : Visa( credit ). Charge Status :Captured. Transaction ID : txn_1CSJwcJ91uK4qPibEmTjip6P:is_customer_note",1,name:LED TV|product_id:616773447|sku:A13|quantity:1|total:23.19|tax:4.17,name:Samsung Galaxy Ace Duos|product_id:616773443|sku:A11|quantity:1|total:8.80|tax:1.58,name:Men's Cotton T-Shirt|product_id:616773455|sku:B11V2|quantity:1|total:8.00|color:Red|_variation_id:616773455|tax:1.44
Sample_Subscription.csv CHANGED
@@ -1,3 +1,3 @@
1
- subscription_id,subscription_status,customer_id,customer_username,customer_email,start_date,trial_end_date,next_payment_date,last_payment_date,end_date,post_parent,billing_period,billing_interval,order_shipping,order_shipping_tax,fee_total,fee_tax_total,order_tax,cart_discount,cart_discount_tax,order_total,order_currency,payment_method,payment_method_title,payment_method_post_meta,payment_method_user_meta,shipping_method,billing_first_name,billing_last_name,billing_email,billing_phone,billing_address_1,billing_address_2,billing_postcode,billing_city,billing_state,billing_country,billing_company,shipping_first_name,shipping_last_name,shipping_address_1,shipping_address_2,shipping_postcode,shipping_city,shipping_state,shipping_country,shipping_company,customer_note,order_items,order_notes,coupon_items,fee_items,tax_items,download_permissions,
2
- 87,wc-active,2,mark,mark@xadapter.com,2016-08-30 07:22:27,2016-09-04 07:22:27,2016-09-04 07:22:27,2016-08-30 07:22:32,2016-12-04 07:22:27,86,month,1,0,0,0,0,0,0,0,9,USD,stripe,Credit card (Stripe),,,,Mark,Wough,mark@xadapter.com,74747474,1st Ave,San Deigo,90001,Naples,AL,US,MarkCO LTD,Steve,Wough,1st Ave,San Deigo,90001,Naples,AL,US,MarkCO LTD,,product_id:10|name:Test Subscription Prdocut|quantity:1|total:9.00|meta:|tax:0.00,Payment received.,Status changed from Pending to Active.,,,,1
3
- 89,wc-on-hold,9,elvin,elvin@wooforce.com,2016-08-25 19:28:19,2016-08-30 19:28:19,2016-08-30 19:28:19,2016-08-31 06:18:25,2016-11-30 19:28:19,88,month,1,0,0,0,0,0,0,0,9,USD,stripe,Credit card (Stripe),,,,Elvin,j,elvin@xadapter.com,74747474,1st Ave,Naples,90001,Naples,AL,US,MarkCO LTD,Mark,Wough,1st Ave,Naples,90001,Naples,AL,US,ElvinCO LTD,Just checking Elvin Placed the Order,product_id:10|name:Test Subscription Prdocut|quantity:1|total:9.00|meta:|tax:0.00,"Payment failed.;Order <a href=""http://localhost/latestpress/wp-admin/post.php?post=233&#038;action=edit"">#233</a> created to record renewal.;Subscription renewal payment due: Status changed from Active to On hold.;Payment received.;Status changed from Pending to Active.",code:|description:|amount:0.00,,,0,
1
+ subscription_id,subscription_status,customer_id,customer_username,customer_email,start_date,trial_end_date,next_payment_date,last_payment_date,end_date,post_parent,billing_period,billing_interval,order_shipping,order_shipping_tax,fee_total,fee_tax_total,order_tax,cart_discount,cart_discount_tax,order_total,order_currency,payment_method,payment_method_title,payment_method_post_meta,payment_method_user_meta,shipping_method,billing_first_name,billing_last_name,billing_email,billing_phone,billing_address_1,billing_address_2,billing_postcode,billing_city,billing_state,billing_country,billing_company,shipping_first_name,shipping_last_name,shipping_address_1,shipping_address_2,shipping_postcode,shipping_city,shipping_state,shipping_country,shipping_company,customer_note,order_items,order_notes,coupon_items,fee_items,tax_items,download_permissions,
2
+ 87,wc-active,2,mark,mark@xadapter.com,2016-08-30 07:22:27,2016-09-04 07:22:27,2016-09-04 07:22:27,2016-08-30 07:22:32,2016-12-04 07:22:27,86,month,1,0,0,0,0,0,0,0,9,USD,stripe,Credit card (Stripe),,,,Mark,Wough,mark@xadapter.com,74747474,1st Ave,San Deigo,90001,Naples,AL,US,MarkCO LTD,Steve,Wough,1st Ave,San Deigo,90001,Naples,AL,US,MarkCO LTD,,product_id:10|name:Test Subscription Prdocut|quantity:1|total:9.00|meta:|tax:0.00,Payment received.,Status changed from Pending to Active.,,,,1
3
+ 89,wc-on-hold,9,elvin,elvin@wooforce.com,2016-08-25 19:28:19,2016-08-30 19:28:19,2016-08-30 19:28:19,2016-08-31 06:18:25,2016-11-30 19:28:19,88,month,1,0,0,0,0,0,0,0,9,USD,stripe,Credit card (Stripe),,,,Elvin,j,elvin@xadapter.com,74747474,1st Ave,Naples,90001,Naples,AL,US,MarkCO LTD,Mark,Wough,1st Ave,Naples,90001,Naples,AL,US,ElvinCO LTD,Just checking Elvin Placed the Order,product_id:10|name:Test Subscription Prdocut|quantity:1|total:9.00|meta:|tax:0.00,"Payment failed.;Order <a href=""http://localhost/latestpress/wp-admin/post.php?post=233&#038;action=edit"">#233</a> created to record renewal.;Subscription renewal payment due: Status changed from Active to On hold.;Payment received.;Status changed from Pending to Active.",code:|description:|amount:0.00,,,0,
includes/class-wf-cpnimpexpcsv-admin-screen.php CHANGED
@@ -1,96 +1,96 @@
1
- <?php
2
- if ( ! defined( 'ABSPATH' ) ) {
3
- exit;
4
- }
5
-
6
- class WF_CpnImpExpCsv_Admin_Screen {
7
-
8
- public function __construct()
9
- {
10
- add_action( 'admin_menu', array( $this, 'admin_menu' ) );
11
- add_action( 'admin_print_styles', array( $this, 'admin_scripts' ) );
12
- add_action( 'admin_notices', array( $this, 'admin_notices' ) );
13
-
14
- }
15
-
16
- public function admin_notices()
17
- {
18
- if ( ! function_exists( 'mb_detect_encoding' ) ) {
19
- echo '<div class="error"><p>' . __( 'Coupon CSV Import Export requires the function <code>mb_detect_encoding</code> to import and export CSV files. Please ask your hosting provider to enable this function.', 'wf_order_import_export' ) . '</p></div>';
20
- }
21
- }
22
-
23
- public function admin_menu()
24
- {
25
- $page = add_submenu_page( 'woocommerce', __( 'Coupon Im-Ex', 'wf_order_import_export' ), __( 'Coupon Im-Ex', 'wf_order_import_export' ), apply_filters( 'coupon_csv_coupon_role', 'manage_woocommerce' ), 'wf_coupon_csv_im_ex', array( $this, 'output' ) );
26
- }
27
-
28
- public static function hf_get_wc_path()
29
- {
30
- if (function_exists('WC')){
31
- $wc_path = WC()->plugin_url();
32
- }else{
33
- $wc_path = plugins_url() . '/woocommerce';
34
- }
35
- return $wc_path;
36
- }
37
-
38
- public function admin_scripts()
39
- {
40
- $wc_path = self::hf_get_wc_path();
41
- wp_enqueue_style( 'woocommerce_admin_styles', $wc_path. '/assets/css/admin.css' );
42
- wp_enqueue_style( 'woocommerce-coupon-csv-importer1', plugins_url( basename( plugin_dir_path( WF_CpnImpExpCsv_FILE ) ) . '/styles/wf-style.css', basename( __FILE__ ) ), '', '1.0.0', 'screen' );
43
-
44
- }
45
-
46
- public function output()
47
- {
48
- $tab = 'import';
49
-
50
-
51
- if(! empty( $_GET['page'] ))
52
- {
53
- if ( $_GET['page'] == 'wf_coupon_csv_im_ex' ) {
54
- $tab = 'coupon';
55
- }
56
- }
57
- if( ! empty( $_GET['tab'] )) {
58
- if( $_GET['tab'] == 'export' ) {
59
- $tab = 'export';
60
- }
61
- else if ( $_GET['tab'] == 'settings' ) {
62
- $tab = 'settings';
63
- }
64
- else if ( $_GET['tab'] == 'coupon' ) {
65
- $tab = 'coupon';
66
- }
67
- }
68
- include( 'views/html-wf-admin-screen.php' );
69
- }
70
-
71
-
72
- public function admin_import_page() {
73
- include( 'views/html-wf-getting-started.php' );
74
- include( 'views/import/html-wf-import-coupons.php' );
75
- $post_columns = include( 'exporter/data/data-wf-post-columns.php' );
76
- include( 'views/export/html-wf-export-coupons.php' );
77
- }
78
-
79
- public function admin_export_page() {
80
- $post_columns = include( 'exporter/data/data-wf-post-columns.php' );
81
- include( 'views/export/html-wf-export-orders.php' );
82
- }
83
-
84
- public function admin_coupon_page()
85
- {
86
- include( 'views/import/html-wf-import-coupons.php' );
87
- include( 'views/export/html-wf-export-coupons.php' );
88
- }
89
-
90
- public function admin_settings_page()
91
- {
92
- include( 'views/settings/html-wf-all-settings.php' );
93
- }
94
- }
95
-
96
  new WF_CpnImpExpCsv_Admin_Screen();
1
+ <?php
2
+ if ( ! defined( 'ABSPATH' ) ) {
3
+ exit;
4
+ }
5
+
6
+ class WF_CpnImpExpCsv_Admin_Screen {
7
+
8
+ public function __construct()
9
+ {
10
+ add_action( 'admin_menu', array( $this, 'admin_menu' ) );
11
+ add_action( 'admin_print_styles', array( $this, 'admin_scripts' ) );
12
+ add_action( 'admin_notices', array( $this, 'admin_notices' ) );
13
+
14
+ }
15
+
16
+ public function admin_notices()
17
+ {
18
+ if ( ! function_exists( 'mb_detect_encoding' ) ) {
19
+ echo '<div class="error"><p>' . __( 'Coupon CSV Import Export requires the function <code>mb_detect_encoding</code> to import and export CSV files. Please ask your hosting provider to enable this function.', 'wf_order_import_export' ) . '</p></div>';
20
+ }
21
+ }
22
+
23
+ public function admin_menu()
24
+ {
25
+ $page = add_submenu_page( 'woocommerce', __( 'Coupon Im-Ex', 'wf_order_import_export' ), __( 'Coupon Im-Ex', 'wf_order_import_export' ), apply_filters( 'coupon_csv_coupon_role', 'manage_woocommerce' ), 'wf_coupon_csv_im_ex', array( $this, 'output' ) );
26
+ }
27
+
28
+ public static function hf_get_wc_path()
29
+ {
30
+ if (function_exists('WC')){
31
+ $wc_path = WC()->plugin_url();
32
+ }else{
33
+ $wc_path = plugins_url() . '/woocommerce';
34
+ }
35
+ return $wc_path;
36
+ }
37
+
38
+ public function admin_scripts()
39
+ {
40
+ $wc_path = self::hf_get_wc_path();
41
+ wp_enqueue_style( 'woocommerce_admin_styles', $wc_path. '/assets/css/admin.css' );
42
+ wp_enqueue_style( 'woocommerce-coupon-csv-importer1', plugins_url( basename( plugin_dir_path( WF_CpnImpExpCsv_FILE ) ) . '/styles/wf-style.css', basename( __FILE__ ) ), '', '1.0.0', 'screen' );
43
+
44
+ }
45
+
46
+ public function output()
47
+ {
48
+ $tab = 'import';
49
+
50
+
51
+ if(! empty( $_GET['page'] ))
52
+ {
53
+ if ( $_GET['page'] == 'wf_coupon_csv_im_ex' ) {
54
+ $tab = 'coupon';
55
+ }
56
+ }
57
+ if( ! empty( $_GET['tab'] )) {
58
+ if( $_GET['tab'] == 'export' ) {
59
+ $tab = 'export';
60
+ }
61
+ else if ( $_GET['tab'] == 'settings' ) {
62
+ $tab = 'settings';
63
+ }
64
+ else if ( $_GET['tab'] == 'coupon' ) {
65
+ $tab = 'coupon';
66
+ }
67
+ }
68
+ include( 'views/html-wf-admin-screen.php' );
69
+ }
70
+
71
+
72
+ public function admin_import_page() {
73
+ include( 'views/html-wf-getting-started.php' );
74
+ include( 'views/import/html-wf-import-coupons.php' );
75
+ $post_columns = include( 'exporter/data/data-wf-post-columns.php' );
76
+ include( 'views/export/html-wf-export-coupons.php' );
77
+ }
78
+
79
+ public function admin_export_page() {
80
+ $post_columns = include( 'exporter/data/data-wf-post-columns.php' );
81
+ include( 'views/export/html-wf-export-orders.php' );
82
+ }
83
+
84
+ public function admin_coupon_page()
85
+ {
86
+ include( 'views/import/html-wf-import-coupons.php' );
87
+ include( 'views/export/html-wf-export-coupons.php' );
88
+ }
89
+
90
+ public function admin_settings_page()
91
+ {
92
+ include( 'views/settings/html-wf-all-settings.php' );
93
+ }
94
+ }
95
+
96
  new WF_CpnImpExpCsv_Admin_Screen();
includes/class-wf-cpnimpexpcsv-ajax-handler.php CHANGED
@@ -1,20 +1,20 @@
1
- <?php
2
-
3
- if (!defined('ABSPATH')) {
4
- exit;
5
- }
6
-
7
- class WF_CpnImpExpCsv_AJAX_Handler {
8
-
9
- public function __construct() {
10
- add_action('wp_ajax_coupon_csv_import_request', array($this, 'csv_import_request'));
11
- }
12
-
13
- public function csv_import_request() {
14
- define('WP_LOAD_IMPORTERS', true);
15
- WF_CpnImpExpCsv_Importer::coupon_importer();
16
- }
17
-
18
- }
19
-
20
- new WF_CpnImpExpCsv_AJAX_Handler();
1
+ <?php
2
+
3
+ if (!defined('ABSPATH')) {
4
+ exit;
5
+ }
6
+
7
+ class WF_CpnImpExpCsv_AJAX_Handler {
8
+
9
+ public function __construct() {
10
+ add_action('wp_ajax_coupon_csv_import_request', array($this, 'csv_import_request'));
11
+ }
12
+
13
+ public function csv_import_request() {
14
+ define('WP_LOAD_IMPORTERS', true);
15
+ WF_CpnImpExpCsv_Importer::coupon_importer();
16
+ }
17
+
18
+ }
19
+
20
+ new WF_CpnImpExpCsv_AJAX_Handler();
includes/class-wf-cpnimpexpcsv-system-status-tools.php CHANGED
@@ -1,55 +1,55 @@
1
- <?php
2
- if ( ! defined( 'ABSPATH' ) ) {
3
- exit;
4
- }
5
-
6
- class WF_CpnImpExpCsv_System_Status_Tools {
7
-
8
- /**
9
- * Constructor
10
- */
11
- public function __construct() {
12
- add_filter( 'woocommerce_debug_tools', array( $this, 'tools' ) );
13
- }
14
-
15
- /**
16
- * Tools we add to WC
17
- * @param array $tools
18
- * @return array
19
- */
20
- public function tools( $tools ) {
21
- $tools['delete_coupons'] = array(
22
- 'name' => __( 'Delete Coupons','wf_order_import_export'),
23
- 'button' => __( 'Delete ALL coupons','wf_order_import_export' ),
24
- 'desc' => __( 'This tool will delete all coupons allowing you to start fresh.', 'wf_order_import_export' ),
25
- 'callback' => array( $this, 'delete_coupons' )
26
- );
27
-
28
- return $tools;
29
- }
30
-
31
- /**
32
- * Delete coupons
33
- */
34
- public function delete_coupons()
35
- {
36
- global $wpdb;
37
-
38
- // Delete coupons
39
- $result = absint( $wpdb->delete( $wpdb->posts, array( 'post_type' => 'shop_coupon' ) ) );
40
-
41
-
42
- // Delete meta and term relationships with no post
43
- $wpdb->query( "DELETE pm
44
- FROM {$wpdb->postmeta} pm
45
- LEFT JOIN {$wpdb->posts} wp ON wp.ID = pm.post_id
46
- WHERE wp.ID IS NULL" );
47
-
48
-
49
- echo '<div class="updated"><p>' . sprintf( __( '%d Coupons Deleted', 'wf_order_import_export' ), ( $result) ) . '</p></div>';
50
- }
51
-
52
-
53
- }
54
-
55
  new WF_CpnImpExpCsv_System_Status_Tools();
1
+ <?php
2
+ if ( ! defined( 'ABSPATH' ) ) {
3
+ exit;
4
+ }
5
+
6
+ class WF_CpnImpExpCsv_System_Status_Tools {
7
+
8
+ /**
9
+ * Constructor
10
+ */
11
+ public function __construct() {
12
+ add_filter( 'woocommerce_debug_tools', array( $this, 'tools' ) );
13
+ }
14
+
15
+ /**
16
+ * Tools we add to WC
17
+ * @param array $tools
18
+ * @return array
19
+ */
20
+ public function tools( $tools ) {
21
+ $tools['delete_coupons'] = array(
22
+ 'name' => __( 'Delete Coupons','wf_order_import_export'),
23
+ 'button' => __( 'Delete ALL coupons','wf_order_import_export' ),
24
+ 'desc' => __( 'This tool will delete all coupons allowing you to start fresh.', 'wf_order_import_export' ),
25
+ 'callback' => array( $this, 'delete_coupons' )
26
+ );
27
+
28
+ return $tools;
29
+ }
30
+
31
+ /**
32
+ * Delete coupons
33
+ */
34
+ public function delete_coupons()
35
+ {
36
+ global $wpdb;
37
+
38
+ // Delete coupons
39
+ $result = absint( $wpdb->delete( $wpdb->posts, array( 'post_type' => 'shop_coupon' ) ) );
40
+
41
+
42
+ // Delete meta and term relationships with no post
43
+ $wpdb->query( "DELETE pm
44
+ FROM {$wpdb->postmeta} pm
45
+ LEFT JOIN {$wpdb->posts} wp ON wp.ID = pm.post_id
46
+ WHERE wp.ID IS NULL" );
47
+
48
+
49
+ echo '<div class="updated"><p>' . sprintf( __( '%d Coupons Deleted', 'wf_order_import_export' ), ( $result) ) . '</p></div>';
50
+ }
51
+
52
+
53
+ }
54
+
55
  new WF_CpnImpExpCsv_System_Status_Tools();
includes/class-wf-orderimpexpcsv-admin-screen.php CHANGED
@@ -1,81 +1,81 @@
1
- <?php
2
- if (!defined('ABSPATH')) {
3
- exit;
4
- }
5
-
6
- class WF_OrderImpExpCsv_Admin_Screen {
7
-
8
- /**
9
- * Constructor
10
- */
11
- public function __construct() {
12
- add_action('admin_menu', array($this, 'admin_menu'));
13
- add_action('admin_print_styles', array($this, 'admin_scripts'));
14
- add_action('admin_notices', array($this, 'admin_notices'));
15
- }
16
-
17
- /**
18
- * Notices in admin
19
- */
20
- public function admin_notices() {
21
- if (!function_exists('mb_detect_encoding')) {
22
- echo '<div class="error"><p>' . __('Order CSV Import Export requires the function <code>mb_detect_encoding</code> to import and export CSV files. Please ask your hosting provider to enable this function.', 'wf_order_import_export') . '</p></div>';
23
- }
24
- }
25
-
26
- /**
27
- * Admin Menu
28
- */
29
- public function admin_menu() {
30
- $page = add_submenu_page('woocommerce', __('Order Im-Ex', 'wf_order_import_export'), __('Order Im-Ex', 'wf_order_import_export'), apply_filters('woocommerce_csv_order_role', 'manage_woocommerce'), 'wf_woocommerce_order_im_ex', array($this, 'output'));
31
- }
32
-
33
- /**
34
- * Admin Scripts
35
- */
36
- public function admin_scripts() {
37
- global $wp_scripts;
38
- wp_enqueue_style('woocommerce_admin_styles', WC()->plugin_url() . '/assets/css/admin.css');
39
- wp_enqueue_style('woocommerce-order-csv-importer', plugins_url(basename(plugin_dir_path(WF_OrderImpExpCsv_FILE)) . '/styles/wf-style.css', basename(__FILE__)), '', '1.0.0', 'screen');
40
-
41
- }
42
-
43
- /**
44
- * Admin Screen output
45
- */
46
- public function output() {
47
- $tab = 'import';
48
- if (!empty($_GET['tab'])) {
49
- if ($_GET['tab'] == 'export') {
50
- $tab = 'export';
51
- }elseif($_GET['tab'] == 'subscription' ) {
52
- $tab = 'subscription';
53
- }
54
- }
55
- include( 'views/html-wf-admin-screen.php' );
56
- }
57
-
58
- /**
59
- * Admin page for importing
60
- */
61
- public function admin_import_page() {
62
- include( 'views/import/html-wf-import-orders.php' );
63
- $post_columns = include( 'exporter/data/data-wf-post-columns.php' );
64
- include( 'views/export/html-wf-export-orders.php' );
65
- }
66
-
67
- /**
68
- * Admin Page for exporting
69
- */
70
- public function admin_export_page() {
71
- $post_columns = include( 'exporter/data/data-wf-post-columns.php' );
72
- include( 'views/export/html-wf-export-orders.php' );
73
- }
74
- public function admin_subscription_page()
75
- {
76
- include( 'views/html-wf-getting-started-subscription.php' );
77
- }
78
-
79
- }
80
-
81
- new WF_OrderImpExpCsv_Admin_Screen();
1
+ <?php
2
+ if (!defined('ABSPATH')) {
3
+ exit;
4
+ }
5
+
6
+ class WF_OrderImpExpCsv_Admin_Screen {
7
+
8
+ /**
9
+ * Constructor
10
+ */
11
+ public function __construct() {
12
+ add_action('admin_menu', array($this, 'admin_menu'));
13
+ add_action('admin_print_styles', array($this, 'admin_scripts'));
14
+ add_action('admin_notices', array($this, 'admin_notices'));
15
+ }
16
+
17
+ /**
18
+ * Notices in admin
19
+ */
20
+ public function admin_notices() {
21
+ if (!function_exists('mb_detect_encoding')) {
22
+ echo '<div class="error"><p>' . __('Order CSV Import Export requires the function <code>mb_detect_encoding</code> to import and export CSV files. Please ask your hosting provider to enable this function.', 'wf_order_import_export') . '</p></div>';
23
+ }
24
+ }
25
+
26
+ /**
27
+ * Admin Menu
28
+ */
29
+ public function admin_menu() {
30
+ $page = add_submenu_page('woocommerce', __('Order Im-Ex', 'wf_order_import_export'), __('Order Im-Ex', 'wf_order_import_export'), apply_filters('woocommerce_csv_order_role', 'manage_woocommerce'), 'wf_woocommerce_order_im_ex', array($this, 'output'));
31
+ }
32
+
33
+ /**
34
+ * Admin Scripts
35
+ */
36
+ public function admin_scripts() {
37
+ global $wp_scripts;
38
+ wp_enqueue_style('woocommerce_admin_styles', WC()->plugin_url() . '/assets/css/admin.css');
39
+ wp_enqueue_style('woocommerce-order-csv-importer', plugins_url(basename(plugin_dir_path(WF_OrderImpExpCsv_FILE)) . '/styles/wf-style.css', basename(__FILE__)), '', '1.0.0', 'screen');
40
+
41
+ }
42
+
43
+ /**
44
+ * Admin Screen output
45
+ */
46
+ public function output() {
47
+ $tab = 'import';
48
+ if (!empty($_GET['tab'])) {
49
+ if ($_GET['tab'] == 'export') {
50
+ $tab = 'export';
51
+ }elseif($_GET['tab'] == 'subscription' ) {
52
+ $tab = 'subscription';
53
+ }
54
+ }
55
+ include( 'views/html-wf-admin-screen.php' );
56
+ }
57
+
58
+ /**
59
+ * Admin page for importing
60
+ */
61
+ public function admin_import_page() {
62
+ include( 'views/import/html-wf-import-orders.php' );
63
+ $post_columns = include( 'exporter/data/data-wf-post-columns.php' );
64
+ include( 'views/export/html-wf-export-orders.php' );
65
+ }
66
+
67
+ /**
68
+ * Admin Page for exporting
69
+ */
70
+ public function admin_export_page() {
71
+ $post_columns = include( 'exporter/data/data-wf-post-columns.php' );
72
+ include( 'views/export/html-wf-export-orders.php' );
73
+ }
74
+ public function admin_subscription_page()
75
+ {
76
+ include( 'views/html-wf-getting-started-subscription.php' );
77
+ }
78
+
79
+ }
80
+
81
+ new WF_OrderImpExpCsv_Admin_Screen();
includes/class-wf-orderimpexpcsv-ajax-handler.php CHANGED
@@ -1,25 +1,25 @@
1
- <?php
2
- if ( ! defined( 'ABSPATH' ) ) {
3
- exit;
4
- }
5
-
6
- class WF_OrderImpExpCsv_AJAX_Handler {
7
-
8
- /**
9
- * Constructor
10
- */
11
- public function __construct() {
12
- add_action( 'wp_ajax_woocommerce_csv_order_import_request', array( $this, 'csv_order_import_request' ) );
13
- }
14
-
15
- /**
16
- * Ajax event for importing a CSV
17
- */
18
- public function csv_order_import_request() {
19
- define( 'WP_LOAD_IMPORTERS', true );
20
- WF_OrderImpExpCsv_Importer::order_importer();
21
- }
22
-
23
- }
24
-
25
  new WF_OrderImpExpCsv_AJAX_Handler();
1
+ <?php
2
+ if ( ! defined( 'ABSPATH' ) ) {
3
+ exit;
4
+ }
5
+
6
+ class WF_OrderImpExpCsv_AJAX_Handler {
7
+
8
+ /**
9
+ * Constructor
10
+ */
11
+ public function __construct() {
12
+ add_action( 'wp_ajax_woocommerce_csv_order_import_request', array( $this, 'csv_order_import_request' ) );
13
+ }
14
+
15
+ /**
16
+ * Ajax event for importing a CSV
17
+ */
18
+ public function csv_order_import_request() {
19
+ define( 'WP_LOAD_IMPORTERS', true );
20
+ WF_OrderImpExpCsv_Importer::order_importer();
21
+ }
22
+
23
+ }
24
+
25
  new WF_OrderImpExpCsv_AJAX_Handler();
includes/class-wf-orderimpexpcsv-system-status-tools.php CHANGED
@@ -1,64 +1,64 @@
1
- <?php
2
- if ( ! defined( 'ABSPATH' ) ) {
3
- exit;
4
- }
5
-
6
- class WF_OrderImpExpCsv_System_Status_Tools {
7
-
8
- /**
9
- * Constructor
10
- */
11
- public function __construct() {
12
- add_filter( 'woocommerce_debug_tools', array( $this, 'tools' ) );
13
- }
14
-
15
- /**
16
- * Tools we add to WC
17
- * @param array $tools
18
- * @return array
19
- */
20
- public function tools( $tools ) {
21
- $tools['delete_trashed_orders'] = array(
22
- 'name' => __( 'Delete Trashed Orders','wf_order_import_export'),
23
- 'button' => __( 'Delete Trashed Orders','wf_order_import_export' ),
24
- 'desc' => __( 'This tool will delete all Trashed Orders.', 'wf_order_import_export' ),
25
- 'callback' => array( $this, 'delete_trashed_orders' )
26
- );
27
- $tools['delete_all_orders'] = array(
28
- 'name' => __( 'Delete Orders','wf_order_import_export'),
29
- 'button' => __( 'Delete ALL Orders','wf_order_import_export' ),
30
- 'desc' => __( 'This tool will delete all orders allowing you to start fresh.', 'wf_order_import_export' ),
31
- 'callback' => array( $this, 'delete_all_orders' )
32
- );
33
- return $tools;
34
- }
35
-
36
- /**
37
- * Delete Trashed Orders
38
- */
39
- public function delete_trashed_orders() {
40
- global $wpdb;
41
- // Delete Trashed Orders
42
- $result = absint( $wpdb->delete( $wpdb->posts, array( 'post_type' => 'shop_order' , 'post_status' => 'trash') ) );
43
- echo '<div class="updated"><p>' . sprintf( __( '%d Orders Deleted', 'wf_order_import_export' ), ( $result ) ) . '</p></div>';
44
- }
45
-
46
- /**
47
- * Delete all orders
48
- */
49
- public function delete_all_orders() {
50
- global $wpdb;
51
-
52
- // Delete Orders
53
- $result = absint( $wpdb->delete( $wpdb->posts, array( 'post_type' => 'shop_order' ) ) );
54
-
55
- // Delete meta and term relationships with no post
56
- $wpdb->query( "DELETE pm
57
- FROM {$wpdb->postmeta} pm
58
- LEFT JOIN {$wpdb->posts} wp ON wp.ID = pm.post_id
59
- WHERE wp.ID IS NULL" );
60
- echo '<div class="updated"><p>' . sprintf( __( '%d Orders Deleted', 'wf_order_import_export' ), $result ) . '</p></div>';
61
- }
62
- }
63
-
64
  new WF_OrderImpExpCsv_System_Status_Tools();
1
+ <?php
2
+ if ( ! defined( 'ABSPATH' ) ) {
3
+ exit;
4
+ }
5
+
6
+ class WF_OrderImpExpCsv_System_Status_Tools {
7
+
8
+ /**
9
+ * Constructor
10
+ */
11
+ public function __construct() {
12
+ add_filter( 'woocommerce_debug_tools', array( $this, 'tools' ) );
13
+ }
14
+
15
+ /**
16
+ * Tools we add to WC
17
+ * @param array $tools
18
+ * @return array
19
+ */
20
+ public function tools( $tools ) {
21
+ $tools['delete_trashed_orders'] = array(
22
+ 'name' => __( 'Delete Trashed Orders','wf_order_import_export'),
23
+ 'button' => __( 'Delete Trashed Orders','wf_order_import_export' ),
24
+ 'desc' => __( 'This tool will delete all Trashed Orders.', 'wf_order_import_export' ),
25
+ 'callback' => array( $this, 'delete_trashed_orders' )
26
+ );
27
+ $tools['delete_all_orders'] = array(
28
+ 'name' => __( 'Delete Orders','wf_order_import_export'),
29
+ 'button' => __( 'Delete ALL Orders','wf_order_import_export' ),
30
+ 'desc' => __( 'This tool will delete all orders allowing you to start fresh.', 'wf_order_import_export' ),
31
+ 'callback' => array( $this, 'delete_all_orders' )
32
+ );
33
+ return $tools;
34
+ }
35
+
36
+ /**
37
+ * Delete Trashed Orders
38
+ */
39
+ public function delete_trashed_orders() {
40
+ global $wpdb;
41
+ // Delete Trashed Orders
42
+ $result = absint( $wpdb->delete( $wpdb->posts, array( 'post_type' => 'shop_order' , 'post_status' => 'trash') ) );
43
+ echo '<div class="updated"><p>' . sprintf( __( '%d Orders Deleted', 'wf_order_import_export' ), ( $result ) ) . '</p></div>';
44
+ }
45
+
46
+ /**
47
+ * Delete all orders
48
+ */
49
+ public function delete_all_orders() {
50
+ global $wpdb;
51
+
52
+ // Delete Orders
53
+ $result = absint( $wpdb->delete( $wpdb->posts, array( 'post_type' => 'shop_order' ) ) );
54
+
55
+ // Delete meta and term relationships with no post
56
+ $wpdb->query( "DELETE pm
57
+ FROM {$wpdb->postmeta} pm
58
+ LEFT JOIN {$wpdb->posts} wp ON wp.ID = pm.post_id
59
+ WHERE wp.ID IS NULL" );
60
+ echo '<div class="updated"><p>' . sprintf( __( '%d Orders Deleted', 'wf_order_import_export' ), $result ) . '</p></div>';
61
+ }
62
+ }
63
+
64
  new WF_OrderImpExpCsv_System_Status_Tools();
includes/exporter/class-wf-cpnimpexpcsv-exporter.php CHANGED
@@ -1,174 +1,174 @@
1
- <?php
2
-
3
- if (!defined('ABSPATH')) {
4
- exit;
5
- }
6
-
7
- class WF_CpnImpExpCsv_Exporter {
8
-
9
- public static function do_export($post_type = 'shop_coupon') {
10
- global $wpdb;
11
-
12
- $cpn_categories = !empty($_POST['cpn_categories']) ? $_POST['cpn_categories'] : array('fixed_cart', 'percent', 'fixed_product', 'percent_product');
13
- $export_limit = !empty($_POST['limit']) ? intval($_POST['limit']) : 999999999;
14
- $export_count = 0;
15
- $limit = 100;
16
- $current_offset = !empty($_POST['offset']) ? intval($_POST['offset']) : 0;
17
- $sortcolumn = !empty($_POST['sortcolumn']) ? $_POST['sortcolumn'] : 'ID';
18
- $delimiter = !empty($_POST['delimiter']) ? $_POST['delimiter'] : ',';
19
-
20
- $csv_columns = include( 'data/data-wf-post-columns-coupon.php' );
21
- $user_columns_name = !empty($_POST['columns_name']) ? $_POST['columns_name'] : $csv_columns;
22
- $export_columns = !empty($_POST['columns']) ? $_POST['columns'] : '';
23
- if ($limit > $export_limit)
24
- $limit = $export_limit;
25
-
26
-
27
- $wpdb->hide_errors();
28
- @set_time_limit(0);
29
- if (function_exists('apache_setenv'))
30
- @apache_setenv('no-gzip', 1);
31
- @ini_set('zlib.output_compression', 0);
32
- @ob_clean();
33
-
34
-
35
- header('Content-Type: text/csv; charset=UTF-8');
36
- header('Content-Disposition: attachment; filename=woocommerce-coupon-export-' . date('Y_m_d_H_i_s', current_time('timestamp')) . '.csv');
37
- header('Pragma: no-cache');
38
- header('Expires: 0');
39
-
40
- $fp = fopen('php://output', 'w');
41
-
42
-
43
- $all_meta_pkeys = self::get_all_metakeys('shop_coupon');
44
- $all_meta_keys = $all_meta_pkeys;
45
-
46
- $found_coupon_meta = array();
47
- foreach ($all_meta_keys as $meta) {
48
- if (!$meta)
49
- continue;
50
- if (!in_array($meta, array_keys($csv_columns)) && substr((string) $meta, 0, 1) == '_')
51
- continue;
52
-
53
- if (in_array($meta, array_keys($csv_columns)))
54
- continue;
55
- $found_coupon_meta[] = $meta;
56
- }
57
- $found_coupon_meta = array_diff($found_coupon_meta, array_keys($csv_columns));
58
- $row = array();
59
- foreach ($csv_columns as $column => $value) {
60
- $temp_head = esc_attr($user_columns_name[$column]);
61
- if (!$export_columns || in_array($column, $export_columns))
62
- $row[] = $temp_head;
63
- }
64
-
65
- if (!$export_columns || in_array('meta', $export_columns)) {
66
- foreach ($found_coupon_meta as $coupon_meta) {
67
- $row[] = 'meta:' . self::format_data($coupon_meta);
68
- }
69
- }
70
-
71
-
72
- $row = array_map('WF_CpnImpExpCsv_Exporter::wrap_column', $row);
73
- fwrite($fp, implode($delimiter, $row) . "\n");
74
- unset($row);
75
-
76
- while ($export_count < $export_limit) {
77
- $coupon_args = apply_filters('coupon_csv_product_export_args', array(
78
- 'numberposts' => $limit,
79
- 'post_status' => array('publish', 'pending', 'private', 'draft'),
80
- 'post_type' => 'shop_coupon',
81
- 'orderby' => $sortcolumn,
82
- 'suppress_filters' => false,
83
- 'order' => 'ASC',
84
- 'offset' => $current_offset
85
- ));
86
-
87
-
88
- $coupons = get_posts($coupon_args);
89
- if (!$coupons || is_wp_error($coupons))
90
- break;
91
- foreach ($coupons as $product) {
92
- foreach ($csv_columns as $column => $value) {
93
-
94
- if(is_array($product->$column)){
95
- $product->$column = implode(',', $product->$column);
96
- }
97
-
98
- if (!$export_columns || in_array($column, $export_columns)) {
99
- if (isset($product->meta->$column)) {
100
- $row[] = self::format_data($product->meta->$column);
101
- } elseif (isset($product->$column) && !is_array($product->$column)) {
102
- if ($column === 'post_title') {
103
- $row[] = sanitize_text_field($product->$column);
104
- } else {
105
- $row[] = self::format_data($product->$column);
106
- }
107
- } else {
108
- $row[] = '';
109
- }
110
- }
111
- }
112
-
113
- if (!$export_columns || in_array('meta', $export_columns)) {
114
- foreach ($found_coupon_meta as $product_meta) {
115
- if (isset($product->meta->$product_meta)) {
116
- $row[] = self::format_data($product->meta->$product_meta);
117
- } else {
118
- $row[] = '';
119
- }
120
- }
121
- }
122
- $row = array_map('WF_CpnImpExpCsv_Exporter::wrap_column', $row);
123
- fwrite($fp, implode($delimiter, $row) . "\n");
124
- unset($row);
125
- }
126
-
127
- $current_offset += $limit;
128
- $export_count += $limit;
129
- unset($coupons);
130
- }
131
-
132
- fclose($fp);
133
- exit;
134
- }
135
-
136
- public static function format_data($data) {
137
- if (!is_array($data))
138
- ;
139
- $data = (string) urldecode($data);
140
- $enc = mb_detect_encoding($data, 'UTF-8, ISO-8859-1', true);
141
- $data = ( $enc == 'UTF-8' ) ? $data : utf8_encode($data);
142
- return $data;
143
- }
144
-
145
- /**
146
- * Wrap a column in quotes for the CSV
147
- * @param string data to wrap
148
- * @return string wrapped data
149
- */
150
- public static function wrap_column($data) {
151
- return '"' . str_replace('"', '""', $data) . '"';
152
- }
153
-
154
- /**
155
- * Get a list of all the meta keys for a post type. This includes all public, private,
156
- * used, no-longer used etc. They will be sorted once fetched.
157
- */
158
- public static function get_all_metakeys($post_type = 'shop_coupon') {
159
- global $wpdb;
160
-
161
- $meta = $wpdb->get_col($wpdb->prepare(
162
- "SELECT DISTINCT pm.meta_key
163
- FROM {$wpdb->postmeta} AS pm
164
- LEFT JOIN {$wpdb->posts} AS p ON p.ID = pm.post_id
165
- WHERE p.post_type = %s
166
- AND p.post_status IN ( 'publish', 'pending', 'private', 'draft' )", $post_type
167
- ));
168
-
169
- sort($meta);
170
-
171
- return $meta;
172
- }
173
-
174
  }
1
+ <?php
2
+
3
+ if (!defined('ABSPATH')) {
4
+ exit;
5
+ }
6
+
7
+ class WF_CpnImpExpCsv_Exporter {
8
+
9
+ public static function do_export($post_type = 'shop_coupon') {
10
+ global $wpdb;
11
+
12
+ $cpn_categories = !empty($_POST['cpn_categories']) ? $_POST['cpn_categories'] : array('fixed_cart', 'percent', 'fixed_product', 'percent_product');
13
+ $export_limit = !empty($_POST['limit']) ? intval($_POST['limit']) : 999999999;
14
+ $export_count = 0;
15
+ $limit = 100;
16
+ $current_offset = !empty($_POST['offset']) ? intval($_POST['offset']) : 0;
17
+ $sortcolumn = !empty($_POST['sortcolumn']) ? $_POST['sortcolumn'] : 'ID';
18
+ $delimiter = !empty($_POST['delimiter']) ? $_POST['delimiter'] : ',';
19
+
20
+ $csv_columns = include( 'data/data-wf-post-columns-coupon.php' );
21
+ $user_columns_name = !empty($_POST['columns_name']) ? $_POST['columns_name'] : $csv_columns;
22
+ $export_columns = !empty($_POST['columns']) ? $_POST['columns'] : '';
23
+ if ($limit > $export_limit)
24
+ $limit = $export_limit;
25
+
26
+
27
+ $wpdb->hide_errors();
28
+ @set_time_limit(0);
29
+ if (function_exists('apache_setenv'))
30
+ @apache_setenv('no-gzip', 1);
31
+ @ini_set('zlib.output_compression', 0);
32
+ @ob_clean();
33
+
34
+
35
+ header('Content-Type: text/csv; charset=UTF-8');
36
+ header('Content-Disposition: attachment; filename=woocommerce-coupon-export-' . date('Y_m_d_H_i_s', current_time('timestamp')) . '.csv');
37
+ header('Pragma: no-cache');
38
+ header('Expires: 0');
39
+
40
+ $fp = fopen('php://output', 'w');
41
+
42
+
43
+ $all_meta_pkeys = self::get_all_metakeys('shop_coupon');
44
+ $all_meta_keys = $all_meta_pkeys;
45
+
46
+ $found_coupon_meta = array();
47
+ foreach ($all_meta_keys as $meta) {
48
+ if (!$meta)
49
+ continue;
50
+ if (!in_array($meta, array_keys($csv_columns)) && substr((string) $meta, 0, 1) == '_')
51
+ continue;
52
+
53
+ if (in_array($meta, array_keys($csv_columns)))
54
+ continue;
55
+ $found_coupon_meta[] = $meta;
56
+ }
57
+ $found_coupon_meta = array_diff($found_coupon_meta, array_keys($csv_columns));
58
+ $row = array();
59
+ foreach ($csv_columns as $column => $value) {
60
+ $temp_head = esc_attr($user_columns_name[$column]);
61
+ if (!$export_columns || in_array($column, $export_columns))
62
+ $row[] = $temp_head;
63
+ }
64
+
65
+ if (!$export_columns || in_array('meta', $export_columns)) {
66
+ foreach ($found_coupon_meta as $coupon_meta) {
67
+ $row[] = 'meta:' . self::format_data($coupon_meta);
68
+ }
69
+ }
70
+
71
+
72
+ $row = array_map('WF_CpnImpExpCsv_Exporter::wrap_column', $row);
73
+ fwrite($fp, implode($delimiter, $row) . "\n");
74
+ unset($row);
75
+
76
+ while ($export_count < $export_limit) {
77
+ $coupon_args = apply_filters('coupon_csv_product_export_args', array(
78
+ 'numberposts' => $limit,
79
+ 'post_status' => array('publish', 'pending', 'private', 'draft'),
80
+ 'post_type' => 'shop_coupon',
81
+ 'orderby' => $sortcolumn,
82
+ 'suppress_filters' => false,
83
+ 'order' => 'ASC',
84
+ 'offset' => $current_offset
85
+ ));
86
+
87
+
88
+ $coupons = get_posts($coupon_args);
89
+ if (!$coupons || is_wp_error($coupons))
90
+ break;
91
+ foreach ($coupons as $product) {
92
+ foreach ($csv_columns as $column => $value) {
93
+
94
+ if(is_array($product->$column)){
95
+ $product->$column = implode(',', $product->$column);
96
+ }
97
+
98
+ if (!$export_columns || in_array($column, $export_columns)) {
99
+ if (isset($product->meta->$column)) {
100
+ $row[] = self::format_data($product->meta->$column);
101
+ } elseif (isset($product->$column) && !is_array($product->$column)) {
102
+ if ($column === 'post_title') {
103
+ $row[] = sanitize_text_field($product->$column);
104
+ } else {
105
+ $row[] = self::format_data($product->$column);
106
+ }
107
+ } else {
108
+ $row[] = '';
109
+ }
110
+ }
111
+ }
112
+
113
+ if (!$export_columns || in_array('meta', $export_columns)) {
114
+ foreach ($found_coupon_meta as $product_meta) {
115
+ if (isset($product->meta->$product_meta)) {
116
+ $row[] = self::format_data($product->meta->$product_meta);
117
+ } else {
118
+ $row[] = '';
119
+ }
120
+ }
121
+ }
122
+ $row = array_map('WF_CpnImpExpCsv_Exporter::wrap_column', $row);
123
+ fwrite($fp, implode($delimiter, $row) . "\n");
124
+ unset($row);
125
+ }
126
+
127
+ $current_offset += $limit;
128
+ $export_count += $limit;
129
+ unset($coupons);
130
+ }
131
+
132
+ fclose($fp);
133
+ exit;
134
+ }
135
+
136
+ public static function format_data($data) {
137
+ if (!is_array($data))
138
+ ;
139
+ $data = (string) urldecode($data);
140
+ $enc = mb_detect_encoding($data, 'UTF-8, ISO-8859-1', true);
141
+ $data = ( $enc == 'UTF-8' ) ? $data : utf8_encode($data);
142
+ return $data;
143
+ }
144
+
145
+ /**
146
+ * Wrap a column in quotes for the CSV
147
+ * @param string data to wrap
148
+ * @return string wrapped data
149
+ */
150
+ public static function wrap_column($data) {
151
+ return '"' . str_replace('"', '""', $data) . '"';
152
+ }
153
+
154
+ /**
155
+ * Get a list of all the meta keys for a post type. This includes all public, private,
156
+ * used, no-longer used etc. They will be sorted once fetched.
157
+ */
158
+ public static function get_all_metakeys($post_type = 'shop_coupon') {
159
+ global $wpdb;
160
+
161
+ $meta = $wpdb->get_col($wpdb->prepare(
162
+ "SELECT DISTINCT pm.meta_key
163
+ FROM {$wpdb->postmeta} AS pm
164
+ LEFT JOIN {$wpdb->posts} AS p ON p.ID = pm.post_id
165
+ WHERE p.post_type = %s
166
+ AND p.post_status IN ( 'publish', 'pending', 'private', 'draft' )", $post_type
167
+ ));
168
+
169
+ sort($meta);
170
+
171
+ return $meta;
172
+ }
173
+
174
  }
includes/exporter/class-wf-orderimpexpcsv-exporter.php CHANGED
@@ -1,379 +1,379 @@
1
- <?php
2
-
3
- if (!defined('ABSPATH')) {
4
- exit;
5
- }
6
-
7
- class WF_OrderImpExpCsv_Exporter {
8
-
9
- /**
10
- * Order Exporter Tool
11
- */
12
-
13
- public static function do_export($post_type = 'shop_order') {
14
- global $wpdb;
15
-
16
- $limit = !empty($_POST['limit']) ? intval($_POST['limit']) : 999999999;
17
-
18
- $export_offset = !empty($_POST['offset']) ? intval($_POST['offset']) : 0;
19
- $csv_columns = include( 'data/data-wf-post-columns.php' );
20
- $user_columns_name = ! empty( $_POST['columns_name'] ) ? $_POST['columns_name'] : $csv_columns;
21
- $export_columns = ! empty( $_POST['columns'] ) ? $_POST['columns'] : array();
22
-
23
- $export_order_statuses = !empty($_POST['order_status']) ? $_POST['order_status'] : 'any';
24
-
25
- $delimiter = !empty($_POST['delimiter']) ? $_POST['delimiter'] : ',';
26
-
27
- $wpdb->hide_errors();
28
- @set_time_limit(0);
29
- if (function_exists('apache_setenv'))
30
- @apache_setenv('no-gzip', 1);
31
- @ini_set('zlib.output_compression', 0);
32
- @ob_clean();
33
-
34
- header('Content-Type: text/csv; charset=UTF-8');
35
- header('Content-Disposition: attachment; filename=woocommerce-order-export.csv');
36
- header('Pragma: no-cache');
37
- header('Expires: 0');
38
-
39
- $fp = fopen('php://output', 'w');
40
-
41
-
42
- // Headers
43
-
44
-
45
-
46
- $query_args = array(
47
- 'fields' => 'ids',
48
- 'post_type' => 'shop_order',
49
- 'post_status' => $export_order_statuses,
50
- 'posts_per_page' => $limit,
51
- 'offset' => $export_offset,
52
- );
53
-
54
- $query = new WP_Query($query_args);
55
- $order_ids = $query->posts;
56
-
57
-
58
- // Variable to hold the CSV data we're exporting
59
- $row = array();
60
- // Export header rows
61
- foreach ($csv_columns as $column => $value) {
62
-
63
- $temp_head = esc_attr( $user_columns_name[$column] );
64
- if ( ! $export_columns || in_array( $column, $export_columns ) )
65
- $row[] = $temp_head;
66
- }
67
- $max_line_items = WF_OrderImpExpCsv_Exporter::get_max_line_items($order_ids);
68
- for ($i = 1; $i <= $max_line_items; $i++) {
69
- $row[] = "line_item_{$i}";
70
- }
71
-
72
- $row = array_map('WF_OrderImpExpCsv_Exporter::wrap_column', $row);
73
- fwrite($fp, implode($delimiter, $row) . "\n");
74
- unset($row);
75
- // Loop orders
76
- foreach ($order_ids as $order_id) {
77
- //$row = array();
78
- $data = WF_OrderImpExpCsv_Exporter::get_orders_csv_row($order_id , $export_columns);
79
- // Add to csv
80
- $row = array_map('WF_OrderImpExpCsv_Exporter::wrap_column', $data);
81
- fwrite($fp, implode($delimiter, $row) . "\n");
82
- unset($row);
83
- unset($data);
84
- }
85
- fclose($fp);
86
- exit;
87
- }
88
-
89
- public static function format_data($data) {
90
- if (!is_array($data))
91
- ;
92
- $data = (string) urldecode($data);
93
- $enc = mb_detect_encoding($data, 'UTF-8, ISO-8859-1', true);
94
- $data = ( $enc == 'UTF-8' ) ? $data : utf8_encode($data);
95
- return $data;
96
- }
97
-
98
- /**
99
- * Wrap a column in quotes for the CSV
100
- * @param string data to wrap
101
- * @return string wrapped data
102
- */
103
- public static function wrap_column($data) {
104
- return '"' . str_replace('"', '""', $data) . '"';
105
- }
106
-
107
- public static function get_max_line_items($order_ids) {
108
-
109
- $max_line_items = 0;
110
-
111
- foreach ($order_ids as $order_id) {
112
-
113
- $order = wc_get_order($order_id);
114
-
115
- $line_items_count = count($order->get_items());
116
-
117
- if ($line_items_count >= $max_line_items) {
118
- $max_line_items = $line_items_count;
119
- }
120
- }
121
-
122
- return $max_line_items;
123
- }
124
-
125
- public static function get_orders_csv_row($order_id , $export_columns) {
126
-
127
- $order = wc_get_order($order_id);
128
-
129
- $line_items = $shipping_items = $fee_items = $tax_items = $coupon_items = array();
130
-
131
- // get line items
132
- foreach ($order->get_items() as $item_id => $item) {
133
-
134
- $product = $order->get_product_from_item($item);
135
-
136
- if (!is_object($product)) {
137
- $product = new WC_Product(0);
138
- }
139
-
140
- if(WC()->version < '3.1.0'){
141
- $item_meta = new WC_Order_Item_Meta((defined('WC_VERSION') >= 2.4) ? $item : $item['item_meta'] );
142
- $meta = $item_meta->display(true, true);
143
- }else{
144
- $arg = array(
145
- 'before' => '',
146
- 'after' => '',
147
- 'separator' => ',',
148
- 'echo' => false,
149
- );
150
-
151
- $meta = wc_display_item_meta( $item,$arg );
152
- }
153
-
154
- if ($meta) {
155
-
156
-
157
- // remove newlines
158
- $meta = str_replace(array("\r", "\r\n", "\n"), '', $meta);
159
- $meta = str_replace(array('<strong class="wc-item-meta-label">', '</strong> <p>', "</p>"), '', $meta);
160
-
161
- // switch reserved chars (:;|) to =
162
- $meta = str_replace(array(': ', ':', ';', '|'), '=', $meta);
163
- $meta = str_replace( 'meta=', '', $meta);
164
- }
165
-
166
- $line_item = array(
167
- 'name' => html_entity_decode($product->get_title() ? $product->get_title() : $item['name'], ENT_NOQUOTES, 'UTF-8'),
168
- 'product_id' => (WC()->version < '2.7.0')?$product->id:$product->get_id(),
169
- 'sku' => $product->get_sku(),
170
- 'quantity' => $item['qty'],
171
- 'total' => wc_format_decimal($order->get_line_total($item), 2),
172
- 'refunded' => wc_format_decimal($order->get_total_refunded_for_item($item_id), 2),
173
- 'meta' => html_entity_decode($meta, ENT_NOQUOTES, 'UTF-8'),
174
- );
175
-
176
- // add line item tax
177
- $line_tax_data = isset($item['line_tax_data']) ? $item['line_tax_data'] : array();
178
- $tax_data = maybe_unserialize($line_tax_data);
179
- $line_item['tax'] = isset($tax_data['total']) ? wc_format_decimal(wc_round_tax_total(array_sum((array) $tax_data['total'])), 2) : '';
180
-
181
- $line_items[] = $line_item;
182
- }
183
-
184
- foreach ($order->get_shipping_methods() as $_ => $shipping_item) {
185
-
186
- $shipping_items[] = implode('|', array(
187
- 'method:' . $shipping_item['name'],
188
- 'total:' . wc_format_decimal($shipping_item['cost'], 2),
189
- ));
190
- }
191
-
192
- // get fee items & total
193
- $fee_total = 0;
194
- $fee_tax_total = 0;
195
-
196
- foreach ($order->get_fees() as $fee_id => $fee) {
197
-
198
- $fee_items[] = implode('|', array(
199
- 'name:' . $fee['name'],
200
- 'total:' . wc_format_decimal($fee['line_total'], 2),
201
- 'tax:' . wc_format_decimal($fee['line_tax'], 2),
202
- ));
203
-
204
- $fee_total += $fee['line_total'];
205
- $fee_tax_total += $fee['line_tax'];
206
- }
207
-
208
- // get tax items
209
- foreach ($order->get_tax_totals() as $tax_code => $tax) {
210
-
211
- $tax_items[] = implode('|', array(
212
- 'code:' . $tax_code,
213
- 'total:' . wc_format_decimal($tax->amount, 2),
214
- ));
215
- }
216
-
217
- // add coupons
218
- foreach ($order->get_items('coupon') as $_ => $coupon_item) {
219
-
220
- $coupon = new WC_Coupon($coupon_item['name']);
221
-
222
- $coupon_post = get_post((WC()->version < '2.7.0')?$coupon->id:$coupon->get_id());
223
-
224
- $coupon_items[] = implode('|', array(
225
- 'code:' . $coupon_item['name'],
226
- 'description:' . ( is_object($coupon_post) ? $coupon_post->post_excerpt : '' ),
227
- 'amount:' . wc_format_decimal($coupon_item['discount_amount'], 2),
228
- ));
229
- }
230
-
231
- if (version_compare(WC_VERSION, '2.7', '<')) {
232
- $order_data = array(
233
- 'order_id' => $order->id,
234
- 'order_number' => $order->get_order_number(),
235
- 'order_date' => $order->order_date,
236
- 'status' => $order->get_status(),
237
- 'shipping_total' => $order->get_total_shipping(),
238
- 'shipping_tax_total' => wc_format_decimal($order->get_shipping_tax(), 2),
239
- 'fee_total' => wc_format_decimal($fee_total, 2),
240
- 'fee_tax_total' => wc_format_decimal($fee_tax_total, 2),
241
- 'tax_total' => wc_format_decimal($order->get_total_tax(), 2),
242
- 'cart_discount' => (defined( 'WC_VERSION' ) && (WC_VERSION >= 2.3)) ? wc_format_decimal($order->get_total_discount(), 2) : wc_format_decimal($order->get_cart_discount(), 2),
243
- 'order_discount' => (defined( 'WC_VERSION' ) && (WC_VERSION >= 2.3)) ? wc_format_decimal($order->get_total_discount(), 2) : wc_format_decimal($order->get_order_discount(), 2),
244
- 'discount_total' => wc_format_decimal($order->get_total_discount(), 2),
245
- 'order_total' => wc_format_decimal($order->get_total(), 2),
246
- 'refunded_total' => wc_format_decimal($order->get_total_refunded(), 2),
247
- 'order_currency' => $order->get_order_currency(),
248
- 'payment_method' => $order->payment_method,
249
- 'shipping_method' => $order->get_shipping_method(),
250
- 'customer_id' => $order->get_user_id(),
251
- 'customer_user' => $order->get_user_id(),
252
- 'customer_email' => ($a = get_userdata($order->get_user_id() )) ? $a->user_email : '',
253
- 'billing_first_name' => $order->billing_first_name,
254
- 'billing_last_name' => $order->billing_last_name,
255
- 'billing_company' => $order->billing_company,
256
- 'billing_email' => $order->billing_email,
257
- 'billing_phone' => $order->billing_phone,
258
- 'billing_address_1' => $order->billing_address_1,
259
- 'billing_address_2' => $order->billing_address_2,
260
- 'billing_postcode' => $order->billing_postcode,
261
- 'billing_city' => $order->billing_city,
262
- 'billing_state' => $order->billing_state,
263
- 'billing_country' => $order->billing_country,
264
- 'shipping_first_name' => $order->shipping_first_name,
265
- 'shipping_last_name' => $order->shipping_last_name,
266
- 'shipping_company' => $order->shipping_company,
267
- 'shipping_address_1' => $order->shipping_address_1,
268
- 'shipping_address_2' => $order->shipping_address_2,
269
- 'shipping_postcode' => $order->shipping_postcode,
270
- 'shipping_city' => $order->shipping_city,
271
- 'shipping_state' => $order->shipping_state,
272
- 'shipping_country' => $order->shipping_country,
273
- 'customer_note' => $order->customer_note,
274
- 'shipping_items' => implode(';', $shipping_items),
275
- 'fee_items' => implode(';', $fee_items),
276
- 'tax_items' => implode(';', $tax_items),
277
- 'coupon_items' => implode(';', $coupon_items),
278
- 'order_notes' => implode('|', WF_OrderImpExpCsv_Exporter::get_order_notes($order)),
279
- 'download_permissions' => $order->download_permissions_granted ? $order->download_permissions_granted : 0,
280
- );
281
- }else{
282
-
283
- $order_data = array(
284
- 'order_id' => $order->get_id(),
285
- 'order_number' => $order->get_order_number(),
286
- 'order_date' => date('Y-m-d H:i:s' , strtotime($order->get_date_created())),
287
- 'status' => $order->get_status(),
288
- 'shipping_total' => $order->get_total_shipping(),
289
- 'shipping_tax_total' => wc_format_decimal($order->get_shipping_tax(), 2),
290
- 'fee_total' => wc_format_decimal($fee_total, 2),
291
- 'fee_tax_total' => wc_format_decimal($fee_tax_total, 2),
292
- 'tax_total' => wc_format_decimal($order->get_total_tax(), 2),
293
- 'cart_discount' => (defined('WC_VERSION') && (WC_VERSION >= 2.3)) ? wc_format_decimal($order->get_total_discount(), 2) : wc_format_decimal($order->get_cart_discount(), 2),
294
- 'order_discount' => (defined('WC_VERSION') && (WC_VERSION >= 2.3)) ? wc_format_decimal($order->get_total_discount(), 2) : wc_format_decimal($order->get_order_discount(), 2),
295
- 'discount_total' => wc_format_decimal($order->get_total_discount(), 2),
296
- 'order_total' => @wc_format_decimal($order->get_total(), 2),
297
- 'refunded_total' => wc_format_decimal($order->get_total_refunded(), 2),
298
- 'order_currency' => $order->get_currency(),
299
- 'payment_method' => $order->get_payment_method(),
300
- 'shipping_method' => $order->get_shipping_method(),
301
- 'customer_id' => $order->get_user_id(),
302
- 'customer_user' => $order->get_user_id(),
303
- 'customer_email' => ($a = get_userdata($order->get_user_id() )) ? $a->user_email : '',
304
- 'billing_first_name' => $order->get_billing_first_name(),
305
- 'billing_last_name' => $order->get_billing_last_name(),
306
- 'billing_company' => $order->get_billing_company(),
307
- 'billing_email' => $order->get_billing_email(),
308
- 'billing_phone' => $order->get_billing_phone(),
309
- 'billing_address_1' => $order->get_billing_address_1(),
310
- 'billing_address_2' => $order->get_billing_address_2(),
311
- 'billing_postcode' => $order->get_billing_postcode(),
312
- 'billing_city' => $order->get_billing_city(),
313
- 'billing_state' => $order->get_billing_state(),
314
- 'billing_country' => $order->get_billing_country(),
315
- 'shipping_first_name' => $order->get_shipping_first_name(),
316
- 'shipping_last_name' => $order->get_shipping_last_name(),
317
- 'shipping_company' => $order->get_shipping_company(),
318
- 'shipping_address_1' => $order->get_shipping_address_1(),
319
- 'shipping_address_2' => $order->get_shipping_address_2(),
320
- 'shipping_postcode' => $order->get_shipping_postcode(),
321
- 'shipping_city' => $order->get_shipping_city(),
322
- 'shipping_state' => $order->get_shipping_state(),
323
- 'shipping_country' => $order->get_shipping_country(),
324
- 'customer_note' => $order->get_customer_note(),
325
- 'shipping_items' => implode(';', $shipping_items),
326
- 'fee_items' => implode(';', $fee_items),
327
- 'tax_items' => implode(';', $tax_items),
328
- 'coupon_items' => implode(';', $coupon_items),
329
- 'order_notes' => implode('|', WF_OrderImpExpCsv_Exporter::get_order_notes($order)),
330
- 'download_permissions' => $order->is_download_permitted() ? $order->is_download_permitted() : 0,
331
- );
332
-
333
- }
334
- foreach ($order_data as $key => $value) {
335
- if (!$export_columns || in_array( $key, $export_columns ) ){
336
- // need to modify code
337
- }else{
338
- unset($order_data[$key]);
339
- }
340
- }
341
- $li = 1;
342
- foreach ($line_items as $line_item) {
343
- foreach ($line_item as $name => $value) {
344
- $line_item[$name] = $name . ':' . $value;
345
- }
346
- $line_item = implode('|', $line_item);
347
- $order_data["line_item_{$li}"] = $line_item;
348
- $li++;
349
- }
350
- return $order_data;
351
- }
352
-
353
- public static function get_order_notes($order) {
354
-
355
- $callback = array('WC_Comments', 'exclude_order_comments');
356
-
357
- $args = array(
358
- 'post_id' => (WC()->version < '2.7.0')?$order->id:$order->get_id(),
359
- 'approve' => 'approve',
360
- 'type' => 'order_note'
361
- );
362
-
363
- remove_filter('comments_clauses', $callback);
364
-
365
- $notes = get_comments($args);
366
-
367
- add_filter('comments_clauses', $callback);
368
-
369
- $order_notes = array();
370
-
371
- foreach ($notes as $note) {
372
-
373
- $order_notes[] = str_replace(array("\r", "\n"), ' ', $note->comment_content);
374
- }
375
-
376
- return $order_notes;
377
- }
378
-
379
- }
1
+ <?php
2
+
3
+ if (!defined('ABSPATH')) {
4
+ exit;
5
+ }
6
+
7
+ class WF_OrderImpExpCsv_Exporter {
8
+
9
+ /**
10
+ * Order Exporter Tool
11
+ */
12
+
13
+ public static function do_export($post_type = 'shop_order') {
14
+ global $wpdb;
15
+
16
+ $limit = !empty($_POST['limit']) ? intval($_POST['limit']) : 999999999;
17
+
18
+ $export_offset = !empty($_POST['offset']) ? intval($_POST['offset']) : 0;
19
+ $csv_columns = include( 'data/data-wf-post-columns.php' );
20
+ $user_columns_name = ! empty( $_POST['columns_name'] ) ? $_POST['columns_name'] : $csv_columns;
21
+ $export_columns = ! empty( $_POST['columns'] ) ? $_POST['columns'] : array();
22
+
23
+ $export_order_statuses = !empty($_POST['order_status']) ? $_POST['order_status'] : 'any';
24
+
25
+ $delimiter = !empty($_POST['delimiter']) ? $_POST['delimiter'] : ',';
26
+
27
+ $wpdb->hide_errors();
28
+ @set_time_limit(0);
29
+ if (function_exists('apache_setenv'))
30
+ @apache_setenv('no-gzip', 1);
31
+ @ini_set('zlib.output_compression', 0);
32
+ @ob_clean();
33
+
34
+ header('Content-Type: text/csv; charset=UTF-8');
35
+ header('Content-Disposition: attachment; filename=woocommerce-order-export.csv');
36
+ header('Pragma: no-cache');
37
+ header('Expires: 0');
38
+
39
+ $fp = fopen('php://output', 'w');
40
+
41
+
42
+ // Headers
43
+
44
+
45
+
46
+ $query_args = array(
47
+ 'fields' => 'ids',
48
+ 'post_type' => 'shop_order',
49
+ 'post_status' => $export_order_statuses,
50
+ 'posts_per_page' => $limit,
51
+ 'offset' => $export_offset,
52
+ );
53
+
54
+ $query = new WP_Query($query_args);
55
+ $order_ids = $query->posts;
56
+
57
+
58
+ // Variable to hold the CSV data we're exporting
59
+ $row = array();
60
+ // Export header rows
61
+ foreach ($csv_columns as $column => $value) {
62
+
63
+ $temp_head = esc_attr( $user_columns_name[$column] );
64
+ if ( ! $export_columns || in_array( $column, $export_columns ) )
65
+ $row[] = $temp_head;
66
+ }
67
+ $max_line_items = WF_OrderImpExpCsv_Exporter::get_max_line_items($order_ids);
68
+ for ($i = 1; $i <= $max_line_items; $i++) {
69
+ $row[] = "line_item_{$i}";
70
+ }
71
+
72
+ $row = array_map('WF_OrderImpExpCsv_Exporter::wrap_column', $row);
73
+ fwrite($fp, implode($delimiter, $row) . "\n");
74
+ unset($row);
75
+ // Loop orders
76
+ foreach ($order_ids as $order_id) {
77
+ //$row = array();
78
+ $data = WF_OrderImpExpCsv_Exporter::get_orders_csv_row($order_id , $export_columns);
79
+ // Add to csv
80
+ $row = array_map('WF_OrderImpExpCsv_Exporter::wrap_column', $data);
81
+ fwrite($fp, implode($delimiter, $row) . "\n");
82
+ unset($row);
83
+ unset($data);
84
+ }
85
+ fclose($fp);
86
+ exit;
87
+ }
88
+
89
+ public static function format_data($data) {
90
+ if (!is_array($data))
91
+ ;
92
+ $data = (string) urldecode($data);
93
+ $enc = mb_detect_encoding($data, 'UTF-8, ISO-8859-1', true);
94
+ $data = ( $enc == 'UTF-8' ) ? $data : utf8_encode($data);
95
+ return $data;
96
+ }
97
+
98
+ /**
99
+ * Wrap a column in quotes for the CSV
100
+ * @param string data to wrap
101
+ * @return string wrapped data
102
+ */
103
+ public static function wrap_column($data) {
104
+ return '"' . str_replace('"', '""', $data) . '"';
105
+ }
106
+
107
+ public static function get_max_line_items($order_ids) {
108
+
109
+ $max_line_items = 0;
110
+
111
+ foreach ($order_ids as $order_id) {
112
+
113
+ $order = wc_get_order($order_id);
114
+
115
+ $line_items_count = count($order->get_items());
116
+
117
+ if ($line_items_count >= $max_line_items) {
118
+ $max_line_items = $line_items_count;
119
+ }
120
+ }
121
+
122
+ return $max_line_items;
123
+ }
124
+
125
+ public static function get_orders_csv_row($order_id , $export_columns) {
126
+
127
+ $order = wc_get_order($order_id);
128
+
129
+ $line_items = $shipping_items = $fee_items = $tax_items = $coupon_items = array();
130
+
131
+ // get line items
132
+ foreach ($order->get_items() as $item_id => $item) {
133
+
134
+ $product = $order->get_product_from_item($item);
135
+
136
+ if (!is_object($product)) {
137
+ $product = new WC_Product(0);
138
+ }
139
+
140
+ if(WC()->version < '3.1.0'){
141
+ $item_meta = new WC_Order_Item_Meta((defined('WC_VERSION') >= 2.4) ? $item : $item['item_meta'] );
142
+ $meta = $item_meta->display(true, true);
143
+ }else{
144
+ $arg = array(
145
+ 'before' => '',
146
+ 'after' => '',
147
+ 'separator' => ',',
148
+ 'echo' => false,
149
+ );
150
+
151
+ $meta = wc_display_item_meta( $item,$arg );
152
+ }
153
+
154
+ if ($meta) {
155
+
156
+
157
+ // remove newlines
158
+ $meta = str_replace(array("\r", "\r\n", "\n"), '', $meta);
159
+ $meta = str_replace(array('<strong class="wc-item-meta-label">', '</strong> <p>', "</p>"), '', $meta);
160
+
161
+ // switch reserved chars (:;|) to =
162
+ $meta = str_replace(array(': ', ':', ';', '|'), '=', $meta);
163
+ $meta = str_replace( 'meta=', '', $meta);
164
+ }
165
+
166
+ $line_item = array(
167
+ 'name' => html_entity_decode($product->get_title() ? $product->get_title() : $item['name'], ENT_NOQUOTES, 'UTF-8'),
168
+ 'product_id' => (WC()->version < '2.7.0')?$product->id:$product->get_id(),
169
+ 'sku' => $product->get_sku(),
170
+ 'quantity' => $item['qty'],
171
+ 'total' => wc_format_decimal($order->get_line_total($item), 2),
172
+ 'refunded' => wc_format_decimal($order->get_total_refunded_for_item($item_id), 2),
173
+ 'meta' => html_entity_decode($meta, ENT_NOQUOTES, 'UTF-8'),
174
+ );
175
+
176
+ // add line item tax
177
+ $line_tax_data = isset($item['line_tax_data']) ? $item['line_tax_data'] : array();
178
+ $tax_data = maybe_unserialize($line_tax_data);
179
+ $line_item['tax'] = isset($tax_data['total']) ? wc_format_decimal(wc_round_tax_total(array_sum((array) $tax_data['total'])), 2) : '';
180
+
181
+ $line_items[] = $line_item;
182
+ }
183
+
184
+ foreach ($order->get_shipping_methods() as $_ => $shipping_item) {
185
+
186
+ $shipping_items[] = implode('|', array(
187
+ 'method:' . $shipping_item['name'],
188
+ 'total:' . wc_format_decimal($shipping_item['cost'], 2),
189
+ ));
190
+ }
191
+
192
+ // get fee items & total
193
+ $fee_total = 0;
194
+ $fee_tax_total = 0;
195
+
196
+ foreach ($order->get_fees() as $fee_id => $fee) {
197
+
198
+ $fee_items[] = implode('|', array(
199
+ 'name:' . $fee['name'],
200
+ 'total:' . wc_format_decimal($fee['line_total'], 2),
201
+ 'tax:' . wc_format_decimal($fee['line_tax'], 2),
202
+ ));
203
+
204
+ $fee_total += $fee['line_total'];
205
+ $fee_tax_total += $fee['line_tax'];
206
+ }
207
+
208
+ // get tax items
209
+ foreach ($order->get_tax_totals() as $tax_code => $tax) {
210
+
211
+ $tax_items[] = implode('|', array(
212
+ 'code:' . $tax_code,
213
+ 'total:' . wc_format_decimal($tax->amount, 2),
214
+ ));
215
+ }
216
+
217
+ // add coupons
218
+ foreach ($order->get_items('coupon') as $_ => $coupon_item) {
219
+
220
+ $coupon = new WC_Coupon($coupon_item['name']);
221
+
222
+ $coupon_post = get_post((WC()->version < '2.7.0')?$coupon->id:$coupon->get_id());
223
+
224
+ $coupon_items[] = implode('|', array(
225
+ 'code:' . $coupon_item['name'],
226
+ 'description:' . ( is_object($coupon_post) ? $coupon_post->post_excerpt : '' ),
227
+ 'amount:' . wc_format_decimal($coupon_item['discount_amount'], 2),
228
+ ));
229
+ }
230
+
231
+ if (version_compare(WC_VERSION, '2.7', '<')) {
232
+ $order_data = array(
233
+ 'order_id' => $order->id,
234
+ 'order_number' => $order->get_order_number(),
235
+ 'order_date' => $order->order_date,
236
+ 'status' => $order->get_status(),
237
+ 'shipping_total' => $order->get_total_shipping(),
238
+ 'shipping_tax_total' => wc_format_decimal($order->get_shipping_tax(), 2),
239
+ 'fee_total' => wc_format_decimal($fee_total, 2),
240
+ 'fee_tax_total' => wc_format_decimal($fee_tax_total, 2),
241
+ 'tax_total' => wc_format_decimal($order->get_total_tax(), 2),
242
+ 'cart_discount' => (defined( 'WC_VERSION' ) && (WC_VERSION >= 2.3)) ? wc_format_decimal($order->get_total_discount(), 2) : wc_format_decimal($order->get_cart_discount(), 2),
243
+ 'order_discount' => (defined( 'WC_VERSION' ) && (WC_VERSION >= 2.3)) ? wc_format_decimal($order->get_total_discount(), 2) : wc_format_decimal($order->get_order_discount(), 2),
244
+ 'discount_total' => wc_format_decimal($order->get_total_discount(), 2),
245
+ 'order_total' => wc_format_decimal($order->get_total(), 2),
246
+ 'refunded_total' => wc_format_decimal($order->get_total_refunded(), 2),
247
+ 'order_currency' => $order->get_order_currency(),
248
+ 'payment_method' => $order->payment_method,
249
+ 'shipping_method' => $order->get_shipping_method(),
250
+ 'customer_id' => $order->get_user_id(),
251
+ 'customer_user' => $order->get_user_id(),
252
+ 'customer_email' => ($a = get_userdata($order->get_user_id() )) ? $a->user_email : '',
253
+ 'billing_first_name' => $order->billing_first_name,
254
+ 'billing_last_name' => $order->billing_last_name,
255
+ 'billing_company' => $order->billing_company,
256
+ 'billing_email' => $order->billing_email,
257
+ 'billing_phone' => $order->billing_phone,
258
+ 'billing_address_1' => $order->billing_address_1,
259
+ 'billing_address_2' => $order->billing_address_2,
260
+ 'billing_postcode' => $order->billing_postcode,
261
+ 'billing_city' => $order->billing_city,
262
+ 'billing_state' => $order->billing_state,
263
+ 'billing_country' => $order->billing_country,
264
+ 'shipping_first_name' => $order->shipping_first_name,
265
+ 'shipping_last_name' => $order->shipping_last_name,
266
+ 'shipping_company' => $order->shipping_company,
267
+ 'shipping_address_1' => $order->shipping_address_1,
268
+ 'shipping_address_2' => $order->shipping_address_2,
269
+ 'shipping_postcode' => $order->shipping_postcode,
270
+ 'shipping_city' => $order->shipping_city,
271
+ 'shipping_state' => $order->shipping_state,
272
+ 'shipping_country' => $order->shipping_country,
273
+ 'customer_note' => $order->customer_note,
274
+ 'shipping_items' => implode(';', $shipping_items),
275
+ 'fee_items' => implode(';', $fee_items),
276
+ 'tax_items' => implode(';', $tax_items),
277
+ 'coupon_items' => implode(';', $coupon_items),
278
+ 'order_notes' => implode('|', WF_OrderImpExpCsv_Exporter::get_order_notes($order)),
279
+ 'download_permissions' => $order->download_permissions_granted ? $order->download_permissions_granted : 0,
280
+ );
281
+ }else{
282
+
283
+ $order_data = array(
284
+ 'order_id' => $order->get_id(),
285
+ 'order_number' => $order->get_order_number(),
286
+ 'order_date' => date('Y-m-d H:i:s' , strtotime($order->get_date_created())),
287
+ 'status' => $order->get_status(),
288
+ 'shipping_total' => $order->get_total_shipping(),
289
+ 'shipping_tax_total' => wc_format_decimal($order->get_shipping_tax(), 2),
290
+ 'fee_total' => wc_format_decimal($fee_total, 2),
291
+ 'fee_tax_total' => wc_format_decimal($fee_tax_total, 2),
292
+ 'tax_total' => wc_format_decimal($order->get_total_tax(), 2),
293
+ 'cart_discount' => (defined('WC_VERSION') && (WC_VERSION >= 2.3)) ? wc_format_decimal($order->get_total_discount(), 2) : wc_format_decimal($order->get_cart_discount(), 2),
294
+ 'order_discount' => (defined('WC_VERSION') && (WC_VERSION >= 2.3)) ? wc_format_decimal($order->get_total_discount(), 2) : wc_format_decimal($order->get_order_discount(), 2),
295
+ 'discount_total' => wc_format_decimal($order->get_total_discount(), 2),
296
+ 'order_total' => @wc_format_decimal($order->get_total(), 2),
297
+ 'refunded_total' => wc_format_decimal($order->get_total_refunded(), 2),
298
+ 'order_currency' => $order->get_currency(),
299
+ 'payment_method' => $order->get_payment_method(),
300
+ 'shipping_method' => $order->get_shipping_method(),
301
+ 'customer_id' => $order->get_user_id(),
302
+ 'customer_user' => $order->get_user_id(),
303
+ 'customer_email' => ($a = get_userdata($order->get_user_id() )) ? $a->user_email : '',
304
+ 'billing_first_name' => $order->get_billing_first_name(),
305
+ 'billing_last_name' => $order->get_billing_last_name(),
306
+ 'billing_company' => $order->get_billing_company(),
307
+ 'billing_email' => $order->get_billing_email(),
308
+ 'billing_phone' => $order->get_billing_phone(),
309
+ 'billing_address_1' => $order->get_billing_address_1(),
310
+ 'billing_address_2' => $order->get_billing_address_2(),
311
+ 'billing_postcode' => $order->get_billing_postcode(),
312
+ 'billing_city' => $order->get_billing_city(),
313
+ 'billing_state' => $order->get_billing_state(),
314
+ 'billing_country' => $order->get_billing_country(),
315
+ 'shipping_first_name' => $order->get_shipping_first_name(),
316
+ 'shipping_last_name' => $order->get_shipping_last_name(),
317
+ 'shipping_company' => $order->get_shipping_company(),
318
+ 'shipping_address_1' => $order->get_shipping_address_1(),
319
+ 'shipping_address_2' => $order->get_shipping_address_2(),
320
+ 'shipping_postcode' => $order->get_shipping_postcode(),
321
+ 'shipping_city' => $order->get_shipping_city(),
322
+ 'shipping_state' => $order->get_shipping_state(),
323
+ 'shipping_country' => $order->get_shipping_country(),
324
+ 'customer_note' => $order->get_customer_note(),
325
+ 'shipping_items' => implode(';', $shipping_items),
326
+ 'fee_items' => implode(';', $fee_items),
327
+ 'tax_items' => implode(';', $tax_items),
328
+ 'coupon_items' => implode(';', $coupon_items),
329
+ 'order_notes' => implode('|', WF_OrderImpExpCsv_Exporter::get_order_notes($order)),
330
+ 'download_permissions' => $order->is_download_permitted() ? $order->is_download_permitted() : 0,
331
+ );
332
+
333
+ }
334
+ foreach ($order_data as $key => $value) {
335
+ if (!$export_columns || in_array( $key, $export_columns ) ){
336
+ // need to modify code
337
+ }else{
338
+ unset($order_data[$key]);
339
+ }
340
+ }
341
+ $li = 1;
342
+ foreach ($line_items as $line_item) {
343
+ foreach ($line_item as $name => $value) {
344
+ $line_item[$name] = $name . ':' . $value;
345
+ }
346
+ $line_item = implode('|', $line_item);
347
+ $order_data["line_item_{$li}"] = $line_item;
348
+ $li++;
349
+ }
350
+ return $order_data;
351
+ }
352
+
353
+ public static function get_order_notes($order) {
354
+
355
+ $callback = array('WC_Comments', 'exclude_order_comments');
356
+
357
+ $args = array(
358
+ 'post_id' => (WC()->version < '2.7.0')?$order->id:$order->get_id(),
359
+ 'approve' => 'approve',
360
+ 'type' => 'order_note'
361
+ );
362
+
363
+ remove_filter('comments_clauses', $callback);
364
+
365
+ $notes = get_comments($args);
366
+
367
+ add_filter('comments_clauses', $callback);
368
+
369
+ $order_notes = array();
370
+
371
+ foreach ($notes as $note) {
372
+
373
+ $order_notes[] = str_replace(array("\r", "\n"), ' ', $note->comment_content);
374
+ }
375
+
376
+ return $order_notes;
377
+ }
378
+
379
+ }
includes/exporter/data/data-wf-post-columns-coupon.php CHANGED
@@ -1,32 +1,32 @@
1
- <?php
2
- if ( ! defined( 'ABSPATH' ) ) {
3
- exit;
4
- }
5
-
6
- return apply_filters('coupon_csv_coupon_post_columns', array(
7
- 'post_title' => 'post_title',
8
- 'ID' => 'ID',
9
- 'post_excerpt' => 'post_excerpt',
10
- 'post_status' => 'post_status',
11
- 'post_date' => 'post_date',
12
- 'post_author' => 'post_author',
13
-
14
- // // Meta
15
- 'discount_type' => 'discount_type',
16
- 'coupon_amount' => 'coupon_amount',
17
- 'individual_use' => 'individual_use',
18
- 'product_ids' => 'product_ids',
19
- 'exclude_product_ids' => 'exclude_product_ids',
20
- 'usage_limit' => 'usage_limit',
21
- 'usage_limit_per_user' => 'usage_limit_per_user',
22
- 'limit_usage_to_x_items' => 'limit_usage_to_x_items',
23
- 'expiry_date' => 'expiry_date',
24
- 'free_shipping' => 'free_shipping',
25
- 'exclude_sale_items' => 'exclude_sale_items',
26
- 'product_categories' => 'product_categories',
27
- 'exclude_product_categories' => 'exclude_product_categories',
28
- 'minimum_amount' => 'minimum_amount',
29
- 'maximum_amount' => 'maximum_amount',
30
- 'customer_email' => 'customer_email',
31
-
32
  ) );
1
+ <?php
2
+ if ( ! defined( 'ABSPATH' ) ) {
3
+ exit;
4
+ }
5
+
6
+ return apply_filters('coupon_csv_coupon_post_columns', array(
7
+ 'post_title' => 'post_title',
8
+ 'ID' => 'ID',
9
+ 'post_excerpt' => 'post_excerpt',
10
+ 'post_status' => 'post_status',
11
+ 'post_date' => 'post_date',
12
+ 'post_author' => 'post_author',
13
+
14
+ // // Meta
15
+ 'discount_type' => 'discount_type',
16
+ 'coupon_amount' => 'coupon_amount',
17
+ 'individual_use' => 'individual_use',
18
+ 'product_ids' => 'product_ids',
19
+ 'exclude_product_ids' => 'exclude_product_ids',
20
+ 'usage_limit' => 'usage_limit',
21
+ 'usage_limit_per_user' => 'usage_limit_per_user',
22
+ 'limit_usage_to_x_items' => 'limit_usage_to_x_items',
23
+ 'expiry_date' => 'expiry_date',
24
+ 'free_shipping' => 'free_shipping',
25
+ 'exclude_sale_items' => 'exclude_sale_items',
26
+ 'product_categories' => 'product_categories',
27
+ 'exclude_product_categories' => 'exclude_product_categories',
28
+ 'minimum_amount' => 'minimum_amount',
29
+ 'maximum_amount' => 'maximum_amount',
30
+ 'customer_email' => 'customer_email',
31
+
32
  ) );
includes/exporter/data/data-wf-post-columns.php CHANGED
@@ -1,55 +1,55 @@
1
- <?php
2
-
3
- if (!defined('ABSPATH')) {
4
- exit;
5
- }
6
-
7
- return apply_filters('woocommerce_csv_order_post_columns', array(
8
- 'order_id' => 'order_id',
9
- 'order_number' => 'order_number',
10
- 'order_date' => 'order_date',
11
- 'status' => 'status',
12
- 'shipping_total' => 'shipping_total',
13
- 'shipping_tax_total' => 'shipping_tax_total',
14
- 'fee_total' => 'fee_total',
15
- 'fee_tax_total' => 'fee_tax_total',
16
- 'tax_total' => 'tax_total',
17
- 'cart_discount' => 'cart_discount',
18
- 'order_discount' => 'order_discount',
19
- 'discount_total' => 'discount_total',
20
- 'order_total' => 'order_total',
21
- 'refunded_total' => 'refunded_total',
22
- 'order_currency' => 'order_currency',
23
- 'payment_method' => 'payment_method',
24
- 'shipping_method' => 'shipping_method',
25
- 'customer_id' => 'customer_id',
26
- 'customer_user' => 'customer_user',
27
- 'customer_email' => 'customer_email',
28
- 'billing_first_name' => 'billing_first_name',
29
- 'billing_last_name' => 'billing_last_name',
30
- 'billing_company' => 'billing_company',
31
- 'billing_email' => 'billing_email',
32
- 'billing_phone' => 'billing_phone',
33
- 'billing_address_1' => 'billing_address_1',
34
- 'billing_address_2' => 'billing_address_2',
35
- 'billing_postcode' => 'billing_postcode',
36
- 'billing_city' => 'billing_city',
37
- 'billing_state' => 'billing_state',
38
- 'billing_country' => 'billing_country',
39
- 'shipping_first_name' => 'shipping_first_name',
40
- 'shipping_last_name' => 'shipping_last_name',
41
- 'shipping_company' => 'shipping_company',
42
- 'shipping_address_1' => 'shipping_address_1',
43
- 'shipping_address_2' => 'shipping_address_2',
44
- 'shipping_postcode' => 'shipping_postcode',
45
- 'shipping_city' => 'shipping_city',
46
- 'shipping_state' => 'shipping_state',
47
- 'shipping_country' => 'shipping_country',
48
- 'customer_note' => 'customer_note',
49
- 'shipping_items' => 'shipping_items',
50
- 'fee_items' => 'fee_items',
51
- 'tax_items' => 'tax_items',
52
- 'coupon_items' => 'coupon_items',
53
- 'order_notes' => 'order_notes',
54
- 'download_permissions' => 'download_permissions'
55
- ));
1
+ <?php
2
+
3
+ if (!defined('ABSPATH')) {
4
+ exit;
5
+ }
6
+
7
+ return apply_filters('woocommerce_csv_order_post_columns', array(
8
+ 'order_id' => 'order_id',
9
+ 'order_number' => 'order_number',
10
+ 'order_date' => 'order_date',
11
+ 'status' => 'status',
12
+ 'shipping_total' => 'shipping_total',
13
+ 'shipping_tax_total' => 'shipping_tax_total',
14
+ 'fee_total' => 'fee_total',
15
+ 'fee_tax_total' => 'fee_tax_total',
16
+ 'tax_total' => 'tax_total',
17
+ 'cart_discount' => 'cart_discount',
18
+ 'order_discount' => 'order_discount',
19
+ 'discount_total' => 'discount_total',
20
+ 'order_total' => 'order_total',
21
+ 'refunded_total' => 'refunded_total',
22
+ 'order_currency' => 'order_currency',
23
+ 'payment_method' => 'payment_method',
24
+ 'shipping_method' => 'shipping_method',
25
+ 'customer_id' => 'customer_id',
26
+ 'customer_user' => 'customer_user',
27
+ 'customer_email' => 'customer_email',
28
+ 'billing_first_name' => 'billing_first_name',
29
+ 'billing_last_name' => 'billing_last_name',
30
+ 'billing_company' => 'billing_company',
31
+ 'billing_email' => 'billing_email',
32
+ 'billing_phone' => 'billing_phone',
33
+ 'billing_address_1' => 'billing_address_1',
34
+ 'billing_address_2' => 'billing_address_2',
35
+ 'billing_postcode' => 'billing_postcode',
36
+ 'billing_city' => 'billing_city',
37
+ 'billing_state' => 'billing_state',
38
+ 'billing_country' => 'billing_country',
39
+ 'shipping_first_name' => 'shipping_first_name',
40
+ 'shipping_last_name' => 'shipping_last_name',
41
+ 'shipping_company' => 'shipping_company',
42
+ 'shipping_address_1' => 'shipping_address_1',
43
+ 'shipping_address_2' => 'shipping_address_2',
44
+ 'shipping_postcode' => 'shipping_postcode',
45
+ 'shipping_city' => 'shipping_city',
46
+ 'shipping_state' => 'shipping_state',
47
+ 'shipping_country' => 'shipping_country',
48
+ 'customer_note' => 'customer_note',
49
+ 'shipping_items' => 'shipping_items',
50
+ 'fee_items' => 'fee_items',
51
+ 'tax_items' => 'tax_items',
52
+ 'coupon_items' => 'coupon_items',
53
+ 'order_notes' => 'order_notes',
54
+ 'download_permissions' => 'download_permissions'
55
+ ));
includes/importer/class-wf-cpnimpexpcsv-coupon-import.php CHANGED
@@ -1,1051 +1,1051 @@
1
- <?php
2
- /**
3
- * WordPress Importer class for managing the import process of a CSV file
4
- *
5
- * @package WordPress
6
- * @subpackage Importer
7
- */
8
- if ( ! class_exists( 'WP_Importer' ) )
9
- return;
10
-
11
- class WF_CpnImpExpCsv_Coupon_Import extends WP_Importer {
12
-
13
- var $id;
14
- var $file_url;
15
- var $delimiter;
16
- var $profile;
17
- var $merge_empty_cells;
18
-
19
- // mappings from old information to new
20
- var $processed_terms = array();
21
- var $processed_posts = array();
22
- var $post_orphans = array();
23
- var $attachments = array();
24
- var $upsell_skus = array();
25
- var $crosssell_skus = array();
26
-
27
- // Results
28
- var $import_results = array();
29
-
30
- /**
31
- * Constructor
32
- */
33
- public function __construct() {
34
-
35
- if (WC()->version < '2.7.0') {
36
- $this->log = new WC_Logger();
37
- } else {
38
- $this->log = wc_get_logger();
39
- }
40
- $this->import_page = 'coupon_csv';
41
- $this->file_url_import_enabled = apply_filters( 'coupon_csv_coupon_file_url_import_enabled', true );
42
- }
43
-
44
- /**
45
- * Registered callback function for the WordPress Importer
46
- *
47
- * Manages the three separate stages of the CSV import process
48
- */
49
- public function dispatch() {
50
- global $woocommerce, $wpdb;
51
-
52
- if ( ! empty( $_POST['delimiter'] ) ) {
53
- $this->delimiter = stripslashes( trim( $_POST['delimiter'] ) );
54
- }else if ( ! empty( $_GET['delimiter'] ) ) {
55
- $this->delimiter = stripslashes( trim( $_GET['delimiter'] ) );
56
- }
57
-
58
- if ( ! $this->delimiter )
59
- $this->delimiter = ',';
60
-
61
- if ( ! empty( $_POST['profile'] ) ) {
62
- $this->profile = stripslashes( trim( $_POST['profile'] ) );
63
- }else if ( ! empty( $_GET['profile'] ) ) {
64
- $this->profile = stripslashes( trim( $_GET['profile'] ) );
65
- }
66
- if ( ! $this->profile )
67
- $this->profile = '';
68
-
69
- if ( ! empty( $_POST['merge_empty_cells'] ) || ! empty( $_GET['merge_empty_cells'] ) ) {
70
- $this->merge_empty_cells = 1;
71
- } else{
72
- $this->merge_empty_cells = 0;
73
- }
74
-
75
- $step = empty( $_GET['step'] ) ? 0 : (int) $_GET['step'];
76
-
77
- switch ( $step ) {
78
- case 0 :
79
- $this->header();
80
- $this->greet();
81
- break;
82
- case 1 :
83
- $this->header();
84
-
85
- check_admin_referer( 'import-upload' );
86
-
87
- if(!empty($_GET['file_url']))
88
- $this->file_url = esc_attr( $_GET['file_url'] );
89
- if(!empty($_GET['file_id']))
90
- $this->id = $_GET['file_id'] ;
91
-
92
- if ( !empty($_GET['clearmapping']) || $this->handle_upload() )
93
- $this->import_options();
94
- else
95
- //_e( 'Error with handle_upload!', 'wf_order_import_export' );
96
- wp_redirect(wp_get_referer().'&wf_coupon_ie_msg=3');
97
- exit;
98
- break;
99
- case 2 :
100
- $this->header();
101
-
102
- check_admin_referer( 'import-woocommerce' );
103
-
104
- $this->id = (int) $_POST['import_id'];
105
-
106
- if ( $this->file_url_import_enabled )
107
- $this->file_url = esc_attr( $_POST['import_url'] );
108
-
109
- if ( $this->id )
110
- $file = get_attached_file( $this->id );
111
- else if ( $this->file_url_import_enabled )
112
- $file = ABSPATH . $this->file_url;
113
-
114
- $file = str_replace( "\\", "/", $file );
115
-
116
- if ( $file ) {
117
- ?>
118
- <table id="import-progress" class="widefat_importer widefat">
119
- <thead>
120
- <tr>
121
- <th class="status">&nbsp;</th>
122
- <th class="row"><?php _e( 'Row', 'wf_order_import_export' ); ?></th>
123
- <th><?php _e( 'Coupon Id', 'wf_order_import_export' ); ?></th>
124
- <th><?php _e( 'Coupon Name', 'wf_order_import_export' ); ?></th>
125
- <th class="reason"><?php _e( 'Status Msg', 'wf_order_import_export' ); ?></th>
126
- </tr>
127
- </thead>
128
- <tfoot>
129
- <tr class="importer-loading">
130
- <td colspan="5"></td>
131
- </tr>
132
- </tfoot>
133
- <tbody></tbody>
134
- </table>
135
- <script type="text/javascript">
136
- jQuery(document).ready(function($) {
137
-
138
- if ( ! window.console ) { window.console = function(){}; }
139
-
140
- var processed_terms = [];
141
- var processed_posts = [];
142
- var post_orphans = [];
143
- var attachments = [];
144
- var upsell_skus = [];
145
- var crosssell_skus = [];
146
- var i = 1;
147
- var done_count = 0;
148
-
149
- function import_rows( start_pos, end_pos ) {
150
-
151
- var data = {
152
- action: 'coupon_csv_import_request',
153
- file: '<?php echo addslashes( $file ); ?>',
154
- mapping: '<?php echo @json_encode( $_POST['map_from'] ); ?>',
155
- profile: '<?php echo $this->profile; ?>',
156
- eval_field: '<?php echo @stripslashes(json_encode(($_POST['eval_field']),JSON_HEX_APOS)) ?>',
157
- delimiter: '<?php echo $this->delimiter; ?>',
158
- merge_empty_cells: '<?php echo $this->merge_empty_cells; ?>',
159
- start_pos: start_pos,
160
- end_pos: end_pos,
161
- };
162
- data.eval_field = $.parseJSON(data.eval_field);
163
- return $.ajax({
164
- url: '<?php echo add_query_arg( array( 'import_page' => $this->import_page, 'step' => '3', 'merge' => ! empty( $_GET['merge'] ) ? '1' : '0' ), admin_url( 'admin-ajax.php' ) ); ?>',
165
- data: data,
166
- type: 'POST',
167
- success: function( response ) {
168
- if ( response ) {
169
-
170
- try {
171
- // Get the valid JSON only from the returned string
172
- if ( response.indexOf("<!--WC_START-->") >= 0 )
173
- response = response.split("<!--WC_START-->")[1]; // Strip off before after WC_START
174
-
175
- if ( response.indexOf("<!--WC_END-->") >= 0 )
176
- response = response.split("<!--WC_END-->")[0]; // Strip off anything after WC_END
177
-
178
- // Parse
179
- var results = $.parseJSON( response );
180
-
181
- if ( results.error ) {
182
-
183
- $('#import-progress tbody').append( '<tr id="row-' + i + '" class="error"><td class="status" colspan="5">' + results.error + '</td></tr>' );
184
-
185
- i++;
186
-
187
- } else if ( results.import_results && $( results.import_results ).size() > 0 ) {
188
-
189
- $.each( results.processed_terms, function( index, value ) {
190
- processed_terms.push( value );
191
- });
192
-
193
- $.each( results.processed_posts, function( index, value ) {
194
- processed_posts.push( value );
195
- });
196
-
197
- $.each( results.post_orphans, function( index, value ) {
198
- post_orphans.push( value );
199
- });
200
-
201
- $.each( results.attachments, function( index, value ) {
202
- attachments.push( value );
203
- });
204
-
205
- upsell_skus = jQuery.extend( {}, upsell_skus, results.upsell_skus );
206
- crosssell_skus = jQuery.extend( {}, crosssell_skus, results.crosssell_skus );
207
-
208
- $( results.import_results ).each(function( index, row ) {
209
- $('#import-progress tbody').append( '<tr id="row-' + i + '" class="' + row['status'] + '"><td><mark class="result" title="' + row['status'] + '">' + row['status'] + '</mark></td><td class="row">' + i + '</td><td>' + row['post_id'] + '</td><td>' + row['post_title'] + '</td><td class="reason">' + row['reason'] + '</td></tr>' );
210
-
211
- i++;
212
- });
213
- }
214
-
215
- } catch(err) {}
216
-
217
- } else {
218
- $('#import-progress tbody').append( '<tr class="error"><td class="status" colspan="5">' + '<?php _e( 'AJAX Error', 'wf_order_import_export' ); ?>' + '</td></tr>' );
219
- }
220
-
221
- var w = $(window);
222
- var row = $( "#row-" + ( i - 1 ) );
223
-
224
- if ( row.length ) {
225
- w.scrollTop( row.offset().top - (w.height()/2) );
226
- }
227
-
228
- done_count++;
229
-
230
- $('body').trigger( 'coupon_csv_import_request_complete' );
231
- }
232
- });
233
- }
234
-
235
- var rows = [];
236
-
237
- <?php
238
- $limit = apply_filters( 'coupon_csv_import_limit_per_request', 10 );
239
- $enc = mb_detect_encoding( $file, 'UTF-8, ISO-8859-1', true );
240
- if ( $enc )
241
- setlocale( LC_ALL, 'en_US.' . $enc );
242
- @ini_set( 'auto_detect_line_endings', true );
243
-
244
- $count = 0;
245
- $previous_position = 0;
246
- $position = 0;
247
- $import_count = 0;
248
-
249
- // Get CSV positions
250
- if ( ( $handle = fopen( $file, "r" ) ) !== FALSE ) {
251
-
252
- while ( ( $postmeta = fgetcsv( $handle, 0, $this->delimiter , '"', '"' ) ) !== FALSE ) {
253
- $count++;
254
-
255
- if ( $count >= $limit ) {
256
- $previous_position = $position;
257
- $position = ftell( $handle );
258
- $count = 0;
259
- $import_count ++;
260
-
261
- // Import rows between $previous_position $position
262
- ?>rows.push( [ <?php echo $previous_position; ?>, <?php echo $position; ?> ] ); <?php
263
- }
264
- }
265
-
266
- // Remainder
267
- if ( $count > 0 ) {
268
- ?>rows.push( [ <?php echo $position; ?>, '' ] ); <?php
269
- $import_count ++;
270
- }
271
-
272
- fclose( $handle );
273
- }
274
- ?>
275
-
276
- var data = rows.shift();
277
- var regen_count = 0;
278
- import_rows( data[0], data[1] );
279
-
280
- $('body').on( 'coupon_csv_import_request_complete', function() {
281
- if ( done_count == <?php echo $import_count; ?> ) {
282
-
283
- if ( attachments.length ) {
284
-
285
- $('#import-progress tbody').append( '<tr class="regenerating"><td colspan="5"><div class="progress"></div></td></tr>' );
286
-
287
- index = 0;
288
-
289
- $.each( attachments, function( i, value ) {
290
- regenerate_thumbnail( value );
291
- index ++;
292
- if ( index == attachments.length ) {
293
- import_done();
294
- }
295
- });
296
-
297
- } else {
298
- import_done();
299
- }
300
-
301
- } else {
302
- // Call next request
303
- data = rows.shift();
304
- import_rows( data[0], data[1] );
305
- }
306
- } );
307
-
308
- // Regenerate a specified image via AJAX
309
- function regenerate_thumbnail( id ) {
310
- $.ajax({
311
- type: 'POST',
312
- url: ajaxurl,
313
- data: { action: "coupon_csv_import_regenerate_thumbnail", id: id },
314
- success: function( response ) {
315
- if ( response !== Object( response ) || ( typeof response.success === "undefined" && typeof response.error === "undefined" ) ) {
316
- response = new Object;
317
- response.success = false;
318
- response.error = "<?php printf( esc_js( __( 'The resize request was abnormally terminated (ID %s). This is likely due to the image exceeding available memory or some other type of fatal error.', 'wf_order_import_export' ) ), '" + id + "' ); ?>";
319
- }
320
-
321
- regen_count ++;
322
-
323
- $('#import-progress tbody .regenerating .progress').css( 'width', ( ( regen_count / attachments.length ) * 100 ) + '%' ).html( regen_count + ' / ' + attachments.length + ' <?php echo esc_js( __( 'thumbnails regenerated', 'wf_order_import_export' ) ); ?>' );
324
-
325
- if ( ! response.success ) {
326
- $('#import-progress tbody').append( '<tr><td colspan="5">' + response.error + '</td></tr>' );
327
- }
328
- },
329
- error: function( response ) {
330
- $('#import-progress tbody').append( '<tr><td colspan="5">' + response.error + '</td></tr>' );
331
- }
332
- });
333
- }
334
-
335
- function import_done() {
336
- var data = {
337
- action: 'coupon_csv_import_request',
338
- file: '<?php echo $file; ?>',
339
- processed_terms: processed_terms,
340
- processed_posts: processed_posts,
341
- post_orphans: post_orphans,
342
- upsell_skus: upsell_skus,
343
- crosssell_skus: crosssell_skus
344
- };
345
-
346
- $.ajax({
347
- url: '<?php echo add_query_arg( array( 'import_page' => $this->import_page, 'step' => '4', 'merge' => ! empty( $_GET['merge'] ) ? 1 : 0 ), admin_url( 'admin-ajax.php' ) ); ?>',
348
- data: data,
349
- type: 'POST',
350
- success: function( response ) {
351
- //console.log( response );
352
- $('#import-progress tbody').append( '<tr class="complete"><td colspan="5">' + response + '</td></tr>' );
353
- $('.importer-loading').hide();
354
- }
355
- });
356
- }
357
- });
358
- </script>
359
- <?php
360
- } else {
361
- echo '<p class="error">' . __( 'Error finding uploaded file!', 'wf_order_import_export' ) . '</p>';
362
- }
363
- break;
364
- case 3 :
365
- // Check access - cannot use nonce here as it will expire after multiple requests
366
- if ( ! current_user_can( 'manage_woocommerce' ) )
367
- die();
368
-
369
- add_filter( 'http_request_timeout', array( $this, 'bump_request_timeout' ) );
370
-
371
- if ( function_exists( 'gc_enable' ) )
372
- gc_enable();
373
-
374
- @set_time_limit(0);
375
- @ob_flush();
376
- @flush();
377
- $wpdb->hide_errors();
378
-
379
- $file = stripslashes( $_POST['file'] );
380
- $mapping = json_decode( stripslashes( $_POST['mapping'] ), true );
381
- $profile = isset( $_POST['profile'] ) ? $_POST['profile']:'';
382
- $eval_field = $_POST['eval_field'];
383
- $start_pos = isset( $_POST['start_pos'] ) ? absint( $_POST['start_pos'] ) : 0;
384
- $end_pos = isset( $_POST['end_pos'] ) ? absint( $_POST['end_pos'] ) : '';
385
-
386
- if($profile!== '')
387
- {
388
- $profile_array = get_option('wf_cpn_csv_imp_exp_mapping');
389
- $profile_array[$profile] = array($mapping,$eval_field);
390
- update_option('wf_cpn_csv_imp_exp_mapping', $profile_array);
391
- }
392
-
393
- $position = $this->import_start( $file, $mapping, $start_pos, $end_pos, $eval_field );
394
- $this->import();
395
- $this->import_end();
396
-
397
- $results = array();
398
- $results['import_results'] = $this->import_results;
399
- $results['processed_terms'] = $this->processed_terms;
400
- $results['processed_posts'] = $this->processed_posts;
401
- $results['post_orphans'] = $this->post_orphans;
402
- $results['attachments'] = $this->attachments;
403
- $results['upsell_skus'] = $this->upsell_skus;
404
- $results['crosssell_skus'] = $this->crosssell_skus;
405
-
406
- echo "<!--WC_START-->";
407
- echo json_encode( $results );
408
- echo "<!--WC_END-->";
409
- exit;
410
- break;
411
- case 4 :
412
- // Check access - cannot use nonce here as it will expire after multiple requests
413
- if ( ! current_user_can( 'manage_woocommerce' ) )
414
- die();
415
-
416
- add_filter( 'http_request_timeout', array( $this, 'bump_request_timeout' ) );
417
-
418
- if ( function_exists( 'gc_enable' ) )
419
- gc_enable();
420
-
421
- @set_time_limit(0);
422
- @ob_flush();
423
- @flush();
424
- $wpdb->hide_errors();
425
-
426
- $this->processed_terms = isset( $_POST['processed_terms'] ) ? $_POST['processed_terms'] : array();
427
- $this->processed_posts = isset( $_POST['processed_posts']) ? $_POST['processed_posts'] : array();
428
- $this->post_orphans = isset( $_POST['post_orphans']) ? $_POST['post_orphans'] : array();
429
- $this->crosssell_skus = isset( $_POST['crosssell_skus']) ? array_filter( (array) $_POST['crosssell_skus'] ) : array();
430
- $this->upsell_skus = isset( $_POST['upsell_skus']) ? array_filter( (array) $_POST['upsell_skus'] ) : array();
431
-
432
- _e( 'Step 1...', 'wf_order_import_export' ) . ' ';
433
-
434
- wp_defer_term_counting( true );
435
- wp_defer_comment_counting( true );
436
-
437
- _e( 'Step 2...', 'wf_order_import_export' ) . ' ';
438
-
439
- echo 'Step 3...' . ' '; // Easter egg
440
- _e( 'Finalizing...', 'wf_order_import_export' ) . ' ';
441
-
442
-
443
- // SUCCESS
444
- _e( 'Finished. Import complete.', 'wf_order_import_export' );
445
-
446
- $this->import_end();
447
- exit;
448
- break;
449
- }
450
-
451
- $this->footer();
452
- }
453
-
454
- /**
455
- * format_data_from_csv
456
- */
457
- public function format_data_from_csv( $data, $enc ) {
458
- return ( $enc == 'UTF-8' ) ? $data : utf8_encode( $data );
459
- }
460
-
461
- /**
462
- * Display pre-import options
463
- */
464
- public function import_options()
465
- {
466
- $j = 0;
467
-
468
- if ( $this->id )
469
- $file = get_attached_file( $this->id );
470
- else if ( $this->file_url_import_enabled )
471
- $file = ABSPATH . $this->file_url;
472
- else
473
- return;
474
-
475
- // Set locale
476
- $enc = mb_detect_encoding( $file, 'UTF-8, ISO-8859-1', true );
477
- if ( $enc ) setlocale( LC_ALL, 'en_US.' . $enc );
478
- @ini_set( 'auto_detect_line_endings', true );
479
-
480
- // Get headers
481
- if ( ( $handle = fopen( $file, "r" ) ) !== FALSE )
482
- {
483
- $row = $raw_headers = array();
484
-
485
- $header = fgetcsv( $handle, 0, $this->delimiter , '"', '"');
486
-
487
- while ( ( $postmeta = fgetcsv( $handle, 0, $this->delimiter , '"', '"') ) !== FALSE )
488
- {
489
- foreach ( $header as $key => $heading )
490
- {
491
- if ( ! $heading ) continue;
492
- $s_heading = strtolower( $heading );
493
- $row[$s_heading] = ( isset( $postmeta[$key] ) ) ? $this->format_data_from_csv( $postmeta[$key], $enc ) : '';
494
- $raw_headers[ $s_heading ] = $heading;
495
- }
496
- break;
497
- }
498
- fclose( $handle );
499
- }
500
-
501
- $mapping_from_db = get_option( 'wf_cpn_csv_imp_exp_mapping');
502
-
503
- if( $this->profile!=='' && !empty($_GET['clearmapping']))
504
- {
505
- unset($mapping_from_db[$this->profile]);
506
- update_option('wf_cpn_csv_imp_exp_mapping', $mapping_from_db);
507
- $this->profile = '';
508
- }
509
- if($this->profile !== '')
510
- $mapping_from_db = $mapping_from_db[$this->profile];
511
-
512
- $saved_mapping = null;
513
- $saved_evaluation = null;
514
- if($mapping_from_db && is_array($mapping_from_db) && count($mapping_from_db) == 2 && empty($_GET['clearmapping']))
515
- {
516
- $reset_action = 'admin.php?clearmapping=1&amp;profile='.$this->profile.'&amp;import=' . $this->import_page . '&amp;step=1&amp;merge=' . ( ! empty( $_GET['merge'] ) ? 1 : 0 ) . '&amp;file_url=' . $this->file_url . '&amp;delimiter=' . $this->delimiter . '&amp;merge_empty_cells=' . $this->merge_empty_cells . '&amp;file_id=' . $this->id . '';
517
- $reset_action = esc_attr(wp_nonce_url($reset_action, 'import-upload'));
518
- echo '<h3>' . __( 'Columns are pre-selected using the Mapping file: "<b style="color:gray">'.$this->profile.'</b>". <a href="'.$reset_action.'"> Delete</a> this mapping file.', 'wf_order_import_export' ) . '</h3>';
519
- $saved_mapping = $mapping_from_db[0];
520
- $saved_evaluation = $mapping_from_db[1];
521
- }
522
-
523
- $merge = (!empty($_GET['merge']) && $_GET['merge']) ? 1 : 0;
524
- include( 'views-coupon/html-wf-import-options.php' );
525
- }
526
-
527
- /**
528
- * The main controller for the actual import stage.
529
- */
530
- public function import()
531
- {
532
- global $woocommerce, $wpdb;
533
-
534
- wp_suspend_cache_invalidation( true );
535
-
536
- $this->hf_coupon_log_data_change( 'coupon-csv-import', '---' );
537
- $this->hf_coupon_log_data_change( 'coupon-csv-import', __( 'Processing coupons.', 'wf_order_import_export' ) );
538
- foreach ( $this->parsed_data as $key => &$item )
539
- {
540
- $coupon = $this->parser->parse_coupon( $item, $this->merge_empty_cells );
541
- if ( ! is_wp_error( $coupon ) )
542
- $this->process_coupon( $coupon );
543
- else
544
- $this->add_import_result( 'failed', $coupon->get_error_message(), 'Not parsed', json_encode( $item ) );
545
-
546
- unset( $item, $coupon );
547
- }
548
- $this->hf_coupon_log_data_change( 'coupon-csv-import', __( 'Finished processing coupons.', 'wf_order_import_export' ) );
549
- wp_suspend_cache_invalidation( false );
550
- }
551
-
552
- /**
553
- * Parses the CSV file and prepares us for the task of processing parsed data
554
- *
555
- * @param string $file Path to the CSV file for importing
556
- */
557
- public function import_start( $file, $mapping, $start_pos, $end_pos, $eval_field ) {
558
-
559
- $memory = size_format( (WC()->version < '2.7.0')?woocommerce_let_to_num( ini_get( 'memory_limit' ) ):wc_let_to_num( ini_get( 'memory_limit' ) ) );
560
- $wp_memory = size_format( (WC()->version < '2.7.0')? woocommerce_let_to_num( WP_MEMORY_LIMIT ) : wc_let_to_num( WP_MEMORY_LIMIT ) );
561
-
562
- $this->hf_coupon_log_data_change( 'coupon-csv-import', '---[ New Import ] PHP Memory: ' . $memory . ', WP Memory: ' . $wp_memory );
563
- $this->hf_coupon_log_data_change( 'coupon-csv-import', __( 'Parsing coupons CSV.', 'wf_order_import_export' ) );
564
-
565
- $this->parser = new WF_CSV_Parser_Coupon( 'shop_coupon' );
566
-
567
- list( $this->parsed_data, $this->raw_headers, $position ) = $this->parser->parse_data( $file, $this->delimiter, $mapping, $start_pos, $end_pos, $eval_field );
568
- $this->hf_coupon_log_data_change( 'coupon-csv-import', __( 'Finished parsing coupons CSV.', 'wf_order_import_export' ) );
569
-
570
- unset( $import_data );
571
-
572
- wp_defer_term_counting( true );
573
- wp_defer_comment_counting( true );
574
-
575
- return $position;
576
- }
577
-
578
- /**
579
- * Performs post-import cleanup of files and the cache
580
- */
581
- public function import_end() {
582
-
583
- do_action( 'import_end' );
584
- }
585
-
586
- /**
587
- * Handles the CSV upload and initial parsing of the file to prepare for
588
- * displaying author import options
589
- *
590
- * @return bool False if error uploading or invalid file, true otherwise
591
- */
592
- public function handle_upload() {
593
- if($this->handle_ftp()){
594
- return true;
595
- }
596
- if ( empty( $_POST['file_url'] ) ) {
597
-
598
- $file = wp_import_handle_upload();
599
-
600
- if ( isset( $file['error'] ) ) {
601
- echo '<p><strong>' . __( 'Sorry, there has been an error.', 'wf_order_import_export' ) . '</strong><br />';
602
- echo esc_html( $file['error'] ) . '</p>';
603
- return false;
604
- }
605
-
606
- $this->id = (int) $file['id'];
607
- return true;
608
-
609
- } else {
610
-
611
- if ( file_exists( ABSPATH . $_POST['file_url'] ) )
612
- {
613
- $this->file_url = esc_attr( $_POST['file_url'] );
614
- return true;
615
- } else {
616
- echo '<p><strong>' . __( 'Sorry, there has been an error.', 'wf_order_import_export' ) . '</strong></p>';
617
- return false;
618
- }
619
-
620
- }
621
-
622
- return false;
623
- }
624
-
625
- public function coupon_exists( $title, $ID = '', $post_name = '' )
626
- {
627
- global $wpdb;
628
-
629
- // Post Title Check
630
- $post_title = stripslashes( sanitize_post_field( 'post_title', $title, 0, 'db' ) );
631
-
632
- $query = "SELECT ID FROM $wpdb->posts WHERE post_type = 'shop_coupon' AND post_status IN ( 'publish', 'private', 'draft', 'pending', 'future' )";
633
- $args = array();
634
-
635
- if ( ! empty ( $post_name ) )
636
- {
637
- $query .= ' AND post_name = %s';
638
- $args[] = $post_name;
639
- }
640
-
641
- if ( ! empty ( $args ) )
642
- {
643
- $posts_that_exist = $wpdb->get_col( $wpdb->prepare( $query, $args ) );
644
- if ( $posts_that_exist )
645
- {
646
- foreach( $posts_that_exist as $post_exists )
647
- {
648
- if ( $ID == $post_exists )
649
- {
650
- return true;
651
- }
652
- }
653
- }
654
- }
655
- return false;
656
- }
657
-
658
- /**
659
- * Create new posts based on import information
660
- */
661
- public function process_coupon( $post )
662
- {
663
-
664
- $processing_coupon_id = absint( $post['post_id'] );
665
- $processing_coupon = get_post( $processing_coupon_id );
666
- $processing_coupon_title = $processing_coupon ? $processing_coupon->post_title : '';
667
- $processing_coupon_sku = $processing_coupon ? $processing_coupon->sku : '';
668
- $merging = ! empty( $post['merging'] );
669
-
670
- if ( ! empty( $post['post_title'] ) ) {
671
- $processing_coupon_title = $post['post_title'];
672
- }
673
- $post['post_type'] = 'shop_coupon';
674
-
675
-
676
- if ( ! empty( $processing_coupon_id ) && isset( $this->processed_posts[ $processing_coupon_id ] ) )
677
- {
678
- $this->add_import_result( 'skipped', __( 'Coupon already processed', 'wf_order_import_export' ), $processing_coupon_id, $processing_coupon_title );
679
- $this->hf_coupon_log_data_change( 'coupon-csv-import', __('> Coupon ID already processed. Skipping.', 'wf_order_import_export'), true );
680
- unset( $post );
681
- return;
682
- }
683
-
684
- if ( ! empty ( $post['post_status'] ) && $post['post_status'] == 'auto-draft' )
685
- {
686
- $this->add_import_result( 'skipped', __( 'Skipping auto-draft', 'wf_order_import_export' ), $processing_coupon_id, $processing_coupon_title);
687
- $this->hf_coupon_log_data_change( 'coupon-csv-import', __('> Skipping auto-draft.', 'wf_order_import_export'), true );
688
- unset( $post );
689
- return;
690
- }
691
- if ( ! $merging )
692
- {
693
- if ( $this->coupon_exists( $processing_coupon_title, $processing_coupon_id, $post['post_name'] ) )
694
- {
695
- if(!$processing_coupon_id)
696
- {
697
- $usr_msg = 'Coupon with same title already exists.';
698
- }else{
699
- $usr_msg = 'Coupon already exists.';
700
- }
701
- $this->add_import_result( 'skipped', __( $usr_msg, 'wf_order_import_export' ), $processing_coupon_id, $processing_coupon_title );
702
- $this->hf_coupon_log_data_change( 'coupon-csv-import', sprintf( __('> &#8220;%s&#8221;'.$usr_msg, 'wf_order_import_export'), esc_html($processing_coupon_title) ), true );
703
- unset( $post );
704
- return;
705
- }
706
-
707
- if ( $processing_coupon_id && is_string( get_post_status( $processing_coupon_id ) ) )
708
- {
709
- $this->add_import_result( 'skipped', __( 'Importing coupon ID conflicts with an existing coupon ID', 'wf_order_import_export' ), $processing_coupon_id, get_the_title( $processing_coupon_id ) );
710
- $this->hf_coupon_log_data_change( 'coupon-csv-import', sprintf( __('> &#8220;%s&#8221; ID already exists.', 'wf_order_import_export'), esc_html( $processing_coupon_id ) ), true );
711
- unset( $post );
712
- return;
713
- }
714
- }
715
- $is_post_exist_in_db = get_post_type( $processing_coupon_id );
716
-
717
- if ( $merging && $processing_coupon_id && !empty($is_post_exist_in_db) && (get_post_type( $processing_coupon_id ) !== $post['post_type'] ))
718
- {
719
- $this->add_import_result( 'skipped', __( 'Post is not a coupon', 'wf_order_import_export' ), $processing_coupon_id, $processing_coupon_title );
720
- $this->hf_coupon_log_data_change( 'coupon-csv-import', sprintf( __('> &#8220;%s&#8221; is not a coupon.', 'wf_order_import_export'), esc_html($processing_coupon_id) ), true );
721
-
722
- unset( $post );
723
- return;
724
- }
725
-
726
- if ( $merging && !empty($is_post_exist_in_db) )
727
- {
728
- $post_id = $processing_coupon_id;
729
-
730
- $this->hf_coupon_log_data_change( 'coupon-csv-import', sprintf( __('> Merging coupon ID %s.', 'wf_order_import_export'), $post_id ), true );
731
-
732
- $postdata = array(
733
- 'ID' => $post_id
734
- );
735
-
736
- if ( $this->merge_empty_cells )
737
- {
738
- if ( isset( $post['post_content'] ) ) {
739
- $postdata['post_content'] = $post['post_content'];
740
- }
741
- if ( isset( $post['post_excerpt'] ) ) {
742
- $postdata['post_excerpt'] = $post['post_excerpt'];
743
- }
744
-
745
- } else {
746
- if ( ! empty( $post['post_content'] ) ) {
747
- $postdata['post_content'] = $post['post_content'];
748
- }
749
- if ( ! empty( $post['post_excerpt'] ) ) {
750
- $postdata['post_excerpt'] = $post['post_excerpt'];
751
- }
752
-
753
- }
754
-
755
- if ( ! empty( $post['post_title'] ) ) {
756
- $postdata['post_title'] = $post['post_title'];
757
- }
758
-
759
- if ( ! empty( $post['post_author'] ) ) {
760
- $postdata['post_author'] = absint( $post['post_author'] );
761
- }
762
- if ( ! empty( $post['post_date'] ) ) {
763
- $postdata['post_date'] = date("Y-m-d H:i:s", strtotime( $post['post_date'] ) );
764
- }
765
- if ( ! empty( $post['post_date_gmt'] ) ) {
766
- $postdata['post_date_gmt'] = date("Y-m-d H:i:s", strtotime( $post['post_date_gmt'] ) );
767
- }
768
- if ( ! empty( $post['post_name'] ) ) {
769
- $postdata['post_name'] = $post['post_name'];
770
- }
771
- if ( ! empty( $post['post_status'] ) ) {
772
- $postdata['post_status'] = $post['post_status'];
773
- }
774
-
775
- if ( sizeof( $postdata ) > 1 )
776
- {
777
- $result = wp_update_post( $postdata );
778
-
779
- if ( ! $result )
780
- {
781
- $this->add_import_result( 'failed', __( 'Failed to update coupon', 'wf_order_import_export' ), $post_id, $processing_coupon_title );
782
- $this->hf_coupon_log_data_change( 'coupon-csv-import', sprintf( __('> Failed to update coupon %s', 'wf_order_import_export'), $post_id ), true );
783
- unset( $post );
784
- return;
785
- } else {
786
- $this->hf_coupon_log_data_change( 'coupon-csv-import', __( '> Merged post data: ', 'wf_order_import_export' ) . print_r( $postdata, true ) );
787
- }
788
- }
789
-
790
- } else
791
- {
792
- $merging = FALSE;
793
-
794
- $this->hf_coupon_log_data_change( 'coupon-csv-import', sprintf( __('> Inserting %s', 'wf_order_import_export'), esc_html( $processing_coupon_title ) ), true );
795
- $postdata = array(
796
- 'post_author' => $post['post_author'] ? absint( $post['post_author'] ) : get_current_user_id(),
797
- 'post_date' => ( $post['post_date'] ) ? date( 'Y-m-d H:i:s', strtotime( $post['post_date'] )) : '',
798
- 'post_date_gmt' => ( $post['post_date_gmt'] ) ? date( 'Y-m-d H:i:s', strtotime( $post['post_date_gmt'] )) : '',
799
- 'post_content' => $post['post_excerpt'],
800
- 'post_excerpt' => $post['post_excerpt'],
801
- 'post_title' => $post['post_title'],
802
- 'post_name' => ( $post['post_name'] ) ? $post['post_name'] : sanitize_title( $post['post_title'] ),
803
- 'post_status' => ( $post['post_status'] ) ? $post['post_status'] : 'publish',
804
- 'post_type' => 'shop_coupon',
805
- );
806
-
807
- $post_id = wp_insert_post( $postdata, true );
808
-
809
- if ( is_wp_error( $post_id ) )
810
- {
811
-
812
- $this->add_import_result( 'failed', __( 'Failed to import coupon', 'wf_order_import_export' ), $processing_coupon_id, $processing_coupon_title );
813
- $this->hf_coupon_log_data_change( 'coupon-csv-import', sprintf( __( 'Failed to import coupon &#8220;%s&#8221;', 'wf_order_import_export' ), esc_html($processing_coupon_title) ) );
814
- unset( $post );
815
- return;
816
-
817
- } else {
818
-
819
- $this->hf_coupon_log_data_change( 'coupon-csv-import', sprintf( __('> Inserted - coupon ID is %s.', 'wf_order_import_export'), $post_id ) );
820
-
821
- }
822
- }
823
-
824
- unset( $postdata );
825
-
826
- if ( empty( $processing_coupon_id ) ) {
827
- $processing_coupon_id = (int) $post_id;
828
- }
829
-
830
- $this->processed_posts[ intval( $processing_coupon_id ) ] = (int) $post_id;
831
- if ( ! empty( $post['postmeta'] ) && is_array( $post['postmeta'] ) )
832
- {
833
- foreach ( $post['postmeta'] as $meta )
834
- {
835
- $key = apply_filters( 'import_post_meta_key', $meta['key'] );
836
-
837
- if ( $key )
838
- {
839
- if($key == 'product_categories' || $key == 'exclude_product_categories')
840
- {
841
- update_post_meta( $post_id, $key, explode(",",$meta['value'] ) );
842
- }
843
- else
844
- {
845
- if($key == 'customer_email'){
846
- $data= explode(',', $meta['value']);
847
- update_post_meta( $post_id, $key,( $data ) );
848
- }else{
849
- update_post_meta( $post_id, $key, maybe_unserialize( $meta['value'] ) );
850
- }
851
- }
852
-
853
- }
854
- }
855
- unset( $post['postmeta'] );
856
- }
857
- if ( $merging )
858
- {
859
- $this->add_import_result( 'merged', 'Coupon Merge successful', $post_id, $processing_coupon_title );
860
- $this->hf_coupon_log_data_change( 'coupon-csv-import', sprintf( __('> Finished merging post ID %s.', 'wf_order_import_export'), $post_id ) );
861
- } else {
862
- $this->add_import_result( 'imported', 'Coupon Import successful', $post_id, $processing_coupon_title );
863
- $this->hf_coupon_log_data_change( 'coupon-csv-import', sprintf( __('> Finished importing post ID %s.', 'wf_order_import_export'), $post_id ) );
864
- }
865
- unset( $post );
866
- }
867
-
868
- /**
869
- * Log a row's import status
870
- */
871
- protected function add_import_result( $status, $reason, $post_id = '', $post_title = '' ) {
872
- $this->import_results[] = array(
873
- 'post_title' => $post_title,
874
- 'post_id' => $post_id,
875
- 'status' => $status,
876
- 'reason' => $reason
877
- );
878
- }
879
- /**
880
- * Attempt to download a remote file attachment
881
- */
882
- public function fetch_remote_file( $url, $post )
883
- {
884
-
885
- // extract the file name and extension from the url
886
- $file_name = basename( current( explode( '?', $url ) ) );
887
- $wp_filetype = wp_check_filetype( $file_name, null );
888
- $parsed_url = @parse_url( $url );
889
-
890
- // Check parsed URL
891
- if ( ! $parsed_url || ! is_array( $parsed_url ) )
892
- return new WP_Error( 'import_file_error', 'Invalid URL' );
893
-
894
- // Ensure url is valid
895
- $url = str_replace( " ", '%20', $url );
896
-
897
- // Get the file
898
- $response = wp_remote_get( $url, array(
899
- 'timeout' => 10
900
- ) );
901
-
902
- if ( is_wp_error( $response ) || wp_remote_retrieve_response_code( $response ) !== 200 )
903
- return new WP_Error( 'import_file_error', 'Error getting remote image' );
904
-
905
- // Ensure we have a file name and type
906
- if ( ! $wp_filetype['type'] ) {
907
-
908
- $headers = wp_remote_retrieve_headers( $response );
909
-
910
- if ( isset( $headers['content-disposition'] ) && strstr( $headers['content-disposition'], 'filename=' ) ) {
911
-
912
- $disposition = end( explode( 'filename=', $headers['content-disposition'] ) );
913
- $disposition = sanitize_file_name( $disposition );
914
- $file_name = $disposition;
915
-
916
- } elseif ( isset( $headers['content-type'] ) && strstr( $headers['content-type'], 'image/' ) ) {
917
-
918
- $file_name = 'image.' . str_replace( 'image/', '', $headers['content-type'] );
919
-
920
- }
921
-
922
- unset( $headers );
923
- }
924
-
925
- // Upload the file
926
- $upload = wp_upload_bits( $file_name, '', wp_remote_retrieve_body( $response ) );
927
-
928
- if ( $upload['error'] )
929
- return new WP_Error( 'upload_dir_error', $upload['error'] );
930
-
931
- // Get filesize
932
- $filesize = filesize( $upload['file'] );
933
-
934
- if ( 0 == $filesize ) {
935
- @unlink( $upload['file'] );
936
- unset( $upload );
937
- return new WP_Error( 'import_file_error', __('Zero size file downloaded', 'wf_order_import_export') );
938
- }
939
-
940
- unset( $response );
941
-
942
- return $upload;
943
- }
944
- private function handle_ftp()
945
- {
946
- $enable_ftp_ie = !empty( $_POST['enable_ftp_ie'] ) ? true : false;
947
- if($enable_ftp_ie == false)
948
- {
949
- $settings_in_db = get_option( 'wf_coupon_tracking_importer_ftp', null );
950
- $settings_in_db['enable_ftp_ie'] = false;
951
- update_option( 'wf_coupon_tracking_importer_ftp', $settings_in_db );
952
- return false;
953
- }
954
-
955
- $ftp_server = ! empty( $_POST['ftp_server'] ) ? $_POST['ftp_server'] : '';
956
- $ftp_server_path = ! empty( $_POST['ftp_server_path'] ) ? $_POST['ftp_server_path'] : '';
957
- $ftp_user = ! empty( $_POST['ftp_user'] ) ? $_POST['ftp_user'] : '';
958
- $ftp_password = ! empty( $_POST['ftp_password'] ) ? $_POST['ftp_password'] : '';
959
- $use_ftps = ! empty( $_POST['use_ftps'] ) ? true : false;
960
-
961
-
962
- $settings = array();
963
- $settings[ 'ftp_server' ] = $ftp_server;
964
- $settings[ 'ftp_user' ] = $ftp_user;
965
- $settings[ 'ftp_password' ] = $ftp_password;
966
- $settings[ 'use_ftps' ] = $use_ftps;
967
- $settings[ 'enable_ftp_ie' ] = $enable_ftp_ie;
968
- $settings[ 'ftp_server_path' ] = $ftp_server_path;
969
-
970
-
971
- $local_file = 'wp-content/plugins/order-import-export-for-woocommerce/temp-import.csv';
972
- $server_file = $ftp_server_path;
973
-
974
- update_option( 'wf_coupon_tracking_importer_ftp', $settings );
975
-
976
- $ftp_conn = $use_ftps ? ftp_ssl_connect($ftp_server) : ftp_connect($ftp_server);
977
- $error_message = "";
978
- $success = false;
979
- if($ftp_conn == false){
980
- $error_message = "There is connection problem\n";
981
- }
982
-
983
- if(empty($error_message)){
984
- if(ftp_login($ftp_conn, $ftp_user, $ftp_password) == false){
985
- $error_message = "Not able to login \n";
986
- }
987
- }
988
- if(empty($error_message)){
989
-
990
- if (ftp_get($ftp_conn, ABSPATH.$local_file, $server_file, FTP_BINARY)) {
991
- $error_message = "";
992
- $success = true;
993
- } else {
994
- $error_message = "There was a problem\n";
995
- }
996
- }
997
-
998
- ftp_close($ftp_conn);
999
- if($success){
1000
- $this->file_url = $local_file;
1001
- }else{
1002
- die($error_message);
1003
- }
1004
- return true;
1005
- }
1006
-
1007
- // Display import page title
1008
- public function header() {
1009
- echo '<div class="wrap"><div class="icon32" id="icon-woocommerce-importer"><br></div>';
1010
- echo '<h2>' . ( empty( $_GET['merge'] ) ? __( 'Import', 'wf_order_import_export' ) : __( 'Merge Coupons', 'wf_order_import_export' ) ) . '</h2>';
1011
- }
1012
-
1013
- // Close div.wrap
1014
- public function footer() {
1015
- echo '</div>';
1016
- }
1017
-
1018
- /**
1019
- * Display introductory text and file upload form
1020
- */
1021
- public function greet()
1022
- {
1023
- $action = 'admin.php?import=coupon_csv&amp;step=1&amp;merge=' . ( ! empty( $_GET['merge'] ) ? 1 : 0 );
1024
- $bytes = apply_filters( 'import_upload_size_limit', wp_max_upload_size() );
1025
- $size = size_format( $bytes );
1026
- $upload_dir = wp_upload_dir();
1027
- $ftp_settings = get_option( 'wf_coupon_tracking_importer_ftp');
1028
- include( 'views-coupon/html-wf-import-greeting.php' );
1029
- }
1030
-
1031
- /**
1032
- * Added to http_request_timeout filter to force timeout at 60 seconds during import
1033
- * @return int 60
1034
- */
1035
- public function bump_request_timeout( $val ) {
1036
- return 60;
1037
- }
1038
-
1039
- public function hf_coupon_log_data_change ($content = 'coupon-csv-import',$data='')
1040
- {
1041
- if (WC()->version < '2.7.0')
1042
- {
1043
- $this->log->add($content,$data);
1044
- }else
1045
- {
1046
- $context = array( 'source' => $content );
1047
- $this->log->log("debug", $data ,$context);
1048
- }
1049
- }
1050
-
1051
  }
1
+ <?php
2
+ /**
3
+ * WordPress Importer class for managing the import process of a CSV file
4
+ *
5
+ * @package WordPress
6
+ * @subpackage Importer
7
+ */
8
+ if ( ! class_exists( 'WP_Importer' ) )
9
+ return;
10
+
11
+ class WF_CpnImpExpCsv_Coupon_Import extends WP_Importer {
12
+
13
+ var $id;
14
+ var $file_url;
15
+ var $delimiter;
16
+ var $profile;
17
+ var $merge_empty_cells;
18
+
19
+ // mappings from old information to new
20
+ var $processed_terms = array();
21
+ var $processed_posts = array();
22
+ var $post_orphans = array();
23
+ var $attachments = array();
24
+ var $upsell_skus = array();
25
+ var $crosssell_skus = array();
26
+
27
+ // Results
28
+ var $import_results = array();
29
+
30
+ /**
31
+ * Constructor
32
+ */
33
+ public function __construct() {
34
+
35
+ if (WC()->version < '2.7.0') {
36
+ $this->log = new WC_Logger();
37
+ } else {
38
+ $this->log = wc_get_logger();
39
+ }
40
+ $this->import_page = 'coupon_csv';
41
+ $this->file_url_import_enabled = apply_filters( 'coupon_csv_coupon_file_url_import_enabled', true );
42
+ }
43
+
44
+ /**
45
+ * Registered callback function for the WordPress Importer
46
+ *
47
+ * Manages the three separate stages of the CSV import process
48
+ */
49
+ public function dispatch() {
50
+ global $woocommerce, $wpdb;
51
+
52
+ if ( ! empty( $_POST['delimiter'] ) ) {
53
+ $this->delimiter = stripslashes( trim( $_POST['delimiter'] ) );
54
+ }else if ( ! empty( $_GET['delimiter'] ) ) {
55
+ $this->delimiter = stripslashes( trim( $_GET['delimiter'] ) );
56
+ }
57
+
58
+ if ( ! $this->delimiter )
59
+ $this->delimiter = ',';
60
+
61
+ if ( ! empty( $_POST['profile'] ) ) {
62
+ $this->profile = stripslashes( trim( $_POST['profile'] ) );
63
+ }else if ( ! empty( $_GET['profile'] ) ) {
64
+ $this->profile = stripslashes( trim( $_GET['profile'] ) );
65
+ }
66
+ if ( ! $this->profile )
67
+ $this->profile = '';
68
+
69
+ if ( ! empty( $_POST['merge_empty_cells'] ) || ! empty( $_GET['merge_empty_cells'] ) ) {
70
+ $this->merge_empty_cells = 1;
71
+ } else{
72
+ $this->merge_empty_cells = 0;
73
+ }
74
+
75
+ $step = empty( $_GET['step'] ) ? 0 : (int) $_GET['step'];
76
+
77
+ switch ( $step ) {
78
+ case 0 :
79
+ $this->header();
80
+ $this->greet();
81
+ break;
82
+ case 1 :
83
+ $this->header();
84
+
85
+ check_admin_referer( 'import-upload' );
86
+
87
+ if(!empty($_GET['file_url']))
88
+ $this->file_url = esc_attr( $_GET['file_url'] );
89
+ if(!empty($_GET['file_id']))
90
+ $this->id = $_GET['file_id'] ;
91
+
92
+ if ( !empty($_GET['clearmapping']) || $this->handle_upload() )
93
+ $this->import_options();
94
+ else
95
+ //_e( 'Error with handle_upload!', 'wf_order_import_export' );
96
+ wp_redirect(wp_get_referer().'&wf_coupon_ie_msg=3');
97
+ exit;
98
+ break;
99
+ case 2 :
100
+ $this->header();
101
+
102
+ check_admin_referer( 'import-woocommerce' );
103
+
104
+ $this->id = (int) $_POST['import_id'];
105
+
106
+ if ( $this->file_url_import_enabled )
107
+ $this->file_url = esc_attr( $_POST['import_url'] );
108
+
109
+ if ( $this->id )
110
+ $file = get_attached_file( $this->id );
111
+ else if ( $this->file_url_import_enabled )
112
+ $file = ABSPATH . $this->file_url;
113
+
114
+ $file = str_replace( "\\", "/", $file );
115
+
116
+ if ( $file ) {
117
+ ?>
118
+ <table id="import-progress" class="widefat_importer widefat">
119
+ <thead>
120
+ <tr>
121
+ <th class="status">&nbsp;</th>
122
+ <th class="row"><?php _e( 'Row', 'wf_order_import_export' ); ?></th>
123
+ <th><?php _e( 'Coupon Id', 'wf_order_import_export' ); ?></th>
124
+ <th><?php _e( 'Coupon Name', 'wf_order_import_export' ); ?></th>
125
+ <th class="reason"><?php _e( 'Status Msg', 'wf_order_import_export' ); ?></th>
126
+ </tr>
127
+ </thead>
128
+ <tfoot>
129
+ <tr class="importer-loading">
130
+ <td colspan="5"></td>
131
+ </tr>
132
+ </tfoot>
133
+ <tbody></tbody>
134
+ </table>
135
+ <script type="text/javascript">
136
+ jQuery(document).ready(function($) {
137
+
138
+ if ( ! window.console ) { window.console = function(){}; }
139
+
140
+ var processed_terms = [];
141
+ var processed_posts = [];
142
+ var post_orphans = [];
143
+ var attachments = [];
144
+ var upsell_skus = [];
145
+ var crosssell_skus = [];
146
+ var i = 1;
147
+ var done_count = 0;
148
+
149
+ function import_rows( start_pos, end_pos ) {
150
+
151
+ var data = {
152
+ action: 'coupon_csv_import_request',
153
+ file: '<?php echo addslashes( $file ); ?>',
154
+ mapping: '<?php echo @json_encode( $_POST['map_from'] ); ?>',
155
+ profile: '<?php echo $this->profile; ?>',
156
+ eval_field: '<?php echo @stripslashes(json_encode(($_POST['eval_field']),JSON_HEX_APOS)) ?>',
157
+ delimiter: '<?php echo $this->delimiter; ?>',
158
+ merge_empty_cells: '<?php echo $this->merge_empty_cells; ?>',
159
+ start_pos: start_pos,
160
+ end_pos: end_pos,
161
+ };
162
+ data.eval_field = $.parseJSON(data.eval_field);
163
+ return $.ajax({
164
+ url: '<?php echo add_query_arg( array( 'import_page' => $this->import_page, 'step' => '3', 'merge' => ! empty( $_GET['merge'] ) ? '1' : '0' ), admin_url( 'admin-ajax.php' ) ); ?>',
165
+ data: data,
166
+ type: 'POST',
167
+ success: function( response ) {
168
+ if ( response ) {
169
+
170
+ try {
171
+ // Get the valid JSON only from the returned string
172
+ if ( response.indexOf("<!--WC_START-->") >= 0 )
173
+ response = response.split("<!--WC_START-->")[1]; // Strip off before after WC_START
174
+
175
+ if ( response.indexOf("<!--WC_END-->") >= 0 )
176
+ response = response.split("<!--WC_END-->")[0]; // Strip off anything after WC_END
177
+
178
+ // Parse
179
+ var results = $.parseJSON( response );
180
+
181
+ if ( results.error ) {
182
+
183
+ $('#import-progress tbody').append( '<tr id="row-' + i + '" class="error"><td class="status" colspan="5">' + results.error + '</td></tr>' );
184
+
185
+ i++;
186
+
187
+ } else if ( results.import_results && $( results.import_results ).size() > 0 ) {
188
+
189
+ $.each( results.processed_terms, function( index, value ) {
190
+ processed_terms.push( value );
191
+ });
192
+
193
+ $.each( results.processed_posts, function( index, value ) {
194
+ processed_posts.push( value );
195
+ });
196
+
197
+ $.each( results.post_orphans, function( index, value ) {
198
+ post_orphans.push( value );
199
+ });
200
+
201
+ $.each( results.attachments, function( index, value ) {
202
+ attachments.push( value );
203
+ });
204
+
205
+ upsell_skus = jQuery.extend( {}, upsell_skus, results.upsell_skus );
206
+ crosssell_skus = jQuery.extend( {}, crosssell_skus, results.crosssell_skus );
207
+
208
+ $( results.import_results ).each(function( index, row ) {
209
+ $('#import-progress tbody').append( '<tr id="row-' + i + '" class="' + row['status'] + '"><td><mark class="result" title="' + row['status'] + '">' + row['status'] + '</mark></td><td class="row">' + i + '</td><td>' + row['post_id'] + '</td><td>' + row['post_title'] + '</td><td class="reason">' + row['reason'] + '</td></tr>' );
210
+
211
+ i++;
212
+ });
213
+ }
214
+
215
+ } catch(err) {}
216
+
217
+ } else {
218
+ $('#import-progress tbody').append( '<tr class="error"><td class="status" colspan="5">' + '<?php _e( 'AJAX Error', 'wf_order_import_export' ); ?>' + '</td></tr>' );
219
+ }
220
+
221
+ var w = $(window);
222
+ var row = $( "#row-" + ( i - 1 ) );
223
+
224
+ if ( row.length ) {
225
+ w.scrollTop( row.offset().top - (w.height()/2) );
226
+ }
227
+
228
+ done_count++;
229
+
230
+ $('body').trigger( 'coupon_csv_import_request_complete' );
231
+ }
232
+ });
233
+ }
234
+
235
+ var rows = [];
236
+
237
+ <?php
238
+ $limit = apply_filters( 'coupon_csv_import_limit_per_request', 10 );
239
+ $enc = mb_detect_encoding( $file, 'UTF-8, ISO-8859-1', true );
240
+ if ( $enc )
241
+ setlocale( LC_ALL, 'en_US.' . $enc );
242
+ @ini_set( 'auto_detect_line_endings', true );
243
+
244
+ $count = 0;
245
+ $previous_position = 0;
246
+ $position = 0;
247
+ $import_count = 0;
248
+
249
+ // Get CSV positions
250
+ if ( ( $handle = fopen( $file, "r" ) ) !== FALSE ) {
251
+
252
+ while ( ( $postmeta = fgetcsv( $handle, 0, $this->delimiter , '"', '"' ) ) !== FALSE ) {
253
+ $count++;
254
+
255
+ if ( $count >= $limit ) {
256
+ $previous_position = $position;
257
+ $position = ftell( $handle );
258
+ $count = 0;
259
+ $import_count ++;
260
+
261
+ // Import rows between $previous_position $position
262
+ ?>rows.push( [ <?php echo $previous_position; ?>, <?php echo $position; ?> ] ); <?php
263
+ }
264
+ }
265
+
266
+ // Remainder
267
+ if ( $count > 0 ) {
268
+ ?>rows.push( [ <?php echo $position; ?>, '' ] ); <?php
269
+ $import_count ++;
270
+ }
271
+
272
+ fclose( $handle );
273
+ }
274
+ ?>
275
+
276
+ var data = rows.shift();
277
+ var regen_count = 0;
278
+ import_rows( data[0], data[1] );
279
+
280
+ $('body').on( 'coupon_csv_import_request_complete', function() {
281
+ if ( done_count == <?php echo $import_count; ?> ) {
282
+
283
+ if ( attachments.length ) {
284
+
285
+ $('#import-progress tbody').append( '<tr class="regenerating"><td colspan="5"><div class="progress"></div></td></tr>' );
286
+
287
+ index = 0;
288
+
289
+ $.each( attachments, function( i, value ) {
290
+ regenerate_thumbnail( value );
291
+ index ++;
292
+ if ( index == attachments.length ) {
293
+ import_done();
294
+ }
295
+ });
296
+
297
+ } else {
298
+ import_done();
299
+ }
300
+
301
+ } else {
302
+ // Call next request
303
+ data = rows.shift();
304
+ import_rows( data[0], data[1] );
305
+ }
306
+ } );
307
+
308
+ // Regenerate a specified image via AJAX
309
+ function regenerate_thumbnail( id ) {
310
+ $.ajax({
311
+ type: 'POST',
312
+ url: ajaxurl,
313
+ data: { action: "coupon_csv_import_regenerate_thumbnail", id: id },
314
+ success: function( response ) {
315
+ if ( response !== Object( response ) || ( typeof response.success === "undefined" && typeof response.error === "undefined" ) ) {
316
+ response = new Object;
317
+ response.success = false;
318
+ response.error = "<?php printf( esc_js( __( 'The resize request was abnormally terminated (ID %s). This is likely due to the image exceeding available memory or some other type of fatal error.', 'wf_order_import_export' ) ), '" + id + "' ); ?>";
319
+ }
320
+
321
+ regen_count ++;
322
+
323
+ $('#import-progress tbody .regenerating .progress').css( 'width', ( ( regen_count / attachments.length ) * 100 ) + '%' ).html( regen_count + ' / ' + attachments.length + ' <?php echo esc_js( __( 'thumbnails regenerated', 'wf_order_import_export' ) ); ?>' );
324
+
325
+ if ( ! response.success ) {
326
+ $('#import-progress tbody').append( '<tr><td colspan="5">' + response.error + '</td></tr>' );
327
+ }
328
+ },
329
+ error: function( response ) {
330
+ $('#import-progress tbody').append( '<tr><td colspan="5">' + response.error + '</td></tr>' );
331
+ }
332
+ });
333
+ }
334
+
335
+ function import_done() {
336
+ var data = {
337
+ action: 'coupon_csv_import_request',
338
+ file: '<?php echo $file; ?>',
339
+ processed_terms: processed_terms,
340
+ processed_posts: processed_posts,
341
+ post_orphans: post_orphans,
342
+ upsell_skus: upsell_skus,
343
+ crosssell_skus: crosssell_skus
344
+ };
345
+
346
+ $.ajax({
347
+ url: '<?php echo add_query_arg( array( 'import_page' => $this->import_page, 'step' => '4', 'merge' => ! empty( $_GET['merge'] ) ? 1 : 0 ), admin_url( 'admin-ajax.php' ) ); ?>',
348
+ data: data,
349
+ type: 'POST',
350
+ success: function( response ) {
351
+ //console.log( response );
352
+ $('#import-progress tbody').append( '<tr class="complete"><td colspan="5">' + response + '</td></tr>' );
353
+ $('.importer-loading').hide();
354
+ }
355
+ });
356
+ }
357
+ });
358
+ </script>
359
+ <?php
360
+ } else {
361
+ echo '<p class="error">' . __( 'Error finding uploaded file!', 'wf_order_import_export' ) . '</p>';
362
+ }
363
+ break;
364
+ case 3 :
365
+ // Check access - cannot use nonce here as it will expire after multiple requests
366
+ if ( ! current_user_can( 'manage_woocommerce' ) )
367
+ die();
368
+
369
+ add_filter( 'http_request_timeout', array( $this, 'bump_request_timeout' ) );
370
+
371
+ if ( function_exists( 'gc_enable' ) )
372
+ gc_enable();
373
+
374
+ @set_time_limit(0);
375
+ @ob_flush();
376
+ @flush();
377
+ $wpdb->hide_errors();
378
+
379
+ $file = stripslashes( $_POST['file'] );
380
+ $mapping = json_decode( stripslashes( $_POST['mapping'] ), true );
381
+ $profile = isset( $_POST['profile'] ) ? $_POST['profile']:'';
382
+ $eval_field = $_POST['eval_field'];
383
+ $start_pos = isset( $_POST['start_pos'] ) ? absint( $_POST['start_pos'] ) : 0;
384
+ $end_pos = isset( $_POST['end_pos'] ) ? absint( $_POST['end_pos'] ) : '';
385
+
386
+ if($profile!== '')
387
+ {
388
+ $profile_array = get_option('wf_cpn_csv_imp_exp_mapping');
389
+ $profile_array[$profile] = array($mapping,$eval_field);
390
+ update_option('wf_cpn_csv_imp_exp_mapping', $profile_array);
391
+ }
392
+
393
+ $position = $this->import_start( $file, $mapping, $start_pos, $end_pos, $eval_field );
394
+ $this->import();
395
+ $this->import_end();
396
+
397
+ $results = array();
398
+ $results['import_results'] = $this->import_results;
399
+ $results['processed_terms'] = $this->processed_terms;
400
+ $results['processed_posts'] = $this->processed_posts;
401
+ $results['post_orphans'] = $this->post_orphans;
402
+ $results['attachments'] = $this->attachments;
403
+ $results['upsell_skus'] = $this->upsell_skus;
404
+ $results['crosssell_skus'] = $this->crosssell_skus;
405
+
406
+ echo "<!--WC_START-->";
407
+ echo json_encode( $results );
408
+ echo "<!--WC_END-->";
409
+ exit;
410
+ break;
411
+ case 4 :
412
+ // Check access - cannot use nonce here as it will expire after multiple requests
413
+ if ( ! current_user_can( 'manage_woocommerce' ) )
414
+ die();
415
+
416
+ add_filter( 'http_request_timeout', array( $this, 'bump_request_timeout' ) );
417
+
418
+ if ( function_exists( 'gc_enable' ) )
419
+ gc_enable();
420
+
421
+ @set_time_limit(0);
422
+ @ob_flush();
423
+ @flush();
424
+ $wpdb->hide_errors();
425
+
426
+ $this->processed_terms = isset( $_POST['processed_terms'] ) ? $_POST['processed_terms'] : array();
427
+ $this->processed_posts = isset( $_POST['processed_posts']) ? $_POST['processed_posts'] : array();
428
+ $this->post_orphans = isset( $_POST['post_orphans']) ? $_POST['post_orphans'] : array();
429
+ $this->crosssell_skus = isset( $_POST['crosssell_skus']) ? array_filter( (array) $_POST['crosssell_skus'] ) : array();
430
+ $this->upsell_skus = isset( $_POST['upsell_skus']) ? array_filter( (array) $_POST['upsell_skus'] ) : array();
431
+
432
+ _e( 'Step 1...', 'wf_order_import_export' ) . ' ';
433
+
434
+ wp_defer_term_counting( true );
435
+ wp_defer_comment_counting( true );
436
+
437
+ _e( 'Step 2...', 'wf_order_import_export' ) . ' ';
438
+
439
+ echo 'Step 3...' . ' '; // Easter egg
440
+ _e( 'Finalizing...', 'wf_order_import_export' ) . ' ';
441
+
442
+
443
+ // SUCCESS
444
+ _e( 'Finished. Import complete.', 'wf_order_import_export' );
445
+
446
+ $this->import_end();
447
+ exit;
448
+ break;
449
+ }
450
+
451
+ $this->footer();
452
+ }
453
+
454
+ /**
455
+ * format_data_from_csv
456
+ */
457
+ public function format_data_from_csv( $data, $enc ) {
458
+ return ( $enc == 'UTF-8' ) ? $data : utf8_encode( $data );
459
+ }
460
+
461
+ /**
462
+ * Display pre-import options
463
+ */
464
+ public function import_options()
465
+ {
466
+ $j = 0;
467
+
468
+ if ( $this->id )
469
+ $file = get_attached_file( $this->id );
470
+ else if ( $this->file_url_import_enabled )
471
+ $file = ABSPATH . $this->file_url;
472
+ else
473
+ return;
474
+
475
+ // Set locale
476
+ $enc = mb_detect_encoding( $file, 'UTF-8, ISO-8859-1', true );
477
+ if ( $enc ) setlocale( LC_ALL, 'en_US.' . $enc );
478
+ @ini_set( 'auto_detect_line_endings', true );
479
+
480
+ // Get headers
481
+ if ( ( $handle = fopen( $file, "r" ) ) !== FALSE )
482
+ {
483
+ $row = $raw_headers = array();
484
+
485
+ $header = fgetcsv( $handle, 0, $this->delimiter , '"', '"');
486
+
487
+ while ( ( $postmeta = fgetcsv( $handle, 0, $this->delimiter , '"', '"') ) !== FALSE )
488
+ {
489
+ foreach ( $header as $key => $heading )
490
+ {
491
+ if ( ! $heading ) continue;
492
+ $s_heading = strtolower( $heading );
493
+ $row[$s_heading] = ( isset( $postmeta[$key] ) ) ? $this->format_data_from_csv( $postmeta[$key], $enc ) : '';
494
+ $raw_headers[ $s_heading ] = $heading;
495
+ }
496
+ break;
497
+ }
498
+ fclose( $handle );
499
+ }
500
+
501
+ $mapping_from_db = get_option( 'wf_cpn_csv_imp_exp_mapping');
502
+
503
+ if( $this->profile!=='' && !empty($_GET['clearmapping']))
504
+ {
505
+ unset($mapping_from_db[$this->profile]);
506
+ update_option('wf_cpn_csv_imp_exp_mapping', $mapping_from_db);
507
+ $this->profile = '';
508
+ }
509
+ if($this->profile !== '')
510
+ $mapping_from_db = $mapping_from_db[$this->profile];
511
+
512
+ $saved_mapping = null;
513
+ $saved_evaluation = null;
514
+ if($mapping_from_db && is_array($mapping_from_db) && count($mapping_from_db) == 2 && empty($_GET['clearmapping']))
515
+ {
516
+ $reset_action = 'admin.php?clearmapping=1&amp;profile='.$this->profile.'&amp;import=' . $this->import_page . '&amp;step=1&amp;merge=' . ( ! empty( $_GET['merge'] ) ? 1 : 0 ) . '&amp;file_url=' . $this->file_url . '&amp;delimiter=' . $this->delimiter . '&amp;merge_empty_cells=' . $this->merge_empty_cells . '&amp;file_id=' . $this->id . '';
517
+ $reset_action = esc_attr(wp_nonce_url($reset_action, 'import-upload'));
518
+ echo '<h3>' . __( 'Columns are pre-selected using the Mapping file: "<b style="color:gray">'.$this->profile.'</b>". <a href="'.$reset_action.'"> Delete</a> this mapping file.', 'wf_order_import_export' ) . '</h3>';
519
+ $saved_mapping = $mapping_from_db[0];
520
+ $saved_evaluation = $mapping_from_db[1];
521
+ }
522
+
523
+ $merge = (!empty($_GET['merge']) && $_GET['merge']) ? 1 : 0;
524
+ include( 'views-coupon/html-wf-import-options.php' );
525
+ }
526
+
527
+ /**
528
+ * The main controller for the actual import stage.
529
+ */
530
+ public function import()
531
+ {
532
+ global $woocommerce, $wpdb;
533
+
534
+ wp_suspend_cache_invalidation( true );
535
+
536
+ $this->hf_coupon_log_data_change( 'coupon-csv-import', '---' );
537
+ $this->hf_coupon_log_data_change( 'coupon-csv-import', __( 'Processing coupons.', 'wf_order_import_export' ) );
538
+ foreach ( $this->parsed_data as $key => &$item )
539
+ {
540
+ $coupon = $this->parser->parse_coupon( $item, $this->merge_empty_cells );
541
+ if ( ! is_wp_error( $coupon ) )
542
+ $this->process_coupon( $coupon );
543
+ else
544
+ $this->add_import_result( 'failed', $coupon->get_error_message(), 'Not parsed', json_encode( $item ) );
545
+
546
+ unset( $item, $coupon );
547
+ }
548
+ $this->hf_coupon_log_data_change( 'coupon-csv-import', __( 'Finished processing coupons.', 'wf_order_import_export' ) );
549
+ wp_suspend_cache_invalidation( false );
550
+ }
551
+
552
+ /**
553
+ * Parses the CSV file and prepares us for the task of processing parsed data
554
+ *
555
+ * @param string $file Path to the CSV file for importing
556
+ */
557
+ public function import_start( $file, $mapping, $start_pos, $end_pos, $eval_field ) {
558
+
559
+ $memory = size_format( (WC()->version < '2.7.0')?woocommerce_let_to_num( ini_get( 'memory_limit' ) ):wc_let_to_num( ini_get( 'memory_limit' ) ) );
560
+ $wp_memory = size_format( (WC()->version < '2.7.0')? woocommerce_let_to_num( WP_MEMORY_LIMIT ) : wc_let_to_num( WP_MEMORY_LIMIT ) );
561
+
562
+ $this->hf_coupon_log_data_change( 'coupon-csv-import', '---[ New Import ] PHP Memory: ' . $memory . ', WP Memory: ' . $wp_memory );
563
+ $this->hf_coupon_log_data_change( 'coupon-csv-import', __( 'Parsing coupons CSV.', 'wf_order_import_export' ) );
564
+
565
+ $this->parser = new WF_CSV_Parser_Coupon( 'shop_coupon' );
566
+
567
+ list( $this->parsed_data, $this->raw_headers, $position ) = $this->parser->parse_data( $file, $this->delimiter, $mapping, $start_pos, $end_pos, $eval_field );
568
+ $this->hf_coupon_log_data_change( 'coupon-csv-import', __( 'Finished parsing coupons CSV.', 'wf_order_import_export' ) );
569
+
570
+ unset( $import_data );
571
+
572
+ wp_defer_term_counting( true );
573
+ wp_defer_comment_counting( true );
574
+
575
+ return $position;
576
+ }
577
+
578
+ /**
579
+ * Performs post-import cleanup of files and the cache
580
+ */
581
+ public function import_end() {
582
+
583
+ do_action( 'import_end' );
584
+ }
585
+
586
+ /**
587
+ * Handles the CSV upload and initial parsing of the file to prepare for
588
+ * displaying author import options
589
+ *
590
+ * @return bool False if error uploading or invalid file, true otherwise
591
+ */
592
+ public function handle_upload() {
593
+ if($this->handle_ftp()){
594
+ return true;
595
+ }
596
+ if ( empty( $_POST['file_url'] ) ) {
597
+
598
+ $file = wp_import_handle_upload();
599
+
600
+ if ( isset( $file['error'] ) ) {
601
+ echo '<p><strong>' . __( 'Sorry, there has been an error.', 'wf_order_import_export' ) . '</strong><br />';
602
+ echo esc_html( $file['error'] ) . '</p>';
603
+ return false;
604
+ }
605
+
606
+ $this->id = (int) $file['id'];
607
+ return true;
608
+
609
+ } else {
610
+
611
+ if ( file_exists( ABSPATH . $_POST['file_url'] ) )
612
+ {
613
+ $this->file_url = esc_attr( $_POST['file_url'] );
614
+ return true;
615
+ } else {
616
+ echo '<p><strong>' . __( 'Sorry, there has been an error.', 'wf_order_import_export' ) . '</strong></p>';
617
+ return false;
618
+ }
619
+
620
+ }
621
+
622
+ return false;
623
+ }
624
+
625
+ public function coupon_exists( $title, $ID = '', $post_name = '' )
626
+ {
627
+ global $wpdb;
628
+
629
+ // Post Title Check
630
+ $post_title = stripslashes( sanitize_post_field( 'post_title', $title, 0, 'db' ) );
631
+
632
+ $query = "SELECT ID FROM $wpdb->posts WHERE post_type = 'shop_coupon' AND post_status IN ( 'publish', 'private', 'draft', 'pending', 'future' )";
633
+ $args = array();
634
+
635
+ if ( ! empty ( $post_name ) )
636
+ {
637
+ $query .= ' AND post_name = %s';
638
+ $args[] = $post_name;
639
+ }
640
+
641
+ if ( ! empty ( $args ) )
642
+ {
643
+ $posts_that_exist = $wpdb->get_col( $wpdb->prepare( $query, $args ) );
644
+ if ( $posts_that_exist )
645
+ {
646
+ foreach( $posts_that_exist as $post_exists )
647
+ {
648
+ if ( $ID == $post_exists )
649
+ {
650
+ return true;
651
+ }
652
+ }
653
+ }
654
+ }
655
+ return false;
656
+ }
657
+
658
+ /**
659
+ * Create new posts based on import information
660
+ */
661
+ public function process_coupon( $post )
662
+ {
663
+
664
+ $processing_coupon_id = absint( $post['post_id'] );
665
+ $processing_coupon = get_post( $processing_coupon_id );
666
+ $processing_coupon_title = $processing_coupon ? $processing_coupon->post_title : '';
667
+ $processing_coupon_sku = $processing_coupon ? $processing_coupon->sku : '';
668
+ $merging = ! empty( $post['merging'] );
669
+
670
+ if ( ! empty( $post['post_title'] ) ) {
671
+ $processing_coupon_title = $post['post_title'];
672
+ }
673
+ $post['post_type'] = 'shop_coupon';
674
+
675
+
676
+ if ( ! empty( $processing_coupon_id ) && isset( $this->processed_posts[ $processing_coupon_id ] ) )
677
+ {
678
+ $this->add_import_result( 'skipped', __( 'Coupon already processed', 'wf_order_import_export' ), $processing_coupon_id, $processing_coupon_title );
679
+ $this->hf_coupon_log_data_change( 'coupon-csv-import', __('> Coupon ID already processed. Skipping.', 'wf_order_import_export'), true );
680
+ unset( $post );
681
+ return;
682
+ }
683
+
684
+ if ( ! empty ( $post['post_status'] ) && $post['post_status'] == 'auto-draft' )
685
+ {
686
+ $this->add_import_result( 'skipped', __( 'Skipping auto-draft', 'wf_order_import_export' ), $processing_coupon_id, $processing_coupon_title);
687
+ $this->hf_coupon_log_data_change( 'coupon-csv-import', __('> Skipping auto-draft.', 'wf_order_import_export'), true );
688
+ unset( $post );
689
+ return;
690
+ }
691
+ if ( ! $merging )
692
+ {
693
+ if ( $this->coupon_exists( $processing_coupon_title, $processing_coupon_id, $post['post_name'] ) )
694
+ {
695
+ if(!$processing_coupon_id)
696
+ {
697
+ $usr_msg = 'Coupon with same title already exists.';
698
+ }else{
699
+ $usr_msg = 'Coupon already exists.';
700
+ }
701
+ $this->add_import_result( 'skipped', __( $usr_msg, 'wf_order_import_export' ), $processing_coupon_id, $processing_coupon_title );
702
+ $this->hf_coupon_log_data_change( 'coupon-csv-import', sprintf( __('> &#8220;%s&#8221;'.$usr_msg, 'wf_order_import_export'), esc_html($processing_coupon_title) ), true );
703
+ unset( $post );
704
+ return;
705
+ }
706
+
707
+ if ( $processing_coupon_id && is_string( get_post_status( $processing_coupon_id ) ) )
708
+ {
709
+ $this->add_import_result( 'skipped', __( 'Importing coupon ID conflicts with an existing coupon ID', 'wf_order_import_export' ), $processing_coupon_id, get_the_title( $processing_coupon_id ) );
710
+ $this->hf_coupon_log_data_change( 'coupon-csv-import', sprintf( __('> &#8220;%s&#8221; ID already exists.', 'wf_order_import_export'), esc_html( $processing_coupon_id ) ), true );
711
+ unset( $post );
712
+ return;
713
+ }
714
+ }
715
+ $is_post_exist_in_db = get_post_type( $processing_coupon_id );
716
+
717
+ if ( $merging && $processing_coupon_id && !empty($is_post_exist_in_db) && (get_post_type( $processing_coupon_id ) !== $post['post_type'] ))
718
+ {
719
+ $this->add_import_result( 'skipped', __( 'Post is not a coupon', 'wf_order_import_export' ), $processing_coupon_id, $processing_coupon_title );
720
+ $this->hf_coupon_log_data_change( 'coupon-csv-import', sprintf( __('> &#8220;%s&#8221; is not a coupon.', 'wf_order_import_export'), esc_html($processing_coupon_id) ), true );
721
+
722
+ unset( $post );
723
+ return;
724
+ }
725
+
726
+ if ( $merging && !empty($is_post_exist_in_db) )
727
+ {
728
+ $post_id = $processing_coupon_id;
729
+
730
+ $this->hf_coupon_log_data_change( 'coupon-csv-import', sprintf( __('> Merging coupon ID %s.', 'wf_order_import_export'), $post_id ), true );
731
+
732
+ $postdata = array(
733
+ 'ID' => $post_id
734
+ );
735
+
736
+ if ( $this->merge_empty_cells )
737
+ {
738
+ if ( isset( $post['post_content'] ) ) {
739
+ $postdata['post_content'] = $post['post_content'];
740
+ }
741
+ if ( isset( $post['post_excerpt'] ) ) {
742
+ $postdata['post_excerpt'] = $post['post_excerpt'];
743
+ }
744
+
745
+ } else {
746
+ if ( ! empty( $post['post_content'] ) ) {
747
+ $postdata['post_content'] = $post['post_content'];
748
+ }
749
+ if ( ! empty( $post['post_excerpt'] ) ) {
750
+ $postdata['post_excerpt'] = $post['post_excerpt'];
751
+ }
752
+
753
+ }
754
+
755
+ if ( ! empty( $post['post_title'] ) ) {
756
+ $postdata['post_title'] = $post['post_title'];
757
+ }
758
+
759
+ if ( ! empty( $post['post_author'] ) ) {
760
+ $postdata['post_author'] = absint( $post['post_author'] );
761
+ }
762
+ if ( ! empty( $post['post_date'] ) ) {
763
+ $postdata['post_date'] = date("Y-m-d H:i:s", strtotime( $post['post_date'] ) );
764
+ }
765
+ if ( ! empty( $post['post_date_gmt'] ) ) {
766
+ $postdata['post_date_gmt'] = date("Y-m-d H:i:s", strtotime( $post['post_date_gmt'] ) );
767
+ }
768
+ if ( ! empty( $post['post_name'] ) ) {
769
+ $postdata['post_name'] = $post['post_name'];
770
+ }
771
+ if ( ! empty( $post['post_status'] ) ) {
772
+ $postdata['post_status'] = $post['post_status'];
773
+ }
774
+
775
+ if ( sizeof( $postdata ) > 1 )
776
+ {
777
+ $result = wp_update_post( $postdata );
778
+
779
+ if ( ! $result )
780
+ {
781
+ $this->add_import_result( 'failed', __( 'Failed to update coupon', 'wf_order_import_export' ), $post_id, $processing_coupon_title );
782
+ $this->hf_coupon_log_data_change( 'coupon-csv-import', sprintf( __('> Failed to update coupon %s', 'wf_order_import_export'), $post_id ), true );
783
+ unset( $post );
784
+ return;
785
+ } else {
786
+ $this->hf_coupon_log_data_change( 'coupon-csv-import', __( '> Merged post data: ', 'wf_order_import_export' ) . print_r( $postdata, true ) );
787
+ }
788
+ }
789
+
790
+ } else
791
+ {
792
+ $merging = FALSE;
793
+
794
+ $this->hf_coupon_log_data_change( 'coupon-csv-import', sprintf( __('> Inserting %s', 'wf_order_import_export'), esc_html( $processing_coupon_title ) ), true );
795
+ $postdata = array(
796
+ 'post_author' => $post['post_author'] ? absint( $post['post_author'] ) : get_current_user_id(),
797
+ 'post_date' => ( $post['post_date'] ) ? date( 'Y-m-d H:i:s', strtotime( $post['post_date'] )) : '',
798
+ 'post_date_gmt' => ( $post['post_date_gmt'] ) ? date( 'Y-m-d H:i:s', strtotime( $post['post_date_gmt'] )) : '',
799
+ 'post_content' => $post['post_excerpt'],
800
+ 'post_excerpt' => $post['post_excerpt'],
801
+ 'post_title' => $post['post_title'],
802
+ 'post_name' => ( $post['post_name'] ) ? $post['post_name'] : sanitize_title( $post['post_title'] ),
803
+ 'post_status' => ( $post['post_status'] ) ? $post['post_status'] : 'publish',
804
+ 'post_type' => 'shop_coupon',
805
+ );
806
+
807
+ $post_id = wp_insert_post( $postdata, true );
808
+
809
+ if ( is_wp_error( $post_id ) )
810
+ {
811
+
812
+ $this->add_import_result( 'failed', __( 'Failed to import coupon', 'wf_order_import_export' ), $processing_coupon_id, $processing_coupon_title );
813
+ $this->hf_coupon_log_data_change( 'coupon-csv-import', sprintf( __( 'Failed to import coupon &#8220;%s&#8221;', 'wf_order_import_export' ), esc_html($processing_coupon_title) ) );
814
+ unset( $post );
815
+ return;
816
+
817
+ } else {
818
+
819
+ $this->hf_coupon_log_data_change( 'coupon-csv-import', sprintf( __('> Inserted - coupon ID is %s.', 'wf_order_import_export'), $post_id ) );
820
+
821
+ }
822
+ }
823
+
824
+ unset( $postdata );
825
+
826
+ if ( empty( $processing_coupon_id ) ) {
827
+ $processing_coupon_id = (int) $post_id;
828
+ }
829
+
830
+ $this->processed_posts[ intval( $processing_coupon_id ) ] = (int) $post_id;
831
+ if ( ! empty( $post['postmeta'] ) && is_array( $post['postmeta'] ) )
832
+ {
833
+ foreach ( $post['postmeta'] as $meta )
834
+ {
835
+ $key = apply_filters( 'import_post_meta_key', $meta['key'] );
836
+
837
+ if ( $key )
838
+ {
839
+ if($key == 'product_categories' || $key == 'exclude_product_categories')
840
+ {
841
+ update_post_meta( $post_id, $key, explode(",",$meta['value'] ) );
842
+ }
843
+ else
844
+ {
845
+ if($key == 'customer_email'){
846
+ $data= explode(',', $meta['value']);
847
+ update_post_meta( $post_id, $key,( $data ) );
848
+ }else{
849
+ update_post_meta( $post_id, $key, maybe_unserialize( $meta['value'] ) );
850
+ }
851
+ }
852
+
853
+ }
854
+ }
855
+ unset( $post['postmeta'] );
856
+ }
857
+ if ( $merging )
858
+ {
859
+ $this->add_import_result( 'merged', 'Coupon Merge successful', $post_id, $processing_coupon_title );
860
+ $this->hf_coupon_log_data_change( 'coupon-csv-import', sprintf( __('> Finished merging post ID %s.', 'wf_order_import_export'), $post_id ) );
861
+ } else {
862
+ $this->add_import_result( 'imported', 'Coupon Import successful', $post_id, $processing_coupon_title );
863
+ $this->hf_coupon_log_data_change( 'coupon-csv-import', sprintf( __('> Finished importing post ID %s.', 'wf_order_import_export'), $post_id ) );
864
+ }
865
+ unset( $post );
866
+ }
867
+
868
+ /**
869
+ * Log a row's import status
870
+ */
871
+ protected function add_import_result( $status, $reason, $post_id = '', $post_title = '' ) {
872
+ $this->import_results[] = array(
873
+ 'post_title' => $post_title,
874
+ 'post_id' => $post_id,
875
+ 'status' => $status,
876
+ 'reason' => $reason
877
+ );
878
+ }
879
+ /**
880
+ * Attempt to download a remote file attachment
881
+ */
882
+ public function fetch_remote_file( $url, $post )
883
+ {
884
+
885
+ // extract the file name and extension from the url
886
+ $file_name = basename( current( explode( '?', $url ) ) );
887
+ $wp_filetype = wp_check_filetype( $file_name, null );
888
+ $parsed_url = @parse_url( $url );
889
+
890
+ // Check parsed URL
891
+ if ( ! $parsed_url || ! is_array( $parsed_url ) )
892
+ return new WP_Error( 'import_file_error', 'Invalid URL' );
893
+
894
+ // Ensure url is valid
895
+ $url = str_replace( " ", '%20', $url );
896
+
897
+ // Get the file
898
+ $response = wp_remote_get( $url, array(
899
+ 'timeout' => 10
900
+ ) );
901
+
902
+ if ( is_wp_error( $response ) || wp_remote_retrieve_response_code( $response ) !== 200 )
903
+ return new WP_Error( 'import_file_error', 'Error getting remote image' );
904
+
905
+ // Ensure we have a file name and type
906
+ if ( ! $wp_filetype['type'] ) {
907
+
908
+ $headers = wp_remote_retrieve_headers( $response );
909
+
910
+ if ( isset( $headers['content-disposition'] ) && strstr( $headers['content-disposition'], 'filename=' ) ) {
911
+
912
+ $disposition = end( explode( 'filename=', $headers['content-disposition'] ) );
913
+ $disposition = sanitize_file_name( $disposition );
914
+ $file_name = $disposition;
915
+
916
+ } elseif ( isset( $headers['content-type'] ) && strstr( $headers['content-type'], 'image/' ) ) {
917
+
918
+ $file_name = 'image.' . str_replace( 'image/', '', $headers['content-type'] );
919
+
920
+ }
921
+
922
+ unset( $headers );
923
+ }
924
+
925
+ // Upload the file
926
+ $upload = wp_upload_bits( $file_name, '', wp_remote_retrieve_body( $response ) );
927
+
928
+ if ( $upload['error'] )
929
+ return new WP_Error( 'upload_dir_error', $upload['error'] );
930
+
931
+ // Get filesize
932
+ $filesize = filesize( $upload['file'] );
933
+
934
+ if ( 0 == $filesize ) {
935
+ @unlink( $upload['file'] );
936
+ unset( $upload );
937
+ return new WP_Error( 'import_file_error', __('Zero size file downloaded', 'wf_order_import_export') );
938
+ }
939
+
940
+ unset( $response );
941
+
942
+ return $upload;
943
+ }
944
+ private function handle_ftp()
945
+ {
946
+ $enable_ftp_ie = !empty( $_POST['enable_ftp_ie'] ) ? true : false;
947
+ if($enable_ftp_ie == false)
948
+ {
949
+ $settings_in_db = get_option( 'wf_coupon_tracking_importer_ftp', null );
950
+ $settings_in_db['enable_ftp_ie'] = false;
951
+ update_option( 'wf_coupon_tracking_importer_ftp', $settings_in_db );
952
+ return false;
953
+ }
954
+
955
+ $ftp_server = ! empty( $_POST['ftp_server'] ) ? $_POST['ftp_server'] : '';
956
+ $ftp_server_path = ! empty( $_POST['ftp_server_path'] ) ? $_POST['ftp_server_path'] : '';
957
+ $ftp_user = ! empty( $_POST['ftp_user'] ) ? $_POST['ftp_user'] : '';
958
+ $ftp_password = ! empty( $_POST['ftp_password'] ) ? $_POST['ftp_password'] : '';
959
+ $use_ftps = ! empty( $_POST['use_ftps'] ) ? true : false;
960
+
961
+
962
+ $settings = array();
963
+ $settings[ 'ftp_server' ] = $ftp_server;
964
+ $settings[ 'ftp_user' ] = $ftp_user;
965
+ $settings[ 'ftp_password' ] = $ftp_password;
966
+ $settings[ 'use_ftps' ] = $use_ftps;
967
+ $settings[ 'enable_ftp_ie' ] = $enable_ftp_ie;
968
+ $settings[ 'ftp_server_path' ] = $ftp_server_path;
969
+
970
+
971
+ $local_file = 'wp-content/plugins/order-import-export-for-woocommerce/temp-import.csv';
972
+ $server_file = $ftp_server_path;
973
+
974
+ update_option( 'wf_coupon_tracking_importer_ftp', $settings );
975
+
976
+ $ftp_conn = $use_ftps ? ftp_ssl_connect($ftp_server) : ftp_connect($ftp_server);
977
+ $error_message = "";
978
+ $success = false;
979
+ if($ftp_conn == false){
980
+ $error_message = "There is connection problem\n";
981
+ }
982
+
983
+ if(empty($error_message)){
984
+ if(ftp_login($ftp_conn, $ftp_user, $ftp_password) == false){
985
+ $error_message = "Not able to login \n";
986
+ }
987
+ }
988
+ if(empty($error_message)){
989
+
990
+ if (ftp_get($ftp_conn, ABSPATH.$local_file, $server_file, FTP_BINARY)) {
991
+ $error_message = "";
992
+ $success = true;
993
+ } else {
994
+ $error_message = "There was a problem\n";
995
+ }
996
+ }
997
+
998
+ ftp_close($ftp_conn);
999
+ if($success){
1000
+ $this->file_url = $local_file;
1001
+ }else{
1002
+ die($error_message);
1003
+ }
1004
+ return true;
1005
+ }
1006
+
1007
+ // Display import page title
1008
+ public function header() {
1009
+ echo '<div class="wrap"><div class="icon32" id="icon-woocommerce-importer"><br></div>';
1010
+ echo '<h2>' . ( empty( $_GET['merge'] ) ? __( 'Import', 'wf_order_import_export' ) : __( 'Merge Coupons', 'wf_order_import_export' ) ) . '</h2>';
1011
+ }
1012
+
1013
+ // Close div.wrap
1014
+ public function footer() {
1015
+ echo '</div>';
1016
+ }
1017
+
1018
+ /**
1019
+ * Display introductory text and file upload form
1020
+ */
1021
+ public function greet()
1022
+ {
1023
+ $action = 'admin.php?import=coupon_csv&amp;step=1&amp;merge=' . ( ! empty( $_GET['merge'] ) ? 1 : 0 );
1024
+ $bytes = apply_filters( 'import_upload_size_limit', wp_max_upload_size() );
1025
+ $size = size_format( $bytes );
1026
+ $upload_dir = wp_upload_dir();
1027
+ $ftp_settings = get_option( 'wf_coupon_tracking_importer_ftp');
1028
+ include( 'views-coupon/html-wf-import-greeting.php' );
1029
+ }
1030
+
1031
+ /**
1032
+ * Added to http_request_timeout filter to force timeout at 60 seconds during import
1033
+ * @return int 60
1034
+ */
1035
+ public function bump_request_timeout( $val ) {
1036
+ return 60;
1037
+ }
1038
+
1039
+ public function hf_coupon_log_data_change ($content = 'coupon-csv-import',$data='')
1040
+ {
1041
+ if (WC()->version < '2.7.0')
1042
+ {
1043
+ $this->log->add($content,$data);
1044
+ }else
1045
+ {
1046
+ $context = array( 'source' => $content );
1047
+ $this->log->log("debug", $data ,$context);
1048
+ }
1049
+ }
1050
+
1051
  }
includes/importer/class-wf-cpnimpexpcsv-importer.php CHANGED
@@ -1,41 +1,41 @@
1
- <?php
2
- if ( ! defined( 'ABSPATH' ) ) {
3
- exit;
4
- }
5
-
6
- class WF_CpnImpExpCsv_Importer {
7
-
8
- /**
9
- * Coupon Exporter Tool
10
- */
11
- public static function load_wp_importer() {
12
- // Load Importer API
13
- require_once ABSPATH . 'wp-admin/includes/import.php';
14
-
15
- if ( ! class_exists( 'WP_Importer' ) ) {
16
- $class_wp_importer = ABSPATH . 'wp-admin/includes/class-wp-importer.php';
17
- if ( file_exists( $class_wp_importer ) ) {
18
- require $class_wp_importer;
19
- }
20
- }
21
- }
22
-
23
- /**
24
- * Coupon Importer Tool
25
- */
26
- public static function coupon_importer() {
27
- if ( ! defined( 'WP_LOAD_IMPORTERS' ) ) {
28
- return;
29
- }
30
-
31
- self::load_wp_importer();
32
-
33
- // includes
34
- require_once 'class-wf-cpnimpexpcsv-coupon-import.php';
35
- require_once 'class-wf-csv-parser-coupon.php';
36
-
37
- // Dispatch
38
- $GLOBALS['WF_CSV_Coupon_Import'] = new WF_CpnImpExpCsv_Coupon_Import();
39
- $GLOBALS['WF_CSV_Coupon_Import'] ->dispatch();
40
- }
41
  }
1
+ <?php
2
+ if ( ! defined( 'ABSPATH' ) ) {
3
+ exit;
4
+ }
5
+
6
+ class WF_CpnImpExpCsv_Importer {
7
+
8
+ /**
9
+ * Coupon Exporter Tool
10
+ */
11
+ public static function load_wp_importer() {
12
+ // Load Importer API
13
+ require_once ABSPATH . 'wp-admin/includes/import.php';
14
+
15
+ if ( ! class_exists( 'WP_Importer' ) ) {
16
+ $class_wp_importer = ABSPATH . 'wp-admin/includes/class-wp-importer.php';
17
+ if ( file_exists( $class_wp_importer ) ) {
18
+ require $class_wp_importer;
19
+ }
20
+ }
21
+ }
22
+
23
+ /**
24
+ * Coupon Importer Tool
25
+ */
26
+ public static function coupon_importer() {
27
+ if ( ! defined( 'WP_LOAD_IMPORTERS' ) ) {
28
+ return;
29
+ }
30
+
31
+ self::load_wp_importer();
32
+
33
+ // includes
34
+ require_once 'class-wf-cpnimpexpcsv-coupon-import.php';
35
+ require_once 'class-wf-csv-parser-coupon.php';
36
+
37
+ // Dispatch
38
+ $GLOBALS['WF_CSV_Coupon_Import'] = new WF_CpnImpExpCsv_Coupon_Import();
39
+ $GLOBALS['WF_CSV_Coupon_Import'] ->dispatch();
40
+ }
41
  }
includes/importer/class-wf-csv-parser-coupon.php CHANGED
@@ -1,224 +1,224 @@
1
- <?php
2
- /**
3
- * WooCommerce CSV Importer class for managing parsing of CSV files.
4
- */
5
- class WF_CSV_Parser_Coupon {
6
-
7
- var $row;
8
- var $post_type;
9
- var $reserved_fields; // Fields we map/handle (not custom fields)
10
- var $post_defaults; // Default post data
11
- var $postmeta_defaults; // default post meta
12
- var $postmeta_allowed; // post meta validation
13
- var $allowed_coupon_types; // Allowed product types
14
-
15
- /**
16
- * Constructor
17
- */
18
- public function __construct( $post_type = 'shop_coupon' )
19
- {
20
- $this->post_type = $post_type;
21
- $this->reserved_fields = include( 'data-coupon/data-wf-reserved-fields.php' );
22
- $this->post_defaults = include( 'data-coupon/data-wf-post-defaults.php' );
23
- $this->postmeta_defaults = include( 'data-coupon/data-wf-postmeta-defaults.php' );
24
- $this->postmeta_allowed = include( 'data-coupon/data-wf-postmeta-allowed.php' );
25
- $this->allowed_coupon_types = array(
26
- 'fixed_cart' ,
27
- 'percent',
28
- 'fixed_product',
29
- 'percent_product'
30
- );
31
-
32
- }
33
-
34
- /**
35
- * Format data from the csv file
36
- * @param string $data
37
- * @param string $enc
38
- * @return string
39
- */
40
- public function format_data_from_csv( $data, $enc ) {
41
- return ( $enc == 'UTF-8' ) ? $data : utf8_encode( $data );
42
- }
43
-
44
- /**
45
- * Parse the data
46
- * @param string $file [description]
47
- * @param string $delimiter [description]
48
- * @param array $mapping [description]
49
- * @param integer $start_pos [description]
50
- * @param integer $end_pos [description]
51
- * @return array
52
- */
53
- public function parse_data( $file, $delimiter, $mapping, $start_pos = 0, $end_pos = null, $eval_field ) {
54
- // Set locale
55
- $enc = mb_detect_encoding( $file, 'UTF-8, ISO-8859-1', true );
56
- if ( $enc )
57
- setlocale( LC_ALL, 'en_US.' . $enc );
58
- @ini_set( 'auto_detect_line_endings', true );
59
-
60
- $parsed_data = array();
61
- $raw_headers = array();
62
-
63
- // Put all CSV data into an associative array
64
- if ( ( $handle = fopen( $file, "r" ) ) !== FALSE ) {
65
-
66
- $header = fgetcsv( $handle, 0, $delimiter , '"', '"' );
67
- if ( $start_pos != 0 )
68
- fseek( $handle, $start_pos );
69
-
70
- while ( ( $postmeta = fgetcsv( $handle, 0, $delimiter , '"', '"' ) ) !== FALSE ) {
71
- $row = array();
72
-
73
- foreach ( $header as $key => $heading ) {
74
- $s_heading = $heading;
75
-
76
-
77
-
78
- if ( $s_heading == '' )
79
- continue;
80
-
81
- // Add the heading to the parsed data
82
- $row[$s_heading] = ( isset( $postmeta[$key] ) ) ? $this->format_data_from_csv( $postmeta[$key], $enc ) : '';
83
-
84
- // Raw Headers stores the actual column name in the CSV
85
- $raw_headers[ $s_heading ] = $heading;
86
- }
87
- $parsed_data[] = $row;
88
-
89
- unset( $postmeta, $row );
90
-
91
- $position = ftell( $handle );
92
-
93
- if ( $end_pos && $position >= $end_pos )
94
- break;
95
- }
96
- fclose( $handle );
97
- }
98
- return array( $parsed_data, $raw_headers, $position );
99
- }
100
-
101
-
102
- /**
103
- * Parse product
104
- * @param array $item
105
- * @param integer $merge_empty_cells
106
- * @return array
107
- */
108
- public function parse_coupon( $item, $merge_empty_cells = 0 ) {
109
- global $WF_CSV_Coupon_Import, $wpdb;
110
- $this->row++;
111
-
112
- $terms_array = $postmeta = $product = array();
113
- $attributes = $default_attributes = $gpf_data = null;
114
- // Merging
115
- $merging = ( ! empty( $_GET['merge'] ) && $_GET['merge'] ) ? true : false;
116
- $this->post_defaults['post_type'] = 'shop_coupon';
117
-
118
- $post_id = ( ! empty( $item['id'] ) ) ? $item['id'] : 0;
119
- $post_id = ( ! empty( $item['post_id'] ) ) ? $item['post_id'] : $post_id;
120
- if ( $merging )
121
- {
122
- $product['merging'] = true;
123
- $WF_CSV_Coupon_Import->hf_coupon_log_data_change( 'coupon-csv-import', sprintf( __('> Row %s - preparing for merge.', 'wf_order_import_export'), $this->row ) );
124
- if ( ! $post_id )
125
- {
126
- $WF_CSV_Coupon_Import->hf_coupon_log_data_change( 'coupon-csv-import', __( '> > Cannot merge without id or sku. Importing instead.', 'wf_order_import_export') );
127
-
128
- $merging = false;
129
- } else
130
- {
131
- if ( ! $post_id )
132
- {
133
- $post_db_type = $this->post_defaults['post_type'];
134
- $post_pass_type = '"'.$post_db_type.'"';
135
- $db_query = $wpdb->prepare("
136
- SELECT $wpdb->posts.ID
137
- FROM $wpdb->posts
138
- LEFT JOIN $wpdb->postmeta ON ($wpdb->posts.ID = $wpdb->postmeta.post_id)
139
- WHERE $wpdb->posts.post_type = $post_pass_type
140
- AND $wpdb->posts.post_status IN ( 'publish', 'private', 'draft', 'pending', 'future' )
141
- AND $wpdb->posts.ID = '%d'
142
- ", $item['ID']);
143
- $found_product_id = $wpdb->get_var($db_query);
144
- if ( ! $found_product_id )
145
- {
146
- $WF_CSV_Coupon_Import->hf_coupon_log_data_change( 'coupon-csv-import', sprintf(__( '> > Skipped. Cannot find coupon with sku %s. Importing instead.', 'wf_order_import_export'), $item['sku']) );
147
- $merging = false;
148
-
149
- } else
150
- {
151
-
152
- $post_id = $found_product_id;
153
- $WF_CSV_Coupon_Import->hf_coupon_log_data_change( 'coupon-csv-import', sprintf(__( '> > Found coupon with ID %s.', 'wf_order_import_export'), $post_id) );
154
-
155
- }
156
- }
157
- $product['merging'] = true;
158
- }
159
- }
160
-
161
- if ( ! $merging )
162
- {
163
-
164
- $product['merging'] = false;
165
- $WF_CSV_Coupon_Import->hf_coupon_log_data_change( 'coupon-csv-import', sprintf( __('> Row %s - preparing for import.', 'wf_order_import_export'), $this->row ) );
166
- if ( isset($item['post_parent']) && $item['post_parent']=== '' && $item['post_title']=== '') {
167
- $WF_CSV_Coupon_Import->hf_coupon_log_data_change( 'coupon-csv-import', __( '> > Skipped. No post_title set for new coupon.', 'wf_order_import_export') );
168
- return new WP_Error( 'parse-error', __( 'No post_title set for new coupon.', 'wf_order_import_export' ) );
169
- }
170
- if ( isset($item['post_parent']) && $item['post_parent']!== '' && $item['post_parent']!== null && $item['parent_sku'] === '' )
171
- {
172
- $WF_CSV_Coupon_Import->hf_coupon_log_data_change( 'coupon-csv-import', __( '> > Skipped. No parent set for new variation product.', 'wf_order_import_export') );
173
- return new WP_Error( 'parse-error', __( 'No parent set for new variation product.', 'wf_order_import_export' ) );
174
- }
175
- }
176
-
177
- $product['post_id'] = $post_id;
178
- foreach ( $this->post_defaults as $column => $default )
179
- {
180
- if ( isset( $item[ $column ] ) ) $product[ $column ] = $item[ $column ];
181
- }
182
-
183
- // Get custom fields
184
- foreach ( $this->postmeta_defaults as $column => $default )
185
- {
186
- if ( isset( $item[$column] ) )
187
- $postmeta[$column] = (string) $item[$column];
188
- elseif ( isset( $item[$column] ) )
189
- $postmeta[$column] = (string) $item[$column];
190
-
191
- // Check custom fields are valid
192
- if ( isset( $postmeta[$column] ) && isset( $this->postmeta_allowed[$column] ) && ! in_array( $postmeta[$column], $this->postmeta_allowed[$column] ) )
193
- {
194
- $postmeta[$column] = $this->postmeta_defaults[$column];
195
- }
196
- }
197
-
198
- if ( ! $merging )
199
- {
200
- // Merge post meta with defaults
201
- $product = wp_parse_args( $product, $this->post_defaults );
202
- $postmeta = wp_parse_args( $postmeta, $this->postmeta_defaults );
203
- }
204
- if ( ! empty( $product['post_status'] ) )
205
- {
206
- if ( ! in_array( $product['post_status'], array( 'publish', 'private', 'draft', 'pending', 'future', 'inherit', 'trash' ) ) ) {
207
- $product['post_status'] = 'publish';
208
- }
209
-
210
- if ( ! in_array( $product['post_status'], array( 'private', 'publish' ) ) ) {
211
- $product['post_status'] = 'publish';
212
- }
213
-
214
- }
215
- foreach ( $postmeta as $key => $value ) {
216
- $product['postmeta'][] = array( 'key' => esc_attr($key), 'value' => $value );
217
- }
218
-
219
- $product['post_title'] = ( ! empty( $item['post_title'] ) ) ? $item['post_title'] : '';
220
- unset( $item, $terms_array, $postmeta, $attributes, $gpf_data, $images );
221
- return $product;
222
- }
223
-
224
  }
1
+ <?php
2
+ /**
3
+ * WooCommerce CSV Importer class for managing parsing of CSV files.
4
+ */
5
+ class WF_CSV_Parser_Coupon {
6
+
7
+ var $row;
8
+ var $post_type;
9
+ var $reserved_fields; // Fields we map/handle (not custom fields)
10
+ var $post_defaults; // Default post data
11
+ var $postmeta_defaults; // default post meta
12
+ var $postmeta_allowed; // post meta validation
13
+ var $allowed_coupon_types; // Allowed product types
14
+
15
+ /**
16
+ * Constructor
17
+ */
18
+ public function __construct( $post_type = 'shop_coupon' )
19
+ {
20
+ $this->post_type = $post_type;
21
+ $this->reserved_fields = include( 'data-coupon/data-wf-reserved-fields.php' );
22
+ $this->post_defaults = include( 'data-coupon/data-wf-post-defaults.php' );
23
+ $this->postmeta_defaults = include( 'data-coupon/data-wf-postmeta-defaults.php' );
24
+ $this->postmeta_allowed = include( 'data-coupon/data-wf-postmeta-allowed.php' );
25
+ $this->allowed_coupon_types = array(
26
+ 'fixed_cart' ,
27
+ 'percent',
28
+ 'fixed_product',
29
+ 'percent_product'
30
+ );
31
+
32
+ }
33
+
34
+ /**
35
+ * Format data from the csv file
36
+ * @param string $data
37
+ * @param string $enc
38
+ * @return string
39
+ */
40
+ public function format_data_from_csv( $data, $enc ) {
41
+ return ( $enc == 'UTF-8' ) ? $data : utf8_encode( $data );
42
+ }
43
+
44
+ /**
45
+ * Parse the data
46
+ * @param string $file [description]
47
+ * @param string $delimiter [description]
48
+ * @param array $mapping [description]
49
+ * @param integer $start_pos [description]
50
+ * @param integer $end_pos [description]
51
+ * @return array
52
+ */
53
+ public function parse_data( $file, $delimiter, $mapping, $start_pos = 0, $end_pos = null, $eval_field ) {
54
+ // Set locale
55
+ $enc = mb_detect_encoding( $file, 'UTF-8, ISO-8859-1', true );
56
+ if ( $enc )
57
+ setlocale( LC_ALL, 'en_US.' . $enc );
58
+ @ini_set( 'auto_detect_line_endings', true );
59
+
60
+ $parsed_data = array();
61
+ $raw_headers = array();
62
+
63
+ // Put all CSV data into an associative array
64
+ if ( ( $handle = fopen( $file, "r" ) ) !== FALSE ) {
65
+
66
+ $header = fgetcsv( $handle, 0, $delimiter , '"', '"' );
67
+ if ( $start_pos != 0 )
68
+ fseek( $handle, $start_pos );
69
+
70
+ while ( ( $postmeta = fgetcsv( $handle, 0, $delimiter , '"', '"' ) ) !== FALSE ) {
71
+ $row = array();
72
+
73
+ foreach ( $header as $key => $heading ) {
74
+ $s_heading = $heading;
75
+
76
+
77
+
78
+ if ( $s_heading == '' )
79
+ continue;
80
+
81
+ // Add the heading to the parsed data
82
+ $row[$s_heading] = ( isset( $postmeta[$key] ) ) ? $this->format_data_from_csv( $postmeta[$key], $enc ) : '';
83
+
84
+ // Raw Headers stores the actual column name in the CSV
85
+ $raw_headers[ $s_heading ] = $heading;
86
+ }
87
+ $parsed_data[] = $row;
88
+
89
+ unset( $postmeta, $row );
90
+
91
+ $position = ftell( $handle );
92
+
93
+ if ( $end_pos && $position >= $end_pos )
94
+ break;
95
+ }
96
+ fclose( $handle );
97
+ }
98
+ return array( $parsed_data, $raw_headers, $position );
99
+ }
100
+
101
+
102
+ /**
103
+ * Parse product
104
+ * @param array $item
105
+ * @param integer $merge_empty_cells
106
+ * @return array
107
+ */
108
+ public function parse_coupon( $item, $merge_empty_cells = 0 ) {
109
+ global $WF_CSV_Coupon_Import, $wpdb;
110
+ $this->row++;
111
+
112
+ $terms_array = $postmeta = $product = array();
113
+ $attributes = $default_attributes = $gpf_data = null;
114
+ // Merging
115
+ $merging = ( ! empty( $_GET['merge'] ) && $_GET['merge'] ) ? true : false;
116
+ $this->post_defaults['post_type'] = 'shop_coupon';
117
+
118
+ $post_id = ( ! empty( $item['id'] ) ) ? $item['id'] : 0;
119
+ $post_id = ( ! empty( $item['post_id'] ) ) ? $item['post_id'] : $post_id;
120
+ if ( $merging )
121
+ {
122
+ $product['merging'] = true;
123
+ $WF_CSV_Coupon_Import->hf_coupon_log_data_change( 'coupon-csv-import', sprintf( __('> Row %s - preparing for merge.', 'wf_order_import_export'), $this->row ) );
124
+ if ( ! $post_id )
125
+ {
126
+ $WF_CSV_Coupon_Import->hf_coupon_log_data_change( 'coupon-csv-import', __( '> > Cannot merge without id or sku. Importing instead.', 'wf_order_import_export') );
127
+
128
+ $merging = false;
129
+ } else
130
+ {
131
+ if ( ! $post_id )
132
+ {
133
+ $post_db_type = $this->post_defaults['post_type'];
134
+ $post_pass_type = '"'.$post_db_type.'"';
135
+ $db_query = $wpdb->prepare("
136
+ SELECT $wpdb->posts.ID
137
+ FROM $wpdb->posts
138
+ LEFT JOIN $wpdb->postmeta ON ($wpdb->posts.ID = $wpdb->postmeta.post_id)
139
+ WHERE $wpdb->posts.post_type = $post_pass_type
140
+ AND $wpdb->posts.post_status IN ( 'publish', 'private', 'draft', 'pending', 'future' )
141
+ AND $wpdb->posts.ID = '%d'
142
+ ", $item['ID']);
143
+ $found_product_id = $wpdb->get_var($db_query);
144
+ if ( ! $found_product_id )
145
+ {
146
+ $WF_CSV_Coupon_Import->hf_coupon_log_data_change( 'coupon-csv-import', sprintf(__( '> > Skipped. Cannot find coupon with sku %s. Importing instead.', 'wf_order_import_export'), $item['sku']) );
147
+ $merging = false;
148
+
149
+ } else
150
+ {
151
+
152
+ $post_id = $found_product_id;
153
+ $WF_CSV_Coupon_Import->hf_coupon_log_data_change( 'coupon-csv-import', sprintf(__( '> > Found coupon with ID %s.', 'wf_order_import_export'), $post_id) );
154
+
155
+ }
156
+ }
157
+ $product['merging'] = true;
158
+ }
159
+ }
160
+
161
+ if ( ! $merging )
162
+ {
163
+
164
+ $product['merging'] = false;
165
+ $WF_CSV_Coupon_Import->hf_coupon_log_data_change( 'coupon-csv-import', sprintf( __('> Row %s - preparing for import.', 'wf_order_import_export'), $this->row ) );
166
+ if ( isset($item['post_parent']) && $item['post_parent']=== '' && $item['post_title']=== '') {
167
+ $WF_CSV_Coupon_Import->hf_coupon_log_data_change( 'coupon-csv-import', __( '> > Skipped. No post_title set for new coupon.', 'wf_order_import_export') );
168
+ return new WP_Error( 'parse-error', __( 'No post_title set for new coupon.', 'wf_order_import_export' ) );
169
+ }
170
+ if ( isset($item['post_parent']) && $item['post_parent']!== '' && $item['post_parent']!== null && $item['parent_sku'] === '' )
171
+ {
172
+ $WF_CSV_Coupon_Import->hf_coupon_log_data_change( 'coupon-csv-import', __( '> > Skipped. No parent set for new variation product.', 'wf_order_import_export') );
173
+ return new WP_Error( 'parse-error', __( 'No parent set for new variation product.', 'wf_order_import_export' ) );
174
+ }
175
+ }
176
+
177
+ $product['post_id'] = $post_id;
178
+ foreach ( $this->post_defaults as $column => $default )
179
+ {
180
+ if ( isset( $item[ $column ] ) ) $product[ $column ] = $item[ $column ];
181
+ }
182
+
183
+ // Get custom fields
184
+ foreach ( $this->postmeta_defaults as $column => $default )
185
+ {
186
+ if ( isset( $item[$column] ) )
187
+ $postmeta[$column] = (string) $item[$column];
188
+ elseif ( isset( $item[$column] ) )
189
+ $postmeta[$column] = (string) $item[$column];
190
+
191
+ // Check custom fields are valid
192
+ if ( isset( $postmeta[$column] ) && isset( $this->postmeta_allowed[$column] ) && ! in_array( $postmeta[$column], $this->postmeta_allowed[$column] ) )
193
+ {
194
+ $postmeta[$column] = $this->postmeta_defaults[$column];
195
+ }
196
+ }
197
+
198
+ if ( ! $merging )
199
+ {
200
+ // Merge post meta with defaults
201
+ $product = wp_parse_args( $product, $this->post_defaults );
202
+ $postmeta = wp_parse_args( $postmeta, $this->postmeta_defaults );
203
+ }
204
+ if ( ! empty( $product['post_status'] ) )
205
+ {
206
+ if ( ! in_array( $product['post_status'], array( 'publish', 'private', 'draft', 'pending', 'future', 'inherit', 'trash' ) ) ) {
207
+ $product['post_status'] = 'publish';
208
+ }
209
+
210
+ if ( ! in_array( $product['post_status'], array( 'private', 'publish' ) ) ) {
211
+ $product['post_status'] = 'publish';
212
+ }
213
+
214
+ }
215
+ foreach ( $postmeta as $key => $value ) {
216
+ $product['postmeta'][] = array( 'key' => esc_attr($key), 'value' => $value );
217
+ }
218
+
219
+ $product['post_title'] = ( ! empty( $item['post_title'] ) ) ? $item['post_title'] : '';
220
+ unset( $item, $terms_array, $postmeta, $attributes, $gpf_data, $images );
221
+ return $product;
222
+ }
223
+
224
  }
includes/importer/class-wf-csv-parser.php CHANGED
@@ -1,802 +1,805 @@
1
- <?php
2
-
3
- /**
4
- * WooCommerce CSV Importer class for managing parsing of CSV files.
5
- */
6
- class WF_CSV_Parser {
7
-
8
- var $row;
9
- var $post_type;
10
- var $posts = array();
11
- var $processed_posts = array();
12
- var $file_url_import_enabled = true;
13
- var $log;
14
- var $merged = 0;
15
- var $skipped = 0;
16
- var $imported = 0;
17
- var $errored = 0;
18
- var $id;
19
- var $file_url;
20
- var $delimiter;
21
-
22
- /**
23
- * Constructor
24
- */
25
- public function __construct($post_type = 'shop_order') {
26
- $this->post_type = $post_type;
27
-
28
- $this->order_meta_fields = array(
29
- "order_tax",
30
- "order_shipping",
31
- "order_shipping_tax",
32
- "shipping_total",
33
- "shipping_tax_total",
34
- "fee_total",
35
- "fee_tax_total",
36
- "tax_total",
37
- "discount_total",
38
- "refunded_total",
39
- "customer_user",
40
- "cart_discount",
41
- "order_discount",
42
- "order_total",
43
- "order_currency",
44
- "payment_method",
45
- "customer_email",
46
- "billing_first_name",
47
- "billing_last_name",
48
- "billing_company",
49
- "billing_address_1",
50
- "billing_address_2",
51
- "billing_city",
52
- "billing_state",
53
- "billing_postcode",
54
- "billing_country",
55
- "billing_email",
56
- "billing_phone",
57
- "shipping_first_name",
58
- "shipping_last_name",
59
- "shipping_company",
60
- "shipping_address_1",
61
- "shipping_address_2",
62
- "shipping_city",
63
- "shipping_state",
64
- "shipping_postcode",
65
- "shipping_country",
66
- "shipping_method",
67
- "Download Permissions Granted",
68
- );
69
- }
70
-
71
- /**
72
- * Format data from the csv file
73
- * @param string $data
74
- * @param string $enc
75
- * @return string
76
- */
77
- public function format_data_from_csv($data, $enc) {
78
- return ( $enc == 'UTF-8' ) ? $data : utf8_encode($data);
79
- }
80
-
81
- /**
82
- * Parse the data
83
- * @param string $file [description]
84
- * @param string $delimiter [description]
85
- * @param integer $start_pos [description]
86
- * @param integer $end_pos [description]
87
- * @return array
88
- */
89
- public function parse_data($file, $delimiter, $start_pos = 0, $end_pos = null) {
90
- // Set locale
91
- $enc = mb_detect_encoding($file, 'UTF-8, ISO-8859-1', true);
92
- if ($enc)
93
- setlocale(LC_ALL, 'en_US.' . $enc);
94
- @ini_set('auto_detect_line_endings', true);
95
-
96
- $parsed_data = array();
97
- $raw_headers = array();
98
-
99
- // Put all CSV data into an associative array
100
- if (( $handle = fopen($file, "r") ) !== FALSE) {
101
-
102
- $header = fgetcsv($handle, 0, $delimiter, '"', '"');
103
- if ($start_pos != 0)
104
- fseek($handle, $start_pos);
105
-
106
- while (( $postmeta = fgetcsv($handle, 0, $delimiter, '"', '"') ) !== FALSE) {
107
- $row = array();
108
-
109
- foreach ($header as $key => $heading) {
110
- $s_heading = $heading;
111
-
112
-
113
-
114
- if ($s_heading == '')
115
- continue;
116
-
117
- // Add the heading to the parsed data
118
- $row[$s_heading] = ( isset($postmeta[$key]) ) ? $this->format_data_from_csv($postmeta[$key], $enc) : '';
119
-
120
- // Raw Headers stores the actual column name in the CSV
121
- $raw_headers[$s_heading] = $heading;
122
- }
123
- $parsed_data[] = $row;
124
-
125
- unset($postmeta, $row);
126
-
127
- $position = ftell($handle);
128
-
129
- if ($end_pos && $position >= $end_pos)
130
- break;
131
- }
132
- fclose($handle);
133
- }
134
- return array($parsed_data, $raw_headers, $position);
135
- }
136
-
137
- /**
138
- * Parse orders
139
- * @param array $item
140
- * @param integer $merge_empty_cells
141
- * @return array
142
- */
143
- public function parse_orders($parsed_data, $raw_headers, $merging, $record_offset) {
144
- $item = $parsed_data;
145
- global $WF_CSV_Order_Import, $wpdb;
146
- //$allow_unknown_products = isset( $_POST['allow_unknown_products'] ) && $_POST['allow_unknown_products'] ? true : false;
147
- $allow_unknown_products = true;
148
- $results = array();
149
-
150
- // Count row
151
- $row = 0;
152
-
153
- // skipped records
154
- $skipped = 0;
155
-
156
- $csv_export_file = true;
157
-
158
- $available_methods = WC()->shipping()->load_shipping_methods();
159
- $available_gateways = WC()->payment_gateways->payment_gateways();
160
- $shop_order_status = $this->wc_get_order_statuses_neat();
161
-
162
- $tax_rates = array();
163
- foreach ($wpdb->get_results("SELECT * FROM {$wpdb->prefix}woocommerce_tax_rates") as $_row) {
164
- $tax_rates[$_row->tax_rate_id] = $_row;
165
- }
166
-
167
- $row++;
168
-
169
- if ($row <= $record_offset) {
170
- $WF_CSV_Order_Import->hf_order_log_data_change('order-csv-import', sprintf(__('> Row %s - skipped due to record offset.', 'wf_order_import_export'), $row));
171
- unset($item);
172
- return;
173
- }
174
-
175
- $postmeta = $order = array();
176
-
177
- if (!$csv_export_file) {
178
- // standard format: optional integer order number and formatted order number
179
- $order_number = (!empty($item['order_number']) ) ? $item['order_number'] : null;
180
- $order_number_formatted = (!empty($item['order_number_formatted']) ) ? $item['order_number_formatted'] : $order_number;
181
-
182
- $WF_CSV_Order_Import->hf_order_log_data_change('order-csv-import', sprintf(__('> Row %s - preparing for import.', 'wf_order_import_export'), $row));
183
-
184
-
185
- // validate the supplied formatted order number/order number
186
- if (is_numeric($order_number_formatted) && !$order_number)
187
- $order_number = $order_number_formatted; // use formatted for underlying order number if possible
188
-
189
- if ($order_number && !is_numeric($order_number)) {
190
-
191
- $WF_CSV_Order_Import->hf_order_log_data_change('order-csv-import', sprintf(__('> > Skipped. Order number field must be an integer: %s.', 'wf_order_import_export'), $order_number));
192
- $skipped++;
193
- unset($item);
194
- return;
195
- }
196
-
197
- if ($order_number_formatted && !$order_number) {
198
-
199
- $WF_CSV_Order_Import->hf_order_log_data_change('order-csv-import', __('> > Skipped. Formatted order number provided but no numerical order number, see the documentation for further details.', 'wf_order_import_export'));
200
- $skipped++;
201
- unset($item);
202
- return;
203
- }
204
- } else {
205
- $order_number_formatted = !empty($item['order_id']) ? $item['order_id'] : 0;
206
- $order_number = (!empty($item['order_number']) ? $item['order_number'] : ( is_numeric($order_number_formatted) ? $order_number_formatted : 0 ) );
207
- }
208
-
209
- if ($order_number_formatted) {
210
- // verify that this order number isn't already in use
211
- $query_args = array(
212
- 'numberposts' => 1,
213
- 'meta_key' => apply_filters('woocommerce_order_number_formatted_meta_name', '_order_number_formatted'),
214
- 'meta_value' => $order_number_formatted,
215
- 'post_type' => 'shop_order',
216
- 'post_status' => array_keys(wc_get_order_statuses()),
217
- 'fields' => 'ids',
218
- );
219
-
220
- $order_id = 0;
221
- $orders = get_posts($query_args);
222
- if (!empty($orders)) {
223
- list( $order_id ) = get_posts($query_args);
224
- }
225
-
226
- $order_id = apply_filters('woocommerce_find_order_by_order_number', $order_id, $order_number_formatted);
227
-
228
- if ($order_id) {
229
- // skip if order ID already exist.
230
- $WF_CSV_Order_Import->hf_order_log_data_change('order-csv-import', sprintf(__('> > Skipped. Order %s already exists.', 'wf_order_import_export'), $order_number_formatted));
231
- $skipped++;
232
- unset($item);
233
- return;
234
- }
235
- }
236
- // handle the special (optional) customer_user field
237
- if (isset($item['customer_id']) && $item['customer_id']) {
238
- // attempt to find the customer user
239
- $found_customer = false;
240
- if (is_int($item['customer_id'])) {
241
-
242
- $found_customer = get_user_by('id', $item['customer_id']);
243
-
244
- if (!$found_customer) {
245
-
246
- $WF_CSV_Order_Import->hf_order_log_data_change('order-csv-import', sprintf(__('> > Skipped. Cannot find customer with id %s.', 'wf_order_import_export'), $item['customer_id']));
247
- $skipped++;
248
- unset($item);
249
- return;
250
- ;
251
- }
252
- } elseif (is_email($item['customer_id'])) {
253
- // check by email
254
- $found_customer = email_exists($item['customer_id']);
255
- }
256
-
257
- if (!$found_customer) {
258
- $found_customer = username_exists($item['customer_id']);
259
- }
260
-
261
- if (!$found_customer) {
262
- // guest checkout
263
- $item['customer_id'] = 0;
264
- } else {
265
- $item['customer_id'] = $found_customer; // user id
266
- }
267
- } elseif ($csv_export_file && isset($item['billing_email']) && $item['billing_email']) {
268
- // see if we can link to user by billing email id
269
- $found_customer = email_exists($item['billing_email']);
270
- if ($found_customer)
271
- $item['customer_id'] = $found_customer;
272
- else
273
- $item['customer_id'] = 0; // guest checkout
274
- } else {
275
- // guest checkout
276
- $item['customer_id'] = 0;
277
- }
278
-
279
-
280
- if (!empty($item['status'])) {
281
- $found_status = false;
282
- $available_statuses = array();
283
- foreach ($shop_order_status as $status_slug => $status_name) {
284
- if (0 == strcasecmp($status_slug, $item['status']))
285
- $found_status = true;
286
- $available_statuses[] = $status_slug;
287
- }
288
-
289
- if (!$found_status) {
290
- $WF_CSV_Order_Import->hf_order_log_data_change('order-csv-import', sprintf(__('> > Skipped. Unknown order status %s (%s).', 'wf_order_import_export'), $item['status'], implode($available_statuses, ', ')));
291
- $skipped++;
292
- unset($item);
293
- return;
294
- }
295
- } else {
296
- $item['status'] = 'processing';
297
- }
298
-
299
- if (!empty($item['order_date']))
300
- $item['date'] = $item['order_date'];
301
-
302
- if (!empty($item['date'])) {
303
- if (false === ( $item['date'] = strtotime($item['date']) )) {
304
- // invalid date format
305
- $WF_CSV_Order_Import->hf_order_log_data_change('order-csv-import', sprintf(__('> > Skipped. Invalid date format %s.', 'wf_order_import_export'), $item['date']));
306
- $skipped++;
307
- unset($item);
308
- return;
309
- }
310
- } else {
311
- $item['date'] = time();
312
- }
313
-
314
-
315
- $order_notes = array();
316
- if (!empty($item['order_notes'])) {
317
- $order_notes = explode("|", $item['order_notes']);
318
- }
319
-
320
- // build the order data object
321
- $order['status'] = $item['status'];
322
- $order['date'] = $item['date'];
323
- $order['order_comments'] = !empty($item['customer_note']) ? $item['customer_note'] : null;
324
- $order['notes'] = $order_notes;
325
- if (!is_null($order_number))
326
- $order['order_number'] = $order_number; // optional order number, for convenience
327
- if ($order_number_formatted)
328
- $order['order_number_formatted'] = $order_number_formatted;
329
-
330
- // totals
331
- $order_tax = $order_shipping_tax = null;
332
-
333
- // Get any known order meta fields, and default any missing ones to 0/null
334
- // the provided shipping/payment method will be used as-is, and if found in the list of available ones, the respective titles will also be set
335
- foreach ($this->order_meta_fields as $column) {
336
-
337
- switch ($column) {
338
-
339
- case 'shipping_method':
340
- $value = isset($item[$column]) ? $item[$column] : '';
341
-
342
- // look up shipping method by id or title
343
- $shipping_method = isset($available_methods[$value]) ? $value : null;
344
-
345
- if (!$shipping_method) {
346
- // try by title
347
- foreach ($available_methods as $method) {
348
- if (0 === strcasecmp($method->title, $value)) {
349
- $shipping_method = $method->id;
350
- break; // go with the first one we find
351
- }
352
- }
353
- }
354
-
355
- if ($shipping_method) {
356
- //known shipping method found
357
- $postmeta[] = array('key' => '_shipping_method', 'value' => $shipping_method);
358
- $postmeta[] = array('key' => '_shipping_method_title', 'value' => $available_methods[$shipping_method]->title);
359
- } elseif ($csv_export_file && $value) {
360
- //Order CSV Export format, shipping method title with no corresponding shipping method type found, so just use the title
361
- $postmeta[] = array('key' => '_shipping_method', 'value' => '');
362
- $postmeta[] = array('key' => '_shipping_method_title', 'value' => $value);
363
- } elseif ($value) {
364
- //Shipping method but no title
365
- $postmeta[] = array('key' => '_shipping_method', 'value' => $value);
366
- $postmeta[] = array('key' => '_shipping_method_title', 'value' => '');
367
- } else {
368
- //none
369
- $postmeta[] = array('key' => '_shipping_method', 'value' => '');
370
- $postmeta[] = array('key' => '_shipping_method_title', 'value' => '');
371
- }
372
- break;
373
-
374
- case 'payment_method':
375
- $value = isset($item[$column]) ? $item[$column] : '';
376
-
377
- // look up shipping method by id or title
378
- $payment_method = isset($available_gateways[$value]) ? $value : null;
379
- if (!$payment_method) {
380
- // try by title
381
- foreach ($available_gateways as $method) {
382
- if (0 === strcasecmp($method->title, $value)) {
383
- $payment_method = $method->id;
384
- break; // go with the first one we find
385
- }
386
- }
387
- }
388
-
389
- if ($payment_method) {
390
- //Known payment method found
391
- $postmeta[] = array('key' => '_payment_method', 'value' => $payment_method);
392
- $postmeta[] = array('key' => '_payment_method_title', 'value' => $available_gateways[$payment_method]->title);
393
- } elseif ($csv_export_file && $value) {
394
- //Order CSV Export format, payment method title with no corresponding payments method type found, so just use the title
395
- $postmeta[] = array('key' => '_payment_method', 'value' => '');
396
- $postmeta[] = array('key' => '_payment_method_title', 'value' => $value);
397
- } elseif ($value) {
398
- //payment method but no title
399
- $postmeta[] = array('key' => '_payment_method', 'value' => $value);
400
- $postmeta[] = array('key' => '_payment_method_title', 'value' => '');
401
- } else {
402
- //none
403
- $postmeta[] = array('key' => '_payment_method', 'value' => '');
404
- $postmeta[] = array('key' => '_payment_method_title', 'value' => '');
405
- }
406
- break;
407
-
408
- // handle numerics
409
- case 'order_shipping': // legacy
410
- case 'shipping_total':
411
- $order_shipping = isset($item[$column]) ? $item[$column] : 0; // save the order shipping total for later use
412
- $postmeta[] = array('key' => '_order_shipping', 'value' => number_format((float) $order_shipping, 2, '.', ''));
413
- break;
414
- case 'order_shipping_tax': // legacy
415
- case 'shipping_tax_total':
416
- // ignore blanks but allow zeroes
417
- if (isset($item[$column]) && is_numeric($item[$column])) {
418
- $order_shipping_tax = $item[$column];
419
- }
420
- break;
421
- case 'order_tax': // legacy
422
- case 'tax_total':
423
- // ignore blanks but allow zeroes
424
- if (isset($item[$column]) && is_numeric($item[$column])) {
425
- $order_tax = $item[$column];
426
- }
427
- break;
428
- case 'order_discount':
429
- case 'cart_discount':
430
- case 'order_total':
431
- $value = isset($item[$column]) ? $item[$column] : 0;
432
- $postmeta[] = array('key' => '_' . $column, 'value' => number_format((float) $value, 2, '.', ''));
433
- break;
434
-
435
- case 'billing_country':
436
- case 'shipping_country':
437
- $value = isset($item[$column]) ? $item[$column] : '';
438
- // support country name or code by converting to code
439
- $country_code = array_search($value, WC()->countries->countries);
440
- if ($country_code)
441
- $value = $country_code;
442
- $postmeta[] = array('key' => '_' . $column, 'value' => $value);
443
- break;
444
-
445
- case 'Download Permissions Granted':
446
- case 'download_permissions_granted':
447
- if (isset($item['download_permissions_granted'])) {
448
- $postmeta[] = array('key' => '_download_permissions_granted', 'value' => $item['download_permissions_granted']);
449
- }
450
- break;
451
- case 'download_permissions':
452
- if (isset($item['download_permissions'])) {
453
- $postmeta[] = array('key' => '_download_permissions_granted', 'value' => $item['download_permissions']);
454
- $postmeta[] = array('key' => '_download_permissions', 'value' => $item['download_permissions']);
455
- }
456
- break;
457
-
458
- default: $postmeta[] = array('key' => '_' . $column, 'value' => isset($item[$column]) ? $item[$column] : "");
459
- }
460
- }
461
-
462
- if (!empty($item['customer_id']))
463
- $postmeta[] = array('key' => '_customer_user', 'value' => $item['customer_id']);
464
-
465
- // Get any custom meta fields
466
- foreach ($item as $key => $value) {
467
-
468
- if (!$value) {
469
- continue;
470
- }
471
-
472
- // Handle meta: columns - import as custom fields
473
- if (strstr($key, 'meta:')) {
474
-
475
- // Get meta key name
476
- $meta_key = ( isset($raw_headers[$key]) ) ? $raw_headers[$key] : $key;
477
- $meta_key = trim(str_replace('meta:', '', $meta_key));
478
-
479
- // Add to postmeta array
480
- $postmeta[] = array(
481
- 'key' => esc_attr($meta_key),
482
- 'value' => $value,
483
- );
484
- }
485
- }
486
-
487
- $order_shipping_methods = array();
488
- $_shipping_methods = array();
489
-
490
- // pre WC 2.1 format of a single shipping method, left for backwards compatibility of import files
491
- if (isset($item['shipping_method']) && $item['shipping_method']) {
492
- // collect the shipping method id/cost
493
- $_shipping_methods[] = array(
494
- $item['shipping_method'],
495
- isset($item['shipping_cost']) ? $item['shipping_cost'] : null
496
- );
497
- }
498
-
499
- // collect any additional shipping methods
500
- $i = null;
501
- if (isset($item['shipping_method_1'])) {
502
- $i = 1;
503
- } elseif (isset($item['shipping_method_2'])) {
504
- $i = 2;
505
- }
506
-
507
- if (!is_null($i)) {
508
- while (!empty($item['shipping_method_' . $i])) {
509
-
510
- $_shipping_methods[] = array(
511
- $item['shipping_method_' . $i],
512
- isset($item['shipping_cost_' . $i]) ? $item['shipping_cost_' . $i] : null
513
- );
514
- $i++;
515
- }
516
- }
517
-
518
- // if the order shipping total wasn't set, calculate it
519
- if (!isset($order_shipping)) {
520
-
521
- $order_shipping = 0;
522
- foreach ($_shipping_methods as $_shipping_method) {
523
- $order_shipping += $_shipping_method[1];
524
- }
525
- $postmeta[] = array('key' => '_order_shipping' . $column, 'value' => number_format((float) $order_shipping, 2, '.', ''));
526
- } elseif (isset($order_shipping) && 1 == count($_shipping_methods) && is_null($_shipping_methods[0][1])) {
527
- // special case: if there was a total order shipping but no cost for the single shipping method, use the total shipping for the order shipping line item
528
- $_shipping_methods[0][1] = $order_shipping;
529
- }
530
-
531
- foreach ($_shipping_methods as $_shipping_method) {
532
-
533
- // look up shipping method by id or title
534
- $shipping_method = isset($available_methods[$_shipping_method[0]]) ? $_shipping_method[0] : null;
535
-
536
- if (!$shipping_method) {
537
- // try by title
538
- foreach ($available_methods as $method) {
539
- if (0 === strcasecmp($method->title, $_shipping_method[0])) {
540
- $shipping_method = $method->id;
541
- break; // go with the first one we find
542
- }
543
- }
544
- }
545
-
546
- if ($shipping_method) {
547
- //Known shipping method found
548
- $order_shipping_methods[] = array('method_id' => $shipping_method, 'cost' => $_shipping_method[1], 'title' => $available_methods[$shipping_method]->title);
549
- } elseif ($csv_export_file && $_shipping_method[0]) {
550
- //Order CSV Export format, shipping method title with no corresponding shipping method type found, so just use the title
551
- $order_shipping_methods[] = array('method_id' => '', 'cost' => $_shipping_method[1], 'title' => $_shipping_method[0]);
552
- } elseif ($_shipping_method[0]) {
553
- //shipping method but no title
554
- $order_shipping_methods[] = array('method_id' => $_shipping_method[0], 'cost' => $_shipping_method[1], 'title' => '');
555
- }
556
- }
557
-
558
- $order_items = array();
559
- if ($csv_export_file) {
560
- // standard format
561
- if (!empty($item['line_item_1'])) {
562
- // one or more order items
563
- $i = 1;
564
- while (!empty($item['line_item_' . $i])) {
565
-
566
- $_item_meta = preg_split("~\\\\.(*SKIP)(*FAIL)|\|~s", $item['line_item_' . $i]);
567
-
568
- if ($item['line_item_' . $i] && empty($_item_meta)) {
569
- $_item_meta = explode('|', $item['line_item_' . $i]);
570
- }
571
- $name = array_shift($_item_meta);
572
- $name = substr($name, strpos($name, ":") + 1);
573
- $product_identifier_by_id = array_shift($_item_meta); // product_id:id
574
- $product_identifier_by_sku = array_shift($_item_meta); // sku
575
-
576
- $qty = array_shift($_item_meta);
577
- $qty = substr($qty, strpos($qty, ":") + 1);
578
- $total = array_shift($_item_meta);
579
- $total = substr($total, strpos($total, ":") + 1);
580
-
581
-
582
- // find by id
583
- if (false !== strpos($product_identifier_by_id, 'product_id:')) {
584
- // product by product_id
585
- $product_id = substr($product_identifier_by_id, 11);
586
-
587
- // not a product
588
- if (!in_array(get_post_type($product_id), array('product', 'product_variation'))) {
589
- $product_id = '';
590
- }
591
- } else {
592
- // find by sku
593
- $product_sku = substr($product_identifier_by_sku, strpos($product_identifier_by_sku, ":") + 1);
594
- if ($product_sku)
595
- $product_id = $wpdb->get_var($wpdb->prepare("SELECT post_id FROM $wpdb->postmeta WHERE meta_key='_sku' AND meta_value=%s LIMIT 1", $product_sku));
596
- else
597
- $product_id = '';
598
- }
599
-
600
- if (!$allow_unknown_products && !$product_id) {
601
- // unknown product
602
- $WF_CSV_Order_Import->hf_order_log_data_change('order-csv-import', sprintf(__('> > Skipped. Unknown order item: %s.', 'wf_order_import_export'), $product_identifier));
603
- $skipped++;
604
- $i++;
605
- continue; // break outer loop
606
- }
607
-
608
- // get any additional item meta
609
- $item_meta = array();
610
- foreach ($_item_meta as $pair) {
611
-
612
- // replace any escaped pipes
613
- $pair = str_replace('\|', '|', $pair);
614
-
615
- // find the first ':' and split into name-value
616
- $split = strpos($pair, ':');
617
- $name = substr($pair, 0, $split);
618
- $value = substr($pair, $split + 1);
619
-
620
- $item_meta[$name] = $value;
621
- }
622
-
623
- $order_items[] = array('product_id' => $product_id, 'qty' => $qty, 'total' => $total, 'meta' => $item_meta);
624
-
625
- $i++;
626
- }
627
- }
628
- } else {
629
- //CSV Order Export format
630
- $sku = $item['item_sku'];
631
- $qty = $item['item_amount'];
632
- $total = $item['row_price'];
633
-
634
- if (!$sku || !$qty || !is_numeric($total)) {
635
- // invalid item
636
- $WF_CSV_Order_Import->hf_order_log_data_change('order-csv-import', sprintf(__('> > Row %d - %s - skipped. Missing SKU, quantity or total', 'wf_order_import_export'), $row, $item['order_id']));
637
- $skipped++;
638
- unset($item);
639
- return; // break outer loop
640
- }
641
-
642
- // find by sku
643
- $product_id = $wpdb->get_var($wpdb->prepare("SELECT post_id FROM $wpdb->postmeta WHERE meta_key='_sku' AND meta_value=%s LIMIT 1", $sku));
644
-
645
- if (!$product_id) {
646
- // unknown product
647
- $WF_CSV_Order_Import->hf_order_log_data_change('order-csv-import', sprintf(__('> > Row %d - %s - skipped. Unknown order item: %s.', 'wf_order_import_export'), $row, $item['order_id'], $sku));
648
- $skipped++;
649
- unset($item);
650
- return; // break outer loop
651
- }
652
-
653
- $order_items[] = array('product_id' => $product_id, 'qty' => $qty, 'total' => $total);
654
- }
655
-
656
- $tax_items = array();
657
-
658
- // standard tax item format which supports multiple tax items in numbered columns containing a pipe-delimated, colon-labeled format
659
- if (!empty($item['tax_item_1']) || !empty($item['tax_item'])) {
660
- // one or more order tax items
661
- // get the first tax item
662
- $tax_item = !empty($item['tax_item_1']) ? $item['tax_item_1'] : $item['tax_item'];
663
-
664
- $i = 1;
665
- $tax_amount_sum = $shipping_tax_amount_sum = 0;
666
- while ($tax_item) {
667
-
668
- $tax_item_data = array();
669
-
670
- // turn "label: Tax | tax_amount: 10" into an associative array
671
- foreach (explode('|', $tax_item) as $piece) {
672
- list( $name, $value ) = explode(':', $piece);
673
- $tax_item_data[trim($name)] = trim($value);
674
- }
675
-
676
- // default rate id to 0 if not set
677
- if (!isset($tax_item_data['rate_id'])) {
678
- $tax_item_data['rate_id'] = 0;
679
- }
680
-
681
- // have a tax amount or shipping tax amount
682
- if (isset($tax_item_data['tax_amount']) || isset($tax_item_data['shipping_tax_amount'])) {
683
-
684
- // try and look up rate id by label if needed
685
- if (isset($tax_item_data['label']) && $tax_item_data['label'] && !$tax_item_data['rate_id']) {
686
- foreach ($tax_rates as $tax_rate) {
687
-
688
- if (0 === strcasecmp($tax_rate->tax_rate_name, $tax_item_data['label'])) {
689
- // found the tax by label
690
- $tax_item_data['rate_id'] = $tax_rate->tax_rate_id;
691
- break;
692
- }
693
- }
694
- }
695
-
696
- // check for a rate being specified which does not exist, and clear it out (technically an error?)
697
- if ($tax_item_data['rate_id'] && !isset($tax_rates[$tax_item_data['rate_id']])) {
698
- $tax_item_data['rate_id'] = 0;
699
- }
700
-
701
- // default label of 'Tax' if not provided
702
- if (!isset($tax_item_data['label']) || !$tax_item_data['label']) {
703
- $tax_item_data['label'] = 'Tax';
704
- }
705
-
706
- // default tax amounts to 0 if not set
707
- if (!isset($tax_item_data['tax_amount'])) {
708
- $tax_item_data['tax_amount'] = 0;
709
- }
710
- if (!isset($tax_item_data['shipping_tax_amount'])) {
711
- $tax_item_data['shipping_tax_amount'] = 0;
712
- }
713
-
714
- // handle compound flag by using the defined tax rate value (if any)
715
- if (!isset($tax_item_data['tax_rate_compound'])) {
716
- $tax_item_data['tax_rate_compound'] = '';
717
- if ($tax_item_data['rate_id']) {
718
- $tax_item_data['tax_rate_compound'] = $tax_rates[$tax_item_data['rate_id']]->tax_rate_compound;
719
- }
720
- }
721
-
722
- $tax_items[] = array(
723
- 'title' => '',
724
- 'rate_id' => $tax_item_data['rate_id'],
725
- 'label' => $tax_item_data['label'],
726
- 'compound' => $tax_item_data['tax_rate_compound'],
727
- 'tax_amount' => $tax_item_data['tax_amount'],
728
- 'shipping_tax_amount' => $tax_item_data['shipping_tax_amount'],
729
- );
730
-
731
- // sum up the order totals, in case it wasn't part of the import
732
- $tax_amount_sum += $tax_item_data['tax_amount'];
733
- $shipping_tax_amount_sum += $tax_item_data['shipping_tax_amount'];
734
- }
735
-
736
- // get the next tax item (if any)
737
- $i++;
738
- $tax_item = isset($item['tax_item_' . $i]) ? $item['tax_item_' . $i] : null;
739
- }
740
-
741
- if (!is_numeric($order_tax)) {
742
- $order_tax = $tax_amount_sum;
743
- }
744
- if (!is_numeric($order_shipping_tax)) {
745
- $order_shipping_tax = $shipping_tax_amount_sum;
746
- }
747
- }
748
-
749
- // default to zero if not set
750
- if (!is_numeric($order_tax)) {
751
- $order_tax = 0;
752
- }
753
- if (!is_numeric($order_shipping_tax)) {
754
- $order_shipping_tax = 0;
755
- }
756
-
757
- // no tax items specified, so create a default one using the tax totals
758
- if (0 == count($tax_items)) {
759
-
760
- $tax_items[] = array(
761
- 'title' => '',
762
- 'rate_id' => 0,
763
- 'label' => 'Tax',
764
- 'compound' => '',
765
- 'tax_amount' => $order_tax,
766
- 'shipping_tax_amount' => $order_shipping_tax,
767
- );
768
- }
769
-
770
- // add the order tax totals to the order meta
771
- $postmeta[] = array('key' => '_order_tax', 'value' => number_format((float) $order_tax, 2, '.', ''));
772
- $postmeta[] = array('key' => '_order_shipping_tax', 'value' => number_format((float) $order_shipping_tax, 2, '.', ''));
773
-
774
-
775
- if ($order) {
776
- $order['postmeta'] = $postmeta;
777
- $order['order_items'] = $order_items;
778
- $order['order_shipping'] = $order_shipping_methods;
779
- $order['tax_items'] = $tax_items;
780
-
781
- // the order array will now contain the necessary name-value pairs for the wp_posts table, and also any meta data in the 'postmeta' array
782
- $results[] = $order;
783
- }
784
- // Result
785
- return array(
786
- $this->post_type => $results,
787
- 'skipped' => $skipped,
788
- );
789
- }
790
-
791
- private function wc_get_order_statuses_neat() {
792
-
793
- $order_statuses = array();
794
-
795
- foreach (wc_get_order_statuses() as $slug => $name) {
796
- $order_statuses[preg_replace('/^wc-/', '', $slug)] = $name;
797
- }
798
-
799
- return $order_statuses;
800
- }
801
-
802
- }
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * WooCommerce CSV Importer class for managing parsing of CSV files.
5
+ */
6
+ class WF_CSV_Parser {
7
+
8
+ var $row;
9
+ var $post_type;
10
+ var $posts = array();
11
+ var $processed_posts = array();
12
+ var $file_url_import_enabled = true;
13
+ var $log;
14
+ var $merged = 0;
15
+ var $skipped = 0;
16
+ var $imported = 0;
17
+ var $errored = 0;
18
+ var $id;
19
+ var $file_url;
20
+ var $delimiter;
21
+
22
+ /**
23
+ * Constructor
24
+ */
25
+ public function __construct($post_type = 'shop_order') {
26
+ $this->post_type = $post_type;
27
+
28
+ $this->order_meta_fields = array(
29
+ "order_tax",
30
+ "order_shipping",
31
+ "order_shipping_tax",
32
+ "shipping_total",
33
+ "shipping_tax_total",
34
+ "fee_total",
35
+ "fee_tax_total",
36
+ "tax_total",
37
+ "discount_total",
38
+ "refunded_total",
39
+ "customer_user",
40
+ "cart_discount",
41
+ "order_discount",
42
+ "order_total",
43
+ "order_currency",
44
+ "payment_method",
45
+ "customer_email",
46
+ "billing_first_name",
47
+ "billing_last_name",
48
+ "billing_company",
49
+ "billing_address_1",
50
+ "billing_address_2",
51
+ "billing_city",
52
+ "billing_state",
53
+ "billing_postcode",
54
+ "billing_country",
55
+ "billing_email",
56
+ "billing_phone",
57
+ "shipping_first_name",
58
+ "shipping_last_name",
59
+ "shipping_company",
60
+ "shipping_address_1",
61
+ "shipping_address_2",
62
+ "shipping_city",
63
+ "shipping_state",
64
+ "shipping_postcode",
65
+ "shipping_country",
66
+ "shipping_method",
67
+ "Download Permissions Granted",
68
+ );
69
+ }
70
+
71
+ /**
72
+ * Format data from the csv file
73
+ * @param string $data
74
+ * @param string $enc
75
+ * @return string
76
+ */
77
+ public function format_data_from_csv($data, $enc) {
78
+ return ( $enc == 'UTF-8' ) ? $data : utf8_encode($data);
79
+ }
80
+
81
+ /**
82
+ * Parse the data
83
+ * @param string $file [description]
84
+ * @param string $delimiter [description]
85
+ * @param integer $start_pos [description]
86
+ * @param integer $end_pos [description]
87
+ * @return array
88
+ */
89
+ public function parse_data($file, $delimiter, $start_pos = 0, $end_pos = null) {
90
+ // Set locale
91
+ $enc = mb_detect_encoding($file, 'UTF-8, ISO-8859-1', true);
92
+ if ($enc)
93
+ setlocale(LC_ALL, 'en_US.' . $enc);
94
+ @ini_set('auto_detect_line_endings', true);
95
+
96
+ $parsed_data = array();
97
+ $raw_headers = array();
98
+
99
+ // Put all CSV data into an associative array
100
+ if (( $handle = fopen($file, "r") ) !== FALSE) {
101
+
102
+ $header = fgetcsv($handle, 0, $delimiter, '"', '"');
103
+ if ($start_pos != 0)
104
+ fseek($handle, $start_pos);
105
+
106
+ while (( $postmeta = fgetcsv($handle, 0, $delimiter, '"', '"') ) !== FALSE) {
107
+ $row = array();
108
+
109
+ foreach ($header as $key => $heading) {
110
+ $s_heading = $heading;
111
+
112
+
113
+
114
+ if ($s_heading == '')
115
+ continue;
116
+
117
+ // Add the heading to the parsed data
118
+ $row[$s_heading] = ( isset($postmeta[$key]) ) ? $this->format_data_from_csv($postmeta[$key], $enc) : '';
119
+
120
+ // Raw Headers stores the actual column name in the CSV
121
+ $raw_headers[$s_heading] = $heading;
122
+ }
123
+ $parsed_data[] = $row;
124
+
125
+ unset($postmeta, $row);
126
+
127
+ $position = ftell($handle);
128
+
129
+ if ($end_pos && $position >= $end_pos)
130
+ break;
131
+ }
132
+ fclose($handle);
133
+ }
134
+ return array($parsed_data, $raw_headers, $position);
135
+ }
136
+
137
+ /**
138
+ * Parse orders
139
+ * @param array $item
140
+ * @param integer $merge_empty_cells
141
+ * @return array
142
+ */
143
+ public function parse_orders($parsed_data, $raw_headers, $merging, $record_offset) {
144
+ $item = $parsed_data;
145
+ global $WF_CSV_Order_Import, $wpdb;
146
+ //$allow_unknown_products = isset( $_POST['allow_unknown_products'] ) && $_POST['allow_unknown_products'] ? true : false;
147
+ $allow_unknown_products = true;
148
+ $results = array();
149
+
150
+ // Count row
151
+ $row = 0;
152
+
153
+ // skipped records
154
+ $skipped = 0;
155
+
156
+ $csv_export_file = true;
157
+
158
+ $available_methods = WC()->shipping()->load_shipping_methods();
159
+ $available_gateways = WC()->payment_gateways->payment_gateways();
160
+ $shop_order_status = $this->wc_get_order_statuses_neat();
161
+
162
+ $tax_rates = array();
163
+ foreach ($wpdb->get_results("SELECT * FROM {$wpdb->prefix}woocommerce_tax_rates") as $_row) {
164
+ $tax_rates[$_row->tax_rate_id] = $_row;
165
+ }
166
+
167
+ $row++;
168
+
169
+ if ($row <= $record_offset) {
170
+ $WF_CSV_Order_Import->hf_order_log_data_change('order-csv-import', sprintf(__('> Row %s - skipped due to record offset.', 'wf_order_import_export'), $row));
171
+ unset($item);
172
+ return;
173
+ }
174
+
175
+ $postmeta = $order = array();
176
+
177
+ if (!$csv_export_file) {
178
+ // standard format: optional integer order number and formatted order number
179
+ $order_number = (!empty($item['order_number']) ) ? $item['order_number'] : null;
180
+ $order_number_formatted = (!empty($item['order_number_formatted']) ) ? $item['order_number_formatted'] : $order_number;
181
+
182
+ $WF_CSV_Order_Import->hf_order_log_data_change('order-csv-import', sprintf(__('> Row %s - preparing for import.', 'wf_order_import_export'), $row));
183
+
184
+
185
+ // validate the supplied formatted order number/order number
186
+ if (is_numeric($order_number_formatted) && !$order_number)
187
+ $order_number = $order_number_formatted; // use formatted for underlying order number if possible
188
+
189
+ if ($order_number && !is_numeric($order_number)) {
190
+
191
+ $WF_CSV_Order_Import->hf_order_log_data_change('order-csv-import', sprintf(__('> > Skipped. Order number field must be an integer: %s.', 'wf_order_import_export'), $order_number));
192
+ $skipped++;
193
+ unset($item);
194
+ return;
195
+ }
196
+
197
+ if ($order_number_formatted && !$order_number) {
198
+
199
+ $WF_CSV_Order_Import->hf_order_log_data_change('order-csv-import', __('> > Skipped. Formatted order number provided but no numerical order number, see the documentation for further details.', 'wf_order_import_export'));
200
+ $skipped++;
201
+ unset($item);
202
+ return;
203
+ }
204
+ } else {
205
+ $order_number_formatted = !empty($item['order_id']) ? $item['order_id'] : 0;
206
+ $order_number = (!empty($item['order_number']) ? $item['order_number'] : ( is_numeric($order_number_formatted) ? $order_number_formatted : 0 ) );
207
+ }
208
+
209
+ if ($order_number_formatted) {
210
+ // verify that this order number isn't already in use
211
+ $query_args = array(
212
+ 'numberposts' => 1,
213
+ 'meta_key' => apply_filters('woocommerce_order_number_formatted_meta_name', '_order_number_formatted'),
214
+ 'meta_value' => $order_number_formatted,
215
+ 'post_type' => 'shop_order',
216
+ 'post_status' => array_keys(wc_get_order_statuses()),
217
+ 'fields' => 'ids',
218
+ );
219
+
220
+ $order_id = 0;
221
+ $orders = get_posts($query_args);
222
+ if (!empty($orders)) {
223
+ list( $order_id ) = get_posts($query_args);
224
+ }
225
+
226
+ $order_id = apply_filters('woocommerce_find_order_by_order_number', $order_id, $order_number_formatted);
227
+
228
+ if ($order_id) {
229
+ // skip if order ID already exist.
230
+ $WF_CSV_Order_Import->hf_order_log_data_change('order-csv-import', sprintf(__('> > Skipped. Order %s already exists.', 'wf_order_import_export'), $order_number_formatted));
231
+ $skipped++;
232
+ unset($item);
233
+ return;
234
+ }
235
+ }
236
+ // handle the special (optional) customer_user field
237
+ if (isset($item['customer_id']) && $item['customer_id']) {
238
+ // attempt to find the customer user
239
+ $found_customer = false;
240
+ if (is_int($item['customer_id'])) {
241
+
242
+ $found_customer = get_user_by('id', $item['customer_id']);
243
+
244
+ if (!$found_customer) {
245
+
246
+ $WF_CSV_Order_Import->hf_order_log_data_change('order-csv-import', sprintf(__('> > Skipped. Cannot find customer with id %s.', 'wf_order_import_export'), $item['customer_id']));
247
+ $skipped++;
248
+ unset($item);
249
+ return;
250
+ ;
251
+ }
252
+ } elseif (is_email($item['customer_id'])) {
253
+ // check by email
254
+ $found_customer = email_exists($item['customer_id']);
255
+ }
256
+
257
+ if (!$found_customer) {
258
+ $found_customer = username_exists($item['customer_id']);
259
+ }
260
+
261
+ if (!$found_customer) {
262
+ // guest checkout
263
+ $item['customer_id'] = 0;
264
+ } else {
265
+ $item['customer_id'] = $found_customer; // user id
266
+ }
267
+ } elseif ($csv_export_file && isset($item['billing_email']) && $item['billing_email']) {
268
+ // see if we can link to user by billing email id
269
+ $found_customer = email_exists($item['billing_email']);
270
+ if ($found_customer)
271
+ $item['customer_id'] = $found_customer;
272
+ else
273
+ $item['customer_id'] = 0; // guest checkout
274
+ } else {
275
+ // guest checkout
276
+ $item['customer_id'] = 0;
277
+ }
278
+
279
+
280
+ if (!empty($item['status'])) {
281
+ $found_status = false;
282
+ $available_statuses = array();
283
+ foreach ($shop_order_status as $status_slug => $status_name) {
284
+ if (0 == strcasecmp($status_slug, $item['status']))
285
+ $found_status = true;
286
+ $available_statuses[] = $status_slug;
287
+ }
288
+
289
+ if (!$found_status) {
290
+ $WF_CSV_Order_Import->hf_order_log_data_change('order-csv-import', sprintf(__('> > Skipped. Unknown order status %s (%s).', 'wf_order_import_export'), $item['status'], implode($available_statuses, ', ')));
291
+ $skipped++;
292
+ unset($item);
293
+ return;
294
+ }
295
+ } else {
296
+ $item['status'] = 'processing';
297
+ }
298
+
299
+ if (!empty($item['order_date']))
300
+ $item['date'] = $item['order_date'];
301
+
302
+ if (!empty($item['date'])) {
303
+ if (false === ( $item['date'] = strtotime($item['date']) )) {
304
+ // invalid date format
305
+ $WF_CSV_Order_Import->hf_order_log_data_change('order-csv-import', sprintf(__('> > Skipped. Invalid date format %s.', 'wf_order_import_export'), $item['date']));
306
+ $skipped++;
307
+ unset($item);
308
+ return;
309
+ }
310
+ } else {
311
+ $item['date'] = time();
312
+ }
313
+
314
+
315
+ $order_notes = array();
316
+ if (!empty($item['order_notes'])) {
317
+ $order_notes = explode("|", $item['order_notes']);
318
+ }
319
+
320
+ // build the order data object
321
+ $order['status'] = $item['status'];
322
+ $order['date'] = $item['date'];
323
+ $order['order_comments'] = !empty($item['customer_note']) ? $item['customer_note'] : null;
324
+ $order['notes'] = $order_notes;
325
+ if (!is_null($order_number))
326
+ $order['order_number'] = $order_number; // optional order number, for convenience
327
+ if ($order_number_formatted)
328
+ $order['order_number_formatted'] = $order_number_formatted;
329
+
330
+ // totals
331
+ $order_tax = $order_shipping_tax = null;
332
+
333
+ // Get any known order meta fields, and default any missing ones to 0/null
334
+ // the provided shipping/payment method will be used as-is, and if found in the list of available ones, the respective titles will also be set
335
+ foreach ($this->order_meta_fields as $column) {
336
+
337
+ switch ($column) {
338
+
339
+ case 'shipping_method':
340
+ $value = isset($item[$column]) ? $item[$column] : '';
341
+
342
+ // look up shipping method by id or title
343
+ $shipping_method = isset($available_methods[$value]) ? $value : null;
344
+
345
+ if (!$shipping_method) {
346
+ // try by title
347
+ foreach ($available_methods as $method) {
348
+ if (0 === strcasecmp($method->title, $value)) {
349
+ $shipping_method = $method->id;
350
+ break; // go with the first one we find
351
+ }
352
+ }
353
+ }
354
+
355
+ if ($shipping_method) {
356
+ //known shipping method found
357
+ $postmeta[] = array('key' => '_shipping_method', 'value' => $shipping_method);
358
+ $postmeta[] = array('key' => '_shipping_method_title', 'value' => $available_methods[$shipping_method]->title);
359
+ } elseif ($csv_export_file && $value) {
360
+ //Order CSV Export format, shipping method title with no corresponding shipping method type found, so just use the title
361
+ $postmeta[] = array('key' => '_shipping_method', 'value' => '');
362
+ $postmeta[] = array('key' => '_shipping_method_title', 'value' => $value);
363
+ } elseif ($value) {
364
+ //Shipping method but no title
365
+ $postmeta[] = array('key' => '_shipping_method', 'value' => $value);
366
+ $postmeta[] = array('key' => '_shipping_method_title', 'value' => '');
367
+ } else {
368
+ //none
369
+ $postmeta[] = array('key' => '_shipping_method', 'value' => '');
370
+ $postmeta[] = array('key' => '_shipping_method_title', 'value' => '');
371
+ }
372
+ break;
373
+
374
+ case 'payment_method':
375
+ $value = isset($item[$column]) ? $item[$column] : '';
376
+
377
+ // look up shipping method by id or title
378
+ $payment_method = isset($available_gateways[$value]) ? $value : null;
379
+ if (!$payment_method) {
380
+ // try by title
381
+ foreach ($available_gateways as $method) {
382
+ if (0 === strcasecmp($method->title, $value)) {
383
+ $payment_method = $method->id;
384
+ break; // go with the first one we find
385
+ }
386
+ }
387
+ }
388
+
389
+ if ($payment_method) {
390
+ //Known payment method found
391
+ $postmeta[] = array('key' => '_payment_method', 'value' => $payment_method);
392
+ $postmeta[] = array('key' => '_payment_method_title', 'value' => $available_gateways[$payment_method]->title);
393
+ } elseif ($csv_export_file && $value) {
394
+ //Order CSV Export format, payment method title with no corresponding payments method type found, so just use the title
395
+ $postmeta[] = array('key' => '_payment_method', 'value' => '');
396
+ $postmeta[] = array('key' => '_payment_method_title', 'value' => $value);
397
+ } elseif ($value) {
398
+ //payment method but no title
399
+ $postmeta[] = array('key' => '_payment_method', 'value' => $value);
400
+ $postmeta[] = array('key' => '_payment_method_title', 'value' => '');
401
+ } else {
402
+ //none
403
+ $postmeta[] = array('key' => '_payment_method', 'value' => '');
404
+ $postmeta[] = array('key' => '_payment_method_title', 'value' => '');
405
+ }
406
+ break;
407
+
408
+ // handle numerics
409
+ case 'order_shipping': // legacy
410
+ case 'shipping_total':
411
+ $order_shipping = isset($item[$column]) ? $item[$column] : 0; // save the order shipping total for later use
412
+ $postmeta[] = array('key' => '_order_shipping', 'value' => number_format((float) $order_shipping, 2, '.', ''));
413
+ break;
414
+ case 'order_shipping_tax': // legacy
415
+ case 'shipping_tax_total':
416
+ // ignore blanks but allow zeroes
417
+ if (isset($item[$column]) && is_numeric($item[$column])) {
418
+ $order_shipping_tax = $item[$column];
419
+ }
420
+ break;
421
+ case 'order_tax': // legacy
422
+ case 'tax_total':
423
+ // ignore blanks but allow zeroes
424
+ if (isset($item[$column]) && is_numeric($item[$column])) {
425
+ $order_tax = $item[$column];
426
+ }
427
+ break;
428
+ case 'order_discount':
429
+ case 'cart_discount':
430
+ case 'order_total':
431
+ $value = isset($item[$column]) ? $item[$column] : 0;
432
+ $postmeta[] = array('key' => '_' . $column, 'value' => number_format((float) $value, 2, '.', ''));
433
+ break;
434
+
435
+ case 'billing_country':
436
+ case 'shipping_country':
437
+ $value = isset($item[$column]) ? $item[$column] : '';
438
+ // support country name or code by converting to code
439
+ $country_code = array_search($value, WC()->countries->countries);
440
+ if ($country_code)
441
+ $value = $country_code;
442
+ $postmeta[] = array('key' => '_' . $column, 'value' => $value);
443
+ break;
444
+
445
+ case 'Download Permissions Granted':
446
+ case 'download_permissions_granted':
447
+ if (isset($item['download_permissions_granted'])) {
448
+ $postmeta[] = array('key' => '_download_permissions_granted', 'value' => $item['download_permissions_granted']);
449
+ }
450
+ break;
451
+ case 'download_permissions':
452
+ if (isset($item['download_permissions'])) {
453
+ $postmeta[] = array('key' => '_download_permissions_granted', 'value' => $item['download_permissions']);
454
+ $postmeta[] = array('key' => '_download_permissions', 'value' => $item['download_permissions']);
455
+ }
456
+ break;
457
+
458
+ default: $postmeta[] = array('key' => '_' . $column, 'value' => isset($item[$column]) ? $item[$column] : "");
459
+ }
460
+ }
461
+
462
+ if (!empty($item['customer_id']))
463
+ $postmeta[] = array('key' => '_customer_user', 'value' => $item['customer_id']);
464
+
465
+ // Get any custom meta fields
466
+ foreach ($item as $key => $value) {
467
+
468
+ if (!$value) {
469
+ continue;
470
+ }
471
+
472
+ // Handle meta: columns - import as custom fields
473
+ if (strstr($key, 'meta:')) {
474
+
475
+ // Get meta key name
476
+ $meta_key = ( isset($raw_headers[$key]) ) ? $raw_headers[$key] : $key;
477
+ $meta_key = trim(str_replace('meta:', '', $meta_key));
478
+
479
+ // Add to postmeta array
480
+ $postmeta[] = array(
481
+ 'key' => esc_attr($meta_key),
482
+ 'value' => $value,
483
+ );
484
+ }
485
+ }
486
+
487
+ $order_shipping_methods = array();
488
+ $_shipping_methods = array();
489
+
490
+ // pre WC 2.1 format of a single shipping method, left for backwards compatibility of import files
491
+ if (isset($item['shipping_method']) && $item['shipping_method']) {
492
+ // collect the shipping method id/cost
493
+ $_shipping_methods[] = array(
494
+ $item['shipping_method'],
495
+ isset($item['shipping_cost']) ? $item['shipping_cost'] : null
496
+ );
497
+ }
498
+
499
+ // collect any additional shipping methods
500
+ $i = null;
501
+ if (isset($item['shipping_method_1'])) {
502
+ $i = 1;
503
+ } elseif (isset($item['shipping_method_2'])) {
504
+ $i = 2;
505
+ }
506
+
507
+ if (!is_null($i)) {
508
+ while (!empty($item['shipping_method_' . $i])) {
509
+
510
+ $_shipping_methods[] = array(
511
+ $item['shipping_method_' . $i],
512
+ isset($item['shipping_cost_' . $i]) ? $item['shipping_cost_' . $i] : null
513
+ );
514
+ $i++;
515
+ }
516
+ }
517
+
518
+ // if the order shipping total wasn't set, calculate it
519
+ if (!isset($order_shipping)) {
520
+
521
+ $order_shipping = 0;
522
+ foreach ($_shipping_methods as $_shipping_method) {
523
+ $order_shipping += $_shipping_method[1];
524
+ }
525
+ $postmeta[] = array('key' => '_order_shipping' . $column, 'value' => number_format((float) $order_shipping, 2, '.', ''));
526
+ } elseif (isset($order_shipping) && 1 == count($_shipping_methods) && is_null($_shipping_methods[0][1])) {
527
+ // special case: if there was a total order shipping but no cost for the single shipping method, use the total shipping for the order shipping line item
528
+ $_shipping_methods[0][1] = $order_shipping;
529
+ }
530
+
531
+ foreach ($_shipping_methods as $_shipping_method) {
532
+
533
+ // look up shipping method by id or title
534
+ $shipping_method = isset($available_methods[$_shipping_method[0]]) ? $_shipping_method[0] : null;
535
+
536
+ if (!$shipping_method) {
537
+ // try by title
538
+ foreach ($available_methods as $method) {
539
+ if (0 === strcasecmp($method->title, $_shipping_method[0])) {
540
+ $shipping_method = $method->id;
541
+ break; // go with the first one we find
542
+ }
543
+ }
544
+ }
545
+
546
+ if ($shipping_method) {
547
+ //Known shipping method found
548
+ $order_shipping_methods[] = array('method_id' => $shipping_method, 'cost' => $_shipping_method[1], 'title' => $available_methods[$shipping_method]->title);
549
+ } elseif ($csv_export_file && $_shipping_method[0]) {
550
+ //Order CSV Export format, shipping method title with no corresponding shipping method type found, so just use the title
551
+ $order_shipping_methods[] = array('method_id' => '', 'cost' => $_shipping_method[1], 'title' => $_shipping_method[0]);
552
+ } elseif ($_shipping_method[0]) {
553
+ //shipping method but no title
554
+ $order_shipping_methods[] = array('method_id' => $_shipping_method[0], 'cost' => $_shipping_method[1], 'title' => '');
555
+ }
556
+ }
557
+
558
+ $order_items = array();
559
+ if ($csv_export_file) {
560
+ // standard format
561
+ if (!empty($item['line_item_1'])) {
562
+ // one or more order items
563
+ $i = 1;
564
+ while (!empty($item['line_item_' . $i])) {
565
+
566
+ $_item_meta = preg_split("~\\\\.(*SKIP)(*FAIL)|\|~s", $item['line_item_' . $i]);
567
+
568
+ if ($item['line_item_' . $i] && empty($_item_meta)) {
569
+ $_item_meta = explode('|', $item['line_item_' . $i]);
570
+ }
571
+ $name = array_shift($_item_meta);
572
+ $name = substr($name, strpos($name, ":") + 1);
573
+ $unknown_product_name = $name;
574
+ $product_identifier_by_id = array_shift($_item_meta); // product_id:id
575
+ $product_identifier_by_sku = array_shift($_item_meta); // sku
576
+
577
+ $qty = array_shift($_item_meta);
578
+ $qty = substr($qty, strpos($qty, ":") + 1);
579
+ $total = array_shift($_item_meta);
580
+ $total = substr($total, strpos($total, ":") + 1);
581
+
582
+
583
+ // find by id
584
+ if (false !== strpos($product_identifier_by_id, 'product_id:')) {
585
+ // product by product_id
586
+ $product_id = substr($product_identifier_by_id, 11);
587
+
588
+ // not a product
589
+ if (!in_array(get_post_type($product_id), array('product', 'product_variation'))) {
590
+ $product_id = '';
591
+ }
592
+ }
593
+
594
+ if (!$product_id) {
595
+ // find by sku
596
+ $product_sku = substr($product_identifier_by_sku, strpos($product_identifier_by_sku, ":") + 1);
597
+ if ($product_sku)
598
+ $product_id = $wpdb->get_var($wpdb->prepare("SELECT post_id FROM $wpdb->postmeta WHERE meta_key='_sku' AND meta_value=%s LIMIT 1", $product_sku));
599
+ else
600
+ $product_id = '';
601
+ }
602
+
603
+ if (!$allow_unknown_products && !$product_id) {
604
+ // unknown product
605
+ $WF_CSV_Order_Import->hf_order_log_data_change('order-csv-import', sprintf(__('> > Skipped. Unknown order item: %s.', 'wf_order_import_export'), $product_identifier));
606
+ $skipped++;
607
+ $i++;
608
+ continue; // break outer loop
609
+ }
610
+
611
+ // get any additional item meta
612
+ $item_meta = array();
613
+ foreach ($_item_meta as $pair) {
614
+
615
+ // replace any escaped pipes
616
+ $pair = str_replace('\|', '|', $pair);
617
+
618
+ // find the first ':' and split into name-value
619
+ $split = strpos($pair, ':');
620
+ $name = substr($pair, 0, $split);
621
+ $value = substr($pair, $split + 1);
622
+
623
+ $item_meta[$name] = $value;
624
+ }
625
+
626
+ $order_items[] = array('product_id' => $product_id, 'qty' => $qty, 'total' => $total, 'meta' => $item_meta, 'unknown_product_name' => $unknown_product_name);
627
+
628
+ $i++;
629
+ }
630
+ }
631
+ } else {
632
+ //CSV Order Export format
633
+ $sku = $item['item_sku'];
634
+ $qty = $item['item_amount'];
635
+ $total = $item['row_price'];
636
+
637
+ if (!$sku || !$qty || !is_numeric($total)) {
638
+ // invalid item
639
+ $WF_CSV_Order_Import->hf_order_log_data_change('order-csv-import', sprintf(__('> > Row %d - %s - skipped. Missing SKU, quantity or total', 'wf_order_import_export'), $row, $item['order_id']));
640
+ $skipped++;
641
+ unset($item);
642
+ return; // break outer loop
643
+ }
644
+
645
+ // find by sku
646
+ $product_id = $wpdb->get_var($wpdb->prepare("SELECT post_id FROM $wpdb->postmeta WHERE meta_key='_sku' AND meta_value=%s LIMIT 1", $sku));
647
+
648
+ if (!$product_id) {
649
+ // unknown product
650
+ $WF_CSV_Order_Import->hf_order_log_data_change('order-csv-import', sprintf(__('> > Row %d - %s - skipped. Unknown order item: %s.', 'wf_order_import_export'), $row, $item['order_id'], $sku));
651
+ $skipped++;
652
+ unset($item);
653
+ return; // break outer loop
654
+ }
655
+
656
+ $order_items[] = array('product_id' => $product_id, 'qty' => $qty, 'total' => $total);
657
+ }
658
+
659
+ $tax_items = array();
660
+
661
+ // standard tax item format which supports multiple tax items in numbered columns containing a pipe-delimated, colon-labeled format
662
+ if (!empty($item['tax_item_1']) || !empty($item['tax_item'])) {
663
+ // one or more order tax items
664
+ // get the first tax item
665
+ $tax_item = !empty($item['tax_item_1']) ? $item['tax_item_1'] : $item['tax_item'];
666
+
667
+ $i = 1;
668
+ $tax_amount_sum = $shipping_tax_amount_sum = 0;
669
+ while ($tax_item) {
670
+
671
+ $tax_item_data = array();
672
+
673
+ // turn "label: Tax | tax_amount: 10" into an associative array
674
+ foreach (explode('|', $tax_item) as $piece) {
675
+ list( $name, $value ) = explode(':', $piece);
676
+ $tax_item_data[trim($name)] = trim($value);
677
+ }
678
+
679
+ // default rate id to 0 if not set
680
+ if (!isset($tax_item_data['rate_id'])) {
681
+ $tax_item_data['rate_id'] = 0;
682
+ }
683
+
684
+ // have a tax amount or shipping tax amount
685
+ if (isset($tax_item_data['tax_amount']) || isset($tax_item_data['shipping_tax_amount'])) {
686
+
687
+ // try and look up rate id by label if needed
688
+ if (isset($tax_item_data['label']) && $tax_item_data['label'] && !$tax_item_data['rate_id']) {
689
+ foreach ($tax_rates as $tax_rate) {
690
+
691
+ if (0 === strcasecmp($tax_rate->tax_rate_name, $tax_item_data['label'])) {
692
+ // found the tax by label
693
+ $tax_item_data['rate_id'] = $tax_rate->tax_rate_id;
694
+ break;
695
+ }
696
+ }
697
+ }
698
+
699
+ // check for a rate being specified which does not exist, and clear it out (technically an error?)
700
+ if ($tax_item_data['rate_id'] && !isset($tax_rates[$tax_item_data['rate_id']])) {
701
+ $tax_item_data['rate_id'] = 0;
702
+ }
703
+
704
+ // default label of 'Tax' if not provided
705
+ if (!isset($tax_item_data['label']) || !$tax_item_data['label']) {
706
+ $tax_item_data['label'] = 'Tax';
707
+ }
708
+
709
+ // default tax amounts to 0 if not set
710
+ if (!isset($tax_item_data['tax_amount'])) {
711
+ $tax_item_data['tax_amount'] = 0;
712
+ }
713
+ if (!isset($tax_item_data['shipping_tax_amount'])) {
714
+ $tax_item_data['shipping_tax_amount'] = 0;
715
+ }
716
+
717
+ // handle compound flag by using the defined tax rate value (if any)
718
+ if (!isset($tax_item_data['tax_rate_compound'])) {
719
+ $tax_item_data['tax_rate_compound'] = '';
720
+ if ($tax_item_data['rate_id']) {
721
+ $tax_item_data['tax_rate_compound'] = $tax_rates[$tax_item_data['rate_id']]->tax_rate_compound;
722
+ }
723
+ }
724
+
725
+ $tax_items[] = array(
726
+ 'title' => '',
727
+ 'rate_id' => $tax_item_data['rate_id'],
728
+ 'label' => $tax_item_data['label'],
729
+ 'compound' => $tax_item_data['tax_rate_compound'],
730
+ 'tax_amount' => $tax_item_data['tax_amount'],
731
+ 'shipping_tax_amount' => $tax_item_data['shipping_tax_amount'],
732
+ );
733
+
734
+ // sum up the order totals, in case it wasn't part of the import
735
+ $tax_amount_sum += $tax_item_data['tax_amount'];
736
+ $shipping_tax_amount_sum += $tax_item_data['shipping_tax_amount'];
737
+ }
738
+
739
+ // get the next tax item (if any)
740
+ $i++;
741
+ $tax_item = isset($item['tax_item_' . $i]) ? $item['tax_item_' . $i] : null;
742
+ }
743
+
744
+ if (!is_numeric($order_tax)) {
745
+ $order_tax = $tax_amount_sum;
746
+ }
747
+ if (!is_numeric($order_shipping_tax)) {
748
+ $order_shipping_tax = $shipping_tax_amount_sum;
749
+ }
750
+ }
751
+
752
+ // default to zero if not set
753
+ if (!is_numeric($order_tax)) {
754
+ $order_tax = 0;
755
+ }
756
+ if (!is_numeric($order_shipping_tax)) {
757
+ $order_shipping_tax = 0;
758
+ }
759
+
760
+ // no tax items specified, so create a default one using the tax totals
761
+ if (0 == count($tax_items)) {
762
+
763
+ $tax_items[] = array(
764
+ 'title' => '',
765
+ 'rate_id' => 0,
766
+ 'label' => 'Tax',
767
+ 'compound' => '',
768
+ 'tax_amount' => $order_tax,
769
+ 'shipping_tax_amount' => $order_shipping_tax,
770
+ );
771
+ }
772
+
773
+ // add the order tax totals to the order meta
774
+ $postmeta[] = array('key' => '_order_tax', 'value' => number_format((float) $order_tax, 2, '.', ''));
775
+ $postmeta[] = array('key' => '_order_shipping_tax', 'value' => number_format((float) $order_shipping_tax, 2, '.', ''));
776
+
777
+
778
+ if ($order) {
779
+ $order['postmeta'] = $postmeta;
780
+ $order['order_items'] = $order_items;
781
+ $order['order_shipping'] = $order_shipping_methods;
782
+ $order['tax_items'] = $tax_items;
783
+
784
+ // the order array will now contain the necessary name-value pairs for the wp_posts table, and also any meta data in the 'postmeta' array
785
+ $results[] = $order;
786
+ }
787
+ // Result
788
+ return array(
789
+ $this->post_type => $results,
790
+ 'skipped' => $skipped,
791
+ );
792
+ }
793
+
794
+ private function wc_get_order_statuses_neat() {
795
+
796
+ $order_statuses = array();
797
+
798
+ foreach (wc_get_order_statuses() as $slug => $name) {
799
+ $order_statuses[preg_replace('/^wc-/', '', $slug)] = $name;
800
+ }
801
+
802
+ return $order_statuses;
803
+ }
804
+
805
+ }
includes/importer/class-wf-orderimpexpcsv-importer.php CHANGED
@@ -1,41 +1,41 @@
1
- <?php
2
- if ( ! defined( 'ABSPATH' ) ) {
3
- exit;
4
- }
5
-
6
- class WF_OrderImpExpCsv_Importer {
7
-
8
- /**
9
- * Order Exporter Tool
10
- */
11
- public static function load_wp_importer() {
12
- // Load Importer API
13
- require_once ABSPATH . 'wp-admin/includes/import.php';
14
-
15
- if ( ! class_exists( 'WP_Importer' ) ) {
16
- $class_wp_importer = ABSPATH . 'wp-admin/includes/class-wp-importer.php';
17
- if ( file_exists( $class_wp_importer ) ) {
18
- require $class_wp_importer;
19
- }
20
- }
21
- }
22
-
23
- /**
24
- * Order Importer Tool
25
- */
26
- public static function order_importer() {
27
- if ( ! defined( 'WP_LOAD_IMPORTERS' ) ) {
28
- return;
29
- }
30
-
31
- self::load_wp_importer();
32
-
33
- // includes
34
- require_once 'class-wf-orderimpexpcsv-order-import.php';
35
- require_once 'class-wf-csv-parser.php';
36
-
37
- // Dispatch
38
- $GLOBALS['WF_CSV_Order_Import'] = new WF_OrderImpExpCsv_Order_Import();
39
- $GLOBALS['WF_CSV_Order_Import'] ->dispatch();
40
- }
41
  }
1
+ <?php
2
+ if ( ! defined( 'ABSPATH' ) ) {
3
+ exit;
4
+ }
5
+
6
+ class WF_OrderImpExpCsv_Importer {
7
+
8
+ /**
9
+ * Order Exporter Tool
10
+ */
11
+ public static function load_wp_importer() {
12
+ // Load Importer API
13
+ require_once ABSPATH . 'wp-admin/includes/import.php';
14
+
15
+ if ( ! class_exists( 'WP_Importer' ) ) {
16
+ $class_wp_importer = ABSPATH . 'wp-admin/includes/class-wp-importer.php';
17
+ if ( file_exists( $class_wp_importer ) ) {
18
+ require $class_wp_importer;
19
+ }
20
+ }
21
+ }
22
+
23
+ /**
24
+ * Order Importer Tool
25
+ */
26
+ public static function order_importer() {
27
+ if ( ! defined( 'WP_LOAD_IMPORTERS' ) ) {
28
+ return;
29
+ }
30
+
31
+ self::load_wp_importer();
32
+
33
+ // includes
34
+ require_once 'class-wf-orderimpexpcsv-order-import.php';
35
+ require_once 'class-wf-csv-parser.php';
36
+
37
+ // Dispatch
38
+ $GLOBALS['WF_CSV_Order_Import'] = new WF_OrderImpExpCsv_Order_Import();
39
+ $GLOBALS['WF_CSV_Order_Import'] ->dispatch();
40
+ }
41
  }
includes/importer/class-wf-orderimpexpcsv-order-import.php CHANGED
@@ -1,901 +1,901 @@
1
- <?php
2
- /**
3
- * WordPress Importer class for managing the import process of a CSV file
4
- *
5
- * @package WordPress
6
- * @subpackage Importer
7
- */
8
- if ( ! class_exists( 'WP_Importer' ) )
9
- return;
10
-
11
- class WF_OrderImpExpCsv_Order_Import extends WP_Importer {
12
-
13
- var $id;
14
- var $file_url;
15
- var $delimiter;
16
-
17
- var $merge_empty_cells;
18
-
19
- // mappings from old information to new
20
- var $processed_terms = array();
21
- var $processed_posts = array();
22
-
23
- var $merged = 0;
24
- var $skipped = 0;
25
- var $imported = 0;
26
- var $errored = 0;
27
-
28
- // Results
29
- var $import_results = array();
30
-
31
- /**
32
- * Constructor
33
- */
34
- public function __construct() {
35
-
36
- if (WC()->version < '2.7.0') {
37
- $this->log = new WC_Logger();
38
- } else {
39
- $this->log = wc_get_logger();
40
- }
41
- $this->import_page = 'woocommerce_wf_order_csv';
42
- $this->file_url_import_enabled = apply_filters( 'woocommerce_csv_product_file_url_import_enabled', true );
43
- }
44
-
45
- /**
46
- * Registered callback function for the WordPress Importer
47
- *
48
- * Manages the three separate stages of the CSV import process
49
- */
50
- public function dispatch() {
51
- global $woocommerce, $wpdb;
52
-
53
- if ( ! empty( $_POST['delimiter'] ) ) {
54
- $this->delimiter = stripslashes( trim( $_POST['delimiter'] ) );
55
- }else if ( ! empty( $_GET['delimiter'] ) ) {
56
- $this->delimiter = stripslashes( trim( $_GET['delimiter'] ) );
57
- }
58
-
59
- if ( ! $this->delimiter )
60
- $this->delimiter = ',';
61
-
62
- if ( ! empty( $_POST['merge_empty_cells'] ) || ! empty( $_GET['merge_empty_cells'] ) ) {
63
- $this->merge_empty_cells = 1;
64
- } else{
65
- $this->merge_empty_cells = 0;
66
- }
67
-
68
- $step = empty( $_GET['step'] ) ? 0 : (int) $_GET['step'];
69
-
70
- switch ( $step ) {
71
- case 0 :
72
- $this->header();
73
- $this->greet();
74
- break;
75
- case 1 :
76
- $this->header();
77
-
78
- check_admin_referer( 'import-upload' );
79
-
80
- if(!empty($_GET['file_url']))
81
- $this->file_url = esc_attr( $_GET['file_url'] );
82
- if(!empty($_GET['file_id']))
83
- $this->id = $_GET['file_id'] ;
84
-
85
- if ( !empty($_GET['clearmapping']) || $this->handle_upload() )
86
- $this->import_options();
87
- else
88
- _e( 'Error with handle_upload!', 'wf_order_import_export' );
89
- break;
90
- case 2 :
91
- $this->header();
92
-
93
- check_admin_referer( 'import-woocommerce' );
94
-
95
- $this->id = (int) $_POST['import_id'];
96
-
97
- if ( $this->file_url_import_enabled )
98
- $this->file_url = esc_attr( $_POST['import_url'] );
99
-
100
- if ( $this->id )
101
- $file = get_attached_file( $this->id );
102
- else if ( $this->file_url_import_enabled )
103
- $file = ABSPATH . $this->file_url;
104
-
105
- $file = str_replace( "\\", "/", $file );
106
-
107
- if ( $file ) {
108
- ?>
109
- <table id="import-progress" class="widefat_importer widefat">
110
- <thead>
111
- <tr>
112
- <th class="status">&nbsp;</th>
113
- <th class="row"><?php _e( 'Row', 'wf_order_import_export' ); ?></th>
114
- <th><?php _e( 'OrderID', 'wf_order_import_export' ); ?></th>
115
- <th><?php _e( 'Order Status', 'wf_order_import_export' ); ?></th>
116
- <th class="reason"><?php _e( 'Status Msg', 'wf_order_import_export' ); ?></th>
117
- </tr>
118
- </thead>
119
- <tfoot>
120
- <tr class="importer-loading">
121
- <td colspan="5"></td>
122
- </tr>
123
- </tfoot>
124
- <tbody></tbody>
125
- </table>
126
- <script type="text/javascript">
127
- jQuery(document).ready(function($) {
128
-
129
- if ( ! window.console ) { window.console = function(){}; }
130
-
131
- var processed_terms = [];
132
- var processed_posts = [];
133
- var i = 1;
134
- var done_count = 0;
135
-
136
- function import_rows( start_pos, end_pos ) {
137
-
138
- var data = {
139
- action: 'woocommerce_csv_order_import_request',
140
- file: '<?php echo addslashes( $file ); ?>',
141
- delimiter: '<?php echo $this->delimiter; ?>',
142
- merge_empty_cells: '<?php echo $this->merge_empty_cells; ?>',
143
- start_pos: start_pos,
144
- end_pos: end_pos,
145
- };
146
- return $.ajax({
147
- url: '<?php echo add_query_arg( array( 'import_page' => $this->import_page, 'step' => '3', 'merge' => ! empty( $_GET['merge'] ) ? '1' : '0' ), admin_url( 'admin-ajax.php' ) ); ?>',
148
- data: data,
149
- type: 'POST',
150
- success: function( response ) {
151
- if ( response ) {
152
-
153
- try {
154
- // Get the valid JSON only from the returned string
155
- if ( response.indexOf("<!--WC_START-->") >= 0 )
156
- response = response.split("<!--WC_START-->")[1]; // Strip off before after WC_START
157
-
158
- if ( response.indexOf("<!--WC_END-->") >= 0 )
159
- response = response.split("<!--WC_END-->")[0]; // Strip off anything after WC_END
160
-
161
- // Parse
162
- var results = $.parseJSON( response );
163
-
164
- if ( results.error ) {
165
-
166
- $('#import-progress tbody').append( '<tr id="row-' + i + '" class="error"><td class="status" colspan="5">' + results.error + '</td></tr>' );
167
-
168
- i++;
169
-
170
- } else if ( results.import_results && $( results.import_results ).size() > 0 ) {
171
-
172
- $.each( results.processed_terms, function( index, value ) {
173
- processed_terms.push( value );
174
- });
175
-
176
- $.each( results.processed_posts, function( index, value ) {
177
- processed_posts.push( value );
178
- });
179
-
180
-
181
-
182
- $( results.import_results ).each(function( index, row ) {
183
- $('#import-progress tbody').append( '<tr id="row-' + i + '" class="' + row['status'] + '"><td><mark class="result" title="' + row['status'] + '">' + row['status'] + '</mark></td><td class="row">' + i + '</td><td>' + row['order_number'] + '</td><td>' + row['post_id'] + ' - ' + row['post_title'] + '</td><td class="reason">' + row['reason'] + '</td></tr>' );
184
-
185
- i++;
186
- });
187
- }
188
-
189
- } catch(err) {}
190
-
191
- } else {
192
- $('#import-progress tbody').append( '<tr class="error"><td class="status" colspan="5">' + '<?php _e( 'AJAX Error', 'wf_order_import_export' ); ?>' + '</td></tr>' );
193
- }
194
-
195
- var w = $(window);
196
- var row = $( "#row-" + ( i - 1 ) );
197
-
198
- if ( row.length ) {
199
- w.scrollTop( row.offset().top - (w.height()/2) );
200
- }
201
-
202
- done_count++;
203
-
204
- $('body').trigger( 'woocommerce_csv_order_import_request_complete' );
205
- }
206
- });
207
- }
208
-
209
- var rows = [];
210
-
211
- <?php
212
- $limit = apply_filters( 'woocommerce_csv_import_limit_per_request', 10 );
213
- $enc = mb_detect_encoding( $file, 'UTF-8, ISO-8859-1', true );
214
- if ( $enc )
215
- setlocale( LC_ALL, 'en_US.' . $enc );
216
- @ini_set( 'auto_detect_line_endings', true );
217
-
218
- $count = 0;
219
- $previous_position = 0;
220
- $position = 0;
221
- $import_count = 0;
222
-
223
- // Get CSV positions
224
- if ( ( $handle = fopen( $file, "r" ) ) !== FALSE ) {
225
-
226
- while ( ( $postmeta = fgetcsv( $handle, 0, $this->delimiter , '"', '"' ) ) !== FALSE ) {
227
- $count++;
228
-
229
- if ( $count >= $limit ) {
230
- $previous_position = $position;
231
- $position = ftell( $handle );
232
- $count = 0;
233
- $import_count ++;
234
-
235
- // Import rows between $previous_position $position
236
- ?>rows.push( [ <?php echo $previous_position; ?>, <?php echo $position; ?> ] ); <?php
237
- }
238
- }
239
-
240
- // Remainder
241
- if ( $count > 0 ) {
242
- ?>rows.push( [ <?php echo $position; ?>, '' ] ); <?php
243
- $import_count ++;
244
- }
245
-
246
- fclose( $handle );
247
- }
248
- ?>
249
-
250
- var data = rows.shift();
251
- var regen_count = 0;
252
- import_rows( data[0], data[1] );
253
-
254
- $('body').on( 'woocommerce_csv_order_import_request_complete', function() {
255
- if ( done_count == <?php echo $import_count; ?> ) {
256
-
257
- import_done();
258
- } else {
259
- // Call next request
260
- data = rows.shift();
261
- import_rows( data[0], data[1] );
262
- }
263
- } );
264
-
265
- function import_done() {
266
- var data = {
267
- action: 'woocommerce_csv_order_import_request',
268
- file: '<?php echo $file; ?>',
269
- processed_terms: processed_terms,
270
- processed_posts: processed_posts,
271
- };
272
-
273
- $.ajax({
274
- url: '<?php echo add_query_arg( array( 'import_page' => $this->import_page, 'step' => '4', 'merge' => ! empty( $_GET['merge'] ) ? 1 : 0 ), admin_url( 'admin-ajax.php' ) ); ?>',
275
- data: data,
276
- type: 'POST',
277
- success: function( response ) {
278
- //console.log( response );
279
- $('#import-progress tbody').append( '<tr class="complete"><td colspan="5">' + response + '</td></tr>' );
280
- $('.importer-loading').hide();
281
- }
282
- });
283
- }
284
- });
285
- </script>
286
- <?php
287
- } else {
288
- echo '<p class="error">' . __( 'Error finding uploaded file!', 'wf_order_import_export' ) . '</p>';
289
- }
290
- break;
291
- case 3 :
292
- // Check access - cannot use nonce here as it will expire after multiple requests
293
- if ( ! current_user_can( 'manage_woocommerce' ) )
294
- die();
295
-
296
- add_filter( 'http_request_timeout', array( $this, 'bump_request_timeout' ) );
297
-
298
- if ( function_exists( 'gc_enable' ) )
299
- gc_enable();
300
-
301
- @set_time_limit(0);
302
- @ob_flush();
303
- @flush();
304
- $wpdb->hide_errors();
305
-
306
- $file = stripslashes( $_POST['file'] );
307
-
308
- $start_pos = isset( $_POST['start_pos'] ) ? absint( $_POST['start_pos'] ) : 0;
309
- $end_pos = isset( $_POST['end_pos'] ) ? absint( $_POST['end_pos'] ) : '';
310
-
311
-
312
-
313
- $position = $this->import_start( $file, $start_pos, $end_pos );
314
- $this->import();
315
- $this->import_end();
316
-
317
- $results = array();
318
- $results['import_results'] = $this->import_results;
319
- $results['processed_terms'] = $this->processed_terms;
320
- $results['processed_posts'] = $this->processed_posts;
321
-
322
- echo "<!--WC_START-->";
323
- echo json_encode( $results );
324
- echo "<!--WC_END-->";
325
- exit;
326
- break;
327
- case 4 :
328
- // Check access - cannot use nonce here as it will expire after multiple requests
329
- if ( ! current_user_can( 'manage_woocommerce' ) )
330
- die();
331
-
332
- add_filter( 'http_request_timeout', array( $this, 'bump_request_timeout' ) );
333
-
334
- if ( function_exists( 'gc_enable' ) )
335
- gc_enable();
336
-
337
- @set_time_limit(0);
338
- @ob_flush();
339
- @flush();
340
- $wpdb->hide_errors();
341
-
342
- $this->processed_terms = isset( $_POST['processed_terms'] ) ? $_POST['processed_terms'] : array();
343
- $this->processed_posts = isset( $_POST['processed_posts']) ? $_POST['processed_posts'] : array();
344
-
345
- _e( 'Step 1...', 'wf_order_import_export' ) . ' ';
346
-
347
- wp_defer_term_counting( true );
348
- wp_defer_comment_counting( true );
349
-
350
- _e( 'Step 2...', 'wf_order_import_export' ) . ' ';
351
-
352
- echo 'Step 3...' . ' '; // Easter egg
353
-
354
- _e( 'Finalizing...', 'wf_order_import_export' ) . ' ';
355
-
356
- // SUCCESS
357
- _e( 'Finished. Import complete.', 'wf_order_import_export' );
358
-
359
- $this->import_end();
360
- exit;
361
- break;
362
- }
363
-
364
- $this->footer();
365
- }
366
-
367
- /**
368
- * format_data_from_csv
369
- */
370
- public function format_data_from_csv( $data, $enc ) {
371
- return ( $enc == 'UTF-8' ) ? $data : utf8_encode( $data );
372
- }
373
-
374
- /**
375
- * Display pre-import options
376
- */
377
- public function import_options() {
378
- $j = 0;
379
-
380
- if ( $this->id )
381
- $file = get_attached_file( $this->id );
382
- else if ( $this->file_url_import_enabled )
383
- $file = ABSPATH . $this->file_url;
384
- else
385
- return;
386
-
387
- // Set locale
388
- $enc = mb_detect_encoding( $file, 'UTF-8, ISO-8859-1', true );
389
- if ( $enc ) setlocale( LC_ALL, 'en_US.' . $enc );
390
- @ini_set( 'auto_detect_line_endings', true );
391
-
392
- // Get headers
393
- if ( ( $handle = fopen( $file, "r" ) ) !== FALSE ) {
394
-
395
- $row = $raw_headers = array();
396
- $header = fgetcsv( $handle, 0, $this->delimiter , '"', '"' );
397
-
398
- while ( ( $postmeta = fgetcsv( $handle, 0, $this->delimiter , '"', '"' ) ) !== FALSE ) {
399
- foreach ( $header as $key => $heading ) {
400
- if ( ! $heading ) continue;
401
- $s_heading = $heading;
402
- $row[$s_heading] = ( isset( $postmeta[$key] ) ) ? $this->format_data_from_csv( $postmeta[$key], $enc ) : '';
403
- $raw_headers[ $s_heading ] = $heading;
404
- }
405
- break;
406
- }
407
- fclose( $handle );
408
- }
409
-
410
- $merge = (!empty($_GET['merge']) && $_GET['merge']) ? 1 : 0;
411
-
412
- include( 'views/html-wf-import-options.php' );
413
- }
414
-
415
- /**
416
- * The main controller for the actual import stage.
417
- */
418
- public function import() {
419
- global $woocommerce, $wpdb;
420
-
421
- wp_suspend_cache_invalidation( true );
422
- $this->hf_order_log_data_change('order-csv-import', '---' );
423
- $this->hf_order_log_data_change('order-csv-import', __( 'Processing orders.', 'wf_order_import_export' ) );
424
- $merging = 1;
425
- $record_offset = 0;
426
- foreach ( $this->parsed_data as $key => &$item ) {
427
- $order = $this->parser->parse_orders( $item, $this->raw_headers, $merging, $record_offset );
428
- if ( ! is_wp_error( $order ) )
429
- $this->process_orders( $order['shop_order'][0] );
430
- else
431
- $this->add_import_result( 'failed', $order->get_error_message(), 'Not parsed', json_encode( $item ), '-' );
432
-
433
- unset( $item, $order );
434
-
435
- }
436
-
437
- $this->hf_order_log_data_change('order-csv-import', __( 'Finished processing Orders.', 'wf_order_import_export' ) );
438
- wp_suspend_cache_invalidation( false );
439
- }
440
-
441
- /**
442
- * Parses the CSV file and prepares us for the task of processing parsed data
443
- *
444
- * @param string $file Path to the CSV file for importing
445
- */
446
- public function import_start( $file, $start_pos, $end_pos ) {
447
-
448
- $memory = size_format( (WC()->version < '2.7.0')?woocommerce_let_to_num( ini_get( 'memory_limit' ) ):wc_let_to_num( ini_get( 'memory_limit' ) ) );
449
- $wp_memory = size_format( (WC()->version < '2.7.0')? woocommerce_let_to_num( WP_MEMORY_LIMIT ) : wc_let_to_num( WP_MEMORY_LIMIT ) );
450
-
451
- $this->hf_order_log_data_change('order-csv-import', '---[ New Import ] PHP Memory: ' . $memory . ', WP Memory: ' . $wp_memory );
452
- $this->hf_order_log_data_change('order-csv-import', __( 'Parsing products CSV.', 'wf_order_import_export' ) );
453
-
454
- $this->parser = new WF_CSV_Parser( 'shop_order' );
455
-
456
- list( $this->parsed_data, $this->raw_headers, $position ) = $this->parser->parse_data( $file, $this->delimiter, $start_pos, $end_pos );
457
-
458
- $this->hf_order_log_data_change('order-csv-import', __( 'Finished parsing products CSV.', 'wf_order_import_export' ) );
459
-
460
- unset( $import_data );
461
-
462
- wp_defer_term_counting( true );
463
- wp_defer_comment_counting( true );
464
-
465
- return $position;
466
- }
467
-
468
- /**
469
- * Performs post-import cleanup of files and the cache
470
- */
471
- public function import_end() {
472
-
473
- //wp_cache_flush(); Stops output in some hosting environments
474
- foreach ( get_taxonomies() as $tax ) {
475
- delete_option( "{$tax}_children" );
476
- _get_term_hierarchy( $tax );
477
- }
478
-
479
- wp_defer_term_counting( false );
480
- wp_defer_comment_counting( false );
481
-
482
- do_action( 'import_end' );
483
- }
484
-
485
- /**
486
- * Handles the CSV upload and initial parsing of the file to prepare for
487
- * displaying author import options
488
- *
489
- * @return bool False if error uploading or invalid file, true otherwise
490
- */
491
- public function handle_upload() {
492
- if ( empty( $_POST['file_url'] ) ) {
493
-
494
- $file = wp_import_handle_upload();
495
-
496
- if ( isset( $file['error'] ) ) {
497
- echo '<p><strong>' . __( 'Sorry, there has been an error.', 'wf_order_import_export' ) . '</strong><br />';
498
- echo esc_html( $file['error'] ) . '</p>';
499
- return false;
500
- }
501
-
502
- $this->id = (int) $file['id'];
503
- return true;
504
-
505
- } else {
506
-
507
- if ( file_exists( ABSPATH . $_POST['file_url'] ) ) {
508
-
509
- $this->file_url = esc_attr( $_POST['file_url'] );
510
- return true;
511
-
512
- } else {
513
-
514
- echo '<p><strong>' . __( 'Sorry, there has been an error.', 'wf_order_import_export' ) . '</strong></p>';
515
- return false;
516
-
517
- }
518
-
519
- }
520
-
521
- return false;
522
- }
523
-
524
- public function order_exists($orderID) {
525
- global $wpdb;
526
- $query = "SELECT ID FROM $wpdb->posts WHERE post_type = 'shop_order' AND post_status IN ( 'wc-pending', 'wc-processing', 'wc-completed', 'wc-on-hold', 'wc-failed' , 'wc-refunded', 'wc-cancelled')";
527
- $args = array();
528
- $posts_are_exist = @$wpdb->get_col($wpdb->prepare($query, $args));
529
-
530
- if ($posts_are_exist) {
531
- foreach ($posts_are_exist as $exist_id) {
532
- $found = false;
533
- if ($exist_id == $orderID) {
534
- $found = TRUE;
535
- }
536
- if($found) return TRUE;
537
- }
538
- } else {
539
- return FALSE;
540
- }
541
- }
542
- /**
543
- * Create new posts based on import information
544
- */
545
- private function process_orders($post) {
546
-
547
- global $wpdb;
548
- $this->imported = $this->merged = 0;
549
- $merging = ( ! empty( $_GET['merge'] )) ? 1 : 0 ;
550
-
551
- // plan a dry run
552
- //$dry_run = isset( $_POST['dry_run'] ) && $_POST['dry_run'] ? true : false;
553
- $dry_run = FALSE;
554
-
555
- $this->hf_order_log_data_change('order-csv-import', '---' );
556
- $this->hf_order_log_data_change('order-csv-import', __( 'Processing orders.', 'wf_order_import_export' ) );
557
-
558
- // check class-wc-checkout.php for reference
559
-
560
- $order_data = array(
561
- 'import_id' => $post['order_number'], //Suggest import to keep the given ID
562
- 'post_date' => date( 'Y-m-d H:i:s', $post['date'] ),
563
- 'post_type' => 'shop_order',
564
- 'post_title' => 'Order &ndash; ' . date( 'F j, Y @ h:i A', $post['date'] ),
565
- 'post_status' => 'wc-' . preg_replace( '/^wc-/', '', $post['status'] ),
566
- 'ping_status' => 'closed',
567
- 'post_excerpt' => isset($post['order_comments'])?($post['order_comments']):'',
568
- 'post_author' => 1,
569
- 'post_password' => uniqid( 'order_' ), // Protects the post just in case
570
- );
571
-
572
- if ( ! $dry_run ) {
573
- // track whether download permissions need to be granted
574
- $add_download_permissions = false;
575
-
576
-
577
- // Check if post exists when importing
578
- $new_added = false;
579
- $is_order_exist = $this->order_exists($post['order_number']);
580
- $meta_array = array();
581
- if (!empty($post['postmeta'])) {
582
- foreach ($post['postmeta'] as $meta) {
583
- $meta_array[$meta['key']] = $meta['value'];
584
- }
585
- }
586
-
587
- $user_id = $this->hf_check_customer($meta_array);
588
- if (is_wp_error($user_id)) {
589
- $this->hf_order_log_data_change('order-csv-import', __($user_id->get_error_message(), 'wf_order_import_export'));
590
- $this->add_import_result('skipped', __($user_id->get_error_message(), 'wf_order_import_export'), $post['order_number'], $post['order_number'], $post['order_number']);
591
- $skipped++;
592
- unset($post);
593
- return;
594
- } elseif (empty($user_id)) {
595
- $user_id = 0;
596
- }
597
-
598
-
599
- if (!$merging && $is_order_exist) {
600
- $usr_msg = 'Order already exists.';
601
- $this->add_import_result('skipped', __($usr_msg, 'wf_order_import_export'), $post['order_number'], $order_data['post_title'], $post['order_number']);
602
- $this->hf_order_log_data_change('order-csv-import', sprintf(__('> &#8220;%s&#8221;' . $usr_msg, 'wf_order_import_export'), esc_html($order_data['post_title'])), true);
603
- unset($post);
604
- return;
605
- }
606
- else{
607
- if($is_order_exist) {
608
- $order_id = $post['order_number'];
609
- $wp_result = wp_update_post($order_data);
610
- } else {
611
- $order_id = wp_insert_post($order_data);
612
- $new_added = true;
613
- if ( is_wp_error( $order_id ) ) {
614
- $this->errored++;
615
- $new_added = false;
616
- //$this->add_import_result('failed', __($order_id->get_error_message() , 'wf_order_import_export'), $post['order_number'], $order_data['post_title'], $post['order_number']);
617
- $this->hf_order_log_data_change('order-csv-import', sprintf( __( '> Error inserting %s: %s', 'wf_order_import_export'), $post['order_number'], $order_id->get_error_message() ), true );
618
- }
619
-
620
- }
621
-
622
-
623
- }
624
- // empty update to bump up the post_modified date to today's date (otherwise it would match the post_date, which isn't quite right)
625
- //wp_update_post( array( 'ID' => $order_id ) );
626
-
627
- // handle special meta fields
628
- $order_currency = (isset($post['order_currency']) && $post['order_currency']) ? $post['order_currency'] : get_woocommerce_currency();
629
- update_post_meta( $order_id, '_order_key', apply_filters( 'woocommerce_generate_order_key', uniqid( 'order_' ) ) );
630
- update_post_meta( $order_id, '_order_currency', $order_currency );
631
- update_post_meta( $order_id, '_prices_include_tax', get_option( 'woocommerce_prices_include_tax' ) );
632
- update_post_meta( $order_id, '_order_number', $post['order_number'] );
633
- // add order postmeta
634
- foreach ( $post['postmeta'] as $meta ) {
635
- $meta_processed = false;
636
-
637
- // we don't set the "download permissions granted" meta, we call the woocommerce function to take care of this for us
638
- if ( ( 'Download Permissions Granted' == $meta['key'] || '_download_permissions_granted' == $meta['key'] ) && $meta['value'] ) {
639
- $add_download_permissions = true;
640
- $meta_processed = true;
641
- }
642
-
643
- if (( '_customer_user' == $meta['key'])) {
644
- update_post_meta($order_id, $meta['key'], $user_id);
645
- $meta_processed = true;
646
- }
647
-
648
- if ( ! $meta_processed ) {
649
- update_post_meta( $order_id, $meta['key'], $meta['value'] );
650
- }
651
-
652
- // set the paying customer flag on the user meta if applicable
653
- if ( '_customer_id' == $meta['key'] && $user_id && in_array( $post['status'], array( 'processing', 'completed', 'refunded' ) ) ) {
654
- update_user_meta( $user_id, "paying_customer", 1 );
655
- }
656
- }
657
-
658
-
659
- // handle order items
660
- $order_items = array();
661
- $order_item_meta = null;
662
-
663
- foreach ( $post['order_items'] as $item ) {
664
-
665
- $product = null;
666
- $variation_item_meta = array();
667
-
668
- if ( $item['product_id'] ) {
669
- $product = wc_get_product( $item['product_id'] );
670
-
671
- // handle variations
672
- if ( $product && ( $product->is_type( 'variable' ) || $product->is_type( 'variation' ) || $product->is_type( 'subscription_variation' ) ) && method_exists( $product, 'get_variation_id' ) ) {
673
- foreach ( $product->get_variation_attributes() as $key => $value ) {
674
- $variation_item_meta[] = array( 'meta_name' => esc_attr( substr( $key, 10 ) ), 'meta_value' => $value ); // remove the leading 'attribute_' from the name to get 'pa_color' for instance
675
- }
676
- }
677
- }
678
-
679
- // order item
680
- $order_items[] = array(
681
- 'order_item_name' => $product ? $product->get_title() : __( 'Unknown Product', 'wf_order_import_export' ),
682
- 'order_item_type' => 'line_item',
683
- );
684
-
685
- $var_id = 0;
686
- if($product){
687
- if (WC()->version < '2.7.0' && method_exists( $product,'get_variation_id' )) {
688
- $var_id = $product->get_variation_id();
689
- }else{
690
- $var_id = $product->get_id();
691
- }
692
- }
693
- // standard order item meta
694
- $_order_item_meta = array(
695
- '_qty' => (int) $item['qty'],
696
- '_tax_class' => '', // Tax class (adjusted by filters)
697
- '_product_id' => $item['product_id'],
698
- '_variation_id' => $var_id,
699
- '_line_subtotal' => number_format( (float) $item['total'], 2, '.', '' ), // Line subtotal (before discounts)
700
- '_line_subtotal_tax' => 0, // Line tax (before discounts)
701
- '_line_total' => number_format( (float) $item['total'], 2, '.', '' ), // Line total (after discounts)
702
- '_line_tax' => 0, // Line Tax (after discounts)
703
- );
704
-
705
- // add any product variation meta
706
- foreach ( $variation_item_meta as $meta ) {
707
- $_order_item_meta[ $meta['meta_name'] ] = $meta['meta_value'];
708
- }
709
-
710
- // include any arbitrary order item meta
711
- $_order_item_meta = array_merge( $_order_item_meta, $item['meta'] );
712
-
713
- $order_item_meta[] = $_order_item_meta;
714
-
715
- }
716
-
717
- foreach ( $order_items as $key => $order_item ) {
718
- $order_item_id = wc_add_order_item( $order_id, $order_item );
719
-
720
- if ( $order_item_id ) {
721
- foreach ( $order_item_meta[ $key ] as $meta_key => $meta_value ) {
722
- wc_add_order_item_meta( $order_item_id, $meta_key, $meta_value );
723
- }
724
- }
725
- }
726
-
727
- // create the shipping order items
728
- foreach ( $post['order_shipping'] as $order_shipping ) {
729
-
730
- $shipping_order_item = array(
731
- 'order_item_name' => ($order_shipping['title']) ? $order_shipping['title'] : $order_shipping['method_id'],
732
- 'order_item_type' => 'shipping',
733
- );
734
-
735
- $shipping_order_item_id = wc_add_order_item( $order_id, $shipping_order_item );
736
-
737
- if ( $shipping_order_item_id ) {
738
- wc_add_order_item_meta( $shipping_order_item_id, 'method_id', $order_shipping['method_id'] );
739
- wc_add_order_item_meta( $shipping_order_item_id, 'cost', $order_shipping['cost'] );
740
- }
741
- }
742
-
743
- // create the tax order items
744
- foreach ( $post['tax_items'] as $tax_item ) {
745
-
746
- $tax_order_item = array(
747
- 'order_item_name' => $tax_item['title'],
748
- 'order_item_type' => 'tax',
749
- );
750
-
751
- $tax_order_item_id = wc_add_order_item( $order_id, $tax_order_item );
752
-
753
- if ( $tax_order_item_id ) {
754
- wc_add_order_item_meta( $tax_order_item_id, 'rate_id', $tax_item['rate_id'] );
755
- wc_add_order_item_meta( $tax_order_item_id, 'label', $tax_item['label'] );
756
- wc_add_order_item_meta( $tax_order_item_id, 'compound', $tax_item['compound'] );
757
- wc_add_order_item_meta( $tax_order_item_id, 'tax_amount', $tax_item['tax_amount'] );
758
- wc_add_order_item_meta( $tax_order_item_id, 'shipping_tax_amount', $tax_item['shipping_tax_amount'] );
759
- }
760
- }
761
-
762
- // Grant downloadalbe product permissions
763
- if ( $add_download_permissions ) {
764
- wc_downloadable_product_permissions( $order_id );
765
- }
766
-
767
- // add order notes
768
- $order = wc_get_order( $order_id );
769
- foreach ( $post['notes'] as $order_note ) {
770
- $order->add_order_note( $order_note );
771
- }
772
-
773
- // record the product sales
774
- if (WC()->version < '2.7.0') {
775
- $order->record_product_sales();
776
- } else {
777
- wc_update_total_sales_counts($order_id);
778
- }
779
- } // ! dry run
780
-
781
- // was an original order number provided?
782
- if ( ! empty( $post['order_number_formatted'] ) ) {
783
- if ( ! $dry_run ) {
784
- // do our best to provide some custom order number functionality while also allowing 3rd party plugins to provide their own custom order number facilities
785
- do_action( 'woocommerce_set_order_number', $order, $post['order_number'], $post['order_number_formatted'] );
786
- $order->add_order_note( sprintf( __( "Original order #%s", 'wf_order_import_export' ), $post['order_number_formatted'] ) );
787
-
788
- // get the order so we can display the correct order number
789
- $order = wc_get_order( $order_id );
790
- }
791
-
792
- $this->processed_posts[ $post['order_number_formatted'] ] = $post['order_number_formatted'];
793
- }
794
- if($merging && !$new_added)
795
- $out_msg = 'Order Successfully updated.';
796
- else
797
- $out_msg = 'Order Imported Successfully.';
798
-
799
- $this->add_import_result('imported', __($out_msg, 'wf_order_import_export'), $order_id, $order_data['post_title'], $order_id);
800
- $this->hf_order_log_data_change('order-csv-import', sprintf(__('> &#8220;%s&#8221;' . $out_msg, 'wf_order_import_export'), esc_html($order_data['post_title'])), true);
801
- $this->imported++;
802
- $this->hf_order_log_data_change( 'order-csv-import', sprintf( __( '> Finished importing order %s', 'wf_order_import_export' ), $dry_run ? "" : $order->get_order_number() ) );
803
-
804
- // }
805
-
806
-
807
- $this->hf_order_log_data_change( 'order-csv-import', __( 'Finished processing orders.', 'wf_order_import_export' ) );
808
-
809
- unset( $post );
810
- }
811
-
812
-
813
- public function hf_check_customer($data) {
814
-
815
- $customer_email = (!empty($data['_customer_email']) ) ? $data['_customer_email'] : '';
816
-
817
- $found_customer = false;
818
- $username = '';
819
-
820
- if (!empty($customer_email)) {
821
-
822
- if (is_email($customer_email) && false !== email_exists($customer_email)) {
823
- $found_customer = email_exists($customer_email);
824
- return $found_customer;
825
- } else {
826
- $found_customer = 0;
827
- }
828
- } else {
829
- $found_customer = 0;
830
- }
831
-
832
- return $found_customer;
833
- }
834
-
835
- /**
836
- * Log a row's import status
837
- */
838
- protected function add_import_result( $status, $reason, $post_id = '', $post_title = '', $order_number = '' ) {
839
- $this->import_results[] = array(
840
- 'post_title' => $post_title,
841
- 'post_id' => $post_id,
842
- 'order_number' => $order_number,
843
- 'status' => $status,
844
- 'reason' => $reason
845
- );
846
- }
847
-
848
-
849
- /**
850
- * Decide what the maximum file size for downloaded attachments is.
851
- * Default is 0 (unlimited), can be filtered via import_attachment_size_limit
852
- *
853
- * @return int Maximum attachment file size to import
854
- */
855
- public function max_attachment_size() {
856
- return apply_filters( 'import_attachment_size_limit', 0 );
857
- }
858
-
859
- // Display import page title
860
- public function header() {
861
- echo '<div class="wrap"><div class="icon32" id="icon-woocommerce-importer"><br></div>';
862
- echo '<h2>' . ( empty( $_GET['merge'] ) ? __( 'Import', 'wf_order_import_export' ) : __( 'Merge Orders', 'wf_order_import_export' ) ) . '</h2>';
863
- }
864
-
865
- // Close div.wrap
866
- public function footer() {
867
- echo '</div>';
868
- }
869
-
870
- /**
871
- * Display introductory text and file upload form
872
- */
873
- public function greet() {
874
- $action = 'admin.php?import=woocommerce_wf_order_csv&amp;step=1&amp;merge=' . ( ! empty( $_GET['merge'] ) ? 1 : 0 );
875
- $bytes = apply_filters( 'import_upload_size_limit', wp_max_upload_size() );
876
- $size = size_format( $bytes );
877
- $upload_dir = wp_upload_dir();
878
- include( 'views/html-wf-import-greeting.php' );
879
- }
880
-
881
- /**
882
- * Added to http_request_timeout filter to force timeout at 60 seconds during import
883
- * @return int 60
884
- */
885
- public function bump_request_timeout( $val ) {
886
- return 60;
887
- }
888
-
889
-
890
- public function hf_order_log_data_change ($content = 'order-csv-import',$data='')
891
- {
892
- if (WC()->version < '2.7.0')
893
- {
894
- $this->log->add($content,$data);
895
- }else
896
- {
897
- $context = array( 'source' => $content );
898
- $this->log->log("debug", $data ,$context);
899
- }
900
- }
901
  }
1
+ <?php
2
+ /**
3
+ * WordPress Importer class for managing the import process of a CSV file
4
+ *
5
+ * @package WordPress
6
+ * @subpackage Importer
7
+ */
8
+ if ( ! class_exists( 'WP_Importer' ) )
9
+ return;
10
+
11
+ class WF_OrderImpExpCsv_Order_Import extends WP_Importer {
12
+
13
+ var $id;
14
+ var $file_url;
15
+ var $delimiter;
16
+
17
+ var $merge_empty_cells;
18
+
19
+ // mappings from old information to new
20
+ var $processed_terms = array();
21
+ var $processed_posts = array();
22
+
23
+ var $merged = 0;
24
+ var $skipped = 0;
25
+ var $imported = 0;
26
+ var $errored = 0;
27
+
28
+ // Results
29
+ var $import_results = array();
30
+
31
+ /**
32
+ * Constructor
33
+ */
34
+ public function __construct() {
35
+
36
+ if (WC()->version < '2.7.0') {
37
+ $this->log = new WC_Logger();
38
+ } else {
39
+ $this->log = wc_get_logger();
40
+ }
41
+ $this->import_page = 'woocommerce_wf_order_csv';
42
+ $this->file_url_import_enabled = apply_filters( 'woocommerce_csv_product_file_url_import_enabled', true );
43
+ }
44
+
45
+ /**
46
+ * Registered callback function for the WordPress Importer
47
+ *
48
+ * Manages the three separate stages of the CSV import process
49
+ */
50
+ public function dispatch() {
51
+ global $woocommerce, $wpdb;
52
+
53
+ if ( ! empty( $_POST['delimiter'] ) ) {
54
+ $this->delimiter = stripslashes( trim( $_POST['delimiter'] ) );
55
+ }else if ( ! empty( $_GET['delimiter'] ) ) {
56
+ $this->delimiter = stripslashes( trim( $_GET['delimiter'] ) );
57
+ }
58
+
59
+ if ( ! $this->delimiter )
60
+ $this->delimiter = ',';
61
+
62
+ if ( ! empty( $_POST['merge_empty_cells'] ) || ! empty( $_GET['merge_empty_cells'] ) ) {
63
+ $this->merge_empty_cells = 1;
64
+ } else{
65
+ $this->merge_empty_cells = 0;
66
+ }
67
+
68
+ $step = empty( $_GET['step'] ) ? 0 : (int) $_GET['step'];
69
+
70
+ switch ( $step ) {
71
+ case 0 :
72
+ $this->header();
73
+ $this->greet();
74
+ break;
75
+ case 1 :
76
+ $this->header();
77
+
78
+ check_admin_referer( 'import-upload' );
79
+
80
+ if(!empty($_GET['file_url']))
81
+ $this->file_url = esc_attr( $_GET['file_url'] );
82
+ if(!empty($_GET['file_id']))
83
+ $this->id = $_GET['file_id'] ;
84
+
85
+ if ( !empty($_GET['clearmapping']) || $this->handle_upload() )
86
+ $this->import_options();
87
+ else
88
+ _e( 'Error with handle_upload!', 'wf_order_import_export' );
89
+ break;
90
+ case 2 :
91
+ $this->header();
92
+
93
+ check_admin_referer( 'import-woocommerce' );
94
+
95
+ $this->id = (int) $_POST['import_id'];
96
+
97
+ if ( $this->file_url_import_enabled )
98
+ $this->file_url = esc_attr( $_POST['import_url'] );
99
+
100
+ if ( $this->id )
101
+ $file = get_attached_file( $this->id );
102
+ else if ( $this->file_url_import_enabled )
103
+ $file = ABSPATH . $this->file_url;
104
+
105
+ $file = str_replace( "\\", "/", $file );
106
+
107
+ if ( $file ) {
108
+ ?>
109
+ <table id="import-progress" class="widefat_importer widefat">
110
+ <thead>
111
+ <tr>
112
+ <th class="status">&nbsp;</th>
113
+ <th class="row"><?php _e( 'Row', 'wf_order_import_export' ); ?></th>
114
+ <th><?php _e( 'OrderID', 'wf_order_import_export' ); ?></th>
115
+ <th><?php _e( 'Order Status', 'wf_order_import_export' ); ?></th>
116
+ <th class="reason"><?php _e( 'Status Msg', 'wf_order_import_export' ); ?></th>
117
+ </tr>
118
+ </thead>
119
+ <tfoot>
120
+ <tr class="importer-loading">
121
+ <td colspan="5"></td>
122
+ </tr>
123
+ </tfoot>
124
+ <tbody></tbody>
125
+ </table>
126
+ <script type="text/javascript">
127
+ jQuery(document).ready(function($) {
128
+
129
+ if ( ! window.console ) { window.console = function(){}; }
130
+
131
+ var processed_terms = [];
132
+ var processed_posts = [];
133
+ var i = 1;
134
+ var done_count = 0;
135
+
136
+ function import_rows( start_pos, end_pos ) {
137
+
138
+ var data = {
139
+ action: 'woocommerce_csv_order_import_request',
140
+ file: '<?php echo addslashes( $file ); ?>',
141
+ delimiter: '<?php echo $this->delimiter; ?>',
142
+ merge_empty_cells: '<?php echo $this->merge_empty_cells; ?>',
143
+ start_pos: start_pos,
144
+ end_pos: end_pos,
145
+ };
146
+ return $.ajax({
147
+ url: '<?php echo add_query_arg( array( 'import_page' => $this->import_page, 'step' => '3', 'merge' => ! empty( $_GET['merge'] ) ? '1' : '0' ), admin_url( 'admin-ajax.php' ) ); ?>',
148
+ data: data,
149
+ type: 'POST',
150
+ success: function( response ) {
151
+ if ( response ) {
152
+
153
+ try {
154
+ // Get the valid JSON only from the returned string
155
+ if ( response.indexOf("<!--WC_START-->") >= 0 )
156
+ response = response.split("<!--WC_START-->")[1]; // Strip off before after WC_START
157
+
158
+ if ( response.indexOf("<!--WC_END-->") >= 0 )
159
+ response = response.split("<!--WC_END-->")[0]; // Strip off anything after WC_END
160
+
161
+ // Parse
162
+ var results = $.parseJSON( response );
163
+
164
+ if ( results.error ) {
165
+
166
+ $('#import-progress tbody').append( '<tr id="row-' + i + '" class="error"><td class="status" colspan="5">' + results.error + '</td></tr>' );
167
+
168
+ i++;
169
+
170
+ } else if ( results.import_results && $( results.import_results ).size() > 0 ) {
171
+
172
+ $.each( results.processed_terms, function( index, value ) {
173
+ processed_terms.push( value );
174
+ });
175
+
176
+ $.each( results.processed_posts, function( index, value ) {
177
+ processed_posts.push( value );
178
+ });
179
+
180
+
181
+
182
+ $( results.import_results ).each(function( index, row ) {
183
+ $('#import-progress tbody').append( '<tr id="row-' + i + '" class="' + row['status'] + '"><td><mark class="result" title="' + row['status'] + '">' + row['status'] + '</mark></td><td class="row">' + i + '</td><td>' + row['order_number'] + '</td><td>' + row['post_id'] + ' - ' + row['post_title'] + '</td><td class="reason">' + row['reason'] + '</td></tr>' );
184
+
185
+ i++;
186
+ });
187
+ }
188
+
189
+ } catch(err) {}
190
+
191
+ } else {
192
+ $('#import-progress tbody').append( '<tr class="error"><td class="status" colspan="5">' + '<?php _e( 'AJAX Error', 'wf_order_import_export' ); ?>' + '</td></tr>' );
193
+ }
194
+
195
+ var w = $(window);
196
+ var row = $( "#row-" + ( i - 1 ) );
197
+
198
+ if ( row.length ) {
199
+ w.scrollTop( row.offset().top - (w.height()/2) );
200
+ }
201
+
202
+ done_count++;
203
+
204
+ $('body').trigger( 'woocommerce_csv_order_import_request_complete' );
205
+ }
206
+ });
207
+ }
208
+
209
+ var rows = [];
210
+
211
+ <?php
212
+ $limit = apply_filters( 'woocommerce_csv_import_limit_per_request', 10 );
213
+ $enc = mb_detect_encoding( $file, 'UTF-8, ISO-8859-1', true );
214
+ if ( $enc )
215
+ setlocale( LC_ALL, 'en_US.' . $enc );
216
+ @ini_set( 'auto_detect_line_endings', true );
217
+
218
+ $count = 0;
219
+ $previous_position = 0;
220
+ $position = 0;
221
+ $import_count = 0;
222
+
223
+ // Get CSV positions
224
+ if ( ( $handle = fopen( $file, "r" ) ) !== FALSE ) {
225
+
226
+ while ( ( $postmeta = fgetcsv( $handle, 0, $this->delimiter , '"', '"' ) ) !== FALSE ) {
227
+ $count++;
228
+
229
+ if ( $count >= $limit ) {
230
+ $previous_position = $position;
231
+ $position = ftell( $handle );
232
+ $count = 0;
233
+ $import_count ++;
234
+
235
+ // Import rows between $previous_position $position
236
+ ?>rows.push( [ <?php echo $previous_position; ?>, <?php echo $position; ?> ] ); <?php
237
+ }
238
+ }
239
+
240
+ // Remainder
241
+ if ( $count > 0 ) {
242
+ ?>rows.push( [ <?php echo $position; ?>, '' ] ); <?php
243
+ $import_count ++;
244
+ }
245
+
246
+ fclose( $handle );
247
+ }
248
+ ?>
249
+
250
+ var data = rows.shift();
251
+ var regen_count = 0;
252
+ import_rows( data[0], data[1] );
253
+
254
+ $('body').on( 'woocommerce_csv_order_import_request_complete', function() {
255
+ if ( done_count == <?php echo $import_count; ?> ) {
256
+
257
+ import_done();
258
+ } else {
259
+ // Call next request
260
+ data = rows.shift();
261
+ import_rows( data[0], data[1] );
262
+ }
263
+ } );
264
+
265
+ function import_done() {
266
+ var data = {
267
+ action: 'woocommerce_csv_order_import_request',
268
+ file: '<?php echo $file; ?>',
269
+ processed_terms: processed_terms,
270
+ processed_posts: processed_posts,
271
+ };
272
+
273
+ $.ajax({
274
+ url: '<?php echo add_query_arg( array( 'import_page' => $this->import_page, 'step' => '4', 'merge' => ! empty( $_GET['merge'] ) ? 1 : 0 ), admin_url( 'admin-ajax.php' ) ); ?>',
275
+ data: data,
276
+ type: 'POST',
277
+ success: function( response ) {
278
+ //console.log( response );
279
+ $('#import-progress tbody').append( '<tr class="complete"><td colspan="5">' + response + '</td></tr>' );
280
+ $('.importer-loading').hide();
281
+ }
282
+ });
283
+ }
284
+ });
285
+ </script>
286
+ <?php
287
+ } else {
288
+ echo '<p class="error">' . __( 'Error finding uploaded file!', 'wf_order_import_export' ) . '</p>';
289
+ }
290
+ break;
291
+ case 3 :
292
+ // Check access - cannot use nonce here as it will expire after multiple requests
293
+ if ( ! current_user_can( 'manage_woocommerce' ) )
294
+ die();
295
+
296
+ add_filter( 'http_request_timeout', array( $this, 'bump_request_timeout' ) );
297
+
298
+ if ( function_exists( 'gc_enable' ) )
299
+ gc_enable();
300
+
301
+ @set_time_limit(0);
302
+ @ob_flush();
303
+ @flush();
304
+ $wpdb->hide_errors();
305
+
306
+ $file = stripslashes( $_POST['file'] );
307
+
308
+ $start_pos = isset( $_POST['start_pos'] ) ? absint( $_POST['start_pos'] ) : 0;
309
+ $end_pos = isset( $_POST['end_pos'] ) ? absint( $_POST['end_pos'] ) : '';
310
+
311
+
312
+
313
+ $position = $this->import_start( $file, $start_pos, $end_pos );
314
+ $this->import();
315
+ $this->import_end();
316
+
317
+ $results = array();
318
+ $results['import_results'] = $this->import_results;
319
+ $results['processed_terms'] = $this->processed_terms;
320
+ $results['processed_posts'] = $this->processed_posts;
321
+
322
+ echo "<!--WC_START-->";
323
+ echo json_encode( $results );
324
+ echo "<!--WC_END-->";
325
+ exit;
326
+ break;
327
+ case 4 :
328
+ // Check access - cannot use nonce here as it will expire after multiple requests
329
+ if ( ! current_user_can( 'manage_woocommerce' ) )
330
+ die();
331
+
332
+ add_filter( 'http_request_timeout', array( $this, 'bump_request_timeout' ) );
333
+
334
+ if ( function_exists( 'gc_enable' ) )
335
+ gc_enable();
336
+
337
+ @set_time_limit(0);
338
+ @ob_flush();
339
+ @flush();
340
+ $wpdb->hide_errors();
341
+
342
+ $this->processed_terms = isset( $_POST['processed_terms'] ) ? $_POST['processed_terms'] : array();
343
+ $this->processed_posts = isset( $_POST['processed_posts']) ? $_POST['processed_posts'] : array();
344
+
345
+ _e( 'Step 1...', 'wf_order_import_export' ) . ' ';
346
+
347
+ wp_defer_term_counting( true );
348
+ wp_defer_comment_counting( true );
349
+
350
+ _e( 'Step 2...', 'wf_order_import_export' ) . ' ';
351
+
352
+ echo 'Step 3...' . ' '; // Easter egg
353
+
354
+ _e( 'Finalizing...', 'wf_order_import_export' ) . ' ';
355
+
356
+ // SUCCESS
357
+ _e( 'Finished. Import complete.', 'wf_order_import_export' );
358
+
359
+ $this->import_end();
360
+ exit;
361
+ break;
362
+ }
363
+
364
+ $this->footer();
365
+ }
366
+
367
+ /**
368
+ * format_data_from_csv
369
+ */
370
+ public function format_data_from_csv( $data, $enc ) {
371
+ return ( $enc == 'UTF-8' ) ? $data : utf8_encode( $data );
372
+ }
373
+
374
+ /**
375
+ * Display pre-import options
376
+ */
377
+ public function import_options() {
378
+ $j = 0;
379
+
380
+ if ( $this->id )
381
+ $file = get_attached_file( $this->id );
382
+ else if ( $this->file_url_import_enabled )
383
+ $file = ABSPATH . $this->file_url;
384
+ else
385
+ return;
386
+
387
+ // Set locale
388
+ $enc = mb_detect_encoding( $file, 'UTF-8, ISO-8859-1', true );
389
+ if ( $enc ) setlocale( LC_ALL, 'en_US.' . $enc );
390
+ @ini_set( 'auto_detect_line_endings', true );
391
+
392
+ // Get headers
393
+ if ( ( $handle = fopen( $file, "r" ) ) !== FALSE ) {
394
+
395
+ $row = $raw_headers = array();
396
+ $header = fgetcsv( $handle, 0, $this->delimiter , '"', '"' );
397
+
398
+ while ( ( $postmeta = fgetcsv( $handle, 0, $this->delimiter , '"', '"' ) ) !== FALSE ) {
399
+ foreach ( $header as $key => $heading ) {
400
+ if ( ! $heading ) continue;
401
+ $s_heading = $heading;
402
+ $row[$s_heading] = ( isset( $postmeta[$key] ) ) ? $this->format_data_from_csv( $postmeta[$key], $enc ) : '';
403
+ $raw_headers[ $s_heading ] = $heading;
404
+ }
405
+ break;
406
+ }
407
+ fclose( $handle );
408
+ }
409
+
410
+ $merge = (!empty($_GET['merge']) && $_GET['merge']) ? 1 : 0;
411
+
412
+ include( 'views/html-wf-import-options.php' );
413
+ }
414
+
415
+ /**
416
+ * The main controller for the actual import stage.
417
+ */
418
+ public function import() {
419
+ global $woocommerce, $wpdb;
420
+
421
+ wp_suspend_cache_invalidation( true );
422
+ $this->hf_order_log_data_change('order-csv-import', '---' );
423
+ $this->hf_order_log_data_change('order-csv-import', __( 'Processing orders.', 'wf_order_import_export' ) );
424
+ $merging = 1;
425
+ $record_offset = 0;
426
+ foreach ( $this->parsed_data as $key => &$item ) {
427
+ $order = $this->parser->parse_orders( $item, $this->raw_headers, $merging, $record_offset );
428
+ if ( ! is_wp_error( $order ) )
429
+ $this->process_orders( $order['shop_order'][0] );
430
+ else
431
+ $this->add_import_result( 'failed', $order->get_error_message(), 'Not parsed', json_encode( $item ), '-' );
432
+
433
+ unset( $item, $order );
434
+
435
+ }
436
+
437
+ $this->hf_order_log_data_change('order-csv-import', __( 'Finished processing Orders.', 'wf_order_import_export' ) );
438
+ wp_suspend_cache_invalidation( false );
439
+ }
440
+
441
+ /**
442
+ * Parses the CSV file and prepares us for the task of processing parsed data
443
+ *
444
+ * @param string $file Path to the CSV file for importing
445
+ */
446
+ public function import_start( $file, $start_pos, $end_pos ) {
447
+
448
+ $memory = size_format( (WC()->version < '2.7.0')?woocommerce_let_to_num( ini_get( 'memory_limit' ) ):wc_let_to_num( ini_get( 'memory_limit' ) ) );
449
+ $wp_memory = size_format( (WC()->version < '2.7.0')? woocommerce_let_to_num( WP_MEMORY_LIMIT ) : wc_let_to_num( WP_MEMORY_LIMIT ) );
450
+
451
+ $this->hf_order_log_data_change('order-csv-import', '---[ New Import ] PHP Memory: ' . $memory . ', WP Memory: ' . $wp_memory );
452
+ $this->hf_order_log_data_change('order-csv-import', __( 'Parsing products CSV.', 'wf_order_import_export' ) );
453
+
454
+ $this->parser = new WF_CSV_Parser( 'shop_order' );
455
+
456
+ list( $this->parsed_data, $this->raw_headers, $position ) = $this->parser->parse_data( $file, $this->delimiter, $start_pos, $end_pos );
457
+
458
+ $this->hf_order_log_data_change('order-csv-import', __( 'Finished parsing products CSV.', 'wf_order_import_export' ) );
459
+
460
+ unset( $import_data );
461
+
462
+ wp_defer_term_counting( true );
463
+ wp_defer_comment_counting( true );
464
+
465
+ return $position;
466
+ }
467
+
468
+ /**
469
+ * Performs post-import cleanup of files and the cache
470
+ */
471
+ public function import_end() {
472
+
473
+ //wp_cache_flush(); Stops output in some hosting environments
474
+ foreach ( get_taxonomies() as $tax ) {
475
+ delete_option( "{$tax}_children" );
476
+ _get_term_hierarchy( $tax );
477
+ }
478
+
479
+ wp_defer_term_counting( false );
480
+ wp_defer_comment_counting( false );
481
+
482
+ do_action( 'import_end' );
483
+ }
484
+
485
+ /**
486
+ * Handles the CSV upload and initial parsing of the file to prepare for
487
+ * displaying author import options
488
+ *
489
+ * @return bool False if error uploading or invalid file, true otherwise
490
+ */
491
+ public function handle_upload() {
492
+ if ( empty( $_POST['file_url'] ) ) {
493
+
494
+ $file = wp_import_handle_upload();
495
+
496
+ if ( isset( $file['error'] ) ) {
497
+ echo '<p><strong>' . __( 'Sorry, there has been an error.', 'wf_order_import_export' ) . '</strong><br />';
498
+ echo esc_html( $file['error'] ) . '</p>';
499
+ return false;
500
+ }
501
+
502
+ $this->id = (int) $file['id'];
503
+ return true;
504
+
505
+ } else {
506
+
507
+ if ( file_exists( ABSPATH . $_POST['file_url'] ) ) {
508
+
509
+ $this->file_url = esc_attr( $_POST['file_url'] );
510
+ return true;
511
+
512
+ } else {
513
+
514
+ echo '<p><strong>' . __( 'Sorry, there has been an error.', 'wf_order_import_export' ) . '</strong></p>';
515
+ return false;
516
+
517
+ }
518
+
519
+ }
520
+
521
+ return false;
522
+ }
523
+
524
+ public function order_exists($orderID) {
525
+ global $wpdb;
526
+ $query = "SELECT ID FROM $wpdb->posts WHERE post_type = 'shop_order' AND post_status IN ( 'wc-pending', 'wc-processing', 'wc-completed', 'wc-on-hold', 'wc-failed' , 'wc-refunded', 'wc-cancelled')";
527
+ $args = array();
528
+ $posts_are_exist = @$wpdb->get_col($wpdb->prepare($query, $args));
529
+
530
+ if ($posts_are_exist) {
531
+ foreach ($posts_are_exist as $exist_id) {
532
+ $found = false;
533
+ if ($exist_id == $orderID) {
534
+ $found = TRUE;
535
+ }
536
+ if($found) return TRUE;
537
+ }
538
+ } else {
539
+ return FALSE;
540
+ }
541
+ }
542
+ /**
543
+ * Create new posts based on import information
544
+ */
545
+ private function process_orders($post) {
546
+
547
+ global $wpdb;
548
+ $this->imported = $this->merged = 0;
549
+ $merging = ( ! empty( $_GET['merge'] )) ? 1 : 0 ;
550
+
551
+ // plan a dry run
552
+ //$dry_run = isset( $_POST['dry_run'] ) && $_POST['dry_run'] ? true : false;
553
+ $dry_run = FALSE;
554
+
555
+ $this->hf_order_log_data_change('order-csv-import', '---' );
556
+ $this->hf_order_log_data_change('order-csv-import', __( 'Processing orders.', 'wf_order_import_export' ) );
557
+
558
+ // check class-wc-checkout.php for reference
559
+
560
+ $order_data = array(
561
+ 'import_id' => $post['order_number'], //Suggest import to keep the given ID
562
+ 'post_date' => date( 'Y-m-d H:i:s', $post['date'] ),
563
+ 'post_type' => 'shop_order',
564
+ 'post_title' => 'Order &ndash; ' . date( 'F j, Y @ h:i A', $post['date'] ),
565
+ 'post_status' => 'wc-' . preg_replace( '/^wc-/', '', $post['status'] ),
566
+ 'ping_status' => 'closed',
567
+ 'post_excerpt' => isset($post['order_comments'])?($post['order_comments']):'',
568
+ 'post_author' => 1,
569
+ 'post_password' => uniqid( 'order_' ), // Protects the post just in case
570
+ );
571
+
572
+ if ( ! $dry_run ) {
573
+ // track whether download permissions need to be granted
574
+ $add_download_permissions = false;
575
+
576
+
577
+ // Check if post exists when importing
578
+ $new_added = false;
579
+ $is_order_exist = $this->order_exists($post['order_number']);
580
+ $meta_array = array();
581
+ if (!empty($post['postmeta'])) {
582
+ foreach ($post['postmeta'] as $meta) {
583
+ $meta_array[$meta['key']] = $meta['value'];
584
+ }
585
+ }
586
+
587
+ $user_id = $this->hf_check_customer($meta_array);
588
+ if (is_wp_error($user_id)) {
589
+ $this->hf_order_log_data_change('order-csv-import', __($user_id->get_error_message(), 'wf_order_import_export'));
590
+ $this->add_import_result('skipped', __($user_id->get_error_message(), 'wf_order_import_export'), $post['order_number'], $post['order_number'], $post['order_number']);
591
+ $skipped++;
592
+ unset($post);
593
+ return;
594
+ } elseif (empty($user_id)) {
595
+ $user_id = 0;
596
+ }
597
+
598
+
599
+ if (!$merging && $is_order_exist) {
600
+ $usr_msg = 'Order already exists.';
601
+ $this->add_import_result('skipped', __($usr_msg, 'wf_order_import_export'), $post['order_number'], $order_data['post_title'], $post['order_number']);
602
+ $this->hf_order_log_data_change('order-csv-import', sprintf(__('> &#8220;%s&#8221;' . $usr_msg, 'wf_order_import_export'), esc_html($order_data['post_title'])), true);
603
+ unset($post);
604
+ return;
605
+ }
606
+ else{
607
+ if($is_order_exist) {
608
+ $order_id = $post['order_number'];
609
+ $wp_result = wp_update_post($order_data);
610
+ } else {
611
+ $order_id = wp_insert_post($order_data);
612
+ $new_added = true;
613
+ if ( is_wp_error( $order_id ) ) {
614
+ $this->errored++;
615
+ $new_added = false;
616
+ //$this->add_import_result('failed', __($order_id->get_error_message() , 'wf_order_import_export'), $post['order_number'], $order_data['post_title'], $post['order_number']);
617
+ $this->hf_order_log_data_change('order-csv-import', sprintf( __( '> Error inserting %s: %s', 'wf_order_import_export'), $post['order_number'], $order_id->get_error_message() ), true );
618
+ }
619
+
620
+ }
621
+
622
+
623
+ }
624
+ // empty update to bump up the post_modified date to today's date (otherwise it would match the post_date, which isn't quite right)
625
+ //wp_update_post( array( 'ID' => $order_id ) );
626
+
627
+ // handle special meta fields
628
+ $order_currency = (isset($post['order_currency']) && $post['order_currency']) ? $post['order_currency'] : get_woocommerce_currency();
629
+ update_post_meta( $order_id, '_order_key', apply_filters( 'woocommerce_generate_order_key', uniqid( 'order_' ) ) );
630
+ update_post_meta( $order_id, '_order_currency', $order_currency );
631
+ update_post_meta( $order_id, '_prices_include_tax', get_option( 'woocommerce_prices_include_tax' ) );
632
+ update_post_meta( $order_id, '_order_number', $post['order_number'] );
633
+ // add order postmeta
634
+ foreach ( $post['postmeta'] as $meta ) {
635
+ $meta_processed = false;
636
+
637
+ // we don't set the "download permissions granted" meta, we call the woocommerce function to take care of this for us
638
+ if ( ( 'Download Permissions Granted' == $meta['key'] || '_download_permissions_granted' == $meta['key'] ) && $meta['value'] ) {
639
+ $add_download_permissions = true;
640
+ $meta_processed = true;
641
+ }
642
+
643
+ if (( '_customer_user' == $meta['key'])) {
644
+ update_post_meta($order_id, $meta['key'], $user_id);
645
+ $meta_processed = true;
646
+ }
647
+
648
+ if ( ! $meta_processed ) {
649
+ update_post_meta( $order_id, $meta['key'], $meta['value'] );
650
+ }
651
+
652
+ // set the paying customer flag on the user meta if applicable
653
+ if ( '_customer_id' == $meta['key'] && $user_id && in_array( $post['status'], array( 'processing', 'completed', 'refunded' ) ) ) {
654
+ update_user_meta( $user_id, "paying_customer", 1 );
655
+ }
656
+ }
657
+
658
+
659
+ // handle order items
660
+ $order_items = array();
661
+ $order_item_meta = null;
662
+
663
+ foreach ( $post['order_items'] as $item ) {
664
+
665
+ $product = null;
666
+ $variation_item_meta = array();
667
+
668
+ if ( $item['product_id'] ) {
669
+ $product = wc_get_product( $item['product_id'] );
670
+
671
+ // handle variations
672
+ if ( $product && ( $product->is_type( 'variable' ) || $product->is_type( 'variation' ) || $product->is_type( 'subscription_variation' ) ) && method_exists( $product, 'get_variation_id' ) ) {
673
+ foreach ( $product->get_variation_attributes() as $key => $value ) {
674
+ $variation_item_meta[] = array( 'meta_name' => esc_attr( substr( $key, 10 ) ), 'meta_value' => $value ); // remove the leading 'attribute_' from the name to get 'pa_color' for instance
675
+ }
676
+ }
677
+ }
678
+
679
+ // order item
680
+ $order_items[] = array(
681
+ 'order_item_name' => $product ? $product->get_title() : (!empty($item['unknown_product_name']) ? $item['unknown_product_name'] : __('Unknown Product', 'wf_order_import_export')),
682
+ 'order_item_type' => 'line_item',
683
+ );
684
+
685
+ $var_id = 0;
686
+ if($product){
687
+ if (WC()->version < '2.7.0' && method_exists( $product,'get_variation_id' )) {
688
+ $var_id = $product->get_variation_id();
689
+ }else{
690
+ $var_id = $product->get_id();
691
+ }
692
+ }
693
+ // standard order item meta
694
+ $_order_item_meta = array(
695
+ '_qty' => (int) $item['qty'],
696
+ '_tax_class' => '', // Tax class (adjusted by filters)
697
+ '_product_id' => $item['product_id'],
698
+ '_variation_id' => $var_id,
699
+ '_line_subtotal' => number_format( (float) $item['total'], 2, '.', '' ), // Line subtotal (before discounts)
700
+ '_line_subtotal_tax' => 0, // Line tax (before discounts)
701
+ '_line_total' => number_format( (float) $item['total'], 2, '.', '' ), // Line total (after discounts)
702
+ '_line_tax' => 0, // Line Tax (after discounts)
703
+ );
704
+
705
+ // add any product variation meta
706
+ foreach ( $variation_item_meta as $meta ) {
707
+ $_order_item_meta[ $meta['meta_name'] ] = $meta['meta_value'];
708
+ }
709
+
710
+ // include any arbitrary order item meta
711
+ $_order_item_meta = array_merge( $_order_item_meta, $item['meta'] );
712
+
713
+ $order_item_meta[] = $_order_item_meta;
714
+
715
+ }
716
+
717
+ foreach ( $order_items as $key => $order_item ) {
718
+ $order_item_id = wc_add_order_item( $order_id, $order_item );
719
+
720
+ if ( $order_item_id ) {
721
+ foreach ( $order_item_meta[ $key ] as $meta_key => $meta_value ) {
722
+ wc_add_order_item_meta( $order_item_id, $meta_key, $meta_value );
723
+ }
724
+ }
725
+ }
726
+
727
+ // create the shipping order items
728
+ foreach ( $post['order_shipping'] as $order_shipping ) {
729
+
730
+ $shipping_order_item = array(
731
+ 'order_item_name' => ($order_shipping['title']) ? $order_shipping['title'] : $order_shipping['method_id'],
732
+ 'order_item_type' => 'shipping',
733
+ );
734
+
735
+ $shipping_order_item_id = wc_add_order_item( $order_id, $shipping_order_item );
736
+
737
+ if ( $shipping_order_item_id ) {
738
+ wc_add_order_item_meta( $shipping_order_item_id, 'method_id', $order_shipping['method_id'] );
739
+ wc_add_order_item_meta( $shipping_order_item_id, 'cost', $order_shipping['cost'] );
740
+ }
741
+ }
742
+
743
+ // create the tax order items
744
+ foreach ( $post['tax_items'] as $tax_item ) {
745
+
746
+ $tax_order_item = array(
747
+ 'order_item_name' => $tax_item['title'],
748
+ 'order_item_type' => 'tax',
749
+ );
750
+
751
+ $tax_order_item_id = wc_add_order_item( $order_id, $tax_order_item );
752
+
753
+ if ( $tax_order_item_id ) {
754
+ wc_add_order_item_meta( $tax_order_item_id, 'rate_id', $tax_item['rate_id'] );
755
+ wc_add_order_item_meta( $tax_order_item_id, 'label', $tax_item['label'] );
756
+ wc_add_order_item_meta( $tax_order_item_id, 'compound', $tax_item['compound'] );
757
+ wc_add_order_item_meta( $tax_order_item_id, 'tax_amount', $tax_item['tax_amount'] );
758
+ wc_add_order_item_meta( $tax_order_item_id, 'shipping_tax_amount', $tax_item['shipping_tax_amount'] );
759
+ }
760
+ }
761
+
762
+ // Grant downloadalbe product permissions
763
+ if ( $add_download_permissions ) {
764
+ wc_downloadable_product_permissions( $order_id );
765
+ }
766
+
767
+ // add order notes
768
+ $order = wc_get_order( $order_id );
769
+ foreach ( $post['notes'] as $order_note ) {
770
+ $order->add_order_note( $order_note );
771
+ }
772
+
773
+ // record the product sales
774
+ if (WC()->version < '2.7.0') {
775
+ $order->record_product_sales();
776
+ } else {
777
+ wc_update_total_sales_counts($order_id);
778
+ }
779
+ } // ! dry run
780
+
781
+ // was an original order number provided?
782
+ if ( ! empty( $post['order_number_formatted'] ) ) {
783
+ if ( ! $dry_run ) {
784
+ // do our best to provide some custom order number functionality while also allowing 3rd party plugins to provide their own custom order number facilities
785
+ do_action( 'woocommerce_set_order_number', $order, $post['order_number'], $post['order_number_formatted'] );
786
+ $order->add_order_note( sprintf( __( "Original order #%s", 'wf_order_import_export' ), $post['order_number_formatted'] ) );
787
+
788
+ // get the order so we can display the correct order number
789
+ $order = wc_get_order( $order_id );
790
+ }
791
+
792
+ $this->processed_posts[ $post['order_number_formatted'] ] = $post['order_number_formatted'];
793
+ }
794
+ if($merging && !$new_added)
795
+ $out_msg = 'Order Successfully updated.';
796
+ else
797
+ $out_msg = 'Order Imported Successfully.';
798
+
799
+ $this->add_import_result('imported', __($out_msg, 'wf_order_import_export'), $order_id, $order_data['post_title'], $order_id);
800
+ $this->hf_order_log_data_change('order-csv-import', sprintf(__('> &#8220;%s&#8221;' . $out_msg, 'wf_order_import_export'), esc_html($order_data['post_title'])), true);
801
+ $this->imported++;
802
+ $this->hf_order_log_data_change( 'order-csv-import', sprintf( __( '> Finished importing order %s', 'wf_order_import_export' ), $dry_run ? "" : $order->get_order_number() ) );
803
+
804
+ // }
805
+
806
+
807
+ $this->hf_order_log_data_change( 'order-csv-import', __( 'Finished processing orders.', 'wf_order_import_export' ) );
808
+
809
+ unset( $post );
810
+ }
811
+
812
+
813
+ public function hf_check_customer($data) {
814
+
815
+ $customer_email = (!empty($data['_customer_email']) ) ? $data['_customer_email'] : '';
816
+
817
+ $found_customer = false;
818
+ $username = '';
819
+
820
+ if (!empty($customer_email)) {
821
+
822
+ if (is_email($customer_email) && false !== email_exists($customer_email)) {
823
+ $found_customer = email_exists($customer_email);
824
+ return $found_customer;
825
+ } else {
826
+ $found_customer = 0;
827
+ }
828
+ } else {
829
+ $found_customer = 0;
830
+ }
831
+
832
+ return $found_customer;
833
+ }
834
+
835
+ /**
836
+ * Log a row's import status
837
+ */
838
+ protected function add_import_result( $status, $reason, $post_id = '', $post_title = '', $order_number = '' ) {
839
+ $this->import_results[] = array(
840
+ 'post_title' => $post_title,
841
+ 'post_id' => $post_id,
842
+ 'order_number' => $order_number,
843
+ 'status' => $status,
844
+ 'reason' => $reason
845
+ );
846
+ }
847
+
848
+
849
+ /**
850
+ * Decide what the maximum file size for downloaded attachments is.
851
+ * Default is 0 (unlimited), can be filtered via import_attachment_size_limit
852
+ *
853
+ * @return int Maximum attachment file size to import
854
+ */
855
+ public function max_attachment_size() {
856
+ return apply_filters( 'import_attachment_size_limit', 0 );
857
+ }
858
+
859
+ // Display import page title
860
+ public function header() {
861
+ echo '<div class="wrap"><div class="icon32" id="icon-woocommerce-importer"><br></div>';
862
+ echo '<h2>' . ( empty( $_GET['merge'] ) ? __( 'Import', 'wf_order_import_export' ) : __( 'Merge Orders', 'wf_order_import_export' ) ) . '</h2>';
863
+ }
864
+
865
+ // Close div.wrap
866
+ public function footer() {
867
+ echo '</div>';
868
+ }
869
+
870
+ /**
871
+ * Display introductory text and file upload form
872
+ */
873
+ public function greet() {
874
+ $action = 'admin.php?import=woocommerce_wf_order_csv&amp;step=1&amp;merge=' . ( ! empty( $_GET['merge'] ) ? 1 : 0 );
875
+ $bytes = apply_filters( 'import_upload_size_limit', wp_max_upload_size() );
876
+ $size = size_format( $bytes );
877
+ $upload_dir = wp_upload_dir();
878
+ include( 'views/html-wf-import-greeting.php' );
879
+ }
880
+
881
+ /**
882
+ * Added to http_request_timeout filter to force timeout at 60 seconds during import
883
+ * @return int 60
884
+ */
885
+ public function bump_request_timeout( $val ) {
886
+ return 60;
887
+ }
888
+
889
+
890
+ public function hf_order_log_data_change ($content = 'order-csv-import',$data='')
891
+ {
892
+ if (WC()->version < '2.7.0')
893
+ {
894
+ $this->log->add($content,$data);
895
+ }else
896
+ {
897
+ $context = array( 'source' => $content );
898
+ $this->log->log("debug", $data ,$context);
899
+ }
900
+ }
901
  }
includes/importer/data-coupon/data-wf-post-defaults.php CHANGED
@@ -1,22 +1,22 @@
1
- <?php
2
- if ( ! defined( 'ABSPATH' ) ) {
3
- exit;
4
- }
5
-
6
- // New post defaults
7
- return array(
8
- 'post_type' => 'shop_coupon',
9
- 'menu_order' => '',
10
- 'postmeta' => array(),
11
- 'post_status' => 'publish',
12
- 'post_title' => '',
13
- 'post_name' => '',
14
- 'post_date' => '',
15
- 'post_date_gmt' => '',
16
- //'post_content' => '',
17
- 'post_excerpt' => '',
18
- 'post_parent' => '',
19
- //'post_password' => '',
20
- 'post_author' => '',
21
- //'comment_status'=> 'open'
22
  );
1
+ <?php
2
+ if ( ! defined( 'ABSPATH' ) ) {
3
+ exit;
4
+ }
5
+
6
+ // New post defaults
7
+ return array(
8
+ 'post_type' => 'shop_coupon',
9
+ 'menu_order' => '',
10
+ 'postmeta' => array(),
11
+ 'post_status' => 'publish',
12
+ 'post_title' => '',
13
+ 'post_name' => '',
14
+ 'post_date' => '',
15
+ 'post_date_gmt' => '',
16
+ //'post_content' => '',
17
+ 'post_excerpt' => '',
18
+ 'post_parent' => '',
19
+ //'post_password' => '',
20
+ 'post_author' => '',
21
+ //'comment_status'=> 'open'
22
  );
includes/importer/data-coupon/data-wf-postmeta-allowed.php CHANGED
@@ -1,16 +1,16 @@
1
- <?php
2
- if ( ! defined( 'ABSPATH' ) ) {
3
- exit;
4
- }
5
-
6
- // New postmeta allowed
7
- return array(
8
- /*'downloadable' => array( 'yes', 'no' ),
9
- 'virtual' => array( 'yes', 'no' ),
10
- 'visibility' => array( 'visible', 'catalog', 'search', 'hidden' ),
11
- 'stock_status' => array( 'instock', 'outofstock' ),
12
- 'backorders' => array( 'yes', 'no', 'notify' ),
13
- 'manage_stock' => array( 'yes', 'no' ),
14
- 'tax_status' => array( 'taxable', 'shipping', 'none' ),
15
- 'featured' => array( 'yes', 'no' ),*/
16
  );
1
+ <?php
2
+ if ( ! defined( 'ABSPATH' ) ) {
3
+ exit;
4
+ }
5
+
6
+ // New postmeta allowed
7
+ return array(
8
+ /*'downloadable' => array( 'yes', 'no' ),
9
+ 'virtual' => array( 'yes', 'no' ),
10
+ 'visibility' => array( 'visible', 'catalog', 'search', 'hidden' ),
11
+ 'stock_status' => array( 'instock', 'outofstock' ),
12
+ 'backorders' => array( 'yes', 'no', 'notify' ),
13
+ 'manage_stock' => array( 'yes', 'no' ),
14
+ 'tax_status' => array( 'taxable', 'shipping', 'none' ),
15
+ 'featured' => array( 'yes', 'no' ),*/
16
  );
includes/importer/data-coupon/data-wf-postmeta-defaults.php CHANGED
@@ -1,24 +1,24 @@
1
- <?php
2
- if ( ! defined( 'ABSPATH' ) ) {
3
- exit;
4
- }
5
-
6
- // New postmeta defaults
7
- return apply_filters( 'coupon_csv_product_postmeta_defaults', array(
8
- 'discount_type' => '',
9
- 'coupon_amount' => '',
10
- 'individual_use' => 'yes',
11
- 'product_ids' => '',
12
- 'exclude_product_ids' => '',
13
- 'usage_limit' => '',
14
- 'usage_limit_per_user' => '',
15
- 'limit_usage_to_x_items' => '',
16
- 'expiry_date' => '',
17
- 'free_shipping' => 'no',
18
- 'exclude_sale_items' => 'no',
19
- 'product_categories' => '',
20
- 'exclude_product_categories' => '',
21
- 'minimum_amount' => '',
22
- 'maximum_amount' => '',
23
- 'customer_email' => '',
24
  ) );
1
+ <?php
2
+ if ( ! defined( 'ABSPATH' ) ) {
3
+ exit;
4
+ }
5
+
6
+ // New postmeta defaults
7
+ return apply_filters( 'coupon_csv_product_postmeta_defaults', array(
8
+ 'discount_type' => '',
9
+ 'coupon_amount' => '',
10
+ 'individual_use' => 'yes',
11
+ 'product_ids' => '',
12
+ 'exclude_product_ids' => '',
13
+ 'usage_limit' => '',
14
+ 'usage_limit_per_user' => '',
15
+ 'limit_usage_to_x_items' => '',
16
+ 'expiry_date' => '',
17
+ 'free_shipping' => 'no',
18
+ 'exclude_sale_items' => 'no',
19
+ 'product_categories' => '',
20
+ 'exclude_product_categories' => '',
21
+ 'minimum_amount' => '',
22
+ 'maximum_amount' => '',
23
+ 'customer_email' => '',
24
  ) );
includes/importer/data-coupon/data-wf-reserved-fields-pair.php CHANGED
@@ -1,31 +1,31 @@
1
- <?php
2
- if (!defined('ABSPATH')) {
3
- exit;
4
- }
5
- // Reserved column names
6
- return apply_filters('hf_coupon_csv_alter_order_data_columns', array(
7
- 'id' => 'Coupon ID | Coupon ID',
8
- 'post_title' => 'Coupon Title | Name of the coupon ',
9
- //'post_name' => 'Coupon Permalink | Unique part of the coupon URL',
10
- 'post_status' => 'Coupon Status | Coupon Status ( published , draft ...)',
11
- //'post_content' => 'Coupon Description | Description about the Coupon',
12
- 'post_excerpt' => 'Coupon Short Description | Short description about the Coupon',
13
- 'post_date' => 'Post Date | Coupon posted date',
14
- 'discount_type' => 'Coupon Type | fixed_cart OR percent OR fixed_product OR percent_product',
15
- 'coupon_amount' => 'Coupon Amount | Numeric values',
16
- 'individual_use' => 'Individual Use? | yes or no',
17
- 'product_ids' => 'Assocoated Product Ids | With comma(,) Separator',
18
- 'exclude_product_ids' => 'Exclude Product Ids | With comma(,) Separator',
19
- 'usage_limit' => 'Usage Limit Per Coupon | Numeric Values',
20
- 'usage_limit_per_user' => 'Usage Limit Per User | Numeric Values',
21
- 'limit_usage_to_x_items' => 'Limit Usage To X Items | Maximum Number Of Individual Items This Coupon Can Apply',
22
- 'expiry_date' => 'Expiry Date | YYYY-MM-DD',
23
- 'free_shipping' => 'Is Free Shipping? | yes or no',
24
- 'exclude_sale_items' => 'Is Exclude Sale Items? | yes or no',
25
- 'product_categories' => 'Product Categories | with comma(,) Separator',
26
- 'exclude_product_categories' => 'Exclude Product Categories | With comma(,) Separator',
27
- 'minimum_amount' => 'Minimum Amount | Numeric',
28
- 'maximum_amount' => 'Maximum Amount | Numeric',
29
- 'customer_email' => 'Restricted Customers Email Ids| With comma(,) Separator',
30
- //'post_date_gmt' => 'Post Date GMT | Tooltip data Status',
31
- ));
1
+ <?php
2
+ if (!defined('ABSPATH')) {
3
+ exit;
4
+ }
5
+ // Reserved column names
6
+ return apply_filters('hf_coupon_csv_alter_order_data_columns', array(
7
+ 'id' => 'Coupon ID | Coupon ID',
8
+ 'post_title' => 'Coupon Title | Name of the coupon ',
9
+ //'post_name' => 'Coupon Permalink | Unique part of the coupon URL',
10
+ 'post_status' => 'Coupon Status | Coupon Status ( published , draft ...)',
11
+ //'post_content' => 'Coupon Description | Description about the Coupon',
12
+ 'post_excerpt' => 'Coupon Short Description | Short description about the Coupon',
13
+ 'post_date' => 'Post Date | Coupon posted date',
14
+ 'discount_type' => 'Coupon Type | fixed_cart OR percent OR fixed_product OR percent_product',
15
+ 'coupon_amount' => 'Coupon Amount | Numeric values',
16
+ 'individual_use' => 'Individual Use? | yes or no',
17
+ 'product_ids' => 'Assocoated Product Ids | With comma(,) Separator',
18
+ 'exclude_product_ids' => 'Exclude Product Ids | With comma(,) Separator',
19
+ 'usage_limit' => 'Usage Limit Per Coupon | Numeric Values',
20
+ 'usage_limit_per_user' => 'Usage Limit Per User | Numeric Values',
21
+ 'limit_usage_to_x_items' => 'Limit Usage To X Items | Maximum Number Of Individual Items This Coupon Can Apply',
22
+ 'expiry_date' => 'Expiry Date | YYYY-MM-DD',
23
+ 'free_shipping' => 'Is Free Shipping? | yes or no',
24
+ 'exclude_sale_items' => 'Is Exclude Sale Items? | yes or no',
25
+ 'product_categories' => 'Product Categories | with comma(,) Separator',
26
+ 'exclude_product_categories' => 'Exclude Product Categories | With comma(,) Separator',
27
+ 'minimum_amount' => 'Minimum Amount | Numeric',
28
+ 'maximum_amount' => 'Maximum Amount | Numeric',
29
+ 'customer_email' => 'Restricted Customers Email Ids| With comma(,) Separator',
30
+ //'post_date_gmt' => 'Post Date GMT | Tooltip data Status',
31
+ ));
includes/importer/data-coupon/data-wf-reserved-fields.php CHANGED
@@ -1,34 +1,34 @@
1
- <?php
2
- if (!defined('ABSPATH')) {
3
- exit;
4
- }
5
- // Reserved column names
6
- return array(
7
- 'id',
8
- 'discount_type',
9
- 'post_id',
10
- 'post_title',
11
- 'post_name',
12
- 'post_status',
13
- 'post_date',
14
- 'post_date_gmt',
15
- 'post_excerpt',
16
- 'post_type',
17
- 'post_author',
18
- 'postmeta',
19
- 'coupon_amount',
20
- 'individual_use',
21
- 'product_ids',
22
- 'exclude_product_ids',
23
- 'usage_limit',
24
- 'usage_limit_per_user',
25
- 'limit_usage_to_x_items',
26
- 'expiry_date',
27
- 'free_shipping',
28
- 'exclude_sale_items',
29
- 'product_categories',
30
- 'exclude_product_categories',
31
- 'minimum_amount',
32
- 'maximum_amount',
33
- 'customer_email',
34
- );
1
+ <?php
2
+ if (!defined('ABSPATH')) {
3
+ exit;
4
+ }
5
+ // Reserved column names
6
+ return array(
7
+ 'id',
8
+ 'discount_type',
9
+ 'post_id',
10
+ 'post_title',
11
+ 'post_name',
12
+ 'post_status',
13
+ 'post_date',
14
+ 'post_date_gmt',
15
+ 'post_excerpt',
16
+ 'post_type',
17
+ 'post_author',
18
+ 'postmeta',
19
+ 'coupon_amount',
20
+ 'individual_use',
21
+ 'product_ids',
22
+ 'exclude_product_ids',
23
+ 'usage_limit',
24
+ 'usage_limit_per_user',
25
+ 'limit_usage_to_x_items',
26
+ 'expiry_date',
27
+ 'free_shipping',
28
+ 'exclude_sale_items',
29
+ 'product_categories',
30
+ 'exclude_product_categories',
31
+ 'minimum_amount',
32
+ 'maximum_amount',
33
+ 'customer_email',
34
+ );
includes/importer/data/data-wf-reserved-fields-pair.php CHANGED
@@ -1,53 +1,53 @@
1
- <?php
2
-
3
- // Reserved column names
4
- return array(
5
-
6
-
7
- 'order_id' => ' Order ID | Order ID ',
8
- 'order_number' => 'Order Number | Order Number',
9
- 'order_date' => 'Order Date | Order Date',
10
- 'status' => 'Order Status | Order Status ( processing , pending ...) ',
11
- 'shipping_total' => 'Shipping Total | Shipping Total amount',
12
- 'shipping_tax_total' => 'Shipping Tax Total | Shipping Tax Total',
13
- 'fee_total' => 'Total Fee | Total Fee',
14
- 'fee_tax_total' => 'Total Tax Fee | Total Tax Fee',
15
- 'tax_total' => 'Total Tax | Total Tax',
16
- 'cart_discount' => 'Cart Discount | Cart Discount',
17
- 'order_discount' => 'Order Discount | Order Discount',
18
- 'discount_total' => 'Discount Total | Discount Total',
19
- 'order_total' => 'Order Total | Order Total',
20
- 'refunded_total' => 'refunded_total | refunded_total',
21
- 'order_currency' => 'order_currency | order_currency',
22
- 'payment_method' => 'payment_method | payment_method',
23
- 'shipping_method' => 'shipping_method | shipping_method',
24
- 'customer_email' => 'customer_email | Customer Email ( if not provided order will be created as Guest)',
25
- 'customer_user' => 'customer_user | Customer id ( if not provided order will be created as Guest)',
26
- 'billing_first_name' => 'billing_first_name | billing_first_name',
27
- 'billing_last_name' => 'billing_last_name | billing_last_name',
28
- 'billing_company' => 'billing_company | billing_company',
29
- 'billing_email' => 'billing_email | billing_email',
30
- 'billing_phone' => 'billing_phone | billing_phone',
31
- 'billing_address_1' => 'billing_address_1 | billing_address_1',
32
- 'billing_address_2' => 'billing_address_2 | billing_address_2',
33
- 'billing_postcode' => 'billing_postcode | billing_postcode',
34
- 'billing_city' => 'billing_city | billing_city',
35
- 'billing_state' => 'billing_state | billing_state',
36
- 'billing_country' => 'billing_country | billing_country',
37
- 'shipping_first_name' => 'shipping_first_name | shipping_first_name',
38
- 'shipping_last_name' => 'shipping_last_name | shipping_last_name',
39
- 'shipping_company' => 'shipping_company | shipping_company',
40
- 'shipping_address_1' => 'shipping_address_1 | shipping_address_1',
41
- 'shipping_address_2' => 'shipping_address_2 | shipping_address_2',
42
- 'shipping_postcode' => 'shipping_postcode | shipping_postcode',
43
- 'shipping_city' => 'shipping_city | shipping_city',
44
- 'shipping_state' => 'shipping_state | shipping_state',
45
- 'shipping_country' => 'shipping_country | shipping_country',
46
- 'customer_note' => 'customer_note | customer_note',
47
- 'shipping_items' => 'shipping_items | shipping_items',
48
- 'fee_items' => 'fee_items | fee_items',
49
- 'tax_items' => 'tax_items | tax_items',
50
- 'coupon_items' => 'coupon_items | coupons',
51
- 'order_notes' => 'order_notes | order_notes',
52
- 'download_permissions' => 'Downloadable Product Permissions | Permissions for order items will automatically be granted when the order status changes to processing or completed.'
53
  );
1
+ <?php
2
+
3
+ // Reserved column names
4
+ return array(
5
+
6
+
7
+ 'order_id' => ' Order ID | Order ID ',
8
+ 'order_number' => 'Order Number | Order Number',
9
+ 'order_date' => 'Order Date | Order Date',
10
+ 'status' => 'Order Status | Order Status ( processing , pending ...) ',
11
+ 'shipping_total' => 'Shipping Total | Shipping Total amount',
12
+ 'shipping_tax_total' => 'Shipping Tax Total | Shipping Tax Total',
13
+ 'fee_total' => 'Total Fee | Total Fee',
14
+ 'fee_tax_total' => 'Total Tax Fee | Total Tax Fee',
15
+ 'tax_total' => 'Total Tax | Total Tax',
16
+ 'cart_discount' => 'Cart Discount | Cart Discount',
17
+ 'order_discount' => 'Order Discount | Order Discount',
18
+ 'discount_total' => 'Discount Total | Discount Total',
19
+ 'order_total' => 'Order Total | Order Total',
20
+ 'refunded_total' => 'refunded_total | refunded_total',
21
+ 'order_currency' => 'order_currency | order_currency',
22
+ 'payment_method' => 'payment_method | payment_method',
23
+ 'shipping_method' => 'shipping_method | shipping_method',
24
+ 'customer_email' => 'customer_email | Customer Email ( if not provided order will be created as Guest)',
25
+ 'customer_user' => 'customer_user | Customer id ( if not provided order will be created as Guest)',
26
+ 'billing_first_name' => 'billing_first_name | billing_first_name',
27
+ 'billing_last_name' => 'billing_last_name | billing_last_name',
28
+ 'billing_company' => 'billing_company | billing_company',
29
+ 'billing_email' => 'billing_email | billing_email',
30
+ 'billing_phone' => 'billing_phone | billing_phone',
31
+ 'billing_address_1' => 'billing_address_1 | billing_address_1',
32
+ 'billing_address_2' => 'billing_address_2 | billing_address_2',
33
+ 'billing_postcode' => 'billing_postcode | billing_postcode',
34
+ 'billing_city' => 'billing_city | billing_city',
35
+ 'billing_state' => 'billing_state | billing_state',
36
+ 'billing_country' => 'billing_country | billing_country',
37
+ 'shipping_first_name' => 'shipping_first_name | shipping_first_name',
38
+ 'shipping_last_name' => 'shipping_last_name | shipping_last_name',
39
+ 'shipping_company' => 'shipping_company | shipping_company',
40
+ 'shipping_address_1' => 'shipping_address_1 | shipping_address_1',
41
+ 'shipping_address_2' => 'shipping_address_2 | shipping_address_2',
42
+ 'shipping_postcode' => 'shipping_postcode | shipping_postcode',
43
+ 'shipping_city' => 'shipping_city | shipping_city',
44
+ 'shipping_state' => 'shipping_state | shipping_state',
45
+ 'shipping_country' => 'shipping_country | shipping_country',
46
+ 'customer_note' => 'customer_note | customer_note',
47
+ 'shipping_items' => 'shipping_items | shipping_items',
48
+ 'fee_items' => 'fee_items | fee_items',
49
+ 'tax_items' => 'tax_items | tax_items',
50
+ 'coupon_items' => 'coupon_items | coupons',
51
+ 'order_notes' => 'order_notes | order_notes',
52
+ 'download_permissions' => 'Downloadable Product Permissions | Permissions for order items will automatically be granted when the order status changes to processing or completed.'
53
  );
includes/importer/views-coupon/html-wf-import-greeting.php CHANGED
@@ -1,43 +1,43 @@
1
- <div class="wrap woocommerce">
2
- <div class="icon32" id="icon-woocommerce-importer"><br></div>
3
- <h2 class="nav-tab-wrapper woo-nav-tab-wrapper">
4
- <a href="<?php echo admin_url('admin.php?page=wf_woocommerce_order_im_ex') ?>" class="nav-tab"><?php _e('Order Import / Export', 'wf_order_import_export'); ?></a>
5
- <a href="<?php echo admin_url('admin.php?page=wf_coupon_csv_im_ex&tab=coupon') ?>" class="nav-tab nav-tab-active"><?php _e('Coupon Import / Export', 'wf_order_import_export'); ?></a>
6
- <a href="<?php echo admin_url('admin.php?page=wf_woocommerce_order_im_ex&tab=subscription') ?>" class="nav-tab"><?php _e('Subscription Import / Export', 'wf_order_import_export'); ?></a>
7
- <a href="https://www.xadapter.com/product/order-import-export-plugin-for-woocommerce/" target="_blank" class="nav-tab nav-tab-premium"><?php _e('Upgrade to Premium for More Features', 'wf_order_import_export'); ?></a>
8
- </h2>
9
- <div class="orderimpexp-main-box">
10
- <div class="tool-box bg-white p-20p orderimpexp-view">
11
- <p><?php _e( 'You can import coupons (in CSV format) in to the shop using below methods.', 'wf_order_import_export' ); ?></p>
12
-
13
- <?php if ( ! empty( $upload_dir['error'] ) ) : ?>
14
- <div class="error"><p><?php _e('Before you can upload your import file, you will need to fix the following error:'); ?></p>
15
- <p><strong><?php echo $upload_dir['error']; ?></strong></p></div>
16
- <?php else : ?>
17
- <form enctype="multipart/form-data" id="import-upload-form" method="post" action="<?php echo esc_attr(wp_nonce_url($action, 'import-upload')); ?>">
18
- <table class="form-table">
19
- <tbody>
20
- <tr>
21
- <th>
22
- <label for="upload"><?php _e( 'Select a file from your computer' ); ?></label>
23
- </th>
24
- <td>
25
- <input type="file" id="upload" name="import" size="25" />
26
- <input type="hidden" name="action" value="save" />
27
- <input type="hidden" name="max_file_size" value="<?php echo $bytes; ?>" />
28
- <small><?php printf( __('Maximum size: %s' ), $size ); ?></small>
29
- </td>
30
- </tr>
31
-
32
- </tbody>
33
- </table>
34
- <p class="submit">
35
- <input type="submit" class="button button-primary" value="<?php esc_attr_e( 'Upload file and import' ); ?>" />
36
- </p>
37
- </form>
38
- <?php endif; ?>
39
- </div>
40
- <?php include(WT_OrdImpExpCsv_BASE . 'includes/views/market.php'); ?>
41
- <div class="clearfix"></div>
42
- </div>
43
  </div>
1
+ <div class="wrap woocommerce">
2
+ <div class="icon32" id="icon-woocommerce-importer"><br></div>
3
+ <h2 class="nav-tab-wrapper woo-nav-tab-wrapper">
4
+ <a href="<?php echo admin_url('admin.php?page=wf_woocommerce_order_im_ex') ?>" class="nav-tab"><?php _e('Order Import / Export', 'wf_order_import_export'); ?></a>
5
+ <a href="<?php echo admin_url('admin.php?page=wf_coupon_csv_im_ex&tab=coupon') ?>" class="nav-tab nav-tab-active"><?php _e('Coupon Import / Export', 'wf_order_import_export'); ?></a>
6
+ <a href="<?php echo admin_url('admin.php?page=wf_woocommerce_order_im_ex&tab=subscription') ?>" class="nav-tab"><?php _e('Subscription Import / Export', 'wf_order_import_export'); ?></a>
7
+ <a href="https://www.xadapter.com/product/order-import-export-plugin-for-woocommerce/" target="_blank" class="nav-tab nav-tab-premium"><?php _e('Upgrade to Premium for More Features', 'wf_order_import_export'); ?></a>
8
+ </h2>
9
+ <div class="orderimpexp-main-box">
10
+ <div class="tool-box bg-white p-20p orderimpexp-view">
11
+ <p><?php _e( 'You can import coupons (in CSV format) in to the shop using below methods.', 'wf_order_import_export' ); ?></p>
12
+
13
+ <?php if ( ! empty( $upload_dir['error'] ) ) : ?>
14
+ <div class="error"><p><?php _e('Before you can upload your import file, you will need to fix the following error:'); ?></p>
15
+ <p><strong><?php echo $upload_dir['error']; ?></strong></p></div>
16
+ <?php else : ?>
17
+ <form enctype="multipart/form-data" id="import-upload-form" method="post" action="<?php echo esc_attr(wp_nonce_url($action, 'import-upload')); ?>">
18
+ <table class="form-table">
19
+ <tbody>
20
+ <tr>
21
+ <th>
22
+ <label for="upload"><?php _e( 'Select a file from your computer' ); ?></label>
23
+ </th>
24
+ <td>
25
+ <input type="file" id="upload" name="import" size="25" />
26
+ <input type="hidden" name="action" value="save" />
27
+ <input type="hidden" name="max_file_size" value="<?php echo $bytes; ?>" />
28
+ <small><?php printf( __('Maximum size: %s' ), $size ); ?></small>
29
+ </td>
30
+ </tr>
31
+
32
+ </tbody>
33
+ </table>
34
+ <p class="submit">
35
+ <input type="submit" class="button button-primary" value="<?php esc_attr_e( 'Upload file and import' ); ?>" />
36
+ </p>
37
+ </form>
38
+ <?php endif; ?>
39
+ </div>
40
+ <?php include(WT_OrdImpExpCsv_BASE . 'includes/views/market.php'); ?>
41
+ <div class="clearfix"></div>
42
+ </div>
43
  </div>
includes/importer/views-coupon/html-wf-import-options.php CHANGED
@@ -1,18 +1,18 @@
1
- <form action="<?php echo admin_url('admin.php?import=' . $this->import_page . '&step=2&merge=' . $merge); ?>" method="post" id="nomap">
2
- <?php wp_nonce_field('import-woocommerce'); ?>
3
- <input type="hidden" name="import_id" value="<?php echo $this->id; ?>" />
4
- <?php if ($this->file_url_import_enabled) : ?>
5
- <input type="hidden" name="import_url" value="<?php echo $this->file_url; ?>" />
6
- <?php endif; ?>
7
-
8
- <p class="submit">
9
- <input style="display:none" type="submit" class="button button-primary" value="<?php esc_attr_e('Submit', 'wf_order_import_export'); ?>" />
10
- <input type="hidden" name="delimiter" value="<?php echo $this->delimiter ?>" />
11
- <input type="hidden" name="merge_empty_cells" value="<?php echo $this->merge_empty_cells ?>" />
12
- </p>
13
- </form>
14
- <script type="text/javascript">
15
- jQuery(document).ready(function () {
16
- jQuery("form#nomap").submit();
17
- });
18
  </script>
1
+ <form action="<?php echo admin_url('admin.php?import=' . $this->import_page . '&step=2&merge=' . $merge); ?>" method="post" id="nomap">
2
+ <?php wp_nonce_field('import-woocommerce'); ?>
3
+ <input type="hidden" name="import_id" value="<?php echo $this->id; ?>" />
4
+ <?php if ($this->file_url_import_enabled) : ?>
5
+ <input type="hidden" name="import_url" value="<?php echo $this->file_url; ?>" />
6
+ <?php endif; ?>
7
+
8
+ <p class="submit">
9
+ <input style="display:none" type="submit" class="button button-primary" value="<?php esc_attr_e('Submit', 'wf_order_import_export'); ?>" />
10
+ <input type="hidden" name="delimiter" value="<?php echo $this->delimiter ?>" />
11
+ <input type="hidden" name="merge_empty_cells" value="<?php echo $this->merge_empty_cells ?>" />
12
+ </p>
13
+ </form>
14
+ <script type="text/javascript">
15
+ jQuery(document).ready(function () {
16
+ jQuery("form#nomap").submit();
17
+ });
18
  </script>
includes/importer/views/html-wf-import-greeting.php CHANGED
@@ -1,43 +1,43 @@
1
- <div class="wrap woocommerce">
2
- <div class="icon32" id="icon-woocommerce-importer"><br></div>
3
- <h2 class="nav-tab-wrapper woo-nav-tab-wrapper">
4
- <a href="<?php echo admin_url('admin.php?page=wf_woocommerce_order_im_ex') ?>" class="nav-tab nav-tab-active"><?php _e('Order Import / Export', 'wf_order_import_export'); ?></a>
5
- <a href="<?php echo admin_url('admin.php?page=wf_coupon_csv_im_ex&tab=coupon') ?>" class="nav-tab"><?php _e('Coupon Import / Export', 'wf_order_import_export'); ?></a>
6
- <a href="<?php echo admin_url('admin.php?page=wf_woocommerce_order_im_ex&tab=subscription') ?>" class="nav-tab"><?php _e('Subscription Import / Export', 'wf_order_import_export'); ?></a>
7
- <a href="https://www.xadapter.com/product/order-import-export-plugin-for-woocommerce/" target="_blank" class="nav-tab nav-tab-premium"><?php _e('Upgrade to Premium for More Features', 'wf_order_import_export'); ?></a>
8
- </h2>
9
- <div class="orderimpexp-main-box">
10
- <div class="tool-box bg-white p-20p orderimpexp-view">
11
- <p><?php _e('You can import orders (in CSV format) in to the shop using below methods.', 'wf_order_import_export'); ?></p>
12
-
13
- <?php if (!empty($upload_dir['error'])) : ?>
14
- <div class="error"><p><?php _e('Before you can upload your import file, you will need to fix the following error:'); ?></p>
15
- <p><strong><?php echo $upload_dir['error']; ?></strong></p></div>
16
- <?php else : ?>
17
- <form enctype="multipart/form-data" id="import-upload-form" method="post" action="<?php echo esc_attr(wp_nonce_url($action, 'import-upload')); ?>">
18
- <table class="form-table">
19
- <tbody>
20
- <tr>
21
- <th>
22
- <label for="upload"><?php _e('Select a file from your computer'); ?></label>
23
- </th>
24
- <td>
25
- <input type="file" id="upload" name="import" size="25" />
26
- <input type="hidden" name="action" value="save" />
27
- <input type="hidden" name="max_file_size" value="<?php echo $bytes; ?>" />
28
- <small><?php printf(__('Maximum size: %s'), $size); ?></small>
29
- </td>
30
- </tr>
31
-
32
- </tbody>
33
- </table>
34
- <p class="submit">
35
- <input type="submit" class="button button-primary" value="<?php esc_attr_e('Upload file and import'); ?>" />
36
- </p>
37
- </form>
38
- <?php endif; ?>
39
- </div>
40
- <?php include(WT_OrdImpExpCsv_BASE . 'includes/views/market.php'); ?>
41
- <div class="clearfix"></div>
42
- </div>
43
  </div>
1
+ <div class="wrap woocommerce">
2
+ <div class="icon32" id="icon-woocommerce-importer"><br></div>
3
+ <h2 class="nav-tab-wrapper woo-nav-tab-wrapper">
4
+ <a href="<?php echo admin_url('admin.php?page=wf_woocommerce_order_im_ex') ?>" class="nav-tab nav-tab-active"><?php _e('Order Import / Export', 'wf_order_import_export'); ?></a>
5
+ <a href="<?php echo admin_url('admin.php?page=wf_coupon_csv_im_ex&tab=coupon') ?>" class="nav-tab"><?php _e('Coupon Import / Export', 'wf_order_import_export'); ?></a>
6
+ <a href="<?php echo admin_url('admin.php?page=wf_woocommerce_order_im_ex&tab=subscription') ?>" class="nav-tab"><?php _e('Subscription Import / Export', 'wf_order_import_export'); ?></a>
7
+ <a href="https://www.xadapter.com/product/order-import-export-plugin-for-woocommerce/" target="_blank" class="nav-tab nav-tab-premium"><?php _e('Upgrade to Premium for More Features', 'wf_order_import_export'); ?></a>
8
+ </h2>
9
+ <div class="orderimpexp-main-box">
10
+ <div class="tool-box bg-white p-20p orderimpexp-view">
11
+ <p><?php _e('You can import orders (in CSV format) in to the shop using below methods.', 'wf_order_import_export'); ?></p>
12
+
13
+ <?php if (!empty($upload_dir['error'])) : ?>
14
+ <div class="error"><p><?php _e('Before you can upload your import file, you will need to fix the following error:'); ?></p>
15
+ <p><strong><?php echo $upload_dir['error']; ?></strong></p></div>
16
+ <?php else : ?>
17
+ <form enctype="multipart/form-data" id="import-upload-form" method="post" action="<?php echo esc_attr(wp_nonce_url($action, 'import-upload')); ?>">
18
+ <table class="form-table">
19
+ <tbody>
20
+ <tr>
21
+ <th>
22
+ <label for="upload"><?php _e('Select a file from your computer'); ?></label>
23
+ </th>
24
+ <td>
25
+ <input type="file" id="upload" name="import" size="25" />
26
+ <input type="hidden" name="action" value="save" />
27
+ <input type="hidden" name="max_file_size" value="<?php echo $bytes; ?>" />
28
+ <small><?php printf(__('Maximum size: %s'), $size); ?></small>
29
+ </td>
30
+ </tr>
31
+
32
+ </tbody>
33
+ </table>
34
+ <p class="submit">
35
+ <input type="submit" class="button button-primary" value="<?php esc_attr_e('Upload file and import'); ?>" />
36
+ </p>
37
+ </form>
38
+ <?php endif; ?>
39
+ </div>
40
+ <?php include(WT_OrdImpExpCsv_BASE . 'includes/views/market.php'); ?>
41
+ <div class="clearfix"></div>
42
+ </div>
43
  </div>
includes/importer/views/html-wf-import-options.php CHANGED
@@ -1,28 +1,28 @@
1
- <?php $tab = (isset($_GET['tab'])?$_GET['tab']:'import'); ?>
2
- <div class="wrap woocommerce">
3
- <div class="icon32" id="icon-woocommerce-importer"><br></div>
4
- <h2 class="nav-tab-wrapper woo-nav-tab-wrapper">
5
- <a href="<?php echo admin_url('admin.php?page=wf_woocommerce_order_im_ex') ?>" class="nav-tab <?php echo ($tab == 'import') ? 'nav-tab-active' : ''; ?>"><?php _e('Order Import / Export', 'wf_order_import_export'); ?></a>
6
- <a href="<?php echo admin_url('admin.php?page=wf_coupon_csv_im_ex&tab=coupon') ?>" class="nav-tab <?php echo ($tab == 'coupon') ? 'nav-tab-active' : ''; ?>"><?php _e('Coupon Import / Export', 'wf_order_import_export'); ?></a>
7
- <a href="<?php echo admin_url('admin.php?page=wf_woocommerce_order_im_ex&tab=subscription') ?>" class="nav-tab <?php echo ($tab == 'subscription') ? 'nav-tab-active' : ''; ?>"><?php _e('Subscription Import / Export', 'wf_order_import_export'); ?></a>
8
- <a href="https://www.xadapter.com/product/order-import-export-plugin-for-woocommerce/" target="_blank" class="nav-tab nav-tab-premium"><?php _e('Upgrade to Premium for More Features', 'wf_order_import_export'); ?></a>
9
- </h2>
10
-
11
- <form action="<?php echo admin_url('admin.php?import=' . $this->import_page . '&step=2&merge=' . $merge); ?>" method="post" id="nomap">
12
- <?php wp_nonce_field('import-woocommerce'); ?>
13
- <input type="hidden" name="import_id" value="<?php echo $this->id; ?>" />
14
- <?php if ($this->file_url_import_enabled) : ?>
15
- <input type="hidden" name="import_url" value="<?php echo $this->file_url; ?>" />
16
- <?php endif; ?>
17
- <p class="submit">
18
- <input style="display:none" type="submit" class="button button-primary" value="<?php esc_attr_e('Submit', 'wf_order_import_export'); ?>" />
19
- <input type="hidden" name="delimiter" value="<?php echo $this->delimiter ?>" />
20
- <input type="hidden" name="merge_empty_cells" value="<?php echo $this->merge_empty_cells ?>" />
21
- </p>
22
- </form>
23
- <script type="text/javascript">
24
- jQuery(document).ready(function(){
25
- jQuery("form#nomap").submit();
26
- });
27
- </script>
28
  </div>
1
+ <?php $tab = (isset($_GET['tab'])?$_GET['tab']:'import'); ?>
2
+ <div class="wrap woocommerce">
3
+ <div class="icon32" id="icon-woocommerce-importer"><br></div>
4
+ <h2 class="nav-tab-wrapper woo-nav-tab-wrapper">
5
+ <a href="<?php echo admin_url('admin.php?page=wf_woocommerce_order_im_ex') ?>" class="nav-tab <?php echo ($tab == 'import') ? 'nav-tab-active' : ''; ?>"><?php _e('Order Import / Export', 'wf_order_import_export'); ?></a>
6
+ <a href="<?php echo admin_url('admin.php?page=wf_coupon_csv_im_ex&tab=coupon') ?>" class="nav-tab <?php echo ($tab == 'coupon') ? 'nav-tab-active' : ''; ?>"><?php _e('Coupon Import / Export', 'wf_order_import_export'); ?></a>
7
+ <a href="<?php echo admin_url('admin.php?page=wf_woocommerce_order_im_ex&tab=subscription') ?>" class="nav-tab <?php echo ($tab == 'subscription') ? 'nav-tab-active' : ''; ?>"><?php _e('Subscription Import / Export', 'wf_order_import_export'); ?></a>
8
+ <a href="https://www.xadapter.com/product/order-import-export-plugin-for-woocommerce/" target="_blank" class="nav-tab nav-tab-premium"><?php _e('Upgrade to Premium for More Features', 'wf_order_import_export'); ?></a>
9
+ </h2>
10
+
11
+ <form action="<?php echo admin_url('admin.php?import=' . $this->import_page . '&step=2&merge=' . $merge); ?>" method="post" id="nomap">
12
+ <?php wp_nonce_field('import-woocommerce'); ?>
13
+ <input type="hidden" name="import_id" value="<?php echo $this->id; ?>" />
14
+ <?php if ($this->file_url_import_enabled) : ?>
15
+ <input type="hidden" name="import_url" value="<?php echo $this->file_url; ?>" />
16
+ <?php endif; ?>
17
+ <p class="submit">
18
+ <input style="display:none" type="submit" class="button button-primary" value="<?php esc_attr_e('Submit', 'wf_order_import_export'); ?>" />
19
+ <input type="hidden" name="delimiter" value="<?php echo $this->delimiter ?>" />
20
+ <input type="hidden" name="merge_empty_cells" value="<?php echo $this->merge_empty_cells ?>" />
21
+ </p>
22
+ </form>
23
+ <script type="text/javascript">
24
+ jQuery(document).ready(function(){
25
+ jQuery("form#nomap").submit();
26
+ });
27
+ </script>
28
  </div>
includes/settings/class-wf-orderimpexpcsv-settings.php CHANGED
@@ -1,21 +1,21 @@
1
- <?php
2
- if ( ! defined( 'ABSPATH' ) ) {
3
- exit;
4
- }
5
-
6
- class WF_OrderImpExpCsv_Settings {
7
-
8
- /**
9
- * Order Exporter Tool
10
- */
11
- public static function save_settings( ) {
12
- global $wpdb;
13
-
14
- $settings = array();
15
-
16
- update_option( 'woocommerce_'.WF_ORDER_IMP_EXP_ID.'_settings', $settings );
17
-
18
- wp_redirect( admin_url( '/admin.php?page='.WF_WOOCOMMERCE_ORDER_IM_EX.'&tab=settings' ) );
19
- exit;
20
- }
21
- }
1
+ <?php
2
+ if ( ! defined( 'ABSPATH' ) ) {
3
+ exit;
4
+ }
5
+
6
+ class WF_OrderImpExpCsv_Settings {
7
+
8
+ /**
9
+ * Order Exporter Tool
10
+ */
11
+ public static function save_settings( ) {
12
+ global $wpdb;
13
+
14
+ $settings = array();
15
+
16
+ update_option( 'woocommerce_'.WF_ORDER_IMP_EXP_ID.'_settings', $settings );
17
+
18
+ wp_redirect( admin_url( '/admin.php?page='.WF_WOOCOMMERCE_ORDER_IM_EX.'&tab=settings' ) );
19
+ exit;
20
+ }
21
+ }
includes/views/export/html-wf-export-coupons.php CHANGED
@@ -1,15 +1,15 @@
1
- <div class="tool-box bg-white p-20p">
2
- <h3 class="title"><?php _e('Export Coupon in CSV Format:', 'wf_order_import_export'); ?></h3>
3
- <p><?php _e('Export and download your coupons in CSV format. This file can be used to import coupons back into your Woocommerce shop.', 'wf_order_import_export'); ?></p>
4
- <form action="<?php echo admin_url('admin.php?page=wf_coupon_csv_im_ex&action=export'); ?>" method="post">
5
-
6
- <table class="form-table">
7
-
8
- </table>
9
- <p class="submit"><input type="submit" class="button button-primary" value="<?php _e('Export Coupons', 'wf_order_import_export'); ?>" /></p>
10
- </form>
11
- </div>
12
- </div>
13
- <?php include(WT_OrdImpExpCsv_BASE . 'includes/views/market.php'); ?>
14
- <div class="clearfix"></div>
15
  </div>
1
+ <div class="tool-box bg-white p-20p">
2
+ <h3 class="title"><?php _e('Export Coupon in CSV Format:', 'wf_order_import_export'); ?></h3>
3
+ <p><?php _e('Export and download your coupons in CSV format. This file can be used to import coupons back into your Woocommerce shop.', 'wf_order_import_export'); ?></p>
4
+ <form action="<?php echo admin_url('admin.php?page=wf_coupon_csv_im_ex&action=export'); ?>" method="post">
5
+
6
+ <table class="form-table">
7
+
8
+ </table>
9
+ <p class="submit"><input type="submit" class="button button-primary" value="<?php _e('Export Coupons', 'wf_order_import_export'); ?>" /></p>
10
+ </form>
11
+ </div>
12
+ </div>
13
+ <?php include(WT_OrdImpExpCsv_BASE . 'includes/views/market.php'); ?>
14
+ <div class="clearfix"></div>
15
  </div>
includes/views/export/html-wf-export-orders.php CHANGED
@@ -1,11 +1,11 @@
1
- <div class="tool-box bg-white p-20p">
2
- <h3 class="title"><?php _e('Export Orders in CSV Format:', 'wf_order_import_export'); ?></h3>
3
- <p><?php _e('Export and download your orders in CSV format. This file can be used to import orders back into your Woocommerce shop.', 'wf_order_import_export'); ?></p>
4
- <form action="<?php echo admin_url('admin.php?page=wf_woocommerce_order_im_ex&action=export'); ?>" method="post">
5
- <p class="submit"><input type="submit" class="button button-primary" value="<?php _e('Export Orders', 'wf_order_import_export'); ?>" /></p>
6
- </form>
7
- </div>
8
- </div>
9
- <?php include(WT_OrdImpExpCsv_BASE . 'includes/views/market.php'); ?>
10
- <div class="clearfix"></div>
11
  </div>
1
+ <div class="tool-box bg-white p-20p">
2
+ <h3 class="title"><?php _e('Export Orders in CSV Format:', 'wf_order_import_export'); ?></h3>
3
+ <p><?php _e('Export and download your orders in CSV format. This file can be used to import orders back into your Woocommerce shop.', 'wf_order_import_export'); ?></p>
4
+ <form action="<?php echo admin_url('admin.php?page=wf_woocommerce_order_im_ex&action=export'); ?>" method="post">
5
+ <p class="submit"><input type="submit" class="button button-primary" value="<?php _e('Export Orders', 'wf_order_import_export'); ?>" /></p>
6
+ </form>
7
+ </div>
8
+ </div>
9
+ <?php include(WT_OrdImpExpCsv_BASE . 'includes/views/market.php'); ?>
10
+ <div class="clearfix"></div>
11
  </div>
includes/views/html-wf-admin-screen.php CHANGED
@@ -1,26 +1,26 @@
1
- <div class="woocommerce" style="margin: 10px 20px 0 2px;">
2
- <div class="icon32" id="icon-woocommerce-importer"><br></div>
3
- <h2 class="nav-tab-wrapper woo-nav-tab-wrapper">
4
- <a href="<?php echo admin_url('admin.php?page=wf_woocommerce_order_im_ex') ?>" class="nav-tab <?php echo ($tab == 'import') ? 'nav-tab-active' : ''; ?>"><?php _e('Order Import / Export', 'wf_order_import_export'); ?></a>
5
- <a href="<?php echo admin_url('admin.php?page=wf_coupon_csv_im_ex&tab=coupon') ?>" class="nav-tab <?php echo ($tab == 'coupon') ? 'nav-tab-active' : ''; ?>"><?php _e('Coupon Import / Export', 'wf_order_import_export'); ?></a>
6
- <a href="<?php echo admin_url('admin.php?page=wf_woocommerce_order_im_ex&tab=subscription') ?>" class="nav-tab <?php echo ($tab == 'subscription') ? 'nav-tab-active' : ''; ?>"><?php _e('Subscription Import / Export', 'wf_order_import_export'); ?></a>
7
- <a href="https://www.xadapter.com/product/order-import-export-plugin-for-woocommerce/" target="_blank" class="nav-tab nav-tab-premium"><?php _e('Upgrade to Premium for More Features', 'wf_order_import_export'); ?></a>
8
- </h2>
9
-
10
- <?php
11
- switch ($tab) {
12
- case "export" :
13
- $this->admin_export_page();
14
- break;
15
- case "coupon" :
16
- $this->admin_coupon_page();
17
- break;
18
- case "subscription" :
19
- $this->admin_subscription_page();
20
- break;
21
- default :
22
- $this->admin_import_page();
23
- break;
24
- }
25
- ?>
26
  </div>
1
+ <div class="woocommerce" style="margin: 10px 20px 0 2px;">
2
+ <div class="icon32" id="icon-woocommerce-importer"><br></div>
3
+ <h2 class="nav-tab-wrapper woo-nav-tab-wrapper">
4
+ <a href="<?php echo admin_url('admin.php?page=wf_woocommerce_order_im_ex') ?>" class="nav-tab <?php echo ($tab == 'import') ? 'nav-tab-active' : ''; ?>"><?php _e('Order Import / Export', 'wf_order_import_export'); ?></a>
5
+ <a href="<?php echo admin_url('admin.php?page=wf_coupon_csv_im_ex&tab=coupon') ?>" class="nav-tab <?php echo ($tab == 'coupon') ? 'nav-tab-active' : ''; ?>"><?php _e('Coupon Import / Export', 'wf_order_import_export'); ?></a>
6
+ <a href="<?php echo admin_url('admin.php?page=wf_woocommerce_order_im_ex&tab=subscription') ?>" class="nav-tab <?php echo ($tab == 'subscription') ? 'nav-tab-active' : ''; ?>"><?php _e('Subscription Import / Export', 'wf_order_import_export'); ?></a>
7
+ <a href="https://www.xadapter.com/product/order-import-export-plugin-for-woocommerce/" target="_blank" class="nav-tab nav-tab-premium"><?php _e('Upgrade to Premium for More Features', 'wf_order_import_export'); ?></a>
8
+ </h2>
9
+
10
+ <?php
11
+ switch ($tab) {
12
+ case "export" :
13
+ $this->admin_export_page();
14
+ break;
15
+ case "coupon" :
16
+ $this->admin_coupon_page();
17
+ break;
18
+ case "subscription" :
19
+ $this->admin_subscription_page();
20
+ break;
21
+ default :
22
+ $this->admin_import_page();
23
+ break;
24
+ }
25
+ ?>
26
  </div>
includes/views/html-wf-getting-started-subscription.php CHANGED
@@ -1,19 +1,18 @@
1
- <div class="orderimpexp-main-box">
2
- <div class="orderimpexp-view" style="width:68%;">
3
- <div class="tool-box bg-white p-20p">
4
- <div id="message" class="updated woocommerce-message wc-connect">
5
- <div class="squeezer">
6
- <h4><?php _e('<strong>This Feature is only available in Premium version</strong>', 'wf_order_import_export'); ?></h4>
7
- <p class="submit">
8
- <a href="http://www.xadapter.com/product/order-import-export-plugin-for-woocommerce/" target="_blank" class="button button-primary"><?php _e('Upgrade to Premium Version', 'wf_order_import_export'); ?></a>
9
- <a href="http://orderimportexport.hikeforce.com/wp-admin/admin.php?page=wf_woocommerce_order_im_ex" target="_blank" class="button"><?php _e('Live Demo', 'wf_order_import_export'); ?></a>
10
- <a href="http://www.xadapter.com/2016/06/20/setting-up-order-import-export-plugin-for-woocommerce/" target="_blank" class="button"><?php _e('Documentation', 'wf_order_import_export'); ?></a>
11
- <a href="<?php echo plugins_url('Sample_Subscription.csv', WF_OrderImpExpCsv_FILE); ?>" target="_blank" class="button"><?php _e('Sample Subscription CSV', 'wf_order_import_export'); ?></a>
12
- </p>
13
- </div>
14
- </div>
15
- </div>
16
- </div>
17
- <?php include(WT_OrdImpExpCsv_BASE . 'includes/views/market.php'); ?>
18
- <div class="clearfix"></div>
19
  </div>
1
+ <div class="orderimpexp-main-box">
2
+ <div class="orderimpexp-view" style="width:68%;">
3
+ <div class="tool-box bg-white p-20p">
4
+ <div id="message" class="updated woocommerce-message wc-connect">
5
+ <div class="squeezer">
6
+ <h4><?php _e('<strong>This Feature is only available in Premium version</strong>', 'wf_order_import_export'); ?></h4>
7
+ <p class="submit">
8
+ <a href="http://www.xadapter.com/product/order-import-export-plugin-for-woocommerce/" target="_blank" class="button button-primary"><?php _e('Upgrade to Premium Version', 'wf_order_import_export'); ?></a>
9
+ <a href="http://www.xadapter.com/2016/06/20/setting-up-order-import-export-plugin-for-woocommerce/" target="_blank" class="button"><?php _e('Documentation', 'wf_order_import_export'); ?></a>
10
+ <a href="<?php echo plugins_url('Sample_Subscription.csv', WF_OrderImpExpCsv_FILE); ?>" target="_blank" class="button"><?php _e('Sample Subscription CSV', 'wf_order_import_export'); ?></a>
11
+ </p>
12
+ </div>
13
+ </div>
14
+ </div>
15
+ </div>
16
+ <?php include(WT_OrdImpExpCsv_BASE . 'includes/views/market.php'); ?>
17
+ <div class="clearfix"></div>
 
18
  </div>
includes/views/import/html-wf-import-coupons.php CHANGED
@@ -1,24 +1,24 @@
1
- <div class="orderimpexp-main-box">
2
- <div class="orderimpexp-view" style="width:68%;">
3
- <div class="tool-box bg-white p-20p" style="margin-bottom: 20px;">
4
- <h3 class="title"><?php _e('Import Coupons in CSV Format:', 'wf_order_import_export'); ?></h3>
5
- <p><?php _e('Import coupons in CSV format from different sources ( from your computer OR from another server via FTP )', 'wf_order_import_export'); ?></p>
6
- <p class="submit">
7
- <?php
8
- $merge_url = admin_url('admin.php?import=coupon_csv&merge=1');
9
- $import_url = admin_url('admin.php?import=coupon_csv');
10
- ?>
11
- <a class="button button-primary" id="mylink" href="<?php echo admin_url('admin.php?import=coupon_csv'); ?>"><?php _e('Import Coupons', 'wf_order_import_export'); ?></a>
12
- &nbsp;
13
- <input type="checkbox" id="merge" value="0"><?php _e('Update coupons if exists', 'wf_order_import_export'); ?> <br>
14
- </p>
15
- </div>
16
- <script type="text/javascript">
17
- jQuery('#merge').click(function () {
18
- if (this.checked) {
19
- jQuery("#mylink").attr("href", '<?php echo $merge_url ?>');
20
- } else {
21
- jQuery("#mylink").attr("href", '<?php echo $import_url ?>');
22
- }
23
- });
24
- </script>
1
+ <div class="orderimpexp-main-box">
2
+ <div class="orderimpexp-view" style="width:68%;">
3
+ <div class="tool-box bg-white p-20p" style="margin-bottom: 20px;">
4
+ <h3 class="title"><?php _e('Import Coupons in CSV Format:', 'wf_order_import_export'); ?></h3>
5
+ <p><?php _e('Import coupons in CSV format from different sources ( from your computer OR from another server via FTP )', 'wf_order_import_export'); ?></p>
6
+ <p class="submit">
7
+ <?php
8
+ $merge_url = admin_url('admin.php?import=coupon_csv&merge=1');
9
+ $import_url = admin_url('admin.php?import=coupon_csv');
10
+ ?>
11
+ <a class="button button-primary" id="mylink" href="<?php echo admin_url('admin.php?import=coupon_csv'); ?>"><?php _e('Import Coupons', 'wf_order_import_export'); ?></a>
12
+ &nbsp;
13
+ <input type="checkbox" id="merge" value="0"><?php _e('Update coupons if exists', 'wf_order_import_export'); ?> <br>
14
+ </p>
15
+ </div>
16
+ <script type="text/javascript">
17
+ jQuery('#merge').click(function () {
18
+ if (this.checked) {
19
+ jQuery("#mylink").attr("href", '<?php echo $merge_url ?>');
20
+ } else {
21
+ jQuery("#mylink").attr("href", '<?php echo $import_url ?>');
22
+ }
23
+ });
24
+ </script>
includes/views/import/html-wf-import-orders.php CHANGED
@@ -1,24 +1,24 @@
1
- <div class="orderimpexp-main-box">
2
- <div class="orderimpexp-view" style="width:68%;">
3
- <div class="tool-box bg-white p-20p" style="margin-bottom: 20px;">
4
- <h3 class="title"><?php _e('Import Orders in CSV Format:', 'wf_order_import_export'); ?></h3>
5
- <p><?php _e('Import Orders in CSV format from different sources ( from your computer OR from another server via FTP )', 'wf_order_import_export'); ?></p>
6
- <p class="submit">
7
- <?php
8
- $merge_url = admin_url('admin.php?import=woocommerce_wf_order_csv&merge=1');
9
- $import_url = admin_url('admin.php?import=woocommerce_wf_order_csv');
10
- ?>
11
- <a class="button button-primary" id="mylink" href="<?php echo admin_url('admin.php?import=woocommerce_wf_order_csv'); ?>"><?php _e('Import Orders', 'wf_order_import_export'); ?></a>
12
- &nbsp;
13
- <input type="checkbox" id="merge" value="0"><?php _e('Update order if exists', 'wf_order_import_export'); ?> <br>
14
- </p>
15
- </div>
16
- <script type="text/javascript">
17
- jQuery('#merge').click(function () {
18
- if (this.checked) {
19
- jQuery("#mylink").attr("href", '<?php echo $merge_url ?>');
20
- } else {
21
- jQuery("#mylink").attr("href", '<?php echo $import_url ?>');
22
- }
23
- });
24
  </script>
1
+ <div class="orderimpexp-main-box">
2
+ <div class="orderimpexp-view" style="width:68%;">
3
+ <div class="tool-box bg-white p-20p" style="margin-bottom: 20px;">
4
+ <h3 class="title"><?php _e('Import Orders in CSV Format:', 'wf_order_import_export'); ?></h3>
5
+ <p><?php _e('Import Orders in CSV format from different sources ( from your computer OR from another server via FTP )', 'wf_order_import_export'); ?></p>
6
+ <p class="submit">
7
+ <?php
8
+ $merge_url = admin_url('admin.php?import=woocommerce_wf_order_csv&merge=1');
9
+ $import_url = admin_url('admin.php?import=woocommerce_wf_order_csv');
10
+ ?>
11
+ <a class="button button-primary" id="mylink" href="<?php echo admin_url('admin.php?import=woocommerce_wf_order_csv'); ?>"><?php _e('Import Orders', 'wf_order_import_export'); ?></a>
12
+ &nbsp;
13
+ <input type="checkbox" id="merge" value="0"><?php _e('Update order if exists', 'wf_order_import_export'); ?> <br>
14
+ </p>
15
+ </div>
16
+ <script type="text/javascript">
17
+ jQuery('#merge').click(function () {
18
+ if (this.checked) {
19
+ jQuery("#mylink").attr("href", '<?php echo $merge_url ?>');
20
+ } else {
21
+ jQuery("#mylink").attr("href", '<?php echo $import_url ?>');
22
+ }
23
+ });
24
  </script>
includes/views/market.php CHANGED
@@ -1,61 +1,59 @@
1
- <?php
2
- if (!defined('ABSPATH')) {
3
- exit;
4
- }
5
- ?>
6
- <div class="market-box table-box-main">
7
- <div class="orderimpexp-premium-features">
8
- <center><a href="https://www.xadapter.com/product/order-import-export-plugin-for-woocommerce/" target="_blank" class="button button-primary button-go-pro"><?php _e('Upgrade to Premium Version', 'wf_csv_import_export'); ?></a></center>
9
- <span>
10
- <ul>
11
- <li><?php _e('Import and Export Subscriptions along with Order and Coupon.', 'wf_order_import_export'); ?></li>
12
- <li><?php _e('Filtering options while Export using Order Status, Date, Coupon Type etc.', 'wf_order_import_export'); ?></li>
13
- <li><?php _e('Change values while import using Evaluation Field feature.', 'wf_order_import_export'); ?></li>
14
- <li><?php _e('A number of third party plugins supported.', 'wf_order_import_export'); ?> </li>
15
- <li><?php _e('Column Mapping Feature to Import from any CSV format ( Magento, Shopify, OpenCart etc. ).', 'wf_order_import_export'); ?></li>
16
- <li><?php _e('Import and Export via FTP.', 'wf_order_import_export'); ?></li>
17
- <li><?php _e('Choice to update or skip existing orderswhile importing.', 'wf_order_import_export'); ?></li>
18
- <li><?php _e('WPML supported. French and German support out of the box.', 'wf_order_import_export'); ?></li>
19
- </ul>
20
- </span>
21
- <div id="show_more" style="display: none">
22
- <span>
23
-
24
- <ul>
25
- <li><?php _e('Schedule automatic import and export using Cron Job Feature.', 'wf_order_import_export'); ?></li>
26
- <li><?php _e('Automatic scheduled import and export.', 'wf_order_import_export'); ?></li>
27
- <li><?php _e('XML Export/Import supports Stamps.com desktop application, UPS WorldShip, Endicia and FedEx.', 'wf_order_import_export'); ?></li>
28
- <li><?php _e('30 Days Money Back Guarantee.', 'wf_order_import_export'); ?></li>
29
- <li><?php _e('More frequent plugin updates.', 'wf_order_import_export'); ?></li>
30
- <li><?php _e('Excellent Support for setting it up!', 'wf_order_import_export'); ?></li>
31
- </ul>
32
-
33
- </span>
34
- <center>
35
- <a href="http://orderimportexport.hikeforce.com/wp-admin/admin.php?page=wf_woocommerce_order_im_ex" target="_blank" class="button button-doc-demo"><?php _e('Live Demo', 'wf_order_import_export'); ?></a>
36
- <a href="https://www.xadapter.com/setting-up-order-import-export-plugin-for-woocommerce/" target="_blank" class="button button-doc-demo"><?php _e('Documentation', 'wf_order_import_export'); ?></a>
37
- </center>
38
- <center>
39
- <a href="<?php echo plugins_url('Sample_Order.csv', WF_OrderImpExpCsv_FILE); ?>" target="_blank" class="button button-doc-demo"><?php _e('Sample Order CSV', 'wf_order_import_export'); ?></a>
40
- <a href="<?php echo plugins_url('Sample_Coupon.csv', WF_OrderImpExpCsv_FILE); ?>" target="_blank" class="button button-doc-demo"><?php _e('Sample Coupon CSV', 'wf_order_import_export'); ?></a>
41
- </center>
42
- </div>
43
- <div class="button-show-more">
44
- <button class="button" onclick="showMoreFeatures()" id="showMoreButton" >Show more
45
- <i class="dashicons dashicons-arrow-down-alt2"></i>
46
- </button>
47
- </div>
48
- </div>
49
- <div class="orderimpexp-review-widget">
50
- <?php
51
- echo sprintf(__('<div class=""><p><i>If you like the plugin please leave us a %1$s review!</i><p></div>', 'wf_csv_import_export'), '<a href="https://wordpress.org/support/plugin/order-import-export-for-woocommerce/reviews?rate=5#new-post" target="_blank" class="xa-orderimpexp-rating-link" data-reviewed="' . esc_attr__('Thanks for the review.', 'wf_csv_import_export') . '">&#9733;&#9733;&#9733;&#9733;&#9733;</a>');
52
- ?>
53
- </div>
54
- </div>
55
- <script>
56
- function showMoreFeatures() {
57
- var moreFeatures = document.getElementById("show_more");
58
- moreFeatures.style.display = "block";
59
- document.getElementById("showMoreButton").style.display = "none";
60
- }
61
  </script>
1
+ <?php
2
+ if (!defined('ABSPATH')) {
3
+ exit;
4
+ }
5
+ ?>
6
+ <div class="market-box table-box-main">
7
+ <div class="orderimpexp-premium-features">
8
+ <center><a href="https://www.xadapter.com/product/order-import-export-plugin-for-woocommerce/" target="_blank" class="button button-primary button-go-pro"><?php _e('Upgrade to Premium Version', 'wf_csv_import_export'); ?></a></center>
9
+ <span>
10
+ <ul>
11
+ <li><?php _e('Import and Export Subscriptions along with Order and Coupon.', 'wf_order_import_export'); ?></li>
12
+ <li><?php _e('Filtering options while Export using Order Status, Date, Coupon Type etc.', 'wf_order_import_export'); ?></li>
13
+ <li><?php _e('Change values while import using Evaluation Field feature.', 'wf_order_import_export'); ?></li>
14
+ <li><?php _e('A number of third party plugins supported.', 'wf_order_import_export'); ?> </li>
15
+ <li><?php _e('Column Mapping Feature to Import from any CSV format ( Magento, Shopify, OpenCart etc. ).', 'wf_order_import_export'); ?></li>
16
+ <li><?php _e('Import and Export via FTP.', 'wf_order_import_export'); ?></li>
17
+ <li><?php _e('Choice to update or skip existing orderswhile importing.', 'wf_order_import_export'); ?></li>
18
+ </ul>
19
+ </span>
20
+ <div id="show_more" style="display: none">
21
+ <span>
22
+
23
+ <ul>
24
+ <li><?php _e('Schedule automatic import and export using Cron Job Feature.', 'wf_order_import_export'); ?></li>
25
+ <li><?php _e('Automatic scheduled import and export.', 'wf_order_import_export'); ?></li>
26
+ <li><?php _e('XML Export/Import supports Stamps.com desktop application, UPS WorldShip, Endicia and FedEx.', 'wf_order_import_export'); ?></li>
27
+ <li><?php _e('30 Days Money Back Guarantee.', 'wf_order_import_export'); ?></li>
28
+ <li><?php _e('More frequent plugin updates.', 'wf_order_import_export'); ?></li>
29
+ <li><?php _e('Excellent Support for setting it up!', 'wf_order_import_export'); ?></li>
30
+ </ul>
31
+
32
+ </span>
33
+ <center>
34
+ <a href="https://www.xadapter.com/setting-up-order-import-export-plugin-for-woocommerce/" target="_blank" class="button button-doc-demo"><?php _e('Documentation', 'wf_order_import_export'); ?></a>
35
+ </center>
36
+ <center>
37
+ <a href="<?php echo plugins_url('Sample_Order.csv', WF_OrderImpExpCsv_FILE); ?>" target="_blank" class="button button-doc-demo"><?php _e('Sample Order CSV', 'wf_order_import_export'); ?></a>
38
+ <a href="<?php echo plugins_url('Sample_Coupon.csv', WF_OrderImpExpCsv_FILE); ?>" target="_blank" class="button button-doc-demo"><?php _e('Sample Coupon CSV', 'wf_order_import_export'); ?></a>
39
+ </center>
40
+ </div>
41
+ <div class="button-show-more">
42
+ <button class="button" onclick="showMoreFeatures()" id="showMoreButton" >Show more
43
+ <i class="dashicons dashicons-arrow-down-alt2"></i>
44
+ </button>
45
+ </div>
46
+ </div>
47
+ <div class="orderimpexp-review-widget">
48
+ <?php
49
+ echo sprintf(__('<div class=""><p><i>If you like the plugin please leave us a %1$s review!</i><p></div>', 'wf_csv_import_export'), '<a href="https://wordpress.org/support/plugin/order-import-export-for-woocommerce/reviews?rate=5#new-post" target="_blank" class="xa-orderimpexp-rating-link" data-reviewed="' . esc_attr__('Thanks for the review.', 'wf_csv_import_export') . '">&#9733;&#9733;&#9733;&#9733;&#9733;</a>');
50
+ ?>
51
+ </div>
52
+ </div>
53
+ <script>
54
+ function showMoreFeatures() {
55
+ var moreFeatures = document.getElementById("show_more");
56
+ moreFeatures.style.display = "block";
57
+ document.getElementById("showMoreButton").style.display = "none";
58
+ }
 
 
59
  </script>
license.txt CHANGED
@@ -1,708 +1,708 @@
1
- Order CSV Import Export For WooCommerce
2
-
3
- Copyright 2015 by the contributors
4
-
5
- This program is free software; you can redistribute it and/or modify
6
- it under the terms of the GNU General Public License as published by
7
- the Free Software Foundation; either version 3 of the License, or
8
- (at your option) any later version.
9
-
10
- This program is distributed in the hope that it will be useful,
11
- but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- GNU General Public License for more details.
14
-
15
- You should have received a copy of the GNU General Public License
16
- along with this program; if not, write to the Free Software
17
- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
-
19
- This program incorporates work covered by the following copyright and
20
- permission notices:
21
-
22
- WooCommerce Order CSV Import Export
23
- Copyright: 2015-2017 Hikeforce.
24
- License: GNU General Public License v3.0
25
- License URI: http://www.gnu.org/licenses/gpl-3.0.html
26
-
27
- and
28
-
29
- HikeForce
30
-
31
- Product CSV Import Export For WooCommerce is released under the GPL
32
-
33
- =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
34
-
35
- GNU GENERAL PUBLIC LICENSE
36
- Version 3, 29 June 2007
37
-
38
- Copyright © 2007 Free Software Foundation, Inc. <http://fsf.org/>
39
- Everyone is permitted to copy and distribute verbatim copies
40
- of this license document, but changing it is not allowed.
41
-
42
- Preamble
43
-
44
- The GNU General Public License is a free, copyleft license for
45
- software and other kinds of works.
46
-
47
- The licenses for most software and other practical works are designed
48
- to take away your freedom to share and change the works. By contrast,
49
- the GNU General Public License is intended to guarantee your freedom to
50
- share and change all versions of a program--to make sure it remains free
51
- software for all its users. We, the Free Software Foundation, use the
52
- GNU General Public License for most of our software; it applies also to
53
- any other work released this way by its authors. You can apply it to
54
- your programs, too.
55
-
56
- When we speak of free software, we are referring to freedom, not
57
- price. Our General Public Licenses are designed to make sure that you
58
- have the freedom to distribute copies of free software (and charge for
59
- them if you wish), that you receive source code or can get it if you
60
- want it, that you can change the software or use pieces of it in new
61
- free programs, and that you know you can do these things.
62
-
63
- To protect your rights, we need to prevent others from denying you
64
- these rights or asking you to surrender the rights. Therefore, you have
65
- certain responsibilities if you distribute copies of the software, or if
66
- you modify it: responsibilities to respect the freedom of others.
67
-
68
- For example, if you distribute copies of such a program, whether
69
- gratis or for a fee, you must pass on to the recipients the same
70
- freedoms that you received. You must make sure that they, too, receive
71
- or can get the source code. And you must show them these terms so they
72
- know their rights.
73
-
74
- Developers that use the GNU GPL protect your rights with two steps:
75
- (1) assert copyright on the software, and (2) offer you this License
76
- giving you legal permission to copy, distribute and/or modify it.
77
-
78
- For the developers' and authors' protection, the GPL clearly explains
79
- that there is no warranty for this free software. For both users' and
80
- authors' sake, the GPL requires that modified versions be marked as
81
- changed, so that their problems will not be attributed erroneously to
82
- authors of previous versions.
83
-
84
- Some devices are designed to deny users access to install or run
85
- modified versions of the software inside them, although the manufacturer
86
- can do so. This is fundamentally incompatible with the aim of
87
- protecting users' freedom to change the software. The systematic
88
- pattern of such abuse occurs in the area of products for individuals to
89
- use, which is precisely where it is most unacceptable. Therefore, we
90
- have designed this version of the GPL to prohibit the practice for those
91
- products. If such problems arise substantially in other domains, we
92
- stand ready to extend this provision to those domains in future versions
93
- of the GPL, as needed to protect the freedom of users.
94
-
95
- Finally, every program is threatened constantly by software patents.
96
- States should not allow patents to restrict development and use of
97
- software on general-purpose computers, but in those that do, we wish to
98
- avoid the special danger that patents applied to a free program could
99
- make it effectively proprietary. To prevent this, the GPL assures that
100
- patents cannot be used to render the program non-free.
101
-
102
- The precise terms and conditions for copying, distribution and
103
- modification follow.
104
-
105
- TERMS AND CONDITIONS
106
-
107
- 0. Definitions.
108
-
109
- "This License" refers to version 3 of the GNU General Public License.
110
-
111
- "Copyright" also means copyright-like laws that apply to other kinds of
112
- works, such as semiconductor masks.
113
-
114
- "The Program" refers to any copyrightable work licensed under this
115
- License. Each licensee is addressed as "you". "Licensees" and
116
- "recipients" may be individuals or organizations.
117
-
118
- To "modify" a work means to copy from or adapt all or part of the work
119
- in a fashion requiring copyright permission, other than the making of an
120
- exact copy. The resulting work is called a "modified version" of the
121
- earlier work or a work "based on" the earlier work.
122
-
123
- A "covered work" means either the unmodified Program or a work based
124
- on the Program.
125
-
126
- To "propagate" a work means to do anything with it that, without
127
- permission, would make you directly or secondarily liable for
128
- infringement under applicable copyright law, except executing it on a
129
- computer or modifying a private copy. Propagation includes copying,
130
- distribution (with or without modification), making available to the
131
- public, and in some countries other activities as well.
132
-
133
- To "convey" a work means any kind of propagation that enables other
134
- parties to make or receive copies. Mere interaction with a user through
135
- a computer network, with no transfer of a copy, is not conveying.
136
-
137
- An interactive user interface displays "Appropriate Legal Notices"
138
- to the extent that it includes a convenient and prominently visible
139
- feature that (1) displays an appropriate copyright notice, and (2)
140
- tells the user that there is no warranty for the work (except to the
141
- extent that warranties are provided), that licensees may convey the
142
- work under this License, and how to view a copy of this License. If
143
- the interface presents a list of user commands or options, such as a
144
- menu, a prominent item in the list meets this criterion.
145
-
146
- 1. Source Code.
147
-
148
- The "source code" for a work means the preferred form of the work
149
- for making modifications to it. "Object code" means any non-source
150
- form of a work.
151
-
152
- A "Standard Interface" means an interface that either is an official
153
- standard defined by a recognized standards body, or, in the case of
154
- interfaces specified for a particular programming language, one that
155
- is widely used among developers working in that language.
156
-
157
- The "System Libraries" of an executable work include anything, other
158
- than the work as a whole, that (a) is included in the normal form of
159
- packaging a Major Component, but which is not part of that Major
160
- Component, and (b) serves only to enable use of the work with that
161
- Major Component, or to implement a Standard Interface for which an
162
- implementation is available to the public in source code form. A
163
- "Major Component", in this context, means a major essential component
164
- (kernel, window system, and so on) of the specific operating system
165
- (if any) on which the executable work runs, or a compiler used to
166
- produce the work, or an object code interpreter used to run it.
167
-
168
- The "Corresponding Source" for a work in object code form means all
169
- the source code needed to generate, install, and (for an executable
170
- work) run the object code and to modify the work, including scripts to
171
- control those activities. However, it does not include the work's
172
- System Libraries, or general-purpose tools or generally available free
173
- programs which are used unmodified in performing those activities but
174
- which are not part of the work. For example, Corresponding Source
175
- includes interface definition files associated with source files for
176
- the work, and the source code for shared libraries and dynamically
177
- linked subprograms that the work is specifically designed to require,
178
- such as by intimate data communication or control flow between those
179
- subprograms and other parts of the work.
180
-
181
- The Corresponding Source need not include anything that users
182
- can regenerate automatically from other parts of the Corresponding
183
- Source.
184
-
185
- The Corresponding Source for a work in source code form is that
186
- same work.
187
-
188
- 2. Basic Permissions.
189
-
190
- All rights granted under this License are granted for the term of
191
- copyright on the Program, and are irrevocable provided the stated
192
- conditions are met. This License explicitly affirms your unlimited
193
- permission to run the unmodified Program. The output from running a
194
- covered work is covered by this License only if the output, given its
195
- content, constitutes a covered work. This License acknowledges your
196
- rights of fair use or other equivalent, as provided by copyright law.
197
-
198
- You may make, run and propagate covered works that you do not
199
- convey, without conditions so long as your license otherwise remains
200
- in force. You may convey covered works to others for the sole purpose
201
- of having them make modifications exclusively for you, or provide you
202
- with facilities for running those works, provided that you comply with
203
- the terms of this License in conveying all material for which you do
204
- not control copyright. Those thus making or running the covered works
205
- for you must do so exclusively on your behalf, under your direction
206
- and control, on terms that prohibit them from making any copies of
207
- your copyrighted material outside their relationship with you.
208
-
209
- Conveying under any other circumstances is permitted solely under
210
- the conditions stated below. Sublicensing is not allowed; section 10
211
- makes it unnecessary.
212
-
213
- 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
214
-
215
- No covered work shall be deemed part of an effective technological
216
- measure under any applicable law fulfilling obligations under article
217
- 11 of the WIPO copyright treaty adopted on 20 December 1996, or
218
- similar laws prohibiting or restricting circumvention of such
219
- measures.
220
-
221
- When you convey a covered work, you waive any legal power to forbid
222
- circumvention of technological measures to the extent such circumvention
223
- is effected by exercising rights under this License with respect to
224
- the covered work, and you disclaim any intention to limit operation or
225
- modification of the work as a means of enforcing, against the work's
226
- users, your or third parties' legal rights to forbid circumvention of
227
- technological measures.
228
-
229
- 4. Conveying Verbatim Copies.
230
-
231
- You may convey verbatim copies of the Program's source code as you
232
- receive it, in any medium, provided that you conspicuously and
233
- appropriately publish on each copy an appropriate copyright notice;
234
- keep intact all notices stating that this License and any
235
- non-permissive terms added in accord with section 7 apply to the code;
236
- keep intact all notices of the absence of any warranty; and give all
237
- recipients a copy of this License along with the Program.
238
-
239
- You may charge any price or no price for each copy that you convey,
240
- and you may offer support or warranty protection for a fee.
241
-
242
- 5. Conveying Modified Source Versions.
243
-
244
- You may convey a work based on the Program, or the modifications to
245
- produce it from the Program, in the form of source code under the
246
- terms of section 4, provided that you also meet all of these conditions:
247
-
248
- a) The work must carry prominent notices stating that you modified
249
- it, and giving a relevant date.
250
-
251
- b) The work must carry prominent notices stating that it is
252
- released under this License and any conditions added under section
253
- 7. This requirement modifies the requirement in section 4 to
254
- "keep intact all notices".
255
-
256
- c) You must license the entire work, as a whole, under this
257
- License to anyone who comes into possession of a copy. This
258
- License will therefore apply, along with any applicable section 7
259
- additional terms, to the whole of the work, and all its parts,
260
- regardless of how they are packaged. This License gives no
261
- permission to license the work in any other way, but it does not
262
- invalidate such permission if you have separately received it.
263
-
264
- d) If the work has interactive user interfaces, each must display
265
- Appropriate Legal Notices; however, if the Program has interactive
266
- interfaces that do not display Appropriate Legal Notices, your
267
- work need not make them do so.
268
-
269
- A compilation of a covered work with other separate and independent
270
- works, which are not by their nature extensions of the covered work,
271
- and which are not combined with it such as to form a larger program,
272
- in or on a volume of a storage or distribution medium, is called an
273
- "aggregate" if the compilation and its resulting copyright are not
274
- used to limit the access or legal rights of the compilation's users
275
- beyond what the individual works permit. Inclusion of a covered work
276
- in an aggregate does not cause this License to apply to the other
277
- parts of the aggregate.
278
-
279
- 6. Conveying Non-Source Forms.
280
-
281
- You may convey a covered work in object code form under the terms
282
- of sections 4 and 5, provided that you also convey the
283
- machine-readable Corresponding Source under the terms of this License,
284
- in one of these ways:
285
-
286
- a) Convey the object code in, or embodied in, a physical product
287
- (including a physical distribution medium), accompanied by the
288
- Corresponding Source fixed on a durable physical medium
289
- customarily used for software interchange.
290
-
291
- b) Convey the object code in, or embodied in, a physical product
292
- (including a physical distribution medium), accompanied by a
293
- written offer, valid for at least three years and valid for as
294
- long as you offer spare parts or customer support for that product
295
- model, to give anyone who possesses the object code either (1) a
296
- copy of the Corresponding Source for all the software in the
297
- product that is covered by this License, on a durable physical
298
- medium customarily used for software interchange, for a price no
299
- more than your reasonable cost of physically performing this
300
- conveying of source, or (2) access to copy the
301
- Corresponding Source from a network server at no charge.
302
-
303
- c) Convey individual copies of the object code with a copy of the
304
- written offer to provide the Corresponding Source. This
305
- alternative is allowed only occasionally and noncommercially, and
306
- only if you received the object code with such an offer, in accord
307
- with subsection 6b.
308
-
309
- d) Convey the object code by offering access from a designated
310
- place (gratis or for a charge), and offer equivalent access to the
311
- Corresponding Source in the same way through the same place at no
312
- further charge. You need not require recipients to copy the
313
- Corresponding Source along with the object code. If the place to
314
- copy the object code is a network server, the Corresponding Source
315
- may be on a different server (operated by you or a third party)
316
- that supports equivalent copying facilities, provided you maintain
317
- clear directions next to the object code saying where to find the
318
- Corresponding Source. Regardless of what server hosts the
319
- Corresponding Source, you remain obligated to ensure that it is
320
- available for as long as needed to satisfy these requirements.
321
-
322
- e) Convey the object code using peer-to-peer transmission, provided
323
- you inform other peers where the object code and Corresponding
324
- Source of the work are being offered to the general public at no
325
- charge under subsection 6d.
326
-
327
- A separable portion of the object code, whose source code is excluded
328
- from the Corresponding Source as a System Library, need not be
329
- included in conveying the object code work.
330
-
331
- A "User Product" is either (1) a "consumer product", which means any
332
- tangible personal property which is normally used for personal, family,
333
- or household purposes, or (2) anything designed or sold for incorporation
334
- into a dwelling. In determining whether a product is a consumer product,
335
- doubtful cases shall be resolved in favor of coverage. For a particular
336
- product received by a particular user, "normally used" refers to a
337
- typical or common use of that class of product, regardless of the status
338
- of the particular user or of the way in which the particular user
339
- actually uses, or expects or is expected to use, the product. A product
340
- is a consumer product regardless of whether the product has substantial
341
- commercial, industrial or non-consumer uses, unless such uses represent
342
- the only significant mode of use of the product.
343
-
344
- "Installation Information" for a User Product means any methods,
345
- procedures, authorization keys, or other information required to install
346
- and execute modified versions of a covered work in that User Product from
347
- a modified version of its Corresponding Source. The information must
348
- suffice to ensure that the continued functioning of the modified object
349
- code is in no case prevented or interfered with solely because
350
- modification has been made.
351
-
352
- If you convey an object code work under this section in, or with, or
353
- specifically for use in, a User Product, and the conveying occurs as
354
- part of a transaction in which the right of possession and use of the
355
- User Product is transferred to the recipient in perpetuity or for a
356
- fixed term (regardless of how the transaction is characterized), the
357
- Corresponding Source conveyed under this section must be accompanied
358
- by the Installation Information. But this requirement does not apply
359
- if neither you nor any third party retains the ability to install
360
- modified object code on the User Product (for example, the work has
361
- been installed in ROM).
362
-
363
- The requirement to provide Installation Information does not include a
364
- requirement to continue to provide support service, warranty, or updates
365
- for a work that has been modified or installed by the recipient, or for
366
- the User Product in which it has been modified or installed. Access to a
367
- network may be denied when the modification itself materially and
368
- adversely affects the operation of the network or violates the rules and
369
- protocols for communication across the network.
370
-
371
- Corresponding Source conveyed, and Installation Information provided,
372
- in accord with this section must be in a format that is publicly
373
- documented (and with an implementation available to the public in
374
- source code form), and must require no special password or key for
375
- unpacking, reading or copying.
376
-
377
- 7. Additional Terms.
378
-
379
- "Additional permissions" are terms that supplement the terms of this
380
- License by making exceptions from one or more of its conditions.
381
- Additional permissions that are applicable to the entire Program shall
382
- be treated as though they were included in this License, to the extent
383
- that they are valid under applicable law. If additional permissions
384
- apply only to part of the Program, that part may be used separately
385
- under those permissions, but the entire Program remains governed by
386
- this License without regard to the additional permissions.
387
-
388
- When you convey a copy of a covered work, you may at your option
389
- remove any additional permissions from that copy, or from any part of
390
- it. (Additional permissions may be written to require their own
391
- removal in certain cases when you modify the work.) You may place
392
- additional permissions on material, added by you to a covered work,
393
- for which you have or can give appropriate copyright permission.
394
-
395
- Notwithstanding any other provision of this License, for material you
396
- add to a covered work, you may (if authorized by the copyright holders of
397
- that material) supplement the terms of this License with terms:
398
-
399
- a) Disclaiming warranty or limiting liability differently from the
400
- terms of sections 15 and 16 of this License; or
401
-
402
- b) Requiring preservation of specified reasonable legal notices or
403
- author attributions in that material or in the Appropriate Legal
404
- Notices displayed by works containing it; or
405
-
406
- c) Prohibiting misrepresentation of the origin of that material, or
407
- requiring that modified versions of such material be marked in
408
- reasonable ways as different from the original version; or
409
-
410
- d) Limiting the use for publicity purposes of names of licensors or
411
- authors of the material; or
412
-
413
- e) Declining to grant rights under trademark law for use of some
414
- trade names, trademarks, or service marks; or
415
-
416
- f) Requiring indemnification of licensors and authors of that
417
- material by anyone who conveys the material (or modified versions of
418
- it) with contractual assumptions of liability to the recipient, for
419
- any liability that these contractual assumptions directly impose on
420
- those licensors and authors.
421
-
422
- All other non-permissive additional terms are considered "further
423
- restrictions" within the meaning of section 10. If the Program as you
424
- received it, or any part of it, contains a notice stating that it is
425
- governed by this License along with a term that is a further
426
- restriction, you may remove that term. If a license document contains
427
- a further restriction but permits relicensing or conveying under this
428
- License, you may add to a covered work material governed by the terms
429
- of that license document, provided that the further restriction does
430
- not survive such relicensing or conveying.
431
-
432
- If you add terms to a covered work in accord with this section, you
433
- must place, in the relevant source files, a statement of the
434
- additional terms that apply to those files, or a notice indicating
435
- where to find the applicable terms.
436
-
437
- Additional terms, permissive or non-permissive, may be stated in the
438
- form of a separately written license, or stated as exceptions;
439
- the above requirements apply either way.
440
-
441
- 8. Termination.
442
-
443
- You may not propagate or modify a covered work except as expressly
444
- provided under this License. Any attempt otherwise to propagate or
445
- modify it is void, and will automatically terminate your rights under
446
- this License (including any patent licenses granted under the third
447
- paragraph of section 11).
448
-
449
- However, if you cease all violation of this License, then your
450
- license from a particular copyright holder is reinstated (a)
451
- provisionally, unless and until the copyright holder explicitly and
452
- finally terminates your license, and (b) permanently, if the copyright
453
- holder fails to notify you of the violation by some reasonable means
454
- prior to 60 days after the cessation.
455
-
456
- Moreover, your license from a particular copyright holder is
457
- reinstated permanently if the copyright holder notifies you of the
458
- violation by some reasonable means, this is the first time you have
459
- received notice of violation of this License (for any work) from that
460
- copyright holder, and you cure the violation prior to 30 days after
461
- your receipt of the notice.
462
-
463
- Termination of your rights under this section does not terminate the
464
- licenses of parties who have received copies or rights from you under
465
- this License. If your rights have been terminated and not permanently
466
- reinstated, you do not qualify to receive new licenses for the same
467
- material under section 10.
468
-
469
- 9. Acceptance Not Required for Having Copies.
470
-
471
- You are not required to accept this License in order to receive or
472
- run a copy of the Program. Ancillary propagation of a covered work
473
- occurring solely as a consequence of using peer-to-peer transmission
474
- to receive a copy likewise does not require acceptance. However,
475
- nothing other than this License grants you permission to propagate or
476
- modify any covered work. These actions infringe copyright if you do
477
- not accept this License. Therefore, by modifying or propagating a
478
- covered work, you indicate your acceptance of this License to do so.
479
-
480
- 10. Automatic Licensing of Downstream Recipients.
481
-
482
- Each time you convey a covered work, the recipient automatically
483
- receives a license from the original licensors, to run, modify and
484
- propagate that work, subject to this License. You are not responsible
485
- for enforcing compliance by third parties with this License.
486
-
487
- An "entity transaction" is a transaction transferring control of an
488
- organization, or substantially all assets of one, or subdividing an
489
- organization, or merging organizations. If propagation of a covered
490
- work results from an entity transaction, each party to that
491
- transaction who receives a copy of the work also receives whatever
492
- licenses to the work the party's predecessor in interest had or could
493
- give under the previous paragraph, plus a right to possession of the
494
- Corresponding Source of the work from the predecessor in interest, if
495
- the predecessor has it or can get it with reasonable efforts.
496
-
497
- You may not impose any further restrictions on the exercise of the
498
- rights granted or affirmed under this License. For example, you may
499
- not impose a license fee, royalty, or other charge for exercise of
500
- rights granted under this License, and you may not initiate litigation
501
- (including a cross-claim or counterclaim in a lawsuit) alleging that
502
- any patent claim is infringed by making, using, selling, offering for
503
- sale, or importing the Program or any portion of it.
504
-
505
- 11. Patents.
506
-
507
- A "contributor" is a copyright holder who authorizes use under this
508
- License of the Program or a work on which the Program is based. The
509
- work thus licensed is called the contributor's "contributor version".
510
-
511
- A contributor's "essential patent claims" are all patent claims
512
- owned or controlled by the contributor, whether already acquired or
513
- hereafter acquired, that would be infringed by some manner, permitted
514
- by this License, of making, using, or selling its contributor version,
515
- but do not include claims that would be infringed only as a
516
- consequence of further modification of the contributor version. For
517
- purposes of this definition, "control" includes the right to grant
518
- patent sublicenses in a manner consistent with the requirements of
519
- this License.
520
-
521
- Each contributor grants you a non-exclusive, worldwide, royalty-free
522
- patent license under the contributor's essential patent claims, to
523
- make, use, sell, offer for sale, import and otherwise run, modify and
524
- propagate the contents of its contributor version.
525
-
526
- In the following three paragraphs, a "patent license" is any express
527
- agreement or commitment, however denominated, not to enforce a patent
528
- (such as an express permission to practice a patent or covenant not to
529
- sue for patent infringement). To "grant" such a patent license to a
530
- party means to make such an agreement or commitment not to enforce a
531
- patent against the party.
532
-
533
- If you convey a covered work, knowingly relying on a patent license,
534
- and the Corresponding Source of the work is not available for anyone
535
- to copy, free of charge and under the terms of this License, through a
536
- publicly available network server or other readily accessible means,
537
- then you must either (1) cause the Corresponding Source to be so
538
- available, or (2) arrange to deprive yourself of the benefit of the
539
- patent license for this particular work, or (3) arrange, in a manner
540
- consistent with the requirements of this License, to extend the patent
541
- license to downstream recipients. "Knowingly relying" means you have
542
- actual knowledge that, but for the patent license, your conveying the
543
- covered work in a country, or your recipient's use of the covered work
544
- in a country, would infringe one or more identifiable patents in that
545
- country that you have reason to believe are valid.
546
-
547
- If, pursuant to or in connection with a single transaction or
548
- arrangement, you convey, or propagate by procuring conveyance of, a
549
- covered work, and grant a patent license to some of the parties
550
- receiving the covered work authorizing them to use, propagate, modify
551
- or convey a specific copy of the covered work, then the patent license
552
- you grant is automatically extended to all recipients of the covered
553
- work and works based on it.
554
-
555
- A patent license is "discriminatory" if it does not include within
556
- the scope of its coverage, prohibits the exercise of, or is
557
- conditioned on the non-exercise of one or more of the rights that are
558
- specifically granted under this License. You may not convey a covered
559
- work if you are a party to an arrangement with a third party that is
560
- in the business of distributing software, under which you make payment
561
- to the third party based on the extent of your activity of conveying
562
- the work, and under which the third party grants, to any of the
563
- parties who would receive the covered work from you, a discriminatory
564
- patent license (a) in connection with copies of the covered work
565
- conveyed by you (or copies made from those copies), or (b) primarily
566
- for and in connection with specific products or compilations that
567
- contain the covered work, unless you entered into that arrangement,
568
- or that patent license was granted, prior to 28 March 2007.
569
-
570
- Nothing in this License shall be construed as excluding or limiting
571
- any implied license or other defenses to infringement that may
572
- otherwise be available to you under applicable patent law.
573
-
574
- 12. No Surrender of Others' Freedom.
575
-
576
- If conditions are imposed on you (whether by court order, agreement or
577
- otherwise) that contradict the conditions of this License, they do not
578
- excuse you from the conditions of this License. If you cannot convey a
579
- covered work so as to satisfy simultaneously your obligations under this
580
- License and any other pertinent obligations, then as a consequence you may
581
- not convey it at all. For example, if you agree to terms that obligate you
582
- to collect a royalty for further conveying from those to whom you convey
583
- the Program, the only way you could satisfy both those terms and this
584
- License would be to refrain entirely from conveying the Program.
585
-
586
- 13. Use with the GNU Affero General Public License.
587
-
588
- Notwithstanding any other provision of this License, you have
589
- permission to link or combine any covered work with a work licensed
590
- under version 3 of the GNU Affero General Public License into a single
591
- combined work, and to convey the resulting work. The terms of this
592
- License will continue to apply to the part which is the covered work,
593
- but the special requirements of the GNU Affero General Public License,
594
- section 13, concerning interaction through a network will apply to the
595
- combination as such.
596
-
597
- 14. Revised Versions of this License.
598
-
599
- The Free Software Foundation may publish revised and/or new versions of
600
- the GNU General Public License from time to time. Such new versions will
601
- be similar in spirit to the present version, but may differ in detail to
602
- address new problems or concerns.
603
-
604
- Each version is given a distinguishing version number. If the
605
- Program specifies that a certain numbered version of the GNU General
606
- Public License "or any later version" applies to it, you have the
607
- option of following the terms and conditions either of that numbered
608
- version or of any later version published by the Free Software
609
- Foundation. If the Program does not specify a version number of the
610
- GNU General Public License, you may choose any version ever published
611
- by the Free Software Foundation.
612
-
613
- If the Program specifies that a proxy can decide which future
614
- versions of the GNU General Public License can be used, that proxy's
615
- public statement of acceptance of a version permanently authorizes you
616
- to choose that version for the Program.
617
-
618
- Later license versions may give you additional or different
619
- permissions. However, no additional obligations are imposed on any
620
- author or copyright holder as a result of your choosing to follow a
621
- later version.
622
-
623
- 15. Disclaimer of Warranty.
624
-
625
- THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
626
- APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
627
- HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
628
- OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
629
- THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
630
- PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
631
- IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
632
- ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
633
-
634
- 16. Limitation of Liability.
635
-
636
- IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
637
- WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
638
- THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
639
- GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
640
- USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
641
- DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
642
- PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
643
- EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
644
- SUCH DAMAGES.
645
-
646
- 17. Interpretation of Sections 15 and 16.
647
-
648
- If the disclaimer of warranty and limitation of liability provided
649
- above cannot be given local legal effect according to their terms,
650
- reviewing courts shall apply local law that most closely approximates
651
- an absolute waiver of all civil liability in connection with the
652
- Program, unless a warranty or assumption of liability accompanies a
653
- copy of the Program in return for a fee.
654
-
655
- END OF TERMS AND CONDITIONS
656
-
657
- How to Apply These Terms to Your New Programs
658
-
659
- If you develop a new program, and you want it to be of the greatest
660
- possible use to the public, the best way to achieve this is to make it
661
- free software which everyone can redistribute and change under these terms.
662
-
663
- To do so, attach the following notices to the program. It is safest
664
- to attach them to the start of each source file to most effectively
665
- state the exclusion of warranty; and each file should have at least
666
- the "copyright" line and a pointer to where the full notice is found.
667
-
668
- <one line to give the program's name and a brief idea of what it does.>
669
- Copyright © <year> <name of author>
670
-
671
- This program is free software: you can redistribute it and/or modify
672
- it under the terms of the GNU General Public License as published by
673
- the Free Software Foundation, either version 3 of the License, or
674
- (at your option) any later version.
675
-
676
- This program is distributed in the hope that it will be useful,
677
- but WITHOUT ANY WARRANTY; without even the implied warranty of
678
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
679
- GNU General Public License for more details.
680
-
681
- You should have received a copy of the GNU General Public License
682
- along with this program. If not, see <http://www.gnu.org/licenses/>.
683
-
684
- Also add information on how to contact you by electronic and paper mail.
685
-
686
- If the program does terminal interaction, make it output a short
687
- notice like this when it starts in an interactive mode:
688
-
689
- <program> Copyright © <year> <name of author>
690
- This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
691
- This is free software, and you are welcome to redistribute it
692
- under certain conditions; type `show c' for details.
693
-
694
- The hypothetical commands `show w' and `show c' should show the appropriate
695
- parts of the General Public License. Of course, your program's commands
696
- might be different; for a GUI interface, you would use an "about box".
697
-
698
- You should also get your employer (if you work as a programmer) or school,
699
- if any, to sign a "copyright disclaimer" for the program, if necessary.
700
- For more information on this, and how to apply and follow the GNU GPL, see
701
- <http://www.gnu.org/licenses/>.
702
-
703
- The GNU General Public License does not permit incorporating your program
704
- into proprietary programs. If your program is a subroutine library, you
705
- may consider it more useful to permit linking proprietary applications with
706
- the library. If this is what you want to do, use the GNU Lesser General
707
- Public License instead of this License. But first, please read
708
  <http://www.gnu.org/philosophy/why-not-lgpl.html>.
1
+ Order CSV Import Export For WooCommerce
2
+
3
+ Copyright 2015 by the contributors
4
+
5
+ This program is free software; you can redistribute it and/or modify
6
+ it under the terms of the GNU General Public License as published by
7
+ the Free Software Foundation; either version 3 of the License, or
8
+ (at your option) any later version.
9
+
10
+ This program is distributed in the hope that it will be useful,
11
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ GNU General Public License for more details.
14
+
15
+ You should have received a copy of the GNU General Public License
16
+ along with this program; if not, write to the Free Software
17
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
+
19
+ This program incorporates work covered by the following copyright and
20
+ permission notices:
21
+
22
+ WooCommerce Order CSV Import Export
23
+ Copyright: 2015-2017 Hikeforce.
24
+ License: GNU General Public License v3.0
25
+ License URI: http://www.gnu.org/licenses/gpl-3.0.html
26
+
27
+ and
28
+
29
+ HikeForce
30
+
31
+ Product CSV Import Export For WooCommerce is released under the GPL
32
+
33
+ =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
34
+
35
+ GNU GENERAL PUBLIC LICENSE
36
+ Version 3, 29 June 2007
37
+
38
+ Copyright © 2007 Free Software Foundation, Inc. <http://fsf.org/>
39
+ Everyone is permitted to copy and distribute verbatim copies
40
+ of this license document, but changing it is not allowed.
41
+
42
+ Preamble
43
+
44
+ The GNU General Public License is a free, copyleft license for
45
+ software and other kinds of works.
46
+
47
+ The licenses for most software and other practical works are designed
48
+ to take away your freedom to share and change the works. By contrast,
49
+ the GNU General Public License is intended to guarantee your freedom to
50
+ share and change all versions of a program--to make sure it remains free
51
+ software for all its users. We, the Free Software Foundation, use the
52
+ GNU General Public License for most of our software; it applies also to
53
+ any other work released this way by its authors. You can apply it to
54
+ your programs, too.
55
+
56
+ When we speak of free software, we are referring to freedom, not
57
+ price. Our General Public Licenses are designed to make sure that you
58
+ have the freedom to distribute copies of free software (and charge for
59
+ them if you wish), that you receive source code or can get it if you
60
+ want it, that you can change the software or use pieces of it in new
61
+ free programs, and that you know you can do these things.
62
+
63
+ To protect your rights, we need to prevent others from denying you
64
+ these rights or asking you to surrender the rights. Therefore, you have
65
+ certain responsibilities if you distribute copies of the software, or if
66
+ you modify it: responsibilities to respect the freedom of others.
67
+
68
+ For example, if you distribute copies of such a program, whether
69
+ gratis or for a fee, you must pass on to the recipients the same
70
+ freedoms that you received. You must make sure that they, too, receive
71
+ or can get the source code. And you must show them these terms so they
72
+ know their rights.
73
+
74
+ Developers that use the GNU GPL protect your rights with two steps:
75
+ (1) assert copyright on the software, and (2) offer you this License
76
+ giving you legal permission to copy, distribute and/or modify it.
77
+
78
+ For the developers' and authors' protection, the GPL clearly explains
79
+ that there is no warranty for this free software. For both users' and
80
+ authors' sake, the GPL requires that modified versions be marked as
81
+ changed, so that their problems will not be attributed erroneously to
82
+ authors of previous versions.
83
+
84
+ Some devices are designed to deny users access to install or run
85
+ modified versions of the software inside them, although the manufacturer
86
+ can do so. This is fundamentally incompatible with the aim of
87
+ protecting users' freedom to change the software. The systematic
88
+ pattern of such abuse occurs in the area of products for individuals to
89
+ use, which is precisely where it is most unacceptable. Therefore, we
90
+ have designed this version of the GPL to prohibit the practice for those
91
+ products. If such problems arise substantially in other domains, we
92
+ stand ready to extend this provision to those domains in future versions
93
+ of the GPL, as needed to protect the freedom of users.
94
+
95
+ Finally, every program is threatened constantly by software patents.
96
+ States should not allow patents to restrict development and use of
97
+ software on general-purpose computers, but in those that do, we wish to
98
+ avoid the special danger that patents applied to a free program could
99
+ make it effectively proprietary. To prevent this, the GPL assures that
100
+ patents cannot be used to render the program non-free.
101
+
102
+ The precise terms and conditions for copying, distribution and
103
+ modification follow.
104
+
105
+ TERMS AND CONDITIONS
106
+
107
+ 0. Definitions.
108
+
109
+ "This License" refers to version 3 of the GNU General Public License.
110
+
111
+ "Copyright" also means copyright-like laws that apply to other kinds of
112
+ works, such as semiconductor masks.
113
+
114
+ "The Program" refers to any copyrightable work licensed under this
115
+ License. Each licensee is addressed as "you". "Licensees" and
116
+ "recipients" may be individuals or organizations.
117
+
118
+ To "modify" a work means to copy from or adapt all or part of the work
119
+ in a fashion requiring copyright permission, other than the making of an
120
+ exact copy. The resulting work is called a "modified version" of the
121
+ earlier work or a work "based on" the earlier work.
122
+
123
+ A "covered work" means either the unmodified Program or a work based
124
+ on the Program.
125
+
126
+ To "propagate" a work means to do anything with it that, without
127
+ permission, would make you directly or secondarily liable for
128
+ infringement under applicable copyright law, except executing it on a
129
+ computer or modifying a private copy. Propagation includes copying,
130
+ distribution (with or without modification), making available to the
131
+ public, and in some countries other activities as well.
132
+
133
+ To "convey" a work means any kind of propagation that enables other
134
+ parties to make or receive copies. Mere interaction with a user through
135
+ a computer network, with no transfer of a copy, is not conveying.
136
+
137
+ An interactive user interface displays "Appropriate Legal Notices"
138
+ to the extent that it includes a convenient and prominently visible
139
+ feature that (1) displays an appropriate copyright notice, and (2)
140
+ tells the user that there is no warranty for the work (except to the
141
+ extent that warranties are provided), that licensees may convey the
142
+ work under this License, and how to view a copy of this License. If
143
+ the interface presents a list of user commands or options, such as a
144
+ menu, a prominent item in the list meets this criterion.
145
+
146
+ 1. Source Code.
147
+
148
+ The "source code" for a work means the preferred form of the work
149
+ for making modifications to it. "Object code" means any non-source
150
+ form of a work.
151
+
152
+ A "Standard Interface" means an interface that either is an official
153
+ standard defined by a recognized standards body, or, in the case of
154
+ interfaces specified for a particular programming language, one that
155
+ is widely used among developers working in that language.
156
+
157
+ The "System Libraries" of an executable work include anything, other
158
+ than the work as a whole, that (a) is included in the normal form of
159
+ packaging a Major Component, but which is not part of that Major
160
+ Component, and (b) serves only to enable use of the work with that
161
+ Major Component, or to implement a Standard Interface for which an
162
+ implementation is available to the public in source code form. A
163
+ "Major Component", in this context, means a major essential component
164
+ (kernel, window system, and so on) of the specific operating system
165
+ (if any) on which the executable work runs, or a compiler used to
166
+ produce the work, or an object code interpreter used to run it.
167
+
168
+ The "Corresponding Source" for a work in object code form means all
169
+ the source code needed to generate, install, and (for an executable
170
+ work) run the object code and to modify the work, including scripts to
171
+ control those activities. However, it does not include the work's
172
+ System Libraries, or general-purpose tools or generally available free
173
+ programs which are used unmodified in performing those activities but
174
+ which are not part of the work. For example, Corresponding Source
175
+ includes interface definition files associated with source files for
176
+ the work, and the source code for shared libraries and dynamically
177
+ linked subprograms that the work is specifically designed to require,
178
+ such as by intimate data communication or control flow between those
179
+ subprograms and other parts of the work.
180
+
181
+ The Corresponding Source need not include anything that users
182
+ can regenerate automatically from other parts of the Corresponding
183
+ Source.
184
+
185
+ The Corresponding Source for a work in source code form is that
186
+ same work.
187
+
188
+ 2. Basic Permissions.
189
+
190
+ All rights granted under this License are granted for the term of
191
+ copyright on the Program, and are irrevocable provided the stated
192
+ conditions are met. This License explicitly affirms your unlimited
193
+ permission to run the unmodified Program. The output from running a
194
+ covered work is covered by this License only if the output, given its
195
+ content, constitutes a covered work. This License acknowledges your
196
+ rights of fair use or other equivalent, as provided by copyright law.
197
+
198
+ You may make, run and propagate covered works that you do not
199
+ convey, without conditions so long as your license otherwise remains
200
+ in force. You may convey covered works to others for the sole purpose
201
+ of having them make modifications exclusively for you, or provide you
202
+ with facilities for running those works, provided that you comply with
203
+ the terms of this License in conveying all material for which you do
204
+ not control copyright. Those thus making or running the covered works
205
+ for you must do so exclusively on your behalf, under your direction
206
+ and control, on terms that prohibit them from making any copies of
207
+ your copyrighted material outside their relationship with you.
208
+
209
+ Conveying under any other circumstances is permitted solely under
210
+ the conditions stated below. Sublicensing is not allowed; section 10
211
+ makes it unnecessary.
212
+
213
+ 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
214
+
215
+ No covered work shall be deemed part of an effective technological
216
+ measure under any applicable law fulfilling obligations under article
217
+ 11 of the WIPO copyright treaty adopted on 20 December 1996, or
218
+ similar laws prohibiting or restricting circumvention of such
219
+ measures.
220
+
221
+ When you convey a covered work, you waive any legal power to forbid
222
+ circumvention of technological measures to the extent such circumvention
223
+ is effected by exercising rights under this License with respect to
224
+ the covered work, and you disclaim any intention to limit operation or
225
+ modification of the work as a means of enforcing, against the work's
226
+ users, your or third parties' legal rights to forbid circumvention of
227
+ technological measures.
228
+
229
+ 4. Conveying Verbatim Copies.
230
+
231
+ You may convey verbatim copies of the Program's source code as you
232
+ receive it, in any medium, provided that you conspicuously and
233
+ appropriately publish on each copy an appropriate copyright notice;
234
+ keep intact all notices stating that this License and any
235
+ non-permissive terms added in accord with section 7 apply to the code;
236
+ keep intact all notices of the absence of any warranty; and give all
237
+ recipients a copy of this License along with the Program.
238
+
239
+ You may charge any price or no price for each copy that you convey,
240
+ and you may offer support or warranty protection for a fee.
241
+
242
+ 5. Conveying Modified Source Versions.
243
+
244
+ You may convey a work based on the Program, or the modifications to
245
+ produce it from the Program, in the form of source code under the
246
+ terms of section 4, provided that you also meet all of these conditions:
247
+
248
+ a) The work must carry prominent notices stating that you modified
249
+ it, and giving a relevant date.
250
+
251
+ b) The work must carry prominent notices stating that it is
252
+ released under this License and any conditions added under section
253
+ 7. This requirement modifies the requirement in section 4 to
254
+ "keep intact all notices".
255
+
256
+ c) You must license the entire work, as a whole, under this
257
+ License to anyone who comes into possession of a copy. This
258
+ License will therefore apply, along with any applicable section 7
259
+ additional terms, to the whole of the work, and all its parts,
260
+ regardless of how they are packaged. This License gives no
261
+ permission to license the work in any other way, but it does not
262
+ invalidate such permission if you have separately received it.
263
+
264
+ d) If the work has interactive user interfaces, each must display
265
+ Appropriate Legal Notices; however, if the Program has interactive
266
+ interfaces that do not display Appropriate Legal Notices, your
267
+ work need not make them do so.
268
+
269
+ A compilation of a covered work with other separate and independent
270
+ works, which are not by their nature extensions of the covered work,
271
+ and which are not combined with it such as to form a larger program,
272
+ in or on a volume of a storage or distribution medium, is called an
273
+ "aggregate" if the compilation and its resulting copyright are not
274
+ used to limit the access or legal rights of the compilation's users
275
+ beyond what the individual works permit. Inclusion of a covered work
276
+ in an aggregate does not cause this License to apply to the other
277
+ parts of the aggregate.
278
+
279
+ 6. Conveying Non-Source Forms.
280
+
281
+ You may convey a covered work in object code form under the terms
282
+ of sections 4 and 5, provided that you also convey the
283
+ machine-readable Corresponding Source under the terms of this License,
284
+ in one of these ways:
285
+
286
+ a) Convey the object code in, or embodied in, a physical product
287
+ (including a physical distribution medium), accompanied by the
288
+ Corresponding Source fixed on a durable physical medium
289
+ customarily used for software interchange.
290
+
291
+ b) Convey the object code in, or embodied in, a physical product
292
+ (including a physical distribution medium), accompanied by a
293
+ written offer, valid for at least three years and valid for as
294
+ long as you offer spare parts or customer support for that product
295
+ model, to give anyone who possesses the object code either (1) a
296
+ copy of the Corresponding Source for all the software in the
297
+ product that is covered by this License, on a durable physical
298
+ medium customarily used for software interchange, for a price no
299
+ more than your reasonable cost of physically performing this
300
+ conveying of source, or (2) access to copy the
301
+ Corresponding Source from a network server at no charge.
302
+
303
+ c) Convey individual copies of the object code with a copy of the
304
+ written offer to provide the Corresponding Source. This
305
+ alternative is allowed only occasionally and noncommercially, and
306
+ only if you received the object code with such an offer, in accord
307
+ with subsection 6b.
308
+
309
+ d) Convey the object code by offering access from a designated
310
+ place (gratis or for a charge), and offer equivalent access to the
311
+ Corresponding Source in the same way through the same place at no
312
+ further charge. You need not require recipients to copy the
313
+ Corresponding Source along with the object code. If the place to
314
+ copy the object code is a network server, the Corresponding Source
315
+ may be on a different server (operated by you or a third party)
316
+ that supports equivalent copying facilities, provided you maintain
317
+ clear directions next to the object code saying where to find the
318
+ Corresponding Source. Regardless of what server hosts the
319
+ Corresponding Source, you remain obligated to ensure that it is
320
+ available for as long as needed to satisfy these requirements.
321
+
322
+ e) Convey the object code using peer-to-peer transmission, provided
323
+ you inform other peers where the object code and Corresponding
324
+ Source of the work are being offered to the general public at no
325
+ charge under subsection 6d.
326
+
327
+ A separable portion of the object code, whose source code is excluded
328
+ from the Corresponding Source as a System Library, need not be
329
+ included in conveying the object code work.
330
+
331
+ A "User Product" is either (1) a "consumer product", which means any
332
+ tangible personal property which is normally used for personal, family,
333
+ or household purposes, or (2) anything designed or sold for incorporation
334
+ into a dwelling. In determining whether a product is a consumer product,
335
+ doubtful cases shall be resolved in favor of coverage. For a particular
336
+ product received by a particular user, "normally used" refers to a
337
+ typical or common use of that class of product, regardless of the status
338
+ of the particular user or of the way in which the particular user
339
+ actually uses, or expects or is expected to use, the product. A product
340
+ is a consumer product regardless of whether the product has substantial
341
+ commercial, industrial or non-consumer uses, unless such uses represent
342
+ the only significant mode of use of the product.
343
+
344
+ "Installation Information" for a User Product means any methods,
345
+ procedures, authorization keys, or other information required to install
346
+ and execute modified versions of a covered work in that User Product from
347
+ a modified version of its Corresponding Source. The information must
348
+ suffice to ensure that the continued functioning of the modified object
349
+ code is in no case prevented or interfered with solely because
350
+ modification has been made.
351
+
352
+ If you convey an object code work under this section in, or with, or
353
+ specifically for use in, a User Product, and the conveying occurs as
354
+ part of a transaction in which the right of possession and use of the
355
+ User Product is transferred to the recipient in perpetuity or for a
356
+ fixed term (regardless of how the transaction is characterized), the
357
+ Corresponding Source conveyed under this section must be accompanied
358
+ by the Installation Information. But this requirement does not apply
359
+ if neither you nor any third party retains the ability to install
360
+ modified object code on the User Product (for example, the work has
361
+ been installed in ROM).
362
+
363
+ The requirement to provide Installation Information does not include a
364
+ requirement to continue to provide support service, warranty, or updates
365
+ for a work that has been modified or installed by the recipient, or for
366
+ the User Product in which it has been modified or installed. Access to a
367
+ network may be denied when the modification itself materially and
368
+ adversely affects the operation of the network or violates the rules and
369
+ protocols for communication across the network.
370
+
371
+ Corresponding Source conveyed, and Installation Information provided,
372
+ in accord with this section must be in a format that is publicly
373
+ documented (and with an implementation available to the public in
374
+ source code form), and must require no special password or key for
375
+ unpacking, reading or copying.
376
+
377
+ 7. Additional Terms.
378
+
379
+ "Additional permissions" are terms that supplement the terms of this
380
+ License by making exceptions from one or more of its conditions.
381
+ Additional permissions that are applicable to the entire Program shall
382
+ be treated as though they were included in this License, to the extent
383
+ that they are valid under applicable law. If additional permissions
384
+ apply only to part of the Program, that part may be used separately
385
+ under those permissions, but the entire Program remains governed by
386
+ this License without regard to the additional permissions.
387
+
388
+ When you convey a copy of a covered work, you may at your option
389
+ remove any additional permissions from that copy, or from any part of
390
+ it. (Additional permissions may be written to require their own
391
+ removal in certain cases when you modify the work.) You may place
392
+ additional permissions on material, added by you to a covered work,
393
+ for which you have or can give appropriate copyright permission.
394
+
395
+ Notwithstanding any other provision of this License, for material you
396
+ add to a covered work, you may (if authorized by the copyright holders of
397
+ that material) supplement the terms of this License with terms:
398
+
399
+ a) Disclaiming warranty or limiting liability differently from the
400
+ terms of sections 15 and 16 of this License; or
401
+
402
+ b) Requiring preservation of specified reasonable legal notices or
403
+ author attributions in that material or in the Appropriate Legal
404
+ Notices displayed by works containing it; or
405
+
406
+ c) Prohibiting misrepresentation of the origin of that material, or
407
+ requiring that modified versions of such material be marked in
408
+ reasonable ways as different from the original version; or
409
+
410
+ d) Limiting the use for publicity purposes of names of licensors or
411
+ authors of the material; or
412
+
413
+ e) Declining to grant rights under trademark law for use of some
414
+ trade names, trademarks, or service marks; or
415
+
416
+ f) Requiring indemnification of licensors and authors of that
417
+ material by anyone who conveys the material (or modified versions of
418
+ it) with contractual assumptions of liability to the recipient, for
419
+ any liability that these contractual assumptions directly impose on
420
+ those licensors and authors.
421
+
422
+ All other non-permissive additional terms are considered "further
423
+ restrictions" within the meaning of section 10. If the Program as you
424
+ received it, or any part of it, contains a notice stating that it is
425
+ governed by this License along with a term that is a further
426
+ restriction, you may remove that term. If a license document contains
427
+ a further restriction but permits relicensing or conveying under this
428
+ License, you may add to a covered work material governed by the terms
429
+ of that license document, provided that the further restriction does
430
+ not survive such relicensing or conveying.
431
+
432
+ If you add terms to a covered work in accord with this section, you
433
+ must place, in the relevant source files, a statement of the
434
+ additional terms that apply to those files, or a notice indicating
435
+ where to find the applicable terms.
436
+
437
+ Additional terms, permissive or non-permissive, may be stated in the
438
+ form of a separately written license, or stated as exceptions;
439
+ the above requirements apply either way.
440
+
441
+ 8. Termination.
442
+
443
+ You may not propagate or modify a covered work except as expressly
444
+ provided under this License. Any attempt otherwise to propagate or
445
+ modify it is void, and will automatically terminate your rights under
446
+ this License (including any patent licenses granted under the third
447
+ paragraph of section 11).
448
+
449
+ However, if you cease all violation of this License, then your
450
+ license from a particular copyright holder is reinstated (a)
451
+ provisionally, unless and until the copyright holder explicitly and
452
+ finally terminates your license, and (b) permanently, if the copyright
453
+ holder fails to notify you of the violation by some reasonable means
454
+ prior to 60 days after the cessation.
455
+
456
+ Moreover, your license from a particular copyright holder is
457
+ reinstated permanently if the copyright holder notifies you of the
458
+ violation by some reasonable means, this is the first time you have
459
+ received notice of violation of this License (for any work) from that
460
+ copyright holder, and you cure the violation prior to 30 days after
461
+ your receipt of the notice.
462
+
463
+ Termination of your rights under this section does not terminate the
464
+ licenses of parties who have received copies or rights from you under
465
+ this License. If your rights have been terminated and not permanently
466
+ reinstated, you do not qualify to receive new licenses for the same
467
+ material under section 10.
468
+
469
+ 9. Acceptance Not Required for Having Copies.
470
+
471
+ You are not required to accept this License in order to receive or
472
+ run a copy of the Program. Ancillary propagation of a covered work
473
+ occurring solely as a consequence of using peer-to-peer transmission
474
+ to receive a copy likewise does not require acceptance. However,
475
+ nothing other than this License grants you permission to propagate or
476
+ modify any covered work. These actions infringe copyright if you do
477
+ not accept this License. Therefore, by modifying or propagating a
478
+ covered work, you indicate your acceptance of this License to do so.
479
+
480
+ 10. Automatic Licensing of Downstream Recipients.
481
+
482
+ Each time you convey a covered work, the recipient automatically
483
+ receives a license from the original licensors, to run, modify and
484
+ propagate that work, subject to this License. You are not responsible
485
+ for enforcing compliance by third parties with this License.
486
+
487
+ An "entity transaction" is a transaction transferring control of an
488
+ organization, or substantially all assets of one, or subdividing an
489
+ organization, or merging organizations. If propagation of a covered
490
+ work results from an entity transaction, each party to that
491
+ transaction who receives a copy of the work also receives whatever
492
+ licenses to the work the party's predecessor in interest had or could
493
+ give under the previous paragraph, plus a right to possession of the
494
+ Corresponding Source of the work from the predecessor in interest, if
495
+ the predecessor has it or can get it with reasonable efforts.
496
+
497
+ You may not impose any further restrictions on the exercise of the
498
+ rights granted or affirmed under this License. For example, you may
499
+ not impose a license fee, royalty, or other charge for exercise of
500
+ rights granted under this License, and you may not initiate litigation
501
+ (including a cross-claim or counterclaim in a lawsuit) alleging that
502
+ any patent claim is infringed by making, using, selling, offering for
503
+ sale, or importing the Program or any portion of it.
504
+
505
+ 11. Patents.
506
+
507
+ A "contributor" is a copyright holder who authorizes use under this
508
+ License of the Program or a work on which the Program is based. The
509
+ work thus licensed is called the contributor's "contributor version".
510
+
511
+ A contributor's "essential patent claims" are all patent claims
512
+ owned or controlled by the contributor, whether already acquired or
513
+ hereafter acquired, that would be infringed by some manner, permitted
514
+ by this License, of making, using, or selling its contributor version,
515
+ but do not include claims that would be infringed only as a
516
+ consequence of further modification of the contributor version. For
517
+ purposes of this definition, "control" includes the right to grant
518
+ patent sublicenses in a manner consistent with the requirements of
519
+ this License.
520
+
521
+ Each contributor grants you a non-exclusive, worldwide, royalty-free
522
+ patent license under the contributor's essential patent claims, to
523
+ make, use, sell, offer for sale, import and otherwise run, modify and
524
+ propagate the contents of its contributor version.
525
+
526
+ In the following three paragraphs, a "patent license" is any express
527
+ agreement or commitment, however denominated, not to enforce a patent
528
+ (such as an express permission to practice a patent or covenant not to
529
+ sue for patent infringement). To "grant" such a patent license to a
530
+ party means to make such an agreement or commitment not to enforce a
531
+ patent against the party.
532
+
533
+ If you convey a covered work, knowingly relying on a patent license,
534
+ and the Corresponding Source of the work is not available for anyone
535
+ to copy, free of charge and under the terms of this License, through a
536
+ publicly available network server or other readily accessible means,
537
+ then you must either (1) cause the Corresponding Source to be so
538
+ available, or (2) arrange to deprive yourself of the benefit of the
539
+ patent license for this particular work, or (3) arrange, in a manner
540
+ consistent with the requirements of this License, to extend the patent
541
+ license to downstream recipients. "Knowingly relying" means you have
542
+ actual knowledge that, but for the patent license, your conveying the
543
+ covered work in a country, or your recipient's use of the covered work
544
+ in a country, would infringe one or more identifiable patents in that
545
+ country that you have reason to believe are valid.
546
+
547
+ If, pursuant to or in connection with a single transaction or
548
+ arrangement, you convey, or propagate by procuring conveyance of, a
549
+ covered work, and grant a patent license to some of the parties
550
+ receiving the covered work authorizing them to use, propagate, modify
551
+ or convey a specific copy of the covered work, then the patent license
552
+ you grant is automatically extended to all recipients of the covered
553
+ work and works based on it.
554
+
555
+ A patent license is "discriminatory" if it does not include within
556
+ the scope of its coverage, prohibits the exercise of, or is
557
+ conditioned on the non-exercise of one or more of the rights that are
558
+ specifically granted under this License. You may not convey a covered
559
+ work if you are a party to an arrangement with a third party that is
560
+ in the business of distributing software, under which you make payment
561
+ to the third party based on the extent of your activity of conveying
562
+ the work, and under which the third party grants, to any of the
563
+ parties who would receive the covered work from you, a discriminatory
564
+ patent license (a) in connection with copies of the covered work
565
+ conveyed by you (or copies made from those copies), or (b) primarily
566
+ for and in connection with specific products or compilations that
567
+ contain the covered work, unless you entered into that arrangement,
568
+ or that patent license was granted, prior to 28 March 2007.
569
+
570
+ Nothing in this License shall be construed as excluding or limiting
571
+ any implied license or other defenses to infringement that may
572
+ otherwise be available to you under applicable patent law.
573
+
574
+ 12. No Surrender of Others' Freedom.
575
+
576
+ If conditions are imposed on you (whether by court order, agreement or
577
+ otherwise) that contradict the conditions of this License, they do not
578
+ excuse you from the conditions of this License. If you cannot convey a
579
+ covered work so as to satisfy simultaneously your obligations under this
580
+ License and any other pertinent obligations, then as a consequence you may
581
+ not convey it at all. For example, if you agree to terms that obligate you
582
+ to collect a royalty for further conveying from those to whom you convey
583
+ the Program, the only way you could satisfy both those terms and this
584
+ License would be to refrain entirely from conveying the Program.
585
+
586
+ 13. Use with the GNU Affero General Public License.
587
+
588
+ Notwithstanding any other provision of this License, you have
589
+ permission to link or combine any covered work with a work licensed
590
+ under version 3 of the GNU Affero General Public License into a single
591
+ combined work, and to convey the resulting work. The terms of this
592
+ License will continue to apply to the part which is the covered work,
593
+ but the special requirements of the GNU Affero General Public License,
594
+ section 13, concerning interaction through a network will apply to the
595
+ combination as such.
596
+
597
+ 14. Revised Versions of this License.
598
+
599
+ The Free Software Foundation may publish revised and/or new versions of
600
+ the GNU General Public License from time to time. Such new versions will
601
+ be similar in spirit to the present version, but may differ in detail to
602
+ address new problems or concerns.
603
+
604
+ Each version is given a distinguishing version number. If the
605
+ Program specifies that a certain numbered version of the GNU General
606
+ Public License "or any later version" applies to it, you have the
607
+ option of following the terms and conditions either of that numbered
608
+ version or of any later version published by the Free Software
609
+ Foundation. If the Program does not specify a version number of the
610
+ GNU General Public License, you may choose any version ever published
611
+ by the Free Software Foundation.
612
+
613
+ If the Program specifies that a proxy can decide which future
614
+ versions of the GNU General Public License can be used, that proxy's
615
+ public statement of acceptance of a version permanently authorizes you
616
+ to choose that version for the Program.
617
+
618
+ Later license versions may give you additional or different
619
+ permissions. However, no additional obligations are imposed on any
620
+ author or copyright holder as a result of your choosing to follow a
621
+ later version.
622
+
623
+ 15. Disclaimer of Warranty.
624
+
625
+ THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
626
+ APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
627
+ HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
628
+ OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
629
+ THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
630
+ PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
631
+ IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
632
+ ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
633
+
634
+ 16. Limitation of Liability.
635
+
636
+ IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
637
+ WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
638
+ THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
639
+ GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
640
+ USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
641
+ DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
642
+ PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
643
+ EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
644
+ SUCH DAMAGES.
645
+
646
+ 17. Interpretation of Sections 15 and 16.
647
+
648
+ If the disclaimer of warranty and limitation of liability provided
649
+ above cannot be given local legal effect according to their terms,
650
+ reviewing courts shall apply local law that most closely approximates
651
+ an absolute waiver of all civil liability in connection with the
652
+ Program, unless a warranty or assumption of liability accompanies a
653
+ copy of the Program in return for a fee.
654
+
655
+ END OF TERMS AND CONDITIONS
656
+
657
+ How to Apply These Terms to Your New Programs
658
+
659
+ If you develop a new program, and you want it to be of the greatest
660
+ possible use to the public, the best way to achieve this is to make it
661
+ free software which everyone can redistribute and change under these terms.
662
+
663
+ To do so, attach the following notices to the program. It is safest
664
+ to attach them to the start of each source file to most effectively
665
+ state the exclusion of warranty; and each file should have at least
666
+ the "copyright" line and a pointer to where the full notice is found.
667
+
668
+ <one line to give the program's name and a brief idea of what it does.>
669
+ Copyright © <year> <name of author>
670
+
671
+ This program is free software: you can redistribute it and/or modify
672
+ it under the terms of the GNU General Public License as published by
673
+ the Free Software Foundation, either version 3 of the License, or
674
+ (at your option) any later version.
675
+
676
+ This program is distributed in the hope that it will be useful,
677
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
678
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
679
+ GNU General Public License for more details.
680
+
681
+ You should have received a copy of the GNU General Public License
682
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
683
+
684
+ Also add information on how to contact you by electronic and paper mail.
685
+
686
+ If the program does terminal interaction, make it output a short
687
+ notice like this when it starts in an interactive mode:
688
+
689
+ <program> Copyright © <year> <name of author>
690
+ This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
691
+ This is free software, and you are welcome to redistribute it
692
+ under certain conditions; type `show c' for details.
693
+
694
+ The hypothetical commands `show w' and `show c' should show the appropriate
695
+ parts of the General Public License. Of course, your program's commands
696
+ might be different; for a GUI interface, you would use an "about box".
697
+
698
+ You should also get your employer (if you work as a programmer) or school,
699
+ if any, to sign a "copyright disclaimer" for the program, if necessary.
700
+ For more information on this, and how to apply and follow the GNU GPL, see
701
+ <http://www.gnu.org/licenses/>.
702
+
703
+ The GNU General Public License does not permit incorporating your program
704
+ into proprietary programs. If your program is a subroutine library, you
705
+ may consider it more useful to permit linking proprietary applications with
706
+ the library. If this is what you want to do, use the GNU Lesser General
707
+ Public License instead of this License. But first, please read
708
  <http://www.gnu.org/philosophy/why-not-lgpl.html>.
order-import-export.php CHANGED
@@ -1,282 +1,282 @@
1
- <?php
2
- /*
3
- *
4
- Plugin Name: Order / Coupon / Subscription Export Import Plugin for WooCommerce (BASIC)
5
- Plugin URI: https://www.xadapter.com/product/order-import-export-plugin-for-woocommerce/
6
- Description: Export and Import Order detail including line items, From and To your WooCommerce Store.
7
- Author: XAdapter
8
- Author URI: https://www.xadapter.com/
9
- Version: 1.3.2
10
- Text Domain: wf_order_import_export
11
- WC tested up to: 3.4.0
12
- */
13
-
14
- if ( ! defined( 'ABSPATH' ) || ! is_admin() ) {
15
- return;
16
- }
17
-
18
- define( "WF_ORDER_IMP_EXP_ID", "wf_order_imp_exp" );
19
- define( "WF_WOOCOMMERCE_ORDER_IM_EX", "wf_woocommerce_order_im_ex" );
20
-
21
- define("WF_CPN_IMP_EXP_ID", "wf_cpn_imp_exp");
22
- define("wf_coupon_csv_im_ex", "wf_coupon_csv_im_ex");
23
-
24
- if (!defined('WF_ORDERIMPEXP_CURRENT_VERSION')) {
25
- define("WF_ORDERIMPEXP_CURRENT_VERSION", "1.3.2");
26
- }
27
-
28
- /**
29
- * Check if WooCommerce is active
30
- */
31
- if (in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) )) {
32
-
33
- if ( ! class_exists( 'WF_Order_Import_Export_CSV' ) ) :
34
-
35
- /**
36
- * Main CSV Import class
37
- */
38
- class WF_Order_Import_Export_CSV {
39
-
40
- /**
41
- * Constructor
42
- */
43
- public function __construct() {
44
-
45
- define( 'WF_OrderImpExpCsv_FILE', __FILE__ );
46
-
47
- if (!defined('WT_OrdImpExpCsv_BASE')) {
48
- define('WT_OrdImpExpCsv_BASE', plugin_dir_path(__FILE__));
49
- }
50
-
51
- add_filter( 'woocommerce_screen_ids', array( $this, 'woocommerce_screen_ids' ) );
52
- add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( $this, 'wf_plugin_action_links' ) );
53
- add_action( 'init', array( $this, 'load_plugin_textdomain' ) );
54
- add_action( 'init', array( $this, 'catch_export_request' ), 20 );
55
- add_action( 'init', array( $this, 'catch_save_settings' ), 20 );
56
- add_action( 'admin_init', array( $this, 'register_importers' ) );
57
-
58
- include_once( 'includes/class-wf-orderimpexpcsv-admin-screen.php' );
59
- include_once( 'includes/importer/class-wf-orderimpexpcsv-importer.php' );
60
-
61
- if ( defined('DOING_AJAX') ) {
62
- include_once( 'includes/class-wf-orderimpexpcsv-ajax-handler.php' );
63
- }
64
-
65
- // uninstall feedback catch
66
- include_once 'includes/class-wf-orderimpexp-plugin-uninstall-feedback.php';
67
- }
68
-
69
- public function wf_plugin_action_links( $links ) {
70
- $plugin_links = array(
71
- '<a href="' . admin_url( 'admin.php?page=wf_woocommerce_order_im_ex' ) . '">' . __( 'Import Export', 'wf_order_import_export' ) . '</a>',
72
- '<a href="https://www.xadapter.com/product/order-import-export-plugin-for-woocommerce/" target="_blank" style="color:#3db634;">' . __( 'Premium Upgrade', 'wf_order_import_export' ) . '</a>',
73
- '<a href="https://wordpress.org/support/plugin/order-import-export-for-woocommerce">' . __( 'Support', 'wf_order_import_export' ) . '</a>',
74
- );
75
- if (array_key_exists('deactivate', $links)) {
76
- $links['deactivate'] = str_replace('<a', '<a class="wforderimpexp-deactivate-link"', $links['deactivate']);
77
- }
78
- return array_merge( $plugin_links, $links );
79
- }
80
-
81
- /**
82
- * Add screen ID
83
- */
84
- public function woocommerce_screen_ids( $ids ) {
85
- $ids[] = 'admin'; // For import screen
86
- return $ids;
87
- }
88
-
89
- /**
90
- * Handle localisation
91
- */
92
- public function load_plugin_textdomain() {
93
- load_plugin_textdomain( 'wf_order_import_export', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
94
- }
95
-
96
- /**
97
- * Catches an export request and exports the data. This class is only loaded in admin.
98
- */
99
- public function catch_export_request() {
100
- if ( ! empty( $_GET['action'] ) && ! empty( $_GET['page'] ) && $_GET['page'] == 'wf_woocommerce_order_im_ex' ) {
101
- switch ( $_GET['action'] ) {
102
- case "export" :
103
- $user_ok = $this->hf_user_permission();
104
- if ($user_ok) {
105
- include_once( 'includes/exporter/class-wf-orderimpexpcsv-exporter.php' );
106
- WF_OrderImpExpCsv_Exporter::do_export( 'shop_order' );
107
- } else {
108
- wp_redirect(wp_login_url());
109
- }
110
- break;
111
- }
112
- }
113
- }
114
-
115
- public function catch_save_settings() {
116
- if ( ! empty( $_GET['action'] ) && ! empty( $_GET['page'] ) && $_GET['page'] == 'wf_woocommerce_order_im_ex' ) {
117
- switch ( $_GET['action'] ) {
118
- case "settings" :
119
- include_once( 'includes/settings/class-wf-orderimpexpcsv-settings.php' );
120
- WF_OrderImpExpCsv_Settings::save_settings( );
121
- break;
122
- }
123
- }
124
- }
125
-
126
- /**
127
- * Register importers for use
128
- */
129
- public function register_importers() {
130
- register_importer( 'woocommerce_wf_order_csv', 'WooCommerce Order (CSV)', __('Import <strong>Orders</strong> to your store via a csv file.', 'wf_order_import_export'), 'WF_OrderImpExpCsv_Importer::order_importer' );
131
- }
132
-
133
- private function hf_user_permission() {
134
- // Check if user has rights to export
135
- $current_user = wp_get_current_user();
136
- $user_ok = false;
137
- $wf_roles = apply_filters('hf_user_permission_roles', array('administrator', 'shop_manager'));
138
- if ($current_user instanceof WP_User) {
139
- $can_users = array_intersect($wf_roles, $current_user->roles);
140
- if (!empty($can_users)) {
141
- $user_ok = true;
142
- }
143
- }
144
- return $user_ok;
145
- }
146
- }
147
- endif;
148
-
149
- new WF_Order_Import_Export_CSV();
150
-
151
-
152
-
153
- if (!class_exists('WF_Coupon_Import_Export_CSV')) :
154
-
155
- class WF_Coupon_Import_Export_CSV {
156
-
157
- public $cron;
158
- public $cron_import;
159
-
160
- /**
161
- * Constructor
162
- */
163
- public function __construct() {
164
-
165
- define('WF_CpnImpExpCsv_FILE', __FILE__);
166
-
167
- if (is_admin()) {
168
- add_action('admin_notices', array($this, 'wf_coupon_ie_admin_notice'), 15);
169
- }
170
-
171
- add_filter('woocommerce_screen_ids', array($this, 'woocommerce_screen_ids'));
172
- add_action('init', array($this, 'load_plugin_textdomain'));
173
- add_action('init', array($this, 'catch_export_request'), 20);
174
- add_action('init', array($this, 'catch_save_settings'), 20);
175
- add_action('admin_init', array($this, 'register_importers'));
176
-
177
- include_once( 'includes/class-wf-cpnimpexpcsv-admin-screen.php' );
178
- include_once( 'includes/importer/class-wf-cpnimpexpcsv-importer.php' );
179
-
180
- if (defined('DOING_AJAX')) {
181
- include_once( 'includes/class-wf-cpnimpexpcsv-ajax-handler.php' );
182
- }
183
-
184
- }
185
-
186
-
187
- function wf_coupon_ie_admin_notice() {
188
- global $pagenow;
189
- global $post;
190
-
191
- if (!isset($_GET["wf_coupon_ie_msg"]) && empty($_GET["wf_coupon_ie_msg"])) {
192
- return;
193
- }
194
-
195
- $wf_coupon_ie_msg = $_GET["wf_coupon_ie_msg"];
196
-
197
- switch ($wf_coupon_ie_msg) {
198
- case "1":
199
- echo '<div class="update"><p>' . __('Successfully uploaded via FTP.', 'wf_order_import_export') . '</p></div>';
200
- break;
201
- case "2":
202
- echo '<div class="error"><p>' . __('Error while uploading via FTP.', 'wf_order_import_export') . '</p></div>';
203
- break;
204
- case "3":
205
- echo '<div class="error"><p>' . __('Please choose the file in CSV format using Method 1.', 'wf_order_import_export') . '</p></div>';
206
- break;
207
- }
208
- }
209
-
210
- /**
211
- * Add screen ID
212
- */
213
- public function woocommerce_screen_ids($ids) {
214
- $ids[] = 'admin'; // For import screen
215
- return $ids;
216
- }
217
-
218
- /**
219
- * Handle localisation
220
- */
221
- public function load_plugin_textdomain() {
222
- load_plugin_textdomain('wf_order_import_export', false, dirname(plugin_basename(__FILE__)) . '/lang/');
223
- }
224
-
225
- /**
226
- * Catches an export request and exports the data. This class is only loaded in admin.
227
- */
228
- public function catch_export_request() {
229
- if (!empty($_GET['action']) && !empty($_GET['page']) && $_GET['page'] == 'wf_coupon_csv_im_ex') {
230
- switch ($_GET['action']) {
231
- case "export" :
232
- $user_ok = $this->hf_user_permission();
233
- if ($user_ok) {
234
- include_once( 'includes/exporter/class-wf-cpnimpexpcsv-exporter.php' );
235
- WF_CpnImpExpCsv_Exporter::do_export('shop_coupon');
236
- } else {
237
- wp_redirect(wp_login_url());
238
- }
239
- break;
240
- }
241
- }
242
- }
243
-
244
- public function catch_save_settings() {
245
- if (!empty($_GET['action']) && !empty($_GET['page']) && $_GET['page'] == 'wf_coupon_csv_im_ex') {
246
- switch ($_GET['action']) {
247
- case "settings" :
248
- include_once( 'includes/settings/class-wf-allimpexpcsv-settings.php' );
249
- wf_allImpExpCsv_Settings::save_settings();
250
- break;
251
- }
252
- }
253
- }
254
-
255
- /**
256
- * Register importers for use
257
- */
258
- public function register_importers() {
259
- register_importer('coupon_csv', 'WooCommerce Coupons (CSV)', __('Import <strong>coupon</strong> to your store via a csv file.', 'wf_order_import_export'), 'WF_CpnImpExpCsv_Importer::coupon_importer');
260
- }
261
-
262
- private function hf_user_permission() {
263
- // Check if user has rights to export
264
- $current_user = wp_get_current_user();
265
- $user_ok = false;
266
- $wf_roles = apply_filters('hf_user_permission_roles', array('administrator', 'shop_manager'));
267
- if ($current_user instanceof WP_User) {
268
- $can_users = array_intersect($wf_roles, $current_user->roles);
269
- if (!empty($can_users)) {
270
- $user_ok = true;
271
- }
272
- }
273
- return $user_ok;
274
- }
275
-
276
- }
277
-
278
- endif;
279
-
280
- new WF_Coupon_Import_Export_CSV();
281
-
282
  }
1
+ <?php
2
+ /*
3
+ *
4
+ Plugin Name: Order / Coupon / Subscription Export Import Plugin for WooCommerce (BASIC)
5
+ Plugin URI: https://wordpress.org/plugins/order-import-export-for-woocommerce/
6
+ Description: Export and Import Order detail including line items, From and To your WooCommerce Store.
7
+ Author: WebToffee
8
+ Author URI: https://www.webtoffee.com/product/woocommerce-order-coupon-subscription-export-import/
9
+ Version: 1.3.3
10
+ Text Domain: wf_order_import_export
11
+ WC tested up to: 3.4.3
12
+ */
13
+
14
+ if ( ! defined( 'ABSPATH' ) || ! is_admin() ) {
15
+ return;
16
+ }
17
+
18
+ define( "WF_ORDER_IMP_EXP_ID", "wf_order_imp_exp" );
19
+ define( "WF_WOOCOMMERCE_ORDER_IM_EX", "wf_woocommerce_order_im_ex" );
20
+
21
+ define("WF_CPN_IMP_EXP_ID", "wf_cpn_imp_exp");
22
+ define("wf_coupon_csv_im_ex", "wf_coupon_csv_im_ex");
23
+
24
+ if (!defined('WF_ORDERIMPEXP_CURRENT_VERSION')) {
25
+ define("WF_ORDERIMPEXP_CURRENT_VERSION", "1.3.3");
26
+ }
27
+
28
+ /**
29
+ * Check if WooCommerce is active
30
+ */
31
+ if (in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) )) {
32
+
33
+ if ( ! class_exists( 'WF_Order_Import_Export_CSV' ) ) :
34
+
35
+ /**
36
+ * Main CSV Import class
37
+ */
38
+ class WF_Order_Import_Export_CSV {
39
+
40
+ /**
41
+ * Constructor
42
+ */
43
+ public function __construct() {
44
+
45
+ define( 'WF_OrderImpExpCsv_FILE', __FILE__ );
46
+
47
+ if (!defined('WT_OrdImpExpCsv_BASE')) {
48
+ define('WT_OrdImpExpCsv_BASE', plugin_dir_path(__FILE__));
49
+ }
50
+
51
+ add_filter( 'woocommerce_screen_ids', array( $this, 'woocommerce_screen_ids' ) );
52
+ add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( $this, 'wf_plugin_action_links' ) );
53
+ add_action( 'init', array( $this, 'load_plugin_textdomain' ) );
54
+ add_action( 'init', array( $this, 'catch_export_request' ), 20 );
55
+ add_action( 'init', array( $this, 'catch_save_settings' ), 20 );
56
+ add_action( 'admin_init', array( $this, 'register_importers' ) );
57
+
58
+ include_once( 'includes/class-wf-orderimpexpcsv-admin-screen.php' );
59
+ include_once( 'includes/importer/class-wf-orderimpexpcsv-importer.php' );
60
+
61
+ if ( defined('DOING_AJAX') ) {
62
+ include_once( 'includes/class-wf-orderimpexpcsv-ajax-handler.php' );
63
+ }
64
+
65
+ // uninstall feedback catch
66
+ include_once 'includes/class-wf-orderimpexp-plugin-uninstall-feedback.php';
67
+ }
68
+
69
+ public function wf_plugin_action_links( $links ) {
70
+ $plugin_links = array(
71
+ '<a href="' . admin_url( 'admin.php?page=wf_woocommerce_order_im_ex' ) . '">' . __( 'Import Export', 'wf_order_import_export' ) . '</a>',
72
+ '<a href="https://www.xadapter.com/product/order-import-export-plugin-for-woocommerce/" target="_blank" style="color:#3db634;">' . __( 'Premium Upgrade', 'wf_order_import_export' ) . '</a>',
73
+ '<a href="https://wordpress.org/support/plugin/order-import-export-for-woocommerce">' . __( 'Support', 'wf_order_import_export' ) . '</a>',
74
+ );
75
+ if (array_key_exists('deactivate', $links)) {
76
+ $links['deactivate'] = str_replace('<a', '<a class="wforderimpexp-deactivate-link"', $links['deactivate']);
77
+ }
78
+ return array_merge( $plugin_links, $links );
79
+ }
80
+
81
+ /**
82
+ * Add screen ID
83
+ */
84
+ public function woocommerce_screen_ids( $ids ) {
85
+ $ids[] = 'admin'; // For import screen
86
+ return $ids;
87
+ }
88
+
89
+ /**
90
+ * Handle localisation
91
+ */
92
+ public function load_plugin_textdomain() {
93
+ load_plugin_textdomain( 'wf_order_import_export', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
94
+ }
95
+
96
+ /**
97
+ * Catches an export request and exports the data. This class is only loaded in admin.
98
+ */
99
+ public function catch_export_request() {
100
+ if ( ! empty( $_GET['action'] ) && ! empty( $_GET['page'] ) && $_GET['page'] == 'wf_woocommerce_order_im_ex' ) {
101
+ switch ( $_GET['action'] ) {
102
+ case "export" :
103
+ $user_ok = $this->hf_user_permission();
104
+ if ($user_ok) {
105
+ include_once( 'includes/exporter/class-wf-orderimpexpcsv-exporter.php' );
106
+ WF_OrderImpExpCsv_Exporter::do_export( 'shop_order' );
107
+ } else {
108
+ wp_redirect(wp_login_url());
109
+ }
110
+ break;
111
+ }
112
+ }
113
+ }
114
+
115
+ public function catch_save_settings() {
116
+ if ( ! empty( $_GET['action'] ) && ! empty( $_GET['page'] ) && $_GET['page'] == 'wf_woocommerce_order_im_ex' ) {
117
+ switch ( $_GET['action'] ) {
118
+ case "settings" :
119
+ include_once( 'includes/settings/class-wf-orderimpexpcsv-settings.php' );
120
+ WF_OrderImpExpCsv_Settings::save_settings( );
121
+ break;
122
+ }
123
+ }
124
+ }
125
+
126
+ /**
127
+ * Register importers for use
128
+ */
129
+ public function register_importers() {
130
+ register_importer( 'woocommerce_wf_order_csv', 'WooCommerce Order (CSV)', __('Import <strong>Orders</strong> to your store via a csv file.', 'wf_order_import_export'), 'WF_OrderImpExpCsv_Importer::order_importer' );
131
+ }
132
+
133
+ private function hf_user_permission() {
134
+ // Check if user has rights to export
135
+ $current_user = wp_get_current_user();
136
+ $user_ok = false;
137
+ $wf_roles = apply_filters('hf_user_permission_roles', array('administrator', 'shop_manager'));
138
+ if ($current_user instanceof WP_User) {
139
+ $can_users = array_intersect($wf_roles, $current_user->roles);
140
+ if (!empty($can_users)) {
141
+ $user_ok = true;
142
+ }
143
+ }
144
+ return $user_ok;
145
+ }
146
+ }
147
+ endif;
148
+
149
+ new WF_Order_Import_Export_CSV();
150
+
151
+
152
+
153
+ if (!class_exists('WF_Coupon_Import_Export_CSV')) :
154
+
155
+ class WF_Coupon_Import_Export_CSV {
156
+
157
+ public $cron;
158
+ public $cron_import;
159
+
160
+ /**
161
+ * Constructor
162
+ */
163
+ public function __construct() {
164
+
165
+ define('WF_CpnImpExpCsv_FILE', __FILE__);
166
+
167
+ if (is_admin()) {
168
+ add_action('admin_notices', array($this, 'wf_coupon_ie_admin_notice'), 15);
169
+ }
170
+
171
+ add_filter('woocommerce_screen_ids', array($this, 'woocommerce_screen_ids'));
172
+ add_action('init', array($this, 'load_plugin_textdomain'));
173
+ add_action('init', array($this, 'catch_export_request'), 20);
174
+ add_action('init', array($this, 'catch_save_settings'), 20);
175
+ add_action('admin_init', array($this, 'register_importers'));
176
+
177
+ include_once( 'includes/class-wf-cpnimpexpcsv-admin-screen.php' );
178
+ include_once( 'includes/importer/class-wf-cpnimpexpcsv-importer.php' );
179
+
180
+ if (defined('DOING_AJAX')) {
181
+ include_once( 'includes/class-wf-cpnimpexpcsv-ajax-handler.php' );
182
+ }
183
+
184
+ }
185
+
186
+
187
+ function wf_coupon_ie_admin_notice() {
188
+ global $pagenow;
189
+ global $post;
190
+
191
+ if (!isset($_GET["wf_coupon_ie_msg"]) && empty($_GET["wf_coupon_ie_msg"])) {
192
+ return;
193
+ }
194
+
195
+ $wf_coupon_ie_msg = $_GET["wf_coupon_ie_msg"];
196
+
197
+ switch ($wf_coupon_ie_msg) {
198
+ case "1":
199
+ echo '<div class="update"><p>' . __('Successfully uploaded via FTP.', 'wf_order_import_export') . '</p></div>';
200
+ break;
201
+ case "2":
202
+ echo '<div class="error"><p>' . __('Error while uploading via FTP.', 'wf_order_import_export') . '</p></div>';
203
+ break;
204
+ case "3":
205
+ echo '<div class="error"><p>' . __('Please choose the file in CSV format using Method 1.', 'wf_order_import_export') . '</p></div>';
206
+ break;
207
+ }
208
+ }
209
+
210
+ /**
211
+ * Add screen ID
212
+ */
213
+ public function woocommerce_screen_ids($ids) {
214
+ $ids[] = 'admin'; // For import screen
215
+ return $ids;
216
+ }
217
+
218
+ /**
219
+ * Handle localisation
220
+ */
221
+ public function load_plugin_textdomain() {
222
+ load_plugin_textdomain('wf_order_import_export', false, dirname(plugin_basename(__FILE__)) . '/lang/');
223
+ }
224
+
225
+ /**
226
+ * Catches an export request and exports the data. This class is only loaded in admin.
227
+ */
228
+ public function catch_export_request() {
229
+ if (!empty($_GET['action']) && !empty($_GET['page']) && $_GET['page'] == 'wf_coupon_csv_im_ex') {
230
+ switch ($_GET['action']) {
231
+ case "export" :
232
+ $user_ok = $this->hf_user_permission();
233
+ if ($user_ok) {
234
+ include_once( 'includes/exporter/class-wf-cpnimpexpcsv-exporter.php' );
235
+ WF_CpnImpExpCsv_Exporter::do_export('shop_coupon');
236
+ } else {
237
+ wp_redirect(wp_login_url());
238
+ }
239
+ break;
240
+ }
241
+ }
242
+ }
243
+
244
+ public function catch_save_settings() {
245
+ if (!empty($_GET['action']) && !empty($_GET['page']) && $_GET['page'] == 'wf_coupon_csv_im_ex') {
246
+ switch ($_GET['action']) {
247
+ case "settings" :
248
+ include_once( 'includes/settings/class-wf-allimpexpcsv-settings.php' );
249
+ wf_allImpExpCsv_Settings::save_settings();
250
+ break;
251
+ }
252
+ }
253
+ }
254
+
255
+ /**
256
+ * Register importers for use
257
+ */
258
+ public function register_importers() {
259
+ register_importer('coupon_csv', 'WooCommerce Coupons (CSV)', __('Import <strong>coupon</strong> to your store via a csv file.', 'wf_order_import_export'), 'WF_CpnImpExpCsv_Importer::coupon_importer');
260
+ }
261
+
262
+ private function hf_user_permission() {
263
+ // Check if user has rights to export
264
+ $current_user = wp_get_current_user();
265
+ $user_ok = false;
266
+ $wf_roles = apply_filters('hf_user_permission_roles', array('administrator', 'shop_manager'));
267
+ if ($current_user instanceof WP_User) {
268
+ $can_users = array_intersect($wf_roles, $current_user->roles);
269
+ if (!empty($can_users)) {
270
+ $user_ok = true;
271
+ }
272
+ }
273
+ return $user_ok;
274
+ }
275
+
276
+ }
277
+
278
+ endif;
279
+
280
+ new WF_Coupon_Import_Export_CSV();
281
+
282
  }
readme.txt CHANGED
@@ -1,10 +1,10 @@
1
  === Order Export & Order Import for WooCommerce ===
2
- Contributors: xadapter, mujeebur, webtoffee
3
  Donate link:
4
  Tags: Order Export, Order Import, WooCommerce Export Orders , WooCommerce Import Orders , Export Orders, Import Orders
5
  Requires at least: 3.0.1
6
- Tested up to: 4.9.6
7
- Stable tag: 1.3.2
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -111,7 +111,11 @@ Yes. You can import or export order line item details.
111
  3. Exported order sample Screen
112
 
113
  == Changelog ==
114
-
 
 
 
 
115
  = 1.3.2 =
116
  * Bug fix.
117
  = 1.3.1 =
@@ -185,5 +189,7 @@ Yes. You can import or export order line item details.
185
  * Export /Import WooCommerce Orders.
186
 
187
  == Upgrade Notice ==
188
- = 1.3.2 =
 
 
189
  * Bug fix.
1
  === Order Export & Order Import for WooCommerce ===
2
+ Contributors: webtoffee
3
  Donate link:
4
  Tags: Order Export, Order Import, WooCommerce Export Orders , WooCommerce Import Orders , Export Orders, Import Orders
5
  Requires at least: 3.0.1
6
+ Tested up to: 4.9.7
7
+ Stable tag: 1.3.3
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
111
  3. Exported order sample Screen
112
 
113
  == Changelog ==
114
+
115
+ = 1.3.3 =
116
+ * Sample CSV file updated.
117
+ * WC 3.4.3 Tested OK.
118
+ * Bug fix.
119
  = 1.3.2 =
120
  * Bug fix.
121
  = 1.3.1 =
189
  * Export /Import WooCommerce Orders.
190
 
191
  == Upgrade Notice ==
192
+ = 1.3.3 =
193
+ * Sample CSV file updated.
194
+ * WC 3.4.3 Tested OK.
195
  * Bug fix.
styles/wf-style.css CHANGED
@@ -1,267 +1,267 @@
1
- #icon-woocommerce-importer {
2
- background-image: url(../images/wf-import.png) !important;
3
- background-position: -3px -5px;
4
- }
5
- .widefat_importer td {
6
- vertical-align: middle;
7
- padding: 5px 9px;
8
- }
9
- #import-progress {
10
- width: 100%;
11
- }
12
- #import-progress td, #import-progress th {
13
- padding: .5em 1em;
14
- }
15
- #import-progress td.status, #import-progress th.status {
16
- width: 32px;
17
- }
18
- #import-progress td.row, #import-progress th.row {
19
- width: 3em;
20
- text-align: center;
21
- }
22
- #import-progress td.reason, #import-progress th.reason {
23
- text-align: right;
24
- }
25
- #import-progress tr.importer-loading td {
26
- background: url(../images/wf-ajax-loader.gif) no-repeat center center;
27
- height: 32px;
28
- }
29
- #import-progress .merged td,
30
- #import-progress .imported td {
31
- }
32
- #import-progress .skipped td {
33
- border-bottom-color: #dbcb83;
34
- background: #f2ecd2;
35
- }
36
- #import-progress .failed td {
37
- border-bottom-color: #e6adaa;
38
- background: #f2d3d2;
39
- }
40
- #import-progress mark.result {
41
- height: 0;
42
- display: block;
43
- line-height: 16px;
44
- overflow: hidden;
45
- padding: 16px 0 0 0;
46
- }
47
- #import-progress .skipped mark.result {
48
- background: url(../images/wf-notice.png) no-repeat center top;
49
- }
50
- #import-progress .merged mark.result,
51
- #import-progress .imported mark.result {
52
- background: url(../images/wf-success.png) no-repeat center top;
53
- }
54
- #import-progress .failed mark.result {
55
- background: url(../images/wf-failed.png) no-repeat center top;
56
- }
57
- #import-progress .complete td {
58
- background: #000;
59
- border-color: #000;
60
- border-top: 4px solid #000;
61
- color: #fff;
62
- font-size: 1.5em;
63
- padding: .95em 1em 1em;
64
- text-align: center;
65
- }
66
- #import-progress .regenerating td {
67
- padding: 0;
68
- }
69
- #import-progress .regenerating div.progress {
70
- background: #464646;
71
- padding: .95em 1em 1em;
72
- color: #fff;
73
- overflow: hidden;
74
- width: 0;
75
- float: left;
76
- text-align: left;
77
- white-space: nowrap;
78
- }
79
- .update{
80
- background: #fff;
81
- border-left: 4px solid #fff;
82
- padding: 1px 12px;
83
- border-left-color: #46b450;
84
- margin-top: 10px;
85
- }
86
- #datagrid { border-collapse: collapse; text-align: left; width: 80%; }
87
- #datagrid {
88
- background: #fff; overflow: hidden;
89
- }
90
- #datagrid td{ padding: 3px 10px; }
91
- #datagrid th { padding: 3px 25px; color: #fff; background-color: #ccc; font-weight: bold;font-size: 15px; }
92
-
93
- .woocommerce-message a.button-primary, .woocommerce-message button.button-primary{
94
- background: #0085ba none repeat scroll 0 0 !important;
95
- border-color: #0073aa #006799 #006799 !important;}
96
- .woocommerce-message{border-left-color:#46b450 !important;}
97
- .chosen-container-multi .chosen-choices li.search-field{
98
- padding: 5px !important;
99
- }
100
- .chosen-container-multi .chosen-choices li.search-field input[type="text"]{
101
- padding: 1px !important;
102
- }
103
- .order_actions .download_to_csv_wf {
104
- display: block;
105
- height: 2em !important;
106
- padding: 0 !important;
107
- position: relative;
108
- text-indent: -9999px;
109
- width: 2em;
110
- }
111
- .order_actions .download_to_csv_wf::after {
112
- content: "";
113
- font-family: "dashicons";
114
- font-variant: normal;
115
- font-weight: normal;
116
- height: 100%;
117
- left: 0;
118
- margin: 0;
119
- position: absolute;
120
- text-align: center;
121
- text-indent: 0;
122
- text-transform: none;
123
- top: 0;
124
- width: 100%;
125
- }
126
-
127
-
128
-
129
-
130
-
131
-
132
- .clearfix{
133
- clear: both;
134
- }
135
- .nav-tab-wrapper .nav-tab-premium {
136
- background: #5ccc96;
137
- color: white;
138
- border-color: #5ccc96;
139
- }
140
- .orderimpexp-main-box{
141
- width: 100%;
142
- }
143
- .orderimpexp-main-box input {
144
- box-shadow: none;
145
- padding: 7px 10px;
146
- }
147
- .orderimpexp-view{
148
- width:65%;
149
- float: left;
150
- }
151
- .market-box{
152
- width:30%;
153
- float: right;
154
- }
155
- .bg-white {
156
- background: #fff;
157
- }
158
- .p-20p {
159
- padding: 20px;
160
- }
161
- .getting-started-video{
162
- background: #fff;
163
- padding: 5px;
164
- margin-bottom: 23px;
165
- }
166
- .getting-started-video h2{
167
- text-align: center;
168
- padding: 5px;
169
- }
170
-
171
- .getting-started-video iframe{
172
- margin:5px auto 25px auto;
173
- display: block;
174
- }
175
- .orderimpexp-premium-features{
176
- background: #fff;
177
- padding:5px;
178
- }
179
- .orderimpexp-premium-features ul {
180
- padding-left: 20px;
181
- padding-right: 20px;
182
- }
183
- .orderimpexp-premium-features li {
184
- margin-bottom: 15px;
185
- padding-left: 15px;
186
- }
187
- .orderimpexp-premium-features li:before
188
- {
189
- font-family: dashicons;
190
- text-decoration: inherit;
191
- font-weight: 400;
192
- font-style: normal;
193
- vertical-align: top;
194
- text-align: center;
195
- content: "\f147";
196
- margin-right: 10px;
197
- margin-left: -25px;
198
- font-size: 16px;
199
- color: #3085bb;
200
- }
201
- .orderimpexp-premium-features .button {
202
- margin-bottom: 20px;
203
- }
204
- .orderimpexp-premium-features .button-go-pro {
205
- box-shadow: none;
206
- border: 0;
207
- text-shadow: none;
208
- padding: 10px 15px;
209
- height: auto;
210
- font-size: 18px;
211
- border-radius: 4px;
212
- font-weight: 600;
213
- background: #00cb95;
214
- margin-top: 20px;
215
- }
216
- .orderimpexp-premium-features .button-go-pro:hover,
217
- .orderimpexp-premium-features .button-go-pro:focus,
218
- .orderimpexp-premium-features .button-go-pro:active {
219
- background: #00a378;
220
- }
221
- .orderimpexp-premium-features .button-doc-demo {
222
- border: 0;
223
- background: #d8d8dc;
224
- box-shadow: none;
225
- padding: 10px 15px;
226
- font-size: 15px;
227
- height: auto;
228
- margin-left: 10px;
229
- margin-right: 10px;
230
- margin-top: 10px;
231
- }
232
- .orderimpexp-premium-features .button-doc-demo:hover,
233
- .orderimpexp-premium-features .button-doc-demo:focus,
234
- .orderimpexp-premium-features .button-doc-demo:active {
235
- background: #dfdfe4;
236
- }
237
- .xa-orderimpexp-rating-link{color:#ffc600;}
238
-
239
- .orderimpexp-review-widget{
240
- background: #fff;
241
- padding: 5px;
242
- margin-top: 23px;
243
- }
244
- .orderimpexp-review-widget p{
245
- margin-right:5px;
246
- margin-left:5px;
247
- }
248
- .button-show-more {
249
- text-align: center;
250
- }
251
- .button-show-more .button,
252
- .button-show-more .button:hover,
253
- .button-show-more .button:focus{
254
- box-shadow: none;
255
- border: 0;
256
- height: auto;
257
- line-height: 1;
258
- color: #4e71a5;
259
- text-shadow: none;
260
- font-weight: 500;
261
- background: transparent;
262
- }
263
-
264
- .button-show-more .button .dashicons {
265
- font-size: 12px;
266
- line-height: 1.5;
267
  }
1
+ #icon-woocommerce-importer {
2
+ background-image: url(../images/wf-import.png) !important;
3
+ background-position: -3px -5px;
4
+ }
5
+ .widefat_importer td {
6
+ vertical-align: middle;
7
+ padding: 5px 9px;
8
+ }
9
+ #import-progress {
10
+ width: 100%;
11
+ }
12
+ #import-progress td, #import-progress th {
13
+ padding: .5em 1em;
14
+ }
15
+ #import-progress td.status, #import-progress th.status {
16
+ width: 32px;
17
+ }
18
+ #import-progress td.row, #import-progress th.row {
19
+ width: 3em;
20
+ text-align: center;
21
+ }
22
+ #import-progress td.reason, #import-progress th.reason {
23
+ text-align: right;
24
+ }
25
+ #import-progress tr.importer-loading td {
26
+ background: url(../images/wf-ajax-loader.gif) no-repeat center center;
27
+ height: 32px;
28
+ }
29
+ #import-progress .merged td,
30
+ #import-progress .imported td {
31
+ }
32
+ #import-progress .skipped td {
33
+ border-bottom-color: #dbcb83;
34
+ background: #f2ecd2;
35
+ }
36
+ #import-progress .failed td {
37
+ border-bottom-color: #e6adaa;
38
+ background: #f2d3d2;
39
+ }
40
+ #import-progress mark.result {
41
+ height: 0;
42
+ display: block;
43
+ line-height: 16px;
44
+ overflow: hidden;
45
+ padding: 16px 0 0 0;
46
+ }
47
+ #import-progress .skipped mark.result {
48
+ background: url(../images/wf-notice.png) no-repeat center top;
49
+ }
50
+ #import-progress .merged mark.result,
51
+ #import-progress .imported mark.result {
52
+ background: url(../images/wf-success.png) no-repeat center top;
53
+ }
54
+ #import-progress .failed mark.result {
55
+ background: url(../images/wf-failed.png) no-repeat center top;
56
+ }
57
+ #import-progress .complete td {
58
+ background: #000;
59
+ border-color: #000;
60
+ border-top: 4px solid #000;
61
+ color: #fff;
62
+ font-size: 1.5em;
63
+ padding: .95em 1em 1em;
64
+ text-align: center;
65
+ }
66
+ #import-progress .regenerating td {
67
+ padding: 0;
68
+ }
69
+ #import-progress .regenerating div.progress {
70
+ background: #464646;
71
+ padding: .95em 1em 1em;
72
+ color: #fff;
73
+ overflow: hidden;
74
+ width: 0;
75
+ float: left;
76
+ text-align: left;
77
+ white-space: nowrap;
78
+ }
79
+ .update{
80
+ background: #fff;
81
+ border-left: 4px solid #fff;
82
+ padding: 1px 12px;
83
+ border-left-color: #46b450;
84
+ margin-top: 10px;
85
+ }
86
+ #datagrid { border-collapse: collapse; text-align: left; width: 80%; }
87
+ #datagrid {
88
+ background: #fff; overflow: hidden;
89
+ }
90
+ #datagrid td{ padding: 3px 10px; }
91
+ #datagrid th { padding: 3px 25px; color: #fff; background-color: #ccc; font-weight: bold;font-size: 15px; }
92
+
93
+ .woocommerce-message a.button-primary, .woocommerce-message button.button-primary{
94
+ background: #0085ba none repeat scroll 0 0 !important;
95
+ border-color: #0073aa #006799 #006799 !important;}
96
+ .woocommerce-message{border-left-color:#46b450 !important;}
97
+ .chosen-container-multi .chosen-choices li.search-field{
98
+ padding: 5px !important;
99
+ }
100
+ .chosen-container-multi .chosen-choices li.search-field input[type="text"]{
101
+ padding: 1px !important;
102
+ }
103
+ .order_actions .download_to_csv_wf {
104
+ display: block;
105
+ height: 2em !important;
106
+ padding: 0 !important;
107
+ position: relative;
108
+ text-indent: -9999px;
109
+ width: 2em;
110
+ }
111
+ .order_actions .download_to_csv_wf::after {
112
+ content: "";
113
+ font-family: "dashicons";
114
+ font-variant: normal;
115
+ font-weight: normal;
116
+ height: 100%;
117
+ left: 0;
118
+ margin: 0;
119
+ position: absolute;
120
+ text-align: center;
121
+ text-indent: 0;
122
+ text-transform: none;
123
+ top: 0;
124
+ width: 100%;
125
+ }
126
+
127
+
128
+
129
+
130
+
131
+
132
+ .clearfix{
133
+ clear: both;
134
+ }
135
+ .nav-tab-wrapper .nav-tab-premium {
136
+ background: #5ccc96;
137
+ color: white;
138
+ border-color: #5ccc96;
139
+ }
140
+ .orderimpexp-main-box{
141
+ width: 100%;
142
+ }
143
+ .orderimpexp-main-box input {
144
+ box-shadow: none;
145
+ padding: 7px 10px;
146
+ }
147
+ .orderimpexp-view{
148
+ width:65%;
149
+ float: left;
150
+ }
151
+ .market-box{
152
+ width:30%;
153
+ float: right;
154
+ }
155
+ .bg-white {
156
+ background: #fff;
157
+ }
158
+ .p-20p {
159
+ padding: 20px;
160
+ }
161
+ .getting-started-video{
162
+ background: #fff;
163
+ padding: 5px;
164
+ margin-bottom: 23px;
165
+ }
166
+ .getting-started-video h2{
167
+ text-align: center;
168
+ padding: 5px;
169
+ }
170
+
171
+ .getting-started-video iframe{
172
+ margin:5px auto 25px auto;
173
+ display: block;
174
+ }
175
+ .orderimpexp-premium-features{
176
+ background: #fff;
177
+ padding:5px;
178
+ }
179
+ .orderimpexp-premium-features ul {
180
+ padding-left: 20px;
181
+ padding-right: 20px;
182
+ }
183
+ .orderimpexp-premium-features li {
184
+ margin-bottom: 15px;
185
+ padding-left: 15px;
186
+ }
187
+ .orderimpexp-premium-features li:before
188
+ {
189
+ font-family: dashicons;
190
+ text-decoration: inherit;
191
+ font-weight: 400;
192
+ font-style: normal;
193
+ vertical-align: top;
194
+ text-align: center;
195
+ content: "\f147";
196
+ margin-right: 10px;
197
+ margin-left: -25px;
198
+ font-size: 16px;
199
+ color: #3085bb;
200
+ }
201
+ .orderimpexp-premium-features .button {
202
+ margin-bottom: 20px;
203
+ }
204
+ .orderimpexp-premium-features .button-go-pro {
205
+ box-shadow: none;
206
+ border: 0;
207
+ text-shadow: none;
208
+ padding: 10px 15px;
209
+ height: auto;
210
+ font-size: 18px;
211
+ border-radius: 4px;
212
+ font-weight: 600;
213
+ background: #00cb95;
214
+ margin-top: 20px;
215
+ }
216
+ .orderimpexp-premium-features .button-go-pro:hover,
217
+ .orderimpexp-premium-features .button-go-pro:focus,
218
+ .orderimpexp-premium-features .button-go-pro:active {
219
+ background: #00a378;
220
+ }
221
+ .orderimpexp-premium-features .button-doc-demo {
222
+ border: 0;
223
+ background: #d8d8dc;
224
+ box-shadow: none;
225
+ padding: 10px 15px;
226
+ font-size: 15px;
227
+ height: auto;
228
+ margin-left: 10px;
229
+ margin-right: 10px;
230
+ margin-top: 10px;
231
+ }
232
+ .orderimpexp-premium-features .button-doc-demo:hover,
233
+ .orderimpexp-premium-features .button-doc-demo:focus,
234
+ .orderimpexp-premium-features .button-doc-demo:active {
235
+ background: #dfdfe4;
236
+ }
237
+ .xa-orderimpexp-rating-link{color:#ffc600;}
238
+
239
+ .orderimpexp-review-widget{
240
+ background: #fff;
241
+ padding: 5px;
242
+ margin-top: 23px;
243
+ }
244
+ .orderimpexp-review-widget p{
245
+ margin-right:5px;
246
+ margin-left:5px;
247
+ }
248
+ .button-show-more {
249
+ text-align: center;
250
+ }
251
+ .button-show-more .button,
252
+ .button-show-more .button:hover,
253
+ .button-show-more .button:focus{
254
+ box-shadow: none;
255
+ border: 0;
256
+ height: auto;
257
+ line-height: 1;
258
+ color: #4e71a5;
259
+ text-shadow: none;
260
+ font-weight: 500;
261
+ background: transparent;
262
+ }
263
+
264
+ .button-show-more .button .dashicons {
265
+ font-size: 12px;
266
+ line-height: 1.5;
267
  }