Nascondere le categorie di prodotti vuote dalla navigazione principale in WooCommerce
· di Daniel

Naturalmente puoi aggiungere quante categorie di prodotti WooCommerce vuoi al menu principale. A volte però restano vuote, ad esempio per variazioni di magazzino.
Se vuoi nascondere automaticamente le categorie di prodotti vuote nel menu di WordPress, inserisci il codice qui sotto nel file functions.php.
add_filter( 'wp_get_nav_menu_items', 'nav_remove_empty_category_menu_item', 10, 3 );
function nav_remove_empty_category_menu_item ( $items, $menu, $args ) {
global $wpdb;
$nopost = $wpdb->get_col( "SELECT term_taxonomy_id FROM $wpdb->term_taxonomy WHERE count = 0" );
foreach ( $items as $key => $item ) {
if ( ( 'taxonomy' == $item->type ) && ( in_array( $item->object_id, $nopost ) ) ) {
unset( $items );
}
}
return $items;
}