YITH WooCommerce Ajax Product Filter - Version 3.0.3

Version Description

  • Released: Jul 6, 2016 =

  • Fixed: Wrong query object in layered nav query with WooCommerce 2.6.2

Download this release

Release Info

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

Code changes from version 3.0.2 to 3.0.3

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.5.2
7
- Stable tag: 3.0.2
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -159,6 +159,10 @@ If you want to see a demonstration version of the premium plugin, you can see it
159
 
160
  == Changelog ==
161
 
 
 
 
 
162
  = 3.0.2 - Released: Jul 4, 2016 =
163
 
164
  * Fixed: Filters disappears in sort count select on Avada theme
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.5.2
7
+ Stable tag: 3.0.3
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
159
 
160
  == Changelog ==
161
 
162
+ = 3.0.3 - Released: Jul 6, 2016 =
163
+
164
+ * Fixed: Wrong query object in layered nav query with WooCommerce 2.6.2
165
+
166
  = 3.0.2 - Released: Jul 4, 2016 =
167
 
168
  * Fixed: Filters disappears in sort count select on Avada theme
includes/class.yith-wcan-frontend.php CHANGED
@@ -44,6 +44,16 @@ if ( ! class_exists( 'YITH_WCAN_Frontend' ) ) {
44
  * @since 1.0.0
45
  */
46
  public function __construct( $version ) {
 
 
 
 
 
 
 
 
 
 
47
  $this->version = $version;
48
  $is_ajax_navigation_active = is_active_widget( false, false, 'yith-woo-ajax-navigation', true );
49
 
@@ -77,6 +87,18 @@ if ( ! class_exists( 'YITH_WCAN_Frontend' ) ) {
77
  }
78
  }
79
 
 
 
 
 
 
 
 
 
 
 
 
 
80
  /**
81
  * Hook into the_posts to do the main product query if needed - relevanssi compatibility.
82
  *
@@ -109,7 +131,7 @@ if ( ! class_exists( 'YITH_WCAN_Frontend' ) ) {
109
  $query->post_count = count( $filtered_posts );
110
 
111
  // Get main query
112
- $current_wp_query = $query->query;
113
 
114
  // Get WP Query for current page (without 'paged')
115
  unset( $current_wp_query['paged'] );
@@ -121,7 +143,7 @@ if ( ! class_exists( 'YITH_WCAN_Frontend' ) ) {
121
  'post_type' => 'product',
122
  'numberposts' => -1,
123
  'post_status' => 'publish',
124
- 'meta_query' => $query->meta_query,
125
  'fields' => 'ids',
126
  'no_found_rows' => true,
127
  'update_post_meta_cache' => false,
@@ -203,7 +225,7 @@ if ( ! class_exists( 'YITH_WCAN_Frontend' ) ) {
203
  public function woocommerce_layered_nav_init() {
204
  $is_ajax_navigation_active = is_active_widget( false, false, 'yith-woo-ajax-navigation', true );
205
 
206
- var_dump( current_action() );
207
 
208
  if ( ! YITH_WCAN()->is_wc_older_2_6 && $is_ajax_navigation_active && ! is_admin() ) {
209
 
@@ -259,9 +281,18 @@ if ( ! class_exists( 'YITH_WCAN_Frontend' ) ) {
259
  * @param array $filtered_posts
260
  * @return array
261
  */
262
- public function layered_nav_query( $filtered_posts = array()) {
263
  $_chosen_attributes = YITH_WCAN()->get_layered_nav_chosen_attributes();
264
 
 
 
 
 
 
 
 
 
 
265
  if ( sizeof( $_chosen_attributes ) > 0 ) {
266
 
267
  $matched_products = array(
@@ -272,16 +303,7 @@ if ( ! class_exists( 'YITH_WCAN_Frontend' ) ) {
272
  'and' => false,
273
  'or' => false
274
  );
275
-
276
- $is_product_taxonomy = false;
277
- if( is_product_taxonomy() ){
278
- $is_product_taxonomy = array(
279
- 'taxonomy' => get_queried_object()->taxonomy,
280
- 'terms' => get_queried_object()->slug,
281
- 'field' => YITH_WCAN()->filter_term_field
282
- );
283
- }
284
-
285
  foreach ( $_chosen_attributes as $attribute => $data ) {
286
  $matched_products_from_attribute = array();
287
  $filtered = false;
@@ -357,6 +379,42 @@ if ( ! class_exists( 'YITH_WCAN_Frontend' ) ) {
357
 
358
  }
359
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
360
  return (array) $filtered_posts;
361
  }
362
 
44
  * @since 1.0.0
45
  */
46
  public function __construct( $version ) {
47
+
48
+ $theme_support = apply_filters( 'yith_wcan_theme_use_wp_the_query_object', array(
49
+ 'porto'
50
+ )
51
+ );
52
+
53
+ if( in_array( strtolower( wp_get_theme()->name ), $theme_support ) ){
54
+ add_filter( 'yith_wcan_use_wp_the_query_object', '__return_true' );
55
+ }
56
+
57
  $this->version = $version;
58
  $is_ajax_navigation_active = is_active_widget( false, false, 'yith-woo-ajax-navigation', true );
59
 
87
  }
88
  }
89
 
90
+ /**
91
+ * Select the correct query object
92
+ *
93
+ * @access public
94
+ * @param WP_Query|bool $query (default: false)
95
+ * @return the query object
96
+ */
97
+ public function select_query_object( $current_wp_query ){
98
+ global $wp_the_query;
99
+ return apply_filters( 'yith_wcan_use_wp_the_query_object', false ) ? $wp_the_query->query : $current_wp_query->query;
100
+ }
101
+
102
  /**
103
  * Hook into the_posts to do the main product query if needed - relevanssi compatibility.
104
  *
131
  $query->post_count = count( $filtered_posts );
132
 
133
  // Get main query
134
+ $current_wp_query = $this->select_query_object( $query );
135
 
136
  // Get WP Query for current page (without 'paged')
137
  unset( $current_wp_query['paged'] );
143
  'post_type' => 'product',
144
  'numberposts' => -1,
145
  'post_status' => 'publish',
146
+ 'meta_query' => $current_wp_query->meta_query,
147
  'fields' => 'ids',
148
  'no_found_rows' => true,
149
  'update_post_meta_cache' => false,
225
  public function woocommerce_layered_nav_init() {
226
  $is_ajax_navigation_active = is_active_widget( false, false, 'yith-woo-ajax-navigation', true );
227
 
228
+
229
 
230
  if ( ! YITH_WCAN()->is_wc_older_2_6 && $is_ajax_navigation_active && ! is_admin() ) {
231
 
281
  * @param array $filtered_posts
282
  * @return array
283
  */
284
+ public function layered_nav_query( $filtered_posts = array() ) {
285
  $_chosen_attributes = YITH_WCAN()->get_layered_nav_chosen_attributes();
286
 
287
+ $is_product_taxonomy = false;
288
+ if( is_product_taxonomy() ){
289
+ $is_product_taxonomy = array(
290
+ 'taxonomy' => get_queried_object()->taxonomy,
291
+ 'terms' => get_queried_object()->slug,
292
+ 'field' => YITH_WCAN()->filter_term_field
293
+ );
294
+ }
295
+
296
  if ( sizeof( $_chosen_attributes ) > 0 ) {
297
 
298
  $matched_products = array(
303
  'and' => false,
304
  'or' => false
305
  );
306
+
 
 
 
 
 
 
 
 
 
307
  foreach ( $_chosen_attributes as $attribute => $data ) {
308
  $matched_products_from_attribute = array();
309
  $filtered = false;
379
 
380
  }
381
  }
382
+
383
+ else {
384
+
385
+ $args = array(
386
+ 'post_type' => 'product',
387
+ 'numberposts' => -1,
388
+ 'post_status' => 'publish',
389
+ 'fields' => 'ids',
390
+ 'no_found_rows' => true,
391
+ 'tax_query' => array()
392
+ );
393
+
394
+
395
+ if( $is_product_taxonomy ){
396
+ $args['tax_query'][] = $is_product_taxonomy;
397
+ }
398
+
399
+ //TODO: Increase performance for get_posts()
400
+ $post_ids = apply_filters( 'woocommerce_layered_nav_query_post_ids', get_posts( $args ), $args, get_queried_object()->taxonomy, get_queried_object()->slug );
401
+
402
+ if( ! is_wp_error( $post_ids ) ){
403
+ $this->layered_nav_post__in = $post_ids;
404
+ $this->layered_nav_post__in[] = 0;
405
+
406
+ if ( sizeof( $filtered_posts ) == 0 ) {
407
+ $filtered_posts = $post_ids;
408
+ $filtered_posts[] = 0;
409
+ }
410
+
411
+ else {
412
+ $filtered_posts = array_intersect( $filtered_posts, $post_ids );
413
+ $filtered_posts[] = 0;
414
+ }
415
+ }
416
+ }
417
+
418
  return (array) $filtered_posts;
419
  }
420
 
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.0.2
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.0.2' );
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.0.3
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.0.3' );
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
 
widgets/class.yith-wcan-navigation-widget.php CHANGED
@@ -675,7 +675,7 @@ if ( ! class_exists( 'YITH_WCAN_Navigation_Widget' ) ) {
675
  // End display type conditional
676
 
677
  echo $after_widget;
678
- $this->found = true;
679
  if ( ! $this->found ) {
680
  ob_end_clean();
681
  echo substr( $before_widget, 0, strlen( $before_widget ) - 1 ) . ' style="display:none">' . $after_widget;
675
  // End display type conditional
676
 
677
  echo $after_widget;
678
+
679
  if ( ! $this->found ) {
680
  ob_end_clean();
681
  echo substr( $before_widget, 0, strlen( $before_widget ) - 1 ) . ' style="display:none">' . $after_widget;