Skip Navigation

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 indrekI 1 year ago.

Assisted by: Dražen Duvnjak.

Author Posts
October 31, 2023 at 5:52 am #14696569

indrekI

We use the Woocommerce Multilingual plugin.

Our products are imported via API (via Erply cloud retail software).

In its main language, it displays the variations nicely, but in foreign languages, the variations are not automatically synchronized, but only displayed when the translation is saved.

But every time products are re-synchronized via the API or product information is changed in woocommerces, the variations are lost. It's a big problem when variations disappear after every product update.

I have understood from the support forums that you always have to save and the variations are not automatically created for the translations?

I have tried various troubleshooting and syncings suggested in your forum but it doesn't work for us.

Screenshot 2023-10-31 at 07.49.49.png
Screenshot 2023-10-31 at 07.50.09.png
October 31, 2023 at 7:50 am #14697017

Dražen Duvnjak
Supporter

Languages: English (English )

Timezone: Europe/Zagreb (GMT+01:00)

Hello,

thanks for contacting us.

Yes, what you have said is correct, if you are adding each time new local attributes you need to save and translate them for them to appear in 2nd language, as without translation they do not exist.

Another way, is you create global attributes, translate them, and then in your import match existing ones. In such case you will also probably need to re-save the product for sync to happen or write some custom code for the import plugin, to achieve more compatibility with WPML, for example using correct hooks and triggering the save_post hook. It is just a guess from my side since I am not aware of how the plugin works.

Example related ticket:
- https://wpml.org/forums/topic/update-wcml-products/

Please note we can not help with custom coding or custom plugins, but you can hire a WPML contractor or invite plugin authors to our compatibility program and we will be glad to help.

- https://wpml.org/documentation/support/go-global-program/
- https://wpml.org/contractors/

Hope this helps.

Regards,
Drazen

November 3, 2023 at 6:30 am #14722557

indrekI

Looks like I found a solution

function refresh_woocommerce_products_on_save($post_id) {
// Check if the post type is 'product' to make sure it's a WooCommerce product.
if (get_post_type($post_id) === 'product') {
// Refresh the product to update its data.
wc_delete_product_transients($post_id);

// Use WPML function to synchronize custom fields.
do_action('wpml_sync_all_custom_fields', $post_id);

// Check if the product is variable (has variations).
if (get_post_meta($post_id, '_product_attributes', true)) {
// Get the variations of the product.
$variations = get_posts(array(
'post_type' => 'product_variation',
'post_parent' => $post_id,
'numberposts' => -1,
));

// Loop through variations and refresh/synchronize each one.
foreach ($variations as $variation) {
wc_delete_product_transients($variation->ID);
do_action('wpml_sync_all_custom_fields', $variation->ID);
}
}
}
}

// Hook into the save_post action to trigger the function when a product is saved.
add_action('save_post', 'refresh_woocommerce_products_on_save', 10, 1);