Improve WooPayments task complete logic
This commit is contained in:
parent
c5b12efcf1
commit
17b85b761d
|
@ -105,7 +105,9 @@ class WooCommercePayments extends Task {
|
|||
*/
|
||||
public function is_complete() {
|
||||
if ( null === $this->is_complete_result ) {
|
||||
$this->is_complete_result = self::is_connected() && ! self::is_account_partially_onboarded();
|
||||
// This task is complete if there are other ecommerce gateways enabled (offline payment methods are excluded),
|
||||
// or if WooPayments is active and has a connected, fully onboarded account.
|
||||
$this->is_complete_result = self::has_other_ecommerce_gateways() || ( self::is_connected() && ! self::is_account_partially_onboarded() );
|
||||
}
|
||||
|
||||
return $this->is_complete_result;
|
||||
|
@ -216,4 +218,26 @@ class WooCommercePayments extends Task {
|
|||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the store has any enabled ecommerce gateways, other than WooPayments.
|
||||
*
|
||||
* We exclude offline payment methods from this check.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function has_other_ecommerce_gateways(): bool {
|
||||
$gateways = WC()->payment_gateways->get_available_payment_gateways();
|
||||
$enabled_gateways = array_filter(
|
||||
$gateways,
|
||||
function( $gateway ) {
|
||||
// Filter out any WooPayments-related or offline gateways.
|
||||
return 'yes' === $gateway->enabled
|
||||
&& 0 !== strpos( $gateway->id, 'woocommerce_payments' )
|
||||
&& ! in_array( $gateway->id, array( 'bacs', 'cheque', 'cod' ), true );
|
||||
}
|
||||
);
|
||||
|
||||
return ! empty( $enabled_gateways );
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue