woocommerce / woocommerce

A customizable, open-source ecommerce platform built on WordPress. Build any commerce solution you can imagine.
https://woocommerce.com
9.38k stars 10.76k forks source link

Error: _load_textdomain_just_in_time Called Incorrectly for WooCommerce in WP 6.7.0-beta #51843

Open kmjamsheed0 opened 1 week ago

kmjamsheed0 commented 1 week ago

Prerequisites

Describe the bug

I'm currently running WordPress 6.7.0-beta, and I'm encountering the following error when visiting a product page or interacting with WooCommerce menus:

Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the woocommerce domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.)

The error seems to indicate that the translation loading for WooCommerce is happening too early in the execution order, likely due to a plugin or theme code being triggered prematurely.

Expected behavior

No errors related to translation loading should be triggered during normal WooCommerce usage.

Actual behavior

The error message about _load_textdomain_just_in_time is displayed, indicating that translation loading was triggered too early.

Steps to reproduce

  1. Install WordPress 6.7.0-beta.
  2. Install and activate WooCommerce.
  3. Visit a product page or interact with WooCommerce menus.
  4. The error message appears on the screen or in the debug log.

WordPress Environment

WordPress Version: 6.7-beta1-59156 WooCommerce Version: 9.3.3 Theme: Storefront

Isolating the problem

webdados commented 1 week ago

I can confirm this happens with WooCommerce 9.4.0-beta.2 and WordPress 6.7-beta1-59158

The notice has since been updated to

_load_textdomain_just_in_time means that WooCommerce hasn't yet called load_plugin_textdomain (which is happening correctly on init) but a i18n function with the woocommerce textdomain was already called and WordPress is trying to load the domain "just in time".

In this case, the first string loaded is "WooCommerce" which makes me to believe this is caused by a call to get_plugin_data before init, because this functions tries to get the plugin name localized, unless you pass false to its third parameter (which is how I fixed it on my plugins).

coreymckrill commented 4 days ago

I haven't been able to replicate the error log using WC 9.3.3 or 9.4 beta.2 along with WP 6.7-beta2. @kmjamsheed0 @webdados do you still get this with the WP beta2? If so, are there any other plugins involved? Could you provide some more detailed reproduction steps?

kmjamsheed0 commented 4 days ago

Hi @coreymckrill ,

I'm currently not experiencing the error anymore. I'm using WooCommerce 9.4.0-beta.2 and WordPress 6.7-beta2-59195, and everything seems to be working fine now. It appears that the issue has been resolved with these updates.

Thank you for checking in!

webdados commented 4 days ago

Just made a fresh install to be sure it was not caused by my dev (messy) install πŸ˜‚ and the notice is showing up

Image

System Status Report ``` ### WordPress Environment ### WordPress address (URL): [Redacted] Site address (URL): [Redacted] WC Version: 9.4.0-beta.2 Legacy REST API Package Version: The Legacy REST API plugin is not installed on this site. Action Scheduler Version: βœ” 3.8.2 Log Directory Writable: βœ” WP Version: 6.7-beta2-59198 WP Multisite: – WP Memory Limit: 256 MB WP Debug Mode: βœ” WP Cron: βœ” Language: pt_PT External object cache: – ### Server Environment ### Server Info: nginx/1.26.1 PHP Version: 8.3.11 PHP Post Max Size: 1.000 MB PHP Time Limit: 1200 PHP Max Input Vars: 4000 cURL Version: 8.6.0 (SecureTransport) LibreSSL/3.3.6 SUHOSIN Installed: – MySQL Version: 8.0.16 Max Upload Size: 300 MB Default Timezone is UTC: βœ” fsockopen/cURL: βœ” SoapClient: βœ” DOMDocument: βœ” GZip: βœ” Multibyte String: βœ” Remote Post: βœ” Remote Get: βœ” ### Database ### [REDACTED] ### Post Type Counts ### attachment: 1 page: 7 post: 2 revision: 1 wp_navigation: 1 ### Security ### Secure connection (HTTPS): ❌ Your store is not using HTTPS. Learn more about HTTPS and SSL Certificates. Hide errors from visitors: ❌Error messages should not be shown to visitors. ### Active Plugins (1) ### WooCommerce: by Automattic – 9.4.0-beta.2 ### Inactive Plugins (2) ### WooCommerce Beta Tester: by WooCommerce – 2.3.2 WordPress Beta Tester: by WordPress Upgrade/Install Team – 3.5.6 ### Settings ### Legacy API Enabled: – Force SSL: – Currency: EUR (€) Currency Position: right_space Thousand Separator: Decimal Separator: , Number of Decimals: 2 Taxonomies: Product Types: external (external) grouped (grouped) simple (simple) variable (variable) Taxonomies: Product Visibility: exclude-from-catalog (exclude-from-catalog) exclude-from-search (exclude-from-search) featured (featured) outofstock (outofstock) rated-1 (rated-1) rated-2 (rated-2) rated-3 (rated-3) rated-4 (rated-4) rated-5 (rated-5) Connected to WooCommerce.com: – Enforce Approved Product Download Directories: βœ” HPOS feature enabled: βœ” Order datastore: Automattic\WooCommerce\Internal\DataStores\Orders\OrdersTableDataStore HPOS data sync enabled: – ### Logging ### Enabled: βœ” Handler: Automattic\WooCommerce\Internal\Admin\Logging\LogHandlerFileV2 Retention period: 30 days Level threshold: – Log directory size: 186 B ### WC Pages ### Shop base: #7 - /loja/ Cart: #8 - /carrinho/ - Contains the woocommerce/cart block Checkout: #9 - /finalizar-compra/ - Contains the woocommerce/checkout block My account: #10 - /minha-conta/ Terms and conditions: ❌ Page not set ### Theme ### Name: Twenty Twenty-Four Version: 1.2 Author URL: https://pt.wordpress.org Child Theme: ❌ – If you are modifying WooCommerce on a parent theme that you did not build personally we recommend using a child theme. See: How to create a child theme WooCommerce Support: ❌ Not declared ### Templates ### Overrides: /Users/marcoalmeida/Documents/Websites/_local/app/public/wp-content/plugins/woocommerce/templates/block-notices/error.php /Users/marcoalmeida/Documents/Websites/_local/app/public/wp-content/plugins/woocommerce/templates/block-notices/notice.php /Users/marcoalmeida/Documents/Websites/_local/app/public/wp-content/plugins/woocommerce/templates/block-notices/success.php ### Admin ### Enabled Features: activity-panels analytics product-block-editor coupons core-profiler customize-store customer-effort-score-tracks import-products-task experimental-fashion-sample-products shipping-smart-defaults shipping-setting-tour homescreen marketing mobile-app-banner navigation onboarding onboarding-tasks pattern-toolkit-full-composability product-custom-fields remote-inbox-notifications remote-free-extensions payment-gateway-suggestions printful shipping-label-banner subscriptions store-alerts transient-notices woo-mobile-welcome wc-pay-promotion wc-pay-welcome-page launch-your-store Disabled Features: product-data-views experimental-blocks minified-js product-pre-publish-modal settings async-product-editor-category-field product-editor-template-system blueprint reactify-classic-payments-settings use-wp-horizon Daily Cron: βœ” Next scheduled: 2024-10-10 09:54:42 +00:00 Options: βœ” Notes: 57 Onboarding: completed ### Action Scheduler ### Complete: 7 Oldest: 2024-10-09 09:55:50 +0000 Newest: 2024-10-09 10:01:34 +0000 Pending: 1 Oldest: 2024-10-10 09:55:50 +0000 Newest: 2024-10-10 09:55:50 +0000 ### Status report information ### Generated at: 2024-10-09 10:03:00 +00:00 ```
kmjamsheed0 commented 4 days ago

Hi @coreymckrill

After further testing, I’m unfortunately encountering the error again, but this time it seems to be happening specifically when I visit a translated WooCommerce page.

I'm still using WooCommerce 9.4.0-beta.2 and WordPress 6.7-beta2-59195, but the issue seems tied to the translation aspect of WooCommerce. Could you please advise if there have been any related updates?

Thank you for checking in!

webdados commented 4 days ago

Yeah, probably people are testing with WordPress set to English :-) They need to change the language.

kmjamsheed0 commented 4 days ago

Yeah, probably people are testing with WordPress set to English :-) They need to change the language.

@webdados That makes sense! It seems like the issue is more noticeable when using translation.

webdados commented 4 days ago

It's not only mode noticeable as it is unique to non English. "Load text domain" does nothing if WordPress is set to the default language.

webdados commented 3 days ago

Actually it looks worse, because the translation is not loading at all (still using the same fresh website mentioned above). Look as WooCommerce strings are the only one in English and not Portuguese:

Image

kmjamsheed0 commented 3 days ago

Also, I can't place an order from the translated checkout page because the cart is stuck in an endless AJAX loading loop in the order review section.

webdados commented 3 days ago

Also, I can't place an order from the translated checkout page because the cart is stuck in an endless AJAX loading loop in the order review section.

That's because of the PHP notice. It's normal. Once the underlying issue is solved, that will go away.

The thing is... will the be fixed in the final release of 9.4? I really hope so.

kmjamsheed0 commented 3 days ago

I solved the issue in my personal project by firing the load_plugin_textdomain function after WooCommerce setup. I achieved this by using the after_setup_theme hook:

$this->loader->add_action( 'after_setup_theme', $plugin_i18n, 'load_plugin_textdomain' );

Alternatively, you can use any hook that fires after the plugins_loaded hook, which ensures that all plugins are fully loaded.

webdados commented 3 days ago

WordPress 6.7 requires that the text domains are only loaded on init or later. https://github.com/WordPress/wordpress-develop/blob/trunk/src/wp-includes/l10n.php#L1344