求助:如何在WooCommerce店铺页面禁用产品短描述(需PHP方案)
Got it, let's solve this for you! Since you need to keep the short description available on other pages (like single product pages) but disable it specifically on the WooCommerce shop and product archive pages, using PHP is the perfect approach—no CSS workarounds that might accidentally hide it elsewhere.
Here are two solid methods you can implement:
Method 1: Remove the Short Description Hook Conditionally
WooCommerce uses hooks to display the short description on archive pages. We can unhook this element only when we're on a shop/archive page. Add this code to your theme's functions.php file (or a custom plugin for safer updates, so you don't lose changes when updating your theme):
add_action( 'woocommerce_before_shop_loop_item_title', 'remove_shop_page_short_description', 11 ); function remove_shop_page_short_description() { // Check if we're on the main shop page, product category, or product tag page if ( is_shop() || is_product_category() || is_product_tag() ) { remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_short_description', 10 ); } }
How this works:
- We hook into
woocommerce_before_shop_loop_item_title(right before the product title displays) with a priority of 11—this ensures our code runs after WooCommerce sets up the short description hook. - The
is_shop(),is_product_category(), andis_product_tag()functions check if we're on any product archive page. Adjust these conditions if you only want to target specific archive types (e.g., just the main shop page). - We then remove the default
woocommerce_template_loop_short_descriptionaction that outputs the short description.
Method 2: Filter the Short Description Output
If Method 1 doesn't work (maybe your theme uses a custom hook to display the short description), you can directly filter the short description content to return an empty string on archive pages. Add this code to your functions.php or custom plugin:
add_filter( 'woocommerce_short_description', 'hide_short_description_on_shop_pages', 10, 1 ); function hide_short_description_on_shop_pages( $description ) { // Check if we're on a product archive page if ( is_shop() || is_product_category() || is_product_tag() ) { $description = ''; } return $description; }
Note:
- This method targets the short description content directly, so it works even if your theme uses a custom display method (as long as it uses the
woocommerce_short_descriptionfilter, which most well-coded themes do). - If you only want to target the main shop page (not categories/tags), simplify the condition to
if ( is_shop() ).
Quick Tips:
- Always back up your
functions.phpfile before adding code, or use a dedicated code snippets plugin to avoid breaking your site if there's a syntax error. - Clear your WooCommerce and site cache after adding the code to see the changes take effect right away.
内容的提问来源于stack exchange,提问作者William

