Hide Payment Methods for Shipping Methods in WooCommerce

If you want to hide specific payment methods for selected shipping methods you just need to add a small code snippet into your functions.php file. An example could be if you want to hide the cheque payment for the local shipping method you can use this:

function we_gateway_disable_shipping( $available_gateways ) {
 
    global $woocommerce;
   
    if ( !is_admin() ) {
         
        $chosen_methods = WC()->session->get( 'chosen_shipping_methods' );
         
        $chosen_shipping = $chosen_methods;
         
        if ( isset( $available_gateways ) && 0 === strpos( $chosen_shipping, 'local_pickup' ) ) {
            unset( $available_gateways );
        }
         
    }
     
	return $available_gateways;  
}
add_filter( 'woocommerce_available_payment_gateways', 'we_gateway_disable_shipping' );

If you do not know the name of your WooCommerce Payment method you want to hide you can inspect the checkout page like this:

Get payment method name in WooCommerce Get payment method name in WooCommerce

Here you can see in the value field the name is “cod” as used in our function code above.

Leave a Reply

Your email address will not be published. Required fields are marked *

We use cookies to give you the best online experience. By agreeing you accept the use of cookies in accordance with our cookie policy.

Close Popup
Privacy Settings saved!
Privacy Settings

When you visit any web site, it may store or retrieve information on your browser, mostly in the form of cookies. Control your personal Cookie Services here.

These cookies are necessary for the website to function and cannot be switched off in our systems.

Technical Cookies
In order to use this website we use the following technically required cookies
  • wordpress_test_cookie
  • wordpress_logged_in_
  • wordpress_sec

Decline all Services
Save
Accept all Services