WC_Emails::additional_address_fields()publicWC 1.0

Renders any additional address fields captured during block-based checkout.

Method of the class: WC_Emails{}

No Hooks.

Return

null. Nothing (null).

Usage

$WC_Emails = new WC_Emails();
$WC_Emails->additional_address_fields( $address_type, $order, $sent_to_admin, $plain_text );
$address_type(string) (required)
Address type.
$order(WC_Order) (required)
Order instance.
$sent_to_admin(true|false)
If email is sent to admin.
Default: false
$plain_text(true|false)
If this is a plain text email.
Default: false

WC_Emails::additional_address_fields() code WC 9.4.2

public function additional_address_fields( $address_type, $order, $sent_to_admin = false, $plain_text = false ) {
	if ( ! is_a( $order, 'WC_Order' ) ) {
		return;
	}

	$checkout_fields = Package::container()->get( CheckoutFields::class );
	$fields          = $checkout_fields->get_order_additional_fields_with_values( $order, 'address', $address_type, 'view' );

	if ( ! $fields ) {
		return;
	}

	foreach ( $fields as $field ) {
		if ( $plain_text ) {
			printf( "%s: %s\n", wp_kses_post( $field['label'] ), wp_kses_post( $field['value'] ) );
		} else {
			printf( '<br><strong>%s</strong>: %s', wp_kses_post( $field['label'] ), wp_kses_post( $field['value'] ) );
		}
	}
}