Magento 2 Disable Checkout Success Page Redirect to Cart

One of the most frustrating pages in Magento to develop is the order confirmation page. There’s nothing too complex about the checkout success page other than the steps it takes to get to it. This gets compounded by you only getting one shot to view it before you have to go through the process again. And if you wanted to view the unmodified source code it’s essentially impossible. If you are working on your Magento order success page design, this quick edit will dramatically decrease your development time!

I was trying to debug a javascript error that only existed on the order confirmation page today. This wasn’t a hard thing to debug, but did require me refreshing the page several times. By (valid) design, Magento redirects you to the cart page however, which drastically slows down development and design time.

There’s a simple hack to keep the order confirmation page from redirecting to the cart page to make this easier. And while it is bad practice to edit core files, this is one instance where I personally suggest doing it (at least on your dev site that is). This is a change I personally feel you do not want to commit live. So if this change gets wipped out – well that’s technically a good thing. Plus I call this a hack for a reason – its hacking the site, not making a modification like our other typical edits are.

Disable Checkout Success Redirect for Magento 2

In the onepage checkout success controller, it checks to see if you have visited the page already. If so, then it redirects you to the cart page. So you simply need to comment out this one line and you’re all set.

And that’s it! Now you can refresh to your hearts content and stay on the checkout success page without being redirected to the cart page.

NOTE: if you attempt to view success page URL directly (https://www.example.com/checkout/onepage/success/) without placing an order with that PHPSESSID you’ll get an error since Magento can’t find an order ID. But as long as you’ve placed an order, refreshing the page works just fine.

For reference – I was working on Magento 2 version 2.4.2 when I wrote this post.

Disable Checkout Success Redirect for Magento 1

To prevent the checkout success page from redirecting to the cart page in Magento 1, use this code edit.