Support » Plugin: WooCommerce » How to show category description if there are no products in this category?

  • Resolved jufin

    (@jufin)


    by default the description is not displayed if there are no products

    The page I need help with: [log in to see the link]

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Support kellymetal a11n

    (@kellymetal)

    Hi there,

    This would be controlled by the active theme on your site. I checked on my personal test site with the default Storefront theme, and saw that the category description was displayed by default, even without any products in the category:

    Category description
    Link to image: https://d.pr/i/jWoDJv

    I see that you are currently using the Flatsome theme on your site. I would recommend checking the customizer to see if there might be a setting available for enabling the display of the description in Flatsome. If you do not see anything though, then it might be worth reaching out to the support team for Flatsome to ask about this:
    https://themeforest.net/item/flatsome-multipurpose-responsive-woocommerce-theme/5484319/support

    One final option — you could try adding the following to see if it causes the description to be displayed:

    
    add_action( 'woocommerce_archive_description', 'woocommerce_taxonomy_archive_description', 10 );
    

    That code should be added to your child theme’s functions.php file or via a plugin that allows custom functions to be added, such as the Code Snippets ( https://wordpress.org/plugins/code-snippets/ ) plugin. Please don’t add custom code directly to your parent theme’s functions.php file as this will be wiped entirely when you update.

    I hope that helps!

    Thread Starter jufin

    (@jufin)

    Hello!
    Wow! This code worked, I am very grateful to you, I shake your hand)

    Thread Starter jufin

    (@jufin)

    But now there is another problem)

    I added this code so that the description is under the products:

    remove_action( 'woocommerce_archive_description', 'woocommerce_taxonomy_archive_description', 10 );
     
    add_action( 'woocommerce_after_shop_loop', 'woocommerce_taxonomy_archive_description', 100 );

    and now it turns out that the description is displayed twice where there are products, example: https://rusikon.ru/product-category/rukopisnye-ikony/pod-zakaz/ikony-spasitelya/

    Plugin Support kellymetal a11n

    (@kellymetal)

    Hi there,

    Glad to hear the previous code worked!

    Regarding it being displayed twice, I tried your code, and saw the same thing on my personal site — the remove_action didn’t seem to be working, so the description was displayed twice.

    Finally, I found an answer in the post below — it seems you may need to remove the action after the parent theme setup is complete, in case it triggers the hook after that theme setup.
    https://wordpress.stackexchange.com/questions/333556/remove-action-on-product-archive-page

    I tried the following, and it seemed to work for me (this includes both the add and remove):

    
    add_action( 'woocommerce_after_shop_loop', 'woocommerce_taxonomy_archive_description', 100 );
    
    add_action( 'after_setup_theme', 'my_remove_parent_theme_stuff', 0 );
    function my_remove_parent_theme_stuff() {
        remove_action( 'woocommerce_archive_description', 'woocommerce_taxonomy_archive_description', 10, 2 );
    }
    

    I hope that helps!

    Thread Starter jufin

    (@jufin)

    unfortunately the code in the last message didn’t work

    the description is not displayed in the category without products (

    Plugin Support kellymetal a11n

    (@kellymetal)

    Hi there,

    Ah yes, I had tested that last one on a category with products to make sure it was only displaying after the products and not before. To get it working with categories without products, it will need to also be added to the “no products found” action as well:

    
    // Move category description to bottom of page.
    add_action( 'after_setup_theme', 'my_remove_parent_theme_stuff', 0 );
    function my_remove_parent_theme_stuff() {
        remove_action( 'woocommerce_archive_description', 'woocommerce_taxonomy_archive_description', 10, 2 );
    }
    add_action( 'woocommerce_after_shop_loop', 'woocommerce_taxonomy_archive_description', 100 );
    add_action( 'woocommerce_no_products_found', 'woocommerce_taxonomy_archive_description', 100 );
    

    That way, it will either be displayed after the loop that displays the products, or after the “no products found” message.

    I hope that helps!

    Thread Starter jufin

    (@jufin)

    wooow!
    yes you are just a magician!) Now everything worked, I am very grateful to you!

    Plugin Support kellymetal a11n

    (@kellymetal)

    Hi there,

    Glad to hear that worked! : )

    I’m going to mark this thread as resolved. If you have any further questions, please start a new thread.

    Have a wonderful day!

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘How to show category description if there are no products in this category?’ is closed to new replies.