/** * Parser for the [PAYMENT_DUE_DATE_*] attribute type shortcode * * @since 4.8.28.rc.011 * * @param string $shortcode The shortcode being parsed. * @param EE_Transaction $transaction * @return string */ protected function _get_payment_due_date($shortcode, EE_Transaction $transaction) { //if transaction is paid in full then we can just return an empty string if ($transaction->remaining() === 0) { return ''; } $attrs = $this->_get_shortcode_attrs($shortcode); $format = isset($attrs['format']) ? $attrs['format'] : get_option('date_format'); $days_until_due = isset($attrs['days_until_due']) ? (int) $attrs['days_until_due'] : 30; $prefix_text = isset($attrs['prefix_text']) ? $attrs['prefix_text'] : __('Payment in full due by: ', 'event_espresso'); $transaction_created = $transaction->get_DateTime_object('TXN_timestamp'); //setup date due: try { if ($transaction_created instanceof DateTime) { $date_due = $transaction_created->add(new DateInterval('P' . $days_until_due . 'D'))->format($format); } else { throw new Exception(); } } catch (Exception $e) { //format was likely invalid. $date_due = 'Unable to calculate date due, likely the format string is invalid.'; } return $prefix_text . $date_due; }