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?

1 Answer 1


As you didn't post your code, I am not able to help you, but here is the simple method to display a custom message in Magento 2.

function myFunction() {
   require(['jquery','Magento_Customer/js/customer-data'], function($, customerData){
      //your code
     success: function(data)
          var yourmsg = msg+' '+wishlist_link;
          customerData.set('messages', {
               messages: [{
                     type: 'success', //user as per your need
                     text: yourmsg

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.