How to add a user custom field into Woocommerce emails?

admin2025-01-08  4

How do you add a user custom field into Woocommerce emails?

This is my code so far in functions.php

add_filter( 'woocommerce_email_order_meta_fields', 'custom_woocommerce_email_order_meta_fields', 10, 3 );

function custom_woocommerce_email_order_meta_fields( $fields, $sent_to_admin, $order ) {
    $fields['meta_key'] = array(
        'label' => __( 'Store number' ),
        'value' => get_user_meta( $user_id, 'wpcf-store-number', true ),
    );
    return $fields;
}

The user custom field is wpcf-store-number which is already in the database. All I need to do now is to show it in the order confirmation email / New order email.

How do you add a user custom field into Woocommerce emails?

This is my code so far in functions.php

add_filter( 'woocommerce_email_order_meta_fields', 'custom_woocommerce_email_order_meta_fields', 10, 3 );

function custom_woocommerce_email_order_meta_fields( $fields, $sent_to_admin, $order ) {
    $fields['meta_key'] = array(
        'label' => __( 'Store number' ),
        'value' => get_user_meta( $user_id, 'wpcf-store-number', true ),
    );
    return $fields;
}

The user custom field is wpcf-store-number which is already in the database. All I need to do now is to show it in the order confirmation email / New order email.

Share Improve this question edited Jul 23, 2020 at 21:41 mozboz 2,6081 gold badge12 silver badges23 bronze badges asked Jul 23, 2020 at 6:04 Stanley TanStanley Tan 1951 gold badge1 silver badge10 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

this link will help you. It is from the Woocommerce repository only

https://docs.woocommerce.com/document/add-a-custom-field-in-an-order-to-the-emails/

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1736266702a1141.html

最新回复(0)