Support » Plugin: WooCommerce » Include Order Notes with Admin New order Email

  • I’m using WooCommerce and want to have the Admin New order email notification include the Customer Notes that are created by Woocomerce, as distinct from Customer entered Notes. Is there a placeholder variable that I can put into the email template to do this?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hey,

    I don’t understand your question that well.

    What do you mean by ‘Customer Notes that are created by Woocomerce’. Do you have an example (sreenshot) of this?

    Regards

    It’s the Order Notes on the upper right hand side of the Orders screen that I want included in the email to Admin.

    How do I add a file to these forum messages?

    Order notes (private note) are only available for backend when using get_comments() function. If you look at WC_Comments exclude_order_comments() method you will see that front end queries are filtered regarding private order notes…

    So the turn around is to build a custom function to get the private Order notes:

    function get_private_order_notes( $order_id){
        global $wpdb;
    
        $table_perfixed = $wpdb->prefix . 'comments';
        $results = $wpdb->get_results("
            SELECT *
            FROM $table_perfixed
            WHERE  <code>comment_post_ID</code> = $order_id
            AND  <code>comment_type</code> LIKE  'order_note'
        ");
    
        foreach($results as $note){
            $order_note[]  = array(
                'note_id'      => $note->comment_ID,
                'note_date'    => $note->comment_date,
                'note_author'  => $note->comment_author,
                'note_content' => $note->comment_content,
            );
        }
        return $order_note;
    }

    Code goes in function.php file of your active child theme (or theme) or also in any plugin file.

    Usage (for example the $order_id = 6238 ):

    $order_id = 6238;
    $order_notes = get_private_order_notes( $order_id );
    foreach($order_notes as $note){
        $note_id = $note['note_id'];
        $note_date = $note['note_date'];
        $note_author = $note['note_author'];
        $note_content = $note['note_content'];
    
        // Outputting each note content for the order
        echo '<p>'.$note_content.'</p>';
    }
Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.