Created
November 17, 2016 16:55
-
-
Save kellenmace/730a34b4d29449446d4379b9caadee22 to your computer and use it in GitHub Desktop.
Get All WooCommerce Order Notes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Get all approved WooCommerce order notes. | |
* | |
* @param int|string $order_id The order ID. | |
* @return array $notes The order notes, or an empty array if none. | |
*/ | |
function km_get_order_notes( $order_id ) { | |
remove_filter( 'comments_clauses', array( 'WC_Comments', 'exclude_order_comments' ) ); | |
$comments = get_comments( array( | |
'post_id' => $order_id, | |
'orderby' => 'comment_ID', | |
'order' => 'DESC', | |
'approve' => 'approve', | |
'type' => 'order_note', | |
) ); | |
$notes = wp_list_pluck( $comments, 'comment_content' ); | |
add_filter( 'comments_clauses', array( 'WC_Comments', 'exclude_order_comments' ) ); | |
return $notes; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi!
Your work is amazing. How can I show all the data - same with what we see on the right side of the Edit Order page?
When I simply use the class WC_Meta_Box_Order_Notes, it's showing as empty.
Thanks!
Eli