Recent product on Home page

Hi,

I have a page called home.php which has the code to display 6 recent products on Home page. Below is that code. Now we have built a new home page using the Pro builder elements. We still want to pull the recent products on this new home page. How can we achieve this?

Summary

The website is mangtum.com

Summary
<?php $args = array( 'post_type' => 'product', 'stock' => 1, 'posts_per_page' => 6, 'orderby' =>'date', 'order' => 'DESC' );

$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
global $product; ?>

<?php if (has_post_thumbnail( $loop->post->ID )) echo get_the_post_thumbnail($loop->post->ID, 'shop_catalog'); else echo 'product placeholder Image'; ?>

<?php the_title(); ?>

<h3 class="price"><?php echo $product->get_price_html(); ?></h3>
<div class = "hover-button">
<?php woocommerce_template_loop_add_to_cart( $loop->post, $product ); ?>
</div>
<?php endwhile; ?> <?php wp_reset_query(); ?>

Thank you

Hi @Mang,

You can still use your code just create a shortcode in your functions.php child theme, then call the shortcode in your homepage, check this out on how to create shortcode in functions.php https://diveinwp.com/how-to-create-shortcode-for-custom-post-type-to-display-posts/

You can also use a plugin to generate a shortcode base on your code https://wordpress.org/plugins/insert-php-code-snippet/

I hope it will help you to solve your concern.

Thank you.

Thank you Cramaton.

I think there are already woocommerce shortcode which can be used to display recent products. Trying to explore those.

Thanks

You’re welcome, @Mang.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.