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

Last updated by matthewL-8 5 months, 4 weeks ago.

Assigned support staff: Bruno.

Author Posts
April 3, 2019 at 5:33 pm #3529363

matthewL-8

Hi
I have an issue with an ajax add to cart, works in one language not the other

(yes i did the setting thing WPML > Languages, and look for the "Language filtering for AJAX operations)

The page i am using , the user HAS to logon.
We have two languages English (default) and Spanish

the issue seems to be that _icl_current_language doesnt change when a logged in user switches language and that causes the fail

So
1 - how do i set the user language (in the short term we could live with this if the users can be setup in the right language)
2 - how can we change the _icl_current_language when the user changes language?
Many thanks
Matt

April 3, 2019 at 8:47 pm #3530431

Bruno
Supporter

Languages: English (English ) Portuguese (Brazil) (Português )

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

Hi,

Thank you for contacting us, I would be very happy to help you but I didn't fully understand what is the issue.

I came to your site and I could not replicate the problem you are reporting. In fact, I add the product to the cart in Spanish and this works correctly.

Can you please elaborate a little more so I can better understand? Sometimes screenshots illustrating what you mean may go a long way to clarify what words fail to transmit so if you like make use of "upload an image" below the comment area.

Thank you.

April 4, 2019 at 5:41 pm #3537385

Bruno
Supporter

Languages: English (English ) Portuguese (Brazil) (Português )

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

Hi,

Thank you for the explanation. I believe in this case you should pass the language code directly into the AJAX call.

I'm not sure if you're making AJAX calls using the WordPress recommendations. If not, one way to do this should be by following the steps for creating AJAX calls using native WordPress documentation: https://codex.wordpress.org/AJAX_in_Plugins

Also, in the headers of the call, I noticed that you are using the Cloudflare cache. Have you tried deactivating it, just to test if the calls are going to be done correctly?

Thank you.

April 4, 2019 at 6:21 pm #3537689

matthewL-8

Hi Bruno
Thank you for your reply - yes we have tested with cloudflare on and off.
The issue is sending the data with the cookie _icl_current_language in the incorrect language
when the languages match its fine
Please coudl you reply on how to control this so that the _icl_current_language matches the language of the page the user is on.
This is where we need support. I have reached out to the plugin maker , though i have examined thier code as well and it seems fine.
As mentioned in all 3 posts the issue seems to be with _icl_current_language
So I would be extremely grateful if you could indicate
1 - is it meant to be fixed to one language
2 - if not what could be causing that
2a - if so, if we programtically changed it would it cause other issues with the plugin
3a - how is it determined - is there any documentation on this cookie

April 4, 2019 at 6:39 pm #3537771

matthewL-8

I am also noting discrepencies in browsers - testing in safari, it seems to work better than in firefox
if by adding the appropriate language into the post to admin-ajax.php
what would the parametre be to add?

April 8, 2019 at 9:50 pm #3561493

Bruno
Supporter

Languages: English (English ) Portuguese (Brazil) (Português )

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

Hi,

Sorry for the delay.

>>> Please coudl you reply on how to control this so that the _icl_current_language matches the language of the page the user is on.

The WPML should handle this automatically. That is, it should not be necessary to deal with anything extra besides the steps I posted above.

One problem that might be happening would be if you add some product on the front end and switch the language on the backend (when you're logged in). Note, however, that I'm not sure if this should affect your site.

>>> I am also noting discrepencies in browsers - testing in safari, it seems to work better than in firefox

Have you tried to test the code you are using within the default WordPress theme to see how the AJAX behavior will be? This does not seem to be happening because of WPML.

Thank you.

April 9, 2019 at 11:26 am #3566021

matthewL-8

Hi Bruno, thank you for your reply, I dont think you are able to answer my questions, please can you assign this thread to a different support agent who may be better placed to answer my questions - i will repeat them again because you seemed to totally ignore them - telling me it should work fine is not helping us find a solution. even if you think my questions are not very good, I would be very grateful if you could actually answer them anyway.
*** _icl_current_language ***
1 - is it meant to be fixed to one language
2 - if not what could be causing that
2a - if so, if we programtically changed it would it cause other issues with the plugin
3a - how is it determined

Again for the new agent the steps to reproduce the problem

1 - LOGIN as a user into the english (default) language
2 - the table using add to basket ajax - works fine (the products are variant products)
3 - change language using the language switcher to spanish
4 - the table add to basket now returns "Invalid value posted for Size" (size is the attribute)

looking at the cookie - the _icl_current_language is "en" throughout

April 9, 2019 at 3:06 pm #3568611

matthewL-8

I have done further testing and the pages work fine if the user is NOT logged in

hidden link
hidden link

the issue is LOGGED in users , the _icl_current_language does not change as expected when the client changes site.

This is perhaps on purpose. I woudl really appreciate if you could engage with me on this issue so i can understand and perhaps find a solution. thank you.

April 9, 2019 at 3:46 pm #3569125

Bruno
Supporter

Languages: English (English ) Portuguese (Brazil) (Português )

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

Hi,

Sure. I'll check if we have another supporter to check your ticket.

Please, could you send us the credentials of your site so that we can test the WPML settings of your site, as well as install your site in our testing environment? This will help us to check the files on your site and understand the problem that may be happening.

I'll mark your next answer as private so that you can share the admin credentials. Also, please, could we install Duplicator to make a copy of your site and test it in our testing environment?

Thank you.

April 10, 2019 at 7:48 am #3573191

matthewL-8

Hi Bruno - as discussed from the begining its all about the cookie, I am reached out for information and help. I dont need you to code, necessairy, but help - i am programmer with 20 years expereince. I would so like you to answer the questions i asked, even if the answer is "we cant do anything"
I saw your video, you did not follow my step by step at all.
step 1
hidden link
- you will have to login with
user : distributor
pass : socklab2b
step 2 - add to basket
this page works!
step 3
now change language to go to
hidden link
step 4 - add to basket - you get error message

its all about the mismatch between the cookies on the admin ajax call and the page. The present solution works in many scenarios but not all scenarios.

Because i dont know how your cookie works - i asked questions, which you keep ignoring. So this small issue has now required almost a week. Its not helped by the language and time zone differences, that why i asked for a different agent to take over. Its frustrating to wake up to a reply that misunderstands my question, and have to wait a whole day for another one that does the same. I appreciate the time you are giving this, but we are no nearer to a solution than a week ago, because you have never once answered my questions. please answer these

*** _icl_current_language ***
1 - is it meant to be fixed to one language
2 - if not what could be causing that
2a - if so, if we programtically changed it would it cause other issues with the plugin
3a - how is it determined

thank you

April 11, 2019 at 1:52 pm #3588529

Bruno
Supporter

Languages: English (English ) Portuguese (Brazil) (Português )

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

Hi,

I do not think the problem is happening because of cookies. The WPML works with cookies only to understand the default language and the current language.

AJAX requests, however, should work normally when the "Store a language cookie to support language filtering for AJAX" option is selected because WPML will automatically pass the language code.

Unfortunately, I can not understand what you are posting because this does not seem to be that clear. Even following the steps you posted, I can not replicate the problem.

I understand that you are wondering about cookies or how this is working, but I am still trying to understand how the error is happening - that is, replicate the error.

I noticed that it looks like you are creating this product table using the "WooCommerce Product Table PRO". Have you tried to replicate this problem with only this plugin (WooCommerce Product Table), WC, WCML and WPML to see if the problem is the same? This may even be a compatibility issue.

At this time, please forget about cookies. Just tell us the step by step to replicate the problem. At the moment I'm following the steps below and the problem does not persist:

- Clear all my browser's cache
- Go to the hidden link
- Log in as distributor
- Go to the hidden link
- Insert some product on the cart (English)
- Switch to the secondary language (Spanish)
- Insert some other product on the cart
- The product was successfully added
- New screencast: hidden link

Should be very useful also if you could record a screencast. This can help us understand the steps you are following.

Note: I'm in touch with 2nd tier support so they can check this out too. It is critical, however, that we can replicate the problem so that we can test.

Thank you.

April 11, 2019 at 2:20 pm #3588831

matthewL-8

Hi Bruno, please can you pass my case to soemone else, we are going nowhere - you wont answer my questions, you dont follow my step by step. You are in a different time zone to me. The support issue has become more frustrating that the actual problem. It has been 8 days in which i ask a question, you ignore it and we lose the whole day, to start again the next day.
I wasnt asking you to fix my issue, i was asking for you to answer my questions. You see i am software developer with 20 plus years of coding. I know how frustrating support is. But I also know to read the support queries and answer the user, even if it seems illogical to me. i did a lot of investigating into this issue. I found that the problem comes from the behaviour of the cookie. this is why i asked about the cookie and how i can manipulate it. In my extensive testing, i realized that when a user was logged in, in some case (not all), in some browsers (not all) the cookies could get mucked up, so that you arrive at the scenario where the frontend cookie and the admin ajax cookie are not in harmony. It is in ths scenario that the issue occurs.
please could you give this to soemoen who will do me the curtesy of answering my questions about the cookie. So i can sort this issue out for my client. You know there is problems with the cookie and ajax, thats why you bothered to program an option. Anyway i am fed up trying to ask the same thing time and time again. I dont want you to "fix" the issue, i would like to understand how the cookie works, what action it is dropped on. How i can manipulate it. i will do the work, i will do the support - i need from you information about the code, so i dont have to dig through hundreds of files.

if you fancy trying my step by step, please do so - please do not do your step by step. But try mine - you'll see it above in the thread.
Likewise you'll see above the questions I asked, i would ever so much like you to attempt to answer them.
Many thanks
Matt

April 11, 2019 at 2:24 pm #3588843

Bruno
Supporter

Languages: English (English ) Portuguese (Brazil) (Português )

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

As I explained above, I'm already in touch with 2nd tier support. Your step by step is still unclear.

What are the steps I have to take exactly to see the alert? Certainly, 2nd tier support will also want to know. Otherwise, it is impossible to verify the issue if we can not replicate the problem.

Again, at this time, please, forget about cookies a bit and just help us replicate the problem.

Thank you.

April 11, 2019 at 2:33 pm #3589005

matthewL-8

step 1
hidden link
- you will have to login with
user : distributor
pass : socklab2b
step 2 - add to basket
this page works!
step 3
now change language to go to
hidden link
step 4 - add to basket - you get error message

try and use firefox as broswer

Please please please answer my questions , even if YOU think they are irrelevant, its quicker, more helpful. Perhaps the old geezer whos been building ecommerce sites since the 1990's might have something, why not make him happy and answer his questions.

There is a cookie issue, it might be difficult to replicate, but thats my problem, not yours. Please please please please please please please please please hear me

Please answer my question.

April 11, 2019 at 2:45 pm #3589227

matthewL-8

btw its really like that the issue is caused when you have previously logged in as admin
its also occurinbg less since your last update and the update done by the table plugin guy, who was working on this too.
What it doesnt do is answer my questions, which i would dearly like an answer to, i am guessign you dont know, as it would have been quicker to answer than write so much.