title: Woocommerce price sorting not working
body: <p>Almost all the guides to implement price sorting on woocommerce site are the same. I've tried two main ways. 1st - hooked up my query args from functions.php like this:</p>
  
  <pre><code>add_filter('woocommerce_get_catalog_ordering_args', 'my_custom_woocommerce_catalog_orderby');
  
  function my_custom_woocommerce_catalog_orderby( $args ) {
      if(isset($_GET['sort'])){
        if($_GET['sort_by'] == 'by_rating'){        
          $args['meta_key'] = '_wc_average_rating';
        } else if($_GET['sort_by'] == 'by_price') {
          $args['meta_key'] = '_price';
        }
        $args['orderby']  = 'meta_value_num';
        $args['order'] = strtoupper($_GET['sort']);  
      }
      return $args;
  } 
  </code></pre>
  
  <p>var_dump shows that it has been catched:</p>
  
  <pre><code>array(3) { ["orderby"]=&gt; string(14) "meta_value_num" ["order"]=&gt; string(4) "DESC" ["meta_key"]=&gt; string(6) "_price" }
  </code></pre>
  
  <p>But products are still sorted by default woocommerce setting (price, asc).</p>
  
  <p>Then i implemented my filter plugin (which is working pretty well) and tried to add this sorting query to it.</p>
  
  <pre><code>class My_blah_blah_filter {
    public static $instance;
    public $productquery;
    public static function init() {
      if ( is_null( self::$instance ) ) {
        self::$instance = new My_blah_blah_filter ();
      }
      return self::$instance;
    }
    private function __construct() {
      add_action( 'woocommerce_product_query', [ $this, 'filter_by_current_range' ] );
    }
  
    public function filter_by_current_range( $query ) {
  
      $this-&gt;productquery = $query;
      $query-&gt;set('tax_query', $this-&gt;get_tax_query());
  
      if(isset($_GET['sort'])){
        if($_GET['sort_by'] == 'by_rating'){
          $query-&gt;set('meta_key', '_wc_average_rating');
        } else if($_GET['sort_by'] == 'by_price') {
          $query-&gt;set('meta_key', '_price');
        } else {
          $query-&gt;set('meta_key', '_price');
        }
        $query-&gt;set('orderby', 'meta_value_num');
        $query-&gt;set('order', strtoupper($_GET['sort']));  
      }
    }
  
    public function get_tax_query() {
  
      // pa_space-overall
      $tax_query = [];
      if( isset( $_GET['max_so'] ) &amp;&amp; isset( $_GET['min_so'] ) ) {
        $terms = get_terms([
          'taxonomy' =&gt; 'pa_space-overall',
        ]);
        $rlt = [];
        foreach( $terms as $term ) {
          if( (int) $term-&gt;name &lt;= (int) $_GET['max_so'] &amp;&amp; (int) $term-&gt;name &gt;= (int) $_GET['min_so'] ) {
            $rlt[] = $term-&gt;term_id;
          }
        }
  
        $tax_query = [
          'relation' =&gt; 'AND',
          [
            'taxonomy' =&gt; 'pa_space-overall',
            'terms' =&gt; $rlt,
            'operator' =&gt; 'IN',
          ],
        ];
      }
      if( isset( $this-&gt;productquery-&gt;tax_query ) ) {
        $tax_query = array_merge( $this-&gt;productquery-&gt;query_vars['tax_query'], $tax_query );
      }
  
      return $tax_query;
  }
  </code></pre>
  
  <p>Some stuff here is hardcoded, but its not the case, its working. But not the ordering. Its still being catched, added to query, but order is default anyways (price, asc - from woocommerce settings)
  The only plugin except woocommerce - is advanced custom fields, which has nothing to do with it. </p>
  
  <p>Cant find any solution anywhere else. Any suggestions? Thanks in advance.
  Sorry for poor english or not-perfectly-formatted code</p>