• Resolved greencode

    (@greencode)


    Not sure why this would have happened but I’ve just disabled Legacy REST API and then the site and backend got a fatal error

    [06-May-2025 12:52:26 UTC] PHP Fatal error:  Uncaught TypeError: strpos() expects parameter 1 to be string, null given in /home/mysite/public_html/wp-content/plugins/woocommerce/src/Blocks/BlockPatterns.php:251
    Stack trace:
    #0 /home/mysite/public_html/wp-content/plugins/woocommerce/src/Blocks/BlockPatterns.php(251): strpos(NULL, '_woo_')
    #1 [internal function]: Automattic\WooCommerce\Blocks\BlockPatterns->Automattic\WooCommerce\Blocks\{closure}(Array)
    #2 /home/mysite/public_html/wp-content/plugins/woocommerce/src/Blocks/BlockPatterns.php(260): array_map(Object(Closure), Array)
    #3 [internal function]: Automattic\WooCommerce\Blocks\BlockPatterns->Automattic\WooCommerce\Blocks\{closure}(Array)
    #4 /home/mysite/public_html/wp-content/plugins/woocommerce/src/Blocks/BlockPatterns.php(247): array_map(Object(Closure), Array)
    #5 /home/mysite/public_html/wp-content/plugins/woocommerce/src/Blocks/BlockPatterns.php(229): Automattic\WooCommerce\Blocks\BlockPatterns->parse_categories(Array)
    #6 /home/mysite/public_h in /home/mysite/public_html/wp-content/plugins/woocommerce/src/Blocks/BlockPatterns.php on line 251

    The only way to get it back up and working again was to replace this in this file wp-content/plugins/woocommerce/src/Blocks/BlockPatterns.php

    if ( strpos( $category['title'], $prefix ) !== false ) {

    with this

    if ( isset( $category['title'] ) && is_string( $category['title'] ) && strpos( $category['title'], $prefix ) !== false ) {

    I was originally running WooCommerce 9.8.2 and even after i’d got everything back up and running and updated to 9.8.3 I got the same error and had to apply the same patch.

    Any ideas?

    • This topic was modified 1 year ago by greencode.
Viewing 15 replies - 1 through 15 (of 22 total)
  • Thread Starter greencode

    (@greencode)

    Edit the code here

    wp-content/plugins/woocommerce/src/Blocks/BlockPatterns.php

    Replace this

    if ( strpos( $category['title'], $prefix ) !== false ) {

    with this

    if ( isset( $category['title'] ) && is_string( $category['title'] ) && strpos( $category['title'], $prefix ) !== false ) {
    José Jefferson

    (@ojosejefferson)

    same problem

    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

    chunkysteveo

    (@chunkysteveo)

    Just got the same error about an hour ago – site is down after doing no updates. Will try this fix to get it back up and running at least….

    Code solution for line 251 worked and site back up. Need resolution from Woo though. Checking GitHub

    Thread Starter greencode

    (@greencode)

    There’s a lot of people reporting it now on GitHub

    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.

    Same here. I was updating plugins, then got this error. Uploaded all the older versions of the plugins back, but still got this error. Chatgpt gave me the solution above and this works for now. But want to keep posted on more solid solutions.

    Same error, no plugin updated.

    maeliacreation

    (@maeliacreation)

    Same error here after updating from WooCommerce 9.8.2 to 9.8.3.

    The workaround is working for now.

    chartnet

    (@chartnet)

    Same here. Even downgrading doesn’t work…

    Hi @greencode, @ekamran, @dvandekamp2, @codifigata , @chunkysteveo,

    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.

    Thread Starter greencode

    (@greencode)

    @mosesmedh Thanks for the quick update. Looking forward to a permanent resolution.

    oldlastman

    (@oldlastman)

    Same error here.

    In my case, upgrading to 9.8.3 doesn’t fix the problem.

    I’ve applied the manual solution described here:

    https://github.com/woocommerce/woocommerce/issues/57760#issuecomment-2854510504. Waiting for any official updates or comments.

    yet, same issue. Downsizing to WooCommerce 9.7.1 made it work again.
    Bizar thing: nothing was going on in the site: no updates, no sale,

    Jonayed (woo-hc)

    (@jonayedhosen)

    Hi @davelo ,

    Just to make sure I’m understanding correctly—after downgrading the plugin version, the site is back up and running, but you’re not seeing any sales data showing up, is that right?

    @jonayedhosen no, that’s not what i meant. During the moment of outage, there was no sale or any update going on. The site has not much traffic.
    So, that’s the scary part of this issue. When and how? Seems like nobody knows.
    And since it’s Mother’s day this weekend, we need to be very very careful for some shops.

Viewing 15 replies - 1 through 15 (of 22 total)

The topic ‘Fatal error BlockPatterns.php:251’ is closed to new replies.