WC_Session_Handler::get_customer_unique_id()publicWC 5.3.0

Get session unique ID for requests if session is initialized or user ID if logged in. Introduced to help with unit tests.

Method of the class: WC_Session_Handler{}

No Hooks.

Return

String.

Usage

$WC_Session_Handler = new WC_Session_Handler();
$WC_Session_Handler->get_customer_unique_id();

Changelog

Since 5.3.0 Introduced.

WC_Session_Handler::get_customer_unique_id() code WC 8.6.1

public function get_customer_unique_id() {
	$customer_id = '';

	if ( $this->has_session() && $this->_customer_id ) {
		$customer_id = $this->_customer_id;
	} elseif ( is_user_logged_in() ) {
		$customer_id = (string) get_current_user_id();
	}

	return $customer_id;
}