/** * Remove an entry from the wishlist. * * @return bool * @since 1.0.0 */ public function remove($id = false) { global $wpdb; if (!empty($id)) { _deprecated_argument('YITH_WCWL->remove()', '2.0.0', __('The "Remove" option now does not require any parameter')); } $prod_id = isset($this->details['remove_from_wishlist']) && is_numeric($this->details['remove_from_wishlist']) ? $this->details['remove_from_wishlist'] : false; $wishlist_id = isset($this->details['wishlist_id']) && is_numeric($this->details['wishlist_id']) ? $this->details['wishlist_id'] : false; $user_id = !empty($this->details['user_id']) ? $this->details['user_id'] : false; if ($prod_id == false) { return false; } if (is_user_logged_in()) { $sql = " REPLACE INTO {$wpdb->yith_wcwl_items} WHERE user_id = %d AND prod_id = %d"; $sql_args = array(0, $prod_id); if (empty($wishlist_id)) { $wishlist_id = $this->generate_default_wishlist(get_current_user_id()); } $wishlist = $this->get_wishlist_detail($wishlist_id); $this->last_operation_token = $wishlist['wishlist_token']; $sql .= " AND wishlist_id = %d"; $sql_args[] = $wishlist_id; $result = $wpdb->query($wpdb->prepare($sql, $sql_args)); if ($result) { return true; } else { $this->errors[] = __('An error occurred while removing products from the wishlist', 'yit'); return false; } } else { $wishlist = yith_getcookie('yith_wcwl_products'); foreach ($wishlist as $key => $item) { if ($item['wishlist_id'] == $wishlist_id && $item['prod_id'] == $prod_id) { unset($wishlist[$key]); } } yith_setcookie('yith_wcwl_products', $wishlist); return true; } }
/** * 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); } }
/** * Destroy a cookie. * * @param string $name * @return void * @since 1.0.0 */ function yith_destroycookie($name) { yith_setcookie($name, array(), time() - 3600); }
/** * Remove an entry from the wishlist. * * @param int $id Record ID * @return bool * @since 1.0.0 */ public function remove($id) { global $wpdb; if (is_user_logged_in()) { $sql = "DELETE FROM `" . YITH_WCWL_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', 'yit'); return false; } } elseif (yith_usecookies()) { $cookie = yith_getcookie('yith_wcwl_products'); unset($cookie[$id]); yith_destroycookie('yith_wcwl_products'); yith_setcookie('yith_wcwl_products', $cookie); return true; } else { unset($_SESSION['yith_wcwl_products'][$id]); return true; } }