Useful Snippets

Disable WooCommerce Payment Method for Specific Country

Pinterest LinkedIn Tumblr

This snippet will help you to remove the payment method.

apply_filters( 'woocommerce_available_payment_gateways', $_available_gateways );
add_filter( 'woocommerce_available_payment_gateways', 'amc_remove_payment_method');

function amc_remove_payment_method( $_available_gateways ){

    if( class_exists( 'WooCommerce' ) ) :

        // Get All Payment Methods
        $payments = $_available_gateways;
    
        if ( isset( $payments['paypal'] ) ) :

            if( WC()->customer->get_billing_country() == "FR" ) :
            
                // Remove Paypal Method
                unset($payments['paypal']);

            endif;

        endif;

    // Send Payment Method without Paypal
    return $payments;
    
    endif;

}

Write A Comment