wp = $wp; $this->settings = $settings; $this->email_headings = [ 'new_account' => [ 'option_name' => 'woocommerce_new_order_settings', 'default' => __('New Order: #{order_number}', 'woocommerce'), ], 'processing_order' => [ 'option_name' => 'woocommerce_customer_processing_order_settings', 'default' => __('Thank you for your order', 'woocommerce'), ], 'completed_order' => [ 'option_name' => 'woocommerce_customer_completed_order_settings', 'default' => __('Thanks for shopping with us', 'woocommerce'), ], 'customer_note' => [ 'option_name' => 'woocommerce_customer_note_settings', 'default' => __('A note has been added to your order', 'woocommerce'), ], ]; } public function init() { $saved_email_id = (bool)$this->settings->get(self::SETTING_EMAIL_ID, false); if (!$saved_email_id) { $email = Newsletter::createOrUpdate([ 'type' => Newsletter::TYPE_WC_TRANSACTIONAL_EMAIL, 'subject' => 'WooCommerce Transactional Email', 'preheader' => '', 'body' => json_encode($this->getBody()), ]); $this->settings->set(self::SETTING_EMAIL_ID, $email->id); } } public function getEmailHeadings() { $values = []; foreach ($this->email_headings as $name => $heading) { $settings = $this->wp->getOption($heading['option_name']); if (!$settings) { $values[$name] = $this->replacePlaceholders($heading['default']); } else { $value = isset($settings['heading']) ? $settings['heading'] : $heading['default']; $values[$name] = $this->replacePlaceholders($value); } } return $values; } private function replacePlaceholders($text) { $title = $this->wp->wpSpecialcharsDecode($this->wp->getOption('blogname'), ENT_QUOTES); $address = $this->wp->wpParseUrl($this->wp->homeUrl(), PHP_URL_HOST); $order_date = date('Y-m-d'); return str_replace( ['{site_title}','{site_address}', '{order_date}', '{order_number}'], [$title, $address, $order_date, '0001'], $text ); } 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_email_settings = $this->getWCEmailSettings(); return [ 'content' => [ 'type' => 'container', 'columnLayout' => false, 'orientation' => 'vertical', 'image' => [ 'src' => null, 'display' => 'scale', ], 'styles' => [ 'block' => [ 'backgroundColor' => 'transparent', ], ], 'blocks' => [ 0 => [ 'type' => 'container', 'columnLayout' => false, 'orientation' => 'horizontal', 'image' => [ 'src' => null, 'display' => 'scale', ], 'styles' => [ 'block' => [ 'backgroundColor' => '#eeeeee', ], ], 'blocks' => [ 0 => [ 'type' => 'container', 'columnLayout' => false, 'orientation' => 'vertical', 'image' => [ 'src' => null, 'display' => 'scale', ], 'styles' => [ 'block' => [ 'backgroundColor' => 'transparent', ], ], 'blocks' => [ 0 => [ 'type' => 'spacer', 'styles' => [ 'block' => [ 'backgroundColor' => 'transparent', 'height' => '20px', ], ], ], 1 => [ 'type' => 'image', 'link' => '', 'src' => $wc_email_settings['header_image'], 'alt' => 'mailpoet-logo', 'fullWidth' => false, 'width' => '160px', 'height' => '490px', 'styles' => [ 'block' => [ 'textAlign' => 'center', ], ], ], 2 => [ 'type' => 'spacer', 'styles' => [ 'block' => [ 'backgroundColor' => 'transparent', 'height' => '20px', ], ], ], ], ], ], ], 1 => [ 'type' => 'woocommerceHeading', ], 2 => [ 'type' => 'container', 'columnLayout' => false, 'orientation' => 'horizontal', 'image' => [ 'src' => null, 'display' => 'scale', ], 'styles' => [ 'block' => [ 'backgroundColor' => 'transparent', ], ], 'blocks' => [ 0 => [ 'type' => 'container', 'columnLayout' => false, 'orientation' => 'vertical', 'image' => [ 'src' => null, 'display' => 'scale', ], 'styles' => [ 'block' => [ 'backgroundColor' => 'transparent', ], ], 'blocks' => [ 0 => [ 'type' => 'spacer', 'styles' => [ 'block' => [ 'backgroundColor' => 'transparent', 'height' => '20px', ], ], ], ], ], ], ], 3 => [ 'type' => 'woocommerceContent', ], 4 => [ 'type' => 'container', 'columnLayout' => false, 'orientation' => 'horizontal', 'image' => [ 'src' => null, 'display' => 'scale', ], 'styles' => [ 'block' => [ 'backgroundColor' => '#ffffff', ], ], 'blocks' => [ 0 => [ 'type' => 'container', 'columnLayout' => false, 'orientation' => 'vertical', 'image' => [ 'src' => null, 'display' => 'scale', ], 'styles' => [ 'block' => [ 'backgroundColor' => 'transparent', ], ], 'blocks' => [ 0 => [ 'type' => 'spacer', 'styles' => [ 'block' => [ 'backgroundColor' => 'transparent', 'height' => '20px', ], ], ], ], ], ], ], 5 => [ 'type' => 'container', 'columnLayout' => false, 'orientation' => 'horizontal', 'image' => [ 'src' => null, 'display' => 'scale', ], 'styles' => [ 'block' => [ 'backgroundColor' => '#eeeeee', ], ], 'blocks' => [ 0 => [ 'type' => 'container', 'columnLayout' => false, 'orientation' => 'vertical', 'image' => [ 'src' => null, 'display' => 'scale', ], 'styles' => [ 'block' => [ 'backgroundColor' => 'transparent', ], ], 'blocks' => [ 0 => [ 'type' => 'spacer', 'styles' => [ 'block' => [ 'backgroundColor' => 'transparent', 'height' => '20px', ], ], ], 1 => [ 'type' => 'text', 'text' => '
' . $wc_email_settings['footer_text'] . '
', ], ], ], ], ], ], ], 'globalStyles' => [ 'text' => [ 'fontColor' => $wc_email_settings['text_color'], 'fontFamily' => 'Arial', 'fontSize' => '16px', 'lineHeight' => '1.6', ], 'h1' => [ 'fontColor' => $wc_email_settings['base_color'], 'fontFamily' => 'Source Sans Pro', 'fontSize' => '36px', 'lineHeight' => '1.6', ], 'h2' => [ 'fontColor' => $wc_email_settings['base_color'], 'fontFamily' => 'Verdana', 'fontSize' => '24px', 'lineHeight' => '1.6', ], 'h3' => [ 'fontColor' => $wc_email_settings['base_color'], 'fontFamily' => 'Trebuchet MS', 'fontSize' => '22px', 'lineHeight' => '1.6', ], 'link' => [ 'fontColor' => '#21759B', 'textDecoration' => 'underline', ], 'wrapper' => [ 'backgroundColor' => $wc_email_settings['background_color'], ], 'body' => [ 'backgroundColor' => $wc_email_settings['body_background_color'], ], ], 'blockDefaults' => [ 'automatedLatestContent' => [ 'amount' => '5', 'withLayout' => false, 'contentType' => 'post', 'inclusionType' => 'include', 'displayType' => 'excerpt', 'titleFormat' => 'h1', 'titleAlignment' => 'left', 'titleIsLink' => false, 'imageFullWidth' => false, 'featuredImagePosition' => 'belowTitle', 'showAuthor' => 'no', 'authorPrecededBy' => 'Author:', 'showCategories' => 'no', 'categoriesPrecededBy' => 'Categories:', 'readMoreType' => 'button', 'readMoreText' => 'Read more', 'readMoreButton' => [ 'text' => 'Read more', 'url' => '[postLink]', 'context' => 'automatedLatestContent.readMoreButton', 'styles' => [ 'block' => [ 'backgroundColor' => '#2ea1cd', 'borderColor' => '#0074a2', 'borderWidth' => '1px', 'borderRadius' => '5px', 'borderStyle' => 'solid', 'width' => '180px', 'lineHeight' => '40px', 'fontColor' => '#ffffff', 'fontFamily' => 'Verdana', 'fontSize' => '18px', 'fontWeight' => 'normal', 'textAlign' => 'center', ], ], ], 'sortBy' => 'newest', 'showDivider' => true, 'divider' => [ 'context' => 'automatedLatestContent.divider', 'styles' => [ 'block' => [ 'backgroundColor' => 'transparent', 'padding' => '13px', 'borderStyle' => 'solid', 'borderWidth' => '3px', 'borderColor' => '#aaaaaa', ], ], ], 'backgroundColor' => '#ffffff', 'backgroundColorAlternate' => '#eeeeee', ], 'automatedLatestContentLayout' => [ 'amount' => '5', 'withLayout' => true, 'contentType' => 'post', 'inclusionType' => 'include', 'displayType' => 'excerpt', 'titleFormat' => 'h1', 'titleAlignment' => 'left', 'titleIsLink' => false, 'imageFullWidth' => false, 'featuredImagePosition' => 'alternate', 'showAuthor' => 'no', 'authorPrecededBy' => 'Author:', 'showCategories' => 'no', 'categoriesPrecededBy' => 'Categories:', 'readMoreType' => 'button', 'readMoreText' => 'Read more', 'readMoreButton' => [ 'text' => 'Read more', 'url' => '[postLink]', 'context' => 'automatedLatestContentLayout.readMoreButton', 'styles' => [ 'block' => [ 'backgroundColor' => '#2ea1cd', 'borderColor' => '#0074a2', 'borderWidth' => '1px', 'borderRadius' => '5px', 'borderStyle' => 'solid', 'width' => '180px', 'lineHeight' => '40px', 'fontColor' => '#ffffff', 'fontFamily' => 'Verdana', 'fontSize' => '18px', 'fontWeight' => 'normal', 'textAlign' => 'center', ], ], ], 'sortBy' => 'newest', 'showDivider' => true, 'divider' => [ 'context' => 'automatedLatestContentLayout.divider', 'styles' => [ 'block' => [ 'backgroundColor' => 'transparent', 'padding' => '13px', 'borderStyle' => 'solid', 'borderWidth' => '3px', 'borderColor' => '#aaaaaa', ], ], ], 'backgroundColor' => '#ffffff', 'backgroundColorAlternate' => '#eeeeee', ], 'button' => [ 'text' => 'Button', 'url' => '', 'styles' => [ 'block' => [ 'backgroundColor' => '#2ea1cd', 'borderColor' => '#0074a2', 'borderWidth' => '1px', 'borderRadius' => '5px', 'borderStyle' => 'solid', 'width' => '180px', 'lineHeight' => '40px', 'fontColor' => '#ffffff', 'fontFamily' => 'Verdana', 'fontSize' => '18px', 'fontWeight' => 'normal', 'textAlign' => 'center', ], ], ], 'divider' => [ 'styles' => [ 'block' => [ 'backgroundColor' => 'transparent', 'padding' => '13px', 'borderStyle' => 'solid', 'borderWidth' => '3px', 'borderColor' => '#aaaaaa', ], ], ], 'footer' => [ 'text' => 'Unsubscribe | Manage subscription
Add your postal address here!