【问题标题】:Different email header images for woocommerce emailswoocommerce 电子邮件的不同电子邮件标题图像
【发布时间】:2017-06-11 03:25:55
【问题描述】:

我正在尝试为发送给客户的每封电子邮件显示不同的标题图像,例如。处理订单。

我在 email-header.php 中尝试过 if 语句,并像这样调用电子邮件模板

<?php if ('class-wc-email-customer-processing-order') :?>
    <img src="#">
<?php else: ?>
    <?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>';
         }
    ?>

我还尝试为每封电子邮件制作单独的电子邮件标题,但我没有任何运气。我知道我必须离得很近,所以我希望有人能指出我正确的方向。

谢谢。

【问题讨论】:

  • if ('class-wc-email-customer-processing-order') 条件不测试任何东西。
  • 感谢您的快速回复 - 在这种情况下,我将如何定位处理订单电子邮件?
  • 通常我认为最终一切皆有可能,但快速浏览(并且高度时差)我没有看到任何关于传递给标题模板或标题钩子的电子邮件对象,所以我看不到任何您可以测试以区分电子邮件的内容。
  • 啊当然!这是有道理的,是否可以为每封电子邮件制作不同的标题模板并在电子邮件模板本身中调用它?
  • 实际上查看电子邮件模板,有第二个变量传递给woocommerce_email_header 钩子。请参阅:do_action( 'woocommerce_email_header', $email_heading, $email ); 因此,您可以有条件地删除当前标题操作并添加自定义操作。

标签: php wordpress email woocommerce


【解决方案1】:

我通过从 email-header.php 获取 HTML 并将其添加到模板中并更改图像路径成功地做到了这一点: 第 1 步:在您的子主题中创建一个名为 woocommerce 的文件夹,并在其中创建另一个名为 emails 的文件夹。 第 2 步:从 wp-content > plugins > woocommerce > templates > emails 复制所有电子邮件 第 3 步:删除 do_action( 'woocommerce_email_header', $email_heading, $email );但留下 ?> 在您的电子邮件模板中关闭 php 第 4 步:然后添加来自 email-header.php 的 HTML 并添加图片的路径

<!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="ADD IMAGE PATH HERE" /></p>';
								}
							?>
						</div>
						<table border="0" cellpadding="0" cellspacing="0" width="800" id="template_container">
							<tr>
								<td align="center" valign="top">
									<!-- Header -->
									<table border="0" cellpadding="0" cellspacing="0" width="800" 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="800" 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">

将您的图像添加到此处显示添加图像路径的位置。 第 5 步:对每个不同的模板执行此操作,以便在每个模板上都有一个自定义图像。

【讨论】:

    猜你喜欢
    • 2018-01-07
    • 2017-06-15
    • 1970-01-01
    • 2012-12-05
    • 2017-06-26
    • 1970-01-01
    • 1970-01-01
    • 2019-07-04
    • 2020-06-14
    相关资源
    最近更新 更多