First remove the filter that does NOT allow to query the order_notes
[code:1:09a748a616]remove_filter(’comments_clauses’, array( ‘WC_Comments’ ,’exclude_order_comments’), 10, 1 );[/code:1:09a748a616]
Now, get the comments
[code:1:09a748a616]$comments = get_comments( [ ‘post_id’ => $wc_order->get_id(), ‘comment_type’ => ‘order_note’ ]);[/code:1:09a748a616]
@see class-wc-comments.php
[code:1:09a748a616] /**
* Exclude order comments from queries and RSS.
*
* This code should exclude shop_order comments from queries. Some queries (like the recent comments widget on the dashboard) are hardcoded.
* and are not filtered, however, the code current_user_can( ‘read_post’, $comment->comment_post_ID ) should keep them safe since only admin and.
* shop managers can view orders anyway.
*
* The frontend view order pages get around this filter by using remove_filter(’comments_clauses’, array( ‘WC_Comments’ ,’exclude_order_comments’), 10, 1 );
*
* @param array $clauses A compacted array of comment query clauses.
* @return array
*/
public static function exclude_order_comments( $clauses ) {
$clauses[’where’] .= ( $clauses[’where’] ? ‘ AND ‘ : ” ) . ” comment_type != ‘order_note’ “;
return $clauses;
}[/code:1:09a748a616]
Leave a Reply