phpwordpress

Wishlist item counter in top bar menu of website (YITH Wishlist/WooCommerce)


I want to add an item counter to the wishlist page link in the top bar menu of my site. I tried adding and using a shortcode, but the counter still does not show up in the menu link - instead of the menu link being Wishlist X (where X is the number of items in the wishlist), it's only displayed as Wishlist. Could someone please help me add an item counter to the link? Thanks in advance! šŸ™‚

The code I’m currently using in my functions.php of my child theme:

function tnc_wishlist_counter_cart(){
    global $woocommerce;
    $wl_items = YITH_WCWL()->get_products();
    $count = 0;
    foreach ($wl_items as $key => $item) {
        $count = $count + 1;
    }
    return $count;
}
add_shortcode( 'tnc-wishlist-counter', 'tnc_wishlist_counter_cart' );

In the Navigation Label of the top menu item, I have added this:
Wishlist <?php echo do_shortcode('[tnc-wishlist-counter]'); ?>


Solution

  • So with the help of YITH Themes Support, I managed to find the answer! :) Sharing the link in case anyone would need this too