ReportCSVEmail.php
<?php
namespace Automattic\WooCommerce\Admin;
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( ! class_exists( 'WC_Email', false ) ) {
include_once WC_ABSPATH . 'includes/emails/class-wc-email.php';
}
class ReportCSVEmail extends \WC_Email {
protected $report_labels;
protected $report_type;
protected $download_url;
public function __construct() {
$this->id = 'admin_report_export_download';
$this->template_base = WC()->plugin_path() . '/includes/react-admin/emails/';
$this->template_html = 'html-admin-report-export-download.php';
$this->template_plain = 'plain-admin-report-export-download.php';
$this->report_labels = array(
'categories' => __( 'Categories', 'woocommerce' ),
'coupons' => __( 'Coupons', 'woocommerce' ),
'customers' => __( 'Customers', 'woocommerce' ),
'downloads' => __( 'Downloads', 'woocommerce' ),
'orders' => __( 'Orders', 'woocommerce' ),
'products' => __( 'Products', 'woocommerce' ),
'revenue' => __( 'Revenue', 'woocommerce' ),
'stock' => __( 'Stock', 'woocommerce' ),
'taxes' => __( 'Taxes', 'woocommerce' ),
'variations' => __( 'Variations', 'woocommerce' ),
);
parent::__construct();
}
public function init_form_fields() {}
public function init_settings() {}
public function get_email_type() {
return class_exists( 'DOMDocument' ) ? 'html' : 'plain';
}
public function get_default_heading() {
return __( 'Your Report Download', 'woocommerce' );
}
public function get_default_subject() {
return __( '[{site_title}]: Your {report_name} Report download is ready', 'woocommerce' );
}
public function get_content_html() {
return wc_get_template_html(
$this->template_html,
array(
'report_name' => $this->report_type,
'download_url' => $this->download_url,
'email_heading' => $this->get_heading(),
'sent_to_admin' => true,
'plain_text' => false,
'email' => $this,
),
'',
$this->template_base
);
}
public function get_content_plain() {
return wc_get_template_html(
$this->template_plain,
array(
'report_name' => $this->report_type,
'download_url' => $this->download_url,
'email_heading' => $this->get_heading(),
'sent_to_admin' => true,
'plain_text' => true,
'email' => $this,
),
'',
$this->template_base
);
}
public function trigger( $user_id, $report_type, $download_url ) {
$user = new \WP_User( $user_id );
$this->recipient = $user->user_email;
$this->download_url = $download_url;
if ( isset( $this->report_labels[ $report_type ] ) ) {
$this->report_type = $this->report_labels[ $report_type ];
$this->placeholders['{report_name}'] = $this->report_type;
}
$this->send(
$this->get_recipient(),
$this->get_subject(),
$this->get_content(),
$this->get_headers(),
$this->get_attachments()
);
}
}