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?
It depends where in the flow you need to detect it, for styling purposes, you can see in the body tag of the success page this css class: checkout-onepage-success
If you need to interact with data in the page you could hook to this event: checkout_onepage_controller_success_action
And in Magento2 you also have action/module names and handles that you could use in your php/phtml code:
Magento 2: How to get controller, module, action and router name?
Yes, you can do the same at Magento 2. Get Full action can at your class or file .
Magento 2: getting Full Action name inside custom Model class?
if( $this->request->getFullActionName() === 'checkout_onepage_success){
// then checkout page
}
head
tag , if you will inject \Magento\Framework\App\Request\Http
respective code then you can get full action
I found the code below here
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$request = $objectManager->get('Magento\Framework\App\Action\Context')->getRequest();
if ($request->getFullActionName() == 'checkout_onepage_success') {
//you are on the success page
}