WooCommerce lets us write a short description for every product that we add to our store, which appears alongside the product image as illustrated in the image below:
This “short description” can be updated anytime that you wish to add some text to it.
However, sometimes, it may so happen that you want to have a site-wide or a store-wide sale, or display an important notification such as that of exclusion of taxes in the price, shipping costs, free shipping above a certain price or of stocks selling fast. In all these cases, it is not feasible to add text to the short description field of every product. In this post, you will learn how to add text below the short description of the product in WooCommerce through code snippets, such that this text gets added to all products in the store.
Add the code snippet below to the functions.php file of your child theme, and assign any text that you wish to display to the variable $text :
add_filter('woocommerce_short_description','ts_add_text_short_descr'); function ts_add_text_short_descr($description){ $text="Offer: 40% OFF at Checkout on all products across the store."; return $description.$text; }
(To know why we edit the functions.php of the child theme and not directly the functions.php file, read this post.)
Here, woocommerce_short_description is a Woocommerce filter associated with the short description of a product to which we are adding a hook/function called as “ts_add_text_short_descr”. The function returns the short description of the product along with the added text. This added text is added to the short description of every product in the store:
You can even add HTML tags to the text to format it. For example,
add_filter('woocommerce_short_description','ts_add_text_short_descr'); function ts_add_text_short_descr($description){ $text="<b>Offer:</b> 40% OFF at Checkout on all products across the store.<br/><br/>"; return $description.$text; }
Modifying the earlier code snippet to the one above will format the added text according to the HTML tags mentioned in the string assigned to the variable $text.
In this way, you can add any text below the short description of products in WooCommerce.
Adding content (be it HTML, text or images) above the short description can also be done using code snippets, in various ways as shown in this post.
Hi,
How can I add a dynamic text after short description? which means for every single product different texts.
That doesn’t work!!!
Would there be a way to do this, but also to apply it only to certain categories or products? Ex: I want a disclaimer text I want to appear on all products under my “exclusive” category. Based on the snippet in the original article, is there a way to modify it to show only on products under that “exclusive” category?
Hi Thanks how can I change the color of the text I added only?
if using paragraph text use <p style=’color:red;’>your text</p> or add a class to the text with <p class=’your-class’>your text</p> then style the class.