I just started writing a plugin and ran into a problem right away. I want to add a column to the order overview page in the WooCommerce admin. The straight forward filter below doesn’t do anything. Replacing shop_order
with post
or product
, however, does show the extra column on the respective overview page.
add_filter('manage_edit-shop_order_columns', 'add_sales_column');
function add_sales_column($columns) {
$columns['order_sales'] = "Sales";
return $columns;
}
Trying this on:
WC Version: 2.1.5
WP Version: 3.8.1
How to solve this?
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: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.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