| 1 |
<?php |
| 2 |
|
| 3 |
namespace YayMail\Emails; |
| 4 |
|
| 5 |
use YayMail\Abstracts\BaseEmail; |
| 6 |
use YayMail\Elements\ElementsLoader; |
| 7 |
use YayMail\Utils\SingletonTrait; |
| 8 |
|
| 9 |
/** |
| 10 |
* CustomerNewAccount Class |
| 11 |
* |
| 12 |
* @method static CustomerNewAccount get_instance() |
| 13 |
*/ |
| 14 |
class CustomerNewAccount extends BaseEmail { |
| 15 |
use SingletonTrait; |
| 16 |
|
| 17 |
public $email_types = [ YAYMAIL_NON_ORDER_EMAILS ]; |
| 18 |
|
| 19 |
protected function __construct() { |
| 20 |
$emails = \WC_Emails::instance()->get_emails(); |
| 21 |
$email = $emails['WC_Email_Customer_New_Account']; |
| 22 |
if ( ! $email ) { |
| 23 |
return; |
| 24 |
} |
| 25 |
$this->id = $email->id; |
| 26 |
$this->title = $email->get_title(); |
| 27 |
$this->root_email = $email; |
| 28 |
$this->recipient = function_exists( 'yaymail_get_email_recipient_zone' ) ? yaymail_get_email_recipient_zone( $email ) : ''; |
| 29 |
|
| 30 |
$this->render_priority = apply_filters( 'yaymail_email_render_priority', $this->render_priority, $this->id ); |
| 31 |
add_filter( 'wc_get_template', [ $this, 'get_template_file' ], $this->render_priority ?? 10, 3 ); |
| 32 |
add_filter( 'yaymail_trigger_to_preview_email', [ $this, 'trigger_to_preview_email' ], 10, 3 ); |
| 33 |
$this->maybe_disable_block_email_editor(); |
| 34 |
} |
| 35 |
|
| 36 |
public function trigger_to_preview_email( $is_permitted, $email, $order_id ) { |
| 37 |
if ( $email->id === $this->id ) { |
| 38 |
add_action( 'yaymail_trigger_email', [ $this, 'trigger_email' ], 10, 2 ); |
| 39 |
$is_permitted = true; |
| 40 |
} |
| 41 |
return $is_permitted; |
| 42 |
} |
| 43 |
|
| 44 |
public function trigger_email( $email, $order_id ) { |
| 45 |
$email->trigger( get_current_user_id() ); |
| 46 |
} |
| 47 |
|
| 48 |
public function get_default_elements() { |
| 49 |
$email_title = __( 'Welcome to {site_title}', 'woocommerce' ); |
| 50 |
$email_title = str_replace( '{site_title}', '', $email_title ); |
| 51 |
// translators: customer username. |
| 52 |
$email_hi = sprintf( esc_html__( 'Hi %s,', 'woocommerce' ), '[yaymail_customer_username]' ); |
| 53 |
// translators: %1$s: site name, %2$s: customer username, %3$s: account url . |
| 54 |
$email_text = sprintf( esc_html__( 'Thanks for creating an account on %1$s. Your username is %2$s. You can access your account area to view orders, change your password, and more at: %3$s', 'woocommerce' ), '[yaymail_site_name]', '<strong>[yaymail_customer_username]</strong>', '[yaymail_user_account_url]' ); |
| 55 |
$email_text_1 = __( 'We look forward to seeing you soon.', 'woocommerce' ); |
| 56 |
$password_generate = '[yaymail_set_password_link]'; |
| 57 |
|
| 58 |
$default_elements = ElementsLoader::load_elements( |
| 59 |
[ |
| 60 |
[ |
| 61 |
'type' => 'Logo', |
| 62 |
], |
| 63 |
[ |
| 64 |
'type' => 'Heading', |
| 65 |
'attributes' => [ |
| 66 |
'rich_text' => $email_title . '[yaymail_site_name]', |
| 67 |
], |
| 68 |
], |
| 69 |
[ |
| 70 |
'type' => 'Text', |
| 71 |
'attributes' => [ |
| 72 |
'rich_text' => '<p><span>' . $email_hi . '<br><br>' . $email_text . '</span></p><p style=\"margin: 26px 0px 0px 0px;\"><span>' . $password_generate . '</span></p><p style=\"margin: 26px 0px 0px 0px;\"><span>' . $email_text_1 . '</span></p>', |
| 73 |
], |
| 74 |
], |
| 75 |
[ |
| 76 |
'type' => 'Footer', |
| 77 |
], |
| 78 |
] |
| 79 |
); |
| 80 |
|
| 81 |
return $default_elements; |
| 82 |
} |
| 83 |
|
| 84 |
public function get_template_path() { |
| 85 |
return yaymail_get_template( 'emails/customer-new-account.php', '', YAYMAIL_PLUGIN_PATH . 'templates/' ); |
| 86 |
} |
| 87 |
} |
| 88 |
|