How to remove shipping fields on the checkout page in WooCommerce
- Published:
- Updated:
A typical solution that can be found on the Internet looks like this:
add_filter( 'woocommerce_checkout_fields', 'woo_del_fields');
function woo_del_fields( $fields ) {
unset( $fields[ 'billing' ][ 'billing_country' ] );
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' ] );
return $fields;
}
This code in the functions.php file will really help remove fields from the checkout page. But, if you try to place an order, you will receive a warning that you have not filled in the fields for delivery. That is, there are no fields, but you still need to fill them. Therefore, the previous code must be supplemented with the following:
add_filter( 'woocommerce_default_address_fields' , 'woo_del_required_fields' );
function woo_del_required_fields( $array ) {
unset( $array['country']['required']);
unset( $array['state']['required']);
unset( $array['postcode']['required']);
unset( $array['city']['required']);
unset( $array['address_1']['required']);
unset( $array['address_2']['required']);
return $array;
}