Skip to content

Instantly share code, notes, and snippets.

@acodesmith
Created August 25, 2017 15:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save acodesmith/4659c23b0789f7c0cbfe0e4067506d58 to your computer and use it in GitHub Desktop.
Save acodesmith/4659c23b0789f7c0cbfe0e4067506d58 to your computer and use it in GitHub Desktop.
Add Order Notes to all WooCommerce emails
<?php
function add_order_notes($order)
{
remove_filter('comments_clauses', array('WC_Comments', 'exclude_order_comments'));
$args = array(
'order' => 'DESC',
'approve' => 'approve',
'type' => 'order_note',
'post_id' => 4087
);
$comments = get_comments($args);
if( ! empty( $comments ) ): ?>
<h2><?php _e('Order Notes', 'woocommerce'); ?></h2>
<?php
$count = 0;
/** @var \WP_Comment $comment */
foreach ($comments as $k => $comment) :
$comment_meta = get_comment_meta($comment->comment_ID);
if ( ! empty( $comment_meta ) && ! empty( $comment_meta[ 'is_customer_note' ] ) ) :
$count++; ?>
<table>
<tbody>
<tr>
<td>
<?= $comment->comment_content; ?>
</td>
</tr>
</tbody>
<tfoot>
<tr>
<td>
<?= __( 'Added On', 'kho-fabric' ); ?> <?= date( 'd-m-Y', strtotime( $comment->comment_date ) ); ?>
</td>
</tr>
</tfoot>
</table>
<?= $count > 1 ? '<hr />' : ''; ?>
<?php endif;
endforeach;
endif;
add_filter( 'comments_clauses', array( 'WC_Comments', 'exclude_order_comments' ) );
}
add_action( 'woocommerce_email_after_order_table', 'add_order_notes', 10, 1 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment