• Hi, I’m loving the theme and its simplicity, but I need to make a few tweeks and wondered if anyone could help me please?

    I’d like to add the little shopping cart icon, which also shows the customer how much they have in their cart please? I see there is a place to add a custom code and wondered if there was a code I could add there please?

Viewing 1 replies (of 1 total)
  • Hi @angelamc,

    I hope you are well today and thank you for your question.

    You can try achieving this by creating a file colorlib-divilab-plugin.php in the wp-content/plugins directory of your WordPress install and add the following code in it then activate this Colorlib Plugin from the admin area of your site.

    <?php
    /*
    Plugin Name: Colorlib Plugin
    Description: Quick Custom Solution Plugin for Implementing Custom Solution.
    Version: 1.0.0
    Author: Movin
    Author URI: https://freewptp.com/
    License: GNU General Public License (Version 2 - GPLv2)
    */
    
    /**
     * Place a cart icon with number of items and total cost in the menu bar.
     */
    function activello_woomenucart($menu, $args) {
    
    	// Check if WooCommerce is active and add a new item to a menu assigned to Primary Navigation Menu location
    	if ( !in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) || 'primary' !== $args->theme_location )
    		return $menu;
    
    	ob_start();
    		global $woocommerce;
    		$viewing_cart = __('View your shopping cart', 'dazzling');
    		$start_shopping = __('Start shopping', 'dazzling');
    		$cart_url = $woocommerce->cart->get_cart_url();
    		$shop_page_url = get_permalink( woocommerce_get_page_id( 'shop' ) );
    		$cart_contents_count = $woocommerce->cart->cart_contents_count;
    		$cart_contents = sprintf(_n('%d item', '%d items', $cart_contents_count, 'dazzling'), $cart_contents_count);
    		$cart_total = $woocommerce->cart->get_cart_total();
    		// Uncomment the line below to hide nav menu cart item when there are no items in the cart
    		// if ( $cart_contents_count > 0 ) {
    			if ($cart_contents_count == 0) {
    				$menu_item = '<li class="menu-item"><a class="woo-menu-cart" href="'. $shop_page_url .'" title="'. $start_shopping .'">';
    			} else {
    				$menu_item = '<li class="menu-item"><a class="woo-menu-cart" href="'. $cart_url .'" title="'. $viewing_cart .'">';
    			}
    
    			$menu_item .= '<i class="fa fa-shopping-cart"></i> ';
    
    			$menu_item .= $cart_contents.' - '. $cart_total;
    			$menu_item .= '</a></li>';
    		// Uncomment the line below to hide nav menu cart item when there are no items in the cart
    		// }
    		echo $menu_item;
    	$social = ob_get_clean();
    	return $menu . $social;
    
    }
    add_filter('wp_nav_menu_items','activello_woomenucart', 10, 2);

    Best Regards,
    Movin

Viewing 1 replies (of 1 total)
  • The topic ‘Add shopping cart icon/total’ is closed to new replies.