Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Add custom order data (order notes) to make it accessible in Order preview template.
- add_filter( 'woocommerce_admin_order_preview_get_order_details', 'admin_order_preview_add_order_notes', 10, 2 );
- function admin_order_preview_add_order_notes( $data, $order ) {
- // $notes = $order->get_customer_order_notes();
- $args = array(
- 'order_id' => $order->get_id(),
- 'orderby' => 'date_created',
- 'type' => '', // use 'internal' for admin and system notes, empty for all
- );
- $notes = wc_get_order_notes( $args );
- ob_start();
- if ( $notes ) {
- foreach( $notes as $note ) {
- $note_classes = get_comment_meta( $note->comment_ID, 'is_customer_note', true ) ? array( 'customer-note', 'note' ) : array( 'note' );
- ?>
- <li rel="<?php echo absint( $note->comment_ID ) ; ?>" class="<?php echo implode( ' ', $note_classes ); ?>">
- <div class="note_content">
- (<?php printf( __( 'added %s ago', 'woocommerce' ), human_time_diff( strtotime( $note->comment_date_gmt ), current_time( 'timestamp', 1 ) ) ); ?>)
- <?php echo wpautop( wptexturize( wp_kses_post( $note->content ) ) ); ?>
- </div>
- </li>
- <?php
- }
- } else {
- echo '<li>' . __( 'There are no notes for this order yet.', 'woocommerce' ) . '</li>';
- }
- $data['order_notes'] = ob_get_clean();
- return $data;
- }
- // Display custom values in Order preview.
- add_action( 'woocommerce_admin_order_preview_end', 'custom_display_order_notes_in_admin' );
- function custom_display_order_notes_in_admin() {
- printf( '
- <div style="padding: 1em 1.5em;">
- <h2>%s</h2>
- <ul class="order_notes">
- {{{data.order_notes}}}
- </ul>
- </div>',
- __( 'Order Notes', 'woocommerce' )
- );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement