0

Is there a way to dynamically display content on a page, based on whether there is something in your basket.

i.e Page would display certain block of text IF there is something in the customers basket AND would not display if there is nothing in the customers basket.

2

If you're comfortable with widgets, you can create a widget for this. In your widget block file, you can inject an instance of \Magento\Checkout\Helper\Cart so you can use the helper functions around the cart state.

You can then override the ::_toHtml() method like so:

protected function _toHtml() {
    if (0 === $this->_checkoutCartHelper->getItemsCount()) return ''; //Return nothing if no items
    return parent::_toHtml(); //Return normal content otherwise
}

You can then have whatever content you need in your widget. The bonus of widgets is that they can be edited in the backend of Magento, both in terms of positioning & content.

0

Fixed this. Used a javascript file to just pull and using find function to grab the cart counter number. Then just use show and hide on the content that on want to display dependant on whether the counter is greater than 0 or not.

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.