Website Building » WooCommerce » How Do I Limit Product Description in WooCommerce?

How Do I Limit Product Description in WooCommerce?

Last updated on January 20, 2023 @ 12:49 pm

WooCommerce is a great eCommerce platform for small businesses, but one of its drawbacks is that the default product descriptions can be quite long. This can be a problem if you want to keep your product pages short and to the point. In this article, we’ll show you how to limit product description in WooCommerce.

The first thing you need to do is install and activate the Advanced Custom Fields plugin. Once you’ve done that, you’ll need to create a new field group with the following fields:

  • Product Description Limit – This will be a number field where you can specify the number of characters that should be displayed in the product description.
  • Description More Link Text – This will be a text field where you can specify the text for the “more” link that will be displayed after the truncated product description.

Once you’ve created your field group, you’ll need to edit each of your products and specify a limit for the product description. You can do this by going to the product editing screen and scrolling down to the “Product Description Limit” field. Enter a number in this field, and then click on the “Update” button.

Now that you’ve specified a limit for the product description, you’ll need to add some code to your theme to actually truncate the description. You can do this by adding the following code to your theme’s functions.php file:

PRO TIP: If you are using WooCommerce to sell products on your website, it is important to limit the product description to a certain number of characters. This will help to keep your product pages looking clean and organized, and will also help to prevent customers from becoming overwhelmed by too much information.
function my_product_description_limit() {
  global $post;
  $product_description_limit = get_post_meta($post->ID, '_product_description_limit', true);
   if (!$product_description_limit) {
     return;
   }
$content = get_the_content();
 if (mb_strlen($content) > $product_description_limit) {
  $content = mb_substr($content, 0, $product_description_limit);
  $more_link_text = get_post_meta($post->ID, '_more_link_text', true);
   if (!$more_link_text) {
     $more_link_text = __('[Read More]', 'your-theme');
   }
echo wpautop($content . ' ' . sprintf('<a href="%s">%s</a>', esc_url(get_the_permalink()), esc_attr($more_link_text)));
 }
}
add_filter('the_content', 'my_product_description_limit');

In conclusion, limiting product descriptions in WooCommerce is easy with a little bit of code. By using the Advanced Custom Fields plugin and adding some code to your theme’s functions.php file, you can easily keep your product pages short and sweet.

Drew Clemente

Drew Clemente

Devops & Sysadmin engineer. I basically build infrastructure online.