Woocommerce Get Sale Products

<h2 class=”head”>Sale Products</h2>

<?php
$args = array(
‘post_type’ => ‘product’,
‘posts_per_page’ => 3,
‘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() ) {
//$i=0;
while ( $loop->have_posts() ) : $loop->the_post();
/* print_r($loop->post);
echo $loop->post->ID;
exit; */
global $product;
$thumbnail = wp_get_attachment_image_src(get_post_thumbnail_id($loop->post->ID, array(300,300) ));
$price = get_post_meta( $loop->post->ID, ‘_regular_price’, true);
$sale = get_post_meta( $loop->post->ID, ‘_sale_price’, true);
global $product;

?>

<a href=”<?php the_permalink(); ?>”>

<img src=”<?php echo $thumbnail[0]; ?>” alt=””/>

<p class=”title”><?php echo $loop->post->post_title;?></p>
<div class=”price1″>
<span class=”reducedfrom”><?php echo get_woocommerce_currency_symbol().$price; ?></span>
<span class=”actual”><?php echo get_woocommerce_currency_symbol().$sale; ?></span>

<?php
endwhile;
}
wp_reset_postdata();
?>

Advertisements

Published by

oudarya

I am a developer

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s