Hi @brijesh24
Yes, you can include pretty much any data you want in the email. The transaction ID is stored by WooCommerce and is available by using the WC_Order::get_transaction_id()
method. The order object is accessible within the email template so you can use that object to display the transaction ID.
Kind Regards
Got it. I came up with the code below with help of Chat GPT and it works well. Thank you for the help.
add_action('woocommerce_email_order_meta', 'add_transaction_id_to_admin_email', 20, 4);
function add_transaction_id_to_admin_email($order, $sent_to_admin, $plain_text, $email) {
// Check if the email is being sent to the admin
if ($sent_to_admin && isset($email) && $email->id === 'new_order') {
// Get the transaction ID from the order object
$transaction_id = $order->get_transaction_id();
// Only display the transaction ID if it exists
if ($transaction_id) {
if ($plain_text) {
// For plain text emails
echo "Transaction ID: " . $transaction_id . "\n";
} else {
// For HTML emails
echo '<p><strong>Stripe Transaction ID:</strong> ' . esc_html($transaction_id) . '</p>';
}
}
}
}