Print custom checkout fields

If you have some custom checkout fields you’d like to include in your order list, you can do this in two ways: by creating a custom template or by using an action hook to output the custom field in a predefined location. Custom templates allow for maximum freedom of where the custom field should be printed, while action hooks are more limited but will ensure that you always use the latest version of the template (custom templates naturally will not be updated automatically).

This requires some knowledge of HTML (and CSS if you want to apply specific styling to the output).
First of all, you need to create a custom template. After you have done this, insert the following code snippet in the location where you’d like to output the custom field:

WooCommerce 3.0 or later:

<?php $order = wc_get_order($order_id); echo $order->get_meta( '_custom_field', true ); ?>

WooCommerce 2.6 or older:

<?php echo get_post_meta( $order_id, '_custom_field', true ); ?>

Where you replace ‘_custom_field’ with the actual (internal) name of your custom checkout field.

This method is more update proof (see intro above), but does require you to put some code in your themes functions.php. If you have never done this before, make sure to check our guide on how to use filters.

The following example will print the custom field below the billing address:

WooCommerce 3.0 or later:

add_action( 'wpo_wcol_billing_address', 'wpo_wcol_output_custom_field', 10, 1 );
function wpo_wcol_output_custom_field ( $order_id ) {
	$order = wc_get_order($order_id);
	?>
	<div class="custom-field"><?php echo $order->get_meta( '_custom_field', true ); ?></div>
	<?php 
}

WooCommerce 2.6 or older:

add_action( 'wpo_wcol_billing_address', 'wpo_wcol_output_custom_field', 10, 1 );
function wpo_wcol_output_custom_field ( $order_id ) {
	?>
	<div class="custom-field"><?php echo get_post_meta( $order_id, '_custom_field', true ); ?></div>
	<?php 
}

To print something below the shipping address, simply replace ‘wpo_wcol_billing_address’ by ‘wpo_wcol_shipping_address’.
Other action hooks that you can use are: ‘wpo_wcol_order_header’ (outputs below the header for the order) and ‘wpo_wcol_custom_row’ (adds an extra row below each order).