To output a specific value from the data output of a WooCommerce order, you can use the WooCommerce function
get_post_meta() to retrieve the value from the order’s post meta data. Here is an example of how you might use this function to output the order’s billing email address:
// Get the order ID
$order_id = 123;
// Get the billing email value from the order's post meta data
$billing_email = get_post_meta( $order_id, '_billing_email', true );
// Output the billing email value
In this example,
$order_id is the ID of the order, and
'_billing_email' is the key for the billing email value in the order’s post meta data. The
true parameter tells the function to return the value as a string, rather than an array.
You can use this same approach to output other values from the order data. Simply replace the key in the
get_post_meta() function with the key for the value you want to output. Some common order data values that you might want to output include the billing and shipping addresses, payment method, and order total.
It’s worth noting that the specific keys for the order data values may vary depending on your WooCommerce configuration and the version of WooCommerce you are using. You can find a list of common order data keys in the WooCommerce documentation.
Last modified: January 13, 2023