From 1962823eb391adc3531c3efd79691e2adc92f8d1 Mon Sep 17 00:00:00 2001 From: Alex P Date: Wed, 20 Dec 2023 15:17:07 +0200 Subject: [PATCH] Split is_pay_later_messaging_enabled --- modules/ppcp-button/src/Assets/SmartButton.php | 2 +- .../src/Helper/SettingsStatus.php | 18 ++++++++++++------ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/modules/ppcp-button/src/Assets/SmartButton.php b/modules/ppcp-button/src/Assets/SmartButton.php index b9959f7da..09a205941 100644 --- a/modules/ppcp-button/src/Assets/SmartButton.php +++ b/modules/ppcp-button/src/Assets/SmartButton.php @@ -394,7 +394,7 @@ class SmartButton implements SmartButtonInterface { * @return bool */ private function render_message_wrapper_registrar(): bool { - if ( ! $this->settings_status->is_pay_later_messaging_enabled() ) { + if ( ! $this->settings_status->is_pay_later_messaging_enabled() || ! $this->settings_status->has_pay_later_messaging_locations() ) { return false; } diff --git a/modules/ppcp-wc-gateway/src/Helper/SettingsStatus.php b/modules/ppcp-wc-gateway/src/Helper/SettingsStatus.php index b29b3b86a..502d7f1dc 100644 --- a/modules/ppcp-wc-gateway/src/Helper/SettingsStatus.php +++ b/modules/ppcp-wc-gateway/src/Helper/SettingsStatus.php @@ -33,15 +33,19 @@ class SettingsStatus { } /** - * Check whether Pay Later message is enabled either for checkout, cart or product page. - * - * @return bool true if is enabled, otherwise false. + * Checks whether Pay Later messaging is enabled. */ public function is_pay_later_messaging_enabled(): bool { - $messaging_enabled = $this->settings->has( 'pay_later_messaging_enabled' ) && $this->settings->get( 'pay_later_messaging_enabled' ); + return $this->settings->has( 'pay_later_messaging_enabled' ) && $this->settings->get( 'pay_later_messaging_enabled' ); + } + + /** + * Check whether any Pay Later messaging location is enabled. + */ + public function has_pay_later_messaging_locations(): bool { $selected_locations = $this->settings->has( 'pay_later_messaging_locations' ) ? $this->settings->get( 'pay_later_messaging_locations' ) : array(); - return $messaging_enabled && ! empty( $selected_locations ); + return ! empty( $selected_locations ); } /** @@ -51,7 +55,9 @@ class SettingsStatus { * @return bool true if is enabled, otherwise false. */ public function is_pay_later_messaging_enabled_for_location( string $location ): bool { - return $this->is_pay_later_messaging_enabled() && $this->is_enabled_for_location( 'pay_later_messaging_locations', $location ); + return $this->is_pay_later_messaging_enabled() && + $this->has_pay_later_messaging_locations() && + $this->is_enabled_for_location( 'pay_later_messaging_locations', $location ); } /**