Exclude 'hidden' queried products from carousel in WooCommerce 3+ Exclude 'hidden' queried products from carousel in WooCommerce 3+ wordpress wordpress

Exclude 'hidden' queried products from carousel in WooCommerce 3+


Since Woocommerce 3 the product visibility is handled by the taxonomy product_visibility for the term exclude-from-catalog, so you need to add a tax query as follow:

$common_args = array(    'post_type'           => 'product',    'posts_per_page'      => !empty($posts_per_page) ? intval($posts_per_page) : 4,    'post_status'         => 'publish',    'ignore_sticky_posts' => true,    'no_found_rows'       => true,    'tax_query'           => array( array(        'taxonomy'  => 'product_visibility',        'terms'     => array('exclude-from-catalog'),        'field'     => 'name',        'operator'  => 'NOT IN',    ) ),);

It should work. Tested this array of arguments with WordPress get_post() function (it works).


Related: Database changes for products in woocommerce 3