Site logo

Archived topic

Hide Product Short Description on Subcategories

4 replies · Started by Otger on March 25, 2023

Viewing posts 1–5 of 5

Hi!

On Shop Main Page I show 4 categories with their descriptions (it is what I want).

The problem comes when I enter a subcategory, which shows me all the short description of the product and I don't want to show it.

I have reviewed the post https://generatepress.com/forums/topic/displaying-the-description-of-a-product-category/#post-1701968 but it is not what I am looking for.

Years ago I would have done such a thing in archive-product.php
<?php /*echo apply_filters( 'woocommerce_short_description', $post->post_excerpt )*/ ?>
<?php if (is_product_category()) { ?>

<?php echo category_description(); ?>

<?php } ?>

But now there are only 5 hooks and I think I have to work with them.

How can I disable the Product Short Description in subcategory pages through hooks? (And continue showing the description of the categories on the shop page)

Thanks!

I have also tried this, but without success either:

// Hide short product descriptions on subcategory pages
add_action( 'woocommerce_before_subcategory_title', 'remove_product_excerpt', 1 );
function remove_product_excerpt() {
remove_action( 'woocommerce_shop_loop_item_excerpt', 'woocommerce_template_single_excerpt', 5 );
}

// Show category description on shop page (shop)
add_action( 'woocommerce_archive_description', 'show_category_description', 5 );
function show_category_description() {
if ( is_product_category() && 0 !== absint( get_query_var( 'paged' ) ) ) {
echo '

' . wpautop( term_description() ) . '

';
}
}

Hi there,

try this:

add_action( 'woocommerce_after_shop_loop_item_title', 'remove_short_description', 1 );
function remove_short_description() {
    if ( is_product_category() ) {
        remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_single_excerpt', 5 );
    }
}

Hi David,

It works perfect! Thank you very much for the quick answer!

Glad to hear that!

This archived topic is closed to new replies.