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

1 Answer 1


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.

  • 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 Commented May 28, 2019 at 20:07
  • if you count($empty_array) you get 0. If you (bool) count($empty_array) you get boolean value Commented May 28, 2019 at 20:18
  • thank you for this I will check this and update this Commented May 28, 2019 at 20:47

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.