Customize the WC transactional email template based on WC settings [MAILPOET-2339]

This commit is contained in:
wxa
2019-11-04 18:47:27 +03:00
committed by Jack Kitterhing
parent ce36b3fdfc
commit 68eb3ade6e
4 changed files with 33 additions and 12 deletions

View File

@ -75,6 +75,7 @@ class NewsletterEditor {
'woocommerce' => [
'email_base_color' => $this->wp->getOption('woocommerce_email_base_color', '#000000'),
'email_heading' => $this->wc_transactional_emails->getEmailHeading(),
'email_text_color' => $this->wp->getOption('woocommerce_email_text_color', '#000000'),
],
];
$this->wp->wpEnqueueMedia();

View File

@ -53,9 +53,28 @@ class TransactionalEmails {
);
}
private function getWCEmailSettings() {
$wc_email_settings = [
'woocommerce_email_background_color' => '#ffffff',
'woocommerce_email_base_color' => '#333333',
'woocommerce_email_body_background_color' => '#eeeeee',
'woocommerce_email_footer_text' => $this->wp->_x('Footer text', 'Default footer text for a WooCommerce transactional email', 'mailpoet'),
'woocommerce_email_header_image' => '',
'woocommerce_email_text_color' => '#111111',
];
$result = [];
foreach ($wc_email_settings as $name => $default) {
$value = $this->wp->getOption($name, $default);
$key = preg_replace('/^woocommerce_email_/', '', $name);
$result[$key] = $value;
}
$result['footer_text'] = $this->replacePlaceholders($result['footer_text']);
return $result;
}
private function getBody() {
$social_icon_url = Env::$assets_url . '/img/newsletter_editor/social-icons';
$wc_header_image = $this->wp->getOption('woocommerce_email_header_image', '');
$wc_email_settings = $this->getWCEmailSettings();
return [
'content' =>
[
@ -130,7 +149,7 @@ class TransactionalEmails {
[
'type' => 'image',
'link' => '',
'src' => $wc_header_image,
'src' => $wc_email_settings['header_image'],
'alt' => 'mailpoet-logo',
'fullWidth' => false,
'width' => '160px',
@ -328,7 +347,7 @@ class TransactionalEmails {
1 =>
[
'type' => 'text',
'text' => '<p style="text-align: center;"><span style="color: #fe5301;">Footer text</span></p>',
'text' => '<p style="text-align: center;">' . $wc_email_settings['footer_text'] . '</p>',
],
],
],
@ -340,28 +359,28 @@ class TransactionalEmails {
[
'text' =>
[
'fontColor' => '#111111',
'fontColor' => $wc_email_settings['text_color'],
'fontFamily' => 'Arial',
'fontSize' => '16px',
'lineHeight' => '1.6',
],
'h1' =>
[
'fontColor' => '#333333',
'fontColor' => $wc_email_settings['base_color'],
'fontFamily' => 'Source Sans Pro',
'fontSize' => '36px',
'lineHeight' => '1.6',
],
'h2' =>
[
'fontColor' => '#222222',
'fontColor' => $wc_email_settings['base_color'],
'fontFamily' => 'Verdana',
'fontSize' => '24px',
'lineHeight' => '1.6',
],
'h3' =>
[
'fontColor' => '#333333',
'fontColor' => $wc_email_settings['base_color'],
'fontFamily' => 'Trebuchet MS',
'fontSize' => '22px',
'lineHeight' => '1.6',
@ -373,11 +392,11 @@ class TransactionalEmails {
],
'wrapper' =>
[
'backgroundColor' => '#ffffff',
'backgroundColor' => $wc_email_settings['background_color'],
],
'body' =>
[
'backgroundColor' => '#eeeeee',
'backgroundColor' => $wc_email_settings['body_background_color'],
],
],
'blockDefaults' =>

View File

@ -45,8 +45,9 @@ class TransactionalEmailsTest extends \MailPoetTest {
function testInitUsesImageFromWCSettings() {
$wp = Stub::make(new WPFunctions, ['getOption' => function($name) {
expect($name)->equals('woocommerce_email_header_image');
return 'my-awesome-image-url';
if ($name == 'woocommerce_email_header_image') {
return 'my-awesome-image-url';
}
}]);
$transactional_emails = new TransactionalEmails($wp, $this->settings);
$transactional_emails->init();

View File

@ -1437,7 +1437,7 @@
woocommerceHeading: {
content: '<%= woocommerce.email_heading %>',
styles: {
fontColor: '#000000',
fontColor: '<%= woocommerce.email_text_color %>',
backgroundColor: '<%= woocommerce.email_base_color %>',
},
},