CTX Feed – WooCommerce Product Feed Manager Plugin - Version 4.3.73

Version Description

(2021-04-23) = * Fixed: Google shipping price issue fixed.

Download this release

Release Info

Developer wahid0003
Plugin Icon 128x128 CTX Feed – WooCommerce Product Feed Manager Plugin
Version 4.3.73
Comparing to
See all releases

Code changes from version 4.3.72 to 4.3.73

README.txt CHANGED
@@ -5,7 +5,7 @@ Tags: Product Feed, WooCommerce, Google Shopping, Google Merchant, Facebook Cata
5
  Requires at least: 3.6
6
  Tested Up To: 5.7
7
  Requires PHP: 5.6
8
- Stable tag: 4.3.72
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
@@ -501,6 +501,9 @@ Using pro version:
501
 
502
  == Changelog ==
503
 
 
 
 
504
  = 4.3.72 (2021-04-22) =
505
  * Fixed: Output type updated, removed date format.
506
 
5
  Requires at least: 3.6
6
  Tested Up To: 5.7
7
  Requires PHP: 5.6
8
+ Stable tag: 4.3.73
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
501
 
502
  == Changelog ==
503
 
504
+ = 4.3.73 (2021-04-23) =
505
+ * Fixed: Google shipping price issue fixed.
506
+
507
  = 4.3.72 (2021-04-22) =
508
  * Fixed: Output type updated, removed date format.
509
 
includes/classes/class-woo-feed-shipping.php CHANGED
@@ -5,15 +5,15 @@ class Woo_Feed_Shipping {
5
  */
6
  private $product;
7
 
8
- /**
9
- * @var array $settings Contain plugin setting.
10
- */
11
- private $settings;
12
 
13
- /**
14
- * @var string $currency Currency sign like `USD`, `EUR`.
15
- */
16
- private $currency;
17
 
18
  /**
19
  * @var string $class_cost_id Shipping class cost id.
@@ -38,8 +38,8 @@ class Woo_Feed_Shipping {
38
  $this->class_cost_id = $this->set_shipping_class_id();
39
  $this->shipping_zones = $this->set_shipping_zone();
40
  $this->feed_country = $this->set_country();
41
- $this->settings = woo_feed_get_options( 'all' );
42
- $this->currency = $this->get_currency();
43
  }
44
 
45
 
@@ -47,39 +47,39 @@ class Woo_Feed_Shipping {
47
  return $this->config['feed_country'];
48
  }
49
 
50
- /**
51
- * Get current feed currency.
52
- *
53
- * @since 5.2.0
54
- * @author Nazrul Islam Nayan
55
- * @return string $currency feed currency
56
- */
57
  private function get_currency() {
58
- $currency = '';
59
- $mattributes = $this->config['mattributes'];
60
- $price_index = array_search('price', $mattributes);
61
- $sale_price_index = array_search('sale_price', $mattributes);
62
-
63
- //when feedCurrency is set to feed config setting, bring it or look at the prices suffix values.
64
- if ( isset($this->config['feedCurrency']) ) {
65
- $currency = $this->config['feedCurrency'];
66
- }else {
67
- if ( isset($price_index) && ! empty($price_index) ) {
68
- $currency = $this->config['suffix'][ $price_index ];
69
-
70
- //when price attribute's suffix value is empty, check and bring sale_price attribute's suffix value if exists.
71
- if ( empty($currency) && ! empty($sale_price_index) ) {
72
- $currency = $this->config['suffix'][ $sale_price_index ];
73
- }
74
- }
75
- }
76
-
77
- return $currency;
78
- }
79
 
80
  private function set_shipping_class_id() {
81
  $class_cost_id = "class_cost_" . $this->product->get_shipping_class_id();
82
- if ( $class_cost_id == "class_cost_0" ) {
83
  return 'no_class_cost';
84
  }
85
 
@@ -87,31 +87,31 @@ class Woo_Feed_Shipping {
87
  }
88
 
89
  public function set_shipping_zone() {
90
- if ( class_exists( 'WC_Shipping_Zones' ) ) {
91
- return WC_Shipping_Zones::get_zones();
92
- }
93
- return false;
94
  }
95
 
96
- /**
97
- * Get shipping information.
98
- *
99
- * @since 5.2.0
100
- * @return array $shipping_info shipping information
101
- */
102
  public function get_shipping() {
103
  $shipping_info = [];
104
 
105
  foreach ( $this->shipping_zones as $zone ) {
106
  $shipping = [];
107
  foreach ( $zone['zone_locations'] as $zone_type ) {
108
- if ( $zone_type->type == "country" ) {
109
  // This is a country shipping zone
110
  $shipping['country'] = $zone_type->code;
111
- } elseif ( $zone_type->type == "code" ) {
112
  // This is a country shipping zone
113
  $shipping['country'] = $zone_type->code;
114
- } elseif ( $zone_type->type == "state" ) {
115
  // This is a state shipping zone, split of country
116
  $zone_explode = explode( ":", $zone_type->code );
117
  $shipping['country'] = $zone_explode[0];
@@ -120,39 +120,39 @@ class Woo_Feed_Shipping {
120
  $region_countries = array( 'US', 'JP', 'AU' );
121
  $shipping['region'] = $zone_explode[1];
122
 
123
- } elseif ( $zone_type->type == "postcode" ) {
124
  // Create an array of postal codes so we can loop over it later
125
  $zone_type->code = str_replace( "...", "-", $zone_type->code );
126
- $shipping['postal_code'] = $zone_type->code;
 
 
127
  }
128
 
129
- //when allow_all_shipping is disabled and feed country doesn't match shipping country then skip the shipping method
130
- if ( isset($this->settings) && is_array($this->settings) ) {
131
- if ( array_key_exists('allow_all_shipping', $this->settings) ) {
132
- $all_country_shipping = $this->settings['allow_all_shipping'];
133
- if ( ! empty($all_country_shipping) && 'no' === $all_country_shipping ) {
134
- if ( $shipping['country'] !== $this->feed_country ) {
135
- unset($shipping);
136
- continue 2;
137
- }
138
- }
139
- }
140
- }
141
 
142
 
143
  $shipping_methods = $zone['shipping_methods'];
144
 
145
- // Continue loop if no shipping method defined.
146
- if ( empty($shipping_methods) ) {
147
- unset($shipping);
148
- continue 2;
149
- }
150
 
151
 
152
  foreach ( $shipping_methods as $method ) {
153
  if ( 'yes' === $method->enabled ) {
154
 
155
- //when only_free_shipping is enabled and shipping is not free shipping then skip the shipping method
156
  // if( isset($this->settings) && is_array($this->settings) ) {
157
  // if( array_key_exists('only_free_shipping', $this->settings) ) {
158
  // $only_free_shipping = $this->settings['only_free_shipping'];
@@ -195,45 +195,43 @@ class Woo_Feed_Shipping {
195
  $shipping['service'] = $zone['zone_name'] . " " . $method->title . " " . $shipping['country'];
196
  }
197
 
198
- //when only_local_pickup_shipping is disabled then skip the local pickup method
199
- if ( $method->id === "local_pickup" ) {
200
- if ( isset($this->settings) && is_array($this->settings) ) {
201
- if ( array_key_exists('only_local_pickup_shipping', $this->settings) ) {
202
- $allow_local_pickup = $this->settings['only_local_pickup_shipping'];
203
- if ( ! empty($allow_local_pickup) && 'no' === $allow_local_pickup ) {
204
- unset( $shipping );
205
- continue 3;
206
- }
207
- }
208
- }
209
- }
210
  }else {
211
- unset( $shipping );
212
- continue 3;
213
- }
214
 
 
 
215
 
216
- if ( 'free_shipping' !== $method->id ) {
217
- $shipping_cost = $this->get_shipping_cost($shipping);
218
- $shipping['price'] = (string) $shipping_cost;
219
- }
220
- }
221
  $shipping_info[] = $shipping;
222
  }
223
  }
224
 
225
- return $shipping_info;
226
  }
227
 
228
 
229
- /**
230
- * Get shipping cost.
231
- *
232
- * @param $shipping array shipping information
233
- *
234
- * @since 5.2.0
235
- * @return mixed $shipping_cost shipping cost
236
- */
237
  private function get_shipping_cost( $shipping ) {
238
  // Set shipping cost
239
  $shipping_cost = 0;
@@ -277,13 +275,13 @@ class Woo_Feed_Shipping {
277
  return $shipping_cost;
278
  }
279
 
280
- /**
281
- * Get lowest shipping price.
282
- *
283
- * @since 5.2.0
284
- * @author Nazrul Islam Nayan
285
- * @return mixed
286
- */
287
  public function get_lowest_shipping_price() {
288
  if ( empty($this->get_shipping()) ) {
289
  return '0';
@@ -292,216 +290,227 @@ class Woo_Feed_Shipping {
292
  return min( wp_list_pluck( $this->get_shipping(), 'price' ) );
293
  }
294
 
295
- /**
296
- * Get highest shipping price.
297
- *
298
- * @since 5.2.0
299
- * @author Nazrul Islam Nayan
300
- * @return mixed
301
- */
302
  public function get_highest_shipping_price() {
303
  return max( wp_list_pluck( $this->get_shipping(), 'price' ) );
304
  }
305
 
306
- /**
307
- * Get first shipping price.
308
- *
309
- * @since 5.2.0
310
- * @author Nazrul Islam Nayan
311
- * @return mixed
312
- */
313
  public function get_first_shipping_price() {
314
  $shipping_prices = wp_list_pluck( $this->get_shipping(), 'price' );
315
 
316
  return reset( $shipping_prices );
317
  }
318
 
319
- /**
320
- * Get google shipping feed structure for XML/CSV feed type.
321
- *
322
- * @since 5.2.0
323
- * @author Nazrul Islam Nayan
324
- * @return string $feedBody shipping feed structure
325
- */
326
- public function get_google_shipping() {
327
- $shipping_arr = $this->get_shipping();
328
- $feedBody = "";
329
-
330
- if ( "xml" === $this->config['feedType'] ) {
331
- $shipping_label = 'g:shipping';
332
-
333
- if ( isset($shipping_arr) && is_array($shipping_arr) ) {
334
- $feedBody .= "<$shipping_label>"; //start shipping label
335
- $i = 0;
336
- $len = count($shipping_arr);
337
-
338
- foreach ( $shipping_arr as $k => $shipping_item ) {
339
- $shipping_child = '';
340
- foreach ( $shipping_item as $shipping_item_attr => $shipping_value ) {
341
- if ( "price" === $shipping_item_attr ) {
342
- $shipping_value = $shipping_value . ' ' . $this->currency;
343
- }
344
-
345
- $shipping_child .= '<g:' . $shipping_item_attr . '>' . $shipping_value . '</g:' . $shipping_item_attr . '>';
346
- $shipping_child = stripslashes( $shipping_child );
347
- }
348
-
349
- // when loop is in last ride skip inserting labels, as it insert label with empty value
350
- $feedBody .= "$shipping_child";
351
- if ( isset($shipping_child) && ! empty($shipping_child) && $i !== $len - 1 ) {
352
- $feedBody .= "</$shipping_label>";
353
- $feedBody .= "\n";
354
- $feedBody .= "<$shipping_label>";
355
- }
356
-
357
- unset($shipping_child); //unset for not to join all item together
358
- $i++;
359
- }
360
-
361
- $feedBody .= "</$shipping_label>"; //end shipping label
362
- $feedBody .= "\n";
363
- }
364
- }elseif ( in_array($this->config['feedType'], [ 'csv', 'tsv', 'xls' ]) ) {
365
-
366
- if ( isset($shipping_arr) && is_array($shipping_arr) ) {
367
- foreach ( $shipping_arr as $k => $shipping_item ) {
368
- $shipping_child = '';
369
- foreach ( $shipping_item as $shipping_item_attr => $shipping_value ) {
370
- if ( "price" === $shipping_item_attr ) {
371
- $shipping_value = $shipping_value . ' ' . $this->currency;
372
- }
373
-
374
- if ( "postal_code" !== $shipping_item_attr ) {
375
- $shipping_child .= $shipping_value . ":";
376
- }
377
- }
378
- $shipping_child = trim( $shipping_child, ":" );
379
-
380
- //add separator for multiple shipping method
381
- $feedBody .= $shipping_child . '||';
382
- }
383
-
384
- //trim last extra sign
385
- $feedBody = trim($feedBody, '||');
386
- }
387
- }
388
-
389
- return $feedBody;
390
- }
391
-
392
-
393
- /**
394
- * Get google tax feed structure for XML/CSV feed type.
395
- *
396
- * @since 5.2.0
397
- * @author Nazrul Islam Nayan
398
- * @return string $feedBody tax feed structure
399
- */
400
- public function get_google_tax() {
401
- $feedBody = "";
402
- $tax_rates = $this->get_tax_rates();
403
-
404
- if ( "xml" === $this->config['feedType'] ) {
405
- if ( isset($tax_rates) && is_array($tax_rates) ) {
406
- $tax_label = "g:tax";
407
- $feedBody .= "<$tax_label>"; //start tax label
408
- $i = 0;
409
- $len = count($tax_rates);
410
-
411
- foreach ( $tax_rates as $k => $tax_item ) {
412
- $tax_child = '';
413
- foreach ( $tax_item as $tax_item_attr => $tax_value ) {
414
- if ( "rate" === $tax_item_attr ) {
415
- $tax_value = $tax_value . ' ' . $this->currency;
416
- }
417
-
418
- $tax_child .= '<' . $tax_item_attr . '>' . "$tax_value" . '</' . $tax_item_attr . '>';
419
- $tax_child = stripslashes( $tax_child );
420
- }
421
-
422
- // Strip slash from output
423
- // when loop is in last ride skip inserting labels, as it insert label with empty value
424
- $feedBody .= "$tax_child";
425
- if ( isset($tax_child) && ! empty($tax_child) && $i !== $len - 1 ) {
426
- $feedBody .= "</$tax_label>";
427
- $feedBody .= "\n";
428
- $feedBody .= "<$tax_label>";
429
- }
430
-
431
- unset($tax_child); //unset for not to join all item together
432
- $i++;
433
- }
434
-
435
- $feedBody .= "</$tax_label>"; //end tax label
436
- $feedBody .= "\n";
437
-
438
- }
439
- }elseif ( in_array($this->config['feedType'], [ 'csv', 'tsv', 'xls' ]) ) {
440
- if ( isset($tax_rates) && is_array($tax_rates) ) {
441
- foreach ( $tax_rates as $k => $tax_item ) {
442
- $tax_child = '';
443
- foreach ( $tax_item as $tax_item_attr => $tax_value ) {
444
- if ( "rate" === $tax_item_attr ) {
445
- $tax_value = $tax_value . ' ' . $this->currency;
446
- }
447
-
448
- if ( "postal_code" !== $tax_item_attr ) {
449
- $tax_value = ! empty($tax_value) ? $tax_value : '';
450
- $tax_child .= $tax_value . ":";
451
- }
452
- }
453
- $tax_child = trim( $tax_child, ":" );
454
-
455
- //add separator for multiple tax
456
- $feedBody .= $tax_child . '||';
457
- }
458
-
459
- //trim last extra sign
460
- $feedBody = trim($feedBody, '||');
461
- }
462
- }
463
-
464
- return $feedBody;
465
- }
466
-
467
- /**
468
- * Get tax rates.
469
- *
470
- * @since 5.2.0
471
- * @return mixed
472
- */
473
- public function get_tax_rates() {
474
- // Skip if product is not taxable.
475
- if ( ! $this->product->is_taxable() ) {
476
- return "";
477
- }
478
-
479
- $all_tax_rates = [];
480
- $formatted_rates = [];
481
-
482
- // Retrieve all tax classes.
483
- $tax_classes = WC_Tax::get_tax_classes();
484
-
485
- // Make sure "Standard rate" (empty class name) is present.
486
- if ( ! in_array('', $tax_classes) ) {
487
- array_unshift($tax_classes, '');
488
- }
489
-
490
- // For each tax class, get all rates.
491
- foreach ( $tax_classes as $tax_class ) {
492
- $taxes = WC_Tax::get_rates_for_tax_class($tax_class);
493
- $all_tax_rates = array_merge($all_tax_rates, $taxes);
494
- }
495
-
496
- if ( ! empty($all_tax_rates) ) {
497
- foreach ( $all_tax_rates as $rate_key => $rate ) {
498
- $formatted_rates[ $rate_key ]['country'] = $rate->tax_rate_country;
499
- $formatted_rates[ $rate_key ]['region'] = $rate->tax_rate_state;
500
- $formatted_rates[ $rate_key ]['rate'] = $rate->tax_rate;
501
- $formatted_rates[ $rate_key ]['tax_ship'] = ($rate->tax_rate_shipping) ? 'yes' : 'no';
502
- }
503
- }
504
-
505
- return $formatted_rates;
506
- }
 
 
 
 
 
 
 
 
 
 
 
507
  }
5
  */
6
  private $product;
7
 
8
+ /**
9
+ * @var array $settings Contain plugin setting.
10
+ */
11
+ private $settings;
12
 
13
+ /**
14
+ * @var string $currency Currency sign like `USD`, `EUR`.
15
+ */
16
+ private $currency;
17
 
18
  /**
19
  * @var string $class_cost_id Shipping class cost id.
38
  $this->class_cost_id = $this->set_shipping_class_id();
39
  $this->shipping_zones = $this->set_shipping_zone();
40
  $this->feed_country = $this->set_country();
41
+ $this->settings = woo_feed_get_options( 'all' );
42
+ $this->currency = $this->get_currency();
43
  }
44
 
45
 
47
  return $this->config['feed_country'];
48
  }
49
 
50
+ /**
51
+ * Get current feed currency.
52
+ *
53
+ * @since 5.2.0
54
+ * @author Nazrul Islam Nayan
55
+ * @return string $currency feed currency
56
+ */
57
  private function get_currency() {
58
+ $currency = '';
59
+ $mattributes = $this->config['mattributes'];
60
+ $price_index = array_search('price', $mattributes);
61
+ $sale_price_index = array_search('sale_price', $mattributes);
62
+
63
+ //when feedCurrency is set to feed config setting, bring it or look at the prices suffix values.
64
+ if ( isset($this->config['feedCurrency']) ) {
65
+ $currency = $this->config['feedCurrency'];
66
+ }else {
67
+ if ( isset($price_index) && ! empty($price_index) ) {
68
+ $currency = $this->config['suffix'][ $price_index ];
69
+
70
+ //when price attribute's suffix value is empty, check and bring sale_price attribute's suffix value if exists.
71
+ if ( empty($currency) && ! empty($sale_price_index) ) {
72
+ $currency = $this->config['suffix'][ $sale_price_index ];
73
+ }
74
+ }
75
+ }
76
+
77
+ return $currency;
78
+ }
79
 
80
  private function set_shipping_class_id() {
81
  $class_cost_id = "class_cost_" . $this->product->get_shipping_class_id();
82
+ if ( "class_cost_0" == $class_cost_id ) {
83
  return 'no_class_cost';
84
  }
85
 
87
  }
88
 
89
  public function set_shipping_zone() {
90
+ if ( class_exists( 'WC_Shipping_Zones' ) ) {
91
+ return WC_Shipping_Zones::get_zones();
92
+ }
93
+ return false;
94
  }
95
 
96
+ /**
97
+ * Get shipping information.
98
+ *
99
+ * @since 5.2.0
100
+ * @return array $shipping_info shipping information
101
+ */
102
  public function get_shipping() {
103
  $shipping_info = [];
104
 
105
  foreach ( $this->shipping_zones as $zone ) {
106
  $shipping = [];
107
  foreach ( $zone['zone_locations'] as $zone_type ) {
108
+ if ( "country" == $zone_type->type ) {
109
  // This is a country shipping zone
110
  $shipping['country'] = $zone_type->code;
111
+ } elseif ( "code" == $zone_type->type ) {
112
  // This is a country shipping zone
113
  $shipping['country'] = $zone_type->code;
114
+ } elseif ( "state" == $zone_type->type ) {
115
  // This is a state shipping zone, split of country
116
  $zone_explode = explode( ":", $zone_type->code );
117
  $shipping['country'] = $zone_explode[0];
120
  $region_countries = array( 'US', 'JP', 'AU' );
121
  $shipping['region'] = $zone_explode[1];
122
 
123
+ } elseif ( "postcode" == $zone_type->type ) {
124
  // Create an array of postal codes so we can loop over it later
125
  $zone_type->code = str_replace( "...", "-", $zone_type->code );
126
+ if ( empty($shipping['region']) ) {
127
+ $shipping['postal_code'] = $zone_type->code;
128
+ }
129
  }
130
 
131
+ //when allow_all_shipping is disabled and feed country doesn't match shipping country then skip the shipping method
132
+ if ( isset($this->settings) && is_array($this->settings) ) {
133
+ if ( array_key_exists('allow_all_shipping', $this->settings) ) {
134
+ $all_country_shipping = $this->settings['allow_all_shipping'];
135
+ if ( 'no' === $all_country_shipping && $shipping['country'] !== $this->feed_country ) {
136
+ unset($shipping);
137
+ continue 2;
138
+ }
139
+ }
140
+ }
 
 
141
 
142
 
143
  $shipping_methods = $zone['shipping_methods'];
144
 
145
+ // Continue loop if no shipping method defined.
146
+ if ( empty($shipping_methods) ) {
147
+ unset($shipping);
148
+ continue 2;
149
+ }
150
 
151
 
152
  foreach ( $shipping_methods as $method ) {
153
  if ( 'yes' === $method->enabled ) {
154
 
155
+ //when only_free_shipping is enabled and shipping is not free shipping then skip the shipping method
156
  // if( isset($this->settings) && is_array($this->settings) ) {
157
  // if( array_key_exists('only_free_shipping', $this->settings) ) {
158
  // $only_free_shipping = $this->settings['only_free_shipping'];
195
  $shipping['service'] = $zone['zone_name'] . " " . $method->title . " " . $shipping['country'];
196
  }
197
 
198
+ //when only_local_pickup_shipping is disabled then skip the local pickup method
199
+ if ( "local_pickup" === $method->id ) {
200
+ if ( isset($this->settings) && is_array($this->settings) ) {
201
+ if ( array_key_exists('only_local_pickup_shipping', $this->settings) ) {
202
+ $allow_local_pickup = $this->settings['only_local_pickup_shipping'];
203
+ if ( ! empty($allow_local_pickup) && 'no' === $allow_local_pickup ) {
204
+ unset( $shipping );
205
+ continue 3;
206
+ }
207
+ }
208
+ }
209
+ }
210
  }else {
211
+ unset( $shipping );
212
+ continue 3;
213
+ }
214
 
215
+ $shipping_cost = $this->get_shipping_cost($shipping);
216
+ $shipping['price'] = $shipping_cost;
217
 
218
+ }
 
 
 
 
219
  $shipping_info[] = $shipping;
220
  }
221
  }
222
 
223
+ return $shipping_info;
224
  }
225
 
226
 
227
+ /**
228
+ * Get shipping cost.
229
+ *
230
+ * @param $shipping array shipping information
231
+ *
232
+ * @since 5.2.0
233
+ * @return mixed $shipping_cost shipping cost
234
+ */
235
  private function get_shipping_cost( $shipping ) {
236
  // Set shipping cost
237
  $shipping_cost = 0;
275
  return $shipping_cost;
276
  }
277
 
278
+ /**
279
+ * Get lowest shipping price.
280
+ *
281
+ * @since 5.2.0
282
+ * @author Nazrul Islam Nayan
283
+ * @return mixed
284
+ */
285
  public function get_lowest_shipping_price() {
286
  if ( empty($this->get_shipping()) ) {
287
  return '0';
290
  return min( wp_list_pluck( $this->get_shipping(), 'price' ) );
291
  }
292
 
293
+ /**
294
+ * Get highest shipping price.
295
+ *
296
+ * @since 5.2.0
297
+ * @author Nazrul Islam Nayan
298
+ * @return mixed
299
+ */
300
  public function get_highest_shipping_price() {
301
  return max( wp_list_pluck( $this->get_shipping(), 'price' ) );
302
  }
303
 
304
+ /**
305
+ * Get first shipping price.
306
+ *
307
+ * @since 5.2.0
308
+ * @author Nazrul Islam Nayan
309
+ * @return mixed
310
+ */
311
  public function get_first_shipping_price() {
312
  $shipping_prices = wp_list_pluck( $this->get_shipping(), 'price' );
313
 
314
  return reset( $shipping_prices );
315
  }
316
 
317
+ /**
318
+ * Get google shipping feed structure for XML/CSV feed type.
319
+ *
320
+ * @since 5.2.0
321
+ * @author Nazrul Islam Nayan
322
+ * @return string $feedBody shipping feed structure
323
+ */
324
+ public function get_google_shipping() {
325
+ $shipping_arr = $this->get_shipping();
326
+ $feedBody = "";
327
+
328
+ if ( "xml" === $this->config['feedType'] ) {
329
+ $shipping_label = 'g:shipping';
330
+
331
+ if ( isset($shipping_arr) && is_array($shipping_arr) ) {
332
+ $feedBody .= "<$shipping_label>"; //start shipping label
333
+ $i = 0;
334
+ $len = count($shipping_arr);
335
+
336
+ foreach ( $shipping_arr as $k => $shipping_item ) {
337
+ $shipping_child = '';
338
+ foreach ( $shipping_item as $shipping_item_attr => $shipping_value ) {
339
+ if ( "price" === $shipping_item_attr ) {
340
+
341
+ if ( isset( $this->config['feedCurrency'] ) && get_woocommerce_currency() !== $this->config['feedCurrency'] ) {
342
+ $shipping_value = woo_feed_get_wcml_price( $this->product->get_id(), $this->config['feedCurrency'], $shipping_value );
343
+ }
344
+
345
+ $shipping_value .= ' ' . $this->currency;
346
+ }
347
+
348
+ $shipping_child .= '<g:' . $shipping_item_attr . '>' . $shipping_value . '</g:' . $shipping_item_attr . '>';
349
+ $shipping_child = stripslashes( $shipping_child );
350
+ }
351
+
352
+ // when loop is in last ride skip inserting labels, as it insert label with empty value
353
+ $feedBody .= "$shipping_child";
354
+ if ( isset($shipping_child) && ! empty($shipping_child) && $i !== $len - 1 ) {
355
+ $feedBody .= "</$shipping_label>";
356
+ $feedBody .= "\n";
357
+ $feedBody .= "<$shipping_label>";
358
+ }
359
+
360
+ unset($shipping_child); //unset for not to join all item together
361
+ $i++;
362
+ }
363
+
364
+ $feedBody .= "</$shipping_label>"; //end shipping label
365
+ $feedBody .= "\n";
366
+ }
367
+ }elseif ( in_array($this->config['feedType'], [ 'csv', 'tsv', 'xls' ]) ) {
368
+
369
+ if ( isset($shipping_arr) && is_array($shipping_arr) ) {
370
+ foreach ( $shipping_arr as $k => $shipping_item ) {
371
+ $shipping_child = '';
372
+ foreach ( $shipping_item as $shipping_item_attr => $shipping_value ) {
373
+ if ( "price" === $shipping_item_attr ) {
374
+
375
+ if ( isset( $this->config['feedCurrency'] ) && get_woocommerce_currency() != $this->config['feedCurrency'] ) {
376
+ $shipping_value = woo_feed_get_wcml_price( $this->product->get_id(), $this->config['feedCurrency'], $shipping_value );
377
+ }
378
+
379
+ $shipping_value = $shipping_value . ' ' . $this->currency;
380
+ }
381
+
382
+ if ( "postal_code" !== $shipping_item_attr ) {
383
+ $shipping_child .= $shipping_value . ":";
384
+ }
385
+ }
386
+ $shipping_child = trim( $shipping_child, ":" );
387
+
388
+ //add separator for multiple shipping method
389
+ $feedBody .= $shipping_child . '||';
390
+ }
391
+
392
+ //trim last extra sign
393
+ $feedBody = trim($feedBody, '||');
394
+ }
395
+ }
396
+
397
+ return $feedBody;
398
+ }
399
+
400
+
401
+ /**
402
+ * Get google tax feed structure for XML/CSV feed type.
403
+ *
404
+ * @since 5.2.0
405
+ * @author Nazrul Islam Nayan
406
+ * @return string $feedBody tax feed structure
407
+ */
408
+ public function get_google_tax() {
409
+ $feedBody = "";
410
+ $tax_rates = $this->get_tax_rates();
411
+
412
+ if ( "xml" === $this->config['feedType'] ) {
413
+ if ( isset($tax_rates) && is_array($tax_rates) ) {
414
+ $tax_label = "g:tax";
415
+ $feedBody .= "<$tax_label>"; //start tax label
416
+ $i = 0;
417
+ $len = count($tax_rates);
418
+
419
+ foreach ( $tax_rates as $k => $tax_item ) {
420
+ $tax_child = '';
421
+ foreach ( $tax_item as $tax_item_attr => $tax_value ) {
422
+ if ( "rate" === $tax_item_attr ) {
423
+
424
+ if ( isset( $this->config['feedCurrency'] ) && get_woocommerce_currency() != $this->config['feedCurrency'] ) {
425
+ $tax_value = woo_feed_get_wcml_price( $this->product->get_id(), $this->config['feedCurrency'], $tax_value );
426
+ }
427
+
428
+ $tax_value = $tax_value . ' ' . $this->currency;
429
+ }
430
+
431
+ $tax_child .= '<' . $tax_item_attr . '>' . "$tax_value" . '</' . $tax_item_attr . '>';
432
+ $tax_child = stripslashes( $tax_child );
433
+ }
434
+
435
+ // Strip slash from output
436
+ // when loop is in last ride skip inserting labels, as it insert label with empty value
437
+ $feedBody .= "$tax_child";
438
+ if ( isset($tax_child) && ! empty($tax_child) && $i !== $len - 1 ) {
439
+ $feedBody .= "</$tax_label>";
440
+ $feedBody .= "\n";
441
+ $feedBody .= "<$tax_label>";
442
+ }
443
+
444
+ unset($tax_child); //unset for not to join all item together
445
+ $i++;
446
+ }
447
+
448
+ $feedBody .= "</$tax_label>"; //end tax label
449
+ $feedBody .= "\n";
450
+
451
+ }
452
+ }elseif ( in_array($this->config['feedType'], [ 'csv', 'tsv', 'xls' ]) ) {
453
+ if ( isset($tax_rates) && is_array($tax_rates) ) {
454
+ foreach ( $tax_rates as $k => $tax_item ) {
455
+ $tax_child = '';
456
+ foreach ( $tax_item as $tax_item_attr => $tax_value ) {
457
+ if ( "postal_code" !== $tax_item_attr ) {
458
+ $tax_value = ! empty($tax_value) ? $tax_value : '';
459
+ $tax_child .= $tax_value . ":";
460
+ }
461
+ }
462
+ $tax_child = trim( $tax_child, ":" );
463
+
464
+ //add separator for multiple tax
465
+ $feedBody .= $tax_child . '||';
466
+ }
467
+
468
+ //trim last extra sign
469
+ $feedBody = trim($feedBody, '||');
470
+ }
471
+ }
472
+
473
+ return $feedBody;
474
+ }
475
+
476
+ /**
477
+ * Get tax rates.
478
+ *
479
+ * @since 5.2.0
480
+ * @return mixed
481
+ */
482
+ public function get_tax_rates() {
483
+ // Skip if product is not taxable.
484
+ if ( ! $this->product->is_taxable() ) {
485
+ return "";
486
+ }
487
+
488
+ $all_tax_rates = [];
489
+ $formatted_rates = [];
490
+
491
+ // Retrieve all tax classes.
492
+ $tax_classes = WC_Tax::get_tax_classes();
493
+
494
+ // Make sure "Standard rate" (empty class name) is present.
495
+ if ( ! in_array('', $tax_classes) ) {
496
+ array_unshift($tax_classes, '');
497
+ }
498
+
499
+ // For each tax class, get all rates.
500
+ foreach ( $tax_classes as $tax_class ) {
501
+ $taxes = WC_Tax::get_rates_for_tax_class($tax_class);
502
+ $all_tax_rates = array_merge($all_tax_rates, $taxes);
503
+ }
504
+
505
+ if ( ! empty($all_tax_rates) ) {
506
+ foreach ( $all_tax_rates as $rate_key => $rate ) {
507
+ $formatted_rates[ $rate_key ]['country'] = $rate->tax_rate_country;
508
+ $formatted_rates[ $rate_key ]['region'] = $rate->tax_rate_state;
509
+ $formatted_rates[ $rate_key ]['rate'] = $rate->tax_rate;
510
+ $formatted_rates[ $rate_key ]['tax_ship'] = ($rate->tax_rate_shipping) ? 'yes' : 'no';
511
+ }
512
+ }
513
+
514
+ return $formatted_rates;
515
+ }
516
  }
woo-feed.php CHANGED
@@ -10,7 +10,7 @@
10
  * Plugin Name: CTX Feed
11
  * Plugin URI: https://webappick.com/
12
  * Description: Easily generate woocommerce product feed for any marketing channel like Google Shopping(Merchant), Facebook Remarketing, Bing, eBay & more. Support 100+ Merchants.
13
- * Version: 4.3.72
14
  * Author: WebAppick
15
  * Author URI: https://webappick.com/
16
  * License: GPL v2
@@ -39,7 +39,7 @@ if ( ! defined( 'WOO_FEED_FREE_VERSION' ) ) {
39
  * @var string
40
  * @since 3.1.6
41
  */
42
- define( 'WOO_FEED_FREE_VERSION', '4.3.72' );
43
  }
44
 
45
  if ( ! defined( 'WOO_FEED_FREE_FILE' ) ) {
10
  * Plugin Name: CTX Feed
11
  * Plugin URI: https://webappick.com/
12
  * Description: Easily generate woocommerce product feed for any marketing channel like Google Shopping(Merchant), Facebook Remarketing, Bing, eBay & more. Support 100+ Merchants.
13
+ * Version: 4.3.73
14
  * Author: WebAppick
15
  * Author URI: https://webappick.com/
16
  * License: GPL v2
39
  * @var string
40
  * @since 3.1.6
41
  */
42
+ define( 'WOO_FEED_FREE_VERSION', '4.3.73' );
43
  }
44
 
45
  if ( ! defined( 'WOO_FEED_FREE_FILE' ) ) {