Hello everyone !
I’m trying to enhance my WordPress / Woocoomerce back office by adding shortcut links to some product categories my client will use pretty often (see screenshot bellow).
So far I have managed to achieve this by adding this code to my functions.php :
<?php function add_toolbar_items($wp_admin_bar) {
$wp_admin_bar->add_node( array(
'id' => 'Products',
'title' => 'Products',
'href' => 'http://localhost/qualityControlHQ2/wp-admin/edit.php?post_type=product&orderby=title&order=asc',
) );
//Subcategories
$wp_admin_bar->add_node( array(
'id' => '7"',
'title' => '7"',
'href' => 'http://localhost/qualityControlHQ2/wp-admin/edit.php?product_cat=7&post_type=product&orderby=title&order=asc',
'parent' => 'Products',
) );
$wp_admin_bar->add_node( array(
'id' => 'LP',
'title' => 'LP',
'href' => 'http://localhost/qualityControlHQ2/wp-admin/edit.php?product_cat=lp&post_type=product&orderby=title&order=asc',
'parent' => 'Products',
) );
..... duplicated for all other Subcategories
}
add_action('admin_bar_menu', 'add_toolbar_items', 72);
?>
But this is not really convenient as I have to copy / paste the same code for all my other 12 subcategories and if my client adds a new category he will have to ask me to add a shortcut manually into the code.
So I thought about adding an ACF switch field (true / false) called “catShortcut” to my categories and have every category with the field value set to “true” displayed in my shortcuts links list.
I understand the logic of what I need to achieve but I’m clueless about how to get it done in my code.
Any idea how to make that happen ?
Thanks !

