WooCommerce Bug Triggers E-commerce Site Crashes
A significant bug in WooCommerce is causing numerous online stores to crash, displaying a fatal error. The issue stems from a single line of code within the WooCommerce BlockPatterns.php file. While the WooCommerce team is actively working on a permanent solution, a temporary workaround is available to restore affected sites.
Widespread Reports of Crashes
Reports of the error surfaced on the WordPress.org support forums, with numerous users confirming similar experiences of sudden site crashes. Many reported no recent changes to their sites prior to the issue appearing.
Temporary Workaround Available
A temporary fix involves editing line 251 of the BlockPatterns.php file, located at:
wp-content/plugins/woocommerce/src/Blocks/BlockPatterns.php
The error message typically displayed is:
Uncaught Error: strpos(): Argument #1 ($haystack) must be of type string, null given in /var/www/site/data/www/site.com.br/wp-content/plugins/woocommerce/src/Blocks/BlockPatterns.php on line 251
One user described the issue and the workaround:
Same issue here. It occurred in version 9.8.2, and upgrading to 9.8.3 didn’t resolve it. Downgrading to 9.7.1 didn’t help either. The problem happened without any interaction with plugins or recent updates. Replacing the code at line 251 worked as a temporary workaround. We’ll need a more stable solution until the WooCommerce team releases an official patch.
Quick Fix for Downtime
A quick fix has been shared on the official WooCommerce GitHub repository:
If your websites are currently down, this is the quick fix. To fix sites displaying the fatal error:
Fatal error: Uncaught TypeError: strpos(): Argument #1 ($haystack) must be of type string, null given in /var/www/html/wp-content/plugins/woocommerce/src/Blocks/BlockPatterns.php:251Add
?? ''
to line 251:if ( strpos( $category['title'] ?? '', $prefix ) !== false ) {Clear any WordPress caching layers after applying this change.
The WooCommerce team acknowledges the issue and is actively working on a permanent fix. They attribute the problem to a bad response from the Woo pattern repository and a subsequent caching issue.
Additional Caching Issues on WP Engine
Users hosting on WP Engine may experience persistent issues even after implementing the fix due to multiple caching layers. Clearing all WP Engine caches, including Page Cache and Varnish, is necessary. See WP Engine's caching documentation for details.