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.
Opens WPIDE on
Code
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 add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.