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.

Sun Mon Tue Wed Thu Fri Sat
10:00 – 14:00 10:00 – 14:00 10:00 – 14:00 10:00 – 14:00 10:00 – 14:00 - -
16:00 – 20:00 16:00 – 20:00 16:00 – 20:00 16:00 – 20:00 16:00 – 20:00 - -

Supporter timezone: Asia/Jerusalem (GMT+03:00)

Tagged: 

This topic contains 16 replies, has 3 voices.

Last updated by Itamar 8 months, 3 weeks ago.

Assisted by: Itamar.

Author Posts
August 24, 2024 at 6:26 pm #16100525

oleksandrD-10

Background of the issue:
I wrote the code for loading products via API. I have three languages in the admin panel. I initially load the product in the default language, and then create duplicate products in other languages. My code looks like this

$get_language_args = array('element_id' => $product_id, 'element_type' => 'post_product' );
$original_post_language_info = apply_filters( 'wpml_element_language_details', null, $get_language_args );

if (function_exists('wpml_set_element_language_details')) {
$set_language_args = array(
'element_id' => $product_id,
'element_type' => 'post_product',
'trid' => $original_post_language_info->trid,
'language_code' => $default_language,
'source_language_code' => $original_post_language_info->language_code
);
do_action('wpml_set_element_language_details', $set_language_args);
}

if (!apply_filters('wpml_element_has_translations', '', $product_id, 'post_product')) {
do_action('wpml_admin_make_post_duplicates', $product_id);
}

what problem I noticed. I set up the uploading of products and checked in real-time how they were loading. and switched to another language. and when I switched, products began to appear whose categories were in the default language. naturally, such products cannot be opened, they caused a fatal error. at first I thought that I wrote the code incorrectly. but then I realized that this happens exactly at the moment when I switched the language in the admin panel. if I start uploading and do not touch the admin panel or move around in the admin panel only in a default language, then such a problem does not arise.
but here is the problem.
I currently have more than 36k products that should be loaded and there will be another batch of products. i.e. this process should happen on the backend and should not be related to switching languages ​​in the admin panel, because in addition to the fact that the cron will be executed, which will take a lot of time, the admin will work in the system and work with the content and he will switch between languages.

I followed the instructions
https://wpml.org/wpml-hook/wpml_set_element_language_details/

Symptoms:
If I upload products and switch to another language in the admin panel, the products are loaded into this language in the default language.

Questions:
What can be added to the code so that the uploading of products is not affected by switching languages in the admin panel?

August 27, 2024 at 7:13 am #16107684

Dražen
Supporter

Languages: English (English )

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

Hello,

Thanks for contacting us.

While you wait for my colleague to take over the ticket, let me try to help you with the issue quickly.

Since this is a custom code issue and might be a bug with WPML, we would need you to try and reproduce the issue in a simple example on test. Please try to use only WPML plugins, Wocommerce, and WP default themes. You can add custom code via the theme editor, but please try to keep it simple.

- hidden link

We will need to check the issue further and escalate to 2nd tier of further suggestions.

Please also share step by step on how can we reproduce /see the issue.

Thanks,
Drazen

August 30, 2024 at 2:17 pm #16125249

oleksandrD-10

Hello.
I am preparing a simplified version. I think I will add it to your test site tomorrow.

September 1, 2024 at 7:11 pm #16129453

Itamar
WPML Supporter since 02/2016

Languages: English (English )

Timezone: Asia/Jerusalem (GMT+03:00)

Hi,

I'll continue to help you with this issue.

If you need further help, please continue to replicate the issue on the sandbox site.

Thanks,
Itamar.

September 5, 2024 at 4:47 am #16142998

oleksandrD-10

I have done tests. Unfortunately I will not be able to make a simplified version on your test site. The error is reproduced only when connecting to the API and loading products with images.
I can provide access to the test site on the my server

September 5, 2024 at 11:33 am #16144557

Itamar
WPML Supporter since 02/2016

Languages: English (English )

Timezone: Asia/Jerusalem (GMT+03:00)

Hi,

Please provide access to your test site, explain in detail how to see the problem, and elaborate on your API and how it works.

If you need further help with this, please share the access details to your site with me. I'm enabling a private message for the following reply.

Privacy and Security Policy
We have strict policies regarding privacy and access to your information. Please see:
https://wpml.org/purchase/support-policy/privacy-and-security-when-providing-debug-information-for-support/
**IMPORTANT**
- - Please backup the site files and database before providing us access. --
-- If you have a staging site where the problem can be reproduced, it is better to share access to the staging site.--

Regards,
Itamar.

September 5, 2024 at 6:16 pm #16146410

Itamar
WPML Supporter since 02/2016

Languages: English (English )

Timezone: Asia/Jerusalem (GMT+03:00)

Hi, and thanks for the access details.

I followed your steps, but I cannot see the problem. I switched to English and refreshed the page a few times; however, the categories are still in English and not Estonian. Please see the attached screenshot.

Am I missing something?

Regards,
Itamar.

September 5, 2024 at 7:01 pm #16146496

oleksandrD-10

you need to look at the end of the page, not the beginning
hidden link

September 5, 2024 at 7:05 pm #16146503

oleksandrD-10

it is also not necessary to load such a number of products. incorrect loading starts immediately after switching to another language.
and deleting a large number of products takes a long time.
therefore, you can stop loading at 50-60 products

September 5, 2024 at 7:17 pm #16146529

oleksandrD-10

also, can you delete please the screenshot with the full site address please.
thank you

September 5, 2024 at 7:46 pm #16146639

Itamar
WPML Supporter since 02/2016

Languages: English (English )

Timezone: Asia/Jerusalem (GMT+03:00)

Hi,

The screenshot has been removed.

I'll check this issue and will get back to you.

Please note that my weekend is Friday-Saturday, and I'll be able to continue to check this issue and help you on Sunday.

Regards,
Itamar.

September 8, 2024 at 2:00 pm #16152679

Itamar
WPML Supporter since 02/2016

Languages: English (English )

Timezone: Asia/Jerusalem (GMT+03:00)

Hi,

I deleted the existing products to try the process again, but no products are being imported when I click the Add/Update products button, so I'm stuck in the stage of seeing the problem. Please see my video here.

hidden link

Can you please correct this problem?

Also, to check this correctly, you must set your site to a minimum environment, which means switching to a default WordPress theme like Twenty Twenty-Four and deactivating all third-party plugins besides WooCommerce and WPML and its add-ons. (If the import plugin must stay active, leave it active.)

Regards,
Itamar.

September 9, 2024 at 3:49 pm #16157569

oleksandrD-10

API not been working since Sunday morning. We are resolving the issue with the provider. I will write back when the issue is resolved.

also about this
..........
Also, to check this correctly, you must set your site to a minimum environment, which means switching to a default WordPress theme like Twenty Twenty-Four and deactivating all third-party plugins besides WooCommerce and WPML and its add-ons. (If the import plugin must stay active, leave it active.)
..........
it's impossible. it will cause a lot of errors. it won't be possible to check the import like that.

September 9, 2024 at 9:02 pm #16158867

Itamar
WPML Supporter since 02/2016

Languages: English (English )

Timezone: Asia/Jerusalem (GMT+03:00)

Hi,

OK, I'll wait for your reply.

I must mention that it sounds like you have a lot of custom code to make your site work. We'll do our best to help, but please know that we might get to a point where it will be out of the scope of our support forum.

Regards,
Itamar.

September 10, 2024 at 5:22 am #16159222

oleksandrD-10

no. the theme is built on the basic wp code. all several modifications have been added to the theme. the point is that in addition to the basic code, custom fields are used.
i.e. if you disable custom fields, then the theme must definitely be switched to the basic one, because otherwise, the site will give a fatal error.
however, these custom fields are also used in products for display in the product template. as well as a plugin for creating custom sections. several sections for products were created through it.
if you disable custom fields and custom sections for products. this is somewhere around 75% of the import code.
that's why I say there will be a lot of errors.
I can try to remove the uploading of this data.
but I think this is a waste of time.
the thing is that I think the reason is that the launch of the product uploading is carried out in the admin panel by pressing the button.
i.e. being at that moment in the basic language of the admin panel, the uploading is launched. then in another section, in this case, products, we switch to another language, but the thing is that according to the logic of your plugin, it doesn't matter in which part of the admin panel you are, the language switches everywhere. i.e. in our case, including on the page where the loading occurs, this happens in the background, so to speak.
the question is how to get around this

The topic ‘[Closed] setting the default language for a product when loading via API, regardless of what language is curr…’ is closed to new replies.