This snippet adds a “Customer Note” column to your WooCommerce orders admin table, displaying any special instructions or comments customers left during checkout. Never miss important delivery instructions or special requests again!
Adds a dedicated column in the orders list showing customer notes/comments with smart truncation for long messages. Includes an expand/collapse feature for lengthy notes and visual indicators for orders requiring special attention.
/**
* Add customer notes column to WooCommerce orders admin table
* Shows order notes/comments left by customers during checkout
* Prefix: tpsc_ (TP Snippet Collection)
*/
// Add customer note column to orders table
add_filter('manage_woocommerce_page_wc-orders_columns', 'tpsc_add_customer_note_column');
function tpsc_add_customer_note_column($columns) {
$new_columns = array();
foreach ($columns as $column_name => $column_info) {
$new_columns[$column_name] = $column_info;
// Add after order status column
if ('order_status' === $column_name) {
$new_columns['customer_note'] = __('Customer Note', 'woocommerce');
}
}
return $new_columns;
}
// Add content to customer note column
add_action('manage_woocommerce_page_wc-orders_custom_column', 'tpsc_show_customer_note_content', 10, 2);
function tpsc_show_customer_note_content($column, $order) {
if ('customer_note' === $column) {
if (!is_a($order, 'WC_Order')) {
$order = wc_get_order($order);
}
if (!$order) {
return;
}
$note = $order->get_customer_note();
if ($note) {
// Truncate long notes
$truncated = wp_trim_words($note, 15, '...');
$has_more = (strlen($note) > strlen($truncated));
// Output note with icon
echo '<div class="tpsc-customer-note">';
echo '<span class="dashicons dashicons-admin-comments"></span>';
echo '<span class="tpsc-note-text" data-full-note="' . esc_attr($note) . '">';
echo esc_html($truncated);
if ($has_more) {
echo ' <a href="#" class="tpsc-note-toggle" onclick="tpscToggleNote(this); return false;">[more]</a>';
}
echo '</span>';
echo '</div>';
} else {
echo '<span class="na">–</span>';
}
}
}
// Add styles and scripts for customer note column
add_action('admin_head', 'tpsc_customer_note_column_assets');
function tpsc_customer_note_column_assets() {
$screen = get_current_screen();
if ($screen && 'woocommerce_page_wc-orders' === $screen->id) {
?>
<style>
/* Column styling */
.column-customer_note {
width: 15%;
min-width: 150px;
}
/* Note container */
.tpsc-customer-note {
display: flex;
align-items: flex-start;
gap: 6px;
padding: 5px;
background: #fff9e6;
border: 1px solid #f0e5c1;
border-radius: 4px;
font-size: 13px;
line-height: 1.5;
}
/* Icon styling */
.tpsc-customer-note .dashicons {
flex-shrink: 0;
color: #f0ad4e;
font-size: 16px;
margin-top: 2px;
}
/* Note text */
.tpsc-note-text {
flex: 1;
color: #666;
}
/* Toggle link */
.tpsc-note-toggle {
color: #2271b1;
text-decoration: none;
font-weight: 600;
font-size: 11px;
white-space: nowrap;
}
.tpsc-note-toggle:hover {
text-decoration: underline;
}
/* Expanded note */
.tpsc-note-expanded {
background: #fffbf0;
border-color: #e8d89f;
}
.tpsc-note-expanded .tpsc-note-text {
white-space: pre-wrap;
word-break: break-word;
}
/* Empty state */
.column-customer_note .na {
color: #999;
font-style: italic;
}
/* Hover effect */
.tpsc-customer-note:hover {
background: #fffcf2;
border-color: #e8d89f;
box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}
/* Priority indicator for long notes */
.tpsc-customer-note.has-long-note {
border-left: 3px solid #f0ad4e;
}
</style>
<script>
function tpscToggleNote(link) {
const noteSpan = link.parentElement;
const container = noteSpan.closest('.tpsc-customer-note');
const fullNote = noteSpan.getAttribute('data-full-note');
if (link.textContent === '[more]') {
// Show full note
noteSpan.innerHTML = noteSpan.getAttribute('data-full-note') +
' <a href="#" class="tpsc-note-toggle" onclick="tpscToggleNote(this); return false;">[less]</a>';
container.classList.add('tpsc-note-expanded');
} else {
// Show truncated note
const truncated = fullNote.split(' ').slice(0, 15).join(' ');
noteSpan.innerHTML = truncated + '...' +
' <a href="#" class="tpsc-note-toggle" onclick="tpscToggleNote(this); return false;">[more]</a>';
container.classList.remove('tpsc-note-expanded');
}
}
// Add long note indicator on load
document.addEventListener('DOMContentLoaded', function() {
document.querySelectorAll('.tpsc-customer-note').forEach(function(note) {
const fullNote = note.querySelector('.tpsc-note-text').getAttribute('data-full-note');
if (fullNote && fullNote.length > 100) {
note.classList.add('has-long-note');
}
});
});
</script>
<?php
}
}
Something not working as expected? Need help customizing it for your specific needs?
Have an idea for functionality you're missing on your site? Tell us what you're looking for!
Share it with us! Our community loves learning and growing together.
No comments yet.