{"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>\n

If 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

\"Get<\/a> Get payment method name in WooCommerce<\/p>\n

Here you can see in the value field the name is “cod” as used in our function code above.<\/p>\n","protected":false},"excerpt":{"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: function we_gateway_disable_shipping( $available_gateways ) { global $woocommerce; if (…<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[4],"tags":[],"class_list":["post-668","post","type-post","status-publish","format-standard","hentry","category-woocommerce"],"_links":{"self":[{"href":"https:\/\/www.welaunch.io\/en\/wp-json\/wp\/v2\/posts\/668","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.welaunch.io\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.welaunch.io\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.welaunch.io\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.welaunch.io\/en\/wp-json\/wp\/v2\/comments?post=668"}],"version-history":[{"count":4,"href":"https:\/\/www.welaunch.io\/en\/wp-json\/wp\/v2\/posts\/668\/revisions"}],"predecessor-version":[{"id":4337,"href":"https:\/\/www.welaunch.io\/en\/wp-json\/wp\/v2\/posts\/668\/revisions\/4337"}],"wp:attachment":[{"href":"https:\/\/www.welaunch.io\/en\/wp-json\/wp\/v2\/media?parent=668"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.welaunch.io\/en\/wp-json\/wp\/v2\/categories?post=668"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.welaunch.io\/en\/wp-json\/wp\/v2\/tags?post=668"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}