skip to Main Content

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[0];
        if ( isset( $available_gateways['cod'] ) && 0 === strpos( $chosen_shipping, 'local_pickup' ) ) {
            unset( $available_gateways['cod'] );
	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.

Daniel Barenkamp

Founder and Creator of WeLaunch (formerly DB-Dzine).

This Post Has 0 Comments

Leave a Reply

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

×Close search