Add WooCommerce Order Notes to Completed Emails From Your WordPress Store

By WP Saviour •  Updated: 03/06/21 •  3 min read

There’s nothing greater than having particulars about an order you made referring to its standing or each different data that you will discover useful referring to your order. By default WooCommerce outlets every movement linked to an order throughout the database. This assortment of actions is obtainable throughout the administration, throughout the sidebar when you edit an order. Nevertheless your purchasers don’t have entry to this actions file. The good news is you may merely add it to any piece of email despatched by WooCommerce. On this publish, I am going to current you add in order so as to add the order notes the entire piece of email (it’s the e-mail despatched when the order standing is marked as completed). Nevertheless you must use that methodology in order so as to add the order notes to each different emails as successfully.

Custom-made templates or hooks?

Solely a quick reminder: all emails inside WooCommerce are supplied using templates, and you may override default templates by creating your particular person templates. Principally a custom-made template enables you to override WooCommerce default info and use your particular person custom-made info as an alternative. This is a quick tutorial which will make clear you the easiest way to create your custom-made templates: http://docs.woothemes.com/doc/template-structure/.

You probably can add the order notes inside a custom-made templates, nevertheless i want to current you one different method to do it, using a hook. The thought is to not use custom-made templates, nevertheless to utilize the capabilities.php file inside your theme folder solely.

Order notes are WordPress suggestions

Order notes are WordPress suggestions having a specific type “order_note”, so you must use the WordPress WP_Query class utilized to suggestions using the get_comments() carry out.

The hook we’ve got to make use of is an movement known as “woocommerce_email_order_meta”. The thought is to call a custom-made carry out when this movement is loaded throughout the WooCommerce course of.

Using get_comments() simplifies a lo the best way through which we are going to retrieve the order notes, we merely should ensure that we want to file the suggestions linked to a specific order using the publish ID and the “approve” comment attribute which signifies that the comment is validated (by WooCommerce on this case).

The code

Proper right here is the code to place contained in the capabilities.php file in your theme folder:

add_action( 'woocommerce_email_order_meta', 'woo_add_order_notes_to_email' ); carry out woo_add_order_notes_to_email() { worldwide $woocommerce, $publish; $args = array( 'post_id' => $publish->ID, 'approve' => 'approve', 'type' => 'order_note' ); $notes = get_comments( $args ); echo '

' . __( 'Order Notes', 'woocommerce' ) . '

'; echo '

WP Saviour