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' => [ 'woocommerce' => [
'email_base_color' => $this->wp->getOption('woocommerce_email_base_color', '#000000'), 'email_base_color' => $this->wp->getOption('woocommerce_email_base_color', '#000000'),
'email_heading' => $this->wc_transactional_emails->getEmailHeading(), 'email_heading' => $this->wc_transactional_emails->getEmailHeading(),
'email_text_color' => $this->wp->getOption('woocommerce_email_text_color', '#000000'),
], ],
]; ];
$this->wp->wpEnqueueMedia(); $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() { private function getBody() {
$social_icon_url = Env::$assets_url . '/img/newsletter_editor/social-icons'; $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 [ return [
'content' => 'content' =>
[ [
@ -130,7 +149,7 @@ class TransactionalEmails {
[ [
'type' => 'image', 'type' => 'image',
'link' => '', 'link' => '',
'src' => $wc_header_image, 'src' => $wc_email_settings['header_image'],
'alt' => 'mailpoet-logo', 'alt' => 'mailpoet-logo',
'fullWidth' => false, 'fullWidth' => false,
'width' => '160px', 'width' => '160px',
@ -328,7 +347,7 @@ class TransactionalEmails {
1 => 1 =>
[ [
'type' => 'text', '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' => 'text' =>
[ [
'fontColor' => '#111111', 'fontColor' => $wc_email_settings['text_color'],
'fontFamily' => 'Arial', 'fontFamily' => 'Arial',
'fontSize' => '16px', 'fontSize' => '16px',
'lineHeight' => '1.6', 'lineHeight' => '1.6',
], ],
'h1' => 'h1' =>
[ [
'fontColor' => '#333333', 'fontColor' => $wc_email_settings['base_color'],
'fontFamily' => 'Source Sans Pro', 'fontFamily' => 'Source Sans Pro',
'fontSize' => '36px', 'fontSize' => '36px',
'lineHeight' => '1.6', 'lineHeight' => '1.6',
], ],
'h2' => 'h2' =>
[ [
'fontColor' => '#222222', 'fontColor' => $wc_email_settings['base_color'],
'fontFamily' => 'Verdana', 'fontFamily' => 'Verdana',
'fontSize' => '24px', 'fontSize' => '24px',
'lineHeight' => '1.6', 'lineHeight' => '1.6',
], ],
'h3' => 'h3' =>
[ [
'fontColor' => '#333333', 'fontColor' => $wc_email_settings['base_color'],
'fontFamily' => 'Trebuchet MS', 'fontFamily' => 'Trebuchet MS',
'fontSize' => '22px', 'fontSize' => '22px',
'lineHeight' => '1.6', 'lineHeight' => '1.6',
@ -373,11 +392,11 @@ class TransactionalEmails {
], ],
'wrapper' => 'wrapper' =>
[ [
'backgroundColor' => '#ffffff', 'backgroundColor' => $wc_email_settings['background_color'],
], ],
'body' => 'body' =>
[ [
'backgroundColor' => '#eeeeee', 'backgroundColor' => $wc_email_settings['body_background_color'],
], ],
], ],
'blockDefaults' => 'blockDefaults' =>

View File

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

View File

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