I calling a button proceed to checkout on title page shopping cart. enter image description here enter image description here but when cart empty, button still show. enter image description here how to check if cart empty and hide button proceed to checkout? Please help me!

  • Could you please share topmetod.phtml and toplink.phtml file code in text format in OP
    – Pawan
    Jun 21, 2018 at 4:33

1 Answer 1


You can use the cart helper to check if shopping cart is empty.

protected $cartHelper;

public function __construct(     
        \Magento\Checkout\Helper\Cart $cartHelper
    ) {
        $this->cartHelper = $cartHelper;

and then you can add your logic if the cart is empty

   if ($this->cartHelper->getItemsCount() === 0) {
          //add your logic 
  • I see protected $_cartHelper; in vendor/magento/module-checkout/Block/Cart.php but I try running if ($this->_cartHelper->getItemsCount() === 0){...} body show only div page-title-wrapper and nothing else. :(
    – Linh
    Jun 21, 2018 at 7:30
  • Here $cartHelper is a variable defined for the helper class. you need to check for getItemsCount() function in vendor/magento/module-checkout/Helper/Cart.php $this->cartHelper->getItemsCount() // This will returns your cart count Jun 21, 2018 at 10:03
  • oh. thankyou!. I'm trying other code: if ($block->getItemsCount() != 0) { .................my code..... } and It worked well.
    – Linh
    Jun 27, 2018 at 1:54

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.