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:
- Log into your WordPress site and access the Dashboard as the admin user.
- 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.
- 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; }
- The code snippet above changes the word Apply coupon to Appliquer le coupon, which is in French. This is the outcome:
- 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; }
- The code snippet above translates the following strings: coupon code, apply the coupon, update cart, product, price, quantity, and total. This is the outcome:
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.
Joe is an experienced full-stack web developer with a decade of industry experience in the LAMP & MERN stacks, WordPress, WooCommerce, and JavaScript – (diverse portfolio). He has a passion for creating elegant and user-friendly solutions and thrives in collaborative environments. In his spare time, he enjoys exploring new tech trends, tinkering with new tools, and contributing to open-source projects. You can hire me here for your next project.
Similar Articles
- How to Edit Billing Details WooCommerce Checkout Page
- WooCommerce Redirect After Checkout: Redirect to Custom Thank You Page
- 100+ Tips, Tricks & Snippets Ultimate WooCommerce Hide Guide
- How to Check if a User is Logged In to WordPress
- How to Set Up WooCommerce Upload File on Checkout
- How to Remove Category from Product Page WooCommerce
- How to Create WooCommerce Clear Cart Button Shortcode
- How to Add Continue Shopping Button WooCommerce Checkout
- How To Display Product Attributes In WooCommerce
- 30+ Best Comment Plugins for WordPress to Boost Engagement
- How to Add Fields in WooCommerce Registration Form
- How to Change Shipping Label WooCommerce
- How to Select All Except Last Child In CSS » CSS Not Last Child Example
- How to Add View Cart Button In WooCommerce
- How to Change WooCommerce Checkout Field Placeholder Text
- How to Set Up WooCommerce Buy One Get One
- How to Add WooCommerce Storefront Hero Image
- How to Create WooCommerce Redirect After Checkout Per Product
- 30+ Best WordPress Gallery Plugins for Attractive Galleries
- How to Duplicate a Product in WooCommerce