We sacrifice by not doing any other technology, so that you get the best of Magento.

We sacrifice by not doing any other technology, so that you get the best of Magento.

    Display the new message and clear the previous messages on every page using Message Manager.

    Create the event.xml in your module and add the below code

    <?xml version="1.0"?>
    <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
        <event name="layout_render_before">
          <observer name="success_message" instance="VendorModuleObserverMessageObserver" shared="false" />
      </event>
    </config>

    Create the MessageObserver.php file in the Observer directory

    <?php
    namespace VendorModuleObserver;
    
    use MagentoFrameworkEventObserverInterface;
    use MagentoFrameworkEventObserver;
    
    class MessageObserver implements ObserverInterface
    {
        public function __construct(       
            MagentoFrameworkMessageManagerInterface $messageManager,
        )
        {    
            $this->messageManager = $messageManager;   
        }
        public function execute(Observer $observer)
        {
            $this->messageManager->getMessages(true); //this will clear your messageManager container
            $this->messageManager->addSuccess(__('Add Custom message here'));
            return $this;
        }
    }

     

    Fill the below form if you need any Magento relate help/advise/consulting.

    With Only Agency that provides a 24/7 emergency support.

      Get a Free Quote