From 3353505be52a2c961f30a7847d7b33155b74ca56 Mon Sep 17 00:00:00 2001 From: Shiva Poudel Date: Thu, 14 Dec 2017 15:37:12 +0545 Subject: [PATCH] Tweak - Duplicate relevance orderby for catalog --- includes/class-wc-query.php | 39 +++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 21 deletions(-) diff --git a/includes/class-wc-query.php b/includes/class-wc-query.php index 53b1b96550e..72a42e6182c 100644 --- a/includes/class-wc-query.php +++ b/includes/class-wc-query.php @@ -450,48 +450,44 @@ class WC_Query { ); switch ( $orderby ) { - case 'menu_order' : + case 'menu_order': $args['orderby'] = 'menu_order title'; break; - case 'relevance' : - $args['orderby']= 'relevance'; - $args['order'] = 'DESC'; + case 'title': + $args['orderby'] = 'title'; + $args['order'] = ( 'DESC' === $order ) ? 'DESC' : 'ASC'; break; - case 'rand' : - $args['orderby'] = 'rand'; // @codingStandardsIgnoreLine + case 'relevance': + $args['orderby'] = 'relevance'; + $args['order'] = 'DESC'; break; - case 'date' : - $args['orderby'] = 'date ID'; - $args['order'] = ( 'ASC' === $order ) ? 'ASC' : 'DESC'; + case 'rand': + $args['orderby'] = 'rand'; // @codingStandardsIgnoreLine break; - case 'price' : + case 'date': + $args['orderby'] = 'date ID'; + $args['order'] = ( 'ASC' === $order ) ? 'ASC' : 'DESC'; + break; + case 'price': if ( 'DESC' === $order ) { add_filter( 'posts_clauses', array( $this, 'order_by_price_desc_post_clauses' ) ); } else { add_filter( 'posts_clauses', array( $this, 'order_by_price_asc_post_clauses' ) ); } break; - case 'popularity' : + case 'popularity': $args['meta_key'] = 'total_sales'; // @codingStandardsIgnoreLine // Sorting handled later though a hook. add_filter( 'posts_clauses', array( $this, 'order_by_popularity_post_clauses' ) ); break; - case 'rating' : + case 'rating': $args['meta_key'] = '_wc_average_rating'; // @codingStandardsIgnoreLine $args['orderby'] = array( 'meta_value_num' => 'DESC', 'ID' => 'ASC', ); break; - case 'title' : - $args['orderby'] = 'title'; - $args['order'] = ( 'DESC' === $order ) ? 'DESC' : 'ASC'; - break; - case 'relevance' : - $args['orderby'] = 'relevance'; - $args['order'] = 'DESC'; - break; } return apply_filters( 'woocommerce_get_catalog_ordering_args', $args ); @@ -740,8 +736,9 @@ class WC_Query { public static function get_layered_nav_chosen_attributes() { if ( ! is_array( self::$_chosen_attributes ) ) { self::$_chosen_attributes = array(); + $attribute_taxonomies = wc_get_attribute_taxonomies(); - if ( $attribute_taxonomies = wc_get_attribute_taxonomies() ) { + if ( ! empty( $attribute_taxonomies ) ) { foreach ( $attribute_taxonomies as $tax ) { $attribute = wc_sanitize_taxonomy_name( $tax->attribute_name ); $taxonomy = wc_attribute_taxonomy_name( $attribute );