In this post I am going to explain how to disable payment method programmatically in magento 2.

First, We need to write the “payment_method_is_active” event, which checks on checkout for payment method availability.

So, we are going to create event.xml file on below path.

Path: app/code/Ht/Mymodule/etc/

Next to that, we are going to create observer PaymentMethodAvailable.php on below path.

Path: app/code/Ht/Mymodule/Observer/

Here I have given you the example to disable the check and money order payment method, you can change payment method code as per your requirement.

 

Related Read:  How to Create a New CMS Block in Magento 2

Thats it. Enjoy Magento 2!!