How to Show Custom Popup on click of “Proceed to Checkout” Button From Minicart in Magento 2
The default Magento 2 redirects a customer to the checkout page when the “Proceed to Checkout” button is clicked as shown below:
However, depending on the business requirements, one may want to show popup on the mini cart when “Proceed to checkout” button is clicked in Magento 2.
The popup may show a custom sales message or further instructions or any offer related details on the mini cart that may be important for the business or customer to know at that stage of the purchase cycle.
Here, I have shared the programmatic solution to show custom popup on click of “Proceed to Checkout” button from minicart in Magento 2.
Method to Show Custom Popup on click of “Proceed to Checkout” Button From Minicart in Magento 2:
- Create file requirejs-config.js under app\code\Vendor\Module\view\frontend
123456789var config = {config: {mixins: {'Magento_Checkout/js/view/minicart': {'Vendor_Module/js/checkout/view/minicart': true}}}}; - Create file minicart.js under app\code\Vendor\Module\view\frontend\web\js\checkout\view
12345678910111213141516171819202122232425262728<pre class="lang:default decode:true">define(['jquery','Magento_Customer/js/customer-data'], function ($, customerData) {'use strict';return function (Component) {return Component.extend({/*** @override*/getCartParam: function (name) {var self = this;if (name === 'possible_onepage_checkout') {$('#top-cart-btn-checkout').click(function (event) {var customer = customerData.get('customer');if (!customer().firstname) {event.preventDefault();$('.custom-popup').modal('openModal'); /* Here you can put your message or call your popup */return false;}});}return this._super(name);},});}});</pre> - Run the below commands:
12php bin/magento setup:static-content:deploy -fphp bin/magento cache:flush
That’s it.
Once you implement the above solution, the frontend shows the custom popup as shown below:
If you need more help regarding this post, feel free to ask in the Comment section below.
I would be happy to help you.
Do consider sharing this post with Magento Community via social media.
Thank you.
Sanjay 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.
7 Comments
is there any ways like using events.xml to perform this??
Hey,
No there is no such event for this in Magento.
Hi, thanks for your tutorial. How to do the pop up modal when after filling the address line, reads like your address is not free-shipping available. Thanks
Hello,
Is it possilbe show a image in popup?
Hello Darwin,
Yes, You can put an image in the popup. Add an image in the file from where your content comes from.
Thank You
Failed to load the “Magento_Checkout/js/view/minicart” component.
am getting this error
Kindly provide any solution for this
Hello,
The mistake seems in the requirejs-config.js.
Please check it again and run the deploy command.
Thank you.