Categories: WordPress 1 Comment »

Add Columns to WooCommerce Admin

If you’re running WooCommerce, the Orders screen is a great way to see – at a glance – what’s going on in your store.  However, there’s one thing that it absolutely doesn’t show: the products that people have ordered.

The code below changes that – it gives you a special column in your Orders screen called “Products” and shows a quantity and product name for each product a person has ordered.  Just paste this code into a site-plugin or into your functions.php file:

add_filter( 'manage_edit-shop_order_columns', 'show_product_order',15 );
function show_product_order($columns){

   //add column
   $columns['product-display'] = __( 'Products'); 

   return $columns; 
}

add_action( 'manage_shop_order_posts_custom_column' , 'snv_custom_shop_order_column', 10, 2 );
function snv_custom_shop_order_column( $column ) {
 global $post, $woocommerce, $the_order;

    switch ( $column ) {

        case 'product-display' :
            $terms = $the_order->get_items();

          if ( is_array( $terms ) ) {
                foreach($terms as $term)
        {
        echo $term['item_meta']['_qty'][0] .' x ' . $term['name'] .'
';
        }
              } else {
                _e( 'Unable get the products', 'woocommerce' );
        }
            break;

    }
}

Let’s break it down:

The filter (“show_product_order”) adds a column to the WooCommerce Orders Admin screen.  The column will show up at the end of the other column lists.

The action (“snv_custom_shop_order_column”) adds a function to the “manage_shop_order_posts_custom_column” (whew!) hook in WooCommerce.  It then checks each order listed in the column and looks for a column field called “product-display” – which we defined in the filter above.  It then echoes the quantity and the name for each product listed.

Feel free to modify this as you wish – you can also find a Gist of this on GitHub if you’d rather see it / bookmark it there!

  • Stefan van den Dungen Gronoviu

    Great article on how to do it yourself.
    There is a plugin that allows you to add a products column to the order overview. Along many other useful WooCommerce columns.
    https://www.admincolumns.com/woocommerce-columns/

Let's Get Started!

Ready to start a project with Mitch? Fantastic! Simply fill out the form below and Mitch will get back to you as soon as he's able!

(Please do not contact me about advertising requests or sales pitches unless you have been invited to do so).

Navigation


Contact