You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Browse filesBrowse the repository at this point in the historyBrowse files
authored
Fix/issue WOOTAX-298 - Prevent StoreApi fatal on sites running old WooCommerce (#2971)
* Fix StoreApi fatal on old WooCommerce by adding class_exists guard
* add changelog
* Defer Store API extension to woocommerce_blocks_loaded
Register the Store API extension on the woocommerce_blocks_loaded action
instead of guarding extend_store_api() with a per-request class_exists()
check. On WooCommerce versions too old to ship the Store API that action
never fires, so the extension is skipped structurally rather than caught,
and the class_exists() check is removed. When Blocks have already loaded
the extension is registered inline as before.
Add unit tests covering both the deferred and already-loaded paths.
* Register Store API extension on woocommerce_blocks_loaded with class guard
Register extend_store_api() on woocommerce_blocks_loaded, the same hook
the block integration already uses, instead of calling it during
woocommerce_init. The extension only surfaces notices in the block
cart/checkout, and on a WooCommerce too old to ship Blocks the hook never
fires, so nothing runs.
Keep a class_exists() guard on the top-level
Automattic\WooCommerce\StoreApi\StoreApi class inside the callback. That
covers the in-between versions that ship Blocks (so they fire the hook)
but predate that class, which would otherwise still fatal with "Class not
found". When the class is absent the method logs a notice and returns.
Replace the two deferral tests with tests that exercise the guard itself:
registration runs when the class is present, is skipped when it is
absent, and is_store_api_available() tracks the real class.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* fix: throttle StoreApi-unavailable notice to once per day
extend_store_api() runs on woocommerce_blocks_loaded, which fires on nearly every request. On installs missing the StoreApi class the unavailable notice was written on every page load. Move the logging into log_store_api_unavailable() and gate it behind a daily transient so an affected site logs at most once per day.
Also strengthen the tests: value-pin is_store_api_available() to true in the harness so a class-string typo fails, and add a test asserting the notice fires once and is throttled on the second same-day call.
---------
Co-authored-by: Abdalsalaam Halawa <abdalsalaamnafez@gmail.com>
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-authored-by: Dustin Parker <11618203+dustinparker@users.noreply.github.com>
0 commit comments