0

We have a "start date" echoed out in a WooCoomerce email like so:

<?php echo esc_html( date_i18n( wc_date_format(), $subscription->get_time( 'start', 'site' ) ) ); ?>

The output looks like this: March 29, 2017

How would I go about adding 12 months to this date and echoing it out in the email as an "end date"?

Thanks

sc2015
  • 123
  • 13
  • What does this give you? `$subscription->get_time( 'start', 'site' )`? If you get a datetime object it has methods to modify the date – JimL Mar 30 '17 at 16:11
  • It gives me the date the customer placed the order through WooCommerce. E.G. March 29, 2017 – sc2015 Mar 30 '17 at 16:17

1 Answers1

0

The first line just sets up a variable for clarity's sake. The second line adds one year to the time and assigns it to $endDate. Simply add $endDate to your echo.

$startDate = $subscription->get_time( 'start', 'site' );
$endDate = date("F-d-Y", strtotime(date("F-d-Y", strtotime($startgDate)) . " + 1 year"));
Justin Burgard
  • 440
  • 1
  • 6
  • 17
  • Thanks. This is just echoed January-01-1970 which isn't right. When i echoed "$startDate" it resulted in 1490861344. – sc2015 Mar 31 '17 at 08:13
  • Hi, I just had to use `esc_html( date_i18n( wc_date_format(), $subscription->get_time( 'start', 'site' ) ) );` in the `$startDate` variable so it became `$startDate = esc_html( date_i18n( wc_date_format(), $subscription->get_time( 'start', 'site' ) ) );`. Thanks for your help :) – sc2015 Mar 31 '17 at 13:03
  • Glad you figured it out – Justin Burgard Mar 31 '17 at 15:46