Francesco Rotondo
Francesco Rotondo

Reputation: 11

Add a column with product category ID in Woocommerce

screenshot dashboard

In Product Category admin page of Woocommerce, I'd like to have an extra column showing the Product Category IDs instead of manually find out on every product category's url.

I've found some snippet for showing the IDs in normal Wordpress categories but nothing about Woocommerce's product category.

Upvotes: 1

Views: 1178

Answers (1)

gvgvgvijayan
gvgvgvijayan

Reputation: 2506

function add_post_tag_columns( $columns ) {
    $columns['id'] = 'Id';
    return $columns;
}
add_filter( 'manage_edit-product_cat_columns', 'add_post_tag_columns' );

function add_post_tag_column_content( $content, $column, $id ) {
    if ( 'id' === $column ) {
        $content = $id;
    }

    return $content;
}
add_filter( 'manage_product_cat_custom_column', 'add_post_tag_column_content', 10, 3 );

The hook manage_edit-product_cat_columns is used to modify/add new column heading. The hook manage_product_cat_custom_column is used to display custom content of a specific column. Here we conditionally check the column heading is equal to id if so we assign $id third parameter value which holds the id of the category to the first parameter $content.

Product category table with ID

Upvotes: 3

Related Questions