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 2 replies, has 2 voices.

Last updated by Diego Pereira 8 months, 1 week ago.

Author Posts
April 18, 2024 at 4:39 pm #15540238

cons-2

Tell us what you are trying to do?
We would like to update our promotional prices regularly via Cronjob.
We use one currency - EUR - and have registered several languages in WPML.

The prices should be the same in all languages.
So we don't have to differentiate between different currencies or countries.

To update the product prices, we use the official CRUD functions from WooCommerce.

Example code:

  $product->set_sale_price('123');
  $product->set_date_on_sale_from('2024-04-01');
  $product->set_date_on_sale_to('2024-04-30');
  
  $product->save();


  do_action('wpml_sync_all_custom_fields', $product->get_id());

Apparently WPML/WCML is not compatible with it.

If we update the price in our source language via Cronjob, the price changes will not be synchronized in the other languages of the shop.

We would prefer to change and save the prices directly instead of filtering them just in time.
This should be more efficient than constantly filtering something.
If that doesn't work, we might be okay with filters temporarily.

I didn't really understand the WPML/WCML documentation.
If I understand this correctly, I can hook into situations where a shop manager saves something in the backend.
Programmatic changes via Cronjob do not seem to be taken into account.

What do I have to do to synchronize prices in all languages?

Is there any documentation that you are following?

    Is there a similar example that we can see?

    Note on debug information
    The debug info is from a staging environment of ours.
    The plugin versions are all correct.
    However, some features that are active on the live site are disabled there.

    The information is therefore more interesting for the active plugins. But not for an overall picture of the site.

April 18, 2024 at 6:22 pm #15540568

cons-2

Hello. Short update: With "do_action('wpml_sync_all_custom_fields', $product->get_id());" we got it running.

The conflict came from somewhere else.

So the issue is settled.

It's a bit unusual with the additional hook, but it seems to work.

Topic can be closed.

April 18, 2024 at 7:44 pm #15540966

Diego Pereira
Supporter

Languages: English (English ) Spanish (Español ) Portuguese (Brazil) (Português )

Timezone: America/Sao_Paulo (GMT-03:00)

Hi there, thanks for the update!

I'm closing the ticket. Please open a new one if needed.