1

I want to add a notice to "new order" email sent to admins before the table so if customer paid with "Purchase Order", processing team will know the payment is pending.

Research & Work Done: I spent some time researching various tuts and docs and came up with the Version 1 code but it's not showing anything on the order email (I changed the code Version 2 and tried again but to no avail). Are the codes wrong? I just want to confirm before I look into other options. Thank you

Version 1

/* Payment pending instruction if payment method is "Purchase Order" */
function add_order_instruction_email( $order, $sent_to_admin, $plain_text, $email ) {
    if ( $sent_to_admin ) {
        echo '<p><strong>Payment Method:</strong> '.$order->payment_method_title().'</p>';
        if ( 'Purchase Order' == $order->get_payment_method_title() ) {
            /* if purchase order method is used */
            echo '<p><strong>Note:</strong> Payment is pending, please contact customer for payment before processing order for shipping.</p>';
        }
    }
}
add_action( 'woocommerce_before_email_order_table', 'add_order_instruction_email', 20, 4 );

Version 2

/* Payment pending instruction if payment method is "Purchase Order" */
function add_order_instruction_email( $order, $sent_to_admin, $plain_text, $email ) {
    if ( $email->id == 'new_order' ) {
        echo '<p><strong>Payment Method:</strong> '.$order->payment_method_title().'</p>';
        if ( 'Purchase Order' == $order->get_payment_method_title() ) {
            /* if purchase order method is used */
            echo '<p><strong>Note:</strong> Payment is pending, please contact customer for payment before processing order for shipping.</p>';
        }
    }
}
add_action( 'woocommerce_before_email_order_table', 'add_order_instruction_email', 10, 2 );
Danish Muneer
  • 568
  • 1
  • 9
  • 22
  • What version of woocommerce are you using? Is this action even called? I didn't find it on [woocommerce's hook reference](https://docs.woocommerce.com/wc-apidocs/hook-docs.html). – Guilherme Pressutto Dec 27 '18 at 17:31
  • okay I made a mistake in this post it's get_payment_method_title() (post now updated) ..using latest WC version. You can find it here: https://docs.woocommerce.com/wc-apidocs/class-WC_Order.html and https://businessbloomer.com/woocommerce-easily-get-order-info-total-items-etc-from-order-object/ – Danish Muneer Dec 27 '18 at 17:53
  • 1
    What about the action? I'm talking about `woocommerce_before_email_order_table` – Guilherme Pressutto Dec 27 '18 at 18:03
  • oops...you are right! I have fixed the code, it's working now. Thanks @GuilhermePressutto – Danish Muneer Dec 27 '18 at 18:16

1 Answers1

1

If someone else is interested in this, here's what worked for me:

/* Payment pending instruction if payment method is "Purchase Order" */
function add_order_instruction_email( $order, $sent_to_admin, $plain_text, $email ) {
    if ( $email->id == 'new_order' ) {
        if ( 'Purchase Order' == $order->get_payment_method_title() ) {
            echo '<p><strong>Note:</strong> Payment is pending, please contact customer for payment before processing order for shipping.</p>';
        }
    }
}
add_action( 'woocommerce_email_order_details', 'add_order_instruction_email', 10, 4 );
Danish Muneer
  • 568
  • 1
  • 9
  • 22