Disable all payment gateways except BACS based on geo-ip country in Woocommerce(禁用WooCommerce中除基于Geo-IP国家/地区的BAC之外的所有支付网关)
本文介绍了禁用WooCommerce中除基于Geo-IP国家/地区的BAC之外的所有支付网关的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在WooCommerce中,我使用的代码来自this answer thread,如果用户的GEO IP来自一组允许的国家/地区,则启用所有支付网关。此处我需要的允许国家/地区代码是"SE"(瑞典)。
我想要的是,如果GEO IP不在瑞典(预定义的允许国家/地区),则禁用除BAC之外的所有支付网关。
感谢任何帮助。
推荐答案
以下代码将禁用除不允许的GEO IP定义的国家/地区(此处为瑞典)的所有可用支付网关:
// Disabling payment gateways (except BACS) based on user IP geolocation country
add_filter( 'woocommerce_available_payment_gateways', 'geo_country_based_available_payment_gateways', 90, 1 );
function geo_country_based_available_payment_gateways( $available_gateways ) {
// Not in backend (admin)
if( is_admin() )
return $available_gateways;
// ==> HERE define your country codes
$allowed_country_codes = array('SE');
// Get an instance of the WC_Geolocation object class
$geolocation_instance = new WC_Geolocation();
// Get user IP
$user_ip_address = $geolocation_instance->get_ip_address();
// Get geolocated user IP country code.
$user_geolocation = $geolocation_instance->geolocate_ip( $user_ip_address );
// Disable payment gateways (except BACS) for all countries except the allowed defined countries
if ( ! in_array( $user_geolocation['country'], $allowed_country_codes ) ){
$bacs_gateways = $available_gateways['bacs'];
$available_gateways = array();
$available_gateways['bacs'] = $bacs_gateways;
}
return $available_gateways;
}
代码放在活动子主题(或活动主题)的函数.php文件中。已测试并正常工作。
相关:Disable payment gateways based on user country geo-ip in Woocommerce
这篇关于禁用WooCommerce中除基于Geo-IP国家/地区的BAC之外的所有支付网关的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
织梦狗教程
本文标题为:禁用WooCommerce中除基于Geo-IP国家/地区的BAC之外的所有支付网关
基础教程推荐
猜你喜欢
- 在PHP中根据W3C规范Unicode 2022-01-01
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- PHP 类:全局变量作为类中的属性 2021-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
- 如何替换eregi() 2022-01-01
