diff --git a/changelog/fix-10193-woopay-express-button-fatal b/changelog/fix-10193-woopay-express-button-fatal new file mode 100644 index 00000000000..cafdf6cb55c --- /dev/null +++ b/changelog/fix-10193-woopay-express-button-fatal @@ -0,0 +1,4 @@ +Significance: patch +Type: fix + +Prevent potential fatal when initializing the WooPay express checkout button. diff --git a/includes/class-wc-payments-woopay-button-handler.php b/includes/class-wc-payments-woopay-button-handler.php index 6d731566ebf..18610781a8a 100644 --- a/includes/class-wc-payments-woopay-button-handler.php +++ b/includes/class-wc-payments-woopay-button-handler.php @@ -125,12 +125,12 @@ public function init() { // Create WooPay button location option if it doesn't exist and enable all locations by default. if ( ! array_key_exists( self::BUTTON_LOCATIONS, get_option( 'woocommerce_woocommerce_payments_settings' ) ) ) { + if ( isset( $this->gateway->form_fields[ self::BUTTON_LOCATIONS ]['options'] ) ) { + $all_locations = $this->gateway->form_fields[ self::BUTTON_LOCATIONS ]['options']; - $all_locations = $this->gateway->form_fields[ self::BUTTON_LOCATIONS ]['options']; - - $this->gateway->update_option( self::BUTTON_LOCATIONS, array_keys( $all_locations ) ); - - WC_Payments::woopay_tracker()->woopay_locations_updated( $all_locations, array_keys( $all_locations ) ); + $this->gateway->update_option( self::BUTTON_LOCATIONS, array_keys( $all_locations ) ); + WC_Payments::woopay_tracker()->woopay_locations_updated( $all_locations, array_keys( $all_locations ) ); + } } add_action( 'wp_enqueue_scripts', [ $this, 'scripts' ] );