【发布时间】:2019-11-29 00:00:37
【问题描述】:
我正在寻找一种使用自定义 WooCommerce 模板发送所有 WordPress 电子邮件的方法,以便所有电子邮件看起来都一样。
模板的路径是:
woocommerce/emails/my-custom-woocommerce-template.php
【问题讨论】:
标签: wordpress email templates woocommerce
我正在寻找一种使用自定义 WooCommerce 模板发送所有 WordPress 电子邮件的方法,以便所有电子邮件看起来都一样。
模板的路径是:
woocommerce/emails/my-custom-woocommerce-template.php
【问题讨论】:
标签: wordpress email templates woocommerce
是否必须全部模板化在一个文件中?如果没有,这些入口点的组合可能会让您获得您正在寻找的标准化:
email-header.php 允许您自定义电子邮件的开头,包括标题图像(如果您需要做的不仅仅是更改其 URL)。它会打开其余电子邮件内容的布局标签email-footer.php 允许您自定义页脚,并关闭在页眉中开始的布局标签。email-styles.php 或 woocommerce_email_styles 过滤器可让您自定义 CSS(请参阅我的文章 here 中的一些陷阱)。【讨论】:
您可以使用以下功能。它正在工作
function myplugin_woocommerce_locate_template( $template, $template_name, $template_path ) {
global $woocommerce;
// List of all templates that should be replaced with custom template
$woo_templates = array(
'emails/admin-new-order.php',
'emails/admin-failed-order.php',
'emails/admin-cancelled-order.php',
'emails/customer-completed-order.php',
'emails/customer-new-account.php',
'emails/customer-note.php',
'emails/customer-on-hold-order.php',
'emails/customer-processing-order.php',
'emails/customer-refunded-order.php',
'emails/customer-reset-password.php',
);
//Check whether template is in replacable template array
if( in_array( $template_name, $woo_templates ) ){
// Set your custom template path
$template = your_template_path.'emails/my-custom-woocommerce-template';
}
// Return what we found
return $template;
}
add_filter( 'woocommerce_locate_template', 'myplugin_woocommerce_locate_template', 10, 3 );
【讨论】:
add_filter( 'wp_mail', 'your_wp_mail_action' ); // $args = compact( 'to', 'subject', 'message', 'headers', 'attachments' )
function your_wp_mail_action( $args ) {
global $your_prefix_your_email_args; // the args you could use in my-custom-woocommerce-template file
$your_prefix_your_email_args = $args;
ob_clean();
get_template_part( 'woocommerce/emails/my-custom-woocommerce-template' );
$args['message'] = ob_get_clean();
// ... your logic
return $args;
}
【讨论】:
要查看和更新电子邮件设置,请登录您的网站仪表板。在左侧菜单中,单击 WooCommerce → 设置。
在那里,您会在顶部找到几个选项标签。点击电子邮件查看以下模板
您可以根据需要自定义所有内容
【讨论】: