WooCommerce:创建自定义电子邮件

时间:2019-01-22 11:41:05

标签: php wordpress woocommerce woocommerce-theming

我正在尝试使用客户发票/订单明细电子邮件创建评论提醒电子邮件。我们不使用此电子邮件,所以我认为最好更改代码以使其成为审阅提醒电子邮件,然后我们可以手动触发它。

我更改了一些代码,所以现在看起来像这样:

<?php
/**
 * Customer completed order email
 *
 * This template can be overridden by copying it to yourtheme/woocommerce/emails/customer-completed-order.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/
 * @package WooCommerce/Templates/Emails
 * @version 3.5.0
 */

if ( ! defined( 'ABSPATH' ) ) {
  exit;
}

/*
 * @hooked WC_Emails::email_header() Output the email header
 */
do_action( 'woocommerce_email_header', $email_heading, $email ); ?>


<?php /* translators: %s: Customer first name */ ?>
<p><?php printf( esc_html__( 'Hi %s,', 'woocommerce' ), esc_html( $order->get_billing_first_name() ) ); ?></p>
<p><?php printf( esc_html__("the more you share, the more you help other customers. We would love to know your thoughts on your most recent purchase and we'd appreciate it if you could take a moment to write a quick review.", 'woocommerce' ), esc_html( wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ) ) ); ?></p>
<?php

/*
 * @hooked WC_Emails::order_details() Shows the order details table.
 * @hooked WC_Structured_Data::generate_order_data() Generates structured data.
 * @hooked WC_Structured_Data::output_structured_data() Outputs structured data.
 * @since 2.5.0
 */

$text_align = is_rtl() ? 'right' : 'left';


  if ( $sent_to_admin ) {
    $before = '<a class="link" href="' . esc_url( $order->get_edit_order_url() ) . '">';
    $after  = '</a>';
  } else {
    $before = '';
    $after  = '';
  }
  /* translators: %s: Order ID. */
  ?>
</h2>

<div style="margin-bottom: 40px;">
  <table class="td" cellspacing="0" cellpadding="0" style="width: 100%; font-family: 'Helvetica Neue', Helvetica, Roboto, Arial, sans-serif;">
<tbody>
      <?php
      echo wc_get_email_order_items( $order, array( // WPCS: XSS ok.
        'show_sku'      => $sent_to_admin,
        'show_image'    => true,
        'image_size'    => array( 100, 100 ),
        'plain_text'    => $plain_text,
        'sent_to_admin' => $sent_to_admin,
      ) );
      ?>

    </tbody>
  </table>
</div>


<p>
<?php esc_html_e( 'Thanks for shopping with us.', 'woocommerce' ); ?>
</p>
<?php

/*
 * @hooked WC_Emails::email_footer() Output the email footer
 */
do_action( 'woocommerce_email_footer', $email );

我需要添加3件事:

    标头下方的
  1. 静态图像 ,指向媒体库中的图像。
  2. 指向所购买特定产品的 URL链接
  3. 此查询为我提供了产品名称(和图片),数量和价格。我想摆脱数量和价格,而只拥有名称和图像。

尽管我不想弄乱主要的电子邮件模板代码,所以我希望能够在一个php文件中全部完成这些事情。

有人可以就这三个项目提供建议吗?谢谢!

1 个答案:

答案 0 :(得分:0)

email-order-items.php 表格 plugins / woocommerce / templates / emails / 复制到这样,您的 wp-content / themefolder / woocommerce / emails / email-order-item.php 即可编辑电子邮件的布局,而无需触及woocommerce的核心功能。详细信息已经在那里,包括图像和标题。