WC_REST_Customers_V2_Controller::get_formatted_item_data_core()protectedWC 1.0

Get formatted item data, not including orders count nor total spent. This method is needed because v3 API doesn't return those two fields.

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

Хуков нет.

Возвращает

Массив.

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

// protected - в коде основоного (родительского) или дочернего класса
$result = $this->get_formatted_item_data_core( $object );
$object(WC_Data) (обязательный)
WC_Data instance.

Код WC_REST_Customers_V2_Controller::get_formatted_item_data_core() WC 7.3.0

protected function get_formatted_item_data_core( $object ) {
	$data        = $object->get_data();
	$format_date = array( 'date_created', 'date_modified' );

	// Format date values.
	foreach ( $format_date as $key ) {
		// Date created is stored UTC, date modified is stored WP local time.
		$datetime              = 'date_created' === $key ? get_date_from_gmt( gmdate( 'Y-m-d H:i:s', $data[ $key ]->getTimestamp() ) ) : $data[ $key ];
		$data[ $key ]          = wc_rest_prepare_date_response( $datetime, false );
		$data[ $key . '_gmt' ] = wc_rest_prepare_date_response( $datetime );
	}

	$formatted_data = array(
		'id'                 => $object->get_id(),
		'date_created'       => $data['date_created'],
		'date_created_gmt'   => $data['date_created_gmt'],
		'date_modified'      => $data['date_modified'],
		'date_modified_gmt'  => $data['date_modified_gmt'],
		'email'              => $data['email'],
		'first_name'         => $data['first_name'],
		'last_name'          => $data['last_name'],
		'role'               => $data['role'],
		'username'           => $data['username'],
		'billing'            => $data['billing'],
		'shipping'           => $data['shipping'],
		'is_paying_customer' => $data['is_paying_customer'],
		'avatar_url'         => $object->get_avatar_url(),
	);

	if ( wc_current_user_has_role( 'administrator' ) ) {
		$formatted_data['meta_data'] = $data['meta_data'];
	}

	return $formatted_data;
}