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.

This topic contains 3 replies, has 2 voices.

Last updated by Dražen 1 year, 8 months ago.

Assisted by: Dražen.

Author Posts
August 25, 2023 at 9:11 am #14290453

janisS-4

Hi!

I'm writing to seek assistance with an issue we've encountered concerning price synchronization across languages within our WooCommerce website that utilizes WPML. Here are the details of the matter:

Issue Description:
We've noticed that there seems to be an inconsistency in price synchronization across languages when we programmatically update product prices using the $product->set_regular_price() and $product->save() methods.

Observations:

When we update a product's price in the main language, the change often reflects accurately in at least one other language.
However, there are instances where the updated price doesn't seem to propagate to the third language as expected.
There are also instances when everything is in sync as one would expect.

Queries:

1) Could this behavior be due to a configuration issue or potentially a bug within WPML?
2) What is the recommended approach to ensure that price changes are consistently synchronized across all languages when updated programmatically?
3) We're considering using the save_post action, like demonstrated in the provided snippet: do_action( 'save_post', $product->get_id(), get_post( $product->get_id() ) ); Would this be a suitable solution?
4) In terms of applying the save_post action, is it advisable to use it for a product variation rather than the base variable product?

Thanks!

August 28, 2023 at 7:21 am #14297607

Dražen
Supporter

Languages: English (English )

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

Hello,

thanks for contacting us. It is expected as WPML runs sync on save post.

Our hooks are registered on save_post action so updating only the post meta will not trigger our hooks to sync custom fields.

However, we introduced some hooks you can also use:

https://wpml.org/wpml-hook/wpml_sync_all_custom_fields/
https://wpml.org/wpml-hook/wpml_sync_custom_field/

I haven't replied to each of your questions, since I think my reply sums it up, but if you have any other doubts please let me know.

Regards,
Drazen

August 29, 2023 at 1:28 pm #14307615

janisS-4

Thanks!
Good to know!

Is there anything to know about situations when these hooks wouldn't sync woocommerce product prices?
I didn't really dig into it but in some instances it worked and in some it didn't. It could also be something wrong in shop setup.

Should it work for single product variations as well?
I.e. when you call those hooks with an ID of single variation - should it also sync the changes to the same variation in other languages?

Anything else to be aware of?

August 30, 2023 at 6:40 am #14310211

Dražen
Supporter

Languages: English (English )

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

Hello,

they should work fine, on save/update post, as this is also triggered when you regularly save your products, and price and rest of the fields are synced.

I am not sure about single variations, but I think it would be needed to call regular product ID and then all of the variations of this product will be synced.

Regards,
Drazen