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
 * @community     https://businessbloomer.com/club/
 */

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 custom code?

You should place custom PHP in functions.php and custom CSS in style.css of your child theme: where to place WooCommerce customization?

This code still works, unless you report otherwise. To exclude conflicts, temporarily switch to the Storefront theme, disable all plugins except WooCommerce, and test the snippet again: WooCommerce troubleshooting 101

Related content

  • WooCommerce: Add Second Description @ Product Category Pages
    In terms of SEO, if you’re trying to rank your product category pages, you really need to make the most of the default WooCommerce product category “description” and “thumbnail”. Most themes, if compatible with WooCommerce, will show this content right below the product category name and above products. Nothing new so far. But what if […]
  • WooCommerce: Add Custom Field to Product Variations
    Adding and displaying custom fields on WooCommerce products is quite simple. For example, you can add a “RRP/MSRP” field to a product, or maybe use ACF and display its value on the single product page. Easy, yes. Unfortunately, the above only applies to “simple” products without variations (or the parent product if it’s a variable […]
  • WooCommerce: Add Custom Product Fields (e.g. RRP) Without a Plugin
    The manufacturer’s suggested retail price (MSRP), or the recommended retail price (RRP), is the price at which the manufacturer recommends that the retailer sells the product at. You might have seen this in an ad, on a magazine, on a price tag: “RRP: $50. Our price: $39!”. WooCommerce entrepreneurs can take advantage of this “marketing […]
  • WooCommerce: Display Advanced Custom Fields @ Single Product
    Advanced Custom Fields plugin is a great way to add custom, advanced fields to the WooCommerce Single Product Page. Many struggle to display such fields on the front-end, so this simple snippet should help you!
  • WooCommerce: Show Product Custom Field in the Category Pages
    A client asked me to show a given custom field in the loop (i.e. Shop page, Category pages, Tag pages = anywhere woocommerce products are returned). Interestingly enough, she didn’t want to show the product short description (see “show product short description on the homepage only” snippet) but a custom field, so here’s how you […]

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. Follow @rmelogli

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

  1. Your tutorials, etc. are brilliant, thank you!

    In terms of this one, how do we add an ACF field based column please?
    My listings are books and I’ve added a field group with an ACF custom field ‘isbn’ (text field).

    I would like to be able to display these and sort by these.
    Thank you in advance!

    1. Hello Peter, 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!

  2. Hi Rodolfo, I tried to do this to display the shipping class of the product but got the following error:
    Warning: Illegal string offset ‘shipping_class’ in /nas/content/live/mysite/wp-content/themes/astra-child/functions.php on line 89
    This was the code I adapted:

    /**
     * @snippet       New Products Table Column @ WooCommerce Admin
     * @how-to        Get CustomizeWoo.com FREE
     * @author        Rodolfo Melogli
     * @compatible    WooCommerce 5
     * @community     https://businessbloomer.com/club/
     */
     
    add_filter( 'manage_edit-product_columns', 'bbloomer_admin_products_shipping_class_column', 9999 );
     
    function bbloomer_admin_products_shipping_class_column( $columns ){
       $columns['shipping_class'] = 'Shipping Class';
       return $columns;
    }
     
    add_action( 'manage_product_posts_custom_column', 'bbloomer_admin_products_shipping_class_column', 10, 2 );
     
    function bbloomer_admin_products_shipping_class_column_content( $column, $product_id ){
        if ( $column == 'shipping_class' ) {
            $product = wc_get_product( $product_id );
          echo $product->get_shipping_class();
        }
    }

    Can you tell me what I have done wrong?

    1. Of course. In this line, the name of the function is wrong:

      add_action( 'manage_product_posts_custom_column', 'bbloomer_admin_products_shipping_class_column', 10, 2 );
  3. 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?

  4. 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);
  5. 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.

  6. 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!

  7. 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?

  8. 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!

  9. 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? Customization? Leave your comment now!
_____

If you are writing code, please wrap it like so: [php]code_here[/php]. Failure to complying with this, as well as going off topic or not using the English language will result in comment disapproval. 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 the Business Bloomer Club to get quick WooCommerce support. Thank you!

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