Php 启用基于客户位置的付款方式
我不知道这是否可能,但是,我们需要为巴塞罗那增加一些不同的付款方式 因此,我们的想法是,如果客户居住在巴塞罗那地区(加泰罗尼亚),他将看到一种不同于西班牙其他地区的信用卡支付方式和银行转账账户 这在商业上可能吗Php 启用基于客户位置的付款方式,php,wordpress,woocommerce,checkout,user-data,Php,Wordpress,Woocommerce,Checkout,User Data,我不知道这是否可能,但是,我们需要为巴塞罗那增加一些不同的付款方式 因此,我们的想法是,如果客户居住在巴塞罗那地区(加泰罗尼亚),他将看到一种不同于西班牙其他地区的信用卡支付方式和银行转账账户 这在商业上可能吗 谢谢。如果您想在WooCommerce中启用此类功能,客户需要先注册并登录,,因为这是在结帐前获取他们所在城镇位置的唯一方法 此外,您还必须更改WooCommerce中的某些设置,这些设置只允许注册用户结账 然后,您必须在注册过程中添加一些必填字段,如城镇、邮政编码和国家 一旦完成,就可
谢谢。如果您想在WooCommerce中启用此类功能,客户需要先注册并登录,,因为这是在结帐前获取他们所在城镇位置的唯一方法 此外,您还必须更改WooCommerce中的某些设置,这些设置只允许注册用户结账 然后,您必须在注册过程中添加一些必填字段,如城镇、邮政编码和国家 一旦完成,就可以很容易地基于此注册客户字段启用/禁用支付网关 1) 用于自定义注册字段:
2) 对于基于此客户信息的支付网关/方法,您可以使用
woocommerce\u可用的\u支付网关中的自定义挂钩功能
过滤挂钩:
add_filter( 'woocommerce_available_payment_gateways', 'custom_payment_gateways_process' );
function custom_payment_gateways_process( $available_gateways ) {
// Not in backend (admin)
if( is_admin() )
return $available_gateways;
if ( is_admin() || !is_user_logged_in() )
return $available_gateways;
$current_user_id = get_current_user_id();
$user_meta = get_user_meta( $current_user_id );
// User City, Postcode, State and Country code
$user_city = $user_meta['billing_city'];
$user_postcode = $user_meta['shipping_postcode'];
$user_State = $user_meta['shipping_state'];
$user_country = $user_meta['shipping_country'];
// Disable Cash on delivery ('cod') method example for customer out of spain:
if ( isset( $available_gateways['cod'] ) && $user_country != 'ES' ) {
unset( $available_gateways['cod'] );
}
// You can set many conditions based on the user data
return $available_gateways;
}
此代码只是一个示例,您必须为目标支付方法/网关设置正确的条件
代码位于活动子主题(或主题)的functions.php文件或任何插件文件中 有一个,;
$current\u user\u id=get\u current\u user\u id()
上缺少一行,该行应为注释“禁用货到付款…”。但是我不能编辑这篇文章,因为它少于6个字符。