• Resolved taniabb

    (@taniabb)


    I am using the plugin : ultra simple paypal shopping cart which provides the code:

    <?php echo wpusc_cart_item_qty(); ?>

    For adding the number of items in the shopping cart. I am trying to use this so that the number of items is displayed AFTER the word ‘cart’ in my navigation bar in () brackets.

    ‘Cart’ has a menu_item_id of 104 but I cannot seem to write a php if statement to achieve what I want… or maybe I’m putting it in the wrong place? I’ve been working with the header.php file.

    If anyone can help I’d really appreciate it. I am not really familiar with PHP coding. I have a maintenance mode on at the moment but can drop it if anyone needs to see the site.

    WordPress 3.5.1
    Template: Twenty Ten child theme
    Plug-in: Ultra simple paypal shopping cart

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator keesiemeijer

    (@keesiemeijer)

    Try it with this in your theme’s functions.php:

    function add_count_menu_items( $items, $menu, $args ) {
    	// Iterate over the items
    	foreach ( $items as $key => $item ) {
    		if ( $item->ID == 104 ) {
    			$item->title .= ' (' . wpusc_cart_item_qty() . ')';
    		}
    	}
    	return $items;
    }
    add_filter( 'wp_get_nav_menu_items', 'add_count_menu_items', 10, 3 );

    Thread Starter taniabb

    (@taniabb)

    Fantastic, thank you!
    I had to change the 3 to a 4 (not sure what that number represents???) to get it to work but that brilliant thanks so much for such a speedy response.

    Moderator keesiemeijer

    (@keesiemeijer)

    You’re welcome ??

    The number represents how many arguments ($items, $menu, $args) the filter “wp_get_nav_menu_items” has. Strange that it only works with 4 arguments.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘how to add number of items in basket to menu item’ is closed to new replies.