延迟向Woocommerce发送新的客户帐户电子邮件

时间:2019-08-27 16:58:58

标签: wordpress woocommerce

在使用wc_create_new_customer函数以编程方式创建客户之后,我正在生成新的优惠券并将其链接到用户ID。我想延迟发送新的客户帐户电子邮件,直到生成优惠券,然后将优惠券包含在发送的电子邮件中。

据我所知,电子邮件是在创建新客户后立即发送的,但是正如您从下面看到的那样,优惠券取决于已经创建了user_id

是否可以在不覆盖和创建自己的电子邮件类别的情况下延迟发送新帐户电子邮件?

public
  function create_user($post_id)
  {
        /** Get acf $_POST fields **/
    $acf                                = $_POST['acf'];
    $email              = $acf['field_landing_page_form_email'];
    $first_name         = $acf['field_landing_page_form_first_name'];
    $last_name          = $acf['field_landing_page_form_last_name'];
    $mobile             = $acf['field_landing_page_form_mobile'];
    $password           = $acf['field_landing_page_form_password'];

        $args = [
         'billing_first_name'    => $first_name,
         'billing_last_name'     => $last_name,
         'billing_phone'         => $mobile,
         'billing_email'                 => $email
        ];

        /** Create new customer from $_POST fields **/
        $user_id = wc_create_new_customer($email, $email, $password, $args);

        /** Get @var WC_User */
        $user = get_user_by( 'id', $user_id );

        /** Check if user is already logged in */
         if (!is_user_logged_in() ) {
             $signin = [
          'user_login'    => $user->user_login,
          'user_password' => $password,
          'remember'      => true
        ];
          $login = wp_signon($signin, false );

          if (is_wp_error($login) ) {
             error_log( $login->get_error_message() );
          }
         }

        /** Generate coupon and assign to new user **/
        $coupon = $this->create_coupon($user_id, $post_id);
  }

0 个答案:

没有答案