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

如何在WooCommerce标准商店页面隐藏促销商品并部署至单独促销页?

Absolutely! You can totally hide all sale-tagged products from your main WooCommerce shop page and redirect them to a dedicated sale page instead. Let me walk you through two solid ways to pull this off—one for code-savvy folks, and another for anyone who prefers avoiding code entirely:

You can tweak your shop page's product query to exclude sale items by adding a custom code snippet. This works without plugins and keeps your setup lightweight.

Add this code to your theme's functions.php file, or use a code snippet plugin (like Code Snippets) to avoid messing with theme files directly:

add_action( 'pre_get_posts', 'exclude_sale_products_from_main_shop' );
function exclude_sale_products_from_main_shop( $query ) {
    // Target only the front-end main shop page query
    if ( ! is_admin() && $query->is_main_query() && is_shop() ) {
        $existing_meta_query = $query->get( 'meta_query', array() );
        
        // Add condition to exclude products with a sale price set
        $existing_meta_query[] = array(
            'key'     => '_sale_price',
            'value'   => '',
            'compare' => '='
        );
        
        $query->set( 'meta_query', $existing_meta_query );
    }
}

What this does:

This hooks into WooCommerce's product query before it runs, adding a rule to only show products that don't have a sale price set (i.e., non-sale items) on the main shop page.

2. Plugin Method (For Non-Developers)

If you'd rather skip code, use a WooCommerce filter plugin to exclude sale items from the shop page:

  • Install a plugin like YITH WooCommerce Product Filter or WooCommerce Product Filters
  • Navigate to the plugin's settings, create a filter rule that excludes products marked as "On Sale" from the main shop page
  • Save your changes, and the plugin will handle the rest

Setting Up Your Dedicated Sale Page

No matter which method you use, creating a separate sale page is easy:

  1. Go to WordPress Dashboard → Pages → Add New
  2. Name your page something like "Sale Items" or "Clearance"
  3. Paste the WooCommerce shortcode [sale_products] into the page content
  4. Publish the page—this will automatically display all your sale-tagged products

Quick Notes to Keep In Mind:

  • If you use a caching plugin, clear your cache after making changes to ensure the updates show up
  • If your theme uses a custom shop page template, double-check that the code snippet's is_shop() condition targets the right page
  • Test with a sample sale product to confirm: it should disappear from the main shop page and show up on your dedicated sale page

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.20 12:02:50