Halloween Sale 15% off Ends in See the plans
PHP

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.

Don’t have WPIDE yet? Install it on your site

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

  1. Install WPIDE on your WordPress site (it is free) and open Code Snippets.
  2. Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
  3. It is added inactive: review the code and settings, then switch it on.

Have a snippet worth sharing?

Publish it to the library from WPIDE or right here. Sign in with any WordPress site that runs WPIDE, free or Pro. Public snippets are reviewed by the WPIDE team before they appear.

Which site should get this snippet?

Enter the address of your WordPress site. WPIDE opens there in a new tab with the snippet ready to review and save.

Remembered in this browser only, so you are asked once.

Report this snippet

Tell the WPIDE team what is wrong: broken code, something harmful, spam or copied work.