NB: Make sure you do a back up of your theme, files and database before attempting the tutorials

Admin WooCommerce: Display the ID Column in the Category table
Intermediate
Web Hosting Canada

Last modified : Oct 01 2022

Estimated reading time : 1 minute, 23 seconds - 127 words

In ths tutorial, we will show you how, with two distinct functions, we can display an ID column in WooCommerce Admin with the help of a shortcode.

There exist two WordPress filters: manage_edit-category_columns and manage_category_custom_column.

In our example, we are going to use them to display WooCommerce taxonomies.

Let’s build our first function, manage_edit-category_columns, by replacing category with product_cat.

To edit the WooCommerce taxonomies, we’ll replace manage_edit-category_columns with manage_edit-product_cat_columns and identify it as termid as our column that we’ll call with our functions:

function my_custom_taxonomy_columns( $columns )
{
	$columns['termid'] = __('Term ID');
        return $columns;
}
add_filter('manage_edit-product_cat_columns' , 'my_custom_taxonomy_columns');

So with this, we can set up the required column.

The next filter will allow us to display the WooCommerce Taxonomy ID. We’ll do the exact same thing for manage_category_custom_column, by replacing it with manage_product_cat_custom_column.

function my_custom_taxonomy_columns_content( $content, $column_name, $term_id )
{
    if ( 'termid' == $column_name ) {
        $content = $term_id;
    }
    return $content;
}
add_filter( 'manage_product_cat_custom_column', 'my_custom_taxonomy_columns_content', 10, 3 );

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>