Skip Navigation

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

Problem:
The client is unable to find the string to translate the "Login / Register" button text that is being replaced using a Code Snippet.

Solution:
We recommend using the

wpml_register_single_string

and

wpml_translate_single_string

hooks to register and retrieve the translation for strings stored in the database by a snippet plugin. Here is a sample code to illustrate how to use these hooks:

function wp_print_login_to_see() {
$str = "Login / Register";
do_action( 'wpml_register_single_string', 'My custom string', 'Register', $str );
$str = apply_filters('wpml_translate_single_string', $str, 'My custom string', 'Register');
echo '<a href="https://amacorprintz.com/my-account/"> <button>'.$str.'</button> </a>';
}

For detailed instructions, please refer to our documentation:

Please note that the solution provided might be irrelevant if it's outdated or not applicable to your case. If the solution does not resolve your issue, 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. If you still need assistance, please open a new support ticket. You can do so by visiting our support forum.

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.

Tagged: 

This topic contains 3 replies, has 3 voices.

Last updated by Bigul 9 months, 1 week ago.

Assisted by: Bigul.

Author Posts
February 23, 2024 at 9:50 pm #15339545

michelR-20

On this shop page:
hidden link

1. The "add to cart" button text is being replaced with "Login / Register" using a Code Snippet.
I can't find the string to translate this text.

2. Also using WPClever Badge Mangement (free) there are EQP* badges which displays hover text "from 72 units".
I can't find the string to translate this text.

Knitwear.jpg
February 23, 2024 at 9:52 pm #15339560

Mihai Apetrei
Supporter

Languages: English (English )

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

Hi there.

Before this ticket gets assigned to my colleagues, I will try to help.

The proper way to translate strings depends a lot on how they have been implemented inside the theme/plugin.

Sometimes, there are even duplicates of the same string and only one of them is the correct one that needs to be translated.

Also, sometimes, simply removing the string (checking the box and removing it) and then re-registering it again by scanning for it (one of the methods below) and re-translating it resolves the issue.

1. Please try this:

Go to WPML > String Translation and at the bottom of the page you will find a checkbox called "Look for strings while pages are rendered". You can enable (check) that and then go in the front end to a page where you have that string showing up and then go back to WPML > String Translation and search for that string and see if it now shows up.

2. If you can't find them inside the WPML > String Translation, they might be added as admin text.

This should be the normal process to find and translate admin text strings:
https://wpml.org/documentation/getting-started-guide/string-translation/finding-strings-that-dont-appear-on-the-string-translation-page/

Please let us know how that goes.

Kind regards,
Mihai Apetrei

February 26, 2024 at 3:23 pm #15345116
michelR-20

1. The "add to cart" button text is being replaced with "Login / Register" using a Code Snippet.
I can't find the string to translate this text.

Code Snippet:
add_action('init', 'wp_hide_price_add_cart_not_logged_in');

function wp_hide_price_add_cart_not_logged_in() {
if ( !is_user_logged_in() ) {
remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 );
remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price', 10 );

add_action( 'woocommerce_single_product_summary', 'wp_print_login_to_see', 31 );
add_action( 'woocommerce_after_shop_loop_item', 'wp_print_login_to_see', 11 );
}
}

function wp_print_login_to_see() {
echo 'hidden link"> <button>Login / Register</button> ';
}

2. Also using WPClever Badge Mangement (free) there are EQP* badges which displays hover text "from 72 units".
I can't find the string to translate this text.

New threads created by Bigul and linked to this one are listed below:

https://wpml.org/forums/topic/i-cant-find-the-wpclever-badge-management-string-to-translate/

February 26, 2024 at 4:27 pm #15345410

Bigul
Supporter

Languages: English (English )

Timezone: Europe/Vienna (GMT+01:00)

Hello,

Thank you for the updates. When we are using a snippet plugin it stores the code in the Database, instead of files like plugins or themes. Therefore please use hooks(wpml_register_single_string & wpml_translate_single_string) for registering strings for translation and retrieving the translation.

Refer to the following documentation for more details and let us know your feedback.

https://wpml.org/wpml-hook/wpml_register_single_string/

https://wpml.org/wpml-hook/wpml_translate_single_string/

//Sample code

function wp_print_login_to_see() {
$str = "Login / Register";
do_action( 'wpml_register_single_string', 'My custom string', 'Register', $str );
$str = apply_filters('wpml_translate_single_string', $str, 'My custom string', 'Register');
echo '<a href="<em><u>hidden link</u></em>"> <button>'.$str.'</button> </a>';
}

Please note that I have opened a new ticket for the other problem. As per our support policies, we can only handle one issue per ticket. It will help us to serve you better and we can avoid discussing multiple problems in one ticket. I will get back to you soon on the latest ticket. Thank you for your understanding.

--
Thanks!

Bigul