WooCommerce Add Custom Column To Orders Table

WooCommerce orders table showing custom column

Pre-Requisites

There are no pre-requisites in order for you to be able to implement this solution. You will probably wish to show different data to mine as I show payment gateway fees.

How To Implement This Solution?

Simply copy the pre-coded solution to your active theme’s functions.php or preferably the Code Snippets Plugin.

About this Solution

This code snippet allows you to show an additional, custom column to the table showing all of the orders located under WordPress Dashboard > WooCommerce > Orders.

In this example, I show the Payment Gateway fee.

Why? I think it’s absolutely nuts that in the WooCommerce reports, you only see sales turnover and not how much actually lands in your bank.

There’s no way to see profit because the reports don’t take into account the payment gateway fees and after all, revenue is vanity, profit is sanity!

When I launched my WooCommerce Conversion Rate Optimisation (CRO) eBook, I wanted to see how much each payment gateway took.

At the time of launch, I used Stripe and PayPal, the two most common payment gateways.

I knew the fee amount was stored in the wp_postmeta database table (pre HPOS schema) because when drilling down and viewing an order, I could see the fee as a deduction in the totals.

				
					/**
 * Snippet Name:	WooCommerce Add Custom Column To Orders Table
 * Snippet Author:	ecommercehints.com
 */

// Create and show the new orders table column
add_filter( 'manage_edit-shop_order_columns', 'ecommercehints_show_custom_orders_table_column' );
function ecommercehints_show_custom_orders_table_column( $columns ) {
    $columns['payment_gateway_fee'] = 'Payment Gateway Fee';	// The ID and Label shown in the table column header
    return $columns;
}
 
/** 
 * Populate the orders table custom column
 * I have chosen to show the payment gateway fee, either from Stripe or PayPal, both stored in the postmeta table (pre HPOS schema)
 */
add_action( 'manage_shop_order_posts_custom_column', 'ecommercehints_populate_orders_custom_table_column' );
function ecommercehints_populate_orders_custom_table_column( $column ) {
    global $post;
    if ( 'payment_gateway_fee' === $column ) {
        $order = wc_get_order( $post->ID );
		if ($order->get_meta('PayPal Transaction Fee')) {	// If the order was paid with PayPal...
			echo wc_price($order->get_meta('PayPal Transaction Fee'));	// ...Then show the PayPal fee (it's meta key in the postmeta database table is "PayPal Transaction Fee")
		} elseif ($order->get_meta('_stripe_fee')) {	// Or, if the order was paid with Stripe...
			 echo wc_price($order->get_meta('_stripe_fee'));	// ...Then show the Stripe fee (it's meta key in the database table is "_stripe_fee")
		}
    }
}
				
			

Snippet Benefits

  • Add a custom column to the orders table where the screen is: /wp-admin/edit.php?post_type=shop_order
  • Show the Stripe and PayPal payment gateway fees in a new column in the admin orders table.
WooCommerce Conversion Rate Optimisation (CRO) eBook
100 WooCommerce Conversion Rate Optimisation Tips

Leave a Reply

If you are going to write code in the comments, please wrap it between code tags.

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

Other Recent Guides

Subscribe To Emails

Get exclusive WooCommerce tips that I only share with email subscribers

Join hundreds of other subscribers