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.

Read Also:  CodeIgniter Login Registration Example Tutorial From Scratch

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.

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:  Rregistration and login form in php and mysql with validation code free download

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.


Related FAQ

Here are some more FAQ related to this Article:

  1. Read Also:  how to prevent bootstrap modal from closing when clicking outside?
  2. Read Also:  Laravel 6 Bootstrap Toggle Switch With Ajax Update To Mysql
  3. Read Also:  How To Fix Laravel Specified Key Was Too Long Error?
  4. Read Also:  jquery image upload preview Delete option
  5. Read Also:  Vue.js Binding Fundamentals Using V-Bind Directive
  6. Read Also:  How to Open URL in New Window using jQuery?
  7. Read Also:  PHP nested FOR loop multiple conditions - ArrayIterator
  8. Read Also:  Laravel ajax get Request Example From Scratch
  9. Read Also:  How To Fix Laravel Specified Key Was Too Long Error?
  10. Read Also:  jquery image upload preview Delete option
CLOSEX