WC_Customer_Data_Store_Session::set_defaults()
Set default values for the customer object if props are unset.
Method of the class: WC_Customer_Data_Store_Session{}
No Hooks.
Return
null
. Nothing (null).
Usage
// protected - for code of main (parent) or child class $result = $this->set_defaults( $customer );
- $customer(WC_Customer) (required) (passed by reference — &)
- Customer object.
WC_Customer_Data_Store_Session::set_defaults() WC Customer Data Store Session::set defaults code WC 9.3.3
protected function set_defaults( &$customer ) { try { $default = wc_get_customer_default_location(); $has_shipping_address = $customer->has_shipping_address(); if ( ! $customer->get_billing_country() ) { $customer->set_billing_country( $default['country'] ); } if ( ! $customer->get_shipping_country() && ! $has_shipping_address ) { $customer->set_shipping_country( $customer->get_billing_country() ); } if ( ! $customer->get_billing_state() ) { $customer->set_billing_state( $default['state'] ); } if ( ! $customer->get_shipping_state() && ! $has_shipping_address ) { $customer->set_shipping_state( $customer->get_billing_state() ); } if ( ! $customer->get_billing_email() && is_user_logged_in() ) { $current_user = wp_get_current_user(); $customer->set_billing_email( $current_user->user_email ); } } catch ( WC_Data_Exception $e ) { // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedCatch } }