WC_Emails::additional_checkout_fields
Renders any additional fields captured during block-based checkout.
Method of the class: WC_Emails{}
No Hooks.
Returns
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() WC Emails::additional checkout fields code WC 10.3.5
public function additional_checkout_fields( $order, $sent_to_admin = false, $plain_text = false ) {
if ( ! is_a( $order, 'WC_Order' ) ) {
return;
}
/**
* Service class managing checkout fields and its related extensibility points.
*
* @var CheckoutFields $checkout_fields
*/
$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' ),
);
$context = array(
'caller' => 'WC_Email::additional_checkout_fields',
'order' => $order,
'sent_to_admin' => $sent_to_admin,
'plain_text' => $plain_text,
);
$fields = $checkout_fields->filter_fields_for_order_confirmation( $fields, $context );
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>';
}
}