Skip to content

Instantly share code, notes, and snippets.

@panayotoff
Created September 19, 2017 12:51
Show Gist options
  • Save panayotoff/e534183982ca84db15da968f3e5d39f7 to your computer and use it in GitHub Desktop.
Save panayotoff/e534183982ca84db15da968f3e5d39f7 to your computer and use it in GitHub Desktop.
WooCommerce - list of latest products
<?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="stinky_wc_more-products-single">
<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" />';
} ?>
<div><?php echo wc_get_product_category_list( $product->get_id(), ' / ', '<span class="stinky_wc_latest_category">', '</span>' ); ?></div>
<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(); ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment