Magento – How to check shopping cart empty magento 2

cartcheckout

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!

Best Answer

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 
   }
Related Topic