| 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 |
* CustomerVerifyEmail Class |
| 11 |
* WC core "Confirm email address" email: asks a customer to verify their email |
| 12 |
* so past guest orders get linked to their account. |
| 13 |
* From WC 11.0 (always registered) |
| 14 |
* |
| 15 |
* @since 4.4.7 |
| 16 |
* @method static CustomerVerifyEmail get_instance() |
| 17 |
*/ |
| 18 |
class CustomerVerifyEmail extends BaseEmail { |
| 19 |
use SingletonTrait; |
| 20 |
|
| 21 |
public $email_types = [ YAYMAIL_NON_ORDER_EMAILS ]; |
| 22 |
|
| 23 |
protected function __construct() { |
| 24 |
$emails = \WC_Emails::instance()->get_emails(); |
| 25 |
$email = $emails['WC_Email_Customer_Verify_Email'] ?? null; |
| 26 |
if ( ! $email ) { |
| 27 |
return; |
| 28 |
} |
| 29 |
$this->id = $email->id; |
| 30 |
$this->title = $email->get_title(); |
| 31 |
$this->root_email = $email; |
| 32 |
$this->recipient = function_exists( 'yaymail_get_email_recipient_zone' ) ? yaymail_get_email_recipient_zone( $email ) : ''; |
| 33 |
|
| 34 |
$this->render_priority = apply_filters( 'yaymail_email_render_priority', $this->render_priority, $this->id ); |
| 35 |
add_filter( 'wc_get_template', [ $this, 'get_template_file' ], $this->render_priority ?? 10, 3 ); |
| 36 |
$this->maybe_disable_block_email_editor(); |
| 37 |
} |
| 38 |
|
| 39 |
public function get_default_elements() { |
| 40 |
$email_title = __( 'Confirm your email address', 'woocommerce' ); |
| 41 |
// translators: %s: customer first name, or username if name is not available. |
| 42 |
$email_hi = sprintf( esc_html__( 'Hi %s,', 'woocommerce' ), '[yaymail_verify_email_user_display_name]' ); |
| 43 |
// translators: %s: the customer's email address. |
| 44 |
$email_text = sprintf( esc_html__( "Once you've confirmed that %s is your email address, we'll link any past orders to your account.", 'woocommerce' ), '<b>[yaymail_verify_email_user_email]</b>' ); |
| 45 |
$ignore_text = esc_html__( "If you didn't request this email, there's nothing to worry about, and you can safely ignore it.", 'woocommerce' ); |
| 46 |
$closing_text = __( 'Thanks for reading.', 'woocommerce' ); |
| 47 |
|
| 48 |
return ElementsLoader::load_elements( |
| 49 |
[ |
| 50 |
[ |
| 51 |
'type' => 'Logo', |
| 52 |
], |
| 53 |
[ |
| 54 |
'type' => 'Heading', |
| 55 |
'attributes' => [ |
| 56 |
'rich_text' => $email_title, |
| 57 |
], |
| 58 |
], |
| 59 |
[ |
| 60 |
'type' => 'Text', |
| 61 |
'attributes' => [ |
| 62 |
'rich_text' => '<p><span>' . $email_hi . '<br /><br /></span></p><p><span>' . $email_text . '</span></p>', |
| 63 |
], |
| 64 |
], |
| 65 |
[ |
| 66 |
'type' => 'Button', |
| 67 |
'attributes' => [ |
| 68 |
'text' => __( 'Confirm email address', 'woocommerce' ), |
| 69 |
'url' => '[yaymail_verify_email_url]', |
| 70 |
'align' => 'left', |
| 71 |
], |
| 72 |
], |
| 73 |
[ |
| 74 |
'type' => 'Text', |
| 75 |
'attributes' => [ |
| 76 |
'rich_text' => '<p><span>' . $ignore_text . '</span></p><p><span>' . esc_html( $closing_text ) . '</span></p>', |
| 77 |
], |
| 78 |
], |
| 79 |
[ |
| 80 |
'type' => 'Footer', |
| 81 |
], |
| 82 |
] |
| 83 |
); |
| 84 |
} |
| 85 |
|
| 86 |
public function get_template_path() { |
| 87 |
return yaymail_get_template( 'emails/customer-verify-email.php', '', YAYMAIL_PLUGIN_PATH . 'templates/' ); |
| 88 |
} |
| 89 |
} |
| 90 |
|