I want to display cart items total to my header cart link.

I have get some reference from https://magento.stackexchange.com/ but not any solution work for me.

Some are works but only it will display on cart page header link. It will display on all pages if cache is display. cart total not showing on other pages header link when cache is enable.

Any one have done this. Please help.


2 Answers 2


You can display cart items sub-total to header minicart link.

Add below code to minicart.phtml to display cart items total

<span data-bind="html: getCartParam('subtotal')"></span>

php bin/magento cache:clean
  • 1
    Thanks. Best answer bro. It also update data after added to cart using ajax. Thanks a lot
    – Asish Hira
    Commented Jun 23, 2017 at 11:27
  • Want to add cart count on product listing page. Please let us know how can we achieve this? Commented Jun 15, 2018 at 13:21
  • Suresh how can we use this method with custom header? Commented Aug 6, 2019 at 6:19
  • its showing Message: getCartParam is not defined, could you please help me out ? Commented Dec 27, 2019 at 9:57

Get total items, total quantity, subtotal and grand total in cart

Please add the following code in your header.phtml file

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$cart = $objectManager->get('\Magento\Checkout\Model\Cart');

echo $totalItems = $cart->getQuote()->getItemsCount();
echo $totalQuantity = $cart->getQuote()->getItemsQty();

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$cart = $objectManager->get('\Magento\Checkout\Model\Cart');

echo $subTotal = $cart->getQuote()->getSubtotal();
echo $grandTotal = $cart->getQuote()->getGrandTotal();
  • This code not working on all other pages when cache is enable. you can see my answer, best solution for that. Commented Dec 14, 2016 at 17:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.