Woocommerce Change Text on Checkout Page | Quick Tutorial

Woocommerce Change Text on Checkout Page tutorial will cover only how to change the texts in the woocommerce checkout page using a function. Manually changing it on the wocoommerce core files is not advisable.

One of my clients asked me to remove the words “have read and” from the Woocommerce checkout page : “I have read and accept the terms & conditions“.

woocommerce change text on checkout page
Woocommerce Change Text on Checkout Page | Radiobox

 

The first step that was on my mind is using the translation function in wordpress and it should remove the 3 words by replacing the whole text statement.

I am going to change the texts using the Gettext  filter hook in WordPress. I copied the whole texts and created a function, this is the one below:


function woo_checkout_texts( $changed_text, $text, $domain ) {
 if ( $changed_text == 'I have read and accept the terms & conditions' ){
 $changed_text = 'I accept the terms & conditions';
 }
 return $changed_text;
}
add_filter( 'gettext', 'woo_checkout_texts', 20, 3 );

 

But the when I checked the website’s checkout page, it doesn’t change. I forgot that the link was composed of an anchor tag. Therefore when you translate something you should also add the static markup that is between the text you are translating/changing.

 

So how?

I looked into the woocommerce plugin folder and find the file containing the texts in it that we can copy and modify into our functions.php file. Yes, we just copy and modify it into our functions.php file.

Any changes within the plugins file is not a good practice, in a plugin update it will get removed because it will be overridden with the new updated file code.

So to make it professional as possible, I’ve search files inside the woocommerce plugin with a word “checkout”. There, I found the terms.php file. I’ve open it on my editor and found this content.

woocommerce change text on checkout page
Woocommerce Change Text on Checkout Page | Terms

Now I’ve got the idea of how to change texts on the checkout page in woocommerce.

I’ve copied the text and pasted it on functions.php with my function. I’ve copied it again as a translated text by removing the words’ “have read and”.

This is final function below:


function woo_checkout_texts( $changed_text, $text, $domain ) {
 if ( $changed_text == 'I&rsquo;ve read and accept the <a href="%s" target="_blank">terms &amp; conditions</a>' ){
 $changed_text = 'I accept the <a href="%s" target="_blank">terms &amp; conditions</a>';
 }
 return $changed_text;
}
add_filter( 'gettext', 'woo_checkout_texts', 20, 3 );

I’ve checked the checkout page, done, now it is finally translated.

This is how you customize the checkout page texts in woocommerce.

 

Hi, did you know that we have a youtube channel? It's called Garnatti one. Check it out!
I believe that education must be free to everyone. Feel free to share.

Leave a comment

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