WC_Customer_Data_Store_Session::set_defaults()protectedWC 1.0

Set default values for the customer object if props are unset.

Метод класса: WC_Customer_Data_Store_Session{}

Хуков нет.

Возвращает

null. Ничего (null).

Использование

// protected - в коде основоного (родительского) или дочернего класса
$result = $this->set_defaults( $customer );
$customer(WC_Customer) (обязательный) (передается по ссылке — &)
Customer object.

Код WC_Customer_Data_Store_Session::set_defaults() WC 8.7.0

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