How to get cart items total in magento 2

Spread the love

i was working on a ecommerce project based on magento 2.In this project i had a requirement where i need cart count in my header.phtml file.So i simply write below code

but after using this i got a php error. So i searched internet and found a simple and short solution in 1 line code that is below

Magento 2 provides 2 ways to show items count. One shows the number of individual items in the cart, while the other one shows the total count of items in the cart.

Let us say that cart helper is:

When you do:

it will show the number of individual items in the cart.If you want to show total items count, then use:

hope this will help you too.



Leave a Reply

Your email address will not be published. Required fields are marked *