WooCommerce:如果使用特定付款方式,则在新订单电子邮件上显示通知

时间:2018-12-27 17:16:50

标签: php wordpress woocommerce hook-woocommerce

我想在表格之前向管理员发送的“新订单”电子邮件中添加一条通知,因此,如果客户使用“购买订单”付款,则处理团队将知道付款正在处理中。

完成研究和工作: 我花了一些时间研究各种tut和文档,并提出了 Version 1 代码,但订单电子邮件中没有显示任何内容(我更改了 Version 2 代码,然后重试但无济于事)。密码有误吗?我只想确认一下,然后再考虑其他选项。谢谢

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

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

1 个答案:

答案 0 :(得分:1)

如果其他人对此感兴趣,这对我有用:

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