Store Shortcuts in the Admin Bar
Adds a "Store" menu to the admin toolbar with quick links to orders, products, coupons, customers and settings, available on the front end too.
Opens WPIDE on
Code
add_action( 'admin_bar_menu', function ( $bar ) {
if ( ! current_user_can( 'manage_woocommerce' ) || ! function_exists( 'wc_get_container' ) ) {
return;
}
$hpos = class_exists( '\Automattic\WooCommerce\Utilities\OrderUtil' ) && \Automattic\WooCommerce\Utilities\OrderUtil::custom_orders_table_usage_is_enabled();
$links = array(
'orders' => array( 'Orders', $hpos ? admin_url( 'admin.php?page=wc-orders' ) : admin_url( 'edit.php?post_type=shop_order' ) ),
'products' => array( 'Products', admin_url( 'edit.php?post_type=product' ) ),
'add' => array( 'Add product', admin_url( 'post-new.php?post_type=product' ) ),
'coupons' => array( 'Coupons', admin_url( 'edit.php?post_type=shop_coupon' ) ),
'customers' => array( 'Customers', admin_url( 'users.php?role=customer' ) ),
'settings' => array( 'Settings', admin_url( 'admin.php?page=wc-settings' ) ),
);
$bar->add_node( array( 'id' => 'wpide-store', 'title' => '<span class="ab-icon dashicons dashicons-cart" style="margin-top:2px"></span>Store', 'href' => $links['orders'][1] ) );
foreach ( $links as $id => $link ) {
$bar->add_node( array( 'parent' => 'wpide-store', 'id' => 'wpide-store-' . $id, 'title' => esc_html( $link[0] ), 'href' => esc_url( $link[1] ) ) );
}
}, 80 );
Notes
Only shown to users who can manage WooCommerce; edit the $links array to add your own shortcuts.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.