EDD Purchases and Lifetime Value in the Users List
Adds "Purchases" and "Lifetime value" columns to Users > All Users from Easy Digital Downloads customer records, so you can spot your best buyers.
Opens WPIDE on
Code
add_filter( 'manage_users_columns', function ( $columns ) {
$columns['wpide_edd_purchases'] = 'Purchases';
$columns['wpide_edd_value'] = 'Lifetime value';
return $columns;
} );
add_filter( 'manage_users_custom_column', function ( $value, $column, $user_id ) {
if ( 'wpide_edd_purchases' !== $column && 'wpide_edd_value' !== $column ) {
return $value;
}
$customer = function_exists( 'edd_get_customer_by' ) ? edd_get_customer_by( 'user_id', $user_id ) : false;
if ( ! $customer ) {
return '–';
}
if ( 'wpide_edd_purchases' === $column ) {
return sprintf( '<a href="%1$s">%2$d</a>', esc_url( admin_url( 'edit.php?post_type=download&page=edd-customers&view=overview&id=' . $customer->id ) ), (int) $customer->purchase_count );
}
return esc_html( html_entity_decode( edd_currency_filter( edd_format_amount( $customer->purchase_value ) ) ) );
}, 10, 3 );
Notes
Users without an EDD customer record show a dash.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.