1 year ago
#368386
Esteban del Aguila
Add custom column with User total spent in woocommerce admin orders
I want to add a column with Customer Total Spent, but I want the sum of users and guest customer. The function Get_total_spent is by registered Customer, i want the guest too.
This is the code that I have:
add_filter( 'manage_edit-shop_order_columns', 'bbloomer_add_another_order_admin_list_column' );
function bbloomer_add_another_order_admin_list_column( $columns ) {
$columns['total_spent'] = 'Historical Spent';
return $columns;
}
add_action( 'manage_shop_order_posts_custom_column', 'bbloomer_add_another_order_admin_list_column_content' );
function bbloomer_add_another_order_admin_list_column_content( $column ) {
global $post;
if ( 'total_spent' === $column ) {
$order = wc_get_order( $post->ID );
$user_id = (int)$order->user_id;
$customer = new WC_Customer( $user_id );
echo $customer->get_total_spent();
}
}
wordpress
woocommerce
orders
0 Answers
Your Answer