WC_Admin_Menus::admin_bar_menus()publicWC 2.4.0

Add the "Visit Store" link in admin bar main menu.

Method of the class: WC_Admin_Menus{}

No Hooks.

Return

null. Nothing (null).

Usage

$WC_Admin_Menus = new WC_Admin_Menus();
$WC_Admin_Menus->admin_bar_menus( $wp_admin_bar );
$wp_admin_bar(WP_Admin_Bar) (required)
Admin bar instance.

Changelog

Since 2.4.0 Introduced.

WC_Admin_Menus::admin_bar_menus() code WC 8.7.0

public function admin_bar_menus( $wp_admin_bar ) {
	if ( ! is_admin() || ! is_admin_bar_showing() ) {
		return;
	}

	// Show only when the user is a member of this site, or they're a super admin.
	if ( ! is_user_member_of_blog() && ! is_super_admin() ) {
		return;
	}

	// Don't display when shop page is the same of the page on front.
	if ( intval( get_option( 'page_on_front' ) ) === wc_get_page_id( 'shop' ) ) {
		return;
	}

	// Add an option to visit the store.
	$wp_admin_bar->add_node(
		array(
			'parent' => 'site-name',
			'id'     => 'view-store',
			'title'  => __( 'Visit Store', 'woocommerce' ),
			'href'   => wc_get_page_permalink( 'shop' ),
		)
	);
}