Customize / Edit / Manage WooCommerce Checkout Fields using Actions and Filters

WooCommerce gets billing and shipping fields from the countries class class-wc-countries.php and get_address_fields function. This gives flexibility enable/disable fields based on the user’s location. With minimal development effort, these fields are highly customizable using actions and filters. If you are looking for a plugin to do this job, this article should help.

Filter Hooks to add and update checkout fields includes Billing and Shipping Address Fields

These actions and filters (refer the function get_address_fields ) give you complete control over checkout fields.

$address_fields = apply_filters( 'woocommerce_' . $type . 'fields', $address_fields, $country );

Filter to hook Billing Address Fields.

$address_fields = apply_filters('woocommerce_billing_fields', $address_fields);

Filter to hook Shipping Address Fields.

$address_fields = apply_filters('woocommerce_shipping_fields', $address_fields);

Filter to hook all checkout fields.
Various checkout field properties like type, label, placeholder, class, label_class, etc. are allowed to change. There is a master filter exposed to change any of the properties of any checkout fields.

$this->checkout_fields = apply_filters('woocommerce_checkout_fields', $this->checkout_fields);

Filter to hook email to additional fields.
You can even change the email content by adding additional checkout fields using the hook

woocommerce_email_order_meta_keys.

Example: Override Existing Checkout Fields.

Below example will change the properties of Comments Field.

Example – Change a Mandatory / Required Checkout Field to Optional/ Not Required

Below example will make the required checkout field ‘Phone Number’ as optional.

Example: Add a new Custom Checkout Field.

Below example will add a new field SSN Number as part of Checkout Fields.

Example: Add new Custom Fields to Emails.

Before using below example code, make sure the Key ( “tracking_code” as per this example ) is added as a custom checkout field as explained in on of the above example. This key should be passed to the $field_keys array.

Leave a Reply