How to Add Text after OR before Cart Button in WooCommerce?

Add Text Before and After Add to Cart

In this article, we will learn how you can add custom text after or before the cart button in woocommerce. We will do this for a single product page and shop/product category page. You don’t need to touch the default template files of woocommerce. We can achieve this by adding an action hook in the functions.php file.

Let’s start to achieve this by adding simple lines of code.

Before Add to Cart Button

The woocommerce_before_add_to_cart_button action will hit the our custom function code. It will run before the add to cart button action hook. See the example below of how I made an action hook to run the function with our custom code.

After Add to Cart Button

The woocommerce_after_add_to_cart_button action will use for show the text after cart button. It will run after the add to cart button.

See the below image result of both above action hooks.

Add Text After and Before Cart Button 1

If you want to learn how you can redirect to checkout after clicking on add to cart button then check here

On Shop or Category Page (before/after)

If you think both the above action hooks will also work for the shop and category page then you are wrong. You have to add a completely different action hook to achieve this. It’s simple as we did above.

We will use woocommerce_loop_add_to_cart_link filter hook to add custom text after or before cart button in woocommerce.

Let’s see the example below.

The above code will show the result like the below image.

Add Text After and Before Cart Button 2

That’s it. All Done.

Hope you understand how you can add text after or before the cart button in woocommerce. If you have any queries/questions then let me know in the below comment section I’ll help you with that.

You May Also Like

About the Author: Aman Mehra

Hey! I'm Aman Mehra and I'm a full-stack developer and have 5+ years of experience. I love coding and help to people with this blog.

1 Comment

Leave a Reply

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