Skip Navigation

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.

Tagged: 

This topic contains 14 replies, has 0 voices.

Last updated by andrewE-3 1 month, 3 weeks ago.

Assisted by: Otto.

Author Posts
February 14, 2025 at 1:15 pm #16706429

andrewE-3

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?

February 14, 2025 at 3:35 pm #16707139

Otto
WPML Supporter since 09/2015

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

Timezone: America/Argentina/Buenos_Aires (GMT-03:00)

Hello,

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.

Here you have a detailed explanation: Duplicate Content

If you need to trigger the automatic translation of a product you may try to hook into save_post and trigger an update of the original.

If this does not work can you please elaborate a bit more on your final goal and the needed flow?

Best Regards,
Otto

February 17, 2025 at 12:44 pm #16714285

andrewE-3

Hello, Otto!

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?

February 17, 2025 at 7:28 pm #16716084

Otto
WPML Supporter since 09/2015

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

Timezone: America/Argentina/Buenos_Aires (GMT-03:00)

Hello,

Thanks for the explanation.

Translating content using the Rest API is not a fully integrated flow in WPML yet.

Please take a look at this ticket that my point you in the right direction:
https://wpml.org/forums/topic/how-to-use-rest-apis-to-set-retrieve-post-translations/

Best Regards,
Otto

February 18, 2025 at 10:53 am #16718192

andrewE-3

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?

February 18, 2025 at 12:25 pm #16718748
andrewE-3

In our WPML we can't find WPML -> Translation management . All WPML connected plugins are updated.

We can't install "Translate Everything Automatically" in Translation management

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

https://wpml.org/forums/topic/we-cant-find-wpml-translation-management/

image_2025-02-18_14-21-50.png
image_2025-02-18_14-21-50 (2).png
February 18, 2025 at 3:31 pm #16719848

Otto
WPML Supporter since 09/2015

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

Timezone: America/Argentina/Buenos_Aires (GMT-03:00)

Hello,

I am glad it partially worked 🙂

Regarding the attributes and options missing.

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.

Best Regards,
Otto

February 19, 2025 at 8:52 am #16722834

andrewE-3

Hello!

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?

February 19, 2025 at 2:35 pm #16725288

Otto
WPML Supporter since 09/2015

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

Timezone: America/Argentina/Buenos_Aires (GMT-03:00)

Hello,

Can you please check these two hooks:
https://wpml.org/wcml-hook/wcml_after_duplicate_product/
https://wpml.org/wcml-hook/wcml_after_duplicate_product_post_meta/

Not sure, but they may help you to the attributes and variations programmatically, once the duplication is done. What do you think?

Best Regards,
Otto

February 20, 2025 at 11:35 am #16729232

andrewE-3

Hello Otto,

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?

Looking forward to your help!

Video:
hidden link

txt file:
hidden link

February 20, 2025 at 7:41 pm #16731177

Otto
WPML Supporter since 09/2015

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

Timezone: America/Argentina/Buenos_Aires (GMT-03:00)

Hello,

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?

Best Regards,
Otto

CleanShot 2025-02-20 at 16.38.33.png
February 24, 2025 at 1:30 pm #16741245

andrewE-3

Hello,

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.

photo_2025-02-24_15-45-59.jpg
photo_2025-02-24_15-45-27.jpg
photo_2025-02-24_15-45-27 (2).jpg
February 24, 2025 at 2:42 pm #16741654

Otto
WPML Supporter since 09/2015

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

Timezone: America/Argentina/Buenos_Aires (GMT-03:00)

Hello,

I am glad you managed to automate the duplication process.

As I explained here:
https://wpml.org/forums/topic/problem-with-translation-via-rest-api/#post-16707139

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?

Best Regards,
Otto

February 25, 2025 at 7:10 am #16744072

andrewE-3

Hello,

How to do auto-translate content after duplication?

We are now doing the translation through editing in the product card. (attached screenshots)

photo_2025-02-25_10-09-29.jpg
photo_2025-02-25_10-09-23.jpg
photo_2025-02-25_10-09-19.jpg
February 25, 2025 at 1:33 pm #16746085

Otto
WPML Supporter since 09/2015

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

Timezone: America/Argentina/Buenos_Aires (GMT-03:00)

Hello,

Yes, that's the expected flow.

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.

Best Regards,
Otto