Merging refund email template files

Changing previous commit to merge templates for partial and full
refunds to cut down on files.
This commit is contained in:
davidlenehan 2015-06-18 11:34:21 +01:00
parent 8b02b02145
commit 718d550252
7 changed files with 57 additions and 130 deletions

View File

@ -126,7 +126,6 @@ class WC_Emails {
$this->emails['WC_Email_Customer_Processing_Order'] = include( 'emails/class-wc-email-customer-processing-order.php' ); $this->emails['WC_Email_Customer_Processing_Order'] = include( 'emails/class-wc-email-customer-processing-order.php' );
$this->emails['WC_Email_Customer_Completed_Order'] = include( 'emails/class-wc-email-customer-completed-order.php' ); $this->emails['WC_Email_Customer_Completed_Order'] = include( 'emails/class-wc-email-customer-completed-order.php' );
$this->emails['WC_Email_Customer_Refunded_Order'] = include( 'emails/class-wc-email-customer-refunded-order.php' ); $this->emails['WC_Email_Customer_Refunded_Order'] = include( 'emails/class-wc-email-customer-refunded-order.php' );
$this->emails['WC_Email_Customer_Partially_Refunded_Order'] = include( 'emails/class-wc-email-customer-partially-refunded-order.php' );
$this->emails['WC_Email_Customer_Invoice'] = include( 'emails/class-wc-email-customer-invoice.php' ); $this->emails['WC_Email_Customer_Invoice'] = include( 'emails/class-wc-email-customer-invoice.php' );
$this->emails['WC_Email_Customer_Note'] = include( 'emails/class-wc-email-customer-note.php' ); $this->emails['WC_Email_Customer_Note'] = include( 'emails/class-wc-email-customer-note.php' );
$this->emails['WC_Email_Customer_Reset_Password'] = include( 'emails/class-wc-email-customer-reset-password.php' ); $this->emails['WC_Email_Customer_Reset_Password'] = include( 'emails/class-wc-email-customer-reset-password.php' );

View File

@ -28,27 +28,40 @@ class WC_Email_Customer_Refunded_Order extends WC_Email {
$this->title = __( 'Refunded order', 'woocommerce' ); $this->title = __( 'Refunded order', 'woocommerce' );
$this->description = __( 'Order refunded emails are sent to customers when their orders are marked refunded.', 'woocommerce' ); $this->description = __( 'Order refunded emails are sent to customers when their orders are marked refunded.', 'woocommerce' );
$this->heading = __( 'Your order has been refunded', 'woocommerce' );
$this->subject = __( 'Your {site_title} order from {order_date} has been refunded', 'woocommerce' );
$this->template_html = 'emails/customer-refunded-order.php'; $this->template_html = 'emails/customer-refunded-order.php';
$this->template_plain = 'emails/plain/customer-refunded-order.php'; $this->template_plain = 'emails/plain/customer-refunded-order.php';
// Triggers for this email // Triggers for this email
add_action( 'woocommerce_order_status_refunded_notification', array( $this, 'trigger' ) ); add_action( 'woocommerce_order_status_refunded_notification', array( $this, 'trigger' ), null, 3 );
add_action( 'woocommerce_order_partially_refunded_notification', array( $this, 'trigger' ), null, 3 );
// Call parent constuctor // Call parent constuctor
parent::__construct(); parent::__construct();
} }
function set_email_strings( $partial_refund ) {
if ( $partial_refund ) {
$this->heading = __( 'Your order has been partially refunded', 'woocommerce' );
$this->subject = __( 'Your {site_title} order from {order_date} has been partially refunded', 'woocommerce' );
}
else {
$this->heading = __( 'Your order has been refunded', 'woocommerce' );
$this->subject = __( 'Your {site_title} order from {order_date} has been refunded', 'woocommerce' );
}
}
/** /**
* trigger function. * trigger function.
* *
* @access public * @access public
* @return void * @return void
*/ */
function trigger( $order_id ) { function trigger( $order_id, $partial_refund = false, $refund_id = null ) {
$this->partial_refund = $partial_refund;
$this->set_email_strings( $partial_refund );
if ( $order_id ) { if ( $order_id ) {
$this->object = wc_get_order( $order_id ); $this->object = wc_get_order( $order_id );
$this->recipient = $this->object->billing_email; $this->recipient = $this->object->billing_email;
@ -59,6 +72,10 @@ class WC_Email_Customer_Refunded_Order extends WC_Email {
$this->replace['order-date'] = date_i18n( wc_date_format(), strtotime( $this->object->order_date ) ); $this->replace['order-date'] = date_i18n( wc_date_format(), strtotime( $this->object->order_date ) );
$this->replace['order-number'] = $this->object->get_order_number(); $this->replace['order-number'] = $this->object->get_order_number();
} }
if ( $refund_id ) {
$this->refund = wc_get_order( $refund_id );
}
if ( ! $this->is_enabled() || ! $this->get_recipient() ) { if ( ! $this->is_enabled() || ! $this->get_recipient() ) {
return; return;
@ -102,10 +119,12 @@ class WC_Email_Customer_Refunded_Order extends WC_Email {
function get_content_html() { function get_content_html() {
ob_start(); ob_start();
wc_get_template( $this->template_html, array( wc_get_template( $this->template_html, array(
'order' => $this->object, 'order' => $this->object,
'email_heading' => $this->get_heading(), 'refund' => $this->refund,
'sent_to_admin' => false, 'partial_refund' => $this->partial_refund,
'plain_text' => false 'email_heading' => $this->get_heading(),
'sent_to_admin' => false,
'plain_text' => false
) ); ) );
return ob_get_clean(); return ob_get_clean();
} }
@ -119,10 +138,12 @@ class WC_Email_Customer_Refunded_Order extends WC_Email {
function get_content_plain() { function get_content_plain() {
ob_start(); ob_start();
wc_get_template( $this->template_plain, array( wc_get_template( $this->template_plain, array(
'order' => $this->object, 'order' => $this->object,
'email_heading' => $this->get_heading(), 'refund' => $this->refund,
'sent_to_admin' => false, 'partial_refund' => $this->partial_refund,
'plain_text' => true 'email_heading' => $this->get_heading(),
'sent_to_admin' => false,
'plain_text' => true
) ); ) );
return ob_get_clean(); return ob_get_clean();
} }

View File

@ -723,7 +723,7 @@ function wc_create_refund( $args = array() ) {
$max_remaining_refund = wc_format_decimal( $order->get_total() - $order->get_total_refunded() ); $max_remaining_refund = wc_format_decimal( $order->get_total() - $order->get_total_refunded() );
if ( $max_remaining_refund > 0 ) { if ( $max_remaining_refund > 0 ) {
do_action( 'woocommerce_order_partially_refunded', $args['order_id'], $refund_id ); do_action( 'woocommerce_order_partially_refunded', $args['order_id'], true, $refund_id );
} }
do_action( 'woocommerce_refund_created', $refund_id ); do_action( 'woocommerce_refund_created', $refund_id );

View File

@ -1,65 +0,0 @@
<?php
/**
* Customer partially refunded order email
*
* @author WooThemes
* @package WooCommerce/Templates/Emails
* @version 2.4.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
?>
<?php do_action( 'woocommerce_email_header', $email_heading ); ?>
<p><?php printf( __( "Hi there. Your order on %s has been partially refunded.", 'woocommerce' ), get_option( 'blogname' ) ); ?></p>
<?php do_action( 'woocommerce_email_before_order_table', $order, $sent_to_admin, $plain_text ); ?>
<h2><?php printf( __( 'Order #%s', 'woocommerce' ), $order->get_order_number() ); ?></h2>
<table cellspacing="0" cellpadding="6" style="width: 100%; border: 1px solid #eee;" border="1" bordercolor="#eee">
<thead>
<tr>
<th scope="col" style="text-align:left; border: 1px solid #eee;"><?php _e( 'Product', 'woocommerce' ); ?></th>
<th scope="col" style="text-align:left; border: 1px solid #eee;"><?php _e( 'Quantity', 'woocommerce' ); ?></th>
<th scope="col" style="text-align:left; border: 1px solid #eee;"><?php _e( 'Price', 'woocommerce' ); ?></th>
</tr>
</thead>
<tbody>
<?php echo $order->email_order_items_table( true, false, true ); ?>
</tbody>
<tfoot>
<?php
if ( $totals = $order->get_order_item_totals() ) {
$i = 0;
if ( $refund->get_refund_amount() > 0 ) {
?><tr>
<th scope="row" colspan="2" style="text-align:left; border: 1px solid #eee;border-top-width: 4px;"><?php _e( 'Amount Refunded', 'woocommerce' ); ?>:</th>
<td style="text-align:left; border: 1px solid #eee;border-top-width: 4px;"><?php echo $refund->get_formatted_refund_amount(); ?></td>
</tr><?php
}
foreach ( $totals as $total ) {
$i++;
?><tr>
<th scope="row" colspan="2" style="text-align:left; border: 1px solid #eee;"><?php echo $total['label']; ?></th>
<td style="text-align:left; border: 1px solid #eee;"><?php echo $total['value']; ?></td>
</tr><?php
}
}
?>
</tfoot>
</table>
<?php do_action( 'woocommerce_email_after_order_table', $order, $sent_to_admin, $plain_text ); ?>
<?php do_action( 'woocommerce_email_order_meta', $order, $sent_to_admin, $plain_text ); ?>
<?php do_action( 'woocommerce_email_customer_details', $order, $sent_to_admin, $plain_text ); ?>
<?php do_action( 'woocommerce_email_footer' ); ?>

View File

@ -15,7 +15,14 @@ if ( ! defined( 'ABSPATH' ) ) {
<?php do_action( 'woocommerce_email_header', $email_heading ); ?> <?php do_action( 'woocommerce_email_header', $email_heading ); ?>
<p><?php printf( __( "Hi there. Your order on %s has been refunded.", 'woocommerce' ), get_option( 'blogname' ) ); ?></p> <p><?php
if ( $partial_refund ) {
printf( __( "Hi there. Your order on %s has been partially refunded.", 'woocommerce' ), get_option( 'blogname' ) );
}
else {
printf( __( "Hi there. Your order on %s has been refunded.", 'woocommerce' ), get_option( 'blogname' ) );
}
?></p>
<?php do_action( 'woocommerce_email_before_order_table', $order, $sent_to_admin, $plain_text ); ?> <?php do_action( 'woocommerce_email_before_order_table', $order, $sent_to_admin, $plain_text ); ?>
@ -35,7 +42,17 @@ if ( ! defined( 'ABSPATH' ) ) {
<tfoot> <tfoot>
<?php <?php
if ( $totals = $order->get_order_item_totals() ) { if ( $totals = $order->get_order_item_totals() ) {
$i = 0; $i = 0;
if ( $refund && $refund->get_refund_amount() > 0 ) {
?><tr>
<th scope="row" colspan="2" style="text-align:left; border: 1px solid #eee;border-top-width: 4px;"><?php _e( 'Amount Refunded', 'woocommerce' ); ?>:</th>
<td style="text-align:left; border: 1px solid #eee;border-top-width: 4px;"><?php echo $refund->get_formatted_refund_amount(); ?></td>
</tr><?php
$i++;
}
foreach ( $totals as $total ) { foreach ( $totals as $total ) {
$i++; $i++;
?><tr> ?><tr>

View File

@ -1,49 +0,0 @@
<?php
/**
* Customer partially refunded order email (plain text)
*
* @author WooThemes
* @package WooCommerce/Templates/Emails/Plain
* @version 2.4.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
echo "= " . $email_heading . " =\n\n";
echo sprintf( __( "Hi there. Your order on %s has been partially refunded. Your order details are shown below for your reference:", 'woocommerce' ), get_option( 'blogname' ) ) . "\n\n";
echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n";
do_action( 'woocommerce_email_before_order_table', $order, $sent_to_admin, $plain_text );
echo strtoupper( sprintf( __( 'Order number: %s', 'woocommerce' ), $order->get_order_number() ) ) . "\n";
echo date_i18n( __( 'jS F Y', 'woocommerce' ), strtotime( $order->order_date ) ) . "\n";
do_action( 'woocommerce_email_order_meta', $order, $sent_to_admin, $plain_text );
echo "\n" . $order->email_order_items_table( true, false, true, '', '', true );
echo "==========\n\n";
if ( $refund->get_refund_amount() > 0 ) {
echo __( 'Amount Refunded', 'woocommerce' ) . "\t " . $refund->get_formatted_refund_amount() . "\n";
}
if ( $totals = $order->get_order_item_totals() ) {
foreach ( $totals as $total ) {
echo $total['label'] . "\t " . $total['value'] . "\n";
}
}
echo "\n=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n";
do_action( 'woocommerce_email_after_order_table', $order, $sent_to_admin, $plain_text );
do_action( 'woocommerce_email_customer_details', $order, $sent_to_admin, $plain_text );
echo "\n=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n";
echo apply_filters( 'woocommerce_email_footer_text', get_option( 'woocommerce_email_footer_text' ) );

View File

@ -28,6 +28,10 @@ echo "\n" . $order->email_order_items_table( true, false, true, '', '', true );
echo "==========\n\n"; echo "==========\n\n";
if ( $refund && $refund->get_refund_amount() > 0 ) {
echo __( 'Amount Refunded', 'woocommerce' ) . "\t " . $refund->get_formatted_refund_amount() . "\n";
}
if ( $totals = $order->get_order_item_totals() ) { if ( $totals = $order->get_order_item_totals() ) {
foreach ( $totals as $total ) { foreach ( $totals as $total ) {
echo $total['label'] . "\t " . $total['value'] . "\n"; echo $total['label'] . "\t " . $total['value'] . "\n";