A WordPress bug is causing WooCommerce sites to display a fatal error, crashing ecommerce sites. The problem originates from a single line of code. A workaround has been created. The WooCommerce team is aware of the issue and is working on issuing a permanent fix in the form of a patch.
WooCommerce Sites Crashing
Someone posted about the error at the WordPress.org support forums and others with the same problem replied that they were experiencing the same thing. Most of those responding reported that they had not recently done anything to their sites, that they had crashed all of a sudden.
The person who initially reported the bug offered a workaround for getting websites back up and running, an edit of a single line of code in the BlockPatterns.php file, which is a WooCommerce file.
The file is located here:
wp-content/plugins/woocommerce/src/Blocks/BlockPatterns.php
Others reported receiving the same fatal error message:
“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 of the commenters on the discussion posted:
“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 to find a more stable solution until the WooCommerce team releases an official patch.”
Others reported that they received the error after updating their plugins but that rolling back the update didn’t solve the problem, while others reported that they hadn’t done anything prior to experiencing the crash.
Someone from WooCommerce support responded to say that the WooCommerce team is aware of the problem and are working to address it:
“Thank you for reporting this. It’s a known issue, and a temporary workaround has been shared here: https://github.com/woocommerce/woocommerce/issues/57760#issuecomment-2854510504
You can track progress and updates on the GitHub thread: https://github.com/woocommerce/woocommerce/issues/57760, as the team is aware and actively addressing it.”
Quick Fix Posted On GitHub Discussion
Someone posted a quick fix to the official GitHub repository that will solve the problem for now:
If Your Websites Are Currently Down – This Is the Quick Fix for You Today
To get sites that were bricked by the update with the error message:
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:251is to add ?? ” into the line 251:
if ( strpos( $category['title'] ?? '', $prefix ) !== false ) {Be sure to clear any WordPress caching layers you might have after applying this change.
Might be helpful for those coming here looking for a quick fix to get live sites working again today, and to buy some time for the WooCommerce team to get #57759 ready.
The same WooCommerce GitHub repository also has this note:
“Some sites might see a fatal error around class BlockPatterns.php, with the website not loading. This was due a bad response from Woo pattern repository. A fix was deployed to the repository but certain sites might still have a bad cache value.”
They also wrote:
“The issue has been fixed from the cache source side but certain sites were left with a bad cache value, we will be releasing patch updates to fix that.”
Extra Problem On WPEngine
Someone wrote that they continued to struggle with their WP Engine site after implementing a fix:
“I’m struggling to implement the fix on WP Engine. I assume it’s a cache issue, but uploading the fix, and clearing all caches isn’t working. Is there an additional step that I’m missing? So far only restoring a backup fixed it.”
The answer was that WP Engine has multiple caches that need to be updated:
“Thats because WPEngine is a platform, not a normal web server – There are many layers you might need to clear including their Page Cache and Varnish caches. See: https://wpengine.com/support/cache/”
Read the initial report on the WordPress Support forum:
Fatal error BlockPatterns.php:251
Read the GitHub discussion:
Fatal Error around strpos in BlockPatterns.php #57760
Featured Image by Shutterstock/Kues