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

Get Weekly Updates

Never miss Magento tips, tricks, tutorials, and news.

Thank you for subscribing.

Something went wrong.

5
(based on 18 Reviews)

Sanjay is a co-founder at Meetanshi. He is a Certified Magento Developer who loves creating Magento E-commerce solutions. Owing to his contributions in Magento Forums and posting solutions, he is among the top 50 contributors of the Magento community in 2019. When he is not engrossed with anything related to Magento, he loves to play cricket.

4 comments On How to Disable Payment Method Programmatically in Magento 2

Leave a reply:

Your email address will not be published.