• Resolved mynetflixtain

    (@mynetflixtain)


    The code below successfully allows me to disable certain payment gateway, but I will like to ask how I can add other countries to the code. Thanks.

    function payment_gateway_disable_country( $available_gateways ) {
    global $woocommerce;
    if ( is_admin() ) return;
    if ( isset( $available_gateways[‘stripe’] ) && $woocommerce->customer->get_billing_country() <> ‘US’ ) {
    unset( $available_gateways[‘stripe’] );
    }
    return $available_gateways;
    }

    add_filter( ‘woocommerce_available_payment_gateways’, ‘payment_gateway_disable_country’ );

Viewing 1 replies (of 1 total)
  • Saif

    (@babylon1999)

    Hello @mynetflixtain,

    The code below successfully allows me to disable certain payment gateway, but I will like to ask how I can add other countries to the code. Thanks.

    I understand you want to include another country other than the US. I assume you can use the “or” operator to include another billing country code.

    In the example below I added Canada (CA), but you can replace it with the other country you want to disable.

    /*  DISABLE STRIPE FOR US AND CA CUSTOMERS  */
    
    function payment_gateway_disable_country( $available_gateways ) {
        global $woocommerce;
        if ( is_admin() ) return;
        $billing_country = $woocommerce->customer->get_billing_country();
        if ( isset( $available_gateways['stripe'] ) && ($billing_country == 'US' || $billing_country == 'CA') ) {
            unset( $available_gateways['stripe'] );
        }
        return $available_gateways;
    }
    add_filter( 'woocommerce_available_payment_gateways', 'payment_gateway_disable_country' );
    

    I should note that custom coding/solutions are not within our scope of support so if you need more help with this please consult a WooExpert.

    If you’re looking for a plugin that allows displaying certain payment methods based on conditional logic, you can check our Conditional Shipping and Payments extension.

    All extensions sold on WooCommerce.com have a 30-day refund policy so if the product doesn’t work the way you need it or you think another product would work better, we are more than happy to provide a full refund.

    Hope this helps!

Viewing 1 replies (of 1 total)
  • The topic ‘Disable payment gateway based on billing address’ is closed to new replies.