Background of the issue:
I am trying to import products (property-listings) to our site using WP All Import and WPML All Import. The main language of the site is Dutch, and the secondary language is French, which is hidden on the frontend. All products should be imported in French and are translated to Dutch if needed. This process works fine when running the import from the backend. However, when using the WP All Import cron task, all products are imported/updated to Dutch. I attempted to force the language before the import with $sitepress->switch_lang('fr') or do_action('wpml_switch_language', 'fr'), but it had no effect.
Symptoms:
When running the import using the WP All Import cron task, all products get imported/updated to Dutch instead of French.
Questions:
Could the issue be related to the fact that French is hidden?
Why does forcing the language before the import have no effect?
Languages: English (English )German (Deutsch )French (Français )
Timezone: Europe/Zagreb (GMT+02:00)
Hi,
When WP All Import is triggered via cron, I believe that WPML defaults to the site’s main language (Dutch) unless we explicitly set it.
What if you try this?
add_action('pmxi_before_xml_import', function($import_id) {
if (defined('DOING_CRON') && DOING_CRON) {
global $sitepress;
$sitepress->switch_lang('fr');
}
}, 10, 1);
This is based on hidden link
This should ensure that whenever the import runs via cron, WPML is switched to French before any data is processed, so all products are created or updated in the correct language.
After your code and it returns the main language of the site (nl).
To be clear: I've checked your code when we are logged in in the back-end and run the cron in the same browser/window. Then it does return the desired language (fr).
So it seems to be related to the login state and the hidden language not being available for the (WP All import) cron.
Thank you for the updates. Please note that with WP All Import Pro and the WPML All Import Glue plugin, the recommended workflow is to first import products in the default language and then import the translated versions separately. It is not possible to import products directly into a secondary language. Therefore, it is an expected result now.
So I shared the details with our second-tier team for further checking. We will get back to you as early as possible. Please wait.
"It is not possible to import products directly into a secondary language. Therefore, it is an expected result now. "
isn't right, because it works perfectly on some of our others sites and the only difference is that we have our secondary language hidden on this one. Hopefully your second-tier team has some hints/a workaround.
Thank you for the updates. The ticket has been escalated to our developers as a feature request. We will get back to you as soon as we have feedback. Thank you for your patience, and please stay tuned.