Setting a Custom Cookie in WordPress only for Logged In Customer/User (non-admin)

I want to create a custom cookie with custom name only for customers who have once logged in. It should be created after they successfully logged in. It should be deleted after they logged out completely. I am using this code below. For some reason it is not working. Can someone throw some light?

    // To Add Cookie
add_action('wp_login', 'add_custom_cookie');
function add_custom_cookie() {
  if(is_user_logged_in()) {
    setcookie('cookie_name', 'cookie value');
  }
}

// To Remove Cookie
add_action('wp_logout', 'remove_custom_cookie');
function remove_custom_cookie() {
  setcookie('cookie_name', 'cookie value');
}