我写了一个自定义用户注册表单,用于处理我的WordPress Woocommerce网站的登录和注册 .
当用户通过我的自定义表单处理程序注册时,我触发了Woocommerce向新用户发送电子邮件 . 但我需要在电子邮件中添加激活码 .
有可能这样做吗?
谢谢
首先,您需要在用户元数据中注册此激活码 .
For example 在您的代码中使用类似于:
// 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 );
然后你可以使用挂在woocommerce_email_header动作钩子中的自定义函数:
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>' ); } }
代码放在活动子主题(或主题)的function.php文件中,或者放在任何插件文件中 .
或者您可以在WooCommerce模板中插入 customer-new-account.php 这个类似的代码:
customer-new-account.php
<?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>' ); } ?>
1 回答
首先,您需要在用户元数据中注册此激活码 .
For example 在您的代码中使用类似于:
然后你可以使用挂在woocommerce_email_header动作钩子中的自定义函数:
代码放在活动子主题(或主题)的function.php文件中,或者放在任何插件文件中 .
或者您可以在WooCommerce模板中插入
customer-new-account.php
这个类似的代码: