I would go about this slightly differently. Still using the wp_get_nav_menu_items
filter, but first I’ll build an array containing the IDs of all empty terms. Then I’ll compare each of the $items
to this for potential exclusion:
add_filter( 'wp_get_nav_menu_items', 'wpse177082', 10, 3 );
function wpse177082 ( $items, $menu, $args ) {
global $wpdb;
$empty = $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, $empty ) ) ) {
unset( $items[$key] );
}
}
return $items;
}
You could of course further restrict this to only affecting WooCommerce Product Categories if needed.
Related Posts:
- Hide some items from Screen options in dashboard for products
- Add to cart php not working [closed]
- woocommerce change currency per category [closed]
- (Woocommerce) Order by price when entering specific category
- add product thumbnail to checkout page only and include variation name
- Which method is more correct for removing WooCommerce Extensions menu item?
- remove empty paragraphs from the_content?
- How to display custom field in woocommerce orders in admin panel?
- Set JPEG compression for specific custom image sizes
- Define custom Page Template without its own .php file
- syntax for remove_filter in parent theme with class
- Convert hyphen to underscore in permalinks
- Override parent theme function that is not hooked or in the functions.php file
- Programmatically Add Font-Awesome Icons to Category Widget
- Remove bulk actions based on user role or capabilities
- How to Acheive the custom woocommerce category template
- Removing title from page
- Remove product description from product archive page
- Adding body class when post contains a specific shortcode
- Replace Archive Widget Link Text
- Can you use admin pages functionality on the frontend of your site
- How to make unique add_filter to the_content of specific page template files – so each template gets its own addition
- Creating loop within functions.php
- Limit filter upgrader_post_install to a single plugin
- How to update feed only 2-3 times a week (for Feedburner email)?
- Manipulate Output of wp_list_something: select menu instead of li’s
- Display WooCommerce subscriptions for user [closed]
- Increment price for Woocommerce Minicart [closed]
- Change woocommerce products weight varation based its product category or tags? [closed]
- Show excerpt for only first post in query
- Woocommerce checkout field maxlength, make input number field only (postcode)
- change in form-checkout.php by using code in functions.php
- Set quantity of woocommerce product on page visit [closed]
- Can’t check if a post has thumbnail adding filter to get_post_metadata()
- Adding HTML to the end of every post with the Block Editor
- How do I add Bootstrap and LESS to my migrated WordPress site?
- Passing values from a widget to a function within a plugin
- Publish/Update post is changing image links from file url to post url
- How can I remove the main description text box in a Woocommerce product editor page? I only use the “Product short description” text box [closed]
- How to display custom option field in woocommerce orders in admin panel?
- Remove the product category module block from the Woocommerce product page
- Replace a menu with widget or a custom template file programmatically
- Run wp_kses_decode_entities on atom feed?
- Filtering out the #more anchor link that gets produced by
- Can’t filter wp_get_attachment_link
- append to existing parent theme function
- Functions when woocommerce isn’t installed
- Override the WordPress core function wp_referer_field
- Modify post filter to set custom number of posts per page and exclude child posts
- How to add custom JavaScript in functions?
- How to edit the Tags within the image file URLs?
- How to change this simple code so that it sends the email notification after payment in WooCommerce?
- How to add_filter html template to middle of content
- Redefine function arguments before rendering
- replace text in Sort Box
- Combine embed_oembed_html and oembed_result
- login_headertitle is deprecated since version 5.2.0
- Filter to wp_list_authors
- add referrer to woo
- Native gallery custom html output
- The_content and Preg_replace in loaded Iframe [closed]
- Auto scroll to id on page load on all pages except home page. Only do this on mobile
- Add Adsense code between job listings – wp job manager plugin
- Adding product to WooCommerce cart [closed]
- WooCommerce -> wc_enqueue_js not working [closed]
- Use existing image sizes for WooCommerce
- Replace header image on all other pages but home – URL issue
- Any adverse effects of adding apply_filters to a function?
- Woocommerce Variable Product Dropdown for Custom Shop Template
- How to hide content on mobile in the functions.php file – woocommerce
- how can I add filter in specfic field in my website?
- Customizing the wp_video_shortcode output with add_filter
- How to add HTML into error message
- Hide ‘add to cart’ when certain value in dropdown is selected
- Removing comment lines from all enqueued js files using a filter function
- Remove text after a dot and a colon in Woocommerce product title
- How Do I Unhook This Parent Theme Function?
- Help with with my function for wordpress
- Remove clickable Link of WordPress Site Logo from Woocommerce Single Product page
- Problems adding a new field to product in cart
- Child theme remove parent filter in functions
- Variable function names
- function replace_text for entire page
- Remove External Links from WordPress posts Using add_filter() in Theme functions.php
- Graphic before title – Specific Category
- Hide disclaimer from summary excerpts
- Only seems to be displaying one child when there are supposed to be multiple
- Why might wptexturize have become re-enabled?
- Shortcode to eliminate and replace with
- Insert menu into theme location depending on user logged in/out status
- functions.php filters not applied in AJAX call
- Problem in outputting shortcode
- Settings in functions.php used by a plugin
- Allow tags and attributes in post and pages content
- Override parent theme function that is not hooked or in the functions.php file
- Can’t change excerpt length and more tag
- Filter to strip unnecessary attributes
- reusing code in function and running it with loop
- Warning: call_user_func_array() expects parameter 1 to be a valid callback
- Add text below WooCommerce short description if metabox value is true