How to Translate WooCommerce Checkout Page

Translate WooCommerce Checkout Page

Are you looking for a way to translate text on the checkout page? Recently, a client contacted us to translate some text on the checkout page.

WordPress supports different languages across the world, but some WooCommerce strings like ‘Update Cart’ and ‘I’ve read and accept the terms & conditions’ may remain untranslated after a plugin update.

You can translate text by using a plugin, but it is important to note that plugins can bloat your site.

How to Translate WooCommerce Checkout Page

In this post, we will show you how you can translate text on the checkout page of your WooCommerce store. We will not be using a localization plugin like WPML.

We will be using custom PHP code to achieve this. This means that you need to have some coding skills before you proceed.

Let’s get into it.

Steps to Translate Text on the WooCommerce Checkout Page

Here are the simple steps you need to follow:

  1. Log into your WordPress site and access the Dashboard as the admin user.
  2. From the Dashboard menu, click on Appearance Menu > Theme Editor Menu. When the Theme Editor page is opened, look for the theme functions file where we will add the function that will translate text on the checkout page.
  3. Add the following code to the PHP file:
add_filter('gettext', 'translate_strings');

add_filter('ngettext', 'translate_strings');

function translate_strings($translated) {

$translated = str_ireplace('Apply coupon', 'Appliquer le coupon', $translated);

return $translated;

}

  1. The code snippet above changes the word Apply coupon to Appliquer le coupon, which is in French. This is the outcome:change text
  2. If you have only one string to translate, the code above is enough. If you want to translate more than one string, then you should add the following code in the functions.php file:
add_filter('gettext', 'translate_strings');

add_filter('ngettext', 'translate_strings');

function translate_strings($translated) {

$translated = str_ireplace('Coupon code', 'Code coupon', $translated);

$translated = str_ireplace('Apply Coupon', 'Appliquer le coupon', $translated);

$translated = str_ireplace('Update Cart', 'Mise à Jour', $translated);

$translated = str_ireplace('PRODUCT', 'PRODUIT', $translated);

$translated = str_ireplace('PRICE', 'PRIX', $translated);

$translated = str_ireplace('QUANTITY', 'QUANTITÉ', $translated);

$translated = str_ireplace('TOTAL', 'TOTALE', $translated);

return $translated;

}

  1. The code snippet above translates the following strings: coupon code, apply the coupon, update cart, product, price, quantity, and total. This is the outcome:totale

Conclusion

By now, you should be able to translate any text in your WooCommerce store. However, we recommend that you back up your site before adding the code. This will ensure that you can revert to the previous version in case of a critical error.

If you are not familiar with handling code, we recommend contacting a qualified WordPress developer so that you do not break down your site.

Similar Articles