1

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.

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/

| improve this answer | |
  • I have read the doc. Don't you need that specific extension for this to work? – Stanley Tan Jul 29 at 1:48
  • I have tried this and it doesn't work for me. I changed meta-key to wpcf-store-number. Both the field label and custom field don't show up in the email. – Stanley Tan Jul 30 at 0:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.