From 3fe7df65150ef6974a7849009a85ed2c146bf0ec Mon Sep 17 00:00:00 2001 From: Mike Jolley Date: Wed, 12 Apr 2017 12:42:55 +0100 Subject: [PATCH] When searching, disable WC sort order Closes #14292 --- includes/class-wc-query.php | 14 +++++++++----- includes/wc-template-functions.php | 2 +- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/includes/class-wc-query.php b/includes/class-wc-query.php index 66127445711..67a2813e9ee 100644 --- a/includes/class-wc-query.php +++ b/includes/class-wc-query.php @@ -384,11 +384,15 @@ class WC_Query { */ public function product_query( $q ) { // Ordering query vars - $ordering = $this->get_catalog_ordering_args(); - $q->set( 'orderby', $ordering['orderby'] ); - $q->set( 'order', $ordering['order'] ); - if ( isset( $ordering['meta_key'] ) ) { - $q->set( 'meta_key', $ordering['meta_key'] ); + if ( ! $q->is_search() ) { + $ordering = $this->get_catalog_ordering_args(); + $q->set( 'orderby', $ordering['orderby'] ); + $q->set( 'order', $ordering['order'] ); + if ( isset( $ordering['meta_key'] ) ) { + $q->set( 'meta_key', $ordering['meta_key'] ); + } + } else { + $q->set( 'orderby', 'relevance' ); } // Query vars that affect posts shown diff --git a/includes/wc-template-functions.php b/includes/wc-template-functions.php index 2b2e52323fb..74bcbc69676 100644 --- a/includes/wc-template-functions.php +++ b/includes/wc-template-functions.php @@ -787,7 +787,7 @@ if ( ! function_exists( 'woocommerce_catalog_ordering' ) ) { function woocommerce_catalog_ordering() { global $wp_query; - if ( 1 === (int) $wp_query->found_posts || ! woocommerce_products_will_display() ) { + if ( 1 === (int) $wp_query->found_posts || ! woocommerce_products_will_display() || $wp_query->is_search() ) { return; }