Automattic\WooCommerce\Blocks\Domain\Services

CheckoutFieldsFrontend::render_address_fields()publicWC 1.0

Renders address fields on the account page.

Method of the class: CheckoutFieldsFrontend{}

No Hooks.

Return

null. Nothing (null).

Usage

$CheckoutFieldsFrontend = new CheckoutFieldsFrontend();
$CheckoutFieldsFrontend->render_address_fields( $address_type );
$address_type(string) (required)
Type of address (billing or shipping).

CheckoutFieldsFrontend::render_address_fields() code WC 9.0.1

public function render_address_fields( $address_type ) {
	if ( ! in_array( $address_type, array( 'billing', 'shipping' ), true ) ) {
		return;
	}

	$customer = new WC_Customer( get_current_user_id() );
	$fields   = $this->checkout_fields_controller->get_fields_for_location( 'address' );

	if ( ! $fields || ! $customer ) {
		return;
	}

	foreach ( $fields as $key => $field ) {
		$value = $this->checkout_fields_controller->format_additional_field_value(
			$this->checkout_fields_controller->get_field_from_object( $key, $customer, $address_type ),
			$field
		);

		if ( ! $value ) {
			continue;
		}

		printf( '<br><strong>%s</strong>: %s', wp_kses_post( $field['label'] ), wp_kses_post( $value ) );
	}
}