Take your website
To the next level
Discover our newly launched customization services and elevate your web projects to new heights.
Delegate tasks, save time, and unlock the power of professional WordPress outsourcing.

Okay
  Public Ticket #1382902
Account icon
Closed

Comments

  • Abra V started the conversation

    Hello,

    How do you add an account icon next to the cart icon.

    More generally how do you manage these icons?

    Many thanks,

    Abra

  •  7,092
    Oliver replied

    HI!

    Here is the code example of adding menu item card:

    function thegem_cart_menu($items, $args) {
        if(thegem_is_plugin_active('woocommerce/woocommerce.php') && $args->theme_location == 'primary' && thegem_get_option('header_layout') !== 'overlay') {
            global $woocommerce;
            $count = sizeof(WC()->cart->get_cart());
            ob_start();
            woocommerce_mini_cart();
            $minicart = ob_get_clean();
            $items .= '<li class="menu-item menu-item-cart"><a href="'.esc_url(get_permalink(wc_get_page_id('cart'))).'" class="minicart-menu-link ' . ($count == 0 ? 'empty' : '') . '">' . '<span class="minicart-item-count">' . $count . '</span>' . '</a><div class="minicart"><div class="widget_shopping_cart_content">'.$minicart.'</div></div></li>';
        }
        return $items;
    }
    add_filter('wp_nav_menu_items', 'thegem_cart_menu', 11, 2);

    You need to create the new filter like this and add this code to the function.php of the child theme

    Please note if you comment on your ticket before we reply, your ticket will be pushed down of the tickets list. 

    Regards, Oliver

  • Abra V replied

    Hi!

    Thank you for your answer but I couldn't redeclare the function as it exists in another file, I've got the following error:

    Fatal error: Cannot redeclare thegem_cart_menu() (previously declared in myBlog/wp-content/themes/thegem-child/functions.php:2) in myBlog/wp-content/themes/thegem/inc/woocommerce.php on line 628 

    What is the best practice in that case?

    Many thanks

  •  7,092
    Oliver replied

    You need to set another name:

    function thegem_cart_menu_new($items, $args) {
        if(thegem_is_plugin_active('woocommerce/woocommerce.php') && $args->theme_location == 'primary' && thegem_get_option('header_layout') !== 'overlay') {
            global $woocommerce;
            $count = sizeof(WC()->cart->get_cart());
            ob_start();
            woocommerce_mini_cart();
            $minicart = ob_get_clean();
            $items .= '<li class="menu-item menu-item-cart"><a href="'.esc_url(get_permalink(wc_get_page_id('cart'))).'" class="minicart-menu-link ' . ($count == 0 ? 'empty' : '') . '">' . '<span class="minicart-item-count">' . $count . '</span>' . '</a><div class="minicart"><div class="widget_shopping_cart_content">'.$minicart.'</div></div></li>';
        }
        return $items;
    }
    add_filter('wp_nav_menu_items', 'thegem_cart_menu_new', 11, 2);

    Please note if you comment on your ticket before we reply, your ticket will be pushed down of the tickets list. 

    Regards, Oliver