woocommerce_checkout_fields
Filters the fields of the classic checkout form: billing, shipping, account and order notes. Not used by the Checkout block.
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
$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
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.