Disable Payment Method Programmatically In Magento2
In this post we will show you Disable Payment Method Programmatically In Magento2, hear for Disable Payment Method Programmatically In Magento2 we will give you demo and example for implement.
Dynamically Enable/Disable Payment Method in Magento2
we will clarify that how you can incapacitate any installment strategy automatically at checkout page in magento 2 in this article. we have done it by utilizing onlooker. So lets begin with the procedure.
To start with you should make events.xml record under app/code/Company/Module/and so forth/. At that point express “payment_method_is_active” occasion in it. This is the occasion which hits on checkout page for installment technique accessibility.
<?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd"> <event name="payment_method_is_active"> <observer name="custom_payment" instance="Company\Module\Observer\SetPaymentMethodAvailable" /> </event> </config>
Presently make SetPaymentMethodAvailable.php under Company/Module/Observer/ and compose following code in the document. we have handicapping the check cash arrange installment technique, we can change installment strategy code as indicated by your need.
<?php namespace Company\Module\Observer; use Magento\Framework\Event\ObserverInterface; class SetPaymentMethodAvailable implements ObserverInterface { /** * payment_method_is_active event handler. * * @param \Magento\Framework\Event\Observer $observer */ public function execute(\Magento\Framework\Event\Observer $observer) { // we can replace "checkmo" with your required payment method code if($observer->getEvent()->getMethodInstance()->getCode()=="checkmo") { $getcheckResult = $observer->getEvent()->getResult(); $getcheckResult->setData('is_available', false); // this is disabling the payment method at checkout page } } }
Now the payment method Check Money Order is disabled from checkout page.
Hope this code and post will helped you for implement Disable Payment Method Programmatically In Magento2. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve onlincode. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs onlincode.org
thank you this is very helpful