Blog: WordPress
Ninja Illustration

Change Add To Cart Text In WooCommerce

Avatar for John Locke

John Locke is a SEO consultant from Sacramento, CA. He helps manufacturing businesses rank higher through his web agency, Lockedown Design & SEO.

WooCommerce is the most popular e-commerce plugin in the WordPress ecosystem, and for most small and medium sized storefronts, it’s the perfect solution. But changing simple things like the Add To Cart button text can be frustrating if you don’t know how to do it.

Changing the verbiage on your Add To Cart button is one of the less painful changes to administer. The following code snippet goes in the functions.php file of your WordPress theme.

The Code You Came Here To Get

This filter with change the Add to Cart text sitewide. For variable products, this will also change the Select Options text on the Shop (products archive) page.


/**
 * Add to your functions.php file
 *
 * Change Add To Cart Button in WooCommerce
**/
add_filter( 'woocommerce_product_single_add_to_cart_text', 'ld_woo_custom_cart_button_text' );
add_filter( 'woocommerce_product_add_to_cart_text', 'ld_woo_custom_cart_button_text' );  
 
function ld_woo_custom_cart_button_text() {
        return __( 'Add to Cizzart', 'woocommerce' );
}

Let’s take a look under the hood at what’s going on here.

WordPress plugins like WooCommerce use web hooks as places where data can be modified. These are functions that developers can “hook” into to make changes. These hooks come in two varieties.

Filters are exactly what they sound like — they take the regular stream of data and allow you to replace the default data with some of your own. Actions are places where you can add or remove code from the normal flow.

For our operation, replacing the WooCommerce Add To Cart button text, we can use a simple filter to substitute text on the Single Product pages, and another to replace text on the Shop (Product Archives) pages.

In each of these filters above, there are two parameters. The first parameter is the WooCommerce function we are hooking into. The second parameter is the name of the custom function we are substituting.

Next we define our custom function that we called in our filters. The first parameter is the new cart text, and the second parameter is the main function, woocommerce. In this case, we have decided to carny it up, and replace the normal Add To Cart text with the kayfabe message, Add To Cizzart.


Now I’d like to ask you a question.

Are you struggling with WooCommerce, WordPress, or just online sales in general? Let me know in the comments below.

Avatar for John Locke

John Locke is a SEO consultant from Sacramento, CA. He helps manufacturing businesses rank higher through his web agency, Lockedown Design & SEO.

13 comments on “Change Add To Cart Text In WooCommerce

  1. Hey that’s great it worked just perfectly for me. One more thing John Is there a way we can change the default “Return to Shop” link also?

  2. Hi John,

    Thanks for this. I have added the code but for some reason it only changes the text on some of my products and not others, any ideas?

  3. Hi Karl:

    It looks like the items change where the color change isn’t involved. When there are options, but no color variation, your code snippet is working. It’s definitely got something to do with that, but hard to pinpoint without looking at the whole setup.

    1. Hi John,

      Im using the WooCommerce Variation Swatches and Photos extension, thats what seems to be causing the conflict, when i deactivate the plugin it works fine, but obviously i need to use this plugin, is there any way around this do you know?

  4. Hi John,

    I actually figured out a better way to do it buy editing the language file, worked a treat, thanks for your help….

Join the Conversation

Your email address will be kept private. Required fields marked *.