WooCommerce not letting me add custom column to shop_order post type WooCommerce not letting me add custom column to shop_order post type wordpress wordpress

WooCommerce not letting me add custom column to shop_order post type


I encountered a similar issue when adding a custom column to the WooCommerce Orders overview page from my theme's functions.php file. I was able to get a custom column to show up by increasing the filter priority above the default value of 10. Try replacing your code with the following:

add_filter('manage_edit-shop_order_columns', 'add_sales_column', 11);    function add_sales_column($columns) {    $columns['order_sales'] = "Sales";    return $columns;}

Tested on WP 3.9.1 and WC 2.1.12.

Check out the WordPress Codex entry on add_filter for more details on the behavior of filters using the $priority parameter.


The problem is that we have to wait for WooCommerce to finish its setup. This goes two ways, first running all our hooks inside a plugins_loaded main hook, and then setting the priority of our hooks for something greater than WC's.

add_action( 'plugins_loaded', 'setup_so_22237380' );function setup_so_22237380() {    // Just to make clear how the filters work    $posttype = "shop_order";    // Priority 20, with 1 parameter (the 1 here is optional)    add_filter( "manage_edit-{$posttype}_columns", 'column_set_so_22237380', 20, 1 );     // Priority 20, with 2 parameters    add_action( "manage_{$posttype}_posts_custom_column", 'column_display_so_22237380', 20, 2 );     // Default priority, default parameters (zero or one)    add_filter( "manage_edit-{$posttype}_sortable_columns", 'column_sort_so_22237380' ); }function column_set_so_22237380( $columns ){    $columns['order_sales'] = "Sales";    return $columns;}function column_display_so_22237380( $column_name, $post_id ) {    if ( 'order_sales' != $column_name )        return;    $sales_information = 'Your custom get_order_sales_information($post_id)';    if ( $sales_information )        echo "<strong style='color:#f00;'> $sales_information </strong>";}function column_sort_so_22237380( $columns ) {    $columns['order_sales'] = 'order_sales';    return $columns;}

Setting the column as sortable is optional (manage_edit-{$posttype}_sortable_columns) and needs an extra action hook to make it work (pre_get_posts). This may be a complex function to build and requires its own research.


It will working fine if you include all the order hook on

add_action( 'admin_init', 'setup_all_order_column_hook' );function setup_all_order_column_hook(){ //Just to make clear how the filters work    $posttype = "shop_order";//Priority 20, with 1 parameter (the 1 here is optional)add_filter( "manage_edit-{$posttype}_columns", 'column_set_so_22237380', 20, 1 ); //Priority 20, with 2 parametersadd_action( "manage_{$posttype}_posts_custom_column",column_display_so_22237380', 20, 2 ); // Default priority, default parameters (zero or one)add_filter( "manage_edit-{$posttype}_sortable_columns",'column_sort_so_22237380' ); }