title: How to check if a product is onsale - WooCommerce
body: <p>I'm trying to get onsale products in a custom query, anybody can help to form the query or the condition to make it happen...</p>
  
  <pre><code>$args = array(
          'post_type'      =&gt; 'product',
          'posts_per_page' =&gt; -1,
      );
      $query = new WP_Query( $args );
      if ( $query-&gt;have_posts() ) :
          echo '&lt;ul class="owl-carousel"&gt;';
          $products_onsale = array();
          while ( $query-&gt;have_posts() ) : $query-&gt;the_post();
              // get_template_part('template-parts/product-slider');
              $product_id = get_the_ID();
              $product = new WC_Product( $product_id );
              if ( $product-&gt;is_on_sale() ) {
                  echo 'on sale';
              }
          endwhile;
          echo '&lt;/ul&gt;';
          print_r( $products_onsale );
      endif;
  </code></pre>
  
  <p>here is the working i'm working on</p>