removed order notes from wp_count_comments() function, closes #5732
This commit is contained in:
parent
0e623e2c50
commit
2fb2d8dfb6
|
@ -46,7 +46,7 @@ add_filter( 'woocommerce_short_description', 'do_shortcode', 11 ); // AFTER wpau
|
|||
* Create a new order programmatically
|
||||
*
|
||||
* Returns a new order object on success which can then be used to add additonal data.
|
||||
*
|
||||
*
|
||||
* @return WC_Order on success, WP_Error on failure
|
||||
*/
|
||||
function wc_create_order( $args = array() ) {
|
||||
|
@ -107,7 +107,7 @@ function wc_create_order( $args = array() ) {
|
|||
if ( is_numeric( $args['customer_id'] ) ) {
|
||||
update_post_meta( $order_id, '_customer_user', $args['customer_id'] );
|
||||
}
|
||||
|
||||
|
||||
return new WC_Order( $order_id );
|
||||
}
|
||||
|
||||
|
@ -552,4 +552,53 @@ function wc_ms_protect_download_rewite_rules( $rewrite ) {
|
|||
|
||||
return $rule . $rewrite;
|
||||
}
|
||||
add_filter( 'mod_rewrite_rules', 'wc_ms_protect_download_rewite_rules' );
|
||||
add_filter( 'mod_rewrite_rules', 'wc_ms_protect_download_rewite_rules' );
|
||||
|
||||
/**
|
||||
* Remove order notes from wp_count_comments()
|
||||
*
|
||||
* @since 2.2
|
||||
* @param object $stats
|
||||
* @param int $post_id
|
||||
* @return object
|
||||
*/
|
||||
function wc_remove_order_notes_from_wp_count_comments( $stats, $post_id ) {
|
||||
global $wpdb;
|
||||
|
||||
if ( 0 === $post_id ) {
|
||||
|
||||
$count = wp_cache_get( 'comments-0', 'counts' );
|
||||
if ( false !== $count ) {
|
||||
return $count;
|
||||
}
|
||||
|
||||
$count = $wpdb->get_results( "SELECT comment_approved, COUNT( * ) AS num_comments FROM {$wpdb->comments} WHERE comment_type != 'order_note' GROUP BY comment_approved", ARRAY_A );
|
||||
|
||||
$total = 0;
|
||||
$approved = array( '0' => 'moderated', '1' => 'approved', 'spam' => 'spam', 'trash' => 'trash', 'post-trashed' => 'post-trashed' );
|
||||
|
||||
foreach ( (array) $count as $row ) {
|
||||
// Don't count post-trashed toward totals
|
||||
if ( 'post-trashed' != $row['comment_approved'] && 'trash' != $row['comment_approved'] ) {
|
||||
$total += $row['num_comments'];
|
||||
}
|
||||
if ( isset( $approved[ $row['comment_approved'] ] ) ) {
|
||||
$stats[ $approved[ $row['comment_approved'] ] ] = $row['num_comments'];
|
||||
}
|
||||
}
|
||||
|
||||
$stats['total_comments'] = $total;
|
||||
foreach ( $approved as $key ) {
|
||||
if ( empty( $stats[ $key ] ) ) {
|
||||
$stats[ $key ] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
$stats = (object) $stats;
|
||||
wp_cache_set( 'comments-0', $stats, 'counts' );
|
||||
}
|
||||
|
||||
return $stats;
|
||||
}
|
||||
|
||||
add_filter( 'wp_count_comments', 'wc_remove_order_notes_from_wp_count_comments', 10, 2 );
|
||||
|
|
Loading…
Reference in New Issue