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 );
}
A friend of mine helped me out with this. Here is the function that I ended up using in case anybody finds it useful:
function new_orders_columns( $columns = array() ) {
// Hide the columns
if( isset($columns['order-total']) ) {
// Unsets the columns which you want to hide
unset( $columns['order-number'] );
unset( $columns['order-date'] );
unset( $columns['order-status'] );
unset( $columns['order-total'] );
unset( $columns['order-actions'] );
}
// Add new columns
$columns['order-number'] = __( 'Reserva', 'Text Domain' );
$columns['reservation-date'] = __( 'Para el día', 'Text Domain' );
$columns['reservation-people'] = __( 'Seréis', 'Text Domain' );
$columns['order-status'] = __( 'Estado de la reserva', 'Text Domain' );
$columns['order-actions'] = __( ' ', 'Text Domain' );
return $columns;
}
add_filter( 'woocommerce_account_orders_columns', 'new_orders_columns' );
Note that it is not necesary to first unset all the columns and then set them again like I did unless you want to change the order in which they apear or insert new columns between the existing ones.
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 );
}
}
You can also check this tutorial for more examples.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With