Skip to content

Early-bird lifetime licence: $199 once, for the first 200 buyers only. See the offer

woocommerce_checkout_fields

Filters the fields of the classic checkout form: billing, shipping, account and order notes. Not used by the Checkout block.

  • Type Filter
  • From WooCommerce
  • Since 1.4.0
  • Fired in includes/class-wc-checkout.php

When it fires

WooCommerce applies this filter the first time the checkout fields are needed in a request (WC_Checkout::get_checkout_fields()): when it shows the classic checkout form, and when it validates and processes an order placed through it. The array is grouped into 'billing', 'shipping', 'account' and 'order'.

The Checkout block, the default for new stores, doesn't use this filter. There you switch fields on or off in the block's settings, or add new ones with woocommerce_register_additional_checkout_field().

Parameters

Parameters
$checkout_fieldsarray[] The checkout fields, grouped by section.

What to return

The whole fields array, with your changes.

Example: Remove the company field and make the phone optional

PHP
add_filter( 'woocommerce_checkout_fields', function ( $fields ) {
	unset( $fields['billing']['billing_company'] );
	if ( isset( $fields['billing']['billing_phone'] ) ) {
		$fields['billing']['billing_phone']['required'] = false;
	}
	return $fields;
} );

Good to know

  • Checkout block: this filter has no effect there. Use the block settings or the Additional Checkout Fields API.
  • Address field labels and placeholders can be replaced per country by WooCommerce's locale data. To change address fields reliably, use woocommerce_default_address_fields.
  • Don't remove fields WooCommerce relies on, such as the billing email, or orders and emails can break.

Move your snippets over this afternoon.

Importing changes nothing until you switch over, and your old shortcodes keep working.