You can inspect the WooCommerce order array with print_r by hooking a debug line into the thank-you page action and dumping the full WC_Order object, giving you a complete map of every property and method available for building custom order confirmation messages or export logic.
Why Inspect the Order Object Directly
- Discover exactly which getter methods and properties are available on an order before writing custom logic
- Debug why a specific piece of order data isn’t showing up as expected elsewhere in your code
- Understand how line items, totals, and metadata are structured inside the order object
Step 1: Add the Debug Snippet
/** TEMPORARY: dump the full order object on the thank-you page for debugging — remove after use */
add_action( 'woocommerce_thankyou', 'debug_print_order_object', 5 );
function debug_print_order_object( $order_id ) {
if ( ! current_user_can( 'manage_options' ) ) {
return;
}
$order = wc_get_order( $order_id );
echo '<pre>';
print_r( $order );
echo '</pre>';
}

As with any debug output, restrict it to administrators only using a capability check, and remove the snippet once you’ve extracted what you needed.
Step 2: Narrow Down to Just What You Need
The full object dump can be overwhelming — once you know the general shape, target specific data instead, for example:
echo '<pre>';
print_r( $order->get_items() ); // line items only
print_r( $order->get_data() ); // clean associative array of order data
echo '</pre>';get_data() in particular is often more readable than dumping the whole object, since it returns a flat associative array rather than the full internal object structure.
Troubleshooting
Output Is Too Long to Read Usefully
Switch to print_r( $order->get_data() ) instead of the raw object, or target a specific method’s return value (like get_items() or get_meta_data()) rather than dumping everything at once.
Sensitive Data Visible in Debug Output
Order objects include billing/shipping details and payment method information — never leave this kind of debug snippet active without the admin-only capability check, and remove it entirely once debugging is done.
print_r Output Isn’t Formatted
Wrap it in <pre> tags, as shown above, so the browser preserves the array’s indentation and line breaks.
Frequently Asked Questions
Should I use print_r or var_dump for order debugging?
Both work — print_r() is generally easier to read for large nested structures, while var_dump() additionally shows data types if that distinction matters for your debugging.
Is there a safer way to inspect orders than printing to the page?
Yes — write the output to a log file with error_log( print_r( $order->get_data(), true ) ) instead of echoing it directly to the front end.
Can I inspect a specific order without visiting its thank-you page?
Yes — call wc_get_order( $order_id ) with a known order ID from anywhere in your code (like an admin-only debug page) rather than relying on the thank-you page hook.
Conclusion
Inspecting the WooCommerce order array with print_r is the quickest way to understand exactly what data an order object exposes. Prefer get_data() or logging to a file over a raw object dump on the live front end, and always restrict output to administrators.
See also How to Print WooCommerce Orders Automatically. Then read How to Get Order Info From the WooCommerce $order Object.
Prefer no code? All-in-One Utilities Woo Add-on adds over 50 WooCommerce features, so you can switch them on without code.