Magento – Display total price and total items in minicart

magento2mini-cart

I have installed magento 2.0.7 and overide the template minicart.phtml to my custom theme. I want to show total price and total items in the header minicart like the below imageenter image description here

Best Answer

Working code for me. Magento 2.2.4

<a class="action showcart" href="<?php /* @escapeNotVerified */ echo $block->getShoppingCartUrl(); ?>"
           data-bind="scope: 'minicart_content'">
        <span class="counter qty empty"
              data-bind="css: { empty: !!getCartParam('summary_count') == false }, blockLoader: isLoading">
            <span class="counter-number">
            <!-- ko ifnot: getCartParam('summary_count') -->
                <!-- ko text: '0' --><!-- /ko -->
            <!-- /ko -->
            <!-- ko if: getCartParam('summary_count') -->
                <!-- ko text: getCartParam('summary_count') --><!-- /ko -->
            <!-- /ko -->
            </span>
            <span class="counter-label">
            <!-- ko if: getCartParam('summary_count') -->
                <!-- ko text: getCartParam('summary_count') --><!-- /ko -->
                <!-- ko i18n: 'items' --><!-- /ko -->
            <!-- /ko -->
            </span>
        </span>

        <span class="text"><?php /* @escapeNotVerified */ echo __('My Cart'); ?></span>

        <span data-bind="html: getCartParam('subtotal')"></span>
            <!-- /ko -->
            <!-- ko if: getCartParam('summary_count') != 1 -->
                <!-- ko text: getCartParam('summary_count') --><!-- /ko -->
                <!-- ko i18n: 'items' --><!-- /ko -->
                <span data-bind="html: getCartParam('subtotal')"></span>
            <!-- /ko -->
        </span>

        </a>
Related Topic