woocommerce-paypal-payments/modules/ppcp-local-alternative-payment-methods/src/LocalAlternativePaymentMethodsModule.php

58 lines
1.7 KiB
PHP
Raw Normal View History

2024-08-08 12:43:29 +02:00
<?php
/**
* The local alternative payment methods module.
*
* @package WooCommerce\PayPalCommerce\LocalAlternativePaymentMethods
*/
declare(strict_types=1);
namespace WooCommerce\PayPalCommerce\LocalAlternativePaymentMethods;
use Automattic\WooCommerce\Blocks\Payments\PaymentMethodRegistry;
2024-08-08 12:43:29 +02:00
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;
/**
* Class LocalAlternativePaymentMethodsModule
*/
class LocalAlternativePaymentMethodsModule implements ModuleInterface {
/**
* {@inheritDoc}
*/
public function setup(): ServiceProviderInterface {
return new ServiceProvider(
require __DIR__ . '/../services.php',
require __DIR__ . '/../extensions.php'
);
}
/**
* {@inheritDoc}
*/
public function run( ContainerInterface $c ): void {
add_filter(
'woocommerce_available_payment_gateways',
function ( $methods ) use ( $c ) {
$customer_country = WC()->customer->get_billing_country() ?: WC()->customer->get_shipping_country();
$site_currency = get_woocommerce_currency();
if ( $customer_country === 'BE' && $site_currency === 'EUR' ) {
$methods[] = $c->get( 'ppcp-local-apms.bancontact.wc-gateway' );
}
return $methods;
}
);
add_action(
'woocommerce_blocks_payment_method_type_registration',
function( PaymentMethodRegistry $payment_method_registry ) use ( $c ): void {
$payment_method_registry->register( $c->get( 'ppcp-local-apms.bancontact.payment-method' ) );
}
);
2024-08-08 12:43:29 +02:00
}
}