WordPress at Your Fingertips
function is not described

WC_Customer_Data_Store_Session::read() public WC 3.0.0

Read customer data from the session unless the user has logged in, in which case the stored ID will differ from the actual ID.

{} It's a method of the class: WC_Customer_Data_Store_Session{}

No Hooks.

Return

null. Nothing.

Usage

$WC_Customer_Data_Store_Session = new WC_Customer_Data_Store_Session();
$WC_Customer_Data_Store_Session->read( $customer );
$customer(WC_Customer) (required) (passed by reference — &)
Customer object.

Changelog

Since 3.0.0 Introduced.

Code of WC_Customer_Data_Store_Session::read() WC 5.8.0

public function read( &$customer ) {
	$data = (array) WC()->session->get( 'customer' );

	/**
	 * There is a valid session if $data is not empty, and the ID matches the logged in user ID.
	 *
	 * If the user object has been updated since the session was created (based on date_modified) we should not load the session - data should be reloaded.
	 */
	if ( isset( $data['id'], $data['date_modified'] ) && $data['id'] === (string) $customer->get_id() && $data['date_modified'] === (string) $customer->get_date_modified( 'edit' ) ) {
		foreach ( $this->session_keys as $session_key ) {
			if ( in_array( $session_key, array( 'id', 'date_modified' ), true ) ) {
				continue;
			}
			$function_key = $session_key;
			if ( 'billing_' === substr( $session_key, 0, 8 ) ) {
				$session_key = str_replace( 'billing_', '', $session_key );
			}
			if ( isset( $data[ $session_key ] ) && is_callable( array( $customer, "set_{$function_key}" ) ) ) {
				$customer->{"set_{$function_key}"}( wp_unslash( $data[ $session_key ] ) );
			}
		}
	}
	$this->set_defaults( $customer );
	$customer->set_object_read( true );
}