WC_Emails::additional_checkout_fields()publicWC 1.0

Renders any additional 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_checkout_fields( $order, $sent_to_admin, $plain_text );
$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_checkout_fields() code WC 9.4.2

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

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

	if ( ! $fields ) {
		return;
	}

	if ( $plain_text ) {
		echo "\n" . esc_html( wc_strtoupper( __( 'Additional information', 'woocommerce' ) ) ) . "\n\n";
		foreach ( $fields as $field ) {
			printf( "%s: %s\n", wp_kses_post( $field['label'] ), wp_kses_post( $field['value'] ) );
		}
	} else {
		echo '<h2>' . esc_html__( 'Additional information', 'woocommerce' ) . '</h2>';
		echo '<ul class="additional-fields" style="margin-bottom: 40px;">';
		foreach ( $fields as $field ) {
			printf( '<li><strong>%s</strong>: %s</li>', wp_kses_post( $field['label'] ), wp_kses_post( $field['value'] ) );
		}
		echo '</ul>';
	}
}