YITH WooCommerce Ajax Product Filter - Version 3.3.0

Version Description

  • Released: 24 February, 2017 =

  • New: Support to WooCoomerce 2.7-beta3

  • Fix: missing argument 2 in yith_wcan_exclude_terms and yith_wcan_include_terms hook

Download this release

Release Info

Developer yithemes
Plugin Icon 128x128 YITH WooCommerce Ajax Product Filter
Version 3.3.0
Comparing to
See all releases

Code changes from version 3.2.0 to 3.3.0

README.txt CHANGED
@@ -4,7 +4,7 @@ Contributors: yithemes
4
  Tags: woocommerce ajax product filter download, woocommerce, widget, ajax, ajax filtered nav, ajax navigation, ajax filtered navigation, woocommerce layered navigation, woocommerce layered nav, product filter, product filters, ajax product filter, woocommerce ajax product filter, woocommerce filters, sidebar filter, sidebar ajax filter, ajax price filter, price filter, product sorting, woocommerce filter, taxonomy filter, attribute filter, attributes filter, woocommerce product sort, ajax sort, woocommerce ajax product filter, advanced product filters, ajax product filters, filters, woocommerce ajax product filters, woocommerce product filters, woocommerce product filters, category filter, attribute filters, woocommerce products filter, woocommerce price filter, yit, yith, yithemes
5
  Requires at least: 4.0
6
  Tested up to: 4.7.2
7
- Stable tag: 3.2.0
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -159,6 +159,11 @@ If you want to see a demonstration version of the premium plugin, you can see it
159
 
160
  == Changelog ==
161
 
 
 
 
 
 
162
  = 3.2.0 - Released: 20 February, 2017 =
163
 
164
  * Add: Back/Next browser button integration
4
  Tags: woocommerce ajax product filter download, woocommerce, widget, ajax, ajax filtered nav, ajax navigation, ajax filtered navigation, woocommerce layered navigation, woocommerce layered nav, product filter, product filters, ajax product filter, woocommerce ajax product filter, woocommerce filters, sidebar filter, sidebar ajax filter, ajax price filter, price filter, product sorting, woocommerce filter, taxonomy filter, attribute filter, attributes filter, woocommerce product sort, ajax sort, woocommerce ajax product filter, advanced product filters, ajax product filters, filters, woocommerce ajax product filters, woocommerce product filters, woocommerce product filters, category filter, attribute filters, woocommerce products filter, woocommerce price filter, yit, yith, yithemes
5
  Requires at least: 4.0
6
  Tested up to: 4.7.2
7
+ Stable tag: 3.3.0
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
159
 
160
  == Changelog ==
161
 
162
+ = 3.3.0 - Released: 24 February, 2017 =
163
+
164
+ * New: Support to WooCoomerce 2.7-beta3
165
+ * Fix: missing argument 2 in yith_wcan_exclude_terms and yith_wcan_include_terms hook
166
+
167
  = 3.2.0 - Released: 20 February, 2017 =
168
 
169
  * Add: Back/Next browser button integration
assets/css/admin.css CHANGED
@@ -34,6 +34,7 @@ div.yit-wcan-widget-tag-list.tags{
34
  p#yit-wcan-style.yit-wcan-style-color,
35
  p#yit-wcan-style.yit-wcan-style-multicolor,
36
  p#yit-wcan-show-count.yit-wcan-show-count-list,
 
37
  p#yit-wcan-show-count.yit-wcan-show-count-brands,
38
  p#yit-wcan-show-count.yit-wcan-show-count-tags{
39
  display: block;
34
  p#yit-wcan-style.yit-wcan-style-color,
35
  p#yit-wcan-style.yit-wcan-style-multicolor,
36
  p#yit-wcan-show-count.yit-wcan-show-count-list,
37
+ p#yit-wcan-show-count.yit-wcan-show-count-categories,
38
  p#yit-wcan-show-count.yit-wcan-show-count-brands,
39
  p#yit-wcan-show-count.yit-wcan-show-count-tags{
40
  display: block;
assets/js/yith-wcan-admin.js CHANGED
@@ -57,7 +57,7 @@ jQuery(function ($) {
57
  style.hide();
58
  }
59
 
60
- if( data.value == 'list' || data.value == 'tags' || data.value == 'brands' ){
61
  show_count.show();
62
  } else {
63
  show_count.hide();
57
  style.hide();
58
  }
59
 
60
+ if( data.value == 'list' || data.value == 'tags' || data.value == 'brands' || data.value == 'categories' ){
61
  show_count.show();
62
  } else {
63
  show_count.hide();
includes/functions.yith-wcan.php CHANGED
@@ -617,7 +617,7 @@ if( ! function_exists( 'yit_terms_sort' ) ){
617
  if( ! function_exists( 'yit_alphabetical_terms_sort' ) ){
618
 
619
  function yit_alphabetical_terms_sort( $a, $b ){
620
- return strnatcmp ( $a->name, $b->name );
621
  }
622
  }
623
 
@@ -656,8 +656,8 @@ if( ! function_exists( 'yit_reorder_hierachical_categories' ) ) {
656
  * @author Andrea Grillo <andrea.grillo@yithemes.com>
657
  */
658
  function yit_reorder_hierachical_categories( $parent_term_id, $taxonomy = 'product_cat' ) {
659
- $exclude = apply_filters( 'yith_wcan_exclude_terms', array() );
660
- $include = apply_filters( 'yith_wcan_include_terms', array() );
661
 
662
  $childs = yith_wcan_wp_get_terms(
663
  array(
617
  if( ! function_exists( 'yit_alphabetical_terms_sort' ) ){
618
 
619
  function yit_alphabetical_terms_sort( $a, $b ){
620
+ return strnatcmp ( strtolower( $a->name ), strtolower( $b->name ) );
621
  }
622
  }
623
 
656
  * @author Andrea Grillo <andrea.grillo@yithemes.com>
657
  */
658
  function yit_reorder_hierachical_categories( $parent_term_id, $taxonomy = 'product_cat' ) {
659
+ $exclude = apply_filters( 'yith_wcan_exclude_terms', array(), array() );
660
+ $include = apply_filters( 'yith_wcan_include_terms', array(), array() );
661
 
662
  $childs = yith_wcan_wp_get_terms(
663
  array(
init.php CHANGED
@@ -3,7 +3,7 @@
3
  * Plugin Name: YITH WooCommerce Ajax Product Filter
4
  * Plugin URI: http://yithemes.com/
5
  * Description: YITH WooCommerce Ajax Product Filter offers the perfect way to filter all the products of your shop.
6
- * Version: 3.2.0
7
  * Author: YITHEMES
8
  * Author URI: http://yithemes.com/
9
  * Text Domain: yith-woocommerce-ajax-navigation
@@ -64,7 +64,7 @@ load_plugin_textdomain( 'yith-woocommerce-ajax-navigation', false, dirname( plug
64
  ! defined( 'YITH_WCAN' ) && define( 'YITH_WCAN', true );
65
  ! defined( 'YITH_WCAN_URL' ) && define( 'YITH_WCAN_URL', plugin_dir_url( __FILE__ ) );
66
  ! defined( 'YITH_WCAN_DIR' ) && define( 'YITH_WCAN_DIR', plugin_dir_path( __FILE__ ) );
67
- ! defined( 'YITH_WCAN_VERSION' ) && define( 'YITH_WCAN_VERSION', '3.2.0' );
68
  ! defined( 'YITH_WCAN_FREE_INIT') && define( 'YITH_WCAN_FREE_INIT', plugin_basename( __FILE__ ) );
69
  ! defined( 'YITH_WCAN_FILE' ) && define( 'YITH_WCAN_FILE', __FILE__ );
70
 
3
  * Plugin Name: YITH WooCommerce Ajax Product Filter
4
  * Plugin URI: http://yithemes.com/
5
  * Description: YITH WooCommerce Ajax Product Filter offers the perfect way to filter all the products of your shop.
6
+ * Version: 3.3.0
7
  * Author: YITHEMES
8
  * Author URI: http://yithemes.com/
9
  * Text Domain: yith-woocommerce-ajax-navigation
64
  ! defined( 'YITH_WCAN' ) && define( 'YITH_WCAN', true );
65
  ! defined( 'YITH_WCAN_URL' ) && define( 'YITH_WCAN_URL', plugin_dir_url( __FILE__ ) );
66
  ! defined( 'YITH_WCAN_DIR' ) && define( 'YITH_WCAN_DIR', plugin_dir_path( __FILE__ ) );
67
+ ! defined( 'YITH_WCAN_VERSION' ) && define( 'YITH_WCAN_VERSION', '3.3.0' );
68
  ! defined( 'YITH_WCAN_FREE_INIT') && define( 'YITH_WCAN_FREE_INIT', plugin_basename( __FILE__ ) );
69
  ! defined( 'YITH_WCAN_FILE' ) && define( 'YITH_WCAN_FILE', __FILE__ );
70
 
plugin-fw/init.php CHANGED
@@ -1,7 +1,7 @@
1
  <?php
2
  /**
3
  * Framework Name: YIT Plugin Framework
4
- * Version: 2.9.41
5
  * Author: Yithemes
6
  * Text Domain: yith-plugin-fw
7
  * Domain Path: /languages/
1
  <?php
2
  /**
3
  * Framework Name: YIT Plugin Framework
4
+ * Version: 2.9.45
5
  * Author: Yithemes
6
  * Text Domain: yith-plugin-fw
7
  * Domain Path: /languages/
plugin-fw/yit-woocommerce-compatibility.php CHANGED
@@ -8,401 +8,508 @@
8
  * http://www.gnu.org/licenses/gpl-3.0.txt
9
  */
10
 
11
- if ( ! defined( 'ABSPATH' ) ) {
12
- exit;
13
  } // Exit if accessed directly
14
 
15
  $changed_objects = array();
16
 
17
- if ( ! function_exists( 'yit_get_prop' ) ) {
18
- /**
19
- *
20
- */
21
- function yit_get_prop( $object, $key, $single = true ) {
22
-
23
- $prop_map = yit_return_new_attribute_map();
24
- $is_wc_data = $object instanceof WC_Data;
25
-
26
- if ( $is_wc_data ) {
27
- $key = ( array_key_exists( $key, $prop_map ) ) ? $prop_map[ $key ] : $key;
28
-
29
- if ( ( $getter = "get{$key}" ) && method_exists( $object, $getter ) ) {
30
- return $object->$getter();
31
- }
32
- elseif ( ( $getter = "get_{$key}" ) && method_exists( $object, $getter ) ) {
33
- return $object->$getter();
34
- }
35
- else {
36
- return $object->get_meta( $key, $single );
37
- }
38
- } else {
39
- $key = ( in_array( $key, $prop_map ) ) ? array_search( $key, $prop_map ) : $key;
40
-
41
- if ( isset( $object->$key ) ) {
42
- return $object->$key;
43
- }
44
- elseif ( yit_wc_check_post_columns( $key ) ) {
45
- return $object->post->$key;
46
- }
47
- else {
48
- $getter = 'get_user_meta';
49
- ! $object instanceof WC_Customer && $getter = 'get_post_meta';
50
-
51
- return $getter( $object->id, $key, true );
52
- }
53
- }
54
- }
55
  }
56
 
57
- if ( ! function_exists( 'yit_set_prop' ) ) {
58
- /**
59
- *
60
- */
61
- function yit_set_prop( $object, $arg1, $arg2 = false ) {
62
-
63
- if( ! is_array( $arg1 ) ){
64
- $arg1 = array(
65
- $arg1 => $arg2
66
- );
67
- }
68
-
69
- $prop_map = yit_return_new_attribute_map();
70
- $is_wc_data = $object instanceof WC_Data;
71
-
72
- foreach( $arg1 as $key => $value ) {
73
- if ( $is_wc_data ) {
74
- $key = ( array_key_exists( $key, $prop_map ) ) ? $prop_map[ $key ] : $key;
75
-
76
- if ( ( $setter = "set{$key}" ) && method_exists( $object, $setter ) ) {
77
- $object->$setter( $value );
78
- }
79
- elseif ( ( $setter = "set_{$key}" ) && method_exists( $object, $setter ) ) {
80
- $object->$setter( $value );
81
- }
82
- else {
83
- $object->update_meta_data( $key, $value );
84
- }
85
- }
86
- else {
87
- $key = ( in_array( $key, $prop_map ) ) ? array_search( $key, $prop_map ) : $key;
88
- ( strpos( $key, '_' ) === 0 ) && $key = substr( $key, 1 );
89
-
90
- if ( yit_wc_check_post_columns( $key ) ) {
91
- $object->post->$key = $value;
92
- }
93
- else {
94
- $object->$key = $value;
95
- }
96
- }
97
- }
98
- }
99
  }
100
 
101
- if ( ! function_exists( 'yit_save_prop' ) ) {
102
- /**
103
- *
104
- */
105
- function yit_save_prop( $object, $arg1, $arg2 = false, $force_meta = false ) {
106
- if( ! is_array( $arg1 ) ){
107
- $arg1 = array(
108
- $arg1 => $arg2
109
- );
110
- }
111
-
112
- $is_wc_data = $object instanceof WC_Data;
113
-
114
- foreach( $arg1 as $key => $value ) {
115
- yit_set_prop( $object, $key, $value );
116
-
117
- if ( $is_wc_data ) {
118
- yit_store_changes( $object, $key, $value );
119
- }
120
- else {
121
- if ( yit_wc_check_post_columns( $key ) ) {
122
- yit_store_changes( $object->post, $key, $value );
123
- }
124
- else {
125
- update_post_meta( $object->id, $key, $value );
126
- }
127
- }
128
- }
129
- }
130
  }
131
 
132
- if ( ! function_exists( 'yit_delete_prop' ) ) {
133
- /**
134
- *
135
- */
136
- function yit_delete_prop( $object, $key, $value = '' ) {
137
- $prop_map = yit_return_new_attribute_map();
138
- $is_wc_data = $object instanceof WC_Data;
139
-
140
- if ( $is_wc_data ) {
141
- $key = ( array_key_exists( $key, $prop_map ) ) ? $prop_map[ $key ] : $key;
142
-
143
- if ( ( $setter = "set{$key}" ) && ( $getter = "get{$key}" ) && method_exists( $object, $setter ) && ( ! $value || $object->$getter == $value ) ) {
144
- $object->$setter( '' );
145
- }
146
- elseif ( ( $setter = "set_{$key}" ) && ( $getter = "get_{$key}" ) && method_exists( $object, $setter ) && ( ! $value || $object->$getter == $value ) ) {
147
- $object->$setter( '' );
148
- }
149
- elseif( ( ! $value || $object->get_meta( $key ) == $value ) ) {
150
- $object->delete_meta_data( $key, $value );
151
- }
152
-
153
- yit_store_changes( $object );
154
- } else {
155
- if ( yit_wc_check_post_columns( $key ) && ( ! $value || $object->post->$key == $value ) ) {
156
- yit_store_changes( $object->post, $key, '' );
157
- }
158
- else {
159
- delete_post_meta( $object->id, $key, $value );
160
- }
161
- }
162
- }
163
  }
164
 
165
- if( ! function_exists( 'yit_return_new_attribute_map' ) ){
166
- function yit_return_new_attribute_map(){
167
- return array(
168
- 'post_parent' => 'parent_id',
169
- 'post_title' => 'name',
170
- 'post_status' => 'status',
171
- 'post_content' => 'description',
172
- 'paid_date' => 'date_paid',
173
- '_paid_date' => '_date_paid',
174
- 'completed_date' => 'date_completed',
175
- '_completed_date' => '_date_completed'
176
- );
177
- }
 
 
 
 
 
 
 
 
 
 
178
  }
179
 
180
- if( ! function_exists( 'yit_store_changes' ) ){
181
- function yit_store_changes( $object, $key = false, $value = false ){
182
- global $changed_objects;
183
 
184
- $is_wc_data = $object instanceof WC_Data;
185
 
186
- if( $is_wc_data ){
187
  /**
188
  * @var $object \WC_Data
189
  */
190
- $class_name = get_class( $object );
191
- $object_reference = $object->get_id();
192
 
193
- $changed_objects[ $object_reference ][ 'object' ] = $object;
194
- $changed_objects[ $object_reference ][ 'changes' ] = array_merge(
195
- isset( $changed_objects[ $object_reference ][ 'changes' ] ) ? $changed_objects[ $object_reference ][ 'changes' ] : array(),
196
- array( $key => $value )
 
 
 
197
  );
198
- }
199
- else {
200
- $changed_objects[ $object->ID ][ $key ] = $value;
201
- }
202
- }
 
203
  }
204
 
205
- if( ! function_exists( 'yit_send_changes_to_db' ) ){
206
- function yit_send_changes_to_db(){
207
- global $changed_objects;
208
 
209
- if( ! empty( $changed_objects ) ){
210
- foreach ( $changed_objects as $id => $data ) {
211
- if( version_compare( WC()->version, '2.7.0', '>=' ) ) {
212
  /**
213
  * @var $object \WC_Data
214
  */
215
- $object = $data['object'];
216
-
217
- yit_set_prop( $object, $data['changes'] );
218
 
219
  $object->save();
220
- }
221
- else{
222
- $data['ID'] = $id;
223
- wp_update_post( $data );
224
- }
225
- }
226
- }
227
- }
228
  }
229
 
230
- if( ! function_exists( 'yit_get_orders' ) ){
231
- /**
232
- *
233
- */
234
- function yit_get_orders( $args ){
235
- if( version_compare( WC()->version, '2.6', '<' ) ){
236
- $args['fields'] = 'objects';
237
- $posts = get_posts( $args );
238
-
239
- return array_map( 'wc_get_order', $posts );
240
- }
241
- else{
242
- return wc_get_orders( $args );
243
- }
244
- }
245
  }
246
 
247
- if( ! function_exists( 'yit_get_products' ) ){
248
- /**
249
- *
250
- */
251
- function yit_get_products( $args ){
252
- if( version_compare( WC()->version, '2.6', '<' ) ){
253
- $args['fields'] = 'objects';
254
- $posts = get_posts( $args );
255
-
256
- return array_map( 'wc_get_product', $posts );
257
- }
258
- else{
259
- return wc_get_products( $args );
260
- }
261
- }
262
  }
263
 
264
- if( ! function_exists( 'yit_update_product_stock' ) ){
265
- /**
266
- *
267
- */
268
- function yit_update_product_stock( $product, $stock_quantity = 1, $operation = 'set' ){
269
- if( function_exists( 'wc_update_product_stock' ) ){
270
- $stock = wc_update_product_stock( $product, $stock_quantity, $operation );
271
- }
272
- else{
273
- switch( $operation ){
274
- case 'increase':
275
- $stock = $product->increase_stock( $stock_quantity );
276
- break;
277
- case 'decrease':
278
- $stock = $product->reduce_stock( $stock_quantity );
279
- break;
280
- case 'set':
281
- default:
282
- $stock = $product->set_stock( $stock_quantity );
283
- break;
284
- }
285
- }
286
-
287
- return $stock;
288
- }
289
  }
290
 
291
- if ( ! function_exists( 'yit_wc_deprecated_filters' ) ) {
292
- /**
293
- *
294
- */
295
- function yit_wc_deprecated_filters() {
296
- return apply_filters( 'yit_wc_deprecated_filters', array(
297
- 'woocommerce_email_order_schema_markup' => 'woocommerce_structured_data_order',
298
- 'woocommerce_product_width' => 'woocommerce_product_get_width',
299
- 'woocommerce_product_height' => 'woocommerce_product_get_height',
300
- 'woocommerce_product_length' => 'woocommerce_product_get_length',
301
- 'woocommerce_product_weight' => 'woocommerce_product_get_weight',
302
- 'woocommerce_get_sku' => 'woocommerce_product_get_sku',
303
- 'woocommerce_get_price' => 'woocommerce_product_get_price',
304
- 'woocommerce_get_regular_price' => 'woocommerce_product_get_regular_price',
305
- 'woocommerce_get_sale_price' => 'woocommerce_product_get_sale_price',
306
- 'woocommerce_product_tax_class' => 'woocommerce_product_get_tax_class',
307
- 'woocommerce_get_stock_quantity' => 'woocommerce_product_get_stock_quantity',
308
- 'woocommerce_get_product_attributes' => 'woocommerce_product_get_attributes',
309
- 'woocommerce_product_gallery_attachment_ids' => 'woocommerce_product_get_gallery_image_ids',
310
- 'woocommerce_product_review_count' => 'woocommerce_product_get_review_count',
311
- 'woocommerce_product_files' => 'woocommerce_product_get_downloads',
312
- 'woocommerce_get_currency' => 'woocommerce_order_get_currency',
313
- 'woocommerce_order_amount_discount_total' => 'woocommerce_order_get_discount_total',
314
- 'woocommerce_order_amount_discount_tax' => 'woocommerce_order_get_discount_tax',
315
- 'woocommerce_order_amount_shipping_total' => 'woocommerce_order_get_shipping_total',
316
- 'woocommerce_order_amount_shipping_tax' => 'woocommerce_order_get_shipping_tax',
317
- 'woocommerce_order_amount_cart_tax' => 'woocommerce_order_get_cart_tax',
318
- 'woocommerce_order_amount_total' => 'woocommerce_order_get_total',
319
- 'woocommerce_order_amount_total_tax' => 'woocommerce_order_get_total_tax',
320
- 'woocommerce_order_amount_total_discount' => 'woocommerce_order_get_total_discount',
321
- 'woocommerce_order_amount_subtotal' => 'woocommerce_order_get_subtotal',
322
- 'woocommerce_order_tax_totals' => 'woocommerce_order_get_tax_totals',
323
- 'woocommerce_refund_amount' => 'woocommerce_get_order_refund_get_amount',
324
- 'woocommerce_refund_reason' => 'woocommerce_get_order_refund_get_reason',
325
- 'default_checkout_country' => 'default_checkout_billing_country',
326
- 'default_checkout_state' => 'default_checkout_billing_state',
327
- 'default_checkout_postcode' => 'default_checkout_billing_postcode',
328
- 'woocommerce_add_order_item_meta' => 'woocommerce_new_order_item',
329
- 'woocommerce_product_write_panels' => 'woocommerce_product_data_panels'
330
- ) );
331
- }
332
  }
333
 
334
- if( ! function_exists( 'yit_fix_wc_deprecated_filters' ) ){
335
- /**
336
- *
337
- */
338
- function yit_fix_wc_deprecated_filters(){
339
-
340
- if( ! version_compare( WC()->version, '2.7.0', '<' ) ) {
341
- return;
342
- }
343
-
344
- $deprecated_filters = yit_wc_deprecated_filters();
345
- foreach ( $deprecated_filters as $old => $new ) {
346
- add_filter( $old, 'yit_wc_deprecated_filter_mapping', 10, 100 );
347
- }
348
- }
349
  }
350
 
351
- if( ! function_exists( 'yit_wc_deprecated_filter_mapping' ) ) {
352
- /**
353
- *
354
- */
355
- function yit_wc_deprecated_filter_mapping() {
356
- $deprecated_filters = yit_wc_deprecated_filters();
357
 
358
- $filter = current_filter();
359
- $args = func_get_args();
360
- $data = $args[0];
361
 
362
 
363
- if ( isset( $deprecated_filters[ $filter ] ) ) {
364
- if ( has_filter( $deprecated_filters[ $filter ] ) ) {
365
- $data = apply_filters_ref_array( $deprecated_filters[ $filter ], $args );
366
- }
367
- }
368
 
369
- return $data;
370
- }
371
  }
372
 
373
- if( ! function_exists( 'yit_wc_check_post_columns' ) ) {
374
- /**
375
- *
376
- */
377
- function yit_wc_check_post_columns( $key ) {
378
- $columns = array(
379
- 'post_author',
380
- 'post_date',
381
- 'post_date_gmt',
382
- 'post_content',
383
- 'post_title',
384
- 'post_excerpt',
385
- 'post_status',
386
- 'comment_status',
387
- 'ping_status',
388
- 'post_password',
389
- 'post_name',
390
- 'to_ping',
391
- 'pinged',
392
- 'post_modified',
393
- 'post_modified_gmt',
394
- 'post_content_filtered',
395
- 'post_parent',
396
- 'guid',
397
- 'menu_order',
398
- 'post_type',
399
- 'post_mime_type',
400
- 'comment_count',
401
- );
402
-
403
- return in_array( $key, $columns );
404
- }
405
  }
406
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
407
  yit_fix_wc_deprecated_filters();
408
  add_action( 'shutdown', 'yit_send_changes_to_db' );
8
  * http://www.gnu.org/licenses/gpl-3.0.txt
9
  */
10
 
11
+ if ( !defined( 'ABSPATH' ) ) {
12
+ exit;
13
  } // Exit if accessed directly
14
 
15
  $changed_objects = array();
16
 
17
+ if ( !function_exists( 'yit_get_prop' ) ) {
18
+ /**
19
+ *
20
+ */
21
+ function yit_get_prop( $object, $key, $single = true, $context = 'view' ) {
22
+
23
+ $prop_map = yit_return_new_attribute_map();
24
+ $is_wc_data = $object instanceof WC_Data;
25
+
26
+ if ( $is_wc_data ) {
27
+ $key = ( array_key_exists( $key, $prop_map ) ) ? $prop_map[ $key ] : $key;
28
+
29
+ if ( ( $getter = "get{$key}" ) && method_exists( $object, $getter ) ) {
30
+ return $object->$getter( $context );
31
+ } elseif ( ( $getter = "get_{$key}" ) && method_exists( $object, $getter ) ) {
32
+ return $object->$getter( $context );
33
+ } else {
34
+ return $object->get_meta( $key, $single );
35
+ }
36
+ } else {
37
+ $key = ( in_array( $key, $prop_map ) ) ? array_search( $key, $prop_map ) : $key;
38
+
39
+ if ( isset( $object->$key ) ) {
40
+ return $object->$key;
41
+ } elseif ( yit_wc_check_post_columns( $key ) ) {
42
+ return $object->post->$key;
43
+ } else {
44
+ $getter = 'get_user_meta';
45
+ !$object instanceof WC_Customer && $getter = 'get_post_meta';
46
+
47
+ return $getter( $object->id, $key, true );
48
+ }
49
+ }
50
+ }
 
 
 
 
51
  }
52
 
53
+ if ( !function_exists( 'yit_set_prop' ) ) {
54
+ /**
55
+ *
56
+ */
57
+ function yit_set_prop( $object, $arg1, $arg2 = false ) {
58
+
59
+ if ( !is_array( $arg1 ) ) {
60
+ $arg1 = array(
61
+ $arg1 => $arg2
62
+ );
63
+ }
64
+
65
+ $prop_map = yit_return_new_attribute_map();
66
+ $is_wc_data = $object instanceof WC_Data;
67
+
68
+ foreach ( $arg1 as $key => $value ) {
69
+ if ( $is_wc_data ) {
70
+ $key = ( array_key_exists( $key, $prop_map ) ) ? $prop_map[ $key ] : $key;
71
+
72
+ if ( ( $setter = "set{$key}" ) && method_exists( $object, $setter ) ) {
73
+ $object->$setter( $value );
74
+ } elseif ( ( $setter = "set_{$key}" ) && method_exists( $object, $setter ) ) {
75
+ $object->$setter( $value );
76
+ } else {
77
+ $object->update_meta_data( $key, $value );
78
+ }
79
+ } else {
80
+ $key = ( in_array( $key, $prop_map ) ) ? array_search( $key, $prop_map ) : $key;
81
+ ( strpos( $key, '_' ) === 0 ) && $key = substr( $key, 1 );
82
+
83
+ if ( yit_wc_check_post_columns( $key ) ) {
84
+ $object->post->$key = $value;
85
+ } else {
86
+ $object->$key = $value;
87
+ }
88
+ }
89
+ }
90
+ }
 
 
 
 
91
  }
92
 
93
+ if ( !function_exists( 'yit_save_prop' ) ) {
94
+ /**
95
+ *
96
+ */
97
+ function yit_save_prop( $object, $arg1, $arg2 = false, $force_meta = false ) {
98
+ if ( !is_array( $arg1 ) ) {
99
+ $arg1 = array(
100
+ $arg1 => $arg2
101
+ );
102
+ }
103
+
104
+ $is_wc_data = $object instanceof WC_Data;
105
+
106
+ foreach ( $arg1 as $key => $value ) {
107
+ yit_set_prop( $object, $key, $value );
108
+
109
+ if ( $is_wc_data ) {
110
+ yit_store_changes( $object, $key, $value );
111
+ } else {
112
+ if ( yit_wc_check_post_columns( $key ) ) {
113
+ yit_store_changes( $object->post, $key, $value );
114
+ } else {
115
+ update_post_meta( $object->id, $key, $value );
116
+ }
117
+ }
118
+ }
119
+ }
 
 
120
  }
121
 
122
+ if ( !function_exists( 'yit_delete_prop' ) ) {
123
+ /**
124
+ *
125
+ */
126
+ function yit_delete_prop( $object, $key, $value = '' ) {
127
+ $prop_map = yit_return_new_attribute_map();
128
+ $is_wc_data = $object instanceof WC_Data;
129
+
130
+ if ( $is_wc_data ) {
131
+ $key = ( array_key_exists( $key, $prop_map ) ) ? $prop_map[ $key ] : $key;
132
+
133
+ if ( ( $setter = "set{$key}" ) && ( $getter = "get{$key}" ) && method_exists( $object, $setter ) && ( !$value || $object->$getter == $value ) ) {
134
+ $object->$setter( '' );
135
+ } elseif ( ( $setter = "set_{$key}" ) && ( $getter = "get_{$key}" ) && method_exists( $object, $setter ) && ( !$value || $object->$getter == $value ) ) {
136
+ $object->$setter( '' );
137
+ } elseif ( ( !$value || $object->get_meta( $key ) == $value ) ) {
138
+ $object->delete_meta_data( $key, $value );
139
+ }
140
+
141
+ yit_store_changes( $object );
142
+ } else {
143
+ if ( yit_wc_check_post_columns( $key ) && ( !$value || $object->post->$key == $value ) ) {
144
+ yit_store_changes( $object->post, $key, '' );
145
+ } else {
146
+ delete_post_meta( $object->id, $key, $value );
147
+ }
148
+ }
149
+ }
 
 
 
150
  }
151
 
152
+ if ( !function_exists( 'yit_return_new_attribute_map' ) ) {
153
+ function yit_return_new_attribute_map() {
154
+ return array(
155
+ 'post_parent' => 'parent_id',
156
+ 'post_title' => 'name',
157
+ 'post_status' => 'status',
158
+ 'post_content' => 'description',
159
+ /* Orders */
160
+ 'paid_date' => 'date_paid',
161
+ '_paid_date' => '_date_paid',
162
+ 'completed_date' => 'date_completed',
163
+ '_completed_date' => '_date_completed',
164
+ '_order_date' => '_date_created',
165
+ 'order_date' => 'date_created',
166
+ /* Products */
167
+ 'visibility' => 'catalog_visibility',
168
+ '_visibility' => '_catalog_visibility',
169
+ 'sale_price_dates_from' => 'date_on_sale_from',
170
+ '_sale_price_dates_from' => '_date_on_sale_from',
171
+ 'sale_price_dates_to' => 'date_on_sale_to',
172
+ '_sale_price_dates_to' => '_date_on_sale_to',
173
+ );
174
+ }
175
  }
176
 
177
+ if ( !function_exists( 'yit_store_changes' ) ) {
178
+ function yit_store_changes( $object, $key = false, $value = false ) {
179
+ global $changed_objects;
180
 
181
+ $is_wc_data = $object instanceof WC_Data;
182
 
183
+ if ( $is_wc_data ) {
184
  /**
185
  * @var $object \WC_Data
186
  */
187
+ $object_reference = $object->get_id();
 
188
 
189
+ $cache_key = is_a( $object, 'WC_Product' ) ? 'product' : 'order';
190
+ $key = $cache_key . '-' . $object_reference;
191
+ $group = $cache_key . 's';
192
+
193
+ $changed_objects[ $object_reference ] = array(
194
+ 'key' => $key,
195
+ 'group' => $group
196
  );
197
+
198
+ wp_cache_set( $key, $object, $group );
199
+ } else {
200
+ $changed_objects[ $object->ID ][ $key ] = $value;
201
+ }
202
+ }
203
  }
204
 
205
+ if ( !function_exists( 'yit_send_changes_to_db' ) ) {
206
+ function yit_send_changes_to_db() {
207
+ global $changed_objects;
208
 
209
+ if ( !empty( $changed_objects ) ) {
210
+ foreach ( $changed_objects as $id => $data ) {
211
+ if ( version_compare( WC()->version, '2.7.0', '>=' ) ) {
212
  /**
213
  * @var $object \WC_Data
214
  */
215
+ $object = wp_cache_get( $data[ 'key' ], $data[ 'group' ] );
 
 
216
 
217
  $object->save();
218
+ } else {
219
+ $data[ 'ID' ] = $id;
220
+ wp_update_post( $data );
221
+ }
222
+ }
223
+ }
224
+ }
 
225
  }
226
 
227
+ if ( !function_exists( 'yit_get_orders' ) ) {
228
+ /**
229
+ *
230
+ */
231
+ function yit_get_orders( $args ) {
232
+ if ( version_compare( WC()->version, '2.6', '<' ) ) {
233
+ $args[ 'fields' ] = 'objects';
234
+ $posts = get_posts( $args );
235
+
236
+ return array_map( 'wc_get_order', $posts );
237
+ } else {
238
+ return wc_get_orders( $args );
239
+ }
240
+ }
 
241
  }
242
 
243
+ if ( !function_exists( 'yit_get_products' ) ) {
244
+ /**
245
+ *
246
+ */
247
+ function yit_get_products( $args ) {
248
+ if ( version_compare( WC()->version, '2.6', '<' ) ) {
249
+ $args[ 'fields' ] = 'objects';
250
+ $posts = get_posts( $args );
251
+
252
+ return array_map( 'wc_get_product', $posts );
253
+ } else {
254
+ return wc_get_products( $args );
255
+ }
256
+ }
 
257
  }
258
 
259
+ if ( !function_exists( 'yit_update_product_stock' ) ) {
260
+ /**
261
+ *
262
+ */
263
+ function yit_update_product_stock( $product, $stock_quantity = 1, $operation = 'set' ) {
264
+ if ( function_exists( 'wc_update_product_stock' ) ) {
265
+ $stock = wc_update_product_stock( $product, $stock_quantity, $operation );
266
+ } else {
267
+ switch ( $operation ) {
268
+ case 'increase':
269
+ $stock = $product->increase_stock( $stock_quantity );
270
+ break;
271
+ case 'decrease':
272
+ $stock = $product->reduce_stock( $stock_quantity );
273
+ break;
274
+ case 'set':
275
+ default:
276
+ $stock = $product->set_stock( $stock_quantity );
277
+ break;
278
+ }
279
+ }
280
+
281
+ return $stock;
282
+ }
 
283
  }
284
 
285
+ if ( !function_exists( 'yit_wc_deprecated_filters' ) ) {
286
+ /**
287
+ *
288
+ */
289
+ function yit_wc_deprecated_filters() {
290
+ return apply_filters( 'yit_wc_deprecated_filters', array(
291
+ 'woocommerce_email_order_schema_markup' => 'woocommerce_structured_data_order',
292
+ 'woocommerce_product_width' => 'woocommerce_product_get_width',
293
+ 'woocommerce_product_height' => 'woocommerce_product_get_height',
294
+ 'woocommerce_product_length' => 'woocommerce_product_get_length',
295
+ 'woocommerce_product_weight' => 'woocommerce_product_get_weight',
296
+ 'woocommerce_get_sku' => 'woocommerce_product_get_sku',
297
+ 'woocommerce_get_price' => 'woocommerce_product_get_price',
298
+ 'woocommerce_get_regular_price' => 'woocommerce_product_get_regular_price',
299
+ 'woocommerce_get_sale_price' => 'woocommerce_product_get_sale_price',
300
+ 'woocommerce_product_tax_class' => 'woocommerce_product_get_tax_class',
301
+ 'woocommerce_get_stock_quantity' => 'woocommerce_product_get_stock_quantity',
302
+ 'woocommerce_get_product_attributes' => 'woocommerce_product_get_attributes',
303
+ 'woocommerce_product_gallery_attachment_ids' => 'woocommerce_product_get_gallery_image_ids',
304
+ 'woocommerce_product_review_count' => 'woocommerce_product_get_review_count',
305
+ 'woocommerce_product_files' => 'woocommerce_product_get_downloads',
306
+ 'woocommerce_get_currency' => 'woocommerce_order_get_currency',
307
+ 'woocommerce_order_amount_discount_total' => 'woocommerce_order_get_discount_total',
308
+ 'woocommerce_order_amount_discount_tax' => 'woocommerce_order_get_discount_tax',
309
+ 'woocommerce_order_amount_shipping_total' => 'woocommerce_order_get_shipping_total',
310
+ 'woocommerce_order_amount_shipping_tax' => 'woocommerce_order_get_shipping_tax',
311
+ 'woocommerce_order_amount_cart_tax' => 'woocommerce_order_get_cart_tax',
312
+ 'woocommerce_order_amount_total' => 'woocommerce_order_get_total',
313
+ 'woocommerce_order_amount_total_tax' => 'woocommerce_order_get_total_tax',
314
+ 'woocommerce_order_amount_total_discount' => 'woocommerce_order_get_total_discount',
315
+ 'woocommerce_order_amount_subtotal' => 'woocommerce_order_get_subtotal',
316
+ 'woocommerce_order_tax_totals' => 'woocommerce_order_get_tax_totals',
317
+ 'woocommerce_refund_amount' => 'woocommerce_get_order_refund_get_amount',
318
+ 'woocommerce_refund_reason' => 'woocommerce_get_order_refund_get_reason',
319
+ 'default_checkout_country' => 'default_checkout_billing_country',
320
+ 'default_checkout_state' => 'default_checkout_billing_state',
321
+ 'default_checkout_postcode' => 'default_checkout_billing_postcode',
322
+ 'woocommerce_add_order_item_meta' => 'woocommerce_new_order_item',
323
+
324
+ ) );
325
+ }
326
  }
327
 
328
+ if ( !function_exists( 'yit_fix_wc_deprecated_filters' ) ) {
329
+ /**
330
+ *
331
+ */
332
+ function yit_fix_wc_deprecated_filters() {
333
+
334
+ if ( !version_compare( WC()->version, '2.7.0', '<' ) ) {
335
+ return;
336
+ }
337
+
338
+ $deprecated_filters = yit_wc_deprecated_filters();
339
+ foreach ( $deprecated_filters as $old => $new ) {
340
+ add_filter( $old, 'yit_wc_deprecated_filter_mapping', 10, 100 );
341
+ }
342
+ }
343
  }
344
 
345
+ if ( !function_exists( 'yit_wc_deprecated_filter_mapping' ) ) {
346
+ /**
347
+ *
348
+ */
349
+ function yit_wc_deprecated_filter_mapping() {
350
+ $deprecated_filters = yit_wc_deprecated_filters();
351
 
352
+ $filter = current_filter();
353
+ $args = func_get_args();
354
+ $data = $args[ 0 ];
355
 
356
 
357
+ if ( isset( $deprecated_filters[ $filter ] ) ) {
358
+ if ( has_filter( $deprecated_filters[ $filter ] ) ) {
359
+ $data = apply_filters_ref_array( $deprecated_filters[ $filter ], $args );
360
+ }
361
+ }
362
 
363
+ return $data;
364
+ }
365
  }
366
 
367
+ if ( !function_exists( 'yit_wc_check_post_columns' ) ) {
368
+ /**
369
+ *
370
+ */
371
+ function yit_wc_check_post_columns( $key ) {
372
+ $columns = array(
373
+ 'post_author',
374
+ 'post_date',
375
+ 'post_date_gmt',
376
+ 'post_content',
377
+ 'post_title',
378
+ 'post_excerpt',
379
+ 'post_status',
380
+ 'comment_status',
381
+ 'ping_status',
382
+ 'post_password',
383
+ 'post_name',
384
+ 'to_ping',
385
+ 'pinged',
386
+ 'post_modified',
387
+ 'post_modified_gmt',
388
+ 'post_content_filtered',
389
+ 'post_parent',
390
+ 'guid',
391
+ 'menu_order',
392
+ 'post_type',
393
+ 'post_mime_type',
394
+ 'comment_count',
395
+ );
396
+
397
+ return in_array( $key, $columns );
398
+ }
399
  }
400
 
401
+
402
+ /* Shortcuts for common functions */
403
+
404
+ if ( !function_exists( 'yit_get_order_id' ) ) {
405
+ /**
406
+ * Retrieve the order id
407
+ *
408
+ * @param WC_Order $order
409
+ *
410
+ * @return mixed
411
+ */
412
+ function yit_get_order_id( $order ) {
413
+ return yit_get_prop( $order, 'id' );
414
+ }
415
+ }
416
+
417
+ if ( !function_exists( 'yit_get_product_id' ) ) {
418
+ /**
419
+ * Retrieve the product id
420
+ *
421
+ * @param WC_Product $product
422
+ *
423
+ * @return mixed
424
+ */
425
+ function yit_get_product_id( $product ) {
426
+ return yit_get_prop( $product, 'id' );
427
+ }
428
+ }
429
+
430
+ if ( !function_exists( 'yit_get_base_product_id' ) ) {
431
+ /**
432
+ * New way to retrieve the $product->id as it was before WC 2.7.
433
+ *
434
+ * Retrieve the parent product id for WC_Product_Variation instances
435
+ * or the product id in the other cases.
436
+ *
437
+ * @param WC_Product $product
438
+ *
439
+ * @return mixed
440
+ */
441
+ function yit_get_base_product_id( $product ) {
442
+
443
+ return $product->is_type( 'variation' ) ?
444
+ yit_get_prop( $product, 'parent_id' ) :
445
+ yit_get_prop( $product, 'id' );
446
+ }
447
+ }
448
+
449
+ if ( !function_exists( 'yit_get_display_price' ) ) {
450
+ /**
451
+ * @param WC_Product $product
452
+ * @param string $price
453
+ * @param int $qty
454
+ */
455
+ function yit_get_display_price( $product, $price = '', $qty = 1 ) {
456
+
457
+ if ( version_compare( WC()->version, '2.7.0', '>=' ) ) {
458
+
459
+ $price = wc_get_price_to_display( $product, array( 'qty' => $qty, 'price' => $price ) );
460
+ } else {
461
+
462
+ $price = $product->get_display_price( $price, $qty );
463
+ }
464
+
465
+ return $price;
466
+ }
467
+ }
468
+
469
+ if ( !function_exists( 'yit_get_price_excluding_tax' ) ) {
470
+ /**
471
+ * @param WC_Product $product
472
+ * @param int $qty
473
+ * @param string $price
474
+ *
475
+ * @return float|string
476
+ */
477
+ function yit_get_price_excluding_tax( $product, $qty = 1, $price = '' ) {
478
+
479
+ if ( version_compare( WC()->version, '2.7.0', '>=' ) ) {
480
+
481
+ $price = wc_get_price_excluding_tax( $product, array( 'qty' => $qty, 'price' => $price ) );
482
+ } else {
483
+
484
+ $price = $product->get_price_excluding_tax( $qty, $price );
485
+ }
486
+
487
+ return $price;
488
+ }
489
+ }
490
+
491
+ if ( !function_exists( 'yit_get_price_including_tax' ) ) {
492
+ /**
493
+ * @param WC_Product $product
494
+ * @param int $qty
495
+ * @param string $price
496
+ *
497
+ * @return float|string
498
+ */
499
+ function yit_get_price_including_tax( $product, $qty = 1, $price = '' ) {
500
+
501
+ if ( version_compare( WC()->version, '2.7.0', '>=' ) ) {
502
+
503
+ $price = wc_get_price_including_tax( $product, array( 'qty' => $qty, 'price' => $price ) );
504
+ } else {
505
+
506
+ $price = $product->get_price_including_tax( $qty, $price );
507
+ }
508
+
509
+ return $price;
510
+ }
511
+ }
512
+
513
+
514
  yit_fix_wc_deprecated_filters();
515
  add_action( 'shutdown', 'yit_send_changes_to_db' );