Add WooCommerce Order Notes to order Emails

  • July 15, 2022
  • 0
Hire Vivek Asodariya

Nothing more than keeping information about the order you placed, its status or any other data that you may find useful regarding your order.

By default WooCommerce stores every action linked to the order in the database. This range of actions is available in Administration, in the sidebar when you edit an order. But your customers do not have access to this list of actions.

But you can use that method to add an order note to any other email.

Store owners want to add a specific order note in Woocommerce to a failed, completed, canceled order email to the admin.

Is there a way to get a note to the customer to show up on the top side of a cancellation email? We would like for the customer to know the reason for the cancellation and then include an email address for them to respond to on the cancellation email.

Add below code in your (child) theme’s functions.php. If you don’t have a child theme then you can create the custom plugin and then you can add the below code on that plugin.

// Add comments to Failed order emails add_action( ‘woocommerce_email_before_order_table’, ‘wpezi_add_order_notes_to_email’, 10, 4 ); function wpezi_add_order_notes_to_email( $order, $sent_to_admin, $plain_text, $email ) { // You want to send those only to the Admin if ( ! $sent_to_admin ) { return; } // You can also check which email you are sending, by checking the order status // Optional, comment it out, if not needed if ( ‘cancelled’ != $order->get_status() ) { // Will end execution, with everything other than the completed order email. return; } // Get the admin order notes $args = array( ‘limit’ => ”, ‘order_id’ => $order->get_id(), ); $notes = wc_get_order_notes( $args ); // If there are no notes if ( empty($notes) ) { echo ‘<li class=”no-order-comment”>There are no order notes</li>’; return; } echo ‘<div style=”font-family:Helvetica Neue,Helvetica,Roboto,Arial,sans-serif;font-size:120%;line-height:110%;color:#d43c42;font-weight:bold;padding-bottom:10px;”>Cancelled Order Notes</div>’; echo ‘<div class=”order_notes”>’; foreach( $notes as $note ) { if(!empty($note->customer_note)){ $note_classes = $note->customer_note ? array( ‘customer-note’, ‘note’ ) : array( ‘note’ ); ?> <div rel=”<?php echo absint($note->id); ?>” class=”<?php echo implode(‘ ‘, $note_classes); ?>”> <div class=”note_content”> <?php echo wpautop( wptexturize( wp_kses_post( $note->content ) ) ); ?> </div> </div> <?php } } echo ‘</div>’; }

The order not will appear on the order item box.

Well, I hope you enjoyed this post, please leave a comment in the comment form, I’d like to get your feedback about it!

Leave a Reply

Your email address will not be published. Required fields are marked *