Viewing 10 replies - 1 through 10 (of 10 total)
  • Plugin Contributor Jeremiah

    (@jprummer)

    That is not a feature, but you can customize it and wrap the output in an if admin statement

    Thread Starter thisisbbc

    (@thisisbbc)

    Thank you for your answer Jeremiah. Would you mind guiding me in the process? Im kind of a novice in plugin coding and I wouldnt know where to start :/

    All best,
    Bastien

    Plugin Contributor Ewout

    (@pomegranate)

    Not out of the box, but you could try adding the following code to your functions.php file:

    add_action('admin_bar_menu', 'add_toolbar_wcmenucart', 100);
    function add_toolbar_wcmenucart($admin_bar){
    	if (!class_exists( 'WcMenuCart' ))
    		return;
    
    	$wcMenuCart = new WcMenuCart();
    	$menucart_html = $wcMenuCart->wcmenucart_menu_item();
    	if (!is_admin() && $menucart_html != '') {
    		$dom = new DOMDocument();
    		$dom->loadHTML($menucart_html);
    
    		foreach ($dom->getElementsByTagName('a') as $a) {
    		    $menutitle = $a->nodeValue;
    			$menuhref = $a->getAttribute('href');
    		}
    
    		$admin_bar->add_menu( array(
    			'id'    => 'wcmenucart',
    			'title' => '<i class="wcmenucart-icon-shopping-cart-0"></i>'.$menutitle,
    			'href'  => $menuhref,
    			'meta'  => array(
    				'title' => __('View your shopping cart', 'wcmenucart'),
    			),
    		));
    	}
    }

    Works on my test setup. Note that this doesn’t work with AJAX, so whenever you add something to the cart it doesn’t appear until you navigate to the next page. I’m assuming that you have some sort of plugin to enable the admin bar for everybody browsing the site?

    Plugin Contributor Jeremiah

    (@jprummer)

    Thanks Ewout!

    Thread Starter thisisbbc

    (@thisisbbc)

    Hi Ewout!

    Thank you very much for your answer. Well we use buddypress so the admin bar stays on top all the time, the notifications, messages and friend requests goes there. About your solution… It is indeed working… on the front end! But there’s a problem with the back-end. The admin-bar is gone and most of the tabs display an empty white page (I can’t even go to the theme editor anymore).

    Also, the menu doesn’t seem to display a drop-down of the items in the cart on the front-end.

    A quick fix would be tremendously appreciated ??

    Thank you again.

    All best,
    Bastien

    Plugin Contributor Ewout

    (@pomegranate)

    Hi Bastien,
    First of all, the fact that it doesn’t work on the back-end is on purpose, because it’s a bit unstable, depending on all sorts of factors. Front-end only is more of a fool proof method. I think your error actually demonstrates that, because it’s most likely this sort of bug that causes the behavior you’re seeing.

    The following code detects the backend one step earlier, and doesn’t do anything at all in the backend. Can you try if this works for you?

    add_action('admin_bar_menu', 'add_toolbar_wcmenucart', 100);
    function add_toolbar_wcmenucart($admin_bar){
    	if (!class_exists( 'WcMenuCart' ) || is_admin() )
    		return;
    
    	$wcMenuCart = new WcMenuCart();
    	$menucart_html = $wcMenuCart->wcmenucart_menu_item();
    	if ( $menucart_html != '') {
    		$dom = new DOMDocument();
    		$dom->loadHTML($menucart_html);
    
    		foreach ($dom->getElementsByTagName('a') as $a) {
    		    $menutitle = $a->nodeValue;
    			$menuhref = $a->getAttribute('href');
    		}
    
    		$admin_bar->add_menu( array(
    			'id'    => 'wcmenucart',
    			'title' => '<i class="wcmenucart-icon-shopping-cart-0"></i>'.$menutitle,
    			'href'  => $menuhref,
    			'meta'  => array(
    				'title' => __('View your shopping cart', 'wcmenucart'),
    			),
    		));
    	}
    }

    The fly-out is a pro feature, so that won’t work. Even if you have the pro version it would take quite a bit of customizing to make it work, because the admin bar works very different from regular menus.

    Thread Starter thisisbbc

    (@thisisbbc)

    Hey Ewout!

    Thanks for your quick answer that’s really appreciated ??
    Working like a charm!

    I effectively seen this feature was reserved to the pro version between the time I posted my answer and I’ve read yours, so no problems with this.

    However since you mention it wouldn’t work in the admin bar, it makes me a bit reluctant to buy the pro version. If you’d be able to add admin bar support you can add me to the satisfied customers list ??

    Meanwhile I’ll stick with the free version since it’s pretty much what I needed.

    Regards,
    Bastien

    hyperV

    (@hyperv)

    Hi all,

    nice stuff!!
    I#m looking the opposit wa to schow the my-account menue from the adminbar in the etop-menu beside the chat menu.

    Have someone a solution?

    Would be great!!!

    Regards

    Josef

    hyperV

    (@hyperv)

    In addition:

    I try to integrate somthing like thi:

    add_filter( 'wp_nav_menu_items', 'add_myaccount_item', 10, 2 );
    function add_myaccount_item( $wp_admin_bar ) {
    	$user_id      = get_current_user_id();
    	$current_user = wp_get_current_user();
    	$profile_url  = get_edit_profile_url( $user_id );
    
    	if ( ! $user_id )
    		return;
    
    	$avatar = get_avatar( $user_id, 26 );
    	$howdy  = sprintf( __('Howdy, %1$s'), $current_user->display_name );
    	$class  = empty( $avatar ) ? '' : 'with-avatar';
    
    	$wp_admin_bar->add_menu( array(
    		'id'        => 'my-account',
    		'parent'    => 'top-secondary',
    		'title'     => $howdy . $avatar,
    		'href'      => $profile_url,
    		'meta'      => array(
    			'class'     => $class,
    			'title'     => __('My Account'),
    		),
    	) );
    }

    How can I show this in the Top-Menu of my mystile wootemplate.

    Thanks in advanced

    Josef

    Plugin Contributor Ewout

    (@pomegranate)

    Hi Josef,
    This has nothing to do with the Menu Cart plugin, so I’m afraid I can’t help you.

    The code below should get you on the way though: it changes the default ‘Howdy’ link to the my-account page. The main thing that I changed was the action hook (admin_bar_menu) and the my_account_url

    add_action('admin_bar_menu', 'admin_bar_my_account', 100);
    function admin_bar_my_account( $admin_bar ){
    	$user_id		= get_current_user_id();
    	$current_user	= wp_get_current_user();
    	$my_account_url	= get_permalink( woocommerce_get_page_id( 'myaccount' ));
    
    	if ( empty($user_id) ) {
    		return;
    	}
    
    	$avatar	= get_avatar( $user_id, 26 );
    	$howdy	= sprintf( __('Howdy, %1$s'), $current_user->display_name );
    	$class	= empty( $avatar ) ? '' : 'with-avatar';
    
    	$admin_bar->add_menu( array(
    		'id'		=> 'my-account',
    		'parent'	=> 'top-secondary',
    		'title'		=> $howdy . $avatar,
    		'href'		=> $my_account_url,
    		'meta'		=> array(
    			'class'	=> $class,
    			'title'	=> __('My Account'),
    		),
    	) );
    }
Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Use in admin bar?’ is closed to new replies.