skip to Main Content

does anyone know how to hide one specific tag name from the tags list in WooCommerce Product page?

Example: in a product page i see TAGS: 1, 2, 3. I do not want to show tag 2 in tag list on every product page the tag 2 appears. Only 1 and 3.

Thanks for yours help.

2

Answers


  1. You can use get_the_terms filter hook. try the below code. code will go in your active theme functions.php file.

    function remove_tags_links( $terms, $post_id, $taxonomy ){
    
        if( is_admin() ) return;
    
        // onlu apply for product_tag.
        if( $taxonomy == 'product_tag' ){
    
            $slugs_to_hide = array( 'test-2' ); // degine slug of tags you want to hide.
            $new_terms     = array(); // store only showing terms
    
            if( !empty( $terms ) ){
                foreach ( $terms as $key => $term ) {
                    if( !in_array( $term->slug, $slugs_to_hide ) ){
                        $new_terms[$key] = $term;
                    }
                }
            }
    
            return $new_terms;
        }
    
        return $terms;
    
    }
    add_filter( 'get_the_terms', 'remove_tags_links', 10, 3 );
    

    Tested and works

    enter image description here

    enter image description here

    Login or Signup to reply.
  2. The answer given is working fine.
    But if you want the tags to show in the Products list on the dashboard (/wp-admin/edit.php?post_type=product) then you need to change :

    if( is_admin() ) return;
    

    To :

    if( is_admin() ) return $terms;
    

    Full code :

    function remove_tags_links( $terms, $post_id, $taxonomy ){
    
        if( is_admin() ) return $terms;
        
        // only apply for product_tag.
        if( $taxonomy == 'product_tag' ){
    
            $slugs_to_hide = array( 'test-2' ); // degine slug of tags you want to hide.
            $new_terms     = array(); // store only showing terms
    
            if( !empty( $terms ) ){
                foreach ( $terms as $key => $term ) {
                    if( !in_array( $term->slug, $slugs_to_hide ) ){
                        $new_terms[$key] = $term;
                    }
                }
            }
    
            return $new_terms;
        }
    
        return $terms;
    
    }
    add_filter( 'get_the_terms', 'remove_tags_links', 10, 3 );
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search