/** * Retrieve elements of the wishlist for a specific user * * @return array * @since 2.0.0 */ public function get_products($args = array()) { global $wpdb; $default = array('user_id' => is_user_logged_in() ? get_current_user_id() : false, 'product_id' => false, 'wishlist_id' => false, 'wishlist_token' => false, 'wishlist_visibility' => 'all', 'is_default' => false, 'id' => false, 'limit' => false, 'offset' => 0); $args = wp_parse_args($args, $default); extract($args); if (!empty($user_id) || !empty($wishlist_token)) { $sql = "SELECT *\r\n FROM `{$wpdb->yith_wcwl_items}` AS i\r\n LEFT JOIN {$wpdb->yith_wcwl_wishlists} AS l ON l.`ID` = i.`wishlist_id` WHERE 1"; if (!empty($user_id)) { $sql .= " AND i.`user_id` = %d"; $sql_args = array($user_id); } if (!empty($product_id)) { $sql .= " AND i.`prod_id` = %d"; $sql_args[] = $product_id; } if (!empty($wishlist_id)) { $sql .= " AND i.`wishlist_id` = %d"; $sql_args[] = $wishlist_id; } elseif (empty($wishlist_id) && empty($wishlist_token) && $is_default != 1) { $sql .= " AND i.`wishlist_id` IS NULL"; } if (!empty($wishlist_token)) { $sql .= " AND l.`wishlist_token` = %s"; $sql_args[] = $wishlist_token; } if (!empty($wishlist_visibility) && $wishlist_visibility != 'all') { switch ($wishlist_visibility) { case 'visible': $sql .= " AND ( l.`wishlist_privacy` = %d OR l.`wishlist_privacy` = %d )"; $sql_args[] = 0; $sql_args[] = 1; break; case 'public': $sql .= " AND l.`wishlist_privacy` = %d"; $sql_args[] = 0; break; case 'shared': $sql .= " AND l.`wishlist_privacy` = %d"; $sql_args[] = 1; break; case 'private': $sql .= " AND l.`wishlist_privacy` = %d"; $sql_args[] = 2; break; default: $sql .= " AND l.`wishlist_privacy` = %d"; $sql_args[] = 0; break; } } if ($is_default !== false) { if (!empty($user_id)) { $this->generate_default_wishlist($user_id); } $sql .= " AND l.`is_default` = %d"; $sql_args[] = $is_default; } if (!empty($id)) { $sql .= " AND `i.ID` = %d"; $sql_args[] = $id; } if (!empty($limit)) { $sql .= " LIMIT " . $offset . ", " . $limit; } $wishlist = $wpdb->get_results($wpdb->prepare($sql, $sql_args), ARRAY_A); } else { $wishlist = yith_getcookie('yith_wcwl_products'); foreach ($wishlist as $key => $cookie) { if (!empty($product_id) && $cookie['prod_id'] != $product_id) { unset($wishlist[$key]); } if (!empty($wishlist_id) && $wishlist_id != 'all' && $cookie['wishlist_id'] != $wishlist_id) { unset($wishlist[$key]); } } if (!empty($limit)) { $wishlist = array_slice($wishlist, $offset, $limit); } } return $wishlist; }
/** * Update old wishlist cookies * * @return void * @since 2.0.0 */ private function _update_cookies() { $cookie = yith_getcookie('yith_wcwl_products'); $new_cookie = array(); if (!empty($cookie)) { foreach ($cookie as $item) { if (!isset($item['add-to-wishlist'])) { return; } $new_cookie[] = array('prod_id' => $item['add-to-wishlist'], 'quantity' => isset($item['quantity']) ? $item['quantity'] : 1, 'wishlist_id' => false); } yith_setcookie('yith_wcwl_products', $new_cookie); } }
$limit_sql = ''; $pagination = 'no'; if ($pagination == 'yes') { $count = array(); if (is_user_logged_in() || isset($user_id) && !empty($user_id)) { $count = $wpdb->get_results($wpdb->prepare('SELECT COUNT(*) as `cnt` FROM `' . YITH_WCWL_TABLE . '` WHERE `user_id` = %d', $user_id), ARRAY_A); $count = $count[0]['cnt']; } elseif (yith_usecookies()) { $count[0]['cnt'] = count(yith_getcookie('yith_wcwl_products')); } else { $count[0]['cnt'] = count($_SESSION['yith_wcwl_products']); } $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() || isset($user_id) && !empty($user_id)) { $wishlist = $wpdb->get_results($wpdb->prepare("SELECT * FROM `" . YITH_WCWL_TABLE . "` WHERE `user_id` = %s" . $limit_sql, $user_id), ARRAY_A); } elseif (yith_usecookies()) { $wishlist = yith_getcookie('yith_wcwl_products'); } else { $wishlist = isset($_SESSION['yith_wcwl_products']) ? $_SESSION['yith_wcwl_products'] : array(); } if (count($wishlist) > 0) { echo '<li class="mini-tools-wishlist"><a href="' . $yith_wcwl->get_wishlist_url() . '"><i class="fa fa-heart"></i><span class="amount">' . count($wishlist) . '</span></a></li>'; } else { echo '<li class="mini-tools-wishlist"><a href="' . $yith_wcwl->get_wishlist_url() . '"><i class="fa fa-heart"></i></a></li>'; }
function thb_wishlist_count() { if (is_user_logged_in()) { $user_id = get_current_user_id(); } $count = array(); if (class_exists('YITH_WCWL_UI')) { if (is_user_logged_in()) { $count = $wpdb->get_results($wpdb->prepare('SELECT COUNT(*) as `cnt` FROM `' . YITH_WCWL_TABLE . '` WHERE `user_id` = %d', $user_id), ARRAY_A); $count = $count[0]['cnt']; } elseif (yith_usecookies()) { $count[0]['cnt'] = count(yith_getcookie('yith_wcwl_products')); } else { $count[0]['cnt'] = count($_SESSION['yith_wcwl_products']); } if (is_array($count)) { $count = 0; } } return $count; }
/** * Initiator method. Initiate properties. * * @return void * @access private * @since 1.0.0 */ public function init() { global $yith_wcwl; $db_colors = get_option('yith_wcwl_frontend_css_colors'); $this->colors_options = !empty($db_colors) ? maybe_unserialize($db_colors) : apply_filters('yith_wcwl_colors_options', array('add_to_wishlist' => array('background' => '#4F4F4F', 'color' => '#FFFFFF', 'border_color' => '#4F4F4F'), 'add_to_wishlist_hover' => array('background' => '#2F2F2F', 'color' => '#FFFFFF', 'border_color' => '#2F2F2F'), 'add_to_cart' => array('background' => '#4F4F4F', 'color' => '#FFFFFF', 'border_color' => '#4F4F4F'), 'add_to_cart_hover' => array('background' => '#2F2F2F', 'color' => '#FFFFFF', 'border_color' => '#2F2F2F'), 'wishlist_table' => array('background' => '#FFFFFF', 'color' => '#676868', 'border_color' => '#676868'))); if (empty($db_colors)) { update_option('yith_wcwl_frontend_css_colors', maybe_serialize($this->colors_options)); } $this->rules = apply_filters('yith_wcwl_colors_rules', array('add_to_wishlist' => '.woocommerce .yith-wcwl-add-button > a.button.alt', 'add_to_wishlist_hover' => '.woocommerce .yith-wcwl-add-button > a.button.alt:hover', 'add_to_cart' => '.woocommerce .wishlist_table a.add_to_cart.button.alt', 'add_to_cart_hover' => '.woocommerce .wishlist_table a.add_to_cart.button.alt:hover', 'wishlist_table' => '.wishlist_table')); if (is_user_logged_in()) { $yith_wcwl->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 (yith_usecookies()) { $cookie = yith_getcookie('yith_wcwl_products'); foreach ($cookie as $details) { $yith_wcwl->details = $details; $yith_wcwl->details['user_id'] = get_current_user_id(); $ret_val = $yith_wcwl->add(); } yith_destroycookie('yith_wcwl_products'); } else { if (isset($_SESSION['yith_wcwl_products'])) { foreach ($_SESSION['yith_wcwl_products'] as $details) { $yith_wcwl->details = $details; $yith_wcwl->details['user_id'] = get_current_user_id(); $ret_val = $yith_wcwl->add(); } unset($_SESSION['yith_wcwl_products']); } } } wp_register_style('yith-wcwl-admin', YITH_WCWL_URL . 'assets/css/admin.css'); }
function ktz_get_wishlist() { global $wpdb, $yith_wcwl, $woocommerce; $wishlist_output = ""; if (is_user_logged_in()) { $user_id = get_current_user_id(); } $count = array(); if (is_user_logged_in()) { $count = $wpdb->get_results($wpdb->prepare('SELECT COUNT(*) as `cnt` FROM `' . YITH_WCWL_TABLE . '` WHERE `user_id` = %d', $user_id), ARRAY_A); $count = $count[0]['cnt']; } elseif (yith_usecookies()) { $count[0]['cnt'] = count(yith_getcookie('yith_wcwl_products')); $count = $count[0]['cnt']; } else { $count[0]['cnt'] = count($_SESSION['yith_wcwl_products']); $count = $count[0]['cnt']; } if (is_array($count)) { $count = 0; } $wishlist_output .= '<div class="ktz-cart-wrap login-block"><span class="ktz-wishlist-head"><a class="wishlist-link" href="' . $yith_wcwl->get_wishlist_url() . '" title="' . __("View your wishlist", ktz_theme_textdomain) . '"><span class="ktz-cart-button"> </span><span class="glyphicon glyphicon-star-empty"></span> <span id="wishlist_item_count">' . $count . '</span></a></span>'; $wishlist_output .= '<div class="ktz-wishlist-wrapper">'; $current_page = 1; $limit_sql = ''; $count_limit = 0; if (is_user_logged_in()) { $wishlist = $wpdb->get_results($wpdb->prepare("SELECT * FROM `" . YITH_WCWL_TABLE . "` WHERE `user_id` = %s" . $limit_sql, $user_id), ARRAY_A); } elseif (yith_usecookies()) { $wishlist = yith_getcookie('yith_wcwl_products'); } else { $wishlist = isset($_SESSION['yith_wcwl_products']) ? $_SESSION['yith_wcwl_products'] : array(); } do_action('yith_wcwl_before_wishlist_title'); $wishlist_title = get_option('yith_wcwl_wishlist_title'); if (!empty($wishlist_title)) { $wishlist_output .= '<div class="ktz-wishlist-titlehead">' . $wishlist_title . '</div>'; } $wishlist_output .= do_action('yith_wcwl_before_wishlist'); if (count($wishlist) > 0) { foreach ($wishlist as $values) { if ($count_limit < 4) { if (!is_user_logged_in()) { if (isset($values['add-to-wishlist']) && is_numeric($values['add-to-wishlist'])) { $values['prod_id'] = $values['add-to-wishlist']; $values['ID'] = $values['add-to-wishlist']; } else { $values['prod_id'] = $values['product_id']; $values['ID'] = $values['product_id']; } } $product_obj = get_product($values['prod_id']); if ($product_obj !== false && $product_obj->exists()) { $wishlist_output .= '<div id="wishlist-' . $values['ID'] . '" class="ktz_cart_box clearfix">'; $params = array('width' => 40, 'height' => 40, 'crop' => true); if (has_post_thumbnail($product_obj->id)) { $image_link = wp_get_attachment_url(get_post_thumbnail_id($product_obj->id)); $image = bfi_thumb($image_link, $params); if ($image) { $wishlist_output .= '<a href="' . esc_url(get_permalink(apply_filters('woocommerce_in_cart_product', $values['prod_id']))) . '"><img itemprop="image" src="' . $image . '" width="40" height="40" /></a>'; } } $wishlist_output .= '<div class="ktz_cart_boxcontent">'; $wishlist_output .= '<a href="' . esc_url(get_permalink(apply_filters('woocommerce_in_cart_product', $values['prod_id']))) . '">' . apply_filters('woocommerce_in_cartproduct_obj_title', $product_obj->get_title(), $product_obj) . '</a>'; if (get_option('woocommerce_display_cart_prices_excluding_tax') == 'yes') { $wishlist_output .= '<span class="quantity">' . apply_filters('woocommerce_cart_item_price_html', woocommerce_price($product_obj->get_price_excluding_tax()), $values, '') . '</span>'; } else { $wishlist_output .= '<span class="quantity">' . apply_filters('woocommerce_cart_item_price_html', woocommerce_price($product_obj->get_price()), $values, '') . '</span>'; } $wishlist_output .= '</div>'; $wishlist_output .= '</div>'; } $count_limit++; } } } else { $wishlist_output .= '<div class="empty">' . __('Your wishlist is currently empty.', ktz_theme_textdomain) . '</div>'; } $wishlist_output .= '<div class="cart-buttons">'; $wishlist_output .= '<a href="' . $yith_wcwl->get_wishlist_url() . '" class="cart-button"><i class="glyphicon glyphicon-star-empty"></i> <span class="text">' . __('Go to your wishlist', ktz_theme_textdomain) . '</span></a>'; $wishlist_output .= '</div>'; do_action('yith_wcwl_after_wishlist'); $wishlist_output .= '</div>'; $wishlist_output .= '</div>'; return $wishlist_output; }
function sf_get_wishlist() { global $wpdb, $yith_wcwl, $woocommerce; if (!$yith_wcwl || !$woocommerce) { return; } $wishlist_output = ""; if (is_user_logged_in()) { $user_id = get_current_user_id(); } $wishlist_icon = apply_filters('sf_view_wishlist_icon', '<i class="ss-star"></i>'); $count = array(); if (is_user_logged_in()) { $count = $wpdb->get_results($wpdb->prepare('SELECT COUNT(*) as `cnt` FROM `' . YITH_WCWL_TABLE . '` WHERE `user_id` = %d', $user_id), ARRAY_A); $count = $count[0]['cnt']; } else { $count[0]['cnt'] = count(yith_getcookie('yith_wcwl_products')); $count = $count[0]['cnt']; } if (is_array($count)) { $count = 0; } if (sf_theme_opts_name() == "sf_atelier_options" || sf_theme_opts_name() == "sf_uplift_options") { $wishlist_output .= '<li class="parent wishlist-item"><a class="wishlist-link" href="' . $yith_wcwl->get_wishlist_url() . '" title="' . __("View your wishlist", "swiftframework") . '"><span class="menu-item-title">' . __("Wishlist", "swiftframework") . '</span> ' . apply_filters('sf_wishlist_menu_icon', '<i class="ss-star"></i>') . '<span class="count">' . $count . '</span><span class="star"></span></a>'; } else { $wishlist_output .= '<li class="parent wishlist-item"><a class="wishlist-link" href="' . $yith_wcwl->get_wishlist_url() . '" title="' . __("View your wishlist", "swiftframework") . '">' . apply_filters('sf_wishlist_menu_icon', '<i class="ss-star"></i>') . '<span class="count">' . $count . '</span><span class="star"></span></a>'; } $wishlist_output .= '<ul class="sub-menu">'; $wishlist_output .= '<li>'; $wishlist_output .= '<div class="wishlist-bag">'; $current_page = 1; $limit_sql = ''; $count_limit = 0; if (is_user_logged_in()) { $wishlist = $wpdb->get_results($wpdb->prepare("SELECT * FROM `" . YITH_WCWL_TABLE . "` WHERE `user_id` = %s" . $limit_sql, $user_id), ARRAY_A); } else { $wishlist = yith_getcookie('yith_wcwl_products'); } $wishlist_output .= '<div class="bag-contents">'; $wishlist_output .= do_action('yith_wcwl_before_wishlist'); if (count($wishlist) > 0) { foreach ($wishlist as $values) { if ($count_limit < 3) { if (!is_user_logged_in()) { if (isset($values['add-to-wishlist']) && is_numeric($values['add-to-wishlist'])) { $values['prod_id'] = $values['add-to-wishlist']; $values['ID'] = $values['add-to-wishlist']; } else { if (isset($values['product_id'])) { $values['prod_id'] = $values['product_id']; $values['ID'] = $values['product_id']; } else { $values['ID'] = $values['prod_id']; } } } $product_obj = get_product($values['prod_id']); if ($product_obj !== false && $product_obj->exists()) { $wishlist_output .= '<div id="wishlist-' . $values['ID'] . '" class="bag-product clearfix prod-' . $values['prod_id'] . '">'; if (has_post_thumbnail($product_obj->id)) { $image_link = wp_get_attachment_url(get_post_thumbnail_id($product_obj->id)); $image = wp_get_attachment_image_src(get_post_thumbnail_id($product_obj->id), 'thumbnail'); if ($image) { $wishlist_output .= '<figure><a class="bag-product-img" href="' . esc_url(get_permalink(apply_filters('woocommerce_in_cart_product', $values['prod_id']))) . '"><img itemprop="image" src="' . $image[0] . '" width="' . $image[1] . '" height="' . $image[2] . '" /></a></figure>'; } } $wishlist_output .= '<div class="bag-product-details">'; $wishlist_output .= '<div class="bag-product-title"><a href="' . esc_url(get_permalink(apply_filters('woocommerce_in_cart_product', $values['prod_id']))) . '">' . apply_filters('woocommerce_in_cartproduct_obj_title', $product_obj->get_title(), $product_obj) . '</a></div>'; if (get_option('woocommerce_display_cart_prices_excluding_tax') == 'yes') { $wishlist_output .= '<div class="bag-product-price">' . apply_filters('woocommerce_cart_item_price_html', woocommerce_price($product_obj->get_price_excluding_tax()), $values, '') . '</div>'; } else { $wishlist_output .= '<div class="bag-product-price">' . apply_filters('woocommerce_cart_item_price_html', woocommerce_price($product_obj->get_price()), $values, '') . '</div>'; } $wishlist_output .= '</div>'; $wishlist_output .= '</div>'; } $count_limit++; } } } else { $wishlist_output .= '<div class="wishlist-empty">' . __('Your wishlist is empty.', 'swiftframework') . '</div>'; } $wishlist_output .= '</div>'; if (count($wishlist) > 0) { $wishlist_output .= '<div class="bag-buttons">'; } else { $wishlist_output .= '<div class="bag-buttons no-items">'; } $wishlist_output .= '<a class="sf-button standard sf-icon-reveal wishlist-button" href="' . $yith_wcwl->get_wishlist_url() . '">' . $wishlist_icon . '<span class="text">' . __('View Wishlist', 'swiftframework') . '</span></a>'; $wishlist_output .= '</div>'; $wishlist_output .= '</div>'; $wishlist_output .= '</li>'; $wishlist_output .= '</ul>'; $wishlist_output .= '</li>'; return $wishlist_output; }
function St_wishlist_cookies() { return yith_getcookie('yith_wcwl_products'); }
/** * Retrieve details of a product in the wishlist. * * @param int $id * @param string $request_from * @return array * @since 1.0.0 */ public function get_product_details($id) { global $wpdb; if (is_user_logged_in()) { return $wpdb->get_results($wpdb->prepare('SELECT * FROM `' . YITH_WCWL_TABLE . '` WHERE `prod_id` = %d', $id), ARRAY_A); } elseif (yith_usecookies()) { $cookie = yith_getcookie('yith_wcwl_products'); $temp_arr[0] = $cookie[$id]; $temp_arr[0]['prod_id'] = $id; return $temp_arr; } else { $temp_arr[0] = $_SESSION['yith_wcwl_products'][$id]; $temp_arr[0]['prod_id'] = $id; return $temp_arr; } return array(); }
/** * Retrieve elements of the wishlist for a specific user * * @return array * @since 2.0.0 */ public function get_products($args = array()) { global $wpdb; $default = array('user_id' => is_user_logged_in() ? get_current_user_id() : false, 'product_id' => false, 'wishlist_id' => false, 'wishlist_token' => false, 'wishlist_visibility' => 'all', 'is_default' => false, 'id' => false, 'limit' => false, 'offset' => 0); $args = wp_parse_args($args, $default); extract($args); if (!empty($user_id) || !empty($wishlist_token)) { $sql = "SELECT *\n FROM `{$wpdb->yith_wcwl_items}` AS i\n LEFT JOIN {$wpdb->yith_wcwl_wishlists} AS l ON l.`ID` = i.`wishlist_id`\n INNER JOIN {$wpdb->posts} AS p ON p.ID = i.prod_id\n INNER JOIN {$wpdb->postmeta} AS pm ON pm.post_id = p.ID\n WHERE 1 AND p.post_type = %s AND p.post_status = %s AND pm.meta_key = %s AND pm.meta_value = %s"; $sql_args = array('product', 'publish', '_visibility', 'visible'); if (!empty($user_id)) { $sql .= " AND i.`user_id` = %d"; $sql_args[] = $user_id; } if (!empty($product_id)) { $sql .= " AND i.`prod_id` = %d"; $sql_args[] = $product_id; } if (!empty($wishlist_id)) { $sql .= " AND i.`wishlist_id` = %d"; $sql_args[] = $wishlist_id; } elseif (empty($wishlist_id) && empty($wishlist_token) && $is_default != 1) { $sql .= " AND i.`wishlist_id` IS NULL"; } if (!empty($wishlist_token)) { $sql .= " AND l.`wishlist_token` = %s"; $sql_args[] = $wishlist_token; } if (!empty($wishlist_visibility) && $wishlist_visibility != 'all') { switch ($wishlist_visibility) { case 'visible': $sql .= " AND ( l.`wishlist_privacy` = %d OR l.`wishlist_privacy` = %d )"; $sql_args[] = 0; $sql_args[] = 1; break; case 'public': $sql .= " AND l.`wishlist_privacy` = %d"; $sql_args[] = 0; break; case 'shared': $sql .= " AND l.`wishlist_privacy` = %d"; $sql_args[] = 1; break; case 'private': $sql .= " AND l.`wishlist_privacy` = %d"; $sql_args[] = 2; break; default: $sql .= " AND l.`wishlist_privacy` = %d"; $sql_args[] = 0; break; } } if ($is_default !== false) { if (!empty($user_id)) { $this->generate_default_wishlist($user_id); } $sql .= " AND l.`is_default` = %d"; $sql_args[] = $is_default; } if (!empty($id)) { $sql .= " AND `i.ID` = %d"; $sql_args[] = $id; } if (!empty($limit)) { $sql .= " LIMIT " . $offset . ", " . $limit; } $sql .= " GROUP BY i.prod_id, l.ID"; $wishlist = $wpdb->get_results($wpdb->prepare($sql, $sql_args), ARRAY_A); } else { $wishlist = yith_getcookie('yith_wcwl_products'); foreach ($wishlist as $key => $cookie) { $existing_products = $wpdb->get_col($wpdb->prepare("SELECT ID FROM {$wpdb->posts} AS p LEFT JOIN {$wpdb->postmeta} AS pm ON p.ID = pm.post_id WHERE post_type = %s AND post_status = %s AND pm.meta_key = %s AND pm.meta_value = %s", array('product', 'publish', '_visibility', 'visible'))); if (!in_array($cookie['prod_id'], $existing_products)) { unset($wishlist[$key]); } if (!empty($product_id) && $cookie['prod_id'] != $product_id) { unset($wishlist[$key]); } if (!empty($wishlist_id) && $wishlist_id != 'all' && $cookie['wishlist_id'] != $wishlist_id) { unset($wishlist[$key]); } } if (!empty($limit)) { $wishlist = array_slice($wishlist, $offset, $limit); } } return $wishlist; }