How to show category description if there are no products in this category?
-
by default the description is not displayed if there are no products
The page I need help with: [log in to see the link]
-
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:
Link to image: https://d.pr/i/jWoDJvI 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/supportOne 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’sfunctions.php
file as this will be wiped entirely when you update.I hope that helps!
Hello!
Wow! This code worked, I am very grateful to you, I shake your hand)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/
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-pageI 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!
unfortunately the code in the last message didn’t work
the description is not displayed in the category without products (
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!
wooow!
yes you are just a magician!) Now everything worked, I am very grateful to you!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!
- The topic ‘How to show category description if there are no products in this category?’ is closed to new replies.