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).

Output in a custom template #

This requires some knowledge of HTML (and CSS if you want to apply specific styling to the output).

First, 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:

<?php echo wc_get_order($order_id)->get_meta( '_custom_field' ); ?>

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

Output using an action hook #

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:

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' ); ?></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).

Here’s another example, using the wpo_wcol_custom_row hook and a custom field _delivery_date:

add_action( 'wpo_wcol_custom_row', 'wpo_wcol_transaction_id', 10, 1 );
function wpo_wcol_transaction_id( $order_id ) {
    $order = wc_get_order( $order_id );
    if ( $delivery_date = $order->get_meta( '_custom_field' ) ) {
        echo "<div><strong>Delivery Date:</strong> $delivery_date</div>";
    }
}