Skip to content
This repository was archived by the owner on May 21, 2025. It is now read-only.

Commit f7dbe32

Browse files
authored
Update subscription-related emails for WC core email improvements (#808)
* Remove template author * Fix phpcs * Fix phpcs * Update the email order details table with WC 9.7 email improvements * Tidy the Order/Subscription summary heading * Remove comment * Separate subheading from datetime formatting * Fix the legacy format of the object ID heading * Add changelog entry * Add comment * Reverse formatting changes * Update template version * Update Admin new renewal order email template * Update email template * Update pre automatic renewal email template * Add email improvement to customer-notification-auto-renewal email * Update the notification-auto-trial-ending email * Various updates to the email templates * Add additional content divs to missing email templates * Update email additional content structure to follow WC 9.8 structure
1 parent 8bc7d80 commit f7dbe32

17 files changed

+284
-127
lines changed

templates/emails/admin-new-renewal-order.php

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,52 @@
22
/**
33
* Admin new renewal order email
44
*
5-
* @author Brent Shepherd
5+
* Based on the WooCommerce core admin-new-order.php template.
6+
*
67
* @package WooCommerce_Subscriptions/Templates/Emails
7-
* @version 1.0.0 - Migrated from WooCommerce Subscriptions v2.6.0
8+
* @version 7.3.0 - Updated for WC core email improvements.
89
*/
9-
if ( ! defined( 'ABSPATH' ) ) {
10-
exit; // Exit if accessed directly
11-
}
1210

11+
defined( 'ABSPATH' ) || exit;
12+
13+
$email_improvements_enabled = wcs_is_wc_feature_enabled( 'email_improvements' );
14+
15+
/*
16+
* @hooked WC_Emails::email_header() Output the email header
17+
*/
1318
do_action( 'woocommerce_email_header', $email_heading, $email ); ?>
1419

20+
<?php echo $email_improvements_enabled ? '<div class="email-introduction">' : ''; ?>
1521
<?php /* translators: $1: customer's billing first name and last name */ ?>
16-
<p><?php printf( esc_html_x( 'You have received a subscription renewal order from %1$s. Their order is as follows:', 'Used in admin email: new renewal order', 'woocommerce-subscriptions' ), esc_html( $order->get_formatted_billing_full_name() ) );?></p>
22+
<p><?php printf( esc_html_x( 'You have received a subscription renewal order from %1$s. Their order is as follows:', 'Used in admin email: new renewal order', 'woocommerce-subscriptions' ), esc_html( $order->get_formatted_billing_full_name() ) ); ?></p>
23+
<?php echo $email_improvements_enabled ? '</div>' : ''; ?>
1724

1825
<?php
1926
/**
2027
* @hooked WC_Subscriptions_Email::order_details() Shows the order details table.
28+
* @hooked WC_Subscriptions_Email::order_download_details() Shows the order downloads table.
2129
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.1.0
2230
*/
2331
do_action( 'woocommerce_subscriptions_email_order_details', $order, $sent_to_admin, $plain_text, $email );
2432

33+
/*
34+
* @hooked WC_Emails::order_meta() Shows order meta data.
35+
*/
2536
do_action( 'woocommerce_email_order_meta', $order, $sent_to_admin, $plain_text, $email );
2637

38+
/*
39+
* @hooked WC_Emails::customer_details() Shows customer details
40+
* @hooked WC_Emails::email_address() Shows email address
41+
*/
2742
do_action( 'woocommerce_email_customer_details', $order, $sent_to_admin, $plain_text, $email );
2843

2944
/**
3045
* Show user-defined additional content - this is set in each email's settings.
3146
*/
3247
if ( $additional_content ) {
48+
echo $email_improvements_enabled ? '<table border="0" cellpadding="0" cellspacing="0" width="100%"><tr><td class="email-additional-content">' : '';
3349
echo wp_kses_post( wpautop( wptexturize( $additional_content ) ) );
50+
echo $email_improvements_enabled ? '</td></tr></table>' : '';
3451
}
3552

3653
do_action( 'woocommerce_email_footer', $email );
Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,52 @@
11
<?php
22
/**
3-
* Admin new switch order email
3+
* Admin new switch order email.
4+
*
5+
* Based on the WooCommerce core admin-new-order.php template.
46
*
5-
* @author Brent Shepherd
67
* @package WooCommerce_Subscriptions/Templates/Emails
7-
* @version 1.0.0 - Migrated from WooCommerce Subscriptions v2.6.0
8+
* @version 7.3.0 - Updated for WC core email improvements.
89
*/
9-
if ( ! defined( 'ABSPATH' ) ) {
10-
exit; // Exit if accessed directly
11-
}
1210

11+
defined( 'ABSPATH' ) || exit;
12+
13+
$email_improvements_enabled = wcs_is_wc_feature_enabled( 'email_improvements' );
14+
15+
/*
16+
* @hooked WC_Emails::email_header() Output the email header
17+
*/
1318
do_action( 'woocommerce_email_header', $email_heading, $email );
1419

1520
$switched_count = count( $subscriptions );
1621

17-
/* translators: $1: customer's first name and last name, $2: how many subscriptions customer switched */ ?>
18-
<p><?php echo esc_html( sprintf( _nx( 'Customer %1$s has switched their subscription. The details of their new subscription are as follows:', 'Customer %1$s has switched %2$d of their subscriptions. The details of their new subscriptions are as follows:', $switched_count, 'Used in switch notification admin email', 'woocommerce-subscriptions' ), $order->get_formatted_billing_full_name(), $switched_count ) );?></p>
22+
echo $email_improvements_enabled ? '<div class="email-introduction">' : '';
23+
?>
24+
<p>
25+
<?php
26+
if ( 1 === $switched_count ) {
27+
/* translators: $1: customer's first name and last name */
28+
echo esc_html( sprintf( _x( 'Customer %1$s has switched their subscription. The details of their new subscription are as follows:', 'Used in switch notification admin email', 'woocommerce-subscriptions' ), $order->get_formatted_billing_full_name() ) );
29+
} else {
30+
/* translators: $1: customer's first name and last name, $2: how many subscriptions customer switched */
31+
echo esc_html( sprintf( _x( 'Customer %1$s has switched %2$d of their subscriptions. The details of their new subscriptions are as follows:', 'Used in switch notification admin email', 'woocommerce-subscriptions' ), $order->get_formatted_billing_full_name(), $switched_count ) );
32+
}
33+
?>
34+
</p>
35+
<?php echo $email_improvements_enabled ? '</div>' : ''; ?>
1936

2037
<h2><?php esc_html_e( 'Switch Order Details', 'woocommerce-subscriptions' ); ?></h2>
2138

2239
<?php
40+
/**
41+
* @hooked WC_Subscriptions_Email::order_details() Shows the order details table.
42+
* @hooked WC_Subscriptions_Email::order_download_details() Shows the order downloads table.
43+
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.1.0
44+
*/
2345
do_action( 'woocommerce_subscriptions_email_order_details', $order, $sent_to_admin, $plain_text, $email );
2446

47+
/*
48+
* @hooked WC_Emails::order_meta() Shows order meta data.
49+
*/
2550
do_action( 'woocommerce_email_order_meta', $order, $sent_to_admin, $plain_text, $email );
2651
?>
2752

@@ -32,13 +57,19 @@
3257
do_action( 'woocommerce_subscriptions_email_order_details', $subscription, $sent_to_admin, $plain_text, $email );
3358
}
3459

60+
/*
61+
* @hooked WC_Emails::customer_details() Shows customer details
62+
* @hooked WC_Emails::email_address() Shows email address
63+
*/
3564
do_action( 'woocommerce_email_customer_details', $order, $sent_to_admin, $plain_text, $email );
3665

3766
/**
3867
* Show user-defined additional content - this is set in each email's settings.
3968
*/
4069
if ( $additional_content ) {
70+
echo $email_improvements_enabled ? '<div class="email-additional-content">' : '';
4171
echo wp_kses_post( wpautop( wptexturize( $additional_content ) ) );
72+
echo $email_improvements_enabled ? '</div>' : '';
4273
}
4374

4475
do_action( 'woocommerce_email_footer', $email );

templates/emails/admin-payment-retry.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,24 @@
55
* Email sent to admins when an attempt to automatically process a subscription renewal payment has failed
66
* and a retry rule has been applied to retry the payment in the future.
77
*
8-
* @author Prospress
98
* @package WooCommerce_Subscriptions/Templates/Emails/Plain
10-
* @version 1.0.0 - Migrated from WooCommerce Subscriptions v2.6.0
9+
* @version 7.3.0 - Updated for WC core email improvements.
1110
*/
1211

13-
if ( ! defined( 'ABSPATH' ) ) {
14-
exit;
15-
}
12+
defined( 'ABSPATH' ) || exit;
13+
14+
$email_improvements_enabled = wcs_is_wc_feature_enabled( 'email_improvements' );
1615

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

21+
<?php echo $email_improvements_enabled ? '<div class="email-introduction">' : ''; ?>
2222
<?php /* translators: %1$s: an order number, %2$s: the customer's full name, %3$s: lowercase human time diff in the form returned by wcs_get_human_time_diff(), e.g. 'in 12 hours' */ ?>
23-
<p><?php echo esc_html( sprintf( _x( 'The automatic recurring payment for order #%d from %s has failed. The payment will be retried %3$s.', 'In customer renewal invoice email', 'woocommerce-subscriptions' ), $order->get_order_number(), $order->get_formatted_billing_full_name(), wcs_get_human_time_diff( $retry->get_time() ) ) ); ?></p>
23+
<p><?php echo esc_html( sprintf( _x( 'The automatic recurring payment for order #%1$d from %2$s has failed. The payment will be retried %3$s.', 'In customer renewal invoice email', 'woocommerce-subscriptions' ), $order->get_order_number(), $order->get_formatted_billing_full_name(), wcs_get_human_time_diff( $retry->get_time() ) ) ); ?></p>
2424
<p><?php esc_html_e( 'The renewal order is as follows:', 'woocommerce-subscriptions' ); ?></p>
25+
<?php echo $email_improvements_enabled ? '</div>' : ''; ?>
2526

2627
<?php
2728

@@ -46,7 +47,9 @@
4647
* Show user-defined additional content - this is set in each email's settings.
4748
*/
4849
if ( $additional_content ) {
50+
echo $email_improvements_enabled ? '<table border="0" cellpadding="0" cellspacing="0" width="100%"><tr><td class="email-additional-content">' : '';
4951
echo wp_kses_post( wpautop( wptexturize( $additional_content ) ) );
52+
echo $email_improvements_enabled ? '</td></tr></table>' : '';
5053
}
5154

5255
/**

templates/emails/cancelled-subscription.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,16 @@
33
* Cancelled Subscription email
44
*
55
* @package WooCommerce_Subscriptions/Templates/Emails
6-
* @version 7.3.0 Provide additional context about the subscription status (if it is pending cancellation, or fully cancelled).
6+
* @version 7.3.0 - Updated for WC core email improvements.
77
*/
8-
if ( ! defined( 'ABSPATH' ) ) {
9-
exit; // Exit if accessed directly
10-
}
8+
9+
defined( 'ABSPATH' ) || exit;
10+
11+
$email_improvements_enabled = wcs_is_wc_feature_enabled( 'email_improvements' );
1112

1213
do_action( 'woocommerce_email_header', $email_heading, $email ); ?>
1314

15+
<?php echo $email_improvements_enabled ? '<div class="email-introduction">' : ''; ?>
1416
<p>
1517
<?php
1618
if ( 'pending-cancel' === $subscription->get_status() ) {
@@ -29,6 +31,7 @@
2931
}
3032
?>
3133
</p>
34+
<?php echo $email_improvements_enabled ? '</div>' : ''; ?>
3235

3336
<table class="td" cellspacing="0" cellpadding="6" style="width: 100%; font-family: 'Helvetica Neue', Helvetica, Roboto, Arial, sans-serif;" border="1">
3437
<thead>
@@ -74,7 +77,9 @@
7477
* Show user-defined additional content - this is set in each email's settings.
7578
*/
7679
if ( $additional_content ) {
80+
echo $email_improvements_enabled ? '<table border="0" cellpadding="0" cellspacing="0" width="100%"><tr><td class="email-additional-content">' : '';
7781
echo wp_kses_post( wpautop( wptexturize( $additional_content ) ) );
82+
echo $email_improvements_enabled ? '</td></tr></table>' : '';
7883
}
7984

8085
do_action( 'woocommerce_email_footer', $email );

templates/emails/customer-completed-renewal-order.php

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,53 @@
22
/**
33
* Customer completed renewal order email
44
*
5-
* @author Brent Shepherd
5+
* Based on the WooCommerce core customer-completed-order.php template.
6+
*
67
* @package WooCommerce_Subscriptions/Templates/Emails
7-
* @version 1.0.0 - Migrated from WooCommerce Subscriptions v2.6.0
8+
* @version 7.3.0 - Updated for WC core email improvements.
89
*/
910

10-
if ( ! defined( 'ABSPATH' ) ) {
11-
exit; // Exit if accessed directly
12-
}
11+
defined( 'ABSPATH' ) || exit;
1312

13+
$email_improvements_enabled = wcs_is_wc_feature_enabled( 'email_improvements' );
14+
15+
/*
16+
* @hooked WC_Emails::email_header() Output the email header
17+
*/
1418
do_action( 'woocommerce_email_header', $email_heading, $email ); ?>
1519

20+
<?php echo $email_improvements_enabled ? '<div class="email-introduction">' : ''; ?>
1621
<?php /* translators: %s: Customer first name */ ?>
1722
<p><?php printf( esc_html__( 'Hi %s,', 'woocommerce-subscriptions' ), esc_html( $order->get_billing_first_name() ) ); ?></p>
1823
<p><?php esc_html_e( 'We have finished processing your subscription renewal order.', 'woocommerce-subscriptions' ); ?></p>
24+
<?php echo $email_improvements_enabled ? '</div>' : ''; ?>
1925

2026
<?php
27+
/**
28+
* @hooked WC_Subscriptions_Email::order_details() Shows the order details table.
29+
* @hooked WC_Subscriptions_Email::order_download_details() Shows the order downloads table.
30+
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.1.0
31+
*/
2132
do_action( 'woocommerce_subscriptions_email_order_details', $order, $sent_to_admin, $plain_text, $email );
2233

34+
/*
35+
* @hooked WC_Emails::order_meta() Shows order meta data.
36+
*/
2337
do_action( 'woocommerce_email_order_meta', $order, $sent_to_admin, $plain_text, $email );
2438

39+
/*
40+
* @hooked WC_Emails::customer_details() Shows customer details
41+
* @hooked WC_Emails::email_address() Shows email address
42+
*/
2543
do_action( 'woocommerce_email_customer_details', $order, $sent_to_admin, $plain_text, $email );
2644

2745
/**
2846
* Show user-defined additional content - this is set in each email's settings.
2947
*/
3048
if ( $additional_content ) {
49+
echo $email_improvements_enabled ? '<table border="0" cellpadding="0" cellspacing="0" width="100%"><tr><td class="email-additional-content">' : '';
3150
echo wp_kses_post( wpautop( wptexturize( $additional_content ) ) );
51+
echo $email_improvements_enabled ? '</td></tr></table>' : '';
3252
}
3353

3454
do_action( 'woocommerce_email_footer', $email );

templates/emails/customer-completed-switch-order.php

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,37 @@
22
/**
33
* Customer completed subscription change email
44
*
5-
* @author Brent Shepherd
5+
* Based on the WooCommerce core customer-completed-order.php template.
6+
*
67
* @package WooCommerce_Subscriptions/Templates/Emails
7-
* @version 1.0.0 - Migrated from WooCommerce Subscriptions v2.6.0
8+
* @version 7.3.0 - Updated for WC core email improvements.
89
*/
910

10-
if ( ! defined( 'ABSPATH' ) ) {
11-
exit; // Exit if accessed directly
12-
}
11+
defined( 'ABSPATH' ) || exit;
12+
13+
$email_improvements_enabled = wcs_is_wc_feature_enabled( 'email_improvements' );
1314

15+
/*
16+
* @hooked WC_Emails::email_header() Output the email header
17+
*/
1418
do_action( 'woocommerce_email_header', $email_heading, $email ); ?>
1519

20+
<?php echo $email_improvements_enabled ? '<div class="email-introduction">' : ''; ?>
1621
<?php /* translators: %s: Customer first name */ ?>
1722
<p><?php printf( esc_html__( 'Hi %s,', 'woocommerce-subscriptions' ), esc_html( $order->get_billing_first_name() ) ); ?></p>
1823
<p><?php esc_html_e( 'You have successfully changed your subscription items. Your new order and subscription details are shown below for your reference:', 'woocommerce-subscriptions' ); ?></p>
19-
24+
<?php echo $email_improvements_enabled ? '</div>' : ''; ?>
2025
<?php
26+
/**
27+
* @hooked WC_Subscriptions_Email::order_details() Shows the order details table.
28+
* @hooked WC_Subscriptions_Email::order_download_details() Shows the order downloads table.
29+
* @since 1.0.0 - Migrated from WooCommerce Subscriptions v2.1.0
30+
*/
2131
do_action( 'woocommerce_subscriptions_email_order_details', $order, $sent_to_admin, $plain_text, $email );
2232

33+
/**
34+
* @hooked WC_Emails::order_meta() Shows order meta data.
35+
*/
2336
do_action( 'woocommerce_email_order_meta', $order, $sent_to_admin, $plain_text, $email );
2437
?>
2538

@@ -30,13 +43,19 @@
3043
do_action( 'woocommerce_subscriptions_email_order_details', $subscription, $sent_to_admin, $plain_text, $email );
3144
}
3245

46+
/**
47+
* @hooked WC_Emails::customer_details() Shows customer details
48+
* @hooked WC_Emails::email_address() Shows email address
49+
*/
3350
do_action( 'woocommerce_email_customer_details', $order, $sent_to_admin, $plain_text, $email );
3451

3552
/**
3653
* Show user-defined additional content - this is set in each email's settings.
3754
*/
3855
if ( $additional_content ) {
56+
echo $email_improvements_enabled ? '<table border="0" cellpadding="0" cellspacing="0" width="100%"><tr><td class="email-additional-content">' : '';
3957
echo wp_kses_post( wpautop( wptexturize( $additional_content ) ) );
58+
echo $email_improvements_enabled ? '</td></tr></table>' : '';
4059
}
4160

4261
do_action( 'woocommerce_email_footer', $email );

templates/emails/customer-notification-auto-renewal.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
* Customer Notification: Notify the customer that an automated renewal their subscription is about to happen.
44
*
55
* @package WooCommerce_Subscriptions/Templates/Emails
6-
* @version 7.2.0
6+
* @version 7.3.0 - Updated for WC core email improvements.
77
*/
8-
if ( ! defined( 'ABSPATH' ) ) {
9-
exit; // Exit if accessed directly
10-
}
8+
9+
defined( 'ABSPATH' ) || exit;
10+
11+
$email_improvements_enabled = wcs_is_wc_feature_enabled( 'email_improvements' );
1112

1213
/**
1314
* @hooked WC_Emails::email_header() Output the email header.
@@ -16,6 +17,7 @@
1617
*/
1718
do_action( 'woocommerce_email_header', $email_heading, $email ); ?>
1819

20+
<?php echo $email_improvements_enabled ? '<div class="email-introduction">' : ''; ?>
1921
<p>
2022
<?php
2123
echo esc_html(
@@ -27,8 +29,6 @@
2729
);
2830
?>
2931
</p>
30-
31-
3232
<p>
3333
<?php
3434
echo wp_kses(
@@ -46,6 +46,7 @@
4646
?>
4747
</p>
4848
<?php
49+
echo $email_improvements_enabled ? '</div>' : '';
4950

5051
// Show subscription details.
5152
\WC_Subscriptions_Email::subscription_details( $subscription, $order, $sent_to_admin, $plain_text, true );
@@ -84,7 +85,9 @@
8485
* Show user-defined additional content - this is set in each email's settings.
8586
*/
8687
if ( $additional_content ) {
88+
echo $email_improvements_enabled ? '<table border="0" cellpadding="0" cellspacing="0" width="100%"><tr><td class="email-additional-content">' : '';
8789
echo wp_kses_post( wpautop( wptexturize( $additional_content ) ) );
90+
echo $email_improvements_enabled ? '</td></tr></table>' : '';
8891
}
8992

9093
/**

0 commit comments

Comments
 (0)