I followed the steps in the below link to disable COD for a particular product.
magento 2 payment methods hide by code.
But I need to show a custom message(some of the items in the cart are not eligible for COD) in the payment section, when COD gets disabled. How can achieve this?