@@ -12,487 +12,487 @@ |
||
| 12 | 12 | */ |
| 13 | 13 | class GetPaid_Invoice_Notification_Emails { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * The array of invoice email actions. |
|
| 17 | - * |
|
| 18 | - * @param array |
|
| 19 | - */ |
|
| 20 | - public $invoice_actions; |
|
| 21 | - |
|
| 22 | - /** |
|
| 23 | - * Class constructor |
|
| 24 | - * |
|
| 25 | - */ |
|
| 26 | - public function __construct() { |
|
| 27 | - |
|
| 28 | - $this->invoice_actions = apply_filters( |
|
| 29 | - 'getpaid_notification_email_invoice_triggers', |
|
| 30 | - array( |
|
| 31 | - 'getpaid_new_invoice' => array( 'new_invoice', 'user_invoice' ), |
|
| 32 | - 'getpaid_invoice_status_wpi-cancelled' => 'cancelled_invoice', |
|
| 33 | - 'getpaid_invoice_status_wpi-failed' => 'failed_invoice', |
|
| 34 | - 'getpaid_invoice_status_wpi-onhold' => 'onhold_invoice', |
|
| 35 | - 'getpaid_invoice_status_wpi-processing' => 'processing_invoice', |
|
| 36 | - 'getpaid_invoice_status_publish' => 'completed_invoice', |
|
| 37 | - 'getpaid_invoice_status_wpi-renewal' => 'completed_invoice', |
|
| 38 | - 'getpaid_invoice_status_wpi-refunded' => 'refunded_invoice', |
|
| 39 | - 'getpaid_new_customer_note' => 'user_note', |
|
| 40 | - 'getpaid_daily_maintenance' => 'overdue', |
|
| 41 | - ) |
|
| 42 | - ); |
|
| 43 | - |
|
| 44 | - $this->init_hooks(); |
|
| 45 | - |
|
| 46 | - } |
|
| 47 | - |
|
| 48 | - /** |
|
| 49 | - * Registers email hooks. |
|
| 50 | - */ |
|
| 51 | - public function init_hooks() { |
|
| 52 | - |
|
| 53 | - add_filter( 'getpaid_get_email_merge_tags', array( $this, 'invoice_merge_tags' ), 10, 2 ); |
|
| 54 | - add_filter( 'getpaid_invoice_email_recipients', array( $this, 'filter_email_recipients' ), 10, 2 ); |
|
| 55 | - |
|
| 56 | - foreach ( $this->invoice_actions as $hook => $email_type ) { |
|
| 57 | - $this->init_email_type_hook( $hook, $email_type ); |
|
| 58 | - } |
|
| 59 | - } |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * Registers an email hook for an invoice action. |
|
| 63 | - * |
|
| 64 | - * @param string $hook |
|
| 65 | - * @param string|array $email_type |
|
| 66 | - */ |
|
| 67 | - public function init_email_type_hook( $hook, $email_type ) { |
|
| 68 | - |
|
| 69 | - $email_type = wpinv_parse_list( $email_type ); |
|
| 70 | - |
|
| 71 | - foreach ( $email_type as $type ) { |
|
| 72 | - |
|
| 73 | - $email = new GetPaid_Notification_Email( $type ); |
|
| 74 | - |
|
| 75 | - // Abort if it is not active. |
|
| 76 | - if ( ! $email->is_active() ) { |
|
| 77 | - continue; |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - if ( method_exists( $this, $type ) ) { |
|
| 81 | - add_action( $hook, array( $this, $type ), 100, 2 ); |
|
| 82 | - continue; |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - do_action( 'getpaid_invoice_init_email_type_hook', $type, $hook ); |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - /** |
|
| 91 | - * Filters invoice merge tags. |
|
| 92 | - * |
|
| 93 | - * @param array $merge_tags |
|
| 94 | - * @param mixed|WPInv_Invoice|WPInv_Subscription $object |
|
| 95 | - */ |
|
| 96 | - public function invoice_merge_tags( $merge_tags, $object ) { |
|
| 97 | - |
|
| 98 | - if ( is_a( $object, 'WPInv_Invoice' ) ) { |
|
| 99 | - return array_merge( |
|
| 100 | - $merge_tags, |
|
| 101 | - $this->get_invoice_merge_tags( $object ) |
|
| 102 | - ); |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - if ( is_a( $object, 'WPInv_Subscription' ) ) { |
|
| 106 | - return array_merge( |
|
| 107 | - $merge_tags, |
|
| 108 | - $this->get_invoice_merge_tags( $object->get_parent_payment() ) |
|
| 109 | - ); |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - return $merge_tags; |
|
| 113 | - |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - /** |
|
| 117 | - * Generates invoice merge tags. |
|
| 118 | - * |
|
| 119 | - * @param WPInv_Invoice $invoice |
|
| 120 | - * @return array |
|
| 121 | - */ |
|
| 122 | - public function get_invoice_merge_tags( $invoice ) { |
|
| 123 | - |
|
| 124 | - // Abort if it does not exist. |
|
| 125 | - if ( ! $invoice->get_id() ) { |
|
| 126 | - return array(); |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - $merge_tags = array( |
|
| 130 | - '{name}' => sanitize_text_field( $invoice->get_user_full_name() ), |
|
| 131 | - '{full_name}' => sanitize_text_field( $invoice->get_user_full_name() ), |
|
| 132 | - '{first_name}' => sanitize_text_field( $invoice->get_first_name() ), |
|
| 133 | - '{last_name}' => sanitize_text_field( $invoice->get_last_name() ), |
|
| 134 | - '{email}' => sanitize_email( $invoice->get_email() ), |
|
| 135 | - '{invoice_number}' => sanitize_text_field( $invoice->get_number() ), |
|
| 136 | - '{invoice_currency}' => sanitize_text_field( $invoice->get_currency() ), |
|
| 137 | - '{invoice_total}' => sanitize_text_field( wpinv_price( $invoice->get_total(), $invoice->get_currency() ) ), |
|
| 138 | - '{invoice_link}' => esc_url( $invoice->get_view_url() ), |
|
| 139 | - '{invoice_pay_link}' => esc_url( $invoice->get_checkout_payment_url() ), |
|
| 140 | - '{invoice_receipt_link}' => esc_url( $invoice->get_receipt_url() ), |
|
| 141 | - '{invoice_date}' => getpaid_format_date_value( $invoice->get_date_created() ), |
|
| 142 | - '{invoice_due_date}' => getpaid_format_date_value( $invoice->get_due_date(), __( 'on receipt', 'invoicing' ) ), |
|
| 143 | - '{invoice_quote}' => sanitize_text_field( strtolower( $invoice->get_label() ) ), |
|
| 144 | - '{invoice_label}' => sanitize_text_field( ucfirst( $invoice->get_label() ) ), |
|
| 145 | - '{invoice_description}' => wp_kses_post( $invoice->get_description() ), |
|
| 146 | - '{subscription_name}' => wp_kses_post( $invoice->get_subscription_name() ), |
|
| 147 | - '{is_was}' => strtotime( $invoice->get_due_date() ) < current_time( 'timestamp' ) ? __( 'was', 'invoicing' ) : __( 'is', 'invoicing' ), |
|
| 148 | - ); |
|
| 149 | - |
|
| 150 | - $payment_form_data = $invoice->get_meta( 'payment_form_data', true ); |
|
| 151 | - |
|
| 152 | - if ( is_array( $payment_form_data ) ) { |
|
| 153 | - |
|
| 154 | - foreach ( $payment_form_data as $label => $value ) { |
|
| 155 | - |
|
| 156 | - $label = preg_replace( '/[^a-z0-9]+/', '_', strtolower( $label ) ); |
|
| 157 | - $value = is_array( $value ) ? implode( ', ', $value ) : $value; |
|
| 158 | - |
|
| 159 | - if ( is_scalar( $value ) ) { |
|
| 160 | - $merge_tags[ "{{$label}}" ] = wp_kses_post( $value ); |
|
| 161 | - } |
|
| 162 | - } |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - return apply_filters( 'getpaid_invoice_email_merge_tags', $merge_tags, $invoice ); |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - /** |
|
| 169 | - * Helper function to send an email. |
|
| 170 | - * |
|
| 171 | - * @param WPInv_Invoice $invoice |
|
| 172 | - * @param GetPaid_Notification_Email $email |
|
| 173 | - * @param string $type |
|
| 174 | - * @param string|array $recipients |
|
| 175 | - * @param array $extra_args Extra template args. |
|
| 176 | - */ |
|
| 177 | - public function send_email( $invoice, $email, $type, $recipients, $extra_args = array() ) { |
|
| 178 | - |
|
| 179 | - do_action( 'getpaid_before_send_invoice_notification', $type, $invoice, $email ); |
|
| 180 | - |
|
| 181 | - $skip = $invoice->is_free() && wpinv_get_option( 'skip_email_free_invoice' ); |
|
| 182 | - if ( apply_filters( 'getpaid_skip_invoice_email', $skip, $type, $invoice ) ) { |
|
| 183 | - return; |
|
| 184 | - } |
|
| 185 | - |
|
| 186 | - $mailer = new GetPaid_Notification_Email_Sender(); |
|
| 187 | - $merge_tags = $email->get_merge_tags(); |
|
| 188 | - |
|
| 189 | - $result = $mailer->send( |
|
| 190 | - apply_filters( 'getpaid_invoice_email_recipients', wpinv_parse_list( $recipients ), $email ), |
|
| 191 | - $email->add_merge_tags( $email->get_subject(), $merge_tags ), |
|
| 192 | - $email->get_content( $merge_tags, $extra_args ), |
|
| 193 | - $email->get_attachments() |
|
| 194 | - ); |
|
| 195 | - |
|
| 196 | - // Maybe send a copy to the admin. |
|
| 197 | - if ( $email->include_admin_bcc() ) { |
|
| 198 | - $mailer->send( |
|
| 199 | - wpinv_get_admin_email(), |
|
| 200 | - $email->add_merge_tags( $email->get_subject() . __( ' - ADMIN BCC COPY', 'invoicing' ), $merge_tags ), |
|
| 201 | - $email->get_content( $merge_tags ), |
|
| 202 | - $email->get_attachments() |
|
| 203 | - ); |
|
| 204 | - } |
|
| 205 | - |
|
| 206 | - if ( $result ) { |
|
| 207 | - $invoice->add_system_note( |
|
| 208 | - sprintf( |
|
| 209 | - __( 'Successfully sent %1$s notification email to %2$s.', 'invoicing' ), |
|
| 210 | - sanitize_key( $type ), |
|
| 211 | - $email->is_admin_email() ? __( 'admin' ) : __( 'the customer' ) |
|
| 212 | - ) |
|
| 213 | - ); |
|
| 214 | - } else { |
|
| 215 | - $invoice->add_system_note( |
|
| 216 | - sprintf( |
|
| 217 | - __( 'Failed sending %1$s notification email to %2$s.', 'invoicing' ), |
|
| 218 | - sanitize_key( $type ), |
|
| 219 | - $email->is_admin_email() ? __( 'admin' ) : __( 'the customer' ) |
|
| 220 | - ) |
|
| 221 | - ); |
|
| 222 | - } |
|
| 223 | - |
|
| 224 | - do_action( 'getpaid_after_send_invoice_notification', $type, $invoice, $email ); |
|
| 225 | - |
|
| 226 | - return $result; |
|
| 227 | - } |
|
| 228 | - |
|
| 229 | - /** |
|
| 230 | - * Also send emails to any cc users. |
|
| 231 | - * |
|
| 232 | - * @param array $recipients |
|
| 233 | - * @param GetPaid_Notification_Email $email |
|
| 234 | - */ |
|
| 235 | - public function filter_email_recipients( $recipients, $email ) { |
|
| 236 | - |
|
| 237 | - if ( ! $email->is_admin_email() ) { |
|
| 238 | - $cc = $email->object->get_email_cc(); |
|
| 239 | - $cc_2 = get_user_meta( $email->object->get_user_id(), '_wpinv_email_cc', true ); |
|
| 240 | - |
|
| 241 | - if ( ! empty( $cc ) ) { |
|
| 242 | - $cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) ); |
|
| 243 | - $recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) ); |
|
| 244 | - } |
|
| 245 | - |
|
| 246 | - if ( ! empty( $cc_2 ) ) { |
|
| 247 | - $cc_2 = array_map( 'sanitize_email', wpinv_parse_list( $cc_2 ) ); |
|
| 248 | - $recipients = array_filter( array_unique( array_merge( $recipients, $cc_2 ) ) ); |
|
| 249 | - } |
|
| 15 | + /** |
|
| 16 | + * The array of invoice email actions. |
|
| 17 | + * |
|
| 18 | + * @param array |
|
| 19 | + */ |
|
| 20 | + public $invoice_actions; |
|
| 21 | + |
|
| 22 | + /** |
|
| 23 | + * Class constructor |
|
| 24 | + * |
|
| 25 | + */ |
|
| 26 | + public function __construct() { |
|
| 27 | + |
|
| 28 | + $this->invoice_actions = apply_filters( |
|
| 29 | + 'getpaid_notification_email_invoice_triggers', |
|
| 30 | + array( |
|
| 31 | + 'getpaid_new_invoice' => array( 'new_invoice', 'user_invoice' ), |
|
| 32 | + 'getpaid_invoice_status_wpi-cancelled' => 'cancelled_invoice', |
|
| 33 | + 'getpaid_invoice_status_wpi-failed' => 'failed_invoice', |
|
| 34 | + 'getpaid_invoice_status_wpi-onhold' => 'onhold_invoice', |
|
| 35 | + 'getpaid_invoice_status_wpi-processing' => 'processing_invoice', |
|
| 36 | + 'getpaid_invoice_status_publish' => 'completed_invoice', |
|
| 37 | + 'getpaid_invoice_status_wpi-renewal' => 'completed_invoice', |
|
| 38 | + 'getpaid_invoice_status_wpi-refunded' => 'refunded_invoice', |
|
| 39 | + 'getpaid_new_customer_note' => 'user_note', |
|
| 40 | + 'getpaid_daily_maintenance' => 'overdue', |
|
| 41 | + ) |
|
| 42 | + ); |
|
| 43 | + |
|
| 44 | + $this->init_hooks(); |
|
| 45 | + |
|
| 46 | + } |
|
| 47 | + |
|
| 48 | + /** |
|
| 49 | + * Registers email hooks. |
|
| 50 | + */ |
|
| 51 | + public function init_hooks() { |
|
| 52 | + |
|
| 53 | + add_filter( 'getpaid_get_email_merge_tags', array( $this, 'invoice_merge_tags' ), 10, 2 ); |
|
| 54 | + add_filter( 'getpaid_invoice_email_recipients', array( $this, 'filter_email_recipients' ), 10, 2 ); |
|
| 55 | + |
|
| 56 | + foreach ( $this->invoice_actions as $hook => $email_type ) { |
|
| 57 | + $this->init_email_type_hook( $hook, $email_type ); |
|
| 58 | + } |
|
| 59 | + } |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * Registers an email hook for an invoice action. |
|
| 63 | + * |
|
| 64 | + * @param string $hook |
|
| 65 | + * @param string|array $email_type |
|
| 66 | + */ |
|
| 67 | + public function init_email_type_hook( $hook, $email_type ) { |
|
| 68 | + |
|
| 69 | + $email_type = wpinv_parse_list( $email_type ); |
|
| 70 | + |
|
| 71 | + foreach ( $email_type as $type ) { |
|
| 72 | + |
|
| 73 | + $email = new GetPaid_Notification_Email( $type ); |
|
| 74 | + |
|
| 75 | + // Abort if it is not active. |
|
| 76 | + if ( ! $email->is_active() ) { |
|
| 77 | + continue; |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + if ( method_exists( $this, $type ) ) { |
|
| 81 | + add_action( $hook, array( $this, $type ), 100, 2 ); |
|
| 82 | + continue; |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + do_action( 'getpaid_invoice_init_email_type_hook', $type, $hook ); |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + /** |
|
| 91 | + * Filters invoice merge tags. |
|
| 92 | + * |
|
| 93 | + * @param array $merge_tags |
|
| 94 | + * @param mixed|WPInv_Invoice|WPInv_Subscription $object |
|
| 95 | + */ |
|
| 96 | + public function invoice_merge_tags( $merge_tags, $object ) { |
|
| 97 | + |
|
| 98 | + if ( is_a( $object, 'WPInv_Invoice' ) ) { |
|
| 99 | + return array_merge( |
|
| 100 | + $merge_tags, |
|
| 101 | + $this->get_invoice_merge_tags( $object ) |
|
| 102 | + ); |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + if ( is_a( $object, 'WPInv_Subscription' ) ) { |
|
| 106 | + return array_merge( |
|
| 107 | + $merge_tags, |
|
| 108 | + $this->get_invoice_merge_tags( $object->get_parent_payment() ) |
|
| 109 | + ); |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + return $merge_tags; |
|
| 113 | + |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + /** |
|
| 117 | + * Generates invoice merge tags. |
|
| 118 | + * |
|
| 119 | + * @param WPInv_Invoice $invoice |
|
| 120 | + * @return array |
|
| 121 | + */ |
|
| 122 | + public function get_invoice_merge_tags( $invoice ) { |
|
| 123 | + |
|
| 124 | + // Abort if it does not exist. |
|
| 125 | + if ( ! $invoice->get_id() ) { |
|
| 126 | + return array(); |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + $merge_tags = array( |
|
| 130 | + '{name}' => sanitize_text_field( $invoice->get_user_full_name() ), |
|
| 131 | + '{full_name}' => sanitize_text_field( $invoice->get_user_full_name() ), |
|
| 132 | + '{first_name}' => sanitize_text_field( $invoice->get_first_name() ), |
|
| 133 | + '{last_name}' => sanitize_text_field( $invoice->get_last_name() ), |
|
| 134 | + '{email}' => sanitize_email( $invoice->get_email() ), |
|
| 135 | + '{invoice_number}' => sanitize_text_field( $invoice->get_number() ), |
|
| 136 | + '{invoice_currency}' => sanitize_text_field( $invoice->get_currency() ), |
|
| 137 | + '{invoice_total}' => sanitize_text_field( wpinv_price( $invoice->get_total(), $invoice->get_currency() ) ), |
|
| 138 | + '{invoice_link}' => esc_url( $invoice->get_view_url() ), |
|
| 139 | + '{invoice_pay_link}' => esc_url( $invoice->get_checkout_payment_url() ), |
|
| 140 | + '{invoice_receipt_link}' => esc_url( $invoice->get_receipt_url() ), |
|
| 141 | + '{invoice_date}' => getpaid_format_date_value( $invoice->get_date_created() ), |
|
| 142 | + '{invoice_due_date}' => getpaid_format_date_value( $invoice->get_due_date(), __( 'on receipt', 'invoicing' ) ), |
|
| 143 | + '{invoice_quote}' => sanitize_text_field( strtolower( $invoice->get_label() ) ), |
|
| 144 | + '{invoice_label}' => sanitize_text_field( ucfirst( $invoice->get_label() ) ), |
|
| 145 | + '{invoice_description}' => wp_kses_post( $invoice->get_description() ), |
|
| 146 | + '{subscription_name}' => wp_kses_post( $invoice->get_subscription_name() ), |
|
| 147 | + '{is_was}' => strtotime( $invoice->get_due_date() ) < current_time( 'timestamp' ) ? __( 'was', 'invoicing' ) : __( 'is', 'invoicing' ), |
|
| 148 | + ); |
|
| 149 | + |
|
| 150 | + $payment_form_data = $invoice->get_meta( 'payment_form_data', true ); |
|
| 151 | + |
|
| 152 | + if ( is_array( $payment_form_data ) ) { |
|
| 153 | + |
|
| 154 | + foreach ( $payment_form_data as $label => $value ) { |
|
| 155 | + |
|
| 156 | + $label = preg_replace( '/[^a-z0-9]+/', '_', strtolower( $label ) ); |
|
| 157 | + $value = is_array( $value ) ? implode( ', ', $value ) : $value; |
|
| 158 | + |
|
| 159 | + if ( is_scalar( $value ) ) { |
|
| 160 | + $merge_tags[ "{{$label}}" ] = wp_kses_post( $value ); |
|
| 161 | + } |
|
| 162 | + } |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + return apply_filters( 'getpaid_invoice_email_merge_tags', $merge_tags, $invoice ); |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + /** |
|
| 169 | + * Helper function to send an email. |
|
| 170 | + * |
|
| 171 | + * @param WPInv_Invoice $invoice |
|
| 172 | + * @param GetPaid_Notification_Email $email |
|
| 173 | + * @param string $type |
|
| 174 | + * @param string|array $recipients |
|
| 175 | + * @param array $extra_args Extra template args. |
|
| 176 | + */ |
|
| 177 | + public function send_email( $invoice, $email, $type, $recipients, $extra_args = array() ) { |
|
| 178 | + |
|
| 179 | + do_action( 'getpaid_before_send_invoice_notification', $type, $invoice, $email ); |
|
| 180 | + |
|
| 181 | + $skip = $invoice->is_free() && wpinv_get_option( 'skip_email_free_invoice' ); |
|
| 182 | + if ( apply_filters( 'getpaid_skip_invoice_email', $skip, $type, $invoice ) ) { |
|
| 183 | + return; |
|
| 184 | + } |
|
| 185 | + |
|
| 186 | + $mailer = new GetPaid_Notification_Email_Sender(); |
|
| 187 | + $merge_tags = $email->get_merge_tags(); |
|
| 188 | + |
|
| 189 | + $result = $mailer->send( |
|
| 190 | + apply_filters( 'getpaid_invoice_email_recipients', wpinv_parse_list( $recipients ), $email ), |
|
| 191 | + $email->add_merge_tags( $email->get_subject(), $merge_tags ), |
|
| 192 | + $email->get_content( $merge_tags, $extra_args ), |
|
| 193 | + $email->get_attachments() |
|
| 194 | + ); |
|
| 195 | + |
|
| 196 | + // Maybe send a copy to the admin. |
|
| 197 | + if ( $email->include_admin_bcc() ) { |
|
| 198 | + $mailer->send( |
|
| 199 | + wpinv_get_admin_email(), |
|
| 200 | + $email->add_merge_tags( $email->get_subject() . __( ' - ADMIN BCC COPY', 'invoicing' ), $merge_tags ), |
|
| 201 | + $email->get_content( $merge_tags ), |
|
| 202 | + $email->get_attachments() |
|
| 203 | + ); |
|
| 204 | + } |
|
| 205 | + |
|
| 206 | + if ( $result ) { |
|
| 207 | + $invoice->add_system_note( |
|
| 208 | + sprintf( |
|
| 209 | + __( 'Successfully sent %1$s notification email to %2$s.', 'invoicing' ), |
|
| 210 | + sanitize_key( $type ), |
|
| 211 | + $email->is_admin_email() ? __( 'admin' ) : __( 'the customer' ) |
|
| 212 | + ) |
|
| 213 | + ); |
|
| 214 | + } else { |
|
| 215 | + $invoice->add_system_note( |
|
| 216 | + sprintf( |
|
| 217 | + __( 'Failed sending %1$s notification email to %2$s.', 'invoicing' ), |
|
| 218 | + sanitize_key( $type ), |
|
| 219 | + $email->is_admin_email() ? __( 'admin' ) : __( 'the customer' ) |
|
| 220 | + ) |
|
| 221 | + ); |
|
| 222 | + } |
|
| 223 | + |
|
| 224 | + do_action( 'getpaid_after_send_invoice_notification', $type, $invoice, $email ); |
|
| 225 | + |
|
| 226 | + return $result; |
|
| 227 | + } |
|
| 228 | + |
|
| 229 | + /** |
|
| 230 | + * Also send emails to any cc users. |
|
| 231 | + * |
|
| 232 | + * @param array $recipients |
|
| 233 | + * @param GetPaid_Notification_Email $email |
|
| 234 | + */ |
|
| 235 | + public function filter_email_recipients( $recipients, $email ) { |
|
| 236 | + |
|
| 237 | + if ( ! $email->is_admin_email() ) { |
|
| 238 | + $cc = $email->object->get_email_cc(); |
|
| 239 | + $cc_2 = get_user_meta( $email->object->get_user_id(), '_wpinv_email_cc', true ); |
|
| 240 | + |
|
| 241 | + if ( ! empty( $cc ) ) { |
|
| 242 | + $cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) ); |
|
| 243 | + $recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) ); |
|
| 244 | + } |
|
| 245 | + |
|
| 246 | + if ( ! empty( $cc_2 ) ) { |
|
| 247 | + $cc_2 = array_map( 'sanitize_email', wpinv_parse_list( $cc_2 ) ); |
|
| 248 | + $recipients = array_filter( array_unique( array_merge( $recipients, $cc_2 ) ) ); |
|
| 249 | + } |
|
| 250 | 250 | } |
| 251 | 251 | |
| 252 | - return $recipients; |
|
| 252 | + return $recipients; |
|
| 253 | 253 | |
| 254 | - } |
|
| 254 | + } |
|
| 255 | 255 | |
| 256 | - /** |
|
| 257 | - * Sends a new invoice notification. |
|
| 258 | - * |
|
| 259 | - * @param WPInv_Invoice $invoice |
|
| 260 | - */ |
|
| 261 | - public function new_invoice( $invoice ) { |
|
| 256 | + /** |
|
| 257 | + * Sends a new invoice notification. |
|
| 258 | + * |
|
| 259 | + * @param WPInv_Invoice $invoice |
|
| 260 | + */ |
|
| 261 | + public function new_invoice( $invoice ) { |
|
| 262 | 262 | |
| 263 | - // Only send this email for invoices created via the admin page. |
|
| 264 | - if ( ! $invoice->is_type( 'invoice' ) || $invoice->is_paid() || $this->is_payment_form_invoice( $invoice->get_id() ) ) { |
|
| 265 | - return; |
|
| 266 | - } |
|
| 263 | + // Only send this email for invoices created via the admin page. |
|
| 264 | + if ( ! $invoice->is_type( 'invoice' ) || $invoice->is_paid() || $this->is_payment_form_invoice( $invoice->get_id() ) ) { |
|
| 265 | + return; |
|
| 266 | + } |
|
| 267 | 267 | |
| 268 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
| 269 | - $recipient = wpinv_get_admin_email(); |
|
| 268 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
| 269 | + $recipient = wpinv_get_admin_email(); |
|
| 270 | 270 | |
| 271 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
| 271 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
| 272 | 272 | |
| 273 | - } |
|
| 273 | + } |
|
| 274 | 274 | |
| 275 | - /** |
|
| 276 | - * Sends a cancelled invoice notification. |
|
| 277 | - * |
|
| 278 | - * @param WPInv_Invoice $invoice |
|
| 279 | - */ |
|
| 280 | - public function cancelled_invoice( $invoice ) { |
|
| 275 | + /** |
|
| 276 | + * Sends a cancelled invoice notification. |
|
| 277 | + * |
|
| 278 | + * @param WPInv_Invoice $invoice |
|
| 279 | + */ |
|
| 280 | + public function cancelled_invoice( $invoice ) { |
|
| 281 | 281 | |
| 282 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
| 283 | - $recipient = $invoice->get_email(); |
|
| 282 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
| 283 | + $recipient = $invoice->get_email(); |
|
| 284 | 284 | |
| 285 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
| 286 | - } |
|
| 285 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
| 286 | + } |
|
| 287 | 287 | |
| 288 | - /** |
|
| 289 | - * Sends a failed invoice notification. |
|
| 290 | - * |
|
| 291 | - * @param WPInv_Invoice $invoice |
|
| 292 | - */ |
|
| 293 | - public function failed_invoice( $invoice ) { |
|
| 288 | + /** |
|
| 289 | + * Sends a failed invoice notification. |
|
| 290 | + * |
|
| 291 | + * @param WPInv_Invoice $invoice |
|
| 292 | + */ |
|
| 293 | + public function failed_invoice( $invoice ) { |
|
| 294 | 294 | |
| 295 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
| 296 | - $recipient = wpinv_get_admin_email(); |
|
| 295 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
| 296 | + $recipient = wpinv_get_admin_email(); |
|
| 297 | 297 | |
| 298 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
| 298 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
| 299 | 299 | |
| 300 | - } |
|
| 300 | + } |
|
| 301 | 301 | |
| 302 | - /** |
|
| 303 | - * Sends a notification whenever an invoice is put on hold. |
|
| 304 | - * |
|
| 305 | - * @param WPInv_Invoice $invoice |
|
| 306 | - */ |
|
| 307 | - public function onhold_invoice( $invoice ) { |
|
| 302 | + /** |
|
| 303 | + * Sends a notification whenever an invoice is put on hold. |
|
| 304 | + * |
|
| 305 | + * @param WPInv_Invoice $invoice |
|
| 306 | + */ |
|
| 307 | + public function onhold_invoice( $invoice ) { |
|
| 308 | 308 | |
| 309 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
| 310 | - $recipient = $invoice->get_email(); |
|
| 309 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
| 310 | + $recipient = $invoice->get_email(); |
|
| 311 | 311 | |
| 312 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
| 312 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
| 313 | 313 | |
| 314 | - } |
|
| 314 | + } |
|
| 315 | 315 | |
| 316 | - /** |
|
| 317 | - * Sends a notification whenever an invoice is marked as processing payment. |
|
| 318 | - * |
|
| 319 | - * @param WPInv_Invoice $invoice |
|
| 320 | - */ |
|
| 321 | - public function processing_invoice( $invoice ) { |
|
| 316 | + /** |
|
| 317 | + * Sends a notification whenever an invoice is marked as processing payment. |
|
| 318 | + * |
|
| 319 | + * @param WPInv_Invoice $invoice |
|
| 320 | + */ |
|
| 321 | + public function processing_invoice( $invoice ) { |
|
| 322 | 322 | |
| 323 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
| 324 | - $recipient = $invoice->get_email(); |
|
| 323 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
| 324 | + $recipient = $invoice->get_email(); |
|
| 325 | 325 | |
| 326 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
| 326 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
| 327 | 327 | |
| 328 | - } |
|
| 328 | + } |
|
| 329 | 329 | |
| 330 | - /** |
|
| 331 | - * Sends a notification whenever an invoice is paid. |
|
| 332 | - * |
|
| 333 | - * @param WPInv_Invoice $invoice |
|
| 334 | - */ |
|
| 335 | - public function completed_invoice( $invoice ) { |
|
| 330 | + /** |
|
| 331 | + * Sends a notification whenever an invoice is paid. |
|
| 332 | + * |
|
| 333 | + * @param WPInv_Invoice $invoice |
|
| 334 | + */ |
|
| 335 | + public function completed_invoice( $invoice ) { |
|
| 336 | 336 | |
| 337 | - // (Maybe) abort if it is a renewal invoice. |
|
| 338 | - if ( $invoice->is_renewal() && ! wpinv_get_option( 'email_completed_invoice_renewal_active', false ) ) { |
|
| 339 | - return; |
|
| 340 | - } |
|
| 337 | + // (Maybe) abort if it is a renewal invoice. |
|
| 338 | + if ( $invoice->is_renewal() && ! wpinv_get_option( 'email_completed_invoice_renewal_active', false ) ) { |
|
| 339 | + return; |
|
| 340 | + } |
|
| 341 | 341 | |
| 342 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
| 343 | - $recipient = $invoice->get_email(); |
|
| 342 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
| 343 | + $recipient = $invoice->get_email(); |
|
| 344 | 344 | |
| 345 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
| 345 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
| 346 | 346 | |
| 347 | - } |
|
| 347 | + } |
|
| 348 | 348 | |
| 349 | - /** |
|
| 350 | - * Sends a notification whenever an invoice is refunded. |
|
| 351 | - * |
|
| 352 | - * @param WPInv_Invoice $invoice |
|
| 353 | - */ |
|
| 354 | - public function refunded_invoice( $invoice ) { |
|
| 349 | + /** |
|
| 350 | + * Sends a notification whenever an invoice is refunded. |
|
| 351 | + * |
|
| 352 | + * @param WPInv_Invoice $invoice |
|
| 353 | + */ |
|
| 354 | + public function refunded_invoice( $invoice ) { |
|
| 355 | 355 | |
| 356 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
| 357 | - $recipient = $invoice->get_email(); |
|
| 358 | - |
|
| 359 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
| 356 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
| 357 | + $recipient = $invoice->get_email(); |
|
| 358 | + |
|
| 359 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
| 360 | 360 | |
| 361 | - } |
|
| 361 | + } |
|
| 362 | 362 | |
| 363 | - /** |
|
| 364 | - * Notifies a user about new invoices |
|
| 365 | - * |
|
| 366 | - * @param WPInv_Invoice $invoice |
|
| 367 | - * @param bool $force |
|
| 368 | - */ |
|
| 369 | - public function user_invoice( $invoice, $force = false ) { |
|
| 363 | + /** |
|
| 364 | + * Notifies a user about new invoices |
|
| 365 | + * |
|
| 366 | + * @param WPInv_Invoice $invoice |
|
| 367 | + * @param bool $force |
|
| 368 | + */ |
|
| 369 | + public function user_invoice( $invoice, $force = false ) { |
|
| 370 | 370 | |
| 371 | - if ( ! $force && ! empty( $GLOBALS['wpinv_skip_invoice_notification'] ) ) { |
|
| 372 | - return; |
|
| 373 | - } |
|
| 374 | - |
|
| 375 | - // Only send this email for invoices created via the admin page. |
|
| 376 | - if ( ! $invoice->is_type( 'invoice' ) || ( empty( $force ) && $invoice->is_paid() ) || ( empty( $force ) && $this->is_payment_form_invoice( $invoice->get_id() ) ) ) { |
|
| 377 | - return; |
|
| 378 | - } |
|
| 371 | + if ( ! $force && ! empty( $GLOBALS['wpinv_skip_invoice_notification'] ) ) { |
|
| 372 | + return; |
|
| 373 | + } |
|
| 374 | + |
|
| 375 | + // Only send this email for invoices created via the admin page. |
|
| 376 | + if ( ! $invoice->is_type( 'invoice' ) || ( empty( $force ) && $invoice->is_paid() ) || ( empty( $force ) && $this->is_payment_form_invoice( $invoice->get_id() ) ) ) { |
|
| 377 | + return; |
|
| 378 | + } |
|
| 379 | 379 | |
| 380 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
| 381 | - $recipient = $invoice->get_email(); |
|
| 382 | - |
|
| 383 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
| 380 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
| 381 | + $recipient = $invoice->get_email(); |
|
| 382 | + |
|
| 383 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
| 384 | 384 | |
| 385 | - } |
|
| 386 | - |
|
| 387 | - /** |
|
| 388 | - * Checks if an invoice is a payment form invoice. |
|
| 389 | - * |
|
| 390 | - * @param int $invoice |
|
| 391 | - * @return bool |
|
| 392 | - */ |
|
| 393 | - public function is_payment_form_invoice( $invoice ) { |
|
| 394 | - $is_payment_form_invoice = empty( $_GET['getpaid-admin-action'] ) && ( 'payment_form' === get_post_meta( $invoice, 'wpinv_created_via', true ) || 'geodirectory' === get_post_meta( $invoice, 'wpinv_created_via', true ) ); |
|
| 395 | - return apply_filters( 'getpaid_invoice_notifications_is_payment_form_invoice', $is_payment_form_invoice, $invoice ); |
|
| 396 | - } |
|
| 385 | + } |
|
| 386 | + |
|
| 387 | + /** |
|
| 388 | + * Checks if an invoice is a payment form invoice. |
|
| 389 | + * |
|
| 390 | + * @param int $invoice |
|
| 391 | + * @return bool |
|
| 392 | + */ |
|
| 393 | + public function is_payment_form_invoice( $invoice ) { |
|
| 394 | + $is_payment_form_invoice = empty( $_GET['getpaid-admin-action'] ) && ( 'payment_form' === get_post_meta( $invoice, 'wpinv_created_via', true ) || 'geodirectory' === get_post_meta( $invoice, 'wpinv_created_via', true ) ); |
|
| 395 | + return apply_filters( 'getpaid_invoice_notifications_is_payment_form_invoice', $is_payment_form_invoice, $invoice ); |
|
| 396 | + } |
|
| 397 | 397 | |
| 398 | - /** |
|
| 399 | - * Notifies admin about new invoice notes |
|
| 400 | - * |
|
| 401 | - * @param WPInv_Invoice $invoice |
|
| 402 | - * @param string $note |
|
| 403 | - */ |
|
| 404 | - public function user_note( $invoice, $note ) { |
|
| 405 | - |
|
| 406 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
| 407 | - $recipient = $invoice->get_email(); |
|
| 398 | + /** |
|
| 399 | + * Notifies admin about new invoice notes |
|
| 400 | + * |
|
| 401 | + * @param WPInv_Invoice $invoice |
|
| 402 | + * @param string $note |
|
| 403 | + */ |
|
| 404 | + public function user_note( $invoice, $note ) { |
|
| 405 | + |
|
| 406 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
| 407 | + $recipient = $invoice->get_email(); |
|
| 408 | 408 | |
| 409 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient, array( 'customer_note' => $note ) ); |
|
| 410 | - |
|
| 411 | - } |
|
| 412 | - |
|
| 413 | - /** |
|
| 414 | - * (Force) Sends overdue notices. |
|
| 415 | - * |
|
| 416 | - * @param WPInv_Invoice $invoice |
|
| 417 | - */ |
|
| 418 | - public function force_send_overdue_notice( $invoice ) { |
|
| 419 | - $email = new GetPaid_Notification_Email( 'overdue', $invoice ); |
|
| 420 | - return $this->send_email( $invoice, $email, 'overdue', $invoice->get_email() ); |
|
| 421 | - } |
|
| 422 | - |
|
| 423 | - /** |
|
| 424 | - * Sends overdue notices. |
|
| 425 | - * |
|
| 426 | - * @TODO: Create an invoices query class. |
|
| 427 | - */ |
|
| 428 | - public function overdue() { |
|
| 429 | - global $wpdb; |
|
| 430 | - |
|
| 431 | - $email = new GetPaid_Notification_Email( __FUNCTION__ ); |
|
| 432 | - |
|
| 433 | - // Fetch reminder days. |
|
| 434 | - $reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) ); |
|
| 435 | - |
|
| 436 | - // Abort if non is set. |
|
| 437 | - if ( empty( $reminder_days ) ) { |
|
| 438 | - return; |
|
| 439 | - } |
|
| 440 | - |
|
| 441 | - // Retrieve date query. |
|
| 442 | - $date_query = $this->get_date_query( $reminder_days ); |
|
| 443 | - |
|
| 444 | - // Invoices table. |
|
| 445 | - $table = $wpdb->prefix . 'getpaid_invoices'; |
|
| 446 | - |
|
| 447 | - // Fetch invoices. |
|
| 448 | - $invoices = $wpdb->get_col( |
|
| 449 | - "SELECT posts.ID FROM $wpdb->posts as posts |
|
| 409 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient, array( 'customer_note' => $note ) ); |
|
| 410 | + |
|
| 411 | + } |
|
| 412 | + |
|
| 413 | + /** |
|
| 414 | + * (Force) Sends overdue notices. |
|
| 415 | + * |
|
| 416 | + * @param WPInv_Invoice $invoice |
|
| 417 | + */ |
|
| 418 | + public function force_send_overdue_notice( $invoice ) { |
|
| 419 | + $email = new GetPaid_Notification_Email( 'overdue', $invoice ); |
|
| 420 | + return $this->send_email( $invoice, $email, 'overdue', $invoice->get_email() ); |
|
| 421 | + } |
|
| 422 | + |
|
| 423 | + /** |
|
| 424 | + * Sends overdue notices. |
|
| 425 | + * |
|
| 426 | + * @TODO: Create an invoices query class. |
|
| 427 | + */ |
|
| 428 | + public function overdue() { |
|
| 429 | + global $wpdb; |
|
| 430 | + |
|
| 431 | + $email = new GetPaid_Notification_Email( __FUNCTION__ ); |
|
| 432 | + |
|
| 433 | + // Fetch reminder days. |
|
| 434 | + $reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) ); |
|
| 435 | + |
|
| 436 | + // Abort if non is set. |
|
| 437 | + if ( empty( $reminder_days ) ) { |
|
| 438 | + return; |
|
| 439 | + } |
|
| 440 | + |
|
| 441 | + // Retrieve date query. |
|
| 442 | + $date_query = $this->get_date_query( $reminder_days ); |
|
| 443 | + |
|
| 444 | + // Invoices table. |
|
| 445 | + $table = $wpdb->prefix . 'getpaid_invoices'; |
|
| 446 | + |
|
| 447 | + // Fetch invoices. |
|
| 448 | + $invoices = $wpdb->get_col( |
|
| 449 | + "SELECT posts.ID FROM $wpdb->posts as posts |
|
| 450 | 450 | LEFT JOIN $table as invoices ON invoices.post_id = posts.ID |
| 451 | 451 | WHERE posts.post_type = 'wpi_invoice' AND posts.post_status = 'wpi-pending' $date_query" |
| 452 | 452 | ); |
| 453 | 453 | |
| 454 | - foreach ( $invoices as $invoice ) { |
|
| 454 | + foreach ( $invoices as $invoice ) { |
|
| 455 | 455 | |
| 456 | - // Only send this email for invoices created via the admin page. |
|
| 457 | - if ( ! $this->is_payment_form_invoice( $invoice ) ) { |
|
| 458 | - $invoice = new WPInv_Invoice( $invoice ); |
|
| 459 | - $email->object = $invoice; |
|
| 456 | + // Only send this email for invoices created via the admin page. |
|
| 457 | + if ( ! $this->is_payment_form_invoice( $invoice ) ) { |
|
| 458 | + $invoice = new WPInv_Invoice( $invoice ); |
|
| 459 | + $email->object = $invoice; |
|
| 460 | 460 | |
| 461 | - if ( $invoice->needs_payment() ) { |
|
| 462 | - $this->send_email( $invoice, $email, __FUNCTION__, $invoice->get_email() ); |
|
| 463 | - } |
|
| 461 | + if ( $invoice->needs_payment() ) { |
|
| 462 | + $this->send_email( $invoice, $email, __FUNCTION__, $invoice->get_email() ); |
|
| 463 | + } |
|
| 464 | 464 | } |
| 465 | 465 | } |
| 466 | 466 | |
| 467 | - } |
|
| 467 | + } |
|
| 468 | 468 | |
| 469 | - /** |
|
| 470 | - * Calculates the date query for an invoices query |
|
| 471 | - * |
|
| 472 | - * @param array $reminder_days |
|
| 473 | - * @return string |
|
| 474 | - */ |
|
| 475 | - public function get_date_query( $reminder_days ) { |
|
| 469 | + /** |
|
| 470 | + * Calculates the date query for an invoices query |
|
| 471 | + * |
|
| 472 | + * @param array $reminder_days |
|
| 473 | + * @return string |
|
| 474 | + */ |
|
| 475 | + public function get_date_query( $reminder_days ) { |
|
| 476 | 476 | |
| 477 | - $date_query = array( |
|
| 478 | - 'relation' => 'OR', |
|
| 479 | - ); |
|
| 477 | + $date_query = array( |
|
| 478 | + 'relation' => 'OR', |
|
| 479 | + ); |
|
| 480 | 480 | |
| 481 | - foreach ( $reminder_days as $days ) { |
|
| 482 | - $date = date_parse( date( 'Y-m-d', strtotime( "-$days days", current_time( 'timestamp' ) ) ) ); |
|
| 481 | + foreach ( $reminder_days as $days ) { |
|
| 482 | + $date = date_parse( date( 'Y-m-d', strtotime( "-$days days", current_time( 'timestamp' ) ) ) ); |
|
| 483 | 483 | |
| 484 | - $date_query[] = array( |
|
| 485 | - 'year' => $date['year'], |
|
| 486 | - 'month' => $date['month'], |
|
| 487 | - 'day' => $date['day'], |
|
| 488 | - ); |
|
| 484 | + $date_query[] = array( |
|
| 485 | + 'year' => $date['year'], |
|
| 486 | + 'month' => $date['month'], |
|
| 487 | + 'day' => $date['day'], |
|
| 488 | + ); |
|
| 489 | 489 | |
| 490 | - } |
|
| 490 | + } |
|
| 491 | 491 | |
| 492 | - $date_query = new WP_Date_Query( $date_query, 'invoices.due_date' ); |
|
| 492 | + $date_query = new WP_Date_Query( $date_query, 'invoices.due_date' ); |
|
| 493 | 493 | |
| 494 | - return $date_query->get_sql(); |
|
| 494 | + return $date_query->get_sql(); |
|
| 495 | 495 | |
| 496 | - } |
|
| 496 | + } |
|
| 497 | 497 | |
| 498 | 498 | } |
@@ -39,40 +39,40 @@ |
||
| 39 | 39 | if ( 'tax' === $key ) { |
| 40 | 40 | wpinv_the_price( $invoice->get_total_tax(), $invoice->get_currency() ); |
| 41 | 41 | |
| 42 | - if ( wpinv_use_taxes() && ! $invoice->get_disable_taxes() ) { |
|
| 42 | + if ( wpinv_use_taxes() && ! $invoice->get_disable_taxes() ) { |
|
| 43 | 43 | |
| 44 | - $taxes = $invoice->get_total_tax(); |
|
| 45 | - if ( empty( $taxes ) && GetPaid_Payment_Form_Submission_Taxes::is_eu_transaction( $invoice->get_country() ) ) { |
|
| 46 | - echo ' <em class="text-muted small">'; |
|
| 47 | - _x( '(Reverse charged)', 'This is a legal term for reverse charging tax in the EU', 'invoicing' ); |
|
| 48 | - echo '</em>'; |
|
| 44 | + $taxes = $invoice->get_total_tax(); |
|
| 45 | + if ( empty( $taxes ) && GetPaid_Payment_Form_Submission_Taxes::is_eu_transaction( $invoice->get_country() ) ) { |
|
| 46 | + echo ' <em class="text-muted small">'; |
|
| 47 | + _x( '(Reverse charged)', 'This is a legal term for reverse charging tax in the EU', 'invoicing' ); |
|
| 48 | + echo '</em>'; |
|
| 49 | 49 | } |
| 50 | 50 | } |
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | // Total Fee. |
| 54 | 54 | if ( 'fee' === $key ) { |
| 55 | - wpinv_the_price( $invoice->get_total_fees(), $invoice->get_currency() ); |
|
| 55 | + wpinv_the_price( $invoice->get_total_fees(), $invoice->get_currency() ); |
|
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | // Total discount. |
| 59 | 59 | if ( 'discount' === $key ) { |
| 60 | - wpinv_the_price( $invoice->get_total_discount(), $invoice->get_currency() ); |
|
| 60 | + wpinv_the_price( $invoice->get_total_discount(), $invoice->get_currency() ); |
|
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | // Shipping. |
| 64 | 64 | if ( 'shipping' === $key ) { |
| 65 | - wpinv_the_price( $invoice->get_shipping(), $invoice->get_currency() ); |
|
| 65 | + wpinv_the_price( $invoice->get_shipping(), $invoice->get_currency() ); |
|
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | // Sub total. |
| 69 | 69 | if ( 'subtotal' === $key ) { |
| 70 | - wpinv_the_price( $invoice->get_subtotal(), $invoice->get_currency() ); |
|
| 70 | + wpinv_the_price( $invoice->get_subtotal(), $invoice->get_currency() ); |
|
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | // Total. |
| 74 | 74 | if ( 'total' === $key ) { |
| 75 | - wpinv_the_price( $invoice->get_total(), $invoice->get_currency() ); |
|
| 75 | + wpinv_the_price( $invoice->get_total(), $invoice->get_currency() ); |
|
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | // Fires when printing a cart total. |