Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Remove billing fields from checkout page
<?php
// Remove billing fields from checkout page
add_filter( 'woocommerce_checkout_fields' , 'remove_billing_fields_from_checkout' );
function remove_billing_fields_from_checkout( $fields ) {
unset( $fields['billing']['billing_country'] );
unset( $fields['billing']['billing_company'] );
unset( $fields['billing']['billing_address_1'] );
unset( $fields['billing']['billing_address_2'] );
unset( $fields['billing']['billing_city'] );
unset( $fields['billing']['billing_state'] );
unset( $fields['billing']['billing_postcode'] );
unset( $fields['billing']['billing_phone'] );
return $fields;
}
// Make billing and shipping addresses fields not required (except first and last name and email)
add_filter( 'woocommerce_default_address_fields' , 'filter_default_address_fields', 20 );
function filter_default_address_fields( $fields ) {
// Only on checkout page
if ( ! is_checkout() ) {
return $fields;
}
// All field keys in this array
$key_fields = array(
'country',
//'first_name',
//'last_name',
'company',
'address_1', // must be disabled here
'address_2',
'city', // must be disabled here
'state',
'postcode', // must be disabled here
//'phone', // not usefull here ?
//'email', // not usefull here ?
);
// Loop through each address fields (billing and shipping)
foreach ( $key_fields as $key_field ) {
$fields[$key_field]['required'] = false;
}
return $fields;
}
// Make billing fields not required (except first and last name and email)
add_filter( 'woocommerce_billing_fields', 'filter_billing_fields', 999 );
function filter_billing_fields( $fields ) {
// Only on checkout page
if ( ! is_checkout() ) {
return $fields;
}
// All field keys in this array
$key_fields = array(
'billing_country',
//'billing_first_name',
//'billing_last_name',
'billing_company',
//'billing_address_1', // not usefull here ?
'billing_address_2',
//'billing_city', // not usefull here ?
'billing_state',
//'billing_postcode', // not usefull here ?
'billing_phone', // must be disabled here
//'billing_email', // must be disabled here
);
// Loop through each address fields (billing and shipping)
foreach ( $key_fields as $key_field ) {
$fields[$key_field]['required'] = false;
}
return $fields;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment