Website Building » WooCommerce » How Do I Display Custom Fields in WooCommerce Orders in Admin Panel?

How Do I Display Custom Fields in WooCommerce Orders in Admin Panel?

Last updated on January 20, 2023 @ 11:36 am

Do you want to display custom fields in WooCommerce orders in the admin panel? By default, WooCommerce only shows a few core order details in the admin panel. However, you can add custom fields to orders and display them in the admin panel using the following methods.

Adding custom fields to WooCommerce orders is a two-step process. First, you need to add the custom field to the order form. Second, you need to display the custom field value in the order details page in the admin panel.

In this article, we will show you how to add and display custom fields in WooCommerce orders in the admin panel.

Method 1: Add Custom Fields to Orders Using a Plugin

The easiest way to add custom fields to WooCommerce orders is by using a plugin. For this method, we will be using the Advanced Custom Fields for WooCommerce plugin. This plugin is free and available on the WordPress.org plugin repository.

First thing you need to do is install and activate the Advanced Custom Fields for WooCommerce plugin.

Once activated, you need to visit Forms → Add New page. Enter a title for your form and click on the Add Field button.

PRO TIP: If you are using a WooCommerce plugin that allows you to display custom fields in WooCommerce orders in the admin panel, be aware that this may expose sensitive information about your customers’ orders. Make sure that you only display information that is necessary and that you have the appropriate security measures in place to protect this information.

This will bring up a popup where you can select a field type and enter other options for that field. For our example, we are going to add a text field type.

After that, you need to enter a label for your field and click on the Save button.

You can now click on Publish button to save your changes.

Method 2: Add Custom Fields to Orders Using Code

Adding custom fields to orders using code is slightly more complicated than using a plugin.

You will need access to your WordPress files via FTP or File Manager in cPanel. Once you have access, open your child theme’s functions.php file or create one if it doesn’t exist yet.

Next, you need to copy and paste the following code at the bottom of your functions.php file:

/**
* Add custom fields to order objects when created/read from the database
* @param WC_Order $order
*/
function wc_add_custom_fields_to_order( $order ) {

  $order->update_meta_data( 'my_field_name', 'my_field_value' ); }
add_action( 'woocommerce_checkout_create_order', 'wc_add_custom_fields_to_order', 10, 1 );.

/** * Update value of custom field when order status changes * @param int $order_id */
function wc_update_custom_field( $order_id ) {
  $order = wc_get_order( $order_id );
  $new_value = 'new_field_value';
  $order->update_meta_data( 'my_field_name', $new_value );
  $order->save();
}
add_action( 'woocommerce_order_status_changed', 'wc_update_custom_field', 10, 1 );
Dale Leydon

Dale Leydon

Sysadmin turned Javascript developer. Owner of 20+ apps graveyard, and a couple of successful ones.