AI Verified

Name

Remove categories from the shop and other pages in Woocommerce

About

Remove any categories from WooCommerce frontend

Language

PHP

Rating

Voted: 1 by 1 user(s)

How to Setup Snippet

Remove categories from the shop and other pages in Woocommerce just change array on line 17 adding the categories you want to remove. In this case I am removing Uncategorized

Link for further information:

The author has provided the following URL that may be helpful to setting up or using this snippet:

https://www.youtube.com/watch?v=YM7EsdbVYXA&ab_channel=GeorgeNicolaou

Codevault

George Snippet Library

Scroll down to see more snippets from this codevault.

Wordpress Compatability

The author has indicated that this snippet is compatable up to wordpress version: 6.1

Our AI bot has checked this snippet is compatable up to wordpress version: 6.1

Code Snippet Plugin Sync

Free & Pro

Download this snippet by clicking the download button, then head over to the Code Snippet Plugin settings in your wordpress admin dashboard, select the import menu then upload this file to import into your wordpress site.

Pro Only (Coming Soon)

You will be able to click a button and sync this snippet to your wordpress site automatically and from your dashboard manage all code snippets across all your wordpress sites that have the Code Snippets Pro plugin installed.

History

Last modified:

13/11/2022

Important Note

This snippet has the following status:

AI Verified

This snippet has been tested by our AI bot, see any comments below.

AI Bot Comments:

Found 0 vulnerabilities

Remove categories from the shop and other pages in Woocommerce

 
                    
1/** Remove categories from the shop and other pages
2* in Woocommerce
3* Change array on line 14
4*/
5 
6function gncy_hide_selected_terms( $terms, $taxonomies, $args ) {
7 
8 $new_terms = array();
9 
10 if ( in_array( 'product_cat', $taxonomies ) && !is_admin() && is_shop() ) {
11 
12foreach ( $terms as $key => $term ) {
13 
14 if ( ! in_array( $term->slug, array( 'uncategorized' ) ) ) {
15 
16 $new_terms[] = $term;
17 
18 }
19 
20 }
21 
22 $terms = $new_terms;
23 
24 }
25 
26 return $terms;
27 
28}
29 
30add_filter( 'get_terms', 'gncy_hide_selected_terms', 10, 3 );

1

Comments

  • GB

    1 year ago

    Would love to try this. I'm a newbie though. Can I see an example of removing two categories named SAMPLE1 and SAMPL2? Not certain how to format it eactly.
  • GN

    1 year ago

    Video has been added for you Greg https://www.youtube.com/watch?v=xTTp56uN1RI&ab_channel=GeorgeNicolaou
  • GN

    1 year ago

    I had shared the wrong screen in the initial video. Here is an updated link https://www.youtube.com/watch?v=YM7EsdbVYXA&ab_channel=GeorgeNicolaou I have corrected the link in the codesnippet description too

Related Snippets

Please see some snippets below related to this snippet..

WooCommerce

AI Verified

1

WooCommerce Change Order Of Product Tabs

Added: 1 year ago

Last Updated: 2 weeks ago

By default, the first tab is the tab which is opened when the product page is loaded. That means, out of the box, WooCommerce will display the product description as open as this is the first tab. How...

WooCommerce

AI Verified

0

Shipping by Weight

Added: 1 year ago

Last Updated: 1 year ago

WooCommerce

AI Verified

0

WooCommerce Add Product-Unique Content Below Loop Item Image

Added: 1 year ago

Last Updated: 1 year ago

Showing product-specific content below the image on a loop item is really easy. In other words, if you want to show content, unique to each individual product below the product featured image on the p...

Other Snippets in this Codevault

These are some popular snippets from this users codevault..

WooCommerce

AI Verified

5

Delete Woocommerce images after deleting product

Added: 1 year ago

Last Updated: 1 month ago

Automatically Delete WooCommerce Images After Deleting a Product. If you use the same image of multiple products the image will not be deleted for those

WooCommerce

AI Verified

2

Add Alphabetical Sorting to Woocommerce

Added: 1 year ago

Last Updated: 2 weeks ago

Sorts products alphabetically in Woocommerce

WooCommerce

AI Verified

1

Remove categories from the shop and other pages in Woocommerce

Added: 1 year ago

Last Updated: 1 year ago

Remove any categories from WooCommerce frontend