Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Hide Payment Method in Woocommerce based on Postal Code

In this woocommerce setup, I have 2 Payment methods, Paypal and Cash on Delivery.

Now how can Cash on Delivery be hidden/disabled for certain Postal codes only.

This is the code I found on Gist

//  Disable gateway based on country
function payment_gateway_disable_country( $available_gateways ) {
    global $woocommerce;
    if ( isset( $available_gateways['ccavenue'] ) && $woocommerce->customer->get_country() <> 'IN' ) {
        unset(  $available_gateways['ccavenue'] );
    } 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' );

Gist Link

like image 544
Nikhil Avatar asked Jun 09 '13 23:06

Nikhil


1 Answers

To disable/hidden "Cash on Delivery", Place this code in your theme's function.php .

For more detail: woocommerce-hide-payment-gatway-based-on-visitors-country

//  Disable gateway based on country
function payment_gateway_disable_country( $available_gateways ) {
global $woocommerce;
if ( isset( $available_gateways['cod'] ) && $woocommerce->customer->get_country() <> 'IN' ) {
    unset(  $available_gateways['cod'] );
}
return $available_gateways;
}
add_filter( 'woocommerce_available_payment_gateways', 'payment_gateway_disable_country' );
like image 56
Denish Avatar answered Dec 14 '22 14:12

Denish