简体   繁体   中英

WooCommerce: Show notice on new order email if specific payment method is used

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 );

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 );

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM