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.

1 Answer 1

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

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

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.