0

I wanted to customize completed order with some extra information. To do so, I added this in functions.php

add_action( 'woocommerce_email_before_order_table', 'mm_email_before_order_table', 10, 4 );
function mm_email_before_order_table( $order, $sent_to_admin, $plain_text, $email ) { 
   echo '<p>extra information</p>';
}

How can I ensure this to work only for completed emails and not other emails (e.g. order creation)

Thank you so much

3
  • Woocommerce has a email template for completed orders, so you can either edit it by creating the appropriate folder/file structure in your child theme of hooking to one of the action of that template, see customer-completed-order.php for all the available actions. Commented Aug 12, 2021 at 7:56
  • There is no simplest way ? I wanted to keep all my code in functions.php Something like if { email = oder completed} {...} ?
    – lt512
    Commented Aug 12, 2021 at 7:58
  • There is, added an answer. I just wanted to show you the available action so you can have some more places to put the content that you want, choose whatever action works best for you =] Commented Aug 12, 2021 at 8:01

1 Answer 1

0

If your code works but it works for all emails you can add a check for only completed orders like this

add_action( 'woocommerce_email_before_order_table', 'mm_email_before_order_table', 10, 4 );
function mm_email_before_order_table( $order, $sent_to_admin, $plain_text, $email ) {
   // if not completed order, exit
   if ($email->id != 'customer_completed_order') return;
   echo '<p>extra information</p>';
}
1
  • exactly what I was looking for , thanks !
    – lt512
    Commented Aug 12, 2021 at 8:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.