Skip to content

Instantly share code, notes, and snippets.

@mcnaveen
Created June 6, 2022 17:46
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save mcnaveen/2e936c999a0259b4fe84697fca494335 to your computer and use it in GitHub Desktop.
Hide Payment gateway based on selected country
<?php
add_filter( 'woocommerce_available_payment_gateways', 'mcnaveen_payment_gateway_based_on_country' );
function mcnaveen_payment_gateway_based_on_country( $available_gateways ) {
if ( is_admin() ) return $available_gateways;
if ( WC()->customer->get_billing_country() !== 'IN' ) {
unset( $available_gateways['wc-razorpay'] );
} else {
if ( WC()->customer->get_billing_country() === 'IN' ) {
unset( $available_gateways['stripe'] );
}
}
return $available_gateways;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment