Extra checkout fields

Last modified:

Nexi Checkout provides a checkout solution that, depending on the checkout flow, can handle both payment methods and customer address fields. In some cases you might need to collect more information than the regular customer address data.

Default checkout fields

The Nexi Checkout plugin retrieves and populates the following address data in the checkout form:

During checkout updates

When customer data is updated from Nexi to WooCommerce.

  • Billing Postcode
  • Billing Country
  • Shipping Postcode
  • Shipping Country

During checkout process

Right before the checkout form is submitted and the order is created in WooCommerce.

  • Billing First name
  • Billing Last name
  • Billing Company (if B2B purchase)
  • Billing Postcode
  • Billing City
  • Billing Country
  • Phone
  • Email address
  • Shipping First name
  • Shipping Last name
  • Shipping Company (if B2B purchase)
  • Shipping Postcode
  • Shipping City
  • Shipping Country

Custom checkout fields

You can add extra checkout fields with the woocommerce_checkout_fields filter, or with the woocommerce_form_field function in a hook such as woocommerce_after_order_notes. The fields are displayed below the order notes field and are submitted with the rest of the checkout form when the order is created in WooCommerce. Saving the values to the order is done by your own code, as in the example below.

An example

If you add the following code as a plugin or in your themes functions.php file:

/**
 * More information about custom checkout fields: https://docs.woocommerce.com/document/tutorial-customising-checkout-fields-using-actions-and-filters
 *
 * Add the custom field to the checkout
 */
add_action( 'woocommerce_after_order_notes', 'my_custom_checkout_field' );

function my_custom_checkout_field( $checkout ) {

	woocommerce_form_field(
		'my_field_name',
		array(
			'type'        => 'text',
			'class'       => array( 'my-field-class form-row-wide' ),
			'label'       => __( 'Custom info' ),
			'placeholder' => __( 'Enter something' ),
			'required'    => true,
		),
		$checkout->get_value( 'my_field_name' )
	);

}

/**
 * Save the field value to the order
 */
add_action( 'woocommerce_checkout_create_order', 'my_custom_checkout_field_save', 10, 2 );

function my_custom_checkout_field_save( $order, $data ) {
	if ( ! empty( $_POST['my_field_name'] ) ) {
		$order->update_meta_data( 'My Field', sanitize_text_field( wp_unslash( $_POST['my_field_name'] ) ) );
	}
}

Then the field will be displayed like this:

Checkout page with a required Custom info field below the order notes, next to the embedded Nexi Checkout

In this case, the field was made required. By doing that, the purchase will not be finalized when pressing the Place order button until data has been entered into the Custom info field.

Compatibility with checkout field plugins

If you don’t want to add extra checkout fields via custom code, there are several plugins that solve this. Nexi Checkout has been tested with the following checkout field plugins: