Thanks so much for your reply.
Sorry I didn't explain properly, my fault. I store cart contents in session id like this
PHP Code:
// current session id
$sid = session_id();
// check if the product is already
// in cart table for this session
$sql = "SELECT pd_id
FROM tbl_cart
WHERE pd_id = $productId AND ct_session_id = '$sid'";
$result = dbQuery($sql);
At the moment it deletes cart entries older than one day but I want them to delete immediately once user leaves site, not logs out because users can shop without logging in. How would I achieve this?
PHP Code:
/* Delete all cart entries older than one day*/
function deleteAbandonedCart(){
$yesterday = date('Y-m-d H:i:s', mktime(0,0,0, date('m'),
date('d') - 1, date('Y')));
$sql = "DELETE FROM tbl_cart
WHERE ct_date < '$yesterday'";
dbQuery($sql);
}
The reason I'm asking is when I was testing it, logging in as different users, I was shocked to see the cart from old user was still there.
Bookmarks