1
votes

Where does WooCommerce include custom fields from third party plugins? I would like to edit the order to display all the fields.

In admin-new-order.php, I can just do this by placing the Woocommerce_email_customer_details hook above woocommerce_email_order_meta.

Only how can I archive this with the email my customer will receive?

1

1 Answers

0
votes

Based on the data from this question / answer, this can be done with the following hooked function, that will allow you to edit billing formatted address data:

add_filter( 'woocommerce_order_formatted_billing_address', 'custom_email_formatted_billing_address', 10, 2 );
function custom_email_formatted_billing_address( $billing_address, $order ){
    // Get your custom field
    $real_first_name = get_post_meta( $order->get_id(), '_billing_voornaam_1_24', true );

    // Insert the custom field value in the billing first name
    if( ! empty( $real_first_name ) )
        $billing_address['first_name'] .= ' ' . $real_first_name;

    // Hiding Last name
    unset($billing_address['last_name']);

    return $billing_address;
}

Code goes in function.php file of the active child theme (or active theme).

Tested and works.

For shipping customer details, you will use woocommerce_order_formatted_shipping_address filter hook in the same way…