Cart::set_cart_hash_cookie( $value = '' )
Sets the cart hash cookie or resets the cookie.
Return
(boolean)
Source
File: src/Tickets/Commerce/Cart.php
public function set_cart_hash_cookie( $value = '' ) {
if ( headers_sent() ) {
return false;
}
/**
* Filters the life span of the Cart Cookie.
*
* @since 5.1.9
*
* @param int $expires The expiry time, as passed to setcookie().
*/
$expire = apply_filters( 'tec_tickets_commerce_cart_expiration', time() + 1 * HOUR_IN_SECONDS );
$referer = wp_get_referer();
if ( $referer ) {
$secure = ( 'https' === parse_url( $referer, PHP_URL_SCHEME ) );
} else {
$secure = false;
}
// When null means we are deleting.
if ( null === $value ) {
$expire = 1;
}
$is_cookie_set = setcookie( static::$cart_hash_cookie_name, $value, $expire, COOKIEPATH ?: '/', COOKIE_DOMAIN, $secure );
// Overwrite local variable so we can use it right away.
$_COOKIE[ static::$cart_hash_cookie_name ] = $value;
return $is_cookie_set;
}
Changelog
| Version | Description |
|---|---|
| 5.1.9 | Introduced. |