PageRenderTime 51ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/www/wp-content/plugins/ithemes-exchange/lib/email-notifications/class.email-notifications.php

https://github.com/ArzuA/gitwordpress
PHP | 621 lines | 327 code | 83 blank | 211 comment | 48 complexity | 8db6922f310f9b8f8b1e63c19f31bb99 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1
  1. <?php
  2. /**
  3. * Contains the class or the email notifications object
  4. * @since 0.4.0
  5. * @package IT_Exchange
  6. */
  7. /**
  8. * The IT_Exchange_Email_Notifications class is for sending out email notification using wp_mail()
  9. *
  10. * @since 0.4.0
  11. */
  12. class IT_Exchange_Email_Notifications {
  13. public $transaction_id;
  14. public $customer_id;
  15. public $user;
  16. /**
  17. * Constructor. Sets up the class
  18. *
  19. * @since 0.4.0
  20. */
  21. function IT_Exchange_Email_Notifications() {
  22. add_action( 'it_exchange_send_email_notification', array( $this, 'it_exchange_send_email_notification' ), 20, 3 );
  23. // Send emails on successfull transaction
  24. add_action( 'it_exchange_add_transaction_success', array( $this, 'send_purchase_emails' ), 20 );
  25. // Send emails when admin requests a resend
  26. add_action( 'admin_init', array( $this, 'handle_resend_confirmation_email_requests' ) );
  27. // Resends email notifications when status is changed from one that's not cleared for delivery to one that is cleared
  28. add_action( 'it_exchange_update_transaction_status', array( $this, 'resend_if_transaction_status_gets_cleared_for_delivery' ), 10, 3 );
  29. add_shortcode( 'it_exchange_email', array( $this, 'ithemes_exchange_email_notification_shortcode' ) );
  30. }
  31. function it_exchange_send_email_notification( $customer_id, $subject, $content ) {
  32. $this->transaction_id = apply_filters( 'it_exchange_send_email_notification_transaction_id', false );
  33. $this->customer_id = $customer_id;
  34. $this->user = it_exchange_get_customer( $customer_id );
  35. $settings = it_exchange_get_option( 'settings_email' );
  36. // Edge case where sale is made before admin visits email settings.
  37. if ( empty( $settings['receipt-email-name'] ) && ! isset( $IT_Exchange_Admin ) ) {
  38. global $IT_Exchange;
  39. include_once( dirname( dirname( __FILE__ ) ) . '/admin/class.admin.php' );
  40. add_filter( 'it_storage_get_defaults_exchange_settings_email', array( 'IT_Exchange_Admin', 'set_email_settings_defaults' ) );
  41. $settings = it_exchange_get_option( 'settings_email', true );
  42. }
  43. $headers[] = 'From: ' . $settings['receipt-email-name'] . ' <' . $settings['receipt-email-address'] . '>';
  44. $headers[] = 'MIME-Version: 1.0';
  45. $headers[] = 'Content-Type: text/html';
  46. $headers[] = 'charset=utf-8';
  47. $subject = do_shortcode( $subject );
  48. $body = apply_filters( 'it_exchange_send_email_notification_body', $content );
  49. $body = $this->body_header() . '<div>' . wpautop( do_shortcode( $body ) ) . '</div>' . $this->body_footer();
  50. $headers = apply_filters( 'it_exchange_send_email_notification_headers', $headers );
  51. wp_mail( $this->user->data->user_email, strip_tags( $subject ), $body, $headers );
  52. }
  53. /**
  54. * Listens for the resend email request and passes along to send_purchase_emails
  55. *
  56. * @since 0.4.0
  57. *
  58. * @return void
  59. */
  60. function handle_resend_confirmation_email_requests() {
  61. // Abort if not requested
  62. if ( empty( $_GET[ 'it-exchange-customer-transaction-action' ] ) || $_GET[ 'it-exchange-customer-transaction-action' ] != 'resend' )
  63. return;
  64. // Abort if no transaction or invalid transaction was passed
  65. $transaction = it_exchange_get_transaction( $_GET['id'] );
  66. if ( empty( $transaction->ID ) ) {
  67. it_exchange_add_message( 'error', __( 'Invalid transaction. Confirmation email not sent.', 'it-l10n-ithemes-exchange' ) );
  68. $url = remove_query_arg( array( 'it-exchange-customer-transaction-action', '_wpnonce' ) );
  69. it_exchange_redirect( $url, 'admin-confirmation-email-resend-failed' );
  70. die();
  71. }
  72. // Abort if nonce is bad
  73. $nonce = empty( $_GET['_wpnonce'] ) ? false : $_GET['_wpnonce'];
  74. if ( ! $nonce || ! wp_verify_nonce( $nonce, 'it-exchange-resend-confirmation-' . $transaction->ID ) ) {
  75. it_exchange_add_message( 'error', __( 'Confirmation Email not sent. Please try again.', 'it-l10n-ithemes-exchange' ) );
  76. $url = remove_query_arg( array( 'it-exchange-customer-transaction-action', '_wpnonce' ) );
  77. it_exchange_redirect( $url, 'admin-confirmation-email-resend-failed' );
  78. die();
  79. }
  80. // Abort if user doesn't have permission
  81. if ( ! current_user_can( 'administrator' ) ) {
  82. it_exchange_add_message( 'error', __( 'You do not have permission to resend confirmation emails.', 'it-l10n-ithemes-exchange' ) );
  83. $url = remove_query_arg( array( 'it-exchange-customer-transaction-action', '_wpnonce' ) );
  84. it_exchange_redirect( $url, 'admin-confirmation-email-resend-failed' );
  85. die();
  86. }
  87. // Resend w/o admin notification
  88. $this->send_purchase_emails( $transaction, false );
  89. it_exchange_add_message( 'notice', __( 'Confirmation email resent', 'it-l10n-ithemes-exchange' ) );
  90. $url = remove_query_arg( array( 'it-exchange-customer-transaction-action', '_wpnonce' ) );
  91. it_exchange_redirect( $url, 'admin-confirmation-email-resend-success' );
  92. die();
  93. }
  94. /**
  95. * Process the transaction and send appropriate emails
  96. *
  97. * @since 0.4.0
  98. *
  99. * @param mixed $transaction ID or object
  100. * @param int $customer_id The customer ID
  101. * @return void
  102. */
  103. function send_purchase_emails( $transaction, $send_admin_email=true ) {
  104. $transaction = it_exchange_get_transaction( $transaction );
  105. if ( empty( $transaction->ID ) )
  106. return;
  107. $this->transaction_id = $transaction->ID;
  108. $this->customer_id = it_exchange_get_transaction_customer_id( $this->transaction_id );
  109. $this->user = it_exchange_get_customer( $this->customer_id );
  110. $settings = it_exchange_get_option( 'settings_email' );
  111. // Edge case where sale is made before admin visits email settings.
  112. if ( empty( $settings['receipt-email-name'] ) && ! isset( $IT_Exchange_Admin ) ) {
  113. global $IT_Exchange;
  114. include_once( dirname( dirname( __FILE__ ) ) . '/admin/class.admin.php' );
  115. add_filter( 'it_storage_get_defaults_exchange_settings_email', array( 'IT_Exchange_Admin', 'set_email_settings_defaults' ) );
  116. $settings = it_exchange_get_option( 'settings_email', true );
  117. }
  118. // Sets Temporary GLOBAL information
  119. $GLOBALS['it_exchange']['email-confirmation-data'] = array( $transaction, $this );
  120. $headers[] = 'From: ' . $settings['receipt-email-name'] . ' <' . $settings['receipt-email-address'] . '>';
  121. $headers[] = 'MIME-Version: 1.0';
  122. $headers[] = 'Content-Type: text/html';
  123. $headers[] = 'charset=utf-8';
  124. $subject = do_shortcode( $settings['receipt-email-subject'] );
  125. $body = apply_filters( 'send_purchase_emails_body', $settings['receipt-email-template'], $transaction );
  126. $body = apply_filters( 'send_purchase_emails_body_' . it_exchange_get_transaction_method( $transaction->ID ), $body, $transaction );
  127. $body = $this->body_header() . '<div>' . wpautop( do_shortcode( $body ) ) . '</div>' . $this->body_footer();
  128. // Filters
  129. $to = empty( $this->user->data->user_email ) ? false : $this->user->data->user_email;
  130. $to = apply_filters( 'it_exchange_send_purchase_emails_to', $to, $transaction, $settings, $this );
  131. $subject = apply_filters( 'it_exchange_send_purchase_emails_subject', $subject, $transaction, $settings, $this );
  132. $body = apply_filters( 'it_exchange_send_purchase_emails_body', $body, $transaction, $settings, $this );
  133. $headers = apply_filters( 'it_exchange_send_purchase_emails_headers', $headers, $transaction, $settings, $this );
  134. $attachments = apply_filters( 'it_exchange_send_purchase_emails_attachments', array(), $transaction, $settings, $this );
  135. wp_mail( $to, strip_tags( $subject ), $body, $headers, $attachments );
  136. // Send admin notification if param is true and email is provided in settings
  137. if ( $send_admin_email && ! empty( $settings['notification-email-address'] ) ) {
  138. $subject = do_shortcode( $settings['admin-email-subject'] );
  139. $body = apply_filters( 'send_admin_emails_body', $settings['admin-email-template'], $transaction );
  140. $body = apply_filters( 'send_admin_emails_body_' . it_exchange_get_transaction_method( $transaction->ID ), $body, $transaction );
  141. $body = $this->body_header() . wpautop( do_shortcode( $body ) ) . $this->body_footer();
  142. $emails = explode( ',', $settings['notification-email-address'] );
  143. foreach ( $emails as $email ) {
  144. wp_mail( trim( $email ), strip_tags( $subject ), $body, $headers );
  145. }
  146. }
  147. // Clear temp data
  148. if ( isset( $GLOBALS['it_exchange']['email-confirmation-data'] ) )
  149. unset( $GLOBALS['it_exchange']['email-confirmation-data'] );
  150. }
  151. /**
  152. * Returns Email HTML header
  153. *
  154. * @since 0.4.0
  155. *
  156. * @return string HTML header
  157. */
  158. function body_header() {
  159. $data = empty( $GLOBALS['it_exchange']['email-confirmation-data'] ) ? false : $GLOBALS['it_exchange']['email-confirmation-data'];
  160. ob_start();
  161. ?>
  162. <html>
  163. <head>
  164. <meta http-equiv="Content-type" content="text/html; charset=utf-8">
  165. </head>
  166. <body>
  167. <?php
  168. $output = ob_get_clean();
  169. return apply_filters( 'it_exchange_email_notification_body_header', $output, $data );
  170. }
  171. /**
  172. * Returns Email HTML footer
  173. *
  174. * @since 0.4.0
  175. *
  176. * @return string HTML footer
  177. */
  178. function body_footer() {
  179. $data = empty( $GLOBALS['it_exchange']['email-confirmation-data'] ) ? false : $GLOBALS['it_exchange']['email-confirmation-data'];
  180. ob_start();
  181. ?>
  182. </body>
  183. </html>
  184. <?php
  185. $output = ob_get_clean();
  186. return apply_filters( 'it_exchange_email_notification_body_footer', $output, $data );
  187. }
  188. /**
  189. * Get available template tags
  190. * Array of tags (key) and callback functions (value)
  191. *
  192. * @since 0.4.0
  193. *
  194. * @return array available replacement template tags
  195. */
  196. function get_shortcode_functions() {
  197. $data = empty( $GLOBALS['it_exchange']['email-confirmation-data'] ) ? false : $GLOBALS['it_exchange']['email-confirmation-data'];
  198. //Key = replacement tag
  199. //Value = callback function
  200. $shortcode_functions = array(
  201. 'download_list' => 'it_exchange_replace_download_list_tag',
  202. 'name' => 'it_exchange_replace_name_tag',
  203. 'fullname' => 'it_exchange_replace_fullname_tag',
  204. 'username' => 'it_exchange_replace_username_tag',
  205. 'order_table' => 'it_exchange_replace_order_table_tag',
  206. 'purchase_date' => 'it_exchange_replace_purchase_date_tag',
  207. 'total' => 'it_exchange_replace_total_tag',
  208. 'payment_id' => 'it_exchange_replace_payment_id_tag',
  209. 'receipt_id' => 'it_exchange_replace_receipt_id_tag',
  210. 'payment_method' => 'it_exchange_replace_payment_method_tag',
  211. 'sitename' => 'it_exchange_replace_sitename_tag',
  212. 'receipt_link' => 'it_exchange_replace_receipt_link_tag',
  213. 'login_link' => 'it_exchange_replace_login_link_tag',
  214. 'account_link' => 'it_exchange_replace_account_link_tag',
  215. );
  216. return apply_filters( 'it_exchange_email_notification_shortcode_functions', $shortcode_functions, $data );
  217. }
  218. /**
  219. * This shortcode is intended to print an email arguments for email templates
  220. *
  221. * @since 0.4.0
  222. * @param array $atts attributess passed from WP Shortcode API
  223. * @param string $content data passed from WP Shortcode API
  224. * @return string html for the 'Add to Shopping Cart' HTML
  225. */
  226. function ithemes_exchange_email_notification_shortcode( $atts, $content='' ) {
  227. $data = empty( $GLOBALS['it_exchange']['email-confirmation-data'] ) ? false : $GLOBALS['it_exchange']['email-confirmation-data'];
  228. $supported_pairs = array(
  229. 'show' => '',
  230. 'options' => '',
  231. );
  232. // Merge supported_pairs with passed attributes
  233. extract( shortcode_atts( $supported_pairs, $atts ) );
  234. $shortcode_functions = $this->get_shortcode_functions();
  235. $return = false;
  236. if ( !empty( $shortcode_functions[$show] ) ) {
  237. if ( is_callable( array( $this, $shortcode_functions[$show] ) ) )
  238. $return = call_user_func( array( $this, $shortcode_functions[$show] ), $this, explode( ',', $options ) );
  239. else if ( is_callable( $shortcode_functions[$show] ) )
  240. $return = call_user_func( $shortcode_functions[$show], $this, explode( ',', $options ) );
  241. }
  242. return apply_filters( 'it_exchange_email_notification_shortcode_' . $atts['show'], $return, $atts, $content, $data );
  243. }
  244. /**
  245. * Replacement Tag
  246. *
  247. * @since 0.4.0
  248. *
  249. * @param object $args of IT_Exchange_Email_Notifications
  250. * @return string Replaced value
  251. */
  252. function it_exchange_replace_download_list_tag( $args, $options = NULL ) {
  253. $status_notice = '';
  254. ob_start();
  255. // Grab products attached to transaction
  256. $transaction_products = it_exchange_get_transaction_products( $args->transaction_id );
  257. // Grab all hashes attached to transaction
  258. $hashes = it_exchange_get_transaction_download_hash_index( $args->transaction_id );
  259. if ( !empty( $hashes ) ) {
  260. ?>
  261. <div style="border-top: 1px solid #EEE">
  262. <?php foreach ( $transaction_products as $transaction_product ) : ?>
  263. <?php
  264. $product_id = $transaction_product['product_id'];
  265. $db_product = it_exchange_get_product( $transaction_product );
  266. ?>
  267. <?php if ( $product_downloads = it_exchange_get_product_feature( $transaction_product['product_id'], 'downloads' ) ) : $downloads_exist_for_transaction = true; ?>
  268. <?php if ( ! it_exchange_transaction_is_cleared_for_delivery( $args->transaction_id ) ) : ?>
  269. <?php
  270. /* Status notice is blank by default and printed here, in the email if downloads are available.
  271. * If downloads are not available for this transaction (tested in loop below), this echo of the status notice won't be printed.
  272. * But we know that downloads will be available if the status changes so we set print the message instead of the files.
  273. * If no files exist for the transaction, then there is no need to print this message even if status is pending
  274. * Clear as mud.
  275. */
  276. $status_notice = '<p>' . __( 'The status for this transaction does not grant access to downloadable files. Once the transaction is updated to an approved status, you will receive a follow-up email with your download links.', 'it-l10n-ithemes-exchange' ) . '</p>';
  277. $status_notice = '<h3>' . __( 'Available Downloads', 'it-l10n-ithemes-exchange' ) . '</h3>' . $status_notice;
  278. ?>
  279. <?php else : ?>
  280. <h4><?php esc_attr_e( it_exchange_get_transaction_product_feature( $transaction_product, 'title' ) ); ?></h4>
  281. <?php $count = it_exchange_get_transaction_product_feature( $transaction_product, 'count' ); ?>
  282. <?php if ( $count > 1 && apply_filters( 'it_exchange_print_downlods_page_link_in_email', true, $this->transaction_id ) ) : ?>
  283. <?php $downloads_url = it_exchange_get_page_url( 'downloads' ); ?>
  284. <p><?php printf( __( 'You have purchased %d unique download link(s) for each file available with this product.%s%sEach link has its own download limits and you can view the details on your %sdownloads%s page.', 'it-l10n-ithemes-exchange' ), $count, '<br />', '<br />', '<a href="' . $downloads_url . '">', '</a>' ); ?></p>
  285. <?php endif; ?>
  286. <?php foreach( $product_downloads as $download_id => $download_data ) : ?>
  287. <?php $hashes_for_product_transaction = it_exchange_get_download_hashes_for_transaction_product( $args->transaction_id, $transaction_product, $download_id ); ?>
  288. <?php $hashes_found = ( ! empty( $hashes_found ) || ! empty( $hashes_for_product_transaction ) ); // If someone purchases a product prior to downloads existing, they dont' get hashes/downloads ?>
  289. <h5><?php esc_attr_e( get_the_title( $download_id ) ); ?></h5>
  290. <ul class="download-hashes">
  291. <?php foreach( (array) $hashes_for_product_transaction as $hash ) : ?>
  292. <?php
  293. $hash_data = it_exchange_get_download_data_from_hash( $hash );
  294. $download_limit = ( 'unlimited' == $hash_data['download_limit'] ) ? __( 'Unlimited', 'it-l10n-ithemes-exchange' ) : $hash_data['download_limit'];
  295. $downloads = empty( $hash_data['downloads'] ) ? (int) 0 : absint( $hash_data['downloads'] );
  296. ?>
  297. <li>
  298. <a href="<?php echo site_url() . '?it-exchange-download=' . $hash; ?>"><?php _e( 'Download link', 'it-l10n-ithemes-exchange' ); ?></a> <span style="font-family: Monaco, monospace;font-size:12px;color:#AAA;">(<?php esc_attr_e( $hash ); ?>)</span>
  299. </li>
  300. <?php endforeach; ?>
  301. </ul>
  302. <?php endforeach; ?>
  303. <?php endif; ?>
  304. <?php endif; ?>
  305. <?php endforeach; ?>
  306. </div>
  307. <?php
  308. }
  309. if ( empty( $downloads_exist_for_transaction ) || empty( $hashes_found ) ) {
  310. echo $status_notice;
  311. return ob_get_clean();
  312. } else {
  313. return ob_get_clean();
  314. }
  315. }
  316. /**
  317. * Replacement Tag
  318. *
  319. * @since 0.4.0
  320. *
  321. * @param object $args of IT_Exchange_Email_Notifications
  322. * @return string Replaced value
  323. */
  324. function it_exchange_replace_name_tag( $args, $options = NULL ) {
  325. $name = '';
  326. if ( !empty( $this->user->data->first_name ) ) {
  327. $name = $this->user->data->first_name;
  328. } else if ( ! empty( $this->user->data->display_name ) ) {
  329. $name = $this->user->data->display_name;
  330. } else if ( ! empty( $GLOBALS['it_exchange']['email-confirmation-data'][0]->customer_id ) && is_email( $GLOBALS['it_exchange']['email-confirmation-data'][0]->customer_id ) ) {
  331. // Guest Chekcout
  332. $name = $GLOBALS['it_exchange']['email-confirmation-data'][0]->customer_id;
  333. }
  334. return $name;
  335. }
  336. /**
  337. * Replacement Tag
  338. *
  339. * @since 0.4.0
  340. *
  341. * @param object $args of IT_Exchange_Email_Notifications
  342. * @return string Replaced value
  343. */
  344. function it_exchange_replace_fullname_tag( $args, $options = NULL ) {
  345. $fullname = '';
  346. if ( ! empty( $this->user->data->first_name ) && ! empty( $this->user->data->last_name ) ) {
  347. $fullname = $this->user->data->first_name . ' ' . $this->user->data->last_name;
  348. } else if ( ! empty( $this->user->data->display_name ) ) {
  349. $fullname = $this->user->data->display_name;
  350. }
  351. return $fullname;
  352. }
  353. /**
  354. * Replacement Tag
  355. *
  356. * @since 0.4.0
  357. *
  358. * @param object $args of IT_Exchange_Email_Notifications
  359. * @return string Replaced value
  360. */
  361. function it_exchange_replace_username_tag( $args, $options = NULL ) {
  362. return empty( $this->user->data->user_login ) ? '' : $this->user->data->user_login;
  363. }
  364. /**
  365. * Replacement Tag
  366. *
  367. * @since 0.4.0
  368. *
  369. * @param object $args of IT_Exchange_Email_Notifications
  370. * @return string Replaced value
  371. */
  372. function it_exchange_replace_order_table_tag( $args, $options = NULL ) {
  373. $purchase_messages_heading = '<h3>' . __( 'Important Information', 'it-l10n-ithemes-exchange' ). '</h3>';
  374. $purchase_messages = '';
  375. $purchase_message_on = false;
  376. if ( in_array( 'purchase_message', $options ) )
  377. $purchase_message_on = true;
  378. ob_start();
  379. ?>
  380. <table style="text-align: left; background: #FBFBFB; margin-bottom: 1.5em;border:1px solid #DDD;border-collapse: collapse;">
  381. <thead style="background:#F3F3F3;">
  382. <tr>
  383. <th style="padding: 10px;border:1px solid #DDD;"><?php _e( 'Product', 'it-l10n-ithemes-exchange' ); ?></th>
  384. <th style="padding: 10px;border:1px solid #DDD;"><?php _e( 'Quantity', 'it-l10n-ithemes-exchange' ); ?></th>
  385. <th style="padding: 10px;border:1px solid #DDD;"><?php _e( 'Total Price', 'it-l10n-ithemes-exchange' ); ?></th>
  386. </tr>
  387. </thead>
  388. <tbody>
  389. <?php if ( $products = it_exchange_get_transaction_products( $this->transaction_id ) ) : ?>
  390. <?php foreach ( $products as $product ) : ?>
  391. <tr>
  392. <td style="padding: 10px;border:1px solid #DDD;">
  393. <?php echo apply_filters( 'it_exchange_email_notification_order_table_product_name', it_exchange_get_transaction_product_feature( $product, 'product_name' ), $product ); ?>
  394. </td>
  395. <td style="padding: 10px;border:1px solid #DDD;"><?php echo apply_filters( 'it_exchange_email_notification_order_table_product_count', it_exchange_get_transaction_product_feature( $product, 'count' ), $product ); ?></td>
  396. <td style="padding: 10px;border:1px solid #DDD;"><?php echo apply_filters( 'it_exchange_email_notification_order_table_product_subtotal', it_exchange_format_price( it_exchange_get_transaction_product_feature( $product, 'product_subtotal' ), $product ) ); ?></td>
  397. </tr>
  398. <?php
  399. // Generate Purchase Messages
  400. if ( $purchase_message_on && it_exchange_product_has_feature( $product['product_id'], 'purchase-message' ) ) {
  401. $purchase_messages .= '<h4>' . esc_attr( it_exchange_get_transaction_product_feature( $product, 'product_name' ) ) . '</h4>';
  402. $purchase_messages .= '<p>' . it_exchange_get_product_feature( $product['product_id'], 'purchase-message' ) . '</p>';
  403. $purchase_messages = apply_filters( 'it_exchange_email_notification_order_table_purchase_message', $purchase_messages, $product );
  404. }
  405. ?>
  406. <?php endforeach; ?>
  407. <?php endif; ?>
  408. </tbody>
  409. <tfoot style="background:#F3F3F3;">
  410. <tr>
  411. <td colspan="2" style="padding: 10px;border:1px solid #DDD;"><?php _e( 'Total', 'it-l10n-ithemes-exchange' ); ?></td>
  412. <td style="padding: 10px;border:1px solid #DDD;"><?php echo it_exchange_get_transaction_total( $this->transaction_id, true ) ?></td>
  413. </tr>
  414. </tfoot>
  415. </table>
  416. <?php
  417. $table = ob_get_clean();
  418. $table .= empty( $purchase_messages ) ? '' : $purchase_messages_heading . $purchase_messages;
  419. return $table;
  420. }
  421. /**
  422. * Replacement Tag
  423. *
  424. * @since 0.4.0
  425. *
  426. * @param object $args of IT_Exchange_Email_Notifications
  427. * @return string Replaced value
  428. */
  429. function it_exchange_replace_purchase_date_tag( $args, $options = NULL ) {
  430. return it_exchange_get_transaction_date( $this->transaction_id );
  431. }
  432. /**
  433. * Replacement Tag
  434. *
  435. * @since 0.4.0
  436. *
  437. * @param object $args of IT_Exchange_Email_Notifications
  438. * @return string Replaced value
  439. */
  440. function it_exchange_replace_total_tag( $args, $options = NULL ) {
  441. return it_exchange_get_transaction_total( $this->transaction_id, true );
  442. }
  443. /**
  444. * Replacement Tag
  445. *
  446. * @since 0.4.0
  447. *
  448. * @param object $args of IT_Exchange_Email_Notifications
  449. * @return string Replaced value
  450. */
  451. function it_exchange_replace_payment_id_tag( $args, $options = NULL ) {
  452. return it_exchange_get_gateway_id_for_transaction( $this->transaction_id );
  453. }
  454. /**
  455. * Replacement Tag
  456. *
  457. * @since 0.4.0
  458. *
  459. * @param object $args of IT_Exchange_Email_Notifications
  460. * @return string Replaced value
  461. */
  462. function it_exchange_replace_receipt_id_tag( $args, $options = NULL ) {
  463. return it_exchange_get_transaction_order_number( $this->transaction_id );
  464. }
  465. /**
  466. * Replacement Tag
  467. *
  468. * @since 0.4.0
  469. *
  470. * @param object $args of IT_Exchange_Email_Notifications
  471. * @return string Replaced value
  472. */
  473. function it_exchange_replace_payment_method_tag( $args, $options = NULL ) {
  474. return it_exchange_get_transaction_method( $this->transaction_id );
  475. }
  476. /**
  477. * Replacement Tag
  478. *
  479. * @since 0.4.0
  480. *
  481. * @param object $args of IT_Exchange_Email_Notifications
  482. * @return string Replaced value
  483. */
  484. function it_exchange_replace_sitename_tag( $args, $options = NULL ) {
  485. return wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES );
  486. }
  487. /**
  488. * Replacement Tag
  489. *
  490. * @since 0.4.0
  491. *
  492. * @param object $args of IT_Exchange_Email_Notifications
  493. * @return string Replaced value
  494. */
  495. function it_exchange_replace_receipt_link_tag( $args, $options = NULL ) {
  496. return it_exchange_get_transaction_confirmation_url( $this->transaction_id );
  497. }
  498. /**
  499. * Replacement Tag
  500. *
  501. * @since 1.0.2
  502. *
  503. * @param object $args of IT_Exchange_Email_Notifications
  504. * @return string Replaced value
  505. */
  506. function it_exchange_replace_login_link_tag( $args, $options = NULL ) {
  507. return it_exchange_get_page_url( 'login' );
  508. }
  509. /**
  510. * Replacement Tag
  511. *
  512. * @since 1.4.0
  513. *
  514. * @param object $args of IT_Exchange_Email_Notifications
  515. * @return string Replaced value
  516. */
  517. function it_exchange_replace_account_link_tag( $args, $options = NULL ) {
  518. return it_exchange_get_page_url( 'account' );
  519. }
  520. /**
  521. * Resends the email to the customer if the transaction status was changed from not cleared for delivery to cleared.
  522. *
  523. * @since 0.4.11
  524. *
  525. * @param object $transaction the transaction object
  526. * @param string $old_status the status it was just changed from
  527. * @param boolean $old_status_cleared was the old status cleared for delivery?
  528. * @return void
  529. */
  530. function resend_if_transaction_status_gets_cleared_for_delivery( $transaction, $old_status, $old_status_cleared ) {
  531. // Using ->ID here so that get_transaction forces a reload and doesn't use the old object with the old status
  532. $new_status = it_exchange_get_transaction_status( $transaction->ID );
  533. $new_status_cleared = it_exchange_transaction_is_cleared_for_delivery( $transaction->ID );
  534. if ( ( $new_status != $old_status ) && ! $old_status_cleared && $new_status_cleared )
  535. $this->send_purchase_emails( $transaction, false );
  536. }
  537. }
  538. $IT_Exchange_Email_Notifications = new IT_Exchange_Email_Notifications();