How to Disable Payment Method Programmatically in Magento 2

How to Disable Payment Method Programmatically in Magento 2

Successful E-commerce store owners have learned the criticality of offering and managing various payment methods at checkout. In the process of providing numerous payment methods, the business ends up messing with the management or incur a loss due to offering such facilities. There should be a balance between maintaining user experience and offering payment methods that do not load the management or be too costly for the store.

The best way to gain this perfect balance is to disable payment method programmatically in Magento 2 on the checkout page. The payment methods can be disabled based on customer groups or for specific products. For example, keep the priority of providing excellent user experience to VIP customers whereas don’t waste your bucks in offering payment facilities to guest customers!

Also, you may want to restrict payment methods based on product or order attributes. For all these above conditions and more, I’ve come up with a method to disable payment method programmatically in Magento 2. The code can be customized to disable payment methods as per the conditions like customer groups, products, etc.

With this method, the payment method won’t be displayed in the frontend.

 

Method to disable payment method programmatically in Magento 2:

    1. Create events.xml at app/code/Vendor/Extension/etc/
    2. Create PaymentMethodAvailable.php at  app/code/Vendor/Extension/Observer/ 

 

With the above code, impose all the restrictions you want in the payment methods in Magento 2 store.

You can always post any doubts about the method in the comments section below. I’d be happy to help 🙂

If you want to skip the tedious implementation process, try Magento 2 Payment Restrictions extension offering similar functionality!

Please rate the post with 5 stars if found useful!

 

CTA_M2-Payment-Restrictions

5
(based on 14 Reviews)

Sanjay is a co-founder at Meetanshi. He is a certified Magento developer who loves creating Magento E-commerce solutions. When he is not engrossed with anything related to Magento, he loves to play cricket.

Leave a Reply