ZaZaKi, a web developer Between Manchester UK & Rotterdam NL. © 2015-2024.

WooCommerce shop page loop

<?php
$loop = new WP_Query( array(
'post_type'      => 'product',
'posts_per_page' => 2,
'post_status'    => 'publish',
'parent'         => 0,
'tax_query'      => array( array(
'taxonomy' => 'product_cat',
'field'    => 'term_id',
'terms'    => array( 29 ), // Term ids to be excluded
'operator' => 'NOT IN' // Excluding terms
) ),
) );
if ( $loop->have_posts() ) :
while ( $loop->have_posts() ) : $loop->the_post();
// Get the instance of the WC_Product from the post ID
$product = wc_get_product( get_the_id() );?>
<a href="<?php echo get_permalink(); ?>">
<?php the_post_thumbnail(); ?><br> 
<?php echo wc_price( $product->get_price() );?> <br>
<a href="<?php echo get_permalink(); ?>" class="dodo">Add to Cart</a><br>
<?php echo get_the_title(); ?><br>
<?php
endwhile;
wp_reset_postdata();
else: ?>
<p><?php _e( 'No posts found.' ); ?></p>
<?php endif;
?>