CTX Feed – WooCommerce Product Feed Manager Plugin - Version 2.2.9

Version Description

Download this release

Release Info

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

Code changes from version 2.2.8 to 2.2.9

README.txt CHANGED
@@ -270,6 +270,10 @@ Using pro version:
270
 
271
  == Changelog ==
272
 
 
 
 
 
273
  = 2.2.8(2018-03-14) =
274
  * Variable product price issue fixed
275
  * Other minor issues about product are fixed
270
 
271
  == Changelog ==
272
 
273
+ = 2.2.9(2018-03-23) =
274
+ * Product missing issue fixed
275
+ * Auto update active/inactive status added
276
+
277
  = 2.2.8(2018-03-14) =
278
  * Variable product price issue fixed
279
  * Other minor issues about product are fixed
admin/class-woo-feed-manage-list.php CHANGED
@@ -64,33 +64,44 @@ class Woo_Feed_Manage_list extends Woo_Feed_List_Table
64
  * @param array $column_name The name/slug of the column to be processed
65
  * @return string Text or HTML to be placed inside the column <td>
66
  **************************************************************************/
67
- function column_default($item, $column_name)
68
- {
69
- $getItem = $item['option_name'];
70
- $itemInfo = unserialize(get_option($getItem));
71
- global $wpdb, $table_prefix;
72
- switch ($column_name) {
73
- case 'option_name':
74
- $name = $item[$column_name];
75
- return str_replace("wf_feed_", "", $name);
76
- case 'provider':
77
- $provider = $itemInfo['feedrules']['provider'];
78
- return ucwords(str_replace("_", " ", $provider));
79
- case 'type':
80
- $feedType = $itemInfo['feedrules']['feedType'];
81
- return strtoupper(str_replace("_", " ", $feedType));
82
- case 'url':
83
- return $itemInfo[$column_name];
84
- case 'last_updated':
85
- return $itemInfo[$column_name];
86
- case 'view':
87
- $view = $itemInfo['url'];
88
- return "<a target='_blank' class='button' href='$view'>" . __('View') . "</a>&nbsp;<input type='button' value=" . __('Regenerate') . " id='$getItem' class='button wpf_regenerate'>&nbsp;<a target='_blank' class='button' href='$view' download>" . __('Download') . "</a>";
89
- default:
90
- return false;
91
- //return print_r($item, true); //Show the whole array for troubleshooting purposes
92
- }
93
- }
 
 
 
 
 
 
 
 
 
 
 
94
 
95
 
96
  /** ************************************************************************
@@ -247,6 +258,7 @@ class Woo_Feed_Manage_list extends Woo_Feed_List_Table
247
  {
248
  $columns = array(
249
  'cb' => '<input type="checkbox" />', //Render a checkbox instead of text
 
250
  'option_name' => __('File Name'),
251
  'provider' => __('Provider'),
252
  'type' => __('Type'),
64
  * @param array $column_name The name/slug of the column to be processed
65
  * @return string Text or HTML to be placed inside the column <td>
66
  **************************************************************************/
67
+ function column_default($item, $column_name)
68
+ {
69
+ $getItem = $item['option_name'];
70
+ $statusId=$item['option_id'];
71
+ $itemInfo = unserialize(get_option($getItem));
72
+
73
+
74
+ global $wpdb, $table_prefix;
75
+ switch ($column_name) {
76
+ case 'option_name':
77
+ $name = $item[$column_name];
78
+ return str_replace("wf_feed_", "", $name);
79
+ case 'status':
80
+ if(!isset($itemInfo['status']) || $itemInfo['status'] == 1){
81
+ return ' <div class="wf_status_wrap"><input style="display: none;" data-index='.$statusId.' id='.$statusId.' checked class="woo_feed_status_input" type="checkbox" value="'.$getItem.'"/>
82
+ <label for='.$statusId.' class= "woo-feed_active_status"></label></div>';
83
+ }else{
84
+ return ' <div class="wf_status_wrap"> <input style="display: none;" data-index='.$statusId.' id='.$statusId.' class="woo_feed_status_input" type="checkbox" value="'.$getItem.'"/>
85
+ <label for='.$statusId.' class= "woo-feed_active_status"></label> </div>';
86
+ }
87
+ case 'provider':
88
+ $provider = $itemInfo['feedrules']['provider'];
89
+ return ucwords(str_replace("_", " ", $provider));
90
+ case 'type':
91
+ $feedType = $itemInfo['feedrules']['feedType'];
92
+ return strtoupper(str_replace("_", " ", $feedType));
93
+ case 'url':
94
+ return $itemInfo[$column_name];
95
+ case 'last_updated':
96
+ return $itemInfo[$column_name];
97
+ case 'view':
98
+ $view = $itemInfo['url'];
99
+ return "<a target='_blank' class='button' href='$view'>" . __('View') . "</a>&nbsp;<input type='button' id='$getItem' value=".__('Regenerate')." class='button wpf_regenerate'>&nbsp;<a target='_blank' class='button' href='$view' download>" . __('Download') . "</a>";
100
+ default:
101
+ return false;
102
+ //return print_r($item, true); //Show the whole array for troubleshooting purposes
103
+ }
104
+ }
105
 
106
 
107
  /** ************************************************************************
258
  {
259
  $columns = array(
260
  'cb' => '<input type="checkbox" />', //Render a checkbox instead of text
261
+ 'status' => __('Status'),
262
  'option_name' => __('File Name'),
263
  'provider' => __('Provider'),
264
  'type' => __('Type'),
admin/css/woo-feed-admin.css CHANGED
@@ -34,8 +34,8 @@
34
  background-image: -ms-linear-gradient(top, #3498db, #2980b9);
35
  background-image: -o-linear-gradient(top, #3498db, #2980b9);
36
  background-image: linear-gradient(to bottom, #3498db, #2980b9);
37
- -webkit-border-radius: 17;
38
- -moz-border-radius: 17;
39
  border-radius: 17px;
40
  -webkit-box-shadow: 0px 1px 3px #666666;
41
  -moz-box-shadow: 0px 1px 3px #666666;
@@ -55,7 +55,7 @@
55
  border-radius:5px;
56
  padding:10px;
57
  color:#fff;
58
- font-size:12px Arial;
59
  }
60
  .wfbtn:hover {
61
  background: #3cb0fd;
@@ -334,3 +334,36 @@ p {
334
  font-size: 14px;
335
  color: #32373c;
336
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34
  background-image: -ms-linear-gradient(top, #3498db, #2980b9);
35
  background-image: -o-linear-gradient(top, #3498db, #2980b9);
36
  background-image: linear-gradient(to bottom, #3498db, #2980b9);
37
+ -webkit-border-radius: 17px;
38
+ -moz-border-radius: 17px;
39
  border-radius: 17px;
40
  -webkit-box-shadow: 0px 1px 3px #666666;
41
  -moz-box-shadow: 0px 1px 3px #666666;
55
  border-radius:5px;
56
  padding:10px;
57
  color:#fff;
58
+ font-size:12px;
59
  }
60
  .wfbtn:hover {
61
  background: #3cb0fd;
334
  font-size: 14px;
335
  color: #32373c;
336
  }
337
+
338
+ /* Feed active and inactive button CSS */
339
+ .wf_status_wrap label{
340
+ width:50px;
341
+ height:25px;
342
+ box-sizing:border-box;
343
+ border :1px solid;
344
+ float:left;
345
+ border-radius:100px;
346
+ position:relative;
347
+ cursor:pointer;
348
+ transition:.3s ease;
349
+ }
350
+ input[class=woo_feed_status_input]:checked + label{
351
+ background:#55e868;
352
+ }
353
+ input[class=woo_feed_status_input]:checked + label:before{
354
+ left:25px;
355
+ }
356
+ .wf_status_wrap label:before{
357
+ transition:.3s ease;
358
+ content:'';
359
+ width:20px;
360
+ height:20px;
361
+ position:absolute;
362
+ background:white;
363
+ left:2px;
364
+ top:2px;
365
+ box-sizing:border-box;
366
+ border:1px solid;
367
+ color:black;
368
+ border-radius:100px;
369
+ }
admin/js/woo-feed-admin.js CHANGED
@@ -249,6 +249,23 @@
249
  }
250
  });
251
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
252
 
253
  });
254
 
249
  }
250
  });
251
 
252
+ // Feed Active and Inactive status change via ajax
253
+ $('.woo_feed_status_input').on('change',function(){
254
+ var counter;
255
+ var $feedName = $(this).val();
256
+ if($(this)[0].checked){
257
+ counter = 1;
258
+ }else {
259
+ counter = 0;
260
+ }
261
+ $.post(wpf_ajax_obj.wpf_ajax_url, { //POST request
262
+ _ajax_nonce: wpf_ajax_obj.nonce, //nonce
263
+ action: "update_feed_status", //action
264
+ feedName: $feedName,
265
+ status: counter
266
+ }, function (data) { //callback
267
+ });
268
+ });
269
 
270
  });
271
 
admin/partials/woo-feed-admin-display.php CHANGED
@@ -10,14 +10,17 @@
10
  * @subpackage Woo_Feed/admin/partial
11
  * @author Ohidul Islam <wahid@webappick.com>
12
  */
13
- //ini_set("max_execution_time",30);
14
- //echo ini_get("max_execution_time");
15
 
16
  $dropDown = new Woo_Feed_Dropdown();
17
  $product = new Woo_Feed_Products();
18
  $attributes=new Woo_Feed_Default_Attributes();
19
  $product->load_attributes();
20
 
 
 
 
 
21
  ?>
22
 
23
  <div class="wrap" id="Feed">
10
  * @subpackage Woo_Feed/admin/partial
11
  * @author Ohidul Islam <wahid@webappick.com>
12
  */
13
+
 
14
 
15
  $dropDown = new Woo_Feed_Dropdown();
16
  $product = new Woo_Feed_Products();
17
  $attributes=new Woo_Feed_Default_Attributes();
18
  $product->load_attributes();
19
 
20
+ //echo "<pre>";
21
+ //print_r();
22
+ //die();
23
+
24
  ?>
25
 
26
  <div class="wrap" id="Feed">
admin/partials/woo-feed-manage-list.php CHANGED
@@ -341,7 +341,7 @@ if(isset($_POST)&& isset($_POST['filename'])){
341
  feed:fileName
342
  },
343
  success : function(response) {
344
- // console.log(response);
345
  if(response.success) {
346
  width ='100';
347
  showFeedProgress();
341
  feed:fileName
342
  },
343
  success : function(response) {
344
+ console.log(response);
345
  if(response.success) {
346
  width ='100';
347
  showFeedProgress();
includes/class-woo-feed.php CHANGED
@@ -70,7 +70,7 @@ class Woo_Feed
70
  public function __construct()
71
  {
72
  $this->woo_feed = 'woo-feed';
73
- $this->version = '2.2.8';
74
 
75
  $this->load_dependencies();
76
  $this->set_locale();
70
  public function __construct()
71
  {
72
  $this->woo_feed = 'woo-feed';
73
+ $this->version = '2.2.9';
74
 
75
  $this->load_dependencies();
76
  $this->set_locale();
includes/classes/class-woo-feed-products.php CHANGED
@@ -11,61 +11,61 @@
11
  class Woo_Feed_Products
12
  {
13
 
14
- /**
15
- * Contain all parent product information for the plugin.
16
- *
17
- * @since 1.0.0
18
- * @access protected
19
- * @var string $parent Contain all parent product information for the plugin.
20
- */
21
- public $parent;
22
-
23
- /**
24
- * Contain all child product information for the plugin.
25
- *
26
- * @since 1.0.0
27
- * @access protected
28
- * @var string $parent Contain all child product information for the plugin.
29
- */
30
- public $child;
31
-
32
- /**
33
- * The parent id of current product.
34
- *
35
- * @since 1.0.0
36
- * @access private
37
- * @var string $parentID The current product's Parent ID.
38
- */
39
- public $parentID;
40
- /**
41
- * The child id of current product.
42
- *
43
- * @since 1.0.0
44
- * @access private
45
- * @var string $parentID The current product's child ID.
46
- */
47
- public $childID;
48
-
49
- /**
50
- * The Variable that contain all products.
51
- *
52
- * @since 1.0.0
53
- * @access private
54
- * @var array $productsList Products list array.
55
- */
56
- public $productsList;
57
-
58
- /**
59
- * The Variable that contain all attributes.
60
- *
61
- * @since 1.0.0
62
- * @access private
63
- * @var array $attributeList attributes list array.
64
- */
65
- public $attributeList;
66
-
67
- public $feedRule;
68
- public $idExist=array();
69
  public $pi;
70
 
71
 
@@ -117,7 +117,7 @@ class Woo_Feed_Products
117
  $offset = ! empty( $offset ) && is_numeric( $offset ) ? absint( $offset ) : '0';
118
 
119
 
120
- try {
121
 
122
 
123
  # Query Arguments
@@ -142,6 +142,7 @@ class Woo_Feed_Products
142
  $products = $query->get_products();
143
 
144
  //$products = $this->wooProductQuery($arg);
 
145
 
146
  $this->pi = 1; # Product Index
147
  foreach ( $products as $key => $productId ) {
@@ -154,7 +155,7 @@ class Woo_Feed_Products
154
 
155
  $simple = new WC_Product_Simple( $id );
156
 
157
- if(!is_object($simple)){
158
  continue;
159
  }
160
 
@@ -235,33 +236,12 @@ class Woo_Feed_Products
235
  $this->productsList[ $this->pi ][$aKey] = $simple->get_attribute($aKey);
236
  }
237
  }
238
-
239
-
240
- // # Get all Product Post Meta and Their Values
241
- // $metas=get_post_meta($simple->get_id());
242
- // if(!empty($metas)){
243
- // foreach ($metas as $mKey=>$meta){
244
- // if($mKey!="_product_attributes"){
245
- // $metaValue=get_post_meta($id,$mKey,true);
246
- // $this->productsList[ $this->pi ]["wf_cattr_".$mKey]=(!empty($metaValue))?$metaValue:"";
247
- // }
248
- // }
249
- // }
250
- //
251
- // # Get all Product Taxonomies and Their values
252
- // $taxonomies=get_post_taxonomies($id);
253
- // if(!empty($taxonomies)){
254
- // foreach ($taxonomies as $tKey=>$taxonomy){
255
- // $this->productsList[ $this->pi ]["wf_taxo_".$taxonomy]=strip_tags(get_the_term_list($id,$taxonomy,"",",",""));
256
- // }
257
- // }
258
-
259
  }
260
  else if ( $prod->is_type( 'external' ) ) {
261
 
262
  $external = new WC_Product_External( $id );
263
 
264
- if(!is_object($external)){
265
  continue;
266
  }
267
 
@@ -343,32 +323,12 @@ class Woo_Feed_Products
343
  $this->productsList[ $this->pi ][$aKey] = $external->get_attribute($aKey);
344
  }
345
  }
346
-
347
-
348
- // # Get all Product Post Meta and Their Values
349
- // $metas=get_post_meta($id);
350
- // if(!empty($metas)){
351
- // foreach ($metas as $mKey=>$meta){
352
- // if($mKey!="_product_attributes"){
353
- // $metaValue=get_post_meta($id,$mKey,true);
354
- // $this->productsList[ $this->pi ]["wf_cattr_".$mKey]=(!empty($metaValue))?$metaValue:"";
355
- // }
356
- // }
357
- // }
358
- //
359
- // # Get all Product Taxonomies and Their values
360
- // $taxonomies=get_post_taxonomies($id);
361
- // if(!empty($taxonomies)){
362
- // foreach ($taxonomies as $tKey=>$taxonomy){
363
- // $this->productsList[ $this->pi ]["wf_taxo_".$taxonomy]=strip_tags(get_the_term_list($id,$taxonomy,"",",",""));
364
- // }
365
- // }
366
  }
367
  else if ( $prod->is_type( 'grouped' ) ) {
368
 
369
  $grouped = new WC_Product_Grouped( $id );
370
 
371
- if(!is_object($grouped)){
372
  continue;
373
  }
374
 
@@ -450,39 +410,16 @@ class Woo_Feed_Products
450
  }
451
  }
452
 
453
-
454
- // # Get all Product Post Meta and Their Values
455
- // $metas=get_post_meta($id);
456
- // if(!empty($metas)){
457
- // foreach ($metas as $mKey=>$meta){
458
- // if($mKey!="_product_attributes"){
459
- // $metaValue=get_post_meta($id,$mKey,true);
460
- // $this->productsList[ $this->pi ]["wf_cattr_".$mKey]=(!empty($metaValue))?$metaValue:"";
461
- // }
462
- // }
463
- // }
464
- //
465
- // # Get all Product Taxonomies and Their values
466
- // $taxonomies=get_post_taxonomies($id);
467
- // if(!empty($taxonomies)){
468
- // foreach ($taxonomies as $tKey=>$taxonomy){
469
- // $this->productsList[ $this->pi ]["wf_taxo_".$taxonomy]=strip_tags(get_the_term_list($id,$taxonomy,"",",",""));
470
- // }
471
- // }
472
  }
473
  else if ( $prod->is_type( 'variable' ) ) {
474
 
475
  $variable = new WC_Product_Variable( $id );
476
 
477
- if(!is_object($variable)){
478
  continue;
479
  }
480
 
481
 
482
-
483
- $this->productsList[ $this->pi ]["attrs"] = wc_get_attribute_taxonomy_names();
484
- $this->productsList[ $this->pi ]["attrs_text"] = wc_get_attribute_taxonomies();
485
-
486
  $this->productsList[ $this->pi ]["id"] = $variable->get_id();
487
  $this->productsList[ $this->pi ]["title"] = $variable->get_name();
488
  $this->productsList[ $this->pi ]["description"] = $this->remove_short_codes($variable->get_description());
@@ -530,13 +467,6 @@ class Woo_Feed_Products
530
  $this->productsList[ $this->pi ]['sku'] = $variable->get_sku();
531
  $this->productsList[ $this->pi ]['availability'] = $this->availability( $id );
532
 
533
- // if ( $this->feedRule['variable_price'] == 'first' ) {
534
- // $price = $variable->get_regular_price();
535
- // $sPrice = $variable->get_sale_price();
536
- // } else {
537
- // $price = $variable->get_variation_regular_price( $this->feedRule['variable_price'], $variable->is_taxable() );
538
- // $sPrice = $variable->get_variation_sale_price( $this->feedRule['variable_price'], $variable->is_taxable() );
539
- // }
540
 
541
  $this->productsList[ $this->pi ]['quantity'] = $variable->get_stock_quantity();
542
  $this->productsList[ $this->pi ]['sale_price_sdate'] = $variable->get_date_on_sale_from();
@@ -569,42 +499,22 @@ class Woo_Feed_Products
569
  $this->productsList[ $this->pi ][$aKey] = $variable->get_attribute($aKey);
570
  }
571
  }
572
-
573
-
574
- // # Get all Product Post Meta and Their Values
575
- // $metas=get_post_meta($id);
576
- // if(!empty($metas)){
577
- // foreach ($metas as $mKey=>$meta){
578
- // if($mKey!="_product_attributes"){
579
- // $metaValue=get_post_meta($id,$mKey,true);
580
- // $this->productsList[ $this->pi ]["wf_cattr_".$mKey]=(!empty($metaValue))?$metaValue:"";
581
- // }
582
- // }
583
- // }
584
- //
585
- // # Get all Product Taxonomies and Their values
586
- // $taxonomies=get_post_taxonomies($id);
587
- // if(!empty($taxonomies)){
588
- // foreach ($taxonomies as $tKey=>$taxonomy){
589
- // $this->productsList[ $this->pi ]["wf_taxo_".$taxonomy]=strip_tags(get_the_term_list($id,$taxonomy,"",",",""));
590
- // }
591
- // }
592
-
593
- # Don't Include Variations for Facebook
594
- // if ( $this->feedRule['provider'] != 'facebook' ) {
595
- // $this->getWC3Variations( $variable->get_available_variations(),$variable);
596
- // }
597
-
598
  }
599
  else if ( $prod->is_type( 'variation' ) && $this->feedRule['provider'] != 'facebook') {
600
  $variation=new WC_Product_Variation($id);
601
 
602
- if(!is_object($variation) || !$variation->variation_is_visible()){
 
 
 
 
 
 
 
 
603
  continue;
604
  }
605
 
606
- # Parent Info
607
- $parent=wc_get_product($variation->get_parent_id());
608
  $parentInfo=$variation->get_parent_data();
609
  $variationTitle= $parentInfo['title'];
610
 
@@ -701,36 +611,16 @@ class Woo_Feed_Products
701
  $this->productsList[ $this->pi ][$aKey] = $variation->get_attribute($aKey);
702
  }
703
  }
704
-
705
-
706
- // # Get all Product Post Meta and Their Values
707
- // $metas=get_post_meta($id);
708
- // if(!empty($metas)){
709
- // foreach ($metas as $mKey=>$meta){
710
- // if($mKey!="_product_attributes"){
711
- // $metaValue=get_post_meta($id,$mKey,true);
712
- // $this->productsList[ $this->pi ]["wf_cattr_".$mKey]=(!empty($metaValue))?$metaValue:"";
713
- // }
714
- // }
715
- // }
716
- //
717
- // # Get all Product Taxonomies and Their values
718
- // $taxonomies=get_post_taxonomies($id);
719
- // if(!empty($taxonomies)){
720
- // foreach ($taxonomies as $tKey=>$taxonomy){
721
- // $this->productsList[ $this->pi ]["wf_taxo_".$taxonomy]=strip_tags(get_the_term_list($id,$taxonomy,"",",",""));
722
- // }
723
- // }
724
  }
725
 
726
  $this->pi ++;
727
  }
728
 
729
-
730
  return $this->productsList;
731
- }catch (Exception $e){
732
 
733
- }
 
 
734
  }
735
 
736
  /**
@@ -882,595 +772,595 @@ class Woo_Feed_Products
882
  }
883
 
884
 
885
- /**
886
- * Get WooCommerce Product
887
- * @param string $feedRule
888
- * @return array
889
- */
890
- public function woo_feed_get_visible_product($feedRule="")
891
- {
892
- $this->feedRule = $feedRule;
893
- $limit = ! empty( $feedRule['Limit'] ) && is_numeric( $feedRule['Limit'] ) ? absint( $feedRule['Limit'] ) : '2000';
894
- $offset = ! empty( $feedRule['Offset'] ) && is_numeric( $feedRule['Offset'] ) ? absint( $feedRule['Offset'] ) : '0';
895
- # WC 3.1+ Compatibility
896
-
897
- if ( woo_feed_wc_version_check(3.1) ) {
898
-
899
- return $this->getWC3Products( $limit, $offset);
900
-
901
- } else {
902
- try {
903
-
904
- if ( ! empty( $feedRule ) ) {
905
- $this->feedRule = $feedRule;
906
- }
907
-
908
-
909
- if ( $offset == '0' ) {
910
- delete_option( "wf_check_duplicate" );
911
- }
912
- $getIDs = get_option( "wf_check_duplicate" );
913
- $arg = array(
914
- 'post_type' => array( 'product', 'product_variation' ),
915
- 'post_status' => 'publish',
916
- 'posts_per_page' => $limit,
917
- 'orderby' => 'date',
918
- 'order' => 'desc',
919
- 'fields' => 'ids',
920
- 'offset' => $offset,
921
- 'cache_results' => false,
922
- 'update_post_term_cache' => false,
923
- 'update_post_meta_cache' => false,
924
- );
925
-
926
-
927
- # Query Database for products
928
- $loop = new WP_Query( $arg );
929
-
930
- $i = 0;
931
-
932
- while ( $loop->have_posts() ) : $loop->the_post();
933
-
934
- $this->childID = get_the_ID();
935
- $this->parentID = ( wp_get_post_parent_id( $this->childID ) ) ? wp_get_post_parent_id( $this->childID ) : $this->childID;
936
-
937
- global $product;
938
- if ( ! is_object( $product ) || ! $product->is_visible() ) {
939
- continue;
940
- }
941
-
942
- $type1 = "";
943
- if ( is_object( $product ) && $product->is_type( 'simple' ) ) {
944
- # No variations to product
945
- $type1 = "simple";
946
- } elseif ( is_object( $product ) && $product->is_type( 'variable' ) ) {
947
- # Product has variations
948
- $type1 = "variable";
949
- } elseif ( is_object( $product ) && $product->is_type( 'grouped' ) ) {
950
- $type1 = "grouped";
951
- } elseif ( is_object( $product ) && $product->is_type( 'external' ) ) {
952
- $type1 = "external";
953
- } elseif ( is_object( $product ) && $product->is_downloadable() ) {
954
- $type1 = "downloadable";
955
- } elseif ( is_object( $product ) && $product->is_virtual() ) {
956
- $type1 = "virtual";
957
- }
958
-
959
-
960
- $post = get_post( $this->parentID );
961
-
962
- if ( ! is_object( $post ) ) {
963
- continue;
964
- }
965
-
966
- if ( $post->post_status == 'trash' ) {
967
- continue;
968
- }
969
-
970
-
971
- if ( get_post_type() == 'product_variation' && $this->feedRule['provider'] != 'facebook' ) {
972
- if ( $this->parentID != 0 ) {
973
-
974
- $status = get_post( $this->childID );
975
- if ( ! $status || ! is_object( $status ) ) {
976
- continue;
977
- }
978
-
979
- if ( $status->post_status == "trash" ) {
980
- continue;
981
- }
982
-
983
- $parentStatus = get_post( $this->parentID );
984
- if ( $parentStatus && is_object( $parentStatus ) && $parentStatus->post_status != 'publish' ) {
985
- continue;
986
- }
987
-
988
- # Check Valid URL
989
- $mainImage = wp_get_attachment_url( $product->get_image_id() );
990
- $link = $product->get_permalink( $this->childID );
991
-
992
- if ( $this->feedRule['provider'] != 'custom' ) {
993
- if ( substr( trim( $link ), 0, 4 ) !== "http" && substr( trim( $mainImage ), 0, 4 ) !== "http" ) {
994
- continue;
995
- }
996
- }
997
-
998
- if ( $getIDs ) {
999
- if ( in_array( $this->childID, $getIDs ) ) {
1000
- continue;
1001
- } else {
1002
- array_push( $this->idExist, $this->childID );
1003
- }
1004
- } else {
1005
- array_push( $this->idExist, $this->childID );
1006
- }
1007
-
1008
-
1009
- $this->productsList[ $i ]['id'] = $this->childID;
1010
- $this->productsList[ $i ]['variation_type'] = "child";
1011
- $this->productsList[ $i ]['item_group_id'] = $this->parentID;
1012
- $this->productsList[ $i ]['sku'] = $this->getAttributeValue( $this->childID, "_sku" );
1013
- $this->productsList[ $i ]['parent_sku'] = $this->getAttributeValue( $this->parentID, "_sku" );
1014
- $this->productsList[ $i ]['title'] = $post->post_title;
1015
- $this->productsList[ $i ]['description'] = $post->post_content;
1016
-
1017
- # Short Description to variable description
1018
- $vDesc = $this->getAttributeValue( $this->childID, "_variation_description" );
1019
- if ( ! empty( $vDesc ) ) {
1020
- $this->productsList[ $i ]['short_description'] = $vDesc;
1021
- } else {
1022
- $this->productsList[ $i ]['short_description'] = $post->post_excerpt;
1023
- }
1024
-
1025
- $this->productsList[ $i ]['product_type'] = $this->get_product_term_list( $post->ID, 'product_cat', "", ">" );
1026
- $this->productsList[ $i ]['link'] = $link;
1027
- $this->productsList[ $i ]['ex_link'] = "";
1028
- $this->productsList[ $i ]['image'] = $this->get_formatted_url( $mainImage );
1029
-
1030
- # Featured Image
1031
- if ( has_post_thumbnail( $post->ID ) ):
1032
- $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' );
1033
- $this->productsList[ $i ]['feature_image'] = $this->get_formatted_url( $image[0] );
1034
- else:
1035
- $this->productsList[ $i ]['feature_image'] = $this->get_formatted_url( $mainImage );
1036
- endif;
1037
-
1038
- # Additional Images
1039
- $imageLinks = array();
1040
- $images = $this->additionalImages( $this->childID );
1041
- if ( $images && is_array( $images ) ) {
1042
- $mKey = 1;
1043
- foreach ( $images as $key => $value ) {
1044
- if ( $value != $this->productsList[ $i ]['image'] ) {
1045
- $imgLink = $this->get_formatted_url( $value );
1046
- $this->productsList[ $i ]["image_$mKey"] = $imgLink;
1047
- if ( ! empty( $imgLink ) ) {
1048
- array_push( $imageLinks, $imgLink );
1049
- }
1050
- }
1051
- $mKey ++;
1052
- }
1053
- }
1054
- $this->productsList[ $i ]['images'] = implode( ",", $imageLinks );
1055
- $this->productsList[ $i ]['condition'] = "New";
1056
- $this->productsList[ $i ]['type'] = $product->get_type();
1057
- $this->productsList[ $i ]['visibility'] = $this->getAttributeValue( $this->childID, "_visibility" );
1058
- $this->productsList[ $i ]['rating_total'] = $product->get_rating_count();
1059
- $this->productsList[ $i ]['rating_average'] = $product->get_average_rating();
1060
- $this->productsList[ $i ]['tags'] = $this->get_product_term_list( $post->ID, 'product_tag' );
1061
- $this->productsList[ $i ]['shipping'] = $product->get_shipping_class();
1062
-
1063
- $this->productsList[ $i ]['availability'] = $this->availability( $this->childID );
1064
- $this->productsList[ $i ]['quantity'] = $this->get_quantity( $this->childID, "_stock" );
1065
- $this->productsList[ $i ]['sale_price_sdate'] = $this->get_date( $this->childID, "_sale_price_dates_from" );
1066
- $this->productsList[ $i ]['sale_price_edate'] = $this->get_date( $this->childID, "_sale_price_dates_to" );
1067
- $this->productsList[ $i ]['price'] = ( $product->get_regular_price() ) ? $product->get_regular_price() : $product->get_price();
1068
- $this->productsList[ $i ]['sale_price'] = ( $product->get_sale_price() ) ? $product->get_sale_price() : "";
1069
- $this->productsList[ $i ]['weight'] = ( $product->get_weight() ) ? $product->get_weight() : "";
1070
- $this->productsList[ $i ]['width'] = ( $product->get_width() ) ? $product->get_width() : "";
1071
- $this->productsList[ $i ]['height'] = ( $product->get_height() ) ? $product->get_height() : "";
1072
- $this->productsList[ $i ]['length'] = ( $product->get_length() ) ? $product->get_length() : "";
1073
-
1074
- # Sale price effective date
1075
- $from = $this->sale_price_effective_date( $this->childID, '_sale_price_dates_from' );
1076
- $to = $this->sale_price_effective_date( $this->childID, '_sale_price_dates_to' );
1077
- if ( ! empty( $from ) && ! empty( $to ) ) {
1078
- $from = date( "c", strtotime( $from ) );
1079
- $to = date( "c", strtotime( $to ) );
1080
- $this->productsList[ $i ]['sale_price_effective_date'] = "$from" . "/" . "$to";
1081
- } else {
1082
- $this->productsList[ $i ]['sale_price_effective_date'] = "";
1083
- }
1084
-
1085
- }
1086
- } elseif ( get_post_type() == 'product' ) {
1087
- if ( $type1 == 'simple' ) {
1088
-
1089
- $mainImage = wp_get_attachment_url( $product->get_image_id() );
1090
- $link = get_permalink( $post->ID );
1091
-
1092
- if ( $this->feedRule['provider'] != 'custom' ) {
1093
- if ( substr( trim( $link ), 0, 4 ) !== "http" && substr( trim( $mainImage ), 0, 4 ) !== "http" ) {
1094
- continue;
1095
- }
1096
- }
1097
-
1098
- if ( $getIDs ) {
1099
- if ( in_array( $post->ID, $getIDs ) ) {
1100
- continue;
1101
- } else {
1102
- array_push( $this->idExist, $post->ID );
1103
- }
1104
- } else {
1105
- array_push( $this->idExist, $post->ID );
1106
- }
1107
-
1108
- $this->productsList[ $i ]['id'] = $post->ID;
1109
- $this->productsList[ $i ]['variation_type'] = "simple";
1110
- $this->productsList[ $i ]['title'] = $product->get_title();
1111
- $this->productsList[ $i ]['description'] = $post->post_content;
1112
-
1113
- $this->productsList[ $i ]['short_description'] = $post->post_excerpt;
1114
- $this->productsList[ $i ]['product_type'] = $this->get_product_term_list( $post->ID, 'product_cat', "", ">" );
1115
- $this->productsList[ $i ]['link'] = $link;
1116
- $this->productsList[ $i ]['ex_link'] = "";
1117
- $this->productsList[ $i ]['image'] = $this->get_formatted_url( $mainImage );
1118
-
1119
- # Featured Image
1120
- if ( has_post_thumbnail( $post->ID ) ):
1121
- $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' );
1122
- $this->productsList[ $i ]['feature_image'] = $this->get_formatted_url( $image[0] );
1123
- else:
1124
- $this->productsList[ $i ]['feature_image'] = $this->get_formatted_url( $mainImage );
1125
- endif;
1126
-
1127
- # Additional Images
1128
- $imageLinks = array();
1129
- $images = $this->additionalImages( $post->ID );
1130
- if ( $images && is_array( $images ) ) {
1131
- $mKey = 1;
1132
- foreach ( $images as $key => $value ) {
1133
- if ( $value != $this->productsList[ $i ]['image'] ) {
1134
- $imgLink = $this->get_formatted_url( $value );
1135
- $this->productsList[ $i ]["image_$mKey"] = $imgLink;
1136
- if ( ! empty( $imgLink ) ) {
1137
- array_push( $imageLinks, $imgLink );
1138
- }
1139
- }
1140
- $mKey ++;
1141
- }
1142
- }
1143
- $this->productsList[ $i ]['images'] = implode( ",", $imageLinks );
1144
-
1145
- $this->productsList[ $i ]['condition'] = "New";
1146
- $this->productsList[ $i ]['type'] = $product->get_type();
1147
- $this->productsList[ $i ]['visibility'] = $this->getAttributeValue( $post->ID, "_visibility" );
1148
- $this->productsList[ $i ]['rating_total'] = $product->get_rating_count();
1149
- $this->productsList[ $i ]['rating_average'] = $product->get_average_rating();
1150
- $this->productsList[ $i ]['tags'] = $this->get_product_term_list( $post->ID, 'product_tag' );
1151
-
1152
- $this->productsList[ $i ]['item_group_id'] = $post->ID;
1153
- $this->productsList[ $i ]['sku'] = $this->getAttributeValue( $post->ID, "_sku" );
1154
-
1155
- $this->productsList[ $i ]['availability'] = $this->availability( $post->ID );
1156
- $this->productsList[ $i ]['quantity'] = $this->get_quantity( $post->ID, "_stock" );
1157
- $this->productsList[ $i ]['sale_price_sdate'] = $this->get_date( $post->ID, "_sale_price_dates_from" );
1158
- $this->productsList[ $i ]['sale_price_edate'] = $this->get_date( $post->ID, "_sale_price_dates_to" );
1159
- $this->productsList[ $i ]['price'] = ( $product->get_regular_price() ) ? $product->get_regular_price() : $product->get_price();
1160
- $this->productsList[ $i ]['sale_price'] = ( $product->get_sale_price() ) ? $product->get_sale_price() : "";
1161
- $this->productsList[ $i ]['weight'] = ( $product->get_weight() ) ? $product->get_weight() : "";
1162
- $this->productsList[ $i ]['width'] = ( $product->get_width() ) ? $product->get_width() : "";
1163
- $this->productsList[ $i ]['height'] = ( $product->get_height() ) ? $product->get_height() : "";
1164
- $this->productsList[ $i ]['length'] = ( $product->get_length() ) ? $product->get_length() : "";
1165
-
1166
- # Sale price effective date
1167
- $from = $this->sale_price_effective_date( $post->ID, '_sale_price_dates_from' );
1168
- $to = $this->sale_price_effective_date( $post->ID, '_sale_price_dates_to' );
1169
- if ( ! empty( $from ) && ! empty( $to ) ) {
1170
- $from = date( "c", strtotime( $from ) );
1171
- $to = date( "c", strtotime( $to ) );
1172
- $this->productsList[ $i ]['sale_price_effective_date'] = "$from" . "/" . "$to";
1173
- } else {
1174
- $this->productsList[ $i ]['sale_price_effective_date'] = "";
1175
- }
1176
-
1177
- }
1178
- else if ( $type1 == 'external' ) {
1179
-
1180
- $mainImage = wp_get_attachment_url( $product->get_image_id() );
1181
-
1182
- $getLink = new WC_Product_External( $post->ID );
1183
- $EX_link = $getLink->get_product_url();
1184
- $link = get_permalink( $post->ID );
1185
- if ( $this->feedRule['provider'] != 'custom' ) {
1186
- if ( substr( trim( $link ), 0, 4 ) !== "http" && substr( trim( $mainImage ), 0, 4 ) !== "http" ) {
1187
- continue;
1188
- }
1189
- }
1190
-
1191
- $this->productsList[ $i ]['id'] = $post->ID;
1192
- $this->productsList[ $i ]['variation_type'] = "external";
1193
- $this->productsList[ $i ]['title'] = $product->get_title();
1194
- $this->productsList[ $i ]['description'] = do_shortcode( $post->post_content );
1195
-
1196
- $this->productsList[ $i ]['short_description'] = $post->post_excerpt;
1197
- $this->productsList[ $i ]['product_type'] = $this->get_product_term_list( $post->ID, 'product_cat', "", ">" );
1198
- $this->productsList[ $i ]['link'] = $link;
1199
- $this->productsList[ $i ]['ex_link'] = $EX_link;
1200
- $this->productsList[ $i ]['image'] = $this->get_formatted_url( $mainImage );
1201
-
1202
- # Featured Image
1203
- if ( has_post_thumbnail( $post->ID ) ):
1204
- $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' );
1205
- $this->productsList[ $i ]['feature_image'] = $this->get_formatted_url( $image[0] );
1206
- else:
1207
- $this->productsList[ $i ]['feature_image'] = $this->get_formatted_url( $mainImage );
1208
- endif;
1209
-
1210
- # Additional Images
1211
- $imageLinks = array();
1212
- $images = $this->additionalImages( $post->ID );
1213
- if ( $images && is_array( $images ) ) {
1214
- $mKey = 1;
1215
- foreach ( $images as $key => $value ) {
1216
- if ( $value != $this->productsList[ $i ]['image'] ) {
1217
- $imgLink = $this->get_formatted_url( $value );
1218
- $this->productsList[ $i ]["image_$mKey"] = $imgLink;
1219
- if ( ! empty( $imgLink ) ) {
1220
- array_push( $imageLinks, $imgLink );
1221
- }
1222
- }
1223
- $mKey ++;
1224
- }
1225
- }
1226
- $this->productsList[ $i ]['images'] = implode( ",", $imageLinks );
1227
-
1228
- $this->productsList[ $i ]['condition'] = "New";
1229
- $this->productsList[ $i ]['type'] = $product->get_type();
1230
- $this->productsList[ $i ]['visibility'] = $this->getAttributeValue( $post->ID, "_visibility" );
1231
- $this->productsList[ $i ]['rating_total'] = $product->get_rating_count();
1232
- $this->productsList[ $i ]['rating_average'] = $product->get_average_rating();
1233
- $this->productsList[ $i ]['tags'] = $this->get_product_term_list( $post->ID, 'product_tag' );
1234
-
1235
- $this->productsList[ $i ]['item_group_id'] = $post->ID;
1236
- $this->productsList[ $i ]['sku'] = $this->getAttributeValue( $post->ID, "_sku" );
1237
-
1238
- $this->productsList[ $i ]['availability'] = $this->availability( $post->ID );
1239
-
1240
- $this->productsList[ $i ]['quantity'] = $this->get_quantity( $post->ID, "_stock" );
1241
- $this->productsList[ $i ]['sale_price_sdate'] = $this->get_date( $post->ID, "_sale_price_dates_from" );
1242
- $this->productsList[ $i ]['sale_price_edate'] = $this->get_date( $post->ID, "_sale_price_dates_to" );
1243
- $this->productsList[ $i ]['price'] = ( $product->get_regular_price() ) ? $product->get_regular_price() : $product->get_price();
1244
- $this->productsList[ $i ]['sale_price'] = ( $product->get_sale_price() ) ? $product->get_sale_price() : "";
1245
- $this->productsList[ $i ]['weight'] = ( $product->get_weight() ) ? $product->get_weight() : "";
1246
- $this->productsList[ $i ]['width'] = ( $product->get_width() ) ? $product->get_width() : "";
1247
- $this->productsList[ $i ]['height'] = ( $product->get_height() ) ? $product->get_height() : "";
1248
- $this->productsList[ $i ]['length'] = ( $product->get_length() ) ? $product->get_length() : "";
1249
-
1250
- # Sale price effective date
1251
- $from = $this->sale_price_effective_date( $post->ID, '_sale_price_dates_from' );
1252
- $to = $this->sale_price_effective_date( $post->ID, '_sale_price_dates_to' );
1253
- if ( ! empty( $from ) && ! empty( $to ) ) {
1254
- $from = date( "c", strtotime( $from ) );
1255
- $to = date( "c", strtotime( $to ) );
1256
- $this->productsList[ $i ]['sale_price_effective_date'] = "$from" . "/" . "$to";
1257
- } else {
1258
- $this->productsList[ $i ]['sale_price_effective_date'] = "";
1259
- }
1260
-
1261
- }
1262
- elseif ( $type1 == 'grouped' ) {
1263
-
1264
- $grouped = new WC_Product_Grouped( $post->ID );
1265
- $children = $grouped->get_children();
1266
- $this->parentID = $post->ID;
1267
- if ( $children ) {
1268
- foreach ( $children as $cKey => $child ) {
1269
-
1270
- $product = new WC_Product( $child );
1271
- $this->childID = $child;
1272
- $post = get_post( $this->childID );
1273
-
1274
- if ( $post->post_status == 'trash' ) {
1275
- continue;
1276
- }
1277
-
1278
- if ( ! empty( $this->ids_in ) && ! in_array( $post->ID, $this->ids_in ) ) {
1279
- continue;
1280
- }
1281
-
1282
- if ( ! empty( $this->ids_not_in ) && in_array( $post->ID, $this->ids_in ) ) {
1283
- continue;
1284
- }
1285
-
1286
- if ( ! $product->is_visible() ) {
1287
- continue;
1288
- }
1289
-
1290
- $i ++;
1291
-
1292
- $mainImage = wp_get_attachment_url( $product->get_image_id() );
1293
- $link = get_permalink( $post->ID );
1294
- if ( $this->feedRule['provider'] != 'custom' ) {
1295
- if ( substr( trim( $link ), 0, 4 ) !== "http" && substr( trim( $mainImage ), 0, 4 ) !== "http" ) {
1296
- continue;
1297
- }
1298
- }
1299
-
1300
- $this->productsList[ $i ]['id'] = $post->ID;
1301
- $this->productsList[ $i ]['variation_type'] = "grouped";
1302
- $this->productsList[ $i ]['title'] = $product->get_title();
1303
- $this->productsList[ $i ]['description'] = do_shortcode( $post->post_content );
1304
-
1305
- $this->productsList[ $i ]['short_description'] = $post->post_excerpt;
1306
- $this->productsList[ $i ]['product_type'] = $this->get_product_term_list( $post->ID, 'product_cat', "", ">" );
1307
- $this->productsList[ $i ]['link'] = $link;
1308
- $this->productsList[ $i ]['ex_link'] = "";
1309
- $this->productsList[ $i ]['image'] = $this->get_formatted_url( $mainImage );
1310
-
1311
- # Featured Image
1312
- if ( has_post_thumbnail( $post->ID ) ):
1313
- $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' );
1314
- $this->productsList[ $i ]['feature_image'] = $this->get_formatted_url( $image[0] );
1315
- else:
1316
- $this->productsList[ $i ]['feature_image'] = $this->get_formatted_url( $mainImage );
1317
- endif;
1318
-
1319
- # Additional Images
1320
- $imageLinks = array();
1321
- $images = $this->additionalImages( $this->childID );
1322
- if ( $images and is_array( $images ) ) {
1323
- $mKey = 1;
1324
- foreach ( $images as $key => $value ) {
1325
- if ( $value != $this->productsList[ $i ]['image'] ) {
1326
- $imgLink = $this->get_formatted_url( $value );
1327
- $this->productsList[ $i ]["image_$mKey"] = $imgLink;
1328
- if ( ! empty( $imgLink ) ) {
1329
- array_push( $imageLinks, $imgLink );
1330
- }
1331
- }
1332
- $mKey ++;
1333
- }
1334
- }
1335
- $this->productsList[ $i ]['images'] = implode( ",", $imageLinks );
1336
- $this->productsList[ $i ]['condition'] = "New";
1337
- $this->productsList[ $i ]['type'] = $product->get_type();
1338
- $this->productsList[ $i ]['visibility'] = $this->getAttributeValue( $post->ID, "_visibility" );
1339
- $this->productsList[ $i ]['rating_total'] = $product->get_rating_count();
1340
- $this->productsList[ $i ]['rating_average'] = $product->get_average_rating();
1341
- $this->productsList[ $i ]['tags'] = $this->get_product_term_list( $post->ID, 'product_tag' );
1342
-
1343
- $this->productsList[ $i ]['item_group_id'] = $this->parentID;
1344
- $this->productsList[ $i ]['sku'] = $this->getAttributeValue( $post->ID, "_sku" );
1345
-
1346
- $this->productsList[ $i ]['availability'] = $this->availability( $post->ID );
1347
-
1348
- $this->productsList[ $i ]['quantity'] = $this->get_quantity( $post->ID, "_stock" );
1349
- $this->productsList[ $i ]['sale_price_sdate'] = $this->get_date( $post->ID, "_sale_price_dates_from" );
1350
- $this->productsList[ $i ]['sale_price_edate'] = $this->get_date( $post->ID, "_sale_price_dates_to" );
1351
- $this->productsList[ $i ]['price'] = ( $product->get_regular_price() ) ? $product->get_regular_price() : $product->get_price();
1352
- $this->productsList[ $i ]['sale_price'] = ( $product->get_sale_price() ) ? $product->get_sale_price() : "";
1353
- $this->productsList[ $i ]['weight'] = ( $product->get_weight() ) ? $product->get_weight() : "";
1354
- $this->productsList[ $i ]['width'] = ( $product->get_width() ) ? $product->get_width() : "";
1355
- $this->productsList[ $i ]['height'] = ( $product->get_height() ) ? $product->get_height() : "";
1356
- $this->productsList[ $i ]['length'] = ( $product->get_length() ) ? $product->get_length() : "";
1357
-
1358
- # Sale price effective date
1359
- $from = $this->sale_price_effective_date( $post->ID, '_sale_price_dates_from' );
1360
- $to = $this->sale_price_effective_date( $post->ID, '_sale_price_dates_to' );
1361
- if ( ! empty( $from ) && ! empty( $to ) ) {
1362
- $from = date( "c", strtotime( $from ) );
1363
- $to = date( "c", strtotime( $to ) );
1364
- $this->productsList[ $i ]['sale_price_effective_date'] = "$from" . "/" . "$to";
1365
- } else {
1366
- $this->productsList[ $i ]['sale_price_effective_date'] = "";
1367
- }
1368
- }
1369
- }
1370
- }
1371
- else if ( $type1 == 'variable' && $product->has_child() ) {
1372
-
1373
- # Check Valid URL
1374
- $mainImage = wp_get_attachment_url( $product->get_image_id() );
1375
- $link = get_permalink( $post->ID );
1376
-
1377
- if ( $this->feedRule['provider'] != 'custom' ) {
1378
- if ( substr( trim( $link ), 0, 4 ) !== "http" && substr( trim( $mainImage ), 0, 4 ) !== "http" ) {
1379
- continue;
1380
- }
1381
- }
1382
-
1383
-
1384
- $this->productsList[ $i ]['id'] = $post->ID;
1385
- $this->productsList[ $i ]['variation_type'] = "parent";
1386
- $this->productsList[ $i ]['title'] = $post->post_title;
1387
- $this->productsList[ $i ]['description'] = $post->post_content;
1388
-
1389
- $this->productsList[ $i ]['short_description'] = $post->post_excerpt;
1390
- $this->productsList[ $i ]['product_type'] = $this->get_product_term_list( $post->ID, 'product_cat', "", ">" );
1391
- $this->productsList[ $i ]['link'] = $link;
1392
- $this->productsList[ $i ]['ex_link'] = "";
1393
- $this->productsList[ $i ]['image'] = $this->get_formatted_url( $mainImage );
1394
-
1395
- # Featured Image
1396
- if ( has_post_thumbnail( $post->ID ) ):
1397
- $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' );
1398
- $this->productsList[ $i ]['feature_image'] = $this->get_formatted_url( $image[0] );
1399
- else:
1400
- $this->productsList[ $i ]['feature_image'] = $this->get_formatted_url( $mainImage );
1401
- endif;
1402
-
1403
- # Additional Images
1404
- $imageLinks = array();
1405
- $images = $this->additionalImages( $post->ID );
1406
- if ( $images and is_array( $images ) ) {
1407
- $mKey = 1;
1408
- foreach ( $images as $key => $value ) {
1409
- if ( $value != $this->productsList[ $i ]['image'] ) {
1410
- $imgLink = $this->get_formatted_url( $value );
1411
- $this->productsList[ $i ]["image_$mKey"] = $imgLink;
1412
- if ( ! empty( $imgLink ) ) {
1413
- array_push( $imageLinks, $imgLink );
1414
- }
1415
- }
1416
- $mKey ++;
1417
- }
1418
- }
1419
- $this->productsList[ $i ]['images'] = implode( ",", $imageLinks );
1420
-
1421
- $this->productsList[ $i ]['condition'] = "New";
1422
- $this->productsList[ $i ]['type'] = $product->get_type();
1423
- $this->productsList[ $i ]['visibility'] = $this->getAttributeValue( $post->ID, "_visibility" );
1424
- $this->productsList[ $i ]['rating_total'] = $product->get_rating_count();
1425
- $this->productsList[ $i ]['rating_average'] = $product->get_average_rating();
1426
- $this->productsList[ $i ]['tags'] = $this->get_product_term_list( $post->ID, 'product_tag' );
1427
-
1428
- $this->productsList[ $i ]['item_group_id'] = $post->ID;
1429
- $this->productsList[ $i ]['sku'] = $this->getAttributeValue( $post->ID, "_sku" );
1430
-
1431
- $this->productsList[ $i ]['availability'] = $this->availability( $post->ID );
1432
- $this->productsList[ $i ]['quantity'] = $this->get_quantity( $post->ID, "_stock" );
1433
- $this->productsList[ $i ]['sale_price_sdate'] = $this->get_date( $post->ID, "_sale_price_dates_from" );
1434
- $this->productsList[ $i ]['sale_price_edate'] = $this->get_date( $post->ID, "_sale_price_dates_to" );
1435
-
1436
- $price = ( $product->get_price() ) ? $product->get_price() : false;
1437
-
1438
- $this->productsList[ $i ]['price'] = ( $product->get_regular_price() ) ? $product->get_regular_price() : $price;
1439
- $this->productsList[ $i ]['sale_price'] = ( $product->get_sale_price() ) ? $product->get_sale_price() : "";
1440
- $this->productsList[ $i ]['weight'] = ( $product->get_weight() ) ? $product->get_weight() : "";
1441
- $this->productsList[ $i ]['width'] = ( $product->get_width() ) ? $product->get_width() : "";
1442
- $this->productsList[ $i ]['height'] = ( $product->get_height() ) ? $product->get_height() : "";
1443
- $this->productsList[ $i ]['length'] = ( $product->get_length() ) ? $product->get_length() : "";
1444
-
1445
- # Sale price effective date
1446
- $from = $this->sale_price_effective_date( $post->ID, '_sale_price_dates_from' );
1447
- $to = $this->sale_price_effective_date( $post->ID, '_sale_price_dates_to' );
1448
- if ( ! empty( $from ) && ! empty( $to ) ) {
1449
- $from = date( "c", strtotime( $from ) );
1450
- $to = date( "c", strtotime( $to ) );
1451
- $this->productsList[ $i ]['sale_price_effective_date'] = "$from" . "/" . "$to";
1452
- } else {
1453
- $this->productsList[ $i ]['sale_price_effective_date'] = "";
1454
- }
1455
- }
1456
- }
1457
- $i ++;
1458
- endwhile;
1459
- wp_reset_query();
1460
-
1461
- if ( $getIDs ) {
1462
- $mergedIds = array_merge( $getIDs, $this->idExist );
1463
- update_option( "wf_check_duplicate", $mergedIds );
1464
- } else {
1465
- update_option( "wf_check_duplicate", $this->idExist );
1466
- }
1467
-
1468
- return $this->productsList;
1469
- } catch ( Exception $e ) {
1470
- return $this->productsList;
1471
- }
1472
- }
1473
- }
1474
 
1475
  /**
1476
  * Remove ShortCodes from contents
@@ -1481,7 +1371,7 @@ class Woo_Feed_Products
1481
  public function remove_short_codes($content)
1482
  {
1483
  if(empty($content)){
1484
- return "";
1485
  }
1486
 
1487
  if(class_exists("WPBMap")){
@@ -1493,136 +1383,136 @@ class Woo_Feed_Products
1493
 
1494
  }
1495
 
1496
- /**
1497
- * Get formatted image url
1498
- *
1499
- * @param $url
1500
- * @return bool|string
1501
- */
1502
- public function get_formatted_url($url = "")
1503
- {
1504
- if (!empty($url)) {
1505
- if (substr(trim($url), 0, 4) === "http" || substr(trim($url), 0, 3) === "ftp" || substr(trim($url), 0, 4) === "sftp") {
1506
- return rtrim($url, "/");
1507
- } else {
1508
- $base = get_site_url();
1509
- $url = $base . $url;
1510
- return rtrim($url, "/");
1511
- }
1512
- }
1513
- return $url;
1514
- }
1515
-
1516
-
1517
- /**
1518
- * Get formatted product date
1519
- *
1520
- * @param $id
1521
- * @param $name
1522
- * @return bool|string
1523
- */
1524
- public function get_date($id, $name)
1525
- {
1526
- $date = $this->getAttributeValue($id, $name);
1527
- if ($date) {
1528
- return date("Y-m-d", $date);
1529
- }
1530
- return false;
1531
- }
1532
-
1533
- /**
1534
- * Get formatted product quantity
1535
- *
1536
- * @param $id
1537
- * @param $name
1538
- * @return bool|mixed
1539
- */
1540
- public function get_quantity($id, $name)
1541
- {
1542
- $qty = $this->getAttributeValue($id, $name);
1543
- if ($qty) {
1544
- return $qty + 0;
1545
- }
1546
- return "0";
1547
- }
1548
-
1549
- /**
1550
- * Retrieve a post's terms as a list with specified format.
1551
- *
1552
- * @since 2.5.0
1553
- *
1554
- * @param int $id Post ID.
1555
- * @param string $taxonomy Taxonomy name.
1556
- * @param string $before Optional. Before list.
1557
- * @param string $sep Optional. Separate items using this.
1558
- * @param string $after Optional. After list.
1559
- *
1560
- * @return string|false|WP_Error A list of terms on success, false if there are no terms, WP_Error on failure.
1561
- */
1562
- function get_product_term_list($id, $taxonomy, $before = '', $sep = ',', $after = '')
1563
- {
1564
- $terms = get_the_terms($id, $taxonomy);
1565
-
1566
- if (is_wp_error($terms)) {
1567
- return $terms;
1568
- }
1569
-
1570
- if (empty($terms)) {
1571
- return false;
1572
- }
1573
-
1574
- $links = array();
1575
-
1576
- foreach ($terms as $term) {
1577
- $links[] = $term->name;
1578
- }
1579
- ksort($links);
1580
- return $before . join($sep, $links) . $after;
1581
- }
1582
-
1583
- /** Return additional image URLs
1584
- *
1585
- * @param int $Id
1586
- *
1587
- * @return bool|array
1588
- */
1589
-
1590
- public function additionalImages($Id)
1591
- {
1592
- $ids=$this->getAttributeValue($Id,"_product_image_gallery");
1593
- $imgIds=!empty($ids)?explode(",",$ids):"";
1594
-
1595
- $images = array();
1596
- if (!empty($imgIds)) {
1597
- foreach ($imgIds as $key => $value) {
1598
- if ($key < 10) {
1599
- $images[$key] = wp_get_attachment_url($value);
1600
- }
1601
- }
1602
- return $images;
1603
- }
1604
- return false;
1605
- }
1606
-
1607
- /**
1608
- * Give space to availability text
1609
- *
1610
- * @param integer $id
1611
- *
1612
- * @return string
1613
- */
1614
- public function availability($id)
1615
- {
1616
- $status=$this->getAttributeValue($id,"_stock_status");
1617
- if ($status) {
1618
- if ($status == 'instock') {
1619
- return "in stock";
1620
- } elseif ($status == 'outofstock') {
1621
- return "out of stock";
1622
- }
1623
- }
1624
- return "out of stock";
1625
- }
1626
 
1627
  /**
1628
  * Ger Product Attribute
@@ -1678,19 +1568,19 @@ class Woo_Feed_Products
1678
  }
1679
  }
1680
 
1681
- /**
1682
- * Get Product Attribute Value
1683
- *
1684
- * @deprecated 2.2.5
1685
- * @param $id
1686
- * @param $name
1687
- *
1688
- * @return mixed
1689
- */
1690
- public function getAttributeValue($id, $name)
1691
- {
1692
-
1693
- return $this->getProductMeta($id,$name);
1694
  // if (strpos($name, 'attribute_pa') !== false) {
1695
  // $taxonomy = str_replace("attribute_","",$name);
1696
  // $meta = get_post_meta($id,$name, true);
@@ -1699,392 +1589,390 @@ class Woo_Feed_Products
1699
  // }else{
1700
  // return get_post_meta($id, $name, true);
1701
  // }
 
1702
 
1703
- }
1704
-
1705
- /**
1706
- * Get Sale price effective date for google
1707
- *
1708
- * @param $id
1709
- * @param $name
1710
- * @return string
1711
- */
1712
- public function sale_price_effective_date($id, $name)
1713
- {
1714
- return ($date = $this->getAttributeValue($id, $name)) ? date_i18n('Y-m-d', $date) : "";
1715
- }
1716
-
1717
-
1718
- /**
1719
- * Get All Default WooCommerce Attributes
1720
- * @return bool|array
1721
- */
1722
- public function getAllAttributes()
1723
- {
1724
- global $wpdb;
1725
-
1726
- //Load the main attributes
1727
- $sql = '
1728
  SELECT attribute_name as name, attribute_type as type
1729
  FROM ' . $wpdb->prefix . 'woocommerce_attribute_taxonomies';
1730
- $data = $wpdb->get_results($sql);
1731
- if (count($data)) {
1732
- foreach ($data as $key => $value) {
1733
- $info["wf_attr_pa_" . $value->name] = $value->name;
1734
- }
1735
- return $info;
1736
- }
1737
- return false;
1738
- }
1739
-
1740
-
1741
- /**
1742
- * Get All Custom Attributes
1743
- * @return array|bool
1744
- */
1745
- public function getAllCustomAttributes()
1746
- {
1747
- global $wpdb;
1748
- $info = array();
1749
- //Load the main attributes
1750
- $sql = "SELECT meta_key as name, meta_value as type
 
1751
  FROM " . $wpdb->prefix . "postmeta" . " group by meta_key";
1752
- $data = $wpdb->get_results($sql);
1753
- if ($data) {
1754
- foreach ($data as $key => $value) {
1755
- if (substr($value->name, 0, 1) !== "_") { //&& substr($value->name, 0, 13) !== "attribute_pa_"
1756
- $info["wf_cattr_" . $value->name] = $value->name;
1757
- }
1758
- }
1759
- return $info;
1760
- }
1761
- return false;
1762
- }
1763
-
1764
- /**
1765
- * Get All Taxonomy
1766
- *
1767
- * @param string $name
1768
- *
1769
- * @return mixed
1770
- */
1771
- public function getAllTaxonomy($name = "color")
1772
- {
1773
- global $wpdb;
1774
- //Load the taxonomies
1775
- $info = false;
1776
-
1777
- $sql = "SELECT taxo.taxonomy, terms.name, terms.slug FROM $wpdb->term_taxonomy taxo
1778
  LEFT JOIN $wpdb->terms terms ON (terms.term_id = taxo.term_id) GROUP BY taxo.taxonomy";
1779
- $data = $wpdb->get_results($sql);
1780
- if (count($data)) {
1781
- foreach ($data as $key => $value) {
1782
- $info["wf_taxo_" . $value->taxonomy] = $value->taxonomy;
1783
- }
1784
- }
1785
- return $info;
1786
- }
1787
-
1788
- /**
1789
- * Get Category Mappings
1790
- * @return bool|array
1791
- */
1792
- public function getCustomCategoryMappedAttributes()
1793
- {
1794
- global $wpdb;
1795
-
1796
- //Load Custom Category Mapped Attributes
1797
- $var = "wf_cmapping_";
1798
- $sql = $wpdb->prepare("SELECT * FROM $wpdb->options WHERE option_name LIKE %s;", $var . "%");
1799
- $data = $wpdb->get_results($sql);
1800
- if (count($data)) {
1801
- foreach ($data as $key => $value) {
1802
- $info[$key] = $value->option_name;
1803
- }
1804
-
1805
- return $info;
1806
- }
1807
-
1808
- return false;
1809
- }
1810
-
1811
- /**
1812
- * Get Dynamic Attribute List
1813
- * @return bool|array
1814
- */
1815
- public function dynamicAttributes()
1816
- {
1817
- global $wpdb;
1818
-
1819
- # Load Custom Category Mapped Attributes
1820
- $var = "wf_dattribute_";
1821
- $sql = $wpdb->prepare("SELECT * FROM $wpdb->options WHERE option_name LIKE %s;", $var . "%");
1822
- $data = $wpdb->get_results($sql);
1823
- if (count($data)) {
1824
- foreach ($data as $key => $value) {
1825
- $info[$key] = $value->option_name;
1826
- }
1827
- return $info;
1828
- }
1829
- return false;
1830
- }
1831
-
1832
- /**
1833
- * Local Attribute List to map product value with merchant attributes
1834
- *
1835
- * @param string $selected
1836
- *
1837
- * @return string
1838
- */
1839
- public function attributeDropdown($selected = "")
1840
- {
1841
- $attributes = array(
1842
- "id" => "Product Id",
1843
- "title" => "Product Title",
1844
- "description" => "Product Description",
1845
- "short_description" => "Product Short Description",
1846
- "product_type" => "Product Local Category",
1847
- "link" => "Product URL",
1848
- "ex_link" => "External Product URL",
1849
- "condition" => "Condition",
1850
- "item_group_id" => "Parent Id [Group Id]",
1851
- "sku" => "SKU",
1852
- "parent_sku" => "Parent SKU",
1853
- "availability" => "Availability",
1854
- "quantity" => "Quantity",
1855
- "price" => "Regular Price",
1856
- "sale_price" => "Sale Price",
1857
- "sale_price_sdate" => "Sale Start Date",
1858
- "sale_price_edate" => "Sale End Date",
1859
- "weight" => "Weight",
1860
- "width" => "Width",
1861
- "height" => "Height",
1862
- "length" => "Length",
1863
- "shipping_class" => "Shipping Class",
1864
- "type" => "Product Type",
1865
- "variation_type" => "Variation Type",
1866
- "visibility" => "Visibility",
1867
- "rating_total" => "Total Rating",
1868
- "rating_average" => "Average Rating",
1869
- "tags" => "Tags",
1870
- "sale_price_effective_date" => "Sale Price Effective Date",
1871
- "is_bundle" => "Is Bundle",
1872
- );
1873
-
1874
- $images = array(
1875
- "image" => "Main Image",
1876
- "feature_image" => "Featured Image",
1877
- "images" => "Images [Comma Separated]",
1878
- "image_1" => "Additional Image 1",
1879
- "image_2" => "Additional Image 2",
1880
- "image_3" => "Additional Image 3",
1881
- "image_4" => "Additional Image 4",
1882
- "image_5" => "Additional Image 5",
1883
- "image_6" => "Additional Image 6",
1884
- "image_7" => "Additional Image 7",
1885
- "image_8" => "Additional Image 8",
1886
- "image_9" => "Additional Image 9",
1887
- "image_10" => "Additional Image 10",
1888
- );
1889
-
1890
- # Primary Attributes
1891
- $str = "<option></option>";
1892
- $sltd = "";
1893
- $str .= "<optgroup label='Primary Attributes'>";
1894
- foreach ($attributes as $key => $value) {
1895
- $sltd = "";
1896
- if ($selected == $key) {
1897
- $sltd = 'selected="selected"';
1898
- }
1899
- $str .= "<option $sltd value='$key'>" . $value . "</option>";
1900
- }
1901
- $str .= "</optgroup>";
1902
-
1903
- # Additional Images
1904
- if ($images) {
1905
- $str .= "<optgroup label='Image Attributes'>";
1906
- foreach ($images as $key => $value) {
1907
- $sltd = "";
1908
- if ($selected == $key) {
1909
- $sltd = 'selected="selected"';
1910
- }
1911
- $str .= "<option $sltd value='$key'>" . $value . "</option>";
1912
- }
1913
- $str .= "</optgroup>";
1914
- }
1915
-
1916
- # Get All WooCommerce Attributes
1917
- $vAttributes = $this->getAllAttributes();
1918
- if ($vAttributes) {
1919
- $str .= "<optgroup label='Product Attributes'>";
1920
- foreach ($vAttributes as $key => $value) {
1921
- $sltd = "";
1922
- if ($selected == $key) {
1923
- $sltd = 'selected="selected"';
1924
- }
1925
- $str .= "<option $sltd value='$key'>" . $value . "</option>";
1926
- }
1927
- $str .= "</optgroup>";
1928
- }
1929
-
1930
- # Get All Custom Attributes
1931
- $customAttributes = $this->getAllCustomAttributes();
1932
- if ($customAttributes) {
1933
- $str .= "<optgroup label='Variation & Custom Attributes'>";
1934
- foreach ($customAttributes as $key => $value) {
1935
- if (strpos($value, 0, 1) != "_") {
1936
- $sltd = "";
1937
- if ($selected == $key) {
1938
- $sltd = 'selected="selected"';
1939
- }
1940
- $str .= "<option $sltd value='$key'>" . $value . "</option>";
1941
- }
1942
- }
1943
- $str .= "</optgroup>";
1944
- }
1945
- return $str;
1946
- }
1947
-
1948
- /**
1949
- * Load all WooCommerce attributes into an option
1950
- */
1951
- public function load_attributes()
1952
- {
1953
- # Get All WooCommerce Attributes
1954
- $vAttributes = $this->getAllAttributes();
1955
- update_option("wpfw_vAttributes", $vAttributes);
1956
-
1957
- # Get All Custom Attributes
1958
- $customAttributes = $this->getAllCustomAttributes();
1959
- update_option("wpfw_customAttributes", $customAttributes);
1960
- }
1961
-
1962
- /**
1963
- * Local Attribute List to map product value with merchant attributes
1964
- *
1965
- * @param string $selected
1966
- *
1967
- * @return string
1968
- */
1969
- public function loadAttributeDropdown($selected = "")
1970
- {
1971
- $attributes = array(
1972
- "id" => "Product Id",
1973
- "title" => "Product Title",
1974
- "description" => "Product Description",
1975
- "short_description" => "Product Short Description",
1976
- "product_type" => "Product Local Category",
1977
- "link" => "Product URL",
1978
- "ex_link" => "External Product URL",
1979
- "condition" => "Condition",
1980
- "item_group_id" => "Parent Id [Group Id]",
1981
- "sku" => "SKU",
1982
- "parent_sku" => "Parent SKU",
1983
- "availability" => "Availability",
1984
- "quantity" => "Quantity",
1985
- "price" => "Regular Price",
1986
- "sale_price" => "Sale Price",
1987
- "sale_price_sdate" => "Sale Start Date",
1988
- "sale_price_edate" => "Sale End Date",
1989
- "weight" => "Weight",
1990
- "width" => "Width",
1991
- "height" => "Height",
1992
- "length" => "Length",
1993
- "shipping_class" => "Shipping Class",
1994
- "type" => "Product Type",
1995
- "variation_type" => "Variation Type",
1996
- "visibility" => "Visibility",
1997
- "rating_total" => "Total Rating",
1998
- "rating_average" => "Average Rating",
1999
- "tags" => "Tags",
2000
- "sale_price_effective_date" => "Sale Price Effective Date",
2001
- "is_bundle" => "Is Bundle",
2002
- );
2003
-
2004
- $images = array(
2005
- "image" => "Main Image",
2006
- "feature_image" => "Featured Image",
2007
- "images" => "Images [Comma Separated]",
2008
- "image_1" => "Additional Image 1",
2009
- "image_2" => "Additional Image 2",
2010
- "image_3" => "Additional Image 3",
2011
- "image_4" => "Additional Image 4",
2012
- "image_5" => "Additional Image 5",
2013
- "image_6" => "Additional Image 6",
2014
- "image_7" => "Additional Image 7",
2015
- "image_8" => "Additional Image 8",
2016
- "image_9" => "Additional Image 9",
2017
- "image_10" => "Additional Image 10",
2018
- );
2019
-
2020
- # Primary Attributes
2021
- $str = "<option></option>";
2022
- $sltd = "";
2023
- $str .= "<optgroup label='Primary Attributes'>";
2024
- foreach ($attributes as $key => $value) {
2025
- $sltd = "";
2026
- if ($selected == $key) {
2027
- $sltd = 'selected="selected"';
2028
- }
2029
- $str .= "<option $sltd value='$key'>" . $value . "</option>";
2030
- }
2031
- $str .= "</optgroup>";
2032
-
2033
- # Additional Images
2034
- if ($images) {
2035
- $str .= "<optgroup label='Image Attributes'>";
2036
- foreach ($images as $key => $value) {
2037
- $sltd = "";
2038
- if ($selected == $key) {
2039
- $sltd = 'selected="selected"';
2040
- }
2041
- $str .= "<option $sltd value='$key'>" . $value . "</option>";
2042
- }
2043
- $str .= "</optgroup>";
2044
- }
2045
-
2046
- # Get All WooCommerce Attributes
2047
- $vAttributes = get_option("wpfw_vAttributes");
2048
- if ($vAttributes) {
2049
- $str .= "<optgroup label='Product Attributes'>";
2050
- foreach ($vAttributes as $key => $value) {
2051
- $sltd = "";
2052
- if ($selected == $key) {
2053
- $sltd = 'selected="selected"';
2054
- }
2055
- $str .= "<option $sltd value='$key'>" . $value . "</option>";
2056
- }
2057
- $str .= "</optgroup>";
2058
- }
2059
-
2060
- # Get All Custom Attributes
2061
- $customAttributes = get_option("wpfw_customAttributes");
2062
- if ($customAttributes) {
2063
- $str .= "<optgroup label='Variation & Custom Attributes'>";
2064
- foreach ($customAttributes as $key => $value) {
2065
- $sltd = "";
2066
- if ($selected == $key) {
2067
- $sltd = 'selected="selected"';
2068
- }
2069
- $str .= "<option $sltd value='$key'>" . $value . "</option>";
2070
- }
2071
- $str .= "</optgroup>";
2072
- }
2073
- return $str;
2074
- }
2075
-
2076
- /**
2077
- * Check WooCommerce Version
2078
- * @param string $version
2079
- * @return bool
2080
- */
2081
- public static function version_check( $version = '3.0' ) {
2082
- if ( class_exists( 'WooCommerce' ) ) {
2083
- global $woocommerce;
2084
- if ( version_compare( $woocommerce->version, $version, ">=" ) ) {
2085
- return true;
2086
- }
2087
- }
2088
- return false;
2089
- }
2090
  }
11
  class Woo_Feed_Products
12
  {
13
 
14
+ /**
15
+ * Contain all parent product information for the plugin.
16
+ *
17
+ * @since 1.0.0
18
+ * @access protected
19
+ * @var string $parent Contain all parent product information for the plugin.
20
+ */
21
+ public $parent;
22
+
23
+ /**
24
+ * Contain all child product information for the plugin.
25
+ *
26
+ * @since 1.0.0
27
+ * @access protected
28
+ * @var string $parent Contain all child product information for the plugin.
29
+ */
30
+ public $child;
31
+
32
+ /**
33
+ * The parent id of current product.
34
+ *
35
+ * @since 1.0.0
36
+ * @access private
37
+ * @var string $parentID The current product's Parent ID.
38
+ */
39
+ public $parentID;
40
+ /**
41
+ * The child id of current product.
42
+ *
43
+ * @since 1.0.0
44
+ * @access private
45
+ * @var string $parentID The current product's child ID.
46
+ */
47
+ public $childID;
48
+
49
+ /**
50
+ * The Variable that contain all products.
51
+ *
52
+ * @since 1.0.0
53
+ * @access private
54
+ * @var array $productsList Products list array.
55
+ */
56
+ public $productsList;
57
+
58
+ /**
59
+ * The Variable that contain all attributes.
60
+ *
61
+ * @since 1.0.0
62
+ * @access private
63
+ * @var array $attributeList attributes list array.
64
+ */
65
+ public $attributeList;
66
+
67
+ public $feedRule;
68
+ public $idExist=array();
69
  public $pi;
70
 
71
 
117
  $offset = ! empty( $offset ) && is_numeric( $offset ) ? absint( $offset ) : '0';
118
 
119
 
120
+ // try {
121
 
122
 
123
  # Query Arguments
142
  $products = $query->get_products();
143
 
144
  //$products = $this->wooProductQuery($arg);
145
+ //return $products;
146
 
147
  $this->pi = 1; # Product Index
148
  foreach ( $products as $key => $productId ) {
155
 
156
  $simple = new WC_Product_Simple( $id );
157
 
158
+ if($simple->get_status()!="publish"){
159
  continue;
160
  }
161
 
236
  $this->productsList[ $this->pi ][$aKey] = $simple->get_attribute($aKey);
237
  }
238
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
239
  }
240
  else if ( $prod->is_type( 'external' ) ) {
241
 
242
  $external = new WC_Product_External( $id );
243
 
244
+ if($external->get_status()!="publish"){
245
  continue;
246
  }
247
 
323
  $this->productsList[ $this->pi ][$aKey] = $external->get_attribute($aKey);
324
  }
325
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
326
  }
327
  else if ( $prod->is_type( 'grouped' ) ) {
328
 
329
  $grouped = new WC_Product_Grouped( $id );
330
 
331
+ if($grouped->get_status()!="publish"){
332
  continue;
333
  }
334
 
410
  }
411
  }
412
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
413
  }
414
  else if ( $prod->is_type( 'variable' ) ) {
415
 
416
  $variable = new WC_Product_Variable( $id );
417
 
418
+ if($variable->get_status()!="publish"){
419
  continue;
420
  }
421
 
422
 
 
 
 
 
423
  $this->productsList[ $this->pi ]["id"] = $variable->get_id();
424
  $this->productsList[ $this->pi ]["title"] = $variable->get_name();
425
  $this->productsList[ $this->pi ]["description"] = $this->remove_short_codes($variable->get_description());
467
  $this->productsList[ $this->pi ]['sku'] = $variable->get_sku();
468
  $this->productsList[ $this->pi ]['availability'] = $this->availability( $id );
469
 
 
 
 
 
 
 
 
470
 
471
  $this->productsList[ $this->pi ]['quantity'] = $variable->get_stock_quantity();
472
  $this->productsList[ $this->pi ]['sale_price_sdate'] = $variable->get_date_on_sale_from();
499
  $this->productsList[ $this->pi ][$aKey] = $variable->get_attribute($aKey);
500
  }
501
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
502
  }
503
  else if ( $prod->is_type( 'variation' ) && $this->feedRule['provider'] != 'facebook') {
504
  $variation=new WC_Product_Variation($id);
505
 
506
+ # Parent Info
507
+ $parent=new WC_Product_Variable($variation->get_parent_id());
508
+
509
+ # Skip if not a valid product
510
+ if(!$variation->variation_is_visible()){
511
+ continue;
512
+ }
513
+
514
+ if($parent->get_status()!="publish"){
515
  continue;
516
  }
517
 
 
 
518
  $parentInfo=$variation->get_parent_data();
519
  $variationTitle= $parentInfo['title'];
520
 
611
  $this->productsList[ $this->pi ][$aKey] = $variation->get_attribute($aKey);
612
  }
613
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
614
  }
615
 
616
  $this->pi ++;
617
  }
618
 
 
619
  return $this->productsList;
 
620
 
621
+ // }catch (Exception $e){
622
+ // return $this->productsList;
623
+ // }
624
  }
625
 
626
  /**
772
  }
773
 
774
 
775
+ /**
776
+ * Get WooCommerce Product
777
+ * @param string $feedRule
778
+ * @return array
779
+ */
780
+ public function woo_feed_get_visible_product($feedRule="")
781
+ {
782
+ $this->feedRule = $feedRule;
783
+ $limit = ! empty( $feedRule['Limit'] ) && is_numeric( $feedRule['Limit'] ) ? absint( $feedRule['Limit'] ) : '2000';
784
+ $offset = ! empty( $feedRule['Offset'] ) && is_numeric( $feedRule['Offset'] ) ? absint( $feedRule['Offset'] ) : '0';
785
+ # WC 3.1+ Compatibility
786
+
787
+ if ( woo_feed_wc_version_check(3.1) ) {
788
+
789
+ return $this->getWC3Products( $limit, $offset);
790
+
791
+ } else {
792
+ try {
793
+
794
+ if ( ! empty( $feedRule ) ) {
795
+ $this->feedRule = $feedRule;
796
+ }
797
+
798
+
799
+ if ( $offset == '0' ) {
800
+ delete_option( "wf_check_duplicate" );
801
+ }
802
+ $getIDs = get_option( "wf_check_duplicate" );
803
+ $arg = array(
804
+ 'post_type' => array( 'product', 'product_variation' ),
805
+ 'post_status' => 'publish',
806
+ 'posts_per_page' => $limit,
807
+ 'orderby' => 'date',
808
+ 'order' => 'desc',
809
+ 'fields' => 'ids',
810
+ 'offset' => $offset,
811
+ 'cache_results' => false,
812
+ 'update_post_term_cache' => false,
813
+ 'update_post_meta_cache' => false,
814
+ );
815
+
816
+
817
+ # Query Database for products
818
+ $loop = new WP_Query( $arg );
819
+
820
+ $i = 0;
821
+
822
+ while ( $loop->have_posts() ) : $loop->the_post();
823
+
824
+ $this->childID = get_the_ID();
825
+ $this->parentID = ( wp_get_post_parent_id( $this->childID ) ) ? wp_get_post_parent_id( $this->childID ) : $this->childID;
826
+
827
+ global $product;
828
+ if ( ! is_object( $product ) || ! $product->is_visible() ) {
829
+ continue;
830
+ }
831
+
832
+ $type1 = "";
833
+ if ( is_object( $product ) && $product->is_type( 'simple' ) ) {
834
+ # No variations to product
835
+ $type1 = "simple";
836
+ } elseif ( is_object( $product ) && $product->is_type( 'variable' ) ) {
837
+ # Product has variations
838
+ $type1 = "variable";
839
+ } elseif ( is_object( $product ) && $product->is_type( 'grouped' ) ) {
840
+ $type1 = "grouped";
841
+ } elseif ( is_object( $product ) && $product->is_type( 'external' ) ) {
842
+ $type1 = "external";
843
+ } elseif ( is_object( $product ) && $product->is_downloadable() ) {
844
+ $type1 = "downloadable";
845
+ } elseif ( is_object( $product ) && $product->is_virtual() ) {
846
+ $type1 = "virtual";
847
+ }
848
+
849
+
850
+ $post = get_post( $this->parentID );
851
+
852
+ if ( ! is_object( $post ) ) {
853
+ continue;
854
+ }
855
+
856
+ if ( $post->post_status == 'trash' ) {
857
+ continue;
858
+ }
859
+
860
+
861
+ if ( get_post_type() == 'product_variation' && $this->feedRule['provider'] != 'facebook' ) {
862
+ if ( $this->parentID != 0 ) {
863
+
864
+ $status = get_post( $this->childID );
865
+ if ( ! $status || ! is_object( $status ) ) {
866
+ continue;
867
+ }
868
+
869
+ if ( $status->post_status == "trash" ) {
870
+ continue;
871
+ }
872
+
873
+ $parentStatus = get_post( $this->parentID );
874
+ if ( $parentStatus && is_object( $parentStatus ) && $parentStatus->post_status != 'publish' ) {
875
+ continue;
876
+ }
877
+
878
+ # Check Valid URL
879
+ $mainImage = wp_get_attachment_url( $product->get_image_id() );
880
+ $link = $product->get_permalink( $this->childID );
881
+
882
+ if ( $this->feedRule['provider'] != 'custom' ) {
883
+ if ( substr( trim( $link ), 0, 4 ) !== "http" && substr( trim( $mainImage ), 0, 4 ) !== "http" ) {
884
+ continue;
885
+ }
886
+ }
887
+
888
+ if ( $getIDs ) {
889
+ if ( in_array( $this->childID, $getIDs ) ) {
890
+ continue;
891
+ } else {
892
+ array_push( $this->idExist, $this->childID );
893
+ }
894
+ } else {
895
+ array_push( $this->idExist, $this->childID );
896
+ }
897
+
898
+
899
+ $this->productsList[ $i ]['id'] = $this->childID;
900
+ $this->productsList[ $i ]['variation_type'] = "child";
901
+ $this->productsList[ $i ]['item_group_id'] = $this->parentID;
902
+ $this->productsList[ $i ]['sku'] = $this->getAttributeValue( $this->childID, "_sku" );
903
+ $this->productsList[ $i ]['parent_sku'] = $this->getAttributeValue( $this->parentID, "_sku" );
904
+ $this->productsList[ $i ]['title'] = $post->post_title;
905
+ $this->productsList[ $i ]['description'] = $post->post_content;
906
+
907
+ # Short Description to variable description
908
+ $vDesc = $this->getAttributeValue( $this->childID, "_variation_description" );
909
+ if ( ! empty( $vDesc ) ) {
910
+ $this->productsList[ $i ]['short_description'] = $vDesc;
911
+ } else {
912
+ $this->productsList[ $i ]['short_description'] = $post->post_excerpt;
913
+ }
914
+
915
+ $this->productsList[ $i ]['product_type'] = $this->get_product_term_list( $post->ID, 'product_cat', "", ">" );
916
+ $this->productsList[ $i ]['link'] = $link;
917
+ $this->productsList[ $i ]['ex_link'] = "";
918
+ $this->productsList[ $i ]['image'] = $this->get_formatted_url( $mainImage );
919
+
920
+ # Featured Image
921
+ if ( has_post_thumbnail( $post->ID ) ):
922
+ $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' );
923
+ $this->productsList[ $i ]['feature_image'] = $this->get_formatted_url( $image[0] );
924
+ else:
925
+ $this->productsList[ $i ]['feature_image'] = $this->get_formatted_url( $mainImage );
926
+ endif;
927
+
928
+ # Additional Images
929
+ $imageLinks = array();
930
+ $images = $this->additionalImages( $this->childID );
931
+ if ( $images && is_array( $images ) ) {
932
+ $mKey = 1;
933
+ foreach ( $images as $key => $value ) {
934
+ if ( $value != $this->productsList[ $i ]['image'] ) {
935
+ $imgLink = $this->get_formatted_url( $value );
936
+ $this->productsList[ $i ]["image_$mKey"] = $imgLink;
937
+ if ( ! empty( $imgLink ) ) {
938
+ array_push( $imageLinks, $imgLink );
939
+ }
940
+ }
941
+ $mKey ++;
942
+ }
943
+ }
944
+ $this->productsList[ $i ]['images'] = implode( ",", $imageLinks );
945
+ $this->productsList[ $i ]['condition'] = "New";
946
+ $this->productsList[ $i ]['type'] = $product->get_type();
947
+ $this->productsList[ $i ]['visibility'] = $this->getAttributeValue( $this->childID, "_visibility" );
948
+ $this->productsList[ $i ]['rating_total'] = $product->get_rating_count();
949
+ $this->productsList[ $i ]['rating_average'] = $product->get_average_rating();
950
+ $this->productsList[ $i ]['tags'] = $this->get_product_term_list( $post->ID, 'product_tag' );
951
+ $this->productsList[ $i ]['shipping'] = $product->get_shipping_class();
952
+
953
+ $this->productsList[ $i ]['availability'] = $this->availability( $this->childID );
954
+ $this->productsList[ $i ]['quantity'] = $this->get_quantity( $this->childID, "_stock" );
955
+ $this->productsList[ $i ]['sale_price_sdate'] = $this->get_date( $this->childID, "_sale_price_dates_from" );
956
+ $this->productsList[ $i ]['sale_price_edate'] = $this->get_date( $this->childID, "_sale_price_dates_to" );
957
+ $this->productsList[ $i ]['price'] = ( $product->get_regular_price() ) ? $product->get_regular_price() : $product->get_price();
958
+ $this->productsList[ $i ]['sale_price'] = ( $product->get_sale_price() ) ? $product->get_sale_price() : "";
959
+ $this->productsList[ $i ]['weight'] = ( $product->get_weight() ) ? $product->get_weight() : "";
960
+ $this->productsList[ $i ]['width'] = ( $product->get_width() ) ? $product->get_width() : "";
961
+ $this->productsList[ $i ]['height'] = ( $product->get_height() ) ? $product->get_height() : "";
962
+ $this->productsList[ $i ]['length'] = ( $product->get_length() ) ? $product->get_length() : "";
963
+
964
+ # Sale price effective date
965
+ $from = $this->sale_price_effective_date( $this->childID, '_sale_price_dates_from' );
966
+ $to = $this->sale_price_effective_date( $this->childID, '_sale_price_dates_to' );
967
+ if ( ! empty( $from ) && ! empty( $to ) ) {
968
+ $from = date( "c", strtotime( $from ) );
969
+ $to = date( "c", strtotime( $to ) );
970
+ $this->productsList[ $i ]['sale_price_effective_date'] = "$from" . "/" . "$to";
971
+ } else {
972
+ $this->productsList[ $i ]['sale_price_effective_date'] = "";
973
+ }
974
+
975
+ }
976
+ } elseif ( get_post_type() == 'product' ) {
977
+ if ( $type1 == 'simple' ) {
978
+
979
+ $mainImage = wp_get_attachment_url( $product->get_image_id() );
980
+ $link = get_permalink( $post->ID );
981
+
982
+ if ( $this->feedRule['provider'] != 'custom' ) {
983
+ if ( substr( trim( $link ), 0, 4 ) !== "http" && substr( trim( $mainImage ), 0, 4 ) !== "http" ) {
984
+ continue;
985
+ }
986
+ }
987
+
988
+ if ( $getIDs ) {
989
+ if ( in_array( $post->ID, $getIDs ) ) {
990
+ continue;
991
+ } else {
992
+ array_push( $this->idExist, $post->ID );
993
+ }
994
+ } else {
995
+ array_push( $this->idExist, $post->ID );
996
+ }
997
+
998
+ $this->productsList[ $i ]['id'] = $post->ID;
999
+ $this->productsList[ $i ]['variation_type'] = "simple";
1000
+ $this->productsList[ $i ]['title'] = $post->post_title;
1001
+ $this->productsList[ $i ]['description'] = $post->post_content;
1002
+
1003
+ $this->productsList[ $i ]['short_description'] = $post->post_excerpt;
1004
+ $this->productsList[ $i ]['product_type'] = $this->get_product_term_list( $post->ID, 'product_cat', "", ">" );
1005
+ $this->productsList[ $i ]['link'] = $link;
1006
+ $this->productsList[ $i ]['ex_link'] = "";
1007
+ $this->productsList[ $i ]['image'] = $this->get_formatted_url( $mainImage );
1008
+
1009
+ # Featured Image
1010
+ if ( has_post_thumbnail( $post->ID ) ):
1011
+ $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' );
1012
+ $this->productsList[ $i ]['feature_image'] = $this->get_formatted_url( $image[0] );
1013
+ else:
1014
+ $this->productsList[ $i ]['feature_image'] = $this->get_formatted_url( $mainImage );
1015
+ endif;
1016
+
1017
+ # Additional Images
1018
+ $imageLinks = array();
1019
+ $images = $this->additionalImages( $post->ID );
1020
+ if ( $images && is_array( $images ) ) {
1021
+ $mKey = 1;
1022
+ foreach ( $images as $key => $value ) {
1023
+ if ( $value != $this->productsList[ $i ]['image'] ) {
1024
+ $imgLink = $this->get_formatted_url( $value );
1025
+ $this->productsList[ $i ]["image_$mKey"] = $imgLink;
1026
+ if ( ! empty( $imgLink ) ) {
1027
+ array_push( $imageLinks, $imgLink );
1028
+ }
1029
+ }
1030
+ $mKey ++;
1031
+ }
1032
+ }
1033
+ $this->productsList[ $i ]['images'] = implode( ",", $imageLinks );
1034
+
1035
+ $this->productsList[ $i ]['condition'] = "New";
1036
+ $this->productsList[ $i ]['type'] = $product->get_type();
1037
+ $this->productsList[ $i ]['visibility'] = $this->getAttributeValue( $post->ID, "_visibility" );
1038
+ $this->productsList[ $i ]['rating_total'] = $product->get_rating_count();
1039
+ $this->productsList[ $i ]['rating_average'] = $product->get_average_rating();
1040
+ $this->productsList[ $i ]['tags'] = $this->get_product_term_list( $post->ID, 'product_tag' );
1041
+
1042
+ $this->productsList[ $i ]['item_group_id'] = $post->ID;
1043
+ $this->productsList[ $i ]['sku'] = $this->getAttributeValue( $post->ID, "_sku" );
1044
+
1045
+ $this->productsList[ $i ]['availability'] = $this->availability( $post->ID );
1046
+ $this->productsList[ $i ]['quantity'] = $this->get_quantity( $post->ID, "_stock" );
1047
+ $this->productsList[ $i ]['sale_price_sdate'] = $this->get_date( $post->ID, "_sale_price_dates_from" );
1048
+ $this->productsList[ $i ]['sale_price_edate'] = $this->get_date( $post->ID, "_sale_price_dates_to" );
1049
+ $this->productsList[ $i ]['price'] = ( $product->get_regular_price() ) ? $product->get_regular_price() : $product->get_price();
1050
+ $this->productsList[ $i ]['sale_price'] = ( $product->get_sale_price() ) ? $product->get_sale_price() : "";
1051
+ $this->productsList[ $i ]['weight'] = ( $product->get_weight() ) ? $product->get_weight() : "";
1052
+ $this->productsList[ $i ]['width'] = ( $product->get_width() ) ? $product->get_width() : "";
1053
+ $this->productsList[ $i ]['height'] = ( $product->get_height() ) ? $product->get_height() : "";
1054
+ $this->productsList[ $i ]['length'] = ( $product->get_length() ) ? $product->get_length() : "";
1055
+
1056
+ # Sale price effective date
1057
+ $from = $this->sale_price_effective_date( $post->ID, '_sale_price_dates_from' );
1058
+ $to = $this->sale_price_effective_date( $post->ID, '_sale_price_dates_to' );
1059
+ if ( ! empty( $from ) && ! empty( $to ) ) {
1060
+ $from = date( "c", strtotime( $from ) );
1061
+ $to = date( "c", strtotime( $to ) );
1062
+ $this->productsList[ $i ]['sale_price_effective_date'] = "$from" . "/" . "$to";
1063
+ } else {
1064
+ $this->productsList[ $i ]['sale_price_effective_date'] = "";
1065
+ }
1066
+
1067
+ }
1068
+ else if ( $type1 == 'external' ) {
1069
+
1070
+ $mainImage = wp_get_attachment_url( $product->get_image_id() );
1071
+
1072
+ $getLink = new WC_Product_External( $post->ID );
1073
+ $EX_link = $getLink->get_product_url();
1074
+ $link = get_permalink( $post->ID );
1075
+ if ( $this->feedRule['provider'] != 'custom' ) {
1076
+ if ( substr( trim( $link ), 0, 4 ) !== "http" && substr( trim( $mainImage ), 0, 4 ) !== "http" ) {
1077
+ continue;
1078
+ }
1079
+ }
1080
+
1081
+ $this->productsList[ $i ]['id'] = $post->ID;
1082
+ $this->productsList[ $i ]['variation_type'] = "external";
1083
+ $this->productsList[ $i ]['title'] =$post->post_title;
1084
+ $this->productsList[ $i ]['description'] = do_shortcode( $post->post_content );
1085
+
1086
+ $this->productsList[ $i ]['short_description'] = $post->post_excerpt;
1087
+ $this->productsList[ $i ]['product_type'] = $this->get_product_term_list( $post->ID, 'product_cat', "", ">" );
1088
+ $this->productsList[ $i ]['link'] = $link;
1089
+ $this->productsList[ $i ]['ex_link'] = $EX_link;
1090
+ $this->productsList[ $i ]['image'] = $this->get_formatted_url( $mainImage );
1091
+
1092
+ # Featured Image
1093
+ if ( has_post_thumbnail( $post->ID ) ):
1094
+ $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' );
1095
+ $this->productsList[ $i ]['feature_image'] = $this->get_formatted_url( $image[0] );
1096
+ else:
1097
+ $this->productsList[ $i ]['feature_image'] = $this->get_formatted_url( $mainImage );
1098
+ endif;
1099
+
1100
+ # Additional Images
1101
+ $imageLinks = array();
1102
+ $images = $this->additionalImages( $post->ID );
1103
+ if ( $images && is_array( $images ) ) {
1104
+ $mKey = 1;
1105
+ foreach ( $images as $key => $value ) {
1106
+ if ( $value != $this->productsList[ $i ]['image'] ) {
1107
+ $imgLink = $this->get_formatted_url( $value );
1108
+ $this->productsList[ $i ]["image_$mKey"] = $imgLink;
1109
+ if ( ! empty( $imgLink ) ) {
1110
+ array_push( $imageLinks, $imgLink );
1111
+ }
1112
+ }
1113
+ $mKey ++;
1114
+ }
1115
+ }
1116
+ $this->productsList[ $i ]['images'] = implode( ",", $imageLinks );
1117
+
1118
+ $this->productsList[ $i ]['condition'] = "New";
1119
+ $this->productsList[ $i ]['type'] = $product->get_type();
1120
+ $this->productsList[ $i ]['visibility'] = $this->getAttributeValue( $post->ID, "_visibility" );
1121
+ $this->productsList[ $i ]['rating_total'] = $product->get_rating_count();
1122
+ $this->productsList[ $i ]['rating_average'] = $product->get_average_rating();
1123
+ $this->productsList[ $i ]['tags'] = $this->get_product_term_list( $post->ID, 'product_tag' );
1124
+
1125
+ $this->productsList[ $i ]['item_group_id'] = $post->ID;
1126
+ $this->productsList[ $i ]['sku'] = $this->getAttributeValue( $post->ID, "_sku" );
1127
+
1128
+ $this->productsList[ $i ]['availability'] = $this->availability( $post->ID );
1129
+
1130
+ $this->productsList[ $i ]['quantity'] = $this->get_quantity( $post->ID, "_stock" );
1131
+ $this->productsList[ $i ]['sale_price_sdate'] = $this->get_date( $post->ID, "_sale_price_dates_from" );
1132
+ $this->productsList[ $i ]['sale_price_edate'] = $this->get_date( $post->ID, "_sale_price_dates_to" );
1133
+ $this->productsList[ $i ]['price'] = ( $product->get_regular_price() ) ? $product->get_regular_price() : $product->get_price();
1134
+ $this->productsList[ $i ]['sale_price'] = ( $product->get_sale_price() ) ? $product->get_sale_price() : "";
1135
+ $this->productsList[ $i ]['weight'] = ( $product->get_weight() ) ? $product->get_weight() : "";
1136
+ $this->productsList[ $i ]['width'] = ( $product->get_width() ) ? $product->get_width() : "";
1137
+ $this->productsList[ $i ]['height'] = ( $product->get_height() ) ? $product->get_height() : "";
1138
+ $this->productsList[ $i ]['length'] = ( $product->get_length() ) ? $product->get_length() : "";
1139
+
1140
+ # Sale price effective date
1141
+ $from = $this->sale_price_effective_date( $post->ID, '_sale_price_dates_from' );
1142
+ $to = $this->sale_price_effective_date( $post->ID, '_sale_price_dates_to' );
1143
+ if ( ! empty( $from ) && ! empty( $to ) ) {
1144
+ $from = date( "c", strtotime( $from ) );
1145
+ $to = date( "c", strtotime( $to ) );
1146
+ $this->productsList[ $i ]['sale_price_effective_date'] = "$from" . "/" . "$to";
1147
+ } else {
1148
+ $this->productsList[ $i ]['sale_price_effective_date'] = "";
1149
+ }
1150
+
1151
+ }
1152
+ elseif ( $type1 == 'grouped' ) {
1153
+
1154
+ $grouped = new WC_Product_Grouped( $post->ID );
1155
+ $children = $grouped->get_children();
1156
+ $this->parentID = $post->ID;
1157
+ if ( $children ) {
1158
+ foreach ( $children as $cKey => $child ) {
1159
+
1160
+ $product = new WC_Product( $child );
1161
+ $this->childID = $child;
1162
+ $post = get_post( $this->childID );
1163
+
1164
+ if ( $post->post_status == 'trash' ) {
1165
+ continue;
1166
+ }
1167
+
1168
+ if ( ! empty( $this->ids_in ) && ! in_array( $post->ID, $this->ids_in ) ) {
1169
+ continue;
1170
+ }
1171
+
1172
+ if ( ! empty( $this->ids_not_in ) && in_array( $post->ID, $this->ids_in ) ) {
1173
+ continue;
1174
+ }
1175
+
1176
+ if ( ! $product->is_visible() ) {
1177
+ continue;
1178
+ }
1179
+
1180
+ $i ++;
1181
+
1182
+ $mainImage = wp_get_attachment_url( $product->get_image_id() );
1183
+ $link = get_permalink( $post->ID );
1184
+ if ( $this->feedRule['provider'] != 'custom' ) {
1185
+ if ( substr( trim( $link ), 0, 4 ) !== "http" && substr( trim( $mainImage ), 0, 4 ) !== "http" ) {
1186
+ continue;
1187
+ }
1188
+ }
1189
+
1190
+ $this->productsList[ $i ]['id'] = $post->ID;
1191
+ $this->productsList[ $i ]['variation_type'] = "grouped";
1192
+ $this->productsList[ $i ]['title'] = $post->post_title;
1193
+ $this->productsList[ $i ]['description'] = do_shortcode( $post->post_content );
1194
+
1195
+ $this->productsList[ $i ]['short_description'] = $post->post_excerpt;
1196
+ $this->productsList[ $i ]['product_type'] = $this->get_product_term_list( $post->ID, 'product_cat', "", ">" );
1197
+ $this->productsList[ $i ]['link'] = $link;
1198
+ $this->productsList[ $i ]['ex_link'] = "";
1199
+ $this->productsList[ $i ]['image'] = $this->get_formatted_url( $mainImage );
1200
+
1201
+ # Featured Image
1202
+ if ( has_post_thumbnail( $post->ID ) ):
1203
+ $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' );
1204
+ $this->productsList[ $i ]['feature_image'] = $this->get_formatted_url( $image[0] );
1205
+ else:
1206
+ $this->productsList[ $i ]['feature_image'] = $this->get_formatted_url( $mainImage );
1207
+ endif;
1208
+
1209
+ # Additional Images
1210
+ $imageLinks = array();
1211
+ $images = $this->additionalImages( $this->childID );
1212
+ if ( $images and is_array( $images ) ) {
1213
+ $mKey = 1;
1214
+ foreach ( $images as $key => $value ) {
1215
+ if ( $value != $this->productsList[ $i ]['image'] ) {
1216
+ $imgLink = $this->get_formatted_url( $value );
1217
+ $this->productsList[ $i ]["image_$mKey"] = $imgLink;
1218
+ if ( ! empty( $imgLink ) ) {
1219
+ array_push( $imageLinks, $imgLink );
1220
+ }
1221
+ }
1222
+ $mKey ++;
1223
+ }
1224
+ }
1225
+ $this->productsList[ $i ]['images'] = implode( ",", $imageLinks );
1226
+ $this->productsList[ $i ]['condition'] = "New";
1227
+ $this->productsList[ $i ]['type'] = $product->get_type();
1228
+ $this->productsList[ $i ]['visibility'] = $this->getAttributeValue( $post->ID, "_visibility" );
1229
+ $this->productsList[ $i ]['rating_total'] = $product->get_rating_count();
1230
+ $this->productsList[ $i ]['rating_average'] = $product->get_average_rating();
1231
+ $this->productsList[ $i ]['tags'] = $this->get_product_term_list( $post->ID, 'product_tag' );
1232
+
1233
+ $this->productsList[ $i ]['item_group_id'] = $this->parentID;
1234
+ $this->productsList[ $i ]['sku'] = $this->getAttributeValue( $post->ID, "_sku" );
1235
+
1236
+ $this->productsList[ $i ]['availability'] = $this->availability( $post->ID );
1237
+
1238
+ $this->productsList[ $i ]['quantity'] = $this->get_quantity( $post->ID, "_stock" );
1239
+ $this->productsList[ $i ]['sale_price_sdate'] = $this->get_date( $post->ID, "_sale_price_dates_from" );
1240
+ $this->productsList[ $i ]['sale_price_edate'] = $this->get_date( $post->ID, "_sale_price_dates_to" );
1241
+ $this->productsList[ $i ]['price'] = ( $product->get_regular_price() ) ? $product->get_regular_price() : $product->get_price();
1242
+ $this->productsList[ $i ]['sale_price'] = ( $product->get_sale_price() ) ? $product->get_sale_price() : "";
1243
+ $this->productsList[ $i ]['weight'] = ( $product->get_weight() ) ? $product->get_weight() : "";
1244
+ $this->productsList[ $i ]['width'] = ( $product->get_width() ) ? $product->get_width() : "";
1245
+ $this->productsList[ $i ]['height'] = ( $product->get_height() ) ? $product->get_height() : "";
1246
+ $this->productsList[ $i ]['length'] = ( $product->get_length() ) ? $product->get_length() : "";
1247
+
1248
+ # Sale price effective date
1249
+ $from = $this->sale_price_effective_date( $post->ID, '_sale_price_dates_from' );
1250
+ $to = $this->sale_price_effective_date( $post->ID, '_sale_price_dates_to' );
1251
+ if ( ! empty( $from ) && ! empty( $to ) ) {
1252
+ $from = date( "c", strtotime( $from ) );
1253
+ $to = date( "c", strtotime( $to ) );
1254
+ $this->productsList[ $i ]['sale_price_effective_date'] = "$from" . "/" . "$to";
1255
+ } else {
1256
+ $this->productsList[ $i ]['sale_price_effective_date'] = "";
1257
+ }
1258
+ }
1259
+ }
1260
+ }
1261
+ else if ( $type1 == 'variable' && $product->has_child() ) {
1262
+
1263
+ # Check Valid URL
1264
+ $mainImage = wp_get_attachment_url( $product->get_image_id() );
1265
+ $link = get_permalink( $post->ID );
1266
+
1267
+ if ( $this->feedRule['provider'] != 'custom' ) {
1268
+ if ( substr( trim( $link ), 0, 4 ) !== "http" && substr( trim( $mainImage ), 0, 4 ) !== "http" ) {
1269
+ continue;
1270
+ }
1271
+ }
1272
+
1273
+
1274
+ $this->productsList[ $i ]['id'] = $post->ID;
1275
+ $this->productsList[ $i ]['variation_type'] = "parent";
1276
+ $this->productsList[ $i ]['title'] = $post->post_title;
1277
+ $this->productsList[ $i ]['description'] = $post->post_content;
1278
+
1279
+ $this->productsList[ $i ]['short_description'] = $post->post_excerpt;
1280
+ $this->productsList[ $i ]['product_type'] = $this->get_product_term_list( $post->ID, 'product_cat', "", ">" );
1281
+ $this->productsList[ $i ]['link'] = $link;
1282
+ $this->productsList[ $i ]['ex_link'] = "";
1283
+ $this->productsList[ $i ]['image'] = $this->get_formatted_url( $mainImage );
1284
+
1285
+ # Featured Image
1286
+ if ( has_post_thumbnail( $post->ID ) ):
1287
+ $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' );
1288
+ $this->productsList[ $i ]['feature_image'] = $this->get_formatted_url( $image[0] );
1289
+ else:
1290
+ $this->productsList[ $i ]['feature_image'] = $this->get_formatted_url( $mainImage );
1291
+ endif;
1292
+
1293
+ # Additional Images
1294
+ $imageLinks = array();
1295
+ $images = $this->additionalImages( $post->ID );
1296
+ if ( $images and is_array( $images ) ) {
1297
+ $mKey = 1;
1298
+ foreach ( $images as $key => $value ) {
1299
+ if ( $value != $this->productsList[ $i ]['image'] ) {
1300
+ $imgLink = $this->get_formatted_url( $value );
1301
+ $this->productsList[ $i ]["image_$mKey"] = $imgLink;
1302
+ if ( ! empty( $imgLink ) ) {
1303
+ array_push( $imageLinks, $imgLink );
1304
+ }
1305
+ }
1306
+ $mKey ++;
1307
+ }
1308
+ }
1309
+ $this->productsList[ $i ]['images'] = implode( ",", $imageLinks );
1310
+
1311
+ $this->productsList[ $i ]['condition'] = "New";
1312
+ $this->productsList[ $i ]['type'] = $product->get_type();
1313
+ $this->productsList[ $i ]['visibility'] = $this->getAttributeValue( $post->ID, "_visibility" );
1314
+ $this->productsList[ $i ]['rating_total'] = $product->get_rating_count();
1315
+ $this->productsList[ $i ]['rating_average'] = $product->get_average_rating();
1316
+ $this->productsList[ $i ]['tags'] = $this->get_product_term_list( $post->ID, 'product_tag' );
1317
+
1318
+ $this->productsList[ $i ]['item_group_id'] = $post->ID;
1319
+ $this->productsList[ $i ]['sku'] = $this->getAttributeValue( $post->ID, "_sku" );
1320
+
1321
+ $this->productsList[ $i ]['availability'] = $this->availability( $post->ID );
1322
+ $this->productsList[ $i ]['quantity'] = $this->get_quantity( $post->ID, "_stock" );
1323
+ $this->productsList[ $i ]['sale_price_sdate'] = $this->get_date( $post->ID, "_sale_price_dates_from" );
1324
+ $this->productsList[ $i ]['sale_price_edate'] = $this->get_date( $post->ID, "_sale_price_dates_to" );
1325
+
1326
+ $price = ( $product->get_price() ) ? $product->get_price() : false;
1327
+
1328
+ $this->productsList[ $i ]['price'] = ( $product->get_regular_price() ) ? $product->get_regular_price() : $price;
1329
+ $this->productsList[ $i ]['sale_price'] = ( $product->get_sale_price() ) ? $product->get_sale_price() : "";
1330
+ $this->productsList[ $i ]['weight'] = ( $product->get_weight() ) ? $product->get_weight() : "";
1331
+ $this->productsList[ $i ]['width'] = ( $product->get_width() ) ? $product->get_width() : "";
1332
+ $this->productsList[ $i ]['height'] = ( $product->get_height() ) ? $product->get_height() : "";
1333
+ $this->productsList[ $i ]['length'] = ( $product->get_length() ) ? $product->get_length() : "";
1334
+
1335
+ # Sale price effective date
1336
+ $from = $this->sale_price_effective_date( $post->ID, '_sale_price_dates_from' );
1337
+ $to = $this->sale_price_effective_date( $post->ID, '_sale_price_dates_to' );
1338
+ if ( ! empty( $from ) && ! empty( $to ) ) {
1339
+ $from = date( "c", strtotime( $from ) );
1340
+ $to = date( "c", strtotime( $to ) );
1341
+ $this->productsList[ $i ]['sale_price_effective_date'] = "$from" . "/" . "$to";
1342
+ } else {
1343
+ $this->productsList[ $i ]['sale_price_effective_date'] = "";
1344
+ }
1345
+ }
1346
+ }
1347
+ $i ++;
1348
+ endwhile;
1349
+ wp_reset_query();
1350
+
1351
+ if ( $getIDs ) {
1352
+ $mergedIds = array_merge( $getIDs, $this->idExist );
1353
+ update_option( "wf_check_duplicate", $mergedIds );
1354
+ } else {
1355
+ update_option( "wf_check_duplicate", $this->idExist );
1356
+ }
1357
+
1358
+ return $this->productsList;
1359
+ } catch ( Exception $e ) {
1360
+ return $this->productsList;
1361
+ }
1362
+ }
1363
+ }
1364
 
1365
  /**
1366
  * Remove ShortCodes from contents
1371
  public function remove_short_codes($content)
1372
  {
1373
  if(empty($content)){
1374
+ return "";
1375
  }
1376
 
1377
  if(class_exists("WPBMap")){
1383
 
1384
  }
1385
 
1386
+ /**
1387
+ * Get formatted image url
1388
+ *
1389
+ * @param $url
1390
+ * @return bool|string
1391
+ */
1392
+ public function get_formatted_url($url = "")
1393
+ {
1394
+ if (!empty($url)) {
1395
+ if (substr(trim($url), 0, 4) === "http" || substr(trim($url), 0, 3) === "ftp" || substr(trim($url), 0, 4) === "sftp") {
1396
+ return rtrim($url, "/");
1397
+ } else {
1398
+ $base = get_site_url();
1399
+ $url = $base . $url;
1400
+ return rtrim($url, "/");
1401
+ }
1402
+ }
1403
+ return $url;
1404
+ }
1405
+
1406
+
1407
+ /**
1408
+ * Get formatted product date
1409
+ *
1410
+ * @param $id
1411
+ * @param $name
1412
+ * @return bool|string
1413
+ */
1414
+ public function get_date($id, $name)
1415
+ {
1416
+ $date = $this->getAttributeValue($id, $name);
1417
+ if ($date) {
1418
+ return date("Y-m-d", $date);
1419
+ }
1420
+ return false;
1421
+ }
1422
+
1423
+ /**
1424
+ * Get formatted product quantity
1425
+ *
1426
+ * @param $id
1427
+ * @param $name
1428
+ * @return bool|mixed
1429
+ */
1430
+ public function get_quantity($id, $name)
1431
+ {
1432
+ $qty = $this->getAttributeValue($id, $name);
1433
+ if ($qty) {
1434
+ return $qty + 0;
1435
+ }
1436
+ return "0";
1437
+ }
1438
+
1439
+ /**
1440
+ * Retrieve a post's terms as a list with specified format.
1441
+ *
1442
+ * @since 2.5.0
1443
+ *
1444
+ * @param int $id Post ID.
1445
+ * @param string $taxonomy Taxonomy name.
1446
+ * @param string $before Optional. Before list.
1447
+ * @param string $sep Optional. Separate items using this.
1448
+ * @param string $after Optional. After list.
1449
+ *
1450
+ * @return string|false|WP_Error A list of terms on success, false if there are no terms, WP_Error on failure.
1451
+ */
1452
+ function get_product_term_list($id, $taxonomy, $before = '', $sep = ',', $after = '')
1453
+ {
1454
+ $terms = get_the_terms($id, $taxonomy);
1455
+
1456
+ if (is_wp_error($terms)) {
1457
+ return $terms;
1458
+ }
1459
+
1460
+ if (empty($terms)) {
1461
+ return false;
1462
+ }
1463
+
1464
+ $links = array();
1465
+
1466
+ foreach ($terms as $term) {
1467
+ $links[] = $term->name;
1468
+ }
1469
+ ksort($links);
1470
+ return $before . join($sep, $links) . $after;
1471
+ }
1472
+
1473
+ /** Return additional image URLs
1474
+ *
1475
+ * @param int $Id
1476
+ *
1477
+ * @return bool|array
1478
+ */
1479
+
1480
+ public function additionalImages($Id)
1481
+ {
1482
+ $ids=$this->getAttributeValue($Id,"_product_image_gallery");
1483
+ $imgIds=!empty($ids)?explode(",",$ids):"";
1484
+
1485
+ $images = array();
1486
+ if (!empty($imgIds)) {
1487
+ foreach ($imgIds as $key => $value) {
1488
+ if ($key < 10) {
1489
+ $images[$key] = wp_get_attachment_url($value);
1490
+ }
1491
+ }
1492
+ return $images;
1493
+ }
1494
+ return false;
1495
+ }
1496
+
1497
+ /**
1498
+ * Give space to availability text
1499
+ *
1500
+ * @param integer $id
1501
+ *
1502
+ * @return string
1503
+ */
1504
+ public function availability($id)
1505
+ {
1506
+ $status=$this->getAttributeValue($id,"_stock_status");
1507
+ if ($status) {
1508
+ if ($status == 'instock') {
1509
+ return "in stock";
1510
+ } elseif ($status == 'outofstock') {
1511
+ return "out of stock";
1512
+ }
1513
+ }
1514
+ return "out of stock";
1515
+ }
1516
 
1517
  /**
1518
  * Ger Product Attribute
1568
  }
1569
  }
1570
 
1571
+ /**
1572
+ * Get Product Attribute Value
1573
+ *
1574
+ * @deprecated 2.2.5
1575
+ * @param $id
1576
+ * @param $name
1577
+ *
1578
+ * @return mixed
1579
+ */
1580
+ public function getAttributeValue($id, $name)
1581
+ {
1582
+
1583
+ return $this->getProductMeta($id,$name);
1584
  // if (strpos($name, 'attribute_pa') !== false) {
1585
  // $taxonomy = str_replace("attribute_","",$name);
1586
  // $meta = get_post_meta($id,$name, true);
1589
  // }else{
1590
  // return get_post_meta($id, $name, true);
1591
  // }
1592
+ }
1593
 
1594
+ /**
1595
+ * Get Sale price effective date for google
1596
+ *
1597
+ * @param $id
1598
+ * @param $name
1599
+ * @return string
1600
+ */
1601
+ public function sale_price_effective_date($id, $name)
1602
+ {
1603
+ return ($date = $this->getAttributeValue($id, $name)) ? date_i18n('Y-m-d', $date) : "";
1604
+ }
1605
+
1606
+
1607
+ /**
1608
+ * Get All Default WooCommerce Attributes
1609
+ * @return bool|array
1610
+ */
1611
+ public function getAllAttributes()
1612
+ {
1613
+ global $wpdb;
1614
+
1615
+ //Load the main attributes
1616
+ $sql = '
 
 
1617
  SELECT attribute_name as name, attribute_type as type
1618
  FROM ' . $wpdb->prefix . 'woocommerce_attribute_taxonomies';
1619
+ $data = $wpdb->get_results($sql);
1620
+ if (count($data)) {
1621
+ foreach ($data as $key => $value) {
1622
+ $info["wf_attr_pa_" . $value->name] = $value->name;
1623
+ }
1624
+ return $info;
1625
+ }
1626
+ return false;
1627
+ }
1628
+
1629
+
1630
+ /**
1631
+ * Get All Custom Attributes
1632
+ * @return array|bool
1633
+ */
1634
+
1635
+ public function getAllCustomAttributes()
1636
+ {
1637
+ global $wpdb;
1638
+ $info = array();
1639
+ //Load the main attributes
1640
+ $sql = "SELECT meta_key as name, meta_value as type
1641
  FROM " . $wpdb->prefix . "postmeta" . " group by meta_key";
1642
+ $data = $wpdb->get_results($sql);
1643
+ if ($data) {
1644
+ foreach ($data as $key => $value) {
1645
+ if (substr($value->name, 0, 1) !== "_") { //&& substr($value->name, 0, 13) !== "attribute_pa_"
1646
+ $info["wf_cattr_" . $value->name] = $value->name;
1647
+ }
1648
+ }
1649
+ return $info;
1650
+ }
1651
+ return false;
1652
+ }
1653
+
1654
+ /**
1655
+ * Get All Taxonomy
1656
+ *
1657
+ * @param string $name
1658
+ *
1659
+ * @return mixed
1660
+ */
1661
+ public function getAllTaxonomy($name = "color")
1662
+ {
1663
+ global $wpdb;
1664
+ //Load the taxonomies
1665
+ $info = false;
1666
+
1667
+ $sql = "SELECT taxo.taxonomy, terms.name, terms.slug FROM $wpdb->term_taxonomy taxo
1668
  LEFT JOIN $wpdb->terms terms ON (terms.term_id = taxo.term_id) GROUP BY taxo.taxonomy";
1669
+ $data = $wpdb->get_results($sql);
1670
+ if (count($data)) {
1671
+ foreach ($data as $key => $value) {
1672
+ $info["wf_taxo_" . $value->taxonomy] = $value->taxonomy;
1673
+ }
1674
+ }
1675
+ return $info;
1676
+ }
1677
+
1678
+ /**
1679
+ * Get Category Mappings
1680
+ * @return bool|array
1681
+ */
1682
+ public function getCustomCategoryMappedAttributes()
1683
+ {
1684
+ global $wpdb;
1685
+
1686
+ //Load Custom Category Mapped Attributes
1687
+ $var = "wf_cmapping_";
1688
+ $sql = $wpdb->prepare("SELECT * FROM $wpdb->options WHERE option_name LIKE %s;", $var . "%");
1689
+ $data = $wpdb->get_results($sql);
1690
+ if (count($data)) {
1691
+ foreach ($data as $key => $value) {
1692
+ $info[$key] = $value->option_name;
1693
+ }
1694
+ return $info;
1695
+ }
1696
+ return false;
1697
+ }
1698
+
1699
+ /**
1700
+ * Get Dynamic Attribute List
1701
+ * @return bool|array
1702
+ */
1703
+ public function dynamicAttributes()
1704
+ {
1705
+ global $wpdb;
1706
+
1707
+ # Load Custom Category Mapped Attributes
1708
+ $var = "wf_dattribute_";
1709
+ $sql = $wpdb->prepare("SELECT * FROM $wpdb->options WHERE option_name LIKE %s;", $var . "%");
1710
+ $data = $wpdb->get_results($sql);
1711
+ if (count($data)) {
1712
+ foreach ($data as $key => $value) {
1713
+ $info[$key] = $value->option_name;
1714
+ }
1715
+ return $info;
1716
+ }
1717
+ return false;
1718
+ }
1719
+
1720
+ /**
1721
+ * Local Attribute List to map product value with merchant attributes
1722
+ *
1723
+ * @param string $selected
1724
+ *
1725
+ * @return string
1726
+ */
1727
+ public function attributeDropdown($selected = "")
1728
+ {
1729
+ $attributes = array(
1730
+ "id" => "Product Id",
1731
+ "title" => "Product Title",
1732
+ "description" => "Product Description",
1733
+ "short_description" => "Product Short Description",
1734
+ "product_type" => "Product Local Category",
1735
+ "link" => "Product URL",
1736
+ "ex_link" => "External Product URL",
1737
+ "condition" => "Condition",
1738
+ "item_group_id" => "Parent Id [Group Id]",
1739
+ "sku" => "SKU",
1740
+ "parent_sku" => "Parent SKU",
1741
+ "availability" => "Availability",
1742
+ "quantity" => "Quantity",
1743
+ "price" => "Regular Price",
1744
+ "sale_price" => "Sale Price",
1745
+ "sale_price_sdate" => "Sale Start Date",
1746
+ "sale_price_edate" => "Sale End Date",
1747
+ "weight" => "Weight",
1748
+ "width" => "Width",
1749
+ "height" => "Height",
1750
+ "length" => "Length",
1751
+ "shipping_class" => "Shipping Class",
1752
+ "type" => "Product Type",
1753
+ "variation_type" => "Variation Type",
1754
+ "visibility" => "Visibility",
1755
+ "rating_total" => "Total Rating",
1756
+ "rating_average" => "Average Rating",
1757
+ "tags" => "Tags",
1758
+ "sale_price_effective_date" => "Sale Price Effective Date",
1759
+ "is_bundle" => "Is Bundle",
1760
+ );
1761
+
1762
+ $images = array(
1763
+ "image" => "Main Image",
1764
+ "feature_image" => "Featured Image",
1765
+ "images" => "Images [Comma Separated]",
1766
+ "image_1" => "Additional Image 1",
1767
+ "image_2" => "Additional Image 2",
1768
+ "image_3" => "Additional Image 3",
1769
+ "image_4" => "Additional Image 4",
1770
+ "image_5" => "Additional Image 5",
1771
+ "image_6" => "Additional Image 6",
1772
+ "image_7" => "Additional Image 7",
1773
+ "image_8" => "Additional Image 8",
1774
+ "image_9" => "Additional Image 9",
1775
+ "image_10" => "Additional Image 10",
1776
+ );
1777
+
1778
+ # Primary Attributes
1779
+ $str = "<option></option>";
1780
+ $sltd = "";
1781
+ $str .= "<optgroup label='Primary Attributes'>";
1782
+ foreach ($attributes as $key => $value) {
1783
+ $sltd = "";
1784
+ if ($selected == $key) {
1785
+ $sltd = 'selected="selected"';
1786
+ }
1787
+ $str .= "<option $sltd value='$key'>" . $value . "</option>";
1788
+ }
1789
+ $str .= "</optgroup>";
1790
+
1791
+ # Additional Images
1792
+ if ($images) {
1793
+ $str .= "<optgroup label='Image Attributes'>";
1794
+ foreach ($images as $key => $value) {
1795
+ $sltd = "";
1796
+ if ($selected == $key) {
1797
+ $sltd = 'selected="selected"';
1798
+ }
1799
+ $str .= "<option $sltd value='$key'>" . $value . "</option>";
1800
+ }
1801
+ $str .= "</optgroup>";
1802
+ }
1803
+
1804
+ # Get All WooCommerce Attributes
1805
+ $vAttributes = $this->getAllAttributes();
1806
+ if ($vAttributes) {
1807
+ $str .= "<optgroup label='Product Attributes'>";
1808
+ foreach ($vAttributes as $key => $value) {
1809
+ $sltd = "";
1810
+ if ($selected == $key) {
1811
+ $sltd = 'selected="selected"';
1812
+ }
1813
+ $str .= "<option $sltd value='$key'>" . $value . "</option>";
1814
+ }
1815
+ $str .= "</optgroup>";
1816
+ }
1817
+
1818
+ # Get All Custom Attributes
1819
+ $customAttributes = $this->getAllCustomAttributes();
1820
+ if ($customAttributes) {
1821
+ $str .= "<optgroup label='Variation & Custom Attributes'>";
1822
+ foreach ($customAttributes as $key => $value) {
1823
+ if (strpos($value, 0, 1) != "_") {
1824
+ $sltd = "";
1825
+ if ($selected == $key) {
1826
+ $sltd = 'selected="selected"';
1827
+ }
1828
+ $str .= "<option $sltd value='$key'>" . $value . "</option>";
1829
+ }
1830
+ }
1831
+ $str .= "</optgroup>";
1832
+ }
1833
+ return $str;
1834
+ }
1835
+
1836
+ /**
1837
+ * Load all WooCommerce attributes into an option
1838
+ */
1839
+ public function load_attributes()
1840
+ {
1841
+ # Get All WooCommerce Attributes
1842
+ $vAttributes = $this->getAllAttributes();
1843
+ update_option("wpfw_vAttributes", $vAttributes);
1844
+
1845
+ # Get All Custom Attributes
1846
+ $customAttributes = $this->getAllCustomAttributes();
1847
+ update_option("wpfw_customAttributes", $customAttributes);
1848
+ }
1849
+
1850
+ /**
1851
+ * Local Attribute List to map product value with merchant attributes
1852
+ *
1853
+ * @param string $selected
1854
+ *
1855
+ * @return string
1856
+ */
1857
+ public function loadAttributeDropdown($selected = "")
1858
+ {
1859
+ $attributes = array(
1860
+ "id" => "Product Id",
1861
+ "title" => "Product Title",
1862
+ "description" => "Product Description",
1863
+ "short_description" => "Product Short Description",
1864
+ "product_type" => "Product Local Category",
1865
+ "link" => "Product URL",
1866
+ "ex_link" => "External Product URL",
1867
+ "condition" => "Condition",
1868
+ "item_group_id" => "Parent Id [Group Id]",
1869
+ "sku" => "SKU",
1870
+ "parent_sku" => "Parent SKU",
1871
+ "availability" => "Availability",
1872
+ "quantity" => "Quantity",
1873
+ "price" => "Regular Price",
1874
+ "sale_price" => "Sale Price",
1875
+ "sale_price_sdate" => "Sale Start Date",
1876
+ "sale_price_edate" => "Sale End Date",
1877
+ "weight" => "Weight",
1878
+ "width" => "Width",
1879
+ "height" => "Height",
1880
+ "length" => "Length",
1881
+ "shipping_class" => "Shipping Class",
1882
+ "type" => "Product Type",
1883
+ "variation_type" => "Variation Type",
1884
+ "visibility" => "Visibility",
1885
+ "rating_total" => "Total Rating",
1886
+ "rating_average" => "Average Rating",
1887
+ "tags" => "Tags",
1888
+ "sale_price_effective_date" => "Sale Price Effective Date",
1889
+ "is_bundle" => "Is Bundle",
1890
+ );
1891
+
1892
+ $images = array(
1893
+ "image" => "Main Image",
1894
+ "feature_image" => "Featured Image",
1895
+ "images" => "Images [Comma Separated]",
1896
+ "image_1" => "Additional Image 1",
1897
+ "image_2" => "Additional Image 2",
1898
+ "image_3" => "Additional Image 3",
1899
+ "image_4" => "Additional Image 4",
1900
+ "image_5" => "Additional Image 5",
1901
+ "image_6" => "Additional Image 6",
1902
+ "image_7" => "Additional Image 7",
1903
+ "image_8" => "Additional Image 8",
1904
+ "image_9" => "Additional Image 9",
1905
+ "image_10" => "Additional Image 10",
1906
+ );
1907
+
1908
+ # Primary Attributes
1909
+ $str = "<option></option>";
1910
+ $sltd = "";
1911
+ $str .= "<optgroup label='Primary Attributes'>";
1912
+ foreach ($attributes as $key => $value) {
1913
+ $sltd = "";
1914
+ if ($selected == $key) {
1915
+ $sltd = 'selected="selected"';
1916
+ }
1917
+ $str .= "<option $sltd value='$key'>" . $value . "</option>";
1918
+ }
1919
+ $str .= "</optgroup>";
1920
+
1921
+ # Additional Images
1922
+ if ($images) {
1923
+ $str .= "<optgroup label='Image Attributes'>";
1924
+ foreach ($images as $key => $value) {
1925
+ $sltd = "";
1926
+ if ($selected == $key) {
1927
+ $sltd = 'selected="selected"';
1928
+ }
1929
+ $str .= "<option $sltd value='$key'>" . $value . "</option>";
1930
+ }
1931
+ $str .= "</optgroup>";
1932
+ }
1933
+
1934
+ # Get All WooCommerce Attributes
1935
+ $vAttributes = get_option("wpfw_vAttributes");
1936
+ if ($vAttributes) {
1937
+ $str .= "<optgroup label='Product Attributes'>";
1938
+ foreach ($vAttributes as $key => $value) {
1939
+ $sltd = "";
1940
+ if ($selected == $key) {
1941
+ $sltd = 'selected="selected"';
1942
+ }
1943
+ $str .= "<option $sltd value='$key'>" . $value . "</option>";
1944
+ }
1945
+ $str .= "</optgroup>";
1946
+ }
1947
+
1948
+ # Get All Custom Attributes
1949
+ $customAttributes = get_option("wpfw_customAttributes");
1950
+ if ($customAttributes) {
1951
+ $str .= "<optgroup label='Variation & Custom Attributes'>";
1952
+ foreach ($customAttributes as $key => $value) {
1953
+ $sltd = "";
1954
+ if ($selected == $key) {
1955
+ $sltd = 'selected="selected"';
1956
+ }
1957
+ $str .= "<option $sltd value='$key'>" . $value . "</option>";
1958
+ }
1959
+ $str .= "</optgroup>";
1960
+ }
1961
+ return $str;
1962
+ }
1963
+
1964
+ /**
1965
+ * Check WooCommerce Version
1966
+ * @param string $version
1967
+ * @return bool
1968
+ */
1969
+ public static function version_check( $version = '3.0' ) {
1970
+ if ( class_exists( 'WooCommerce' ) ) {
1971
+ global $woocommerce;
1972
+ if ( version_compare( $woocommerce->version, $version, ">=" ) ) {
1973
+ return true;
1974
+ }
1975
+ }
1976
+ return false;
1977
+ }
 
 
1978
  }
woo-feed.php CHANGED
@@ -16,7 +16,7 @@
16
  * Plugin Name: WooCommerce Product Feed
17
  * Plugin URI: https://webappick.com/
18
  * Description: This plugin generate WooCommerce product feed for Shopping Engines like Google Shopping,Facebook Product Feed,eBay,Amazon,Idealo and many more..
19
- * Version: 2.2.8
20
  * Author: WebAppick
21
  * Author URI: https://webappick.com/
22
  * License: GPL v2
@@ -206,7 +206,8 @@ function woo_feed_add_update($info = "", $name = "")
206
  $feedInfo = array(
207
  'feedrules' => $feedRules,
208
  'url' => $url,
209
- 'last_updated' => date("Y-m-d H:i:s")
 
210
  );
211
 
212
  if (!empty($name) && $name != "wf_feed_" . $fileName) {
@@ -289,16 +290,6 @@ function woo_feed_get_product_information(){
289
  $totalProducts=$products->publish + $variations->publish;
290
  }
291
 
292
- // global $wpdb;
293
- // $query = "SELECT DISTINCT {$wpdb->prefix}posts.ID
294
- // FROM {$wpdb->prefix}posts
295
- // LEFT JOIN {$wpdb->prefix}term_relationships ON ({$wpdb->prefix}posts.ID = {$wpdb->prefix}term_relationships.object_id)
296
- // LEFT JOIN {$wpdb->prefix}term_taxonomy ON ({$wpdb->prefix}term_relationships.term_taxonomy_id = {$wpdb->prefix}term_taxonomy.term_taxonomy_id)
297
- // WHERE {$wpdb->prefix}posts.post_type IN ('product','product_variation') AND {$wpdb->prefix}posts.post_status = 'publish'
298
- // ORDER BY ID";
299
- // $products = $wpdb->get_results($query, OBJECT );
300
- //
301
- // $totalProducts=count($products);
302
 
303
  $data=array('product'=>$totalProducts);
304
 
@@ -512,11 +503,16 @@ function woo_feed_save_feed_file(){
512
 
513
  check_ajax_referer('wpf_feed_nonce');
514
  $feed=str_replace("wf_feed_", "",$_POST['feed']);
 
 
515
  $info=get_option($feed);
 
516
  if(!$info){
517
  $getInfo=unserialize(get_option($_POST['feed']));
518
  $info=$getInfo['feedrules'];
519
  }
 
 
520
  $feedService = $info['provider'];
521
  $fileName = str_replace(" ", "",$info['filename']);
522
  $type = $info['feedType'];
@@ -568,6 +564,13 @@ function woo_feed_save_feed_file(){
568
  'last_updated' => date("Y-m-d H:i:s"),
569
  );
570
 
 
 
 
 
 
 
 
571
  if (!empty($name) && $name != "wf_feed_" . $fileName) {
572
  delete_option($name);
573
  }
@@ -677,10 +680,10 @@ function woo_feed_manage_feed()
677
  // if ($process) {
678
  // $message = "<b>Feed Updated Successfully. Feed URL: <a style='font-weight: bold;color:green;' target='_blank' href=$process>$process</a></b>";
679
  // update_option('wpf_message', $message);
680
- // wp_redirect(admin_url("admin.php?page=woo_feed_manage_feed&wpf_message=success"));
681
  // } else {
682
  // update_option('wpf_message', 'Failed To Update Feed');
683
- // wp_redirect(admin_url("admin.php?page=woo_feed_manage_feed&wpf_message=error"));
684
  // }
685
 
686
  $fileName = "wf_config".str_replace(" ", "", sanitize_text_field($_POST['filename']));
@@ -763,6 +766,25 @@ function woo_feed_getFeedInfoForCronUpdate(){
763
  }
764
 
765
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
766
  /*
767
  * Scheduled Action Hook
768
  */
@@ -774,6 +796,8 @@ function woo_feed_cron_update_feed()
774
  $result = $wpdb->get_results($query, 'ARRAY_A');
775
  foreach ($result as $key => $value) {
776
  $feedInfo = unserialize(get_option($value['option_name']));
777
- woo_feed_add_update($feedInfo['feedrules']);
 
 
778
  }
779
  }
16
  * Plugin Name: WooCommerce Product Feed
17
  * Plugin URI: https://webappick.com/
18
  * Description: This plugin generate WooCommerce product feed for Shopping Engines like Google Shopping,Facebook Product Feed,eBay,Amazon,Idealo and many more..
19
+ * Version: 2.2.9
20
  * Author: WebAppick
21
  * Author URI: https://webappick.com/
22
  * License: GPL v2
206
  $feedInfo = array(
207
  'feedrules' => $feedRules,
208
  'url' => $url,
209
+ 'last_updated' => date("Y-m-d H:i:s"),
210
+ 'status'=>1
211
  );
212
 
213
  if (!empty($name) && $name != "wf_feed_" . $fileName) {
290
  $totalProducts=$products->publish + $variations->publish;
291
  }
292
 
 
 
 
 
 
 
 
 
 
 
293
 
294
  $data=array('product'=>$totalProducts);
295
 
503
 
504
  check_ajax_referer('wpf_feed_nonce');
505
  $feed=str_replace("wf_feed_", "",$_POST['feed']);
506
+
507
+
508
  $info=get_option($feed);
509
+
510
  if(!$info){
511
  $getInfo=unserialize(get_option($_POST['feed']));
512
  $info=$getInfo['feedrules'];
513
  }
514
+
515
+
516
  $feedService = $info['provider'];
517
  $fileName = str_replace(" ", "",$info['filename']);
518
  $type = $info['feedType'];
564
  'last_updated' => date("Y-m-d H:i:s"),
565
  );
566
 
567
+ $feedOldInfo=unserialize(get_option("wf_feed_".$fileName));
568
+ if(isset($feedOldInfo['status'])){
569
+ $feedInfo['status']=$feedOldInfo['status'];
570
+ }else{
571
+ $feedInfo['status']=1;
572
+ }
573
+
574
  if (!empty($name) && $name != "wf_feed_" . $fileName) {
575
  delete_option($name);
576
  }
680
  // if ($process) {
681
  // $message = "<b>Feed Updated Successfully. Feed URL: <a style='font-weight: bold;color:green;' target='_blank' href=$process>$process</a></b>";
682
  // update_option('wpf_message', $message);
683
+ // //wp_redirect(admin_url("admin.php?page=woo_feed_manage_feed&wpf_message=success"));
684
  // } else {
685
  // update_option('wpf_message', 'Failed To Update Feed');
686
+ // // wp_redirect(admin_url("admin.php?page=woo_feed_manage_feed&wpf_message=error"));
687
  // }
688
 
689
  $fileName = "wf_config".str_replace(" ", "", sanitize_text_field($_POST['filename']));
766
  }
767
 
768
 
769
+ /**
770
+ * Update feed status
771
+ */
772
+ add_action('wp_ajax_update_feed_status', 'woo_feed_update_feed_status');
773
+ function woo_feed_update_feed_status(){
774
+ if(!empty($_POST['feedName'])){
775
+ $feedInfo = unserialize(get_option($_POST['feedName']));
776
+ $feedInfo['status'] = $_POST['status'];
777
+ $data = array('status' => true);
778
+ update_option($_POST['feedName'],serialize($feedInfo));
779
+ return wp_send_json_success($data);
780
+ }else{
781
+ $data = array('status' => false);
782
+ return wp_send_json_error($data);
783
+ }
784
+ wp_die();
785
+ }
786
+
787
+
788
  /*
789
  * Scheduled Action Hook
790
  */
796
  $result = $wpdb->get_results($query, 'ARRAY_A');
797
  foreach ($result as $key => $value) {
798
  $feedInfo = unserialize(get_option($value['option_name']));
799
+ if(!isset($feedInfo['status']) || $feedInfo['status'] != "0") {
800
+ woo_feed_add_update( $feedInfo['feedrules'] );
801
+ }
802
  }
803
  }