@@ -254,20 +254,36 @@ private function add_placeholders( $email ) {
254
254
return ;
255
255
}
256
256
257
- $ placeholders = [
258
- '{time_until_renewal} ' => human_time_diff ( time (), time () + WEEK_IN_SECONDS ),
259
- '{customers_first_name} ' => 'John ' ,
260
- ];
257
+ $ placeholders = [];
261
258
262
- // Pull the real values from the email object (Order or Subscription) if available.
263
- if ( is_a ( $ email ->object , 'WC_Subscription ' ) ) {
264
- $ placeholders ['{time_until_renewal} ' ] = human_time_diff ( time (), $ email ->object ->get_time ( 'next_payment ' ) );
265
- }
259
+ switch ( $ this ->email_type ) {
260
+ case 'WCS_Email_Customer_Notification_Manual_Trial_Expiration ' :
261
+ case 'WCS_Email_Customer_Notification_Auto_Trial_Expiration ' :
262
+ case 'WCS_Email_Customer_Notification_Manual_Renewal ' :
263
+ case 'WCS_Email_Customer_Notification_Auto_Renewal ' :
264
+ case 'WCS_Email_Customer_Notification_Subscription_Expiration ' :
265
+ if ( is_a ( $ email ->object , 'WC_Subscription ' ) ) {
266
+ $ time_until_renewal = $ email ->get_time_until_date ( $ email ->object , 'next_payment ' );
267
+ $ customer_first_name = $ email ->object ->get_billing_first_name ();
268
+ } else {
269
+ $ time_until_renewal = human_time_diff ( time (), time () + WEEK_IN_SECONDS );
270
+ $ customer_first_name = 'John ' ;
271
+ }
272
+
273
+ $ placeholders ['{time_until_renewal} ' ] = $ time_until_renewal ;
274
+ $ placeholders ['{customers_first_name} ' ] = $ customer_first_name ;
275
+ break ;
276
+ case 'WCS_Email_Customer_Payment_Retry ' :
277
+ case 'WCS_Email_Payment_Retry ' :
278
+ $ retry_time = is_a ( $ email ->retry , 'WCS_Retry ' )
279
+ ? $ email ->retry ->get_time ()
280
+ : time () + ( 12 * HOUR_IN_SECONDS );
266
281
267
- if ( is_a ( $ email -> object , ' WC_Abstract_Order ' ) ) {
268
- $ placeholders [ ' {customers_first_name} ' ] = $ email -> object -> get_billing_first_name () ;
282
+ $ placeholders [ ' {retry_time} ' ] = wcs_get_human_time_diff ( $ retry_time );
283
+ break ;
269
284
}
270
285
286
+ // Merge placeholders without overriding existing ones, and only adding those in the email.
271
287
$ email ->placeholders = wp_parse_args (
272
288
$ placeholders ,
273
289
$ email ->placeholders
0 commit comments