title: Wordpress ordered by two custom fields meta_key's
body: <p>I have a Woocomerce query working with one meta_key ( '<code>countdown_date</code>' <strong>or</strong> '<code>hour</code>' ).</p>
  
  <p>It sorts the products by a custom <code>'meta_key' =&gt; 'countdown_date'</code> <strong>or</strong> <code>'hour'</code> and <code>orders them using 'orderby' =&gt; 'meta_value_num'</code>. </p>
  
  <p>I need to join two <code>meta_key's</code> together. ('hour' key only returns the first two ints of a <code>24hr</code> time).</p>
  
  <p><strong>Result required</strong>, products ordered by two custom fields <strong>countdown_date</strong> and <strong>hour</strong></p>
  
  <pre><code>$args = array(
              'posts_per_page' =&gt; 20,
              'tax_query' =&gt; array(
                  'relation' =&gt; 'AND',
                  array(
                      'taxonomy' =&gt; 'product_cat',
                      'field' =&gt; 'slug',
                      'terms' =&gt; 'live-events'
                  )),
              'post_type' =&gt; 'product',
              'meta_key' =&gt; 'countdown_date',
  // need to add second meta key here 'meta_key' =&gt; 'hour',
               'orderby' =&gt; 'meta_value_num',
               'order'   =&gt; 'ASC'
              );
          $the_query = new WP_Query( $args );
  </code></pre>
  
  <p>I've looked at loads of similar questions with no results. </p>
  
  <p>Two loops seems overkill and adding the meta_query is not working for me. </p>
  
  <p>Any help would be great. :)</p>
  
  <p>Full working code in the answer below from @Rene_Korss</p>
  
  <p>Could i get a hand add this to functions.php so that the archive will sort the same way as the custom loop.</p>
  
  <p>Below is a simplified version of the function i've got working. I need to add the two meta_key's here too.</p>
  
  <pre><code>    add_filter('woocommerce_get_catalog_ordering_args','wdm_change_ordering',10,1);
          function wdm_change_ordering($args) { 
              if(is_product_category()) {
  
                      $args['meta_key'] = 'countdown_date';
  // need to add second meta key here $args['meta_key'] = 'hour', 
                      $args['orderby'] = 'meta_value';
                      $args['order'] = 'ASC';
  
                  } 
      return $args;  
      }
  </code></pre>