From 34ae2ee30b97ec773901a2e72881e77e5969bfce Mon Sep 17 00:00:00 2001 From: Alex P Date: Wed, 1 Sep 2021 16:28:17 +0300 Subject: [PATCH] Show notice only on ppcp and payments page --- modules/ppcp-wc-gateway/services.php | 4 ++- .../class-dccwithoutpaypaladminnotice.php | 30 +++++++++++++++++-- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/modules/ppcp-wc-gateway/services.php b/modules/ppcp-wc-gateway/services.php index 1595b76b3..428caf750 100644 --- a/modules/ppcp-wc-gateway/services.php +++ b/modules/ppcp-wc-gateway/services.php @@ -143,7 +143,9 @@ return array( 'wcgateway.notice.dcc-without-paypal' => static function ( $container ): DccWithoutPayPalAdminNotice { $state = $container->get( 'onboarding.state' ); $settings = $container->get( 'wcgateway.settings' ); - return new DccWithoutPayPalAdminNotice( $state, $settings ); + $is_payments_page = $container->get( 'wcgateway.is-wc-payments-page' ); + $is_ppcp_settings_page = $container->get( 'wcgateway.is-ppcp-settings-page' ); + return new DccWithoutPayPalAdminNotice( $state, $settings, $is_payments_page, $is_ppcp_settings_page ); }, 'wcgateway.notice.authorize-order-action' => static function ( $container ): AuthorizeOrderActionNotice { diff --git a/modules/ppcp-wc-gateway/src/Notice/class-dccwithoutpaypaladminnotice.php b/modules/ppcp-wc-gateway/src/Notice/class-dccwithoutpaypaladminnotice.php index cd88d292a..2343c9e00 100644 --- a/modules/ppcp-wc-gateway/src/Notice/class-dccwithoutpaypaladminnotice.php +++ b/modules/ppcp-wc-gateway/src/Notice/class-dccwithoutpaypaladminnotice.php @@ -32,15 +32,38 @@ class DccWithoutPayPalAdminNotice { */ private $settings; + /** + * Whether the current page is the WC payment page. + * + * @var bool + */ + private $is_payments_page; + + /** + * Whether the current page is the PPCP settings page. + * + * @var bool + */ + private $is_ppcp_settings_page; + /** * ConnectAdminNotice constructor. * * @param State $state The state. * @param ContainerInterface $settings The settings. + * @param bool $is_payments_page Whether the current page is the WC payment page. + * @param bool $is_ppcp_settings_page Whether the current page is the PPCP settings page. */ - public function __construct( State $state, ContainerInterface $settings ) { - $this->state = $state; - $this->settings = $settings; + public function __construct( + State $state, + ContainerInterface $settings, + bool $is_payments_page, + bool $is_ppcp_settings_page + ) { + $this->state = $state; + $this->settings = $settings; + $this->is_payments_page = $is_payments_page; + $this->is_ppcp_settings_page = $is_ppcp_settings_page; } /** @@ -71,6 +94,7 @@ class DccWithoutPayPalAdminNotice { */ protected function should_display(): bool { return State::STATE_ONBOARDED === $this->state->current_state() + && ( $this->is_payments_page || $this->is_ppcp_settings_page ) && ( $this->settings->has( 'dcc_enabled' ) && $this->settings->get( 'dcc_enabled' ) ) && ( ! $this->settings->has( 'enabled' ) || ! $this->settings->get( 'enabled' ) ); }