php - 仅为 WooCommerce 中的“客户保留订单”电子邮件通知编辑页眉和页脚
问题描述
我尝试编辑商店电子邮件的页眉和页脚,但只有当它直接进入所有电子邮件的模板时才能进行编辑。
我还尝试将email-header.php和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 );
我怎样才能找到/编辑这个?有什么建议吗?
解决方案
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 中测试和工作
推荐阅读
- javascript - 从子表更新父表单元格值
- flutter - 颤振图标不在容器中居中
- amazon-web-services - KMS get_public_key() UnsupportedOperationException
- node.js - `npm i` 和 `npm i 之间的区别
` - php - 是否可以使用 PHP 在邮递员中测试单选按钮
- java - 无法使用 MessageFormat 解析文本
- node.js - 从后端发送的状态 400 在角度拦截器中未被识别为 HttpResponse
- oracle - 寻找在 S3 存储桶中复制 oracle 表的最佳方法
- javascript - 同时过滤两个数组?
- javascript - 单击 jQuery 中的引导选项卡时,有什么方法可以刷新 div?