Black Friday & Cyber Monday SUPER SALE ALL WEEK:
Grab 40% OFF on plugins
Days
Hours
Minutes
Seconds

How to Remove WooCommerce Shipping Fields’ First and Last Name?

WooCommerce provides a standard set of fields in both billing and shipping forms. As an online store owner, you can choose a cleaner checkout design that aligns with your specific business model and customer needs. For digital product sales, removing fields like the first and last name from the shipping form can contribute to a more visually appealing checkout page.

This post helps you remove the first name and last name fields from the WooCommerce shipping form.

Where to Add Custom Code in WooCommerce?

It is advisable to add the code snippets to the functions.php file of your child theme. Access the file directly from Appearance->Theme File Editor->Locating the child theme’s functions.php from the right sidebar. You can also access it from your theme’s directory file. Insert the following code snippet in functions.php. The alternative & easy option is to install & activate the Code Snippets plugin. You can then add the code as a new snippet via the plugin.

Solution: Remove WooCommerce Shipping Fields’ First and Last Name

Some stores may have unique business models or specific requirements for customer information collection. In the case of an online store that sells products to B2B eCommerce companies, there’s no need to collect individual names for shipping. In such cases, the store owner may only require a single “Company Name” for shipping. The code snippet provided below will help remove these unnecessary fields, making the checkout process cleaner and more straightforward.

add_filter( 'woocommerce_shipping_fields', 'ts_shipping_remove_fields' );
function ts_shipping_remove_fields( $fields )
{
    unset( $fields[ 'shipping_last_name' ] );
    unset( $fields[ 'shipping_first_name' ] );
    return $fields; 
}

Output

Use Case: Removed First and Last Name shipping  fields

After applying the provided code, it will remove the First and Last Name fields from the shipping form in the checkout process.

How to Remove WooCommerce Shipping Fields' First and Last Name? - Tyche Softwares

Use Case: Default Shipping Fields

The following output shows that the default shipping form includes the “First Name” and “Last Name” fields.

How to Remove WooCommerce Shipping Fields' First and Last Name? - Tyche Softwares

Code Explanation

Hooking into woocommerce_shipping_fields:

The code begins by using the add_filter function to hook into the woocommerce_shipping_fields filter. Here, ts_shipping_remove_fields is the name of the function that will be called when this filter is triggered.

Custom Function ‘ts_shipping_remove_fields’:

The next section defines the custom function ts_shipping_remove_fields, which will be responsible for removing the unwanted fields. This function takes one parameter, $fields, which represents an array containing information about the shipping fields.

Removing ‘shipping_first_name’ Field and ‘shipping_last_name’ Field:

The code utilizes unset to remove the ‘shipping_first_name’ and ‘shipping_last_name‘ fields from the $fields array. Using the HTML field names given below you can choose to remove any field of your choice.

Returning the Modified Fields:

After removing the undesired fields, the function returns the modified $fields array. This step is crucial because WooCommerce’s ‘woocommerce_shipping_fields’ filter expects the modified array to be returned.

Conclusion

The above code snippets will help you remove the first and last name fields from the shipping form.

Here is a list of the HTML names for all the fields on the Checkout page. These names indicate which field they represent. By replacing the HTML names of the shipping fields in the code, you can easily remove any other fields of your choice.

Billing Fields

  • billing_first_name
  • billing_last_name
  • billing_company
  • billing_country
  • billing_address_1
  • billing_address_2
  • billing_city
  • billing_state
  • billing_postcode
  • billing_phone
  • billing_email

Shipping Fields

  • shipping_first_name
  • shipping_last_name
  • shipping_company
  • shipping_country
  • shipping_address_1
  • shipping_address_2
  • shipping_city
  • shipping_state
  • shipping_postcode

In addition, you can also customize the checkout fields to make the billing and shipping fields required or optional.

Let us know your feedback on how the code was useful or any other queries in the comment section.

Browse more in: Code Snippets, WooCommerce How Tos, WooCommerce Tutorials

Share It:

Subscribe
Notify of
0 Comments
Newest
Oldest
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x