Wordpress · 5 min read · Updated

Add Custom Fields to the WooCommerce Block Checkout With the Additional Checkout Fields API (Tested on WooCommerce 11)

How to add, validate and save custom fields on the WooCommerce block checkout with the Additional Checkout Fields API, with a tested plugin.

Woocommerce additional checkout fields

The WooCommerce checkout block doesn’t run the old woocommerce_checkout_fields filter, so the snippets most tutorials show for adding a field do nothing on a block checkout. Since WooCommerce 8.9 there is a proper way instead: the Additional Checkout Fields API, one PHP function that adds a field, validates it, saves it to the order and shows it in the admin.

This guide adds three real fields, a VAT number, a delivery option and a marketing opt-in, and shows what we saw when we tested them on WooCommerce 11.3.1: the fields on the checkout, the validation errors, where the values are stored and how to read them.

The WooCommerce block checkout with Contact information including an Email me about new products and offers (optional) checkbox, and a Billing address ending with a VAT number (optional) field under ZIP Code and Phone
A VAT number in the address section and an opt-in checkbox under the email, added with the API.

Download the plugin (one PHP file; upload it under Plugins > Add New > Upload Plugin).

Three places a field can go

LocationWhere it showsSaved as
'contact'Under the email addressOrder meta _wc_other/<id>
'address'In both the billing and shipping address_wc_billing/<id> and _wc_shipping/<id>
'order'In “Additional order information”, above the order note_wc_other/<id>

Fields can be text inputs, selects or checkboxes, and each needs a namespaced id such as webocreation/vat-number.

The plugin

<?php
/**
 * Plugin Name: Webocreation Checkout Fields
 * Description: A VAT number, delivery instructions and a marketing opt-in on the WooCommerce block checkout, using the Additional Checkout Fields API.
 * Version: 1.0.0
 * Requires Plugins: woocommerce
 */

defined( 'ABSPATH' ) || exit;

add_action( 'woocommerce_init', function () {
	if ( ! function_exists( 'woocommerce_register_additional_checkout_field' ) ) {
		return; // WooCommerce older than 8.9.
	}

	// Address section: shown with the billing and the shipping address, saved for each.
	woocommerce_register_additional_checkout_field(
		array(
			'id'                => 'webocreation/vat-number',
			'label'             => __( 'VAT number', 'webocreation' ),
			'optionalLabel'     => __( 'VAT number (optional)', 'webocreation' ),
			'location'          => 'address',
			'type'              => 'text',
			'required'          => false,
			'attributes'        => array(
				'autocomplete' => 'off',
				'maxLength'    => 16,
			),
			'sanitize_callback' => function ( $value ) {
				return strtoupper( preg_replace( '/[^A-Za-z0-9]/', '', (string) $value ) );
			},
			'validate_callback' => function ( $value ) {
				if ( '' !== $value && ! preg_match( '/^[A-Z]{2}[A-Z0-9]{2,14}$/', $value ) ) {
					return new WP_Error( 'invalid_vat_number', __( 'Enter the VAT number with its country code, for example DE123456789.', 'webocreation' ) );
				}
			},
		)
	);

	// Order section: once per order, under "Add a note to your order".
	woocommerce_register_additional_checkout_field(
		array(
			'id'       => 'webocreation/delivery-instructions',
			'label'    => __( 'Delivery option', 'webocreation' ),
			'location' => 'order',
			'type'     => 'select',
			'required' => true,
			'options'  => array(
				array( 'value' => 'front-door', 'label' => __( 'Leave at the front door', 'webocreation' ) ),
				array( 'value' => 'neighbour', 'label' => __( 'Leave with a neighbour', 'webocreation' ) ),
				array( 'value' => 'signature', 'label' => __( 'Signature required', 'webocreation' ) ),
			),
		)
	);

	// Contact section: saved to the order and, for signed-in customers, to their account.
	woocommerce_register_additional_checkout_field(
		array(
			'id'       => 'webocreation/marketing-opt-in',
			'label'    => __( 'Email me about new products and offers', 'webocreation' ),
			'location' => 'contact',
			'type'     => 'checkbox',
		)
	);
} );

// Read the values after the order is placed, for example to send them to a fulfilment service.
add_action( 'woocommerce_store_api_checkout_order_processed', function ( WC_Order $order ) {
	$fields = Automattic\WooCommerce\Blocks\Package::container()->get( Automattic\WooCommerce\Blocks\Domain\Services\CheckoutFields::class );

	$vat      = $fields->get_field_from_object( 'webocreation/vat-number', $order, 'billing' );
	$delivery = $fields->get_field_from_object( 'webocreation/delivery-instructions', $order, 'other' );
	$opt_in   = $fields->get_field_from_object( 'webocreation/marketing-opt-in', $order, 'other' );

	$order->add_order_note( sprintf( 'VAT: %s | Delivery: %s | Opt-in: %s', $vat ?: '-', $delivery, $opt_in ? 'yes' : 'no' ) );
} );

What each part does

  • Registration runs on woocommerce_init, after WooCommerce has loaded; registering earlier causes errors. The function_exists() check keeps older WooCommerce versions from failing.
  • VAT number: sanitize_callback runs first and turns “de 123 456 789” into “DE123456789”; validate_callback then returns a WP_Error if the result doesn’t look like a VAT number, and its message is shown under the field. Leaving it empty is allowed because required is false; WooCommerce adds “(optional)” to the label.
  • Delivery option: a required select. WooCommerce builds the placeholder from the label (“Select a delivery option”), so choose a label that reads well after “Select a”.
  • Marketing opt-in: a checkbox under the email, saved as 1 when ticked.
  • The last hook reads the three values once the order is placed, using WooCommerce’s CheckoutFields service, and adds them as an order note; that’s where you would send them to an ERP or fulfilment service.
The lower part of the block checkout: the billing address with the VAT number field, Cash on delivery as the payment option, Additional order information with a Delivery option select showing Select a delivery option, an Add a note to your order checkbox and the Place Order button
The required select in “Additional order information”, with the placeholder built from its label.

What we saw when we tested it

We ran a checkout through the Store API, the same API the checkout block uses, on WooCommerce 11.3.1:

  • A VAT number of “123” was refused with a 400 error and our message: “Enter the VAT number with its country code, for example DE123456789.”
  • Leaving out the required delivery option was refused with an additional_fields error.
  • A valid order was accepted with the VAT number saved as DE123456789 for both addresses, and the order note read “VAT: DE123456789 | Delivery: neighbour | Opt-in: yes”.
  • The order stored _wc_billing/webocreation/vat-number, _wc_shipping/webocreation/vat-number, _wc_other/webocreation/delivery-instructions and _wc_other/webocreation/marketing-opt-in.

The values also appear on the order edit screen without any extra code, under the billing and shipping addresses:

The WooCommerce Edit order screen for order 13: under Billing the address in Berlin, VAT number DE123456789, the email address and Email me about new products and offers: Yes; under Shipping the same address, VAT number DE123456789 and Delivery option: Leave with a neighbour
The admin order screen shows all three fields automatically.

Things to know

  • Block checkout only. These fields don’t appear on the classic [woocommerce_checkout] shortcode checkout. If you still use it, the old hooks are the way, or better, move to the block checkout.
  • Read values with the service, as in the plugin, rather than guessing meta keys, so your code keeps working if the storage changes.
  • Headless checkouts: the Store API returns the fields under additional_fields and in the addresses, and accepts them the same way. In WooCommerce 11 the Store API also expects state codes with a country prefix, such as DE-BE for Berlin; a plain BE was rejected.
  • Speed: the fields add nothing noticeable to the checkout; for the rest of the store see speeding up WooCommerce.

How we tested

WordPress with WooCommerce 11.3.1 (from wordpress.org) and PHP 8.3 in throwaway Docker containers, a $49 test product, Cash on Delivery, the plugin above, and a Python script calling the Store API cart and checkout endpoints. The containers were removed afterwards.

Filed underWordpress
Rupak Nepali
Written byRupak Nepali

Rupak Nepali is a web developer, manage Webocreation website and the author of six books:
Getting Started with OpenCart Module Development (Packt, 2013),
OpenCart Theme and Module Development (Packt, 2015),
OpenCart 4: Dev Guide for Themes & Extensions (2024),
OpenCart 4: User Manual (2025),
Cloudflare for the Enterprise Website (2026) and
The Technical Web Guide for Marketers (2026).
Rupak has built OpenCart stores and extensions since 2010, has published more than 600 tutorials on Webocreation, and shares free OpenCart extensions on GitHub.
Find Rupak on
GitHub | Amazon | LinkedIn | X | YouTube.

Leave a Reply

Your email address will not be published. Required fields are marked *