diff --git a/ps_emailsubscription.php b/ps_emailsubscription.php index 18c9147..8d7de00 100644 --- a/ps_emailsubscription.php +++ b/ps_emailsubscription.php @@ -948,23 +948,24 @@ public function hookActionCustomerAccountAdd($params) if (empty($params['newCustomer'])) { return false; } + $id_shop = $params['newCustomer']->id_shop; $email = $params['newCustomer']->email; $newsletter = $params['newCustomer']->newsletter; - if (Validate::isEmail($email)) { - if ($params['newCustomer']->newsletter && $code = Configuration::get('NW_VOUCHER_CODE')) { - $this->sendVoucher($email, $code); - } - return (bool) Db::getInstance()->execute('DELETE FROM ' . _DB_PREFIX_ . 'emailsubscription WHERE id_shop=' . (int) $id_shop . ' AND email=\'' . pSQL($email) . "'"); + if (!Validate::isEmail($email)) { + return false; } if ($newsletter) { - if (Configuration::get('NW_CONFIRMATION_EMAIL')) {// send confirmation email - $this->sendConfirmationEmail($params['newCustomer']->email); - } + Db::getInstance()->execute('DELETE FROM ' . _DB_PREFIX_ . 'emailsubscription WHERE id_shop=' . (int) $id_shop . ' AND email=\'' . pSQL($email) . "'"); + if ($code = Configuration::get('NW_VOUCHER_CODE')) {// send voucher - $this->sendVoucher($params['newCustomer']->email, $code); + $this->sendVoucher($email, $code); + } + + if (Configuration::get('NW_CONFIRMATION_EMAIL')) {// send confirmation email + $this->sendConfirmationEmail($email); } }