Is it possible to get check if cart has any product been added in. I want to check if a product been added to the cart in a phtml page. If the user click the page I want to show how many product they added in just the quantity If there is nothing show 0

Is this possible


Do you mean any logic to get cart contents. If so this should offer all the explanation you need.


In addition to this you need to add a count.

So count($block->cart->getQuote()->getAllVisibleItems()) for example

If I have misunderstood can you add more detail.

| improve this answer | |
  • I just need to see if the user added anything to the cart. Wouldn’t this return an array? I am trying to check if the user added anything in the cart return true if not return false – Jack Brooks May 28 '19 at 20:07
  • if you count($empty_array) you get 0. If you (bool) count($empty_array) you get boolean value – Dominic Xigen May 28 '19 at 20:18
  • thank you for this I will check this and update this – Jack Brooks May 28 '19 at 20:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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