Disable payment gateways based on user country geo-ip in Woocommerce

后端 未结 3 2049
被撕碎了的回忆
被撕碎了的回忆 2020-12-20 08:25

In my Woocommerce shop I set up the geolocation system, when geolocation identifies any country other than IT I would like to disable payment methods

If it is IT (ge

3条回答
  •  一向
    一向 (楼主)
    2020-12-20 09:24

    I know Istack, as well as maxmind etc .. I thought something simpler like this function, which is based on the blling_country and not on the geo-ip country:

    function payment_gateway_disable_country( $available_gateways ) {
    global $woocommerce;
    if ( is_admin() ) return;
    if ( isset( $available_gateways['authorize'] ) && $woocommerce->customer->get_billing_country() <> 'US' ) {
    unset( $available_gateways['authorize'] );
    } else if ( isset( $available_gateways['paypal'] ) && $woocommerce->customer->get_billing_country() == 'US' ) {
    unset( $available_gateways['paypal'] );
    }
    return $available_gateways;
    }
    
    add_filter( 'woocommerce_available_payment_gateways', 'payment_gateway_disable_country' );
    

提交回复
热议问题