How to add short description before the Add to cart button in the Woocommerce

  • August 17, 2021
  • 0
Hire Vivek Asodariya

When some user wants easily read the description then the site admin can display a short description in the shop archive page.

We can display any custom text and description on the shop archive page.

We can add text using the woocommerce filter.

You can’t add the custom code in the main theme because if you will add then when you will update the main theme that time the code will remove autometically.

Add below code in your (child) theme’s functions.php

add_filter( 'woocommerce_loop_add_to_cart_link', 'vivek_patel_before_content', 10, 3 );

function vivek_patel_before_content( $add_to_cart_html, $product, $args ){
global $product; return $product->post->post_excerpt . $add_to_cart_html; }

If you don’t have child them then you can create your own custom plugin. You can add the custom code in the plugin. To create the custome plugin, here you can find out the steps.

If you have no child theme on the site then you can install the Code snippet plugin and add the above code in the snippet.

After adding the code you must need to activate the snippet then only it will work.
 
This is a woocommerce hook(woocommerce_loop_add_to_cart_link). That hook use for the archive product page shop link. Using that hook we can change the button name, link and we can add the custom text before and after shop button.
 
Using the above code, the product short description will appear before the “ADD TO CART” button.
 
If the cache plugins or 3rd party cache are available in the site then you must need to clear all the cache then the code will reflect in the website.
 
If you have any queries then you can drop a comment so I will try to solve your query.

Leave a Reply

Your email address will not be published. Required fields are marked *