Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #28629

    I found another thread here from a different theme that suggested adding some code to the functions.php file and I tried that but it didn’t seem to do anything. I have a category that is showing up in my shop but I need to exclude it from there.

    #138142

    I found this article: http://www.wptaskforce.com/how-to-exclude-one-or-more-category-in-woocommerce-shop-page/

    Basically you need to insert it at the bottom of functions.php. Then replace

    'field' => 'slug',
    'terms' => array( 'PUT YOUR CATEGORY HERE' ), // Don't display products in the m

    with

    'field' => 'id',
    'terms' => array(20,25), // Don't display products in the m

    and instead of 20, 25 insert the category id(s) you want to exclude. Separate them with a comma.

    #138143

    I tried entering that but nothing seems to happen. I’m still seeing the categories I want to hide. I put it in the functions.php in the theme, and then tried in in woocommerce-core-funtions.php, but nothing changes. Am I doing something wrong?

    #138144

    Not sure why it doesn’t work in your case. I tested it with

    add_action( 'pre_get_posts', 'custom_pre_get_posts_query' );
    function custom_pre_get_posts_query( $q )
    {

    if (!$q->is_main_query() || !is_shop()) return;
    if ( ! is_admin() )
    {
    $q->set( 'tax_query', array(array(
    'taxonomy' => 'product_cat',
    'field' => 'id',
    'terms' => array( 57 ),
    'operator' => 'NOT IN'
    )));

    }
    }

    (57 is the id of the category I excluded) and it worked for me. If it doesn’t work try to deactivate all third party plugins/extensions except WooCommerce – maybe another plugin hooks into the query and breaks it.

Viewing 4 posts - 1 through 4 (of 4 total)
  • The topic ‘Hide/Exclude a category from WooCommerce Shop page’ is closed to new replies.