本文整理汇总了PHP中yith_setcookie函数的典型用法代码示例。如果您正苦于以下问题:PHP yith_setcookie函数的具体用法?PHP yith_setcookie怎么用?PHP yith_setcookie使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了yith_setcookie函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: remove
/**
* 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;
}
}
示例2: _update_cookies
/**
* 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);
}
}
示例3: yith_destroycookie
/**
* Destroy a cookie.
*
* @param string $name
* @return void
* @since 1.0.0
*/
function yith_destroycookie($name)
{
yith_setcookie($name, array(), time() - 3600);
}
示例4: remove
/**
* 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;
}
}