Skip to content

Instantly share code, notes, and snippets.

@mino129
Last active August 26, 2024 09:09
Show Gist options
  • Select an option

  • Save mino129/0e5d7ee44ddbba4fb4a7162a4038549d to your computer and use it in GitHub Desktop.

Select an option

Save mino129/0e5d7ee44ddbba4fb4a7162a4038549d to your computer and use it in GitHub Desktop.
Restore the old tooltip functionality in WooCommerce (show order comments).
<?php
function add_old_order_status_tooltips( $status_names, $order ) {
$order_id = $order->get_id();
$order_status = wc_get_order_statuses();
remove_filter( 'comments_clauses', array( 'WC_Comments', 'exclude_order_comments' ), 10, 1 );
$comment_count = get_comment_count( $order_id );
add_filter( 'comments_clauses', array( 'WC_Comments', 'exclude_order_comments' ), 10, 1 );
$approved_comments_count = absint( $comment_count['approved'] );
if ( $approved_comments_count ) {
$latest_notes = wc_get_order_notes( array(
'order_id' => $order_id,
'limit' => 1,
'orderby' => 'date_created_gmt',
) );
$latest_note = current( $latest_notes );
if ( isset( $latest_note->content ) && 1 === $approved_comments_count ) {
$message = wc_sanitize_tooltip( $latest_note->content );
} elseif ( isset( $latest_note->content ) ) {
$message = wc_sanitize_tooltip( $latest_note->content . '<br/><small style="display:block">' . sprintf(
/* translators: %d: notes count */
_n( 'Plus %d other note', 'Plus %d other notes', ( $approved_comments_count - 1 ), 'woocommerce' ),
$approved_comments_count - 1
) . '</small>' );
} else {
$message = wc_sanitize_tooltip( sprintf(
/* translators: %d: notes count */
_n( '%d note', '%d notes', $approved_comments_count, 'woocommerce' ),
$approved_comments_count
) );
}
}
foreach ($order_status as $order_status_name) {
$status_names[$order_status_name] = ($message) ? $message : $order_status_name;
}
return $status_names;
}
add_filter( 'woocommerce_get_order_status_labels', 'add_old_order_status_tooltips', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment