Get the Official WPSaviour App Now!


Add WooCommerce Order Notes to Completed Emails From Your WordPress Store

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:

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 '<h2>' . __( 'Order Notes', 'woocommerce' ) . '</h2>';

	echo '<ul class="order_notes">';

	if ( $notes ) {
		foreach( $notes as $observe ) {
			$note_classes = get_comment_meta( $observe->comment_ID, 'is_customer_note', true ) ? array( 'customer-note', 'observe' ) : array( 'observe' );

			<li rel="comment_ID ) ; ?>" class="">
				<div class="note_content">
					comment_content ) ) ); ?>
				<p class="meta">
					comment_date_gmt ), current_time( 'timestamp', 1 ) ) ); ?>
	} else {
		echo '<li>' . __( 'There usually are not any notes for this order however.', 'woocommerce' ) . '</li>';

	echo '</ul>';

As you can see this code is pretty straightforward, nothing really difficult, so you can merely customise it. Please observe the utilization of some good capabilities like human_time_diff(), wptexturize(), or wp_kses_post().

Download The WPSaviour App Now

Related posts
Beginner’s GuideBlogShowcase

7 Best Shopify Alternatives in 2020 (Cheaper and More Powerful)

Beginner’s GuideBest WordPress PluginsBlog

14 Best AI Chatbots Software for Your Website (Comparison)

Beginner’s GuideBlogTips

Magento vs WooCommerce – Which one is Better? (Comparison)

Beginner’s GuideBlogTips

12 Best Calculator Plugins for Your WordPress Site

Sign up for our Newsletter and
stay informed

Fear Of Missing Out?

Sign up with your email address to receive WordPress tips and updates
Terms and Conditions apply
Click Me