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

Commit 6783f11

Browse files
author
Matt Allan
authored
In our customer notification emails, only display the subscription that is about to renew or expire, don't show all subscriptions purchased in the parent order. (#722)
* New function subscription_details() to display subscription details, similar to order_details() * Replace add_sub_info_email() uses with new subscription_detail() function * Clean up subscription_details() * Remove unnecessary whitespace * Fix docblock * Add changelog entry
1 parent f311fe7 commit 6783f11

12 files changed

+38
-10
lines changed

changelog.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
*** WooCommerce Subscriptions Core Changelog ***
22

3+
= 7.7.1 - 2024-xx-xx =
4+
* Fix - Only show the individual subscription information in customer notification emails, not all subscriptions purchased in the initial order.
5+
36
= 7.7.0 - 2024-11-13 =
47
* Add - New Customer Notification feature: sends reminder emails for upcoming subscription renewals, trials ending, and subscription expirations.
58
* Fix - Prevent adding products to the cart if a subscription renewal is already present.

includes/class-wc-subscriptions-email.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,31 @@ public static function order_details( $order, $sent_to_admin = false, $plain_tex
294294
);
295295
}
296296

297+
/**
298+
* Show the subscription details table.
299+
*
300+
* @param WC_Subscription[] $subscriptions List of subscriptions. Also accepts a single subscription.
301+
* @param WC_Order|null $order The order related to the subscription - defaults to parent order.
302+
* @param bool $sent_to_admin Whether the email is sent to admin - defaults to false.
303+
* @param bool $plain_text Whether the email should use plain text templates - defaults to false.
304+
* @param bool $skip_my_account_link Whether to skip displaying the My Account link - defaults to false.
305+
*/
306+
public static function subscription_details( $subscriptions, $order = null, $sent_to_admin = false, $plain_text = false, $skip_my_account_link = false ) {
307+
$template = ( $plain_text ) ? 'emails/plain/subscription-info.php' : 'emails/subscription-info.php';
308+
309+
wc_get_template(
310+
$template,
311+
array(
312+
'order' => ! $order ? $subscription->get_parent() : $order,
313+
'subscriptions' => is_array( $subscriptions ) ? $subscriptions : [ $subscriptions ],
314+
'is_admin_email' => $sent_to_admin,
315+
'skip_my_account_link' => $skip_my_account_link,
316+
),
317+
'',
318+
WC_Subscriptions_Core_Plugin::instance()->get_subscriptions_core_directory( 'templates/' )
319+
);
320+
}
321+
297322
/**
298323
* Detach WC transactional emails from a specific hook.
299324
*

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
<?php
5757

5858
// Show subscription details.
59-
\WC_Subscriptions_Order::add_sub_info_email( $order, $sent_to_admin, $plain_text, true );
59+
\WC_Subscriptions_Email::subscription_details( $subscription, $order, $sent_to_admin, $plain_text, true );
6060
?>
6161
<p>
6262
<small>

templates/emails/customer-notification-auto-trial-ending.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
<?php
7070

7171
// Show subscription details.
72-
\WC_Subscriptions_Order::add_sub_info_email( $order, $sent_to_admin, $plain_text, true );
72+
\WC_Subscriptions_Email::subscription_details( $subscription, $order, $sent_to_admin, $plain_text, true );
7373

7474
/**
7575
* Show user-defined additional content - this is set in each email's settings.

templates/emails/customer-notification-expiring-subscription.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
<?php
5757

5858
// Show subscription details.
59-
\WC_Subscriptions_Order::add_sub_info_email( $order, $sent_to_admin, $plain_text, true );
59+
\WC_Subscriptions_Email::subscription_details( $subscription, $order, $sent_to_admin, $plain_text, true );
6060

6161
/**
6262
* Show user-defined additional content - this is set in each email's settings.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@
9797
<?php
9898

9999
// Show subscription details.
100-
\WC_Subscriptions_Order::add_sub_info_email( $order, $sent_to_admin, $plain_text );
100+
\WC_Subscriptions_Email::subscription_details( $subscription, $order, $sent_to_admin, $plain_text );
101101

102102
/**
103103
* Show user-defined additional content - this is set in each email's settings.

templates/emails/customer-notification-manual-trial-ending.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
<?php
5252

5353
// Show subscription details.
54-
\WC_Subscriptions_Order::add_sub_info_email( $order, $sent_to_admin, $plain_text );
54+
\WC_Subscriptions_Email::subscription_details( $subscription, $order, $sent_to_admin, $plain_text );
5555

5656
/**
5757
* Show user-defined additional content - this is set in each email's settings.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
esc_html_e( 'Here are the details:', 'woocommerce-subscriptions' );
4141
echo "\n";
4242
// Show subscription details.
43-
\WC_Subscriptions_Order::add_sub_info_email( $order, $sent_to_admin, $plain_text, true );
43+
\WC_Subscriptions_Email::subscription_details( $subscription, $order, $sent_to_admin, $plain_text, true );
4444

4545
esc_html_e( 'You can manage this subscription from your account dashboard: ', 'woocommerce-subscriptions' );
4646
echo esc_url( wc_get_page_permalink( 'myaccount' ) );

templates/emails/plain/customer-notification-auto-trial-ending.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
esc_html_e( 'Here are the details:', 'woocommerce-subscriptions' );
4747

4848
// Show subscription details.
49-
\WC_Subscriptions_Order::add_sub_info_email( $order, $sent_to_admin, $plain_text, true );
49+
\WC_Subscriptions_Email::subscription_details( $subscription, $order, $sent_to_admin, $plain_text, true );
5050

5151
echo "\n\n=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n";
5252

templates/emails/plain/customer-notification-expiring-subscription.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
esc_html_e( 'Here are the details:', 'woocommerce-subscriptions' );
4141

4242
// Show subscription details.
43-
\WC_Subscriptions_Order::add_sub_info_email( $order, $sent_to_admin, $plain_text, true );
43+
\WC_Subscriptions_Email::subscription_details( $subscription, $order, $sent_to_admin, $plain_text, true );
4444

4545
/**
4646
* Show user-defined additional content - this is set in each email's settings.

0 commit comments

Comments
 (0)