Home›Support›English Support›[Resolved] Import in secondary language only using cron sets all products to primary language
[Resolved] Import in secondary language only using cron sets all products to primary language
This thread is resolved. Here is a description of the problem and solution.
Problem: You are experiencing issues with WP All Import where products are being imported into a different language than the one you set during the import process. Solution: We are aware of this issue and it will be resolved in the next release of the WPML Export & Import plugin. Please keep an eye out for the upcoming release. We will announce it through a blog post and provide detailed documentation on how to implement this. We 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 this solution becomes outdated or does not apply to your case, please open a new support ticket. We highly recommend visiting our support forum for further assistance 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.
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.
Just a quick follow-up on this issue: it will be resolved in the next release of the WPML Export & Import plugin.
Please keep an eye out for the upcoming release. It will be accompanied by a blog post announcing the new feature and providing a link to detailed documentation on how to implement it.