Since the era of e-commerce has started, developers are working hard to make CMS smarter and flexible with their coding capabilities. We developers are born to save time and efforts of end users by playing with codes and numbers. Also, day by day store owners become demanding to add new tons of functionality to improvise their store and stay ahead of the competition.

CHECK OUT: Magento 2 Save Cart Pro Extension for your store.

Recently while working on one of customers store, we came across the requirement of clearing shopping cart programmatically. Well, it is possible to clear the cart using three different ways which are mentioned below. Working with Magento several times you came across such a situation that’s why we thought of creating an article on Magecomp blog.

1. First method :
Create “Clearcart.php” file using following code at below location inside your custom extension folder.

2. Second Method :
In this method, we can get the current cart using model cart object and then simply truncate it.

3. Third Method :
In this last method, we can delete item from cart Modal using below code.

From give three methods, you can pick any one according to your need and choice.
Lastly, Comment down below if you face an issue while using this code.
Happy Cart Cleaning!

Click to rate this post!
[Total: 30 Average: 3.9]