How to hide uncategorized category from the shop page on the frontend
Please add the following code to your child theme’s functions.php file. The below code will remove the “Uncategorized” category from widget and subcategories.
add_filter( 'woocommerce_product_categories_widget_args', 'thb_remove_uncategorized_category' );
add_filter( 'woocommerce_product_subcategories_args', 'thb_remove_uncategorized_category' );
function thb_remove_uncategorized_category( $args ) {
$uncategorized = get_option( 'default_product_cat' );
$args['exclude'] = $uncategorized;
return $args;
}
You can also use the bottom code to remove Uncategorized from Product Listings:
add_filter( 'get_terms', 'thb_remove_uncategorized_from_listing', 20, 3 );
function thb_remove_uncategorized_from_listing( $terms, $post_id, $taxonomy ) {
$uncategorized = get_option( 'default_product_cat' );
foreach ( $terms as $key => $term ) {
if ( intval( $uncategorized ) === $term->term_id ) {
unset( $terms[ $key ] );
}
}
return $terms;
}