If you do not have the facility to take payments other than cash for in-person shipping methods like local pickup, you may wish to disable the appropriate payment gateways and force the customer to pay by cash for example. This quick guide shows you how to do exactly that.
/*
* Snippet Name: Payment gateway dependent shipping methods
* Snippet Author: ecommercehints.com
*/
add_filter('woocommerce_available_payment_gateways', 'ecommercehints_payment_dependent_delivery');
function ecommercehints_payment_dependent_delivery($gateways) {
if(is_admin()) {
return $gateways;
}
if(is_wc_endpoint_url('order-pay')) {
$order = wc_get_order(wc_get_order_id_by_order_key($_GET['key']));
if($order->has_shipping_method('local_pickup')) {
if(isset($gateways['cheque'])) { // Cheque payments will be disabled
unset($gateways['cheque']);
}
}
} else {
$chosen_shipping_method = WC()->session->get('chosen_shipping_methods')[0];
if ('local_pickup:2' === $chosen_shipping_method) { //shipping method radio button value
if(isset($gateways['cheque'])) {
unset($gateways['cheque']);
}
}
}
return $gateways;
}
How Do I get The Payment Gateway Radio Button Value?
Use your browser dev tools to inspect the element. You are looking for the radio button’s value

How Do I get the shipping method radio button value?
Again, use your browser dev tools to inspect the element. You are looking for the radio button’s value
