WC_Cart_Session::set_cart_cookies
Set cart hash cookie and items in cart if not already set.
Method of the class: WC_Cart_Session{}
Hooks from the method
Returns
null. Nothing (null).
Usage
// private - for code of main (parent) class only $result = $this->set_cart_cookies( $set );
- $set(true|false)
- Should cookies be set (true) or unset.
Default:true
WC_Cart_Session::set_cart_cookies() WC Cart Session::set cart cookies code WC 10.7.0
private function set_cart_cookies( $set = true ) {
if ( $set ) {
$setcookies = array(
'woocommerce_items_in_cart' => '1',
'woocommerce_cart_hash' => WC()->cart->get_cart_hash(),
);
foreach ( $setcookies as $name => $value ) {
if ( ! isset( $_COOKIE[ $name ] ) || $_COOKIE[ $name ] !== $value ) {
wc_setcookie( $name, $value );
$_COOKIE[ $name ] = $value;
}
}
} else {
$unsetcookies = array(
'woocommerce_items_in_cart',
'woocommerce_cart_hash',
);
foreach ( $unsetcookies as $name ) {
if ( isset( $_COOKIE[ $name ] ) ) {
wc_setcookie( $name, 0, time() - HOUR_IN_SECONDS );
unset( $_COOKIE[ $name ] );
}
}
}
do_action( 'woocommerce_set_cart_cookies', $set );
}