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']); } } } }
$count = $count[0]['cnt']; } else { $count = 0; } } else { $count = 0; } $total_pages = $count / $per_page; if ($total_pages > 1) { $current_page = max(1, get_query_var('page')); $page_links = paginate_links(array('base' => get_pagenum_link(1) . '%_%', 'format' => '&page=%#%', 'current' => $current_page, 'total' => $total_pages, 'show_all' => true)); } $limit_sql = "LIMIT " . ($current_page - 1) * 1 . ',' . $per_page; if (is_user_logged_in()) { $wishlist = $wpdb->get_results($wpdb->prepare("SELECT * FROM `" . king_WISHLIST_TABLE . "` WHERE `user_id` = %s" . $limit_sql, $user_id), ARRAY_A); } elseif (king_usecookies()) { $wishlist = king_getcookie('king_wishlist_products'); } else { $wishlist = isset($_SESSION['king_wishlist_products']) ? $_SESSION['king_wishlist_products'] : array(); } // Start wishlist page printing if (function_exists('wc_print_notice')) { wc_print_notices(); } else { $woocommerce->show_messages(); } ?> <div id="king-wishlist-messages"></div> <form id="king-wishlist-form" action="<?php echo esc_url($king_wishlist->get_wishlist_url());
/** * Retrieve details of a product in the wishlist. */ public function get_product_details($id) { global $wpdb; if (is_user_logged_in()) { return $wpdb->get_results($wpdb->prepare('SELECT * FROM `' . king_WISHLIST_TABLE . '` WHERE `prod_id` = %d', $id), ARRAY_A); } elseif (king_usecookies()) { $cookie = king_getcookie('king_wishlist_products'); $temp_arr[0] = $cookie[$id]; $temp_arr[0]['prod_id'] = $id; return $temp_arr; } else { $temp_arr[0] = $_SESSION['king_wishlist_products'][$id]; $temp_arr[0]['prod_id'] = $id; return $temp_arr; } return array(); }