You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

WooCommerce:如何在店铺页面隐藏「shoes」分类产品

Hey there! Let's sort out your WooCommerce request—you want to hide all products in the 'shoes' category from your main shop page, only show non-shoes items, and keep shoes on a dedicated separate page. Here are two reliable solutions for you:

方案一:PHP代码实现(无需插件)

This approach is great if you're comfortable working with a bit of code, and it avoids adding extra plugins to your site.

步骤:

  1. Add the code to your site: You can either paste this into your theme's functions.php file (note: theme updates might overwrite it) or use a code snippet plugin like Code Snippets (safer for long-term use).
  2. Adjust the code if needed: If your "shoes" category uses a different slug, replace 'shoes' with your actual category slug. If you know the category ID, you can skip the get_term_by line and directly use the ID number.
add_action( 'pre_get_posts', 'exclude_shoes_category_from_shop' );
function exclude_shoes_category_from_shop( $query ) {
    // Only target the front-end main shop page product query
    if ( ! is_admin() && $query->is_main_query() && is_shop() ) {
        // Get the ID of the "shoes" product category
        $shoes_cat = get_term_by( 'slug', 'shoes', 'product_cat' );
        if ( $shoes_cat ) {
            $shoes_cat_id = $shoes_cat->term_id;
            
            // Set up the tax query to exclude this category
            $tax_query = $query->get( 'tax_query', array() );
            $tax_query[] = array(
                'taxonomy' => 'product_cat',
                'field'    => 'term_id',
                'terms'    => $shoes_cat_id,
                'operator' => 'NOT IN',
            );
            $query->set( 'tax_query', $tax_query );
        }
    }
}

额外提示:

To create your dedicated shoes page, make a new page in WordPress and add this shortcode:

[products category="shoes"]

Or use the block editor to add a "Products by Category" block and select the "shoes" category—this will display only your shoes products on that page.

方案二:插件实现(无需代码)

Perfect if you don't want to mess with code at all. There are several free WooCommerce plugins that let you exclude categories from the shop page easily:

推荐插件 & 操作步骤:

  • WooCommerce Exclude Categories from Shop:

    1. Install and activate the plugin from the WordPress plugin repository.
    2. Go to WooCommerce > Settings > Exclude Categories.
    3. Under "Exclude Categories from Shop", find and check the "shoes" category.
    4. Save your changes—your shop page will now stop showing any shoes products.
  • Alternative: WooCommerce Product Filters:
    This plugin offers more advanced filtering options, including category exclusion. Once activated, navigate to its settings and set up a rule to exclude the "shoes" category from the main shop page.

鞋子专属页面设置:

Same as the code method—create a new page and use the [products category="shoes"] shortcode or the "Products by Category" block to display only shoes products.

内容的提问来源于stack exchange,提问作者SIlencer Halloul

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.26 10:49:52