我想用一个新的模板更改woocommerce电子邮件标题模板,以便我可以在标题模板中添加条件以从仪表板中获取值(根据用户从仪表板中的输入更改标题的颜色)。为此,我创建了一个插件文件。
我已经学习了几本教程,但我收到的只是一堆错误。我有一个具有以下代码的类:
public function __construct(){
add_action(\'woocommerce_email\',array($this,\'woocommerce_email\'));
}
现在,我添加了删除默认标题挂钩的代码
public function woocommerce_email($mailer){
remove_action(\'woocommerce_header\',array($mailer,\'email_header\'));
add_action(\'woocommerce_header\',array($this,\'email_header\'));
现在调用模板
public function email_header() {
wc_get_template( \'emails/email-header.php\');
}
我没有向模板文件传递任何内容。因此,没有参数传递给函数。我只是想看看我的模板被拿走了。还有,我想
$mailer
成为woocommerce课程的一部分。任何帮助都将不胜感激。
请注意,这是一个插件功能,因此我对替换woocommerce电子邮件模板不感兴趣。
最合适的回答,由SO网友:Malay Solanki 整理而成
您必须删除操作woocommerce\\u email\\u标头
remove_action( \'woocommerce_email_header\', \'email_header\');
注册于
wp-content\\plugins\\woocommerce\\includes\\class-wc-emails.php
然后添加自己的操作
add_action(\'woocommerce_email_header\',\'your_function_name\');
您的函数应该输出html
默认标题模板中有以下代码
<?php
/**
* Email Header
*
* This template can be overridden by copying it to yourtheme/woocommerce/emails/email-header.php.
*
* HOWEVER, on occasion WooCommerce will need to update template files and you
* (the theme developer) will need to copy the new files to your theme to
* maintain compatibility. We try to do this as little as possible, but it does
* happen. When this occurs the version of the template file will be bumped and
* the readme will list any important changes.
*
* @see https://docs.woocommerce.com/document/template-structure/
* @author WooThemes
* @package WooCommerce/Templates/Emails
* @version 2.4.0
*/
if ( ! defined( \'ABSPATH\' ) ) {
exit; // Exit if accessed directly
}
?>
<!DOCTYPE html>
<html <?php language_attributes(); ?>>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=<?php bloginfo( \'charset\' ); ?>" />
<title><?php echo get_bloginfo( \'name\', \'display\' ); ?></title>
</head>
<body <?php echo is_rtl() ? \'rightmargin\' : \'leftmargin\'; ?>="0" marginwidth="0" topmargin="0" marginheight="0" offset="0">
<div id="wrapper" dir="<?php echo is_rtl() ? \'rtl\' : \'ltr\'?>">
<table border="0" cellpadding="0" cellspacing="0" height="100%" width="100%">
<tr>
<td align="center" valign="top">
<div id="template_header_image">
<?php
if ( $img = get_option( \'woocommerce_email_header_image\' ) ) {
echo \'<p style="margin-top:0;"><img src="\' . esc_url( $img ) . \'" alt="\' . get_bloginfo( \'name\', \'display\' ) . \'" /></p>\';
}
?>
</div>
<table border="0" cellpadding="0" cellspacing="0" width="600" id="template_container">
<tr>
<td align="center" valign="top">
<!-- Header -->
<table border="0" cellpadding="0" cellspacing="0" width="600" id="template_header">
<tr>
<td id="header_wrapper">
<h1><?php echo $email_heading; ?></h1>
</td>
</tr>
</table>
<!-- End Header -->
</td>
</tr>
<tr>
<td align="center" valign="top">
<!-- Body -->
<table border="0" cellpadding="0" cellspacing="0" width="600" id="template_body">
<tr>
<td valign="top" id="body_content">
<!-- Content -->
<table border="0" cellpadding="20" cellspacing="0" width="100%">
<tr>
<td valign="top">
<div id="body_content_inner">