I want to disable a specific payment method on the checkout page based on some criteria.
I use the "get_shipping_info" event in the di.xml and make in the "afterSaveAddressInformation" function a customer check and want to disable some payment methods based on the check result.
I have no idea how I can disable a specific payment method.
I tried it with:
\Magento\Framework\App\Config\ScopeConfigInterface $this->payment
$payment_methods = $this->payment->getValue("payment");
foreach ($payment_methods as $method) {
if($method['code'] == "checkmo")
$method->setData("is_available", false);
}
But with this I get only an array with all available payment methods.