Automattic\WooCommerce\Blocks\Domain\Services

CheckoutFieldsFrontend::render_address_fieldspublicWC 1.0

Renders address fields on the account page.

Method of the class: CheckoutFieldsFrontend{}

No Hooks.

Returns

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.9.4

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() );

	$document_object = new DocumentObject();
	$document_object->set_customer( $customer );
	$document_object->set_context( $address_type . '_address' );
	$fields = $this->checkout_fields_controller->get_contextual_fields_for_location( 'address', $document_object );

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