class-wc-email-cancelled-order.php
3 years ago
class-wc-email-customer-completed-order.php
5 years ago
class-wc-email-customer-invoice.php
5 years ago
class-wc-email-customer-new-account.php
4 years ago
class-wc-email-customer-note.php
5 years ago
class-wc-email-customer-on-hold-order.php
3 years ago
class-wc-email-customer-processing-order.php
5 years ago
class-wc-email-customer-refunded-order.php
5 years ago
class-wc-email-customer-reset-password.php
5 years ago
class-wc-email-failed-order.php
5 years ago
class-wc-email-new-order.php
3 years ago
class-wc-email.php
3 years ago
class-wc-email-customer-new-account.php
204 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Class WC_Email_Customer_New_Account file. |
| 4 | * |
| 5 | * @package WooCommerce\Emails |
| 6 | */ |
| 7 | |
| 8 | if ( ! defined( 'ABSPATH' ) ) { |
| 9 | exit; // Exit if accessed directly. |
| 10 | } |
| 11 | |
| 12 | if ( ! class_exists( 'WC_Email_Customer_New_Account', false ) ) : |
| 13 | |
| 14 | /** |
| 15 | * Customer New Account. |
| 16 | * |
| 17 | * An email sent to the customer when they create an account. |
| 18 | * |
| 19 | * @class WC_Email_Customer_New_Account |
| 20 | * @version 3.5.0 |
| 21 | * @package WooCommerce\Classes\Emails |
| 22 | * @extends WC_Email |
| 23 | */ |
| 24 | class WC_Email_Customer_New_Account extends WC_Email { |
| 25 | |
| 26 | /** |
| 27 | * User login name. |
| 28 | * |
| 29 | * @var string |
| 30 | */ |
| 31 | public $user_login; |
| 32 | |
| 33 | /** |
| 34 | * User email. |
| 35 | * |
| 36 | * @var string |
| 37 | */ |
| 38 | public $user_email; |
| 39 | |
| 40 | /** |
| 41 | * User password. |
| 42 | * |
| 43 | * @var string |
| 44 | */ |
| 45 | public $user_pass; |
| 46 | |
| 47 | /** |
| 48 | * Is the password generated? |
| 49 | * |
| 50 | * @var bool |
| 51 | */ |
| 52 | public $password_generated; |
| 53 | |
| 54 | /** |
| 55 | * Magic link to set initial password. |
| 56 | * |
| 57 | * @var string |
| 58 | */ |
| 59 | public $set_password_url; |
| 60 | |
| 61 | /** |
| 62 | * Constructor. |
| 63 | */ |
| 64 | public function __construct() { |
| 65 | $this->id = 'customer_new_account'; |
| 66 | $this->customer_email = true; |
| 67 | $this->title = __( 'New account', 'woocommerce' ); |
| 68 | $this->description = __( 'Customer "new account" emails are sent to the customer when a customer signs up via checkout or account pages.', 'woocommerce' ); |
| 69 | $this->template_html = 'emails/customer-new-account.php'; |
| 70 | $this->template_plain = 'emails/plain/customer-new-account.php'; |
| 71 | |
| 72 | // Call parent constructor. |
| 73 | parent::__construct(); |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * Get email subject. |
| 78 | * |
| 79 | * @since 3.1.0 |
| 80 | * @return string |
| 81 | */ |
| 82 | public function get_default_subject() { |
| 83 | return __( 'Your {site_title} account has been created!', 'woocommerce' ); |
| 84 | } |
| 85 | |
| 86 | /** |
| 87 | * Get email heading. |
| 88 | * |
| 89 | * @since 3.1.0 |
| 90 | * @return string |
| 91 | */ |
| 92 | public function get_default_heading() { |
| 93 | return __( 'Welcome to {site_title}', 'woocommerce' ); |
| 94 | } |
| 95 | |
| 96 | /** |
| 97 | * Trigger. |
| 98 | * |
| 99 | * @param int $user_id User ID. |
| 100 | * @param string $user_pass User password. |
| 101 | * @param bool $password_generated Whether the password was generated automatically or not. |
| 102 | */ |
| 103 | public function trigger( $user_id, $user_pass = '', $password_generated = false ) { |
| 104 | $this->setup_locale(); |
| 105 | |
| 106 | if ( $user_id ) { |
| 107 | $this->object = new WP_User( $user_id ); |
| 108 | |
| 109 | $this->user_pass = $user_pass; |
| 110 | $this->user_login = stripslashes( $this->object->user_login ); |
| 111 | $this->user_email = stripslashes( $this->object->user_email ); |
| 112 | $this->recipient = $this->user_email; |
| 113 | $this->password_generated = $password_generated; |
| 114 | $this->set_password_url = $this->generate_set_password_url(); |
| 115 | } |
| 116 | |
| 117 | if ( $this->is_enabled() && $this->get_recipient() ) { |
| 118 | $this->send( $this->get_recipient(), $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments() ); |
| 119 | } |
| 120 | |
| 121 | $this->restore_locale(); |
| 122 | } |
| 123 | |
| 124 | /** |
| 125 | * Get content html. |
| 126 | * |
| 127 | * @return string |
| 128 | */ |
| 129 | public function get_content_html() { |
| 130 | return wc_get_template_html( |
| 131 | $this->template_html, |
| 132 | array( |
| 133 | 'email_heading' => $this->get_heading(), |
| 134 | 'additional_content' => $this->get_additional_content(), |
| 135 | 'user_login' => $this->user_login, |
| 136 | 'user_pass' => $this->user_pass, |
| 137 | 'blogname' => $this->get_blogname(), |
| 138 | 'password_generated' => $this->password_generated, |
| 139 | 'sent_to_admin' => false, |
| 140 | 'plain_text' => false, |
| 141 | 'email' => $this, |
| 142 | 'set_password_url' => $this->set_password_url, |
| 143 | ) |
| 144 | ); |
| 145 | } |
| 146 | |
| 147 | /** |
| 148 | * Get content plain. |
| 149 | * |
| 150 | * @return string |
| 151 | */ |
| 152 | public function get_content_plain() { |
| 153 | return wc_get_template_html( |
| 154 | $this->template_plain, |
| 155 | array( |
| 156 | 'email_heading' => $this->get_heading(), |
| 157 | 'additional_content' => $this->get_additional_content(), |
| 158 | 'user_login' => $this->user_login, |
| 159 | 'user_pass' => $this->user_pass, |
| 160 | 'blogname' => $this->get_blogname(), |
| 161 | 'password_generated' => $this->password_generated, |
| 162 | 'sent_to_admin' => false, |
| 163 | 'plain_text' => true, |
| 164 | 'email' => $this, |
| 165 | 'set_password_url' => $this->set_password_url, |
| 166 | ) |
| 167 | ); |
| 168 | } |
| 169 | |
| 170 | /** |
| 171 | * Default content to show below main email content. |
| 172 | * |
| 173 | * @since 3.7.0 |
| 174 | * @return string |
| 175 | */ |
| 176 | public function get_default_additional_content() { |
| 177 | return __( 'We look forward to seeing you soon.', 'woocommerce' ); |
| 178 | } |
| 179 | |
| 180 | /** |
| 181 | * Generate set password URL link for a new user. |
| 182 | * |
| 183 | * See also Automattic\WooCommerce\Blocks\Domain\Services\Email\CustomerNewAccount and wp_new_user_notification. |
| 184 | * |
| 185 | * @since 6.0.0 |
| 186 | * @return string |
| 187 | */ |
| 188 | protected function generate_set_password_url() { |
| 189 | // Generate a magic link so user can set initial password. |
| 190 | $key = get_password_reset_key( $this->object ); |
| 191 | if ( ! is_wp_error( $key ) ) { |
| 192 | $action = 'newaccount'; |
| 193 | return wc_get_account_endpoint_url( 'lost-password' ) . "?action=$action&key=$key&login=" . rawurlencode( $this->object->user_login ); |
| 194 | } else { |
| 195 | // Something went wrong while getting the key for new password URL, send customer to the generic password reset. |
| 196 | return wc_get_account_endpoint_url( 'lost-password' ); |
| 197 | } |
| 198 | } |
| 199 | } |
| 200 | |
| 201 | endif; |
| 202 | |
| 203 | return new WC_Email_Customer_New_Account(); |
| 204 |