Advertisement
Udoro

order notes in order preview (shows all notes, date bug)

Mar 18th, 2021 (edited)
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. // Add custom order data (order notes) to make it accessible in Order preview template.
  2. add_filter( 'woocommerce_admin_order_preview_get_order_details', 'admin_order_preview_add_order_notes', 10, 2 );
  3. function admin_order_preview_add_order_notes( $data, $order ) {
  4. // $notes = $order->get_customer_order_notes();
  5.  
  6. $args = array(
  7. 'order_id' => $order->get_id(),
  8. 'orderby' => 'date_created',
  9. 'type' => '', // use 'internal' for admin and system notes, empty for all
  10. );
  11.  
  12. $notes = wc_get_order_notes( $args );
  13.  
  14. ob_start();
  15.  
  16. if ( $notes ) {
  17. foreach( $notes as $note ) {
  18. $note_classes = get_comment_meta( $note->comment_ID, 'is_customer_note', true ) ? array( 'customer-note', 'note' ) : array( 'note' );
  19.  
  20. ?>
  21. <li rel="<?php echo absint( $note->comment_ID ) ; ?>" class="<?php echo implode( ' ', $note_classes ); ?>">
  22. <div class="note_content">
  23. (<?php printf( __( 'added %s ago', 'woocommerce' ), human_time_diff( strtotime( $note->comment_date_gmt ), current_time( 'timestamp', 1 ) ) ); ?>)
  24. <?php echo wpautop( wptexturize( wp_kses_post( $note->content ) ) ); ?>
  25. </div>
  26. </li>
  27. <?php
  28. }
  29. } else {
  30. echo '<li>' . __( 'There are no notes for this order yet.', 'woocommerce' ) . '</li>';
  31. }
  32.  
  33. $data['order_notes'] = ob_get_clean();
  34.  
  35. return $data;
  36. }
  37.  
  38. // Display custom values in Order preview.
  39. add_action( 'woocommerce_admin_order_preview_end', 'custom_display_order_notes_in_admin' );
  40. function custom_display_order_notes_in_admin() {
  41. printf( '
  42. <div style="padding: 1em 1.5em;">
  43. <h2>%s</h2>
  44. <ul class="order_notes">
  45. {{{data.order_notes}}}
  46. </ul>
  47. </div>',
  48. __( 'Order Notes', 'woocommerce' )
  49. );
  50. }
  51.  
  52.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement