{"id":668,"date":"2018-11-12T11:09:27","date_gmt":"2018-11-12T10:09:27","guid":{"rendered":"https:\/\/www.welaunch.io\/en\/?p=668"},"modified":"2020-06-20T12:28:40","modified_gmt":"2020-06-20T10:28:40","slug":"hide-payment-methods-specific-shipping-methods-woocommerce","status":"publish","type":"post","link":"https:\/\/www.welaunch.io\/en\/2018\/11\/hide-payment-methods-specific-shipping-methods-woocommerce\/","title":{"rendered":"Hide Payment Methods for Shipping Methods in WooCommerce"},"content":{"rendered":"
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:<\/p>\n
function we_gateway_disable_shipping( $available_gateways ) {\r\n \r\n global $woocommerce;\r\n \r\n if ( !is_admin() ) {\r\n \r\n $chosen_methods = WC()->session->get( 'chosen_shipping_methods' );\r\n \r\n $chosen_shipping = $chosen_methods;\r\n \r\n if ( isset( $available_gateways ) && 0 === strpos( $chosen_shipping, 'local_pickup' ) ) {\r\n unset( $available_gateways );\r\n }\r\n \r\n }\r\n \r\n\treturn $available_gateways; \r\n}\r\nadd_filter( 'woocommerce_available_payment_gateways', 'we_gateway_disable_shipping' );\r\n<\/pre>\nIf you do not know the name of your WooCommerce Payment method you want to hide you can inspect the checkout page like this:<\/p>\n