How to Change the WooCommerce Add to Cart Button Text

In this tutorial we're taking a look at how to change the WooCommerce Add to Cart button text to text of your choice using a simple PHP function.

In this article we’re going to take a look at how to change the default WooCommerce ‘Add to Cart’ text. You may want this to say something that is more on brand, or relevant to your store for example ‘Add to Basket’ or ‘Add to Trolley’ or even ‘Add to Order’.

There are multiple ways to do this for example with jQuery however we’re going to look at how to add a filter to your functions.php file so this snippet will be written in PHP.

If you’re not sure of how to add code to your functions.php file take a look at our article here:

Adding Functions to WordPress

However the quick version is to make a backup of your site, ensure that you’re using a child theme and then open the functions.php file via the file manager or FTP. Ideally any updates should be made on a staging or local copy of your site before pushing it to live.

There will be two main locations where you may need to change the text, these are within the archive / category / shop pages which will all be the same and within the individual product pages.

So let’s take a look at the PHP:
// Changing the add to cart text within individual product pages


add_filter( 'woocommerce_product_single_add_to_cart_text',  'individual_product_add_to_cart_text' ); 

function individual_product_add_to_cart_text() {
    return __( 'Add to Basket', 'woocommerce' ); 
}

// Changing the add to cart text within archive / category and shop pages


add_filter( 'woocommerce_product_add_to_cart_text', 'product_archive_add_to_cart' );  


function product_archive_add_to_cart() {
    return __( 'Add to Basket', 'woocommerce' );
}


So let’s take a quick look at what the above includes and how to adjust it to the needs of your site. 

The sections that include the forward slashes for example:

// Changing the add to cart text within individual product pages

are simply code comments. You may want to adjust this text to more accurately reflect exactly what you’re setting the code to.

Next we assign the name of the function to the specific filter. The woocommerce_product_single_add_to_cart_text hook targets the add to cart button within the individual product page.

The ‘individual_product_add_to_cart_text’ is the name of the function.

Within the next section we return the text ‘Add to Basket’ in place of the default text. You can change this text here to be anything you would like.

Summary:

We hope this helps when it comes to tweaking the Add to Cart button in WooCommerce if you found it useful we would really appreciate a comment and a share thanks!

Tech Typed
Tech Typed
Articles: 186

Leave a Reply

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