Disable WooCommerce Payment Gateway for Specific Country WordPress

To disable a payment gateway for a specific country in WooCommerce, you will first need to identify the gateway’s slug. Once you have done this, you can use a simple code snippet to achieve your objective. There may be times when you need to disable a payment gateway for a specific country in WooCommerce. For […]

To disable a payment gateway for a specific country in WooCommerce, you will first need to identify the gateway’s slug. Once you have done this, you can use a simple code snippet to achieve your objective.

There may be times when you need to disable a payment gateway for a specific country in WooCommerce. For example, you may only want to offer PayPal as a payment option for customers in the United States but not for customers in other countries.

Now Install plugin or Your theme function.php code.

better now install plugin…..

function.php code
add_filter( 'woocommerce_available_payment_gateways', 'wc_hide_payment_for_countries' );

function wc_hide_payment_for_countries( $payment_gateways ) {
	if ( is_admin() ) return $payment_gateways;

	// Get country
	$customer_country = WC()->customer->get_shipping_country() ? WC()->customer->get_shipping_country() : WC()->customer->get_billing_country();

	// Hide COD for Bangladesh (BD)
	if ( in_array( $customer_country, array( 'BD' ) ) ) {       
		// Hide Cash on delivery for United States
		if ( isset( $payment_gateways['cod'] ) ) {
			unset( $payment_gateways['cod'] );
		}
	} 

	// Hide Bank Transfer and Cheque payments for Singapore (SG) and India (IN)
	if ( in_array( $customer_country, array( 'SG', 'IN' ) ) ) {       
		if ( isset( $payment_gateways['cheque'] ) ) {
			unset( $payment_gateways['cheque'] );
		}
		
		if ( isset( $payment_gateways['bacs'] ) ) {
			unset( $payment_gateways['bacs'] );
		}
	} 
	
	return $payment_gateways;
}
Previous Code

Advanced Custom Fields All Need Code Snippet

Advance custom field Link Field, Flexible content ...

Next Code

How to Create a Dropdown Box to Sorting Posts in WordPress

With Search by Category:custom-sort-form.php Witho ...

Leave a Reply

Your email address will not be published. Required fields are marked *

If you find it useful

buymeacoffee

ACF

Blog

Elementor

HTML JQuery

PHP

WordPress

Ban Email Addresses Or Domains Name in Fluent Forms Form Submission

Ban Email Domains (Ban Particular Domains) in Flue ...

How to Create a Dropdown Box to Sorting Posts in WordPress

With Search by Category:custom-sort-form.php Witho ...

Create a new WordPress Administrator User via functions.php & FTP Code

Can not delete User/admin/manager Change your Need ...

top