@@ -14,30 +14,30 @@ discard block |
||
| 14 | 14 | class WPInv_Invoice extends GetPaid_Data { |
| 15 | 15 | |
| 16 | 16 | /** |
| 17 | - * Which data store to load. |
|
| 18 | - * |
|
| 19 | - * @var string |
|
| 20 | - */ |
|
| 17 | + * Which data store to load. |
|
| 18 | + * |
|
| 19 | + * @var string |
|
| 20 | + */ |
|
| 21 | 21 | protected $data_store_name = 'invoice'; |
| 22 | 22 | |
| 23 | 23 | /** |
| 24 | - * This is the name of this object type. |
|
| 25 | - * |
|
| 26 | - * @var string |
|
| 27 | - */ |
|
| 24 | + * This is the name of this object type. |
|
| 25 | + * |
|
| 26 | + * @var string |
|
| 27 | + */ |
|
| 28 | 28 | protected $object_type = 'invoice'; |
| 29 | 29 | |
| 30 | 30 | /** |
| 31 | - * Item Data array. This is the core item data exposed in APIs. |
|
| 32 | - * |
|
| 33 | - * @since 1.0.19 |
|
| 34 | - * @var array |
|
| 35 | - */ |
|
| 36 | - protected $data = array( |
|
| 37 | - 'parent_id' => 0, |
|
| 38 | - 'status' => 'wpi-pending', |
|
| 39 | - 'version' => '', |
|
| 40 | - 'date_created' => null, |
|
| 31 | + * Item Data array. This is the core item data exposed in APIs. |
|
| 32 | + * |
|
| 33 | + * @since 1.0.19 |
|
| 34 | + * @var array |
|
| 35 | + */ |
|
| 36 | + protected $data = array( |
|
| 37 | + 'parent_id' => 0, |
|
| 38 | + 'status' => 'wpi-pending', |
|
| 39 | + 'version' => '', |
|
| 40 | + 'date_created' => null, |
|
| 41 | 41 | 'date_modified' => null, |
| 42 | 42 | 'due_date' => null, |
| 43 | 43 | 'completed_date' => null, |
@@ -67,8 +67,8 @@ discard block |
||
| 67 | 67 | 'subtotal' => 0, |
| 68 | 68 | 'total_discount' => 0, |
| 69 | 69 | 'total_tax' => 0, |
| 70 | - 'total_fees' => 0, |
|
| 71 | - 'total' => 0, |
|
| 70 | + 'total_fees' => 0, |
|
| 71 | + 'total' => 0, |
|
| 72 | 72 | 'fees' => array(), |
| 73 | 73 | 'discounts' => array(), |
| 74 | 74 | 'taxes' => array(), |
@@ -80,22 +80,22 @@ discard block |
||
| 80 | 80 | 'transaction_id' => '', |
| 81 | 81 | 'currency' => '', |
| 82 | 82 | 'disable_taxes' => false, |
| 83 | - 'subscription_id' => null, |
|
| 84 | - 'remote_subscription_id' => null, |
|
| 85 | - 'is_viewed' => false, |
|
| 86 | - 'email_cc' => '', |
|
| 87 | - 'template' => 'quantity', // hours, amount only |
|
| 88 | - 'created_via' => null, |
|
| 83 | + 'subscription_id' => null, |
|
| 84 | + 'remote_subscription_id' => null, |
|
| 85 | + 'is_viewed' => false, |
|
| 86 | + 'email_cc' => '', |
|
| 87 | + 'template' => 'quantity', // hours, amount only |
|
| 88 | + 'created_via' => null, |
|
| 89 | 89 | ); |
| 90 | 90 | |
| 91 | 91 | /** |
| 92 | - * Stores meta in cache for future reads. |
|
| 93 | - * |
|
| 94 | - * A group must be set to to enable caching. |
|
| 95 | - * |
|
| 96 | - * @var string |
|
| 97 | - */ |
|
| 98 | - protected $cache_group = 'getpaid_invoices'; |
|
| 92 | + * Stores meta in cache for future reads. |
|
| 93 | + * |
|
| 94 | + * A group must be set to to enable caching. |
|
| 95 | + * |
|
| 96 | + * @var string |
|
| 97 | + */ |
|
| 98 | + protected $cache_group = 'getpaid_invoices'; |
|
| 99 | 99 | |
| 100 | 100 | /** |
| 101 | 101 | * Stores a reference to the original WP_Post object |
@@ -109,111 +109,111 @@ discard block |
||
| 109 | 109 | * |
| 110 | 110 | * @var int |
| 111 | 111 | */ |
| 112 | - protected $recurring_item = null; |
|
| 112 | + protected $recurring_item = null; |
|
| 113 | 113 | |
| 114 | - /** |
|
| 114 | + /** |
|
| 115 | 115 | * Stores an array of item totals. |
| 116 | - * |
|
| 117 | - * e.g $totals['discount'] = array( |
|
| 118 | - * 'initial' => 10, |
|
| 119 | - * 'recurring' => 10, |
|
| 120 | - * ) |
|
| 116 | + * |
|
| 117 | + * e.g $totals['discount'] = array( |
|
| 118 | + * 'initial' => 10, |
|
| 119 | + * 'recurring' => 10, |
|
| 120 | + * ) |
|
| 121 | 121 | * |
| 122 | 122 | * @var array |
| 123 | 123 | */ |
| 124 | - protected $totals = array(); |
|
| 124 | + protected $totals = array(); |
|
| 125 | 125 | |
| 126 | - /** |
|
| 126 | + /** |
|
| 127 | 127 | * Tax rate. |
| 128 | - * |
|
| 128 | + * |
|
| 129 | 129 | * @var float |
| 130 | 130 | */ |
| 131 | - protected $tax_rate = 0; |
|
| 131 | + protected $tax_rate = 0; |
|
| 132 | 132 | |
| 133 | - /** |
|
| 134 | - * Stores the status transition information. |
|
| 135 | - * |
|
| 136 | - * @since 1.0.19 |
|
| 137 | - * @var bool|array |
|
| 138 | - */ |
|
| 139 | - protected $status_transition = false; |
|
| 133 | + /** |
|
| 134 | + * Stores the status transition information. |
|
| 135 | + * |
|
| 136 | + * @since 1.0.19 |
|
| 137 | + * @var bool|array |
|
| 138 | + */ |
|
| 139 | + protected $status_transition = false; |
|
| 140 | 140 | |
| 141 | 141 | /** |
| 142 | - * Get the invoice if ID is passed, otherwise the invoice is new and empty. |
|
| 143 | - * |
|
| 144 | - * @param int|string|object|WPInv_Invoice|WPInv_Legacy_Invoice|WP_Post $invoice Invoice id, key, transaction id, number or object to read. |
|
| 145 | - */ |
|
| 142 | + * Get the invoice if ID is passed, otherwise the invoice is new and empty. |
|
| 143 | + * |
|
| 144 | + * @param int|string|object|WPInv_Invoice|WPInv_Legacy_Invoice|WP_Post $invoice Invoice id, key, transaction id, number or object to read. |
|
| 145 | + */ |
|
| 146 | 146 | public function __construct( $invoice = 0 ) { |
| 147 | 147 | |
| 148 | 148 | parent::__construct( $invoice ); |
| 149 | 149 | |
| 150 | - if ( ! empty( $invoice ) && is_numeric( $invoice ) && getpaid_is_invoice_post_type( get_post_type( (int) $invoice ) ) ) { |
|
| 151 | - $this->set_id( (int) $invoice ); |
|
| 152 | - } elseif ( $invoice instanceof self ) { |
|
| 153 | - $this->set_id( $invoice->get_id() ); |
|
| 154 | - } elseif ( ! empty( $invoice->ID ) ) { |
|
| 155 | - $this->set_id( $invoice->ID ); |
|
| 156 | - } elseif ( is_array( $invoice ) ) { |
|
| 157 | - $this->set_props( $invoice ); |
|
| 158 | - |
|
| 159 | - if ( isset( $invoice['ID'] ) ) { |
|
| 160 | - $this->set_id( $invoice['ID'] ); |
|
| 161 | - } |
|
| 162 | - |
|
| 163 | - } elseif ( is_string( $invoice ) && $invoice_id = self::get_invoice_id_by_field( $invoice, 'key' ) ) { |
|
| 164 | - $this->set_id( $invoice_id ); |
|
| 165 | - } elseif ( is_string( $invoice ) && $invoice_id = self::get_invoice_id_by_field( $invoice, 'number' ) ) { |
|
| 166 | - $this->set_id( $invoice_id ); |
|
| 167 | - } elseif ( is_string( $invoice ) && $invoice_id = self::get_invoice_id_by_field( $invoice, 'transaction_id' ) ) { |
|
| 168 | - $this->set_id( $invoice_id ); |
|
| 169 | - } else { |
|
| 170 | - $this->set_object_read( true ); |
|
| 171 | - } |
|
| 150 | + if ( ! empty( $invoice ) && is_numeric( $invoice ) && getpaid_is_invoice_post_type( get_post_type( (int) $invoice ) ) ) { |
|
| 151 | + $this->set_id( (int) $invoice ); |
|
| 152 | + } elseif ( $invoice instanceof self ) { |
|
| 153 | + $this->set_id( $invoice->get_id() ); |
|
| 154 | + } elseif ( ! empty( $invoice->ID ) ) { |
|
| 155 | + $this->set_id( $invoice->ID ); |
|
| 156 | + } elseif ( is_array( $invoice ) ) { |
|
| 157 | + $this->set_props( $invoice ); |
|
| 158 | + |
|
| 159 | + if ( isset( $invoice['ID'] ) ) { |
|
| 160 | + $this->set_id( $invoice['ID'] ); |
|
| 161 | + } |
|
| 162 | + |
|
| 163 | + } elseif ( is_string( $invoice ) && $invoice_id = self::get_invoice_id_by_field( $invoice, 'key' ) ) { |
|
| 164 | + $this->set_id( $invoice_id ); |
|
| 165 | + } elseif ( is_string( $invoice ) && $invoice_id = self::get_invoice_id_by_field( $invoice, 'number' ) ) { |
|
| 166 | + $this->set_id( $invoice_id ); |
|
| 167 | + } elseif ( is_string( $invoice ) && $invoice_id = self::get_invoice_id_by_field( $invoice, 'transaction_id' ) ) { |
|
| 168 | + $this->set_id( $invoice_id ); |
|
| 169 | + } else { |
|
| 170 | + $this->set_object_read( true ); |
|
| 171 | + } |
|
| 172 | 172 | |
| 173 | 173 | // Load the datastore. |
| 174 | - $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
| 174 | + $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
| 175 | 175 | |
| 176 | - if ( $this->get_id() > 0 ) { |
|
| 176 | + if ( $this->get_id() > 0 ) { |
|
| 177 | 177 | $this->post = get_post( $this->get_id() ); |
| 178 | 178 | $this->ID = $this->get_id(); |
| 179 | - $this->data_store->read( $this ); |
|
| 179 | + $this->data_store->read( $this ); |
|
| 180 | 180 | } |
| 181 | 181 | |
| 182 | 182 | } |
| 183 | 183 | |
| 184 | 184 | /** |
| 185 | - * Given an invoice key/number, it returns its id. |
|
| 186 | - * |
|
| 187 | - * |
|
| 188 | - * @static |
|
| 189 | - * @param string $value The invoice key or number |
|
| 190 | - * @param string $field Either key, transaction_id or number. |
|
| 191 | - * @since 1.0.15 |
|
| 192 | - * @return int |
|
| 193 | - */ |
|
| 194 | - public static function get_invoice_id_by_field( $value, $field = 'key' ) { |
|
| 185 | + * Given an invoice key/number, it returns its id. |
|
| 186 | + * |
|
| 187 | + * |
|
| 188 | + * @static |
|
| 189 | + * @param string $value The invoice key or number |
|
| 190 | + * @param string $field Either key, transaction_id or number. |
|
| 191 | + * @since 1.0.15 |
|
| 192 | + * @return int |
|
| 193 | + */ |
|
| 194 | + public static function get_invoice_id_by_field( $value, $field = 'key' ) { |
|
| 195 | 195 | global $wpdb; |
| 196 | 196 | |
| 197 | - // Trim the value. |
|
| 198 | - $value = trim( $value ); |
|
| 197 | + // Trim the value. |
|
| 198 | + $value = trim( $value ); |
|
| 199 | 199 | |
| 200 | - if ( empty( $value ) ) { |
|
| 201 | - return 0; |
|
| 202 | - } |
|
| 200 | + if ( empty( $value ) ) { |
|
| 201 | + return 0; |
|
| 202 | + } |
|
| 203 | 203 | |
| 204 | 204 | // Valid fields. |
| 205 | 205 | $fields = array( 'key', 'number', 'transaction_id' ); |
| 206 | 206 | |
| 207 | - // Ensure a field has been passed. |
|
| 208 | - if ( empty( $field ) || ! in_array( $field, $fields ) ) { |
|
| 209 | - return 0; |
|
| 210 | - } |
|
| 207 | + // Ensure a field has been passed. |
|
| 208 | + if ( empty( $field ) || ! in_array( $field, $fields ) ) { |
|
| 209 | + return 0; |
|
| 210 | + } |
|
| 211 | 211 | |
| 212 | - // Maybe retrieve from the cache. |
|
| 213 | - $invoice_id = wp_cache_get( $value, "getpaid_invoice_{$field}s_to_invoice_ids" ); |
|
| 214 | - if ( false !== $invoice_id ) { |
|
| 215 | - return $invoice_id; |
|
| 216 | - } |
|
| 212 | + // Maybe retrieve from the cache. |
|
| 213 | + $invoice_id = wp_cache_get( $value, "getpaid_invoice_{$field}s_to_invoice_ids" ); |
|
| 214 | + if ( false !== $invoice_id ) { |
|
| 215 | + return $invoice_id; |
|
| 216 | + } |
|
| 217 | 217 | |
| 218 | 218 | // Fetch from the db. |
| 219 | 219 | $table = $wpdb->prefix . 'getpaid_invoices'; |
@@ -221,10 +221,10 @@ discard block |
||
| 221 | 221 | $wpdb->prepare( "SELECT `post_id` FROM $table WHERE `$field`=%s LIMIT 1", $value ) |
| 222 | 222 | ); |
| 223 | 223 | |
| 224 | - // Update the cache with our data |
|
| 225 | - wp_cache_set( $value, $invoice_id, "getpaid_invoice_{$field}s_to_invoice_ids" ); |
|
| 224 | + // Update the cache with our data |
|
| 225 | + wp_cache_set( $value, $invoice_id, "getpaid_invoice_{$field}s_to_invoice_ids" ); |
|
| 226 | 226 | |
| 227 | - return $invoice_id; |
|
| 227 | + return $invoice_id; |
|
| 228 | 228 | } |
| 229 | 229 | |
| 230 | 230 | /** |
@@ -250,83 +250,83 @@ discard block |
||
| 250 | 250 | */ |
| 251 | 251 | |
| 252 | 252 | /** |
| 253 | - * Get parent invoice ID. |
|
| 254 | - * |
|
| 255 | - * @since 1.0.19 |
|
| 256 | - * @param string $context View or edit context. |
|
| 257 | - * @return int |
|
| 258 | - */ |
|
| 259 | - public function get_parent_id( $context = 'view' ) { |
|
| 260 | - return (int) $this->get_prop( 'parent_id', $context ); |
|
| 253 | + * Get parent invoice ID. |
|
| 254 | + * |
|
| 255 | + * @since 1.0.19 |
|
| 256 | + * @param string $context View or edit context. |
|
| 257 | + * @return int |
|
| 258 | + */ |
|
| 259 | + public function get_parent_id( $context = 'view' ) { |
|
| 260 | + return (int) $this->get_prop( 'parent_id', $context ); |
|
| 261 | 261 | } |
| 262 | 262 | |
| 263 | 263 | /** |
| 264 | - * Get parent invoice. |
|
| 265 | - * |
|
| 266 | - * @since 1.0.19 |
|
| 267 | - * @return WPInv_Invoice |
|
| 268 | - */ |
|
| 264 | + * Get parent invoice. |
|
| 265 | + * |
|
| 266 | + * @since 1.0.19 |
|
| 267 | + * @return WPInv_Invoice |
|
| 268 | + */ |
|
| 269 | 269 | public function get_parent_payment() { |
| 270 | 270 | return new WPInv_Invoice( $this->get_parent_id() ); |
| 271 | 271 | } |
| 272 | 272 | |
| 273 | 273 | /** |
| 274 | - * Alias for self::get_parent_payment(). |
|
| 275 | - * |
|
| 276 | - * @since 1.0.19 |
|
| 277 | - * @return WPInv_Invoice |
|
| 278 | - */ |
|
| 274 | + * Alias for self::get_parent_payment(). |
|
| 275 | + * |
|
| 276 | + * @since 1.0.19 |
|
| 277 | + * @return WPInv_Invoice |
|
| 278 | + */ |
|
| 279 | 279 | public function get_parent() { |
| 280 | 280 | return $this->get_parent_payment(); |
| 281 | 281 | } |
| 282 | 282 | |
| 283 | 283 | /** |
| 284 | - * Get invoice status. |
|
| 285 | - * |
|
| 286 | - * @since 1.0.19 |
|
| 287 | - * @param string $context View or edit context. |
|
| 288 | - * @return string |
|
| 289 | - */ |
|
| 290 | - public function get_status( $context = 'view' ) { |
|
| 291 | - return $this->get_prop( 'status', $context ); |
|
| 292 | - } |
|
| 284 | + * Get invoice status. |
|
| 285 | + * |
|
| 286 | + * @since 1.0.19 |
|
| 287 | + * @param string $context View or edit context. |
|
| 288 | + * @return string |
|
| 289 | + */ |
|
| 290 | + public function get_status( $context = 'view' ) { |
|
| 291 | + return $this->get_prop( 'status', $context ); |
|
| 292 | + } |
|
| 293 | 293 | |
| 294 | - /** |
|
| 295 | - * Retrieves an array of possible invoice statuses. |
|
| 296 | - * |
|
| 297 | - * @since 1.0.19 |
|
| 298 | - * @return array |
|
| 299 | - */ |
|
| 300 | - public function get_all_statuses() { |
|
| 301 | - return wpinv_get_invoice_statuses( true, true, $this ); |
|
| 302 | - } |
|
| 303 | - |
|
| 304 | - /** |
|
| 305 | - * Get invoice status nice name. |
|
| 306 | - * |
|
| 307 | - * @since 1.0.19 |
|
| 308 | - * @return string |
|
| 309 | - */ |
|
| 294 | + /** |
|
| 295 | + * Retrieves an array of possible invoice statuses. |
|
| 296 | + * |
|
| 297 | + * @since 1.0.19 |
|
| 298 | + * @return array |
|
| 299 | + */ |
|
| 300 | + public function get_all_statuses() { |
|
| 301 | + return wpinv_get_invoice_statuses( true, true, $this ); |
|
| 302 | + } |
|
| 303 | + |
|
| 304 | + /** |
|
| 305 | + * Get invoice status nice name. |
|
| 306 | + * |
|
| 307 | + * @since 1.0.19 |
|
| 308 | + * @return string |
|
| 309 | + */ |
|
| 310 | 310 | public function get_status_nicename() { |
| 311 | - $statuses = $this->get_all_statuses(); |
|
| 311 | + $statuses = $this->get_all_statuses(); |
|
| 312 | 312 | |
| 313 | 313 | $status = isset( $statuses[ $this->get_status() ] ) ? $statuses[ $this->get_status() ] : $this->get_status(); |
| 314 | 314 | |
| 315 | 315 | return apply_filters( 'wpinv_get_invoice_status_nicename', $status, $this ); |
| 316 | 316 | } |
| 317 | 317 | |
| 318 | - /** |
|
| 319 | - * Retrieves the invoice status class |
|
| 320 | - * |
|
| 321 | - * @since 1.0.19 |
|
| 322 | - * @return string |
|
| 323 | - */ |
|
| 324 | - public function get_status_class() { |
|
| 325 | - $statuses = getpaid_get_invoice_status_classes(); |
|
| 326 | - return isset( $statuses[ $this->get_status() ] ) ? $statuses[ $this->get_status() ] : 'badge-dark'; |
|
| 327 | - } |
|
| 318 | + /** |
|
| 319 | + * Retrieves the invoice status class |
|
| 320 | + * |
|
| 321 | + * @since 1.0.19 |
|
| 322 | + * @return string |
|
| 323 | + */ |
|
| 324 | + public function get_status_class() { |
|
| 325 | + $statuses = getpaid_get_invoice_status_classes(); |
|
| 326 | + return isset( $statuses[ $this->get_status() ] ) ? $statuses[ $this->get_status() ] : 'badge-dark'; |
|
| 327 | + } |
|
| 328 | 328 | |
| 329 | - /** |
|
| 329 | + /** |
|
| 330 | 330 | * Retrieves the invoice status label html |
| 331 | 331 | * |
| 332 | 332 | * @since 1.0.0 |
@@ -334,263 +334,263 @@ discard block |
||
| 334 | 334 | */ |
| 335 | 335 | public function get_status_label_html() { |
| 336 | 336 | |
| 337 | - $status_label = sanitize_text_field( $this->get_status_nicename() ); |
|
| 338 | - $status = sanitize_html_class( $this->get_status() ); |
|
| 339 | - $class = esc_attr( $this->get_status_class() ); |
|
| 337 | + $status_label = sanitize_text_field( $this->get_status_nicename() ); |
|
| 338 | + $status = sanitize_html_class( $this->get_status() ); |
|
| 339 | + $class = esc_attr( $this->get_status_class() ); |
|
| 340 | 340 | |
| 341 | - return "<span class='bsui'><span class='badge $class $status'>$status_label</span></span>"; |
|
| 342 | - } |
|
| 341 | + return "<span class='bsui'><span class='badge $class $status'>$status_label</span></span>"; |
|
| 342 | + } |
|
| 343 | 343 | |
| 344 | 344 | /** |
| 345 | - * Get plugin version when the invoice was created. |
|
| 346 | - * |
|
| 347 | - * @since 1.0.19 |
|
| 348 | - * @param string $context View or edit context. |
|
| 349 | - * @return string |
|
| 350 | - */ |
|
| 351 | - public function get_version( $context = 'view' ) { |
|
| 352 | - return $this->get_prop( 'version', $context ); |
|
| 353 | - } |
|
| 345 | + * Get plugin version when the invoice was created. |
|
| 346 | + * |
|
| 347 | + * @since 1.0.19 |
|
| 348 | + * @param string $context View or edit context. |
|
| 349 | + * @return string |
|
| 350 | + */ |
|
| 351 | + public function get_version( $context = 'view' ) { |
|
| 352 | + return $this->get_prop( 'version', $context ); |
|
| 353 | + } |
|
| 354 | 354 | |
| 355 | - /** |
|
| 356 | - * @deprecated |
|
| 357 | - */ |
|
| 358 | - public function get_invoice_date( $format = true ) { |
|
| 359 | - $date = getpaid_format_date( $this->get_date_completed() ); |
|
| 360 | - $date = empty( $date ) ? $this->get_date_created() : $this->get_date_completed(); |
|
| 361 | - $formatted = getpaid_format_date( $date ); |
|
| 355 | + /** |
|
| 356 | + * @deprecated |
|
| 357 | + */ |
|
| 358 | + public function get_invoice_date( $format = true ) { |
|
| 359 | + $date = getpaid_format_date( $this->get_date_completed() ); |
|
| 360 | + $date = empty( $date ) ? $this->get_date_created() : $this->get_date_completed(); |
|
| 361 | + $formatted = getpaid_format_date( $date ); |
|
| 362 | 362 | |
| 363 | - if ( $format ) { |
|
| 364 | - return $formatted; |
|
| 365 | - } |
|
| 363 | + if ( $format ) { |
|
| 364 | + return $formatted; |
|
| 365 | + } |
|
| 366 | 366 | |
| 367 | - return empty( $formatted ) ? '' : $date; |
|
| 367 | + return empty( $formatted ) ? '' : $date; |
|
| 368 | 368 | |
| 369 | 369 | } |
| 370 | 370 | |
| 371 | 371 | /** |
| 372 | - * Get date when the invoice was created. |
|
| 373 | - * |
|
| 374 | - * @since 1.0.19 |
|
| 375 | - * @param string $context View or edit context. |
|
| 376 | - * @return string |
|
| 377 | - */ |
|
| 378 | - public function get_date_created( $context = 'view' ) { |
|
| 379 | - return $this->get_prop( 'date_created', $context ); |
|
| 380 | - } |
|
| 372 | + * Get date when the invoice was created. |
|
| 373 | + * |
|
| 374 | + * @since 1.0.19 |
|
| 375 | + * @param string $context View or edit context. |
|
| 376 | + * @return string |
|
| 377 | + */ |
|
| 378 | + public function get_date_created( $context = 'view' ) { |
|
| 379 | + return $this->get_prop( 'date_created', $context ); |
|
| 380 | + } |
|
| 381 | 381 | |
| 382 | - /** |
|
| 383 | - * Alias for self::get_date_created(). |
|
| 384 | - * |
|
| 385 | - * @since 1.0.19 |
|
| 386 | - * @param string $context View or edit context. |
|
| 387 | - * @return string |
|
| 388 | - */ |
|
| 389 | - public function get_created_date( $context = 'view' ) { |
|
| 390 | - return $this->get_date_created( $context ); |
|
| 391 | - } |
|
| 392 | - |
|
| 393 | - /** |
|
| 394 | - * Get GMT date when the invoice was created. |
|
| 395 | - * |
|
| 396 | - * @since 1.0.19 |
|
| 397 | - * @param string $context View or edit context. |
|
| 398 | - * @return string |
|
| 399 | - */ |
|
| 400 | - public function get_date_created_gmt( $context = 'view' ) { |
|
| 382 | + /** |
|
| 383 | + * Alias for self::get_date_created(). |
|
| 384 | + * |
|
| 385 | + * @since 1.0.19 |
|
| 386 | + * @param string $context View or edit context. |
|
| 387 | + * @return string |
|
| 388 | + */ |
|
| 389 | + public function get_created_date( $context = 'view' ) { |
|
| 390 | + return $this->get_date_created( $context ); |
|
| 391 | + } |
|
| 392 | + |
|
| 393 | + /** |
|
| 394 | + * Get GMT date when the invoice was created. |
|
| 395 | + * |
|
| 396 | + * @since 1.0.19 |
|
| 397 | + * @param string $context View or edit context. |
|
| 398 | + * @return string |
|
| 399 | + */ |
|
| 400 | + public function get_date_created_gmt( $context = 'view' ) { |
|
| 401 | 401 | $date = $this->get_date_created( $context ); |
| 402 | 402 | |
| 403 | 403 | if ( $date ) { |
| 404 | 404 | $date = get_gmt_from_date( $date ); |
| 405 | 405 | } |
| 406 | - return $date; |
|
| 406 | + return $date; |
|
| 407 | 407 | } |
| 408 | 408 | |
| 409 | 409 | /** |
| 410 | - * Get date when the invoice was last modified. |
|
| 411 | - * |
|
| 412 | - * @since 1.0.19 |
|
| 413 | - * @param string $context View or edit context. |
|
| 414 | - * @return string |
|
| 415 | - */ |
|
| 416 | - public function get_date_modified( $context = 'view' ) { |
|
| 417 | - return $this->get_prop( 'date_modified', $context ); |
|
| 418 | - } |
|
| 410 | + * Get date when the invoice was last modified. |
|
| 411 | + * |
|
| 412 | + * @since 1.0.19 |
|
| 413 | + * @param string $context View or edit context. |
|
| 414 | + * @return string |
|
| 415 | + */ |
|
| 416 | + public function get_date_modified( $context = 'view' ) { |
|
| 417 | + return $this->get_prop( 'date_modified', $context ); |
|
| 418 | + } |
|
| 419 | 419 | |
| 420 | - /** |
|
| 421 | - * Alias for self::get_date_modified(). |
|
| 422 | - * |
|
| 423 | - * @since 1.0.19 |
|
| 424 | - * @param string $context View or edit context. |
|
| 425 | - * @return string |
|
| 426 | - */ |
|
| 427 | - public function get_modified_date( $context = 'view' ) { |
|
| 428 | - return $this->get_date_modified( $context ); |
|
| 420 | + /** |
|
| 421 | + * Alias for self::get_date_modified(). |
|
| 422 | + * |
|
| 423 | + * @since 1.0.19 |
|
| 424 | + * @param string $context View or edit context. |
|
| 425 | + * @return string |
|
| 426 | + */ |
|
| 427 | + public function get_modified_date( $context = 'view' ) { |
|
| 428 | + return $this->get_date_modified( $context ); |
|
| 429 | 429 | } |
| 430 | 430 | |
| 431 | 431 | /** |
| 432 | - * Get GMT date when the invoice was last modified. |
|
| 433 | - * |
|
| 434 | - * @since 1.0.19 |
|
| 435 | - * @param string $context View or edit context. |
|
| 436 | - * @return string |
|
| 437 | - */ |
|
| 438 | - public function get_date_modified_gmt( $context = 'view' ) { |
|
| 432 | + * Get GMT date when the invoice was last modified. |
|
| 433 | + * |
|
| 434 | + * @since 1.0.19 |
|
| 435 | + * @param string $context View or edit context. |
|
| 436 | + * @return string |
|
| 437 | + */ |
|
| 438 | + public function get_date_modified_gmt( $context = 'view' ) { |
|
| 439 | 439 | $date = $this->get_date_modified( $context ); |
| 440 | 440 | |
| 441 | 441 | if ( $date ) { |
| 442 | 442 | $date = get_gmt_from_date( $date ); |
| 443 | 443 | } |
| 444 | - return $date; |
|
| 444 | + return $date; |
|
| 445 | 445 | } |
| 446 | 446 | |
| 447 | 447 | /** |
| 448 | - * Get the invoice due date. |
|
| 449 | - * |
|
| 450 | - * @since 1.0.19 |
|
| 451 | - * @param string $context View or edit context. |
|
| 452 | - * @return string |
|
| 453 | - */ |
|
| 454 | - public function get_due_date( $context = 'view' ) { |
|
| 455 | - return $this->get_prop( 'due_date', $context ); |
|
| 448 | + * Get the invoice due date. |
|
| 449 | + * |
|
| 450 | + * @since 1.0.19 |
|
| 451 | + * @param string $context View or edit context. |
|
| 452 | + * @return string |
|
| 453 | + */ |
|
| 454 | + public function get_due_date( $context = 'view' ) { |
|
| 455 | + return $this->get_prop( 'due_date', $context ); |
|
| 456 | 456 | } |
| 457 | 457 | |
| 458 | 458 | /** |
| 459 | - * Alias for self::get_due_date(). |
|
| 460 | - * |
|
| 461 | - * @since 1.0.19 |
|
| 462 | - * @param string $context View or edit context. |
|
| 463 | - * @return string |
|
| 464 | - */ |
|
| 465 | - public function get_date_due( $context = 'view' ) { |
|
| 466 | - return $this->get_due_date( $context ); |
|
| 459 | + * Alias for self::get_due_date(). |
|
| 460 | + * |
|
| 461 | + * @since 1.0.19 |
|
| 462 | + * @param string $context View or edit context. |
|
| 463 | + * @return string |
|
| 464 | + */ |
|
| 465 | + public function get_date_due( $context = 'view' ) { |
|
| 466 | + return $this->get_due_date( $context ); |
|
| 467 | 467 | } |
| 468 | 468 | |
| 469 | 469 | /** |
| 470 | - * Get the invoice GMT due date. |
|
| 471 | - * |
|
| 472 | - * @since 1.0.19 |
|
| 473 | - * @param string $context View or edit context. |
|
| 474 | - * @return string |
|
| 475 | - */ |
|
| 476 | - public function get_due_date_gmt( $context = 'view' ) { |
|
| 470 | + * Get the invoice GMT due date. |
|
| 471 | + * |
|
| 472 | + * @since 1.0.19 |
|
| 473 | + * @param string $context View or edit context. |
|
| 474 | + * @return string |
|
| 475 | + */ |
|
| 476 | + public function get_due_date_gmt( $context = 'view' ) { |
|
| 477 | 477 | $date = $this->get_due_date( $context ); |
| 478 | 478 | |
| 479 | 479 | if ( $date ) { |
| 480 | 480 | $date = get_gmt_from_date( $date ); |
| 481 | 481 | } |
| 482 | - return $date; |
|
| 482 | + return $date; |
|
| 483 | 483 | } |
| 484 | 484 | |
| 485 | 485 | /** |
| 486 | - * Alias for self::get_due_date_gmt(). |
|
| 487 | - * |
|
| 488 | - * @since 1.0.19 |
|
| 489 | - * @param string $context View or edit context. |
|
| 490 | - * @return string |
|
| 491 | - */ |
|
| 492 | - public function get_gmt_date_due( $context = 'view' ) { |
|
| 493 | - return $this->get_due_date_gmt( $context ); |
|
| 486 | + * Alias for self::get_due_date_gmt(). |
|
| 487 | + * |
|
| 488 | + * @since 1.0.19 |
|
| 489 | + * @param string $context View or edit context. |
|
| 490 | + * @return string |
|
| 491 | + */ |
|
| 492 | + public function get_gmt_date_due( $context = 'view' ) { |
|
| 493 | + return $this->get_due_date_gmt( $context ); |
|
| 494 | 494 | } |
| 495 | 495 | |
| 496 | 496 | /** |
| 497 | - * Get date when the invoice was completed. |
|
| 498 | - * |
|
| 499 | - * @since 1.0.19 |
|
| 500 | - * @param string $context View or edit context. |
|
| 501 | - * @return string |
|
| 502 | - */ |
|
| 503 | - public function get_completed_date( $context = 'view' ) { |
|
| 504 | - return $this->get_prop( 'completed_date', $context ); |
|
| 497 | + * Get date when the invoice was completed. |
|
| 498 | + * |
|
| 499 | + * @since 1.0.19 |
|
| 500 | + * @param string $context View or edit context. |
|
| 501 | + * @return string |
|
| 502 | + */ |
|
| 503 | + public function get_completed_date( $context = 'view' ) { |
|
| 504 | + return $this->get_prop( 'completed_date', $context ); |
|
| 505 | 505 | } |
| 506 | 506 | |
| 507 | 507 | /** |
| 508 | - * Alias for self::get_completed_date(). |
|
| 509 | - * |
|
| 510 | - * @since 1.0.19 |
|
| 511 | - * @param string $context View or edit context. |
|
| 512 | - * @return string |
|
| 513 | - */ |
|
| 514 | - public function get_date_completed( $context = 'view' ) { |
|
| 515 | - return $this->get_completed_date( $context ); |
|
| 508 | + * Alias for self::get_completed_date(). |
|
| 509 | + * |
|
| 510 | + * @since 1.0.19 |
|
| 511 | + * @param string $context View or edit context. |
|
| 512 | + * @return string |
|
| 513 | + */ |
|
| 514 | + public function get_date_completed( $context = 'view' ) { |
|
| 515 | + return $this->get_completed_date( $context ); |
|
| 516 | 516 | } |
| 517 | 517 | |
| 518 | 518 | /** |
| 519 | - * Get GMT date when the invoice was was completed. |
|
| 520 | - * |
|
| 521 | - * @since 1.0.19 |
|
| 522 | - * @param string $context View or edit context. |
|
| 523 | - * @return string |
|
| 524 | - */ |
|
| 525 | - public function get_completed_date_gmt( $context = 'view' ) { |
|
| 519 | + * Get GMT date when the invoice was was completed. |
|
| 520 | + * |
|
| 521 | + * @since 1.0.19 |
|
| 522 | + * @param string $context View or edit context. |
|
| 523 | + * @return string |
|
| 524 | + */ |
|
| 525 | + public function get_completed_date_gmt( $context = 'view' ) { |
|
| 526 | 526 | $date = $this->get_completed_date( $context ); |
| 527 | 527 | |
| 528 | 528 | if ( $date ) { |
| 529 | 529 | $date = get_gmt_from_date( $date ); |
| 530 | 530 | } |
| 531 | - return $date; |
|
| 531 | + return $date; |
|
| 532 | 532 | } |
| 533 | 533 | |
| 534 | 534 | /** |
| 535 | - * Alias for self::get_completed_date_gmt(). |
|
| 536 | - * |
|
| 537 | - * @since 1.0.19 |
|
| 538 | - * @param string $context View or edit context. |
|
| 539 | - * @return string |
|
| 540 | - */ |
|
| 541 | - public function get_gmt_completed_date( $context = 'view' ) { |
|
| 542 | - return $this->get_completed_date_gmt( $context ); |
|
| 535 | + * Alias for self::get_completed_date_gmt(). |
|
| 536 | + * |
|
| 537 | + * @since 1.0.19 |
|
| 538 | + * @param string $context View or edit context. |
|
| 539 | + * @return string |
|
| 540 | + */ |
|
| 541 | + public function get_gmt_completed_date( $context = 'view' ) { |
|
| 542 | + return $this->get_completed_date_gmt( $context ); |
|
| 543 | 543 | } |
| 544 | 544 | |
| 545 | 545 | /** |
| 546 | - * Get the invoice number. |
|
| 547 | - * |
|
| 548 | - * @since 1.0.19 |
|
| 549 | - * @param string $context View or edit context. |
|
| 550 | - * @return string |
|
| 551 | - */ |
|
| 552 | - public function get_number( $context = 'view' ) { |
|
| 553 | - $number = $this->get_prop( 'number', $context ); |
|
| 546 | + * Get the invoice number. |
|
| 547 | + * |
|
| 548 | + * @since 1.0.19 |
|
| 549 | + * @param string $context View or edit context. |
|
| 550 | + * @return string |
|
| 551 | + */ |
|
| 552 | + public function get_number( $context = 'view' ) { |
|
| 553 | + $number = $this->get_prop( 'number', $context ); |
|
| 554 | 554 | |
| 555 | - if ( empty( $number ) ) { |
|
| 556 | - $number = $this->generate_number(); |
|
| 557 | - $this->set_number( $this->generate_number() ); |
|
| 558 | - } |
|
| 555 | + if ( empty( $number ) ) { |
|
| 556 | + $number = $this->generate_number(); |
|
| 557 | + $this->set_number( $this->generate_number() ); |
|
| 558 | + } |
|
| 559 | 559 | |
| 560 | - return $number; |
|
| 560 | + return $number; |
|
| 561 | 561 | } |
| 562 | 562 | |
| 563 | - /** |
|
| 564 | - * Set the invoice number. |
|
| 565 | - * |
|
| 566 | - * @since 1.0.19 |
|
| 567 | - */ |
|
| 568 | - public function maybe_set_number() { |
|
| 563 | + /** |
|
| 564 | + * Set the invoice number. |
|
| 565 | + * |
|
| 566 | + * @since 1.0.19 |
|
| 567 | + */ |
|
| 568 | + public function maybe_set_number() { |
|
| 569 | 569 | $number = $this->get_number(); |
| 570 | 570 | |
| 571 | 571 | if ( empty( $number ) || $this->get_id() == $number ) { |
| 572 | - $this->set_number( $this->generate_number() ); |
|
| 572 | + $this->set_number( $this->generate_number() ); |
|
| 573 | 573 | } |
| 574 | 574 | |
| 575 | - } |
|
| 575 | + } |
|
| 576 | 576 | |
| 577 | 577 | /** |
| 578 | - * Get the invoice key. |
|
| 579 | - * |
|
| 580 | - * @since 1.0.19 |
|
| 581 | - * @param string $context View or edit context. |
|
| 582 | - * @return string |
|
| 583 | - */ |
|
| 584 | - public function get_key( $context = 'view' ) { |
|
| 578 | + * Get the invoice key. |
|
| 579 | + * |
|
| 580 | + * @since 1.0.19 |
|
| 581 | + * @param string $context View or edit context. |
|
| 582 | + * @return string |
|
| 583 | + */ |
|
| 584 | + public function get_key( $context = 'view' ) { |
|
| 585 | 585 | return $this->get_prop( 'key', $context ); |
| 586 | - } |
|
| 587 | - |
|
| 588 | - /** |
|
| 589 | - * Set the invoice key. |
|
| 590 | - * |
|
| 591 | - * @since 1.0.19 |
|
| 592 | - */ |
|
| 593 | - public function maybe_set_key() { |
|
| 586 | + } |
|
| 587 | + |
|
| 588 | + /** |
|
| 589 | + * Set the invoice key. |
|
| 590 | + * |
|
| 591 | + * @since 1.0.19 |
|
| 592 | + */ |
|
| 593 | + public function maybe_set_key() { |
|
| 594 | 594 | $key = $this->get_key(); |
| 595 | 595 | |
| 596 | 596 | if ( empty( $key ) ) { |
@@ -601,140 +601,140 @@ discard block |
||
| 601 | 601 | } |
| 602 | 602 | |
| 603 | 603 | /** |
| 604 | - * Get the invoice type. |
|
| 605 | - * |
|
| 606 | - * @since 1.0.19 |
|
| 607 | - * @param string $context View or edit context. |
|
| 608 | - * @return string |
|
| 609 | - */ |
|
| 610 | - public function get_type( $context = 'view' ) { |
|
| 604 | + * Get the invoice type. |
|
| 605 | + * |
|
| 606 | + * @since 1.0.19 |
|
| 607 | + * @param string $context View or edit context. |
|
| 608 | + * @return string |
|
| 609 | + */ |
|
| 610 | + public function get_type( $context = 'view' ) { |
|
| 611 | 611 | return $this->get_prop( 'type', $context ); |
| 612 | - } |
|
| 613 | - |
|
| 614 | - /** |
|
| 615 | - * Returns the post type name. |
|
| 616 | - * |
|
| 617 | - * @since 1.0.19 |
|
| 618 | - * @return string |
|
| 619 | - */ |
|
| 620 | - public function get_invoice_quote_type() { |
|
| 612 | + } |
|
| 613 | + |
|
| 614 | + /** |
|
| 615 | + * Returns the post type name. |
|
| 616 | + * |
|
| 617 | + * @since 1.0.19 |
|
| 618 | + * @return string |
|
| 619 | + */ |
|
| 620 | + public function get_invoice_quote_type() { |
|
| 621 | 621 | return getpaid_get_post_type_label( $this->get_post_type(), false ); |
| 622 | 622 | } |
| 623 | 623 | |
| 624 | 624 | /** |
| 625 | - * Get the invoice post type label. |
|
| 626 | - * |
|
| 627 | - * @since 1.0.19 |
|
| 628 | - * @param string $context View or edit context. |
|
| 629 | - * @return string |
|
| 630 | - */ |
|
| 631 | - public function get_label( $context = 'view' ) { |
|
| 625 | + * Get the invoice post type label. |
|
| 626 | + * |
|
| 627 | + * @since 1.0.19 |
|
| 628 | + * @param string $context View or edit context. |
|
| 629 | + * @return string |
|
| 630 | + */ |
|
| 631 | + public function get_label( $context = 'view' ) { |
|
| 632 | 632 | return getpaid_get_post_type_label( $this->get_post_type( $context ), false ); |
| 633 | - } |
|
| 634 | - |
|
| 635 | - /** |
|
| 636 | - * Get the invoice post type. |
|
| 637 | - * |
|
| 638 | - * @since 1.0.19 |
|
| 639 | - * @param string $context View or edit context. |
|
| 640 | - * @return string |
|
| 641 | - */ |
|
| 642 | - public function get_post_type( $context = 'view' ) { |
|
| 633 | + } |
|
| 634 | + |
|
| 635 | + /** |
|
| 636 | + * Get the invoice post type. |
|
| 637 | + * |
|
| 638 | + * @since 1.0.19 |
|
| 639 | + * @param string $context View or edit context. |
|
| 640 | + * @return string |
|
| 641 | + */ |
|
| 642 | + public function get_post_type( $context = 'view' ) { |
|
| 643 | 643 | return $this->get_prop( 'post_type', $context ); |
| 644 | 644 | } |
| 645 | 645 | |
| 646 | 646 | /** |
| 647 | - * Get the invoice mode. |
|
| 648 | - * |
|
| 649 | - * @since 1.0.19 |
|
| 650 | - * @param string $context View or edit context. |
|
| 651 | - * @return string |
|
| 652 | - */ |
|
| 653 | - public function get_mode( $context = 'view' ) { |
|
| 647 | + * Get the invoice mode. |
|
| 648 | + * |
|
| 649 | + * @since 1.0.19 |
|
| 650 | + * @param string $context View or edit context. |
|
| 651 | + * @return string |
|
| 652 | + */ |
|
| 653 | + public function get_mode( $context = 'view' ) { |
|
| 654 | 654 | return $this->get_prop( 'mode', $context ); |
| 655 | 655 | } |
| 656 | 656 | |
| 657 | 657 | /** |
| 658 | - * Get the invoice path. |
|
| 659 | - * |
|
| 660 | - * @since 1.0.19 |
|
| 661 | - * @param string $context View or edit context. |
|
| 662 | - * @return string |
|
| 663 | - */ |
|
| 664 | - public function get_path( $context = 'view' ) { |
|
| 658 | + * Get the invoice path. |
|
| 659 | + * |
|
| 660 | + * @since 1.0.19 |
|
| 661 | + * @param string $context View or edit context. |
|
| 662 | + * @return string |
|
| 663 | + */ |
|
| 664 | + public function get_path( $context = 'view' ) { |
|
| 665 | 665 | $path = $this->get_prop( 'path', $context ); |
| 666 | - $prefix = $this->get_type(); |
|
| 666 | + $prefix = $this->get_type(); |
|
| 667 | 667 | |
| 668 | - if ( 0 !== strpos( $path, $prefix ) ) { |
|
| 669 | - $path = sanitize_title( $prefix . '-' . $this->get_id() ); |
|
| 670 | - $this->set_path( $path ); |
|
| 671 | - } |
|
| 668 | + if ( 0 !== strpos( $path, $prefix ) ) { |
|
| 669 | + $path = sanitize_title( $prefix . '-' . $this->get_id() ); |
|
| 670 | + $this->set_path( $path ); |
|
| 671 | + } |
|
| 672 | 672 | |
| 673 | - return $path; |
|
| 673 | + return $path; |
|
| 674 | 674 | } |
| 675 | 675 | |
| 676 | 676 | /** |
| 677 | - * Get the invoice name/title. |
|
| 678 | - * |
|
| 679 | - * @since 1.0.19 |
|
| 680 | - * @param string $context View or edit context. |
|
| 681 | - * @return string |
|
| 682 | - */ |
|
| 683 | - public function get_name( $context = 'view' ) { |
|
| 677 | + * Get the invoice name/title. |
|
| 678 | + * |
|
| 679 | + * @since 1.0.19 |
|
| 680 | + * @param string $context View or edit context. |
|
| 681 | + * @return string |
|
| 682 | + */ |
|
| 683 | + public function get_name( $context = 'view' ) { |
|
| 684 | 684 | return $this->get_prop( 'title', $context ); |
| 685 | 685 | } |
| 686 | 686 | |
| 687 | 687 | /** |
| 688 | - * Alias of self::get_name(). |
|
| 689 | - * |
|
| 690 | - * @since 1.0.19 |
|
| 691 | - * @param string $context View or edit context. |
|
| 692 | - * @return string |
|
| 693 | - */ |
|
| 694 | - public function get_title( $context = 'view' ) { |
|
| 695 | - return $this->get_name( $context ); |
|
| 688 | + * Alias of self::get_name(). |
|
| 689 | + * |
|
| 690 | + * @since 1.0.19 |
|
| 691 | + * @param string $context View or edit context. |
|
| 692 | + * @return string |
|
| 693 | + */ |
|
| 694 | + public function get_title( $context = 'view' ) { |
|
| 695 | + return $this->get_name( $context ); |
|
| 696 | 696 | } |
| 697 | 697 | |
| 698 | 698 | /** |
| 699 | - * Get the invoice description. |
|
| 700 | - * |
|
| 701 | - * @since 1.0.19 |
|
| 702 | - * @param string $context View or edit context. |
|
| 703 | - * @return string |
|
| 704 | - */ |
|
| 705 | - public function get_description( $context = 'view' ) { |
|
| 706 | - return $this->get_prop( 'description', $context ); |
|
| 699 | + * Get the invoice description. |
|
| 700 | + * |
|
| 701 | + * @since 1.0.19 |
|
| 702 | + * @param string $context View or edit context. |
|
| 703 | + * @return string |
|
| 704 | + */ |
|
| 705 | + public function get_description( $context = 'view' ) { |
|
| 706 | + return $this->get_prop( 'description', $context ); |
|
| 707 | 707 | } |
| 708 | 708 | |
| 709 | 709 | /** |
| 710 | - * Alias of self::get_description(). |
|
| 711 | - * |
|
| 712 | - * @since 1.0.19 |
|
| 713 | - * @param string $context View or edit context. |
|
| 714 | - * @return string |
|
| 715 | - */ |
|
| 716 | - public function get_excerpt( $context = 'view' ) { |
|
| 717 | - return $this->get_description( $context ); |
|
| 710 | + * Alias of self::get_description(). |
|
| 711 | + * |
|
| 712 | + * @since 1.0.19 |
|
| 713 | + * @param string $context View or edit context. |
|
| 714 | + * @return string |
|
| 715 | + */ |
|
| 716 | + public function get_excerpt( $context = 'view' ) { |
|
| 717 | + return $this->get_description( $context ); |
|
| 718 | 718 | } |
| 719 | 719 | |
| 720 | 720 | /** |
| 721 | - * Alias of self::get_description(). |
|
| 722 | - * |
|
| 723 | - * @since 1.0.19 |
|
| 724 | - * @param string $context View or edit context. |
|
| 725 | - * @return string |
|
| 726 | - */ |
|
| 727 | - public function get_summary( $context = 'view' ) { |
|
| 728 | - return $this->get_description( $context ); |
|
| 721 | + * Alias of self::get_description(). |
|
| 722 | + * |
|
| 723 | + * @since 1.0.19 |
|
| 724 | + * @param string $context View or edit context. |
|
| 725 | + * @return string |
|
| 726 | + */ |
|
| 727 | + public function get_summary( $context = 'view' ) { |
|
| 728 | + return $this->get_description( $context ); |
|
| 729 | 729 | } |
| 730 | 730 | |
| 731 | 731 | /** |
| 732 | - * Returns the user info. |
|
| 733 | - * |
|
| 734 | - * @since 1.0.19 |
|
| 732 | + * Returns the user info. |
|
| 733 | + * |
|
| 734 | + * @since 1.0.19 |
|
| 735 | 735 | * @param string $context View or edit context. |
| 736 | - * @return array |
|
| 737 | - */ |
|
| 736 | + * @return array |
|
| 737 | + */ |
|
| 738 | 738 | public function get_user_info( $context = 'view' ) { |
| 739 | 739 | |
| 740 | 740 | $user_info = array( |
@@ -751,616 +751,616 @@ discard block |
||
| 751 | 751 | 'company' => $this->get_company( $context ), |
| 752 | 752 | 'vat_number' => $this->get_vat_number( $context ), |
| 753 | 753 | 'discount' => $this->get_discount_code( $context ), |
| 754 | - ); |
|
| 754 | + ); |
|
| 755 | 755 | |
| 756 | - return apply_filters( 'wpinv_user_info', $user_info, $this->get_id(), $this ); |
|
| 756 | + return apply_filters( 'wpinv_user_info', $user_info, $this->get_id(), $this ); |
|
| 757 | 757 | |
| 758 | 758 | } |
| 759 | 759 | |
| 760 | 760 | /** |
| 761 | - * Get the customer id. |
|
| 762 | - * |
|
| 763 | - * @since 1.0.19 |
|
| 764 | - * @param string $context View or edit context. |
|
| 765 | - * @return int |
|
| 766 | - */ |
|
| 767 | - public function get_author( $context = 'view' ) { |
|
| 768 | - return (int) $this->get_prop( 'author', $context ); |
|
| 761 | + * Get the customer id. |
|
| 762 | + * |
|
| 763 | + * @since 1.0.19 |
|
| 764 | + * @param string $context View or edit context. |
|
| 765 | + * @return int |
|
| 766 | + */ |
|
| 767 | + public function get_author( $context = 'view' ) { |
|
| 768 | + return (int) $this->get_prop( 'author', $context ); |
|
| 769 | 769 | } |
| 770 | 770 | |
| 771 | 771 | /** |
| 772 | - * Alias of self::get_author(). |
|
| 773 | - * |
|
| 774 | - * @since 1.0.19 |
|
| 775 | - * @param string $context View or edit context. |
|
| 776 | - * @return int |
|
| 777 | - */ |
|
| 778 | - public function get_user_id( $context = 'view' ) { |
|
| 779 | - return $this->get_author( $context ); |
|
| 772 | + * Alias of self::get_author(). |
|
| 773 | + * |
|
| 774 | + * @since 1.0.19 |
|
| 775 | + * @param string $context View or edit context. |
|
| 776 | + * @return int |
|
| 777 | + */ |
|
| 778 | + public function get_user_id( $context = 'view' ) { |
|
| 779 | + return $this->get_author( $context ); |
|
| 780 | 780 | } |
| 781 | 781 | |
| 782 | - /** |
|
| 783 | - * Alias of self::get_author(). |
|
| 784 | - * |
|
| 785 | - * @since 1.0.19 |
|
| 786 | - * @param string $context View or edit context. |
|
| 787 | - * @return int |
|
| 788 | - */ |
|
| 789 | - public function get_customer_id( $context = 'view' ) { |
|
| 790 | - return $this->get_author( $context ); |
|
| 782 | + /** |
|
| 783 | + * Alias of self::get_author(). |
|
| 784 | + * |
|
| 785 | + * @since 1.0.19 |
|
| 786 | + * @param string $context View or edit context. |
|
| 787 | + * @return int |
|
| 788 | + */ |
|
| 789 | + public function get_customer_id( $context = 'view' ) { |
|
| 790 | + return $this->get_author( $context ); |
|
| 791 | 791 | } |
| 792 | 792 | |
| 793 | 793 | /** |
| 794 | - * Get the customer's ip. |
|
| 795 | - * |
|
| 796 | - * @since 1.0.19 |
|
| 797 | - * @param string $context View or edit context. |
|
| 798 | - * @return string |
|
| 799 | - */ |
|
| 800 | - public function get_ip( $context = 'view' ) { |
|
| 801 | - return $this->get_prop( 'user_ip', $context ); |
|
| 794 | + * Get the customer's ip. |
|
| 795 | + * |
|
| 796 | + * @since 1.0.19 |
|
| 797 | + * @param string $context View or edit context. |
|
| 798 | + * @return string |
|
| 799 | + */ |
|
| 800 | + public function get_ip( $context = 'view' ) { |
|
| 801 | + return $this->get_prop( 'user_ip', $context ); |
|
| 802 | 802 | } |
| 803 | 803 | |
| 804 | 804 | /** |
| 805 | - * Alias of self::get_ip(). |
|
| 806 | - * |
|
| 807 | - * @since 1.0.19 |
|
| 808 | - * @param string $context View or edit context. |
|
| 809 | - * @return string |
|
| 810 | - */ |
|
| 811 | - public function get_user_ip( $context = 'view' ) { |
|
| 812 | - return $this->get_ip( $context ); |
|
| 805 | + * Alias of self::get_ip(). |
|
| 806 | + * |
|
| 807 | + * @since 1.0.19 |
|
| 808 | + * @param string $context View or edit context. |
|
| 809 | + * @return string |
|
| 810 | + */ |
|
| 811 | + public function get_user_ip( $context = 'view' ) { |
|
| 812 | + return $this->get_ip( $context ); |
|
| 813 | 813 | } |
| 814 | 814 | |
| 815 | - /** |
|
| 816 | - * Alias of self::get_ip(). |
|
| 817 | - * |
|
| 818 | - * @since 1.0.19 |
|
| 819 | - * @param string $context View or edit context. |
|
| 820 | - * @return string |
|
| 821 | - */ |
|
| 822 | - public function get_customer_ip( $context = 'view' ) { |
|
| 823 | - return $this->get_ip( $context ); |
|
| 815 | + /** |
|
| 816 | + * Alias of self::get_ip(). |
|
| 817 | + * |
|
| 818 | + * @since 1.0.19 |
|
| 819 | + * @param string $context View or edit context. |
|
| 820 | + * @return string |
|
| 821 | + */ |
|
| 822 | + public function get_customer_ip( $context = 'view' ) { |
|
| 823 | + return $this->get_ip( $context ); |
|
| 824 | 824 | } |
| 825 | 825 | |
| 826 | 826 | /** |
| 827 | - * Get the customer's first name. |
|
| 828 | - * |
|
| 829 | - * @since 1.0.19 |
|
| 830 | - * @param string $context View or edit context. |
|
| 831 | - * @return string |
|
| 832 | - */ |
|
| 833 | - public function get_first_name( $context = 'view' ) { |
|
| 834 | - return $this->get_prop( 'first_name', $context ); |
|
| 827 | + * Get the customer's first name. |
|
| 828 | + * |
|
| 829 | + * @since 1.0.19 |
|
| 830 | + * @param string $context View or edit context. |
|
| 831 | + * @return string |
|
| 832 | + */ |
|
| 833 | + public function get_first_name( $context = 'view' ) { |
|
| 834 | + return $this->get_prop( 'first_name', $context ); |
|
| 835 | 835 | } |
| 836 | 836 | |
| 837 | 837 | /** |
| 838 | - * Alias of self::get_first_name(). |
|
| 839 | - * |
|
| 840 | - * @since 1.0.19 |
|
| 841 | - * @param string $context View or edit context. |
|
| 842 | - * @return string |
|
| 843 | - */ |
|
| 844 | - public function get_user_first_name( $context = 'view' ) { |
|
| 845 | - return $this->get_first_name( $context ); |
|
| 838 | + * Alias of self::get_first_name(). |
|
| 839 | + * |
|
| 840 | + * @since 1.0.19 |
|
| 841 | + * @param string $context View or edit context. |
|
| 842 | + * @return string |
|
| 843 | + */ |
|
| 844 | + public function get_user_first_name( $context = 'view' ) { |
|
| 845 | + return $this->get_first_name( $context ); |
|
| 846 | 846 | } |
| 847 | 847 | |
| 848 | - /** |
|
| 849 | - * Alias of self::get_first_name(). |
|
| 850 | - * |
|
| 851 | - * @since 1.0.19 |
|
| 852 | - * @param string $context View or edit context. |
|
| 853 | - * @return string |
|
| 854 | - */ |
|
| 855 | - public function get_customer_first_name( $context = 'view' ) { |
|
| 856 | - return $this->get_first_name( $context ); |
|
| 848 | + /** |
|
| 849 | + * Alias of self::get_first_name(). |
|
| 850 | + * |
|
| 851 | + * @since 1.0.19 |
|
| 852 | + * @param string $context View or edit context. |
|
| 853 | + * @return string |
|
| 854 | + */ |
|
| 855 | + public function get_customer_first_name( $context = 'view' ) { |
|
| 856 | + return $this->get_first_name( $context ); |
|
| 857 | 857 | } |
| 858 | 858 | |
| 859 | 859 | /** |
| 860 | - * Get the customer's last name. |
|
| 861 | - * |
|
| 862 | - * @since 1.0.19 |
|
| 863 | - * @param string $context View or edit context. |
|
| 864 | - * @return string |
|
| 865 | - */ |
|
| 866 | - public function get_last_name( $context = 'view' ) { |
|
| 867 | - return $this->get_prop( 'last_name', $context ); |
|
| 860 | + * Get the customer's last name. |
|
| 861 | + * |
|
| 862 | + * @since 1.0.19 |
|
| 863 | + * @param string $context View or edit context. |
|
| 864 | + * @return string |
|
| 865 | + */ |
|
| 866 | + public function get_last_name( $context = 'view' ) { |
|
| 867 | + return $this->get_prop( 'last_name', $context ); |
|
| 868 | 868 | } |
| 869 | 869 | |
| 870 | 870 | /** |
| 871 | - * Alias of self::get_last_name(). |
|
| 872 | - * |
|
| 873 | - * @since 1.0.19 |
|
| 874 | - * @param string $context View or edit context. |
|
| 875 | - * @return string |
|
| 876 | - */ |
|
| 877 | - public function get_user_last_name( $context = 'view' ) { |
|
| 878 | - return $this->get_last_name( $context ); |
|
| 871 | + * Alias of self::get_last_name(). |
|
| 872 | + * |
|
| 873 | + * @since 1.0.19 |
|
| 874 | + * @param string $context View or edit context. |
|
| 875 | + * @return string |
|
| 876 | + */ |
|
| 877 | + public function get_user_last_name( $context = 'view' ) { |
|
| 878 | + return $this->get_last_name( $context ); |
|
| 879 | 879 | } |
| 880 | 880 | |
| 881 | 881 | /** |
| 882 | - * Alias of self::get_last_name(). |
|
| 883 | - * |
|
| 884 | - * @since 1.0.19 |
|
| 885 | - * @param string $context View or edit context. |
|
| 886 | - * @return string |
|
| 887 | - */ |
|
| 888 | - public function get_customer_last_name( $context = 'view' ) { |
|
| 889 | - return $this->get_last_name( $context ); |
|
| 882 | + * Alias of self::get_last_name(). |
|
| 883 | + * |
|
| 884 | + * @since 1.0.19 |
|
| 885 | + * @param string $context View or edit context. |
|
| 886 | + * @return string |
|
| 887 | + */ |
|
| 888 | + public function get_customer_last_name( $context = 'view' ) { |
|
| 889 | + return $this->get_last_name( $context ); |
|
| 890 | 890 | } |
| 891 | 891 | |
| 892 | 892 | /** |
| 893 | - * Get the customer's full name. |
|
| 894 | - * |
|
| 895 | - * @since 1.0.19 |
|
| 896 | - * @param string $context View or edit context. |
|
| 897 | - * @return string |
|
| 898 | - */ |
|
| 899 | - public function get_full_name( $context = 'view' ) { |
|
| 900 | - return trim( $this->get_first_name( $context ) . ' ' . $this->get_last_name( $context ) ); |
|
| 893 | + * Get the customer's full name. |
|
| 894 | + * |
|
| 895 | + * @since 1.0.19 |
|
| 896 | + * @param string $context View or edit context. |
|
| 897 | + * @return string |
|
| 898 | + */ |
|
| 899 | + public function get_full_name( $context = 'view' ) { |
|
| 900 | + return trim( $this->get_first_name( $context ) . ' ' . $this->get_last_name( $context ) ); |
|
| 901 | 901 | } |
| 902 | 902 | |
| 903 | 903 | /** |
| 904 | - * Alias of self::get_full_name(). |
|
| 905 | - * |
|
| 906 | - * @since 1.0.19 |
|
| 907 | - * @param string $context View or edit context. |
|
| 908 | - * @return string |
|
| 909 | - */ |
|
| 910 | - public function get_user_full_name( $context = 'view' ) { |
|
| 911 | - return $this->get_full_name( $context ); |
|
| 904 | + * Alias of self::get_full_name(). |
|
| 905 | + * |
|
| 906 | + * @since 1.0.19 |
|
| 907 | + * @param string $context View or edit context. |
|
| 908 | + * @return string |
|
| 909 | + */ |
|
| 910 | + public function get_user_full_name( $context = 'view' ) { |
|
| 911 | + return $this->get_full_name( $context ); |
|
| 912 | 912 | } |
| 913 | 913 | |
| 914 | 914 | /** |
| 915 | - * Alias of self::get_full_name(). |
|
| 916 | - * |
|
| 917 | - * @since 1.0.19 |
|
| 918 | - * @param string $context View or edit context. |
|
| 919 | - * @return string |
|
| 920 | - */ |
|
| 921 | - public function get_customer_full_name( $context = 'view' ) { |
|
| 922 | - return $this->get_full_name( $context ); |
|
| 915 | + * Alias of self::get_full_name(). |
|
| 916 | + * |
|
| 917 | + * @since 1.0.19 |
|
| 918 | + * @param string $context View or edit context. |
|
| 919 | + * @return string |
|
| 920 | + */ |
|
| 921 | + public function get_customer_full_name( $context = 'view' ) { |
|
| 922 | + return $this->get_full_name( $context ); |
|
| 923 | 923 | } |
| 924 | 924 | |
| 925 | 925 | /** |
| 926 | - * Get the customer's phone number. |
|
| 927 | - * |
|
| 928 | - * @since 1.0.19 |
|
| 929 | - * @param string $context View or edit context. |
|
| 930 | - * @return string |
|
| 931 | - */ |
|
| 932 | - public function get_phone( $context = 'view' ) { |
|
| 933 | - return $this->get_prop( 'phone', $context ); |
|
| 926 | + * Get the customer's phone number. |
|
| 927 | + * |
|
| 928 | + * @since 1.0.19 |
|
| 929 | + * @param string $context View or edit context. |
|
| 930 | + * @return string |
|
| 931 | + */ |
|
| 932 | + public function get_phone( $context = 'view' ) { |
|
| 933 | + return $this->get_prop( 'phone', $context ); |
|
| 934 | 934 | } |
| 935 | 935 | |
| 936 | 936 | /** |
| 937 | - * Alias of self::get_phone(). |
|
| 938 | - * |
|
| 939 | - * @since 1.0.19 |
|
| 940 | - * @param string $context View or edit context. |
|
| 941 | - * @return string |
|
| 942 | - */ |
|
| 943 | - public function get_phone_number( $context = 'view' ) { |
|
| 944 | - return $this->get_phone( $context ); |
|
| 937 | + * Alias of self::get_phone(). |
|
| 938 | + * |
|
| 939 | + * @since 1.0.19 |
|
| 940 | + * @param string $context View or edit context. |
|
| 941 | + * @return string |
|
| 942 | + */ |
|
| 943 | + public function get_phone_number( $context = 'view' ) { |
|
| 944 | + return $this->get_phone( $context ); |
|
| 945 | 945 | } |
| 946 | 946 | |
| 947 | 947 | /** |
| 948 | - * Alias of self::get_phone(). |
|
| 949 | - * |
|
| 950 | - * @since 1.0.19 |
|
| 951 | - * @param string $context View or edit context. |
|
| 952 | - * @return string |
|
| 953 | - */ |
|
| 954 | - public function get_user_phone( $context = 'view' ) { |
|
| 955 | - return $this->get_phone( $context ); |
|
| 956 | - } |
|
| 957 | - |
|
| 948 | + * Alias of self::get_phone(). |
|
| 949 | + * |
|
| 950 | + * @since 1.0.19 |
|
| 951 | + * @param string $context View or edit context. |
|
| 952 | + * @return string |
|
| 953 | + */ |
|
| 954 | + public function get_user_phone( $context = 'view' ) { |
|
| 955 | + return $this->get_phone( $context ); |
|
| 956 | + } |
|
| 957 | + |
|
| 958 | 958 | /** |
| 959 | - * Alias of self::get_phone(). |
|
| 960 | - * |
|
| 961 | - * @since 1.0.19 |
|
| 962 | - * @param string $context View or edit context. |
|
| 963 | - * @return string |
|
| 964 | - */ |
|
| 965 | - public function get_customer_phone( $context = 'view' ) { |
|
| 966 | - return $this->get_phone( $context ); |
|
| 959 | + * Alias of self::get_phone(). |
|
| 960 | + * |
|
| 961 | + * @since 1.0.19 |
|
| 962 | + * @param string $context View or edit context. |
|
| 963 | + * @return string |
|
| 964 | + */ |
|
| 965 | + public function get_customer_phone( $context = 'view' ) { |
|
| 966 | + return $this->get_phone( $context ); |
|
| 967 | 967 | } |
| 968 | 968 | |
| 969 | 969 | /** |
| 970 | - * Get the customer's email address. |
|
| 971 | - * |
|
| 972 | - * @since 1.0.19 |
|
| 973 | - * @param string $context View or edit context. |
|
| 974 | - * @return string |
|
| 975 | - */ |
|
| 976 | - public function get_email( $context = 'view' ) { |
|
| 977 | - return $this->get_prop( 'email', $context ); |
|
| 970 | + * Get the customer's email address. |
|
| 971 | + * |
|
| 972 | + * @since 1.0.19 |
|
| 973 | + * @param string $context View or edit context. |
|
| 974 | + * @return string |
|
| 975 | + */ |
|
| 976 | + public function get_email( $context = 'view' ) { |
|
| 977 | + return $this->get_prop( 'email', $context ); |
|
| 978 | 978 | } |
| 979 | 979 | |
| 980 | 980 | /** |
| 981 | - * Alias of self::get_email(). |
|
| 982 | - * |
|
| 983 | - * @since 1.0.19 |
|
| 984 | - * @param string $context View or edit context. |
|
| 985 | - * @return string |
|
| 986 | - */ |
|
| 987 | - public function get_email_address( $context = 'view' ) { |
|
| 988 | - return $this->get_email( $context ); |
|
| 981 | + * Alias of self::get_email(). |
|
| 982 | + * |
|
| 983 | + * @since 1.0.19 |
|
| 984 | + * @param string $context View or edit context. |
|
| 985 | + * @return string |
|
| 986 | + */ |
|
| 987 | + public function get_email_address( $context = 'view' ) { |
|
| 988 | + return $this->get_email( $context ); |
|
| 989 | 989 | } |
| 990 | 990 | |
| 991 | 991 | /** |
| 992 | - * Alias of self::get_email(). |
|
| 993 | - * |
|
| 994 | - * @since 1.0.19 |
|
| 995 | - * @param string $context View or edit context. |
|
| 996 | - * @return string |
|
| 997 | - */ |
|
| 998 | - public function get_user_email( $context = 'view' ) { |
|
| 999 | - return $this->get_email( $context ); |
|
| 992 | + * Alias of self::get_email(). |
|
| 993 | + * |
|
| 994 | + * @since 1.0.19 |
|
| 995 | + * @param string $context View or edit context. |
|
| 996 | + * @return string |
|
| 997 | + */ |
|
| 998 | + public function get_user_email( $context = 'view' ) { |
|
| 999 | + return $this->get_email( $context ); |
|
| 1000 | 1000 | } |
| 1001 | 1001 | |
| 1002 | 1002 | /** |
| 1003 | - * Alias of self::get_email(). |
|
| 1004 | - * |
|
| 1005 | - * @since 1.0.19 |
|
| 1006 | - * @param string $context View or edit context. |
|
| 1007 | - * @return string |
|
| 1008 | - */ |
|
| 1009 | - public function get_customer_email( $context = 'view' ) { |
|
| 1010 | - return $this->get_email( $context ); |
|
| 1003 | + * Alias of self::get_email(). |
|
| 1004 | + * |
|
| 1005 | + * @since 1.0.19 |
|
| 1006 | + * @param string $context View or edit context. |
|
| 1007 | + * @return string |
|
| 1008 | + */ |
|
| 1009 | + public function get_customer_email( $context = 'view' ) { |
|
| 1010 | + return $this->get_email( $context ); |
|
| 1011 | 1011 | } |
| 1012 | 1012 | |
| 1013 | 1013 | /** |
| 1014 | - * Get the customer's country. |
|
| 1015 | - * |
|
| 1016 | - * @since 1.0.19 |
|
| 1017 | - * @param string $context View or edit context. |
|
| 1018 | - * @return string |
|
| 1019 | - */ |
|
| 1020 | - public function get_country( $context = 'view' ) { |
|
| 1021 | - $country = $this->get_prop( 'country', $context ); |
|
| 1022 | - return empty( $country ) ? wpinv_get_default_country() : $country; |
|
| 1014 | + * Get the customer's country. |
|
| 1015 | + * |
|
| 1016 | + * @since 1.0.19 |
|
| 1017 | + * @param string $context View or edit context. |
|
| 1018 | + * @return string |
|
| 1019 | + */ |
|
| 1020 | + public function get_country( $context = 'view' ) { |
|
| 1021 | + $country = $this->get_prop( 'country', $context ); |
|
| 1022 | + return empty( $country ) ? wpinv_get_default_country() : $country; |
|
| 1023 | 1023 | } |
| 1024 | 1024 | |
| 1025 | 1025 | /** |
| 1026 | - * Alias of self::get_country(). |
|
| 1027 | - * |
|
| 1028 | - * @since 1.0.19 |
|
| 1029 | - * @param string $context View or edit context. |
|
| 1030 | - * @return string |
|
| 1031 | - */ |
|
| 1032 | - public function get_user_country( $context = 'view' ) { |
|
| 1033 | - return $this->get_country( $context ); |
|
| 1026 | + * Alias of self::get_country(). |
|
| 1027 | + * |
|
| 1028 | + * @since 1.0.19 |
|
| 1029 | + * @param string $context View or edit context. |
|
| 1030 | + * @return string |
|
| 1031 | + */ |
|
| 1032 | + public function get_user_country( $context = 'view' ) { |
|
| 1033 | + return $this->get_country( $context ); |
|
| 1034 | 1034 | } |
| 1035 | 1035 | |
| 1036 | 1036 | /** |
| 1037 | - * Alias of self::get_country(). |
|
| 1038 | - * |
|
| 1039 | - * @since 1.0.19 |
|
| 1040 | - * @param string $context View or edit context. |
|
| 1041 | - * @return string |
|
| 1042 | - */ |
|
| 1043 | - public function get_customer_country( $context = 'view' ) { |
|
| 1044 | - return $this->get_country( $context ); |
|
| 1037 | + * Alias of self::get_country(). |
|
| 1038 | + * |
|
| 1039 | + * @since 1.0.19 |
|
| 1040 | + * @param string $context View or edit context. |
|
| 1041 | + * @return string |
|
| 1042 | + */ |
|
| 1043 | + public function get_customer_country( $context = 'view' ) { |
|
| 1044 | + return $this->get_country( $context ); |
|
| 1045 | 1045 | } |
| 1046 | 1046 | |
| 1047 | 1047 | /** |
| 1048 | - * Get the customer's state. |
|
| 1049 | - * |
|
| 1050 | - * @since 1.0.19 |
|
| 1051 | - * @param string $context View or edit context. |
|
| 1052 | - * @return string |
|
| 1053 | - */ |
|
| 1054 | - public function get_state( $context = 'view' ) { |
|
| 1055 | - $state = $this->get_prop( 'state', $context ); |
|
| 1056 | - return empty( $state ) ? wpinv_get_default_state() : $state; |
|
| 1048 | + * Get the customer's state. |
|
| 1049 | + * |
|
| 1050 | + * @since 1.0.19 |
|
| 1051 | + * @param string $context View or edit context. |
|
| 1052 | + * @return string |
|
| 1053 | + */ |
|
| 1054 | + public function get_state( $context = 'view' ) { |
|
| 1055 | + $state = $this->get_prop( 'state', $context ); |
|
| 1056 | + return empty( $state ) ? wpinv_get_default_state() : $state; |
|
| 1057 | 1057 | } |
| 1058 | 1058 | |
| 1059 | 1059 | /** |
| 1060 | - * Alias of self::get_state(). |
|
| 1061 | - * |
|
| 1062 | - * @since 1.0.19 |
|
| 1063 | - * @param string $context View or edit context. |
|
| 1064 | - * @return string |
|
| 1065 | - */ |
|
| 1066 | - public function get_user_state( $context = 'view' ) { |
|
| 1067 | - return $this->get_state( $context ); |
|
| 1060 | + * Alias of self::get_state(). |
|
| 1061 | + * |
|
| 1062 | + * @since 1.0.19 |
|
| 1063 | + * @param string $context View or edit context. |
|
| 1064 | + * @return string |
|
| 1065 | + */ |
|
| 1066 | + public function get_user_state( $context = 'view' ) { |
|
| 1067 | + return $this->get_state( $context ); |
|
| 1068 | 1068 | } |
| 1069 | 1069 | |
| 1070 | 1070 | /** |
| 1071 | - * Alias of self::get_state(). |
|
| 1072 | - * |
|
| 1073 | - * @since 1.0.19 |
|
| 1074 | - * @param string $context View or edit context. |
|
| 1075 | - * @return string |
|
| 1076 | - */ |
|
| 1077 | - public function get_customer_state( $context = 'view' ) { |
|
| 1078 | - return $this->get_state( $context ); |
|
| 1071 | + * Alias of self::get_state(). |
|
| 1072 | + * |
|
| 1073 | + * @since 1.0.19 |
|
| 1074 | + * @param string $context View or edit context. |
|
| 1075 | + * @return string |
|
| 1076 | + */ |
|
| 1077 | + public function get_customer_state( $context = 'view' ) { |
|
| 1078 | + return $this->get_state( $context ); |
|
| 1079 | 1079 | } |
| 1080 | 1080 | |
| 1081 | 1081 | /** |
| 1082 | - * Get the customer's city. |
|
| 1083 | - * |
|
| 1084 | - * @since 1.0.19 |
|
| 1085 | - * @param string $context View or edit context. |
|
| 1086 | - * @return string |
|
| 1087 | - */ |
|
| 1088 | - public function get_city( $context = 'view' ) { |
|
| 1089 | - return $this->get_prop( 'city', $context ); |
|
| 1082 | + * Get the customer's city. |
|
| 1083 | + * |
|
| 1084 | + * @since 1.0.19 |
|
| 1085 | + * @param string $context View or edit context. |
|
| 1086 | + * @return string |
|
| 1087 | + */ |
|
| 1088 | + public function get_city( $context = 'view' ) { |
|
| 1089 | + return $this->get_prop( 'city', $context ); |
|
| 1090 | 1090 | } |
| 1091 | 1091 | |
| 1092 | 1092 | /** |
| 1093 | - * Alias of self::get_city(). |
|
| 1094 | - * |
|
| 1095 | - * @since 1.0.19 |
|
| 1096 | - * @param string $context View or edit context. |
|
| 1097 | - * @return string |
|
| 1098 | - */ |
|
| 1099 | - public function get_user_city( $context = 'view' ) { |
|
| 1100 | - return $this->get_city( $context ); |
|
| 1093 | + * Alias of self::get_city(). |
|
| 1094 | + * |
|
| 1095 | + * @since 1.0.19 |
|
| 1096 | + * @param string $context View or edit context. |
|
| 1097 | + * @return string |
|
| 1098 | + */ |
|
| 1099 | + public function get_user_city( $context = 'view' ) { |
|
| 1100 | + return $this->get_city( $context ); |
|
| 1101 | 1101 | } |
| 1102 | 1102 | |
| 1103 | 1103 | /** |
| 1104 | - * Alias of self::get_city(). |
|
| 1105 | - * |
|
| 1106 | - * @since 1.0.19 |
|
| 1107 | - * @param string $context View or edit context. |
|
| 1108 | - * @return string |
|
| 1109 | - */ |
|
| 1110 | - public function get_customer_city( $context = 'view' ) { |
|
| 1111 | - return $this->get_city( $context ); |
|
| 1104 | + * Alias of self::get_city(). |
|
| 1105 | + * |
|
| 1106 | + * @since 1.0.19 |
|
| 1107 | + * @param string $context View or edit context. |
|
| 1108 | + * @return string |
|
| 1109 | + */ |
|
| 1110 | + public function get_customer_city( $context = 'view' ) { |
|
| 1111 | + return $this->get_city( $context ); |
|
| 1112 | 1112 | } |
| 1113 | 1113 | |
| 1114 | 1114 | /** |
| 1115 | - * Get the customer's zip. |
|
| 1116 | - * |
|
| 1117 | - * @since 1.0.19 |
|
| 1118 | - * @param string $context View or edit context. |
|
| 1119 | - * @return string |
|
| 1120 | - */ |
|
| 1121 | - public function get_zip( $context = 'view' ) { |
|
| 1122 | - return $this->get_prop( 'zip', $context ); |
|
| 1115 | + * Get the customer's zip. |
|
| 1116 | + * |
|
| 1117 | + * @since 1.0.19 |
|
| 1118 | + * @param string $context View or edit context. |
|
| 1119 | + * @return string |
|
| 1120 | + */ |
|
| 1121 | + public function get_zip( $context = 'view' ) { |
|
| 1122 | + return $this->get_prop( 'zip', $context ); |
|
| 1123 | 1123 | } |
| 1124 | 1124 | |
| 1125 | 1125 | /** |
| 1126 | - * Alias of self::get_zip(). |
|
| 1127 | - * |
|
| 1128 | - * @since 1.0.19 |
|
| 1129 | - * @param string $context View or edit context. |
|
| 1130 | - * @return string |
|
| 1131 | - */ |
|
| 1132 | - public function get_user_zip( $context = 'view' ) { |
|
| 1133 | - return $this->get_zip( $context ); |
|
| 1126 | + * Alias of self::get_zip(). |
|
| 1127 | + * |
|
| 1128 | + * @since 1.0.19 |
|
| 1129 | + * @param string $context View or edit context. |
|
| 1130 | + * @return string |
|
| 1131 | + */ |
|
| 1132 | + public function get_user_zip( $context = 'view' ) { |
|
| 1133 | + return $this->get_zip( $context ); |
|
| 1134 | 1134 | } |
| 1135 | 1135 | |
| 1136 | 1136 | /** |
| 1137 | - * Alias of self::get_zip(). |
|
| 1138 | - * |
|
| 1139 | - * @since 1.0.19 |
|
| 1140 | - * @param string $context View or edit context. |
|
| 1141 | - * @return string |
|
| 1142 | - */ |
|
| 1143 | - public function get_customer_zip( $context = 'view' ) { |
|
| 1144 | - return $this->get_zip( $context ); |
|
| 1137 | + * Alias of self::get_zip(). |
|
| 1138 | + * |
|
| 1139 | + * @since 1.0.19 |
|
| 1140 | + * @param string $context View or edit context. |
|
| 1141 | + * @return string |
|
| 1142 | + */ |
|
| 1143 | + public function get_customer_zip( $context = 'view' ) { |
|
| 1144 | + return $this->get_zip( $context ); |
|
| 1145 | 1145 | } |
| 1146 | 1146 | |
| 1147 | 1147 | /** |
| 1148 | - * Get the customer's company. |
|
| 1149 | - * |
|
| 1150 | - * @since 1.0.19 |
|
| 1151 | - * @param string $context View or edit context. |
|
| 1152 | - * @return string |
|
| 1153 | - */ |
|
| 1154 | - public function get_company( $context = 'view' ) { |
|
| 1155 | - return $this->get_prop( 'company', $context ); |
|
| 1148 | + * Get the customer's company. |
|
| 1149 | + * |
|
| 1150 | + * @since 1.0.19 |
|
| 1151 | + * @param string $context View or edit context. |
|
| 1152 | + * @return string |
|
| 1153 | + */ |
|
| 1154 | + public function get_company( $context = 'view' ) { |
|
| 1155 | + return $this->get_prop( 'company', $context ); |
|
| 1156 | 1156 | } |
| 1157 | 1157 | |
| 1158 | 1158 | /** |
| 1159 | - * Alias of self::get_company(). |
|
| 1160 | - * |
|
| 1161 | - * @since 1.0.19 |
|
| 1162 | - * @param string $context View or edit context. |
|
| 1163 | - * @return string |
|
| 1164 | - */ |
|
| 1165 | - public function get_user_company( $context = 'view' ) { |
|
| 1166 | - return $this->get_company( $context ); |
|
| 1159 | + * Alias of self::get_company(). |
|
| 1160 | + * |
|
| 1161 | + * @since 1.0.19 |
|
| 1162 | + * @param string $context View or edit context. |
|
| 1163 | + * @return string |
|
| 1164 | + */ |
|
| 1165 | + public function get_user_company( $context = 'view' ) { |
|
| 1166 | + return $this->get_company( $context ); |
|
| 1167 | 1167 | } |
| 1168 | 1168 | |
| 1169 | 1169 | /** |
| 1170 | - * Alias of self::get_company(). |
|
| 1171 | - * |
|
| 1172 | - * @since 1.0.19 |
|
| 1173 | - * @param string $context View or edit context. |
|
| 1174 | - * @return string |
|
| 1175 | - */ |
|
| 1176 | - public function get_customer_company( $context = 'view' ) { |
|
| 1177 | - return $this->get_company( $context ); |
|
| 1170 | + * Alias of self::get_company(). |
|
| 1171 | + * |
|
| 1172 | + * @since 1.0.19 |
|
| 1173 | + * @param string $context View or edit context. |
|
| 1174 | + * @return string |
|
| 1175 | + */ |
|
| 1176 | + public function get_customer_company( $context = 'view' ) { |
|
| 1177 | + return $this->get_company( $context ); |
|
| 1178 | 1178 | } |
| 1179 | 1179 | |
| 1180 | 1180 | /** |
| 1181 | - * Get the customer's vat number. |
|
| 1182 | - * |
|
| 1183 | - * @since 1.0.19 |
|
| 1184 | - * @param string $context View or edit context. |
|
| 1185 | - * @return string |
|
| 1186 | - */ |
|
| 1187 | - public function get_vat_number( $context = 'view' ) { |
|
| 1188 | - return $this->get_prop( 'vat_number', $context ); |
|
| 1181 | + * Get the customer's vat number. |
|
| 1182 | + * |
|
| 1183 | + * @since 1.0.19 |
|
| 1184 | + * @param string $context View or edit context. |
|
| 1185 | + * @return string |
|
| 1186 | + */ |
|
| 1187 | + public function get_vat_number( $context = 'view' ) { |
|
| 1188 | + return $this->get_prop( 'vat_number', $context ); |
|
| 1189 | 1189 | } |
| 1190 | 1190 | |
| 1191 | 1191 | /** |
| 1192 | - * Alias of self::get_vat_number(). |
|
| 1193 | - * |
|
| 1194 | - * @since 1.0.19 |
|
| 1195 | - * @param string $context View or edit context. |
|
| 1196 | - * @return string |
|
| 1197 | - */ |
|
| 1198 | - public function get_user_vat_number( $context = 'view' ) { |
|
| 1199 | - return $this->get_vat_number( $context ); |
|
| 1192 | + * Alias of self::get_vat_number(). |
|
| 1193 | + * |
|
| 1194 | + * @since 1.0.19 |
|
| 1195 | + * @param string $context View or edit context. |
|
| 1196 | + * @return string |
|
| 1197 | + */ |
|
| 1198 | + public function get_user_vat_number( $context = 'view' ) { |
|
| 1199 | + return $this->get_vat_number( $context ); |
|
| 1200 | 1200 | } |
| 1201 | 1201 | |
| 1202 | 1202 | /** |
| 1203 | - * Alias of self::get_vat_number(). |
|
| 1204 | - * |
|
| 1205 | - * @since 1.0.19 |
|
| 1206 | - * @param string $context View or edit context. |
|
| 1207 | - * @return string |
|
| 1208 | - */ |
|
| 1209 | - public function get_customer_vat_number( $context = 'view' ) { |
|
| 1210 | - return $this->get_vat_number( $context ); |
|
| 1203 | + * Alias of self::get_vat_number(). |
|
| 1204 | + * |
|
| 1205 | + * @since 1.0.19 |
|
| 1206 | + * @param string $context View or edit context. |
|
| 1207 | + * @return string |
|
| 1208 | + */ |
|
| 1209 | + public function get_customer_vat_number( $context = 'view' ) { |
|
| 1210 | + return $this->get_vat_number( $context ); |
|
| 1211 | + } |
|
| 1212 | + |
|
| 1213 | + /** |
|
| 1214 | + * Get the customer's vat rate. |
|
| 1215 | + * |
|
| 1216 | + * @since 1.0.19 |
|
| 1217 | + * @param string $context View or edit context. |
|
| 1218 | + * @return string |
|
| 1219 | + */ |
|
| 1220 | + public function get_vat_rate( $context = 'view' ) { |
|
| 1221 | + return $this->get_prop( 'vat_rate', $context ); |
|
| 1222 | + } |
|
| 1223 | + |
|
| 1224 | + /** |
|
| 1225 | + * Alias of self::get_vat_rate(). |
|
| 1226 | + * |
|
| 1227 | + * @since 1.0.19 |
|
| 1228 | + * @param string $context View or edit context. |
|
| 1229 | + * @return string |
|
| 1230 | + */ |
|
| 1231 | + public function get_user_vat_rate( $context = 'view' ) { |
|
| 1232 | + return $this->get_vat_rate( $context ); |
|
| 1211 | 1233 | } |
| 1212 | 1234 | |
| 1213 | 1235 | /** |
| 1214 | - * Get the customer's vat rate. |
|
| 1215 | - * |
|
| 1216 | - * @since 1.0.19 |
|
| 1217 | - * @param string $context View or edit context. |
|
| 1218 | - * @return string |
|
| 1219 | - */ |
|
| 1220 | - public function get_vat_rate( $context = 'view' ) { |
|
| 1221 | - return $this->get_prop( 'vat_rate', $context ); |
|
| 1222 | - } |
|
| 1223 | - |
|
| 1224 | - /** |
|
| 1225 | - * Alias of self::get_vat_rate(). |
|
| 1226 | - * |
|
| 1227 | - * @since 1.0.19 |
|
| 1228 | - * @param string $context View or edit context. |
|
| 1229 | - * @return string |
|
| 1230 | - */ |
|
| 1231 | - public function get_user_vat_rate( $context = 'view' ) { |
|
| 1232 | - return $this->get_vat_rate( $context ); |
|
| 1233 | - } |
|
| 1234 | - |
|
| 1235 | - /** |
|
| 1236 | - * Alias of self::get_vat_rate(). |
|
| 1237 | - * |
|
| 1238 | - * @since 1.0.19 |
|
| 1239 | - * @param string $context View or edit context. |
|
| 1240 | - * @return string |
|
| 1241 | - */ |
|
| 1242 | - public function get_customer_vat_rate( $context = 'view' ) { |
|
| 1243 | - return $this->get_vat_rate( $context ); |
|
| 1244 | - } |
|
| 1245 | - |
|
| 1246 | - /** |
|
| 1247 | - * Get the customer's address. |
|
| 1248 | - * |
|
| 1249 | - * @since 1.0.19 |
|
| 1250 | - * @param string $context View or edit context. |
|
| 1251 | - * @return string |
|
| 1252 | - */ |
|
| 1253 | - public function get_address( $context = 'view' ) { |
|
| 1254 | - return $this->get_prop( 'address', $context ); |
|
| 1255 | - } |
|
| 1256 | - |
|
| 1257 | - /** |
|
| 1258 | - * Alias of self::get_address(). |
|
| 1259 | - * |
|
| 1260 | - * @since 1.0.19 |
|
| 1261 | - * @param string $context View or edit context. |
|
| 1262 | - * @return string |
|
| 1263 | - */ |
|
| 1264 | - public function get_user_address( $context = 'view' ) { |
|
| 1265 | - return $this->get_address( $context ); |
|
| 1266 | - } |
|
| 1267 | - |
|
| 1268 | - /** |
|
| 1269 | - * Alias of self::get_address(). |
|
| 1270 | - * |
|
| 1271 | - * @since 1.0.19 |
|
| 1272 | - * @param string $context View or edit context. |
|
| 1273 | - * @return string |
|
| 1274 | - */ |
|
| 1275 | - public function get_customer_address( $context = 'view' ) { |
|
| 1276 | - return $this->get_address( $context ); |
|
| 1277 | - } |
|
| 1278 | - |
|
| 1279 | - /** |
|
| 1280 | - * Get whether the customer has viewed the invoice or not. |
|
| 1281 | - * |
|
| 1282 | - * @since 1.0.19 |
|
| 1283 | - * @param string $context View or edit context. |
|
| 1284 | - * @return bool |
|
| 1285 | - */ |
|
| 1286 | - public function get_is_viewed( $context = 'view' ) { |
|
| 1287 | - return (bool) $this->get_prop( 'is_viewed', $context ); |
|
| 1288 | - } |
|
| 1289 | - |
|
| 1290 | - /** |
|
| 1291 | - * Get other recipients for invoice communications. |
|
| 1292 | - * |
|
| 1293 | - * @since 1.0.19 |
|
| 1294 | - * @param string $context View or edit context. |
|
| 1295 | - * @return bool |
|
| 1296 | - */ |
|
| 1297 | - public function get_email_cc( $context = 'view' ) { |
|
| 1298 | - return $this->get_prop( 'email_cc', $context ); |
|
| 1299 | - } |
|
| 1300 | - |
|
| 1301 | - /** |
|
| 1302 | - * Get invoice template. |
|
| 1303 | - * |
|
| 1304 | - * @since 1.0.19 |
|
| 1305 | - * @param string $context View or edit context. |
|
| 1306 | - * @return bool |
|
| 1307 | - */ |
|
| 1308 | - public function get_template( $context = 'view' ) { |
|
| 1309 | - return $this->get_prop( 'template', $context ); |
|
| 1310 | - } |
|
| 1311 | - |
|
| 1312 | - /** |
|
| 1313 | - * Get invoice source. |
|
| 1314 | - * |
|
| 1315 | - * @since 1.0.19 |
|
| 1316 | - * @param string $context View or edit context. |
|
| 1317 | - * @return bool |
|
| 1318 | - */ |
|
| 1319 | - public function get_created_via( $context = 'view' ) { |
|
| 1320 | - return $this->get_prop( 'created_via', $context ); |
|
| 1321 | - } |
|
| 1322 | - |
|
| 1323 | - /** |
|
| 1324 | - * Get whether the customer has confirmed their address. |
|
| 1325 | - * |
|
| 1326 | - * @since 1.0.19 |
|
| 1327 | - * @param string $context View or edit context. |
|
| 1328 | - * @return bool |
|
| 1329 | - */ |
|
| 1330 | - public function get_address_confirmed( $context = 'view' ) { |
|
| 1331 | - return (bool) $this->get_prop( 'address_confirmed', $context ); |
|
| 1332 | - } |
|
| 1333 | - |
|
| 1334 | - /** |
|
| 1335 | - * Alias of self::get_address_confirmed(). |
|
| 1336 | - * |
|
| 1337 | - * @since 1.0.19 |
|
| 1338 | - * @param string $context View or edit context. |
|
| 1339 | - * @return bool |
|
| 1340 | - */ |
|
| 1341 | - public function get_user_address_confirmed( $context = 'view' ) { |
|
| 1342 | - return $this->get_address_confirmed( $context ); |
|
| 1343 | - } |
|
| 1344 | - |
|
| 1345 | - /** |
|
| 1346 | - * Alias of self::get_address(). |
|
| 1347 | - * |
|
| 1348 | - * @since 1.0.19 |
|
| 1349 | - * @param string $context View or edit context. |
|
| 1350 | - * @return bool |
|
| 1351 | - */ |
|
| 1352 | - public function get_customer_address_confirmed( $context = 'view' ) { |
|
| 1353 | - return $this->get_address_confirmed( $context ); |
|
| 1354 | - } |
|
| 1355 | - |
|
| 1356 | - /** |
|
| 1357 | - * Get the invoice subtotal. |
|
| 1358 | - * |
|
| 1359 | - * @since 1.0.19 |
|
| 1360 | - * @param string $context View or edit context. |
|
| 1361 | - * @return float |
|
| 1362 | - */ |
|
| 1363 | - public function get_subtotal( $context = 'view' ) { |
|
| 1236 | + * Alias of self::get_vat_rate(). |
|
| 1237 | + * |
|
| 1238 | + * @since 1.0.19 |
|
| 1239 | + * @param string $context View or edit context. |
|
| 1240 | + * @return string |
|
| 1241 | + */ |
|
| 1242 | + public function get_customer_vat_rate( $context = 'view' ) { |
|
| 1243 | + return $this->get_vat_rate( $context ); |
|
| 1244 | + } |
|
| 1245 | + |
|
| 1246 | + /** |
|
| 1247 | + * Get the customer's address. |
|
| 1248 | + * |
|
| 1249 | + * @since 1.0.19 |
|
| 1250 | + * @param string $context View or edit context. |
|
| 1251 | + * @return string |
|
| 1252 | + */ |
|
| 1253 | + public function get_address( $context = 'view' ) { |
|
| 1254 | + return $this->get_prop( 'address', $context ); |
|
| 1255 | + } |
|
| 1256 | + |
|
| 1257 | + /** |
|
| 1258 | + * Alias of self::get_address(). |
|
| 1259 | + * |
|
| 1260 | + * @since 1.0.19 |
|
| 1261 | + * @param string $context View or edit context. |
|
| 1262 | + * @return string |
|
| 1263 | + */ |
|
| 1264 | + public function get_user_address( $context = 'view' ) { |
|
| 1265 | + return $this->get_address( $context ); |
|
| 1266 | + } |
|
| 1267 | + |
|
| 1268 | + /** |
|
| 1269 | + * Alias of self::get_address(). |
|
| 1270 | + * |
|
| 1271 | + * @since 1.0.19 |
|
| 1272 | + * @param string $context View or edit context. |
|
| 1273 | + * @return string |
|
| 1274 | + */ |
|
| 1275 | + public function get_customer_address( $context = 'view' ) { |
|
| 1276 | + return $this->get_address( $context ); |
|
| 1277 | + } |
|
| 1278 | + |
|
| 1279 | + /** |
|
| 1280 | + * Get whether the customer has viewed the invoice or not. |
|
| 1281 | + * |
|
| 1282 | + * @since 1.0.19 |
|
| 1283 | + * @param string $context View or edit context. |
|
| 1284 | + * @return bool |
|
| 1285 | + */ |
|
| 1286 | + public function get_is_viewed( $context = 'view' ) { |
|
| 1287 | + return (bool) $this->get_prop( 'is_viewed', $context ); |
|
| 1288 | + } |
|
| 1289 | + |
|
| 1290 | + /** |
|
| 1291 | + * Get other recipients for invoice communications. |
|
| 1292 | + * |
|
| 1293 | + * @since 1.0.19 |
|
| 1294 | + * @param string $context View or edit context. |
|
| 1295 | + * @return bool |
|
| 1296 | + */ |
|
| 1297 | + public function get_email_cc( $context = 'view' ) { |
|
| 1298 | + return $this->get_prop( 'email_cc', $context ); |
|
| 1299 | + } |
|
| 1300 | + |
|
| 1301 | + /** |
|
| 1302 | + * Get invoice template. |
|
| 1303 | + * |
|
| 1304 | + * @since 1.0.19 |
|
| 1305 | + * @param string $context View or edit context. |
|
| 1306 | + * @return bool |
|
| 1307 | + */ |
|
| 1308 | + public function get_template( $context = 'view' ) { |
|
| 1309 | + return $this->get_prop( 'template', $context ); |
|
| 1310 | + } |
|
| 1311 | + |
|
| 1312 | + /** |
|
| 1313 | + * Get invoice source. |
|
| 1314 | + * |
|
| 1315 | + * @since 1.0.19 |
|
| 1316 | + * @param string $context View or edit context. |
|
| 1317 | + * @return bool |
|
| 1318 | + */ |
|
| 1319 | + public function get_created_via( $context = 'view' ) { |
|
| 1320 | + return $this->get_prop( 'created_via', $context ); |
|
| 1321 | + } |
|
| 1322 | + |
|
| 1323 | + /** |
|
| 1324 | + * Get whether the customer has confirmed their address. |
|
| 1325 | + * |
|
| 1326 | + * @since 1.0.19 |
|
| 1327 | + * @param string $context View or edit context. |
|
| 1328 | + * @return bool |
|
| 1329 | + */ |
|
| 1330 | + public function get_address_confirmed( $context = 'view' ) { |
|
| 1331 | + return (bool) $this->get_prop( 'address_confirmed', $context ); |
|
| 1332 | + } |
|
| 1333 | + |
|
| 1334 | + /** |
|
| 1335 | + * Alias of self::get_address_confirmed(). |
|
| 1336 | + * |
|
| 1337 | + * @since 1.0.19 |
|
| 1338 | + * @param string $context View or edit context. |
|
| 1339 | + * @return bool |
|
| 1340 | + */ |
|
| 1341 | + public function get_user_address_confirmed( $context = 'view' ) { |
|
| 1342 | + return $this->get_address_confirmed( $context ); |
|
| 1343 | + } |
|
| 1344 | + |
|
| 1345 | + /** |
|
| 1346 | + * Alias of self::get_address(). |
|
| 1347 | + * |
|
| 1348 | + * @since 1.0.19 |
|
| 1349 | + * @param string $context View or edit context. |
|
| 1350 | + * @return bool |
|
| 1351 | + */ |
|
| 1352 | + public function get_customer_address_confirmed( $context = 'view' ) { |
|
| 1353 | + return $this->get_address_confirmed( $context ); |
|
| 1354 | + } |
|
| 1355 | + |
|
| 1356 | + /** |
|
| 1357 | + * Get the invoice subtotal. |
|
| 1358 | + * |
|
| 1359 | + * @since 1.0.19 |
|
| 1360 | + * @param string $context View or edit context. |
|
| 1361 | + * @return float |
|
| 1362 | + */ |
|
| 1363 | + public function get_subtotal( $context = 'view' ) { |
|
| 1364 | 1364 | $subtotal = (float) $this->get_prop( 'subtotal', $context ); |
| 1365 | 1365 | |
| 1366 | 1366 | // Backwards compatibility. |
@@ -1372,192 +1372,192 @@ discard block |
||
| 1372 | 1372 | } |
| 1373 | 1373 | |
| 1374 | 1374 | /** |
| 1375 | - * Get the invoice discount total. |
|
| 1376 | - * |
|
| 1377 | - * @since 1.0.19 |
|
| 1378 | - * @param string $context View or edit context. |
|
| 1379 | - * @return float |
|
| 1380 | - */ |
|
| 1381 | - public function get_total_discount( $context = 'view' ) { |
|
| 1382 | - return wpinv_round_amount( wpinv_sanitize_amount( $this->get_prop( 'total_discount', $context ) ) ); |
|
| 1375 | + * Get the invoice discount total. |
|
| 1376 | + * |
|
| 1377 | + * @since 1.0.19 |
|
| 1378 | + * @param string $context View or edit context. |
|
| 1379 | + * @return float |
|
| 1380 | + */ |
|
| 1381 | + public function get_total_discount( $context = 'view' ) { |
|
| 1382 | + return wpinv_round_amount( wpinv_sanitize_amount( $this->get_prop( 'total_discount', $context ) ) ); |
|
| 1383 | 1383 | } |
| 1384 | 1384 | |
| 1385 | 1385 | /** |
| 1386 | - * Get the invoice tax total. |
|
| 1387 | - * |
|
| 1388 | - * @since 1.0.19 |
|
| 1389 | - * @param string $context View or edit context. |
|
| 1390 | - * @return float |
|
| 1391 | - */ |
|
| 1392 | - public function get_total_tax( $context = 'view' ) { |
|
| 1393 | - return wpinv_round_amount( wpinv_sanitize_amount( $this->get_prop( 'total_tax', $context ) ) ); |
|
| 1394 | - } |
|
| 1386 | + * Get the invoice tax total. |
|
| 1387 | + * |
|
| 1388 | + * @since 1.0.19 |
|
| 1389 | + * @param string $context View or edit context. |
|
| 1390 | + * @return float |
|
| 1391 | + */ |
|
| 1392 | + public function get_total_tax( $context = 'view' ) { |
|
| 1393 | + return wpinv_round_amount( wpinv_sanitize_amount( $this->get_prop( 'total_tax', $context ) ) ); |
|
| 1394 | + } |
|
| 1395 | 1395 | |
| 1396 | - /** |
|
| 1397 | - * @deprecated |
|
| 1398 | - */ |
|
| 1399 | - public function get_final_tax( $currency = false ) { |
|
| 1400 | - $tax = $this->get_total_tax(); |
|
| 1396 | + /** |
|
| 1397 | + * @deprecated |
|
| 1398 | + */ |
|
| 1399 | + public function get_final_tax( $currency = false ) { |
|
| 1400 | + $tax = $this->get_total_tax(); |
|
| 1401 | 1401 | |
| 1402 | 1402 | if ( $currency ) { |
| 1403 | - return wpinv_price( $tax, $this->get_currency() ); |
|
| 1403 | + return wpinv_price( $tax, $this->get_currency() ); |
|
| 1404 | 1404 | } |
| 1405 | 1405 | |
| 1406 | 1406 | return $tax; |
| 1407 | 1407 | } |
| 1408 | 1408 | |
| 1409 | 1409 | /** |
| 1410 | - * Get the invoice fees total. |
|
| 1411 | - * |
|
| 1412 | - * @since 1.0.19 |
|
| 1413 | - * @param string $context View or edit context. |
|
| 1414 | - * @return float |
|
| 1415 | - */ |
|
| 1416 | - public function get_total_fees( $context = 'view' ) { |
|
| 1417 | - return wpinv_round_amount( wpinv_sanitize_amount( $this->get_prop( 'total_fees', $context ) ) ); |
|
| 1410 | + * Get the invoice fees total. |
|
| 1411 | + * |
|
| 1412 | + * @since 1.0.19 |
|
| 1413 | + * @param string $context View or edit context. |
|
| 1414 | + * @return float |
|
| 1415 | + */ |
|
| 1416 | + public function get_total_fees( $context = 'view' ) { |
|
| 1417 | + return wpinv_round_amount( wpinv_sanitize_amount( $this->get_prop( 'total_fees', $context ) ) ); |
|
| 1418 | + } |
|
| 1419 | + |
|
| 1420 | + /** |
|
| 1421 | + * Alias for self::get_total_fees(). |
|
| 1422 | + * |
|
| 1423 | + * @since 1.0.19 |
|
| 1424 | + * @param string $context View or edit context. |
|
| 1425 | + * @return float |
|
| 1426 | + */ |
|
| 1427 | + public function get_fees_total( $context = 'view' ) { |
|
| 1428 | + return $this->get_total_fees( $context ); |
|
| 1418 | 1429 | } |
| 1419 | 1430 | |
| 1420 | 1431 | /** |
| 1421 | - * Alias for self::get_total_fees(). |
|
| 1422 | - * |
|
| 1423 | - * @since 1.0.19 |
|
| 1424 | - * @param string $context View or edit context. |
|
| 1425 | - * @return float |
|
| 1426 | - */ |
|
| 1427 | - public function get_fees_total( $context = 'view' ) { |
|
| 1428 | - return $this->get_total_fees( $context ); |
|
| 1432 | + * Get the invoice total. |
|
| 1433 | + * |
|
| 1434 | + * @since 1.0.19 |
|
| 1435 | + * @return float |
|
| 1436 | + */ |
|
| 1437 | + public function get_total( $context = 'view' ) { |
|
| 1438 | + return wpinv_round_amount( wpinv_sanitize_amount( $this->get_prop( 'total', $context ) ) ); |
|
| 1429 | 1439 | } |
| 1430 | 1440 | |
| 1431 | 1441 | /** |
| 1432 | - * Get the invoice total. |
|
| 1433 | - * |
|
| 1434 | - * @since 1.0.19 |
|
| 1442 | + * Retrieves the non-recurring total of items. |
|
| 1443 | + * |
|
| 1444 | + * @since 2.3.0 |
|
| 1435 | 1445 | * @return float |
| 1436 | - */ |
|
| 1437 | - public function get_total( $context = 'view' ) { |
|
| 1438 | - return wpinv_round_amount( wpinv_sanitize_amount( $this->get_prop( 'total', $context ) ) ); |
|
| 1439 | - } |
|
| 1440 | - |
|
| 1441 | - /** |
|
| 1442 | - * Retrieves the non-recurring total of items. |
|
| 1443 | - * |
|
| 1444 | - * @since 2.3.0 |
|
| 1445 | - * @return float |
|
| 1446 | - */ |
|
| 1447 | - public function get_non_recurring_total() { |
|
| 1448 | - |
|
| 1449 | - $subtotal = 0; |
|
| 1450 | - foreach ( $this->get_items() as $item ) { |
|
| 1451 | - if ( ! $item->is_recurring() ) { |
|
| 1452 | - $subtotal += $item->get_sub_total(); |
|
| 1453 | - } |
|
| 1454 | - } |
|
| 1455 | - |
|
| 1456 | - foreach ( $this->get_fees() as $fee ) { |
|
| 1457 | - if ( empty( $fee['recurring_fee'] ) ) { |
|
| 1458 | - $subtotal += wpinv_sanitize_amount( $fee['initial_fee'] ); |
|
| 1459 | - } |
|
| 1460 | - } |
|
| 1461 | - |
|
| 1462 | - $subtotal = wpinv_round_amount( wpinv_sanitize_amount( $subtotal ) ); |
|
| 1446 | + */ |
|
| 1447 | + public function get_non_recurring_total() { |
|
| 1448 | + |
|
| 1449 | + $subtotal = 0; |
|
| 1450 | + foreach ( $this->get_items() as $item ) { |
|
| 1451 | + if ( ! $item->is_recurring() ) { |
|
| 1452 | + $subtotal += $item->get_sub_total(); |
|
| 1453 | + } |
|
| 1454 | + } |
|
| 1455 | + |
|
| 1456 | + foreach ( $this->get_fees() as $fee ) { |
|
| 1457 | + if ( empty( $fee['recurring_fee'] ) ) { |
|
| 1458 | + $subtotal += wpinv_sanitize_amount( $fee['initial_fee'] ); |
|
| 1459 | + } |
|
| 1460 | + } |
|
| 1461 | + |
|
| 1462 | + $subtotal = wpinv_round_amount( wpinv_sanitize_amount( $subtotal ) ); |
|
| 1463 | 1463 | return apply_filters( 'wpinv_get_non_recurring_invoice_total', $subtotal, $this ); |
| 1464 | 1464 | |
| 1465 | 1465 | } |
| 1466 | 1466 | |
| 1467 | - /** |
|
| 1468 | - * Get the invoice totals. |
|
| 1469 | - * |
|
| 1470 | - * @since 1.0.19 |
|
| 1467 | + /** |
|
| 1468 | + * Get the invoice totals. |
|
| 1469 | + * |
|
| 1470 | + * @since 1.0.19 |
|
| 1471 | 1471 | * @return array |
| 1472 | - */ |
|
| 1473 | - public function get_totals() { |
|
| 1474 | - return $this->totals; |
|
| 1472 | + */ |
|
| 1473 | + public function get_totals() { |
|
| 1474 | + return $this->totals; |
|
| 1475 | 1475 | } |
| 1476 | 1476 | |
| 1477 | 1477 | /** |
| 1478 | - * Get the initial invoice total. |
|
| 1479 | - * |
|
| 1480 | - * @since 1.0.19 |
|
| 1478 | + * Get the initial invoice total. |
|
| 1479 | + * |
|
| 1480 | + * @since 1.0.19 |
|
| 1481 | 1481 | * @param string $context View or edit context. |
| 1482 | 1482 | * @return float |
| 1483 | - */ |
|
| 1483 | + */ |
|
| 1484 | 1484 | public function get_initial_total() { |
| 1485 | 1485 | |
| 1486 | - if ( empty( $this->totals ) ) { |
|
| 1487 | - $this->recalculate_total(); |
|
| 1488 | - } |
|
| 1486 | + if ( empty( $this->totals ) ) { |
|
| 1487 | + $this->recalculate_total(); |
|
| 1488 | + } |
|
| 1489 | 1489 | |
| 1490 | - $tax = $this->totals['tax']['initial']; |
|
| 1491 | - $fee = $this->totals['fee']['initial']; |
|
| 1492 | - $discount = $this->totals['discount']['initial']; |
|
| 1493 | - $subtotal = $this->totals['subtotal']['initial']; |
|
| 1494 | - $total = $tax + $fee - $discount + $subtotal; |
|
| 1490 | + $tax = $this->totals['tax']['initial']; |
|
| 1491 | + $fee = $this->totals['fee']['initial']; |
|
| 1492 | + $discount = $this->totals['discount']['initial']; |
|
| 1493 | + $subtotal = $this->totals['subtotal']['initial']; |
|
| 1494 | + $total = $tax + $fee - $discount + $subtotal; |
|
| 1495 | 1495 | |
| 1496 | - if ( 0 > $total ) { |
|
| 1497 | - $total = 0; |
|
| 1498 | - } |
|
| 1496 | + if ( 0 > $total ) { |
|
| 1497 | + $total = 0; |
|
| 1498 | + } |
|
| 1499 | 1499 | |
| 1500 | - $total = wpinv_round_amount( wpinv_sanitize_amount( $total ) ); |
|
| 1500 | + $total = wpinv_round_amount( wpinv_sanitize_amount( $total ) ); |
|
| 1501 | 1501 | return apply_filters( 'wpinv_get_initial_invoice_total', $total, $this ); |
| 1502 | - } |
|
| 1502 | + } |
|
| 1503 | 1503 | |
| 1504 | - /** |
|
| 1505 | - * Get the recurring invoice total. |
|
| 1506 | - * |
|
| 1507 | - * @since 1.0.19 |
|
| 1504 | + /** |
|
| 1505 | + * Get the recurring invoice total. |
|
| 1506 | + * |
|
| 1507 | + * @since 1.0.19 |
|
| 1508 | 1508 | * @param string $context View or edit context. |
| 1509 | 1509 | * @return float |
| 1510 | - */ |
|
| 1510 | + */ |
|
| 1511 | 1511 | public function get_recurring_total() { |
| 1512 | 1512 | |
| 1513 | - if ( empty( $this->totals ) ) { |
|
| 1514 | - $this->recalculate_total(); |
|
| 1515 | - } |
|
| 1513 | + if ( empty( $this->totals ) ) { |
|
| 1514 | + $this->recalculate_total(); |
|
| 1515 | + } |
|
| 1516 | 1516 | |
| 1517 | - $tax = $this->totals['tax']['recurring']; |
|
| 1518 | - $fee = $this->totals['fee']['recurring']; |
|
| 1519 | - $discount = $this->totals['discount']['recurring']; |
|
| 1520 | - $subtotal = $this->totals['subtotal']['recurring']; |
|
| 1521 | - $total = $tax + $fee - $discount + $subtotal; |
|
| 1517 | + $tax = $this->totals['tax']['recurring']; |
|
| 1518 | + $fee = $this->totals['fee']['recurring']; |
|
| 1519 | + $discount = $this->totals['discount']['recurring']; |
|
| 1520 | + $subtotal = $this->totals['subtotal']['recurring']; |
|
| 1521 | + $total = $tax + $fee - $discount + $subtotal; |
|
| 1522 | 1522 | |
| 1523 | - if ( 0 > $total ) { |
|
| 1524 | - $total = 0; |
|
| 1525 | - } |
|
| 1523 | + if ( 0 > $total ) { |
|
| 1524 | + $total = 0; |
|
| 1525 | + } |
|
| 1526 | 1526 | |
| 1527 | - $total = wpinv_round_amount( wpinv_sanitize_amount( $total ) ); |
|
| 1527 | + $total = wpinv_round_amount( wpinv_sanitize_amount( $total ) ); |
|
| 1528 | 1528 | return apply_filters( 'wpinv_get_recurring_invoice_total', $total, $this ); |
| 1529 | - } |
|
| 1529 | + } |
|
| 1530 | 1530 | |
| 1531 | - /** |
|
| 1532 | - * Returns recurring payment details. |
|
| 1533 | - * |
|
| 1534 | - * @since 1.0.19 |
|
| 1531 | + /** |
|
| 1532 | + * Returns recurring payment details. |
|
| 1533 | + * |
|
| 1534 | + * @since 1.0.19 |
|
| 1535 | 1535 | * @param string $field Optionally provide a field to return. |
| 1536 | - * @param string $currency Whether to include the currency. |
|
| 1536 | + * @param string $currency Whether to include the currency. |
|
| 1537 | 1537 | * @return float|string |
| 1538 | - */ |
|
| 1538 | + */ |
|
| 1539 | 1539 | public function get_recurring_details( $field = '', $currency = false ) { |
| 1540 | 1540 | |
| 1541 | - // Maybe recalculate totals. |
|
| 1542 | - if ( empty( $this->totals ) ) { |
|
| 1543 | - $this->recalculate_total(); |
|
| 1544 | - } |
|
| 1541 | + // Maybe recalculate totals. |
|
| 1542 | + if ( empty( $this->totals ) ) { |
|
| 1543 | + $this->recalculate_total(); |
|
| 1544 | + } |
|
| 1545 | 1545 | |
| 1546 | - // Prepare recurring totals. |
|
| 1546 | + // Prepare recurring totals. |
|
| 1547 | 1547 | $data = apply_filters( |
| 1548 | - 'wpinv_get_invoice_recurring_details', |
|
| 1549 | - array( |
|
| 1550 | - 'cart_details' => $this->get_cart_details(), |
|
| 1551 | - 'subtotal' => $this->totals['subtotal']['recurring'], |
|
| 1552 | - 'discount' => $this->totals['discount']['recurring'], |
|
| 1553 | - 'tax' => $this->totals['tax']['recurring'], |
|
| 1554 | - 'fee' => $this->totals['fee']['recurring'], |
|
| 1555 | - 'total' => $this->get_recurring_total(), |
|
| 1556 | - ), |
|
| 1557 | - $this, |
|
| 1558 | - $field, |
|
| 1559 | - $currency |
|
| 1560 | - ); |
|
| 1548 | + 'wpinv_get_invoice_recurring_details', |
|
| 1549 | + array( |
|
| 1550 | + 'cart_details' => $this->get_cart_details(), |
|
| 1551 | + 'subtotal' => $this->totals['subtotal']['recurring'], |
|
| 1552 | + 'discount' => $this->totals['discount']['recurring'], |
|
| 1553 | + 'tax' => $this->totals['tax']['recurring'], |
|
| 1554 | + 'fee' => $this->totals['fee']['recurring'], |
|
| 1555 | + 'total' => $this->get_recurring_total(), |
|
| 1556 | + ), |
|
| 1557 | + $this, |
|
| 1558 | + $field, |
|
| 1559 | + $currency |
|
| 1560 | + ); |
|
| 1561 | 1561 | |
| 1562 | 1562 | if ( isset( $data[$field] ) ) { |
| 1563 | 1563 | return ( $currency ? wpinv_price( $data[$field], $this->get_currency() ) : $data[$field] ); |
@@ -1567,166 +1567,166 @@ discard block |
||
| 1567 | 1567 | } |
| 1568 | 1568 | |
| 1569 | 1569 | /** |
| 1570 | - * Get the invoice fees. |
|
| 1571 | - * |
|
| 1572 | - * @since 1.0.19 |
|
| 1573 | - * @param string $context View or edit context. |
|
| 1574 | - * @return array |
|
| 1575 | - */ |
|
| 1576 | - public function get_fees( $context = 'view' ) { |
|
| 1577 | - return wpinv_parse_list( $this->get_prop( 'fees', $context ) ); |
|
| 1570 | + * Get the invoice fees. |
|
| 1571 | + * |
|
| 1572 | + * @since 1.0.19 |
|
| 1573 | + * @param string $context View or edit context. |
|
| 1574 | + * @return array |
|
| 1575 | + */ |
|
| 1576 | + public function get_fees( $context = 'view' ) { |
|
| 1577 | + return wpinv_parse_list( $this->get_prop( 'fees', $context ) ); |
|
| 1578 | 1578 | } |
| 1579 | 1579 | |
| 1580 | 1580 | /** |
| 1581 | - * Get the invoice discounts. |
|
| 1582 | - * |
|
| 1583 | - * @since 1.0.19 |
|
| 1584 | - * @param string $context View or edit context. |
|
| 1585 | - * @return array |
|
| 1586 | - */ |
|
| 1587 | - public function get_discounts( $context = 'view' ) { |
|
| 1588 | - return wpinv_parse_list( $this->get_prop( 'discounts', $context ) ); |
|
| 1581 | + * Get the invoice discounts. |
|
| 1582 | + * |
|
| 1583 | + * @since 1.0.19 |
|
| 1584 | + * @param string $context View or edit context. |
|
| 1585 | + * @return array |
|
| 1586 | + */ |
|
| 1587 | + public function get_discounts( $context = 'view' ) { |
|
| 1588 | + return wpinv_parse_list( $this->get_prop( 'discounts', $context ) ); |
|
| 1589 | 1589 | } |
| 1590 | 1590 | |
| 1591 | 1591 | /** |
| 1592 | - * Get the invoice taxes. |
|
| 1593 | - * |
|
| 1594 | - * @since 1.0.19 |
|
| 1595 | - * @param string $context View or edit context. |
|
| 1596 | - * @return array |
|
| 1597 | - */ |
|
| 1598 | - public function get_taxes( $context = 'view' ) { |
|
| 1599 | - return wpinv_parse_list( $this->get_prop( 'taxes', $context ) ); |
|
| 1592 | + * Get the invoice taxes. |
|
| 1593 | + * |
|
| 1594 | + * @since 1.0.19 |
|
| 1595 | + * @param string $context View or edit context. |
|
| 1596 | + * @return array |
|
| 1597 | + */ |
|
| 1598 | + public function get_taxes( $context = 'view' ) { |
|
| 1599 | + return wpinv_parse_list( $this->get_prop( 'taxes', $context ) ); |
|
| 1600 | 1600 | } |
| 1601 | 1601 | |
| 1602 | 1602 | /** |
| 1603 | - * Get the invoice items. |
|
| 1604 | - * |
|
| 1605 | - * @since 1.0.19 |
|
| 1606 | - * @param string $context View or edit context. |
|
| 1607 | - * @return GetPaid_Form_Item[] |
|
| 1608 | - */ |
|
| 1609 | - public function get_items( $context = 'view' ) { |
|
| 1603 | + * Get the invoice items. |
|
| 1604 | + * |
|
| 1605 | + * @since 1.0.19 |
|
| 1606 | + * @param string $context View or edit context. |
|
| 1607 | + * @return GetPaid_Form_Item[] |
|
| 1608 | + */ |
|
| 1609 | + public function get_items( $context = 'view' ) { |
|
| 1610 | 1610 | return $this->get_prop( 'items', $context ); |
| 1611 | - } |
|
| 1611 | + } |
|
| 1612 | 1612 | |
| 1613 | - /** |
|
| 1614 | - * Get the invoice item ids. |
|
| 1615 | - * |
|
| 1616 | - * @since 1.0.19 |
|
| 1617 | - * @return string |
|
| 1618 | - */ |
|
| 1619 | - public function get_item_ids() { |
|
| 1620 | - return implode( ', ', wp_list_pluck( $this->get_cart_details(), 'item_id' ) ); |
|
| 1613 | + /** |
|
| 1614 | + * Get the invoice item ids. |
|
| 1615 | + * |
|
| 1616 | + * @since 1.0.19 |
|
| 1617 | + * @return string |
|
| 1618 | + */ |
|
| 1619 | + public function get_item_ids() { |
|
| 1620 | + return implode( ', ', wp_list_pluck( $this->get_cart_details(), 'item_id' ) ); |
|
| 1621 | 1621 | } |
| 1622 | 1622 | |
| 1623 | 1623 | /** |
| 1624 | - * Get the invoice's payment form. |
|
| 1625 | - * |
|
| 1626 | - * @since 1.0.19 |
|
| 1627 | - * @param string $context View or edit context. |
|
| 1628 | - * @return int |
|
| 1629 | - */ |
|
| 1630 | - public function get_payment_form( $context = 'view' ) { |
|
| 1631 | - return intval( $this->get_prop( 'payment_form', $context ) ); |
|
| 1624 | + * Get the invoice's payment form. |
|
| 1625 | + * |
|
| 1626 | + * @since 1.0.19 |
|
| 1627 | + * @param string $context View or edit context. |
|
| 1628 | + * @return int |
|
| 1629 | + */ |
|
| 1630 | + public function get_payment_form( $context = 'view' ) { |
|
| 1631 | + return intval( $this->get_prop( 'payment_form', $context ) ); |
|
| 1632 | 1632 | } |
| 1633 | 1633 | |
| 1634 | 1634 | /** |
| 1635 | - * Get the invoice's submission id. |
|
| 1636 | - * |
|
| 1637 | - * @since 1.0.19 |
|
| 1638 | - * @param string $context View or edit context. |
|
| 1639 | - * @return string |
|
| 1640 | - */ |
|
| 1641 | - public function get_submission_id( $context = 'view' ) { |
|
| 1642 | - return $this->get_prop( 'submission_id', $context ); |
|
| 1635 | + * Get the invoice's submission id. |
|
| 1636 | + * |
|
| 1637 | + * @since 1.0.19 |
|
| 1638 | + * @param string $context View or edit context. |
|
| 1639 | + * @return string |
|
| 1640 | + */ |
|
| 1641 | + public function get_submission_id( $context = 'view' ) { |
|
| 1642 | + return $this->get_prop( 'submission_id', $context ); |
|
| 1643 | 1643 | } |
| 1644 | 1644 | |
| 1645 | 1645 | /** |
| 1646 | - * Get the invoice's discount code. |
|
| 1647 | - * |
|
| 1648 | - * @since 1.0.19 |
|
| 1649 | - * @param string $context View or edit context. |
|
| 1650 | - * @return string |
|
| 1651 | - */ |
|
| 1652 | - public function get_discount_code( $context = 'view' ) { |
|
| 1653 | - return $this->get_prop( 'discount_code', $context ); |
|
| 1646 | + * Get the invoice's discount code. |
|
| 1647 | + * |
|
| 1648 | + * @since 1.0.19 |
|
| 1649 | + * @param string $context View or edit context. |
|
| 1650 | + * @return string |
|
| 1651 | + */ |
|
| 1652 | + public function get_discount_code( $context = 'view' ) { |
|
| 1653 | + return $this->get_prop( 'discount_code', $context ); |
|
| 1654 | 1654 | } |
| 1655 | 1655 | |
| 1656 | 1656 | /** |
| 1657 | - * Get the invoice's gateway. |
|
| 1658 | - * |
|
| 1659 | - * @since 1.0.19 |
|
| 1660 | - * @param string $context View or edit context. |
|
| 1661 | - * @return string |
|
| 1662 | - */ |
|
| 1663 | - public function get_gateway( $context = 'view' ) { |
|
| 1664 | - return $this->get_prop( 'gateway', $context ); |
|
| 1657 | + * Get the invoice's gateway. |
|
| 1658 | + * |
|
| 1659 | + * @since 1.0.19 |
|
| 1660 | + * @param string $context View or edit context. |
|
| 1661 | + * @return string |
|
| 1662 | + */ |
|
| 1663 | + public function get_gateway( $context = 'view' ) { |
|
| 1664 | + return $this->get_prop( 'gateway', $context ); |
|
| 1665 | 1665 | } |
| 1666 | 1666 | |
| 1667 | 1667 | /** |
| 1668 | - * Get the invoice's gateway display title. |
|
| 1669 | - * |
|
| 1670 | - * @since 1.0.19 |
|
| 1671 | - * @return string |
|
| 1672 | - */ |
|
| 1668 | + * Get the invoice's gateway display title. |
|
| 1669 | + * |
|
| 1670 | + * @since 1.0.19 |
|
| 1671 | + * @return string |
|
| 1672 | + */ |
|
| 1673 | 1673 | public function get_gateway_title() { |
| 1674 | 1674 | $title = wpinv_get_gateway_checkout_label( $this->get_gateway() ); |
| 1675 | 1675 | return apply_filters( 'wpinv_gateway_title', $title, $this->get_id(), $this ); |
| 1676 | 1676 | } |
| 1677 | 1677 | |
| 1678 | 1678 | /** |
| 1679 | - * Get the invoice's transaction id. |
|
| 1680 | - * |
|
| 1681 | - * @since 1.0.19 |
|
| 1682 | - * @param string $context View or edit context. |
|
| 1683 | - * @return string |
|
| 1684 | - */ |
|
| 1685 | - public function get_transaction_id( $context = 'view' ) { |
|
| 1686 | - return $this->get_prop( 'transaction_id', $context ); |
|
| 1679 | + * Get the invoice's transaction id. |
|
| 1680 | + * |
|
| 1681 | + * @since 1.0.19 |
|
| 1682 | + * @param string $context View or edit context. |
|
| 1683 | + * @return string |
|
| 1684 | + */ |
|
| 1685 | + public function get_transaction_id( $context = 'view' ) { |
|
| 1686 | + return $this->get_prop( 'transaction_id', $context ); |
|
| 1687 | 1687 | } |
| 1688 | 1688 | |
| 1689 | 1689 | /** |
| 1690 | - * Get the invoice's currency. |
|
| 1691 | - * |
|
| 1692 | - * @since 1.0.19 |
|
| 1693 | - * @param string $context View or edit context. |
|
| 1694 | - * @return string |
|
| 1695 | - */ |
|
| 1696 | - public function get_currency( $context = 'view' ) { |
|
| 1690 | + * Get the invoice's currency. |
|
| 1691 | + * |
|
| 1692 | + * @since 1.0.19 |
|
| 1693 | + * @param string $context View or edit context. |
|
| 1694 | + * @return string |
|
| 1695 | + */ |
|
| 1696 | + public function get_currency( $context = 'view' ) { |
|
| 1697 | 1697 | $currency = $this->get_prop( 'currency', $context ); |
| 1698 | 1698 | return empty( $currency ) ? wpinv_get_currency() : $currency; |
| 1699 | 1699 | } |
| 1700 | 1700 | |
| 1701 | 1701 | /** |
| 1702 | - * Checks if we are charging taxes for this invoice. |
|
| 1703 | - * |
|
| 1704 | - * @since 1.0.19 |
|
| 1705 | - * @param string $context View or edit context. |
|
| 1706 | - * @return bool |
|
| 1707 | - */ |
|
| 1708 | - public function get_disable_taxes( $context = 'view' ) { |
|
| 1702 | + * Checks if we are charging taxes for this invoice. |
|
| 1703 | + * |
|
| 1704 | + * @since 1.0.19 |
|
| 1705 | + * @param string $context View or edit context. |
|
| 1706 | + * @return bool |
|
| 1707 | + */ |
|
| 1708 | + public function get_disable_taxes( $context = 'view' ) { |
|
| 1709 | 1709 | return (bool) $this->get_prop( 'disable_taxes', $context ); |
| 1710 | 1710 | } |
| 1711 | 1711 | |
| 1712 | 1712 | /** |
| 1713 | - * Retrieves the subscription id for an invoice. |
|
| 1714 | - * |
|
| 1715 | - * @since 1.0.19 |
|
| 1716 | - * @param string $context View or edit context. |
|
| 1717 | - * @return int |
|
| 1718 | - */ |
|
| 1713 | + * Retrieves the subscription id for an invoice. |
|
| 1714 | + * |
|
| 1715 | + * @since 1.0.19 |
|
| 1716 | + * @param string $context View or edit context. |
|
| 1717 | + * @return int |
|
| 1718 | + */ |
|
| 1719 | 1719 | public function get_subscription_id( $context = 'view' ) { |
| 1720 | - return $this->is_renewal() ? $this->get_parent()->get_subscription_id( $context ) : $this->get_prop( 'subscription_id', $context ); |
|
| 1721 | - } |
|
| 1722 | - |
|
| 1723 | - /** |
|
| 1724 | - * Retrieves the remote subscription id for an invoice. |
|
| 1725 | - * |
|
| 1726 | - * @since 1.0.19 |
|
| 1727 | - * @param string $context View or edit context. |
|
| 1728 | - * @return int |
|
| 1729 | - */ |
|
| 1720 | + return $this->is_renewal() ? $this->get_parent()->get_subscription_id( $context ) : $this->get_prop( 'subscription_id', $context ); |
|
| 1721 | + } |
|
| 1722 | + |
|
| 1723 | + /** |
|
| 1724 | + * Retrieves the remote subscription id for an invoice. |
|
| 1725 | + * |
|
| 1726 | + * @since 1.0.19 |
|
| 1727 | + * @param string $context View or edit context. |
|
| 1728 | + * @return int |
|
| 1729 | + */ |
|
| 1730 | 1730 | public function get_remote_subscription_id( $context = 'view' ) { |
| 1731 | 1731 | $subscription_id = $this->get_prop( 'remote_subscription_id', $context ); |
| 1732 | 1732 | |
@@ -1739,12 +1739,12 @@ discard block |
||
| 1739 | 1739 | } |
| 1740 | 1740 | |
| 1741 | 1741 | /** |
| 1742 | - * Retrieves the payment meta for an invoice. |
|
| 1743 | - * |
|
| 1744 | - * @since 1.0.19 |
|
| 1745 | - * @param string $context View or edit context. |
|
| 1746 | - * @return array |
|
| 1747 | - */ |
|
| 1742 | + * Retrieves the payment meta for an invoice. |
|
| 1743 | + * |
|
| 1744 | + * @since 1.0.19 |
|
| 1745 | + * @param string $context View or edit context. |
|
| 1746 | + * @return array |
|
| 1747 | + */ |
|
| 1748 | 1748 | public function get_payment_meta( $context = 'view' ) { |
| 1749 | 1749 | |
| 1750 | 1750 | return array( |
@@ -1764,31 +1764,31 @@ discard block |
||
| 1764 | 1764 | } |
| 1765 | 1765 | |
| 1766 | 1766 | /** |
| 1767 | - * Retrieves the cart details for an invoice. |
|
| 1768 | - * |
|
| 1769 | - * @since 1.0.19 |
|
| 1770 | - * @return array |
|
| 1771 | - */ |
|
| 1767 | + * Retrieves the cart details for an invoice. |
|
| 1768 | + * |
|
| 1769 | + * @since 1.0.19 |
|
| 1770 | + * @return array |
|
| 1771 | + */ |
|
| 1772 | 1772 | public function get_cart_details() { |
| 1773 | 1773 | $items = $this->get_items(); |
| 1774 | 1774 | $cart_details = array(); |
| 1775 | 1775 | |
| 1776 | 1776 | foreach ( $items as $item ) { |
| 1777 | - $item->invoice_id = $this->get_id(); |
|
| 1777 | + $item->invoice_id = $this->get_id(); |
|
| 1778 | 1778 | $cart_details[] = $item->prepare_data_for_saving(); |
| 1779 | 1779 | } |
| 1780 | 1780 | |
| 1781 | 1781 | return $cart_details; |
| 1782 | - } |
|
| 1782 | + } |
|
| 1783 | 1783 | |
| 1784 | - /** |
|
| 1785 | - * Retrieves the recurring item. |
|
| 1786 | - * |
|
| 1787 | - * @return null|GetPaid_Form_Item|int |
|
| 1788 | - */ |
|
| 1789 | - public function get_recurring( $object = false ) { |
|
| 1784 | + /** |
|
| 1785 | + * Retrieves the recurring item. |
|
| 1786 | + * |
|
| 1787 | + * @return null|GetPaid_Form_Item|int |
|
| 1788 | + */ |
|
| 1789 | + public function get_recurring( $object = false ) { |
|
| 1790 | 1790 | |
| 1791 | - // Are we returning an object? |
|
| 1791 | + // Are we returning an object? |
|
| 1792 | 1792 | if ( $object ) { |
| 1793 | 1793 | return $this->get_item( $this->recurring_item ); |
| 1794 | 1794 | } |
@@ -1796,114 +1796,114 @@ discard block |
||
| 1796 | 1796 | return $this->recurring_item; |
| 1797 | 1797 | } |
| 1798 | 1798 | |
| 1799 | - /** |
|
| 1800 | - * Retrieves the subscription name. |
|
| 1801 | - * |
|
| 1802 | - * @since 1.0.19 |
|
| 1803 | - * @return string |
|
| 1804 | - */ |
|
| 1805 | - public function get_subscription_name() { |
|
| 1799 | + /** |
|
| 1800 | + * Retrieves the subscription name. |
|
| 1801 | + * |
|
| 1802 | + * @since 1.0.19 |
|
| 1803 | + * @return string |
|
| 1804 | + */ |
|
| 1805 | + public function get_subscription_name() { |
|
| 1806 | 1806 | |
| 1807 | - // Retrieve the recurring name |
|
| 1807 | + // Retrieve the recurring name |
|
| 1808 | 1808 | $item = $this->get_recurring( true ); |
| 1809 | 1809 | |
| 1810 | - // Abort if it does not exist. |
|
| 1810 | + // Abort if it does not exist. |
|
| 1811 | 1811 | if ( empty( $item ) ) { |
| 1812 | 1812 | return ''; |
| 1813 | 1813 | } |
| 1814 | 1814 | |
| 1815 | - // Return the item name. |
|
| 1815 | + // Return the item name. |
|
| 1816 | 1816 | return apply_filters( 'wpinv_invoice_get_subscription_name', $item->get_name(), $this ); |
| 1817 | - } |
|
| 1818 | - |
|
| 1819 | - /** |
|
| 1820 | - * Retrieves the view url. |
|
| 1821 | - * |
|
| 1822 | - * @since 1.0.19 |
|
| 1823 | - * @return string |
|
| 1824 | - */ |
|
| 1825 | - public function get_view_url() { |
|
| 1817 | + } |
|
| 1818 | + |
|
| 1819 | + /** |
|
| 1820 | + * Retrieves the view url. |
|
| 1821 | + * |
|
| 1822 | + * @since 1.0.19 |
|
| 1823 | + * @return string |
|
| 1824 | + */ |
|
| 1825 | + public function get_view_url() { |
|
| 1826 | 1826 | $invoice_url = get_permalink( $this->get_id() ); |
| 1827 | - $invoice_url = add_query_arg( 'invoice_key', $this->get_key(), $invoice_url ); |
|
| 1827 | + $invoice_url = add_query_arg( 'invoice_key', $this->get_key(), $invoice_url ); |
|
| 1828 | 1828 | return apply_filters( 'wpinv_get_view_url', $invoice_url, $this ); |
| 1829 | - } |
|
| 1829 | + } |
|
| 1830 | 1830 | |
| 1831 | - /** |
|
| 1832 | - * Retrieves the payment url. |
|
| 1833 | - * |
|
| 1834 | - * @since 1.0.19 |
|
| 1835 | - * @return string |
|
| 1836 | - */ |
|
| 1837 | - public function get_checkout_payment_url( $deprecated = false, $secret = false ) { |
|
| 1831 | + /** |
|
| 1832 | + * Retrieves the payment url. |
|
| 1833 | + * |
|
| 1834 | + * @since 1.0.19 |
|
| 1835 | + * @return string |
|
| 1836 | + */ |
|
| 1837 | + public function get_checkout_payment_url( $deprecated = false, $secret = false ) { |
|
| 1838 | 1838 | |
| 1839 | - // Retrieve the checkout url. |
|
| 1839 | + // Retrieve the checkout url. |
|
| 1840 | 1840 | $pay_url = wpinv_get_checkout_uri(); |
| 1841 | 1841 | |
| 1842 | - // Maybe force ssl. |
|
| 1842 | + // Maybe force ssl. |
|
| 1843 | 1843 | if ( is_ssl() ) { |
| 1844 | 1844 | $pay_url = str_replace( 'http:', 'https:', $pay_url ); |
| 1845 | 1845 | } |
| 1846 | 1846 | |
| 1847 | - // Add the invoice key. |
|
| 1848 | - $pay_url = add_query_arg( 'invoice_key', $this->get_key(), $pay_url ); |
|
| 1847 | + // Add the invoice key. |
|
| 1848 | + $pay_url = add_query_arg( 'invoice_key', $this->get_key(), $pay_url ); |
|
| 1849 | 1849 | |
| 1850 | - // (Maybe?) add a secret |
|
| 1850 | + // (Maybe?) add a secret |
|
| 1851 | 1851 | if ( $secret ) { |
| 1852 | 1852 | $pay_url = add_query_arg( array( '_wpipay' => md5( $this->get_user_id() . '::' . $this->get_email() . '::' . $this->get_key() ) ), $pay_url ); |
| 1853 | 1853 | } |
| 1854 | 1854 | |
| 1855 | 1855 | return apply_filters( 'wpinv_get_checkout_payment_url', $pay_url, $this, $deprecated, $secret ); |
| 1856 | - } |
|
| 1856 | + } |
|
| 1857 | 1857 | |
| 1858 | - /** |
|
| 1859 | - * Retrieves the receipt url. |
|
| 1860 | - * |
|
| 1861 | - * @since 1.0.19 |
|
| 1862 | - * @return string |
|
| 1863 | - */ |
|
| 1864 | - public function get_receipt_url() { |
|
| 1865 | - |
|
| 1866 | - // Retrieve the checkout url. |
|
| 1858 | + /** |
|
| 1859 | + * Retrieves the receipt url. |
|
| 1860 | + * |
|
| 1861 | + * @since 1.0.19 |
|
| 1862 | + * @return string |
|
| 1863 | + */ |
|
| 1864 | + public function get_receipt_url() { |
|
| 1865 | + |
|
| 1866 | + // Retrieve the checkout url. |
|
| 1867 | 1867 | $receipt_url = wpinv_get_success_page_uri(); |
| 1868 | 1868 | |
| 1869 | - // Maybe force ssl. |
|
| 1869 | + // Maybe force ssl. |
|
| 1870 | 1870 | if ( is_ssl() ) { |
| 1871 | 1871 | $receipt_url = str_replace( 'http:', 'https:', $receipt_url ); |
| 1872 | 1872 | } |
| 1873 | 1873 | |
| 1874 | - // Add the invoice key. |
|
| 1875 | - $receipt_url = add_query_arg( 'invoice_key', $this->get_key(), $receipt_url ); |
|
| 1874 | + // Add the invoice key. |
|
| 1875 | + $receipt_url = add_query_arg( 'invoice_key', $this->get_key(), $receipt_url ); |
|
| 1876 | 1876 | |
| 1877 | 1877 | return apply_filters( 'getpaid_get_invoice_receipt_url', $receipt_url, $this ); |
| 1878 | - } |
|
| 1878 | + } |
|
| 1879 | 1879 | |
| 1880 | - /** |
|
| 1881 | - * Retrieves the default status. |
|
| 1882 | - * |
|
| 1883 | - * @since 1.0.19 |
|
| 1884 | - * @return string |
|
| 1885 | - */ |
|
| 1886 | - public function get_default_status() { |
|
| 1887 | - |
|
| 1888 | - $type = $this->get_type(); |
|
| 1889 | - $status = "wpi-$type-pending"; |
|
| 1890 | - return str_replace( '-invoice', '', $status ); |
|
| 1891 | - |
|
| 1892 | - } |
|
| 1893 | - |
|
| 1894 | - /** |
|
| 1895 | - * Magic method for accessing invoice properties. |
|
| 1896 | - * |
|
| 1897 | - * @since 1.0.15 |
|
| 1898 | - * @access public |
|
| 1899 | - * |
|
| 1900 | - * @param string $key Discount data to retrieve |
|
| 1901 | - * @param string $context View or edit context. |
|
| 1902 | - * @return mixed Value of the given invoice property (if set). |
|
| 1903 | - */ |
|
| 1904 | - public function get( $key, $context = 'view' ) { |
|
| 1880 | + /** |
|
| 1881 | + * Retrieves the default status. |
|
| 1882 | + * |
|
| 1883 | + * @since 1.0.19 |
|
| 1884 | + * @return string |
|
| 1885 | + */ |
|
| 1886 | + public function get_default_status() { |
|
| 1887 | + |
|
| 1888 | + $type = $this->get_type(); |
|
| 1889 | + $status = "wpi-$type-pending"; |
|
| 1890 | + return str_replace( '-invoice', '', $status ); |
|
| 1891 | + |
|
| 1892 | + } |
|
| 1893 | + |
|
| 1894 | + /** |
|
| 1895 | + * Magic method for accessing invoice properties. |
|
| 1896 | + * |
|
| 1897 | + * @since 1.0.15 |
|
| 1898 | + * @access public |
|
| 1899 | + * |
|
| 1900 | + * @param string $key Discount data to retrieve |
|
| 1901 | + * @param string $context View or edit context. |
|
| 1902 | + * @return mixed Value of the given invoice property (if set). |
|
| 1903 | + */ |
|
| 1904 | + public function get( $key, $context = 'view' ) { |
|
| 1905 | 1905 | return $this->get_prop( $key, $context ); |
| 1906 | - } |
|
| 1906 | + } |
|
| 1907 | 1907 | |
| 1908 | 1908 | /* |
| 1909 | 1909 | |-------------------------------------------------------------------------- |
@@ -1916,130 +1916,130 @@ discard block |
||
| 1916 | 1916 | */ |
| 1917 | 1917 | |
| 1918 | 1918 | /** |
| 1919 | - * Magic method for setting invoice properties. |
|
| 1920 | - * |
|
| 1921 | - * @since 1.0.19 |
|
| 1922 | - * @access public |
|
| 1923 | - * |
|
| 1924 | - * @param string $key Discount data to retrieve |
|
| 1925 | - * @param mixed $value new value. |
|
| 1926 | - * @return mixed Value of the given invoice property (if set). |
|
| 1927 | - */ |
|
| 1928 | - public function set( $key, $value ) { |
|
| 1919 | + * Magic method for setting invoice properties. |
|
| 1920 | + * |
|
| 1921 | + * @since 1.0.19 |
|
| 1922 | + * @access public |
|
| 1923 | + * |
|
| 1924 | + * @param string $key Discount data to retrieve |
|
| 1925 | + * @param mixed $value new value. |
|
| 1926 | + * @return mixed Value of the given invoice property (if set). |
|
| 1927 | + */ |
|
| 1928 | + public function set( $key, $value ) { |
|
| 1929 | 1929 | |
| 1930 | 1930 | $setter = "set_$key"; |
| 1931 | 1931 | if ( is_callable( array( $this, $setter ) ) ) { |
| 1932 | 1932 | $this->{$setter}( $value ); |
| 1933 | 1933 | } |
| 1934 | 1934 | |
| 1935 | - } |
|
| 1935 | + } |
|
| 1936 | 1936 | |
| 1937 | - /** |
|
| 1938 | - * Sets item status. |
|
| 1939 | - * |
|
| 1940 | - * @since 1.0.19 |
|
| 1941 | - * @param string $new_status New status. |
|
| 1942 | - * @param string $note Optional note to add. |
|
| 1943 | - * @param bool $manual_update Is this a manual status change?. |
|
| 1944 | - * @return array details of change. |
|
| 1945 | - */ |
|
| 1946 | - public function set_status( $new_status, $note = '', $manual_update = false ) { |
|
| 1947 | - $old_status = $this->get_status(); |
|
| 1937 | + /** |
|
| 1938 | + * Sets item status. |
|
| 1939 | + * |
|
| 1940 | + * @since 1.0.19 |
|
| 1941 | + * @param string $new_status New status. |
|
| 1942 | + * @param string $note Optional note to add. |
|
| 1943 | + * @param bool $manual_update Is this a manual status change?. |
|
| 1944 | + * @return array details of change. |
|
| 1945 | + */ |
|
| 1946 | + public function set_status( $new_status, $note = '', $manual_update = false ) { |
|
| 1947 | + $old_status = $this->get_status(); |
|
| 1948 | 1948 | |
| 1949 | - $statuses = $this->get_all_statuses(); |
|
| 1949 | + $statuses = $this->get_all_statuses(); |
|
| 1950 | 1950 | |
| 1951 | - if ( isset( $statuses[ 'draft' ] ) ) { |
|
| 1952 | - unset( $statuses[ 'draft' ] ); |
|
| 1953 | - } |
|
| 1951 | + if ( isset( $statuses[ 'draft' ] ) ) { |
|
| 1952 | + unset( $statuses[ 'draft' ] ); |
|
| 1953 | + } |
|
| 1954 | 1954 | |
| 1955 | - $this->set_prop( 'status', $new_status ); |
|
| 1955 | + $this->set_prop( 'status', $new_status ); |
|
| 1956 | 1956 | |
| 1957 | - // If setting the status, ensure it's set to a valid status. |
|
| 1958 | - if ( true === $this->object_read ) { |
|
| 1957 | + // If setting the status, ensure it's set to a valid status. |
|
| 1958 | + if ( true === $this->object_read ) { |
|
| 1959 | 1959 | |
| 1960 | - // Only allow valid new status. |
|
| 1961 | - if ( ! array_key_exists( $new_status, $statuses ) ) { |
|
| 1962 | - $new_status = $this->get_default_status(); |
|
| 1963 | - } |
|
| 1960 | + // Only allow valid new status. |
|
| 1961 | + if ( ! array_key_exists( $new_status, $statuses ) ) { |
|
| 1962 | + $new_status = $this->get_default_status(); |
|
| 1963 | + } |
|
| 1964 | 1964 | |
| 1965 | - // If the old status is set but unknown (e.g. draft) assume its pending for action usage. |
|
| 1966 | - if ( $old_status && ! array_key_exists( $new_status, $statuses ) ) { |
|
| 1967 | - $old_status = $this->get_default_status(); |
|
| 1968 | - } |
|
| 1965 | + // If the old status is set but unknown (e.g. draft) assume its pending for action usage. |
|
| 1966 | + if ( $old_status && ! array_key_exists( $new_status, $statuses ) ) { |
|
| 1967 | + $old_status = $this->get_default_status(); |
|
| 1968 | + } |
|
| 1969 | 1969 | |
| 1970 | - // Paid - Renewal (i.e when duplicating a parent invoice ) |
|
| 1971 | - if ( $new_status == 'wpi-pending' && $old_status == 'publish' && ! $this->get_id() ) { |
|
| 1972 | - $old_status = 'wpi-pending'; |
|
| 1973 | - } |
|
| 1970 | + // Paid - Renewal (i.e when duplicating a parent invoice ) |
|
| 1971 | + if ( $new_status == 'wpi-pending' && $old_status == 'publish' && ! $this->get_id() ) { |
|
| 1972 | + $old_status = 'wpi-pending'; |
|
| 1973 | + } |
|
| 1974 | 1974 | |
| 1975 | - if ( $old_status !== $new_status ) { |
|
| 1976 | - $this->status_transition = array( |
|
| 1977 | - 'from' => ! empty( $this->status_transition['from'] ) ? $this->status_transition['from'] : $old_status, |
|
| 1978 | - 'to' => $new_status, |
|
| 1979 | - 'note' => $note, |
|
| 1980 | - 'manual' => (bool) $manual_update, |
|
| 1981 | - ); |
|
| 1975 | + if ( $old_status !== $new_status ) { |
|
| 1976 | + $this->status_transition = array( |
|
| 1977 | + 'from' => ! empty( $this->status_transition['from'] ) ? $this->status_transition['from'] : $old_status, |
|
| 1978 | + 'to' => $new_status, |
|
| 1979 | + 'note' => $note, |
|
| 1980 | + 'manual' => (bool) $manual_update, |
|
| 1981 | + ); |
|
| 1982 | 1982 | |
| 1983 | - if ( $manual_update ) { |
|
| 1984 | - do_action( 'getpaid_' . $this->object_type .'_edit_status', $this->get_id(), $new_status ); |
|
| 1985 | - } |
|
| 1983 | + if ( $manual_update ) { |
|
| 1984 | + do_action( 'getpaid_' . $this->object_type .'_edit_status', $this->get_id(), $new_status ); |
|
| 1985 | + } |
|
| 1986 | 1986 | |
| 1987 | - $this->maybe_set_date_paid(); |
|
| 1987 | + $this->maybe_set_date_paid(); |
|
| 1988 | 1988 | |
| 1989 | - } |
|
| 1989 | + } |
|
| 1990 | 1990 | |
| 1991 | - } |
|
| 1991 | + } |
|
| 1992 | 1992 | |
| 1993 | - return array( |
|
| 1994 | - 'from' => $old_status, |
|
| 1995 | - 'to' => $new_status, |
|
| 1996 | - ); |
|
| 1997 | - } |
|
| 1993 | + return array( |
|
| 1994 | + 'from' => $old_status, |
|
| 1995 | + 'to' => $new_status, |
|
| 1996 | + ); |
|
| 1997 | + } |
|
| 1998 | 1998 | |
| 1999 | - /** |
|
| 2000 | - * Maybe set date paid. |
|
| 2001 | - * |
|
| 2002 | - * Sets the date paid variable when transitioning to the payment complete |
|
| 2003 | - * order status. |
|
| 2004 | - * |
|
| 2005 | - * @since 1.0.19 |
|
| 2006 | - */ |
|
| 2007 | - public function maybe_set_date_paid() { |
|
| 1999 | + /** |
|
| 2000 | + * Maybe set date paid. |
|
| 2001 | + * |
|
| 2002 | + * Sets the date paid variable when transitioning to the payment complete |
|
| 2003 | + * order status. |
|
| 2004 | + * |
|
| 2005 | + * @since 1.0.19 |
|
| 2006 | + */ |
|
| 2007 | + public function maybe_set_date_paid() { |
|
| 2008 | 2008 | |
| 2009 | - if ( ! $this->get_date_completed( 'edit' ) && $this->is_paid() ) { |
|
| 2010 | - $this->set_date_completed( current_time( 'mysql' ) ); |
|
| 2011 | - } |
|
| 2012 | - } |
|
| 2009 | + if ( ! $this->get_date_completed( 'edit' ) && $this->is_paid() ) { |
|
| 2010 | + $this->set_date_completed( current_time( 'mysql' ) ); |
|
| 2011 | + } |
|
| 2012 | + } |
|
| 2013 | 2013 | |
| 2014 | 2014 | /** |
| 2015 | - * Set parent invoice ID. |
|
| 2016 | - * |
|
| 2017 | - * @since 1.0.19 |
|
| 2018 | - */ |
|
| 2019 | - public function set_parent_id( $value ) { |
|
| 2020 | - if ( $value && ( $value === $this->get_id() ) ) { |
|
| 2021 | - return; |
|
| 2022 | - } |
|
| 2023 | - $this->set_prop( 'parent_id', absint( $value ) ); |
|
| 2015 | + * Set parent invoice ID. |
|
| 2016 | + * |
|
| 2017 | + * @since 1.0.19 |
|
| 2018 | + */ |
|
| 2019 | + public function set_parent_id( $value ) { |
|
| 2020 | + if ( $value && ( $value === $this->get_id() ) ) { |
|
| 2021 | + return; |
|
| 2022 | + } |
|
| 2023 | + $this->set_prop( 'parent_id', absint( $value ) ); |
|
| 2024 | 2024 | } |
| 2025 | 2025 | |
| 2026 | 2026 | /** |
| 2027 | - * Set plugin version when the invoice was created. |
|
| 2028 | - * |
|
| 2029 | - * @since 1.0.19 |
|
| 2030 | - */ |
|
| 2031 | - public function set_version( $value ) { |
|
| 2032 | - $this->set_prop( 'version', $value ); |
|
| 2027 | + * Set plugin version when the invoice was created. |
|
| 2028 | + * |
|
| 2029 | + * @since 1.0.19 |
|
| 2030 | + */ |
|
| 2031 | + public function set_version( $value ) { |
|
| 2032 | + $this->set_prop( 'version', $value ); |
|
| 2033 | 2033 | } |
| 2034 | - |
|
| 2035 | - /** |
|
| 2036 | - * Set date when the invoice was created. |
|
| 2037 | - * |
|
| 2038 | - * @since 1.0.19 |
|
| 2039 | - * @param string $value Value to set. |
|
| 2034 | + |
|
| 2035 | + /** |
|
| 2036 | + * Set date when the invoice was created. |
|
| 2037 | + * |
|
| 2038 | + * @since 1.0.19 |
|
| 2039 | + * @param string $value Value to set. |
|
| 2040 | 2040 | * @return bool Whether or not the date was set. |
| 2041 | - */ |
|
| 2042 | - public function set_date_created( $value ) { |
|
| 2041 | + */ |
|
| 2042 | + public function set_date_created( $value ) { |
|
| 2043 | 2043 | $date = strtotime( $value ); |
| 2044 | 2044 | |
| 2045 | 2045 | if ( $date && $value !== '0000-00-00 00:00:00' ) { |
@@ -2047,19 +2047,19 @@ discard block |
||
| 2047 | 2047 | return true; |
| 2048 | 2048 | } |
| 2049 | 2049 | |
| 2050 | - $this->set_prop( 'date_created', '' ); |
|
| 2051 | - return false; |
|
| 2050 | + $this->set_prop( 'date_created', '' ); |
|
| 2051 | + return false; |
|
| 2052 | 2052 | |
| 2053 | 2053 | } |
| 2054 | 2054 | |
| 2055 | 2055 | /** |
| 2056 | - * Set date invoice due date. |
|
| 2057 | - * |
|
| 2058 | - * @since 1.0.19 |
|
| 2059 | - * @param string $value Value to set. |
|
| 2056 | + * Set date invoice due date. |
|
| 2057 | + * |
|
| 2058 | + * @since 1.0.19 |
|
| 2059 | + * @param string $value Value to set. |
|
| 2060 | 2060 | * @return bool Whether or not the date was set. |
| 2061 | - */ |
|
| 2062 | - public function set_due_date( $value ) { |
|
| 2061 | + */ |
|
| 2062 | + public function set_due_date( $value ) { |
|
| 2063 | 2063 | $date = strtotime( $value ); |
| 2064 | 2064 | |
| 2065 | 2065 | if ( $date && $value !== '0000-00-00 00:00:00' ) { |
@@ -2067,29 +2067,29 @@ discard block |
||
| 2067 | 2067 | return true; |
| 2068 | 2068 | } |
| 2069 | 2069 | |
| 2070 | - $this->set_prop( 'due_date', '' ); |
|
| 2070 | + $this->set_prop( 'due_date', '' ); |
|
| 2071 | 2071 | return false; |
| 2072 | 2072 | |
| 2073 | 2073 | } |
| 2074 | 2074 | |
| 2075 | 2075 | /** |
| 2076 | - * Alias of self::set_due_date(). |
|
| 2077 | - * |
|
| 2078 | - * @since 1.0.19 |
|
| 2079 | - * @param string $value New name. |
|
| 2080 | - */ |
|
| 2081 | - public function set_date_due( $value ) { |
|
| 2082 | - $this->set_due_date( $value ); |
|
| 2076 | + * Alias of self::set_due_date(). |
|
| 2077 | + * |
|
| 2078 | + * @since 1.0.19 |
|
| 2079 | + * @param string $value New name. |
|
| 2080 | + */ |
|
| 2081 | + public function set_date_due( $value ) { |
|
| 2082 | + $this->set_due_date( $value ); |
|
| 2083 | 2083 | } |
| 2084 | 2084 | |
| 2085 | 2085 | /** |
| 2086 | - * Set date invoice was completed. |
|
| 2087 | - * |
|
| 2088 | - * @since 1.0.19 |
|
| 2089 | - * @param string $value Value to set. |
|
| 2086 | + * Set date invoice was completed. |
|
| 2087 | + * |
|
| 2088 | + * @since 1.0.19 |
|
| 2089 | + * @param string $value Value to set. |
|
| 2090 | 2090 | * @return bool Whether or not the date was set. |
| 2091 | - */ |
|
| 2092 | - public function set_completed_date( $value ) { |
|
| 2091 | + */ |
|
| 2092 | + public function set_completed_date( $value ) { |
|
| 2093 | 2093 | $date = strtotime( $value ); |
| 2094 | 2094 | |
| 2095 | 2095 | if ( $date && $value !== '0000-00-00 00:00:00' ) { |
@@ -2097,29 +2097,29 @@ discard block |
||
| 2097 | 2097 | return true; |
| 2098 | 2098 | } |
| 2099 | 2099 | |
| 2100 | - $this->set_prop( 'completed_date', '' ); |
|
| 2100 | + $this->set_prop( 'completed_date', '' ); |
|
| 2101 | 2101 | return false; |
| 2102 | 2102 | |
| 2103 | 2103 | } |
| 2104 | 2104 | |
| 2105 | 2105 | /** |
| 2106 | - * Alias of self::set_completed_date(). |
|
| 2107 | - * |
|
| 2108 | - * @since 1.0.19 |
|
| 2109 | - * @param string $value New name. |
|
| 2110 | - */ |
|
| 2111 | - public function set_date_completed( $value ) { |
|
| 2112 | - $this->set_completed_date( $value ); |
|
| 2106 | + * Alias of self::set_completed_date(). |
|
| 2107 | + * |
|
| 2108 | + * @since 1.0.19 |
|
| 2109 | + * @param string $value New name. |
|
| 2110 | + */ |
|
| 2111 | + public function set_date_completed( $value ) { |
|
| 2112 | + $this->set_completed_date( $value ); |
|
| 2113 | 2113 | } |
| 2114 | 2114 | |
| 2115 | 2115 | /** |
| 2116 | - * Set date when the invoice was last modified. |
|
| 2117 | - * |
|
| 2118 | - * @since 1.0.19 |
|
| 2119 | - * @param string $value Value to set. |
|
| 2116 | + * Set date when the invoice was last modified. |
|
| 2117 | + * |
|
| 2118 | + * @since 1.0.19 |
|
| 2119 | + * @param string $value Value to set. |
|
| 2120 | 2120 | * @return bool Whether or not the date was set. |
| 2121 | - */ |
|
| 2122 | - public function set_date_modified( $value ) { |
|
| 2121 | + */ |
|
| 2122 | + public function set_date_modified( $value ) { |
|
| 2123 | 2123 | $date = strtotime( $value ); |
| 2124 | 2124 | |
| 2125 | 2125 | if ( $date && $value !== '0000-00-00 00:00:00' ) { |
@@ -2127,788 +2127,788 @@ discard block |
||
| 2127 | 2127 | return true; |
| 2128 | 2128 | } |
| 2129 | 2129 | |
| 2130 | - $this->set_prop( 'date_modified', '' ); |
|
| 2130 | + $this->set_prop( 'date_modified', '' ); |
|
| 2131 | 2131 | return false; |
| 2132 | 2132 | |
| 2133 | 2133 | } |
| 2134 | 2134 | |
| 2135 | 2135 | /** |
| 2136 | - * Set the invoice number. |
|
| 2137 | - * |
|
| 2138 | - * @since 1.0.19 |
|
| 2139 | - * @param string $value New number. |
|
| 2140 | - */ |
|
| 2141 | - public function set_number( $value ) { |
|
| 2136 | + * Set the invoice number. |
|
| 2137 | + * |
|
| 2138 | + * @since 1.0.19 |
|
| 2139 | + * @param string $value New number. |
|
| 2140 | + */ |
|
| 2141 | + public function set_number( $value ) { |
|
| 2142 | 2142 | $number = sanitize_text_field( $value ); |
| 2143 | - $this->set_prop( 'number', $number ); |
|
| 2143 | + $this->set_prop( 'number', $number ); |
|
| 2144 | 2144 | } |
| 2145 | 2145 | |
| 2146 | 2146 | /** |
| 2147 | - * Set the invoice type. |
|
| 2148 | - * |
|
| 2149 | - * @since 1.0.19 |
|
| 2150 | - * @param string $value Type. |
|
| 2151 | - */ |
|
| 2152 | - public function set_type( $value ) { |
|
| 2147 | + * Set the invoice type. |
|
| 2148 | + * |
|
| 2149 | + * @since 1.0.19 |
|
| 2150 | + * @param string $value Type. |
|
| 2151 | + */ |
|
| 2152 | + public function set_type( $value ) { |
|
| 2153 | 2153 | $type = sanitize_text_field( str_replace( 'wpi_', '', $value ) ); |
| 2154 | - $this->set_prop( 'type', $type ); |
|
| 2155 | - } |
|
| 2154 | + $this->set_prop( 'type', $type ); |
|
| 2155 | + } |
|
| 2156 | 2156 | |
| 2157 | 2157 | /** |
| 2158 | - * Set the invoice post type. |
|
| 2159 | - * |
|
| 2160 | - * @since 1.0.19 |
|
| 2161 | - * @param string $value Post type. |
|
| 2162 | - */ |
|
| 2163 | - public function set_post_type( $value ) { |
|
| 2158 | + * Set the invoice post type. |
|
| 2159 | + * |
|
| 2160 | + * @since 1.0.19 |
|
| 2161 | + * @param string $value Post type. |
|
| 2162 | + */ |
|
| 2163 | + public function set_post_type( $value ) { |
|
| 2164 | 2164 | if ( getpaid_is_invoice_post_type( $value ) ) { |
| 2165 | - $this->set_type( $value ); |
|
| 2165 | + $this->set_type( $value ); |
|
| 2166 | 2166 | $this->set_prop( 'post_type', $value ); |
| 2167 | 2167 | } |
| 2168 | 2168 | } |
| 2169 | 2169 | |
| 2170 | 2170 | /** |
| 2171 | - * Set the invoice key. |
|
| 2172 | - * |
|
| 2173 | - * @since 1.0.19 |
|
| 2174 | - * @param string $value New key. |
|
| 2175 | - */ |
|
| 2176 | - public function set_key( $value ) { |
|
| 2171 | + * Set the invoice key. |
|
| 2172 | + * |
|
| 2173 | + * @since 1.0.19 |
|
| 2174 | + * @param string $value New key. |
|
| 2175 | + */ |
|
| 2176 | + public function set_key( $value ) { |
|
| 2177 | 2177 | $key = sanitize_text_field( $value ); |
| 2178 | - $this->set_prop( 'key', $key ); |
|
| 2178 | + $this->set_prop( 'key', $key ); |
|
| 2179 | 2179 | } |
| 2180 | 2180 | |
| 2181 | 2181 | /** |
| 2182 | - * Set the invoice mode. |
|
| 2183 | - * |
|
| 2184 | - * @since 1.0.19 |
|
| 2185 | - * @param string $value mode. |
|
| 2186 | - */ |
|
| 2187 | - public function set_mode( $value ) { |
|
| 2182 | + * Set the invoice mode. |
|
| 2183 | + * |
|
| 2184 | + * @since 1.0.19 |
|
| 2185 | + * @param string $value mode. |
|
| 2186 | + */ |
|
| 2187 | + public function set_mode( $value ) { |
|
| 2188 | 2188 | if ( in_array( $value, array( 'live', 'test' ) ) ) { |
| 2189 | 2189 | $this->set_prop( 'mode', $value ); |
| 2190 | 2190 | } |
| 2191 | 2191 | } |
| 2192 | 2192 | |
| 2193 | 2193 | /** |
| 2194 | - * Set the invoice path. |
|
| 2195 | - * |
|
| 2196 | - * @since 1.0.19 |
|
| 2197 | - * @param string $value path. |
|
| 2198 | - */ |
|
| 2199 | - public function set_path( $value ) { |
|
| 2194 | + * Set the invoice path. |
|
| 2195 | + * |
|
| 2196 | + * @since 1.0.19 |
|
| 2197 | + * @param string $value path. |
|
| 2198 | + */ |
|
| 2199 | + public function set_path( $value ) { |
|
| 2200 | 2200 | $this->set_prop( 'path', $value ); |
| 2201 | 2201 | } |
| 2202 | 2202 | |
| 2203 | 2203 | /** |
| 2204 | - * Set the invoice name. |
|
| 2205 | - * |
|
| 2206 | - * @since 1.0.19 |
|
| 2207 | - * @param string $value New name. |
|
| 2208 | - */ |
|
| 2209 | - public function set_name( $value ) { |
|
| 2204 | + * Set the invoice name. |
|
| 2205 | + * |
|
| 2206 | + * @since 1.0.19 |
|
| 2207 | + * @param string $value New name. |
|
| 2208 | + */ |
|
| 2209 | + public function set_name( $value ) { |
|
| 2210 | 2210 | $name = sanitize_text_field( $value ); |
| 2211 | - $this->set_prop( 'name', $name ); |
|
| 2211 | + $this->set_prop( 'name', $name ); |
|
| 2212 | 2212 | } |
| 2213 | 2213 | |
| 2214 | 2214 | /** |
| 2215 | - * Alias of self::set_name(). |
|
| 2216 | - * |
|
| 2217 | - * @since 1.0.19 |
|
| 2218 | - * @param string $value New name. |
|
| 2219 | - */ |
|
| 2220 | - public function set_title( $value ) { |
|
| 2221 | - $this->set_name( $value ); |
|
| 2215 | + * Alias of self::set_name(). |
|
| 2216 | + * |
|
| 2217 | + * @since 1.0.19 |
|
| 2218 | + * @param string $value New name. |
|
| 2219 | + */ |
|
| 2220 | + public function set_title( $value ) { |
|
| 2221 | + $this->set_name( $value ); |
|
| 2222 | 2222 | } |
| 2223 | 2223 | |
| 2224 | 2224 | /** |
| 2225 | - * Set the invoice description. |
|
| 2226 | - * |
|
| 2227 | - * @since 1.0.19 |
|
| 2228 | - * @param string $value New description. |
|
| 2229 | - */ |
|
| 2230 | - public function set_description( $value ) { |
|
| 2225 | + * Set the invoice description. |
|
| 2226 | + * |
|
| 2227 | + * @since 1.0.19 |
|
| 2228 | + * @param string $value New description. |
|
| 2229 | + */ |
|
| 2230 | + public function set_description( $value ) { |
|
| 2231 | 2231 | $description = wp_kses_post( $value ); |
| 2232 | - $this->set_prop( 'description', $description ); |
|
| 2232 | + $this->set_prop( 'description', $description ); |
|
| 2233 | + } |
|
| 2234 | + |
|
| 2235 | + /** |
|
| 2236 | + * Alias of self::set_description(). |
|
| 2237 | + * |
|
| 2238 | + * @since 1.0.19 |
|
| 2239 | + * @param string $value New description. |
|
| 2240 | + */ |
|
| 2241 | + public function set_excerpt( $value ) { |
|
| 2242 | + $this->set_description( $value ); |
|
| 2243 | + } |
|
| 2244 | + |
|
| 2245 | + /** |
|
| 2246 | + * Alias of self::set_description(). |
|
| 2247 | + * |
|
| 2248 | + * @since 1.0.19 |
|
| 2249 | + * @param string $value New description. |
|
| 2250 | + */ |
|
| 2251 | + public function set_summary( $value ) { |
|
| 2252 | + $this->set_description( $value ); |
|
| 2253 | + } |
|
| 2254 | + |
|
| 2255 | + /** |
|
| 2256 | + * Set the receiver of the invoice. |
|
| 2257 | + * |
|
| 2258 | + * @since 1.0.19 |
|
| 2259 | + * @param int $value New author. |
|
| 2260 | + */ |
|
| 2261 | + public function set_author( $value ) { |
|
| 2262 | + $user = get_user_by( 'id', (int) $value ); |
|
| 2263 | + |
|
| 2264 | + if ( $user && $user->ID ) { |
|
| 2265 | + $this->set_prop( 'author', $user->ID ); |
|
| 2266 | + $this->set_prop( 'email', $user->user_email ); |
|
| 2267 | + } |
|
| 2268 | + |
|
| 2269 | + } |
|
| 2270 | + |
|
| 2271 | + /** |
|
| 2272 | + * Alias of self::set_author(). |
|
| 2273 | + * |
|
| 2274 | + * @since 1.0.19 |
|
| 2275 | + * @param int $value New user id. |
|
| 2276 | + */ |
|
| 2277 | + public function set_user_id( $value ) { |
|
| 2278 | + $this->set_author( $value ); |
|
| 2279 | + } |
|
| 2280 | + |
|
| 2281 | + /** |
|
| 2282 | + * Alias of self::set_author(). |
|
| 2283 | + * |
|
| 2284 | + * @since 1.0.19 |
|
| 2285 | + * @param int $value New user id. |
|
| 2286 | + */ |
|
| 2287 | + public function set_customer_id( $value ) { |
|
| 2288 | + $this->set_author( $value ); |
|
| 2289 | + } |
|
| 2290 | + |
|
| 2291 | + /** |
|
| 2292 | + * Set the customer's ip. |
|
| 2293 | + * |
|
| 2294 | + * @since 1.0.19 |
|
| 2295 | + * @param string $value ip address. |
|
| 2296 | + */ |
|
| 2297 | + public function set_ip( $value ) { |
|
| 2298 | + $this->set_prop( 'ip', $value ); |
|
| 2299 | + } |
|
| 2300 | + |
|
| 2301 | + /** |
|
| 2302 | + * Alias of self::set_ip(). |
|
| 2303 | + * |
|
| 2304 | + * @since 1.0.19 |
|
| 2305 | + * @param string $value ip address. |
|
| 2306 | + */ |
|
| 2307 | + public function set_user_ip( $value ) { |
|
| 2308 | + $this->set_ip( $value ); |
|
| 2309 | + } |
|
| 2310 | + |
|
| 2311 | + /** |
|
| 2312 | + * Set the customer's first name. |
|
| 2313 | + * |
|
| 2314 | + * @since 1.0.19 |
|
| 2315 | + * @param string $value first name. |
|
| 2316 | + */ |
|
| 2317 | + public function set_first_name( $value ) { |
|
| 2318 | + $this->set_prop( 'first_name', $value ); |
|
| 2233 | 2319 | } |
| 2234 | 2320 | |
| 2235 | 2321 | /** |
| 2236 | - * Alias of self::set_description(). |
|
| 2237 | - * |
|
| 2238 | - * @since 1.0.19 |
|
| 2239 | - * @param string $value New description. |
|
| 2240 | - */ |
|
| 2241 | - public function set_excerpt( $value ) { |
|
| 2242 | - $this->set_description( $value ); |
|
| 2322 | + * Alias of self::set_first_name(). |
|
| 2323 | + * |
|
| 2324 | + * @since 1.0.19 |
|
| 2325 | + * @param string $value first name. |
|
| 2326 | + */ |
|
| 2327 | + public function set_user_first_name( $value ) { |
|
| 2328 | + $this->set_first_name( $value ); |
|
| 2243 | 2329 | } |
| 2244 | 2330 | |
| 2245 | 2331 | /** |
| 2246 | - * Alias of self::set_description(). |
|
| 2247 | - * |
|
| 2248 | - * @since 1.0.19 |
|
| 2249 | - * @param string $value New description. |
|
| 2250 | - */ |
|
| 2251 | - public function set_summary( $value ) { |
|
| 2252 | - $this->set_description( $value ); |
|
| 2332 | + * Alias of self::set_first_name(). |
|
| 2333 | + * |
|
| 2334 | + * @since 1.0.19 |
|
| 2335 | + * @param string $value first name. |
|
| 2336 | + */ |
|
| 2337 | + public function set_customer_first_name( $value ) { |
|
| 2338 | + $this->set_first_name( $value ); |
|
| 2253 | 2339 | } |
| 2254 | 2340 | |
| 2255 | 2341 | /** |
| 2256 | - * Set the receiver of the invoice. |
|
| 2257 | - * |
|
| 2258 | - * @since 1.0.19 |
|
| 2259 | - * @param int $value New author. |
|
| 2260 | - */ |
|
| 2261 | - public function set_author( $value ) { |
|
| 2262 | - $user = get_user_by( 'id', (int) $value ); |
|
| 2342 | + * Set the customer's last name. |
|
| 2343 | + * |
|
| 2344 | + * @since 1.0.19 |
|
| 2345 | + * @param string $value last name. |
|
| 2346 | + */ |
|
| 2347 | + public function set_last_name( $value ) { |
|
| 2348 | + $this->set_prop( 'last_name', $value ); |
|
| 2349 | + } |
|
| 2263 | 2350 | |
| 2264 | - if ( $user && $user->ID ) { |
|
| 2265 | - $this->set_prop( 'author', $user->ID ); |
|
| 2266 | - $this->set_prop( 'email', $user->user_email ); |
|
| 2267 | - } |
|
| 2351 | + /** |
|
| 2352 | + * Alias of self::set_last_name(). |
|
| 2353 | + * |
|
| 2354 | + * @since 1.0.19 |
|
| 2355 | + * @param string $value last name. |
|
| 2356 | + */ |
|
| 2357 | + public function set_user_last_name( $value ) { |
|
| 2358 | + $this->set_last_name( $value ); |
|
| 2359 | + } |
|
| 2268 | 2360 | |
| 2361 | + /** |
|
| 2362 | + * Alias of self::set_last_name(). |
|
| 2363 | + * |
|
| 2364 | + * @since 1.0.19 |
|
| 2365 | + * @param string $value last name. |
|
| 2366 | + */ |
|
| 2367 | + public function set_customer_last_name( $value ) { |
|
| 2368 | + $this->set_last_name( $value ); |
|
| 2269 | 2369 | } |
| 2270 | 2370 | |
| 2271 | 2371 | /** |
| 2272 | - * Alias of self::set_author(). |
|
| 2273 | - * |
|
| 2274 | - * @since 1.0.19 |
|
| 2275 | - * @param int $value New user id. |
|
| 2276 | - */ |
|
| 2277 | - public function set_user_id( $value ) { |
|
| 2278 | - $this->set_author( $value ); |
|
| 2372 | + * Set the customer's phone number. |
|
| 2373 | + * |
|
| 2374 | + * @since 1.0.19 |
|
| 2375 | + * @param string $value phone. |
|
| 2376 | + */ |
|
| 2377 | + public function set_phone( $value ) { |
|
| 2378 | + $this->set_prop( 'phone', $value ); |
|
| 2279 | 2379 | } |
| 2280 | 2380 | |
| 2281 | 2381 | /** |
| 2282 | - * Alias of self::set_author(). |
|
| 2283 | - * |
|
| 2284 | - * @since 1.0.19 |
|
| 2285 | - * @param int $value New user id. |
|
| 2286 | - */ |
|
| 2287 | - public function set_customer_id( $value ) { |
|
| 2288 | - $this->set_author( $value ); |
|
| 2382 | + * Alias of self::set_phone(). |
|
| 2383 | + * |
|
| 2384 | + * @since 1.0.19 |
|
| 2385 | + * @param string $value phone. |
|
| 2386 | + */ |
|
| 2387 | + public function set_user_phone( $value ) { |
|
| 2388 | + $this->set_phone( $value ); |
|
| 2289 | 2389 | } |
| 2290 | 2390 | |
| 2291 | 2391 | /** |
| 2292 | - * Set the customer's ip. |
|
| 2293 | - * |
|
| 2294 | - * @since 1.0.19 |
|
| 2295 | - * @param string $value ip address. |
|
| 2296 | - */ |
|
| 2297 | - public function set_ip( $value ) { |
|
| 2298 | - $this->set_prop( 'ip', $value ); |
|
| 2392 | + * Alias of self::set_phone(). |
|
| 2393 | + * |
|
| 2394 | + * @since 1.0.19 |
|
| 2395 | + * @param string $value phone. |
|
| 2396 | + */ |
|
| 2397 | + public function set_customer_phone( $value ) { |
|
| 2398 | + $this->set_phone( $value ); |
|
| 2299 | 2399 | } |
| 2300 | 2400 | |
| 2301 | 2401 | /** |
| 2302 | - * Alias of self::set_ip(). |
|
| 2303 | - * |
|
| 2304 | - * @since 1.0.19 |
|
| 2305 | - * @param string $value ip address. |
|
| 2306 | - */ |
|
| 2307 | - public function set_user_ip( $value ) { |
|
| 2308 | - $this->set_ip( $value ); |
|
| 2402 | + * Alias of self::set_phone(). |
|
| 2403 | + * |
|
| 2404 | + * @since 1.0.19 |
|
| 2405 | + * @param string $value phone. |
|
| 2406 | + */ |
|
| 2407 | + public function set_phone_number( $value ) { |
|
| 2408 | + $this->set_phone( $value ); |
|
| 2309 | 2409 | } |
| 2310 | 2410 | |
| 2311 | 2411 | /** |
| 2312 | - * Set the customer's first name. |
|
| 2313 | - * |
|
| 2314 | - * @since 1.0.19 |
|
| 2315 | - * @param string $value first name. |
|
| 2316 | - */ |
|
| 2317 | - public function set_first_name( $value ) { |
|
| 2318 | - $this->set_prop( 'first_name', $value ); |
|
| 2412 | + * Set the customer's email address. |
|
| 2413 | + * |
|
| 2414 | + * @since 1.0.19 |
|
| 2415 | + * @param string $value email address. |
|
| 2416 | + */ |
|
| 2417 | + public function set_email( $value ) { |
|
| 2418 | + $this->set_prop( 'email', $value ); |
|
| 2319 | 2419 | } |
| 2320 | 2420 | |
| 2321 | 2421 | /** |
| 2322 | - * Alias of self::set_first_name(). |
|
| 2323 | - * |
|
| 2324 | - * @since 1.0.19 |
|
| 2325 | - * @param string $value first name. |
|
| 2326 | - */ |
|
| 2327 | - public function set_user_first_name( $value ) { |
|
| 2328 | - $this->set_first_name( $value ); |
|
| 2422 | + * Alias of self::set_email(). |
|
| 2423 | + * |
|
| 2424 | + * @since 1.0.19 |
|
| 2425 | + * @param string $value email address. |
|
| 2426 | + */ |
|
| 2427 | + public function set_user_email( $value ) { |
|
| 2428 | + $this->set_email( $value ); |
|
| 2329 | 2429 | } |
| 2330 | 2430 | |
| 2331 | 2431 | /** |
| 2332 | - * Alias of self::set_first_name(). |
|
| 2333 | - * |
|
| 2334 | - * @since 1.0.19 |
|
| 2335 | - * @param string $value first name. |
|
| 2336 | - */ |
|
| 2337 | - public function set_customer_first_name( $value ) { |
|
| 2338 | - $this->set_first_name( $value ); |
|
| 2432 | + * Alias of self::set_email(). |
|
| 2433 | + * |
|
| 2434 | + * @since 1.0.19 |
|
| 2435 | + * @param string $value email address. |
|
| 2436 | + */ |
|
| 2437 | + public function set_email_address( $value ) { |
|
| 2438 | + $this->set_email( $value ); |
|
| 2339 | 2439 | } |
| 2340 | 2440 | |
| 2341 | 2441 | /** |
| 2342 | - * Set the customer's last name. |
|
| 2343 | - * |
|
| 2344 | - * @since 1.0.19 |
|
| 2345 | - * @param string $value last name. |
|
| 2346 | - */ |
|
| 2347 | - public function set_last_name( $value ) { |
|
| 2348 | - $this->set_prop( 'last_name', $value ); |
|
| 2442 | + * Alias of self::set_email(). |
|
| 2443 | + * |
|
| 2444 | + * @since 1.0.19 |
|
| 2445 | + * @param string $value email address. |
|
| 2446 | + */ |
|
| 2447 | + public function set_customer_email( $value ) { |
|
| 2448 | + $this->set_email( $value ); |
|
| 2349 | 2449 | } |
| 2350 | 2450 | |
| 2351 | 2451 | /** |
| 2352 | - * Alias of self::set_last_name(). |
|
| 2353 | - * |
|
| 2354 | - * @since 1.0.19 |
|
| 2355 | - * @param string $value last name. |
|
| 2356 | - */ |
|
| 2357 | - public function set_user_last_name( $value ) { |
|
| 2358 | - $this->set_last_name( $value ); |
|
| 2452 | + * Set the customer's country. |
|
| 2453 | + * |
|
| 2454 | + * @since 1.0.19 |
|
| 2455 | + * @param string $value country. |
|
| 2456 | + */ |
|
| 2457 | + public function set_country( $value ) { |
|
| 2458 | + $this->set_prop( 'country', $value ); |
|
| 2459 | + } |
|
| 2460 | + |
|
| 2461 | + /** |
|
| 2462 | + * Alias of self::set_country(). |
|
| 2463 | + * |
|
| 2464 | + * @since 1.0.19 |
|
| 2465 | + * @param string $value country. |
|
| 2466 | + */ |
|
| 2467 | + public function set_user_country( $value ) { |
|
| 2468 | + $this->set_country( $value ); |
|
| 2469 | + } |
|
| 2470 | + |
|
| 2471 | + /** |
|
| 2472 | + * Alias of self::set_country(). |
|
| 2473 | + * |
|
| 2474 | + * @since 1.0.19 |
|
| 2475 | + * @param string $value country. |
|
| 2476 | + */ |
|
| 2477 | + public function set_customer_country( $value ) { |
|
| 2478 | + $this->set_country( $value ); |
|
| 2359 | 2479 | } |
| 2360 | 2480 | |
| 2361 | 2481 | /** |
| 2362 | - * Alias of self::set_last_name(). |
|
| 2363 | - * |
|
| 2364 | - * @since 1.0.19 |
|
| 2365 | - * @param string $value last name. |
|
| 2366 | - */ |
|
| 2367 | - public function set_customer_last_name( $value ) { |
|
| 2368 | - $this->set_last_name( $value ); |
|
| 2482 | + * Set the customer's state. |
|
| 2483 | + * |
|
| 2484 | + * @since 1.0.19 |
|
| 2485 | + * @param string $value state. |
|
| 2486 | + */ |
|
| 2487 | + public function set_state( $value ) { |
|
| 2488 | + $this->set_prop( 'state', $value ); |
|
| 2369 | 2489 | } |
| 2370 | 2490 | |
| 2371 | 2491 | /** |
| 2372 | - * Set the customer's phone number. |
|
| 2373 | - * |
|
| 2374 | - * @since 1.0.19 |
|
| 2375 | - * @param string $value phone. |
|
| 2376 | - */ |
|
| 2377 | - public function set_phone( $value ) { |
|
| 2378 | - $this->set_prop( 'phone', $value ); |
|
| 2492 | + * Alias of self::set_state(). |
|
| 2493 | + * |
|
| 2494 | + * @since 1.0.19 |
|
| 2495 | + * @param string $value state. |
|
| 2496 | + */ |
|
| 2497 | + public function set_user_state( $value ) { |
|
| 2498 | + $this->set_state( $value ); |
|
| 2499 | + } |
|
| 2500 | + |
|
| 2501 | + /** |
|
| 2502 | + * Alias of self::set_state(). |
|
| 2503 | + * |
|
| 2504 | + * @since 1.0.19 |
|
| 2505 | + * @param string $value state. |
|
| 2506 | + */ |
|
| 2507 | + public function set_customer_state( $value ) { |
|
| 2508 | + $this->set_state( $value ); |
|
| 2509 | + } |
|
| 2510 | + |
|
| 2511 | + /** |
|
| 2512 | + * Set the customer's city. |
|
| 2513 | + * |
|
| 2514 | + * @since 1.0.19 |
|
| 2515 | + * @param string $value city. |
|
| 2516 | + */ |
|
| 2517 | + public function set_city( $value ) { |
|
| 2518 | + $this->set_prop( 'city', $value ); |
|
| 2519 | + } |
|
| 2520 | + |
|
| 2521 | + /** |
|
| 2522 | + * Alias of self::set_city(). |
|
| 2523 | + * |
|
| 2524 | + * @since 1.0.19 |
|
| 2525 | + * @param string $value city. |
|
| 2526 | + */ |
|
| 2527 | + public function set_user_city( $value ) { |
|
| 2528 | + $this->set_city( $value ); |
|
| 2379 | 2529 | } |
| 2380 | 2530 | |
| 2381 | 2531 | /** |
| 2382 | - * Alias of self::set_phone(). |
|
| 2383 | - * |
|
| 2384 | - * @since 1.0.19 |
|
| 2385 | - * @param string $value phone. |
|
| 2386 | - */ |
|
| 2387 | - public function set_user_phone( $value ) { |
|
| 2388 | - $this->set_phone( $value ); |
|
| 2532 | + * Alias of self::set_city(). |
|
| 2533 | + * |
|
| 2534 | + * @since 1.0.19 |
|
| 2535 | + * @param string $value city. |
|
| 2536 | + */ |
|
| 2537 | + public function set_customer_city( $value ) { |
|
| 2538 | + $this->set_city( $value ); |
|
| 2389 | 2539 | } |
| 2390 | 2540 | |
| 2391 | 2541 | /** |
| 2392 | - * Alias of self::set_phone(). |
|
| 2393 | - * |
|
| 2394 | - * @since 1.0.19 |
|
| 2395 | - * @param string $value phone. |
|
| 2396 | - */ |
|
| 2397 | - public function set_customer_phone( $value ) { |
|
| 2398 | - $this->set_phone( $value ); |
|
| 2542 | + * Set the customer's zip code. |
|
| 2543 | + * |
|
| 2544 | + * @since 1.0.19 |
|
| 2545 | + * @param string $value zip. |
|
| 2546 | + */ |
|
| 2547 | + public function set_zip( $value ) { |
|
| 2548 | + $this->set_prop( 'zip', $value ); |
|
| 2399 | 2549 | } |
| 2400 | 2550 | |
| 2401 | 2551 | /** |
| 2402 | - * Alias of self::set_phone(). |
|
| 2403 | - * |
|
| 2404 | - * @since 1.0.19 |
|
| 2405 | - * @param string $value phone. |
|
| 2406 | - */ |
|
| 2407 | - public function set_phone_number( $value ) { |
|
| 2408 | - $this->set_phone( $value ); |
|
| 2552 | + * Alias of self::set_zip(). |
|
| 2553 | + * |
|
| 2554 | + * @since 1.0.19 |
|
| 2555 | + * @param string $value zip. |
|
| 2556 | + */ |
|
| 2557 | + public function set_user_zip( $value ) { |
|
| 2558 | + $this->set_zip( $value ); |
|
| 2409 | 2559 | } |
| 2410 | 2560 | |
| 2411 | 2561 | /** |
| 2412 | - * Set the customer's email address. |
|
| 2413 | - * |
|
| 2414 | - * @since 1.0.19 |
|
| 2415 | - * @param string $value email address. |
|
| 2416 | - */ |
|
| 2417 | - public function set_email( $value ) { |
|
| 2418 | - $this->set_prop( 'email', $value ); |
|
| 2562 | + * Alias of self::set_zip(). |
|
| 2563 | + * |
|
| 2564 | + * @since 1.0.19 |
|
| 2565 | + * @param string $value zip. |
|
| 2566 | + */ |
|
| 2567 | + public function set_customer_zip( $value ) { |
|
| 2568 | + $this->set_zip( $value ); |
|
| 2419 | 2569 | } |
| 2420 | 2570 | |
| 2421 | 2571 | /** |
| 2422 | - * Alias of self::set_email(). |
|
| 2423 | - * |
|
| 2424 | - * @since 1.0.19 |
|
| 2425 | - * @param string $value email address. |
|
| 2426 | - */ |
|
| 2427 | - public function set_user_email( $value ) { |
|
| 2428 | - $this->set_email( $value ); |
|
| 2572 | + * Set the customer's company. |
|
| 2573 | + * |
|
| 2574 | + * @since 1.0.19 |
|
| 2575 | + * @param string $value company. |
|
| 2576 | + */ |
|
| 2577 | + public function set_company( $value ) { |
|
| 2578 | + $this->set_prop( 'company', $value ); |
|
| 2429 | 2579 | } |
| 2430 | 2580 | |
| 2431 | 2581 | /** |
| 2432 | - * Alias of self::set_email(). |
|
| 2433 | - * |
|
| 2434 | - * @since 1.0.19 |
|
| 2435 | - * @param string $value email address. |
|
| 2436 | - */ |
|
| 2437 | - public function set_email_address( $value ) { |
|
| 2438 | - $this->set_email( $value ); |
|
| 2582 | + * Alias of self::set_company(). |
|
| 2583 | + * |
|
| 2584 | + * @since 1.0.19 |
|
| 2585 | + * @param string $value company. |
|
| 2586 | + */ |
|
| 2587 | + public function set_user_company( $value ) { |
|
| 2588 | + $this->set_company( $value ); |
|
| 2439 | 2589 | } |
| 2440 | 2590 | |
| 2441 | 2591 | /** |
| 2442 | - * Alias of self::set_email(). |
|
| 2443 | - * |
|
| 2444 | - * @since 1.0.19 |
|
| 2445 | - * @param string $value email address. |
|
| 2446 | - */ |
|
| 2447 | - public function set_customer_email( $value ) { |
|
| 2448 | - $this->set_email( $value ); |
|
| 2592 | + * Alias of self::set_company(). |
|
| 2593 | + * |
|
| 2594 | + * @since 1.0.19 |
|
| 2595 | + * @param string $value company. |
|
| 2596 | + */ |
|
| 2597 | + public function set_customer_company( $value ) { |
|
| 2598 | + $this->set_company( $value ); |
|
| 2449 | 2599 | } |
| 2450 | 2600 | |
| 2451 | 2601 | /** |
| 2452 | - * Set the customer's country. |
|
| 2453 | - * |
|
| 2454 | - * @since 1.0.19 |
|
| 2455 | - * @param string $value country. |
|
| 2456 | - */ |
|
| 2457 | - public function set_country( $value ) { |
|
| 2458 | - $this->set_prop( 'country', $value ); |
|
| 2602 | + * Set the customer's var number. |
|
| 2603 | + * |
|
| 2604 | + * @since 1.0.19 |
|
| 2605 | + * @param string $value var number. |
|
| 2606 | + */ |
|
| 2607 | + public function set_vat_number( $value ) { |
|
| 2608 | + $this->set_prop( 'vat_number', $value ); |
|
| 2459 | 2609 | } |
| 2460 | 2610 | |
| 2461 | 2611 | /** |
| 2462 | - * Alias of self::set_country(). |
|
| 2463 | - * |
|
| 2464 | - * @since 1.0.19 |
|
| 2465 | - * @param string $value country. |
|
| 2466 | - */ |
|
| 2467 | - public function set_user_country( $value ) { |
|
| 2468 | - $this->set_country( $value ); |
|
| 2612 | + * Alias of self::set_vat_number(). |
|
| 2613 | + * |
|
| 2614 | + * @since 1.0.19 |
|
| 2615 | + * @param string $value var number. |
|
| 2616 | + */ |
|
| 2617 | + public function set_user_vat_number( $value ) { |
|
| 2618 | + $this->set_vat_number( $value ); |
|
| 2469 | 2619 | } |
| 2470 | 2620 | |
| 2471 | 2621 | /** |
| 2472 | - * Alias of self::set_country(). |
|
| 2473 | - * |
|
| 2474 | - * @since 1.0.19 |
|
| 2475 | - * @param string $value country. |
|
| 2476 | - */ |
|
| 2477 | - public function set_customer_country( $value ) { |
|
| 2478 | - $this->set_country( $value ); |
|
| 2622 | + * Alias of self::set_vat_number(). |
|
| 2623 | + * |
|
| 2624 | + * @since 1.0.19 |
|
| 2625 | + * @param string $value var number. |
|
| 2626 | + */ |
|
| 2627 | + public function set_customer_vat_number( $value ) { |
|
| 2628 | + $this->set_vat_number( $value ); |
|
| 2479 | 2629 | } |
| 2480 | 2630 | |
| 2481 | 2631 | /** |
| 2482 | - * Set the customer's state. |
|
| 2483 | - * |
|
| 2484 | - * @since 1.0.19 |
|
| 2485 | - * @param string $value state. |
|
| 2486 | - */ |
|
| 2487 | - public function set_state( $value ) { |
|
| 2488 | - $this->set_prop( 'state', $value ); |
|
| 2632 | + * Set the customer's vat rate. |
|
| 2633 | + * |
|
| 2634 | + * @since 1.0.19 |
|
| 2635 | + * @param string $value var rate. |
|
| 2636 | + */ |
|
| 2637 | + public function set_vat_rate( $value ) { |
|
| 2638 | + $this->set_prop( 'vat_rate', $value ); |
|
| 2489 | 2639 | } |
| 2490 | 2640 | |
| 2491 | 2641 | /** |
| 2492 | - * Alias of self::set_state(). |
|
| 2493 | - * |
|
| 2494 | - * @since 1.0.19 |
|
| 2495 | - * @param string $value state. |
|
| 2496 | - */ |
|
| 2497 | - public function set_user_state( $value ) { |
|
| 2498 | - $this->set_state( $value ); |
|
| 2642 | + * Alias of self::set_vat_rate(). |
|
| 2643 | + * |
|
| 2644 | + * @since 1.0.19 |
|
| 2645 | + * @param string $value var number. |
|
| 2646 | + */ |
|
| 2647 | + public function set_user_vat_rate( $value ) { |
|
| 2648 | + $this->set_vat_rate( $value ); |
|
| 2499 | 2649 | } |
| 2500 | 2650 | |
| 2501 | 2651 | /** |
| 2502 | - * Alias of self::set_state(). |
|
| 2503 | - * |
|
| 2504 | - * @since 1.0.19 |
|
| 2505 | - * @param string $value state. |
|
| 2506 | - */ |
|
| 2507 | - public function set_customer_state( $value ) { |
|
| 2508 | - $this->set_state( $value ); |
|
| 2652 | + * Alias of self::set_vat_rate(). |
|
| 2653 | + * |
|
| 2654 | + * @since 1.0.19 |
|
| 2655 | + * @param string $value var number. |
|
| 2656 | + */ |
|
| 2657 | + public function set_customer_vat_rate( $value ) { |
|
| 2658 | + $this->set_vat_rate( $value ); |
|
| 2509 | 2659 | } |
| 2510 | 2660 | |
| 2511 | 2661 | /** |
| 2512 | - * Set the customer's city. |
|
| 2513 | - * |
|
| 2514 | - * @since 1.0.19 |
|
| 2515 | - * @param string $value city. |
|
| 2516 | - */ |
|
| 2517 | - public function set_city( $value ) { |
|
| 2518 | - $this->set_prop( 'city', $value ); |
|
| 2662 | + * Set the customer's address. |
|
| 2663 | + * |
|
| 2664 | + * @since 1.0.19 |
|
| 2665 | + * @param string $value address. |
|
| 2666 | + */ |
|
| 2667 | + public function set_address( $value ) { |
|
| 2668 | + $this->set_prop( 'address', $value ); |
|
| 2519 | 2669 | } |
| 2520 | 2670 | |
| 2521 | 2671 | /** |
| 2522 | - * Alias of self::set_city(). |
|
| 2523 | - * |
|
| 2524 | - * @since 1.0.19 |
|
| 2525 | - * @param string $value city. |
|
| 2526 | - */ |
|
| 2527 | - public function set_user_city( $value ) { |
|
| 2528 | - $this->set_city( $value ); |
|
| 2672 | + * Alias of self::set_address(). |
|
| 2673 | + * |
|
| 2674 | + * @since 1.0.19 |
|
| 2675 | + * @param string $value address. |
|
| 2676 | + */ |
|
| 2677 | + public function set_user_address( $value ) { |
|
| 2678 | + $this->set_address( $value ); |
|
| 2529 | 2679 | } |
| 2530 | 2680 | |
| 2531 | 2681 | /** |
| 2532 | - * Alias of self::set_city(). |
|
| 2533 | - * |
|
| 2534 | - * @since 1.0.19 |
|
| 2535 | - * @param string $value city. |
|
| 2536 | - */ |
|
| 2537 | - public function set_customer_city( $value ) { |
|
| 2538 | - $this->set_city( $value ); |
|
| 2682 | + * Alias of self::set_address(). |
|
| 2683 | + * |
|
| 2684 | + * @since 1.0.19 |
|
| 2685 | + * @param string $value address. |
|
| 2686 | + */ |
|
| 2687 | + public function set_customer_address( $value ) { |
|
| 2688 | + $this->set_address( $value ); |
|
| 2539 | 2689 | } |
| 2540 | 2690 | |
| 2541 | 2691 | /** |
| 2542 | - * Set the customer's zip code. |
|
| 2543 | - * |
|
| 2544 | - * @since 1.0.19 |
|
| 2545 | - * @param string $value zip. |
|
| 2546 | - */ |
|
| 2547 | - public function set_zip( $value ) { |
|
| 2548 | - $this->set_prop( 'zip', $value ); |
|
| 2692 | + * Set whether the customer has viewed the invoice or not. |
|
| 2693 | + * |
|
| 2694 | + * @since 1.0.19 |
|
| 2695 | + * @param int|bool $value confirmed. |
|
| 2696 | + */ |
|
| 2697 | + public function set_is_viewed( $value ) { |
|
| 2698 | + $this->set_prop( 'is_viewed', $value ); |
|
| 2549 | 2699 | } |
| 2550 | 2700 | |
| 2551 | 2701 | /** |
| 2552 | - * Alias of self::set_zip(). |
|
| 2553 | - * |
|
| 2554 | - * @since 1.0.19 |
|
| 2555 | - * @param string $value zip. |
|
| 2556 | - */ |
|
| 2557 | - public function set_user_zip( $value ) { |
|
| 2558 | - $this->set_zip( $value ); |
|
| 2702 | + * Set extra email recipients. |
|
| 2703 | + * |
|
| 2704 | + * @since 1.0.19 |
|
| 2705 | + * @param string $value email recipients. |
|
| 2706 | + */ |
|
| 2707 | + public function set_email_cc( $value ) { |
|
| 2708 | + $this->set_prop( 'email_cc', $value ); |
|
| 2559 | 2709 | } |
| 2560 | 2710 | |
| 2561 | 2711 | /** |
| 2562 | - * Alias of self::set_zip(). |
|
| 2563 | - * |
|
| 2564 | - * @since 1.0.19 |
|
| 2565 | - * @param string $value zip. |
|
| 2566 | - */ |
|
| 2567 | - public function set_customer_zip( $value ) { |
|
| 2568 | - $this->set_zip( $value ); |
|
| 2712 | + * Set the invoice template. |
|
| 2713 | + * |
|
| 2714 | + * @since 1.0.19 |
|
| 2715 | + * @param string $value template. |
|
| 2716 | + */ |
|
| 2717 | + public function set_template( $value ) { |
|
| 2718 | + if ( in_array( $value, array( 'quantity', 'hours', 'amount' ) ) ) { |
|
| 2719 | + $this->set_prop( 'template', $value ); |
|
| 2720 | + } |
|
| 2569 | 2721 | } |
| 2570 | 2722 | |
| 2571 | 2723 | /** |
| 2572 | - * Set the customer's company. |
|
| 2573 | - * |
|
| 2574 | - * @since 1.0.19 |
|
| 2575 | - * @param string $value company. |
|
| 2576 | - */ |
|
| 2577 | - public function set_company( $value ) { |
|
| 2578 | - $this->set_prop( 'company', $value ); |
|
| 2724 | + * Set the invoice source. |
|
| 2725 | + * |
|
| 2726 | + * @since 1.0.19 |
|
| 2727 | + * @param string $value source. |
|
| 2728 | + * @deprecated |
|
| 2729 | + */ |
|
| 2730 | + public function created_via( $value ) { |
|
| 2731 | + $this->set_created_via( sanitize_text_field( $value ) ); |
|
| 2579 | 2732 | } |
| 2580 | 2733 | |
| 2581 | 2734 | /** |
| 2582 | - * Alias of self::set_company(). |
|
| 2583 | - * |
|
| 2584 | - * @since 1.0.19 |
|
| 2585 | - * @param string $value company. |
|
| 2586 | - */ |
|
| 2587 | - public function set_user_company( $value ) { |
|
| 2588 | - $this->set_company( $value ); |
|
| 2735 | + * Set the invoice source. |
|
| 2736 | + * |
|
| 2737 | + * @since 1.0.19 |
|
| 2738 | + * @param string $value source. |
|
| 2739 | + */ |
|
| 2740 | + public function set_created_via( $value ) { |
|
| 2741 | + $this->set_prop( 'created_via', sanitize_text_field( $value ) ); |
|
| 2589 | 2742 | } |
| 2590 | 2743 | |
| 2591 | 2744 | /** |
| 2592 | - * Alias of self::set_company(). |
|
| 2593 | - * |
|
| 2594 | - * @since 1.0.19 |
|
| 2595 | - * @param string $value company. |
|
| 2596 | - */ |
|
| 2597 | - public function set_customer_company( $value ) { |
|
| 2598 | - $this->set_company( $value ); |
|
| 2745 | + * Set the customer's address confirmed status. |
|
| 2746 | + * |
|
| 2747 | + * @since 1.0.19 |
|
| 2748 | + * @param int|bool $value confirmed. |
|
| 2749 | + */ |
|
| 2750 | + public function set_address_confirmed( $value ) { |
|
| 2751 | + $this->set_prop( 'address_confirmed', $value ); |
|
| 2599 | 2752 | } |
| 2600 | 2753 | |
| 2601 | 2754 | /** |
| 2602 | - * Set the customer's var number. |
|
| 2603 | - * |
|
| 2604 | - * @since 1.0.19 |
|
| 2605 | - * @param string $value var number. |
|
| 2606 | - */ |
|
| 2607 | - public function set_vat_number( $value ) { |
|
| 2608 | - $this->set_prop( 'vat_number', $value ); |
|
| 2755 | + * Alias of self::set_address_confirmed(). |
|
| 2756 | + * |
|
| 2757 | + * @since 1.0.19 |
|
| 2758 | + * @param int|bool $value confirmed. |
|
| 2759 | + */ |
|
| 2760 | + public function set_user_address_confirmed( $value ) { |
|
| 2761 | + $this->set_address_confirmed( $value ); |
|
| 2609 | 2762 | } |
| 2610 | 2763 | |
| 2611 | 2764 | /** |
| 2612 | - * Alias of self::set_vat_number(). |
|
| 2613 | - * |
|
| 2614 | - * @since 1.0.19 |
|
| 2615 | - * @param string $value var number. |
|
| 2616 | - */ |
|
| 2617 | - public function set_user_vat_number( $value ) { |
|
| 2618 | - $this->set_vat_number( $value ); |
|
| 2765 | + * Alias of self::set_address_confirmed(). |
|
| 2766 | + * |
|
| 2767 | + * @since 1.0.19 |
|
| 2768 | + * @param int|bool $value confirmed. |
|
| 2769 | + */ |
|
| 2770 | + public function set_customer_address_confirmed( $value ) { |
|
| 2771 | + $this->set_address_confirmed( $value ); |
|
| 2619 | 2772 | } |
| 2620 | 2773 | |
| 2621 | 2774 | /** |
| 2622 | - * Alias of self::set_vat_number(). |
|
| 2623 | - * |
|
| 2624 | - * @since 1.0.19 |
|
| 2625 | - * @param string $value var number. |
|
| 2626 | - */ |
|
| 2627 | - public function set_customer_vat_number( $value ) { |
|
| 2628 | - $this->set_vat_number( $value ); |
|
| 2775 | + * Set the invoice sub total. |
|
| 2776 | + * |
|
| 2777 | + * @since 1.0.19 |
|
| 2778 | + * @param float $value sub total. |
|
| 2779 | + */ |
|
| 2780 | + public function set_subtotal( $value ) { |
|
| 2781 | + $this->set_prop( 'subtotal', max( 0, $value ) ); |
|
| 2629 | 2782 | } |
| 2630 | 2783 | |
| 2631 | 2784 | /** |
| 2632 | - * Set the customer's vat rate. |
|
| 2633 | - * |
|
| 2634 | - * @since 1.0.19 |
|
| 2635 | - * @param string $value var rate. |
|
| 2636 | - */ |
|
| 2637 | - public function set_vat_rate( $value ) { |
|
| 2638 | - $this->set_prop( 'vat_rate', $value ); |
|
| 2785 | + * Set the invoice total. |
|
| 2786 | + * |
|
| 2787 | + * @since 1.0.19 |
|
| 2788 | + * @param float $value sub total. |
|
| 2789 | + */ |
|
| 2790 | + public function set_total( $value ) { |
|
| 2791 | + $this->set_prop( 'total', max( 0, $value ) ); |
|
| 2639 | 2792 | } |
| 2640 | 2793 | |
| 2641 | 2794 | /** |
| 2642 | - * Alias of self::set_vat_rate(). |
|
| 2643 | - * |
|
| 2644 | - * @since 1.0.19 |
|
| 2645 | - * @param string $value var number. |
|
| 2646 | - */ |
|
| 2647 | - public function set_user_vat_rate( $value ) { |
|
| 2648 | - $this->set_vat_rate( $value ); |
|
| 2649 | - } |
|
| 2650 | - |
|
| 2651 | - /** |
|
| 2652 | - * Alias of self::set_vat_rate(). |
|
| 2653 | - * |
|
| 2654 | - * @since 1.0.19 |
|
| 2655 | - * @param string $value var number. |
|
| 2656 | - */ |
|
| 2657 | - public function set_customer_vat_rate( $value ) { |
|
| 2658 | - $this->set_vat_rate( $value ); |
|
| 2659 | - } |
|
| 2660 | - |
|
| 2661 | - /** |
|
| 2662 | - * Set the customer's address. |
|
| 2663 | - * |
|
| 2664 | - * @since 1.0.19 |
|
| 2665 | - * @param string $value address. |
|
| 2666 | - */ |
|
| 2667 | - public function set_address( $value ) { |
|
| 2668 | - $this->set_prop( 'address', $value ); |
|
| 2669 | - } |
|
| 2670 | - |
|
| 2671 | - /** |
|
| 2672 | - * Alias of self::set_address(). |
|
| 2673 | - * |
|
| 2674 | - * @since 1.0.19 |
|
| 2675 | - * @param string $value address. |
|
| 2676 | - */ |
|
| 2677 | - public function set_user_address( $value ) { |
|
| 2678 | - $this->set_address( $value ); |
|
| 2679 | - } |
|
| 2680 | - |
|
| 2681 | - /** |
|
| 2682 | - * Alias of self::set_address(). |
|
| 2683 | - * |
|
| 2684 | - * @since 1.0.19 |
|
| 2685 | - * @param string $value address. |
|
| 2686 | - */ |
|
| 2687 | - public function set_customer_address( $value ) { |
|
| 2688 | - $this->set_address( $value ); |
|
| 2689 | - } |
|
| 2690 | - |
|
| 2691 | - /** |
|
| 2692 | - * Set whether the customer has viewed the invoice or not. |
|
| 2693 | - * |
|
| 2694 | - * @since 1.0.19 |
|
| 2695 | - * @param int|bool $value confirmed. |
|
| 2696 | - */ |
|
| 2697 | - public function set_is_viewed( $value ) { |
|
| 2698 | - $this->set_prop( 'is_viewed', $value ); |
|
| 2699 | - } |
|
| 2700 | - |
|
| 2701 | - /** |
|
| 2702 | - * Set extra email recipients. |
|
| 2703 | - * |
|
| 2704 | - * @since 1.0.19 |
|
| 2705 | - * @param string $value email recipients. |
|
| 2706 | - */ |
|
| 2707 | - public function set_email_cc( $value ) { |
|
| 2708 | - $this->set_prop( 'email_cc', $value ); |
|
| 2709 | - } |
|
| 2710 | - |
|
| 2711 | - /** |
|
| 2712 | - * Set the invoice template. |
|
| 2713 | - * |
|
| 2714 | - * @since 1.0.19 |
|
| 2715 | - * @param string $value template. |
|
| 2716 | - */ |
|
| 2717 | - public function set_template( $value ) { |
|
| 2718 | - if ( in_array( $value, array( 'quantity', 'hours', 'amount' ) ) ) { |
|
| 2719 | - $this->set_prop( 'template', $value ); |
|
| 2720 | - } |
|
| 2721 | - } |
|
| 2722 | - |
|
| 2723 | - /** |
|
| 2724 | - * Set the invoice source. |
|
| 2725 | - * |
|
| 2726 | - * @since 1.0.19 |
|
| 2727 | - * @param string $value source. |
|
| 2728 | - * @deprecated |
|
| 2729 | - */ |
|
| 2730 | - public function created_via( $value ) { |
|
| 2731 | - $this->set_created_via( sanitize_text_field( $value ) ); |
|
| 2732 | - } |
|
| 2733 | - |
|
| 2734 | - /** |
|
| 2735 | - * Set the invoice source. |
|
| 2736 | - * |
|
| 2737 | - * @since 1.0.19 |
|
| 2738 | - * @param string $value source. |
|
| 2739 | - */ |
|
| 2740 | - public function set_created_via( $value ) { |
|
| 2741 | - $this->set_prop( 'created_via', sanitize_text_field( $value ) ); |
|
| 2742 | - } |
|
| 2743 | - |
|
| 2744 | - /** |
|
| 2745 | - * Set the customer's address confirmed status. |
|
| 2746 | - * |
|
| 2747 | - * @since 1.0.19 |
|
| 2748 | - * @param int|bool $value confirmed. |
|
| 2749 | - */ |
|
| 2750 | - public function set_address_confirmed( $value ) { |
|
| 2751 | - $this->set_prop( 'address_confirmed', $value ); |
|
| 2752 | - } |
|
| 2753 | - |
|
| 2754 | - /** |
|
| 2755 | - * Alias of self::set_address_confirmed(). |
|
| 2756 | - * |
|
| 2757 | - * @since 1.0.19 |
|
| 2758 | - * @param int|bool $value confirmed. |
|
| 2759 | - */ |
|
| 2760 | - public function set_user_address_confirmed( $value ) { |
|
| 2761 | - $this->set_address_confirmed( $value ); |
|
| 2762 | - } |
|
| 2763 | - |
|
| 2764 | - /** |
|
| 2765 | - * Alias of self::set_address_confirmed(). |
|
| 2766 | - * |
|
| 2767 | - * @since 1.0.19 |
|
| 2768 | - * @param int|bool $value confirmed. |
|
| 2769 | - */ |
|
| 2770 | - public function set_customer_address_confirmed( $value ) { |
|
| 2771 | - $this->set_address_confirmed( $value ); |
|
| 2772 | - } |
|
| 2773 | - |
|
| 2774 | - /** |
|
| 2775 | - * Set the invoice sub total. |
|
| 2776 | - * |
|
| 2777 | - * @since 1.0.19 |
|
| 2778 | - * @param float $value sub total. |
|
| 2779 | - */ |
|
| 2780 | - public function set_subtotal( $value ) { |
|
| 2781 | - $this->set_prop( 'subtotal', max( 0, $value ) ); |
|
| 2782 | - } |
|
| 2783 | - |
|
| 2784 | - /** |
|
| 2785 | - * Set the invoice total. |
|
| 2786 | - * |
|
| 2787 | - * @since 1.0.19 |
|
| 2788 | - * @param float $value sub total. |
|
| 2789 | - */ |
|
| 2790 | - public function set_total( $value ) { |
|
| 2791 | - $this->set_prop( 'total', max( 0, $value ) ); |
|
| 2792 | - } |
|
| 2793 | - |
|
| 2794 | - /** |
|
| 2795 | - * Set the invoice discount amount. |
|
| 2796 | - * |
|
| 2797 | - * @since 1.0.19 |
|
| 2798 | - * @param float $value discount total. |
|
| 2799 | - */ |
|
| 2800 | - public function set_total_discount( $value ) { |
|
| 2801 | - $this->set_prop( 'total_discount', max( 0, $value ) ); |
|
| 2795 | + * Set the invoice discount amount. |
|
| 2796 | + * |
|
| 2797 | + * @since 1.0.19 |
|
| 2798 | + * @param float $value discount total. |
|
| 2799 | + */ |
|
| 2800 | + public function set_total_discount( $value ) { |
|
| 2801 | + $this->set_prop( 'total_discount', max( 0, $value ) ); |
|
| 2802 | 2802 | } |
| 2803 | 2803 | |
| 2804 | 2804 | /** |
| 2805 | - * Alias of self::set_total_discount(). |
|
| 2806 | - * |
|
| 2807 | - * @since 1.0.19 |
|
| 2808 | - * @param float $value discount total. |
|
| 2809 | - */ |
|
| 2810 | - public function set_discount( $value ) { |
|
| 2811 | - $this->set_total_discount( $value ); |
|
| 2805 | + * Alias of self::set_total_discount(). |
|
| 2806 | + * |
|
| 2807 | + * @since 1.0.19 |
|
| 2808 | + * @param float $value discount total. |
|
| 2809 | + */ |
|
| 2810 | + public function set_discount( $value ) { |
|
| 2811 | + $this->set_total_discount( $value ); |
|
| 2812 | 2812 | } |
| 2813 | 2813 | |
| 2814 | 2814 | /** |
| 2815 | - * Set the invoice tax amount. |
|
| 2816 | - * |
|
| 2817 | - * @since 1.0.19 |
|
| 2818 | - * @param float $value tax total. |
|
| 2819 | - */ |
|
| 2820 | - public function set_total_tax( $value ) { |
|
| 2821 | - $this->set_prop( 'total_tax', max( 0, $value ) ); |
|
| 2815 | + * Set the invoice tax amount. |
|
| 2816 | + * |
|
| 2817 | + * @since 1.0.19 |
|
| 2818 | + * @param float $value tax total. |
|
| 2819 | + */ |
|
| 2820 | + public function set_total_tax( $value ) { |
|
| 2821 | + $this->set_prop( 'total_tax', max( 0, $value ) ); |
|
| 2822 | 2822 | } |
| 2823 | 2823 | |
| 2824 | 2824 | /** |
| 2825 | - * Alias of self::set_total_tax(). |
|
| 2826 | - * |
|
| 2827 | - * @since 1.0.19 |
|
| 2828 | - * @param float $value tax total. |
|
| 2829 | - */ |
|
| 2830 | - public function set_tax_total( $value ) { |
|
| 2831 | - $this->set_total_tax( $value ); |
|
| 2825 | + * Alias of self::set_total_tax(). |
|
| 2826 | + * |
|
| 2827 | + * @since 1.0.19 |
|
| 2828 | + * @param float $value tax total. |
|
| 2829 | + */ |
|
| 2830 | + public function set_tax_total( $value ) { |
|
| 2831 | + $this->set_total_tax( $value ); |
|
| 2832 | 2832 | } |
| 2833 | 2833 | |
| 2834 | 2834 | /** |
| 2835 | - * Set the invoice fees amount. |
|
| 2836 | - * |
|
| 2837 | - * @since 1.0.19 |
|
| 2838 | - * @param float $value fees total. |
|
| 2839 | - */ |
|
| 2840 | - public function set_total_fees( $value ) { |
|
| 2841 | - $this->set_prop( 'total_fees', max( 0, $value ) ); |
|
| 2835 | + * Set the invoice fees amount. |
|
| 2836 | + * |
|
| 2837 | + * @since 1.0.19 |
|
| 2838 | + * @param float $value fees total. |
|
| 2839 | + */ |
|
| 2840 | + public function set_total_fees( $value ) { |
|
| 2841 | + $this->set_prop( 'total_fees', max( 0, $value ) ); |
|
| 2842 | 2842 | } |
| 2843 | 2843 | |
| 2844 | 2844 | /** |
| 2845 | - * Alias of self::set_total_fees(). |
|
| 2846 | - * |
|
| 2847 | - * @since 1.0.19 |
|
| 2848 | - * @param float $value fees total. |
|
| 2849 | - */ |
|
| 2850 | - public function set_fees_total( $value ) { |
|
| 2851 | - $this->set_total_fees( $value ); |
|
| 2845 | + * Alias of self::set_total_fees(). |
|
| 2846 | + * |
|
| 2847 | + * @since 1.0.19 |
|
| 2848 | + * @param float $value fees total. |
|
| 2849 | + */ |
|
| 2850 | + public function set_fees_total( $value ) { |
|
| 2851 | + $this->set_total_fees( $value ); |
|
| 2852 | 2852 | } |
| 2853 | 2853 | |
| 2854 | 2854 | /** |
| 2855 | - * Set the invoice fees. |
|
| 2856 | - * |
|
| 2857 | - * @since 1.0.19 |
|
| 2858 | - * @param array $value fees. |
|
| 2859 | - */ |
|
| 2860 | - public function set_fees( $value ) { |
|
| 2855 | + * Set the invoice fees. |
|
| 2856 | + * |
|
| 2857 | + * @since 1.0.19 |
|
| 2858 | + * @param array $value fees. |
|
| 2859 | + */ |
|
| 2860 | + public function set_fees( $value ) { |
|
| 2861 | 2861 | |
| 2862 | - if ( ! is_array( $value ) ) { |
|
| 2863 | - $value = array(); |
|
| 2864 | - } |
|
| 2862 | + if ( ! is_array( $value ) ) { |
|
| 2863 | + $value = array(); |
|
| 2864 | + } |
|
| 2865 | 2865 | |
| 2866 | - $this->set_prop( 'fees', $value ); |
|
| 2866 | + $this->set_prop( 'fees', $value ); |
|
| 2867 | 2867 | |
| 2868 | 2868 | } |
| 2869 | 2869 | |
| 2870 | 2870 | /** |
| 2871 | - * Set the invoice taxes. |
|
| 2872 | - * |
|
| 2873 | - * @since 1.0.19 |
|
| 2874 | - * @param array $value taxes. |
|
| 2875 | - */ |
|
| 2876 | - public function set_taxes( $value ) { |
|
| 2871 | + * Set the invoice taxes. |
|
| 2872 | + * |
|
| 2873 | + * @since 1.0.19 |
|
| 2874 | + * @param array $value taxes. |
|
| 2875 | + */ |
|
| 2876 | + public function set_taxes( $value ) { |
|
| 2877 | 2877 | |
| 2878 | - if ( ! is_array( $value ) ) { |
|
| 2879 | - $value = array(); |
|
| 2880 | - } |
|
| 2878 | + if ( ! is_array( $value ) ) { |
|
| 2879 | + $value = array(); |
|
| 2880 | + } |
|
| 2881 | 2881 | |
| 2882 | - $this->set_prop( 'taxes', $value ); |
|
| 2882 | + $this->set_prop( 'taxes', $value ); |
|
| 2883 | 2883 | |
| 2884 | 2884 | } |
| 2885 | 2885 | |
| 2886 | 2886 | /** |
| 2887 | - * Set the invoice discounts. |
|
| 2888 | - * |
|
| 2889 | - * @since 1.0.19 |
|
| 2890 | - * @param array $value discounts. |
|
| 2891 | - */ |
|
| 2892 | - public function set_discounts( $value ) { |
|
| 2887 | + * Set the invoice discounts. |
|
| 2888 | + * |
|
| 2889 | + * @since 1.0.19 |
|
| 2890 | + * @param array $value discounts. |
|
| 2891 | + */ |
|
| 2892 | + public function set_discounts( $value ) { |
|
| 2893 | 2893 | |
| 2894 | - if ( ! is_array( $value ) ) { |
|
| 2895 | - $value = array(); |
|
| 2896 | - } |
|
| 2894 | + if ( ! is_array( $value ) ) { |
|
| 2895 | + $value = array(); |
|
| 2896 | + } |
|
| 2897 | 2897 | |
| 2898 | - $this->set_prop( 'discounts', $value ); |
|
| 2898 | + $this->set_prop( 'discounts', $value ); |
|
| 2899 | 2899 | } |
| 2900 | 2900 | |
| 2901 | 2901 | /** |
| 2902 | - * Set the invoice items. |
|
| 2903 | - * |
|
| 2904 | - * @since 1.0.19 |
|
| 2905 | - * @param GetPaid_Form_Item[] $value items. |
|
| 2906 | - */ |
|
| 2907 | - public function set_items( $value ) { |
|
| 2902 | + * Set the invoice items. |
|
| 2903 | + * |
|
| 2904 | + * @since 1.0.19 |
|
| 2905 | + * @param GetPaid_Form_Item[] $value items. |
|
| 2906 | + */ |
|
| 2907 | + public function set_items( $value ) { |
|
| 2908 | 2908 | |
| 2909 | 2909 | // Remove existing items. |
| 2910 | 2910 | $this->set_prop( 'items', array() ); |
| 2911 | - $this->recurring_item = null; |
|
| 2911 | + $this->recurring_item = null; |
|
| 2912 | 2912 | |
| 2913 | 2913 | // Ensure that we have an array. |
| 2914 | 2914 | if ( ! is_array( $value ) ) { |
@@ -2922,95 +2922,95 @@ discard block |
||
| 2922 | 2922 | } |
| 2923 | 2923 | |
| 2924 | 2924 | /** |
| 2925 | - * Set the payment form. |
|
| 2926 | - * |
|
| 2927 | - * @since 1.0.19 |
|
| 2928 | - * @param int $value payment form. |
|
| 2929 | - */ |
|
| 2930 | - public function set_payment_form( $value ) { |
|
| 2931 | - $this->set_prop( 'payment_form', $value ); |
|
| 2925 | + * Set the payment form. |
|
| 2926 | + * |
|
| 2927 | + * @since 1.0.19 |
|
| 2928 | + * @param int $value payment form. |
|
| 2929 | + */ |
|
| 2930 | + public function set_payment_form( $value ) { |
|
| 2931 | + $this->set_prop( 'payment_form', $value ); |
|
| 2932 | 2932 | } |
| 2933 | 2933 | |
| 2934 | 2934 | /** |
| 2935 | - * Set the submission id. |
|
| 2936 | - * |
|
| 2937 | - * @since 1.0.19 |
|
| 2938 | - * @param string $value submission id. |
|
| 2939 | - */ |
|
| 2940 | - public function set_submission_id( $value ) { |
|
| 2941 | - $this->set_prop( 'submission_id', $value ); |
|
| 2935 | + * Set the submission id. |
|
| 2936 | + * |
|
| 2937 | + * @since 1.0.19 |
|
| 2938 | + * @param string $value submission id. |
|
| 2939 | + */ |
|
| 2940 | + public function set_submission_id( $value ) { |
|
| 2941 | + $this->set_prop( 'submission_id', $value ); |
|
| 2942 | 2942 | } |
| 2943 | 2943 | |
| 2944 | 2944 | /** |
| 2945 | - * Set the discount code. |
|
| 2946 | - * |
|
| 2947 | - * @since 1.0.19 |
|
| 2948 | - * @param string $value discount code. |
|
| 2949 | - */ |
|
| 2950 | - public function set_discount_code( $value ) { |
|
| 2951 | - $this->set_prop( 'discount_code', sanitize_text_field( $value ) ); |
|
| 2945 | + * Set the discount code. |
|
| 2946 | + * |
|
| 2947 | + * @since 1.0.19 |
|
| 2948 | + * @param string $value discount code. |
|
| 2949 | + */ |
|
| 2950 | + public function set_discount_code( $value ) { |
|
| 2951 | + $this->set_prop( 'discount_code', sanitize_text_field( $value ) ); |
|
| 2952 | 2952 | } |
| 2953 | 2953 | |
| 2954 | 2954 | /** |
| 2955 | - * Set the gateway. |
|
| 2956 | - * |
|
| 2957 | - * @since 1.0.19 |
|
| 2958 | - * @param string $value gateway. |
|
| 2959 | - */ |
|
| 2960 | - public function set_gateway( $value ) { |
|
| 2961 | - $this->set_prop( 'gateway', $value ); |
|
| 2955 | + * Set the gateway. |
|
| 2956 | + * |
|
| 2957 | + * @since 1.0.19 |
|
| 2958 | + * @param string $value gateway. |
|
| 2959 | + */ |
|
| 2960 | + public function set_gateway( $value ) { |
|
| 2961 | + $this->set_prop( 'gateway', $value ); |
|
| 2962 | 2962 | } |
| 2963 | 2963 | |
| 2964 | 2964 | /** |
| 2965 | - * Set the transaction id. |
|
| 2966 | - * |
|
| 2967 | - * @since 1.0.19 |
|
| 2968 | - * @param string $value transaction id. |
|
| 2969 | - */ |
|
| 2970 | - public function set_transaction_id( $value ) { |
|
| 2971 | - if ( ! empty( $value ) ) { |
|
| 2972 | - $this->set_prop( 'transaction_id', $value ); |
|
| 2973 | - } |
|
| 2965 | + * Set the transaction id. |
|
| 2966 | + * |
|
| 2967 | + * @since 1.0.19 |
|
| 2968 | + * @param string $value transaction id. |
|
| 2969 | + */ |
|
| 2970 | + public function set_transaction_id( $value ) { |
|
| 2971 | + if ( ! empty( $value ) ) { |
|
| 2972 | + $this->set_prop( 'transaction_id', $value ); |
|
| 2973 | + } |
|
| 2974 | 2974 | } |
| 2975 | 2975 | |
| 2976 | 2976 | /** |
| 2977 | - * Set the currency id. |
|
| 2978 | - * |
|
| 2979 | - * @since 1.0.19 |
|
| 2980 | - * @param string $value currency id. |
|
| 2981 | - */ |
|
| 2982 | - public function set_currency( $value ) { |
|
| 2983 | - $this->set_prop( 'currency', $value ); |
|
| 2977 | + * Set the currency id. |
|
| 2978 | + * |
|
| 2979 | + * @since 1.0.19 |
|
| 2980 | + * @param string $value currency id. |
|
| 2981 | + */ |
|
| 2982 | + public function set_currency( $value ) { |
|
| 2983 | + $this->set_prop( 'currency', $value ); |
|
| 2984 | 2984 | } |
| 2985 | 2985 | |
| 2986 | - /** |
|
| 2987 | - * Set whether to disable taxes. |
|
| 2988 | - * |
|
| 2989 | - * @since 1.0.19 |
|
| 2990 | - * @param bool $value value. |
|
| 2991 | - */ |
|
| 2992 | - public function set_disable_taxes( $value ) { |
|
| 2993 | - $this->set_prop( 'disable_taxes', (bool) $value ); |
|
| 2994 | - } |
|
| 2986 | + /** |
|
| 2987 | + * Set whether to disable taxes. |
|
| 2988 | + * |
|
| 2989 | + * @since 1.0.19 |
|
| 2990 | + * @param bool $value value. |
|
| 2991 | + */ |
|
| 2992 | + public function set_disable_taxes( $value ) { |
|
| 2993 | + $this->set_prop( 'disable_taxes', (bool) $value ); |
|
| 2994 | + } |
|
| 2995 | 2995 | |
| 2996 | 2996 | /** |
| 2997 | - * Set the subscription id. |
|
| 2998 | - * |
|
| 2999 | - * @since 1.0.19 |
|
| 3000 | - * @param string $value subscription id. |
|
| 3001 | - */ |
|
| 3002 | - public function set_subscription_id( $value ) { |
|
| 3003 | - $this->set_prop( 'subscription_id', $value ); |
|
| 3004 | - } |
|
| 2997 | + * Set the subscription id. |
|
| 2998 | + * |
|
| 2999 | + * @since 1.0.19 |
|
| 3000 | + * @param string $value subscription id. |
|
| 3001 | + */ |
|
| 3002 | + public function set_subscription_id( $value ) { |
|
| 3003 | + $this->set_prop( 'subscription_id', $value ); |
|
| 3004 | + } |
|
| 3005 | 3005 | |
| 3006 | - /** |
|
| 3007 | - * Set the remote subscription id. |
|
| 3008 | - * |
|
| 3009 | - * @since 1.0.19 |
|
| 3010 | - * @param string $value subscription id. |
|
| 3011 | - */ |
|
| 3012 | - public function set_remote_subscription_id( $value ) { |
|
| 3013 | - $this->set_prop( 'remote_subscription_id', $value ); |
|
| 3006 | + /** |
|
| 3007 | + * Set the remote subscription id. |
|
| 3008 | + * |
|
| 3009 | + * @since 1.0.19 |
|
| 3010 | + * @param string $value subscription id. |
|
| 3011 | + */ |
|
| 3012 | + public function set_remote_subscription_id( $value ) { |
|
| 3013 | + $this->set_prop( 'remote_subscription_id', $value ); |
|
| 3014 | 3014 | } |
| 3015 | 3015 | |
| 3016 | 3016 | /* |
@@ -3049,24 +3049,24 @@ discard block |
||
| 3049 | 3049 | */ |
| 3050 | 3050 | public function is_taxable() { |
| 3051 | 3051 | return ! $this->get_disable_taxes(); |
| 3052 | - } |
|
| 3052 | + } |
|
| 3053 | 3053 | |
| 3054 | - /** |
|
| 3055 | - * @deprecated |
|
| 3056 | - */ |
|
| 3057 | - public function has_vat() { |
|
| 3054 | + /** |
|
| 3055 | + * @deprecated |
|
| 3056 | + */ |
|
| 3057 | + public function has_vat() { |
|
| 3058 | 3058 | return $this->is_taxable(); |
| 3059 | - } |
|
| 3059 | + } |
|
| 3060 | 3060 | |
| 3061 | - /** |
|
| 3062 | - * Checks to see if the invoice requires payment. |
|
| 3063 | - */ |
|
| 3064 | - public function is_free() { |
|
| 3061 | + /** |
|
| 3062 | + * Checks to see if the invoice requires payment. |
|
| 3063 | + */ |
|
| 3064 | + public function is_free() { |
|
| 3065 | 3065 | $is_free = ( (float) wpinv_round_amount( $this->get_initial_total() ) == 0 ); |
| 3066 | 3066 | |
| 3067 | - if ( $this->is_recurring() && $this->get_recurring_total() > 0 ) { |
|
| 3068 | - $is_free = false; |
|
| 3069 | - } |
|
| 3067 | + if ( $this->is_recurring() && $this->get_recurring_total() > 0 ) { |
|
| 3068 | + $is_free = false; |
|
| 3069 | + } |
|
| 3070 | 3070 | |
| 3071 | 3071 | return apply_filters( 'wpinv_invoice_is_free', $is_free, $this ); |
| 3072 | 3072 | } |
@@ -3077,46 +3077,46 @@ discard block |
||
| 3077 | 3077 | public function is_paid() { |
| 3078 | 3078 | $is_paid = $this->has_status( array( 'publish', 'wpi-processing', 'wpi-renewal' ) ); |
| 3079 | 3079 | return apply_filters( 'wpinv_invoice_is_paid', $is_paid, $this ); |
| 3080 | - } |
|
| 3080 | + } |
|
| 3081 | 3081 | |
| 3082 | - /** |
|
| 3082 | + /** |
|
| 3083 | 3083 | * Checks if the invoice needs payment. |
| 3084 | 3084 | */ |
| 3085 | - public function needs_payment() { |
|
| 3086 | - $needs_payment = ! $this->is_paid() && ! $this->is_refunded() && ! $this->is_free(); |
|
| 3085 | + public function needs_payment() { |
|
| 3086 | + $needs_payment = ! $this->is_paid() && ! $this->is_refunded() && ! $this->is_free(); |
|
| 3087 | 3087 | return apply_filters( 'wpinv_needs_payment', $needs_payment, $this ); |
| 3088 | 3088 | } |
| 3089 | 3089 | |
| 3090 | - /** |
|
| 3090 | + /** |
|
| 3091 | 3091 | * Checks if the invoice is refunded. |
| 3092 | 3092 | */ |
| 3093 | - public function is_refunded() { |
|
| 3093 | + public function is_refunded() { |
|
| 3094 | 3094 | $is_refunded = $this->has_status( 'wpi-refunded' ); |
| 3095 | 3095 | return apply_filters( 'wpinv_invoice_is_refunded', $is_refunded, $this ); |
| 3096 | - } |
|
| 3096 | + } |
|
| 3097 | 3097 | |
| 3098 | - /** |
|
| 3098 | + /** |
|
| 3099 | 3099 | * Checks if the invoice is held. |
| 3100 | 3100 | */ |
| 3101 | - public function is_held() { |
|
| 3101 | + public function is_held() { |
|
| 3102 | 3102 | $is_held = $this->has_status( 'wpi-onhold' ); |
| 3103 | 3103 | return apply_filters( 'wpinv_invoice_is_held', $is_held, $this ); |
| 3104 | - } |
|
| 3104 | + } |
|
| 3105 | 3105 | |
| 3106 | - /** |
|
| 3106 | + /** |
|
| 3107 | 3107 | * Checks if the invoice is due. |
| 3108 | 3108 | */ |
| 3109 | - public function is_due() { |
|
| 3110 | - $due_date = $this->get_due_date(); |
|
| 3111 | - return empty( $due_date ) ? false : current_time( 'timestamp' ) > strtotime( $due_date ); |
|
| 3112 | - } |
|
| 3109 | + public function is_due() { |
|
| 3110 | + $due_date = $this->get_due_date(); |
|
| 3111 | + return empty( $due_date ) ? false : current_time( 'timestamp' ) > strtotime( $due_date ); |
|
| 3112 | + } |
|
| 3113 | 3113 | |
| 3114 | - /** |
|
| 3114 | + /** |
|
| 3115 | 3115 | * Checks if the invoice is draft. |
| 3116 | 3116 | */ |
| 3117 | - public function is_draft() { |
|
| 3117 | + public function is_draft() { |
|
| 3118 | 3118 | return $this->has_status( 'draft, auto-draft' ); |
| 3119 | - } |
|
| 3119 | + } |
|
| 3120 | 3120 | |
| 3121 | 3121 | /** |
| 3122 | 3122 | * Checks if the invoice has a given status. |
@@ -3124,9 +3124,9 @@ discard block |
||
| 3124 | 3124 | public function has_status( $status ) { |
| 3125 | 3125 | $status = wpinv_parse_list( $status ); |
| 3126 | 3126 | return apply_filters( 'wpinv_has_status', in_array( $this->get_status(), $status ), $status ); |
| 3127 | - } |
|
| 3127 | + } |
|
| 3128 | 3128 | |
| 3129 | - /** |
|
| 3129 | + /** |
|
| 3130 | 3130 | * Checks if the invoice is of a given type. |
| 3131 | 3131 | */ |
| 3132 | 3132 | public function is_type( $type ) { |
@@ -3149,25 +3149,25 @@ discard block |
||
| 3149 | 3149 | */ |
| 3150 | 3150 | public function has_free_trial() { |
| 3151 | 3151 | return $this->is_recurring() && 0 == $this->get_initial_total(); |
| 3152 | - } |
|
| 3152 | + } |
|
| 3153 | 3153 | |
| 3154 | - /** |
|
| 3154 | + /** |
|
| 3155 | 3155 | * @deprecated |
| 3156 | 3156 | */ |
| 3157 | 3157 | public function is_free_trial() { |
| 3158 | 3158 | $this->has_free_trial(); |
| 3159 | 3159 | } |
| 3160 | 3160 | |
| 3161 | - /** |
|
| 3161 | + /** |
|
| 3162 | 3162 | * Check if the initial payment if 0. |
| 3163 | 3163 | * |
| 3164 | 3164 | */ |
| 3165 | - public function is_initial_free() { |
|
| 3165 | + public function is_initial_free() { |
|
| 3166 | 3166 | $is_initial_free = ! ( (float) wpinv_round_amount( $this->get_initial_total() ) > 0 ); |
| 3167 | 3167 | return apply_filters( 'wpinv_invoice_is_initial_free', $is_initial_free, $this->get_cart_details(), $this ); |
| 3168 | 3168 | } |
| 3169 | 3169 | |
| 3170 | - /** |
|
| 3170 | + /** |
|
| 3171 | 3171 | * Check if the recurring item has a free trial. |
| 3172 | 3172 | * |
| 3173 | 3173 | */ |
@@ -3180,21 +3180,21 @@ discard block |
||
| 3180 | 3180 | |
| 3181 | 3181 | $item = $this->get_recurring( true ); |
| 3182 | 3182 | return $item->has_free_trial(); |
| 3183 | - } |
|
| 3183 | + } |
|
| 3184 | 3184 | |
| 3185 | - /** |
|
| 3185 | + /** |
|
| 3186 | 3186 | * Check if the free trial is a result of a discount. |
| 3187 | 3187 | */ |
| 3188 | 3188 | public function is_free_trial_from_discount() { |
| 3189 | - return $this->has_free_trial() && ! $this->item_has_free_trial(); |
|
| 3190 | - } |
|
| 3189 | + return $this->has_free_trial() && ! $this->item_has_free_trial(); |
|
| 3190 | + } |
|
| 3191 | 3191 | |
| 3192 | - /** |
|
| 3192 | + /** |
|
| 3193 | 3193 | * @deprecated |
| 3194 | 3194 | */ |
| 3195 | 3195 | public function discount_first_payment_only() { |
| 3196 | 3196 | |
| 3197 | - $discount = wpinv_get_discount_obj( $this->get_discount_code() ); |
|
| 3197 | + $discount = wpinv_get_discount_obj( $this->get_discount_code() ); |
|
| 3198 | 3198 | if ( ! $discount->exists() || ! $this->is_recurring() ) { |
| 3199 | 3199 | return true; |
| 3200 | 3200 | } |
@@ -3219,143 +3219,143 @@ discard block |
||
| 3219 | 3219 | */ |
| 3220 | 3220 | public function add_item( $item ) { |
| 3221 | 3221 | |
| 3222 | - if ( is_array( $item ) ) { |
|
| 3223 | - $item = $this->process_array_item( $item ); |
|
| 3224 | - } |
|
| 3222 | + if ( is_array( $item ) ) { |
|
| 3223 | + $item = $this->process_array_item( $item ); |
|
| 3224 | + } |
|
| 3225 | 3225 | |
| 3226 | - if ( is_numeric( $item ) ) { |
|
| 3227 | - $item = new GetPaid_Form_Item( $item ); |
|
| 3228 | - } |
|
| 3226 | + if ( is_numeric( $item ) ) { |
|
| 3227 | + $item = new GetPaid_Form_Item( $item ); |
|
| 3228 | + } |
|
| 3229 | 3229 | |
| 3230 | 3230 | // Make sure that it is available for purchase. |
| 3231 | - if ( $item->get_id() > 0 && ! $item->can_purchase() ) { |
|
| 3232 | - return new WP_Error( 'invalid_item', __( 'This item is not available for purchase', 'invoicing' ) ); |
|
| 3231 | + if ( $item->get_id() > 0 && ! $item->can_purchase() ) { |
|
| 3232 | + return new WP_Error( 'invalid_item', __( 'This item is not available for purchase', 'invoicing' ) ); |
|
| 3233 | 3233 | } |
| 3234 | 3234 | |
| 3235 | 3235 | // Do we have a recurring item? |
| 3236 | - if ( $item->is_recurring() ) { |
|
| 3237 | - $this->recurring_item = $item->get_id(); |
|
| 3236 | + if ( $item->is_recurring() ) { |
|
| 3237 | + $this->recurring_item = $item->get_id(); |
|
| 3238 | 3238 | } |
| 3239 | 3239 | |
| 3240 | 3240 | // Invoice id. |
| 3241 | 3241 | $item->invoice_id = (int) $this->get_id(); |
| 3242 | 3242 | |
| 3243 | - // Remove duplicates. |
|
| 3244 | - $this->remove_item( $item->get_id() ); |
|
| 3243 | + // Remove duplicates. |
|
| 3244 | + $this->remove_item( $item->get_id() ); |
|
| 3245 | 3245 | |
| 3246 | - // Retrieve all items. |
|
| 3246 | + // Retrieve all items. |
|
| 3247 | 3247 | $items = $this->get_items(); |
| 3248 | 3248 | |
| 3249 | - // Add new item. |
|
| 3249 | + // Add new item. |
|
| 3250 | 3250 | $items[] = $item; |
| 3251 | 3251 | |
| 3252 | 3252 | $this->set_prop( 'items', $items ); |
| 3253 | 3253 | |
| 3254 | - return true; |
|
| 3255 | - } |
|
| 3254 | + return true; |
|
| 3255 | + } |
|
| 3256 | 3256 | |
| 3257 | - /** |
|
| 3258 | - * Converts an array to an item. |
|
| 3259 | - * |
|
| 3260 | - * @since 1.0.19 |
|
| 3261 | - * @return GetPaid_Form_Item |
|
| 3262 | - */ |
|
| 3263 | - protected function process_array_item( $array ) { |
|
| 3257 | + /** |
|
| 3258 | + * Converts an array to an item. |
|
| 3259 | + * |
|
| 3260 | + * @since 1.0.19 |
|
| 3261 | + * @return GetPaid_Form_Item |
|
| 3262 | + */ |
|
| 3263 | + protected function process_array_item( $array ) { |
|
| 3264 | 3264 | |
| 3265 | - $item_id = isset( $array['item_id'] ) ? $array['item_id'] : 0; |
|
| 3266 | - $item = new GetPaid_Form_Item( $item_id ); |
|
| 3265 | + $item_id = isset( $array['item_id'] ) ? $array['item_id'] : 0; |
|
| 3266 | + $item = new GetPaid_Form_Item( $item_id ); |
|
| 3267 | 3267 | |
| 3268 | - // Set item data. |
|
| 3269 | - foreach ( array( 'name', 'price', 'description' ) as $key ) { |
|
| 3270 | - if ( isset( $array[ "item_$key" ] ) ) { |
|
| 3271 | - $method = "set_$key"; |
|
| 3272 | - $item->$method( $array[ "item_$key" ] ); |
|
| 3273 | - } |
|
| 3274 | - } |
|
| 3268 | + // Set item data. |
|
| 3269 | + foreach ( array( 'name', 'price', 'description' ) as $key ) { |
|
| 3270 | + if ( isset( $array[ "item_$key" ] ) ) { |
|
| 3271 | + $method = "set_$key"; |
|
| 3272 | + $item->$method( $array[ "item_$key" ] ); |
|
| 3273 | + } |
|
| 3274 | + } |
|
| 3275 | 3275 | |
| 3276 | - if ( isset( $array['quantity'] ) ) { |
|
| 3277 | - $item->set_quantity( $array['quantity'] ); |
|
| 3278 | - } |
|
| 3276 | + if ( isset( $array['quantity'] ) ) { |
|
| 3277 | + $item->set_quantity( $array['quantity'] ); |
|
| 3278 | + } |
|
| 3279 | 3279 | |
| 3280 | - // Set item meta. |
|
| 3281 | - if ( isset( $array['meta'] ) && is_array( $array['meta'] ) ) { |
|
| 3282 | - $item->set_item_meta( $array['meta'] ); |
|
| 3283 | - } |
|
| 3280 | + // Set item meta. |
|
| 3281 | + if ( isset( $array['meta'] ) && is_array( $array['meta'] ) ) { |
|
| 3282 | + $item->set_item_meta( $array['meta'] ); |
|
| 3283 | + } |
|
| 3284 | 3284 | |
| 3285 | - return $item; |
|
| 3285 | + return $item; |
|
| 3286 | 3286 | |
| 3287 | - } |
|
| 3287 | + } |
|
| 3288 | 3288 | |
| 3289 | 3289 | /** |
| 3290 | - * Retrieves a specific item. |
|
| 3291 | - * |
|
| 3292 | - * @since 1.0.19 |
|
| 3293 | - * @return GetPaid_Form_Item|null |
|
| 3294 | - */ |
|
| 3295 | - public function get_item( $item_id ) { |
|
| 3290 | + * Retrieves a specific item. |
|
| 3291 | + * |
|
| 3292 | + * @since 1.0.19 |
|
| 3293 | + * @return GetPaid_Form_Item|null |
|
| 3294 | + */ |
|
| 3295 | + public function get_item( $item_id ) { |
|
| 3296 | 3296 | |
| 3297 | - foreach ( $this->get_items() as $item ) { |
|
| 3298 | - if ( (int) $item_id == $item->get_id() ) { |
|
| 3299 | - return $item; |
|
| 3300 | - } |
|
| 3301 | - } |
|
| 3297 | + foreach ( $this->get_items() as $item ) { |
|
| 3298 | + if ( (int) $item_id == $item->get_id() ) { |
|
| 3299 | + return $item; |
|
| 3300 | + } |
|
| 3301 | + } |
|
| 3302 | 3302 | |
| 3303 | - return null; |
|
| 3303 | + return null; |
|
| 3304 | 3304 | } |
| 3305 | 3305 | |
| 3306 | 3306 | /** |
| 3307 | - * Removes a specific item. |
|
| 3308 | - * |
|
| 3309 | - * @since 1.0.19 |
|
| 3310 | - */ |
|
| 3311 | - public function remove_item( $item_id ) { |
|
| 3312 | - $items = $this->get_items(); |
|
| 3313 | - $item_id = (int) $item_id; |
|
| 3307 | + * Removes a specific item. |
|
| 3308 | + * |
|
| 3309 | + * @since 1.0.19 |
|
| 3310 | + */ |
|
| 3311 | + public function remove_item( $item_id ) { |
|
| 3312 | + $items = $this->get_items(); |
|
| 3313 | + $item_id = (int) $item_id; |
|
| 3314 | 3314 | |
| 3315 | - foreach ( $items as $index => $item ) { |
|
| 3316 | - if ( (int) $item_id == $item->get_id() ) { |
|
| 3317 | - unset( $items[ $index ] ); |
|
| 3318 | - $this->set_prop( 'items', $items ); |
|
| 3315 | + foreach ( $items as $index => $item ) { |
|
| 3316 | + if ( (int) $item_id == $item->get_id() ) { |
|
| 3317 | + unset( $items[ $index ] ); |
|
| 3318 | + $this->set_prop( 'items', $items ); |
|
| 3319 | 3319 | |
| 3320 | - if ( $item_id == $this->recurring_item ) { |
|
| 3321 | - $this->recurring_item = null; |
|
| 3322 | - } |
|
| 3320 | + if ( $item_id == $this->recurring_item ) { |
|
| 3321 | + $this->recurring_item = null; |
|
| 3322 | + } |
|
| 3323 | 3323 | |
| 3324 | - } |
|
| 3325 | - } |
|
| 3324 | + } |
|
| 3325 | + } |
|
| 3326 | 3326 | |
| 3327 | 3327 | } |
| 3328 | 3328 | |
| 3329 | 3329 | /** |
| 3330 | - * Adds a fee to the invoice. |
|
| 3331 | - * |
|
| 3332 | - * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required. |
|
| 3333 | - * @since 1.0.19 |
|
| 3334 | - */ |
|
| 3330 | + * Adds a fee to the invoice. |
|
| 3331 | + * |
|
| 3332 | + * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required. |
|
| 3333 | + * @since 1.0.19 |
|
| 3334 | + */ |
|
| 3335 | 3335 | public function add_fee( $fee ) { |
| 3336 | 3336 | |
| 3337 | - $fees = $this->get_fees(); |
|
| 3338 | - $fees[ $fee['name'] ] = $fee; |
|
| 3339 | - $this->set_prop( 'fees', $fees ); |
|
| 3337 | + $fees = $this->get_fees(); |
|
| 3338 | + $fees[ $fee['name'] ] = $fee; |
|
| 3339 | + $this->set_prop( 'fees', $fees ); |
|
| 3340 | 3340 | |
| 3341 | 3341 | } |
| 3342 | 3342 | |
| 3343 | 3343 | /** |
| 3344 | - * Retrieves a specific fee. |
|
| 3345 | - * |
|
| 3346 | - * @since 1.0.19 |
|
| 3347 | - */ |
|
| 3348 | - public function get_fee( $fee ) { |
|
| 3344 | + * Retrieves a specific fee. |
|
| 3345 | + * |
|
| 3346 | + * @since 1.0.19 |
|
| 3347 | + */ |
|
| 3348 | + public function get_fee( $fee ) { |
|
| 3349 | 3349 | $fees = $this->get_fees(); |
| 3350 | - return isset( $fees[ $fee ] ) ? $fees[ $fee ] : null; |
|
| 3350 | + return isset( $fees[ $fee ] ) ? $fees[ $fee ] : null; |
|
| 3351 | 3351 | } |
| 3352 | 3352 | |
| 3353 | 3353 | /** |
| 3354 | - * Removes a specific fee. |
|
| 3355 | - * |
|
| 3356 | - * @since 1.0.19 |
|
| 3357 | - */ |
|
| 3358 | - public function remove_fee( $fee ) { |
|
| 3354 | + * Removes a specific fee. |
|
| 3355 | + * |
|
| 3356 | + * @since 1.0.19 |
|
| 3357 | + */ |
|
| 3358 | + public function remove_fee( $fee ) { |
|
| 3359 | 3359 | $fees = $this->get_fees(); |
| 3360 | 3360 | if ( isset( $fees[ $fee ] ) ) { |
| 3361 | 3361 | unset( $fees[ $fee ] ); |
@@ -3363,55 +3363,55 @@ discard block |
||
| 3363 | 3363 | } |
| 3364 | 3364 | } |
| 3365 | 3365 | |
| 3366 | - /** |
|
| 3367 | - * Adds a discount to the invoice. |
|
| 3368 | - * |
|
| 3369 | - * @param array $discount An array of discount details. name, initial_discount, and recurring_discount are required. Include discount_code if the discount is from a discount code. |
|
| 3370 | - * @since 1.0.19 |
|
| 3371 | - */ |
|
| 3372 | - public function add_discount( $discount ) { |
|
| 3366 | + /** |
|
| 3367 | + * Adds a discount to the invoice. |
|
| 3368 | + * |
|
| 3369 | + * @param array $discount An array of discount details. name, initial_discount, and recurring_discount are required. Include discount_code if the discount is from a discount code. |
|
| 3370 | + * @since 1.0.19 |
|
| 3371 | + */ |
|
| 3372 | + public function add_discount( $discount ) { |
|
| 3373 | 3373 | |
| 3374 | - $discounts = $this->get_discounts(); |
|
| 3375 | - $discounts[ $discount['name'] ] = $discount; |
|
| 3376 | - $this->set_prop( 'discounts', $discounts ); |
|
| 3374 | + $discounts = $this->get_discounts(); |
|
| 3375 | + $discounts[ $discount['name'] ] = $discount; |
|
| 3376 | + $this->set_prop( 'discounts', $discounts ); |
|
| 3377 | 3377 | |
| 3378 | - } |
|
| 3378 | + } |
|
| 3379 | 3379 | |
| 3380 | 3380 | /** |
| 3381 | - * Retrieves a specific discount. |
|
| 3382 | - * |
|
| 3383 | - * @since 1.0.19 |
|
| 3384 | - * @return float |
|
| 3385 | - */ |
|
| 3386 | - public function get_discount( $discount = false ) { |
|
| 3381 | + * Retrieves a specific discount. |
|
| 3382 | + * |
|
| 3383 | + * @since 1.0.19 |
|
| 3384 | + * @return float |
|
| 3385 | + */ |
|
| 3386 | + public function get_discount( $discount = false ) { |
|
| 3387 | 3387 | |
| 3388 | - // Backwards compatibilty. |
|
| 3389 | - if ( empty( $discount ) ) { |
|
| 3390 | - return $this->get_total_discount(); |
|
| 3391 | - } |
|
| 3388 | + // Backwards compatibilty. |
|
| 3389 | + if ( empty( $discount ) ) { |
|
| 3390 | + return $this->get_total_discount(); |
|
| 3391 | + } |
|
| 3392 | 3392 | |
| 3393 | 3393 | $discounts = $this->get_discounts(); |
| 3394 | - return isset( $discounts[ $discount ] ) ? $discounts[ $discount ] : null; |
|
| 3394 | + return isset( $discounts[ $discount ] ) ? $discounts[ $discount ] : null; |
|
| 3395 | 3395 | } |
| 3396 | 3396 | |
| 3397 | 3397 | /** |
| 3398 | - * Removes a specific discount. |
|
| 3399 | - * |
|
| 3400 | - * @since 1.0.19 |
|
| 3401 | - */ |
|
| 3402 | - public function remove_discount( $discount ) { |
|
| 3398 | + * Removes a specific discount. |
|
| 3399 | + * |
|
| 3400 | + * @since 1.0.19 |
|
| 3401 | + */ |
|
| 3402 | + public function remove_discount( $discount ) { |
|
| 3403 | 3403 | $discounts = $this->get_discounts(); |
| 3404 | 3404 | if ( isset( $discounts[ $discount ] ) ) { |
| 3405 | 3405 | unset( $discounts[ $discount ] ); |
| 3406 | 3406 | $this->set_prop( 'discounts', $discounts ); |
| 3407 | 3407 | } |
| 3408 | 3408 | |
| 3409 | - if ( 'discount_code' == $discount ) { |
|
| 3410 | - foreach ( $this->get_items() as $item ) { |
|
| 3411 | - $item->item_discount = 0; |
|
| 3412 | - $item->recurring_item_discount = 0; |
|
| 3413 | - } |
|
| 3414 | - } |
|
| 3409 | + if ( 'discount_code' == $discount ) { |
|
| 3410 | + foreach ( $this->get_items() as $item ) { |
|
| 3411 | + $item->item_discount = 0; |
|
| 3412 | + $item->recurring_item_discount = 0; |
|
| 3413 | + } |
|
| 3414 | + } |
|
| 3415 | 3415 | |
| 3416 | 3416 | } |
| 3417 | 3417 | |
@@ -3424,34 +3424,34 @@ discard block |
||
| 3424 | 3424 | if ( $this->is_taxable() ) { |
| 3425 | 3425 | |
| 3426 | 3426 | $taxes = $this->get_taxes(); |
| 3427 | - $taxes[ $tax['name'] ] = $tax; |
|
| 3428 | - $this->set_prop( 'taxes', $tax ); |
|
| 3427 | + $taxes[ $tax['name'] ] = $tax; |
|
| 3428 | + $this->set_prop( 'taxes', $tax ); |
|
| 3429 | 3429 | |
| 3430 | 3430 | } |
| 3431 | 3431 | } |
| 3432 | 3432 | |
| 3433 | 3433 | /** |
| 3434 | - * Retrieves a specific tax. |
|
| 3435 | - * |
|
| 3436 | - * @since 1.0.19 |
|
| 3437 | - */ |
|
| 3438 | - public function get_tax( $tax = null ) { |
|
| 3434 | + * Retrieves a specific tax. |
|
| 3435 | + * |
|
| 3436 | + * @since 1.0.19 |
|
| 3437 | + */ |
|
| 3438 | + public function get_tax( $tax = null ) { |
|
| 3439 | 3439 | |
| 3440 | - // Backwards compatility. |
|
| 3441 | - if ( empty( $tax ) ) { |
|
| 3442 | - return $this->get_total_tax(); |
|
| 3443 | - } |
|
| 3440 | + // Backwards compatility. |
|
| 3441 | + if ( empty( $tax ) ) { |
|
| 3442 | + return $this->get_total_tax(); |
|
| 3443 | + } |
|
| 3444 | 3444 | |
| 3445 | 3445 | $taxes = $this->get_taxes(); |
| 3446 | - return isset( $taxes[ $tax ] ) ? $taxes[ $tax ] : null; |
|
| 3446 | + return isset( $taxes[ $tax ] ) ? $taxes[ $tax ] : null; |
|
| 3447 | 3447 | } |
| 3448 | 3448 | |
| 3449 | 3449 | /** |
| 3450 | - * Removes a specific tax. |
|
| 3451 | - * |
|
| 3452 | - * @since 1.0.19 |
|
| 3453 | - */ |
|
| 3454 | - public function remove_tax( $tax ) { |
|
| 3450 | + * Removes a specific tax. |
|
| 3451 | + * |
|
| 3452 | + * @since 1.0.19 |
|
| 3453 | + */ |
|
| 3454 | + public function remove_tax( $tax ) { |
|
| 3455 | 3455 | $taxes = $this->get_taxes(); |
| 3456 | 3456 | if ( isset( $taxes[ $tax ] ) ) { |
| 3457 | 3457 | unset( $taxes[ $tax ] ); |
@@ -3460,185 +3460,185 @@ discard block |
||
| 3460 | 3460 | } |
| 3461 | 3461 | |
| 3462 | 3462 | /** |
| 3463 | - * Recalculates the invoice subtotal. |
|
| 3464 | - * |
|
| 3465 | - * @since 1.0.19 |
|
| 3466 | - * @return float The recalculated subtotal |
|
| 3467 | - */ |
|
| 3468 | - public function recalculate_subtotal() { |
|
| 3463 | + * Recalculates the invoice subtotal. |
|
| 3464 | + * |
|
| 3465 | + * @since 1.0.19 |
|
| 3466 | + * @return float The recalculated subtotal |
|
| 3467 | + */ |
|
| 3468 | + public function recalculate_subtotal() { |
|
| 3469 | 3469 | $items = $this->get_items(); |
| 3470 | - $subtotal = 0; |
|
| 3471 | - $recurring = 0; |
|
| 3470 | + $subtotal = 0; |
|
| 3471 | + $recurring = 0; |
|
| 3472 | 3472 | |
| 3473 | 3473 | foreach ( $items as $item ) { |
| 3474 | - $subtotal += $item->get_sub_total(); |
|
| 3475 | - $recurring += $item->get_recurring_sub_total(); |
|
| 3474 | + $subtotal += $item->get_sub_total(); |
|
| 3475 | + $recurring += $item->get_recurring_sub_total(); |
|
| 3476 | 3476 | } |
| 3477 | 3477 | |
| 3478 | - if ( wpinv_prices_include_tax() ) { |
|
| 3479 | - $subtotal = max( 0, $subtotal - $this->totals['tax']['initial'] ); |
|
| 3480 | - $recurring = max( 0, $recurring - $this->totals['tax']['recurring'] ); |
|
| 3481 | - } |
|
| 3478 | + if ( wpinv_prices_include_tax() ) { |
|
| 3479 | + $subtotal = max( 0, $subtotal - $this->totals['tax']['initial'] ); |
|
| 3480 | + $recurring = max( 0, $recurring - $this->totals['tax']['recurring'] ); |
|
| 3481 | + } |
|
| 3482 | 3482 | |
| 3483 | - $current = $this->is_renewal() ? $recurring : $subtotal; |
|
| 3484 | - $this->set_subtotal( $current ); |
|
| 3483 | + $current = $this->is_renewal() ? $recurring : $subtotal; |
|
| 3484 | + $this->set_subtotal( $current ); |
|
| 3485 | 3485 | |
| 3486 | - $this->totals['subtotal'] = array( |
|
| 3487 | - 'initial' => $subtotal, |
|
| 3488 | - 'recurring' => $recurring, |
|
| 3489 | - ); |
|
| 3486 | + $this->totals['subtotal'] = array( |
|
| 3487 | + 'initial' => $subtotal, |
|
| 3488 | + 'recurring' => $recurring, |
|
| 3489 | + ); |
|
| 3490 | 3490 | |
| 3491 | 3491 | return $current; |
| 3492 | 3492 | } |
| 3493 | 3493 | |
| 3494 | 3494 | /** |
| 3495 | - * Recalculates the invoice discount total. |
|
| 3496 | - * |
|
| 3497 | - * @since 1.0.19 |
|
| 3498 | - * @return float The recalculated discount |
|
| 3499 | - */ |
|
| 3500 | - public function recalculate_total_discount() { |
|
| 3495 | + * Recalculates the invoice discount total. |
|
| 3496 | + * |
|
| 3497 | + * @since 1.0.19 |
|
| 3498 | + * @return float The recalculated discount |
|
| 3499 | + */ |
|
| 3500 | + public function recalculate_total_discount() { |
|
| 3501 | 3501 | $discounts = $this->get_discounts(); |
| 3502 | - $discount = 0; |
|
| 3503 | - $recurring = 0; |
|
| 3502 | + $discount = 0; |
|
| 3503 | + $recurring = 0; |
|
| 3504 | 3504 | |
| 3505 | 3505 | foreach ( $discounts as $data ) { |
| 3506 | - $discount += wpinv_sanitize_amount( $data['initial_discount'] ); |
|
| 3507 | - $recurring += wpinv_sanitize_amount( $data['recurring_discount'] ); |
|
| 3508 | - } |
|
| 3506 | + $discount += wpinv_sanitize_amount( $data['initial_discount'] ); |
|
| 3507 | + $recurring += wpinv_sanitize_amount( $data['recurring_discount'] ); |
|
| 3508 | + } |
|
| 3509 | 3509 | |
| 3510 | - $current = $this->is_renewal() ? $recurring : $discount; |
|
| 3510 | + $current = $this->is_renewal() ? $recurring : $discount; |
|
| 3511 | 3511 | |
| 3512 | - $this->set_total_discount( $current ); |
|
| 3512 | + $this->set_total_discount( $current ); |
|
| 3513 | 3513 | |
| 3514 | - $this->totals['discount'] = array( |
|
| 3515 | - 'initial' => $discount, |
|
| 3516 | - 'recurring' => $recurring, |
|
| 3517 | - ); |
|
| 3514 | + $this->totals['discount'] = array( |
|
| 3515 | + 'initial' => $discount, |
|
| 3516 | + 'recurring' => $recurring, |
|
| 3517 | + ); |
|
| 3518 | 3518 | |
| 3519 | - return $current; |
|
| 3519 | + return $current; |
|
| 3520 | 3520 | |
| 3521 | 3521 | } |
| 3522 | 3522 | |
| 3523 | 3523 | /** |
| 3524 | - * Recalculates the invoice tax total. |
|
| 3525 | - * |
|
| 3526 | - * @since 1.0.19 |
|
| 3527 | - * @return float The recalculated tax |
|
| 3528 | - */ |
|
| 3529 | - public function recalculate_total_tax() { |
|
| 3524 | + * Recalculates the invoice tax total. |
|
| 3525 | + * |
|
| 3526 | + * @since 1.0.19 |
|
| 3527 | + * @return float The recalculated tax |
|
| 3528 | + */ |
|
| 3529 | + public function recalculate_total_tax() { |
|
| 3530 | 3530 | |
| 3531 | - // Maybe disable taxes. |
|
| 3532 | - $vat_number = $this->get_vat_number(); |
|
| 3533 | - $skip_tax = GetPaid_Payment_Form_Submission_Taxes::is_eu_transaction( $this->get_country() ) && ! empty( $vat_number ); |
|
| 3531 | + // Maybe disable taxes. |
|
| 3532 | + $vat_number = $this->get_vat_number(); |
|
| 3533 | + $skip_tax = GetPaid_Payment_Form_Submission_Taxes::is_eu_transaction( $this->get_country() ) && ! empty( $vat_number ); |
|
| 3534 | 3534 | |
| 3535 | - if ( wpinv_is_base_country( $this->get_country() ) && 'vat_too' == wpinv_get_option( 'vat_same_country_rule', 'vat_too' ) ) { |
|
| 3536 | - $skip_tax = false; |
|
| 3537 | - } |
|
| 3535 | + if ( wpinv_is_base_country( $this->get_country() ) && 'vat_too' == wpinv_get_option( 'vat_same_country_rule', 'vat_too' ) ) { |
|
| 3536 | + $skip_tax = false; |
|
| 3537 | + } |
|
| 3538 | 3538 | |
| 3539 | - if ( ! wpinv_use_taxes() || $this->get_disable_taxes() || ! wpinv_is_country_taxable( $this->get_country() ) || $skip_tax ) { |
|
| 3539 | + if ( ! wpinv_use_taxes() || $this->get_disable_taxes() || ! wpinv_is_country_taxable( $this->get_country() ) || $skip_tax ) { |
|
| 3540 | 3540 | |
| 3541 | - $this->totals['tax'] = array( |
|
| 3542 | - 'initial' => 0, |
|
| 3543 | - 'recurring' => 0, |
|
| 3544 | - ); |
|
| 3541 | + $this->totals['tax'] = array( |
|
| 3542 | + 'initial' => 0, |
|
| 3543 | + 'recurring' => 0, |
|
| 3544 | + ); |
|
| 3545 | 3545 | |
| 3546 | - $this->tax_rate = 0; |
|
| 3546 | + $this->tax_rate = 0; |
|
| 3547 | 3547 | |
| 3548 | - $this->set_taxes( array() ); |
|
| 3549 | - $current = 0; |
|
| 3550 | - } else { |
|
| 3548 | + $this->set_taxes( array() ); |
|
| 3549 | + $current = 0; |
|
| 3550 | + } else { |
|
| 3551 | 3551 | |
| 3552 | - $item_taxes = array(); |
|
| 3552 | + $item_taxes = array(); |
|
| 3553 | 3553 | |
| 3554 | - foreach ( $this->get_items() as $item ) { |
|
| 3555 | - $rates = getpaid_get_item_tax_rates( $item, $this->get_country(), $this->get_state() ); |
|
| 3556 | - $rates = getpaid_filter_item_tax_rates( $item, $rates ); |
|
| 3557 | - $taxes = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item, false ), $rates ); |
|
| 3558 | - $r_taxes = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item, true ), $rates ); |
|
| 3559 | - foreach ( $taxes as $name => $amount ) { |
|
| 3560 | - $recurring = isset( $r_taxes[ $name ] ) ? $r_taxes[ $name ] : 0; |
|
| 3561 | - $tax = getpaid_prepare_item_tax( $item, $name, $amount, $recurring ); |
|
| 3554 | + foreach ( $this->get_items() as $item ) { |
|
| 3555 | + $rates = getpaid_get_item_tax_rates( $item, $this->get_country(), $this->get_state() ); |
|
| 3556 | + $rates = getpaid_filter_item_tax_rates( $item, $rates ); |
|
| 3557 | + $taxes = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item, false ), $rates ); |
|
| 3558 | + $r_taxes = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item, true ), $rates ); |
|
| 3559 | + foreach ( $taxes as $name => $amount ) { |
|
| 3560 | + $recurring = isset( $r_taxes[ $name ] ) ? $r_taxes[ $name ] : 0; |
|
| 3561 | + $tax = getpaid_prepare_item_tax( $item, $name, $amount, $recurring ); |
|
| 3562 | 3562 | |
| 3563 | - if ( ! isset( $item_taxes[ $name ] ) ) { |
|
| 3564 | - $item_taxes[ $name ] = $tax; |
|
| 3565 | - continue; |
|
| 3566 | - } |
|
| 3563 | + if ( ! isset( $item_taxes[ $name ] ) ) { |
|
| 3564 | + $item_taxes[ $name ] = $tax; |
|
| 3565 | + continue; |
|
| 3566 | + } |
|
| 3567 | 3567 | |
| 3568 | - $item_taxes[ $name ]['initial_tax'] += $tax['initial_tax']; |
|
| 3569 | - $item_taxes[ $name ]['recurring_tax'] += $tax['recurring_tax']; |
|
| 3568 | + $item_taxes[ $name ]['initial_tax'] += $tax['initial_tax']; |
|
| 3569 | + $item_taxes[ $name ]['recurring_tax'] += $tax['recurring_tax']; |
|
| 3570 | 3570 | |
| 3571 | - } |
|
| 3571 | + } |
|
| 3572 | 3572 | |
| 3573 | - } |
|
| 3573 | + } |
|
| 3574 | 3574 | |
| 3575 | - $item_taxes = array_replace( $this->get_taxes(), $item_taxes ); |
|
| 3576 | - $this->set_taxes( $item_taxes ); |
|
| 3575 | + $item_taxes = array_replace( $this->get_taxes(), $item_taxes ); |
|
| 3576 | + $this->set_taxes( $item_taxes ); |
|
| 3577 | 3577 | |
| 3578 | - $initial_tax = array_sum( wp_list_pluck( $item_taxes, 'initial_tax' ) ); |
|
| 3579 | - $recurring_tax = array_sum( wp_list_pluck( $item_taxes, 'recurring_tax' ) ); |
|
| 3578 | + $initial_tax = array_sum( wp_list_pluck( $item_taxes, 'initial_tax' ) ); |
|
| 3579 | + $recurring_tax = array_sum( wp_list_pluck( $item_taxes, 'recurring_tax' ) ); |
|
| 3580 | 3580 | |
| 3581 | - $current = $this->is_renewal() ? $recurring_tax : $initial_tax; |
|
| 3581 | + $current = $this->is_renewal() ? $recurring_tax : $initial_tax; |
|
| 3582 | 3582 | |
| 3583 | - $this->totals['tax'] = array( |
|
| 3584 | - 'initial' => $initial_tax, |
|
| 3585 | - 'recurring' => $recurring_tax, |
|
| 3586 | - ); |
|
| 3583 | + $this->totals['tax'] = array( |
|
| 3584 | + 'initial' => $initial_tax, |
|
| 3585 | + 'recurring' => $recurring_tax, |
|
| 3586 | + ); |
|
| 3587 | 3587 | |
| 3588 | - } |
|
| 3588 | + } |
|
| 3589 | 3589 | |
| 3590 | - $this->set_total_tax( $current ); |
|
| 3590 | + $this->set_total_tax( $current ); |
|
| 3591 | 3591 | |
| 3592 | - return $current; |
|
| 3592 | + return $current; |
|
| 3593 | 3593 | |
| 3594 | 3594 | } |
| 3595 | 3595 | |
| 3596 | 3596 | /** |
| 3597 | - * Recalculates the invoice fees total. |
|
| 3598 | - * |
|
| 3599 | - * @since 1.0.19 |
|
| 3600 | - * @return float The recalculated fee |
|
| 3601 | - */ |
|
| 3602 | - public function recalculate_total_fees() { |
|
| 3603 | - $fees = $this->get_fees(); |
|
| 3604 | - $fee = 0; |
|
| 3605 | - $recurring = 0; |
|
| 3597 | + * Recalculates the invoice fees total. |
|
| 3598 | + * |
|
| 3599 | + * @since 1.0.19 |
|
| 3600 | + * @return float The recalculated fee |
|
| 3601 | + */ |
|
| 3602 | + public function recalculate_total_fees() { |
|
| 3603 | + $fees = $this->get_fees(); |
|
| 3604 | + $fee = 0; |
|
| 3605 | + $recurring = 0; |
|
| 3606 | 3606 | |
| 3607 | 3607 | foreach ( $fees as $data ) { |
| 3608 | - $fee += wpinv_sanitize_amount( $data['initial_fee'] ); |
|
| 3609 | - $recurring += wpinv_sanitize_amount( $data['recurring_fee'] ); |
|
| 3610 | - } |
|
| 3608 | + $fee += wpinv_sanitize_amount( $data['initial_fee'] ); |
|
| 3609 | + $recurring += wpinv_sanitize_amount( $data['recurring_fee'] ); |
|
| 3610 | + } |
|
| 3611 | 3611 | |
| 3612 | - $current = $this->is_renewal() ? $recurring : $fee; |
|
| 3613 | - $this->set_total_fees( $current ); |
|
| 3612 | + $current = $this->is_renewal() ? $recurring : $fee; |
|
| 3613 | + $this->set_total_fees( $current ); |
|
| 3614 | 3614 | |
| 3615 | - $this->totals['fee'] = array( |
|
| 3616 | - 'initial' => $fee, |
|
| 3617 | - 'recurring' => $recurring, |
|
| 3618 | - ); |
|
| 3615 | + $this->totals['fee'] = array( |
|
| 3616 | + 'initial' => $fee, |
|
| 3617 | + 'recurring' => $recurring, |
|
| 3618 | + ); |
|
| 3619 | 3619 | |
| 3620 | 3620 | $this->set_total_fees( $fee ); |
| 3621 | 3621 | return $current; |
| 3622 | 3622 | } |
| 3623 | 3623 | |
| 3624 | 3624 | /** |
| 3625 | - * Recalculates the invoice total. |
|
| 3626 | - * |
|
| 3627 | - * @since 1.0.19 |
|
| 3625 | + * Recalculates the invoice total. |
|
| 3626 | + * |
|
| 3627 | + * @since 1.0.19 |
|
| 3628 | 3628 | * @return float The invoice total |
| 3629 | - */ |
|
| 3630 | - public function recalculate_total() { |
|
| 3629 | + */ |
|
| 3630 | + public function recalculate_total() { |
|
| 3631 | 3631 | $this->recalculate_total_fees(); |
| 3632 | 3632 | $this->recalculate_total_discount(); |
| 3633 | - $this->recalculate_total_tax(); |
|
| 3634 | - $this->recalculate_subtotal(); |
|
| 3635 | - $this->set_total( $this->get_total_tax() + $this->get_total_fees() + $this->get_subtotal() - $this->get_total_discount() ); |
|
| 3636 | - return $this->get_total(); |
|
| 3637 | - } |
|
| 3638 | - |
|
| 3639 | - /** |
|
| 3640 | - * @deprecated |
|
| 3641 | - */ |
|
| 3633 | + $this->recalculate_total_tax(); |
|
| 3634 | + $this->recalculate_subtotal(); |
|
| 3635 | + $this->set_total( $this->get_total_tax() + $this->get_total_fees() + $this->get_subtotal() - $this->get_total_discount() ); |
|
| 3636 | + return $this->get_total(); |
|
| 3637 | + } |
|
| 3638 | + |
|
| 3639 | + /** |
|
| 3640 | + * @deprecated |
|
| 3641 | + */ |
|
| 3642 | 3642 | public function recalculate_totals() { |
| 3643 | 3643 | $this->recalculate_total(); |
| 3644 | 3644 | $this->save( true ); |
@@ -3652,22 +3652,22 @@ discard block |
||
| 3652 | 3652 | return $this->get_data(); |
| 3653 | 3653 | } |
| 3654 | 3654 | |
| 3655 | - /** |
|
| 3655 | + /** |
|
| 3656 | 3656 | * Adds a system note to an invoice. |
| 3657 | 3657 | * |
| 3658 | 3658 | * @param string $note The note being added. |
| 3659 | - * @return int|false The new note's ID on success, false on failure. |
|
| 3659 | + * @return int|false The new note's ID on success, false on failure. |
|
| 3660 | 3660 | * |
| 3661 | 3661 | */ |
| 3662 | 3662 | public function add_system_note( $note ) { |
| 3663 | - return $this->add_note( $note, false, false, true ); |
|
| 3664 | - } |
|
| 3663 | + return $this->add_note( $note, false, false, true ); |
|
| 3664 | + } |
|
| 3665 | 3665 | |
| 3666 | 3666 | /** |
| 3667 | 3667 | * Adds a note to an invoice. |
| 3668 | 3668 | * |
| 3669 | 3669 | * @param string $note The note being added. |
| 3670 | - * @return int|false The new note's ID on success, false on failure. |
|
| 3670 | + * @return int|false The new note's ID on success, false on failure. |
|
| 3671 | 3671 | * |
| 3672 | 3672 | */ |
| 3673 | 3673 | public function add_note( $note = '', $customer_type = false, $added_by_user = false, $system = false ) { |
@@ -3677,21 +3677,21 @@ discard block |
||
| 3677 | 3677 | return false; |
| 3678 | 3678 | } |
| 3679 | 3679 | |
| 3680 | - $author = 'System'; |
|
| 3681 | - $author_email = '[email protected]'; |
|
| 3680 | + $author = 'System'; |
|
| 3681 | + $author_email = '[email protected]'; |
|
| 3682 | 3682 | |
| 3683 | - // If this is an admin comment or it has been added by the user. |
|
| 3684 | - if ( is_user_logged_in() && ( ! $system || $added_by_user ) ) { |
|
| 3685 | - $user = get_user_by( 'id', get_current_user_id() ); |
|
| 3683 | + // If this is an admin comment or it has been added by the user. |
|
| 3684 | + if ( is_user_logged_in() && ( ! $system || $added_by_user ) ) { |
|
| 3685 | + $user = get_user_by( 'id', get_current_user_id() ); |
|
| 3686 | 3686 | $author = $user->display_name; |
| 3687 | 3687 | $author_email = $user->user_email; |
| 3688 | - } |
|
| 3688 | + } |
|
| 3689 | 3689 | |
| 3690 | - return getpaid_notes()->add_invoice_note( $this, $note, $author, $author_email, $customer_type ); |
|
| 3690 | + return getpaid_notes()->add_invoice_note( $this, $note, $author, $author_email, $customer_type ); |
|
| 3691 | 3691 | |
| 3692 | - } |
|
| 3692 | + } |
|
| 3693 | 3693 | |
| 3694 | - /** |
|
| 3694 | + /** |
|
| 3695 | 3695 | * Generates a unique key for the invoice. |
| 3696 | 3696 | */ |
| 3697 | 3697 | public function generate_key( $string = '' ) { |
@@ -3711,113 +3711,113 @@ discard block |
||
| 3711 | 3711 | $number = wpinv_get_next_invoice_number( $this->get_post_type() ); |
| 3712 | 3712 | } |
| 3713 | 3713 | |
| 3714 | - return wpinv_format_invoice_number( $number, $this->get_post_type() ); |
|
| 3715 | - |
|
| 3716 | - } |
|
| 3717 | - |
|
| 3718 | - /** |
|
| 3719 | - * Handle the status transition. |
|
| 3720 | - */ |
|
| 3721 | - protected function status_transition() { |
|
| 3722 | - $status_transition = $this->status_transition; |
|
| 3723 | - |
|
| 3724 | - // Reset status transition variable. |
|
| 3725 | - $this->status_transition = false; |
|
| 3714 | + return wpinv_format_invoice_number( $number, $this->get_post_type() ); |
|
| 3726 | 3715 | |
| 3727 | - if ( $status_transition ) { |
|
| 3728 | - try { |
|
| 3729 | - |
|
| 3730 | - // Fire a hook for the status change. |
|
| 3731 | - do_action( 'getpaid_invoice_status_' . $status_transition['to'], $this, $status_transition ); |
|
| 3732 | - |
|
| 3733 | - // @deprecated this is deprecated and will be removed in the future. |
|
| 3734 | - do_action( 'wpinv_status_' . $status_transition['to'], $this->get_id(), $status_transition['from'] ); |
|
| 3735 | - |
|
| 3736 | - if ( ! empty( $status_transition['from'] ) ) { |
|
| 3737 | - |
|
| 3738 | - /* translators: 1: old invoice status 2: new invoice status */ |
|
| 3739 | - $transition_note = sprintf( __( 'Status changed from %1$s to %2$s.', 'invoicing' ), wpinv_status_nicename( $status_transition['from'], $this ), wpinv_status_nicename( $status_transition['to'], $this ) ); |
|
| 3740 | - |
|
| 3741 | - // Fire another hook. |
|
| 3742 | - do_action( 'getpaid_invoice_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this ); |
|
| 3743 | - do_action( 'getpaid_invoice_status_changed', $this, $status_transition['from'], $status_transition['to'] ); |
|
| 3744 | - |
|
| 3745 | - // @deprecated this is deprecated and will be removed in the future. |
|
| 3746 | - do_action( 'wpinv_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $status_transition['from'] ); |
|
| 3747 | - |
|
| 3748 | - // Note the transition occurred. |
|
| 3749 | - $this->add_note( trim( $status_transition['note'] . ' ' . $transition_note ), false, $status_transition['manual'] ); |
|
| 3750 | - |
|
| 3751 | - // Work out if this was for a payment, and trigger a payment_status hook instead. |
|
| 3752 | - if ( |
|
| 3753 | - in_array( $status_transition['from'], array( 'wpi-cancelled', 'wpi-pending', 'wpi-failed', 'wpi-refunded', 'wpi-onhold' ), true ) |
|
| 3754 | - && in_array( $status_transition['to'], array( 'publish', 'wpi-processing', 'wpi-renewal' ), true ) |
|
| 3755 | - ) { |
|
| 3756 | - do_action( 'getpaid_invoice_payment_status_changed', $this, $status_transition ); |
|
| 3757 | - } |
|
| 3758 | - |
|
| 3759 | - // Work out if this was for a payment reversal, and trigger a payment_status_reversed hook instead. |
|
| 3760 | - if ( |
|
| 3761 | - in_array( $status_transition['from'], array( 'publish', 'wpi-processing', 'wpi-renewal' ), true ) |
|
| 3762 | - && in_array( $status_transition['to'], array( 'wpi-cancelled', 'wpi-pending', 'wpi-failed', 'wpi-refunded', 'wpi-onhold' ), true ) |
|
| 3763 | - ) { |
|
| 3764 | - do_action( 'getpaid_invoice_payment_status_reversed', $this, $status_transition ); |
|
| 3765 | - } |
|
| 3766 | - } else { |
|
| 3767 | - /* translators: %s: new invoice status */ |
|
| 3768 | - $transition_note = sprintf( __( 'Status set to %s.', 'invoicing' ), wpinv_status_nicename( $status_transition['to'], $this ) ); |
|
| 3769 | - |
|
| 3770 | - // Note the transition occurred. |
|
| 3771 | - $this->add_note( trim( $status_transition['note'] . ' ' . $transition_note ), 0, $status_transition['manual'] ); |
|
| 3716 | + } |
|
| 3772 | 3717 | |
| 3773 | - } |
|
| 3774 | - } catch ( Exception $e ) { |
|
| 3775 | - $this->add_note( __( 'Error during status transition.', 'invoicing' ) . ' ' . $e->getMessage() ); |
|
| 3776 | - } |
|
| 3777 | - } |
|
| 3778 | - } |
|
| 3718 | + /** |
|
| 3719 | + * Handle the status transition. |
|
| 3720 | + */ |
|
| 3721 | + protected function status_transition() { |
|
| 3722 | + $status_transition = $this->status_transition; |
|
| 3723 | + |
|
| 3724 | + // Reset status transition variable. |
|
| 3725 | + $this->status_transition = false; |
|
| 3726 | + |
|
| 3727 | + if ( $status_transition ) { |
|
| 3728 | + try { |
|
| 3729 | + |
|
| 3730 | + // Fire a hook for the status change. |
|
| 3731 | + do_action( 'getpaid_invoice_status_' . $status_transition['to'], $this, $status_transition ); |
|
| 3732 | + |
|
| 3733 | + // @deprecated this is deprecated and will be removed in the future. |
|
| 3734 | + do_action( 'wpinv_status_' . $status_transition['to'], $this->get_id(), $status_transition['from'] ); |
|
| 3735 | + |
|
| 3736 | + if ( ! empty( $status_transition['from'] ) ) { |
|
| 3737 | + |
|
| 3738 | + /* translators: 1: old invoice status 2: new invoice status */ |
|
| 3739 | + $transition_note = sprintf( __( 'Status changed from %1$s to %2$s.', 'invoicing' ), wpinv_status_nicename( $status_transition['from'], $this ), wpinv_status_nicename( $status_transition['to'], $this ) ); |
|
| 3740 | + |
|
| 3741 | + // Fire another hook. |
|
| 3742 | + do_action( 'getpaid_invoice_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this ); |
|
| 3743 | + do_action( 'getpaid_invoice_status_changed', $this, $status_transition['from'], $status_transition['to'] ); |
|
| 3744 | + |
|
| 3745 | + // @deprecated this is deprecated and will be removed in the future. |
|
| 3746 | + do_action( 'wpinv_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $status_transition['from'] ); |
|
| 3747 | + |
|
| 3748 | + // Note the transition occurred. |
|
| 3749 | + $this->add_note( trim( $status_transition['note'] . ' ' . $transition_note ), false, $status_transition['manual'] ); |
|
| 3750 | + |
|
| 3751 | + // Work out if this was for a payment, and trigger a payment_status hook instead. |
|
| 3752 | + if ( |
|
| 3753 | + in_array( $status_transition['from'], array( 'wpi-cancelled', 'wpi-pending', 'wpi-failed', 'wpi-refunded', 'wpi-onhold' ), true ) |
|
| 3754 | + && in_array( $status_transition['to'], array( 'publish', 'wpi-processing', 'wpi-renewal' ), true ) |
|
| 3755 | + ) { |
|
| 3756 | + do_action( 'getpaid_invoice_payment_status_changed', $this, $status_transition ); |
|
| 3757 | + } |
|
| 3758 | + |
|
| 3759 | + // Work out if this was for a payment reversal, and trigger a payment_status_reversed hook instead. |
|
| 3760 | + if ( |
|
| 3761 | + in_array( $status_transition['from'], array( 'publish', 'wpi-processing', 'wpi-renewal' ), true ) |
|
| 3762 | + && in_array( $status_transition['to'], array( 'wpi-cancelled', 'wpi-pending', 'wpi-failed', 'wpi-refunded', 'wpi-onhold' ), true ) |
|
| 3763 | + ) { |
|
| 3764 | + do_action( 'getpaid_invoice_payment_status_reversed', $this, $status_transition ); |
|
| 3765 | + } |
|
| 3766 | + } else { |
|
| 3767 | + /* translators: %s: new invoice status */ |
|
| 3768 | + $transition_note = sprintf( __( 'Status set to %s.', 'invoicing' ), wpinv_status_nicename( $status_transition['to'], $this ) ); |
|
| 3769 | + |
|
| 3770 | + // Note the transition occurred. |
|
| 3771 | + $this->add_note( trim( $status_transition['note'] . ' ' . $transition_note ), 0, $status_transition['manual'] ); |
|
| 3772 | + |
|
| 3773 | + } |
|
| 3774 | + } catch ( Exception $e ) { |
|
| 3775 | + $this->add_note( __( 'Error during status transition.', 'invoicing' ) . ' ' . $e->getMessage() ); |
|
| 3776 | + } |
|
| 3777 | + } |
|
| 3778 | + } |
|
| 3779 | 3779 | |
| 3780 | - /** |
|
| 3781 | - * Updates an invoice status. |
|
| 3782 | - */ |
|
| 3783 | - public function update_status( $new_status = false, $note = '', $manual = false ) { |
|
| 3780 | + /** |
|
| 3781 | + * Updates an invoice status. |
|
| 3782 | + */ |
|
| 3783 | + public function update_status( $new_status = false, $note = '', $manual = false ) { |
|
| 3784 | 3784 | |
| 3785 | - // Fires before updating a status. |
|
| 3786 | - do_action( 'wpinv_before_invoice_status_change', $this->get_id(), $new_status, $this->get_status( 'edit' ) ); |
|
| 3785 | + // Fires before updating a status. |
|
| 3786 | + do_action( 'wpinv_before_invoice_status_change', $this->get_id(), $new_status, $this->get_status( 'edit' ) ); |
|
| 3787 | 3787 | |
| 3788 | - // Update the status. |
|
| 3789 | - $this->set_status( $new_status, $note, $manual ); |
|
| 3788 | + // Update the status. |
|
| 3789 | + $this->set_status( $new_status, $note, $manual ); |
|
| 3790 | 3790 | |
| 3791 | - // Save the order. |
|
| 3792 | - return $this->save(); |
|
| 3791 | + // Save the order. |
|
| 3792 | + return $this->save(); |
|
| 3793 | 3793 | |
| 3794 | - } |
|
| 3794 | + } |
|
| 3795 | 3795 | |
| 3796 | - /** |
|
| 3797 | - * @deprecated |
|
| 3798 | - */ |
|
| 3799 | - public function refresh_item_ids() { |
|
| 3796 | + /** |
|
| 3797 | + * @deprecated |
|
| 3798 | + */ |
|
| 3799 | + public function refresh_item_ids() { |
|
| 3800 | 3800 | $item_ids = implode( ',', array_unique( wp_list_pluck( $this->get_cart_details(), 'item_id' ) ) ); |
| 3801 | 3801 | update_post_meta( $this->get_id(), '_wpinv_item_ids', $item_ids ); |
| 3802 | - } |
|
| 3802 | + } |
|
| 3803 | 3803 | |
| 3804 | - /** |
|
| 3805 | - * @deprecated |
|
| 3806 | - */ |
|
| 3807 | - public function update_items( $temp = false ) { |
|
| 3804 | + /** |
|
| 3805 | + * @deprecated |
|
| 3806 | + */ |
|
| 3807 | + public function update_items( $temp = false ) { |
|
| 3808 | 3808 | |
| 3809 | - $this->set_items( $this->get_items() ); |
|
| 3809 | + $this->set_items( $this->get_items() ); |
|
| 3810 | 3810 | |
| 3811 | - if ( ! $temp ) { |
|
| 3812 | - $this->save(); |
|
| 3813 | - } |
|
| 3811 | + if ( ! $temp ) { |
|
| 3812 | + $this->save(); |
|
| 3813 | + } |
|
| 3814 | 3814 | |
| 3815 | 3815 | return $this; |
| 3816 | - } |
|
| 3816 | + } |
|
| 3817 | 3817 | |
| 3818 | - /** |
|
| 3819 | - * @deprecated |
|
| 3820 | - */ |
|
| 3818 | + /** |
|
| 3819 | + * @deprecated |
|
| 3820 | + */ |
|
| 3821 | 3821 | public function validate_discount() { |
| 3822 | 3822 | |
| 3823 | 3823 | $discount_code = $this->get_discount_code(); |
@@ -3833,93 +3833,93 @@ discard block |
||
| 3833 | 3833 | |
| 3834 | 3834 | } |
| 3835 | 3835 | |
| 3836 | - /** |
|
| 3837 | - * Refunds an invoice. |
|
| 3838 | - */ |
|
| 3836 | + /** |
|
| 3837 | + * Refunds an invoice. |
|
| 3838 | + */ |
|
| 3839 | 3839 | public function refund() { |
| 3840 | - $this->set_status( 'wpi-refunded' ); |
|
| 3840 | + $this->set_status( 'wpi-refunded' ); |
|
| 3841 | 3841 | $this->save(); |
| 3842 | - } |
|
| 3842 | + } |
|
| 3843 | 3843 | |
| 3844 | - /** |
|
| 3845 | - * Marks an invoice as paid. |
|
| 3846 | - * |
|
| 3847 | - * @param string $transaction_id |
|
| 3848 | - */ |
|
| 3844 | + /** |
|
| 3845 | + * Marks an invoice as paid. |
|
| 3846 | + * |
|
| 3847 | + * @param string $transaction_id |
|
| 3848 | + */ |
|
| 3849 | 3849 | public function mark_paid( $transaction_id = null, $note = '' ) { |
| 3850 | 3850 | |
| 3851 | - // Set the transaction id. |
|
| 3852 | - if ( empty( $transaction_id ) ) { |
|
| 3853 | - $transaction_id = $this->generate_key('trans_'); |
|
| 3854 | - } |
|
| 3851 | + // Set the transaction id. |
|
| 3852 | + if ( empty( $transaction_id ) ) { |
|
| 3853 | + $transaction_id = $this->generate_key('trans_'); |
|
| 3854 | + } |
|
| 3855 | 3855 | |
| 3856 | - if ( ! $this->get_transaction_id() ) { |
|
| 3857 | - $this->set_transaction_id( $transaction_id ); |
|
| 3858 | - } |
|
| 3856 | + if ( ! $this->get_transaction_id() ) { |
|
| 3857 | + $this->set_transaction_id( $transaction_id ); |
|
| 3858 | + } |
|
| 3859 | 3859 | |
| 3860 | - if ( $this->is_paid() && 'wpi-processing' != $this->get_status() ) { |
|
| 3861 | - return $this->save(); |
|
| 3862 | - } |
|
| 3860 | + if ( $this->is_paid() && 'wpi-processing' != $this->get_status() ) { |
|
| 3861 | + return $this->save(); |
|
| 3862 | + } |
|
| 3863 | 3863 | |
| 3864 | - // Set the completed date. |
|
| 3865 | - $this->set_date_completed( current_time( 'mysql' ) ); |
|
| 3864 | + // Set the completed date. |
|
| 3865 | + $this->set_date_completed( current_time( 'mysql' ) ); |
|
| 3866 | 3866 | |
| 3867 | - // Set the new status. |
|
| 3868 | - $gateway = sanitize_text_field( $this->get_gateway_title() ); |
|
| 3869 | - if ( $this->is_renewal() ) { |
|
| 3867 | + // Set the new status. |
|
| 3868 | + $gateway = sanitize_text_field( $this->get_gateway_title() ); |
|
| 3869 | + if ( $this->is_renewal() ) { |
|
| 3870 | 3870 | |
| 3871 | - $_note = wp_sprintf( __( 'Renewed via %s', 'invoicing' ), $gateway ); |
|
| 3872 | - $_note = $_note . empty( $note ) ? '' : " ($note)"; |
|
| 3871 | + $_note = wp_sprintf( __( 'Renewed via %s', 'invoicing' ), $gateway ); |
|
| 3872 | + $_note = $_note . empty( $note ) ? '' : " ($note)"; |
|
| 3873 | 3873 | |
| 3874 | - if ( 'none' == $this->get_gateway() ) { |
|
| 3875 | - $_note = $note; |
|
| 3876 | - } |
|
| 3874 | + if ( 'none' == $this->get_gateway() ) { |
|
| 3875 | + $_note = $note; |
|
| 3876 | + } |
|
| 3877 | 3877 | |
| 3878 | - $this->set_status( 'wpi-renewal', $_note ); |
|
| 3878 | + $this->set_status( 'wpi-renewal', $_note ); |
|
| 3879 | 3879 | |
| 3880 | - } else { |
|
| 3880 | + } else { |
|
| 3881 | 3881 | |
| 3882 | - $_note = wp_sprintf( __( 'Paid via %s', 'invoicing' ), $gateway ); |
|
| 3883 | - $_note = $_note . empty( $note ) ? '' : " ($note)"; |
|
| 3882 | + $_note = wp_sprintf( __( 'Paid via %s', 'invoicing' ), $gateway ); |
|
| 3883 | + $_note = $_note . empty( $note ) ? '' : " ($note)"; |
|
| 3884 | 3884 | |
| 3885 | - if ( 'none' == $this->get_gateway() ) { |
|
| 3886 | - $_note = $note; |
|
| 3887 | - } |
|
| 3885 | + if ( 'none' == $this->get_gateway() ) { |
|
| 3886 | + $_note = $note; |
|
| 3887 | + } |
|
| 3888 | 3888 | |
| 3889 | - $this->set_status( 'publish', $_note ); |
|
| 3889 | + $this->set_status( 'publish', $_note ); |
|
| 3890 | 3890 | |
| 3891 | - } |
|
| 3891 | + } |
|
| 3892 | 3892 | |
| 3893 | - // Set checkout mode. |
|
| 3894 | - $mode = wpinv_is_test_mode( $this->get_gateway() ) ? 'test' : 'live'; |
|
| 3895 | - $this->set_mode( $mode ); |
|
| 3893 | + // Set checkout mode. |
|
| 3894 | + $mode = wpinv_is_test_mode( $this->get_gateway() ) ? 'test' : 'live'; |
|
| 3895 | + $this->set_mode( $mode ); |
|
| 3896 | 3896 | |
| 3897 | - // Save the invoice. |
|
| 3897 | + // Save the invoice. |
|
| 3898 | 3898 | $this->save(); |
| 3899 | - } |
|
| 3900 | - |
|
| 3901 | - /** |
|
| 3902 | - * Save data to the database. |
|
| 3903 | - * |
|
| 3904 | - * @since 1.0.19 |
|
| 3905 | - * @return int invoice ID |
|
| 3906 | - */ |
|
| 3907 | - public function save() { |
|
| 3908 | - $this->maybe_set_date_paid(); |
|
| 3909 | - $this->maybe_set_key(); |
|
| 3910 | - parent::save(); |
|
| 3911 | - $this->clear_cache(); |
|
| 3912 | - $this->status_transition(); |
|
| 3913 | - return $this->get_id(); |
|
| 3914 | - } |
|
| 3915 | - |
|
| 3916 | - /** |
|
| 3899 | + } |
|
| 3900 | + |
|
| 3901 | + /** |
|
| 3902 | + * Save data to the database. |
|
| 3903 | + * |
|
| 3904 | + * @since 1.0.19 |
|
| 3905 | + * @return int invoice ID |
|
| 3906 | + */ |
|
| 3907 | + public function save() { |
|
| 3908 | + $this->maybe_set_date_paid(); |
|
| 3909 | + $this->maybe_set_key(); |
|
| 3910 | + parent::save(); |
|
| 3911 | + $this->clear_cache(); |
|
| 3912 | + $this->status_transition(); |
|
| 3913 | + return $this->get_id(); |
|
| 3914 | + } |
|
| 3915 | + |
|
| 3916 | + /** |
|
| 3917 | 3917 | * Clears the subscription's cache. |
| 3918 | 3918 | */ |
| 3919 | 3919 | public function clear_cache() { |
| 3920 | - wp_cache_delete( $this->get_key(), 'getpaid_invoice_keys_to_invoice_ids' ); |
|
| 3921 | - wp_cache_delete( $this->get_number(), 'getpaid_invoice_numbers_to_invoice_ids' ); |
|
| 3922 | - wp_cache_delete( $this->get_transaction_id(), 'getpaid_invoice_transaction_ids_to_invoice_ids' ); |
|
| 3923 | - } |
|
| 3920 | + wp_cache_delete( $this->get_key(), 'getpaid_invoice_keys_to_invoice_ids' ); |
|
| 3921 | + wp_cache_delete( $this->get_number(), 'getpaid_invoice_numbers_to_invoice_ids' ); |
|
| 3922 | + wp_cache_delete( $this->get_transaction_id(), 'getpaid_invoice_transaction_ids_to_invoice_ids' ); |
|
| 3923 | + } |
|
| 3924 | 3924 | |
| 3925 | 3925 | } |
@@ -13,300 +13,300 @@ |
||
| 13 | 13 | class GetPaid_Subscription_Notification_Emails { |
| 14 | 14 | |
| 15 | 15 | /** |
| 16 | - * The array of subscription email actions. |
|
| 17 | - * |
|
| 18 | - * @param array |
|
| 19 | - */ |
|
| 20 | - public $subscription_actions; |
|
| 16 | + * The array of subscription email actions. |
|
| 17 | + * |
|
| 18 | + * @param array |
|
| 19 | + */ |
|
| 20 | + public $subscription_actions; |
|
| 21 | 21 | |
| 22 | 22 | /** |
| 23 | - * Class constructor |
|
| 23 | + * Class constructor |
|
| 24 | 24 | * |
| 25 | - */ |
|
| 26 | - public function __construct() { |
|
| 27 | - |
|
| 28 | - $this->subscription_actions = apply_filters( |
|
| 29 | - 'getpaid_notification_email_subscription_triggers', |
|
| 30 | - array( |
|
| 31 | - 'getpaid_subscription_trialling' => 'subscription_trial', |
|
| 32 | - 'getpaid_subscription_cancelled' => 'subscription_cancelled', |
|
| 33 | - 'getpaid_subscription_expired' => 'subscription_expired', |
|
| 34 | - 'getpaid_subscription_completed' => 'subscription_complete', |
|
| 35 | - 'getpaid_daily_maintenance' => 'renewal_reminder', |
|
| 36 | - ) |
|
| 37 | - ); |
|
| 38 | - |
|
| 39 | - $this->init_hooks(); |
|
| 25 | + */ |
|
| 26 | + public function __construct() { |
|
| 27 | + |
|
| 28 | + $this->subscription_actions = apply_filters( |
|
| 29 | + 'getpaid_notification_email_subscription_triggers', |
|
| 30 | + array( |
|
| 31 | + 'getpaid_subscription_trialling' => 'subscription_trial', |
|
| 32 | + 'getpaid_subscription_cancelled' => 'subscription_cancelled', |
|
| 33 | + 'getpaid_subscription_expired' => 'subscription_expired', |
|
| 34 | + 'getpaid_subscription_completed' => 'subscription_complete', |
|
| 35 | + 'getpaid_daily_maintenance' => 'renewal_reminder', |
|
| 36 | + ) |
|
| 37 | + ); |
|
| 38 | + |
|
| 39 | + $this->init_hooks(); |
|
| 40 | 40 | |
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | /** |
| 44 | - * Registers email hooks. |
|
| 45 | - */ |
|
| 46 | - public function init_hooks() { |
|
| 47 | - |
|
| 48 | - add_filter( 'getpaid_get_email_merge_tags', array( $this, 'subscription_merge_tags' ), 10, 2 ); |
|
| 49 | - foreach ( $this->subscription_actions as $hook => $email_type ) { |
|
| 50 | - |
|
| 51 | - $email = new GetPaid_Notification_Email( $email_type ); |
|
| 52 | - |
|
| 53 | - if ( ! $email->is_active() ) { |
|
| 54 | - continue; |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - if ( method_exists( $this, $email_type ) ) { |
|
| 58 | - add_action( $hook, array( $this, $email_type ), 100, 2 ); |
|
| 59 | - continue; |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - do_action( 'getpaid_subscription_notification_email_register_hook', $email_type, $hook ); |
|
| 63 | - |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - /** |
|
| 69 | - * Filters subscription merge tags. |
|
| 70 | - * |
|
| 71 | - * @param array $merge_tags |
|
| 72 | - * @param mixed|WPInv_Invoice|WPInv_Subscription $object |
|
| 73 | - */ |
|
| 74 | - public function subscription_merge_tags( $merge_tags, $object ) { |
|
| 75 | - |
|
| 76 | - if ( is_a( $object, 'WPInv_Subscription' ) ) { |
|
| 77 | - $merge_tags = array_merge( |
|
| 78 | - $merge_tags, |
|
| 79 | - $this->get_subscription_merge_tags( $object ) |
|
| 80 | - ); |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - return $merge_tags; |
|
| 84 | - |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - /** |
|
| 88 | - * Generates subscription merge tags. |
|
| 89 | - * |
|
| 90 | - * @param WPInv_Subscription $subscription |
|
| 91 | - * @return array |
|
| 92 | - */ |
|
| 93 | - public function get_subscription_merge_tags( $subscription ) { |
|
| 94 | - |
|
| 95 | - // Abort if it does not exist. |
|
| 96 | - if ( ! $subscription->get_id() ) { |
|
| 97 | - return array(); |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - $invoice = $subscription->get_parent_invoice(); |
|
| 101 | - return array( |
|
| 102 | - '{subscription_renewal_date}' => getpaid_format_date_value( $subscription->get_next_renewal_date(), __( 'Never', 'invoicing' ) ), |
|
| 103 | - '{subscription_created}' => getpaid_format_date_value( $subscription->get_date_created() ), |
|
| 104 | - '{subscription_status}' => sanitize_text_field( $subscription->get_status_label() ), |
|
| 105 | - '{subscription_profile_id}' => sanitize_text_field( $subscription->get_profile_id() ), |
|
| 106 | - '{subscription_id}' => absint( $subscription->get_id() ), |
|
| 107 | - '{subscription_recurring_amount}' => sanitize_text_field( wpinv_price( $subscription->get_recurring_amount(), $invoice->get_currency() ) ), |
|
| 108 | - '{subscription_initial_amount}' => sanitize_text_field( wpinv_price( $subscription->get_initial_amount(), $invoice->get_currency() ) ), |
|
| 109 | - '{subscription_recurring_period}' => getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' ), |
|
| 110 | - '{subscription_bill_times}' => $subscription->get_bill_times(), |
|
| 111 | - '{subscription_url}' => esc_url( $subscription->get_view_url() ), |
|
| 112 | - ); |
|
| 113 | - |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - /** |
|
| 117 | - * Checks if we should send a notification for a subscription. |
|
| 118 | - * |
|
| 119 | - * @param WPInv_Invoice $invoice |
|
| 120 | - * @return bool |
|
| 121 | - */ |
|
| 122 | - public function should_send_notification( $invoice ) { |
|
| 123 | - return 0 != $invoice->get_id(); |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - /** |
|
| 127 | - * Returns notification recipients. |
|
| 128 | - * |
|
| 129 | - * @param WPInv_Invoice $invoice |
|
| 130 | - * @return array |
|
| 131 | - */ |
|
| 132 | - public function get_recipients( $invoice ) { |
|
| 133 | - $recipients = array( $invoice->get_email() ); |
|
| 134 | - |
|
| 135 | - $cc = $invoice->get_email_cc(); |
|
| 136 | - |
|
| 137 | - if ( ! empty( $cc ) ) { |
|
| 138 | - $cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) ); |
|
| 139 | - $recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) ); |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - return $recipients; |
|
| 143 | - } |
|
| 144 | - |
|
| 145 | - /** |
|
| 146 | - * Helper function to send an email. |
|
| 147 | - * |
|
| 148 | - * @param WPInv_Subscription $subscription |
|
| 149 | - * @param GetPaid_Notification_Email $email |
|
| 150 | - * @param string $type |
|
| 151 | - * @param array $extra_args Extra template args. |
|
| 152 | - */ |
|
| 153 | - public function send_email( $subscription, $email, $type, $extra_args = array() ) { |
|
| 154 | - |
|
| 155 | - // Abort in case the parent invoice does not exist. |
|
| 156 | - $invoice = $subscription->get_parent_invoice(); |
|
| 157 | - if ( ! $this->should_send_notification( $invoice ) ) { |
|
| 158 | - return; |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - if ( apply_filters( 'getpaid_skip_subscription_email', false, $type, $subscription ) ) { |
|
| 162 | - return; |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - do_action( 'getpaid_before_send_subscription_notification', $type, $subscription, $email ); |
|
| 166 | - |
|
| 167 | - $recipients = $this->get_recipients( $invoice ); |
|
| 168 | - $mailer = new GetPaid_Notification_Email_Sender(); |
|
| 169 | - $merge_tags = $email->get_merge_tags(); |
|
| 170 | - $content = $email->get_content( $merge_tags, $extra_args ); |
|
| 171 | - $subject = $email->add_merge_tags( $email->get_subject(), $merge_tags ); |
|
| 172 | - $attachments = $email->get_attachments(); |
|
| 173 | - |
|
| 174 | - $result = $mailer->send( |
|
| 175 | - apply_filters( 'getpaid_subscription_email_recipients', wpinv_parse_list( $recipients ), $email ), |
|
| 176 | - $subject, |
|
| 177 | - $content, |
|
| 178 | - $attachments |
|
| 179 | - ); |
|
| 180 | - |
|
| 181 | - // Maybe send a copy to the admin. |
|
| 182 | - if ( $email->include_admin_bcc() ) { |
|
| 183 | - $mailer->send( |
|
| 184 | - wpinv_get_admin_email(), |
|
| 185 | - $subject . __( ' - ADMIN BCC COPY', 'invoicing' ), |
|
| 186 | - $content, |
|
| 187 | - $attachments |
|
| 188 | - ); |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - if ( $result ) { |
|
| 192 | - $invoice->add_system_note( |
|
| 193 | - sprintf( |
|
| 194 | - __( 'Successfully sent %s notification email to %s.', 'invoicing' ), |
|
| 195 | - sanitize_key( $type ), |
|
| 196 | - $email->is_admin_email() ? __( 'admin' ) : __( 'the customer' ) |
|
| 197 | - ) |
|
| 198 | - ); |
|
| 199 | - } else { |
|
| 200 | - $invoice->add_system_note( |
|
| 201 | - sprintf( |
|
| 202 | - __( 'Failed sending %s notification email to %s.', 'invoicing' ), |
|
| 203 | - sanitize_key( $type ), |
|
| 204 | - $email->is_admin_email() ? __( 'admin' ) : __( 'the customer' ) |
|
| 205 | - ) |
|
| 206 | - ); |
|
| 207 | - } |
|
| 208 | - |
|
| 209 | - do_action( 'getpaid_after_send_subscription_notification', $type, $subscription, $email ); |
|
| 210 | - |
|
| 211 | - } |
|
| 44 | + * Registers email hooks. |
|
| 45 | + */ |
|
| 46 | + public function init_hooks() { |
|
| 47 | + |
|
| 48 | + add_filter( 'getpaid_get_email_merge_tags', array( $this, 'subscription_merge_tags' ), 10, 2 ); |
|
| 49 | + foreach ( $this->subscription_actions as $hook => $email_type ) { |
|
| 50 | + |
|
| 51 | + $email = new GetPaid_Notification_Email( $email_type ); |
|
| 52 | + |
|
| 53 | + if ( ! $email->is_active() ) { |
|
| 54 | + continue; |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + if ( method_exists( $this, $email_type ) ) { |
|
| 58 | + add_action( $hook, array( $this, $email_type ), 100, 2 ); |
|
| 59 | + continue; |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + do_action( 'getpaid_subscription_notification_email_register_hook', $email_type, $hook ); |
|
| 63 | + |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + } |
|
| 212 | 67 | |
| 213 | 68 | /** |
| 214 | - * Sends a new trial notification. |
|
| 215 | - * |
|
| 216 | - * @param WPInv_Subscription $subscription |
|
| 217 | - */ |
|
| 218 | - public function subscription_trial( $subscription ) { |
|
| 69 | + * Filters subscription merge tags. |
|
| 70 | + * |
|
| 71 | + * @param array $merge_tags |
|
| 72 | + * @param mixed|WPInv_Invoice|WPInv_Subscription $object |
|
| 73 | + */ |
|
| 74 | + public function subscription_merge_tags( $merge_tags, $object ) { |
|
| 219 | 75 | |
| 220 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $subscription ); |
|
| 221 | - $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
| 76 | + if ( is_a( $object, 'WPInv_Subscription' ) ) { |
|
| 77 | + $merge_tags = array_merge( |
|
| 78 | + $merge_tags, |
|
| 79 | + $this->get_subscription_merge_tags( $object ) |
|
| 80 | + ); |
|
| 81 | + } |
|
| 222 | 82 | |
| 223 | - } |
|
| 83 | + return $merge_tags; |
|
| 224 | 84 | |
| 225 | - /** |
|
| 226 | - * Sends a cancelled subscription notification. |
|
| 227 | - * |
|
| 228 | - * @param WPInv_Subscription $subscription |
|
| 229 | - */ |
|
| 230 | - public function subscription_cancelled( $subscription ) { |
|
| 85 | + } |
|
| 231 | 86 | |
| 232 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $subscription ); |
|
| 233 | - $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
| 87 | + /** |
|
| 88 | + * Generates subscription merge tags. |
|
| 89 | + * |
|
| 90 | + * @param WPInv_Subscription $subscription |
|
| 91 | + * @return array |
|
| 92 | + */ |
|
| 93 | + public function get_subscription_merge_tags( $subscription ) { |
|
| 94 | + |
|
| 95 | + // Abort if it does not exist. |
|
| 96 | + if ( ! $subscription->get_id() ) { |
|
| 97 | + return array(); |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + $invoice = $subscription->get_parent_invoice(); |
|
| 101 | + return array( |
|
| 102 | + '{subscription_renewal_date}' => getpaid_format_date_value( $subscription->get_next_renewal_date(), __( 'Never', 'invoicing' ) ), |
|
| 103 | + '{subscription_created}' => getpaid_format_date_value( $subscription->get_date_created() ), |
|
| 104 | + '{subscription_status}' => sanitize_text_field( $subscription->get_status_label() ), |
|
| 105 | + '{subscription_profile_id}' => sanitize_text_field( $subscription->get_profile_id() ), |
|
| 106 | + '{subscription_id}' => absint( $subscription->get_id() ), |
|
| 107 | + '{subscription_recurring_amount}' => sanitize_text_field( wpinv_price( $subscription->get_recurring_amount(), $invoice->get_currency() ) ), |
|
| 108 | + '{subscription_initial_amount}' => sanitize_text_field( wpinv_price( $subscription->get_initial_amount(), $invoice->get_currency() ) ), |
|
| 109 | + '{subscription_recurring_period}' => getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' ), |
|
| 110 | + '{subscription_bill_times}' => $subscription->get_bill_times(), |
|
| 111 | + '{subscription_url}' => esc_url( $subscription->get_view_url() ), |
|
| 112 | + ); |
|
| 234 | 113 | |
| 235 | - } |
|
| 114 | + } |
|
| 236 | 115 | |
| 237 | - /** |
|
| 238 | - * Sends a subscription expired notification. |
|
| 239 | - * |
|
| 240 | - * @param WPInv_Subscription $subscription |
|
| 241 | - */ |
|
| 242 | - public function subscription_expired( $subscription ) { |
|
| 116 | + /** |
|
| 117 | + * Checks if we should send a notification for a subscription. |
|
| 118 | + * |
|
| 119 | + * @param WPInv_Invoice $invoice |
|
| 120 | + * @return bool |
|
| 121 | + */ |
|
| 122 | + public function should_send_notification( $invoice ) { |
|
| 123 | + return 0 != $invoice->get_id(); |
|
| 124 | + } |
|
| 243 | 125 | |
| 244 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $subscription ); |
|
| 245 | - $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
| 126 | + /** |
|
| 127 | + * Returns notification recipients. |
|
| 128 | + * |
|
| 129 | + * @param WPInv_Invoice $invoice |
|
| 130 | + * @return array |
|
| 131 | + */ |
|
| 132 | + public function get_recipients( $invoice ) { |
|
| 133 | + $recipients = array( $invoice->get_email() ); |
|
| 246 | 134 | |
| 247 | - } |
|
| 135 | + $cc = $invoice->get_email_cc(); |
|
| 248 | 136 | |
| 249 | - /** |
|
| 250 | - * Sends a completed subscription notification. |
|
| 251 | - * |
|
| 252 | - * @param WPInv_Subscription $subscription |
|
| 253 | - */ |
|
| 254 | - public function subscription_complete( $subscription ) { |
|
| 137 | + if ( ! empty( $cc ) ) { |
|
| 138 | + $cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) ); |
|
| 139 | + $recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) ); |
|
| 140 | + } |
|
| 255 | 141 | |
| 256 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $subscription ); |
|
| 257 | - $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
| 142 | + return $recipients; |
|
| 143 | + } |
|
| 258 | 144 | |
| 259 | - } |
|
| 145 | + /** |
|
| 146 | + * Helper function to send an email. |
|
| 147 | + * |
|
| 148 | + * @param WPInv_Subscription $subscription |
|
| 149 | + * @param GetPaid_Notification_Email $email |
|
| 150 | + * @param string $type |
|
| 151 | + * @param array $extra_args Extra template args. |
|
| 152 | + */ |
|
| 153 | + public function send_email( $subscription, $email, $type, $extra_args = array() ) { |
|
| 154 | + |
|
| 155 | + // Abort in case the parent invoice does not exist. |
|
| 156 | + $invoice = $subscription->get_parent_invoice(); |
|
| 157 | + if ( ! $this->should_send_notification( $invoice ) ) { |
|
| 158 | + return; |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + if ( apply_filters( 'getpaid_skip_subscription_email', false, $type, $subscription ) ) { |
|
| 162 | + return; |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + do_action( 'getpaid_before_send_subscription_notification', $type, $subscription, $email ); |
|
| 166 | + |
|
| 167 | + $recipients = $this->get_recipients( $invoice ); |
|
| 168 | + $mailer = new GetPaid_Notification_Email_Sender(); |
|
| 169 | + $merge_tags = $email->get_merge_tags(); |
|
| 170 | + $content = $email->get_content( $merge_tags, $extra_args ); |
|
| 171 | + $subject = $email->add_merge_tags( $email->get_subject(), $merge_tags ); |
|
| 172 | + $attachments = $email->get_attachments(); |
|
| 173 | + |
|
| 174 | + $result = $mailer->send( |
|
| 175 | + apply_filters( 'getpaid_subscription_email_recipients', wpinv_parse_list( $recipients ), $email ), |
|
| 176 | + $subject, |
|
| 177 | + $content, |
|
| 178 | + $attachments |
|
| 179 | + ); |
|
| 180 | + |
|
| 181 | + // Maybe send a copy to the admin. |
|
| 182 | + if ( $email->include_admin_bcc() ) { |
|
| 183 | + $mailer->send( |
|
| 184 | + wpinv_get_admin_email(), |
|
| 185 | + $subject . __( ' - ADMIN BCC COPY', 'invoicing' ), |
|
| 186 | + $content, |
|
| 187 | + $attachments |
|
| 188 | + ); |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + if ( $result ) { |
|
| 192 | + $invoice->add_system_note( |
|
| 193 | + sprintf( |
|
| 194 | + __( 'Successfully sent %s notification email to %s.', 'invoicing' ), |
|
| 195 | + sanitize_key( $type ), |
|
| 196 | + $email->is_admin_email() ? __( 'admin' ) : __( 'the customer' ) |
|
| 197 | + ) |
|
| 198 | + ); |
|
| 199 | + } else { |
|
| 200 | + $invoice->add_system_note( |
|
| 201 | + sprintf( |
|
| 202 | + __( 'Failed sending %s notification email to %s.', 'invoicing' ), |
|
| 203 | + sanitize_key( $type ), |
|
| 204 | + $email->is_admin_email() ? __( 'admin' ) : __( 'the customer' ) |
|
| 205 | + ) |
|
| 206 | + ); |
|
| 207 | + } |
|
| 208 | + |
|
| 209 | + do_action( 'getpaid_after_send_subscription_notification', $type, $subscription, $email ); |
|
| 260 | 210 | |
| 261 | - /** |
|
| 262 | - * Sends a subscription renewal reminder notification. |
|
| 263 | - * |
|
| 264 | - */ |
|
| 265 | - public function renewal_reminder() { |
|
| 211 | + } |
|
| 266 | 212 | |
| 267 | - $email = new GetPaid_Notification_Email( __FUNCTION__ ); |
|
| 213 | + /** |
|
| 214 | + * Sends a new trial notification. |
|
| 215 | + * |
|
| 216 | + * @param WPInv_Subscription $subscription |
|
| 217 | + */ |
|
| 218 | + public function subscription_trial( $subscription ) { |
|
| 268 | 219 | |
| 269 | - // Fetch reminder days. |
|
| 270 | - $reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) ); |
|
| 220 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $subscription ); |
|
| 221 | + $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
| 271 | 222 | |
| 272 | - // Abort if non is set. |
|
| 273 | - if ( empty( $reminder_days ) ) { |
|
| 274 | - return; |
|
| 275 | - } |
|
| 223 | + } |
|
| 276 | 224 | |
| 277 | - // Fetch matching subscriptions. |
|
| 225 | + /** |
|
| 226 | + * Sends a cancelled subscription notification. |
|
| 227 | + * |
|
| 228 | + * @param WPInv_Subscription $subscription |
|
| 229 | + */ |
|
| 230 | + public function subscription_cancelled( $subscription ) { |
|
| 231 | + |
|
| 232 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $subscription ); |
|
| 233 | + $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
| 234 | + |
|
| 235 | + } |
|
| 236 | + |
|
| 237 | + /** |
|
| 238 | + * Sends a subscription expired notification. |
|
| 239 | + * |
|
| 240 | + * @param WPInv_Subscription $subscription |
|
| 241 | + */ |
|
| 242 | + public function subscription_expired( $subscription ) { |
|
| 243 | + |
|
| 244 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $subscription ); |
|
| 245 | + $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
| 246 | + |
|
| 247 | + } |
|
| 248 | + |
|
| 249 | + /** |
|
| 250 | + * Sends a completed subscription notification. |
|
| 251 | + * |
|
| 252 | + * @param WPInv_Subscription $subscription |
|
| 253 | + */ |
|
| 254 | + public function subscription_complete( $subscription ) { |
|
| 255 | + |
|
| 256 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $subscription ); |
|
| 257 | + $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
| 258 | + |
|
| 259 | + } |
|
| 260 | + |
|
| 261 | + /** |
|
| 262 | + * Sends a subscription renewal reminder notification. |
|
| 263 | + * |
|
| 264 | + */ |
|
| 265 | + public function renewal_reminder() { |
|
| 266 | + |
|
| 267 | + $email = new GetPaid_Notification_Email( __FUNCTION__ ); |
|
| 268 | + |
|
| 269 | + // Fetch reminder days. |
|
| 270 | + $reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) ); |
|
| 271 | + |
|
| 272 | + // Abort if non is set. |
|
| 273 | + if ( empty( $reminder_days ) ) { |
|
| 274 | + return; |
|
| 275 | + } |
|
| 276 | + |
|
| 277 | + // Fetch matching subscriptions. |
|
| 278 | 278 | $args = array( |
| 279 | 279 | 'number' => -1, |
| 280 | - 'count_total' => false, |
|
| 281 | - 'status' => 'trialling active', |
|
| 280 | + 'count_total' => false, |
|
| 281 | + 'status' => 'trialling active', |
|
| 282 | 282 | 'date_expires_query' => array( |
| 283 | - 'relation' => 'OR' |
|
| 283 | + 'relation' => 'OR' |
|
| 284 | 284 | ), |
| 285 | - ); |
|
| 285 | + ); |
|
| 286 | 286 | |
| 287 | - foreach ( $reminder_days as $days ) { |
|
| 288 | - $date = date_parse( date( 'Y-m-d', strtotime( "+$days days", current_time( 'timestamp' ) ) ) ); |
|
| 287 | + foreach ( $reminder_days as $days ) { |
|
| 288 | + $date = date_parse( date( 'Y-m-d', strtotime( "+$days days", current_time( 'timestamp' ) ) ) ); |
|
| 289 | 289 | |
| 290 | - $args['date_expires_query'][] = array( |
|
| 291 | - 'year' => $date['year'], |
|
| 292 | - 'month' => $date['month'], |
|
| 293 | - 'day' => $date['day'], |
|
| 294 | - ); |
|
| 290 | + $args['date_expires_query'][] = array( |
|
| 291 | + 'year' => $date['year'], |
|
| 292 | + 'month' => $date['month'], |
|
| 293 | + 'day' => $date['day'], |
|
| 294 | + ); |
|
| 295 | 295 | |
| 296 | - } |
|
| 296 | + } |
|
| 297 | 297 | |
| 298 | - $subscriptions = new GetPaid_Subscriptions_Query( $args ); |
|
| 298 | + $subscriptions = new GetPaid_Subscriptions_Query( $args ); |
|
| 299 | 299 | |
| 300 | 300 | foreach ( $subscriptions as $subscription ) { |
| 301 | 301 | |
| 302 | - // Skip packages. |
|
| 303 | - if ( get_post_meta( $subscription->get_product_id(), '_wpinv_type', true ) != 'package' ) { |
|
| 304 | - $email->object = $subscription; |
|
| 305 | - $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
| 306 | - } |
|
| 302 | + // Skip packages. |
|
| 303 | + if ( get_post_meta( $subscription->get_product_id(), '_wpinv_type', true ) != 'package' ) { |
|
| 304 | + $email->object = $subscription; |
|
| 305 | + $this->send_email( $subscription, $email, __FUNCTION__ ); |
|
| 306 | + } |
|
| 307 | 307 | |
| 308 | - } |
|
| 308 | + } |
|
| 309 | 309 | |
| 310 | - } |
|
| 310 | + } |
|
| 311 | 311 | |
| 312 | 312 | } |
@@ -12,486 +12,486 @@ |
||
| 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 | - } |
|
| 166 | - |
|
| 167 | - return apply_filters( 'getpaid_invoice_email_merge_tags', $merge_tags, $invoice ); |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - /** |
|
| 171 | - * Helper function to send an email. |
|
| 172 | - * |
|
| 173 | - * @param WPInv_Invoice $invoice |
|
| 174 | - * @param GetPaid_Notification_Email $email |
|
| 175 | - * @param string $type |
|
| 176 | - * @param string|array $recipients |
|
| 177 | - * @param array $extra_args Extra template args. |
|
| 178 | - */ |
|
| 179 | - public function send_email( $invoice, $email, $type, $recipients, $extra_args = array() ) { |
|
| 180 | - |
|
| 181 | - do_action( 'getpaid_before_send_invoice_notification', $type, $invoice, $email ); |
|
| 182 | - |
|
| 183 | - $skip = $invoice->is_free() && wpinv_get_option( 'skip_email_free_invoice' ); |
|
| 184 | - if ( apply_filters( 'getpaid_skip_invoice_email', $skip, $type, $invoice ) ) { |
|
| 185 | - return; |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - $mailer = new GetPaid_Notification_Email_Sender(); |
|
| 189 | - $merge_tags = $email->get_merge_tags(); |
|
| 190 | - |
|
| 191 | - $result = $mailer->send( |
|
| 192 | - apply_filters( 'getpaid_invoice_email_recipients', wpinv_parse_list( $recipients ), $email ), |
|
| 193 | - $email->add_merge_tags( $email->get_subject(), $merge_tags ), |
|
| 194 | - $email->get_content( $merge_tags, $extra_args ), |
|
| 195 | - $email->get_attachments() |
|
| 196 | - ); |
|
| 197 | - |
|
| 198 | - // Maybe send a copy to the admin. |
|
| 199 | - if ( $email->include_admin_bcc() ) { |
|
| 200 | - $mailer->send( |
|
| 201 | - wpinv_get_admin_email(), |
|
| 202 | - $email->add_merge_tags( $email->get_subject() . __( ' - ADMIN BCC COPY', 'invoicing' ), $merge_tags ), |
|
| 203 | - $email->get_content( $merge_tags ), |
|
| 204 | - $email->get_attachments() |
|
| 205 | - ); |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - if ( $result ) { |
|
| 209 | - $invoice->add_system_note( |
|
| 210 | - sprintf( |
|
| 211 | - __( 'Successfully sent %s notification email to %s.', 'invoicing' ), |
|
| 212 | - sanitize_key( $type ), |
|
| 213 | - $email->is_admin_email() ? __( 'admin' ) : __( 'the customer' ) |
|
| 214 | - ) |
|
| 215 | - ); |
|
| 216 | - } else { |
|
| 217 | - $invoice->add_system_note( |
|
| 218 | - sprintf( |
|
| 219 | - __( 'Failed sending %s notification email to %s.', 'invoicing' ), |
|
| 220 | - sanitize_key( $type ), |
|
| 221 | - $email->is_admin_email() ? __( 'admin' ) : __( 'the customer' ) |
|
| 222 | - ) |
|
| 223 | - ); |
|
| 224 | - } |
|
| 225 | - |
|
| 226 | - do_action( 'getpaid_after_send_invoice_notification', $type, $invoice, $email ); |
|
| 227 | - |
|
| 228 | - return $result; |
|
| 229 | - } |
|
| 230 | - |
|
| 231 | - /** |
|
| 232 | - * Also send emails to any cc users. |
|
| 233 | - * |
|
| 234 | - * @param array $recipients |
|
| 235 | - * @param GetPaid_Notification_Email $email |
|
| 236 | - */ |
|
| 237 | - public function filter_email_recipients( $recipients, $email ) { |
|
| 238 | - |
|
| 239 | - if ( ! $email->is_admin_email() ) { |
|
| 240 | - $cc = $email->object->get_email_cc(); |
|
| 241 | - |
|
| 242 | - if ( ! empty( $cc ) ) { |
|
| 243 | - $cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) ); |
|
| 244 | - $recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) ); |
|
| 245 | - } |
|
| 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 | + } |
|
| 166 | + |
|
| 167 | + return apply_filters( 'getpaid_invoice_email_merge_tags', $merge_tags, $invoice ); |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + /** |
|
| 171 | + * Helper function to send an email. |
|
| 172 | + * |
|
| 173 | + * @param WPInv_Invoice $invoice |
|
| 174 | + * @param GetPaid_Notification_Email $email |
|
| 175 | + * @param string $type |
|
| 176 | + * @param string|array $recipients |
|
| 177 | + * @param array $extra_args Extra template args. |
|
| 178 | + */ |
|
| 179 | + public function send_email( $invoice, $email, $type, $recipients, $extra_args = array() ) { |
|
| 180 | + |
|
| 181 | + do_action( 'getpaid_before_send_invoice_notification', $type, $invoice, $email ); |
|
| 182 | + |
|
| 183 | + $skip = $invoice->is_free() && wpinv_get_option( 'skip_email_free_invoice' ); |
|
| 184 | + if ( apply_filters( 'getpaid_skip_invoice_email', $skip, $type, $invoice ) ) { |
|
| 185 | + return; |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + $mailer = new GetPaid_Notification_Email_Sender(); |
|
| 189 | + $merge_tags = $email->get_merge_tags(); |
|
| 190 | + |
|
| 191 | + $result = $mailer->send( |
|
| 192 | + apply_filters( 'getpaid_invoice_email_recipients', wpinv_parse_list( $recipients ), $email ), |
|
| 193 | + $email->add_merge_tags( $email->get_subject(), $merge_tags ), |
|
| 194 | + $email->get_content( $merge_tags, $extra_args ), |
|
| 195 | + $email->get_attachments() |
|
| 196 | + ); |
|
| 197 | + |
|
| 198 | + // Maybe send a copy to the admin. |
|
| 199 | + if ( $email->include_admin_bcc() ) { |
|
| 200 | + $mailer->send( |
|
| 201 | + wpinv_get_admin_email(), |
|
| 202 | + $email->add_merge_tags( $email->get_subject() . __( ' - ADMIN BCC COPY', 'invoicing' ), $merge_tags ), |
|
| 203 | + $email->get_content( $merge_tags ), |
|
| 204 | + $email->get_attachments() |
|
| 205 | + ); |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + if ( $result ) { |
|
| 209 | + $invoice->add_system_note( |
|
| 210 | + sprintf( |
|
| 211 | + __( 'Successfully sent %s notification email to %s.', 'invoicing' ), |
|
| 212 | + sanitize_key( $type ), |
|
| 213 | + $email->is_admin_email() ? __( 'admin' ) : __( 'the customer' ) |
|
| 214 | + ) |
|
| 215 | + ); |
|
| 216 | + } else { |
|
| 217 | + $invoice->add_system_note( |
|
| 218 | + sprintf( |
|
| 219 | + __( 'Failed sending %s notification email to %s.', 'invoicing' ), |
|
| 220 | + sanitize_key( $type ), |
|
| 221 | + $email->is_admin_email() ? __( 'admin' ) : __( 'the customer' ) |
|
| 222 | + ) |
|
| 223 | + ); |
|
| 224 | + } |
|
| 225 | + |
|
| 226 | + do_action( 'getpaid_after_send_invoice_notification', $type, $invoice, $email ); |
|
| 227 | + |
|
| 228 | + return $result; |
|
| 229 | + } |
|
| 230 | + |
|
| 231 | + /** |
|
| 232 | + * Also send emails to any cc users. |
|
| 233 | + * |
|
| 234 | + * @param array $recipients |
|
| 235 | + * @param GetPaid_Notification_Email $email |
|
| 236 | + */ |
|
| 237 | + public function filter_email_recipients( $recipients, $email ) { |
|
| 238 | + |
|
| 239 | + if ( ! $email->is_admin_email() ) { |
|
| 240 | + $cc = $email->object->get_email_cc(); |
|
| 241 | + |
|
| 242 | + if ( ! empty( $cc ) ) { |
|
| 243 | + $cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) ); |
|
| 244 | + $recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) ); |
|
| 245 | + } |
|
| 246 | 246 | |
| 247 | - } |
|
| 247 | + } |
|
| 248 | 248 | |
| 249 | - return $recipients; |
|
| 250 | - |
|
| 251 | - } |
|
| 252 | - |
|
| 253 | - /** |
|
| 254 | - * Sends a new invoice notification. |
|
| 255 | - * |
|
| 256 | - * @param WPInv_Invoice $invoice |
|
| 257 | - */ |
|
| 258 | - public function new_invoice( $invoice ) { |
|
| 259 | - |
|
| 260 | - // Only send this email for invoices created via the admin page. |
|
| 261 | - if ( ! $invoice->is_type( 'invoice' ) || $this->is_payment_form_invoice( $invoice->get_id() ) ) { |
|
| 262 | - return; |
|
| 263 | - } |
|
| 264 | - |
|
| 265 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
| 266 | - $recipient = wpinv_get_admin_email(); |
|
| 267 | - |
|
| 268 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
| 269 | - |
|
| 270 | - } |
|
| 271 | - |
|
| 272 | - /** |
|
| 273 | - * Sends a cancelled invoice notification. |
|
| 274 | - * |
|
| 275 | - * @param WPInv_Invoice $invoice |
|
| 276 | - */ |
|
| 277 | - public function cancelled_invoice( $invoice ) { |
|
| 278 | - |
|
| 279 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
| 280 | - $recipient = wpinv_get_admin_email(); |
|
| 281 | - |
|
| 282 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
| 283 | - |
|
| 284 | - } |
|
| 285 | - |
|
| 286 | - /** |
|
| 287 | - * Sends a failed invoice notification. |
|
| 288 | - * |
|
| 289 | - * @param WPInv_Invoice $invoice |
|
| 290 | - */ |
|
| 291 | - public function failed_invoice( $invoice ) { |
|
| 292 | - |
|
| 293 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
| 294 | - $recipient = wpinv_get_admin_email(); |
|
| 295 | - |
|
| 296 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
| 297 | - |
|
| 298 | - } |
|
| 299 | - |
|
| 300 | - /** |
|
| 301 | - * Sends a notification whenever an invoice is put on hold. |
|
| 302 | - * |
|
| 303 | - * @param WPInv_Invoice $invoice |
|
| 304 | - */ |
|
| 305 | - public function onhold_invoice( $invoice ) { |
|
| 306 | - |
|
| 307 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
| 308 | - $recipient = $invoice->get_email(); |
|
| 309 | - |
|
| 310 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
| 249 | + return $recipients; |
|
| 250 | + |
|
| 251 | + } |
|
| 252 | + |
|
| 253 | + /** |
|
| 254 | + * Sends a new invoice notification. |
|
| 255 | + * |
|
| 256 | + * @param WPInv_Invoice $invoice |
|
| 257 | + */ |
|
| 258 | + public function new_invoice( $invoice ) { |
|
| 259 | + |
|
| 260 | + // Only send this email for invoices created via the admin page. |
|
| 261 | + if ( ! $invoice->is_type( 'invoice' ) || $this->is_payment_form_invoice( $invoice->get_id() ) ) { |
|
| 262 | + return; |
|
| 263 | + } |
|
| 264 | + |
|
| 265 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
| 266 | + $recipient = wpinv_get_admin_email(); |
|
| 267 | + |
|
| 268 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
| 269 | + |
|
| 270 | + } |
|
| 271 | + |
|
| 272 | + /** |
|
| 273 | + * Sends a cancelled invoice notification. |
|
| 274 | + * |
|
| 275 | + * @param WPInv_Invoice $invoice |
|
| 276 | + */ |
|
| 277 | + public function cancelled_invoice( $invoice ) { |
|
| 278 | + |
|
| 279 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
| 280 | + $recipient = wpinv_get_admin_email(); |
|
| 281 | + |
|
| 282 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
| 283 | + |
|
| 284 | + } |
|
| 285 | + |
|
| 286 | + /** |
|
| 287 | + * Sends a failed invoice notification. |
|
| 288 | + * |
|
| 289 | + * @param WPInv_Invoice $invoice |
|
| 290 | + */ |
|
| 291 | + public function failed_invoice( $invoice ) { |
|
| 292 | + |
|
| 293 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
| 294 | + $recipient = wpinv_get_admin_email(); |
|
| 295 | + |
|
| 296 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
| 297 | + |
|
| 298 | + } |
|
| 299 | + |
|
| 300 | + /** |
|
| 301 | + * Sends a notification whenever an invoice is put on hold. |
|
| 302 | + * |
|
| 303 | + * @param WPInv_Invoice $invoice |
|
| 304 | + */ |
|
| 305 | + public function onhold_invoice( $invoice ) { |
|
| 306 | + |
|
| 307 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
| 308 | + $recipient = $invoice->get_email(); |
|
| 309 | + |
|
| 310 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
| 311 | 311 | |
| 312 | - } |
|
| 312 | + } |
|
| 313 | 313 | |
| 314 | - /** |
|
| 315 | - * Sends a notification whenever an invoice is marked as processing payment. |
|
| 316 | - * |
|
| 317 | - * @param WPInv_Invoice $invoice |
|
| 318 | - */ |
|
| 319 | - public function processing_invoice( $invoice ) { |
|
| 314 | + /** |
|
| 315 | + * Sends a notification whenever an invoice is marked as processing payment. |
|
| 316 | + * |
|
| 317 | + * @param WPInv_Invoice $invoice |
|
| 318 | + */ |
|
| 319 | + public function processing_invoice( $invoice ) { |
|
| 320 | 320 | |
| 321 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
| 322 | - $recipient = $invoice->get_email(); |
|
| 321 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
| 322 | + $recipient = $invoice->get_email(); |
|
| 323 | 323 | |
| 324 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
| 324 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
| 325 | 325 | |
| 326 | - } |
|
| 326 | + } |
|
| 327 | 327 | |
| 328 | - /** |
|
| 329 | - * Sends a notification whenever an invoice is paid. |
|
| 330 | - * |
|
| 331 | - * @param WPInv_Invoice $invoice |
|
| 332 | - */ |
|
| 333 | - public function completed_invoice( $invoice ) { |
|
| 328 | + /** |
|
| 329 | + * Sends a notification whenever an invoice is paid. |
|
| 330 | + * |
|
| 331 | + * @param WPInv_Invoice $invoice |
|
| 332 | + */ |
|
| 333 | + public function completed_invoice( $invoice ) { |
|
| 334 | 334 | |
| 335 | - // (Maybe) abort if it is a renewal invoice. |
|
| 336 | - if ( $invoice->is_renewal() && ! wpinv_get_option( 'email_completed_invoice_renewal_active', false ) ) { |
|
| 337 | - return; |
|
| 338 | - } |
|
| 335 | + // (Maybe) abort if it is a renewal invoice. |
|
| 336 | + if ( $invoice->is_renewal() && ! wpinv_get_option( 'email_completed_invoice_renewal_active', false ) ) { |
|
| 337 | + return; |
|
| 338 | + } |
|
| 339 | 339 | |
| 340 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
| 341 | - $recipient = $invoice->get_email(); |
|
| 340 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
| 341 | + $recipient = $invoice->get_email(); |
|
| 342 | 342 | |
| 343 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
| 343 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
| 344 | 344 | |
| 345 | - } |
|
| 345 | + } |
|
| 346 | 346 | |
| 347 | - /** |
|
| 348 | - * Sends a notification whenever an invoice is refunded. |
|
| 349 | - * |
|
| 350 | - * @param WPInv_Invoice $invoice |
|
| 351 | - */ |
|
| 352 | - public function refunded_invoice( $invoice ) { |
|
| 347 | + /** |
|
| 348 | + * Sends a notification whenever an invoice is refunded. |
|
| 349 | + * |
|
| 350 | + * @param WPInv_Invoice $invoice |
|
| 351 | + */ |
|
| 352 | + public function refunded_invoice( $invoice ) { |
|
| 353 | 353 | |
| 354 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
| 355 | - $recipient = $invoice->get_email(); |
|
| 354 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
| 355 | + $recipient = $invoice->get_email(); |
|
| 356 | 356 | |
| 357 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
| 357 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
| 358 | 358 | |
| 359 | - } |
|
| 359 | + } |
|
| 360 | 360 | |
| 361 | - /** |
|
| 362 | - * Notifies a user about new invoices |
|
| 363 | - * |
|
| 364 | - * @param WPInv_Invoice $invoice |
|
| 365 | - * @param bool $force |
|
| 366 | - */ |
|
| 367 | - public function user_invoice( $invoice, $force = false ) { |
|
| 361 | + /** |
|
| 362 | + * Notifies a user about new invoices |
|
| 363 | + * |
|
| 364 | + * @param WPInv_Invoice $invoice |
|
| 365 | + * @param bool $force |
|
| 366 | + */ |
|
| 367 | + public function user_invoice( $invoice, $force = false ) { |
|
| 368 | 368 | |
| 369 | - if ( ! empty( $GLOBALS['wpinv_skip_invoice_notification'] ) ) { |
|
| 370 | - return; |
|
| 371 | - } |
|
| 372 | - |
|
| 373 | - // Only send this email for invoices created via the admin page. |
|
| 374 | - if ( ! $invoice->is_type( 'invoice' ) || ( empty( $force ) && $this->is_payment_form_invoice( $invoice->get_id() ) ) ) { |
|
| 375 | - return; |
|
| 376 | - } |
|
| 369 | + if ( ! empty( $GLOBALS['wpinv_skip_invoice_notification'] ) ) { |
|
| 370 | + return; |
|
| 371 | + } |
|
| 372 | + |
|
| 373 | + // Only send this email for invoices created via the admin page. |
|
| 374 | + if ( ! $invoice->is_type( 'invoice' ) || ( empty( $force ) && $this->is_payment_form_invoice( $invoice->get_id() ) ) ) { |
|
| 375 | + return; |
|
| 376 | + } |
|
| 377 | 377 | |
| 378 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
| 379 | - $recipient = $invoice->get_email(); |
|
| 378 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
| 379 | + $recipient = $invoice->get_email(); |
|
| 380 | 380 | |
| 381 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
| 381 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
| 382 | 382 | |
| 383 | - } |
|
| 384 | - |
|
| 385 | - /** |
|
| 386 | - * Checks if an invoice is a payment form invoice. |
|
| 387 | - * |
|
| 388 | - * @param int $invoice |
|
| 389 | - * @return bool |
|
| 390 | - */ |
|
| 391 | - public function is_payment_form_invoice( $invoice ) { |
|
| 392 | - $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 ) ); |
|
| 393 | - return apply_filters( 'getpaid_invoice_notifications_is_payment_form_invoice', $is_payment_form_invoice, $invoice ); |
|
| 394 | - } |
|
| 383 | + } |
|
| 384 | + |
|
| 385 | + /** |
|
| 386 | + * Checks if an invoice is a payment form invoice. |
|
| 387 | + * |
|
| 388 | + * @param int $invoice |
|
| 389 | + * @return bool |
|
| 390 | + */ |
|
| 391 | + public function is_payment_form_invoice( $invoice ) { |
|
| 392 | + $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 ) ); |
|
| 393 | + return apply_filters( 'getpaid_invoice_notifications_is_payment_form_invoice', $is_payment_form_invoice, $invoice ); |
|
| 394 | + } |
|
| 395 | 395 | |
| 396 | - /** |
|
| 397 | - * Notifies admin about new invoice notes |
|
| 398 | - * |
|
| 399 | - * @param WPInv_Invoice $invoice |
|
| 400 | - * @param string $note |
|
| 401 | - */ |
|
| 402 | - public function user_note( $invoice, $note ) { |
|
| 403 | - |
|
| 404 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
| 405 | - $recipient = $invoice->get_email(); |
|
| 396 | + /** |
|
| 397 | + * Notifies admin about new invoice notes |
|
| 398 | + * |
|
| 399 | + * @param WPInv_Invoice $invoice |
|
| 400 | + * @param string $note |
|
| 401 | + */ |
|
| 402 | + public function user_note( $invoice, $note ) { |
|
| 403 | + |
|
| 404 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
| 405 | + $recipient = $invoice->get_email(); |
|
| 406 | 406 | |
| 407 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient, array( 'customer_note' => $note ) ); |
|
| 408 | - |
|
| 409 | - } |
|
| 410 | - |
|
| 411 | - /** |
|
| 412 | - * (Force) Sends overdue notices. |
|
| 413 | - * |
|
| 414 | - * @param WPInv_Invoice $invoice |
|
| 415 | - */ |
|
| 416 | - public function force_send_overdue_notice( $invoice ) { |
|
| 417 | - $email = new GetPaid_Notification_Email( 'overdue', $invoice ); |
|
| 418 | - return $this->send_email( $invoice, $email, 'overdue', $invoice->get_email() ); |
|
| 419 | - } |
|
| 420 | - |
|
| 421 | - /** |
|
| 422 | - * Sends overdue notices. |
|
| 423 | - * |
|
| 424 | - * @TODO: Create an invoices query class. |
|
| 425 | - */ |
|
| 426 | - public function overdue() { |
|
| 427 | - global $wpdb; |
|
| 428 | - |
|
| 429 | - $email = new GetPaid_Notification_Email( __FUNCTION__ ); |
|
| 430 | - |
|
| 431 | - // Fetch reminder days. |
|
| 432 | - $reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) ); |
|
| 433 | - |
|
| 434 | - // Abort if non is set. |
|
| 435 | - if ( empty( $reminder_days ) ) { |
|
| 436 | - return; |
|
| 437 | - } |
|
| 438 | - |
|
| 439 | - // Retrieve date query. |
|
| 440 | - $date_query = $this->get_date_query( $reminder_days ); |
|
| 441 | - |
|
| 442 | - // Invoices table. |
|
| 443 | - $table = $wpdb->prefix . 'getpaid_invoices'; |
|
| 444 | - |
|
| 445 | - // Fetch invoices. |
|
| 446 | - $invoices = $wpdb->get_col( |
|
| 447 | - "SELECT posts.ID FROM $wpdb->posts as posts |
|
| 407 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient, array( 'customer_note' => $note ) ); |
|
| 408 | + |
|
| 409 | + } |
|
| 410 | + |
|
| 411 | + /** |
|
| 412 | + * (Force) Sends overdue notices. |
|
| 413 | + * |
|
| 414 | + * @param WPInv_Invoice $invoice |
|
| 415 | + */ |
|
| 416 | + public function force_send_overdue_notice( $invoice ) { |
|
| 417 | + $email = new GetPaid_Notification_Email( 'overdue', $invoice ); |
|
| 418 | + return $this->send_email( $invoice, $email, 'overdue', $invoice->get_email() ); |
|
| 419 | + } |
|
| 420 | + |
|
| 421 | + /** |
|
| 422 | + * Sends overdue notices. |
|
| 423 | + * |
|
| 424 | + * @TODO: Create an invoices query class. |
|
| 425 | + */ |
|
| 426 | + public function overdue() { |
|
| 427 | + global $wpdb; |
|
| 428 | + |
|
| 429 | + $email = new GetPaid_Notification_Email( __FUNCTION__ ); |
|
| 430 | + |
|
| 431 | + // Fetch reminder days. |
|
| 432 | + $reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) ); |
|
| 433 | + |
|
| 434 | + // Abort if non is set. |
|
| 435 | + if ( empty( $reminder_days ) ) { |
|
| 436 | + return; |
|
| 437 | + } |
|
| 438 | + |
|
| 439 | + // Retrieve date query. |
|
| 440 | + $date_query = $this->get_date_query( $reminder_days ); |
|
| 441 | + |
|
| 442 | + // Invoices table. |
|
| 443 | + $table = $wpdb->prefix . 'getpaid_invoices'; |
|
| 444 | + |
|
| 445 | + // Fetch invoices. |
|
| 446 | + $invoices = $wpdb->get_col( |
|
| 447 | + "SELECT posts.ID FROM $wpdb->posts as posts |
|
| 448 | 448 | LEFT JOIN $table as invoices ON invoices.post_id = posts.ID |
| 449 | 449 | WHERE posts.post_type = 'wpi_invoice' AND posts.post_status = 'wpi-pending' $date_query"); |
| 450 | 450 | |
| 451 | - foreach ( $invoices as $invoice ) { |
|
| 451 | + foreach ( $invoices as $invoice ) { |
|
| 452 | 452 | |
| 453 | - // Only send this email for invoices created via the admin page. |
|
| 454 | - if ( ! $this->is_payment_form_invoice( $invoice ) ) { |
|
| 455 | - $invoice = new WPInv_Invoice( $invoice ); |
|
| 456 | - $email->object = $invoice; |
|
| 453 | + // Only send this email for invoices created via the admin page. |
|
| 454 | + if ( ! $this->is_payment_form_invoice( $invoice ) ) { |
|
| 455 | + $invoice = new WPInv_Invoice( $invoice ); |
|
| 456 | + $email->object = $invoice; |
|
| 457 | 457 | |
| 458 | - if ( $invoice->needs_payment() ) { |
|
| 459 | - $this->send_email( $invoice, $email, __FUNCTION__, $invoice->get_email() ); |
|
| 460 | - } |
|
| 458 | + if ( $invoice->needs_payment() ) { |
|
| 459 | + $this->send_email( $invoice, $email, __FUNCTION__, $invoice->get_email() ); |
|
| 460 | + } |
|
| 461 | 461 | |
| 462 | - } |
|
| 462 | + } |
|
| 463 | 463 | |
| 464 | - } |
|
| 464 | + } |
|
| 465 | 465 | |
| 466 | - } |
|
| 466 | + } |
|
| 467 | 467 | |
| 468 | - /** |
|
| 469 | - * Calculates the date query for an invoices query |
|
| 470 | - * |
|
| 471 | - * @param array $reminder_days |
|
| 472 | - * @return string |
|
| 473 | - */ |
|
| 474 | - public function get_date_query( $reminder_days ) { |
|
| 468 | + /** |
|
| 469 | + * Calculates the date query for an invoices query |
|
| 470 | + * |
|
| 471 | + * @param array $reminder_days |
|
| 472 | + * @return string |
|
| 473 | + */ |
|
| 474 | + public function get_date_query( $reminder_days ) { |
|
| 475 | 475 | |
| 476 | - $date_query = array( |
|
| 477 | - 'relation' => 'OR' |
|
| 478 | - ); |
|
| 476 | + $date_query = array( |
|
| 477 | + 'relation' => 'OR' |
|
| 478 | + ); |
|
| 479 | 479 | |
| 480 | - foreach ( $reminder_days as $days ) { |
|
| 481 | - $date = date_parse( date( 'Y-m-d', strtotime( "-$days days", current_time( 'timestamp' ) ) ) ); |
|
| 480 | + foreach ( $reminder_days as $days ) { |
|
| 481 | + $date = date_parse( date( 'Y-m-d', strtotime( "-$days days", current_time( 'timestamp' ) ) ) ); |
|
| 482 | 482 | |
| 483 | - $date_query[] = array( |
|
| 484 | - 'year' => $date['year'], |
|
| 485 | - 'month' => $date['month'], |
|
| 486 | - 'day' => $date['day'], |
|
| 487 | - ); |
|
| 483 | + $date_query[] = array( |
|
| 484 | + 'year' => $date['year'], |
|
| 485 | + 'month' => $date['month'], |
|
| 486 | + 'day' => $date['day'], |
|
| 487 | + ); |
|
| 488 | 488 | |
| 489 | - } |
|
| 489 | + } |
|
| 490 | 490 | |
| 491 | - $date_query = new WP_Date_Query( $date_query, 'invoices.due_date' ); |
|
| 491 | + $date_query = new WP_Date_Query( $date_query, 'invoices.due_date' ); |
|
| 492 | 492 | |
| 493 | - return $date_query->get_sql(); |
|
| 493 | + return $date_query->get_sql(); |
|
| 494 | 494 | |
| 495 | - } |
|
| 495 | + } |
|
| 496 | 496 | |
| 497 | 497 | } |