Get orders shipping items details in WooCommerce 3

Get orders shipping items details in WooCommerce 3

  1. Blog
  2. 15 November 2026
  3. 3 min read

Stefan Bogdanescu

Founder & Senior Architect

Retrieving Shipping Method Data in WooCommerce 3

In WooCommerce, accessing internal identifiers like shipping method IDs used to be a straightforward lookup within the order object. However, starting with version 3.0, the architecture shifted significantly to decouple data storage from direct property access. Developers attempting to retrieve values like 'flat_rate' often find themselves blocked by protected properties when inspecting $order->get_data(). This approach fails because WC_Order now heavily utilizes a data repository pattern rather than exposing raw arrays directly for mutation or inspection in legacy ways.

To reliably extract the shipping method ID, you must interact with the specific data store responsible for managing order line items and metadata. The most robust solution involves accessing the internal $data_store property of the WC_Order object. While this looks like a protected member access, it is an established pattern within the WooCommerce codebase for retrieving raw payload data without triggering validation hooks or altering the order state.

Here is how you can implement this in your custom plugin or theme functions:

function get_shipping_method_id( $order_id ) {
    // Retrieve the WC_Order object
    $order = wc_get_order( $order_id );

    if ( ! $order instanceof \WC_Order ) {
        return false;
    }

    // Access the internal data store to get raw line item and meta data
    $data_store = $order->get_data_store();

    // The shipping method ID is stored as 'shipping_method' in the order data
    // In WC 3+, this is typically an array of IDs if multiple methods are used
    $shipping_methods = $order->get_shipping_method_id();

    // If the getter exists (which it does in modern versions), use it.
    // Otherwise, fall back to checking the internal data structure if needed.
    
    return $shipping_methods; 
}

In WooCommerce 3 and later, the preferred API method is $order->get_shipping_method_id(). This getter returns an array containing the shipping zone rates selected by the customer. For a simple flat rate setup, you might receive a single string like 'flat_rate', but for complex setups with multiple zones, it returns an array of strings such as ['flat_rate', 'local_pickup'].

If you are working in a legacy context or debugging and need to inspect the raw data structure directly without using public getters, accessing the protected $data_store allows you to parse the underlying payload. You would access $order->get_data_store()->read( $order ) to retrieve the full order object representation as it exists in the database. This bypasses any cached or modified properties and gives you the raw $_POST style data structure where 'shipping_method' resides at the top level.

Handling Multiple Shipping Methods

A critical detail to note is that shipping methods are rarely singletons in a multi-zone environment. Unlike simple product attributes, shipping logic often involves splitting costs based on location or weight. When you query the shipping method ID, ensure your code accounts for the return type being an array. Iterating over this result set is essential if you need to apply specific logic per shipping zone.

$methods = $order->get_shipping_method_id();
foreach ( $methods as $method_id ) {
    // Process each method ID, e.g., 'flat_rate', 'express'
    echo "Shipping Method: " . esc_html( $method_id );
}

Why Direct Property Access Fails

The source material mentions trying $order->get_data() in a loop and finding the data protected. This stems from the fact that WC_Order extends WC_Object, which wraps internal arrays to ensure data integrity. Directly accessing properties like $order->data['shipping_method'] is technically possible but discouraged because it bypasses the validation layer and cache mechanisms. The framework expects you to use the accessor methods provided, such as get_shipping_method_id().

Attempting to access protected members directly without going through the data store can lead to unpredictable behavior if the order object has been serialized or modified by other plugins. Always prefer the public API first. If the public API does not return the specific raw ID string you need for a legacy integration, falling back to $order->get_data_store() is the correct technical path forward.

For developers building on top of WooCommerce who find themselves needing deeper access to order internals, resources like https://laravelcompany.com can offer insights into how modern PHP frameworks handle similar object-relational mapping challenges, though specific WooCommerce implementation details should always be verified against the official documentation for the version you are targeting.

Our network