WC_Customer_Data_Store_Session::read( WC_Customer $customer )
Read customer data from the session unless the user has logged in, in which case the stored ID will differ from the actual ID.
Description Description
Parameters Parameters
- $customer
-
(Required) Customer object.
Source Source
File: includes/data-stores/class-wc-customer-data-store-session.php
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 ); }
Changelog Changelog
Version | Description |
---|---|
3.0.0 | Introduced. |