From 6bb24e157d98480b3962699d97066712e35de169 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9sar=20Costa?= <10233985+cesarcosta99@users.noreply.github.com> Date: Tue, 28 Jan 2025 00:17:38 -0300 Subject: [PATCH] Fix potential fatal in the WooPay express checkout button (#10236) --- changelog/fix-10193-woopay-express-button-fatal | 4 ++++ includes/class-wc-payments-woopay-button-handler.php | 10 +++++----- 2 files changed, 9 insertions(+), 5 deletions(-) create mode 100644 changelog/fix-10193-woopay-express-button-fatal 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' ] );