This thread is resolved. Here is a description of the problem and solution.
Problem: The client is using WooCommerce Multilingual (WPML) and needs to trigger the translation of a product via REST API using its SKU. However, when using the REST API, the product is not fully copied, and elements such as title, short description, attributes, and variations are not translated or copied correctly. Solution: We explained that the hook
wpml_make_post_duplicates
used by the client only duplicates the post but does not translate it. For automatic translation after duplication, we suggested hooking into
save_post
and triggering an update of the original. However, translating content using the REST API is not fully integrated in WPML yet. We recommended checking the following documentation on Duplicate Content and a related support ticket at REST APIs to set/retrieve post translations. Additionally, enabling "Translate Everything Automatically" might help as a workaround, though it is not officially tested.
If this solution does not resolve your issue or seems 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. If the problem persists, please open a new support ticket.
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.
Background of the issue:
We are using WooCommerce Multilingual (WPML) on our website hidden link and need to trigger the translation of a product via REST API, using its SKU as an id. To achieve this, we call: do_action('wpml_make_post_duplicates', $product_id);
Symptoms:
Title is not translated, Short_description is not translated, Attributes and Variations are not copied to the translation.
Questions:
How can we properly trigger the translation process via REST API using SKU, ensuring that all mentioned elements are correctly translated?
The hook you are using won't translate the post but it will duplicate it in the WPML sense, which means copy the content and keep it in sync with the original.
Thank you for your response. However, the issue is that when using the REST API, the product is not fully copied.
Issue Description:
- Manual translation in the admin panel works correctly when creating a translation via WPML (plus icon).
- Through the API, the process does not work the same way as in the admin panel.
Technical Process and Problem Details:
- In the first scenario, we create a product via the API, add attributes and variations. Attributes are created correctly, but variations for these attributes are not generated. hidden link
- In the second scenario, we create a product, duplicate it, and attempt to add it to the jobs queue for translation, but at the logging level, there is no indication that the translation is being added to jobs. hidden link
Could you advise on what might be causing the absence of variations and why the translation is not being added to the jobs queue?
The product linkage can be established using the example from GitHub – that part works fine. However, when creating a product through WPML, an issue remains: products are created, but attributes and options are missing.
Could you please advise on how to resolve this? Is there any additional configuration or code adjustment required?
Let me recap the issue so I am sure I understand the problem properly.
You "duplicate" a product programmatically using wpml_make_post_duplicates. The "translation" is properly created but the attributes are missing in the secondary language. Am I right? If you duplicate the product using the user interface it works correctly, right?
Are those attributes global or per product? If they are global attributes, can you please try translating them beforehand and check if this way the code works as expected?
Regarding the new issue you mentioned, I'll create another ticket and follow up there.
You "duplicate" a product programmatically using wpml_make_post_duplicates. The "translation" is properly created but the attributes are missing in the secondary language. Am I right?
---- Yes we use their function do_action(‘wpml_make_post_duplicates’, $product_id); it duplicates the product but only the name description, while it does not duplicate attributes and variations
If you duplicate the product using the user interface it works correctly, right?
---- Yes.
Are those attributes global or per product? If they are global attributes, can you please try translating them beforehand and check if this way the code works as expected?
---- Even if global attributes are all translated, it doesn't fully work correctly. If global attributes are translated in advance there is no problem with them, but then variations are not duplicated?
We recorded a video showing the product creation process and the database status. The records exist in the database but are not linked to the English version via WPML.
We need the product to be correctly linked with options and displayed properly on the frontend. Could you advise on the correct WPML setup?
I think I'll need to consult with our second-tier support...
But first, let me share something I noted from your video.
The "translated" variation in wp_icl_translations doesn't have the source_language_code set.
source_language_code is Null only when it's the original language. The translations should have the source languages from which they were translated. Check the screenshot attached.
Can you please try to sort this in your code and check if it works?
We have rolled back our website to the previous version of the plugin and made the necessary configuration adjustments. Currently, the page is being duplicated and both variations and attributes are loading correctly; however, the description translation is not being applied, even though it indicates that the translation is ready.
Please see the attached screenshots for more details.
the wpml_make_post_duplicates behaves as the WPML duplicate "translation": it creates a synched copy of the original content. It does not trigger the automatic translation. How are you doing the translation after duplicating the original content?
WPML's API does not include any hook to handle the translation flow yet 🙁
Have you tried enabling "Translate Everything Automatically" (see attached screenshot)? After you create the original product programmatically via the rest API it is not automatically translated? If not, you may try resaving the product using save_post.
But this is just a workaround and I didn't test it. At the moment, WPML does not provide an official method to trigger the Advanced Translation Editor’s (ATE) automatic translation programmatically.