Hi,
Thank you for contacting us,
Custom fields will always be displayed in predefined positions in both Order Details Page and Order Email.
In Order Details page, all custom fields will always be displayed along with ‘Customer Details’. And in Order Email, all custom fields will always be displayed just before ‘Your details’ section.
Below example code can be used to display custom fields as part of address.
add_filter( ‘woocommerce_order_formatted_billing_address’ , ‘my_default_address_fields’, 10,2 );
function my_default_address_fields( $fields, $order ) {
$address_3 = get_post_meta( $order->id, ‘billing_address_3’, true ); // use your custom field name here(ex: billing_address_3)
$fields[‘address_3’] = $address_3;
return $fields;
}
add_filter( ‘woocommerce_formatted_address_replacements’, ‘add_new_replacement_fields’,10,2 );
function add_new_replacement_fields( $replacements, $address ) {
$replacements[‘{address_3}’] = isset($address[‘address_3’]) ? $address[‘address_3’] : ”;
return $replacements;
}
add_filter( ‘woocommerce_localisation_address_formats’, ‘my_address_formats’ );
function my_address_formats( $formats ) {
// Rearrange these fields how you need, each country has an entry in the array like this:
$formats[‘IN’] = “{name}\n{company}\n{address_1}\n{address_2}\n{address_3}\n{city}, {state} {postcode}\n{country}”;
return $formats;
}
Regards,
Support-ThemeHigh