WooCommerce: Display Global Short Description When Empty @ Single Product Page
The WooCommerce product short description is that piece of content that appears on the right hand side of the featured image above the add to cart button. This is, of course, unless you forgot to enter the short description under Product > Edit Product > Short Description!
In case you forgot to enter it or you want to display a global short description, here’s a quick PHP snippet for you. Enjoy!
WooCommerce: display a custom short description when empty @ single product page
PHP Snippet: Display Custom Short Description When Empty @ WooCommerce Single Product Page
/**
* @snippet Show Global Short Description If Empty - WooCommerce
* @how-to Get CustomizeWoo.com FREE
* @author Rodolfo Melogli
* @compatible WooCommerce 6
* @donate $9 https://businessbloomer.com/bloomer-armada/
*/
add_action( 'woocommerce_single_product_summary', 'bbloomer_echo_short_desc_if_empty', 21 );
function bbloomer_echo_short_desc_if_empty() {
global $post;
if ( empty ( $post->post_excerpt ) ) {
$global_excerpt = '<p class="default-short-desc">';
$global_excerpt .= 'This is the default, global, short description.<br>It will show if <b>no short description has been entered!</b>';
$global_excerpt .= '</p>';
echo $global_excerpt;
}
}
You can place PHP snippets at the bottom of your child theme functions.php file (delete "?>" if you have it there). CSS, on the other hand, goes in your child theme style.css file. Make sure you know what you are doing when editing such files - if you need more guidance, please take a look at my free video tutorial "Where to Place WooCommerce Customization?"
Does this snippet (still) work?
Please let me know in the comments if everything worked as expected. I would be happy to revise the snippet if you report otherwise (please provide screenshots). I have tested this code with Storefront theme, the WooCommerce version listed above and a WordPress-friendly hosting on PHP 7.3.
If you think this code saved you time & money, feel free to join 14,000+ WooCommerce Weekly subscribers for blog post updates or 250+ Business Bloomer supporters for 365 days of WooCommerce benefits. Thank you in advance :)
Need Help with WooCommerce?
Check out these free video tutorials. You can learn how to customize WooCommerce without unnecessary plugins, how to properly configure the WooCommerce plugin settings and even how to master WooCommerce troubleshooting in case of a bug!
Rodolfo Melogli
Business Bloomer Founder
Author, WooCommerce expert and WordCamp speaker, Rodolfo has worked as an independent WooCommerce freelancer since 2011. His goal is to help entrepreneurs and developers overcome their WooCommerce nightmares. Rodolfo loves travelling, chasing tennis & soccer balls and, of course, wood fired oven pizza.
16 thoughts on “WooCommerce: Display Global Short Description When Empty @ Single Product Page”
Anil
Is it possible to add a shortcode in place of ‘This is the default, global, short description.It will show if no short description has been entered!‘; ? I would like to add the shortcode [specs-table]. Thanks in advance
Hi Maged, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!
Hi Steve, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!
When we force the short description it is not picked up by the woocommerce schema any ideas how we can all fix this? Schema has become a big thing lately with Google. ๐
Hello Nexus, thanks so much for your comment! Yes, this is possible – unfortunately this is custom work and I cannot provide a complementary solution here via the blog comments. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding! ~R
That’s a really good idea. Something to enhance it just a little more would be to pull a short description from an associated tag or category, therefore if there is nothing in the product description for that item, it can pull a generic one for whatever is in that category, whether it be “boys shorts”, “men’s watches”, “pizzas”, “flooring”, etc.
Questions? Feedback? Support? Leave your Comment Now! _____
If you are writing code, please wrap it between shortcodes: [php]code_here[/php]. Failure to complying with this (as well as going off topic, not writing in English, etc.) will result in comment deletion. You should expect a reply in about 2 weeks - this is a popular blog but I need to get paid work done first. Please consider joining BloomerArmada to get blog comment reply priority, ask me 1-to-1 WooCommerce questions and enjoy many more perks. Thank you :)
With 100,000 (and growing) monthly organic sessions, Business Bloomer is the most consistent, most active and most complete WooCommerce development/customization blog.
Of course this website itself uses the WooCommerce plugin, the Storefront theme and runs on a WooCommerce-friendly hosting.
Is it possible to add a shortcode in place of ‘This is the default, global, short description.It will show if no short description has been entered!‘; ? I would like to add the shortcode [specs-table]. Thanks in advance
Sure, check the WordPress function do_shortcode()
Show can i show the product description instead of the custom text?
This should help https://businessbloomer.com/woocommerce-remove-product-tabs-echo-long-description/
How can we do this but for the product description itself not the product short description ?
Hi Maged, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!
Thank you for your post. How can I add the “Short Description” by specific tags? Or insert the main descriptions to the short descriptions?
Hi Steve, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!
When we force the short description it is not picked up by the woocommerce schema any ideas how we can all fix this? Schema has become a big thing lately with Google. ๐
Hello Nexus, thanks so much for your comment! Yes, this is possible – unfortunately this is custom work and I cannot provide a complementary solution here via the blog comments. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding! ~R
Hi,
This snippet works great for Single posts where it displays only once, however for variable products when a variation is selected it displays twice.
I can hide the second custom short description by using css, but was wondering if there is a way to hide is programmatically.
Thanks
You’re right – snippet updated!
That’s a really good idea. Something to enhance it just a little more would be to pull a short description from an associated tag or category, therefore if there is nothing in the product description for that item, it can pull a generic one for whatever is in that category, whether it be “boys shorts”, “men’s watches”, “pizzas”, “flooring”, etc.
Nice idea! Thank you Madivad ๐
Another amazing snippet!
Thank you ๐