• Display woocommerce recent products on home page or any wp page?

    Display woocommerce recent products on home page or any wp page?

    Silver Member Asked on May 25, 2016 in Wordpress.
    Add Comment
  • 3 Answer(s)
    
    [recent_products per_page="12" columns="4"]
    
    
    Silver Member Answered on May 25, 2016.
    Add Comment
    
    <?php
    
    $args = array(
    
    'post_type' => 'product',
    
    'stock' => 1,
    
    'posts_per_page' => 4,
    
    'orderby' =>'date',
    
    'order' => 'DESC' );
    
    $loop = new WP_Query( $args );
    
    while ( $loop->have_posts() ) : $loop->the_post(); global $product; ?>
    
    <div class="span3">
    
    <a id="id-<?php the_id(); ?>" href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">
    
    <?php if (has_post_thumbnail( $loop->post->ID )) echo get_the_post_thumbnail($loop->post->ID, 'shop_catalog'); else echo '<img src="'.woocommerce_placeholder_img_src().'" alt="My Image Placeholder" width="65px" height="115px" />'; ?>
    
    <h3><?php the_title(); ?></h3>
    
    <span class="price"><?php echo $product->get_price_html(); ?></span>
    
    </a>
    
    <?php woocommerce_template_loop_add_to_cart( $loop->post, $product ); ?>
    
    </div><!-- /span3 -->
    
    <?php endwhile; ?>
    
    <?php wp_reset_query(); ?>
    
    
    Silver Member Answered on May 25, 2016.
    Add Comment
    [recent_products per_page="12" columns="4" orderby="date" order="desc"]
    
    Silver Member Answered on May 25, 2016.
    Add Comment
  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.