How to display Product type column in WooCommerce Products Table
One common issue users encounter is the absence of a product type column in the WooCommerce products table on the admin side. While WooCommerce offers various default columns to display product information, having a product type column can significantly improve product management and organization.
To address the issue of the missing product type column in the WooCommerce products table, we propose a simple solution in two steps:
1) Register the product type Column
add_filter( 'manage_product_posts_columns', 'wc_products_column_name', 100, 1 );
function wc_products_column_name( $columns ) {
$columns['product_type'] = esc_html__( 'Product Type', 'woocommerce' );
return $columns;
}
This code snippet registers the product type column in the WooCommerce products table columns.
Improve Column Position
Adjusting the position of the product type column within the products table for better visibility and usability.
add_filter( 'manage_product_posts_columns', 'wc_products_column_name', 100, 1 );
/**
* Register Product type column to products table columns.
*
* @param array $columns
* @return array
*/
function wc_products_column_name( $columns ) {
$columns = array_slice( $columns, 0, 3, true ) + array( 'product_type' => esc_html__( 'Product Type', 'woocommerce' ) ) + array_slice( $columns, 3, count( $columns ) - 3, true );
return $columns;
}
2) Set the Column Value
add_filter( 'manage_product_posts_custom_column', 'wc_product_type_column_content', 10, 2 );
function wc_product_type_column_content( $column_name, $product_id ) {
if ( 'product_type' === $column_name ) {
echo wp_kses_post( '<strong>' . ucwords( \WC_Product_Factory::get_product_type( $product_id ) ) . '</strong>' );
}
}
This snippet sets the value for the product type column based on the product type of each individual product.
How to Use the Snippet Code
You can implement this snippet by following on of these steps:
- Child Theme: If you’re using a custom child theme, you can add the snippet to the
functions.php
file of your child theme. This ensures that the functionality remains intact even when you update your theme. - Custom Plugin: A better way, you can create a custom plugin to add the snippet. Creating a custom plugin allows you to keep your code separate from the theme files, making it easier to manage and maintain. You can use our online tool WP Plugin Creator to generate a custom plugin with the snippet included. Simply paste the snippet into the plugin code editor, specify the plugin name, and download the generated plugin zip file.
By following these three steps and implementing the provided code snippets, you can seamlessly integrate the product type column into your WooCommerce admin interface, enhancing your product management capabilities.