Skip Navigation

This thread is resolved. Here is a description of the problem and solution.

Problem:
The client wants to change the text 'Please select some product options before adding this product to your cart.' in both the default and secondary languages on their WooCommerce site.
Solution:
We recommend three methods to achieve this:
1) Use PHP getText() calls to register the string for translation into secondary languages. You can attempt to change the source language of the string to your secondary language and then translate it back to English, although this is not recommended. More details can be found here: https://wpml.org/documentation/getting-started-guide/string-translation/how-to-change-the-source-language-of-strings.
2) Modify the WooCommerce .PO language file to change the original string to English and then translate it to your secondary language. Instructions for importing .PO files in WPML are available here: https://wpml.org/documentation/getting-started-guide/string-translation/#import-export-po-files.
3) Implement custom code to manipulate the output text at the specified position. A relevant example can be found on Stack Overflow: https://stackoverflow.com/questions/50216622/change-the-alert-text-on-add-to-cart-action-without-selected-variation-in-woocom.

If these solutions do not resolve your issue or seem outdated, we highly recommend checking related known issues at https://wpml.org/known-issues/, verifying the version of the permanent fix, and confirming that you have installed the latest versions of themes and plugins. Should you need further assistance, please open a new support ticket at https://wpml.org/forums/forum/english-support/.

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 3 voices.

Last updated by Marcel 1 year, 1 month ago.

Assisted by: Marcel.

Author Posts
May 3, 2024 at 11:04 am #15591067

dewic

Tell us what you are trying to do?
Change translate: Please select some product options before adding this product to your cart.

Is there a similar example that we can see?
What is the link to your site?
hidden link

go to this link and direct add to cart it will pop up that say: "Please select some product options before adding this product to your cart."

How i can change the text and the translate?

popup.png
May 4, 2024 at 1:08 am #15593026

Andreas W.
WPML Supporter since 12/2018

Languages: English (English ) Spanish (Español ) German (Deutsch )

Timezone: America/Lima (GMT-05:00)

Hello,

Your example is an "Alert" created with JavaScript and this is sadly not translatable with WPML, as it can only translate PHP files coming from WordPress, Themes, or Plugins.

It is usually a bad practice to use such "Alerts" in WordPress and you do not see them very often anymore.

Do you know which plugin of your site is responsible for this "Alert" message?

Best regards
Andreas

May 6, 2024 at 6:23 am #15595114

dewic

Hey, It's coming from Woocommerce it self. here the file
...public\wp-content\plugins\woocommerce\includes\class-wc-frontend-scripts.php

May 6, 2024 at 8:46 am #15595948

Marcel
Supporter

Languages: English (English ) Spanish (Español ) German (Deutsch )

Timezone: Europe/Madrid (GMT+02:00)

Hi,

Please note, WPML is specifically designed to translate strings from your default to your secondary language. It's not intended for translating a string in your default language, such as English.

There are three methods we can explore: using PHP getText () calls, modifying the WooCommerce. PO language file, or using custom code via hooks. Let's delve into each one.

1) The string itself uses PHP getText() calls, so it's registered for translation into other secondary languages: https://plugins.trac.wordpress.org/browser/woocommerce/trunk/includes/class-wc-frontend-scripts.php#L592. You can change the source language of the string to your secondary language and translate it to English. It will switch the source's language: https://wpml.org/documentation/getting-started-guide/string-translation/how-to-change-the-source-language-of-strings. It's possible, but I would not recommend that

2) The correct way would be to modify the WooCommerce .PO language file and import it in WPML, so you still have the original string changed to English and can translate it as any other string to your secondary language. This is coming from this .pot template here: https://plugins.trac.wordpress.org/browser/woocommerce/trunk/i18n/languages/woocommerce.pot. You can import it as described here: https://wpml.org/documentation/getting-started-guide/string-translation/#import-export-po-files.

3) You can use custom code to manipulate the output at that position: https://stackoverflow.com/questions/50216622/change-the-alert-text-on-add-to-cart-action-without-selected-variation-in-woocom.

Best Regards
Marcel

May 6, 2024 at 8:52 am #15595977

Marcel
Supporter

Languages: English (English ) Spanish (Español ) German (Deutsch )

Timezone: Europe/Madrid (GMT+02:00)

Hi,

Please note, WPML is specifically designed to translate strings from your default to your secondary language. It's not intended for translating a string in your default language, such as English.

There are three methods we can explore: using PHP getText () calls, modifying the WooCommerce. PO language file, or using custom code via hooks. Let's delve into each one.

1) The string itself uses PHP getText() calls, so it's registered for translation into other secondary languages: https://plugins.trac.wordpress.org/browser/woocommerce/trunk/includes/class-wc-frontend-scripts.php#L592. You can change the source language of the string to your secondary language and translate it to English. It will switch the source's language and allow you to modify the original text: https://wpml.org/documentation/getting-started-guide/string-translation/how-to-change-the-source-language-of-strings. It's possible, but I would not recommend that.

2) The correct way would be to modify the WooCommerce .PO language file and import it in WPML, so you still have the original string changed to English and can translate it as any other string to your secondary language. This is coming from this .pot template here: https://plugins.trac.wordpress.org/browser/woocommerce/trunk/i18n/languages/woocommerce.pot. You can import it as described here: https://wpml.org/documentation/getting-started-guide/string-translation/#import-export-po-files.

3) You can use custom code to manipulate the output at that position: https://stackoverflow.com/questions/50216622/change-the-alert-text-on-add-to-cart-action-without-selected-variation-in-woocom.

Best Regards
Marcel