I need to disable COD option from observer, For observer my code is:
public function execute(\Magento\Framework\Event\Observer $observer)
{
$order= $observer->getData('order');
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$quote = $observer->getEvent()->getQuote();
$QuoteData = $quote->getItemsCollection();
$checkResult = $observer->getEvent()->getResult();
foreach($QuoteData as $data) {
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$p = $objectManager->get('Magento\Catalog\Model\Product')->load($data['product_id']);
$attribute = $p->getResource()->getAttribute('cod');
if ($attribute)
{
$attr_value = $attribute ->getFrontend()->getValue($p);
if($attr_value == 'Yes' || $attr_value == 'yes' || $attr_value == 'YES'){ return;
$code = $observer->getEvent()->getMethodInstance()->getCode();
if($code == "cashondelivery" || $code == "mpcashondelivery"){
$checkResult->setData('is_available', false); //this is disabling the payment method at checkout page
}
}
}
}
}
But COD is not disabling if anyone have solution please share.