🔥 Just Launched! Werra Premium Template for HyväSee it in Action

How to Redirect Customer Login or Registration Success to Checkout in Magento 2

By Sanjay JethvaUpdated on May 22, 2025 2 min read

Magento 2, by default, offers many features that help store owners to increase conversions. However, sometimes the default Magento 2 lacks functions that might just be helpful for that little push required for customers to convert!

To overcome such limitations, developers can tweak the default features to enhance the user experience, one which I discussed earlier to change the default configuration to redirect customers to the previous page after login in Magento and Magento 2.

Similarly, I have implemented a solution to redirect customer login or registration success to checkout in Magento 2. However, you’ll have to follow the programmatic method to do so.

Also you can redirect customer to custom page after login in Magento 2 as when a customer logs in to your store, it is the prime time when you can redirect their attention to things you want. It is a short time span where you can lure them for engagement or even conversion.

With this solution, the guest visitors who have selected items and added them to cart won’t have to repeat the process after logging in or registering in your store! You can simply take them to the checkout step and encourage them to buy the items already added to the cart.

Steps to Redirect Customer Login or Registration Success to Checkout in Magento 2:

1. Create di.xml file at app/code/Vendor/Extension/etc/ folder

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Magento\Checkout\Model\Session">
        <plugin name="set_redirection_url_if_have_quote" type="Vendor\Extension\Plugin\LoginRedirection" />
    </type>
</config>

2. Create LoginRedirection file at app/code/Vendor/Extension/Plugin/ folder

<?php
namespace Vendor\Extension\Plugin;

class LoginRedirection
{
    protected $storeManager;
    protected $customerSession;

    public function __construct(
        \Magento\Store\Model\StoreManagerInterface $storeManager,
        \Magento\Customer\Model\Session $customerSession
    )
    {
        $this->storeManager = $storeManager;
        $this->customerSession = $customerSession;
    }
    public function afterLoadCustomerQuote(
        \Magento\Checkout\Model\Session $subject,
        $result
    )
    {
        $quote = $subject->getQuote();
        if(count($quote->getAllItems())>0){
            $this->customerSession
                ->setBeforeAuthUrl($this->storeManager->getStore()->getUrl('onepagecheckout/index/index'));
        }
    }
}

That’s it.

Take your newly signed up customers directly to checkout, prompt them to make a purchase, and enjoy sales!

Sanjay Jethva Full Image
Article bySanjay Jethva

Sanjay is the co-founder and CTO of Meetanshi with hands-on expertise with Magento since 2011. He specializes in complex development, integrations, extensions, and customizations. Sanjay is one the top 50 contributor to the Magento community and is recognized by Adobe. His passion for Magento 2 and Shopify solutions has made him a trusted source for businesses seeking to optimize their online stores. He loves sharing technical solutions related to Magento 2 & Shopify.