For Woocommerce, with the help of this answer thread, I created some custom columns in Back end (Admin) user list:
In the database, there are some meta_key
values called billing_vatnr
and billing_company
coming from the WooCommerce registration form and saved in wp_usermeta
table.
What I'm trying to figure out is how to display the corresponding meta_value
for those meta keys and show them in their respective column for each user.
In other words, in the VAT Nr field, the content of the meta key billing_vatnr
should be displayed and if there is no content, display N/A
. Same for Company Name column with billing_company
.
This is what I've tried so far is:
add_filter('manage_users_custom_column', 'vatnr_status_data', 10, 3);
function vatnr_status_data( $value, $column_name, $user_id ) {
if ( 'account_vatnr' == $column_name ) {
if( $billing_vatnr = get_user_meta( $user_id, 'billing_vatnr', true )) {
echo $billing_vatnr; } else { echo "N/A"; }
}
return $value;
}
But it doesn't work.
Here are the different columns I've added:
// creating the columns
add_action('manage_users_columns','account_verification_status_and_company_columns');
function account_verification_status_and_company_columns($column_headers) {
unset($column_headers['posts']);
$column_headers['account_verification'] = __('Verification Status');
$column_headers['account_vatnr'] = __('VAT Nr');
$column_headers['account_companyname'] = __('Company Name');
return $column_headers;
}
// fetching the verification status, thanks to LoicTheAztec
add_filter('manage_users_custom_column', 'user_account_verification_status_data', 10, 3);
function user_account_verification_status_data( $value, $column_name, $user_id ) {
if ( 'account_verification' == $column_name ) {
if( get_user_meta( $user_id, 'is_activated', true ) == 1 ) {
$value = '<span style="color:green;font-weight:bold;">Verified</span>';
} else {
$value = '<span class="na" style="color:grey;"><em>Not Verified</em></span>';
}
}
return $value;
}
Any help is very much appreciated.