# Add Invoice, Tracking and Delivery Data to Order API Responses

> Includes invoice numbers, tracking details, delivery dates and other order fields you list in WooCommerce REST API order responses, for accounting and shipping integrations.

- Type: PHP
- Runs: Run everywhere
- Category: [WooCommerce](https://wpide.com/library/category/woocommerce/)
- Requires: WooCommerce
- Tags: woocommerce, rest-api, orders, integrations
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/woo-rest-order-extra-data/

## Code

```php
$wpide_rest_order_meta = array( // Response field => order meta key.
    'invoice_number' => '_wpide_invoice_number',
    'carrier'        => '_wpide_carrier',
    'tracking'       => '_wpide_tracking',
    'delivery_date'  => '_wpide_delivery_date',
    'po_number'      => '_wpide_po_number',
);

add_filter( 'woocommerce_rest_prepare_shop_order_object', function ( $response, $order ) use ( $wpide_rest_order_meta ) {
    $extra = array();

    foreach ( $wpide_rest_order_meta as $field => $key ) {
        $extra[ $field ] = $order->get_meta( $key );
    }

    $response->data['wpide'] = $extra;

    return $response;
}, 10, 2 );
```

## Notes

Read-only; the default keys match other WPIDE snippets (invoice numbers, tracking, delivery date) and you can add your own.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Add Invoice, Tracking and Delivery Data to Order API Responses" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
