D
D
Denchik2019-08-21 13:23:34
WordPress
Denchik, 2019-08-21 13:23:34

How to display the number of items in the cart on the wp-megamenu icon?

How to display the number of items in the cart on the wp-megamenu icon without plugins?
The result should be something like this: 5d5d19a25f111115856553.png
How the basket is displayed in the menu

<li class="top-cart menu-item menu-item-type-post_type menu-item-object-page wp-megamenu-item-11984  wpmm_mega_menu  wpmm-fadeindown wpmm-submenu-right">
<a href="http://xxxx.xxx.xx/cart/">
<span class="wpmm-selected-icon wpmm-selected-icon-left"><i class="fa fa-cart-arrow-down"></i>
</span>
</a>
</li>

Perhaps someone faced such a task, tell me where to dig.
Thanks in advance.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Pychev Anatoly, 2019-08-21
@pton

In the storefront theme, it's done like this

<?php /* translators: %d: number of items in cart */ ?>
    <?php echo wp_kses_post( WC()->cart->get_cart_subtotal() ); ?>
        <span class="count">
            <?php echo wp_kses_data( sprintf( _n( '%d item', '%d items', WC()->cart->get_cart_contents_count(), 'storefront' ), WC()->cart->get_cart_contents_count() ) ); ?>
        </span>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question