Product Import Export for WooCommerce - Version 2.0.9

Version Description

  • WC 5.7 tested OK.
  • Product categories and tags export and import option added.
Download this release

Release Info

Developer webtoffee
Plugin Icon 128x128 Product Import Export for WooCommerce
Version 2.0.9
Comparing to
See all releases

Code changes from version 2.0.8 to 2.0.9

admin/class-wt-import-export-for-woo-admin.php CHANGED
@@ -122,8 +122,17 @@ class Wt_Import_Export_For_Woo_Admin_Basic {
122
  'sure'=>__('Are you sure?'),
123
  'use_expression'=>__('Use expression as value.'),
124
  'cancel'=>__('Cancel'),
125
- )
126
- );
 
 
 
 
 
 
 
 
 
127
  wp_localize_script($this->plugin_name, 'wt_iew_basic_params', $params);
128
  }
129
 
@@ -333,6 +342,8 @@ class Wt_Import_Export_For_Woo_Admin_Basic {
333
  'coupon'=>'order-import-export-for-woocommerce',
334
  'product'=>'product-import-export-for-woo',
335
  'product_review'=>'product-import-export-for-woo',
 
 
336
  'user'=>'users-customers-import-export-for-wp-woocommerce',
337
  );
338
  foreach ($addon_modules_basic as $module_key => $module_path)
122
  'sure'=>__('Are you sure?'),
123
  'use_expression'=>__('Use expression as value.'),
124
  'cancel'=>__('Cancel'),
125
+ ),
126
+ 'pro_plugins' => array(
127
+ 'order' => "https://www.webtoffee.com/product/order-import-export-plugin-for-woocommerce/?utm_source=free_plugin_revamp&utm_medium=basic_revamp&utm_campaign=Order_Import_Export&utm_content=".WT_P_IEW_VERSION,
128
+ 'coupon' => "https://www.webtoffee.com/product/order-import-export-plugin-for-woocommerce/?utm_source=free_plugin_revamp&utm_medium=basic_revamp&utm_campaign=Order_Import_Export&utm_content=".WT_P_IEW_VERSION,
129
+ 'product' => "https://www.webtoffee.com/product/product-import-export-woocommerce/?utm_source=free_plugin_revamp&utm_medium=basic_revamp&utm_campaign=Product_Import_Export&utm_content=".WT_P_IEW_VERSION,
130
+ 'product_review' => "https://www.webtoffee.com/product/product-import-export-woocommerce/?utm_source=free_plugin_revamp&utm_medium=basic_revamp&utm_campaign=Product_Import_Export&utm_content=".WT_P_IEW_VERSION,
131
+ 'product_categories' => "https://www.webtoffee.com/product/product-import-export-woocommerce/?utm_source=free_plugin_revamp&utm_medium=basic_revamp&utm_campaign=Product_Import_Export&utm_content=".WT_P_IEW_VERSION,
132
+ 'product_tags' => "https://www.webtoffee.com/product/product-import-export-woocommerce/?utm_source=free_plugin_revamp&utm_medium=basic_revamp&utm_campaign=Product_Import_Export&utm_content=".WT_P_IEW_VERSION,
133
+ 'user' => "https://www.webtoffee.com/product/wordpress-users-woocommerce-customers-import-export/?utm_source=free_plugin_revamp&utm_medium=basic_revamp&utm_campaign=User_Import_Export&utm_content=".WT_P_IEW_VERSION,
134
+ )
135
+ );
136
  wp_localize_script($this->plugin_name, 'wt_iew_basic_params', $params);
137
  }
138
 
342
  'coupon'=>'order-import-export-for-woocommerce',
343
  'product'=>'product-import-export-for-woo',
344
  'product_review'=>'product-import-export-for-woo',
345
+ 'product_categories'=>'product-import-export-for-woo',
346
+ 'product_tags'=>'product-import-export-for-woo',
347
  'user'=>'users-customers-import-export-for-wp-woocommerce',
348
  );
349
  foreach ($addon_modules_basic as $module_key => $module_path)
admin/modules/export/assets/js/main.js CHANGED
@@ -627,9 +627,10 @@ var wt_iew_basic_export=(function( $ ) {
627
  if(this.to_export!="" && this.to_export_title=='')
628
  {
629
  $('[name="wt_iew_export_post_type"]').val(this.to_export);
630
- this.to_export_title=$('[name="wt_iew_export_post_type"] option:selected').text();
631
  }
632
  $('.wt_iew_step_head_post_type_name').html(this.to_export_title);
 
633
  },
634
  page_actions:function(step)
635
  {
627
  if(this.to_export!="" && this.to_export_title=='')
628
  {
629
  $('[name="wt_iew_export_post_type"]').val(this.to_export);
630
+ this.to_export_title=$('[name="wt_iew_export_post_type"] option:selected').text();
631
  }
632
  $('.wt_iew_step_head_post_type_name').html(this.to_export_title);
633
+ $('.wt-ier-green-btn').attr("href", wt_iew_basic_params.pro_plugins[this.to_export]);
634
  },
635
  page_actions:function(step)
636
  {
admin/modules/import/assets/js/main.js CHANGED
@@ -779,6 +779,7 @@ var wt_iew_basic_import=(function( $ ) {
779
  this.to_import_title=$('[name="wt_iew_import_post_type"] option:selected').text();
780
  }
781
  $('.wt_iew_step_head_post_type_name').html(this.to_import_title);
 
782
  if(this.to_import_title.includes('User'))
783
  $('#user-required-field-message').show();
784
  },
779
  this.to_import_title=$('[name="wt_iew_import_post_type"] option:selected').text();
780
  }
781
  $('.wt_iew_step_head_post_type_name').html(this.to_import_title);
782
+ $('.wt-ier-green-btn').attr("href", wt_iew_basic_params.pro_plugins[this.to_import]);
783
  if(this.to_import_title.includes('User'))
784
  $('#user-required-field-message').show();
785
  },
admin/modules/product/import/import.php CHANGED
@@ -475,7 +475,7 @@ class Wt_Import_Export_For_Woo_Basic_Product_Import {
475
  if(empty($this->item_data['id'])){
476
  $this->item_data['id'] = $this->wt_parse_id_field($mapped_data);
477
  }
478
-
479
  return $this->item_data;
480
  } catch (Exception $e) {
481
  return new WP_Error('woocommerce_product_importer_error', $e->getMessage(), array('status' => $e->getCode()));
475
  if(empty($this->item_data['id'])){
476
  $this->item_data['id'] = $this->wt_parse_id_field($mapped_data);
477
  }
478
+
479
  return $this->item_data;
480
  } catch (Exception $e) {
481
  return new WP_Error('woocommerce_product_importer_error', $e->getMessage(), array('status' => $e->getCode()));
admin/modules/product/product.php CHANGED
@@ -214,7 +214,7 @@ class Wt_Import_Export_For_Woo_Basic_Product {
214
  return $this->product_categories;
215
  }
216
  $out = array();
217
- $product_categories = get_terms('product_cat');
218
  if (!is_wp_error($product_categories)) {
219
  $version = get_bloginfo('version');
220
  foreach ($product_categories as $category) {
214
  return $this->product_categories;
215
  }
216
  $out = array();
217
+ $product_categories = get_terms('product_cat', array('hide_empty' => false) );
218
  if (!is_wp_error($product_categories)) {
219
  $version = get_bloginfo('version');
220
  foreach ($product_categories as $category) {
admin/modules/product_categories/data/data-product-categories-columns.php ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ if (!defined('WPINC')) {
4
+ exit;
5
+ }
6
+
7
+ return apply_filters('taxonomies_csv_product_post_columns', array(
8
+ 'term_id' => 'term_id',
9
+ 'name' => 'name',
10
+ 'slug' => 'slug',
11
+ 'description' => 'description',
12
+ 'display_type' => 'display_type',
13
+ 'parent' => 'parent',
14
+ 'thumbnail' => 'thumbnail',
15
+ ));
admin/modules/product_categories/data/data/data-wf-reserved-fields-pair.php ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ if (!defined('WPINC')) {
4
+ exit;
5
+ }
6
+ // Reserved column names
7
+ return apply_filters('woocommerce_csv_taxonomies_import_reserved_fields_pair', array(
8
+ 'term_id' => array('title' => 'Taxonomy term ID', 'description' => 'Taxonomy term ID'),
9
+ 'name' => array('title' => 'Name', 'description' => 'Name of the taxonomy'),
10
+ 'slug' => array('title' => 'Slug', 'description' => 'Slug of the taxonomy'),
11
+ 'description' => array('title' => 'Description', 'description' => 'Description of the taxonomy'),
12
+ 'display_type' => array('title' => 'Display type', 'description' => 'Display type of the taxonomy'),
13
+ 'parent' => array('title' => 'Parent ID', 'description' => 'Parent ID'),
14
+ 'thumbnail' => array('title' => 'Thumbnail', 'description' => 'Thumbnail'),
15
+ ));
admin/modules/product_categories/export/export.php ADDED
@@ -0,0 +1,139 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ if (!defined('WPINC')) {
4
+ exit;
5
+ }
6
+
7
+ class Wt_Import_Export_For_Woo_Basic_Categories_Export {
8
+
9
+ public $parent_module = null;
10
+
11
+ public function __construct($parent_object) {
12
+
13
+ $this->parent_module = $parent_object;
14
+ }
15
+
16
+ public function prepare_header() {
17
+
18
+ $export_columns = $this->parent_module->get_selected_column_names();
19
+
20
+ return apply_filters('wt_alter_product_reviews_export_csv_columns', $export_columns);
21
+ }
22
+
23
+ /**
24
+ * Prepare data that will be exported.
25
+ */
26
+ public function prepare_data_to_export($form_data, $batch_offset) {
27
+ if (!function_exists('get_current_screen')) {
28
+ require_once(ABSPATH . 'wp-admin/includes/screen.php');
29
+ }
30
+
31
+
32
+ $sortcolumn = !empty($form_data['filter_form_data']['wt_iew_sort_columns']) ? $form_data['filter_form_data']['wt_iew_sort_columns'] : 'id';
33
+ $export_sort_order = !empty($form_data['filter_form_data']['wt_iew_order_by']) ? $form_data['filter_form_data']['wt_iew_order_by'] : 'ASC';
34
+ $taxonomy_type = 'product_cat';
35
+
36
+ $export_limit = !empty($form_data['filter_form_data']['wt_iew_limit']) ? intval($form_data['filter_form_data']['wt_iew_limit']) : 999999999; //user limit
37
+ $current_offset = !empty($form_data['filter_form_data']['wt_iew_offset']) ? intval($form_data['filter_form_data']['wt_iew_offset']) : 0; //user offset
38
+ $batch_count = !empty($form_data['advanced_form_data']['wt_iew_batch_count']) ? $form_data['advanced_form_data']['wt_iew_batch_count'] : Wt_Import_Export_For_Woo_Basic_Common_Helper::get_advanced_settings('default_export_batch');
39
+
40
+
41
+ $real_offset = ($current_offset + $batch_offset);
42
+
43
+ if($batch_count<=$export_limit)
44
+ {
45
+ if(($batch_offset+$batch_count)>$export_limit) //last offset
46
+ {
47
+ $limit=$export_limit-$batch_offset;
48
+ }else
49
+ {
50
+ $limit=$batch_count;
51
+ }
52
+ }else
53
+ {
54
+ $limit=$export_limit;
55
+ }
56
+
57
+ $data_array = array();
58
+ if ($batch_offset < $export_limit)
59
+ {
60
+
61
+ $args = array('taxonomy' => $taxonomy_type, 'orderby' => $sortcolumn, 'order'=> $export_sort_order, 'hide_empty' => 0, 'offset' => $real_offset, 'number' => $limit);
62
+
63
+ $terms = get_terms( $args );
64
+
65
+ foreach ($terms as $term) {
66
+ $data_array[] = $this->hf_import_to_csv($term, $terms, $taxonomy_type);
67
+
68
+
69
+ }
70
+ /**
71
+ * taking total records
72
+ */
73
+ $total_records=0;
74
+ if($batch_offset==0) //first batch
75
+ {
76
+ $total_item_args=$args;
77
+ $total_item_args['number']=$export_limit; //user given limit
78
+ $total_item_args['offset']=$current_offset; //user given offset
79
+ $total_terms = wp_count_terms( $taxonomy_type );
80
+ $total_records = $total_terms;
81
+ }
82
+
83
+ $return['total'] = $total_records;
84
+ $return['data'] = $data_array;
85
+ return $return;
86
+ }
87
+
88
+ }
89
+
90
+ public function hf_import_to_csv($term, $terms, $taxonomy_type) {
91
+ $row = array();
92
+
93
+ $csv_columns = $this->parent_module->get_selected_column_names();
94
+
95
+ foreach ($csv_columns as $column => $value) {
96
+
97
+ if ($column === 'term_id') {
98
+ $row[$column] = $term->term_id;
99
+ continue;
100
+ }
101
+ if ($column === 'name') {
102
+ $row[$column] = $term->name;
103
+ continue;
104
+ }
105
+ if ($column === 'slug') {
106
+ $row[$column] = rawurldecode($term->slug);
107
+ continue;
108
+ }
109
+ if ($column === 'description') {
110
+ $row[$column] = $term->description;
111
+ continue;
112
+ }
113
+ if ($column === 'display_type') {
114
+ $display_type = get_term_meta( $term->term_id, 'display_type', true );
115
+ $row[$column] = $display_type ? $display_type : 'default';
116
+ continue;
117
+ }
118
+ if ($column === 'parent') {
119
+ $row[$column] = $term->parent;
120
+ continue;
121
+ }
122
+
123
+ if ($column === 'thumbnail') {
124
+ $thumbnail_id = get_term_meta($term->term_id, 'thumbnail_id', true);
125
+ $thumbnail = wp_get_attachment_url($thumbnail_id);
126
+ if (filter_var($thumbnail, FILTER_VALIDATE_URL) === FALSE) {
127
+ $thumbnail = '';
128
+ }
129
+ $row[$column] = $thumbnail;
130
+ continue;
131
+ }
132
+ }
133
+
134
+ $row = apply_filters('wt_alter_product_categories_export_csv_data', $row, $term->term_id, $csv_columns);
135
+ return $row;
136
+
137
+ }
138
+
139
+ }
admin/modules/product_categories/import/import.php ADDED
@@ -0,0 +1,309 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ if (!defined('WPINC')) {
4
+ exit;
5
+ }
6
+
7
+ class Wt_Import_Export_For_Woo_Basic_Categories_Import {
8
+
9
+ public $parent_module = null;
10
+ public $parsed_data = array();
11
+ var $is_update;
12
+ var $taxonomy_type;
13
+ var $import_results = array();
14
+ var $row;
15
+
16
+ public function __construct($parent_object) {
17
+
18
+ $this->parent_module = $parent_object;
19
+
20
+ $this->taxonomy_post_defaults = apply_filters('wt_categories_csv_product_post_columns', array(
21
+ 'term_id' => 'term_id',
22
+ 'name' => 'name',
23
+ 'slug' => 'slug',
24
+ 'description' => 'description',
25
+ 'parent' => 'parent',
26
+ 'thumbnail' => 'thumbnail',
27
+ ));
28
+ }
29
+
30
+ public function hf_log_data_change($content = 'categories-csv-import', $data = '') {
31
+
32
+ Wt_Import_Export_For_Woo_Basic_Logwriter::write_log($this->parent_module->module_base, 'import', $data);
33
+ }
34
+
35
+ public function prepare_data_to_import($import_data, $form_data, $batch_offset, $is_last_batch) {
36
+
37
+ $this->is_update = isset($form_data['advanced_form_data']['wt_iew_merge']) ? $form_data['advanced_form_data']['wt_iew_merge'] : 0;
38
+ $this->taxonomy_type = 'product_cat';
39
+
40
+ Wt_Import_Export_For_Woo_Basic_Logwriter::write_log($this->parent_module->module_base, 'import', "Preparing for import.");
41
+
42
+ $success = 0;
43
+ $failed = 0;
44
+ $msg = 'Category imported successfully.';
45
+ foreach ($import_data as $key => $data) {
46
+ $row = $batch_offset + $key + 1;
47
+ Wt_Import_Export_For_Woo_Basic_Logwriter::write_log($this->parent_module->module_base, 'import', "Row :$row - Parsing item.");
48
+ $parsed_data = $this->parse_product_categories($data, $this->is_update, $this->taxonomy_type);
49
+ if (!is_wp_error($parsed_data)) {
50
+ Wt_Import_Export_For_Woo_Basic_Logwriter::write_log($this->parent_module->module_base, 'import', "Row :$row - Processing item.");
51
+ $result = $this->process_product_categories($parsed_data, $this->is_update, $this->taxonomy_type);
52
+
53
+ if (!is_wp_error($result)) {
54
+ if (isset($result['status']) && $result['status'] == 'updated') {
55
+ $msg = 'Category updated successfully.';
56
+ }
57
+
58
+ $this->import_results[$row] = array('row' => $row, 'message' => $msg, 'status' => true, 'post_id' => $result['id']);
59
+ Wt_Import_Export_For_Woo_Basic_Logwriter::write_log($this->parent_module->module_base, 'import', "Row :$row - " . $msg);
60
+ $success++;
61
+ } else {
62
+ $this->import_results[$row] = array('row' => $row, 'message' => $result->get_error_message(), 'status' => false, 'post_id' => '');
63
+ Wt_Import_Export_For_Woo_Basic_Logwriter::write_log($this->parent_module->module_base, 'import', "Row :$row - Prosessing failed. Reason: " . $result->get_error_message());
64
+ $failed++;
65
+ }
66
+ } else {
67
+ $this->import_results[$row] = array('row' => $row, 'message' => $parsed_data->get_error_message(), 'status' => false, 'post_id' => '');
68
+ Wt_Import_Export_For_Woo_Basic_Logwriter::write_log($this->parent_module->module_base, 'import', "Row :$row - Parsing failed. Reason: " . $parsed_data->get_error_message());
69
+ $failed++;
70
+ }
71
+ unset($data, $parsed_data);
72
+ }
73
+
74
+ $this->clean_after_import();
75
+
76
+ $import_response = array(
77
+ 'total_success' => $success,
78
+ 'total_failed' => $failed,
79
+ 'log_data' => $this->import_results,
80
+ );
81
+
82
+ return $import_response;
83
+ }
84
+
85
+ /**
86
+ * Parse product review
87
+ * @param array $item
88
+ * @return array
89
+ */
90
+ public function parse_product_categories($data, $is_update, $taxonomy_type) {
91
+ try {
92
+ $data = apply_filters('wt_woocommerce_product_categories_importer_pre_parse_data', $data);
93
+
94
+ $item = $data['mapping_fields'];
95
+
96
+ return $item;
97
+ } catch (Exception $e) {
98
+ return new WP_Error('woocommerce_product_importer_error', $e->getMessage(), array('status' => $e->getCode()));
99
+ }
100
+ }
101
+
102
+ /**
103
+ * Create new taxonomy based on import information
104
+ */
105
+ public function process_product_categories($post, $is_update, $taxonomy_type) {
106
+ try {
107
+
108
+ $term_data = $this->process_taxonomy_by_type($post, $is_update, $taxonomy_type);
109
+
110
+ return $term_data;
111
+ } catch (Exception $e) {
112
+ return new WP_Error('woocommerce_product_importer_error', $e->getMessage(), array('status' => $e->getCode()));
113
+ }
114
+ }
115
+
116
+ public function process_taxonomy_by_type($data, $is_update = 0, $taxonomy_type = 'product_cat') {
117
+
118
+ $parent_id = '';
119
+ $name = isset($data['name']) ? $data['name'] : '';
120
+ $slug = isset($data['slug']) ? $data['slug'] : '';
121
+ $term_id = isset($data['term_id']) ? $data['term_id'] : '';
122
+ $description = isset($data['description']) ? $data['description'] : '';
123
+ $display_type = isset($data['display_type']) ? $data['display_type'] : '';
124
+
125
+ $parent_id = (isset($data['parent']) && ($data['parent'] != 0 )) ? $data['parent'] : '';
126
+
127
+ global $wpdb;
128
+
129
+ switch ($taxonomy_type) {
130
+
131
+ case 'product_cat':
132
+ $tax_type = 'product_cat';
133
+ $term_meta_tbl_key = 'orginal_term_id';
134
+ break;
135
+ case 'product_tag':
136
+ $tax_type = 'product_tag';
137
+ $term_meta_tbl_key = 'orginal_product_tag_term_id';
138
+ break;
139
+ }
140
+ $pid = '';
141
+ if ($parent_id) {
142
+ $pid = $parent_id;
143
+ }
144
+ $term_name = $name;
145
+ $taxonomy_name = $tax_type;
146
+ $related_data = array(
147
+ 'name' => $name,
148
+ 'description' => $description,
149
+ 'slug' => $slug);
150
+ if ($pid) {
151
+ $related_data['parent'] = $pid;
152
+ }
153
+ $chk = $wpdb->get_row($wpdb->prepare("SELECT t.term_id, t.name, t.slug FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy as tt ON tt.term_id = t.term_id WHERE t.name = %s and t.slug = %s and tt.taxonomy = %s ORDER BY t.term_id", $name, $slug, $tax_type), ARRAY_A);
154
+
155
+ $tid = '';
156
+ $status = '';
157
+ if (isset($chk['term_id']))
158
+ $tid = $chk['term_id'];
159
+
160
+ if ($taxonomy_type == 'product_tag' || $taxonomy_type == 'product_cat') {
161
+
162
+ if ($tid == '') {
163
+
164
+ if (!empty($data['slug'])) {
165
+
166
+ if ($taxonomy_type == 'product_tag' || $taxonomy_type == 'product_cat') {
167
+
168
+ $res = $wpdb->get_results($wpdb->prepare("SELECT term_id FROM $wpdb->termmeta WHERE meta_key = %s and meta_value = %d ORDER BY meta_key,meta_id", $term_meta_tbl_key, $parent_id), ARRAY_A);
169
+
170
+ $term_id = $term_id;
171
+
172
+ if (!empty($res)) {
173
+ $pid = $res[0]['term_id'];
174
+ }
175
+ $related_data['parent'] = $pid;
176
+ }
177
+
178
+ if (!empty($parent_id) && empty($res)) {
179
+
180
+ $status = array(
181
+ 'name' => $name,
182
+ 'status' => 'Data skipped parent not found',
183
+ );
184
+ return new WP_Error('data-error', '> Data skipped parent not found');
185
+ } else {
186
+
187
+ $cid = wp_insert_term($term_name, $taxonomy_name, $related_data);
188
+ if (is_wp_error($cid)) {
189
+ return new WP_Error('data-error', $cid->get_error_message());
190
+ }
191
+
192
+ $cid = $cid['term_id'];
193
+ if(!empty($term_id))
194
+ update_term_meta($cid, $term_meta_tbl_key, $term_id);
195
+
196
+ if ($taxonomy_type == 'product_cat') {
197
+
198
+ $thumbnail = isset($data['thumbnail']) ? $data['thumbnail'] : '';
199
+ if ($thumbnail != "") {
200
+
201
+ $image_url = $data['thumbnail'];
202
+ $attach_id = $this->image_library_attachment($image_url);
203
+ update_term_meta($cid, 'thumbnail_id', absint($attach_id));
204
+ }
205
+ }
206
+ if(!empty($display_type)){
207
+ update_term_meta($cid, 'display_type', $display_type);
208
+ }
209
+ $status = array(
210
+ 'id' => $cid,
211
+ 'name' => $name,
212
+ 'status' => 'imported',
213
+ );
214
+ unset($cid);
215
+ }
216
+ }
217
+ } else {
218
+
219
+ if ($is_update) {
220
+ $update = wp_update_term($tid, $taxonomy_name, $related_data);
221
+ if ($taxonomy_type == 'product_cat') {
222
+ $thumbnail = isset($data['thumbnail']) ? $data['thumbnail'] : '';
223
+ if ($thumbnail != "") {
224
+
225
+ $thumbnail_id = get_term_meta($tid, 'thumbnail_id', true);
226
+ $thumbnail_url = wp_get_attachment_url($thumbnail_id);
227
+ $existing_filename = basename($thumbnail_url);
228
+
229
+ $image_url = $thumbnail;
230
+ $current_filename = basename($image_url);
231
+ if ($current_filename != $existing_filename) {
232
+
233
+ $attach_id = $this->image_library_attachment($image_url);
234
+
235
+ update_term_meta($tid, 'thumbnail_id', absint($attach_id));
236
+ }
237
+ }
238
+ }
239
+
240
+ if (!empty($display_type)) {
241
+ update_term_meta($tid, 'display_type', $display_type);
242
+ }
243
+ $status = array(
244
+ 'id' => $tid,
245
+ 'name' => $name,
246
+ 'status' => 'updated',
247
+ );
248
+ } else {
249
+ return new WP_Error('data-exist', '> Category skipped - already exist');
250
+ }
251
+ if($term_id)
252
+ update_term_meta($tid, $term_meta_tbl_key, $term_id);
253
+ }
254
+ }
255
+
256
+ unset($chk);
257
+ return $status;
258
+ }
259
+
260
+ /**
261
+ * Method used for attach image file to wp library
262
+ *
263
+ * $image_url is url
264
+ * return attachment id
265
+ */
266
+ public function image_library_attachment($image_url) {
267
+
268
+ $upload_dir = wp_upload_dir();
269
+
270
+ $image_data = file_get_contents($image_url);
271
+
272
+ $filename = basename($image_url);
273
+
274
+ if (wp_mkdir_p($upload_dir['path'])) {
275
+ $file = $upload_dir['path'] . '/' . $filename;
276
+ } else {
277
+ $file = $upload_dir['basedir'] . '/' . $filename;
278
+ }
279
+
280
+ file_put_contents($file, $image_data);
281
+
282
+ $wp_filetype = wp_check_filetype($filename, null);
283
+
284
+ $attachment = array(
285
+ 'post_mime_type' => $wp_filetype['type'],
286
+ 'post_title' => sanitize_file_name($filename),
287
+ 'post_content' => '',
288
+ 'post_status' => 'inherit'
289
+ );
290
+
291
+ $attach_id = wp_insert_attachment($attachment, $file);
292
+ require_once( ABSPATH . 'wp-admin/includes/image.php' );
293
+ $attach_data = wp_generate_attachment_metadata($attach_id, $file);
294
+ wp_update_attachment_metadata($attach_id, $attach_data);
295
+
296
+ return $attach_id;
297
+ }
298
+
299
+ public function clean_after_import() {
300
+ wp_suspend_cache_invalidation(false);
301
+ wp_defer_term_counting(false);
302
+ wp_defer_comment_counting(false);
303
+ global $wpdb;
304
+ if (class_exists('WC_Product_Reviews_Pro')) {
305
+ $wpdb->query("DELETE FROM `$wpdb->options` WHERE `option_name` LIKE ('%_transient_wc_product_reviews_pro_review_count_%')");
306
+ }
307
+ }
308
+
309
+ }
admin/modules/product_categories/product_categories.php ADDED
@@ -0,0 +1,464 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Product categories section of the plugin
4
+ *
5
+ * @link
6
+ *
7
+ * @package Wt_Import_Export_For_Woo
8
+ */
9
+ if (!defined('ABSPATH')) {
10
+ exit;
11
+ }
12
+
13
+ if(!class_exists('Wt_Import_Export_For_Woo_Basic_Product_Categories')){
14
+ class Wt_Import_Export_For_Woo_Basic_Product_Categories {
15
+
16
+ public $module_id = '';
17
+ public static $module_id_static = '';
18
+ public $module_base = 'product_categories';
19
+ public $module_name = 'Categories Import Export for WooCommerce';
20
+ public $min_base_version= '1.0.0'; /* Minimum `Import export plugin` required to run this add on plugin */
21
+
22
+ private $all_meta_keys = array();
23
+ private $found_product_meta = array();
24
+ private $selected_column_names = null;
25
+
26
+ public function __construct()
27
+ {
28
+ /**
29
+ * Checking the minimum required version of `Import export plugin` plugin available
30
+ */
31
+ if(!Wt_Import_Export_For_Woo_Basic_Common_Helper::check_base_version($this->module_base, $this->module_name, $this->min_base_version))
32
+ {
33
+ return;
34
+ }
35
+ if(!function_exists('is_plugin_active'))
36
+ {
37
+ include_once(ABSPATH.'wp-admin/includes/plugin.php');
38
+ }
39
+ if(!is_plugin_active('woocommerce/woocommerce.php'))
40
+ {
41
+ return;
42
+ }
43
+
44
+ $this->module_id = Wt_Import_Export_For_Woo_basic::get_module_id($this->module_base);
45
+
46
+ self::$module_id_static = $this->module_id;
47
+
48
+ add_filter('wt_iew_exporter_post_types_basic', array($this, 'wt_iew_exporter_post_types'), 10, 1);
49
+ add_filter('wt_iew_importer_post_types_basic', array($this, 'wt_iew_exporter_post_types'), 10, 1);
50
+
51
+ add_filter('wt_iew_exporter_alter_filter_fields_basic', array($this, 'exporter_alter_filter_fields'), 10, 3);
52
+
53
+ add_filter('wt_iew_exporter_alter_mapping_fields_basic', array($this, 'exporter_alter_mapping_fields'), 10, 3);
54
+ add_filter('wt_iew_importer_alter_mapping_fields_basic', array($this, 'get_importer_post_columns'), 10, 3);
55
+
56
+ add_filter('wt_iew_exporter_alter_advanced_fields_basic', array($this, 'exporter_alter_advanced_fields'), 10, 3);
57
+ add_filter('wt_iew_importer_alter_advanced_fields_basic', array($this, 'importer_alter_advanced_fields'), 10, 3);
58
+
59
+ add_filter('wt_iew_exporter_alter_meta_mapping_fields_basic', array($this, 'exporter_alter_meta_mapping_fields'), 10, 3);
60
+ add_filter('wt_iew_importer_alter_meta_mapping_fields_basic', array($this, 'importer_alter_meta_mapping_fields'), 10, 3);
61
+
62
+ add_filter('wt_iew_exporter_alter_mapping_enabled_fields_basic', array($this, 'exporter_alter_mapping_enabled_fields'), 10, 3);
63
+ add_filter('wt_iew_importer_alter_mapping_enabled_fields_basic', array($this, 'exporter_alter_mapping_enabled_fields'), 10, 3);
64
+
65
+ add_filter('wt_iew_exporter_do_export_basic', array($this, 'exporter_do_export'), 10, 7);
66
+ add_filter('wt_iew_importer_do_import_basic', array($this, 'importer_do_import'), 10, 8);
67
+
68
+ add_filter('wt_iew_importer_steps_basic', array($this, 'importer_steps'), 10, 2);
69
+ }
70
+
71
+
72
+ /**
73
+ * Altering advanced step description
74
+ */
75
+ public function importer_steps($steps, $base)
76
+ {
77
+ if($this->module_base==$base)
78
+ {
79
+ $steps['advanced']['description']=__('Use advanced options from below to decide updates to existing reviews, batch import count or schedule an import. You can also save the template file for future imports.');
80
+ }
81
+ return $steps;
82
+ }
83
+
84
+ public function importer_do_import($import_data, $base, $step, $form_data, $selected_template_data, $method_import, $batch_offset, $is_last_batch) {
85
+ if ($this->module_base != $base) {
86
+ return $import_data;
87
+ }
88
+
89
+ if(0 == $batch_offset){
90
+ $memory = size_format(self::wt_let_to_num(ini_get('memory_limit')));
91
+ $wp_memory = size_format(self::wt_let_to_num(WP_MEMORY_LIMIT));
92
+ Wt_Import_Export_For_Woo_Basic_Logwriter::write_log($this->module_base, 'import', '---[ New import started at '.date('Y-m-d H:i:s').' ] PHP Memory: ' . $memory . ', WP Memory: ' . $wp_memory);
93
+ }
94
+
95
+ include plugin_dir_path(__FILE__) . 'import/import.php';
96
+ $import = new Wt_Import_Export_For_Woo_Basic_Categories_Import($this);
97
+
98
+ $response = $import->prepare_data_to_import($import_data,$form_data,$batch_offset,$is_last_batch);
99
+
100
+ if($is_last_batch){
101
+ Wt_Import_Export_For_Woo_Basic_Logwriter::write_log($this->module_base, 'import', '---[ Import ended at '.date('Y-m-d H:i:s').']---');
102
+ }
103
+
104
+ return $response;
105
+ }
106
+
107
+ public static function wt_let_to_num( $size ) {
108
+ $l = substr( $size, -1 );
109
+ $ret = (int) substr( $size, 0, -1 );
110
+ switch ( strtoupper( $l ) ) {
111
+ case 'P':
112
+ $ret *= 1024;
113
+ // No break.
114
+ case 'T':
115
+ $ret *= 1024;
116
+ // No break.
117
+ case 'G':
118
+ $ret *= 1024;
119
+ // No break.
120
+ case 'M':
121
+ $ret *= 1024;
122
+ // No break.
123
+ case 'K':
124
+ $ret *= 1024;
125
+ // No break.
126
+ }
127
+ return $ret;
128
+ }
129
+
130
+ public function exporter_do_export($export_data, $base, $step, $form_data, $selected_template_data, $method_export, $batch_offset) {
131
+ if ($this->module_base != $base) {
132
+ return $export_data;
133
+ }
134
+
135
+
136
+ switch ($method_export) {
137
+ case 'quick':
138
+ $this->set_export_columns_for_quick_export($form_data);
139
+ break;
140
+
141
+ case 'template':
142
+ case 'new':
143
+ $this->set_selected_column_names($form_data);
144
+ break;
145
+
146
+ default:
147
+ break;
148
+ }
149
+
150
+ include plugin_dir_path(__FILE__) . 'export/export.php';
151
+ $export = new Wt_Import_Export_For_Woo_Basic_Categories_Export($this);
152
+
153
+ $header_row = $export->prepare_header();
154
+
155
+ $data_row = $export->prepare_data_to_export($form_data, $batch_offset);
156
+
157
+ $export_data = array(
158
+ 'head_data' => $header_row,
159
+ 'body_data' => $data_row['data'],
160
+ );
161
+
162
+ if(isset($data_row['total']) && !empty($data_row['total'])){
163
+ $export_data['total'] = $data_row['total'];
164
+ }
165
+
166
+ return $export_data;
167
+ }
168
+
169
+ /**
170
+ * Adding current post type to export list
171
+ *
172
+ */
173
+ public function wt_iew_exporter_post_types($arr) {
174
+ $arr['product_categories'] = __('Product Categories');
175
+ return $arr;
176
+ }
177
+
178
+
179
+
180
+ /*
181
+ * Setting default export columns for quick export
182
+ */
183
+
184
+ public function set_export_columns_for_quick_export($form_data) {
185
+
186
+ $post_columns = self::get_categories_post_columns();
187
+
188
+ $this->selected_column_names = array_combine(array_keys($post_columns), array_keys($post_columns));
189
+
190
+ if (isset($form_data['method_export_form_data']['mapping_enabled_fields']) && !empty($form_data['method_export_form_data']['mapping_enabled_fields'])) {
191
+ foreach ($form_data['method_export_form_data']['mapping_enabled_fields'] as $value) {
192
+ $additional_quick_export_fields[$value] = array('fields' => array());
193
+ }
194
+
195
+ $export_additional_columns = $this->exporter_alter_meta_mapping_fields($additional_quick_export_fields, $this->module_base, array());
196
+ foreach ($export_additional_columns as $value) {
197
+ $this->selected_column_names = array_merge($this->selected_column_names, $value['fields']);
198
+ }
199
+ }
200
+ }
201
+
202
+
203
+ public static function get_categories_sort_columns() {
204
+ $sort_columns = array(
205
+ 'id' => __('Category ID'),
206
+ 'name' => __('Category name'),
207
+ 'slug' => __('Category slug'),
208
+ );
209
+ return apply_filters('wt_iew_allowed_categories_sort_columns', $sort_columns);
210
+ }
211
+
212
+ public static function get_categories_post_columns() {
213
+
214
+ return include plugin_dir_path(__FILE__) . 'data/data-product-categories-columns.php';
215
+ }
216
+
217
+ public function get_importer_post_columns($fields, $base, $step_page_form_data) {
218
+
219
+ if ($base != $this->module_base) {
220
+ return $fields;
221
+ }
222
+ $colunm = include plugin_dir_path(__FILE__) . 'data/data/data-wf-reserved-fields-pair.php';
223
+ // $colunm = array_map(function($vl){ return array('title'=>$vl, 'description'=>$vl); }, $arr);
224
+ return $colunm;
225
+ }
226
+
227
+
228
+ public function exporter_alter_mapping_enabled_fields($mapping_enabled_fields, $base, $form_data_mapping_enabled_fields) {
229
+ if ($base == $this->module_base) {
230
+
231
+ }
232
+
233
+ return $mapping_enabled_fields;
234
+ }
235
+
236
+
237
+ public function exporter_alter_meta_mapping_fields($fields, $base, $step_page_form_data) {
238
+ if ($base != $this->module_base) {
239
+ return $fields;
240
+ }
241
+
242
+
243
+ return $fields;
244
+ }
245
+
246
+
247
+ public function wt_get_product_categories() {
248
+
249
+ if (!empty($this->product_taxonomies)) {
250
+ return $this->product_taxonomies;
251
+ }
252
+ $product_ptaxonomies = get_object_taxonomies('product', 'name');
253
+ $product_vtaxonomies = get_object_taxonomies('product_variation', 'name');
254
+ $product_taxonomies = array_merge($product_ptaxonomies, $product_vtaxonomies);
255
+
256
+ $this->product_taxonomies = $product_taxonomies;
257
+ return $this->product_taxonomies;
258
+ }
259
+
260
+
261
+ public function importer_alter_meta_mapping_fields($fields, $base, $step_page_form_data) {
262
+ if ($base != $this->module_base) {
263
+ return $fields;
264
+ }
265
+ $fields=$this->exporter_alter_meta_mapping_fields($fields, $base, $step_page_form_data);
266
+ $out=array();
267
+ foreach ($fields as $key => $value)
268
+ {
269
+ $value['fields']=array_map(function($vl){ return array('title'=>$vl, 'description'=>$vl); }, $value['fields']);
270
+ $out[$key]=$value;
271
+ }
272
+ return $out;
273
+ }
274
+
275
+ public function wt_get_found_product_meta() {
276
+
277
+ if (!empty($this->found_product_meta)) {
278
+ return $this->found_product_meta;
279
+ }
280
+
281
+ // Loop products and load meta data
282
+ $found_product_meta = array();
283
+ // Some of the values may not be usable (e.g. arrays of arrays) but the worse
284
+ // that can happen is we get an empty column.
285
+
286
+ $all_meta_keys = $this->wt_get_all_meta_keys();
287
+
288
+ $csv_columns = self::get_taxonomies_post_columns();
289
+
290
+ foreach ($all_meta_keys as $meta) {
291
+
292
+ if (!$meta || (substr((string) $meta, 0, 1) == '_') || in_array($meta, array_keys($csv_columns)) || in_array('meta:' . $meta, array_keys($csv_columns)))
293
+ continue;
294
+
295
+ $found_product_meta[] = $meta;
296
+ }
297
+
298
+ $found_product_meta = array_diff($found_product_meta, array_keys($csv_columns));
299
+
300
+ $this->found_product_meta = $found_product_meta;
301
+ return $this->found_product_meta;
302
+ }
303
+
304
+
305
+
306
+ public function wt_get_all_meta_keys() {
307
+
308
+ if (!empty($this->all_meta_keys)) {
309
+ return $this->all_meta_keys;
310
+ }
311
+
312
+ $all_meta_pkeys = self::get_all_metakeys();
313
+
314
+ $this->all_meta_keys = $all_meta_pkeys;
315
+
316
+ return $this->all_meta_keys;
317
+ }
318
+
319
+ /**
320
+ * Get a list of all the meta keys for a post type. This includes all public, private,
321
+ * used, no-longer used etc. They will be sorted once fetched.
322
+ */
323
+ public static function get_all_metakeys() {
324
+ global $wpdb;
325
+
326
+ $meta = $wpdb->get_col(
327
+ "SELECT DISTINCT cm.meta_key
328
+ FROM {$wpdb->commentmeta} AS cm
329
+ LEFT JOIN {$wpdb->comments} AS c ON c.comment_ID = cm.comment_id
330
+ WHERE c.comment_type = 'review'"
331
+ );
332
+ sort($meta);
333
+ return $meta;
334
+ }
335
+
336
+ public function set_selected_column_names($full_form_data) {
337
+
338
+ if (is_null($this->selected_column_names)) {
339
+
340
+ if (isset($full_form_data['mapping_form_data']['mapping_selected_fields']) && !empty($full_form_data['mapping_form_data']['mapping_selected_fields'])) {
341
+ $this->selected_column_names = $full_form_data['mapping_form_data']['mapping_selected_fields'];
342
+ }
343
+ if (isset($full_form_data['meta_step_form_data']['mapping_selected_fields']) && !empty($full_form_data['meta_step_form_data']['mapping_selected_fields'])) {
344
+ $export_additional_columns = $full_form_data['meta_step_form_data']['mapping_selected_fields'];
345
+ foreach ($export_additional_columns as $value) {
346
+ $this->selected_column_names = array_merge($this->selected_column_names, $value);
347
+ }
348
+ }
349
+ }
350
+
351
+ return $full_form_data;
352
+ }
353
+
354
+ public function get_selected_column_names() {
355
+ return $this->selected_column_names;
356
+ }
357
+
358
+ public function exporter_alter_mapping_fields($fields, $base, $mapping_form_data) {
359
+ if ($base != $this->module_base) {
360
+ return $fields;
361
+ }
362
+
363
+ $fields = self::get_categories_post_columns();
364
+
365
+ return $fields;
366
+ }
367
+
368
+
369
+ /**
370
+ * Customize the items in filter export page
371
+ */
372
+ public function exporter_alter_filter_fields($fields, $base, $filter_form_data) {
373
+ if ($this->module_base != $base) {
374
+ return $fields;
375
+ }
376
+
377
+ $fields = array();
378
+
379
+ $sort_columns = self::get_categories_sort_columns();
380
+ $fields['sort_columns'] = array(
381
+ 'label' => __('Sort Columns'),
382
+ 'placeholder' => __('comment_ID'),
383
+ 'field_name' => 'sort_columns',
384
+ 'sele_vals' => $sort_columns,
385
+ 'help_text' => __('Sort the exported data based on the selected column in the order specified. Defaulted to ascending order.'),
386
+ 'type' => 'select',
387
+ );
388
+
389
+ $fields['order_by'] = array(
390
+ 'label' => __('Sort'),
391
+ 'placeholder' => __('ASC'),
392
+ 'field_name' => 'order_by',
393
+ 'sele_vals' => array('ASC' => 'Ascending', 'DESC' => 'Descending'),
394
+ 'help_text' => __('Defaulted to Ascending. Applicable to above selected columns in the order specified.'),
395
+ 'type' => 'select',
396
+ 'css_class' => '',
397
+ );
398
+
399
+ return $fields;
400
+ }
401
+
402
+
403
+ public function exporter_alter_advanced_fields($fields, $base, $advanced_form_data) {
404
+ if ($this->module_base != $base) {
405
+ return $fields;
406
+ }
407
+ unset($fields['export_shortcode_tohtml']);
408
+
409
+ return $fields;
410
+ }
411
+
412
+ public function importer_alter_advanced_fields($fields, $base, $advanced_form_data) {
413
+ if ($this->module_base != $base) {
414
+ return $fields;
415
+ }
416
+ $out = array();
417
+
418
+
419
+
420
+ $out['merge'] = array(
421
+ 'label' => __("If the category exists in the store"),
422
+ 'type' => 'radio',
423
+ 'radio_fields' => array(
424
+ '0' => __('Skip'),
425
+ '1' => __('Update')
426
+ ),
427
+ 'value' => '0',
428
+ 'field_name' => 'merge',
429
+ 'help_text' => __('Categories are matched by their ID/slugs.'),
430
+ 'help_text_conditional'=>array(
431
+ array(
432
+ 'help_text'=> __('Retains the categories in the store as is and skips the matching category from the input file.'),
433
+ 'condition'=>array(
434
+ array('field'=>'wt_iew_merge', 'value'=>0)
435
+ )
436
+ ),
437
+ array(
438
+ 'help_text'=> __('Update category as per data from the input file'),
439
+ 'condition'=>array(
440
+ array('field'=>'wt_iew_merge', 'value'=>1)
441
+ )
442
+ )
443
+ ),
444
+ 'form_toggler'=>array(
445
+ 'type'=>'parent',
446
+ 'target'=>'wt_iew_found_action'
447
+ )
448
+ );
449
+
450
+
451
+ foreach ($fields as $fieldk => $fieldv) {
452
+ $out[$fieldk] = $fieldv;
453
+ }
454
+ return $out;
455
+ }
456
+
457
+ public function get_item_by_id($id) {
458
+ $post['edit_url']= get_edit_term_link($id);
459
+ $post['title'] = @get_term($id)->name;
460
+ return $post;
461
+ }
462
+ }
463
+ }
464
+ new Wt_Import_Export_For_Woo_Basic_Product_Categories();
admin/modules/product_tags/data/data-product-review-columns.php ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ if (!defined('WPINC')) {
4
+ exit;
5
+ }
6
+
7
+ return apply_filters('wt_tags_csv_product_post_columns', array(
8
+ 'term_id' => 'term_id',
9
+ 'name' => 'name',
10
+ 'slug' => 'slug',
11
+ 'description' => 'description',
12
+ ));
admin/modules/product_tags/data/data/data-wf-reserved-fields-pair.php ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ if (!defined('WPINC')) {
4
+ exit;
5
+ }
6
+ // Reserved column names
7
+ return apply_filters('woocommerce_csv_tags_import_reserved_fields_pair', array(
8
+ 'term_id' => array('title' => 'Tag term ID', 'description' => 'Tag term ID'),
9
+ 'name' => array('title' => 'Name', 'description' => 'Name of the tag'),
10
+ 'slug' => array('title' => 'Slug', 'description' => 'Slug of the tag'),
11
+ 'description' => array('title' => 'Description', 'description' => 'Description of the tag'),
12
+ ));
admin/modules/product_tags/export/export.php ADDED
@@ -0,0 +1,120 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ if (!defined('WPINC')) {
4
+ exit;
5
+ }
6
+
7
+ class Wt_Import_Export_For_Woo_Basic_Tags_Export {
8
+
9
+ public $parent_module = null;
10
+
11
+ public function __construct($parent_object) {
12
+
13
+ $this->parent_module = $parent_object;
14
+ }
15
+
16
+ public function prepare_header() {
17
+
18
+ $export_columns = $this->parent_module->get_selected_column_names();
19
+
20
+ return apply_filters('wt_alter_product_reviews_export_csv_columns', $export_columns);
21
+ }
22
+
23
+ /**
24
+ * Prepare data that will be exported.
25
+ */
26
+ public function prepare_data_to_export($form_data, $batch_offset) {
27
+ if (!function_exists('get_current_screen')) {
28
+ require_once(ABSPATH . 'wp-admin/includes/screen.php');
29
+ }
30
+
31
+
32
+ $sortcolumn = !empty($form_data['filter_form_data']['wt_iew_sort_columns']) ? $form_data['filter_form_data']['wt_iew_sort_columns'] : 'id';
33
+ $export_sort_order = !empty($form_data['filter_form_data']['wt_iew_order_by']) ? $form_data['filter_form_data']['wt_iew_order_by'] : 'ASC';
34
+ $taxonomy_type = 'product_tag';
35
+
36
+ $export_limit = !empty($form_data['filter_form_data']['wt_iew_limit']) ? intval($form_data['filter_form_data']['wt_iew_limit']) : 999999999; //user limit
37
+ $current_offset = !empty($form_data['filter_form_data']['wt_iew_offset']) ? intval($form_data['filter_form_data']['wt_iew_offset']) : 0; //user offset
38
+ $batch_count = !empty($form_data['advanced_form_data']['wt_iew_batch_count']) ? $form_data['advanced_form_data']['wt_iew_batch_count'] : Wt_Import_Export_For_Woo_Basic_Common_Helper::get_advanced_settings('default_export_batch');
39
+
40
+
41
+ $real_offset = ($current_offset + $batch_offset);
42
+
43
+ if($batch_count<=$export_limit)
44
+ {
45
+ if(($batch_offset+$batch_count)>$export_limit) //last offset
46
+ {
47
+ $limit=$export_limit-$batch_offset;
48
+ }else
49
+ {
50
+ $limit=$batch_count;
51
+ }
52
+ }else
53
+ {
54
+ $limit=$export_limit;
55
+ }
56
+
57
+ $data_array = array();
58
+ if ($batch_offset < $export_limit)
59
+ {
60
+
61
+ $args = array('taxonomy' => $taxonomy_type, 'orderby' => $sortcolumn, 'order'=> $export_sort_order, 'hide_empty' => 0, 'offset' => $real_offset, 'number' => $limit);
62
+
63
+ $terms = get_terms( $args );
64
+
65
+ foreach ($terms as $term) {
66
+ $data_array[] = $this->hf_import_to_csv($term, $terms, $taxonomy_type);
67
+
68
+
69
+ }
70
+ /**
71
+ * taking total records
72
+ */
73
+ $total_records=0;
74
+ if($batch_offset==0) //first batch
75
+ {
76
+ $total_item_args=$args;
77
+ $total_item_args['number']=$export_limit; //user given limit
78
+ $total_item_args['offset']=$current_offset; //user given offset
79
+ $total_terms = wp_count_terms( $taxonomy_type );
80
+ $total_records = $total_terms;
81
+ }
82
+
83
+ $return['total'] = $total_records;
84
+ $return['data'] = $data_array;
85
+ return $return;
86
+ }
87
+
88
+ }
89
+
90
+ public function hf_import_to_csv($term, $terms, $taxonomy_type) {
91
+ $row = array();
92
+
93
+ $csv_columns = $this->parent_module->get_selected_column_names();
94
+
95
+ foreach ($csv_columns as $column => $value) {
96
+
97
+ if ($column === 'term_id') {
98
+ $row[$column] = $term->term_id;
99
+ continue;
100
+ }
101
+ if ($column === 'name') {
102
+ $row[$column] = $term->name;
103
+ continue;
104
+ }
105
+ if ($column === 'slug') {
106
+ $row[$column] = rawurldecode($term->slug);
107
+ continue;
108
+ }
109
+ if ($column === 'description') {
110
+ $row[$column] = $term->description;
111
+ continue;
112
+ }
113
+ }
114
+
115
+ $row = apply_filters('wt_alter_product_tags_export_csv_data', $row, $term->term_id, $csv_columns);
116
+ return $row;
117
+
118
+ }
119
+
120
+ }
admin/modules/product_tags/import/import.php ADDED
@@ -0,0 +1,309 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ if (!defined('WPINC')) {
4
+ exit;
5
+ }
6
+
7
+ class Wt_Import_Export_For_Woo_Basic_Tags_Import {
8
+
9
+ public $parent_module = null;
10
+ public $parsed_data = array();
11
+ var $is_update;
12
+ var $taxonomy_type;
13
+ var $import_results = array();
14
+ var $row;
15
+
16
+ public function __construct($parent_object) {
17
+
18
+ $this->parent_module = $parent_object;
19
+
20
+ $this->taxonomy_post_defaults = apply_filters('wt_tags_csv_product_post_columns', array(
21
+ 'term_id' => 'term_id',
22
+ 'name' => 'name',
23
+ 'slug' => 'slug',
24
+ 'description' => 'description',
25
+ ));
26
+ }
27
+
28
+ public function hf_log_data_change($content = 'tags-csv-import', $data = '') {
29
+
30
+ Wt_Import_Export_For_Woo_Basic_Logwriter::write_log($this->parent_module->module_base, 'import', $data);
31
+ }
32
+
33
+ public function prepare_data_to_import($import_data, $form_data, $batch_offset, $is_last_batch) {
34
+
35
+ $this->is_update = isset($form_data['advanced_form_data']['wt_iew_merge']) ? $form_data['advanced_form_data']['wt_iew_merge'] : 0;
36
+ $this->taxonomy_type = 'product_tag';
37
+
38
+ Wt_Import_Export_For_Woo_Basic_Logwriter::write_log($this->parent_module->module_base, 'import', "Preparing for import.");
39
+
40
+ $success = 0;
41
+ $failed = 0;
42
+ $msg = 'Tag imported successfully.';
43
+ foreach ($import_data as $key => $data) {
44
+ $row = $batch_offset + $key + 1;
45
+ Wt_Import_Export_For_Woo_Basic_Logwriter::write_log($this->parent_module->module_base, 'import', "Row :$row - Parsing item.");
46
+ $parsed_data = $this->parse_product_tags($data, $this->is_update, $this->taxonomy_type);
47
+ if (!is_wp_error($parsed_data)) {
48
+ Wt_Import_Export_For_Woo_Basic_Logwriter::write_log($this->parent_module->module_base, 'import', "Row :$row - Processing item.");
49
+ $result = $this->process_product_tags($parsed_data, $this->is_update, $this->taxonomy_type);
50
+
51
+ if (!is_wp_error($result)) {
52
+ if (isset($result['status']) && $result['status'] == 'updated') {
53
+ $msg = 'Tag updated successfully.';
54
+ }
55
+
56
+ $this->import_results[$row] = array('row' => $row, 'message' => $msg, 'status' => true, 'post_id' => $result['id']);
57
+ Wt_Import_Export_For_Woo_Basic_Logwriter::write_log($this->parent_module->module_base, 'import', "Row :$row - " . $msg);
58
+ $success++;
59
+ } else {
60
+ $this->import_results[$row] = array('row' => $row, 'message' => $result->get_error_message(), 'status' => false, 'post_id' => '');
61
+ Wt_Import_Export_For_Woo_Basic_Logwriter::write_log($this->parent_module->module_base, 'import', "Row :$row - Prosessing failed. Reason: " . $result->get_error_message());
62
+ $failed++;
63
+ }
64
+ } else {
65
+ $this->import_results[$row] = array('row' => $row, 'message' => $parsed_data->get_error_message(), 'status' => false, 'post_id' => '');
66
+ Wt_Import_Export_For_Woo_Basic_Logwriter::write_log($this->parent_module->module_base, 'import', "Row :$row - Parsing failed. Reason: " . $parsed_data->get_error_message());
67
+ $failed++;
68
+ }
69
+ unset($data, $parsed_data);
70
+ }
71
+
72
+ $this->clean_after_import();
73
+
74
+ $import_response = array(
75
+ 'total_success' => $success,
76
+ 'total_failed' => $failed,
77
+ 'log_data' => $this->import_results,
78
+ );
79
+
80
+ return $import_response;
81
+ }
82
+
83
+ /**
84
+ * Parse product review
85
+ * @param array $item
86
+ * @return array
87
+ */
88
+ public function parse_product_tags($data, $is_update, $taxonomy_type) {
89
+ try {
90
+ $data = apply_filters('wt_woocommerce_product_tags_importer_pre_parse_data', $data);
91
+
92
+ $item = $data['mapping_fields'];
93
+
94
+ return $item;
95
+ } catch (Exception $e) {
96
+ return new WP_Error('woocommerce_product_importer_error', $e->getMessage(), array('status' => $e->getCode()));
97
+ }
98
+ }
99
+
100
+ /**
101
+ * Create new taxonomy based on import information
102
+ */
103
+ public function process_product_tags($post, $is_update, $taxonomy_type) {
104
+ try {
105
+
106
+ $term_data = $this->process_taxonomy_by_type($post, $is_update, $taxonomy_type);
107
+
108
+ return $term_data;
109
+ } catch (Exception $e) {
110
+ return new WP_Error('woocommerce_product_importer_error', $e->getMessage(), array('status' => $e->getCode()));
111
+ }
112
+ }
113
+
114
+ public function process_taxonomy_by_type($data, $is_update = 0, $taxonomy_type = 'product_cat') {
115
+
116
+ $parent_id = '';
117
+ $name = isset($data['name']) ? $data['name'] : '';
118
+ $slug = isset($data['slug']) ? $data['slug'] : '';
119
+
120
+ $term_id = isset($data['term_id']) ? $data['term_id'] : '';
121
+ $description = isset($data['description']) ? $data['description'] : '';
122
+ $display_type = isset($data['display_type']) ? $data['display_type'] : '';
123
+
124
+ $parent_id = (isset($data['parent']) && ($data['parent'] != 0 )) ? $data['parent'] : '';
125
+
126
+ global $wpdb;
127
+
128
+ switch ($taxonomy_type) {
129
+
130
+ case 'product_cat':
131
+ $tax_type = 'product_cat';
132
+ $term_meta_tbl_key = 'orginal_term_id';
133
+ break;
134
+ case 'product_tag':
135
+ $tax_type = 'product_tag';
136
+ $term_meta_tbl_key = 'orginal_product_tag_term_id';
137
+ break;
138
+ }
139
+ $pid = '';
140
+ if ($parent_id) {
141
+ $pid = $parent_id;
142
+ }
143
+ $term_name = $name;
144
+ $taxonomy_name = $tax_type;
145
+ $related_data = array(
146
+ 'name' => $name,
147
+ 'description' => $description,
148
+ 'slug' => strtolower(rawurlencode($slug))
149
+ );
150
+ if ($pid) {
151
+ $related_data['parent'] = $pid;
152
+ }
153
+ $chk = $wpdb->get_row($wpdb->prepare("SELECT t.term_id, t.name, t.slug FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy as tt ON tt.term_id = t.term_id WHERE t.name = %s and t.slug = %s and tt.taxonomy = %s ORDER BY t.term_id", $name, $slug, $tax_type), ARRAY_A);
154
+
155
+ $tid = '';
156
+ $status = '';
157
+ if (isset($chk['term_id']))
158
+ $tid = $chk['term_id'];
159
+
160
+ if ($taxonomy_type == 'product_tag' || $taxonomy_type == 'product_cat') {
161
+
162
+ if ($tid == '') {
163
+
164
+ if (!empty($data['slug'])) {
165
+
166
+ if ($taxonomy_type == 'product_tag' || $taxonomy_type == 'product_cat') {
167
+
168
+ $res = $wpdb->get_results($wpdb->prepare("SELECT term_id FROM $wpdb->termmeta WHERE meta_key = %s and meta_value = %d ORDER BY meta_key,meta_id", $term_meta_tbl_key, $parent_id), ARRAY_A);
169
+
170
+ $term_id = $term_id;
171
+
172
+ if (!empty($res)) {
173
+ $pid = $res[0]['term_id'];
174
+ }
175
+ $related_data['parent'] = $pid;
176
+ }
177
+
178
+ if (!empty($parent_id) && empty($res)) {
179
+
180
+ $status = array(
181
+ 'name' => $name,
182
+ 'status' => 'Data skipped parent not found',
183
+ );
184
+ return new WP_Error('data-error', '> Data skipped parent not found');
185
+ } else {
186
+
187
+ $cid = wp_insert_term($term_name, $taxonomy_name, $related_data);
188
+ if (is_wp_error($cid)) {
189
+ return new WP_Error('data-error', $cid->get_error_message());
190
+ }
191
+
192
+ $cid = $cid['term_id'];
193
+ if(!empty($term_id))
194
+ update_term_meta($cid, $term_meta_tbl_key, $term_id);
195
+
196
+ if ($taxonomy_type == 'product_cat') {
197
+
198
+ $thumbnail = isset($data['thumbnail']) ? $data['thumbnail'] : '';
199
+ if ($thumbnail != "") {
200
+
201
+ $image_url = $data['thumbnail'];
202
+ $attach_id = $this->image_library_attachment($image_url);
203
+ update_term_meta($cid, 'thumbnail_id', absint($attach_id));
204
+ }
205
+ }
206
+ if(!empty($display_type)){
207
+ update_term_meta($cid, 'display_type', $display_type);
208
+ }
209
+ $status = array(
210
+ 'id' => $cid,
211
+ 'name' => $name,
212
+ 'status' => 'imported',
213
+ );
214
+ unset($cid);
215
+ }
216
+ }
217
+ } else {
218
+
219
+ if ($is_update) {
220
+ $update = wp_update_term($tid, $taxonomy_name, $related_data);
221
+ if ($taxonomy_type == 'product_cat') {
222
+ $thumbnail = isset($data['thumbnail']) ? $data['thumbnail'] : '';
223
+ if ($thumbnail != "") {
224
+
225
+ $thumbnail_id = get_term_meta($tid, 'thumbnail_id', true);
226
+ $thumbnail_url = wp_get_attachment_url($thumbnail_id);
227
+ $existing_filename = basename($thumbnail_url);
228
+
229
+ $image_url = $thumbnail;
230
+ $current_filename = basename($image_url);
231
+ if ($current_filename != $existing_filename) {
232
+
233
+ $attach_id = $this->image_library_attachment($image_url);
234
+
235
+ update_term_meta($tid, 'thumbnail_id', absint($attach_id));
236
+ }
237
+ }
238
+ }
239
+
240
+ if (!empty($display_type)) {
241
+ update_term_meta($tid, 'display_type', $display_type);
242
+ }
243
+ $status = array(
244
+ 'id' => $tid,
245
+ 'name' => $name,
246
+ 'status' => 'updated',
247
+ );
248
+ } else {
249
+ return new WP_Error('data-exist', '> Taxonomy skipped - already exist');
250
+ }
251
+ if($term_id)
252
+ update_term_meta($tid, $term_meta_tbl_key, $term_id);
253
+ }
254
+ }
255
+
256
+ unset($chk);
257
+ return $status;
258
+ }
259
+
260
+ /**
261
+ * Method used for attach image file to wp library
262
+ *
263
+ * $image_url is url
264
+ * return attachment id
265
+ */
266
+ public function image_library_attachment($image_url) {
267
+
268
+ $upload_dir = wp_upload_dir();
269
+
270
+ $image_data = file_get_contents($image_url);
271
+
272
+ $filename = basename($image_url);
273
+
274
+ if (wp_mkdir_p($upload_dir['path'])) {
275
+ $file = $upload_dir['path'] . '/' . $filename;
276
+ } else {
277
+ $file = $upload_dir['basedir'] . '/' . $filename;
278
+ }
279
+
280
+ file_put_contents($file, $image_data);
281
+
282
+ $wp_filetype = wp_check_filetype($filename, null);
283
+
284
+ $attachment = array(
285
+ 'post_mime_type' => $wp_filetype['type'],
286
+ 'post_title' => sanitize_file_name($filename),
287
+ 'post_content' => '',
288
+ 'post_status' => 'inherit'
289
+ );
290
+
291
+ $attach_id = wp_insert_attachment($attachment, $file);
292
+ require_once( ABSPATH . 'wp-admin/includes/image.php' );
293
+ $attach_data = wp_generate_attachment_metadata($attach_id, $file);
294
+ wp_update_attachment_metadata($attach_id, $attach_data);
295
+
296
+ return $attach_id;
297
+ }
298
+
299
+ public function clean_after_import() {
300
+ wp_suspend_cache_invalidation(false);
301
+ wp_defer_term_counting(false);
302
+ wp_defer_comment_counting(false);
303
+ global $wpdb;
304
+ if (class_exists('WC_Product_Reviews_Pro')) {
305
+ $wpdb->query("DELETE FROM `$wpdb->options` WHERE `option_name` LIKE ('%_transient_wc_product_reviews_pro_review_count_%')");
306
+ }
307
+ }
308
+
309
+ }
admin/modules/product_tags/product_tags.php ADDED
@@ -0,0 +1,470 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Product tags section of the plugin
4
+ *
5
+ * @link
6
+ *
7
+ * @package Wt_Import_Export_For_Woo
8
+ */
9
+ if (!defined('ABSPATH')) {
10
+ exit;
11
+ }
12
+
13
+ if(!class_exists('Wt_Import_Export_For_Woo_Basic_Product_Tags')){
14
+ class Wt_Import_Export_For_Woo_Basic_Product_Tags {
15
+
16
+ public $module_id = '';
17
+ public static $module_id_static = '';
18
+ public $module_base = 'product_tags';
19
+ public $module_name = 'Tags Import Export for WooCommerce';
20
+ public $min_base_version= '1.0.0'; /* Minimum `Import export plugin` required to run this add on plugin */
21
+
22
+ private $all_meta_keys = array();
23
+ private $found_product_meta = array();
24
+ private $selected_column_names = null;
25
+
26
+ public function __construct()
27
+ {
28
+ /**
29
+ * Checking the minimum required version of `Import export plugin` plugin available
30
+ */
31
+ if(!Wt_Import_Export_For_Woo_Basic_Common_Helper::check_base_version($this->module_base, $this->module_name, $this->min_base_version))
32
+ {
33
+ return;
34
+ }
35
+ if(!function_exists('is_plugin_active'))
36
+ {
37
+ include_once(ABSPATH.'wp-admin/includes/plugin.php');
38
+ }
39
+ if(!is_plugin_active('woocommerce/woocommerce.php'))
40
+ {
41
+ return;
42
+ }
43
+
44
+ $this->module_id = Wt_Import_Export_For_Woo_basic::get_module_id($this->module_base);
45
+
46
+ self::$module_id_static = $this->module_id;
47
+
48
+ add_filter('wt_iew_exporter_post_types_basic', array($this, 'wt_iew_exporter_post_types'), 10, 1);
49
+ add_filter('wt_iew_importer_post_types_basic', array($this, 'wt_iew_exporter_post_types'), 10, 1);
50
+
51
+ add_filter('wt_iew_exporter_alter_filter_fields_basic', array($this, 'exporter_alter_filter_fields'), 10, 3);
52
+
53
+ add_filter('wt_iew_exporter_alter_mapping_fields_basic', array($this, 'exporter_alter_mapping_fields'), 10, 3);
54
+ add_filter('wt_iew_importer_alter_mapping_fields_basic', array($this, 'get_importer_post_columns'), 10, 3);
55
+
56
+ add_filter('wt_iew_exporter_alter_advanced_fields_basic', array($this, 'exporter_alter_advanced_fields'), 10, 3);
57
+ add_filter('wt_iew_importer_alter_advanced_fields_basic', array($this, 'importer_alter_advanced_fields'), 10, 3);
58
+
59
+ add_filter('wt_iew_exporter_alter_meta_mapping_fields_basic', array($this, 'exporter_alter_meta_mapping_fields'), 10, 3);
60
+ add_filter('wt_iew_importer_alter_meta_mapping_fields_basic', array($this, 'importer_alter_meta_mapping_fields'), 10, 3);
61
+
62
+ add_filter('wt_iew_exporter_alter_mapping_enabled_fields_basic', array($this, 'exporter_alter_mapping_enabled_fields'), 10, 3);
63
+ add_filter('wt_iew_importer_alter_mapping_enabled_fields_basic', array($this, 'exporter_alter_mapping_enabled_fields'), 10, 3);
64
+
65
+ add_filter('wt_iew_exporter_do_export_basic', array($this, 'exporter_do_export'), 10, 7);
66
+ add_filter('wt_iew_importer_do_import_basic', array($this, 'importer_do_import'), 10, 8);
67
+
68
+ add_filter('wt_iew_importer_steps_basic', array($this, 'importer_steps'), 10, 2);
69
+ }
70
+
71
+
72
+ /**
73
+ * Altering advanced step description
74
+ */
75
+ public function importer_steps($steps, $base)
76
+ {
77
+ if($this->module_base==$base)
78
+ {
79
+ $steps['advanced']['description']=__('Use advanced options from below to decide updates to existing reviews, batch import count or schedule an import. You can also save the template file for future imports.');
80
+ }
81
+ return $steps;
82
+ }
83
+
84
+ public function importer_do_import($import_data, $base, $step, $form_data, $selected_template_data, $method_import, $batch_offset, $is_last_batch) {
85
+ if ($this->module_base != $base) {
86
+ return $import_data;
87
+ }
88
+
89
+ if(0 == $batch_offset){
90
+ $memory = size_format(self::wt_let_to_num(ini_get('memory_limit')));
91
+ $wp_memory = size_format(self::wt_let_to_num(WP_MEMORY_LIMIT));
92
+ Wt_Import_Export_For_Woo_Basic_Logwriter::write_log($this->module_base, 'import', '---[ New import started at '.date('Y-m-d H:i:s').' ] PHP Memory: ' . $memory . ', WP Memory: ' . $wp_memory);
93
+ }
94
+
95
+ include plugin_dir_path(__FILE__) . 'import/import.php';
96
+ $import = new Wt_Import_Export_For_Woo_Basic_Tags_Import($this);
97
+
98
+ $response = $import->prepare_data_to_import($import_data,$form_data,$batch_offset,$is_last_batch);
99
+
100
+ if($is_last_batch){
101
+ Wt_Import_Export_For_Woo_Basic_Logwriter::write_log($this->module_base, 'import', '---[ Import ended at '.date('Y-m-d H:i:s').']---');
102
+ }
103
+
104
+ return $response;
105
+ }
106
+
107
+ public static function wt_let_to_num( $size ) {
108
+ $l = substr( $size, -1 );
109
+ $ret = (int) substr( $size, 0, -1 );
110
+ switch ( strtoupper( $l ) ) {
111
+ case 'P':
112
+ $ret *= 1024;
113
+ // No break.
114
+ case 'T':
115
+ $ret *= 1024;
116
+ // No break.
117
+ case 'G':
118
+ $ret *= 1024;
119
+ // No break.
120
+ case 'M':
121
+ $ret *= 1024;
122
+ // No break.
123
+ case 'K':
124
+ $ret *= 1024;
125
+ // No break.
126
+ }
127
+ return $ret;
128
+ }
129
+
130
+ public function exporter_do_export($export_data, $base, $step, $form_data, $selected_template_data, $method_export, $batch_offset) {
131
+ if ($this->module_base != $base) {
132
+ return $export_data;
133
+ }
134
+
135
+
136
+ switch ($method_export) {
137
+ case 'quick':
138
+ $this->set_export_columns_for_quick_export($form_data);
139
+ break;
140
+
141
+ case 'template':
142
+ case 'new':
143
+ $this->set_selected_column_names($form_data);
144
+ break;
145
+
146
+ default:
147
+ break;
148
+ }
149
+
150
+ include plugin_dir_path(__FILE__) . 'export/export.php';
151
+ $export = new Wt_Import_Export_For_Woo_Basic_Tags_Export($this);
152
+
153
+ $header_row = $export->prepare_header();
154
+
155
+ $data_row = $export->prepare_data_to_export($form_data, $batch_offset);
156
+
157
+ $export_data = array(
158
+ 'head_data' => $header_row,
159
+ 'body_data' => $data_row['data'],
160
+ );
161
+
162
+ if(isset($data_row['total']) && !empty($data_row['total'])){
163
+ $export_data['total'] = $data_row['total'];
164
+ }
165
+
166
+ return $export_data;
167
+ }
168
+
169
+ /**
170
+ * Adding current post type to export list
171
+ *
172
+ */
173
+ public function wt_iew_exporter_post_types($arr) {
174
+ $arr['product_tags'] = __('Product Tags');
175
+ return $arr;
176
+ }
177
+
178
+
179
+
180
+ /*
181
+ * Setting default export columns for quick export
182
+ */
183
+
184
+ public function set_export_columns_for_quick_export($form_data) {
185
+
186
+ $post_columns = self::get_tags_post_columns();
187
+
188
+ $this->selected_column_names = array_combine(array_keys($post_columns), array_keys($post_columns));
189
+
190
+ if (isset($form_data['method_export_form_data']['mapping_enabled_fields']) && !empty($form_data['method_export_form_data']['mapping_enabled_fields'])) {
191
+ foreach ($form_data['method_export_form_data']['mapping_enabled_fields'] as $value) {
192
+ $additional_quick_export_fields[$value] = array('fields' => array());
193
+ }
194
+
195
+ $export_additional_columns = $this->exporter_alter_meta_mapping_fields($additional_quick_export_fields, $this->module_base, array());
196
+ foreach ($export_additional_columns as $value) {
197
+ $this->selected_column_names = array_merge($this->selected_column_names, $value['fields']);
198
+ }
199
+ }
200
+ }
201
+
202
+
203
+ public static function get_product_review_statuses() {
204
+ $product_statuses = array('publish', 'private', 'draft', 'pending', 'future');
205
+ return apply_filters('wt_iew_allowed_product_review_statuses', array_combine($product_statuses, $product_statuses));
206
+ }
207
+
208
+ public static function get_tags_sort_columns() {
209
+ $sort_columns = array(
210
+ 'id' => __('Tag ID'),
211
+ 'name' => __('Tag name'),
212
+ 'slug' => __('Tag slug'),
213
+ );
214
+ return apply_filters('wt_iew_allowed_tags_sort_columns', $sort_columns);
215
+ }
216
+
217
+ public static function get_tags_post_columns() {
218
+
219
+ return include plugin_dir_path(__FILE__) . 'data/data-product-review-columns.php';
220
+ }
221
+
222
+ public function get_importer_post_columns($fields, $base, $step_page_form_data) {
223
+
224
+ if ($base != $this->module_base) {
225
+ return $fields;
226
+ }
227
+ $colunm = include plugin_dir_path(__FILE__) . 'data/data/data-wf-reserved-fields-pair.php';
228
+ // $colunm = array_map(function($vl){ return array('title'=>$vl, 'description'=>$vl); }, $arr);
229
+ return $colunm;
230
+ }
231
+
232
+
233
+ public function exporter_alter_mapping_enabled_fields($mapping_enabled_fields, $base, $form_data_mapping_enabled_fields) {
234
+ if ($base == $this->module_base) {
235
+
236
+ }
237
+
238
+ return $mapping_enabled_fields;
239
+ }
240
+
241
+
242
+ public function exporter_alter_meta_mapping_fields($fields, $base, $step_page_form_data) {
243
+ if ($base != $this->module_base) {
244
+ return $fields;
245
+ }
246
+
247
+
248
+ return $fields;
249
+ }
250
+
251
+
252
+ public function wt_get_product_tags() {
253
+
254
+ if (!empty($this->product_taxonomies)) {
255
+ return $this->product_taxonomies;
256
+ }
257
+ $product_ptaxonomies = get_object_taxonomies('product', 'name');
258
+ $product_vtaxonomies = get_object_taxonomies('product_variation', 'name');
259
+ $product_taxonomies = array_merge($product_ptaxonomies, $product_vtaxonomies);
260
+
261
+ $this->product_taxonomies = $product_taxonomies;
262
+ return $this->product_taxonomies;
263
+ }
264
+
265
+
266
+ public function importer_alter_meta_mapping_fields($fields, $base, $step_page_form_data) {
267
+ if ($base != $this->module_base) {
268
+ return $fields;
269
+ }
270
+ $fields=$this->exporter_alter_meta_mapping_fields($fields, $base, $step_page_form_data);
271
+ $out=array();
272
+ foreach ($fields as $key => $value)
273
+ {
274
+ $value['fields']=array_map(function($vl){ return array('title'=>$vl, 'description'=>$vl); }, $value['fields']);
275
+ $out[$key]=$value;
276
+ }
277
+ return $out;
278
+ }
279
+
280
+ public function wt_get_found_product_meta() {
281
+
282
+ if (!empty($this->found_product_meta)) {
283
+ return $this->found_product_meta;
284
+ }
285
+
286
+ // Loop products and load meta data
287
+ $found_product_meta = array();
288
+ // Some of the values may not be usable (e.g. arrays of arrays) but the worse
289
+ // that can happen is we get an empty column.
290
+
291
+ $all_meta_keys = $this->wt_get_all_meta_keys();
292
+
293
+ $csv_columns = self::get_tags_post_columns();
294
+
295
+ foreach ($all_meta_keys as $meta) {
296
+
297
+ if (!$meta || (substr((string) $meta, 0, 1) == '_') || in_array($meta, array_keys($csv_columns)) || in_array('meta:' . $meta, array_keys($csv_columns)))
298
+ continue;
299
+
300
+ $found_product_meta[] = $meta;
301
+ }
302
+
303
+ $found_product_meta = array_diff($found_product_meta, array_keys($csv_columns));
304
+
305
+ $this->found_product_meta = $found_product_meta;
306
+ return $this->found_product_meta;
307
+ }
308
+
309
+
310
+
311
+ public function wt_get_all_meta_keys() {
312
+
313
+ if (!empty($this->all_meta_keys)) {
314
+ return $this->all_meta_keys;
315
+ }
316
+
317
+ $all_meta_pkeys = self::get_all_metakeys();
318
+
319
+ $this->all_meta_keys = $all_meta_pkeys;
320
+
321
+ return $this->all_meta_keys;
322
+ }
323
+
324
+ /**
325
+ * Get a list of all the meta keys for a post type. This includes all public, private,
326
+ * used, no-longer used etc. They will be sorted once fetched.
327
+ */
328
+ public static function get_all_metakeys() {
329
+ global $wpdb;
330
+
331
+ $meta = $wpdb->get_col(
332
+ "SELECT DISTINCT cm.meta_key
333
+ FROM {$wpdb->commentmeta} AS cm
334
+ LEFT JOIN {$wpdb->comments} AS c ON c.comment_ID = cm.comment_id
335
+ WHERE c.comment_type = 'review'"
336
+ );
337
+ sort($meta);
338
+ return $meta;
339
+ }
340
+
341
+ public function set_selected_column_names($full_form_data) {
342
+
343
+ if (is_null($this->selected_column_names)) {
344
+
345
+ if (isset($full_form_data['mapping_form_data']['mapping_selected_fields']) && !empty($full_form_data['mapping_form_data']['mapping_selected_fields'])) {
346
+ $this->selected_column_names = $full_form_data['mapping_form_data']['mapping_selected_fields'];
347
+ }
348
+ if (isset($full_form_data['meta_step_form_data']['mapping_selected_fields']) && !empty($full_form_data['meta_step_form_data']['mapping_selected_fields'])) {
349
+ $export_additional_columns = $full_form_data['meta_step_form_data']['mapping_selected_fields'];
350
+ foreach ($export_additional_columns as $value) {
351
+ $this->selected_column_names = array_merge($this->selected_column_names, $value);
352
+ }
353
+ }
354
+ }
355
+
356
+ return $full_form_data;
357
+ }
358
+
359
+ public function get_selected_column_names() {
360
+ return $this->selected_column_names;
361
+ }
362
+
363
+ public function exporter_alter_mapping_fields($fields, $base, $mapping_form_data) {
364
+ if ($base != $this->module_base) {
365
+ return $fields;
366
+ }
367
+
368
+ $fields = self::get_tags_post_columns();
369
+
370
+ return $fields;
371
+ }
372
+
373
+
374
+ /**
375
+ * Customize the items in filter export page
376
+ */
377
+ public function exporter_alter_filter_fields($fields, $base, $filter_form_data) {
378
+ if ($this->module_base != $base) {
379
+ return $fields;
380
+ }
381
+
382
+ $fields = array();
383
+
384
+
385
+ $sort_columns = self::get_tags_sort_columns();
386
+ $fields['sort_columns'] = array(
387
+ 'label' => __('Sort Columns'),
388
+ 'placeholder' => __('comment_ID'),
389
+ 'field_name' => 'sort_columns',
390
+ 'sele_vals' => $sort_columns,
391
+ 'help_text' => __('Sort the exported data based on the selected column in the order specified. Defaulted to ascending order.'),
392
+ 'type' => 'select',
393
+ );
394
+
395
+ $fields['order_by'] = array(
396
+ 'label' => __('Sort'),
397
+ 'placeholder' => __('ASC'),
398
+ 'field_name' => 'order_by',
399
+ 'sele_vals' => array('ASC' => 'Ascending', 'DESC' => 'Descending'),
400
+ 'help_text' => __('Defaulted to Ascending. Applicable to above selected columns in the order specified.'),
401
+ 'type' => 'select',
402
+ 'css_class' => '',
403
+ );
404
+
405
+ return $fields;
406
+ }
407
+
408
+
409
+ public function exporter_alter_advanced_fields($fields, $base, $advanced_form_data) {
410
+ if ($this->module_base != $base) {
411
+ return $fields;
412
+ }
413
+ unset($fields['export_shortcode_tohtml']);
414
+
415
+ return $fields;
416
+ }
417
+
418
+ public function importer_alter_advanced_fields($fields, $base, $advanced_form_data) {
419
+ if ($this->module_base != $base) {
420
+ return $fields;
421
+ }
422
+ $out = array();
423
+
424
+
425
+
426
+ $out['merge'] = array(
427
+ 'label' => __("If the tag exists in the store"),
428
+ 'type' => 'radio',
429
+ 'radio_fields' => array(
430
+ '0' => __('Skip'),
431
+ '1' => __('Update')
432
+ ),
433
+ 'value' => '0',
434
+ 'field_name' => 'merge',
435
+ 'help_text' => __('Tags are matched by their ID/slugs.'),
436
+ 'help_text_conditional'=>array(
437
+ array(
438
+ 'help_text'=> __('Retains the tag in the store as is and skips the matching tag from the input file.'),
439
+ 'condition'=>array(
440
+ array('field'=>'wt_iew_merge', 'value'=>0)
441
+ )
442
+ ),
443
+ array(
444
+ 'help_text'=> __('Update tag as per data from the input file'),
445
+ 'condition'=>array(
446
+ array('field'=>'wt_iew_merge', 'value'=>1)
447
+ )
448
+ )
449
+ ),
450
+ 'form_toggler'=>array(
451
+ 'type'=>'parent',
452
+ 'target'=>'wt_iew_found_action'
453
+ )
454
+ );
455
+
456
+
457
+ foreach ($fields as $fieldk => $fieldv) {
458
+ $out[$fieldk] = $fieldv;
459
+ }
460
+ return $out;
461
+ }
462
+
463
+ public function get_item_by_id($id) {
464
+ $post['edit_url']= get_edit_term_link($id);
465
+ $post['title'] = @get_term($id)->name;
466
+ return $post;
467
+ }
468
+ }
469
+ }
470
+ new Wt_Import_Export_For_Woo_Basic_Product_Tags();
assets/images/webtoffee-logo_small.png ADDED
Binary file
class-wt-product-review-request.php ADDED
@@ -0,0 +1,252 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Review request
5
+ *
6
+ *
7
+ * @package Cookie_Law_Info
8
+ */
9
+ if (!defined('ABSPATH')) {
10
+ exit;
11
+ }
12
+ class Product_Import_Export_Review_Request
13
+ {
14
+ /**
15
+ * config options
16
+ */
17
+ private $plugin_title = "Product CSV Import Export (BASIC)";
18
+ private $review_url = "https://wordpress.org/support/plugin/product-import-export-for-woo/reviews/#new-post";
19
+ private $plugin_prefix = "wt_p_iew_basic"; /* must be unique name */
20
+ private $activation_hook = "wt_p_iew_basic_activate"; /* hook for activation, to store activated date */
21
+ private $deactivation_hook = "wt_p_iew_basic_deactivate"; /* hook for deactivation, to delete activated date */
22
+ private $days_to_show_banner = 7; /* when did the banner to show */
23
+ private $remind_days = 5; /* remind interval in days */
24
+ private $webtoffee_logo_url = WT_P_IEW_PLUGIN_URL.'assets/images/webtoffee-logo_small.png';
25
+
26
+
27
+
28
+ private $start_date = 0; /* banner to show count start date. plugin installed date, remind me later added date */
29
+ private $current_banner_state = 2; /* 1: active, 2: waiting to show(first after installation), 3: closed by user/not interested to review, 4: user done the review, 5:remind me later */
30
+ private $banner_state_option_name = ''; /* WP option name to save banner state */
31
+ private $start_date_option_name = ''; /* WP option name to save start date */
32
+ private $banner_css_class = ''; /* CSS class name for Banner HTML element. */
33
+ private $banner_message = ''; /* Banner message. */
34
+ private $later_btn_text = ''; /* Remind me later button text */
35
+ private $never_btn_text = ''; /* Never review button text. */
36
+ private $review_btn_text = ''; /* Review now button text. */
37
+ private $ajax_action_name = ''; /* Name of ajax action to save banner state. */
38
+ private $allowed_action_type_arr = array(
39
+ 'later', /* remind me later */
40
+ 'never', /* never */
41
+ 'review', /* review now */
42
+ 'closed', /* not interested */
43
+ );
44
+
45
+ public function __construct()
46
+ {
47
+ //Set config vars
48
+ $this->set_vars();
49
+
50
+ add_action($this->activation_hook, array($this, 'on_activate'));
51
+ add_action($this->deactivation_hook, array($this, 'on_deactivate'));
52
+
53
+ if ($this->check_condition()) /* checks the banner is active now */ {
54
+ $this->banner_message = sprintf(__("Hey, we at %sWebToffee%s would like to thank you for using our plugin. We would really appreciate if you could take a moment to drop a quick review that will inspire us to keep going."), '<b>', '</b>');
55
+
56
+ /* button texts */
57
+ $this->later_btn_text = __("Remind me later");
58
+ $this->never_btn_text = __("Not interested");
59
+ $this->review_btn_text = __("Review now");
60
+
61
+ add_action('admin_notices', array($this, 'show_banner')); /* show banner */
62
+ add_action('admin_print_footer_scripts', array($this, 'add_banner_scripts')); /* add banner scripts */
63
+ add_action('wp_ajax_' . $this->ajax_action_name, array($this, 'process_user_action')); /* process banner user action */
64
+ }
65
+ }
66
+
67
+ /**
68
+ * Set config vars
69
+ */
70
+ public function set_vars()
71
+ {
72
+ $this->ajax_action_name = $this->plugin_prefix . '_process_user_review_action';
73
+ $this->banner_state_option_name = $this->plugin_prefix . "_review_request";
74
+ $this->start_date_option_name = $this->plugin_prefix . "_start_date";
75
+ $this->banner_css_class = $this->plugin_prefix . "_review_request";
76
+
77
+ $this->start_date = absint(get_option($this->start_date_option_name));
78
+ $banner_state = absint(get_option($this->banner_state_option_name));
79
+ $this->current_banner_state = ($banner_state == 0 ? $this->current_banner_state : $banner_state);
80
+ }
81
+
82
+ /**
83
+ * Actions on plugin activation
84
+ * Saves activation date
85
+ */
86
+ public function on_activate()
87
+ {
88
+ $this->reset_start_date();
89
+ }
90
+
91
+ /**
92
+ * Actions on plugin deactivation
93
+ * Removes activation date
94
+ */
95
+ public function on_deactivate()
96
+ {
97
+ delete_option($this->start_date_option_name);
98
+ }
99
+
100
+ /**
101
+ * Reset the start date.
102
+ */
103
+ private function reset_start_date()
104
+ {
105
+ update_option($this->start_date_option_name, time());
106
+ }
107
+
108
+ /**
109
+ * Update the banner state
110
+ */
111
+ private function update_banner_state($val)
112
+ {
113
+ update_option($this->banner_state_option_name, $val);
114
+ }
115
+
116
+ /**
117
+ * Prints the banner
118
+ */
119
+ public function show_banner()
120
+ {
121
+ $this->update_banner_state(1); /* update banner active state */
122
+ ?>
123
+ <div class="<?php echo $this->banner_css_class; ?> notice-info notice is-dismissible">
124
+ <?php
125
+ if ($this->webtoffee_logo_url != "") {
126
+ ?>
127
+ <h3 style="margin: 10px 0;"><?php echo $this->plugin_title; ?></h3>
128
+ <?php
129
+ }
130
+ ?>
131
+ <p>
132
+ <?php echo $this->banner_message; ?>
133
+ </p>
134
+ <p>
135
+ <a class="button button-secondary" style="color:#333; border-color:#ccc; background:#efefef;" data-type="later"><?php echo $this->later_btn_text; ?></a>
136
+ <a class="button button-primary" data-type="review"><?php echo $this->review_btn_text; ?></a>
137
+ </p>
138
+ <div class="wt-piew-review-footer" style="position: relative;">
139
+ <span class="wt-cli-footer-icon" style="position: absolute;right: 0;bottom: 10px;"><img src="<?php echo $this->webtoffee_logo_url; ?>" style="max-width:100px;"></span>
140
+ </div>
141
+ </div>
142
+ <?php
143
+ }
144
+
145
+ /**
146
+ * Ajax hook to process user action on the banner
147
+ */
148
+ public function process_user_action()
149
+ {
150
+ check_ajax_referer($this->plugin_prefix);
151
+ if (isset($_POST['wt_review_action_type'])) {
152
+ $action_type = sanitize_text_field($_POST['wt_review_action_type']);
153
+
154
+ /* current action is in allowed action list */
155
+ if (in_array($action_type, $this->allowed_action_type_arr)) {
156
+ if ($action_type == 'never' || $action_type == 'closed') {
157
+ $new_banner_state = 3;
158
+ } elseif ($action_type == 'review') {
159
+ $new_banner_state = 4;
160
+ } else {
161
+ /* reset start date to current date */
162
+ $this->reset_start_date();
163
+ $new_banner_state = 5; /* remind me later */
164
+ }
165
+ $this->update_banner_state($new_banner_state);
166
+ }
167
+ }
168
+ exit();
169
+ }
170
+
171
+ /**
172
+ * Add banner JS to admin footer
173
+ */
174
+ public function add_banner_scripts()
175
+ {
176
+ $ajax_url = admin_url('admin-ajax.php');
177
+ $nonce = wp_create_nonce($this->plugin_prefix);
178
+ ?>
179
+ <script type="text/javascript">
180
+ (function($) {
181
+ "use strict";
182
+
183
+ /* prepare data object */
184
+ var data_obj = {
185
+ _wpnonce: '<?php echo $nonce; ?>',
186
+ action: '<?php echo $this->ajax_action_name; ?>',
187
+ wt_review_action_type: ''
188
+ };
189
+
190
+ $(document).on('click', '.<?php echo $this->banner_css_class; ?> a.button', function(e) {
191
+ e.preventDefault();
192
+ var elm = $(this);
193
+ var btn_type = elm.attr('data-type');
194
+ if (btn_type == 'review') {
195
+ window.open('<?php echo $this->review_url; ?>');
196
+ }
197
+ elm.parents('.<?php echo $this->banner_css_class; ?>').hide();
198
+
199
+ data_obj['wt_review_action_type'] = btn_type;
200
+ $.ajax({
201
+ url: '<?php echo $ajax_url; ?>',
202
+ data: data_obj,
203
+ type: 'POST'
204
+ });
205
+
206
+ }).on('click', '.<?php echo $this->banner_css_class; ?> .notice-dismiss', function(e) {
207
+ e.preventDefault();
208
+ data_obj['wt_review_action_type'] = 'closed';
209
+ $.ajax({
210
+ url: '<?php echo $ajax_url; ?>',
211
+ data: data_obj,
212
+ type: 'POST',
213
+ });
214
+
215
+ });
216
+
217
+ })(jQuery)
218
+ </script>
219
+ <?php
220
+ }
221
+
222
+ /**
223
+ * Checks the condition to show the banner
224
+ */
225
+ private function check_condition()
226
+ {
227
+
228
+ if ($this->current_banner_state == 1) /* currently showing then return true */ {
229
+ return true;
230
+ }
231
+
232
+ if ($this->current_banner_state == 2 || $this->current_banner_state == 5) /* only waiting/remind later state */ {
233
+ if ($this->start_date == 0) /* unable to get activated date */ {
234
+ /* set current date as activation date*/
235
+ $this->reset_start_date();
236
+ return false;
237
+ }
238
+
239
+ $days = ($this->current_banner_state == 2 ? $this->days_to_show_banner : $this->remind_days);
240
+
241
+ $date_to_check = $this->start_date + (86400 * $days);
242
+ if ($date_to_check <= time()) /* time reached to show the banner */ {
243
+ return true;
244
+ } else {
245
+ return false;
246
+ }
247
+ }
248
+
249
+ return false;
250
+ }
251
+ }
252
+ new Product_Import_Export_Review_Request();
includes/class-wt-import-export-for-woo.php CHANGED
@@ -80,7 +80,7 @@ class Wt_Import_Export_For_Woo_Basic {
80
  if ( defined( 'WT_P_IEW_VERSION' ) ) {
81
  $this->version = WT_P_IEW_VERSION;
82
  } else {
83
- $this->version = '2.0.8';
84
  }
85
  $this->plugin_name = 'wt-import-export-for-woo-basic';
86
 
80
  if ( defined( 'WT_P_IEW_VERSION' ) ) {
81
  $this->version = WT_P_IEW_VERSION;
82
  } else {
83
+ $this->version = '2.0.9';
84
  }
85
  $this->plugin_name = 'wt-import-export-for-woo-basic';
86
 
product-import-export-for-woo.php CHANGED
@@ -5,8 +5,8 @@
5
  Description: Import and Export Products From and To your WooCommerce Store.
6
  Author: WebToffee
7
  Author URI: https://www.webtoffee.com/product/product-import-export-woocommerce/
8
- Version: 2.0.8
9
- WC tested up to: 5.6
10
  License: GPLv3
11
  License URI: https://www.gnu.org/licenses/gpl-3.0.html
12
  Text Domain: product-import-export-for-woo
@@ -43,7 +43,7 @@ if ( !defined( 'WT_IEW_DEBUG_BASIC_TROUBLESHOOT' ) ) {
43
  * Start at version 1.0.0 and use SemVer - https://semver.org
44
  * Rename this for your plugin and update it as you release new versions.
45
  */
46
- define( 'WT_P_IEW_VERSION', '2.0.8' );
47
 
48
  /**
49
  * The code that runs during plugin activation.
@@ -119,7 +119,10 @@ require plugin_dir_path( __FILE__ ) . 'includes/class-wt-import-export-for-woo.p
119
 
120
  $advanced_settings = get_option('wt_iew_advanced_settings', array());
121
  $ier_get_max_execution_time = (isset($advanced_settings['wt_iew_maximum_execution_time']) && $advanced_settings['wt_iew_maximum_execution_time'] != '') ? $advanced_settings['wt_iew_maximum_execution_time'] : ini_get('max_execution_time');
122
- set_time_limit($ier_get_max_execution_time);
 
 
 
123
 
124
  /**
125
  * Begins execution of the plugin.
@@ -222,6 +225,8 @@ $product_legacy_menu->old_menu_params = array(
222
  );
223
 
224
 
 
 
225
  // Add dismissible server info for file restrictions
226
  include_once plugin_dir_path( __FILE__ ) . 'includes/class-wt-non-apache-info.php';
227
  $inform_server_secure = new wt_inform_server_secure( 'product' );
5
  Description: Import and Export Products From and To your WooCommerce Store.
6
  Author: WebToffee
7
  Author URI: https://www.webtoffee.com/product/product-import-export-woocommerce/
8
+ Version: 2.0.9
9
+ WC tested up to: 5.7
10
  License: GPLv3
11
  License URI: https://www.gnu.org/licenses/gpl-3.0.html
12
  Text Domain: product-import-export-for-woo
43
  * Start at version 1.0.0 and use SemVer - https://semver.org
44
  * Rename this for your plugin and update it as you release new versions.
45
  */
46
+ define( 'WT_P_IEW_VERSION', '2.0.9' );
47
 
48
  /**
49
  * The code that runs during plugin activation.
119
 
120
  $advanced_settings = get_option('wt_iew_advanced_settings', array());
121
  $ier_get_max_execution_time = (isset($advanced_settings['wt_iew_maximum_execution_time']) && $advanced_settings['wt_iew_maximum_execution_time'] != '') ? $advanced_settings['wt_iew_maximum_execution_time'] : ini_get('max_execution_time');
122
+
123
+ if (strpos(@ini_get('disable_functions'), 'set_time_limit') === false) {
124
+ @set_time_limit($ier_get_max_execution_time);
125
+ }
126
 
127
  /**
128
  * Begins execution of the plugin.
225
  );
226
 
227
 
228
+ include_once 'class-wt-product-review-request.php';
229
+
230
  // Add dismissible server info for file restrictions
231
  include_once plugin_dir_path( __FILE__ ) . 'includes/class-wt-non-apache-info.php';
232
  $inform_server_secure = new wt_inform_server_secure( 'product' );
readme.txt CHANGED
@@ -5,7 +5,7 @@ Tags: product export, product import, CSV import export, woocommerce, CSV, produ
5
  Requires at least: 3.0.1
6
  Tested up to: 5.8
7
  Requires PHP: 5.6
8
- Stable tag: 2.0.8
9
  License: GPLv3 or later
10
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
11
 
@@ -19,23 +19,30 @@ The Product Import Export for WooCommerce plugin exports and imports WooCommerce
19
 
20
  ##Major Features##
21
 
22
- * <strong>Export WooCommerce products into CSV</strong>
23
- * <strong>Import products from CSV</strong> to WooCommerce
24
- * Supported product types - <strong>simple, grouped, external/affiliate</strong>
25
- * Export and import <strong>products with images</strong>
26
- * Export and import <strong>products by category/tags/product status</strong>
27
- * Export and import <strong>product attributes, taxonomies</strong>
28
- * <strong>Bulk edit products</strong>
29
- * Compatible with <strong>All-in-one SEO</strong> and <strong>Yoast WooCommerce SEO</strong> plugins
30
- * <strong>Batch import-export</strong>
31
- * Option to <strong>update or skip existing products</strong>
32
- * <strong>Set CSV delimiter</strong> for import
33
- * Select from <strong>multiple import/export methods</strong>
34
- * Export and import <strong>column mapping</strong>
35
- * Import/export using <strong>pre-saved configurations</strong>
36
- * View <strong>import-export history</strong>
37
- * View <strong>import log</strong> for easy debugging
38
- * Tested OK with WooCommerce 5.6
 
 
 
 
 
 
 
39
 
40
 
41
  ###Setup Guide - Product Import Export for WooCommerce###
@@ -62,7 +69,6 @@ Product Import Export Plugin for WooCommerce is the leading tool for the export
62
 
63
  ✅ Export/Import simple, group, external, custom and variation product types.</li>
64
  ✅ Export/Import custom fields(meta) and hidden meta.</li>
65
- ✅ Import/Export product reviews.</li>
66
  ✅ Choose from XML/CSV format for import/export.</li>
67
  ✅ <a href="https://www.webtoffee.com/product-import-export-for-woocommerce/#Step_3_Filter_d4">Various filter options for exporting products</a>
68
  ✅ <a href="https://www.webtoffee.com/product-import-export-for-woocommerce/#Step_3_Map_impo10">Map and transform fields during import</a>
@@ -80,8 +86,7 @@ Please visit <a rel="nofollow" href="https://www.webtoffee.com/product/product-i
80
 
81
  ## Product Import Export Plugin for WooCommerce (Pro) ##
82
 
83
- [youtube http://www.youtube.com/watch?v=L-01qI1EZWE&rel=0&showinfo=0]
84
-
85
 
86
  ### WooCommerce export products (all product types are supported) ###
87
  There are multiple cases where one needs to export WooCommerce products. It could be either for sending the details to someone else or integrating with a third-party system. With the plugin, you can import all product types including custom product types such as subscription and bundled products.
@@ -174,6 +179,10 @@ Yes. You can import grouped, affiliate/external products in addition to simple p
174
 
175
  == Changelog ==
176
 
 
 
 
 
177
  = 2.0.8 =
178
  * Fix: Product review import.
179
 
@@ -487,5 +496,6 @@ Yes. You can import grouped, affiliate/external products in addition to simple p
487
 
488
  == Upgrade Notice ==
489
 
490
- = 2.0.8 =
491
- * Fix: Product review import.
 
5
  Requires at least: 3.0.1
6
  Tested up to: 5.8
7
  Requires PHP: 5.6
8
+ Stable tag: 2.0.9
9
  License: GPLv3 or later
10
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
11
 
19
 
20
  ##Major Features##
21
 
22
+ * <strong>Export WooCommerce products into CSV</strong>.
23
+ * <strong>Import products from CSV</strong> to WooCommerce.
24
+ * Supported product types - <strong>simple, grouped, external/affiliate</strong>.
25
+ * Export and import <strong>products with images</strong>.
26
+ * Export and import <strong>product reviews</strong> along with ratings.
27
+ * Export and import <strong>products by category/tags/selected products/status</strong>.
28
+ * Export and import product <strong>attributes, taxonomies, price, stock, and more</strong>.
29
+ * <strong>Bulk edit products</strong>.
30
+
31
+ ##Additional Features##
32
+
33
+ * <strong>Import/export in batches</strong> with custom batch count.
34
+ * <strong>Set CSV delimiter</strong> for import.
35
+ * Select from <strong>multiple import/export methods</strong>.
36
+ * Export and import <strong>column mapping</strong>.
37
+ * Easy recurring import/exports using <strong>pre-saved configurations</strong>.
38
+ * <strong>List of all past imports and exports</strong> with option to re-run them.
39
+ * View <strong>import log</strong> for easy debugging.
40
+ * Tested OK with WooCommerce 5.7
41
+
42
+ ###Compatible Plugins###
43
+
44
+ * [Yoast WooCommerce SEO](https://wordpress.org/plugins/wordpress-seo/)
45
+ * [All-in-one SEO](https://wordpress.org/plugins/all-in-one-seo-pack/)
46
 
47
 
48
  ###Setup Guide - Product Import Export for WooCommerce###
69
 
70
  ✅ Export/Import simple, group, external, custom and variation product types.</li>
71
  ✅ Export/Import custom fields(meta) and hidden meta.</li>
 
72
  ✅ Choose from XML/CSV format for import/export.</li>
73
  ✅ <a href="https://www.webtoffee.com/product-import-export-for-woocommerce/#Step_3_Filter_d4">Various filter options for exporting products</a>
74
  ✅ <a href="https://www.webtoffee.com/product-import-export-for-woocommerce/#Step_3_Map_impo10">Map and transform fields during import</a>
86
 
87
  ## Product Import Export Plugin for WooCommerce (Pro) ##
88
 
89
+ Following are some of the use-cases supported by the Product Import Export for WooCommerce premium version.
 
90
 
91
  ### WooCommerce export products (all product types are supported) ###
92
  There are multiple cases where one needs to export WooCommerce products. It could be either for sending the details to someone else or integrating with a third-party system. With the plugin, you can import all product types including custom product types such as subscription and bundled products.
179
 
180
  == Changelog ==
181
 
182
+ = 2.0.9 =
183
+ * WC 5.7 tested OK.
184
+ * Product categories and tags export and import option added.
185
+
186
  = 2.0.8 =
187
  * Fix: Product review import.
188
 
496
 
497
  == Upgrade Notice ==
498
 
499
+ = 2.0.9 =
500
+ * WC 5.7 tested OK.
501
+ * Product categories and tags export and import option added.