In WooCommerce, the default product table includes basic columns like product name, SKU, tags, and categories. However, store owners often use custom fields to store additional information. For example, a store might use a warranty code for each product and may want to display this information directly in the product table. Adding a custom column for warranty codes makes it easier for store admins to quickly see the warranty details without opening each individual product.
In this post, we will help you with the solution that adds a custom column to the admin product table. This is especially helpful for store admins who need quick access to specific product information.
Solution: Add Custom Columns to the Product Table in Admin
This code adds a new column called “Warranty Code” to the WooCommerce product table. This column will display the warranty code associated with each product, which is saved using a custom field.
add_filter( 'manage_edit-product_columns', 'ts_add_warranty_code_column', 15 ); function ts_add_warranty_code_column($columns) { // Add new custom column for Warranty Code $columns['warranty_code'] = __( 'Warranty Code', 'your-text-domain' ); return $columns; } add_action( 'manage_product_posts_custom_column', 'ts_populate_warranty_code_column', 10, 2 ); function ts_populate_warranty_code_column($column, $postid) { if ($column == 'warranty_code') { // Fetch the custom field value (e.g., 'warrantycode') $warranty_code = get_post_meta($postid, 'warrantycode', true); // Display the raw custom field value as it is stored echo $warranty_code ? $warranty_code : 'No Warranty Code'; // Show "No Warranty Code" if not set } }
Output
When store owners add a warranty code for each product using a custom field, this code adds a new column to the WooCommerce product table labeled “Warranty Code.” As a result, the warranty code entered for each product will be displayed in this new column.
With this solution, you can easily view specific product details directly on the product listing page. Similarly, you can also add shipping class column on the product admin page. This adds an extra layer of convenience, eliminating the need for store owners to manually edit each product to check if a shipping class is assigned.