Featured Products Loop in WooCommerce 3.0
WooCommerce updated the featured products meta_key _featured in the latest version WooCommerce 3.0. I used the Featured Products Loop for a slider with Advanced custom field, after upadating the WooCommerce version 3.0 my slider was not working, finally i got the solution.
Code I used on WooCommerce old version
<?php $args = array(
'post_type' => 'product',
'meta_key' => '_featured',
'meta_value' => 'yes',
'posts_per_page' => 3
);
$featured_query = new WP_Query( $args );
if ($featured_query->have_posts()) :
while ($featured_query->have_posts()) :
$featured_query->the_post();
$product = get_product( $featured_query->post->ID ); ?>
<li><a href="<?php the_permalink(); ?>"><img src="<?php the_field('featured_product_image'); ?>"/></a></li>
<?php endwhile;
endif;
wp_reset_query(); // Remember to reset ?>
Featured Products Loop in WooCommerce 3.0
<?php
$args = array(
'post_type' => 'product',
'posts_per_page' => 12,
'tax_query' => array(
array(
'taxonomy' => 'product_visibility',
'field' => 'name',
'terms' => 'featured',
),
),
);
$loop = new WP_Query( $args );
if ( $loop->have_posts() ) {
while ( $loop->have_posts() ) : $loop->the_post();?>
<li><a href="<?php the_permalink(); ?>"><img src="<?php the_field('featured_product_image'); ?>"/></a></li>
<?php
endwhile;
} else {
echo __( 'No products found' );
}
wp_reset_postdata();
?>
Credits: ciorici
