Reputation: 15
what is the method for add a column in the admin order list with a simple sequential number?
Just add a column with 1 / 2 / 3 / 4 for the single order, just for have a quick view about the number of order with a filter active.
I try with a plugin but I think I need to modify the WooCommerce file of the theme.
Upvotes: 0
Views: 400
Reputation: 683
The order_id in WooCommerce is the id in wp_posts table which is used for many things, posts, pages, orders ... That's why the order ids are rarely in sequence. This means you have to add a separate sequence and keep track of it. There is a plugin that does exactly that: https://wordpress.org/plugins/wt-woocommerce-sequential-order-numbers/
You can configure it to use a numbered sequence or any other custom sequence.
The plugin is storing data into "_order_number" postmeta and replaces the original first column content, like this enter image description here
If you want to see this sequence number in a separate column then you can use a plugin like: https://wordpress.org/plugins/codepress-admin-columns/ to add a custom column with the order number
EDIT: Adding code snippet to show sequential numbers in the first column.
function custom_columns_head_only_shop_order( $columns ) {
$new_columns = array( 'sequential_number' => 'Sequential Number' );
$columns = array_merge( $new_columns, $columns );
return $columns;
}
add_filter( 'manage_edit-shop_order_columns', 'custom_columns_head_only_shop_order', 10 );
function custom_columns_content_only_shop_order( $column_name ) {
if ( $column_name == 'sequential_number' ) {
$paged = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1;
$per_page = get_query_var( 'posts_per_page' );
$offset = ( $paged - 1 ) * $per_page;
global $sequential_number_counter;
if ( ! isset( $sequential_number_counter ) ) {
$sequential_number_counter = 0;
}
$sequential_number_counter++;
echo $offset + $sequential_number_counter;
}
}
add_action( 'manage_shop_order_posts_custom_column', 'custom_columns_content_only_shop_order', 10, 1 );
Upvotes: 1