WordPress at Your Fingertips
function is not described

WC_Customer_Data_Store_Session::set_defaults() protected WC 1.0

Load default values if props are unset.

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

No Hooks.

Return

null. Nothing.

Usage

// protected - for code of main (parent) or child class
$result = $this->set_defaults( $customer );
$customer(WC_Customer) (required) (passed by reference — &)
Customer object.

Code of WC_Customer_Data_Store_Session::set_defaults() WC 5.7.1

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
	}
}