pronamic / wp-pay-core

Core components for the WordPress payment processing library. This library is used in the WordPress plugin Pronamic Pay: https://www.pronamicpay.com/, but also allows other plugin developers to set up a payment plugin.
https://www.wp-pay.org/
GNU General Public License v3.0
27 stars 3 forks source link

Issue with customer locale. #148

Closed knit-pay closed 11 months ago

knit-pay commented 11 months ago

When a customer does not select a preferred language from /wp-admin/profile.php page, and selects "Site Default" on profile page. below code ($user->locale) returns '' (blank) string.

https://github.com/pronamic/wp-pay-core/blob/32713309a863f1dc29de39fea2ebef10b7d21e9a/src/CustomerHelper.php#L90

In the above case, The customer locale should be set to get_locale(). Because the customer is logged in and the customer has chosen the site's default language as their preferred language. But in this case, locale_accept_from_http is getting set as customer language, which in my opinion is wrong. https://github.com/pronamic/wp-pay-core/blob/32713309a863f1dc29de39fea2ebef10b7d21e9a/src/CustomerHelper.php#L105 https://github.com/pronamic/wp-pay-core/blob/32713309a863f1dc29de39fea2ebef10b7d21e9a/src/CustomerHelper.php#L122

Is this intentional or it is a bug?

Steps to reproduce

  1. The website language is Spanish.
  2. The user language on profile page is "Site Default" (which means Spanish).
  3. Language in Windows or any other device and Browser is set to English
  4. Customer language should be set as Spanish (From Step 2), it should not set at English from step 3.

If you also think it is a bug, may I raise the pull request to fix it?

rvdsteege commented 11 months ago

The language from the user profile is only considered when set explicitly by the user. "Site Default" is the default value, not a language and not necessarily selected by the user intentionally, therefore it is correct that this value is ignored. In this case, the browser language tells probably more about the preferred language than the site language, so in your example it should be English.

knit-pay commented 11 months ago

Thanks for the information.