Halloween Sale 15% off Ends in See the plans
PHP

Flag Orders That Have a Customer Note

Adds a narrow column to the admin orders list with an icon on orders where the customer left a note, and shows the note when you hover over it.

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

Code

$wpide_note_column = function ( $columns ) {
    $new = array();

    foreach ( $columns as $key => $label ) {
        $new[ $key ] = $label;

        if ( 'order_number' === $key ) {
            $new['wpide_note'] = '<span class="dashicons dashicons-format-chat" title="Customer note"></span><span class="screen-reader-text">Customer note</span>';
        }
    }

    return $new;
};

$wpide_note_render = function ( $column, $order ) {
    if ( 'wpide_note' !== $column ) {
        return;
    }

    $order = $order instanceof WC_Order ? $order : wc_get_order( $order );
    $note  = $order ? trim( (string) $order->get_customer_note() ) : '';

    if ( '' !== $note ) {
        printf( '<span class="dashicons dashicons-format-chat" style="color:#d63638" title="%1$s"></span><span class="screen-reader-text">%2$s</span>', esc_attr( $note ), esc_html( $note ) );
    }
};

add_filter( 'manage_woocommerce_page_wc-orders_columns', $wpide_note_column );
add_filter( 'manage_edit-shop_order_columns', $wpide_note_column );
add_action( 'manage_woocommerce_page_wc-orders_custom_column', $wpide_note_render, 10, 2 );
add_action( 'manage_shop_order_posts_custom_column', $wpide_note_render, 10, 2 );

add_action( 'admin_head', function () {
    echo '<style>.column-wpide_note{width:2.5em;text-align:center}</style>';
} );

Notes

Helps you spot delivery instructions and gift messages before packing.

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.