Where in the database can I find that a product is marked "featured"? I have marked 4 products as featured but I have yet to find out how to retrieve this information from any the database tables.
Thank you.
Since 3.0 featured products are marked as featured by being given the featured
term that WooCommerce creates in the product_visibility
taxonomy.
But to tell if a product is featured, instead of checking the terms directly or using get_post_meta()
(which wouldn't work anymore anyway), use the get_featured()
method of WC_Product
:
$product_id = 1;
$product = wc_get_product( $product_id );
$featured = $product->get_featured();
Featured Products Loop in WooCommerce 3
<ul class="products">
<?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();
wc_get_template_part( 'content', 'product' );
endwhile;
} else {
echo __( 'No products found' );
}
wp_reset_postdata();
?>