Skip to content

Instantly share code, notes, and snippets.

@CmdrMahesh
Created February 26, 2022 04:56
Show Gist options
  • Save CmdrMahesh/9a892f1eaf5e91f5ab119c8fa49a3973 to your computer and use it in GitHub Desktop.
Save CmdrMahesh/9a892f1eaf5e91f5ab119c8fa49a3973 to your computer and use it in GitHub Desktop.
<?php
/**
* Plugin Name: Conditional Payment Gateway
* Description: Conditional Payment Gateway
* Version: 1.0
*/
defined( 'ABSPATH' ) || exit;
add_action( 'plugins_loaded',function(){
add_filter( 'woocommerce_available_payment_gateways', function($available_gateways) {
if ( is_admin() ) return $available_gateways;
if ( isset( $available_gateways['bacs'] ) && WC()->customer->get_billing_country() <> 'IN' ) {
unset( $available_gateways['bacs'] );
} elseif ( isset( $available_gateways['wc-upi'] ) && WC()->customer->get_billing_country() <> 'IN' ) {
unset( $available_gateways['wc-upi'] );
} else {
if ( isset( $available_gateways['ppec_paypal'] ) && WC()->customer->get_billing_country() == 'IN' ) {
unset( $available_gateways['ppec_paypal'] );
}
}
return $available_gateways;
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment