Untranslated WooCommerce strings in Cart and Checkout pages

Learn how to translate WooCommerce strings like Update Cart and I’ve read and accept the terms & conditions which remain untranslated after plugin update. In my case French language is the primary WordPress language (no additional languages are  being used hence no Loco nor WPML plugins are installed) and the strings like Product, Price, Quantity, Total, Coupon code, Apply Coupon and Update Cart, which appear on the Cart page, still remain in English. Moreover, on the next step the string “I’ve read and accept the terms & conditions” also appears in English.

Since I don’t use any localization plugin for this project and all official language files are already in place, I had to find a workaround for those stubborn strings. For the first step and strings on the Cart page I modified the theme’s functions.php file to manually translate the English strings.

1. Locate and edit the functions.php file

The file is located in /wp-content/themes/YOUR-THEME-NAME/
Open it for editing and at the bottom place the following code:

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;
}

If you have only one string to translate this should be enough, just change the words Apply Coupon and Appliquer le coupon accordingly to your language (this is applicable for any other string as well).

However, if you need to translate more than one string then the code should look something like this:

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;
}

Be aware that errors might occur so backup your functions.php file before you try this one!

This concludes step 1 of the WooCommerce ghost strings translation. For the next step on the Checkout page there is the string “I’ve read and accept the terms & conditions” which was also in English. This is the string located in the file terms.php found in one of the following 2 locations:
– /wp-content/themes/YOUR-THEME-NAME/woocommerce/checkout/terms.php
– /wp-content/plugins/woocommerce/templates/checkout/terms.php

In my case the file terms.php was in the second location and the string I was looking for was in span HTML tag like this:
<span><?php printf( __( 'I&rsquo;ve read and accept the <a href="%s" target="_blank" class="woocommerce-terms-and-conditions-link">terms &amp; conditions</a>', 'woocommerce' ), esc_url( wc_get_page_permalink( 'terms' ) ) ); ?></span>

Edit accordingly your language translation and mind the special characters like apostrophe &rsquo; and & sign &amp; which can break your page coding.

Useful post regarding this topic can also be found on the official support page for WooCommerce plugin on WordPress.org website.

By janoshke

Web developer and IT consultant. Freelancer with full respect for OpenCart and WordPress. Gamer, (ex)drummer and parent.

18 comments

    1. Thanks. There has been a lot of changes and updates lately across the web. Please do share which ones don’t work so others may find this comment useful 😉

    1. This example shows French as default language which leaves some strings untranslated. However, if you need to have bilingual website then you should consider using a plug-in like Polylang, Loco or WPML.

  1. Hi janoshke
    I add your code top my site but it shows translated string in English language. I am translating ‘Availability’ from Eng(Native Language) to German. I just want to show translated string only when german language is activated.I am using polylang plugin.

    1. Hi there,

      Please note that this translation of strings using the functions.php file (in my case) was for single language site. For multilanguage site you should be able to translate the strings via string translator in Polylang (works best in PRO version).

      Cheers

Leave a ReplyCancel reply

Exit mobile version
%%footer%%