I need Cash On Delivery payment method when the customer selects a Store Pick up Shipping method during the checkout process. You can do this using “payment_method_is_active“ event:
Create an events.xml file at:
/app/code/Vendor/Modulename/etc/. Add the following code in this file:
<?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="codpaymentdisableregion" instance="VendorModulenameObserverPaymentactive" />
</event>
</config>
And create Paymentactive.php file at
Vendor/ModuelName/Observer/path. Add the following code in this file:
<?php
namespace VendorModuelNameObserver;
use MagentoFrameworkEventObserverInterface;
class Paymentactive implements ObserverInterface
{
protected $_checkoutSession;
public function __construct(MagentoCheckoutModelSession $checkoutSession) {
$this->_checkoutSession = $checkoutSession;
}
public function execute(MagentoFrameworkEventObserver $observer) {
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$_session = $objectManager->get('MagentoCheckoutModelSession');
$method = $observer->getEvent()->getMethodInstance();
$result = $observer->getEvent()->getResult();
$shippingMethod = $_session->getQuote()->getShippingAddress()->getShippingMethod();
if($_session->getQuote()->getShippingAddress()->getShippingMethod()=='storepickup_storepickup' && $method->getCode()=="cashondelivery")
{
return $result->setData('is_available', true);
}
if(strpos($shippingMethod,'ups_') !== false && $method->getCode()=="paypal_express")
{
return $result->setData('is_available', true);
}
return $result->setData('is_available', false);
}
}
You need to replace “storepickup_storepickup” with your shipping code and “cashondelivery” or “ paypal_express” with your payment method code.

