From 44d260ea9ab792cd5c3b26644c47c87fae243f8a Mon Sep 17 00:00:00 2001 From: Emili Castells Guasch Date: Wed, 1 May 2024 18:09:43 +0200 Subject: [PATCH] Hide credit card gateway on checkout when using Fastlane --- modules/ppcp-axo/src/AxoModule.php | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/modules/ppcp-axo/src/AxoModule.php b/modules/ppcp-axo/src/AxoModule.php index 6680c9fd7..4f224f08b 100644 --- a/modules/ppcp-axo/src/AxoModule.php +++ b/modules/ppcp-axo/src/AxoModule.php @@ -20,6 +20,7 @@ use WooCommerce\PayPalCommerce\Vendor\Dhii\Container\ServiceProvider; use WooCommerce\PayPalCommerce\Vendor\Dhii\Modular\Module\ModuleInterface; use WooCommerce\PayPalCommerce\Vendor\Interop\Container\ServiceProviderInterface; use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface; +use WooCommerce\PayPalCommerce\WcGateway\Gateway\CreditCardGateway; /** * Class AxoModule @@ -77,6 +78,31 @@ class AxoModule implements ModuleInterface { 9 ); + // Hides credit card gateway on checkout when using Fastlane. + add_filter( + 'woocommerce_available_payment_gateways', + /** + * Param types removed to avoid third-party issues. + * + * @psalm-suppress MissingClosureParamType + */ + function ( $methods ) use ( $c ): array { + if ( ! is_array( $methods ) || ! $c->get( 'axo.eligible' ) ) { + return $methods; + } + + if ( + ! is_admin() + && is_user_logged_in() === false + && isset( $methods[ CreditCardGateway::ID ] ) + ) { + unset( $methods[ CreditCardGateway::ID ] ); + } + + return $methods; + } + ); + add_action( 'init', static function () use ( $c, $module ) {