简体   繁体   English

WooCommerce中何时触发新订单邮件? 尝试在发送前添加新值

[英]When the new order mail is trigger in WooCommerce? Trying to add a new value before send it

I have a plugin for official payment (Transbank of Chile) in WooCommerce but this plugin print the transaction_id directly in a "thankyou" page. 我在WooCommerce中有一个官方付款插件(智利的Transbank),但是此插件直接在“ thankyou”页面中打印transaction_id I did to get this transaction and add to the database. 我确实获得了该交易并将其添加到数据库中。

The problem is when WooCommerce send the "new Order" mail the transaction_id is never shown. 问题是当WooCommerce发送“新订单”邮件时, transaction_id永远不会显示。 I think that mail already sent before I get the transaction_id number. 我认为在获得transaction_id号之前已经发送了邮件。 I want to know, when WooCommerce send the new order mail? 我想知道,WooCommerce何时发送新订单邮件?

You can use woocommerce_email_after_order_table hook to add custom data into Email. 您可以使用woocommerce_email_after_order_table挂钩将自定义数据添加到电子邮件中。

/**
 * 
 * @param instance $order
 * @param bool $sent_to_admin TRUE for admin
 */
function wh_addTransactionIdOrderEmail($order, $sent_to_admin)
{
    $order_id = method_exists($order, 'get_id') ? $order->get_id() : $order->id;
    $transaction_id = get_post_meta($order_id, "_transaction_id ", true); //<-- replace it with your metakey
    if(empty($transaction_id)) //if blank i.e for Failed/Cancelled order then do not add transaction ID
        return;
    echo '<p></p><p><strong>Transaction ID:</strong> ' . $transaction_id . '</p>';
}

add_action('woocommerce_email_after_order_table', 'wh_addTransactionIdOrderEmail', 10, 2);

Code goes in functions.php file of your active child theme (or theme). 代码进入您的活动子主题(或主题)的functions.php文件中。 Or also in any plugin php files. 或在任何插件php文件中。
Code is tested and works. 代码已经过测试并且可以正常工作。

Hope this helps! 希望这可以帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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