From d1dce11535494a4636d857c1b9e0dcd3db328243 Mon Sep 17 00:00:00 2001 From: Hristijan Manasijev <34198639+KIKOmanasijev@users.noreply.github.com> Date: Wed, 19 Jun 2024 17:35:11 +0200 Subject: [PATCH] =?UTF-8?q?Feat:=20add=20filter=20to=20toggle=20showing=20?= =?UTF-8?q?tooltips=20over=20Order=20statuses=20in=20da=E2=80=A6=20(#47861?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Feat: add filter to toggle showing tooltips over Order statuses in dashboard * Use status labels when hovering over Order status badge * wip * Add changelog * Fix lint issues * Reset indentation * Reset indentation --------- Co-authored-by: Adrian Duffell <9312929+adrianduffell@users.noreply.github.com> --- .../changelog/2024-06-11-14-30-36-229170 | 4 ++ .../src/Internal/Admin/Orders/ListTable.php | 62 +++++++++++-------- 2 files changed, 39 insertions(+), 27 deletions(-) create mode 100644 plugins/woocommerce/changelog/2024-06-11-14-30-36-229170 diff --git a/plugins/woocommerce/changelog/2024-06-11-14-30-36-229170 b/plugins/woocommerce/changelog/2024-06-11-14-30-36-229170 new file mode 100644 index 00000000000..7bf5a98f02c --- /dev/null +++ b/plugins/woocommerce/changelog/2024-06-11-14-30-36-229170 @@ -0,0 +1,4 @@ +Significance: minor +Type: enhancement + +Modified order status tooltip labels diff --git a/plugins/woocommerce/src/Internal/Admin/Orders/ListTable.php b/plugins/woocommerce/src/Internal/Admin/Orders/ListTable.php index 944bf1d0552..b568f1effa6 100644 --- a/plugins/woocommerce/src/Internal/Admin/Orders/ListTable.php +++ b/plugins/woocommerce/src/Internal/Admin/Orders/ListTable.php @@ -1030,33 +1030,8 @@ class ListTable extends WP_List_Table { * @return void */ public function render_order_status_column( WC_Order $order ): void { - $tooltip = ''; - remove_filter( 'comments_clauses', array( 'WC_Comments', 'exclude_order_comments' ), 10, 1 ); - $comment_count = get_comment_count( $order->get_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->get_id(), - 'limit' => 1, - 'orderby' => 'date_created_gmt', - ) - ); - - $latest_note = current( $latest_notes ); - - if ( isset( $latest_note->content ) && 1 === $approved_comments_count ) { - $tooltip = wc_sanitize_tooltip( $latest_note->content ); - } elseif ( isset( $latest_note->content ) ) { - /* translators: %d: notes count */ - $tooltip = wc_sanitize_tooltip( $latest_note->content . '
' . sprintf( _n( 'Plus %d other note', 'Plus %d other notes', ( $approved_comments_count - 1 ), 'woocommerce' ), $approved_comments_count - 1 ) . '' ); - } else { - /* translators: %d: notes count */ - $tooltip = wc_sanitize_tooltip( sprintf( _n( '%d note', '%d notes', $approved_comments_count, 'woocommerce' ), $approved_comments_count ) ); - } - } + /* translators: %s: order status label */ + $tooltip = wc_sanitize_tooltip( $this->get_order_status_label( $order ) ); // Gracefully handle legacy statuses. if ( in_array( $order->get_status(), array( 'trash', 'draft', 'auto-draft' ), true ) ) { @@ -1072,6 +1047,39 @@ class ListTable extends WP_List_Table { } } + /** + * Gets the order status label for an order. + * + * @param WC_Order $order The order object. + * + * @return string + */ + private function get_order_status_label( WC_Order $order ): string { + $status_names = array( + 'Pending payment' => __( 'The order has been received, but no payment has been made. Pending payment orders are generally awaiting customer action.', 'woocommerce' ), + 'On hold' => __( 'The order is awaiting payment confirmation. Stock is reduced, but you need to confirm payment.', 'woocommerce' ), + 'Processing' => __( 'Payment has been received (paid), and the stock has been reduced. The order is awaiting fulfillment.', 'woocommerce' ), + 'Completed' => __( 'Order fulfilled and complete.', 'woocommerce' ), + 'Failed' => __( 'The customer’s payment failed or was declined, and no payment has been successfully made.', 'woocommerce' ), + 'Draft' => __( 'Draft orders are created when customers start the checkout process while the block version of the checkout is in place.', 'woocommerce' ), + 'Canceled' => __( 'The order was canceled by an admin or the customer.', 'woocommerce' ), + 'Refunded' => __( 'Orders are automatically put in the Refunded status when an admin or shop manager has fully refunded the order’s value after payment.', 'woocommerce' ), + ); + + /** + * Provides an opportunity to modify and extend the order status labels. + * + * @param array $action Order actions. + * @param WC_Order $order Current order object. + * @since 9.1.0 + */ + $status_names = apply_filters( 'woocommerce_get_order_status_labels', $status_names ); + + $status_name = wc_get_order_status_name( $order->get_status() ); + + return isset( $status_names[ $status_name ] ) ? $status_names[ $status_name ] : ''; + } + /** * Renders order billing information. *