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.

1 Answer 1

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/

2
  • I have read the doc. Don't you need that specific extension for this to work? Commented Jul 29, 2020 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. Commented Jul 30, 2020 at 0:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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