WC_Customer::__construct()publicWC 1.0

Load customer data based on how WC_Customer is called.

If $customer is 'new', you can build a new WC_Customer object. If it's empty, some data will be pulled from the session for the current user/customer.

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

Хуков нет.

Возвращает

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

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

$WC_Customer = new WC_Customer();
$WC_Customer->__construct( $data, $is_session );
$data(WC_Customer|int)
Customer ID or data.
$is_session(true|false)
True if this is the customer session.
По умолчанию: false

Код WC_Customer::__construct() WC 8.7.0

public function __construct( $data = 0, $is_session = false ) {
	parent::__construct( $data );

	if ( $data instanceof WC_Customer ) {
		$this->set_id( absint( $data->get_id() ) );
	} elseif ( is_numeric( $data ) ) {
		$this->set_id( $data );
	}

	$this->data_store = WC_Data_Store::load( 'customer' );

	// If we have an ID, load the user from the DB.
	if ( $this->get_id() ) {
		try {
			$this->data_store->read( $this );
		} catch ( Exception $e ) {
			$this->set_id( 0 );
			$this->set_object_read( true );
		}
	} else {
		$this->set_object_read( true );
	}

	// If this is a session, set or change the data store to sessions. Changes do not persist in the database.
	if ( $is_session && isset( WC()->session ) ) {
		$this->data_store = WC_Data_Store::load( 'customer-session' );
		$this->data_store->read( $this );
	}
}