Commit a113a12a29 for woocommerce
commit a113a12a2931852af5ed6c6d5e5bcaa5cb58e321
Author: Vladimir Reznichenko <kalessil@gmail.com>
Date: Mon Jan 26 08:24:53 2026 +0100
[Performance] Comments: use `akismet_excluded_comment_types`hook to filter out product notes (#62913)
Integrate `akismet_excluded_comment_types` hook from Akismet::get_user_comments_approved() to remove order notes from counting for better SQL performance.
diff --git a/plugins/woocommerce/changelog/perfromance-61916-akismet-comments-count-integration b/plugins/woocommerce/changelog/perfromance-61916-akismet-comments-count-integration
new file mode 100644
index 0000000000..ded4ce1791
--- /dev/null
+++ b/plugins/woocommerce/changelog/perfromance-61916-akismet-comments-count-integration
@@ -0,0 +1,4 @@
+Significance: patch
+Type: performance
+
+Integrate the `akismet_excluded_comment_types` hook from `Akismet::get_user_comments_approved()` to ensure order notes are excluded from the count.
diff --git a/plugins/woocommerce/includes/class-wc-comments.php b/plugins/woocommerce/includes/class-wc-comments.php
index 71a95ca5e7..31d7448527 100644
--- a/plugins/woocommerce/includes/class-wc-comments.php
+++ b/plugins/woocommerce/includes/class-wc-comments.php
@@ -45,8 +45,9 @@ class WC_Comments {
add_action( 'wp_update_comment_count', array( __CLASS__, 'clear_transients' ) );
// Secure order notes.
- add_filter( 'comments_clauses', array( __CLASS__, 'exclude_order_comments' ), 10, 1 );
+ add_filter( 'comments_clauses', array( __CLASS__, 'exclude_order_comments' ) );
add_filter( 'comment_feed_where', array( __CLASS__, 'exclude_order_comments_from_feed_where' ) );
+ add_filter( 'akismet_excluded_comment_types', array( __CLASS__, 'akismet_excluded_comment_types' ) );
// Secure webhook comments.
add_filter( 'comments_clauses', array( __CLASS__, 'exclude_webhook_comments' ), 10, 1 );
@@ -121,6 +122,19 @@ class WC_Comments {
return $clauses;
}
+ /**
+ * Exclude order comments from Akismet comments counting SQL queries for better performance.
+ *
+ * @since 10.6.0
+ *
+ * @param string[] $comment_types Excluded comments types.
+ * @return string[]
+ */
+ public static function akismet_excluded_comment_types( $comment_types ): array {
+ $comment_types[] = 'order_note';
+ return $comment_types;
+ }
+
/**
* Exclude order comments from feed.
*
diff --git a/plugins/woocommerce/tests/php/includes/class-wc-comments-test.php b/plugins/woocommerce/tests/php/includes/class-wc-comments-test.php
index 3f18348640..c868bce866 100644
--- a/plugins/woocommerce/tests/php/includes/class-wc-comments-test.php
+++ b/plugins/woocommerce/tests/php/includes/class-wc-comments-test.php
@@ -142,4 +142,13 @@ class WC_Comments_Tests extends \WC_Unit_Test_Case {
// Clean up.
wp_delete_post( $post_id, true );
}
+
+ /**
+ * Test hook akismet_excluded_comment_types integration.
+ */
+ public function test_integrates_akismet_excluded_comment_types(): void {
+ $this->assertTrue( has_filter( 'akismet_excluded_comment_types' ) );
+ // phpcs:ignore WooCommerce.Commenting.CommentHooks.MissingHookComment
+ $this->assertSame( array( 'order_note' ), apply_filters( 'akismet_excluded_comment_types', array() ) );
+ }
}