This thread is resolved. Here is a description of the problem and solution.
Problem:
The client needed to translate a custom tab added to the WooCommerce product data, which was not appearing in the WPML String Translation interface.
Solution:
1. We advised the client to ensure that the strings are wrapped in the gettext function. For example, replace:
'Refund and Returns Policy'
with:
__('Refund and Returns Policy', 'themedomain')
2. We instructed the client to go to WPML >> String Translation and enable the 'Look for strings while pages are rendered' option in the Auto register strings for translation section.
3. The client should then visit the page on the front end where the string appears.
4. After that, revisit the WPML >> String Translation page and search for the string.
5. Translate the string as needed.
6. Finally, uncheck the auto-registration option to maintain site speed.
For more details, we provided a documentation link: Translating the Theme You Created.
If this solution does not apply to your case, or if it seems outdated, we highly recommend checking the related 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 do not hesitate to open a new support ticket. You can do so by visiting the WPML 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: Custom Work
This topic contains 10 replies, has 2 voices.
Last updated by ylyasK 8 months ago.
Assisted by: Noman.
Author | Posts |
---|---|
April 26, 2024 at 10:17 pm #15572197 | |
ylyasK |
Hi, I was looking for how to add a custom tab to the product data at woocommerce. And I found one code snippet that lets me do that. I have added it to my codesnippets plugin and it works just fine (adds a custom tab which in my case is Refund and Returns Policy and Shippemnt) Now I want to translate them, but I couldn't find them anywhere even in WPML>String translation>Translate texts in admin screens » I will attach the screenshots Here is the link for that page where I inserted that custom tab hidden link Thanks in advance |
April 27, 2024 at 2:46 am #15572337 | |
ylyasK |
Now looking for the solution among other tickets I found this recommendation Temporarily Enabling Auto-Register Strings But when I was about to start it there was a note: * This feature is only intended for sites that are in development. It will significantly slow down the site, but help you find strings that WPML cannot detect in the PHP code. which is stopping me to use this method. I don't want my site to be slow, and I want to translate that strings in my live site. Please help |
April 28, 2024 at 1:41 pm #15574007 | |
Noman Supporter
Languages: English (English ) Timezone: Asia/Karachi (GMT+05:00) |
Hi, Thank you for contacting WPML Support. To translate the strings in custom code, you need to follow the below steps: 1. Please make sure to wrap the strings in the gettext(__()) function for example, replace the below string: 'Refund and Returns Policy' With: __('Refund and Returns Policy', 'themedomain') And the same need to apply on the paragraph text that is started from “For each specific product” in your screenshot. Here is a doc for more details: https://wpml.org/documentation/support/translating-the-theme-you-created/ 2. Go to the WPML >> String Translation page and in the Auto register strings for translation section, enable the ‘Look for strings while pages are rendered’ option. Please note that you just need to enable that option only for a moment to register that string by reloading the frontend page in which that string appears and then again you can uncheck it and your site speed will be back to normal instantly. Please let me know if you have any questions or if you need further assistance with this issue and I’ll be happy to help. Thank you |
April 28, 2024 at 2:33 pm #15574059 | |
ylyasK |
Hello Noman, thank you for your assistance Actually I am not that cody and it is little hard for me to understand especially step 1. The rest steps are much easier to execute. Is it possible to make it without first step? So the thing that is not quite clear for me about first step is that do I just change that symbol to symbol or there might be a variable? For example in provided by you string "__('Refund and Returns Policy', 'themedomain')" do I have to change 'themedomain' to the name of my theme? Which in my case is Hello from Elementor. So if yes then is this to code snippet correct: add_filter( 'woocommerce_product_tabs', 'ecommercehints_custom_product_tab' ); function ecommercehints_custom_product_tab_content( $slug, $tab ) { |
April 28, 2024 at 3:02 pm #15574074 | |
Noman Supporter
Languages: English (English ) Timezone: Asia/Karachi (GMT+05:00) |
Thanks for trying the above steps and sharing the code. The step #1 is necesary to make the text translatable. Please try to use the updated code: add_filter( 'woocommerce_product_tabs', 'ecommercehints_custom_product_tab' ); function ecommercehints_custom_product_tab( $tabs ) { $tabs['ecommercehints_custom_product_tab'] = array( 'title' => __('Refund and Returns Policy', 'hello'), 'callback' => 'ecommercehints_custom_product_tab_content', 'priority' => 40, ); return $tabs; } function ecommercehints_custom_product_tab_content( $slug, $tab ) { echo '<h2>' . $tab['title'] . '</h2><p>'. __('For each specific product purchased from our platform, a contract will be created that includes the details of our return and refund policy. To learn more about our refund and return policy, visit <a href="<em><u>hidden link</u></em>">here</a>', 'hello').'</p>'; } Here you can see the details about Text domain: Please let me know the results, |
April 28, 2024 at 3:37 pm #15574134 | |
ylyasK |
Thank you Noman for your reply I changed my code snippet to the one that you provided then enabled the ‘Look for strings while pages are rendered’ option. |
April 28, 2024 at 4:14 pm #15574160 | |
Noman Supporter
Languages: English (English ) Timezone: Asia/Karachi (GMT+05:00) |
Okay, to take a closer look at this issue, please provide temporary access (WP-Admin and FTP Login info) to your site (preferably staging site), so that I can look into your setup and debug the issue. Your next answer will be private which means only you and I have access to it. === Please backup your database and website === ✙ I would additionally need your permission to deactivate and reactivate Plugins and the Theme and to change configurations on the site. This is also a reason the backup is really important. Thank you |
April 29, 2024 at 9:53 am #15576187 | |
Noman Supporter
Languages: English (English ) Timezone: Asia/Karachi (GMT+05:00) |
Thanks for sharing the staging site access. I’ve followed the below steps: 1. Enabled the “Look for strings while pages are rendered” option from WPML >> String Translation page. Could you please try to follow the same steps on your live site and let me know how it goes? Thank you |
April 29, 2024 at 6:40 pm #15578531 | |
ylyasK |
Great! Thank you Noman very much. I will let you know as soon as I try it on my live site. |
April 30, 2024 at 4:26 am #15579153 | |
Noman Supporter
Languages: English (English ) Timezone: Asia/Karachi (GMT+05:00) |
No problem, feel free to take your time and update me. Thank you, have a great day. |
May 1, 2024 at 5:55 am #15583082 | |
ylyasK |
Everything is working fine. Thank you very much Noman! |
May 1, 2024 at 5:56 am #15583084 | |
ylyasK |
Thank you very much |