This thread is resolved. Here is a description of the problem and solution.
Problem:
The client was unable to translate the name of a product variation in a WooCommerce site using WPML. Despite the translation being completed in the Advanced Translation Editor (ATE), the variation name still displayed in the original language on the front-end.
Solution:
We identified that the issue was related to a custom function in the theme's
functions.php
file, which incorrectly handled language information and prevented translations from being applied. We modified the function to ensure it checks for valid data before proceeding. Here's the corrected code snippet:
if (function_exists('wpml_get_language_information')) {<br /> $lang_info = wpml_get_language_information($post_id);<br /> // Check if we got a WP_Error<br /> if (is_wp_error($lang_info)) {<br /> error_log('WP_Error encountered in wpml_get_language_information: ' + $lang_info->get_error_message());<br /> return; // Stop execution if there's an error<br /> }<br /> <br /> if ($lang_info['language_code'] !== 'en') {<br /> return;<br /> }<br />}
After applying this fix, the product variation name displayed correctly in all languages. If this solution does not resolve your issue, or if it seems outdated or irrelevant to your case, please check related known issues at https://wpml.org/known-issues/, verify the version of the permanent fix, and confirm that you have installed the latest versions of themes and plugins. We highly recommend opening a new support ticket if further assistance is needed. You can do so at 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, WCML
Related documentation:
This topic contains 8 replies, has 2 voices.
Last updated by Prosenjit Barman 3 weeks, 5 days ago.
Assisted by: Prosenjit Barman.
Author | Posts |
---|---|
October 20, 2024 at 9:34 am #16308264 | |
petrC-8 |
Background of the issue: Symptoms: Questions: |
October 20, 2024 at 9:44 am #16308347 | |
petrC-8 |
I tried and it didn't help: 1: WPML -> Taxonomy translations - Resync Attributes: no effect 2: WPML -> Support -> Troubleshooting: Products - resync post taxonomies (completed with 10 products): no effect 3: WPML -> Support -> Troubleshooting: Clear the cache in WPML Now, when I go back to product edit in English and click the Update Translation "eye icon" in Advanced Translation Editor, I can now see "Pack of 20" with its translation. I hit Complete Translation, but it's still in English on the front-end. |
October 20, 2024 at 9:53 am #16308388 | |
petrC-8 |
Another weird thing is that in the Translation queue, the Variations are marked as Completed, but the Product is impossible to complete. Even when I hit Continue Reviewing and Complete translation in the Advanced Translate Editor, it's still in "Review in progress" state. |
October 21, 2024 at 9:27 am #16311238 | |
Prosenjit Barman Supporter
Languages: English (English ) Timezone: Asia/Dhaka (GMT+06:00) |
Hello There, I reviewed the product and noticed the issue. After checking the translation job in our system, I found that the translation is completed but hasn't been delivered to your site due to some issues. This seems to be why the text isn't displaying correctly in other languages. Additionally, I noticed that the site has been moved from 'hidden link' to the main site, but the site key for the main site hasn't been updated yet. This could be causing issues with delivering the translation. Please try updating the site key by following the steps below and check if that helps in solving the issue. - Please go to Registered Sites section of WPMl and delete the site key for your main site. Click on the Trash icon(Screenshot: hidden link) and delete the site key. Sometimes the firewall can also affect both inbound and outbound API requests, I recommend following the instructions in this guide and then trying to translate the product again. I hope it will help. Please feel free to let me know if you need further assistance in this matter. I will be happy to help. Best regards, |
October 21, 2024 at 11:25 am #16311937 | |
petrC-8 |
Hi, I made these changes: But it's still the same. Instead of "Paquete de 20", I still see "Pack of 20", even though in ATE it's correct. Still missing this attribute in product attributes. Please see screenshots. |
October 22, 2024 at 4:20 am #16314897 | |
Prosenjit Barman Supporter
Languages: English (English ) Timezone: Asia/Dhaka (GMT+06:00) |
Hello There, Since the attribute has been translated correctly, it should not be missing from the translated product. Upon reviewing the product again, the variation title appears to be displayed in the pricing section. This could indicate that the variation hasn't been synchronized properly, leading to the issue. Could you please try the following steps and see if they resolve the problem? - Please go to WPML > Support > Troubleshooting => Synchronize posts taxonomies [Select 'Variations' from the dropdown under "cleanup"] - After completing the steps, clear the cache from both your site and browser. Please give it a try and let me know how it goes. I'll be happy to help if you need further assistance in this matter. Best regards, |
October 22, 2024 at 7:49 am #16315374 | |
petrC-8 |
I did exactly what you said and recreated the variation completely from scratch, but the results are the same. Please try accessing the site yourself. Sending messages once a day is highly inefficient for us, and my client is not very happy with this situation. I had to create a temporary solution and label this variation in the main English language as Czech (which is the most important market for my client, so you will now see the variation name as "Balení po 20 kusech"), but the issue persists. The translation is not visible in other languages (such as Spanish). Even though I have this text translated into Spanish in ATE, the FE still shows the text from the English version (now in Czech). We didn't have this issue when creating products for the first time. It's only happening now while editing the product. Please try enter the site and do what is necessary by yourself . Sending messages once a day is highly inefficient for us, and my client is not very happy with this situation. |
October 23, 2024 at 3:05 am #16319734 | |
Prosenjit Barman Supporter
Languages: English (English ) Timezone: Asia/Dhaka (GMT+06:00) |
Hi There! As the issue persists, a closer inspection will be required to understand its root cause. I request temporary access (wp-admin and FTP) to your site so I can take a better look at the issue. It would be better to have a testing site where the issue is replicated. You will find the needed fields below the comment area when you log in to leave your next reply. The information you will enter is private which means only you and I can see and have access to it. Maybe I'll need to replicate your site locally. For this, I’ll need to temporarily install a plugin called “Duplicator” or "All in One WP Migration" on your site. This will allow me to create a copy of your site and your content. Once the problem is resolved I will delete the local site. Let me know if this is ok with you. IMPORTANT Looking forward to your response. Best Regards, |
October 24, 2024 at 3:32 am #16324098 | |
Prosenjit Barman Supporter
Languages: English (English ) Timezone: Asia/Dhaka (GMT+06:00) |
Hello There, I've checked the issue and was able to identify the problem. In the `functions.php` file of your theme, the following condition in the `sync_price_and_sale_price_czk_to_translations_variations()` function was causing an error. if ($lang_info['language_code'] !== 'en') { return; } This condition caused an error that prevented the translation from being applied correctly on your site. As a result, the default variation name was displayed in other languages instead of the translated version. Here is the error that was logged: Cannot use object of type WP_Error as array /home/u244214315/domains/bitters.bio/public_html/wp-content/themes/hello-theme-child-master/functions.php:37 The error occurred because the function used to check the product's language (`wpml_get_language_information()`) sometimes returns an error (WP_Error) when there’s an issue retrieving the language information. This can happen if the product ID is invalid or if there's a configuration problem. When the function returns an error, the code tries to process it like normal data, leading to this issue. Although providing support of the custom coding is typically beyond the scope of our support, For now, i’ve fixed the issue by adding a check to ensure the function returns valid data before it is used. If an error is encountered, the system now logs it and stops further execution to avoid problems. Here is the updated code: if (function_exists('wpml_get_language_information')) { $lang_info = wpml_get_language_information($post_id); // Check if we got a WP_Error if (is_wp_error($lang_info)) { error_log('WP_Error encountered in wpml_get_language_information: ' . $lang_info->get_error_message()); return; // Stop execution if there's an error } if ($lang_info['language_code'] !== 'en') { return; } } After making this update, I refreshed the Spanish and Czech translations for the product, and the variation name now displays correctly. You can check the result here: hidden link I hope this resolves the issue. Please note that if you need further assistance with custom code, please consider hiring a developer. You can find experienced professionals on WPML's verified contractor list. If you have any other questions or need clarification, feel free to let me know. I'll be happy to help! Best regards, |
October 24, 2024 at 7:58 am #16324794 | |
petrC-8 |
Wow! You are the best Prosenjit!!!!! |