Helper function
Here’s a helper function (untested) to check if a given user ID is the first commenter for a given post ID:
/**
* Check if a given user ID is the first commenter for a given post ID
*
* @param int $user_id User ID
* @param int $post_id Post ID
* @return bool True/False
*/
function wpse_is_user_first_commenter( $user_id = 0, $post_id = 0 )
{
$first_comment = get_comments(
[
'status' => 'approve',
'number' => 1,
'order' => 'ASC',
'orderby' => 'comment_date_gmt',
'post_id' => (int) $post_id,
]
);
if( empty( $first_comment ) )
return false;
return $first_comment[0]->user_id === $user_id;
}
Usage example:
Check if the current user is the first commenter of the current post:
if ( wpse_is_user_first_commenter( get_current_user_id(), get_the_ID() ) )
{
// ...
}
Hope you can adjust it to your needs!