Michelle
Michelle

Reputation: 549

WooCommerce: Create custom email

I am trying to create a review reminder email using the Customer invoice / Order details email. We don't use this email so I thought it would be good to change the code to make it a review reminder email and then we can trigger it manually.

I have changed a bit of code, so it now looks like this:

<?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 );

I need to add 3 things though:

  1. A static image, below the header, pointing to an image in the media library.
  2. A URL link to the particular product purchased.
  3. This query gives me the product name (and image), quantity and price. I want to get rid of quantity and price and just have the name and image.

I don't want to mess with the main email template code though, so I want to be able to do these things all within this one php file.

Can someone please advise on any of these three items? Thanks!

Upvotes: 1

Views: 1576

Answers (1)

Mel
Mel

Reputation: 943

Copy the email-order-items.php form plugins/woocommerce/templates/emails/ to your wp-content/themefolder/woocommerce/emails/email-order-item.php by doing this you can edit the layout of your email without touching the core functions of woocommerce. The details are already there including the image and the title.

Upvotes: 1

Related Questions