I have created a custom column for WordPress users called "Verification". Upon WooCommerce registration, an email is sent to the user asking them to verify their email and that way, account. This information is stored in the database under usermeta (wp_usermeta)
as a meta_key and that key is called is_activated
.
Here is the code for the custom column:
add_action('manage_users_columns','account_verification_status_column');
function account_verification_status_column($column_headers) {
unset($column_headers['posts']);
$column_headers['account_verification'] = 'Verification Status';
return $column_headers;
}
function make_verification_status_column_sortable( $columns ) {
$columns['account_verification'] = 'Verification Status';
return $columns;
}
add_filter( 'manage_users_sortable_columns', 'make_verification_status_column_sortable' );
I am now trying to figure out how to fetch data from the usermeta table and in this case, the meta_key
is_activated
. Here is what I tried:
add_action('manage_users_custom_column', 'account_verification_information', 10, 3);
function account_verification_information($status = '1') {
global $wpdb;
$has_user_verified = $wpdb->get_var( $wpdb->prepare(
"SELECT COUNT(*) FROM $wpdb->users
LEFT JOIN $wpdb->usermeta ON $wpdb->users.ID = $wpdb->usermeta.user_id
WHERE meta_key = 'is_activated'
AND meta_value = '$status';"
, $level ));
return $has_user_verified;
$check_verification = account_verification_information(1);
if ( $column_name === account_verification ) {
echo $check_verification;
} else {
echo '<span class="na">Not yet Verified</span>';
}
}
Hopefully, by looking at it, you "get the idea". I need it to show "Verified" if the value is 1 and "Not Verified" if the value is 0.
I've tried so many different versions of this I am getting lost..
Any help is highly appreciated.
Try the following instead:
Code goes in function.php file of your active child theme (active theme). Tested and works.