Commit f112a1a2d7c for woocommerce
commit f112a1a2d7c4afa47067bf932dca9defb533a59a
Author: Abhishek Sharma <abhisheksharmaa1404@gmail.com>
Date: Mon Aug 24 23:59:58 2026 +0530
Exclude WordPress notes from the comment count cache (#67795)
---------
Co-authored-by: Jorge Torres <jorge.torres@automattic.com>
diff --git a/plugins/woocommerce/changelog/67610-fix-note-comment-count b/plugins/woocommerce/changelog/67610-fix-note-comment-count
new file mode 100644
index 00000000000..76aad32304c
--- /dev/null
+++ b/plugins/woocommerce/changelog/67610-fix-note-comment-count
@@ -0,0 +1,4 @@
+Significance: patch
+Type: fix
+
+Exclude WordPress editorial notes from the WooCommerce comment count cache, so adding a note no longer inflates the pending comment count shown in wp-admin.
diff --git a/plugins/woocommerce/includes/class-wc-comments.php b/plugins/woocommerce/includes/class-wc-comments.php
index f93d8117555..16be6d325b9 100644
--- a/plugins/woocommerce/includes/class-wc-comments.php
+++ b/plugins/woocommerce/includes/class-wc-comments.php
@@ -329,7 +329,7 @@ class WC_Comments {
* @return bool
*/
private static function is_comment_excluded_from_wp_comment_counts( $comment ) {
- return in_array( $comment->comment_type, array( 'action_log', 'order_note', 'webhook_delivery' ), true )
+ return in_array( $comment->comment_type, array( 'action_log', 'note', 'order_note', 'webhook_delivery' ), true )
|| get_post_type( $comment->comment_post_ID ) === 'product';
}
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 b4eb51262d4..913d126d795 100644
--- a/plugins/woocommerce/tests/php/includes/class-wc-comments-test.php
+++ b/plugins/woocommerce/tests/php/includes/class-wc-comments-test.php
@@ -150,4 +150,79 @@ class WC_Comments_Tests extends \WC_Unit_Test_Case {
$this->assertTrue( has_filter( 'akismet_excluded_comment_types' ) );
$this->assertSame( array( 'order_note' ), apply_filters( 'akismet_excluded_comment_types', array() ) );
}
+
+ /**
+ * @testdox Should not increment the cached comment count for comment types excluded from the counts.
+ *
+ * @testWith ["action_log"]
+ * ["note"]
+ * ["order_note"]
+ * ["webhook_delivery"]
+ *
+ * @param string $comment_type Comment type that should be excluded from the counts.
+ */
+ public function test_excluded_comment_types_do_not_increment_the_count_cache( string $comment_type ): void {
+ $post_id = wp_insert_post(
+ array(
+ 'post_title' => 'A post that is not a product',
+ 'post_status' => 'publish',
+ 'post_type' => 'post',
+ )
+ );
+
+ wp_cache_set( 'wc_count_comments_unapproved', 0, 'wc_comment_counts' );
+
+ $comment_id = wp_insert_comment(
+ array(
+ 'comment_post_ID' => $post_id,
+ 'comment_type' => $comment_type,
+ 'comment_approved' => '0',
+ )
+ );
+
+ $this->assertSame(
+ 0,
+ wp_cache_get( 'wc_count_comments_unapproved', 'wc_comment_counts' ),
+ "Inserting a '{$comment_type}' comment should leave the cached unapproved count untouched"
+ );
+
+ // Clean up.
+ wp_delete_comment( $comment_id, true );
+ wp_delete_post( $post_id, true );
+ }
+
+ /**
+ * @testdox Should still increment the cached comment count for a regular comment.
+ *
+ * Guards the test above: without this, the exclusion assertions could pass for the wrong reason.
+ */
+ public function test_regular_comments_still_increment_the_count_cache(): void {
+ $post_id = wp_insert_post(
+ array(
+ 'post_title' => 'A post that is not a product',
+ 'post_status' => 'publish',
+ 'post_type' => 'post',
+ )
+ );
+
+ wp_cache_set( 'wc_count_comments_unapproved', 0, 'wc_comment_counts' );
+
+ $comment_id = wp_insert_comment(
+ array(
+ 'comment_post_ID' => $post_id,
+ 'comment_type' => 'comment',
+ 'comment_approved' => '0',
+ )
+ );
+
+ $this->assertSame(
+ 1,
+ wp_cache_get( 'wc_count_comments_unapproved', 'wc_comment_counts' ),
+ 'A regular comment should increment the cached unapproved count'
+ );
+
+ // Clean up.
+ wp_delete_comment( $comment_id, true );
+ wp_delete_post( $post_id, true );
+ }
}