fbpx

Remove products of a specific category from search results in the theme

HomeTopicsSupport forumRemove products of a specific category from search results in the theme
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #16379
    Avatar
    Sky786
    Participant

    How can I remove products of a specific category from search results in the theme?

    I have tried the code below but it didn’t work on the your theme.

    function wpse188669_pre_get_posts( $query ) {
    if (
    ! is_admin()
    && $query->is_main_query()
    && $query->is_search()
    ) {
    $query->set( ‘post_type’, array( ‘product’ ) );
    $tax_query = array(
    array(
    ‘taxonomy’ => ‘product_cat’,
    ‘field’ => ‘slug’,
    ‘terms’ => ‘category-2’,
    ‘operator’ => ‘NOT IN’,
    ),
    );
    $query->set( ‘tax_query’, $tax_query );
    }
    }
    add_action( ‘pre_get_posts’, ‘wpse188669_pre_get_posts’ );

    Any suggestions?

    #16386
    Artem Temos
    Artem Temos
    Keymaster

    Hello,

    Sorry, but we don’t know how this code is supposed to work. There is no such ability in WooCommerce by default and additional code customization like that is out of our theme support scope.

    Kind Regards

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.

Sign in

No account yet?

Create an Account