get( 'post_type' ) && is_string( $query->get( 'post_type' ) ) && $query->get( 'post_type' ) === 'product' && is_string( $query->get( 's' ) ) && strlen( $query->get( 's' ) ) > 0 ) { $enabled = true; } return $enabled; }, 10, 2 ); /** * Force orderby (if empty) during AJAX loading of subsequent pages when the Grid * element's pagination is set to "Load items on page scroll" */ add_filter( 'woocommerce_get_catalog_ordering_args', function ( $args ) { if ( function_exists( 'us_maybe_get_post_json' ) ) { $template_vars = us_maybe_get_post_json(); if ( ! empty( $template_vars ) && isset( $template_vars['query_args']['post_type'] ) && $template_vars['query_args']['post_type'] === 'product' && ! empty( $template_vars['query_args']['s'] ) && empty( $template_vars['query_args']['orderby'] ) ) { $args['orderby'] = 'relevance'; $args['order'] = 'DESC'; } } return $args; }, 999, 1 );