简体   繁体   中英

Edit customer details in Woocommerce email notifications

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?

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…

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM