Translate Apply Coupon / Woocommerce Cart page

Hi there,

I’m making a site here:

  1. Here’s a product:
  1. After I add it to the cart, here’s the cart page:

https://www.tablebudapest.com/kosar/

Everything is in Hungarian, except for “apply coupon”. After some search, I found the following code:

jQuery(“input[name=‘apply_coupon’]”).attr(“value”,“custom text”);

Then I tried this:

add_filter(‘gettext’, ‘x_translate_text’ , 20, 3);
function x_translate_text ( $translated_text, $text, $domain ) {

$translation = array (
‘Apply Coupon’ => ‘Your new text’
);

if( isset( $translation[$text] ) ) {
return $translation[$text];
}

return $translated_text;

}

However, neither does not seem to work anymore. Any ideas?

Thanks!

Hello @Pbalazs89,

Thanks for posting in!

To resolve your issue, please use this code instead:

add_filter('gettext', 'x_translate_text');
function x_translate_text ( $translated_text ) {
	$your_text  = "Your new text";
  	$translated = str_ireplace('Apply Coupon', $your_text, $translated);
  	return $translated; 
}

We would love to know if this has worked for you. Thank you.

Hi again,

Tried it, it does not work unfortunately.

Hey @Pbalazs89,

Please try this code instead:

// Translate Strings
add_filter( 'gettext', 'translate_x_strings', 20, 3 );

function translate_x_strings( $translated_text, $text, $domain ) {

        switch ( $translated_text ) {

            case 'Apply coupon' :

                $translated_text = __( 'Your translated text.', '__x__' );
                break;

        }

    return $translated_text;
}

Hope this helps.

Unfortunately, this does not work either.

Hey @Pbalazs89,

Please update the code to:


// Translate Strings
add_filter( 'gettext', 'translate_x_strings', 20, 3 );

function translate_x_strings( $translated_text, $text, $domain ) {

        switch ( $translated_text ) {

            case 'Apply coupon' :
            case 'Apply Coupon' :

                $translated_text = __( 'Your translated text.', '__x__' );
                break;

        }

    return $translated_text;
}

Hope this helps.

Sorry, not working. :frowning:

Hey @Pbalazs89,

I tried those code in my setup and they work correctly:

Perhaps there is something different in your setup, please provide us with the admin access to your site in a Secure Note:

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.