wordpress - WooCommerce 自定义电子邮件模板“template_base”无法正常工作
问题描述
我正在开发一个创建自定义电子邮件模板的插件。
电子邮件模板将存储在插件本身上。但是,这无法正常工作。这是我的电子邮件课程
class SV_SplitEmail_New_Order extends WC_Email
{
/**
* Constructor.
*/
public function __construct() {
$this->id = 'sv_split_new_order';
$this->title = __( 'New Order - Split Orders', 'woocommerce' );
$this->description = __( 'New order emails are sent to chosen recipient(s) when a new order is received. Compatible with Split and Plain orders. The default "New Order" email should be disabled.', 'woocommerce' );
$this->customer_email = false;
$this->template_base = SVTHEMING_PATH.'app/Providers/Order_Splitting/templates/';
$this->template_html = 'emails/admin-new-split-order.php';
$this->placeholders = array(
'{order_date}' => '',
'{order_number}' => '',
);
// Triggers for this email.
add_action( 'woocommerce_order_status_pending_to_processing_notification', array( $this, 'trigger' ), 10, 2 );
add_action( 'woocommerce_order_status_pending_to_completed_notification', array( $this, 'trigger' ), 10, 2 );
add_action( 'woocommerce_order_status_pending_to_on-hold_notification', array( $this, 'trigger' ), 10, 2 );
add_action( 'woocommerce_order_status_failed_to_processing_notification', array( $this, 'trigger' ), 10, 2 );
add_action( 'woocommerce_order_status_failed_to_completed_notification', array( $this, 'trigger' ), 10, 2 );
add_action( 'woocommerce_order_status_failed_to_on-hold_notification', array( $this, 'trigger' ), 10, 2 );
add_action( 'woocommerce_order_status_cancelled_to_processing_notification', array( $this, 'trigger' ), 10, 2 );
add_action( 'woocommerce_order_status_cancelled_to_completed_notification', array( $this, 'trigger' ), 10, 2 );
add_action( 'woocommerce_order_status_cancelled_to_on-hold_notification', array( $this, 'trigger' ), 10, 2 );
// Call parent constructor.
parent::__construct();
// Other settings.
$this->recipient = $this->get_option( 'recipient', get_option( 'admin_email' ) );
}
这在仪表板上正确显示。
但是,当电子邮件发出时,它们是空白的。
如果我将电子邮件模板文件放在网站的主题文件夹中,则可以正常工作。
但是,这并不理想,因为在插件的部署/更新时,我总是需要更新主题的电子邮件模板。
我已确保$this->template_base
正确定义,并且可以确认,因为仪表板显示正确的文件。
我错过了什么?
解决方案
我不确定您是否仍然遇到此问题,但我直到最近才找到解决方法(至少对于我的问题)。希望它会为您解决这个问题,或帮助其他人。
在get_content_html()
andget_content_plain()
函数中,需要传入新的template_base路径。如果你像这样修改你的函数(或者如果你的类中没有它们,则添加它们),它应该解决它:
public function get_content_html() {
return wc_get_template_html(
$this->template_html,
array(
'order' => $this->object,
'email_heading' => $this->get_heading(),
'additional_content' => $this->get_additional_content(),
'sent_to_admin' => false,
'plain_text' => false,
'email' => $this,
), '', $this->template_base
);
}
public function get_content_plain() {
return wc_get_template_html(
$this->template_plain,
array(
'order' => $this->object,
'email_heading' => $this->get_heading(),
'additional_content' => $this->get_additional_content(),
'sent_to_admin' => false,
'plain_text' => true,
'email' => $this,
), '', $this->template_base
);
}
在那之后,它似乎知道在哪里看,我的新电子邮件课程肯定触发得很好。
推荐阅读
- android - 如何仅在意图选择器中显示 PDF 文件
- json - 如何遍历 HttpClient 返回的 JSON
- laravel - 非静态方法 Spatie\Analytics\Analytics::fetchMostVisitedPages() 不应在 laravel 8 中静态调用
- c++ - 请回答。我的代码不起作用。cout 不工作
- python - 了解 Keras 正则化
- ios - xamarin中ios的重叠列表
- python - Keras 如何对方法 flow_from_directory 中的数据进行洗牌?
- javascript - 将项目添加到减速器中的空数组中给出错误“类型错误:传播不可迭代实例的无效尝试。”
- socket.io - 使用 Traefik 或 NGINX 在 Docker Swarm 上正确处理 Socket.io
- azure-devops - 当阶段在 azure devops 中的第一个版本定义中传递时,如何在第二个版本定义中触发发布