You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在WooCommerce邮件中自定义格式化账单全名(含自定义字段)

Customize Admin New Order Email to Show Title + Custom Name Field

Absolutely, you can tweak this to display exactly what you need—your billing first name (the Mr/Mrs title) plus your custom name field! Let’s break down two approaches, including the recommended safe method that won’t break when WooCommerce updates:

1. Quick (but Not Permanent) Core File Edit

If you just need a temporary fix and don’t mind redoing it after WooCommerce updates, you can modify the admin-new-order.php file directly:

  1. Find the line you mentioned:
    <p><?php printf( __( 'You have received an order from %s. The order is as follows:', 'woocommerce' ), $order->get_formatted_billing_full_name() ); ?></p>
    
  2. Replace it with this code (make sure to swap _billing_custom_name with your actual custom field’s meta key):
    <?php
    // Grab the title from billing first name
    $billing_title = $order->get_billing_first_name();
    // Grab your custom name field value (update the meta key below!)
    $custom_name = $order->get_meta('_billing_custom_name');
    // Combine them into the full display text
    $custom_display_name = trim("$billing_title $custom_name");
    ?>
    <p><?php printf( __( 'You have received an order from %s. The order is as follows:', 'woocommerce' ), $custom_display_name ); ?></p>
    

Note: To find your custom field’s meta key, go to any WooCommerce order edit page, scroll down to the "Custom Fields" section, and look for the "Meta Key" associated with your name field (it usually starts with _billing_ if you added it via checkout fields).

Modifying core files isn’t ideal because updates will overwrite your changes. Instead, use a WooCommerce filter hook to override the get_formatted_billing_full_name() output globally (including in the admin new order email):

  1. Go to your WordPress dashboard → Appearance → Theme File Editor → Open your theme’s functions.php file (or use a child theme for extra safety).
  2. Add this code at the bottom (again, replace _billing_custom_name with your actual meta key):
    add_filter('woocommerce_order_formatted_billing_full_name', 'custom_admin_email_billing_name', 10, 2);
    function custom_admin_email_billing_name($formatted_name, $order) {
        // Get the title from billing first name
        $billing_title = $order->get_billing_first_name();
        // Get your custom name field value
        $custom_name = $order->get_meta('_billing_custom_name');
        
        // Only override if the custom name exists; fallback to default if not
        if (!empty($custom_name)) {
            $formatted_name = trim("$billing_title $custom_name");
        }
        
        return $formatted_name;
    }
    
  3. Save the file, and test a new order—your admin email should now show the title plus your custom name field!

This method is better because it’s tied to your theme (or child theme) and won’t be lost when WooCommerce updates.

内容的提问来源于stack exchange,提问作者Carina

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 04:50:04