我试图发送邮箱从我的插件使用标准的WooCommerce布局,但我想使用我自己的模板位于我的插件.当我将我的模板移动到/wp-content/plugins/woocommerce/templates/emails时,以下代码可以工作:
function get_custom_email_html( $heading = false, $mailer ) {
$template = 'emails/my-custom-email-i-want-to-send.php';
return wc_get_template_html( $template, array(
'email_heading' => $heading,
'sent_to_admin' => false,
'plain_text' => false,
'email' => $mailer
) );
}
// load the mailer class
$mailer = WC()->mailer();
//format the email
$recipient = "someone@somewhere.com";
$subject = __("Hi! Here is a custom notification from us!", 'theme_name');
$content = get_custom_email_html( $subject, $mailer );
$headers = "Content-Type: text/html\r\n";
//send the email through wordpress
$mailer->send( $recipient, $subject, $content, $headers );
我假设我需要添加一个指向GET_CUSTOM_EMAIL_html()的路径,但我不确定如何添加.有人能给我个提示吗? 我的模板是一个非常简单的:
/*
* @hooked WC_Emails::email_header() Output the email header
*/
do_action( 'woocommerce_email_header', $email_heading, $email ); ?>
<p><?php esc_html_e( 'This a test', 'my-plugin' ); ?></p>
<?php
/*
* @hooked WC_Emails::email_footer() Output the email footer
*/
do_action( 'woocommerce_email_footer', $email );