How7o
  • Home
  • Tools
  • Prank Screens
  • Contact
  • Blog
Reading: How to Get the Customer ID from an Order ID in WooCommerce
Share
Subscribe Now
How7oHow7o
Font ResizerAa
  • Marketing
  • OS
  • Features
  • Guide
  • Complaint
  • Advertise
Search
  • Home
  • Tools
  • Prank Screens
  • Contact
  • Blog
Follow US
Copyright © 2014-2023 Ruby Theme Ltd. All Rights Reserved.
How7o > Blog > Web Development > How to Get the Customer ID from an Order ID in WooCommerce
Web Development

How to Get the Customer ID from an Order ID in WooCommerce

how7o
By how7o
Last updated: May 10, 2026
7 Min Read
WooCommerce get customer ID from order — WC_Order::get_user_id
SHARE

For woocommerce get customer id from order, call $order->get_user_id() (or its alias get_customer_id()) on any WC_Order object. Returns the customer’s WP_User ID, or 0 for guest checkouts. On older installs without HPOS, the legacy meta read (_customer_user) still works but has been superseded — this guide shows the modern method and why the older pattern breaks on current WooCommerce.

Contents
  • TL;DR
  • In a $order-aware hook
  • Why not get_post_meta($order_id, '_customer_user')?
  • Loading an order by ID
  • Order snapshot vs live user data
  • Frequently asked questions
  • Related guides
  • References

Last verified: 2026-04-23 on WooCommerce 9.x (HPOS enabled) with WordPress 6.5. Originally published 2022-11-08, rewritten and updated 2026-04-23.

TL;DR

// From a $order object already in scope
$user_id = $order->get_user_id();   // int, 0 for guests

// If you only have the order ID
$order   = wc_get_order( $order_id );
$user_id = $order ? $order->get_user_id() : 0;

In a $order-aware hook

add_action( 'woocommerce_admin_order_data_after_billing_address', 'how7o_customer_details', 10, 1 );

function how7o_customer_details( $order ) {
    $user_id = $order->get_user_id();

    if ( ! $user_id ) {
        echo '<p><em>Guest checkout</em></p>';
        return;
    }

    $custom_details = get_user_meta( $user_id, '_custom_details', true );
    if ( $custom_details ) {
        printf(
            '<p><strong>Custom Details:</strong> %s</p>',
            esc_html( $custom_details )
        );
    }
}

The woocommerce_admin_order_data_after_billing_address hook passes the $order object so you can grab get_user_id() directly. Guard against 0 (guest checkout) before handing the value to get_user_meta — meta lookups against user ID 0 would return a WordPress-wide record, which is not what you want.

woocommerce get customer id from order — WC_Order method on HPOS vs legacy meta read

Why not get_post_meta($order_id, '_customer_user')?

// Legacy — only works on pre-HPOS installs
$user_id = get_post_meta( $order_id, '_customer_user', true );

This pattern reads the _customer_user post meta that WooCommerce used to write to wp_postmeta when orders were stored as custom posts. WooCommerce 8.2 made HPOS (High-Performance Order Storage) the default: orders move to a dedicated wc_orders table and wp_postmeta no longer holds the link. get_post_meta returns an empty string on HPOS installs — silently, no error.

Always use the WC_Order method (get_user_id() / get_customer_id()). It abstracts the storage mode — works the same whether the order lives in posts (legacy) or the custom table (HPOS).

Loading an order by ID

$order = wc_get_order( $order_id );

if ( ! $order ) {
    // Order doesn't exist or the ID is bogus
    return;
}

$user_id       = $order->get_user_id();
$billing_email = $order->get_billing_email();
$status        = $order->get_status();

wc_get_order() is the factory that handles every order type (standard, subscription, refund). It accepts an ID, a post object, or an existing order object, and returns false when the input doesn’t resolve. The return-value check catches deleted orders and typos without fatal errors.

Order snapshot vs live user data

// From the order — the values as they were when the order was placed
$order->get_billing_first_name();
$order->get_billing_email();
$order->get_shipping_city();

// From the current user record — may have been updated since
$user         = $order->get_user();     // WP_User or false
$current_name = $user ? $user->first_name : '';

WooCommerce snapshots the billing and shipping addresses on the order at checkout time. The $order->get_billing_*() methods give you that frozen copy. $order->get_user() gives you the live WP_User, which may have been updated since the order.

For analytics and invoicing, use the order snapshot (the customer’s name at the time of purchase). For sending a post-purchase email or running a loyalty check, use the live user data.

Frequently asked questions

What’s the shortest woocommerce get customer id from order?

$order->get_user_id() (or the alias get_customer_id()) — both return the WP_User ID of the customer who placed the order, or 0 if it was a guest checkout. Works anywhere you have a WC_Order object.

What if I only have an order ID, not the object?

Load it: $order = wc_get_order($order_id);. wc_get_order is the proper factory — works with HPOS (High-Performance Order Storage, now the default on new WooCommerce installs), handles subscription order types, and returns false if the ID doesn’t exist. Don’t reach for new WC_Order($id) directly; the factory is what handles storage differences.

Is get_post_meta($order_id, '_customer_user', true) still valid?

Only on legacy installs that haven’t migrated to HPOS. With HPOS enabled (default since WooCommerce 8.2), orders live in a custom table wc_orders instead of wp_posts, and get_post_meta returns empty. Always prefer the $order->get_user_id() method — it works in both storage modes.

How do I handle guest orders?

get_user_id() returns 0 for guest checkouts. Use $order->get_billing_email() to identify the guest, or match against user_email in wp_users to see if they later created an account with the same address. Don’t assume every order has a logged-in customer — guest checkout is common.

Can I look up the customer’s meta from the order?

$user_id = $order->get_user_id(); $meta = get_user_meta($user_id, 'some_key', true); — two calls. Or the shortcut: WooCommerce stores the snapshot of customer info on the order itself (billing address, shipping address), accessible via $order->get_billing_first_name(), $order->get_shipping_city(), etc. Reach for the user_meta lookup when you need data that isn’t in the order snapshot; reach for the order getters when you want the address as it was when the order was placed.

Related guides

  • How to Display Orders Instead of Dashboard on the WooCommerce My Account Page — another order-surface customization.
  • How to Search Users by Multiple Fields in WordPress — finding customers when you don’t have an order ID.
  • How to Login a User Programmatically in WordPress — post-purchase account linking.
  • How to Add a Custom Fee in WooCommerce — order-context hook patterns.

References

WooCommerce WC_Order reference: woocommerce.github.io/code-reference/classes/WC-Order.

TAGGED:phpWooCommercewordpress

Sign Up For Daily Newsletter

Be keep up! Get the latest breaking news delivered straight to your inbox.
By signing up, you agree to our Terms of Use and acknowledge the data practices in our Privacy Policy. You may unsubscribe at any time.
Share This Article
Facebook Copy Link Print
Previous Article WooCommerce dynamic currency switcher — cookie-stored currency applied via woocommerce_currency filter How to Dynamically Change Currency in WooCommerce
Next Article WooCommerce SKU search — posts_search filter injecting SKU-matched product IDs How to Include SKU in WooCommerce Search
Leave a Comment

Leave a Reply Cancel reply

You must be logged in to post a comment.

FacebookLike
XFollow
PinterestPin
InstagramFollow

Subscribe Now

Subscribe to our newsletter to get our newest articles instantly!
Most Popular
Display PHP errors — ini_set + php.ini configuration
How to Display PHP Errors
May 10, 2026
PHP convert string to uppercase — strtoupper and mb_strtoupper
How to Convert a String to Uppercase in PHP
May 10, 2026
PHP string to float conversion with cast, regex cleanup, NumberFormatter
How to Convert a String to Float in PHP
May 10, 2026
PHP merge arrays without duplicates — union operator and array_unique
How to Combine Two Arrays Without Duplicates in PHP
May 10, 2026
PHP delete array element — unset, array_splice, array_filter, array_search
How to Delete an Element from a PHP Array
May 10, 2026

You Might Also Like

Laravel Eloquent orderBy — code snippet sorting posts by id descending with arrow icons
Web Development

How to Use orderBy in Laravel Eloquent (with Examples)

6 Min Read
Install PHP on Ubuntu — terminal with apt install php command and stylized elephant icon
Web Development

How to Install PHP on Ubuntu (22.04 & 24.04): Step-by-Step Guide

9 Min Read
Install Node.js on Ubuntu — terminal with NodeSource setup_22.x curl command and Node.js hexagon icon
Web Development

How to Install Node.js on Ubuntu (22.04 & 24.04): Step-by-Step

11 Min Read
WordPress system cron — DISABLE_WP_CRON + system crontab hitting wp-cron.php
Web Development

How to Set Up a System-Based Cron Job in WordPress

7 Min Read
How7o

We provide tips, tricks, and advice for improving websites and doing better search.

Latest News

  • SEO Audit Tool
  • Client ReferralsNew
  • Execution of SEO
  • Reporting Tool

Resouce

  • Google Search Console
  • Google Keyword Planner
  • Google OptimiseHot
  • SEO Spider

Get the Top 10 in Search!

Looking for a trustworthy service to optimize the company website?
Request a Quote
Welcome Back!

Sign in to your account

Username or Email Address
Password

Lost your password?