1

I am importing some users using wp_insert_user function. I am trying to send WooCommerce new account email, when user is successfully imported. It works fine, when there is only one user. But if there are multiple users, the email comes with multiple header and footer loop!

This is what the email looks like, when I am importing four users: enter image description here

This is how my code looks like:

foreach ($users as $user) {
    $user_id = wp_insert_user( $userdata[$user] );
    $wc = new WC_Emails();
    $wc->customer_new_account( $user_id, null, true );
}
mujuonly
  • 11,370
  • 5
  • 45
  • 75
тнє Sufi
  • 574
  • 2
  • 9
  • 23

1 Answers1

1
foreach ($users as $user) {
    $user_id = wp_insert_user( $userdata[$user] );
    global $woocommerce;
    $mailer = $woocommerce->mailer();
    $mailer->customer_new_account( $user_id, null, true );
}

Try like this

mujuonly
  • 11,370
  • 5
  • 45
  • 75
  • Thanks. This worked perfectly. Also moving `$wc = new WC_Emails();` out of foreach loop solved the issue for me. – тнє Sufi Apr 05 '22 at 21:05