Change "View Cart" and "Checkout" buttons text in Cart Widget Woocommerce

13,593

Solution 1

You can use str_ireplace() to change the text of the button, the following function will allow you to change the text of a Woocommerce button:

//The filters.. both are required.
add_filter('gettext', 'change_checkout_btn');
add_filter('ngettext', 'change_checkout_btn');

//function
function change_checkout_btn($checkout_btn){
  $checkout_btn= str_ireplace('Checkout', 'Your New Text', $checkout_btn);
  return $checkout_btn;
}

Solution 2

To easily translate plugins use this plugin:

https://wordpress.org/plugins/loco-translate/

It lets you select a plugin.

Note, only plugins with .mo/.po files can be translated.

I hope this will help you!

Good luck.

Share:
13,593

Related videos on Youtube

Fantin B
Author by

Fantin B

Updated on September 27, 2022

Comments

  • Fantin B
    Fantin B over 1 year

    I'm trying to find the correct function or filter to edit the text of the buttons "View Cart" and "Checkout" in the Cart Widget of Woocommerce.

    My website url : http://modularwave.com/ (just so you know i'm using Brutal, great theme from zigzagpress).

    Thanks in advance for you help, F.

  • Fantin B
    Fantin B over 8 years
    Hi Michael, thanks a lot for your answer but I'm not there yet (translation I mean). I'm just looking to change the text in English for that button precisely :).
  • Michael Vermeulen
    Michael Vermeulen over 8 years
    Not 100% but that plugin also shows where the string is located. You can then open the file containing the English translated sting and edit it your self. See the plugin as a quick help.
  • Fantin B
    Fantin B over 8 years
    Thanks a lot it works ! Just one thing, how do you change it again ? If i do : 'Checkout', 'Your New Text', $checkout_btn or : 'Your New Text', 'Your New Text2', $checkout_btn It's not working.
  • Daniel_ZA
    Daniel_ZA over 8 years
    I just tested it now and I see what you mean. You have to still use 'Checkout', in str_ireplace as that is the text that is generated by Woocommerce for the button when the page loads (even though you might not see it) so you need to go: str_ireplace('Checkout', 'Your New Text2', $checkout_btn);
  • Fantin B
    Fantin B over 8 years
    Yes thanks a lot Daniel it's working like a charm! (It was just the CDN or caching messing with me I guess)
  • Zach Smith
    Zach Smith about 7 years
    this must have been depreciated in latest WC as it is not working for us
  • Daniel_ZA
    Daniel_ZA about 7 years
    I tested this today on WC 2.6.1.4 and it still changed the checkout button text