简体   繁体   中英

Warning: Trying to access array offset on value of type bool in /mytheme/functions.php on line 43

Warning: Trying to access array offset on value of type bool in /mytheme/functions.php on line 43

// Add woocommerce support
$start_extended_woo = get_option( 'swp_woo' );
if( $start_extended_woo[0] == 'Enable' ){
add_theme_support( 'woocommerce' );
add_theme_support( 'wc-product-gallery-zoom' );
add_theme_support( 'wc-product-gallery-lightbox' );
add_theme_support( 'wc-product-gallery-slider' );
add_action( 'init', 'woo_remove_wc_breadcrumbs' );
function woo_remove_wc_breadcrumbs() {
    remove_action( 'woocommerce_before_main_content', 'woocommerce_breadcrumb', 20, 0 );
}
}

Im getting this error after upgrading php from 7.4 to php 8.0 any idea how to fix this?

The them im using is Start Wp Theme, Unfortunately it hasnt been updated in 3 years

According to thedocumentation get_option() returns false if it cannot find the option. It's likely your option doesn't exist anymore. To keep it "safe" change to

if( is_array($start_extended) && $start_extended_woo[0] == 'Enable' ){

This will prevent the exact error your referencing.

Another way would be to change the get_option() call to:

$start_extended_woo = get_option( 'swp_woo' , ['Disabled'] );

This will return the, presumed, opposite of your call.

Alternately, add an option for swp_woo in the database, without any code changes.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM