On my WooCommerce Orders page ( wp-admin/admin.php?page=wc-orders ), I need to add a new custom column.
Based on these answers, this is my code:
function sss_add_column_to_orders_tabls( $columns ) {
$columns['my_test'] = "My Test";
return $columns;
}
add_filter( 'manage_edit-shop_order_columns', 'sss_add_column_to_orders_tabls' );
But the new “My Test” column is not added to the Orders table.
What could be wrong?
0
Just found the solution thanks to this page.
function sss_add_column_to_orders_table( $columns ) {
$columns['my_new_col'] = "My Column Header";
return $columns;
}
add_filter( 'manage_woocommerce_page_wc-orders_columns', 'sss_add_column_to_orders_table' );
The change in WooCommerce is due to HPOS (High-Performance Order Storage) which has been turned on by default for new stores since WC 8.2.
Incidentally, the accompanying code to populate the new column is:
function sss_populate_column_in_orders_table( $column, $wc_order_obj ) {
if ( $column === 'my_new_col' ) {
echo 'My column data';
}
}
add_action( 'manage_woocommerce_page_wc-orders_custom_column' , 'sss_populate_column_in_orders_table', 10, 2 );