Filtering Out Billing State Data from WooCommerce Orders in the Admin

In a recent Business Bloomer Club discussion, a member asked about hiding the billing state data from order details displayed in the WooCommerce admin.

While WooCommerce provides extensive flexibility for managing orders and customizing the order view, certain data fields, like the billing state, might need to be filtered out for simplicity or privacy.

This guide will cover a solution to remove the billing state field from WooCommerce’s formatted billing address in the order view, making it possible to clean up the order display according to your preferences.

Why Filter Out the Billing State?

The billing state may not always be essential for certain stores, especially if your sales are within regions that don’t require this information for processing. Filtering it out reduces unnecessary data and streamlines the view for admin users, providing a more concise view of orders.

Step-By-Step Solution to Filter Billing State

To filter the billing state, we can use a WooCommerce filter hook that allows modification of formatted address replacements. Below is the custom code to achieve this.

Code Snippet

Place the following code in your theme’s functions.php file or within a custom plugin:

add_filter( 'woocommerce_formatted_address_replacements', function( $replacements ) {
   $replacements['{state}'] = ''; // Remove the billing state data
   return $replacements;
});

Explanation of the Code

  • Filter Hook: The woocommerce_formatted_address_replacements filter hook is used to modify the address formatting structure.
  • Removing State Data: By setting $replacements['{state}'] = '';, the code effectively clears the state field, so it won’t display in the admin order details.

Testing the Solution

  1. Implement the Code: Add the code snippet to your site.
  2. View Orders in Admin: Go to WooCommerce > Orders in the admin panel and view an order’s details.
  3. Verify: Confirm that the billing state is no longer displayed in the order address information.

Additional Customization Ideas

If you need to hide other address components, such as the billing city or postal code, you can extend this snippet by setting replacements for additional fields within the $replacements array.

// Example: Remove billing state and postal code
add_filter( 'woocommerce_formatted_address_replacements', function( $replacements ) {
   $replacements['{state}'] = '';       // Removes billing state
   $replacements['{postcode}'] = '';    // Removes postal code
   return $replacements;
});

Conclusion

This solution allows WooCommerce store admins to tailor the order details page by hiding non-essential information. Whether you need a cleaner admin view or want to focus only on relevant details, using filters like woocommerce_formatted_address_replacements provides effective control over how customer data appears.

This customization can simplify order management, making order details clearer and more focused on what matters most to your business operations.

Related content

Rodolfo Melogli

Business Bloomer Founder

Author, WooCommerce expert and WordCamp speaker, Rodolfo has worked as an independent WooCommerce freelancer since 2011. His goal is to help entrepreneurs and developers overcome their WooCommerce nightmares. Rodolfo loves travelling, chasing tennis & soccer balls and, of course, wood fired oven pizza. Follow @rmelogli

Reply

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