First you need to register this activation code in the user metadata.
For example using in your code something like:
// Set your activation code in the user meta
$activation_code = 'dHu12548-oh$r' // example for a generated activation code
// Saving the activation code in user meta data.
update_user_meta( $user_id, 'activation_code', $activation_code );
Then you can use a custom function hooked in woocommerce_email_header action hook:
add_action( 'woocommerce_email_header', 'custom_email_new_account', 100, 2 );
function custom_email_new_account( $email_heading, $email ) {
if ( 'customer_new_account' === $email->id ){
$user_id = $email->object->ID;
$activation_code = get_user_meta( $user_id, 'activation_code', $true );
// Displaying the activation code
printf( __( 'Here is your activation code: %s', 'woocommerce' ), '<strong>' . esc_html( $activation_code ) . '</strong>' );
}
}
Code goes in function.php file of your active child theme (or theme) or also in any plugin file.
Or you can insert in the WooCommerce template customer-new-account.php
this similar code:
<?php
if ( 'customer_new_account' === $email->id ){
$user_id = $email->object->ID;
$activation_code = get_user_meta( $user_id, 'activation_code', $true );
// Displaying the activation code
printf( __( 'Here is your activation code: %s', 'woocommerce' ), '<strong>' . esc_html( $activation_code ) . '</strong>' );
}
?>