Skip to content
Advertisement

Detect Success Page on Magento 2

Is there a way to check if am I on Success page on Magento 2?

I know in Magento 1 we can check and compare the action name, for example. But in Magento 2, there is something similar?

Advertisement

Answer

One way would be via URL.

In your Class use this in construct:

public function __construct(
        // ...
        MagentoFrameworkUrlInterface $urlInterface,    
        // ...
    )
    {        
        //...
        $this->_urlInterface = $urlInterface;
        // ...
    }

With $this->_urlInterface->getCurrentUrl() you get the current url, so you can check against your checkout success url.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement