WooCommerce: Add Product Table Columns @ Admin

The default WooCommerce Dashboard Products page (/wp-admin/edit.php?post_type=product page) shows the list of products in a table. Default fields are: Image, SKU, Stock, Price, Categories, Tags, Featured and Date.

Sometimes, these columns are not enough and you need more. For example, you might want to quickly take a look at a product custom field, such as “visibility” (whether the product is hidden or not).

So, here’s the snippet for that. Of course, you can adapt it to show your own custom field, an ACF field or whatever product-related information you require.

Here’s a new WooCommerce Products Table column – in this case it’s the products’s “visibility” status

PHP Snippet: Add Column to Products Table @ WooCommerce Dashboard

/**
 * @snippet       New Products Table Column @ WooCommerce Admin
 * @how-to        Get CustomizeWoo.com FREE
 * @author        Rodolfo Melogli
 * @compatible    WooCommerce 5
 * @donate $9     https://businessbloomer.com/bloomer-armada/
 */

add_filter( 'manage_edit-product_columns', 'bbloomer_admin_products_visibility_column', 9999 );

function bbloomer_admin_products_visibility_column( $columns ){
	$columns['visibility'] = 'Visibility';
	return $columns;
}

add_action( 'manage_product_posts_custom_column', 'bbloomer_admin_products_visibility_column_content', 10, 2 );

function bbloomer_admin_products_visibility_column_content( $column, $product_id ){
    if ( $column == 'visibility' ) {
        $product = wc_get_product( $product_id );
		echo $product->get_catalog_visibility();
    }
}

Bonus PHP Snippet 1: Place New Column In A Specific Position

Inside the bbloomer_admin_products_visibility_column function, write this instead (you will be placing the column “Visibility” in position “3”, so edit all occurrences of “3”to define another position):

return array_slice( $columns, 0, 3, true ) + array( 'visibility' => 'Visibility' ) + array_slice( $columns, 3, count( $columns ) - 3, true );

Bonus PHP Snippet 2: Make New Column Sortable

Simply add this snippet to make your column sortable as well.

Please note, this won’t work specifically for the “visibility” field, as it’s now considered and stored as a taxonomy. You can only sort by custom fields.

add_filter( 'manage_edit-product_sortable_columns', 'bbloomer_admin_products_visibility_column_sortable' );

function bbloomer_admin_products_visibility_column_sortable( $columns ){
	$columns['visibility'] = 'visibility';
	return $columns;
}

Where to add this snippet?

You can place PHP snippets at the bottom of your child theme functions.php file (delete "?>" if you have it there). CSS, on the other hand, goes in your child theme style.css file. Make sure you know what you are doing when editing such files - if you need more guidance, please take a look at my free video tutorial "Where to Place WooCommerce Customization?"

Does this snippet (still) work?

Please let me know in the comments if everything worked as expected. I would be happy to revise the snippet if you report otherwise (please provide screenshots). I have tested this code with Storefront theme, the WooCommerce version listed above and a WordPress-friendly hosting on PHP 7.3.

If you think this code saved you time & money, feel free to join 14,000+ WooCommerce Weekly subscribers for blog post updates or 250+ Business Bloomer supporters for 365 days of WooCommerce benefits. Thank you in advance :)

Need Help with WooCommerce?

Check out these free video tutorials. You can learn how to customize WooCommerce without unnecessary plugins, how to properly configure the WooCommerce plugin settings and even how to master WooCommerce troubleshooting in case of a bug!

Rodolfo Melogli

Business Bloomer Founder

Author, WooCommerce expert and WordCamp speaker, Rodolfo has worked as an independent WooCommerce freelancer since 2011. His goal is to help entrepreneurs and developers overcome their WooCommerce nightmares. Rodolfo loves travelling, chasing tennis & soccer balls and, of course, wood fired oven pizza.

19 thoughts on “WooCommerce: Add Product Table Columns @ Admin

  1. Hi

    Sorting is not working unfortunately.

    1. Hi Hakan, what’s not working exactly? After you click it sorts them randomly? What type of data did you display?

  2. Thanks
    If i wanted a colum with the product ID number??
    What line should i change, and to what??

    1. Just this one:

      echo $product->get_catalog_visibility();

      to:

      echo $product->get_id);
  3. A little late to the game and a bit of a novice. I’ve added the function and the column is there but there is no CSS at all and I’m a little unsure how to add that for the Admin area.

    Can you advise on how to place this CSS? As shown in your picture is exactly what I desire so if you could share and where to put it I would appreciate it.

    1. Hey Jeff thanks for your comment! What is the problem / are you trying to achieve? CSS is probably not needed. Let me know

      1. Thanks, nice of you to reply.

        So this adds the Visibility column to the far right in a very thin line (one letter wide with word stretching down) and not in a “normal” column like the other column fields.

        Separate issue but the sort does not seem to work as I would expect. I would think “hidden” would come to the top but it’s mixed in the results with seemingly no sort in play.

        Even “broken” as it is this is currently is still helpful.

        I started this because it appears I need to also set “private” so google, for example, search results don’t take people to a deactivated (for a reason) product.

        1. Thanks Jeff! For the column width, there is not much you can do apart from removing some other column so that this one fits in. Applies to all WordPress tables. Go to “Screen Options” (top right) and toggle columns. This will show properly as soon as you hide one default column.

          For the other query, unfortunately “visibility” is now a custom taxonomy, and I found it very difficult trying to sort by it despite my attempts. The ideal would be to save the visibility value into a custom field, so that you can simply sort by it.

          1. Fair enough and thanks. Didn’t even occur regarding the screen options and now I can at least see the column. Maybe if time frees up I’ll explore making it function the way I would like but this was useful and thanks for your time and for providing this for everyone.

  4. Hi, how would we do this with a plugins meta field? We have a plugin that adds a UPC code to products and the meta field is _rank_math_gtin_code

    1. Hey Stavros! You can use get_post_meta() WordPress function to retrieve that custom field and then echo it. Hope this helps!

  5. This snippet does not appear to work on WooCommerce 4.1.0 and WordPress 5.4.1.

    1. Tried with a different theme and no plugins active apart Woo?

  6. Sir also show us how to edit to desired custom field such as “yith cost of goods” etc

    1. Sam, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

  7. As always, great information. Very helpful.

    How do you set the column width?

    1. Not sure you can do that David!

      1. Column width can be set with admin side CSS that you inject in your functions.php as follows:

        add_action('admin_head', 'my_admin_css');
        
        function my_admin_css() {
          echo '<style>
            // Your CSS here
          </style>';
        }
        
Questions? Feedback? Support? Leave your Comment Now!
_____

If you are writing code, please wrap it between shortcodes: [php]code_here[/php]. Failure to complying with this (as well as going off topic, not writing in English, etc.) will result in comment deletion. You should expect a reply in about 2 weeks - this is a popular blog but I need to get paid work done first. Please consider joining BloomerArmada to get blog comment reply priority, ask me 1-to-1 WooCommerce questions and enjoy many more perks. Thank you :)

Your email address will not be published.