# Record Which Staff Member Changed an Order Status

> Adds the name of the logged-in user to the order notes every time an order status changes, so you can see who marked an order shipped or refunded.

- Type: PHP
- Runs: Run everywhere
- Category: [WooCommerce](https://wpide.com/library/category/woocommerce/)
- Requires: WooCommerce
- Tags: woocommerce, orders, notes, audit
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/woo-log-status-changes-by-user/

## Code

```php
add_action( 'woocommerce_order_status_changed', function ( $order_id, $from, $to, $order ) {
    $user = wp_get_current_user();

    if ( ! $user->exists() || ! current_user_can( 'edit_shop_orders' ) || ! $order instanceof WC_Order ) {
        return;
    }

    $order->add_order_note( sprintf( 'Status changed from %1$s to %2$s by %3$s.', wc_get_order_status_name( $from ), wc_get_order_status_name( $to ), $user->display_name ), false, true );
}, 10, 4 );
```

## Notes

Status changes made by payment gateways, cron or the customer are not labelled, since no staff user is logged in.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Record Which Staff Member Changed an Order Status" 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/
