How to Translate a WooCommerce String (Rename Any Text, No Plugin Needed)

How to Translate a WooCommerce String (Rename Any Text, No Plugin Needed)
On this page
  1. Why You'd Want to Translate a Single WooCommerce String
  2. Step 1: Add the Translation Snippet
  3. Step 2: Find the Exact String You Need to Replace
  4. Common Issues When a Translation Doesn't Apply
  5. Frequently Asked Questions
  6. Conclusion

You can translate a WooCommerce string — or simply rename a label — without installing a full translation plugin. WordPress ships with a built-in filter called gettext that lets you intercept any text WooCommerce prints on the front end and swap it for whatever wording you want, in any language.

This is the fastest way to change a single word or sentence (like “Sale!” or “Related Products”) without touching .po/.mo files or loading a heavyweight localization tool for one small edit.

Why You’d Want to Translate a Single WooCommerce String

Full translation plugins are useful when you’re localizing an entire store, but they’re overkill when you only need to:

  • Rename a WooCommerce label in your own language (e.g. turn “Sale!” into “On Offer”)
  • Fix or override one word in an existing translation file
  • Keep your site fast by avoiding another plugin running on every page load

In these cases, a five-line PHP snippet in your child theme’s functions.php does the job instantly.

Step 1: Add the Translation Snippet

The snippet below hooks into gettext, WordPress’s core translation filter, and checks whether the string belongs to the woocommerce text domain before replacing it.

Renaming a String in the Same Language (e.g. English to English)

PHP
/**
 * Swap out any WooCommerce front-end label for custom wording
 * Add to your child theme's functions.php
 */
add_filter( 'gettext', 'swap_wc_frontend_label', 999, 3 );

function swap_wc_frontend_label( $translated, $original, $domain ) {

    if ( ! is_admin() && 'woocommerce' === $domain ) {

        switch ( $translated ) {

            case 'Add to cart':
                $translated = 'Add to Bag';
                break;

            case 'In stock':
                $translated = 'Ships Today';
                break;

            // Add more cases as needed
        }
    }

    return $translated;
}
Translate a WooCommerce string: the page before adding the code
Before
Translate a WooCommerce string: the page after adding the code
After

Translating a String Into a Different Language

If your store already runs in a language other than English, match against the untranslated (original English) string instead, since that’s the value WooCommerce passes through before translation:

PHP
add_filter( 'gettext', 'localize_wc_frontend_label', 999, 3 );

function localize_wc_frontend_label( $translated, $original, $domain ) {

    if ( ! is_admin() && 'woocommerce' === $domain ) {

        switch ( $original ) {

            case 'Add to cart':
                $translated = 'Ajouter au panier';
                break;

            case 'In stock':
                $translated = 'En stock';
                break;
        }
    }

    return $translated;
}

Why the is_admin() Check Matters

The ! is_admin() condition restricts the filter to the storefront only, so your WordPress dashboard keeps the original wording. This also avoids running the filter unnecessarily on every admin screen, which is a small but easy performance win.

Step 2: Find the Exact String You Need to Replace

The most common reason this snippet “doesn’t work” is that the wrong string was targeted. WooCommerce sometimes uses slightly different text internally than what’s displayed, especially with placeholders:

Text
// Straightforward:
'Pay for order'

// Contains a %s placeholder for the product name —
// the string you must match is the raw, un-rendered version:
'Sorry, "%s" is no longer in stock so this order cannot be paid for. We apologize for any inconvenience caused.'

When a translation doesn’t apply, search the WooCommerce plugin files (or a tool like Loco Translate’s string list) for the exact source string, including punctuation and special characters — a smart quote (’) versus a straight quote (‘) is a common mismatch.

Special Characters and Ellipses

Strings containing an ellipsis are often stored as the HTML entity … rather than three dots. If your case statement isn’t matching, try the entity version of the string instead of “…”.

Common Issues When a Translation Doesn’t Apply

The String Comes From a Theme or Another Plugin

This snippet only affects text registered under the woocommerce text domain. If a label comes from your theme or a third-party plugin, you’ll need to change the domain check to match, or use that plugin’s own text domain.

The Text Is Generated Dynamically

Messages built with sprintf() at runtime — like cart notices — sometimes bypass gettext entirely. In that case, hook into the specific filter that generates the message (for example, wc_add_to_cart_message) instead.

Multisite or Caching Conflicts

If the change reverts after saving, clear any page or object cache and confirm no other plugin is re-registering the same filter with a higher priority.

Frequently Asked Questions

Do I need a translation plugin to change one WooCommerce string?

No. The gettext filter shown above lets you translate or rename a single WooCommerce string using a small PHP snippet, with no additional plugin required.

Where do I add this code?

Paste it into your child theme’s functions.php file, or add it as a code snippet using a plugin such as Code Snippets. Never edit a parent theme directly, since updates will overwrite your changes.

Can I translate more than one string at once?

Yes — add as many case statements as you need inside the same switch block.

Conclusion

Whenever you need to translate a WooCommerce string or simply rename a default label, the gettext filter is the lightest and most reliable method available. Identify the exact source string, drop in the snippet above, and your custom wording will apply across the storefront instantly.

See also How to Translate the Shipping Label in WooCommerce Cart Totals. Then read How to Rename the Tags Label on the WooCommerce Single Product Page.

Prefer no code? All-in-One Utilities Woo Add-on adds over 50 WooCommerce features, so you can switch them on without code.

Leave a Reply

Schedule a call