Fatal error on product editing screen in custom block theme
-
There’s a high probability that “you’re doing it wrong” applies here, as I am building a block theme for the first time.
I found that I needed to override some of the HTML of the default WooCommerce block templates for archives and single products, so I handled that by creating
templates/single-product.html
(etc.) in my theme, copying the contents ofwoocommerce/packages/woocommerce-blocks/templates/templates/single-product.html
into my new file, and making the necessary changes.On the front end, this works perfectly. But in the admin, if I try to edit the product, I get a fatal error:
An error of type E_ERROR was caused in line 279 of the file /woocommerce/includes/admin/class-wc-admin-meta-boxes.php. Error message: Uncaught TypeError: in_array(): Argument #2 ($haystack) must be of type array, null given in /woocommerce/includes/admin/class-wc-admin-meta-boxes.php:279
Here’s line 279 from
class-wc-admin-meta-boxes.php
in WC:if ( $block_template && in_array( 'product', $block_template->post_types ) ) {
Again, I am probably doing something wrong that is causing this issue, but I also think that WooCommerce should be verifying that
$block_template->post_types
is actually an array before callingin_array()
. Even just casting its type with(array)
will fix the issue. (As a habit in my own code, I always do this when I’m dealing with variables that may or may not be an array.)I should also note that I am running this code on a brand new server running Ubuntu 22.04 with PHP 8.1; this is the first time I’ve spent any considerable time working with PHP 8.x, so it’s possible this code in WC is not causing any problems on servers running PHP 7.4 or earlier.
- The topic ‘Fatal error on product editing screen in custom block theme’ is closed to new replies.