Fix WooPayments incentives allowed promo notes logic (#48105)

* Fix WCPay incentive allowed promo notes logic

The WCPay promo notes need to be added to the allowed
list regardless if WCPay is installed and active.
We will respect marketplace suggestions and promo
dismissal settings.

* Added changelog entry
This commit is contained in:
Vlad Olaru 2024-06-04 13:34:11 +03:00 committed by GitHub
parent 7d3309dc6c
commit 54a2466f32
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 15 additions and 6 deletions

View File

@ -0,0 +1,5 @@
Significance: patch
Type: fix
Comment: We fix the WCPay incentives promo notes logic to avoid needless friction in the merchant UX.

View File

@ -52,11 +52,13 @@ class WcPayWelcomePage {
/**
* Whether the WooPayments welcome page should be visible.
*
* @param bool $skip_wcpay_active Whether to skip the check for the WooPayments plugin being active.
*
* @return boolean
*/
public function must_be_visible(): bool {
public function must_be_visible( $skip_wcpay_active = false ): bool {
// The WooPayments plugin must not be active.
if ( $this->is_wcpay_active() ) {
if ( ! $skip_wcpay_active && $this->is_wcpay_active() ) {
return false;
}
@ -174,18 +176,20 @@ class WcPayWelcomePage {
}
/**
* Adds allowed promo notes from the WooPayments incentive.
* Adds allowed promo notes for the WooPayments incentives.
*
* @param array $promo_notes Allowed promo notes.
* @return array
*/
public function allowed_promo_notes( $promo_notes = [] ): array {
// Return early if the incentive must not be visible.
if ( ! $this->must_be_visible() ) {
// Note: We need to disregard if WooPayments is active when adding the promo note to the list of
// allowed promo notes. The AJAX call that adds the promo note happens after WooPayments is installed and activated.
// Return early if the incentive page must not be visible, without checking if WooPayments is active.
if ( ! $this->must_be_visible( true ) ) {
return $promo_notes;
}
// Add our incentive ID to the promo notes.
// Add our incentive ID to the allowed promo notes so it can be added to the store.
$promo_notes[] = $this->get_incentive()['id'];
return $promo_notes;