簡體   English   中英

WooCommerce中何時觸發新訂單郵件? 嘗試在發送前添加新值

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

我在WooCommerce中有一個官方付款插件(智利的Transbank),但是此插件直接在“ thankyou”頁面中打印transaction_id 我確實獲得了該交易並將其添加到數據庫中。

問題是當WooCommerce發送“新訂單”郵件時, transaction_id永遠不會顯示。 我認為在獲得transaction_id號之前已經發送了郵件。 我想知道,WooCommerce何時發送新訂單郵件?

您可以使用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);

代碼進入您的活動子主題(或主題)的functions.php文件中。 或在任何插件php文件中。
代碼已經過測試並且可以正常工作。

希望這可以幫助!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM