Remove The Checkout Fields WooCommerce

Remove The Checkout Fields WooCommerce
898 Views
4.6
(156)

The filter woocommerce_checkout_fields makes it easy to unset checkout fields. To remove all of the checkout fields from WooCommerce, copy and paste the below code into the function.php file of your active child theme (or active theme).

<?php
add_filter( 'woocommerce_checkout_fields' , 'cxc_custom_remove_woo_checkout_fields' );
?>

This is a type of filter hook, which means that it must return something when you execute it. And what is it going to return? The data with the fields you want to remove.

Remove the last name

For example, if you want to delete the last name field, you can use the following:

<?php
unset( $fields['billing']['billing_last_name'] );
?>

After that, you need to insert it into a function with the same name you’ve used in the filter hook in the first step cxc_custom_override_checkout_fields

<?php
function cxc_custom_remove_woo_checkout_fields( $fields ) {
	unset( $fields['billing']['billing_last_name'] );
	return $fields;
}
?>

Finally, insert the full script to remove the WooCommerce field last name in the functions.php file of a child theme as shown below

<?php
add_filter( 'woocommerce_checkout_fields' , 'cxc_custom_remove_woo_checkout_fields' );

function cxc_custom_remove_woo_checkout_fields( $fields ) {
	unset( $fields['billing']['billing_last_name'] );
	return $fields;
}
?>

Delete any other fields

So, if you want to delete any other field, you need to add the corresponding line. Below you can find the available names of fields that you can remove:

    // remove billing fields
	unset($fields['billing']['billing_first_name']);
	unset($fields['billing']['billing_last_name']);
	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_postcode']);
	unset($fields['billing']['billing_country']);
	unset($fields['billing']['billing_state']);
	unset($fields['billing']['billing_phone']);
	unset($fields['billing']['billing_email']);
	
    // remove shipping fields 
	unset($fields['shipping']['shipping_first_name']);    
	unset($fields['shipping']['shipping_last_name']);  
	unset($fields['shipping']['shipping_company']);
	unset($fields['shipping']['shipping_address_1']);
	unset($fields['shipping']['shipping_address_2']);
	unset($fields['shipping']['shipping_city']);
	unset($fields['shipping']['shipping_postcode']);
	unset($fields['shipping']['shipping_country']);
	unset($fields['shipping']['shipping_state']);
	
    // remove order comment fields
	unset($fields['order']['order_comments']);

	// account fields
	unset($fields['account']['account_username']);
	unset($fields['account']['account_password']);
	unset($fields['account']['account_password-2']);

How to show checkout fields that you have previously removed?

What can you do if you have deleted some checkout fields that you want to display again? Simply delete the line of code that hides the specific field you want to show. For example, if you disabled the postcode field and now you want to add it again, you have to remove the following line from the functions.php file of your child theme:

unset($fields['billing']['billing_postcode']);

How useful was this blog?

Click on a star to rate it!

Average rating 4.6 / 5. Vote count: 156

No votes so far! Be the first to rate this blog.

Leave a comment

Your email address will not be published. Required fields are marked *