How to programmatically clear Magento 2 cart, mini cart – This is something very common and often required by the developers. When it comes to custom development in cart / mini cart in magento 2 projects. We need to empty the cart in several circumstances. Some times cart is getting clear but mini cart is not getting clear. Some times cart is getting clear mini cart show some products are in mini cart. Recently i came across such a situation and managed to flush both the cart and mini cart by using below code. I hope this might help some one in future. So i decided to write a mark up on this.
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$cartObject = $objectManager->create('Magento\Checkout\Model\Cart')->truncate();
This code line totally clear Magento 2 cart & mini cart. For more article on how to section.