Displaying customer numbers

WooCommerce stores the WordPress user_id in each order as a property, customer_id (or in 2.6 or older, a custom field named _customer_user), which you can display as follows:

Displaying the customer number (user_id) #

Using the Professional extension #

With the Professional extension, you can use the Address customization area, WooCommerce > PDF Invoices > Pro, adding the customer number below the billing address (note that the leading underscore is stripped here!)

{{billing_address}}
Customer Number: {{user_id}}

In a custom template #

<?php echo $this->order->get_user_id(); ?>

Using template hooks #

add_action( 'wpo_wcpdf_after_order_data', 'wpo_wcpdf_customer_number', 10, 2 );
function wpo_wcpdf_customer_number ($template_type, $order) {
    ?>
    <tr class="customer-number">
        <th>Customer Number:</th>
        <td><?php echo $order->get_user_id(); ?></td>
    </tr>
    <?php
}

Please note! This will only work for registered users. If the customer doesn’t register, it doesn’t automatically get a customer number in WooCommerce – see below.

Using WooCommerce Customer Manager #

If you also need customer numbers for non-registered/guest customers, you do this using the WooCommerce Customer Manager. This will give you an additional custom field to work with, named _customer_number.

In the Customer Manager, you can simply check on which documents you would like to display the customer number:

With the Professional extension, for example, below the billing address (note that the leading underscore is stripped here!)

{{billing_address}}
Customer Number: {{customer_number}}

If you want full freedom about where you would like to display the number, you can insert the following in a custom template:

<?php $this->custom_field('_customer_number'); ?>