So I have two functions. Once returns some information and I am trying to get this to be accessible in my second function but this is currently empty/ Here is my first function code:
function get_current_user_role_custom() {
global $wp_roles;
$current_user = wp_get_current_user();
$roles = $current_user->roles;
$role = array_shift( $roles );
return isset( $wp_roles->role_names[ $role ] ) ? translate_user_role( $wp_roles->role_names[ $role ] ) : FALSE;
}
$user_role = get_current_user_role_custom();
And the second function (which I am trying to use the $user_role
variable in:
function new_customer_registered_send_email_admin() {
//variables
global $user_role;
global $current_user;
$current_user = wp_get_current_user();
ob_start();
do_action('woocommerce_email_header', 'New customer registered');
$email_header = ob_get_clean();
ob_start();
do_action('woocommerce_email_footer');
$email_footer = ob_get_clean();
woocommerce_mail(
get_bloginfo('admin_email'),
get_bloginfo('name').' - New customer registered',
$email_header.'<p>User Role: ' . $user_role . '</p>'.$email_footer
);
}
add_action('new_customer_registered', 'new_customer_registered_send_email_admin');