根据客户位置启用付款方式 [英] Enabling Payment method based on the customers location

查看:89
本文介绍了根据客户位置启用付款方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道是否可能,但是,我们需要为巴塞罗那添加一些不同的付款方式.

I don't know if it's possible, but, we would need to add some different payment methods for Barcelona.

因此,我们的想法是,如果客户居住在巴塞罗那地区(Catalunya),他将看到与西班牙其他地区不同的信用卡付款方式和银行转帐帐户.

So, our idea is that if the customer lives in Barcelona area (Catalunya), he will see a credit card payment method and a bank transfer account different than the rest of Spain.

WooCommerce可以吗?

Is that possible with WooCommerce?

谢谢.

推荐答案

如果您想在WooCommerce中启用此类功能,则需要注册并登录客户>首先,因为这是在结帐流程之前获取城镇位置的唯一方法.

If you want to enable this kind of feature in WooCommerce, Customers need to be registered and logged on first, as it's the only way to get they town location before checkout process.

此外,您还必须更改WooCommerce中的某些设置,仅允许注册用户签出.

Also you will have to change some settings in WooCommerce allowing only registerers users to checkout.

然后,您将必须在注册过程中添加一些必填字段,例如城镇,邮政编码和国家/地区.

Then you will have to add some mandatory fields in the registration process as the town, zip code and country.

一旦完成,基于此注册的客户字段启用/禁用支付网关将变得很容易.

Once that done, it's going to be easy to enable / disable payment gateways based on this registered customer fields.

1)用于自定义注册字段:

1) For customizing the registration fields:
How to add custom fields in user registration on the "My Account" page

2)对于基于此客户信息的支付网关/方法,可以在 woocommerce_available_payment_gateways 过滤器挂钩中使用自定义的挂钩函数:

2) For payment gateways/methods based on this Customer information, You can use a custom hooked function in woocommerce_available_payment_gateways filter hook:

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;
}

此代码仅是示例,您将必须在正确的条件下为目标付款方式/网关设置……

This code is just an example, and you will have to set inside the right conditions for the targeted payment methods/gateways…

代码会出现在您活动的子主题(或主题)的functions.php文件或任何插件文件中.

这篇关于根据客户位置启用付款方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆