LLMS_Comments::wp_count_comments( object $stats, int $post_id )
Remove order notes from the count when counting comments
Description Description
See also See also
- thanks: WooCommerce 😀
Parameters Parameters
- $stats
-
(object) (Required) original comment stats
- $post_id
-
(int) (Required) WP Post ID
Return Return
(object)
Source Source
File: includes/class.llms.comments.php
public static function wp_count_comments( $stats, $post_id ) { global $wpdb; if ( 0 === $post_id ) { $trans = get_transient( 'llms_count_comments' ); if ( ! $trans ) { $count = $wpdb->get_results( "SELECT comment_approved, COUNT( * ) AS num_comments FROM {$wpdb->comments} WHERE comment_type = 'llms_order_note' GROUP BY comment_approved;", ARRAY_A ); $approved = array( '0' => 'moderated', '1' => 'approved', 'spam' => 'spam', 'trash' => 'trash', 'post-trashed' => 'post-trashed', ); foreach ( $count as $row ) { // Don't count post-trashed toward totals if ( 'post-trashed' != $row['comment_approved'] && 'trash' != $row['comment_approved'] ) { $stats->total_comments -= $row['num_comments']; } if ( isset( $approved[ $row['comment_approved'] ] ) ) { $var = $approved[ $row['comment_approved'] ]; $stats->$var -= $row['num_comments']; } } set_transient( 'llms_count_comments', $stats ); } else { $stats = $trans; } } return $stats; }
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
Version | Description |
---|---|
3.0.0 | Introduced. |