1

I am working on Magento version 2.1.10 and created an observer for event "sales_order_place_after", I need to show custom success message after successful checkout on checkout success page.

following is my current code:

namespace Vendor\Module\Observer;
use Magento\Framework\Event\ObserverInterface;

class Customsuccess implements \Magento\Framework\Event\ObserverInterface
{
    protected $_messageManager;

    public function __construct(\Magento\Framework\Message\ManagerInterface $messageManager )
    {
        $this->_messageManager = $messageManager;
    }

    public function execute(\Magento\Framework\Event\Observer $observer)
    { 
        $this->_messageManager->addSuccessMessage(__('This is a success message'));
    }
}

But I am getting the error on checkout.

0

I think you can override the success page and write your own success messages. Why you creating event.

Go to your current theme

app\design\frontend\Renegade\default\Magento_Checkout\templates\success.phtml

You can changed success message that you want

  • This is OK.. but I have various conditions on which I need to show different custom messages. That is why i am creating event. – Prabhat Mishra May 9 '18 at 12:38
  • You can use various condition on success pages as well – Impunkj May 10 '18 at 4:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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