Skip to content

Instantly share code, notes, and snippets.

@corsonr
Created Jan 22, 2014
Embed
What would you like to do?
woocommerce - add order notes to completed emails
<?php
add_action( 'woocommerce_email_order_meta', 'woo_add_order_notes_to_email' );
function woo_add_order_notes_to_email() {
global $woocommerce, $post;
$args = array(
'post_id' => $post->ID,
'approve' => 'approve',
'type' => 'order_note'
);
$notes = get_comments( $args );
echo '<h2>' . __( 'Order Notes', 'woocommerce' ) . '</h2>';
echo '<ul class="order_notes">';
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->comment_content ) ) ); ?>
</div>
</li>
<?php
}
} else {
echo '<li>' . __( 'There are no notes for this order yet.', 'woocommerce' ) . '</li>';
}
echo '</ul>';
}
@RPDeshaies

This comment has been minimized.

Copy link

@RPDeshaies RPDeshaies commented Jun 23, 2014

I'm getting an error in my email :

Notice: Trying to get property of non-object in /home/my-project/public_html/wp-content/themes/default/functions.php on line 626

because of :

global $woocommerce, $post;

$args = array(
    'post_id'   => $post->ID, // line 626 error !
    'approve'   => 'approve',
    'type'      => 'order_note'
);
@toledox82

This comment has been minimized.

Copy link

@toledox82 toledox82 commented Jul 23, 2014

Try 'status' => 'approve',

@ea0723

This comment has been minimized.

Copy link

@ea0723 ea0723 commented May 6, 2015

In order for this to work in the latest woocommerce email templates, I needed to add

?>

to the end

@numzie

This comment has been minimized.

Copy link

@numzie numzie commented Nov 4, 2015

I can see the comments are split between 'privat' and 'what the customer can see'.
Is it possible through this script only to show the 'customer comments'?

I need just to include a note where I post the tracking link.

@ElyFornoville

This comment has been minimized.

Copy link

@ElyFornoville ElyFornoville commented Mar 21, 2018

It would be nice to indeed only add the tracking link that is posted as a customer note.

@programmerkev

This comment has been minimized.

Copy link

@programmerkev programmerkev commented Jul 25, 2018

If all you need is the customer comments, try replacing this:

function woo_add_order_notes_to_email() {
	global $woocommerce, $post;
	$args = array(
		'post_id' 	=> $post->ID,
		'approve' 	=> 'approve',
		'type' 		=> 'order_note'
	);
	$notes = get_comments( $args );

with this:

function woo_add_order_notes_to_email($order) {
        $notes = $order->get_customer_order_notes();
@sandresson

This comment has been minimized.

Copy link

@sandresson sandresson commented Feb 10, 2020

Hello, great snippet of code but it applies to all the emails including the processing and invoice. Is there any way to target the completed email only?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment