WC_Cart_Session::maybe_set_cart_cookies()publicWC 3.2.0

Will set cart cookies if needed and when possible.

Headers are only updated if headers have not yet been sent.

Method of the class: WC_Cart_Session{}

No Hooks.

Return

null. Nothing (null).

Usage

$WC_Cart_Session = new WC_Cart_Session();
$WC_Cart_Session->maybe_set_cart_cookies();

Changelog

Since 3.2.0 Introduced.

WC_Cart_Session::maybe_set_cart_cookies() code WC 8.6.1

public function maybe_set_cart_cookies() {
	if ( headers_sent() || ! did_action( 'wp_loaded' ) ) {
		return;
	}
	if ( ! $this->cart->is_empty() ) {
		$this->set_cart_cookies( true );
	} elseif ( isset( $_COOKIE['woocommerce_items_in_cart'] ) ) { // WPCS: input var ok.
		$this->set_cart_cookies( false );
	}
	$this->dedupe_cookies();
}