I want to display a custom message on product page after Ajax add to cart success message in list page. Can you suggest anyway?

  • 1
    Can you please explain more what you do actually? 1. Add div after add to cart button 2. Add text message after the success message Commented May 17, 2018 at 8:47
  • I want add custom message in div..after addtocart success message..
    – Mahi M
    Commented May 17, 2018 at 8:49
  • Use this extension. It lets you add custom message to cart, checkout & order success page. You can also use attributes and conditions to display the message. Commented Sep 2, 2019 at 10:44

1 Answer 1


You can use plugin or event/observer to update the success message.


<event name="controller_action_postdispatch_checkout_cart_add">
    <observer name="updatemessage" instance="{Vendor}\{Module}\Observer\UpdateMessage" />

In observer, Use \Magento\Framework\Message\ManagerInterface to get last added message and add new/updated success message.


namespace {Vendor}\{Module}\Observer;

use Magento\Framework\Event\ObserverInterface;
use Magento\Framework\App\RequestInterface;

class UpdateMessage implements ObserverInterface
    /** @var \Magento\Framework\Message\ManagerInterface */
    protected $messageManager;

    /** @var \Magento\Framework\UrlInterface */
    protected $url;

    public function __construct(
        \Magento\Framework\Message\ManagerInterface $managerInterface,
        \Magento\Framework\UrlInterface $url
    ) {
        $this->messageManager = $managerInterface;
        $this->url = $url;

    public function execute(\Magento\Framework\Event\Observer $observer) {
        $messageCollection = $this->messageManager->getMessages(true);
        $customMessage = '<div>Your Message Here</div>';
        $this->messageManager->addSuccess($messageCollection->getLastAddedMessage()->getText() . '  ' . $customMessage);
  • I need this message in list page.(Ajax Addtocart)
    – Mahi M
    Commented May 17, 2018 at 9:07
  • @ManoM please add all the information in your question. Commented May 17, 2018 at 9:08
  • Ok ...I will update....
    – Mahi M
    Commented May 17, 2018 at 9:11
  • @ManoM It's common add to cart event. You can customize on your way in that code. Commented May 17, 2018 at 9: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.