title: WooCommerce: Display on-sale products in shop
body: <p>There are plenty of questions and answers regarding making only on-sale products display, but no matter what one I try, it doesn't work.</p>
  
  <p>I have the following query</p>
  
  <pre><code>function my_modify_main_query($query) {
      if ($query -&gt; query['post_type'] == 'product' &amp;&amp; $query -&gt; is_main_query() &amp;&amp; is_shop()) {// Run only on the shop
          if (isset($_GET['sale'])):
              $query -&gt; set('meta_query',
                  array(
                      'relation' =&gt; 'OR',
                      array(// Simple products type
                          'key' =&gt; '_sale_price',
                          'value' =&gt; 0,
                          'compare' =&gt; '&gt;',
                          'type' =&gt; 'numeric'
                      ),
                      array(// Variable products type
                          'key' =&gt; '_min_variation_sale_price',
                          'value' =&gt; 0,
                          'compare' =&gt; '&gt;',
                          'type' =&gt; 'numeric'
                      )
                  )
              );
          endif;
      }
  }
  // Hook my above function to the pre_get_posts action
  add_action( 'pre_get_posts', 'my_modify_main_query' );
  </code></pre>
  
  <p>The query itself is being applied, BUT the problem is.
  If the Product has been a variable with a sale price, the Product is then changed to a Simple Product, the "_min_variation_sale_price" meta value is still in the database.</p>
  
  <p>Does anybody know of a workaround for this? I believe it to be a bug, but their support is closed currently.</p>
  
  <p>Thanks.</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>What I think I need is a way to  only check _sale_price if the product is in the "simple" or "external" terms, then do similar for _min_variation_sale_price.</p>
  
  <p>I have created an issue on their github.
  <a href="https://github.com/woothemes/woocommerce/issues/10096" rel="nofollow">https://github.com/woothemes/woocommerce/issues/10096</a></p>
  
  <p><strong>EDIT</strong></p>
  
  <p>Issue is fixed using @helgatheviking answer.
  Although, take note that to resolve the issue completely, you must delete the variations, save, change the type, save, run <code>delete_transient( 'wc_products_onsale' );</code>
  Only then did it work for me.</p>