Blog: WordPress

Change Proceed To PayPal Checkout 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.

A reader asked how to change the Proceed To Paypal button text on the WooCommerce Checkout page.

I figured there would be a filter for this, because it’s WooCommerce. but because it’s a payment gateway, there’s no built in hook for this button, like there is for the Place Order button text.

What I found out is there’s a way to change text on many plugin labels and buttons — provided they are already set up for localization and translation. (More on that later).

First, let me give you the code, then we’ll dive into how it works.

The Code Snippet

Add this to your functions.php file. Where it says Your new PayPal button text here, add the button text you’d like to have appear.


/**
 * Custom PayPal button text
 *
 */

add_filter( 'gettext', 'ld_custom_paypal_button_text', 20, 3 );
function ld_custom_paypal_button_text( $translated_text, $text, $domain ) {
	switch ( $translated_text ) {
		case 'Proceed to PayPal' :
			$translated_text = __( 'Your new Paypal button text here', 'woocommerce' );
			break;
	}
	return $translated_text;
}

Let’s analyze what’s going on here in our code snippet.

In the first line, we’re adding a filter. In WordPress development, filters adjust our content as it gets output to the page.

In this filter, we’re calling a built-in WordPress function, gettext, which will run inside our custom function, ld_custom_paypal_button_text.

If you’re unfamiliar with gettext, it’s main purpose is to swap out text strings when a plugin or theme has translations available. Translation is becoming more prevalent, so if you’re looking to change a text label in a popular plugin, chances are you can use a similar code snippet for other labels, once you understand how the pattern works.

When a plugin is localized and translatable, instead of hard-coding labels into the plugin, they are often stored as text strings. You’ll often see these stored using _e() or __(), with the text string as a first parameter, and the text domain of the plugin as the second parameter.

For example: __( 'Related Products', 'woocommerce' );

In this case, the text string Related Products in the plugin text domain woocommerce. Text domains are the parent directory name of the plugin or theme folder as it appears on the server.

You can find out more about localization and translation by watching this video from Pippin Williamson:

Localizing and Translating WordPress Plugins

Our Custom Function

So, we are using a filter to run gettext on our custom function, ld_custom_paypal_button_text.

That function takes three arguments: the variables for translated text ($translated_text), the text to replace out target text with ($text), and the text domain of the plugin or theme we are looking in ($domain).

We use a switch case to say to the function, if you find the text string, Proceed to Paypal anywhere inside the plugin directory woocommerce, swap that for the text string Your new Paypal button text here, and store that in a variable for that particular instance.

We then tell the function to stop, and return our new text string everywhere the original text string appeared.

The result is we’ve changed our text for Proceed to Paypal anywhere it appears in WooCommerce.

Essentially, we can repurpose the translation capabilities of WordPress for any plugin that is translation ready, and make it return custom text wherever there is a text string stored for localized output.

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.

26 comments on “Change Proceed To PayPal Checkout Text in WooCommerce

  1. Thank you John. This is a life saver. New EU regulations require the normal “proceed to paypal” “order and pay” buttons, be replaced with an “order with obligation to pay”.

    Regards
    Paddy

  2. Hi Cecillie:

    If you’ve put this code at the bottom of your functions.php file (with your new Proceed to PayPal button text in place), and it’s still not working for you, it’s hard to say what’s going on without taking a look at how your theme is set up.

    I tested this code snippet on a few test sites running WooCommerce this morning, just to double check, and everything seemed to be functioning properly.

    Perhaps you can tell me more about what you’re experiencing?

    1. Hi.
      It’s finally working! Turns out that, because the websites language is set to Danish, I had to change the “case ‘Proceed to PayPal’ :” to the Danish translation.
      Thanks for the code ๐Ÿ™‚

  3. Hi Cecillie:

    I’m glad you got this to work! Thanks for the tip about changing the button text when it’s in a non-English language. That’s good information to know. ๐Ÿ™‚

    Enjoy your weekend!

    1. Hello John/Cecillie,

      In the switch statement, shouldn’t the case be based on $text rather than $translated_text? It seems as if $text is the raw text while $translated_text is the translation by the time that ld_custom_paypal_button_text() is called. I don’t have non-English locale installed so I have not tested, but if my thinking is correct then the code will not need to be adjusted for each locale.

  4. Please do not use this code if you have a multilingual site using qtranslate, it causes the checkout page on secondary languages to break.

    1. Hi Dragos:

      You should never drop a code snippet from any site into your live site. Always test any change to your website in development or staging before you push those changes to production.

      Every site has a different combination of hosting environment, themes, plugins, and third-party code. Changes to any of those should be tested first.

      It’s good to give a heads up about the conflict with qTranslate, but realize you should be testing on a staging site first, anyway.

      An alternative is to translating text strings is to create a translation file for specific languages, which qTranslate and many plugins do, which is also mentioned in the article. If you are already using a translation file as a solution, then translating a text string via functions can indeed cause a conflict.

  5. Hi Eyong:

    Your thinking is on point. The function takes three arguments: one for the default text, one for the new text, and the third for the text domain of the plugin (in this case, woocommerce.)

    The function looks for a case where the default text would appear, swaps the new translated text, and then returns the value. On the front end of the site, the customer sees the new text.

    If you are using another means of translating text, such as a plugin like Polylang or Say What?, or modifying the WooCommerce translation file for certain phrases, this function may be redundant.

    Thanks,
    John

  6. Hi John,

    I wanted to change the “Proceed to PayPal” button to “Proceed to Payment”. Thank you for the code but where do I find the functions.php file? I’m not technical at all and still building my site.

    Please help.

    1. Hi Noel:

      Remove any opening and closing PHP tags, and place the code snippet at the end of your functions file.

      As always, if you are making changes to your site, make sure you have a working backup of your website, and FTP access, or another way to restore your website, in case something goes awry.

      (This is why I prefer hosting with sites like WP Engine which have daily backups. Having your own redundant backups is also advised.)

      Thanks,
      John

  7. Hi John,

    This is Noel again. I’ve seen on other forums that it is advisable to install a “Child Theme” in WordPress before I start with the process of changing the button because if there is an update in my theme then all the changes will be lost. What’s your advice?

    Thanks

  8. Hi

    As I needed to change names of both buttons I worked only in that order. Thanks so much for posting that!

    add_filter( 'gettext', 'ld_custom_paypal_button_text', 20, 3 );
    function ld_custom_paypal_button_text( $translated_text, $text, $domain ) {
    switch ( $translated_text ) {
    case 'Proceed to PayPal' :
    $translated_text = __( 'Buy', 'woocommerce' );
    break;
    }
    return $translated_text;
    }
    
    add_action( 'yith_wcwl_added_to_cart_message', 'yith_wcwl_added_to_cart_message' );
     
    /* Add to the functions.php file of your theme */
    
    
    add_filter( 'woocommerce_order_button_text', 'woo_custom_order_button_text' ); 
    
    function woo_custom_order_button_text() {
        return __( 'Buy', 'woocommerce' ); 
    }
    

Join the Conversation

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