wc_get_account_formatted_address()WC 3.2.0

Get account formatted address.

Return

String.

Usage

wc_get_account_formatted_address( $address_type, $customer_id );
$address_type(string)
Type of address; 'billing' or 'shipping'.
Default: 'billing'
$customer_id(int)
Customer ID.

Changelog

Since 3.2.0 Introduced.

wc_get_account_formatted_address() code WC 8.7.0

function wc_get_account_formatted_address( $address_type = 'billing', $customer_id = 0 ) {
	$getter  = "get_{$address_type}";
	$address = array();

	if ( 0 === $customer_id ) {
		$customer_id = get_current_user_id();
	}

	$customer = new WC_Customer( $customer_id );

	if ( is_callable( array( $customer, $getter ) ) ) {
		$address = $customer->$getter();
		unset( $address['email'], $address['tel'] );
	}

	return WC()->countries->get_formatted_address( apply_filters( 'woocommerce_my_account_my_address_formatted_address', $address, $customer->get_id(), $address_type ) );
}