Am try to exclude a specific category form woocommerce variable page. I have the following code.

Any help how can achieved that?

 add_action( 'pre_get_posts', 'custom_pre_get_posts_query' );

function custom_pre_get_posts_query( $q ) {

  if ( ! $q->is_main_query() ) return;
  if ( ! $q->is_post_type_archive() ) return;

  if ( ! is_admin() && is_shop() && is_front_page() ) {

    $q->set( 'tax_query', array(array(
      'taxonomy' => 'product_cat',
      'field' => 'slug',
      'terms' => array( 'category-name' ), // Don't display products in the category on the shop page and front page
      'operator' => 'NOT IN'


  remove_action( 'pre_get_posts', 'custom_pre_get_posts_query' );


Read more here: Exclude specific category from variable archive


If you know the solution of this issue, please leave us a reply in Comment section, to update the question.

Wordpress related questions and answers: