I am trying to modify the columns in the Woocommerce orders.php table. I would like to get rid of the TOTAL column as well as the DATE column and then I would like to add a new column with some custom information that’s specific to my store.
The following function used to work but has been deprecated since Woocommerce 2.6. So the question is, does anybody know how to delete/add columns to this table after 2.6?
function wc_get_account_orders_columns() {
$columns = apply_filters( 'woocommerce_account_orders_columns', array(
'order-number' => __( 'Order', 'woocommerce' ),
'order-date' => __( 'Date', 'woocommerce' ),
'order-status' => __( 'Status', 'woocommerce' ),
'order-total' => __( 'Total', 'woocommerce' ),
'order-actions' => ' ',
) );
// Deprecated filter since 2.6.0.
return apply_filters( 'woocommerce_my_account_my_orders_columns', $columns );
}
In the other answers it is not mentioned how to populate a column with custom information. So, the complete algorithm is below:
add_filter( 'manage_edit-shop_order_columns','your_function_name');
function your_function_name($columns)
{
// to remove just use unset
unset($columns['order_total']); // remove Total column
unset($columns['order_date']); // remove Date column
// now it is time to add a custom one
$columns['custom_column'] = "Column title";
return $columns;
}
add_action( 'manage_shop_order_posts_custom_column' , 'your_function_name2' );
function your_function_name2( $column ) {
global $the_order; // you can use the global WP_Order object here
// global $post; // is also available here
if( $column == 'custom_column' ) {
// do stuff, ex: get_post_meta( $post->ID, 'key', true );
}
}