• Resolved amarstyle

    (@amarstyle)


    How can i display woocommerce recent products on my home Page?

    someone please help.
    I know where to add but just dont know the exact code. i want to show 4 recently added products with link to to view more.

    my website is : http://amarstyle.com

    please help.

    thanks in advance.

Viewing 11 replies - 1 through 11 (of 11 total)
  • Thread Starter amarstyle

    (@amarstyle)

    figured it out myself.

    Hello amarstyle,

    I also want to do same thing on my website, so please could you tell me how to solved you on your website??

    I hope for your immediate response!!

    Thread Starter amarstyle

    (@amarstyle)

    add this in your index page

    <ul class="productshome">
        <?php
            $args = array( 'post_type' => 'product', 'stock' => 1, 'posts_per_page' => 2, 'product_cat' => 'Salwar-Kameez', 'orderby' =>'rand','order' => 'DESC' );
            $loop = new WP_Query( $args );
            while ( $loop->have_posts() ) : $loop->the_post(); global $product; ?>
    
                    <li class="producthome">    
    
                        <a>post->ID ) ?>" title="<?php echo esc_attr($loop->post->post_title ? $loop->post->post_title : $loop->post->ID); ?>">
    
                            <?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="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 ); ?>
    
        <?php endwhile; ?>
        <?php wp_reset_query(); ?>
    
    </div>

    Amarstyle’s code was slightly broken, so I’ve updated it.

    You can drop this straight into your code and it should work – it returns four products, arranges the product via date and is bootstrap ready (if you use it).

    <section id="recent">
    
        <h1>Recently Added</h1>
    
        <ul class="row-fluid">
    
            <?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; ?>
    
                        <li 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="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 ); ?>
                        </li><!-- /span3 -->
            <?php endwhile; ?>
            <?php wp_reset_query(); ?>
    
        </ul><!-- /row-fluid -->
    </section><!-- /recent -->

    Jon,
    Your code is great! It’s working!

    But one trouble, they couldn’s display the button “add to cart”, the place is just words with link, not a image of button.

    Can you please tell me the reason? Thank you very much!

    Ice,
    The Add to Cart link has the classes “add_to_cart_button” and “button” that can be used to make it look like a button with CSS.

    Guys, where I need to put this code? Tks

    Funk,
    Tks for your reply, right, it’s a problem of html:)
    $
    Jorgeanr,
    just add the code anywhere you want to display your products list on homepage (index.php or other page setted as homepage).

    Hey Jon Reader, works great can you tell me how to add rating in this code.

    Jon

    Your code is great! It’s working!

    This code is great, can anyone help me modify this so instead of latest products it shows featured products?

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Display woocommerce recent products on home page’ is closed to new replies.