Administrators Nathan Posted February 24, 2018 Administrators Share Posted February 24, 2018 Quick and easy example of how to disable payment gateways based on the Country in WooCommerce. Currently there isn't an easy way to do this through the WooCommerce settings so you'll need to open up your code editor. Navigate to your theme folder at /wp-content/themes/themename . Hopefully you're using a child theme so jump into that theme's folder and look for your functions.php file. Scroll down to the bottom and drop in this snippet. If you're using WooCommerce 3.0 or newer: function payment_gateway_disable_country( $available_gateways ) { global $woocommerce; if ( is_admin() ) return; if ( isset( $available_gateways['stripe'] ) && $woocommerce->customer->get_billing_country() <> 'US' ) { unset( $available_gateways['stripe'] ); } return $available_gateways; } add_filter( 'woocommerce_available_payment_gateways', 'payment_gateway_disable_country' ); If you're using WooCommerce 2.6 or older: function payment_gateway_disable_country( $available_gateways ) { global $woocommerce; if ( isset( $available_gateways['stripe'] ) && $woocommerce->customer->get_country() <> 'US' ) { unset( $available_gateways['stripe'] ); } return $available_gateways; } add_filter( 'woocommerce_available_payment_gateways', 'payment_gateway_disable_country' ); In this example I'm disabling my Stripe credit card payment gateway if the country is not equal to the United States (US). In doing this anyone outside of the United States (US) when checking out and entering their billing/shipping address will have to pay with my other payment gateway of PayPal. You can enter any of your gateways here to disable by going into your WordPress admin area -> WooCommerce -> Settings -> Checkout and viewing the gatewayID. You can look up the country code here. Once you're ready save your functions.php file and you're all set. View the Prodjex Web Development blog post on how to disable payment gateways based on the Country in WooCommerce. Quote Link to comment Share on other sites More sharing options...
mynetflixtain Posted March 16, 2023 Share Posted March 16, 2023 Hi, does it mean that if stripe is enabled for Us from the code, others payment won't be available for the USA Quote Link to comment Share on other sites More sharing options...
mynetflixtain Posted March 16, 2023 Share Posted March 16, 2023 Hi, please how do I include other countries from that same code, thanks Quote Link to comment Share on other sites More sharing options...
mynetflixtain Posted March 17, 2023 Share Posted March 17, 2023 Hi is any one there Quote Link to comment Share on other sites More sharing options...
Administrators Nathan Posted May 16, 2023 Author Administrators Share Posted May 16, 2023 On 3/16/2023 at 12:05 PM, mynetflixtain said: Hi, does it mean that if stripe is enabled for Us from the code, others payment won't be available for the USA Yes it means the Stripe gateway is only available for USA IP addresses. On 3/16/2023 at 1:24 PM, mynetflixtain said: Hi, please how do I include other countries from that same code, thanks Just include other country codes, you can find them here: https://www.nationsonline.org/oneworld/country_code_list.htm Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.