WooCommerce is a popular e-commerce plugin for WordPress, but sometimes you may need to translate or rename certain strings on your website.

Whether it’s to customize the checkout process for your customers, or to display your website in a different language, translating or renaming strings in WooCommerce is a straightforward process.

Why Translate WooCommerce Strings / Terms?

Translating or renaming strings in WooCommerce can have several benefits:

  1. Localization: If your target audience speaks a different language, translating your website into that language can help you reach more customers.
  2. Customization: Renaming certain strings on your website can help you customize the checkout process for your customers. For example, you may want to change the label for the “Add to Cart” button to something more descriptive.
  3. Branding: Renaming certain strings on your website can help you reinforce your brand. For example, you may want to change the label for the “Checkout” button to reflect your brand’s messaging.

Also read: best WooCommerce hosting reviews, cost & comparison

How to Translate Any WooCommerce Strings / Terms without Plugin

The quickest and easiest way to translate or rename strings in WooCommerce is to use PHP snippet code.

By adding and customizing the following code, you can quickly translate WooCommerce strings to any words you like.

We’ll change the default “add to cart” button to show an example. This is how it looks by default:

translate woocommerce string addtocart

Now let’s add the following code to your website:

/**
* @snippet Translate WooCommerce Strings Terms without Plugin
* @source https://www.wptechnic.com/?p=7475
* @compatible WC 7.3.0
*/
add_filter( 'gettext', 'rename_add_to_cart_button', 10, 3 );
function rename_add_to_cart_button( $translated_text, $text, $domain ) {
  if ( $text === 'Add to cart' && $domain === 'woocommerce' ) {
    $translated_text = __( 'Add to Basket', $domain );
  }
  return $translated_text;
}

and the result will be like this:

translate woocommerce strings addtocart

This code uses the gettext filter to change the text of the “Add to Cart” button to “Add to Basket”. You can adjust the text to anything you want.

You can also use this code to translate any other strings in WooCommerce. Simply replace the “Add to cart” text from line 8 with the word that you like to change and “Add to Basket” text from line 9 with your preferred words.

so the code will be something like this:

/**
* @snippet Translate WooCommerce Strings Terms without Plugin
* @source https://www.wptechnic.com/?p=7475
* @compatible WC 7.3.0
*/
add_filter( 'gettext', 'rename_add_to_cart_button', 10, 3 );
function rename_add_to_cart_button( $translated_text, $text, $domain ) {
  if ( $text === 'Words That I want to Translate' && $domain === 'woocommerce' ) {
    $translated_text = __( 'My Own Translated Words', $domain );
  }
  return $translated_text;
}

Here’s another output:

Left ImageRight Image

Conclusion

Translating or renaming strings in WooCommerce is a simple process that can help you attract more customers, customize the checkout process for your customers, or reinforce your brand.

You might do this using a plugin, however, the above simple PHP snippet code makes the job easier. Hope this will be an effective way to improve the user experience on your website.

Did it work for you?

Did this code work for your website? Or you’re having difficulties? Either way, let me know by leaving a comment below right now.

Avatar for Muhammad Tamzid
Author

Muhammad Tamzid, the founder of WPTechnic, is a WordPress Enthusiast with a passion to help beginners learning WordPress. Also managing WPrevival, a 24/7 WordPress Website Development, Maintenance & Security Service company.

3 Comments

  1. Avatar for Kambro

    Thank you for this post.
    Can I use a similar snippet to translate strings of another plugin than WooCommerce?
    Best regards.

    • Avatar for Muhammad Tamzid

      Hi Kambro,
      Yes, you can use the same snippet to translate strings of other plugins (if it’s compatible). However, you must change the domain name ($domain === ‘woocommerce’) to your plugin’s domain, like ‘elementor’,

Write A Comment