Do not show add PayPal payment method on subscription change payment

This commit is contained in:
Emili Castells Guasch 2024-01-16 11:56:12 +01:00
parent a979ec28ff
commit 184bfb2eee

View file

@ -159,10 +159,7 @@ class WcSubscriptionsModule implements ModuleInterface {
add_filter(
'woocommerce_available_payment_gateways',
function( array $methods ) use ( $c ) : array {
if (
! is_wc_endpoint_url( 'order-pay' )
|| $c->has( 'save-payment-methods.eligible' ) && $c->get( 'save-payment-methods.eligible' )
) {
if ( ! is_wc_endpoint_url( 'order-pay' ) ) {
return $methods;
}
@ -171,6 +168,10 @@ class WcSubscriptionsModule implements ModuleInterface {
unset( $methods[ PayPalGateway::ID ] );
}
if ( $c->has( 'save-payment-methods.eligible' ) && $c->get( 'save-payment-methods.eligible' ) ) {
return $methods;
}
$card_tokens = WC_Payment_Tokens::get_customer_tokens( get_current_user_id(), CreditCardGateway::ID );
if ( ! $card_tokens ) {
unset( $methods[ CreditCardGateway::ID ] );