WooCommerce Only OnSale Products Loop Snippet [closed]

Finally, I got the code. Using the code below, you can pick OnSale products that are either Simple Product On Sale or Variable Product On Sale. Keep in mind that this code will pick every post in which you added a sale price. So avoid adding the price in this field (Shown in attached Image) if your sale price is same as the original price because then it will not be a sale product but this code will pick it in sale products loops.

WooCommerce Product Data Form ScreenShot

<!-- WooCommerce On-Sale Products -->
<ul class="products">
    <?php
        $args = array(
            'post_type'      => 'product',
            'posts_per_page' => 4,
            'meta_query'     => array(
                    'relation' => 'OR',
                    array( // Simple products type
                        'key'           => '_sale_price',
                        'value'         => 0,
                        'compare'       => '>',
                        'type'          => 'numeric'
                    ),
                    array( // Variable products type
                        'key'           => '_min_variation_sale_price',
                        'value'         => 0,
                        'compare'       => '>',
                        'type'          => 'numeric'
                    )
                )
        );
        $loop = new WP_Query( $args );
        if ( $loop->have_posts() ) {
            while ( $loop->have_posts() ) : $loop->the_post();
                woocommerce_get_template_part( 'content', 'product' );
            endwhile;
        } else {
            echo __( 'No products found' );
        }
        wp_reset_postdata();
    ?>
</ul>
<!-- WooCommerce On-Sale Products -->