We could disable particular payment method on checkout page using following event:
payment_method_is_active
we need to create two files in our extension for the same:
first one is events.xml: and following is the code of events.xml:
<?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="packagename_payment_filter_module" instance="packagename\Modulename\Observer\Observerfilename"/>
</event>
</config>
second one is Observerfilename.php: and following is the code of Observerfilename.php, and we have to put this code inside execute function:
$event = $observer->getEvent();
$code = $event->getMethodInstance()->getCode();
$checkResult = $observer->getEvent()->getResult();
if($code == "cashondelivery") {
$checkResult->setData('is_available', FALSE);
}else {
$checkResult->setData('is_available', TRUE);
}
payment_method_is_active
we need to create two files in our extension for the same:
first one is events.xml: and following is the code of events.xml:
<?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="packagename_payment_filter_module" instance="packagename\Modulename\Observer\Observerfilename"/>
</event>
</config>
second one is Observerfilename.php: and following is the code of Observerfilename.php, and we have to put this code inside execute function:
$event = $observer->getEvent();
$code = $event->getMethodInstance()->getCode();
$checkResult = $observer->getEvent()->getResult();
if($code == "cashondelivery") {
$checkResult->setData('is_available', FALSE);
}else {
$checkResult->setData('is_available', TRUE);
}
Comments
Post a Comment