douxuzui4590 2018-05-12 12:11
浏览 53

如何在woocommerce中禁用基于客户IP的付款选项

I have a woocommerce store based in India and also deals with europe and america. So I want to disable payments options based on customer IP. I have enabled two payment options Payumoney(for india) and Paypal(rest of countries). I am using a snippet that disable selected payment option based on billing country.

function payment_gateway_disable_country( $available_gateways ) {global $woocommerce;
if ( isset( $available_gateways['pumcp'] ) && $woocommerce->customer->get_country() <> 'IN' ) {
unset( $available_gateways['pumcp'] );
} else if ( isset( $available_gateways['paypal'] ) && $woocommerce->customer->get_country() == 'IN' ) {
unset( $available_gateways['paypal'] );
}
return $available_gateways;
}

add_filter( 'woocommerce_available_payment_gateways', 'payment_gateway_disable_country' );

Now problem with this snippet is that if someone orders from USA and choose shipping address to India. Then they have to choose PayUmoney as payment option. And now PayUmoney convenience fee for International payment is around 10%. and vice versa. Yes I know that this snippet works with billing address. So customers will their billing address based on USA and shipping address to India. But sometimes customers fill billing address same of shipping address. Then this snippet causes an issue. So I was thinking to switch payment options based on IP.
Thanx in advance.

  • 写回答

1条回答 默认 最新

  • donglao4370 2018-05-12 16:23
    关注

    Ip based country will not solve your problem… instead you should use the customer shipping country instead of billing country. Also using global $woocommerce; with $woocommerce->customer is outdated and has been replaced by WC()->customer.

    So your revisited code will be:

    add_filter( 'woocommerce_available_payment_gateways', 'payment_gateway_disable_country', 20, 1 );
    function payment_gateway_disable_country( $available_gateways ) {
        if ( isset( $available_gateways['pumcp'] ) && WC()->customer->get_shipping_country() <> 'IN' ) {
            unset( $available_gateways['pumcp'] );
        } else if ( isset( $available_gateways['paypal'] ) && WC()->customer->get_country() == 'IN' ) {
            unset( $available_gateways['paypal'] );
        }
        return $available_gateways;
    }
    

    Code goes in function.php file of your active child theme (or active theme). Tested and works. This should solve your problem…

    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度