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');
}
Edit: Using the above code, Cookie is not created at all. BTW, I can manually create cookies just using setcookie(), they work. But, in the code it won't.