php - Cannot unset payment gateway woocommerce

I am trying to dynamically set payment gateways. I have tried researching and a couple plugins for role based gateways but nothing has worked.
The following code proves that 'cod' is an available payment method as it disables stripe successfully
function set_payment_gateways($gateways) {
if(isset($gateways['cod'])) {
unset($gateways['stripe']);
}
return $gateways;
}
add_filter('woocommerce_available_payment_gateways', 'set_payment_gateways');
However when changing the unset method to disable 'cod':
if(isset($gateways['cod'])) {
unset($gateways['cod']);
}
The payment gateways make no change.
The exact same problem is happening with paypal's gateway
Has anyone run into a similar issue? I would appreciate any help, Thanks
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: an exception occurred in the driver: could not find driver
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.