Hide Uncategorized category from WooCommerce

Today, We want to share with you Hide Uncategorized category from WooCommerce pages.In this post we will show you How to Delete ‘Uncategorized’ in WordPress, hear for How to hide/delete uncategorized category in shop page we will give you demo and example for implement.In this post, we will learn about how to remove uncategorized product category in woocommerce with an example.

Hide Uncategorized category from WooCommerce pages

There are the Following The simple About delete Uncategorized category from WooCommerce pages Full Information With Example and source code.

As I will cover this Post with live Working example to develop remove category from product page woocommerce, so the hide uncategorized category wordpress for this example is following below.

Read Also:  PHP Yii Maintenance Mode Tutorial with Examples

function hide_remove_all_uncategorized_category( $terms, $taxonomy, $query_vars, $term_query ) {
if ( is_admin() )
return $terms;

if ( $taxonomy[0] == ‘product_cat’ ) {
foreach ( $terms as $k => $term ) {
if ( $term->term_id == get_option( ‘default_product_cat’ ) ) {
unset( $terms[$k] );
}
}
}

return $terms;
}
add_filter( ‘get_terms’, ‘hide_remove_all_uncategorized_category’, 10, 4 );

Remove Uncategorized category permanently from woocommrce

if ( ! function_exists( ‘hide_remove_all_uncategorized_category’ ) ) {
function hide_remove_all_uncategorized_category( $query = false ) {

$query->set( ‘tax_query’, array(
‘relation’ => ‘OR’,
array(
‘taxonomy’ => ‘product_visibility’,
‘field’ => ‘name’,
‘terms’ => ‘exclude-from-catalog’,
‘operator’ => ‘NOT IN’,
),
array(
‘taxonomy’ => ‘product_visibility’,
‘field’ => ‘name’,
‘terms’ => ‘exclude-from-catalog’,
‘operator’ => ‘!=’,
),
));

}
}
add_action( ‘pre_get_posts’, ‘hide_remove_all_uncategorized_category’ );

Removing the ‘Uncategorized’ Category in WordPress

add_action( ‘woocommerce_product_query’, ‘hide_remove_all_uncategorized_category’ );

function hide_remove_all_uncategorized_category( $q ) {

$tax_query = (array) $q->get( ‘tax_query’ );

$tax_query[] = array(
‘taxonomy’ => ‘product_cat’,
‘field’ => ‘slug’,
‘terms’ => array( ‘uncategorized’ ), // Simple put your Category slug here
‘operator’ => ‘NOT IN’
);

$q->set( ‘tax_query’, $tax_query );

}

Web Programming Tutorials Example with Demo

Read :

Read Also:  VueJS onload Function Call Example with Demo

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about remove Uncategorized category in wordpress.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.