Show notice only on ppcp and payments page

This commit is contained in:
Alex P 2021-09-01 16:28:17 +03:00
parent 9408d1a9e5
commit 34ae2ee30b
2 changed files with 30 additions and 4 deletions

View file

@ -143,7 +143,9 @@ return array(
'wcgateway.notice.dcc-without-paypal' => static function ( $container ): DccWithoutPayPalAdminNotice { 'wcgateway.notice.dcc-without-paypal' => static function ( $container ): DccWithoutPayPalAdminNotice {
$state = $container->get( 'onboarding.state' ); $state = $container->get( 'onboarding.state' );
$settings = $container->get( 'wcgateway.settings' ); $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' => 'wcgateway.notice.authorize-order-action' =>
static function ( $container ): AuthorizeOrderActionNotice { static function ( $container ): AuthorizeOrderActionNotice {

View file

@ -32,15 +32,38 @@ class DccWithoutPayPalAdminNotice {
*/ */
private $settings; 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. * ConnectAdminNotice constructor.
* *
* @param State $state The state. * @param State $state The state.
* @param ContainerInterface $settings The settings. * @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 ) { public function __construct(
$this->state = $state; State $state,
$this->settings = $settings; 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 { protected function should_display(): bool {
return State::STATE_ONBOARDED === $this->state->current_state() 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( 'dcc_enabled' ) && $this->settings->get( 'dcc_enabled' ) )
&& ( ! $this->settings->has( 'enabled' ) || ! $this->settings->get( 'enabled' ) ); && ( ! $this->settings->has( 'enabled' ) || ! $this->settings->get( 'enabled' ) );
} }