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.

Tagged: 

This topic contains 28 replies, has 2 voices.

Last updated by Dražen Duvnjak 1 year, 1 month ago.

Assisted by: Dražen Duvnjak.

Author Posts
September 21, 2023 at 3:10 pm #14440697

Jerzy Afanasjew

I am trying to: programatically update product array/category discounts or discount schedule

Link to a page where the issue can be seen: protestkit.eu/debugging (access available on request)

I expected to see: changed discount rate and/or schedule

Instead, I got: correctly changed discount rate if site language is set to Polish (default currency is Polish zlotys), otherwise (site default language set to English) prices are updated incorrectly, even if code only changes schedule and does not edit prices at all.

Code examples used: https://stackoverflow.com/questions/77123493/programatically-change-discount-price-for-products-including-translations

I am certain this is a bug (not custom work request) because no matter what approach I try to access only specific language version of products or hardcoded product IDs, the code only works correctly when site default language in WPML settings is set to Polish. Please inspect, thank you.

September 23, 2023 at 6:32 am #14449973

Jerzy Afanasjew

To my surprise the issue is not limited to updating products programatically. It also happens when I simply schedule discounts via WooCommerce product settings. Today at 00:00 the discounts I configured manually got corrupted, both these that ended and those that become enabled. I have a few clues:

1) Price discount badge snippet displayed "Warning: A non-numeric value encountered in /usr/home/sin/domains/www.protestkit.eu/public_html/wp-content/themes/Themify-Shoppe-Child/functions.php on line 1004" and showed -100%. Line 1004 is " $max_percentage = ( ( $product->get_regular_price() - $product->get_sale_price() ) / $product->get_regular_price() ) * 100;"

2) Products which discounts become enabled did not keep the starting date, it dissapeared

3) prices displayed after data corruption did not match at all the disount I set

September 24, 2023 at 6:39 am #14451553

Jerzy Afanasjew

I have tried to recreate the bug on my staging site which 100% showed the same issue the day before yesterday. I deactivated all plugins and enabled default theme, didn't use any custom code, just set the price scheduling with Woocommerce and WPML enabled. On my main site this corrupts prices when scheduling ends/begins. To my surprise suddently the staging site works perfectly in that regard. This is the second time this has happened, issue appears on main site but doesnt appear on staging site.

I have deactivated all plugins and enabled default theme on my main site, yet the issue there appears.

I attach screenshot of log of when I attempt to programaticaly update discounts. I see in the log that at first when I enable the function (or alter the function slightly by changing the category ID to differeent language version) the product IDs are returned correctly but then everything that comes after is again corrupted. This is with all caching disabling, all plugins except for Woo and WPML disabled, default theme enabled.

Is it possible WPML is somehow caching product IDs? What can possibly explain the issue? It does not show on my staging site with all plugins and custom theme enabled, even though it did earlier, and it shows on main version of the same site with all plugins disabled and only default theme...

CapturFiles_2701.png
September 26, 2023 at 7:01 am #14463319

Dražen Duvnjak
Supporter

Languages: English (English )

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

Hello,

thanks for contacting us.

To keep this simple and summarize it, the issue here happens also with the WP default theme and without any additional custom code or plugins. So let's concentrate on that part and check the issue in such a minimal environment.

It happens when scheduling discounts via WooCommerce product settings.

1) As you mentioned it happens on the production site but not on the staging site, I can only assume there is a difference in the website or server/hosting settings.

The best I can advise is to create a new staging site and see if you can reproduce the issue in such a minimal environment, and compare your hosting/server settings of both ( must use plugins, server caching, PHP versions etc)

Let me know how it goes.

Thanks,
Drazen

September 28, 2023 at 10:17 pm #14484871

Jerzy Afanasjew

I agree that there must be a difference between my staging and production sites but I am unable to find. Sites are identical. All plugins except WooCommerce and WPML disabled. Same settings. Default theme enabled. Staging works, production corrupts schedules sales prices. But all settings are the same. There is no server caching enabled. And I swear staging also didnt work at first which makes me think if it can be a WCML/WPML thing somehow....

In any case, I have two identical sites. One experiences the issue, one doesn't. How do you recommend to proceed? Usually switching of theme and plugins finds the diffeence, but here the issue persists with minimal environment on my production site.

Staging and production are on the same domain.

Could it be somehow a .htaccess issue?

CapturFiles_2719.png
CapturFiles_2718.png
September 29, 2023 at 6:24 am #14485521

Dražen Duvnjak
Supporter

Languages: English (English )

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

Hello,

to start I suggest taking a copy of your production site and checking it on localhost or some other hosting. Then create a new fresh staging site from your production site, and check if the issue happens then, it should if identical copy.

If not, maybe you can try pushing back the staging site to production to see if that fixes the problem.

Other than that, maybe also contact hosting support to see if there is any different from their side, or some object caching is enabled on production but not on the staging site.

Regards,
Drazen

September 30, 2023 at 5:04 am #14490559

Jerzy Afanasjew

Pushing back staging to production is hardly a solution, if I don't understand what caused the issue it will simply reappear again in the future.

Look, I already made a copy of production site. That identical site spontanously after about 3 days stopped having the issue. I know it sounds improbable but that's what happened so there must be some WPML mechanism responsible for it. WPML/WCML is controling price scheduling due to multicurrency use. When I disable WPML, the price schedules dissappear. When I keep only WPML, WCML, WooCommerce and default theme enabled, the issue is present. On my main site that is, as after a few days of running the same schedules manually or via snippet on my staging site, identical to production site, the issue spontanously ended.

There is no caching enabled, my hosting won't help.

All I'm asking for is help in determining what can possibly be the cause after I have determined the issue is caused by WPML/WCML, no other plugins or theme have any impact. I can provide debug info for both sites. Would that help us find the difference? All I did on the staging site, the only difference I manually entered, was change default site language back and forth, but that doesnt help on my main site. When I switch back to Polish as default, prices get corrupted again.

PS. A workaround could be if there is a way to change site default language version without changing the default url.

October 2, 2023 at 6:33 am #14494561

Dražen Duvnjak
Supporter

Languages: English (English )

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

Hello,

we would be glad to help and debug further, but the problem here is an issue only happens on your production website, which makes it difficult for us to check and debug the issue. We can not debug issues on a live production website.

That is why I am trying for you to get a staging site where the issue happens, that way we could take a copy and escalate to our 2nd tier/devs to debug further and check what causes the issue. If it happens only on the production version, then as said it must be related to some difference in settings.

1) So for us to move forward, would need to get a copy or access to the staging site where the issue happens in such a minimal environment. Let me know, please.

2) I am not sure about your question on default language. There are 2 parts, one is changing the default language of the website via WPML > Language and the other is changing the default language in which post/product is created.

- https://wpml.org/forums/topic/changing-the-default-language-of-a-page/

Regards,
Drazen

October 3, 2023 at 7:24 am #14501807

Jerzy Afanasjew

1) I understand, I have set up a fresh staging site, please tell me how to confidentially share credentials with you

2) When I switch default language in main WPML settings then my default domain .eu changes language. If I could change default language to Polish but keep default domain as English that workaround would solve the issue.

October 3, 2023 at 9:28 am #14502915

Dražen Duvnjak
Supporter

Languages: English (English )

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

Hello,

thanks.

1) Please make a full backup of your site (files and database) and confirm it in your next reply. .

Please note, that I might need to do some debugging procedures like enable/disable plugins, switch themes, change the default language of the user account, and/or access your website database to debug the issue further.

Share step by step guide to check the issue.

2) You can not keep the same default domain and language while changing the default language in WPML settings.

The only way would be to change WP address/settings / migrate to use your 2nd domain as your first and default website address.

Regards,
Drazen

October 4, 2023 at 9:04 am #14510943

Dražen Duvnjak
Supporter

Languages: English (English )

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

Hello,

thanks for getting back.

1) Please check and make sure I can log in via FTP I am getting an error.

2) I have switched to the WP default theme and updated WC.

3) Please share with me step by step to check the issue, just a simple reply to keep things clear, and make sure settings are set correctly so I can confirm the issue.

Since I am not sure anymore after all the replies, at one point you said it is working fine with Polish, now saying it is not working fine with Polish, while now your site has the default language set to English, and products are default in Polish?

So, please let's keep it simple and share with me step by step, without any custom code, need to change settings etc.

4) If I understand correctly, I should set the sale price from date to date, and see if this is showing correctly at that date or not, right?

5) If I set sale to the default language of the product (PL) that sale should be applied to that PL product but it is not. Correct?

Thanks,
Drazen

October 4, 2023 at 5:34 pm #14515171

Jerzy Afanasjew

I apologize for any confusion.

1) There should be "hidden link" instead of "hidden link", credentials work, checked. My bad.
2) ok
3)

- site is configured in WPML settings as default language English, in WCML default currency PLN (Polish).
- configure sale schedule for any product for next day
- check how the discount does not apply correctly on the next day

Issue appears with site language English. Issue does not appear with site language Polish.
4. Yes, if you dont want to use the custom function I wrote which enables you to troubleshoot the same mechanisms every 20 seconds. But I understand, first check normal manual scheduling.
5. Sale does apply on schedule but price is different (random?) than defined when scheduling. That is with default site languge set in WPML settings to English. When site language is changed to Polish in WPML language settings then all works perfectly.

October 5, 2023 at 6:14 am #14516791

Dražen Duvnjak
Supporter

Languages: English (English )

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

Hello,

thanks.

I have enabled the wp debug log and scheduled 4 products:

- 2 Product default in EN, one with tax and one without tax applied
-2 Product default in PL, one with tax and one without tax applied

I will check again tomorrow to see how it is applied, and if tax has some effect on this or the default language of products.

Regards,
Drazen

October 6, 2023 at 6:38 am #14524191

Dražen Duvnjak
Supporter

Languages: English (English )

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

Hello,

thanks for your patience, I have checked and could see the same wrong number is applied to all products.

I assume the issue is something with the currency rate, so what I have done now is:

- disabled automatic rate
- Removed EN-US and USD
- Create new fresh website with same settings to confirm issue still happens there

I will check again when the schedule happens, since it is the weekend it will probably be on Monday.

I will update you.

Regards,
Drazen

October 9, 2023 at 5:56 am #14535855

Dražen Duvnjak
Supporter

Languages: English (English )

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

Hello,

thanks for your patience.

1) I see still same issue on your website. Can you please also confirm it using your script.

2) I can reproduce same issue on clean test site with same setting. Can you please also check it out with your script if you can reproduce issue?

- hidden link

3) Please explain to me how your script works, so we can also test it out like that. Do I set the sale price in the same way or inside code?

Thanks,
Drazen