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:
- 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_landmarkorshipping_phone. - Add Custom Code: Insert the following code snippet into your child theme's
functions.phpfile. 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; } - Modify the Format: The
woocommerce_localisation_address_formatsfilter 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_emailorbilling_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
-
Custom fields – setting place to display in emailhttps://wordpress.org/support/topic/custom-fields-setting-place-to-display-in-email/
-
Positioning in emailhttps://wordpress.org/support/topic/positioning-in-email/
-
Custom Email Template displayhttps://wordpress.org/support/topic/custom-email-template-display/
-
Custom Checkout Fields label in emailhttps://wordpress.org/support/topic/custom-checkout-fields-label-in-email/
-
Multi-line address fieldhttps://wordpress.org/support/topic/multi-line-address-field/
-
filed labels “title” shwoing in the emailhttps://wordpress.org/support/topic/filed-labels-title-shwoing-in-the-email/
-
billing_title and shipping_titlehttps://wordpress.org/support/topic/billing_title-and-shipping_title/
-
Titel (z. B. “Professor”) in Mails und Rechnunghttps://wordpress.org/support/topic/titel-z-b-professor-in-mails-und-rechnung-2/
-
Position of custom billing fieldhttps://wordpress.org/support/topic/position-of-custom-billing-field/
-
Email with fields orderinghttps://wordpress.org/support/topic/email-with-fields-ordering/
-
How to show Heading and Label in emailhttps://wordpress.org/support/topic/how-to-show-heading-and-label-in-email/
-
Hide doubled fields in order E-mailshttps://wordpress.org/support/topic/hide-doubled-fields-in-order-e-mails/
-
Additional address field to show under addresshttps://wordpress.org/support/topic/additional-address-field-to-show-under-address/
-
Display Custom Field Under The Address in The Emailhttps://wordpress.org/support/topic/display-custom-field-under-the-address-in-the-email/
-
Custom Field positioninghttps://wordpress.org/support/topic/custom-field-positioning/
-
Custom field above the title “billing address” in customer e-mail templatehttps://wordpress.org/support/topic/custom-field-above-the-title-billing-address-in-customer-e-mail-template/
-
Custom Fields locationhttps://wordpress.org/support/topic/custom-fields-location-3/
-
Insert name of a field in the subject of the order emailhttps://wordpress.org/support/topic/insert-name-of-a-field-in-the-subject-of-the-order-email/
-
Reorder fields on thank you pagehttps://wordpress.org/support/topic/reorder-fields-on-thank-you-page/
-
Use fields in confirmation emailhttps://wordpress.org/support/topic/use-fields-in-confirmation-email/
-
Reposition Added Shipping Field in Emailhttps://wordpress.org/support/topic/reposition-added-shipping-field-in-email/
-
How to fix position in new fieldhttps://wordpress.org/support/topic/how-to-fix-position-in-new-field/
-
How to display the custom field value/text in the Title of email?https://wordpress.org/support/topic/how-to-display-the-custom-field-value-text-in-the-title-of-email/
-
New Order Email show ‘temptitle’ instead of From namehttps://wordpress.org/support/topic/new-order-email-show-temptitle-instead-of-from-name/
-
Custom Field (Landmark) not appearing below Billing Addresshttps://wordpress.org/support/topic/custom-field-landmark-not-appearing-below-billing-address/
-
Extra Field position in eMailhttps://wordpress.org/support/topic/extra-field-position-in-email/
-
Custom Field in Email confirmationhttps://wordpress.org/support/topic/custom-field-in-email-confirmation/
-
Want to Show Email under billing sectionhttps://wordpress.org/support/topic/want-to-show-email-under-billing-section/
-
Add Suburb to billing & shipping address on order emailhttps://wordpress.org/support/topic/add-suburb-to-billing-shipping-address-on-order-email/