[英]How do I replace the OOTB woo customer completed order email?
In a plugin I'm working on, I'm trying to replace the OOTB customer-completed-order email with a template in the plugin在我正在使用的插件中,我试图用插件中的模板替换 OOTB customer-completed-order email
Constructor:构造函数:
define( 'BKF_WC_EMAIL_PATH', plugin_dir_path( __FILE__ ) );
add_filter('wc_get_template', array($this, 'bkf_customer_completed_order_template'), PHP_INT_MAX, 5);
Function: Function:
function bkf_customer_completed_order_template($template, $template_name, $args, $template_path, $default_path) {
if( $template_name == 'emails/customer-completed-order.php' ) {
$template = trailingslashit(BKF_WC_EMAIL_PATH) . 'templates/' . $template_name;
return $template;
}
}
note the template is still pulling the default woo one请注意,模板仍在拉取默认的 woo one
Any thoughts/ideas are welcome!欢迎任何想法/想法!
Worked it out!解决了!
Instead of the method used in my original question, here's what worked for me:以下是对我有用的方法,而不是我原来问题中使用的方法:
I created a new class (similar to woocommerce/includes/emails/class-wc-email-customer-completed-order.php) - for demo purposes we'll call it My_Custom_Class
我创建了一个新的 class(类似于 woocommerce/includes/emails/class-wc-email-customer-completed-order.php)——出于演示目的,我们将其称为
My_Custom_Class
I then called like so in my constructor for the parent class I was working on:然后我在我正在处理的父 class 的构造函数中这样调用:
add_action('woocommerce_email_classes', array( $this, 'bk_register_email' ), PHP_INT_MAX, 1 );
And added this function:并添加了这个 function:
public function bk_register_email( $emails ) {
require_once 'emails/my-custom-class.php';
$emails['WC_Email_Customer_Completed_Order'] = new My_Custom_Class();
return $emails;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.