Magento 2 - Go directly to the checkout page when adding a product to the cart

Magento 2 - Go directly to the checkout page when adding a product to the cart

July 8, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Magento 2 - Go directly to the checkout page when adding a product to the cart

Go Directly to Checkout Page When Adding a Product to Cart in Magento 2

[This post originally appeared on https://laravelcompany.com/blog/magento-direct-checkout-add-cart and is reprinted here with permission. The content has been slightly modified for this platform.]

One common request from clients is to allow users to bypass the cart page and go directly to checkout when adding a product to their cart in Magento 2. While Magento provides built-in functionality, it requires multiple clicks by default.

To achieve this, you can utilize observers and events in your custom extension. Here’s a step-by-step guide to implementing direct checkout after adding a product:

Prerequisites:

  1. You have already created an extension for Magento 2.
  2. The extension is activated in the Magento admin panel.

Step 1: Define the Event

Open the etc/frontend/events.xml file inside your module’s directory and add the following code to define the event that will trigger when a product is added to the cart:

<?xml version="1.0" encoding="utf-8"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
    <event name="checkout_cart_add_product_complete">
        <observer
            name="mycompany_go_to_checkout"
            instance="MyCompany\GoToCheckout\Observer\GoToCheckout"/>
    </event>
</config>

Replace mycompany with your actual module’s name.

Step 2: Create the Observer

Create a new file named GoToCheckout.php inside the Observer folder of your module. This file will contain the observer that handles the event defined above:

namespace MyCompany\GoToCheckout\Observer;

use Magento\Framework\Event\Observer;
use Magento\Framework\Event\ObserverInterface;

class GoToCheckout implements ObserverInterface
{
    protected $_url;

    public function execute(Observer $observer)
    {
        $urlInterface = \Magento\Framework\App\ObjectManager::getInstance()->get('Magento\Framework\UrlInterface');
        $url = $urlInterface->getUrl('checkout');
        $observer->getControllerAction()->getResponse()->setRedirect($url);
    }
}

In the execute method, we get an instance of \Magento\Framework\UrlInterface and retrieve the URL for the checkout page. We then set this as a redirect for the current response.

Step 3: Clear Cache

After updating your files, clear the cache in Magento:

php bin/magento cache:flush

Now when you add a product to the cart from the frontend and click “Add to Cart”, you will be redirected directly to the checkout page instead of going through the cart.

This approach allows for a smoother user experience by reducing the number of clicks required during the purchasing process. Remember to always test your changes thoroughly before deploying them to a live environment.

If you found this guide helpful, please share it with others in the Magento community and feel free to explore more advanced customization possibilities at https://laravelcompany.com/blog/magento-customizations. Happy coding!

Magento 2 Checkout Catalog Security

Our network