ool { // First, try to use the transient value. $transient = get_transient( self::TRANSIENT_HAS_PROVIDERS_WITH_INCENTIVE_KEY ); if ( false !== $transient ) { return filter_var( $transient, FILTER_VALIDATE_BOOLEAN ); } try { $providers = $this->payments->get_payment_providers( $this->payments->get_country(), false ); } catch ( Throwable $e ) { // Catch everything since we don't want to break all the WP admin pages. // Log so we can investigate. SafeGlobalFunctionProxy::wc_get_logger()->error( 'Failed to get payment providers: ' . $e->getMessage(), array( 'source' => 'settings-payments', ) ); // In case of an error, default to false. // Set the transient to avoid repeated errors. set_transient( self::TRANSIENT_HAS_PROVIDERS_WITH_INCENTIVE_KEY, 'no', HOUR_IN_SECONDS ); return false; } $has_providers_with_incentive = false; // Go through the providers and check if any of them have a "prominently" visible incentive (i.e., modal or banner). foreach ( $providers as $provider ) { if ( empty( $provider['_incentive'] ) ) { continue; } $dismissals = $provider['_incentive']['_dismissals'] ?? array(); // If there are no dismissals at all, the incentive is prominently visible. if ( empty( $dismissals ) ) { $has_providers_with_incentive = true; break; } // First, we check to see if the incentive was dismissed in the banner context. // The banner context has the lowest priority, so if it was dismissed, we don't need to check the modal context. // If the banner is dismissed, there is no prominent incentive. $is_dismissed_banner = ! empty( array_filter( $dismissals, function ( $dismissal ) { return isset( $dismissal['context'] ) && 'wc_settings_payments__banner' === $dismissal['context']; } ) ); if ( $is_dismissed_banner ) { continue; } // In case an incentive uses the modal surface also (like the WooPayments Switch incentive), // we rely on the fact that the modal falls back to the banner, once dismissed, after 30 days. // @see here's its frontend "brother" in client/admin/client/settings-payments/settings-payments-main.tsx. $is_dismissed_modal = ! empty( array_filter( $dismissals, function ( $dismissal ) { return isset( $dismissal['context'] ) && 'wc_settings_payments__modal' === $dismissal['context']; } ) ); // If there are no modal dismissals, the incentive is still visible. if ( ! $is_dismissed_modal ) { $has_providers_with_incentive = true; break; } $is_dismissed_modal_more_than_30_days_ago = ! empty( array_filter( $dismissals, function ( $dismissal ) { return isset( $dismissal['context'], $dismissal['timestamp'] ) && 'wc_settings_payments__modal' === $dismissal['context'] && $dismissal['timestamp'] < strtotime( '-30 days' ); } ) ); // If the modal was dismissed less than 30 days ago, there is no prominent incentive (aka the banner is not shown). if ( ! $is_dismissed_modal_more_than_30_days_ago ) { continue; } // The modal was dismissed more than 30 days ago, so the banner is visible. $has_providers_with_incentive = true; break; } // Save the value in a transient to avoid unnecessary processing throughout the WP admin. // Incentives don't change frequently, so it is safe to cache the value for 1 hour. set_transient( self::TRANSIENT_HAS_PROVIDERS_WITH_INCENTIVE_KEY, $has_providers_with_incentive ? 'yes' : 'no', HOUR_IN_SECONDS ); return $has_providers_with_incentive; } /** * Check if the WooPayments account is onboarded. * * @return boolean */ private function is_woopayments_account_onboarded(): bool { // Sanity check: the WooPayments extension must be active. if ( ! class_exists( '\WC_Payments' ) ) { return false; } $account_data = get_option( 'wcpay_account_data', array() ); // The account ID must be present. if ( empty( $account_data['data']['account_id'] ) ) { return false; } // We consider the store to have an onboarded WooPayments account if account data in the WooPayments account cache // contains a details_submitted = true entry. This implies that WooPayments is also connected. if ( empty( $account_data['data']['details_submitted'] ) ) { return false; } return filter_var( $account_data['data']['details_submitted'], FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE ) ?? false; } }