首页 > 解决方案 > 仅为 WooCommerce 中的“客户保留订单”电子邮件通知编辑页眉和页脚

问题描述

我尝试编辑商店电子邮件的页眉和页脚,但只有当它直接进入所有电子邮件的模板时才能进行编辑。

我还尝试将email-header.phpemail-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 );

我怎样才能找到/编辑这个?有什么建议吗?

标签: phpwordpresswoocommerceemail-notifications

解决方案


woocommerce_email_headerwoocommerce_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 中测试和工作


推荐阅读