X

How To Change the Default “Add To Cart” Button Text in WooCommerce

Snippets by IsItWP

Are you looking for a way to change the default “add to cart” button text in WooCommerce? This snippet will let you change the text to “Donate Now”, “Add Product”, “Buy”, or whatever you like.

Instructions:

  1. Add this code to your theme’s functions.php file or in a site-specific plugin.
  2. Then, just change the “Add Item” text on line 4 to whatever you want.
add_filter(‘woocommerce_product_single_add_to_cart_text’, ‘woo_custom_cart_button_text’);

function woo_custom_cart_button_text() {
return __(‘Book Now’, ‘woocommerce’);
}

Note: If this is your first time adding code snippets in WordPress, then please refer to our guide on how to properly copy / paste code snippets in WordPress, so you don’t accidentally break your site.

If you liked this code snippet, please consider checking out our other articles on the site like: 30 Ways to Make Money Online Blogging (On the Side).

Comments  Leave a Reply

  1. Good Samartian was and is correct. The single quotes used in this page were curly quotes and that breaks the PHP coding.

    I used Windows Notepad and replaced the curly quotes with single straight quotes, keyboard key ‘

    Curly quotes are not standard to English keyboards, either single or double straight quote characters are standard to the keyboard. So why the author, Debjit Saha, used curly quotes for us to copy is beyond me and he/she hasn’t even returned to correct this error.

    Here is the PHP code with the correct quotes:

    add_filter(‘woocommerce_product_single_add_to_cart_text’, ‘woo_custom_cart_button_text’);

    function woo_custom_cart_button_text() {
    return __(‘Book Now’, ‘woocommerce’);
    }

  2. Good Samaritan April 11, 2019 at 9:06 am

    Dude, change the apostrophe from ‘ to ‘, as in ENGLISH it’s not used and it breaks the code.

    1. That’s worked for me.
      I write code again with the help of keyboard and its working now.

      Thanks.

  3. joseph Tersoo April 5, 2019 at 9:16 pm

    I tried this code on my site but the Code doesnt work for me here is the working code you can try it out:
    add_filter( ‘add_to_cart_text’, ‘woo_custom_single_add_to_cart_text’ ); // < 2.1
    add_filter( 'woocommerce_product_single_add_to_cart_text', 'woo_custom_single_add_to_cart_text' ); // 2.1 +

    function woo_custom_single_add_to_cart_text() {

    return __( 'My Button Text', 'woocommerce' );

    }

  4. add_filter( ‘woocommerce_product_single_add_to_cart_text’ , ‘woo_custom_cart_button_text’ );

    function woo_custom_cart_button_text() {
    return __(‘Adauga in cos’ , ‘woocommerce’);
    }

    This is how it works. Tried everything up there. Nothing worked for me.

  5. // Changing Add to Cart button text to custom text in individual product pages
    function woo_custom_cart_button_text()
    {
    return __(‘Add Item’, ‘woocommerce’);
    }
    add_filter(‘woocommerce_product_single_add_to_cart_text’, ‘woo_custom_cart_button_text’);

    // Changing Add to Cart button text to custom text in product archive/listing pages
    function woo_custom_product_add_to_cart_text() {
    return __( ‘Add Item’, ‘woocommerce’ );
    }
    add_filter( ‘woocommerce_product_add_to_cart_text’, ‘woo_custom_product_add_to_cart_text’ );

    1. Thank you Pavan Yogi, your answer was the one that worked for me.

    2. Thanks Pavan Yogi, your solution worked for me too.

    3. Thank you! This code worked for me.

  6. What if I want to add some HTML to my button label (a span tag to display an icon)? I tried but the HTML is printed straight, not “rendered”.

  7. Doesn’t work. Any other suggestions?

  8. I don’t suppose anyone knows how to change the text on the ‘Log in’ and ‘Register’ buttons on Woocommece?

  9. For those having problems and it not working try this –

    add_filter(‘woocommerce_product_single_add_to_cart_text’, ‘woo_custom_cart_button_text’);

    function woo_custom_cart_button_text() {
    return __(‘Book Now’, ‘woocommerce’);
    }

    1. This is the right one! But the ” ‘ ” is wrong, should be

      add_filter(‘woocommerce_product_single_add_to_cart_text’, ‘woo_custom_cart_button_text’);

      function woo_custom_cart_button_text() {
      return __(‘Book Now’, ‘woocommerce’);
      }

    2. It worked after correcting quotes. Thanks a lot!

  10. this is not working , i tried it .

  11. Hmmm, added this to my child theme on the customs function php section & my button text did not change??

    add_filter(‘single_add_to_cart_text’, ‘woo_custom_cart_button_text’);

    function woo_custom_cart_button_text() {
    return __(‘Add to Bag’, ‘woocommerce’);
    }

  12. Hi Saha,

    thanks for your article. I want to change the change the last button in the checkout `Buy now` or `Pay now`(Sorry I don’t know the right text in english).

    do you have any tip for that?

    1. write to your functions.php in your theme folder:
      add_filter(‘single_add_to_cart_text’, ‘woo_custom_cart_button_text’);

      function woo_custom_cart_button_text() {
      return __(‘Buy now’, ‘woocommerce’);
      }

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WordPress Launch Checklist

The Ultimate WordPress Launch Checklist

We've compiled all the essential checklist items for your next WordPress website launch into one handy ebook.
Yes, Send Me the Free eBook!