Remove Optional Checkout Fields
Removes the company and second address line fields from the classic checkout form to make it shorter.
Opens WPIDE on
Code
add_filter( 'woocommerce_checkout_fields', function ( $fields ) {
// Field keys to remove.
$remove = array( 'billing_company', 'billing_address_2', 'shipping_company', 'shipping_address_2' );
foreach ( $remove as $key ) {
$group = 0 === strpos( $key, 'shipping_' ) ? 'shipping' : 'billing';
unset( $fields[ $group ][ $key ] );
}
return $fields;
} );
Notes
Applies to the classic checkout shortcode. Block checkout fields are managed in the Site Editor.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.