{"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":"<p>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<pre>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()-&gt;session-&gt;get( 'chosen_shipping_methods' );\r\n         \r\n        $chosen_shipping = $chosen_methods;\r\n         \r\n        if ( isset( $available_gateways ) &amp;&amp; 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<p>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<p><a href=\"https:\/\/www.welaunch.io\/en\/wp-content\/uploads\/sites\/4\/2018\/11\/Get-payment-method-name-in-WooCommerce.png\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-669 size-full\" src=\"https:\/\/www.welaunch.io\/en\/wp-content\/uploads\/sites\/4\/2018\/11\/Get-payment-method-name-in-WooCommerce.png\" alt=\"Get payment method name in WooCommerce\" width=\"1013\" height=\"88\" srcset=\"https:\/\/www.welaunch.io\/en\/wp-content\/uploads\/sites\/8\/2018\/11\/Get-payment-method-name-in-WooCommerce.png 1013w, https:\/\/www.welaunch.io\/en\/wp-content\/uploads\/sites\/8\/2018\/11\/Get-payment-method-name-in-WooCommerce-247x21.png 247w, https:\/\/www.welaunch.io\/en\/wp-content\/uploads\/sites\/8\/2018\/11\/Get-payment-method-name-in-WooCommerce-510x44.png 510w, https:\/\/www.welaunch.io\/en\/wp-content\/uploads\/sites\/8\/2018\/11\/Get-payment-method-name-in-WooCommerce-300x26.png 300w, https:\/\/www.welaunch.io\/en\/wp-content\/uploads\/sites\/8\/2018\/11\/Get-payment-method-name-in-WooCommerce-768x67.png 768w\" sizes=\"auto, (max-width: 1013px) 100vw, 1013px\" \/><\/a> Get payment method name in WooCommerce<\/p>\n<p>Here you can see in the value field the name is &#8220;cod&#8221; as used in our function code above.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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 (&#8230;<\/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}]}}