Back to Community

How to Reposition Custom Checkout Fields in WooCommerce Emails and Order Details

Content

A common challenge when using the 'Checkout Field Editor (Checkout Manager) for WooCommerce' plugin is that custom fields often appear in an unexpected location within order confirmation emails and on the order details page. Instead of being neatly integrated with the standard billing or shipping address, they are frequently displayed in a separate "Custom Checkout Fields" section above the address information. This guide explains why this happens and provides the most effective solutions to reposition these fields.

Why Custom Fields Appear in the Wrong Place

By default, WooCommerce has a predefined structure for formatting and displaying address information. The 'Checkout Field Editor' plugin adds custom fields to the checkout form and saves their values as order meta data. However, for these fields to appear within the formatted address block in emails and order summaries, they must be explicitly integrated into WooCommerce's address formatting system. The plugin's "Display in Emails" option makes the field's value available, but it does not automatically change its position within the email's HTML structure. This is not a bug in the plugin but a fundamental aspect of how WooCommerce handles address data.

Solution 1: Override the Address Format (Most Common Solution)

The primary method for integrating a custom field into the billing or shipping address block is to override WooCommerce's default address format using code. This involves using filters to add your custom field to the array of formatted address data.

Step-by-Step Guide:

  1. Identify Your Field's Meta Key: Find the exact name (meta key) of your custom field. This is typically the name you gave it in the Checkout Field Editor, such as billing_landmark or shipping_phone.
  2. Add Custom Code: Insert the following code snippet into your child theme's functions.php file. This example adds a custom "Landmark" field to the billing address.
    // Add custom field to formatted billing address
    add_filter( 'woocommerce_order_formatted_billing_address', 'my_custom_formatted_billing_address', 10, 2 );
    function my_custom_formatted_billing_address( $address, $order ) {
        $address['landmark'] = $order->get_meta('billing_landmark'); // Replace 'billing_landmark' with your field's meta key
        return $address;
    }
    
    // Add custom field to formatted shipping address (if needed)
    add_filter( 'woocommerce_order_formatted_shipping_address', 'my_custom_formatted_shipping_address', 10, 2 );
    function my_custom_formatted_shipping_address( $address, $order ) {
        $address['landmark'] = $order->get_meta('shipping_landmark');
        return $address;
    }
    
    // Define the address format for your country, including the new field
    add_filter( 'woocommerce_localisation_address_formats', 'my_custom_address_format' );
    function my_custom_address_format( $formats ) {
        // This adds the {landmark} tag on a new line after {address_2} for all countries
        foreach( $formats as $country => $format ){
            $formats[$country] = $format . "n{landmark}";
        }
        return $formats;
    }
    
    // Replace the placeholder {landmark} with the actual value
    add_filter( 'woocommerce_formatted_address_replacements', 'my_custom_address_replacement', 10, 2 );
    function my_custom_address_replacement( $replacements, $args ) {
        $replacements['{landmark}'] = isset( $args['landmark'] ) ? $args['landmark'] : '';
        return $replacements;
    }
  3. Modify the Format: The woocommerce_localisation_address_formats filter in the code above adds the {landmark} tag for all countries. You can customize this line to precisely position your field. For example, to place it between the address and city, you could use a format like: "{name}n{company}n{address_1}n{address_2}n{landmark}n{city}".

Important Note: After adding this code, you must untick the "Display in Emails" option for the custom field in the Checkout Field Editor settings. If you leave it enabled, the field will appear twice: once within the formatted address (from the code) and once in the separate "Custom Checkout Fields" section (from the plugin's default behavior).

Solution 2: Check Locale Override Settings

For simpler repositioning of address fields (not adding entirely new ones), the plugin offers a built-in tool. Navigate to WooCommerce > Checkout Form > Advanced Settings and find the "Locale override settings." Enable the option "Enable priority override for address fields." This can sometimes allow for easier reordering of standard and custom address fields without code.

Solution 3: Customize the Email Template (Advanced)

If you need to place a field somewhere completely different in the email, like within the salutation, you may need to edit the WooCommerce email template itself. This is a more advanced method and requires creating a custom template in your theme. You would then use WooCommerce's $order->get_meta('your_field_key') function to output the custom field value directly in the template.

Troubleshooting Tips

  • Field Shows Twice: This is almost always because the "Display in Emails" option is still enabled in the Checkout Field Editor after adding the address format code. Disable it.
  • Code Doesn't Work: Double-check that the meta key in your code (e.g., billing_landmark) matches the name of your custom field exactly. Clear any caching on your site after adding the code.
  • Not a Default Address Field: Avoid recreating default WooCommerce fields (like billing_email or billing_address_1) with the plugin, as this can cause conflicts and unexpected behavior.

By following these methods, particularly the address format override, you can seamlessly integrate your custom checkout fields into the appropriate sections of your WooCommerce emails and order details, providing a cleaner and more professional experience for your customers.

Related Support Threads Support