WC_Customer_Data_Store::read()
Method to read a customer object.
Method of the class: WC_Customer_Data_Store{}
Hooks from the method
Return
null
. Nothing (null).
Usage
$WC_Customer_Data_Store = new WC_Customer_Data_Store(); $WC_Customer_Data_Store->read( $customer );
- $customer(WC_Customer) (required) (passed by reference — &)
- Customer object.
Changelog
Since 3.0.0 | Introduced. |
WC_Customer_Data_Store::read() WC Customer Data Store::read code WC 9.4.2
public function read( &$customer ) { $user_object = $customer->get_id() ? get_user_by( 'id', $customer->get_id() ) : false; // User object is required. if ( ! $user_object || empty( $user_object->ID ) ) { throw new Exception( __( 'Invalid customer.', 'woocommerce' ) ); } $customer_id = $customer->get_id(); // Load meta but exclude deprecated props and parent keys. $user_meta = array_diff_key( array_change_key_case( array_map( 'wc_flatten_meta_callback', get_user_meta( $customer_id ) ) ), array_flip( array( 'country', 'state', 'postcode', 'city', 'address', 'address_2', 'default', 'location' ) ), array_change_key_case( (array) $user_object->data ) ); $customer->set_props( $user_meta ); $customer->set_props( array( 'is_paying_customer' => get_user_meta( $customer_id, 'paying_customer', true ), 'email' => $user_object->user_email, 'username' => $user_object->user_login, 'display_name' => $user_object->display_name, 'date_created' => $user_object->user_registered, // Mysql string in local format. 'date_modified' => get_user_meta( $customer_id, 'last_update', true ), 'role' => ! empty( $user_object->roles[0] ) ? $user_object->roles[0] : 'customer', ) ); $customer->read_meta_data(); $customer->set_object_read( true ); do_action( 'woocommerce_customer_loaded', $customer ); }