问题描述
我使用Woocommerce,我需要根据其类型更改电子邮件标题,以便使 customer-new-account.php, customer-processing-order.php, admin-new-order.php(等等)。它们必须具有不同的标题。
I use Woocommerce and I need to change email header according to its type, so that "customer-new-account.php", "customer-processing-order.php", "admin-new-order.php" (and so on)... they must have different header.
我刚刚在子模板中复制了woocommerce emails文件夹,现在我需要知道如何进行代码更改。
I've just copied woocommerce "emails" folder inside my child template and now I need to know how to make code changes.
任何帮助都是值得的。 ;-)
预先感谢。
Any help is appreciate. ;-)Thanks in advance.
推荐答案
如评论中所述,我认为没有 woocommerce_email_header
挂钩上使用条件逻辑的方法。您可以使用 $ header
变量,但这是一个很长的字符串,可能会更改。
As mentioned in the comments, I don't think there is a way to use conditional logic on the woocommerce_email_header
hook. You could go by the $header
variable, but it is kind of a long string and it could change.
首先,我们删除现有的电子邮件标头:
First, we remove the existing email header:
function so_27400044_remove_email_header(){
remove_action( 'woocommerce_email_header', array( WC()->mailer(), 'email_header' ) );
}
add_action( 'init', 'so_27400044_remove_email_header' );
然后直接在电子邮件模板中调用特定的标题模板。例如,在 customer-invoice.php
模板中,我们可以调用 wc_get_template()
直接加载适当的/特定的标头。假设您已经复制了 email-header.php
模板,并将用于客户发票的模板重命名为 email-header-invoice.php
可能看起来像这样:
Then directly call the specific header template in your email template. For example, in the customer-invoice.php
template, we can call wc_get_template()
to directly load an appropriate/specific header. Assuming you've duplicated the email-header.php
template and renamed the one for customer invoices to email-header-invoice.php
it might look like this:
<?php
/**
* Customer invoice email
*
* @author WooThemes
* @package WooCommerce/Templates/Emails
* @version 2.2.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
?>
<?php do_action( 'woocommerce_email_header', $email_heading ); ?>
<?php wc_get_template( 'emails/email-header-invoice.php', array( 'email_heading' => $email_heading ) ) ; ?>
<?php if ( $order->has_status( 'pending' ) ) : ?>
我的本地设置不会通过电子邮件发送,因此我已经对以下内容进行了测试:
My local set up doesn't email so I've tested it with the following:
function kia_testing(){
$order= wc_get_order( 381 );
ob_start();
wc_get_template( 'emails/customer-processing-order.php', array(
'order' => $order,
'email_heading' => 'some title',
'sent_to_admin' => false,
'plain_text' => true
) );
echo ob_get_clean();
}
add_action( 'woocommerce_before_single_product' , 'kia_testing' );
我看到新的标题被修改后的 customer-processing- order.php
模板。
I am seeing the new header being called by the modified customer-processing-order.php
template.
这篇关于Woocommerce为每种电子邮件类型使用不同的标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!