How to Customize Billing and Shipping Address Fields in WooCommerce

How to Customize Billing and Shipping Address Fields in WooCommerce (2)
1405 Views
4.3
(154)

The article will walk you through the process of adding custom fields to billing and shipping addresses on your WooCommerce checkout. The billing and shipping address sections are critical to the WooCommerce checkout process.

Add the following code to your child theme’s functions.php file.

Remove the default billing and shipping field

<?php
add_filter( 'woocommerce_default_address_fields', 'cxc_remove_billing_shipping_add_fields' );
function cxc_remove_billing_shipping_add_fields( $fields ) {
	unset( $fields[ 'address_1' ] );
	unset( $fields[ 'postcode' ] );
	return $fields;
}
?>
<?php
add_filter( 'woocommerce_billing_fields', 'cxc_remove_billing_fields' );
function cxc_remove_billing_fields( $fields ) {
	unset( $fields[ 'billing_address_1' ] ); // or shipping_address_2 for woocommerce_shipping_fields hook
	unset( $fields[ 'billing_postcode' ] );
	return $fields;
}
?>

Disable Shipping LastName Field Validation

<?php
add_filter( 'woocommerce_shipping_fields', 'cxc_remove_shipping_fields' );
function cxc_remove_shipping_fields( $fields ) {
	unset( $fields[ 'shipping_last_name' ][ 'required' ] );
	return $fields;
}
?>

Enabled Shipping Company Field Validation

<?php
add_filter( 'woocommerce_shipping_fields', 'cxc_shipping_compnay_required_fields' );
function cxc_shipping_compnay_required_fields( $fields ) {
	$fields[ 'shipping_company' ][ 'required' ] = true;
	return $fields;
}
?>

Changes In Both Billing And Shipping Address First Name Fields

<?php
add_filter( 'woocommerce_default_address_fields', 'cxc_billing_shipping_change_fname_field' );
function cxc_billing_shipping_change_fname_field( $fields ) {
	$fields[ 'first_name' ][ 'label' ] = 'Name';
	$fields[ 'first_name' ][ 'placeholder' ] = 'What is your name ?';
	return $fields;
}
?>

Add Two Custom Fields In Both Billing And Shipping Address

<?php
//woocommerce_billing_fields, woocommerce_shipping_fields
add_filter( 'woocommerce_default_address_fields', 'misha_add_field' );
function misha_add_field( $fields ) {
	
	$fields[ 'fav_color' ]   = array(
		'label'        => __( 'Cxc Favorite color', 'cxc-codexcoach' ), // Add custom field label
		'placeholder'  => _x( 'Is it Yellow or Green or maybe Blue ...?', 'placeholder', 'cxc-codexcoach' ), // Add custom field placeholder
		'required'     => true, // if field is required or not
		'clear'        => true, // add clear or not
		'class'        => array( 'form-row-wide', 'cxc-custom-color-class' ), // add class name
		'type'         => "text", // add field type
		'priority'     => 20,
	);

	$fields['gst_numbers'] = array(
        'label'       => __( 'GST', 'cxc-codexcoach' ), // Add custom field label
        'placeholder' => _x( 'Your GST Number here....', 'placeholder', 'cxc-codexcoach' ), // Add custom field placeholder
        'required'    => true, // if field is required or not
        'clear'       => false, // add clear or not
        'class'       => array( 'form-row-wide', 'cxc-custom-gst-class' ),  // add class name
        'type'        => "text", // add field type
        'priority'    => 21, // add priority
    );
	
	return $fields;
}
?>

How do I update my billing and delivery addresses in WooCommerce?

To change your billing and shipping addresses in WooCommerce, just log in to your WordPress site, navigate to the WooCommerce Settings page, and click on the Accounts tab.

How useful was this blog?

Click on a star to rate it!

Average rating 4.3 / 5. Vote count: 154

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 *