您可以直接使用 $order 与此电子邮件模板中的所有 WC_Order 方法,以获取订单 ID,这样:
// Get the Order ID (WooCommerce retro-compatibility)
$order_id = method_exists( $order, 'get_id' ) ? $order->get_id() : $order->id;
// Get "serial" custom field value
$serial = get_post_meta($order_id, "wccaf_serial", true );
// Display "serial" custom field value
echo '<p>'.__('Serial', 'woocommerce') . $serial . '</p>';
请阅读:Template Structure + Overriding Templates via a Theme
除了覆盖这个模板,你还可以使用任何可用的钩子,例如:
add_action( 'woocommerce_email_order_details', 'action_wc_email_order_details' 50, 4 );
function action_wc_email_order_details( $order, $sent_to_admin, $plain_text, $email ){
// Get the Order ID (WooCommerce retro-compatibility)
$order_id = method_exists( $order, 'get_id' ) ? $order->get_id() : $order->id;
// Get "serial" custom field value
$serial = get_post_meta($order_id, "wccaf_serial", true );
// Display "serial" custom field value
echo '<p>'.__('Serial', 'woocommerce') . $serial . '</p>';
}
代码进入您的活动子主题(或主题)的 function.php 文件或任何插件文件中。
代码经过测试,可在 WooCommerce 2.6.x 或 3+ 中运行