When searching, disable WC sort order

Closes #14292
This commit is contained in:
Mike Jolley 2017-04-12 12:42:55 +01:00
parent e7acb2918c
commit 3fe7df6515
2 changed files with 10 additions and 6 deletions

View File

@ -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

View File

@ -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;
}