仅为 WooCommerce 中的 "customer-on-hold-order" 电子邮件通知编辑页眉和页脚
Edit header and footer only for "customer-on-hold-order" email notifications in WooCommerce
我试图编辑我商店电子邮件的页眉和页脚,但我只能在直接转到 ALL 电子邮件的模板时才能编辑。
我也尝试将 email-header.php and email-footer.php 复制到我的子主题,但没有任何反应。
因为模板customer-on-holder-order列出了代码
/*
* @hooked WC_Emails::email_header() Output the email header
*/
do_action( 'woocommerce_email_header', $email_heading, $email ); ?>
...
/*
* @hooked WC_Emails::email_footer() Output the email footer
*/
do_action( 'woocommerce_email_footer', $email );
我怎么能find/edit这个?有什么建议吗?
woocommerce_email_header
和 woocommerce_email_footer
动作挂钩出现在多个模板文件中是正确的。
但是,要针对特定电子邮件,您可以使用 $email->id
,因为 $email
作为参数传递给两个挂钩
所以你得到:
// Header
function action_woocommerce_email_header( $email_heading, $email ) {
// Target
if ( $email->id == 'customer_on_hold_order' ) {
echo 'customer on hold order header';
}
}
add_action( 'woocommerce_email_header', 'action_woocommerce_email_header', 10, 2 );
// Footer
function action_woocommerce_email_footer( $email ) {
// Target
if ( $email->id == 'customer_on_hold_order' ) {
echo 'customer on hold order footer';
}
}
add_action( 'woocommerce_email_footer', 'action_woocommerce_email_footer', 10, 1 );
代码进入活动子主题(或活动主题)的 functions.php
文件。在 Wordpress 5.8.1 和 WooCommerce 5.8.0
中测试并工作
我试图编辑我商店电子邮件的页眉和页脚,但我只能在直接转到 ALL 电子邮件的模板时才能编辑。
我也尝试将 email-header.php and email-footer.php 复制到我的子主题,但没有任何反应。
因为模板customer-on-holder-order列出了代码
/*
* @hooked WC_Emails::email_header() Output the email header
*/
do_action( 'woocommerce_email_header', $email_heading, $email ); ?>
...
/*
* @hooked WC_Emails::email_footer() Output the email footer
*/
do_action( 'woocommerce_email_footer', $email );
我怎么能find/edit这个?有什么建议吗?
woocommerce_email_header
和 woocommerce_email_footer
动作挂钩出现在多个模板文件中是正确的。
但是,要针对特定电子邮件,您可以使用 $email->id
,因为 $email
作为参数传递给两个挂钩
所以你得到:
// Header
function action_woocommerce_email_header( $email_heading, $email ) {
// Target
if ( $email->id == 'customer_on_hold_order' ) {
echo 'customer on hold order header';
}
}
add_action( 'woocommerce_email_header', 'action_woocommerce_email_header', 10, 2 );
// Footer
function action_woocommerce_email_footer( $email ) {
// Target
if ( $email->id == 'customer_on_hold_order' ) {
echo 'customer on hold order footer';
}
}
add_action( 'woocommerce_email_footer', 'action_woocommerce_email_footer', 10, 1 );
代码进入活动子主题(或活动主题)的 functions.php
文件。在 Wordpress 5.8.1 和 WooCommerce 5.8.0