On my shop page I want to display only a few select items. I figured the simplest way to do this would be to mark those that I want to show as 'featured' - via the product edit screen in my Wordpress dashboard.
I found this following code which I thought worked. However, I discovered it works only if I am logged in as Admin.
Is there a way to show the 'featured' products ONLY on the shop page?
// Display featured products in shop pages
add_filter( 'woocommerce_product_query_tax_query', 'custom_product_query_tax_query', 10, 2 );
function custom_product_query_tax_query( $tax_query, $query ) {
if( is_admin() ) return $tax_query;
if ( is_shop() ) {
$tax_query[] = array(
'taxonomy' => 'product_visibility',
'field' => 'name',
'terms' => 'featured'
);
}
return $tax_query;
}