How to Properly Trigger Default WooCommerce Welcome Email Using Meta Key Change
-
I am using the BitForm plugin to create a custom registration form with WordPress authentication and email confirmation. This form creates a new WordPress user with the role of “customer” and assigns a custom meta key (bf_activation) with an initial value of
0
. Once the user confirms their email address, the plugin updates the meta value from0
to1
, allowing the user to fully access and use my WooCommerce shop.What I need is a way to trigger the default WooCommerce “New User Welcome Email” after the user confirms their email address (i.e., when the meta value changes from
0
to1
). I have already tried several solutions, but I am encountering an issue with email styling.Here’s the problem:
- If I manually trigger the WooCommerce new user email immediately after the user is created by BitForm, the email is sent correctly with the appropriate styling (as I am using Kadence Email Customizer to override default WooCommerce email templates).
- However, if I trigger the email after the user confirms their email address, the email is sent with broken styling and missing footer content. This seems to happen because WooCommerce is not triggering the full registration process at this stage.
Exemple - add_action(‘updated_user_meta’, ‘send_woocommerce_new_user_email’, 10, 4);
- function send_woocommerce_new_user_email($meta_id, $user_id, $meta_key, $meta_value) {
- if ($meta_key === ‘bf_activation’ && $meta_value == 1) {
- $user = get_userdata($user_id);
- if ($user) {
- // Trigger WooCommerce “New Account” email
- $mailer = WC()->mailer();
- $email = $mailer->emails[‘WC_Email_Customer_New_Account’];
- // Manually trigger the email
- $email->trigger($user_id, $user);
- }
- }
- }
Could you please help me find a solution to:
- Trigger the default WooCommerce “New User Welcome Email” after the user confirms their email address.
- Ensure that the email is sent with the correct styling and formatting, as defined by Kadence Email Customizer.
Thank you for your assistance!
- You must be logged in to reply to this topic.