Skip Navigation

This is the technical support forum for WPML - the multilingual WordPress plugin.

Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.

This topic contains 4 replies, has 2 voices.

Last updated by alexandreG-2 4 years, 7 months ago.

Assisted by: Diego Pereira.

Author Posts
June 23, 2020 at 10:00 am #6433365

alexandreG-2

Hello,

thank you in advance for the help you will provide.
I've been searching out in the wpml forum and on the web but can't find a solution that works for me.
I have a badge appearing when some products are on sale, I want to change the text 'On Sale' by 'Pre Order'.

I've been looking for the string to translate it but impossible to find it in wpml plugin so I used the following code placed in the functions.php file:

add_filter('woocommerce_sale_flash', 'woocommerce_custom_sale_text', 10, 3);
function woocommerce_custom_sale_text($text, $post, $_product)
{
return '<span class="onsale">Pre Order</span>';
}

but unfortunately, it doesn't help with translations.
My goal is to have 'Pre-order' in English and 'Pré-commande' in French.

Here is the link to my website: hidden link

Cheers,

Alex.

June 23, 2020 at 7:09 pm #6437535

Diego Pereira
Supporter

Languages: English (English ) Spanish (Español ) Portuguese (Brazil) (Português )

Timezone: America/Sao_Paulo (GMT-03:00)

Hello, welcome to the WPML support Forum!

Please try the following:
- Replace the function with the following code:

add_filter('woocommerce_sale_flash', 'woocommerce_custom_sale_text', 10, 3);
function woocommerce_custom_sale_text($text, $post, $_product)
{
    return __('<span class="onsale">Pre Order</span>', 'your-theme-textdomain-here');
}

- Make sure you have the Translation Magagement and String Translator extensions active. If not, you can download here: https://wpml.org/account/downloads/
- Go to WPML → Theme and Plugin Localization → Strings in the themes
- Select your theme and click on Scan selected theme for strings
- Go to WPML → String Translation and search for the String
- Translate the string, check the Translation is complete field and click on Save.

Ref: https://wpml.org/documentation/getting-started-guide/string-translation/

Please let me know if it worked for you.

June 23, 2020 at 9:14 pm #6438443

alexandreG-2

Hi Diego,

thank you for your reply.
I have a few questions:
- What should I replace "your-theme-textdomain-here" with? Is it the name of the theme?
- I followed your steps and it can't find the string... I've searched for 'onsale' (found it but doesn't affect anything), 'Pre Order' etc...
Thank you in advance for your help.
Alex.

June 24, 2020 at 1:35 pm #6444801

Diego Pereira
Supporter

Languages: English (English ) Spanish (Español ) Portuguese (Brazil) (Português )

Timezone: America/Sao_Paulo (GMT-03:00)

Hi there,

Please try the following:
- Replace 'your-theme-textdomain-here' with 'woocommerce'
- Scan the theme on WPML → Theme and Plugin Localization → Strings in the themes
- Search for "<span class="onsale">Pre Order</span>" on String Translator then translate it

If it does not work, you can try with the following function:

add_filter('woocommerce_sale_flash', 'woocommerce_custom_sale_text', 10, 3);
function woocommerce_custom_sale_text($text, $post, $_product)
{    
	//French Language
	if ( defined( 'ICL_LANGUAGE_CODE' ) && 'fr' == ICL_LANGUAGE_CODE ) {
		return '<span class="onsale">Pré-commande</span>';   
	}
	//English Language
	else {
		return '<span class="onsale">Pre Order</span>';
	}
}

Please let me know if it worked for you.

June 24, 2020 at 2:14 pm #6445219

alexandreG-2

Thanks Diego! The last solution worked perfectly!!!