Split is_pay_later_messaging_enabled

This commit is contained in:
Alex P 2023-12-20 15:17:07 +02:00
parent a87eba2044
commit 1962823eb3
No known key found for this signature in database
GPG key ID: 54487A734A204D71
2 changed files with 13 additions and 7 deletions

View file

@ -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;
}

View file

@ -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 );
}
/**