0% found this document useful (0 votes)
60 views

How To Add Text After or Before Cart Button in Woocommerce

Do you know that? You can add your custom text before and after add to cart button on the single product page and shop/archive page in woocommerce. It is very easy by just adding a simple action hook. Check the file.

Uploaded by

Aman Mehra
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
60 views

How To Add Text After or Before Cart Button in Woocommerce

Do you know that? You can add your custom text before and after add to cart button on the single product page and shop/archive page in woocommerce. It is very easy by just adding a simple action hook. Check the file.

Uploaded by

Aman Mehra
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

HOME BLOG CATEGORIES  CONTACT

HOME HOW TO HOW TO ADD TEXT AFTER OR BEFORE CART BUTTON IN WOOCOMMERCE?
RECENT POSTS

How to add text after OR before


cart button in WooCommerce?
How to add text after OR before cart button in
How to Check String Contains a
WooCommerce? Specific Word in PHP?
AMAN MEHRA APRIL 5, 2021 1 COMMENT
How to Create a Child Theme in
WordPress?
Tweet on Twitter Share on Facebook
How to Install WordPress Plugin
Step by Step Guide 2021?

How to Create a Custom Page


Template in WordPress?

CATEGORIES

How To

PHP

ReactJS

WooCommerce

WordPress

MOST VIEWED POSTS

WooCommerce Remove Update Cart


button and make it automatically
In this article, we will learn how you can add text after or before cart button in woocommerce. We will do update.
October 5, 2020
this for 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.

How to change price of


Let’s start to achieve this by adding simple lines of code. specific product and
quantity in cart?
October 14, 2020
Before Add to Cart Button
How to redirect to
checkout after Add to
The woocommerce_before_add_to_cart_button action will hit the our custom function code. It
cart?
will run before the add to cart button action hook. See the example below of how I made an action hook October 16, 2020
to run the function with our custom code.
How can I prevent SQL
injection in PHP?
add_action( 'woocommerce_before_add_to_cart_button', 'ybc_before_add_to_cart_ October 7, 2020

function ybc_before_add_to_cart_btn(){
Upload multiple featured
//add text OR HTML here images in a post OR page
echo '<p>Before custom text here</p>'; January 4, 2021
}

After Add to Cart Button


FOLLOW US
Stay updated via social channels
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.

add_action( 'woocommerce_after_add_to_cart_button', 'ybc_after_add_to_cart_bt

function ybc_after_add_to_cart_btn(){
//add text OR HTML here
echo '<p>After custom text here</p>';
}
See the below image result of both above action hooks.

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 text after or before cart
button in woocommerce. Let’s see the example below.

add_filter( 'woocommerce_loop_add_to_cart_link', 'ybc_shop_before_after_btn',

function ybc_shop_before_after_btn( $add_to_cart_html, $product, $args ){


// Before text or HTML here
$before = '<p>Before custom text here</p>';
// After text or HTML here
$after = '<p>After custom text here</p>';

return $before . $add_to_cart_html . $after;


}

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

That’s it. All Done.

Hope you understand how you can add text after or before 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.

ADD TO CART CART BUTTON WOOCOMMERCE WORDPRESS WORDPRESS ACTIONS WORDPRESS HOOKS
Tweet on Twitter Share on Facebook

YOU MAY ALSO LIKE

How to Check String Contains a How to Create a Child Theme in How to Install WordPress Plugin
Specific Word in PHP? WordPress? Step by Step Guide 2021?

How to Create a Custom Page How to install React-Router and How to install reactjs and
Template in WordPress? use it? create a app?

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 find solutions to bugs.

1 COMMENT

Pingback: How to redirect to checkout after Add to cart? » Your Blog Coach
LEAVE A REPLY

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

Comment

Name * Email * Website

Save my name, email, and website in this browser for the next time I comment.

POST COMMENT

ABOUT QUICK LINKS RECENT POSTS JOIN OUR NEWSLETTER

Your Blog Coach is the best site for Home How to add text after OR before cart Name
finding the solution to any issue related button in WooCommerce?
Blog
to coding and learn more cool stuff
How to Check String Contains a
and tricks. WordPress Email
Specific Word in PHP?
WooCommerce
How to Create a Child Theme in
Contact WordPress?
SUBSCRIBE
© 2020 Your Blog Coach Privacy Policy Terms and Conditions Sitemap

PDFmyURL.com - convert URLs, web pages or even full websites to PDF online. Easy API for developers!

You might also like