Skip Navigation

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

Problem:
The client is developing a site using WPML to manage product translations and has created a custom plugin to fetch and migrate products from another WooCommerce WPML store. The issue arises when duplicating a product for another language, as it requires manual selection of 'Translate independently' due to WPML maintaining the product, causing both languages to get translated simultaneously when synchronized.
Solution:
We recommend using a custom code approach to automate the process of setting duplicated products to 'Translate independently'. Here is a step-by-step guide on how to implement this:

global $wpdb;<br />$table_name = $wpdb->prefix . 'icl_translations';<br />$product_ids = $wpdb->get_col("SELECT element_id FROM $table_name WHERE element_type = 'post_product'");<br />foreach ($product_ids as $product_id) {<br />    do_action('wpml_make_post_duplicates', $product_id);<br />    do_action('wpml_set_element_translation', 'post_product', $product_id, [<br />        apply_filters('wpml_default_language', NULL) => $product_id,<br />        apply_filters('wpml_secondary_language', NULL) => $product_id,<br />    ]);<br />}

This code should be triggered with a CTA for test purposes. If this solution does not apply to your case, or if it 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 further assistance is needed, please open a new support ticket 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: 

This topic contains 2 replies, has 2 voices.

Last updated by Bahij 10 months, 1 week ago.

Assisted by: Mihai Apetrei.

Author Posts
August 1, 2024 at 1:46 pm #16029890

Bahij

Background of the issue:
I am developing a site and using WPML to manage product translations. I created a custom plugin to fetch and migrate products from another WooCommerce WPML store, creating products in both French (FR) and English (EN) using an API. My plugin translates products with matching SKUs to the correct language.

Symptoms:
When I duplicate a product for another language, I need to manually select 'Translate independently' in the editor because the product is maintained by WPML. This causes both languages to get translated simultaneously when they are synchronized.

Questions:
Is there an option to make duplicated products independent automatically?

August 1, 2024 at 2:08 pm #16030070

Mihai Apetrei
WPML Supporter since 03/2018

Languages: English (English )

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

Hi there,

Please take a look at what my colleague mentioned in this existing ticket: https://wpml.org/forums/topic/disable-translate-independently-on-pages/.

That is the current status at the moment, and the only way you can tackle that "in bulk," in case you really need it, is by editing the database, but it is not recommended.

I wish I could offer you another alternative, but those are the options at the moment.

Kind regards,
Mihai Apetrei

August 1, 2024 at 5:40 pm #16031005

Bahij

I fixed my problem with that part of code :
global $wpdb;
$table_name = $wpdb->prefix . 'icl_translations';

// Fetch all products and update their WPML relationship
$product_ids = $wpdb->get_col("SELECT element_id FROM $table_name WHERE element_type = 'post_product'");

foreach ($product_ids as $product_id) {
// Set WPML relationship to translate separately
do_action('wpml_make_post_duplicates', $product_id);
do_action('wpml_set_element_translation', 'post_product', $product_id, [
apply_filters('wpml_default_language', NULL) => $product_id,
apply_filters('wpml_secondary_language', NULL) => $product_id,
]);
}

that part of code is triggered with a cta as a test purpose. it works.