public function init() { global $king_wishlist; if (is_user_logged_in()) { $king_wishlist->details['user_id'] = get_current_user_id(); //check whether any products are added to wishlist, then after login add to the wishlist if not added if (king_usecookies()) { $cookie = king_getcookie('king_wishlist_products'); foreach ($cookie as $details) { $king_wishlist->details = $details; $king_wishlist->details['user_id'] = get_current_user_id(); $ret_val = $king_wishlist->add(); } king_destroycookie('king_wishlist_products'); } else { if (isset($_SESSION['king_wishlist_products'])) { foreach ($_SESSION['king_wishlist_products'] as $details) { $king_wishlist->details = $details; $king_wishlist->details['user_id'] = get_current_user_id(); $ret_val = $king_wishlist->add(); } unset($_SESSION['king_wishlist_products']); } } } }
/** * Remove an entry from the wishlist. */ public function remove($id) { global $wpdb; if (is_user_logged_in()) { $sql = "DELETE FROM `" . king_WISHLIST_TABLE . "` WHERE `ID` = " . $id . " AND `user_id` = " . $this->details['user_id']; if ($wpdb->query($sql)) { return true; } else { $this->errors[] = __('Error occurred while removing product from wishlist', 'king'); return false; } } elseif (king_usecookies()) { $cookie = king_getcookie('king_wishlist_products'); unset($cookie[$id]); king_destroycookie('king_wishlist_products'); king_setcookie('king_wishlist_products', $cookie); return true; } else { unset($_SESSION['king_wishlist_products'][$id]); return true; } }