Show or hide bancontact in checkout page based on country and currency

This commit is contained in:
Emili Castells Guasch 2024-08-19 15:47:38 +02:00
parent 83424f1110
commit 4879425e1d

View file

@ -36,16 +36,27 @@ class LocalAlternativePaymentMethodsModule implements ModuleInterface {
*/ */
public function run( ContainerInterface $c ): void { public function run( ContainerInterface $c ): void {
add_filter( add_filter(
'woocommerce_available_payment_gateways', 'woocommerce_payment_gateways',
function ( $methods ) use ( $c ) { function ( $methods ) use ( $c ) {
if ( is_admin() ) { if ( is_admin() ) {
$methods[] = $c->get( 'ppcp-local-apms.bancontact.wc-gateway' );
return $methods; return $methods;
} }
$customer_country = WC()->customer->get_billing_country() ?: WC()->customer->get_shipping_country(); return $methods;
$site_currency = get_woocommerce_currency(); }
if ( $customer_country === 'BE' && $site_currency === 'EUR' ) { );
$methods[ BancontactGateway::ID ] = $c->get( 'ppcp-local-apms.bancontact.wc-gateway' );
add_filter(
'woocommerce_available_payment_gateways',
function ( $methods ) use ( $c ) {
if ( ! is_admin() ) {
$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[ BancontactGateway::ID ] = $c->get( 'ppcp-local-apms.bancontact.wc-gateway' );
return $methods;
}
} }
return $methods; return $methods;