In this article, I’ll share the code snippet that you can use to remove the product short description from a single product page. I’ll share two different snippets, and you can use the one that best suits your requirements.
Without any further ado, let’s jump into the tutorial.
On This Page
Snippet 1: WooCommerce Remove Short Description From Single Product Page
There could be several reasons to remove the short description from the single product page in WooCommerce like you may want to remove it to get a clean product page.
Note: If you do not want to use the code to remove the short description, then you can edit the product for which you want to remove it, and empty the ‘Product Short Description’ field. It will also remove the description from the product page.
You can use the following code snippet to remove the short description field.
1. Copy the Code Snippet
Here’s the code to remove the short description from the WooCommerce single product page:
// Remove Short Description from WooCommerce Single Product Page
remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_excerpt', 20);
2. Understanding the Code(Optional)
The following is the complete breakdown of the above code snippet to understand how it works.
- remove_action: This is a WordPress function that is used to remove a previously added action. Actions are hooks in WordPress that allow you to execute custom code at specific points during the execution of a page.
- ‘woocommerce_single_product_summary’: This is the hook (or action) from which we are removing another action. In WooCommerce, the woocommerce_single_product_summary hook is used to display various elements on a single product page.
- ‘woocommerce_template_single_excerpt’: This is the name of the function that is hooked into the woocommerce_single_product_summary hook to display the short description. By removing this action, we prevent the short description from being displayed.
- 20: This is the priority of the action. In WordPress, actions can have different priorities, and they determine the order in which the functions hooked into the same action are executed. In this case, we use a priority of 20.
So, the entire line of code is essentially saying, “Remove the action named ‘woocommerce_template_single_excerpt’ from the ‘woocommerce_single_product_summary’ hook with a priority of 20.”
3. Paste the Code Into WordPress
Now let’s paste the code into the WordPress/WooCommerce store to remove the short description from the single product page.
There are several methods to paste a code snippet into WordPress. I have a guide ‘How to Add Code Snippets to WordPress’ that explains all the methods to paste any code to your WordPress site.
You can follow the method that best suits your experience and requirements. I’ll paste the code snippet to my demo store using the plugin.
4. Final Results
Now let’s test if it is working or not.
Before:
To test it, I first visited the product page without adding the code snippet to my demo store and as you can see in the screenshot below, the short description was displayed below the product price.
After:
Now when I added the code snippet to my demo store and revisited the product page, there was no short description below the product price. It means the code is working properly.
Snippet 2: WooCommerce Remove Short Description From a Specific Product Page
The previous code snippet was to remove the short description from all the product pages on your store. However, if you want to remove it from a specific product page, the following are the steps to do so.
1. Get the Product ID
First, you need to get the product ID for which you want to remove the short description from the product page. To get the product ID, navigate to Products > All Products from your WordPress dashboard and hover your mouse over the product for which you want to remove the short description from the front end.
Once you hover over it, you’ll see its ID. Make sure to copy it.
2. Copy the Code Snippet
Here’s the code to remove the short description from a specific WooCommerce product page. Make sure to replace the value of $specific_product_id with the one that you copied in the previous step.
// Remove Short Description from WooCommerce Single Product Page for a Specific Product
function aovup_remove_short_description_for_specific_product() {
global $post;
// Replace '123' with the ID of your specific product
$specific_product_id = 123;
// Check if the current page is a single product page and if the product ID matches
if ( is_product() && $post->ID === $specific_product_id ) {
remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_excerpt', 20);
}
}
add_action('wp', 'aovup_remove_short_description_for_specific_product');
3. Understanding the Code(Optional)
The following is the complete breakdown of the above code snippet to clearly understand how it works.
- function aovup_remove_short_description_for_specific_product(): This declares a custom function named aovup_remove_short_description_for_specific_product. This function will be responsible for removing the short description under specific conditions.
- global $post: This makes the $post object available within the function. The $post object contains information about the currently displayed post or page.
- $specific_product_id = 123: Replace 123 with the actual ID of the specific product from which you want to remove the short description.
- if ( is_product() && $post->ID === $specific_product_id ) { … }: This checks if the current page is a single product page (is_product()) and if the ID of the current product matches the specified $specific_product_id.
- remove_action(‘woocommerce_single_product_summary’, ‘woocommerce_template_single_excerpt’, 20);: If the conditions are met, this line removes the action that displays the short description. The action is hooked into the woocommerce_single_product_summary hook with a priority of 20.
- add_action(‘wp’, ‘aovup_remove_short_description_for_specific_product’);: This adds the aovup_remove_short_description_for_specific_product function to the WordPress action hook wp. The action hook wp is fired after WordPress has finished loading, making it suitable for this kind of customization.
4. Paste the Code Into WordPress
Now let’s paste the code into the WordPress/WooCommerce store to remove the short description from a specific product page.
You can follow the method that best suits your experience and requirements. I’ll paste the code snippet to my demo store using the plugin.
5. Final Results
Now let’s test if it is working or not.
Before:
To test it, I first visited the product page without adding the code snippet to my demo WooCommerce store and as you can see in the screenshot below, the short description was displayed below the product price.
After:
Now when I added the code snippet to my demo store and visited the product page again, there was no short description below the product price. It means the code is working properly.
Conclusion
That’s it for today’s article.
I hope it was helpful to you and you were able to use the code to remove the short description from the WooCommerce product page.