@@ -281,9 +281,9 @@ |
||
| 281 | 281 | return $value; |
| 282 | 282 | } |
| 283 | 283 | |
| 284 | - /** |
|
| 285 | - * Sets an invoice key. |
|
| 286 | - */ |
|
| 284 | + /** |
|
| 285 | + * Sets an invoice key. |
|
| 286 | + */ |
|
| 287 | 287 | public function set( $key, $value ) { |
| 288 | 288 | $ignore = array( 'items', 'cart_details', 'fees', '_ID' ); |
| 289 | 289 | |
@@ -1,8 +1,8 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | // MUST have WordPress. |
| 4 | -if ( !defined( 'WPINC' ) ) { |
|
| 5 | - exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) ); |
|
| 4 | +if (!defined('WPINC')) { |
|
| 5 | + exit('Do NOT access this file directly: ' . basename(__FILE__)); |
|
| 6 | 6 | } |
| 7 | 7 | |
| 8 | 8 | /** |
@@ -13,7 +13,7 @@ discard block |
||
| 13 | 13 | /** |
| 14 | 14 | * @var int the invoice ID. |
| 15 | 15 | */ |
| 16 | - public $ID = 0; |
|
| 16 | + public $ID = 0; |
|
| 17 | 17 | |
| 18 | 18 | /** |
| 19 | 19 | * @var string the invoice title. |
@@ -258,23 +258,23 @@ discard block |
||
| 258 | 258 | /** |
| 259 | 259 | * @param int|WPInv_Invoice|WP_Post $invoice The invoice. |
| 260 | 260 | */ |
| 261 | - public function __construct( $invoice = false ) { |
|
| 261 | + public function __construct($invoice = false) { |
|
| 262 | 262 | |
| 263 | 263 | // Do we have an invoice? |
| 264 | - if ( empty( $invoice ) ) { |
|
| 264 | + if (empty($invoice)) { |
|
| 265 | 265 | return false; |
| 266 | 266 | } |
| 267 | 267 | |
| 268 | - $this->setup_invoice( $invoice ); |
|
| 268 | + $this->setup_invoice($invoice); |
|
| 269 | 269 | |
| 270 | 270 | } |
| 271 | 271 | |
| 272 | 272 | /** |
| 273 | 273 | * Retrieves an invoice key. |
| 274 | 274 | */ |
| 275 | - public function get( $key ) { |
|
| 276 | - if ( method_exists( $this, 'get_' . $key ) ) { |
|
| 277 | - $value = call_user_func( array( $this, 'get_' . $key ) ); |
|
| 275 | + public function get($key) { |
|
| 276 | + if (method_exists($this, 'get_' . $key)) { |
|
| 277 | + $value = call_user_func(array($this, 'get_' . $key)); |
|
| 278 | 278 | } else { |
| 279 | 279 | $value = $this->$key; |
| 280 | 280 | } |
@@ -285,18 +285,18 @@ discard block |
||
| 285 | 285 | /** |
| 286 | 286 | * Sets an invoice key. |
| 287 | 287 | */ |
| 288 | - public function set( $key, $value ) { |
|
| 289 | - $ignore = array( 'items', 'cart_details', 'fees', '_ID' ); |
|
| 288 | + public function set($key, $value) { |
|
| 289 | + $ignore = array('items', 'cart_details', 'fees', '_ID'); |
|
| 290 | 290 | |
| 291 | - if ( $key === 'status' ) { |
|
| 291 | + if ($key === 'status') { |
|
| 292 | 292 | $this->old_status = $this->status; |
| 293 | 293 | } |
| 294 | 294 | |
| 295 | - if ( ! in_array( $key, $ignore ) ) { |
|
| 296 | - $this->pending[ $key ] = $value; |
|
| 295 | + if (!in_array($key, $ignore)) { |
|
| 296 | + $this->pending[$key] = $value; |
|
| 297 | 297 | } |
| 298 | 298 | |
| 299 | - if( '_ID' !== $key ) { |
|
| 299 | + if ('_ID' !== $key) { |
|
| 300 | 300 | $this->$key = $value; |
| 301 | 301 | } |
| 302 | 302 | } |
@@ -304,9 +304,9 @@ discard block |
||
| 304 | 304 | /** |
| 305 | 305 | * Checks if an invoice key is set. |
| 306 | 306 | */ |
| 307 | - public function _isset( $name ) { |
|
| 308 | - if ( property_exists( $this, $name) ) { |
|
| 309 | - return false === empty( $this->$name ); |
|
| 307 | + public function _isset($name) { |
|
| 308 | + if (property_exists($this, $name)) { |
|
| 309 | + return false === empty($this->$name); |
|
| 310 | 310 | } else { |
| 311 | 311 | return null; |
| 312 | 312 | } |
@@ -315,66 +315,66 @@ discard block |
||
| 315 | 315 | /** |
| 316 | 316 | * @param int|WPInv_Invoice|WP_Post $invoice The invoice. |
| 317 | 317 | */ |
| 318 | - private function setup_invoice( $invoice ) { |
|
| 318 | + private function setup_invoice($invoice) { |
|
| 319 | 319 | global $wpdb; |
| 320 | 320 | $this->pending = array(); |
| 321 | 321 | |
| 322 | - if ( empty( $invoice ) ) { |
|
| 322 | + if (empty($invoice)) { |
|
| 323 | 323 | return false; |
| 324 | 324 | } |
| 325 | 325 | |
| 326 | - if ( is_a( $invoice, 'WPInv_Invoice' ) ) { |
|
| 327 | - foreach ( get_object_vars( $invoice ) as $prop => $value ) { |
|
| 326 | + if (is_a($invoice, 'WPInv_Invoice')) { |
|
| 327 | + foreach (get_object_vars($invoice) as $prop => $value) { |
|
| 328 | 328 | $this->$prop = $value; |
| 329 | 329 | } |
| 330 | 330 | return true; |
| 331 | 331 | } |
| 332 | 332 | |
| 333 | 333 | // Retrieve post object. |
| 334 | - $invoice = get_post( $invoice ); |
|
| 334 | + $invoice = get_post($invoice); |
|
| 335 | 335 | |
| 336 | - if( ! $invoice || is_wp_error( $invoice ) ) { |
|
| 336 | + if (!$invoice || is_wp_error($invoice)) { |
|
| 337 | 337 | return false; |
| 338 | 338 | } |
| 339 | 339 | |
| 340 | - if( ! ( 'wpi_invoice' == $invoice->post_type OR 'wpi_quote' == $invoice->post_type ) ) { |
|
| 340 | + if (!('wpi_invoice' == $invoice->post_type OR 'wpi_quote' == $invoice->post_type)) { |
|
| 341 | 341 | return false; |
| 342 | 342 | } |
| 343 | 343 | |
| 344 | 344 | // Retrieve post data. |
| 345 | 345 | $table = $wpdb->prefix . 'getpaid_invoices'; |
| 346 | 346 | $data = $wpdb->get_row( |
| 347 | - $wpdb->prepare( "SELECT * FROM $table WHERE post_id=%d", $invoice->ID ) |
|
| 347 | + $wpdb->prepare("SELECT * FROM $table WHERE post_id=%d", $invoice->ID) |
|
| 348 | 348 | ); |
| 349 | 349 | |
| 350 | - do_action( 'wpinv_pre_setup_invoice', $this, $invoice->ID, $data ); |
|
| 350 | + do_action('wpinv_pre_setup_invoice', $this, $invoice->ID, $data); |
|
| 351 | 351 | |
| 352 | 352 | // Primary Identifier |
| 353 | - $this->ID = absint( $invoice->ID ); |
|
| 353 | + $this->ID = absint($invoice->ID); |
|
| 354 | 354 | $this->post_type = $invoice->post_type; |
| 355 | 355 | |
| 356 | 356 | $this->date = $invoice->post_date; |
| 357 | 357 | $this->status = $invoice->post_status; |
| 358 | 358 | |
| 359 | - if ( 'future' == $this->status ) { |
|
| 359 | + if ('future' == $this->status) { |
|
| 360 | 360 | $this->status = 'publish'; |
| 361 | 361 | } |
| 362 | 362 | |
| 363 | 363 | $this->post_status = $this->status; |
| 364 | 364 | $this->parent_invoice = $invoice->post_parent; |
| 365 | - $this->post_name = $this->setup_post_name( $invoice ); |
|
| 366 | - $this->status_nicename = $this->setup_status_nicename( $invoice->post_status ); |
|
| 365 | + $this->post_name = $this->setup_post_name($invoice); |
|
| 366 | + $this->status_nicename = $this->setup_status_nicename($invoice->post_status); |
|
| 367 | 367 | |
| 368 | - $this->user_id = ! empty( $invoice->post_author ) ? $invoice->post_author : get_current_user_id(); |
|
| 369 | - $this->email = get_the_author_meta( 'email', $this->user_id ); |
|
| 368 | + $this->user_id = !empty($invoice->post_author) ? $invoice->post_author : get_current_user_id(); |
|
| 369 | + $this->email = get_the_author_meta('email', $this->user_id); |
|
| 370 | 370 | $this->currency = wpinv_get_currency(); |
| 371 | - $this->setup_invoice_data( $data ); |
|
| 371 | + $this->setup_invoice_data($data); |
|
| 372 | 372 | |
| 373 | 373 | // Other Identifiers |
| 374 | - $this->title = ! empty( $invoice->post_title ) ? $invoice->post_title : $this->number; |
|
| 374 | + $this->title = !empty($invoice->post_title) ? $invoice->post_title : $this->number; |
|
| 375 | 375 | |
| 376 | 376 | // Allow extensions to add items to this object via hook |
| 377 | - do_action( 'wpinv_setup_invoice', $this, $invoice->ID, $data ); |
|
| 377 | + do_action('wpinv_setup_invoice', $this, $invoice->ID, $data); |
|
| 378 | 378 | |
| 379 | 379 | return true; |
| 380 | 380 | } |
@@ -382,16 +382,16 @@ discard block |
||
| 382 | 382 | /** |
| 383 | 383 | * @param stdClass $data The invoice data. |
| 384 | 384 | */ |
| 385 | - private function setup_invoice_data( $data ) { |
|
| 385 | + private function setup_invoice_data($data) { |
|
| 386 | 386 | |
| 387 | - if ( empty( $data ) ) { |
|
| 388 | - $this->number = $this->setup_invoice_number( $data ); |
|
| 387 | + if (empty($data)) { |
|
| 388 | + $this->number = $this->setup_invoice_number($data); |
|
| 389 | 389 | return; |
| 390 | 390 | } |
| 391 | 391 | |
| 392 | - $data = map_deep( $data, 'maybe_unserialize' ); |
|
| 392 | + $data = map_deep($data, 'maybe_unserialize'); |
|
| 393 | 393 | |
| 394 | - $this->payment_meta = is_array( $data->custom_meta ) ? $data->custom_meta : array(); |
|
| 394 | + $this->payment_meta = is_array($data->custom_meta) ? $data->custom_meta : array(); |
|
| 395 | 395 | $this->due_date = $data->due_date; |
| 396 | 396 | $this->completed_date = $data->completed_date; |
| 397 | 397 | $this->mode = $data->mode; |
@@ -399,7 +399,7 @@ discard block |
||
| 399 | 399 | // Items |
| 400 | 400 | $this->fees = $this->setup_fees(); |
| 401 | 401 | $this->cart_details = $this->setup_cart_details(); |
| 402 | - $this->items = ! empty( $this->payment_meta['items'] ) ? $this->payment_meta['items'] : array(); |
|
| 402 | + $this->items = !empty($this->payment_meta['items']) ? $this->payment_meta['items'] : array(); |
|
| 403 | 403 | |
| 404 | 404 | // Currency Based |
| 405 | 405 | $this->total = $data->total; |
@@ -407,7 +407,7 @@ discard block |
||
| 407 | 407 | $this->tax = $data->tax; |
| 408 | 408 | $this->fees_total = $data->fees_total; |
| 409 | 409 | $this->subtotal = $data->subtotal; |
| 410 | - $this->currency = empty( $data->currency ) ? wpinv_get_currency() : $data->currency ; |
|
| 410 | + $this->currency = empty($data->currency) ? wpinv_get_currency() : $data->currency; |
|
| 411 | 411 | |
| 412 | 412 | // Gateway based |
| 413 | 413 | $this->gateway = $data->gateway; |
@@ -416,30 +416,30 @@ discard block |
||
| 416 | 416 | |
| 417 | 417 | // User based |
| 418 | 418 | $this->ip = $data->user_ip; |
| 419 | - $this->user_info = ! empty( $this->payment_meta['user_info'] ) ? $this->payment_meta['user_info'] : array(); |
|
| 419 | + $this->user_info = !empty($this->payment_meta['user_info']) ? $this->payment_meta['user_info'] : array(); |
|
| 420 | 420 | |
| 421 | 421 | $this->first_name = $data->first_name; |
| 422 | 422 | $this->last_name = $data->last_name; |
| 423 | 423 | $this->company = $data->company; |
| 424 | 424 | $this->vat_number = $data->vat_number; |
| 425 | 425 | $this->vat_rate = $data->vat_rate; |
| 426 | - $this->adddress_confirmed = (int) $data->adddress_confirmed; |
|
| 426 | + $this->adddress_confirmed = (int) $data->adddress_confirmed; |
|
| 427 | 427 | $this->address = $data->address; |
| 428 | 428 | $this->city = $data->city; |
| 429 | 429 | $this->country = $data->country; |
| 430 | 430 | $this->state = $data->state; |
| 431 | 431 | $this->zip = $data->zip; |
| 432 | - $this->phone = ! empty( $this->user_info['phone'] ) ? $this->user_info['phone'] : ''; |
|
| 432 | + $this->phone = !empty($this->user_info['phone']) ? $this->user_info['phone'] : ''; |
|
| 433 | 433 | |
| 434 | - $this->discounts = ! empty( $this->user_info['discount'] ) ? $this->user_info['discount'] : ''; |
|
| 434 | + $this->discounts = !empty($this->user_info['discount']) ? $this->user_info['discount'] : ''; |
|
| 435 | 435 | $this->discount = $data->discount; |
| 436 | 436 | $this->discount_code = $data->discount_code; |
| 437 | 437 | |
| 438 | 438 | // Other Identifiers |
| 439 | 439 | $this->key = $data->key; |
| 440 | - $this->number = $this->setup_invoice_number( $data ); |
|
| 440 | + $this->number = $this->setup_invoice_number($data); |
|
| 441 | 441 | |
| 442 | - $this->full_name = trim( $this->first_name . ' '. $this->last_name ); |
|
| 442 | + $this->full_name = trim($this->first_name . ' ' . $this->last_name); |
|
| 443 | 443 | |
| 444 | 444 | |
| 445 | 445 | return true; |
@@ -449,52 +449,52 @@ discard block |
||
| 449 | 449 | /** |
| 450 | 450 | * Sets up the status nice name. |
| 451 | 451 | */ |
| 452 | - private function setup_status_nicename( $status ) { |
|
| 453 | - $all_invoice_statuses = wpinv_get_invoice_statuses( true, true, $this ); |
|
| 452 | + private function setup_status_nicename($status) { |
|
| 453 | + $all_invoice_statuses = wpinv_get_invoice_statuses(true, true, $this); |
|
| 454 | 454 | |
| 455 | - if ( $this->is_quote() && class_exists( 'Wpinv_Quotes_Shared' ) ) { |
|
| 456 | - $all_invoice_statuses = Wpinv_Quotes_Shared::wpinv_get_quote_statuses(); |
|
| 455 | + if ($this->is_quote() && class_exists('Wpinv_Quotes_Shared')) { |
|
| 456 | + $all_invoice_statuses = Wpinv_Quotes_Shared::wpinv_get_quote_statuses(); |
|
| 457 | 457 | } |
| 458 | - $status = isset( $all_invoice_statuses[$status] ) ? $all_invoice_statuses[$status] : __( $status, 'invoicing' ); |
|
| 458 | + $status = isset($all_invoice_statuses[$status]) ? $all_invoice_statuses[$status] : __($status, 'invoicing'); |
|
| 459 | 459 | |
| 460 | - return apply_filters( 'setup_status_nicename', $status ); |
|
| 460 | + return apply_filters('setup_status_nicename', $status); |
|
| 461 | 461 | } |
| 462 | 462 | |
| 463 | 463 | /** |
| 464 | 464 | * Set's up the invoice number. |
| 465 | 465 | */ |
| 466 | - private function setup_invoice_number( $data ) { |
|
| 466 | + private function setup_invoice_number($data) { |
|
| 467 | 467 | |
| 468 | - if ( ! empty( $data ) && ! empty( $data->number ) ) { |
|
| 468 | + if (!empty($data) && !empty($data->number)) { |
|
| 469 | 469 | return $data->number; |
| 470 | 470 | } |
| 471 | 471 | |
| 472 | 472 | $number = $this->ID; |
| 473 | 473 | |
| 474 | - if ( $this->status == 'auto-draft' && wpinv_sequential_number_active( $this->post_type ) ) { |
|
| 475 | - $next_number = wpinv_get_next_invoice_number( $this->post_type ); |
|
| 474 | + if ($this->status == 'auto-draft' && wpinv_sequential_number_active($this->post_type)) { |
|
| 475 | + $next_number = wpinv_get_next_invoice_number($this->post_type); |
|
| 476 | 476 | $number = $next_number; |
| 477 | 477 | } |
| 478 | 478 | |
| 479 | - return wpinv_format_invoice_number( $number, $this->post_type ); |
|
| 479 | + return wpinv_format_invoice_number($number, $this->post_type); |
|
| 480 | 480 | |
| 481 | 481 | } |
| 482 | 482 | |
| 483 | 483 | /** |
| 484 | 484 | * Invoice's post name. |
| 485 | 485 | */ |
| 486 | - private function setup_post_name( $post = NULL ) { |
|
| 486 | + private function setup_post_name($post = NULL) { |
|
| 487 | 487 | global $wpdb; |
| 488 | 488 | |
| 489 | 489 | $post_name = ''; |
| 490 | 490 | |
| 491 | - if ( !empty( $post ) ) { |
|
| 492 | - if( !empty( $post->post_name ) ) { |
|
| 491 | + if (!empty($post)) { |
|
| 492 | + if (!empty($post->post_name)) { |
|
| 493 | 493 | $post_name = $post->post_name; |
| 494 | - } else if ( !empty( $post->ID ) ) { |
|
| 495 | - $post_name = wpinv_generate_post_name( $post->ID ); |
|
| 494 | + } else if (!empty($post->ID)) { |
|
| 495 | + $post_name = wpinv_generate_post_name($post->ID); |
|
| 496 | 496 | |
| 497 | - $wpdb->update( $wpdb->posts, array( 'post_name' => $post_name ), array( 'ID' => $post->ID ) ); |
|
| 497 | + $wpdb->update($wpdb->posts, array('post_name' => $post_name), array('ID' => $post->ID)); |
|
| 498 | 498 | } |
| 499 | 499 | } |
| 500 | 500 | |
@@ -507,18 +507,18 @@ discard block |
||
| 507 | 507 | public function setup_cart_details() { |
| 508 | 508 | global $wpdb; |
| 509 | 509 | |
| 510 | - $table = $wpdb->prefix . 'getpaid_invoice_items'; |
|
| 510 | + $table = $wpdb->prefix . 'getpaid_invoice_items'; |
|
| 511 | 511 | $items = $wpdb->get_results( |
| 512 | - $wpdb->prepare( "SELECT * FROM $table WHERE `post_id`=%d", $this->ID ) |
|
| 512 | + $wpdb->prepare("SELECT * FROM $table WHERE `post_id`=%d", $this->ID) |
|
| 513 | 513 | ); |
| 514 | 514 | |
| 515 | - if ( empty( $items ) ) { |
|
| 515 | + if (empty($items)) { |
|
| 516 | 516 | return array(); |
| 517 | 517 | } |
| 518 | 518 | |
| 519 | 519 | $details = array(); |
| 520 | 520 | |
| 521 | - foreach ( $items as $item ) { |
|
| 521 | + foreach ($items as $item) { |
|
| 522 | 522 | $item = (array) $item; |
| 523 | 523 | $details[] = array( |
| 524 | 524 | 'name' => $item['item_name'], |
@@ -537,7 +537,7 @@ discard block |
||
| 537 | 537 | ); |
| 538 | 538 | } |
| 539 | 539 | |
| 540 | - return map_deep( $details, 'maybe_unserialize' ); |
|
| 540 | + return map_deep($details, 'maybe_unserialize'); |
|
| 541 | 541 | |
| 542 | 542 | } |
| 543 | 543 | |
@@ -545,16 +545,16 @@ discard block |
||
| 545 | 545 | * Convert this to an array. |
| 546 | 546 | */ |
| 547 | 547 | public function array_convert() { |
| 548 | - return get_object_vars( $this ); |
|
| 548 | + return get_object_vars($this); |
|
| 549 | 549 | } |
| 550 | 550 | |
| 551 | 551 | private function setup_fees() { |
| 552 | - $payment_fees = isset( $this->payment_meta['fees'] ) ? $this->payment_meta['fees'] : array(); |
|
| 552 | + $payment_fees = isset($this->payment_meta['fees']) ? $this->payment_meta['fees'] : array(); |
|
| 553 | 553 | return $payment_fees; |
| 554 | 554 | } |
| 555 | 555 | |
| 556 | 556 | private function setup_gateway_title() { |
| 557 | - $gateway_title = wpinv_get_gateway_checkout_label( $this->gateway ); |
|
| 557 | + $gateway_title = wpinv_get_gateway_checkout_label($this->gateway); |
|
| 558 | 558 | return $gateway_title; |
| 559 | 559 | } |
| 560 | 560 | |
@@ -590,16 +590,16 @@ discard block |
||
| 590 | 590 | 'fees' => $this->fees, |
| 591 | 591 | ); |
| 592 | 592 | |
| 593 | - $this->payment_meta = array_merge( $this->payment_meta, $payment_data ); |
|
| 593 | + $this->payment_meta = array_merge($this->payment_meta, $payment_data); |
|
| 594 | 594 | |
| 595 | 595 | } |
| 596 | 596 | |
| 597 | 597 | private function insert_invoice() { |
| 598 | 598 | |
| 599 | - if ( empty( $this->post_type ) ) { |
|
| 600 | - if ( !empty( $this->ID ) && $post_type = get_post_type( $this->ID ) ) { |
|
| 599 | + if (empty($this->post_type)) { |
|
| 600 | + if (!empty($this->ID) && $post_type = get_post_type($this->ID)) { |
|
| 601 | 601 | $this->post_type = $post_type; |
| 602 | - } else if ( !empty( $this->parent_invoice ) && $post_type = get_post_type( $this->parent_invoice ) ) { |
|
| 602 | + } else if (!empty($this->parent_invoice) && $post_type = get_post_type($this->parent_invoice)) { |
|
| 603 | 603 | $this->post_type = $post_type; |
| 604 | 604 | } else { |
| 605 | 605 | $this->post_type = 'wpi_invoice'; |
@@ -607,16 +607,16 @@ discard block |
||
| 607 | 607 | } |
| 608 | 608 | |
| 609 | 609 | $invoice_number = $this->ID; |
| 610 | - if ( $number = $this->number ) { |
|
| 610 | + if ($number = $this->number) { |
|
| 611 | 611 | $invoice_number = $number; |
| 612 | 612 | } |
| 613 | 613 | |
| 614 | - if ( empty( $this->key ) ) { |
|
| 614 | + if (empty($this->key)) { |
|
| 615 | 615 | $this->key = $this->generate_key(); |
| 616 | 616 | $this->pending['key'] = $this->key; |
| 617 | 617 | } |
| 618 | 618 | |
| 619 | - if ( empty( $this->ip ) ) { |
|
| 619 | + if (empty($this->ip)) { |
|
| 620 | 620 | $this->ip = wpinv_get_ip(); |
| 621 | 621 | $this->pending['ip'] = $this->ip; |
| 622 | 622 | } |
@@ -653,34 +653,34 @@ discard block |
||
| 653 | 653 | 'post_status' => $this->status, |
| 654 | 654 | 'post_author' => $this->user_id, |
| 655 | 655 | 'post_type' => $this->post_type, |
| 656 | - 'post_date' => ! empty( $this->date ) && $this->date != '0000-00-00 00:00:00' ? $this->date : current_time( 'mysql' ), |
|
| 657 | - 'post_date_gmt' => ! empty( $this->date ) && $this->date != '0000-00-00 00:00:00' ? get_gmt_from_date( $this->date ) : current_time( 'mysql', 1 ), |
|
| 656 | + 'post_date' => !empty($this->date) && $this->date != '0000-00-00 00:00:00' ? $this->date : current_time('mysql'), |
|
| 657 | + 'post_date_gmt' => !empty($this->date) && $this->date != '0000-00-00 00:00:00' ? get_gmt_from_date($this->date) : current_time('mysql', 1), |
|
| 658 | 658 | 'post_parent' => $this->parent_invoice, |
| 659 | 659 | ); |
| 660 | - $args = apply_filters( 'wpinv_insert_invoice_args', $post_data, $this ); |
|
| 660 | + $args = apply_filters('wpinv_insert_invoice_args', $post_data, $this); |
|
| 661 | 661 | |
| 662 | 662 | // Create a blank invoice |
| 663 | - if ( !empty( $this->ID ) ) { |
|
| 664 | - $args['ID'] = $this->ID; |
|
| 665 | - $invoice_id = wp_update_post( $args, true ); |
|
| 663 | + if (!empty($this->ID)) { |
|
| 664 | + $args['ID'] = $this->ID; |
|
| 665 | + $invoice_id = wp_update_post($args, true); |
|
| 666 | 666 | } else { |
| 667 | - $invoice_id = wp_insert_post( $args, true ); |
|
| 667 | + $invoice_id = wp_insert_post($args, true); |
|
| 668 | 668 | } |
| 669 | 669 | |
| 670 | - if ( is_wp_error( $invoice_id ) ) { |
|
| 670 | + if (is_wp_error($invoice_id)) { |
|
| 671 | 671 | return false; |
| 672 | 672 | } |
| 673 | 673 | |
| 674 | - if ( ! empty( $invoice_id ) ) { |
|
| 674 | + if (!empty($invoice_id)) { |
|
| 675 | 675 | $this->ID = $invoice_id; |
| 676 | 676 | $this->_ID = $invoice_id; |
| 677 | 677 | |
| 678 | - $this->payment_meta = array_merge( $this->payment_meta, $payment_data ); |
|
| 678 | + $this->payment_meta = array_merge($this->payment_meta, $payment_data); |
|
| 679 | 679 | |
| 680 | - if ( ! empty( $this->payment_meta['fees'] ) ) { |
|
| 681 | - $this->fees = array_merge( $this->fees, $this->payment_meta['fees'] ); |
|
| 682 | - foreach( $this->fees as $fee ) { |
|
| 683 | - $this->increase_fees( $fee['amount'] ); |
|
| 680 | + if (!empty($this->payment_meta['fees'])) { |
|
| 681 | + $this->fees = array_merge($this->fees, $this->payment_meta['fees']); |
|
| 682 | + foreach ($this->fees as $fee) { |
|
| 683 | + $this->increase_fees($fee['amount']); |
|
| 684 | 684 | } |
| 685 | 685 | } |
| 686 | 686 | |
@@ -696,11 +696,11 @@ discard block |
||
| 696 | 696 | */ |
| 697 | 697 | public function get_special_fields() { |
| 698 | 698 | |
| 699 | - return array ( |
|
| 699 | + return array( |
|
| 700 | 700 | 'post_id' => $this->ID, |
| 701 | 701 | 'number' => $this->get_number(), |
| 702 | 702 | 'key' => $this->get_key(), |
| 703 | - 'type' => str_replace( 'wpi_', '', $this->post_type ), |
|
| 703 | + 'type' => str_replace('wpi_', '', $this->post_type), |
|
| 704 | 704 | 'mode' => $this->mode, |
| 705 | 705 | 'user_ip' => $this->get_ip(), |
| 706 | 706 | 'first_name' => $this->get_first_name(), |
@@ -740,37 +740,37 @@ discard block |
||
| 740 | 740 | $this->refresh_payment_data(); |
| 741 | 741 | |
| 742 | 742 | $fields = $this->get_special_fields(); |
| 743 | - $fields = array_map( 'maybe_serialize', $fields ); |
|
| 743 | + $fields = array_map('maybe_serialize', $fields); |
|
| 744 | 744 | |
| 745 | - $table = $wpdb->prefix . 'getpaid_invoices'; |
|
| 745 | + $table = $wpdb->prefix . 'getpaid_invoices'; |
|
| 746 | 746 | |
| 747 | 747 | $id = (int) $this->ID; |
| 748 | 748 | |
| 749 | - if ( empty( $id ) ) { |
|
| 749 | + if (empty($id)) { |
|
| 750 | 750 | return; |
| 751 | 751 | } |
| 752 | 752 | |
| 753 | - if ( $wpdb->get_var( "SELECT `post_id` FROM $table WHERE `post_id`=$id" ) ) { |
|
| 753 | + if ($wpdb->get_var("SELECT `post_id` FROM $table WHERE `post_id`=$id")) { |
|
| 754 | 754 | |
| 755 | - $wpdb->update( $table, $fields, array( 'post_id' => $id ) ); |
|
| 755 | + $wpdb->update($table, $fields, array('post_id' => $id)); |
|
| 756 | 756 | |
| 757 | 757 | } else { |
| 758 | 758 | |
| 759 | - $wpdb->insert( $table, $fields ); |
|
| 759 | + $wpdb->insert($table, $fields); |
|
| 760 | 760 | |
| 761 | 761 | } |
| 762 | 762 | |
| 763 | - $table = $wpdb->prefix . 'getpaid_invoice_items'; |
|
| 764 | - $wpdb->delete( $table, array( 'post_id' => $this->ID ) ); |
|
| 763 | + $table = $wpdb->prefix . 'getpaid_invoice_items'; |
|
| 764 | + $wpdb->delete($table, array('post_id' => $this->ID)); |
|
| 765 | 765 | |
| 766 | - foreach ( $this->get_cart_details() as $details ) { |
|
| 766 | + foreach ($this->get_cart_details() as $details) { |
|
| 767 | 767 | $fields = array( |
| 768 | 768 | 'post_id' => $this->ID, |
| 769 | 769 | 'item_id' => $details['id'], |
| 770 | 770 | 'item_name' => $details['name'], |
| 771 | - 'item_description' => empty( $details['meta']['description'] ) ? '' : $details['meta']['description'], |
|
| 771 | + 'item_description' => empty($details['meta']['description']) ? '' : $details['meta']['description'], |
|
| 772 | 772 | 'vat_rate' => $details['vat_rate'], |
| 773 | - 'vat_class' => empty( $details['vat_class'] ) ? '_standard' : $details['vat_class'], |
|
| 773 | + 'vat_class' => empty($details['vat_class']) ? '_standard' : $details['vat_class'], |
|
| 774 | 774 | 'tax' => $details['tax'], |
| 775 | 775 | 'item_price' => $details['item_price'], |
| 776 | 776 | 'custom_price' => $details['custom_price'], |
@@ -782,41 +782,41 @@ discard block |
||
| 782 | 782 | 'fees' => $details['fees'], |
| 783 | 783 | ); |
| 784 | 784 | |
| 785 | - $item_columns = array_keys ( $fields ); |
|
| 785 | + $item_columns = array_keys($fields); |
|
| 786 | 786 | |
| 787 | - foreach ( $fields as $key => $val ) { |
|
| 788 | - if ( is_null( $val ) ) { |
|
| 787 | + foreach ($fields as $key => $val) { |
|
| 788 | + if (is_null($val)) { |
|
| 789 | 789 | $val = ''; |
| 790 | 790 | } |
| 791 | - $val = maybe_serialize( $val ); |
|
| 792 | - $fields[ $key ] = $wpdb->prepare( '%s', $val ); |
|
| 791 | + $val = maybe_serialize($val); |
|
| 792 | + $fields[$key] = $wpdb->prepare('%s', $val); |
|
| 793 | 793 | } |
| 794 | 794 | |
| 795 | - $fields = implode( ', ', $fields ); |
|
| 795 | + $fields = implode(', ', $fields); |
|
| 796 | 796 | $item_rows[] = "($fields)"; |
| 797 | 797 | } |
| 798 | 798 | |
| 799 | - $item_rows = implode( ', ', $item_rows ); |
|
| 800 | - $item_columns = implode( ', ', $item_columns ); |
|
| 801 | - $wpdb->query( "INSERT INTO $table ($item_columns) VALUES $item_rows" ); |
|
| 799 | + $item_rows = implode(', ', $item_rows); |
|
| 800 | + $item_columns = implode(', ', $item_columns); |
|
| 801 | + $wpdb->query("INSERT INTO $table ($item_columns) VALUES $item_rows"); |
|
| 802 | 802 | } |
| 803 | 803 | |
| 804 | - public function save( $setup = false ) { |
|
| 804 | + public function save($setup = false) { |
|
| 805 | 805 | global $wpi_session; |
| 806 | 806 | |
| 807 | 807 | $saved = false; |
| 808 | - if ( empty( $this->items ) ) { |
|
| 808 | + if (empty($this->items)) { |
|
| 809 | 809 | return $saved; |
| 810 | 810 | } |
| 811 | 811 | |
| 812 | - if ( empty( $this->key ) ) { |
|
| 812 | + if (empty($this->key)) { |
|
| 813 | 813 | $this->key = $this->generate_key(); |
| 814 | 814 | } |
| 815 | 815 | |
| 816 | - if ( empty( $this->ID ) ) { |
|
| 816 | + if (empty($this->ID)) { |
|
| 817 | 817 | $invoice_id = $this->insert_invoice(); |
| 818 | 818 | |
| 819 | - if ( false === $invoice_id ) { |
|
| 819 | + if (false === $invoice_id) { |
|
| 820 | 820 | $saved = false; |
| 821 | 821 | } else { |
| 822 | 822 | $this->ID = $invoice_id; |
@@ -824,28 +824,28 @@ discard block |
||
| 824 | 824 | } |
| 825 | 825 | |
| 826 | 826 | // If we have something pending, let's save it |
| 827 | - if ( ! empty( $this->pending ) ) { |
|
| 827 | + if (!empty($this->pending)) { |
|
| 828 | 828 | $total_increase = 0; |
| 829 | 829 | $total_decrease = 0; |
| 830 | 830 | |
| 831 | - foreach ( $this->pending as $key => $value ) { |
|
| 831 | + foreach ($this->pending as $key => $value) { |
|
| 832 | 832 | |
| 833 | - switch( $key ) { |
|
| 833 | + switch ($key) { |
|
| 834 | 834 | case 'items': |
| 835 | 835 | // Update totals for pending items |
| 836 | - foreach ( $this->pending[ $key ] as $item ) { |
|
| 837 | - switch( $item['action'] ) { |
|
| 836 | + foreach ($this->pending[$key] as $item) { |
|
| 837 | + switch ($item['action']) { |
|
| 838 | 838 | case 'add': |
| 839 | 839 | $price = $item['price']; |
| 840 | 840 | $taxes = $item['tax']; |
| 841 | 841 | |
| 842 | - if ( 'publish' === $this->status ) { |
|
| 842 | + if ('publish' === $this->status) { |
|
| 843 | 843 | $total_increase += $price; |
| 844 | 844 | } |
| 845 | 845 | break; |
| 846 | 846 | |
| 847 | 847 | case 'remove': |
| 848 | - if ( 'publish' === $this->status ) { |
|
| 848 | + if ('publish' === $this->status) { |
|
| 849 | 849 | $total_decrease += $item['price']; |
| 850 | 850 | } |
| 851 | 851 | break; |
@@ -853,16 +853,16 @@ discard block |
||
| 853 | 853 | } |
| 854 | 854 | break; |
| 855 | 855 | case 'fees': |
| 856 | - if ( 'publish' !== $this->status ) { |
|
| 856 | + if ('publish' !== $this->status) { |
|
| 857 | 857 | break; |
| 858 | 858 | } |
| 859 | 859 | |
| 860 | - if ( empty( $this->pending[ $key ] ) ) { |
|
| 860 | + if (empty($this->pending[$key])) { |
|
| 861 | 861 | break; |
| 862 | 862 | } |
| 863 | 863 | |
| 864 | - foreach ( $this->pending[ $key ] as $fee ) { |
|
| 865 | - switch( $fee['action'] ) { |
|
| 864 | + foreach ($this->pending[$key] as $fee) { |
|
| 865 | + switch ($fee['action']) { |
|
| 866 | 866 | case 'add': |
| 867 | 867 | $total_increase += $fee['amount']; |
| 868 | 868 | break; |
@@ -874,7 +874,7 @@ discard block |
||
| 874 | 874 | } |
| 875 | 875 | break; |
| 876 | 876 | case 'status': |
| 877 | - $this->update_status( $this->status ); |
|
| 877 | + $this->update_status($this->status); |
|
| 878 | 878 | break; |
| 879 | 879 | case 'first_name': |
| 880 | 880 | $this->user_info['first_name'] = $this->first_name; |
@@ -906,12 +906,12 @@ discard block |
||
| 906 | 906 | case 'vat_number': |
| 907 | 907 | $this->user_info['vat_number'] = $this->vat_number; |
| 908 | 908 | |
| 909 | - $vat_info = $wpi_session->get( 'user_vat_data' ); |
|
| 910 | - if ( $this->vat_number && !empty( $vat_info ) && isset( $vat_info['number'] ) && isset( $vat_info['valid'] ) && $vat_info['number'] == $this->vat_number ) { |
|
| 911 | - $adddress_confirmed = isset( $vat_info['adddress_confirmed'] ) ? $vat_info['adddress_confirmed'] : false; |
|
| 912 | - $this->update_meta( '_wpinv_adddress_confirmed', (bool)$adddress_confirmed ); |
|
| 913 | - $this->user_info['adddress_confirmed'] = (bool)$adddress_confirmed; |
|
| 914 | - $this->adddress_confirmed = (bool)$adddress_confirmed; |
|
| 909 | + $vat_info = $wpi_session->get('user_vat_data'); |
|
| 910 | + if ($this->vat_number && !empty($vat_info) && isset($vat_info['number']) && isset($vat_info['valid']) && $vat_info['number'] == $this->vat_number) { |
|
| 911 | + $adddress_confirmed = isset($vat_info['adddress_confirmed']) ? $vat_info['adddress_confirmed'] : false; |
|
| 912 | + $this->update_meta('_wpinv_adddress_confirmed', (bool) $adddress_confirmed); |
|
| 913 | + $this->user_info['adddress_confirmed'] = (bool) $adddress_confirmed; |
|
| 914 | + $this->adddress_confirmed = (bool) $adddress_confirmed; |
|
| 915 | 915 | } |
| 916 | 916 | |
| 917 | 917 | break; |
@@ -928,34 +928,34 @@ discard block |
||
| 928 | 928 | 'edit_date' => true, |
| 929 | 929 | ); |
| 930 | 930 | |
| 931 | - wp_update_post( $args ); |
|
| 931 | + wp_update_post($args); |
|
| 932 | 932 | break; |
| 933 | 933 | case 'due_date': |
| 934 | - if ( empty( $this->due_date ) ) { |
|
| 934 | + if (empty($this->due_date)) { |
|
| 935 | 935 | $this->due_date = 'none'; |
| 936 | 936 | } |
| 937 | 937 | break; |
| 938 | 938 | case 'discounts': |
| 939 | - if ( ! is_array( $this->discounts ) ) { |
|
| 940 | - $this->discounts = explode( ',', $this->discounts ); |
|
| 939 | + if (!is_array($this->discounts)) { |
|
| 940 | + $this->discounts = explode(',', $this->discounts); |
|
| 941 | 941 | } |
| 942 | 942 | |
| 943 | - $this->user_info['discount'] = implode( ',', $this->discounts ); |
|
| 943 | + $this->user_info['discount'] = implode(',', $this->discounts); |
|
| 944 | 944 | break; |
| 945 | 945 | case 'parent_invoice': |
| 946 | 946 | $args = array( |
| 947 | 947 | 'ID' => $this->ID, |
| 948 | 948 | 'post_parent' => $this->parent_invoice, |
| 949 | 949 | ); |
| 950 | - wp_update_post( $args ); |
|
| 950 | + wp_update_post($args); |
|
| 951 | 951 | break; |
| 952 | 952 | default: |
| 953 | - do_action( 'wpinv_save', $this, $key ); |
|
| 953 | + do_action('wpinv_save', $this, $key); |
|
| 954 | 954 | break; |
| 955 | 955 | } |
| 956 | 956 | } |
| 957 | 957 | |
| 958 | - $this->items = array_values( $this->items ); |
|
| 958 | + $this->items = array_values($this->items); |
|
| 959 | 959 | |
| 960 | 960 | $this->pending = array(); |
| 961 | 961 | $saved = true; |
@@ -968,14 +968,14 @@ discard block |
||
| 968 | 968 | 'currency' => $this->currency, |
| 969 | 969 | 'user_info' => $this->user_info, |
| 970 | 970 | ); |
| 971 | - $this->payment_meta = array_merge( $this->payment_meta, $new_meta ); |
|
| 971 | + $this->payment_meta = array_merge($this->payment_meta, $new_meta); |
|
| 972 | 972 | $this->update_items(); |
| 973 | 973 | |
| 974 | 974 | $this->save_special(); |
| 975 | - do_action( 'wpinv_invoice_save', $this, $saved ); |
|
| 975 | + do_action('wpinv_invoice_save', $this, $saved); |
|
| 976 | 976 | |
| 977 | - if ( true === $saved || $setup ) { |
|
| 978 | - $this->setup_invoice( $this->ID ); |
|
| 977 | + if (true === $saved || $setup) { |
|
| 978 | + $this->setup_invoice($this->ID); |
|
| 979 | 979 | } |
| 980 | 980 | |
| 981 | 981 | $this->refresh_item_ids(); |
@@ -983,7 +983,7 @@ discard block |
||
| 983 | 983 | return $saved; |
| 984 | 984 | } |
| 985 | 985 | |
| 986 | - public function add_fee( $args, $global = true ) { |
|
| 986 | + public function add_fee($args, $global = true) { |
|
| 987 | 987 | $default_args = array( |
| 988 | 988 | 'label' => '', |
| 989 | 989 | 'amount' => 0, |
@@ -993,75 +993,75 @@ discard block |
||
| 993 | 993 | 'item_id' => 0, |
| 994 | 994 | ); |
| 995 | 995 | |
| 996 | - $fee = wp_parse_args( $args, $default_args ); |
|
| 996 | + $fee = wp_parse_args($args, $default_args); |
|
| 997 | 997 | |
| 998 | - if ( empty( $fee['label'] ) ) { |
|
| 998 | + if (empty($fee['label'])) { |
|
| 999 | 999 | return false; |
| 1000 | 1000 | } |
| 1001 | 1001 | |
| 1002 | - $fee['id'] = sanitize_title( $fee['label'] ); |
|
| 1002 | + $fee['id'] = sanitize_title($fee['label']); |
|
| 1003 | 1003 | |
| 1004 | - $this->fees[] = $fee; |
|
| 1004 | + $this->fees[] = $fee; |
|
| 1005 | 1005 | |
| 1006 | 1006 | $added_fee = $fee; |
| 1007 | 1007 | $added_fee['action'] = 'add'; |
| 1008 | 1008 | $this->pending['fees'][] = $added_fee; |
| 1009 | - reset( $this->fees ); |
|
| 1009 | + reset($this->fees); |
|
| 1010 | 1010 | |
| 1011 | - $this->increase_fees( $fee['amount'] ); |
|
| 1011 | + $this->increase_fees($fee['amount']); |
|
| 1012 | 1012 | return true; |
| 1013 | 1013 | } |
| 1014 | 1014 | |
| 1015 | - public function remove_fee( $key ) { |
|
| 1015 | + public function remove_fee($key) { |
|
| 1016 | 1016 | $removed = false; |
| 1017 | 1017 | |
| 1018 | - if ( is_numeric( $key ) ) { |
|
| 1019 | - $removed = $this->remove_fee_by( 'index', $key ); |
|
| 1018 | + if (is_numeric($key)) { |
|
| 1019 | + $removed = $this->remove_fee_by('index', $key); |
|
| 1020 | 1020 | } |
| 1021 | 1021 | |
| 1022 | 1022 | return $removed; |
| 1023 | 1023 | } |
| 1024 | 1024 | |
| 1025 | - public function remove_fee_by( $key, $value, $global = false ) { |
|
| 1026 | - $allowed_fee_keys = apply_filters( 'wpinv_fee_keys', array( |
|
| 1025 | + public function remove_fee_by($key, $value, $global = false) { |
|
| 1026 | + $allowed_fee_keys = apply_filters('wpinv_fee_keys', array( |
|
| 1027 | 1027 | 'index', 'label', 'amount', 'type', |
| 1028 | - ) ); |
|
| 1028 | + )); |
|
| 1029 | 1029 | |
| 1030 | - if ( ! in_array( $key, $allowed_fee_keys ) ) { |
|
| 1030 | + if (!in_array($key, $allowed_fee_keys)) { |
|
| 1031 | 1031 | return false; |
| 1032 | 1032 | } |
| 1033 | 1033 | |
| 1034 | 1034 | $removed = false; |
| 1035 | - if ( 'index' === $key && array_key_exists( $value, $this->fees ) ) { |
|
| 1036 | - $removed_fee = $this->fees[ $value ]; |
|
| 1035 | + if ('index' === $key && array_key_exists($value, $this->fees)) { |
|
| 1036 | + $removed_fee = $this->fees[$value]; |
|
| 1037 | 1037 | $removed_fee['action'] = 'remove'; |
| 1038 | 1038 | $this->pending['fees'][] = $removed_fee; |
| 1039 | 1039 | |
| 1040 | - $this->decrease_fees( $removed_fee['amount'] ); |
|
| 1040 | + $this->decrease_fees($removed_fee['amount']); |
|
| 1041 | 1041 | |
| 1042 | - unset( $this->fees[ $value ] ); |
|
| 1042 | + unset($this->fees[$value]); |
|
| 1043 | 1043 | $removed = true; |
| 1044 | - } else if ( 'index' !== $key ) { |
|
| 1045 | - foreach ( $this->fees as $index => $fee ) { |
|
| 1046 | - if ( isset( $fee[ $key ] ) && $fee[ $key ] == $value ) { |
|
| 1044 | + } else if ('index' !== $key) { |
|
| 1045 | + foreach ($this->fees as $index => $fee) { |
|
| 1046 | + if (isset($fee[$key]) && $fee[$key] == $value) { |
|
| 1047 | 1047 | $removed_fee = $fee; |
| 1048 | 1048 | $removed_fee['action'] = 'remove'; |
| 1049 | 1049 | $this->pending['fees'][] = $removed_fee; |
| 1050 | 1050 | |
| 1051 | - $this->decrease_fees( $removed_fee['amount'] ); |
|
| 1051 | + $this->decrease_fees($removed_fee['amount']); |
|
| 1052 | 1052 | |
| 1053 | - unset( $this->fees[ $index ] ); |
|
| 1053 | + unset($this->fees[$index]); |
|
| 1054 | 1054 | $removed = true; |
| 1055 | 1055 | |
| 1056 | - if ( false === $global ) { |
|
| 1056 | + if (false === $global) { |
|
| 1057 | 1057 | break; |
| 1058 | 1058 | } |
| 1059 | 1059 | } |
| 1060 | 1060 | } |
| 1061 | 1061 | } |
| 1062 | 1062 | |
| 1063 | - if ( true === $removed ) { |
|
| 1064 | - $this->fees = array_values( $this->fees ); |
|
| 1063 | + if (true === $removed) { |
|
| 1064 | + $this->fees = array_values($this->fees); |
|
| 1065 | 1065 | } |
| 1066 | 1066 | |
| 1067 | 1067 | return $removed; |
@@ -1069,35 +1069,35 @@ discard block |
||
| 1069 | 1069 | |
| 1070 | 1070 | |
| 1071 | 1071 | |
| 1072 | - public function add_note( $note = '', $customer_type = false, $added_by_user = false, $system = false ) { |
|
| 1072 | + public function add_note($note = '', $customer_type = false, $added_by_user = false, $system = false) { |
|
| 1073 | 1073 | // Bail if no note specified |
| 1074 | - if( !$note ) { |
|
| 1074 | + if (!$note) { |
|
| 1075 | 1075 | return false; |
| 1076 | 1076 | } |
| 1077 | 1077 | |
| 1078 | - if ( empty( $this->ID ) ) |
|
| 1078 | + if (empty($this->ID)) |
|
| 1079 | 1079 | return false; |
| 1080 | 1080 | |
| 1081 | - if ( ( ( is_user_logged_in() && wpinv_current_user_can_manage_invoicing() ) || $added_by_user ) && !$system ) { |
|
| 1082 | - $user = get_user_by( 'id', get_current_user_id() ); |
|
| 1081 | + if (((is_user_logged_in() && wpinv_current_user_can_manage_invoicing()) || $added_by_user) && !$system) { |
|
| 1082 | + $user = get_user_by('id', get_current_user_id()); |
|
| 1083 | 1083 | $comment_author = $user->display_name; |
| 1084 | 1084 | $comment_author_email = $user->user_email; |
| 1085 | 1085 | } else { |
| 1086 | 1086 | $comment_author = 'System'; |
| 1087 | 1087 | $comment_author_email = 'system@'; |
| 1088 | - $comment_author_email .= isset( $_SERVER['HTTP_HOST'] ) ? str_replace( 'www.', '', $_SERVER['HTTP_HOST'] ) : 'noreply.com'; |
|
| 1089 | - $comment_author_email = sanitize_email( $comment_author_email ); |
|
| 1088 | + $comment_author_email .= isset($_SERVER['HTTP_HOST']) ? str_replace('www.', '', $_SERVER['HTTP_HOST']) : 'noreply.com'; |
|
| 1089 | + $comment_author_email = sanitize_email($comment_author_email); |
|
| 1090 | 1090 | } |
| 1091 | 1091 | |
| 1092 | - do_action( 'wpinv_pre_insert_invoice_note', $this->ID, $note, $customer_type ); |
|
| 1092 | + do_action('wpinv_pre_insert_invoice_note', $this->ID, $note, $customer_type); |
|
| 1093 | 1093 | |
| 1094 | - $note_id = wp_insert_comment( wp_filter_comment( array( |
|
| 1094 | + $note_id = wp_insert_comment(wp_filter_comment(array( |
|
| 1095 | 1095 | 'comment_post_ID' => $this->ID, |
| 1096 | 1096 | 'comment_content' => $note, |
| 1097 | 1097 | 'comment_agent' => 'WPInvoicing', |
| 1098 | 1098 | 'user_id' => is_admin() ? get_current_user_id() : 0, |
| 1099 | - 'comment_date' => current_time( 'mysql' ), |
|
| 1100 | - 'comment_date_gmt' => current_time( 'mysql', 1 ), |
|
| 1099 | + 'comment_date' => current_time('mysql'), |
|
| 1100 | + 'comment_date_gmt' => current_time('mysql', 1), |
|
| 1101 | 1101 | 'comment_approved' => 1, |
| 1102 | 1102 | 'comment_parent' => 0, |
| 1103 | 1103 | 'comment_author' => $comment_author, |
@@ -1105,53 +1105,53 @@ discard block |
||
| 1105 | 1105 | 'comment_author_url' => '', |
| 1106 | 1106 | 'comment_author_email' => $comment_author_email, |
| 1107 | 1107 | 'comment_type' => 'wpinv_note' |
| 1108 | - ) ) ); |
|
| 1108 | + ))); |
|
| 1109 | 1109 | |
| 1110 | - do_action( 'wpinv_insert_payment_note', $note_id, $this->ID, $note ); |
|
| 1110 | + do_action('wpinv_insert_payment_note', $note_id, $this->ID, $note); |
|
| 1111 | 1111 | |
| 1112 | - if ( $customer_type ) { |
|
| 1113 | - add_comment_meta( $note_id, '_wpi_customer_note', 1 ); |
|
| 1112 | + if ($customer_type) { |
|
| 1113 | + add_comment_meta($note_id, '_wpi_customer_note', 1); |
|
| 1114 | 1114 | |
| 1115 | - do_action( 'wpinv_new_customer_note', array( 'invoice_id' => $this->ID, 'user_note' => $note ) ); |
|
| 1115 | + do_action('wpinv_new_customer_note', array('invoice_id' => $this->ID, 'user_note' => $note)); |
|
| 1116 | 1116 | } |
| 1117 | 1117 | |
| 1118 | 1118 | return $note_id; |
| 1119 | 1119 | } |
| 1120 | 1120 | |
| 1121 | - private function increase_subtotal( $amount = 0.00 ) { |
|
| 1121 | + private function increase_subtotal($amount = 0.00) { |
|
| 1122 | 1122 | $amount = (float) $amount; |
| 1123 | 1123 | $this->subtotal += $amount; |
| 1124 | - $this->subtotal = wpinv_round_amount( $this->subtotal ); |
|
| 1124 | + $this->subtotal = wpinv_round_amount($this->subtotal); |
|
| 1125 | 1125 | |
| 1126 | 1126 | $this->recalculate_total(); |
| 1127 | 1127 | } |
| 1128 | 1128 | |
| 1129 | - private function decrease_subtotal( $amount = 0.00 ) { |
|
| 1129 | + private function decrease_subtotal($amount = 0.00) { |
|
| 1130 | 1130 | $amount = (float) $amount; |
| 1131 | 1131 | $this->subtotal -= $amount; |
| 1132 | - $this->subtotal = wpinv_round_amount( $this->subtotal ); |
|
| 1132 | + $this->subtotal = wpinv_round_amount($this->subtotal); |
|
| 1133 | 1133 | |
| 1134 | - if ( $this->subtotal < 0 ) { |
|
| 1134 | + if ($this->subtotal < 0) { |
|
| 1135 | 1135 | $this->subtotal = 0; |
| 1136 | 1136 | } |
| 1137 | 1137 | |
| 1138 | 1138 | $this->recalculate_total(); |
| 1139 | 1139 | } |
| 1140 | 1140 | |
| 1141 | - private function increase_fees( $amount = 0.00 ) { |
|
| 1142 | - $amount = (float)$amount; |
|
| 1141 | + private function increase_fees($amount = 0.00) { |
|
| 1142 | + $amount = (float) $amount; |
|
| 1143 | 1143 | $this->fees_total += $amount; |
| 1144 | - $this->fees_total = wpinv_round_amount( $this->fees_total ); |
|
| 1144 | + $this->fees_total = wpinv_round_amount($this->fees_total); |
|
| 1145 | 1145 | |
| 1146 | 1146 | $this->recalculate_total(); |
| 1147 | 1147 | } |
| 1148 | 1148 | |
| 1149 | - private function decrease_fees( $amount = 0.00 ) { |
|
| 1149 | + private function decrease_fees($amount = 0.00) { |
|
| 1150 | 1150 | $amount = (float) $amount; |
| 1151 | 1151 | $this->fees_total -= $amount; |
| 1152 | - $this->fees_total = wpinv_round_amount( $this->fees_total ); |
|
| 1152 | + $this->fees_total = wpinv_round_amount($this->fees_total); |
|
| 1153 | 1153 | |
| 1154 | - if ( $this->fees_total < 0 ) { |
|
| 1154 | + if ($this->fees_total < 0) { |
|
| 1155 | 1155 | $this->fees_total = 0; |
| 1156 | 1156 | } |
| 1157 | 1157 | |
@@ -1162,54 +1162,54 @@ discard block |
||
| 1162 | 1162 | global $wpi_nosave; |
| 1163 | 1163 | |
| 1164 | 1164 | $this->total = $this->subtotal + $this->tax + $this->fees_total - $this->discount; |
| 1165 | - $this->total = wpinv_round_amount( $this->total ); |
|
| 1165 | + $this->total = wpinv_round_amount($this->total); |
|
| 1166 | 1166 | |
| 1167 | - do_action( 'wpinv_invoice_recalculate_total', $this, $wpi_nosave ); |
|
| 1167 | + do_action('wpinv_invoice_recalculate_total', $this, $wpi_nosave); |
|
| 1168 | 1168 | } |
| 1169 | 1169 | |
| 1170 | - public function increase_tax( $amount = 0.00 ) { |
|
| 1170 | + public function increase_tax($amount = 0.00) { |
|
| 1171 | 1171 | $amount = (float) $amount; |
| 1172 | 1172 | $this->tax += $amount; |
| 1173 | 1173 | |
| 1174 | 1174 | $this->recalculate_total(); |
| 1175 | 1175 | } |
| 1176 | 1176 | |
| 1177 | - public function decrease_tax( $amount = 0.00 ) { |
|
| 1177 | + public function decrease_tax($amount = 0.00) { |
|
| 1178 | 1178 | $amount = (float) $amount; |
| 1179 | 1179 | $this->tax -= $amount; |
| 1180 | 1180 | |
| 1181 | - if ( $this->tax < 0 ) { |
|
| 1181 | + if ($this->tax < 0) { |
|
| 1182 | 1182 | $this->tax = 0; |
| 1183 | 1183 | } |
| 1184 | 1184 | |
| 1185 | 1185 | $this->recalculate_total(); |
| 1186 | 1186 | } |
| 1187 | 1187 | |
| 1188 | - public function update_status( $new_status = false, $note = '', $manual = false ) { |
|
| 1189 | - $old_status = ! empty( $this->old_status ) ? $this->old_status : get_post_status( $this->ID ); |
|
| 1188 | + public function update_status($new_status = false, $note = '', $manual = false) { |
|
| 1189 | + $old_status = !empty($this->old_status) ? $this->old_status : get_post_status($this->ID); |
|
| 1190 | 1190 | |
| 1191 | - if ( $old_status === $new_status && in_array( $new_status, array_keys( wpinv_get_invoice_statuses( true ) ) ) ) { |
|
| 1191 | + if ($old_status === $new_status && in_array($new_status, array_keys(wpinv_get_invoice_statuses(true)))) { |
|
| 1192 | 1192 | return false; // Don't permit status changes that aren't changes |
| 1193 | 1193 | } |
| 1194 | 1194 | |
| 1195 | - $do_change = apply_filters( 'wpinv_should_update_invoice_status', true, $this->ID, $new_status, $old_status ); |
|
| 1195 | + $do_change = apply_filters('wpinv_should_update_invoice_status', true, $this->ID, $new_status, $old_status); |
|
| 1196 | 1196 | $updated = false; |
| 1197 | 1197 | |
| 1198 | - if ( $do_change ) { |
|
| 1199 | - do_action( 'wpinv_before_invoice_status_change', $this->ID, $new_status, $old_status ); |
|
| 1198 | + if ($do_change) { |
|
| 1199 | + do_action('wpinv_before_invoice_status_change', $this->ID, $new_status, $old_status); |
|
| 1200 | 1200 | |
| 1201 | 1201 | $update_post_data = array(); |
| 1202 | 1202 | $update_post_data['ID'] = $this->ID; |
| 1203 | 1203 | $update_post_data['post_status'] = $new_status; |
| 1204 | - $update_post_data['edit_date'] = current_time( 'mysql', 0 ); |
|
| 1205 | - $update_post_data['edit_date_gmt'] = current_time( 'mysql', 1 ); |
|
| 1204 | + $update_post_data['edit_date'] = current_time('mysql', 0); |
|
| 1205 | + $update_post_data['edit_date_gmt'] = current_time('mysql', 1); |
|
| 1206 | 1206 | |
| 1207 | - $update_post_data = apply_filters( 'wpinv_update_invoice_status_fields', $update_post_data, $this->ID ); |
|
| 1207 | + $update_post_data = apply_filters('wpinv_update_invoice_status_fields', $update_post_data, $this->ID); |
|
| 1208 | 1208 | |
| 1209 | - $updated = wp_update_post( $update_post_data ); |
|
| 1209 | + $updated = wp_update_post($update_post_data); |
|
| 1210 | 1210 | |
| 1211 | 1211 | // Process any specific status functions |
| 1212 | - switch( $new_status ) { |
|
| 1212 | + switch ($new_status) { |
|
| 1213 | 1213 | case 'wpi-refunded': |
| 1214 | 1214 | $this->process_refund(); |
| 1215 | 1215 | break; |
@@ -1222,9 +1222,9 @@ discard block |
||
| 1222 | 1222 | } |
| 1223 | 1223 | |
| 1224 | 1224 | // Status was changed. |
| 1225 | - do_action( 'wpinv_status_' . $new_status, $this->ID, $old_status ); |
|
| 1226 | - do_action( 'wpinv_status_' . $old_status . '_to_' . $new_status, $this->ID, $old_status ); |
|
| 1227 | - do_action( 'wpinv_update_status', $this->ID, $new_status, $old_status ); |
|
| 1225 | + do_action('wpinv_status_' . $new_status, $this->ID, $old_status); |
|
| 1226 | + do_action('wpinv_status_' . $old_status . '_to_' . $new_status, $this->ID, $old_status); |
|
| 1227 | + do_action('wpinv_update_status', $this->ID, $new_status, $old_status); |
|
| 1228 | 1228 | } |
| 1229 | 1229 | |
| 1230 | 1230 | return $updated; |
@@ -1238,68 +1238,68 @@ discard block |
||
| 1238 | 1238 | $this->save(); |
| 1239 | 1239 | } |
| 1240 | 1240 | |
| 1241 | - public function update_meta( $meta_key = '', $meta_value = '', $prev_value = '' ) { |
|
| 1242 | - if ( empty( $meta_key ) ) { |
|
| 1241 | + public function update_meta($meta_key = '', $meta_value = '', $prev_value = '') { |
|
| 1242 | + if (empty($meta_key)) { |
|
| 1243 | 1243 | return false; |
| 1244 | 1244 | } |
| 1245 | 1245 | |
| 1246 | - if ( $meta_key == 'key' || $meta_key == 'date' ) { |
|
| 1246 | + if ($meta_key == 'key' || $meta_key == 'date') { |
|
| 1247 | 1247 | $current_meta = $this->get_meta(); |
| 1248 | - $current_meta[ $meta_key ] = $meta_value; |
|
| 1248 | + $current_meta[$meta_key] = $meta_value; |
|
| 1249 | 1249 | |
| 1250 | 1250 | $meta_key = '_wpinv_payment_meta'; |
| 1251 | 1251 | $meta_value = $current_meta; |
| 1252 | 1252 | } |
| 1253 | 1253 | |
| 1254 | - $key = str_ireplace( '_wpinv_', '', $meta_key ); |
|
| 1254 | + $key = str_ireplace('_wpinv_', '', $meta_key); |
|
| 1255 | 1255 | $this->$key = $meta_value; |
| 1256 | 1256 | |
| 1257 | - $special = array_keys( $this->get_special_fields() ); |
|
| 1258 | - if ( in_array( $key, $special ) ) { |
|
| 1257 | + $special = array_keys($this->get_special_fields()); |
|
| 1258 | + if (in_array($key, $special)) { |
|
| 1259 | 1259 | $this->save_special(); |
| 1260 | 1260 | } else { |
| 1261 | - $meta_value = apply_filters( 'wpinv_update_payment_meta_' . $meta_key, $meta_value, $this->ID ); |
|
| 1261 | + $meta_value = apply_filters('wpinv_update_payment_meta_' . $meta_key, $meta_value, $this->ID); |
|
| 1262 | 1262 | } |
| 1263 | 1263 | |
| 1264 | - return update_post_meta( $this->ID, $meta_key, $meta_value, $prev_value ); |
|
| 1264 | + return update_post_meta($this->ID, $meta_key, $meta_value, $prev_value); |
|
| 1265 | 1265 | } |
| 1266 | 1266 | |
| 1267 | 1267 | private function process_refund() { |
| 1268 | 1268 | $process_refund = true; |
| 1269 | 1269 | |
| 1270 | 1270 | // If the payment was not in publish, don't decrement stats as they were never incremented |
| 1271 | - if ( 'publish' != $this->old_status || 'wpi-refunded' != $this->status ) { |
|
| 1271 | + if ('publish' != $this->old_status || 'wpi-refunded' != $this->status) { |
|
| 1272 | 1272 | $process_refund = false; |
| 1273 | 1273 | } |
| 1274 | 1274 | |
| 1275 | 1275 | // Allow extensions to filter for their own payment types, Example: Recurring Payments |
| 1276 | - $process_refund = apply_filters( 'wpinv_should_process_refund', $process_refund, $this ); |
|
| 1276 | + $process_refund = apply_filters('wpinv_should_process_refund', $process_refund, $this); |
|
| 1277 | 1277 | |
| 1278 | - if ( false === $process_refund ) { |
|
| 1278 | + if (false === $process_refund) { |
|
| 1279 | 1279 | return; |
| 1280 | 1280 | } |
| 1281 | 1281 | |
| 1282 | - do_action( 'wpinv_pre_refund_invoice', $this ); |
|
| 1282 | + do_action('wpinv_pre_refund_invoice', $this); |
|
| 1283 | 1283 | |
| 1284 | - $decrease_store_earnings = apply_filters( 'wpinv_decrease_store_earnings_on_refund', true, $this ); |
|
| 1285 | - $decrease_customer_value = apply_filters( 'wpinv_decrease_customer_value_on_refund', true, $this ); |
|
| 1286 | - $decrease_purchase_count = apply_filters( 'wpinv_decrease_customer_purchase_count_on_refund', true, $this ); |
|
| 1284 | + $decrease_store_earnings = apply_filters('wpinv_decrease_store_earnings_on_refund', true, $this); |
|
| 1285 | + $decrease_customer_value = apply_filters('wpinv_decrease_customer_value_on_refund', true, $this); |
|
| 1286 | + $decrease_purchase_count = apply_filters('wpinv_decrease_customer_purchase_count_on_refund', true, $this); |
|
| 1287 | 1287 | |
| 1288 | - do_action( 'wpinv_post_refund_invoice', $this ); |
|
| 1288 | + do_action('wpinv_post_refund_invoice', $this); |
|
| 1289 | 1289 | } |
| 1290 | 1290 | |
| 1291 | 1291 | private function process_failure() { |
| 1292 | 1292 | $discounts = $this->discounts; |
| 1293 | - if ( empty( $discounts ) ) { |
|
| 1293 | + if (empty($discounts)) { |
|
| 1294 | 1294 | return; |
| 1295 | 1295 | } |
| 1296 | 1296 | |
| 1297 | - if ( ! is_array( $discounts ) ) { |
|
| 1298 | - $discounts = array_map( 'trim', explode( ',', $discounts ) ); |
|
| 1297 | + if (!is_array($discounts)) { |
|
| 1298 | + $discounts = array_map('trim', explode(',', $discounts)); |
|
| 1299 | 1299 | } |
| 1300 | 1300 | |
| 1301 | - foreach ( $discounts as $discount ) { |
|
| 1302 | - wpinv_decrease_discount_usage( $discount ); |
|
| 1301 | + foreach ($discounts as $discount) { |
|
| 1302 | + wpinv_decrease_discount_usage($discount); |
|
| 1303 | 1303 | } |
| 1304 | 1304 | } |
| 1305 | 1305 | |
@@ -1307,95 +1307,95 @@ discard block |
||
| 1307 | 1307 | $process_pending = true; |
| 1308 | 1308 | |
| 1309 | 1309 | // If the payment was not in publish or revoked status, don't decrement stats as they were never incremented |
| 1310 | - if ( ( 'publish' != $this->old_status && 'revoked' != $this->old_status ) || 'wpi-pending' != $this->status ) { |
|
| 1310 | + if (('publish' != $this->old_status && 'revoked' != $this->old_status) || 'wpi-pending' != $this->status) { |
|
| 1311 | 1311 | $process_pending = false; |
| 1312 | 1312 | } |
| 1313 | 1313 | |
| 1314 | 1314 | // Allow extensions to filter for their own payment types, Example: Recurring Payments |
| 1315 | - $process_pending = apply_filters( 'wpinv_should_process_pending', $process_pending, $this ); |
|
| 1315 | + $process_pending = apply_filters('wpinv_should_process_pending', $process_pending, $this); |
|
| 1316 | 1316 | |
| 1317 | - if ( false === $process_pending ) { |
|
| 1317 | + if (false === $process_pending) { |
|
| 1318 | 1318 | return; |
| 1319 | 1319 | } |
| 1320 | 1320 | |
| 1321 | - $decrease_store_earnings = apply_filters( 'wpinv_decrease_store_earnings_on_pending', true, $this ); |
|
| 1322 | - $decrease_customer_value = apply_filters( 'wpinv_decrease_customer_value_on_pending', true, $this ); |
|
| 1323 | - $decrease_purchase_count = apply_filters( 'wpinv_decrease_customer_purchase_count_on_pending', true, $this ); |
|
| 1321 | + $decrease_store_earnings = apply_filters('wpinv_decrease_store_earnings_on_pending', true, $this); |
|
| 1322 | + $decrease_customer_value = apply_filters('wpinv_decrease_customer_value_on_pending', true, $this); |
|
| 1323 | + $decrease_purchase_count = apply_filters('wpinv_decrease_customer_purchase_count_on_pending', true, $this); |
|
| 1324 | 1324 | |
| 1325 | 1325 | $this->completed_date = ''; |
| 1326 | - $this->update_meta( '_wpinv_completed_date', '' ); |
|
| 1326 | + $this->update_meta('_wpinv_completed_date', ''); |
|
| 1327 | 1327 | } |
| 1328 | 1328 | |
| 1329 | 1329 | // get data |
| 1330 | - public function get_meta( $meta_key = '_wpinv_payment_meta', $single = true ) { |
|
| 1331 | - $meta = get_post_meta( $this->ID, $meta_key, $single ); |
|
| 1330 | + public function get_meta($meta_key = '_wpinv_payment_meta', $single = true) { |
|
| 1331 | + $meta = get_post_meta($this->ID, $meta_key, $single); |
|
| 1332 | 1332 | |
| 1333 | - if ( $meta_key === '_wpinv_payment_meta' ) { |
|
| 1333 | + if ($meta_key === '_wpinv_payment_meta') { |
|
| 1334 | 1334 | |
| 1335 | - if(!is_array($meta)){$meta = array();} // we need this to be an array so make sure it is. |
|
| 1335 | + if (!is_array($meta)) {$meta = array(); } // we need this to be an array so make sure it is. |
|
| 1336 | 1336 | |
| 1337 | - if ( empty( $meta['key'] ) ) { |
|
| 1337 | + if (empty($meta['key'])) { |
|
| 1338 | 1338 | $meta['key'] = $this->key; |
| 1339 | 1339 | } |
| 1340 | 1340 | |
| 1341 | - if ( empty( $meta['date'] ) ) { |
|
| 1342 | - $meta['date'] = get_post_field( 'post_date', $this->ID ); |
|
| 1341 | + if (empty($meta['date'])) { |
|
| 1342 | + $meta['date'] = get_post_field('post_date', $this->ID); |
|
| 1343 | 1343 | } |
| 1344 | 1344 | } |
| 1345 | 1345 | |
| 1346 | - $meta = apply_filters( 'wpinv_get_invoice_meta_' . $meta_key, $meta, $this->ID ); |
|
| 1346 | + $meta = apply_filters('wpinv_get_invoice_meta_' . $meta_key, $meta, $this->ID); |
|
| 1347 | 1347 | |
| 1348 | - return apply_filters( 'wpinv_get_invoice_meta', $meta, $this->ID, $meta_key ); |
|
| 1348 | + return apply_filters('wpinv_get_invoice_meta', $meta, $this->ID, $meta_key); |
|
| 1349 | 1349 | } |
| 1350 | 1350 | |
| 1351 | 1351 | public function get_description() { |
| 1352 | - $post = get_post( $this->ID ); |
|
| 1352 | + $post = get_post($this->ID); |
|
| 1353 | 1353 | |
| 1354 | - $description = !empty( $post ) ? $post->post_content : ''; |
|
| 1355 | - return apply_filters( 'wpinv_get_description', $description, $this->ID, $this ); |
|
| 1354 | + $description = !empty($post) ? $post->post_content : ''; |
|
| 1355 | + return apply_filters('wpinv_get_description', $description, $this->ID, $this); |
|
| 1356 | 1356 | } |
| 1357 | 1357 | |
| 1358 | - public function get_status( $nicename = false ) { |
|
| 1359 | - if ( !$nicename ) { |
|
| 1358 | + public function get_status($nicename = false) { |
|
| 1359 | + if (!$nicename) { |
|
| 1360 | 1360 | $status = $this->status; |
| 1361 | 1361 | } else { |
| 1362 | 1362 | $status = $this->status_nicename; |
| 1363 | 1363 | } |
| 1364 | 1364 | |
| 1365 | - return apply_filters( 'wpinv_get_status', $status, $nicename, $this->ID, $this ); |
|
| 1365 | + return apply_filters('wpinv_get_status', $status, $nicename, $this->ID, $this); |
|
| 1366 | 1366 | } |
| 1367 | 1367 | |
| 1368 | 1368 | public function get_cart_details() { |
| 1369 | - return apply_filters( 'wpinv_cart_details', $this->cart_details, $this->ID, $this ); |
|
| 1369 | + return apply_filters('wpinv_cart_details', $this->cart_details, $this->ID, $this); |
|
| 1370 | 1370 | } |
| 1371 | 1371 | |
| 1372 | - public function get_subtotal( $currency = false ) { |
|
| 1373 | - $subtotal = wpinv_round_amount( $this->subtotal ); |
|
| 1372 | + public function get_subtotal($currency = false) { |
|
| 1373 | + $subtotal = wpinv_round_amount($this->subtotal); |
|
| 1374 | 1374 | |
| 1375 | - if ( $currency ) { |
|
| 1376 | - $subtotal = wpinv_price( wpinv_format_amount( $subtotal, NULL, !$currency ), $this->get_currency() ); |
|
| 1375 | + if ($currency) { |
|
| 1376 | + $subtotal = wpinv_price(wpinv_format_amount($subtotal, NULL, !$currency), $this->get_currency()); |
|
| 1377 | 1377 | } |
| 1378 | 1378 | |
| 1379 | - return apply_filters( 'wpinv_get_invoice_subtotal', $subtotal, $this->ID, $this, $currency ); |
|
| 1379 | + return apply_filters('wpinv_get_invoice_subtotal', $subtotal, $this->ID, $this, $currency); |
|
| 1380 | 1380 | } |
| 1381 | 1381 | |
| 1382 | - public function get_total( $currency = false ) { |
|
| 1383 | - if ( $this->is_free_trial() ) { |
|
| 1384 | - $total = wpinv_round_amount( 0 ); |
|
| 1382 | + public function get_total($currency = false) { |
|
| 1383 | + if ($this->is_free_trial()) { |
|
| 1384 | + $total = wpinv_round_amount(0); |
|
| 1385 | 1385 | } else { |
| 1386 | - $total = wpinv_round_amount( $this->total ); |
|
| 1386 | + $total = wpinv_round_amount($this->total); |
|
| 1387 | 1387 | } |
| 1388 | - if ( $currency ) { |
|
| 1389 | - $total = wpinv_price( wpinv_format_amount( $total, NULL, !$currency ), $this->get_currency() ); |
|
| 1388 | + if ($currency) { |
|
| 1389 | + $total = wpinv_price(wpinv_format_amount($total, NULL, !$currency), $this->get_currency()); |
|
| 1390 | 1390 | } |
| 1391 | 1391 | |
| 1392 | - return apply_filters( 'wpinv_get_invoice_total', $total, $this->ID, $this, $currency ); |
|
| 1392 | + return apply_filters('wpinv_get_invoice_total', $total, $this->ID, $this, $currency); |
|
| 1393 | 1393 | } |
| 1394 | 1394 | |
| 1395 | 1395 | /** |
| 1396 | 1396 | * Returns recurring payment details. |
| 1397 | 1397 | */ |
| 1398 | - public function get_recurring_details( $field = '', $currency = false ) { |
|
| 1398 | + public function get_recurring_details($field = '', $currency = false) { |
|
| 1399 | 1399 | $data = array(); |
| 1400 | 1400 | $data['cart_details'] = $this->cart_details; |
| 1401 | 1401 | $data['subtotal'] = $this->get_subtotal(); |
@@ -1403,85 +1403,85 @@ discard block |
||
| 1403 | 1403 | $data['tax'] = $this->get_tax(); |
| 1404 | 1404 | $data['total'] = $this->get_total(); |
| 1405 | 1405 | |
| 1406 | - if ( $this->is_parent() || $this->is_renewal() ) { |
|
| 1406 | + if ($this->is_parent() || $this->is_renewal()) { |
|
| 1407 | 1407 | |
| 1408 | 1408 | // Use the parent to calculate recurring details. |
| 1409 | - if ( $this->is_renewal() ){ |
|
| 1409 | + if ($this->is_renewal()) { |
|
| 1410 | 1410 | $parent = $this->get_parent_payment(); |
| 1411 | 1411 | } else { |
| 1412 | 1412 | $parent = $this; |
| 1413 | 1413 | } |
| 1414 | 1414 | |
| 1415 | - if ( empty( $parent ) ) { |
|
| 1415 | + if (empty($parent)) { |
|
| 1416 | 1416 | $parent = $this; |
| 1417 | 1417 | } |
| 1418 | 1418 | |
| 1419 | 1419 | // Subtotal. |
| 1420 | - $data['subtotal'] = wpinv_round_amount( $parent->subtotal ); |
|
| 1421 | - $data['tax'] = wpinv_round_amount( $parent->tax ); |
|
| 1422 | - $data['discount'] = wpinv_round_amount( $parent->discount ); |
|
| 1420 | + $data['subtotal'] = wpinv_round_amount($parent->subtotal); |
|
| 1421 | + $data['tax'] = wpinv_round_amount($parent->tax); |
|
| 1422 | + $data['discount'] = wpinv_round_amount($parent->discount); |
|
| 1423 | 1423 | |
| 1424 | - if ( $data['discount'] > 0 && $parent->discount_first_payment_only() ) { |
|
| 1425 | - $data['discount'] = wpinv_round_amount( 0 ); |
|
| 1424 | + if ($data['discount'] > 0 && $parent->discount_first_payment_only()) { |
|
| 1425 | + $data['discount'] = wpinv_round_amount(0); |
|
| 1426 | 1426 | } |
| 1427 | 1427 | |
| 1428 | - $data['total'] = wpinv_round_amount( $data['subtotal'] + $data['tax'] - $data['discount'] ); |
|
| 1428 | + $data['total'] = wpinv_round_amount($data['subtotal'] + $data['tax'] - $data['discount']); |
|
| 1429 | 1429 | |
| 1430 | 1430 | } |
| 1431 | 1431 | |
| 1432 | - $data = apply_filters( 'wpinv_get_invoice_recurring_details', $data, $this, $field, $currency ); |
|
| 1432 | + $data = apply_filters('wpinv_get_invoice_recurring_details', $data, $this, $field, $currency); |
|
| 1433 | 1433 | |
| 1434 | - if ( $data['total'] < 0 ) { |
|
| 1434 | + if ($data['total'] < 0) { |
|
| 1435 | 1435 | $data['total'] = 0; |
| 1436 | 1436 | } |
| 1437 | 1437 | |
| 1438 | - if ( isset( $data[$field] ) ) { |
|
| 1439 | - return ( $currency ? wpinv_price( $data[$field], $this->get_currency() ) : $data[$field] ); |
|
| 1438 | + if (isset($data[$field])) { |
|
| 1439 | + return ($currency ? wpinv_price($data[$field], $this->get_currency()) : $data[$field]); |
|
| 1440 | 1440 | } |
| 1441 | 1441 | |
| 1442 | 1442 | return $data; |
| 1443 | 1443 | } |
| 1444 | 1444 | |
| 1445 | - public function get_final_tax( $currency = false ) { |
|
| 1446 | - $final_total = wpinv_round_amount( $this->tax ); |
|
| 1447 | - if ( $currency ) { |
|
| 1448 | - $final_total = wpinv_price( wpinv_format_amount( $final_total, NULL, !$currency ), $this->get_currency() ); |
|
| 1445 | + public function get_final_tax($currency = false) { |
|
| 1446 | + $final_total = wpinv_round_amount($this->tax); |
|
| 1447 | + if ($currency) { |
|
| 1448 | + $final_total = wpinv_price(wpinv_format_amount($final_total, NULL, !$currency), $this->get_currency()); |
|
| 1449 | 1449 | } |
| 1450 | 1450 | |
| 1451 | - return apply_filters( 'wpinv_get_invoice_final_total', $final_total, $this, $currency ); |
|
| 1451 | + return apply_filters('wpinv_get_invoice_final_total', $final_total, $this, $currency); |
|
| 1452 | 1452 | } |
| 1453 | 1453 | |
| 1454 | - public function get_discounts( $array = false ) { |
|
| 1454 | + public function get_discounts($array = false) { |
|
| 1455 | 1455 | $discounts = $this->discounts; |
| 1456 | - if ( $array && $discounts ) { |
|
| 1457 | - $discounts = explode( ',', $discounts ); |
|
| 1456 | + if ($array && $discounts) { |
|
| 1457 | + $discounts = explode(',', $discounts); |
|
| 1458 | 1458 | } |
| 1459 | - return apply_filters( 'wpinv_payment_discounts', $discounts, $this->ID, $this, $array ); |
|
| 1459 | + return apply_filters('wpinv_payment_discounts', $discounts, $this->ID, $this, $array); |
|
| 1460 | 1460 | } |
| 1461 | 1461 | |
| 1462 | - public function get_discount( $currency = false, $dash = false ) { |
|
| 1463 | - if ( !empty( $this->discounts ) ) { |
|
| 1462 | + public function get_discount($currency = false, $dash = false) { |
|
| 1463 | + if (!empty($this->discounts)) { |
|
| 1464 | 1464 | global $ajax_cart_details; |
| 1465 | 1465 | $ajax_cart_details = $this->get_cart_details(); |
| 1466 | 1466 | |
| 1467 | - if ( !empty( $ajax_cart_details ) && count( $ajax_cart_details ) == count( $this->items ) ) { |
|
| 1467 | + if (!empty($ajax_cart_details) && count($ajax_cart_details) == count($this->items)) { |
|
| 1468 | 1468 | $cart_items = $ajax_cart_details; |
| 1469 | 1469 | } else { |
| 1470 | 1470 | $cart_items = $this->items; |
| 1471 | 1471 | } |
| 1472 | 1472 | |
| 1473 | - $this->discount = wpinv_get_cart_items_discount_amount( $cart_items , $this->discounts ); |
|
| 1473 | + $this->discount = wpinv_get_cart_items_discount_amount($cart_items, $this->discounts); |
|
| 1474 | 1474 | } |
| 1475 | - $discount = wpinv_round_amount( $this->discount ); |
|
| 1475 | + $discount = wpinv_round_amount($this->discount); |
|
| 1476 | 1476 | $dash = $dash && $discount > 0 ? '–' : ''; |
| 1477 | 1477 | |
| 1478 | - if ( $currency ) { |
|
| 1479 | - $discount = wpinv_price( wpinv_format_amount( $discount, NULL, !$currency ), $this->get_currency() ); |
|
| 1478 | + if ($currency) { |
|
| 1479 | + $discount = wpinv_price(wpinv_format_amount($discount, NULL, !$currency), $this->get_currency()); |
|
| 1480 | 1480 | } |
| 1481 | 1481 | |
| 1482 | - $discount = $dash . $discount; |
|
| 1482 | + $discount = $dash . $discount; |
|
| 1483 | 1483 | |
| 1484 | - return apply_filters( 'wpinv_get_invoice_discount', $discount, $this->ID, $this, $currency, $dash ); |
|
| 1484 | + return apply_filters('wpinv_get_invoice_discount', $discount, $this->ID, $this, $currency, $dash); |
|
| 1485 | 1485 | } |
| 1486 | 1486 | |
| 1487 | 1487 | public function get_discount_code() { |
@@ -1493,163 +1493,163 @@ discard block |
||
| 1493 | 1493 | return (int) $this->disable_taxes === 0; |
| 1494 | 1494 | } |
| 1495 | 1495 | |
| 1496 | - public function get_tax( $currency = false ) { |
|
| 1497 | - $tax = wpinv_round_amount( $this->tax ); |
|
| 1496 | + public function get_tax($currency = false) { |
|
| 1497 | + $tax = wpinv_round_amount($this->tax); |
|
| 1498 | 1498 | |
| 1499 | - if ( $currency ) { |
|
| 1500 | - $tax = wpinv_price( wpinv_format_amount( $tax, NULL, !$currency ), $this->get_currency() ); |
|
| 1499 | + if ($currency) { |
|
| 1500 | + $tax = wpinv_price(wpinv_format_amount($tax, NULL, !$currency), $this->get_currency()); |
|
| 1501 | 1501 | } |
| 1502 | 1502 | |
| 1503 | - if ( ! $this->is_taxable() ) { |
|
| 1504 | - $tax = wpinv_round_amount( 0.00 ); |
|
| 1503 | + if (!$this->is_taxable()) { |
|
| 1504 | + $tax = wpinv_round_amount(0.00); |
|
| 1505 | 1505 | } |
| 1506 | 1506 | |
| 1507 | - return apply_filters( 'wpinv_get_invoice_tax', $tax, $this->ID, $this, $currency ); |
|
| 1507 | + return apply_filters('wpinv_get_invoice_tax', $tax, $this->ID, $this, $currency); |
|
| 1508 | 1508 | } |
| 1509 | 1509 | |
| 1510 | - public function get_fees( $type = 'all' ) { |
|
| 1511 | - $fees = array(); |
|
| 1510 | + public function get_fees($type = 'all') { |
|
| 1511 | + $fees = array(); |
|
| 1512 | 1512 | |
| 1513 | - if ( ! empty( $this->fees ) && is_array( $this->fees ) ) { |
|
| 1514 | - foreach ( $this->fees as $fee ) { |
|
| 1515 | - if( 'all' != $type && ! empty( $fee['type'] ) && $type != $fee['type'] ) { |
|
| 1513 | + if (!empty($this->fees) && is_array($this->fees)) { |
|
| 1514 | + foreach ($this->fees as $fee) { |
|
| 1515 | + if ('all' != $type && !empty($fee['type']) && $type != $fee['type']) { |
|
| 1516 | 1516 | continue; |
| 1517 | 1517 | } |
| 1518 | 1518 | |
| 1519 | - $fee['label'] = stripslashes( $fee['label'] ); |
|
| 1520 | - $fee['amount_display'] = wpinv_price( $fee['amount'], $this->get_currency() ); |
|
| 1521 | - $fees[] = $fee; |
|
| 1519 | + $fee['label'] = stripslashes($fee['label']); |
|
| 1520 | + $fee['amount_display'] = wpinv_price($fee['amount'], $this->get_currency()); |
|
| 1521 | + $fees[] = $fee; |
|
| 1522 | 1522 | } |
| 1523 | 1523 | } |
| 1524 | 1524 | |
| 1525 | - return apply_filters( 'wpinv_get_invoice_fees', $fees, $this->ID, $this ); |
|
| 1525 | + return apply_filters('wpinv_get_invoice_fees', $fees, $this->ID, $this); |
|
| 1526 | 1526 | } |
| 1527 | 1527 | |
| 1528 | - public function get_fees_total( $type = 'all' ) { |
|
| 1528 | + public function get_fees_total($type = 'all') { |
|
| 1529 | 1529 | $fees_total = (float) 0.00; |
| 1530 | 1530 | |
| 1531 | - $payment_fees = isset( $this->payment_meta['fees'] ) ? $this->payment_meta['fees'] : array(); |
|
| 1532 | - if ( ! empty( $payment_fees ) ) { |
|
| 1533 | - foreach ( $payment_fees as $fee ) { |
|
| 1531 | + $payment_fees = isset($this->payment_meta['fees']) ? $this->payment_meta['fees'] : array(); |
|
| 1532 | + if (!empty($payment_fees)) { |
|
| 1533 | + foreach ($payment_fees as $fee) { |
|
| 1534 | 1534 | $fees_total += (float) $fee['amount']; |
| 1535 | 1535 | } |
| 1536 | 1536 | } |
| 1537 | 1537 | |
| 1538 | - return apply_filters( 'wpinv_get_invoice_fees_total', $fees_total, $this->ID, $this ); |
|
| 1538 | + return apply_filters('wpinv_get_invoice_fees_total', $fees_total, $this->ID, $this); |
|
| 1539 | 1539 | |
| 1540 | 1540 | } |
| 1541 | 1541 | |
| 1542 | 1542 | public function get_user_id() { |
| 1543 | - return apply_filters( 'wpinv_user_id', $this->user_id, $this->ID, $this ); |
|
| 1543 | + return apply_filters('wpinv_user_id', $this->user_id, $this->ID, $this); |
|
| 1544 | 1544 | } |
| 1545 | 1545 | |
| 1546 | 1546 | public function get_first_name() { |
| 1547 | - return apply_filters( 'wpinv_first_name', $this->first_name, $this->ID, $this ); |
|
| 1547 | + return apply_filters('wpinv_first_name', $this->first_name, $this->ID, $this); |
|
| 1548 | 1548 | } |
| 1549 | 1549 | |
| 1550 | 1550 | public function get_last_name() { |
| 1551 | - return apply_filters( 'wpinv_last_name', $this->last_name, $this->ID, $this ); |
|
| 1551 | + return apply_filters('wpinv_last_name', $this->last_name, $this->ID, $this); |
|
| 1552 | 1552 | } |
| 1553 | 1553 | |
| 1554 | 1554 | public function get_user_full_name() { |
| 1555 | - return apply_filters( 'wpinv_user_full_name', $this->full_name, $this->ID, $this ); |
|
| 1555 | + return apply_filters('wpinv_user_full_name', $this->full_name, $this->ID, $this); |
|
| 1556 | 1556 | } |
| 1557 | 1557 | |
| 1558 | 1558 | public function get_user_info() { |
| 1559 | - return apply_filters( 'wpinv_user_info', $this->user_info, $this->ID, $this ); |
|
| 1559 | + return apply_filters('wpinv_user_info', $this->user_info, $this->ID, $this); |
|
| 1560 | 1560 | } |
| 1561 | 1561 | |
| 1562 | 1562 | public function get_email() { |
| 1563 | - return apply_filters( 'wpinv_user_email', $this->email, $this->ID, $this ); |
|
| 1563 | + return apply_filters('wpinv_user_email', $this->email, $this->ID, $this); |
|
| 1564 | 1564 | } |
| 1565 | 1565 | |
| 1566 | 1566 | public function get_address() { |
| 1567 | - return apply_filters( 'wpinv_address', $this->address, $this->ID, $this ); |
|
| 1567 | + return apply_filters('wpinv_address', $this->address, $this->ID, $this); |
|
| 1568 | 1568 | } |
| 1569 | 1569 | |
| 1570 | 1570 | public function get_phone() { |
| 1571 | - return apply_filters( 'wpinv_phone', $this->phone, $this->ID, $this ); |
|
| 1571 | + return apply_filters('wpinv_phone', $this->phone, $this->ID, $this); |
|
| 1572 | 1572 | } |
| 1573 | 1573 | |
| 1574 | 1574 | public function get_number() { |
| 1575 | - return apply_filters( 'wpinv_number', $this->number, $this->ID, $this ); |
|
| 1575 | + return apply_filters('wpinv_number', $this->number, $this->ID, $this); |
|
| 1576 | 1576 | } |
| 1577 | 1577 | |
| 1578 | 1578 | public function get_items() { |
| 1579 | - return apply_filters( 'wpinv_payment_meta_items', $this->items, $this->ID, $this ); |
|
| 1579 | + return apply_filters('wpinv_payment_meta_items', $this->items, $this->ID, $this); |
|
| 1580 | 1580 | } |
| 1581 | 1581 | |
| 1582 | 1582 | public function get_key() { |
| 1583 | - return apply_filters( 'wpinv_key', $this->key, $this->ID, $this ); |
|
| 1583 | + return apply_filters('wpinv_key', $this->key, $this->ID, $this); |
|
| 1584 | 1584 | } |
| 1585 | 1585 | |
| 1586 | 1586 | public function get_transaction_id() { |
| 1587 | - return apply_filters( 'wpinv_get_invoice_transaction_id', $this->transaction_id, $this->ID, $this ); |
|
| 1587 | + return apply_filters('wpinv_get_invoice_transaction_id', $this->transaction_id, $this->ID, $this); |
|
| 1588 | 1588 | } |
| 1589 | 1589 | |
| 1590 | 1590 | public function get_gateway() { |
| 1591 | - return apply_filters( 'wpinv_gateway', $this->gateway, $this->ID, $this ); |
|
| 1591 | + return apply_filters('wpinv_gateway', $this->gateway, $this->ID, $this); |
|
| 1592 | 1592 | } |
| 1593 | 1593 | |
| 1594 | 1594 | public function get_gateway_title() { |
| 1595 | - $this->gateway_title = !empty( $this->gateway_title ) ? $this->gateway_title : wpinv_get_gateway_checkout_label( $this->gateway ); |
|
| 1595 | + $this->gateway_title = !empty($this->gateway_title) ? $this->gateway_title : wpinv_get_gateway_checkout_label($this->gateway); |
|
| 1596 | 1596 | |
| 1597 | - return apply_filters( 'wpinv_gateway_title', $this->gateway_title, $this->ID, $this ); |
|
| 1597 | + return apply_filters('wpinv_gateway_title', $this->gateway_title, $this->ID, $this); |
|
| 1598 | 1598 | } |
| 1599 | 1599 | |
| 1600 | 1600 | public function get_currency() { |
| 1601 | - return apply_filters( 'wpinv_currency_code', $this->currency, $this->ID, $this ); |
|
| 1601 | + return apply_filters('wpinv_currency_code', $this->currency, $this->ID, $this); |
|
| 1602 | 1602 | } |
| 1603 | 1603 | |
| 1604 | 1604 | public function get_created_date() { |
| 1605 | - return apply_filters( 'wpinv_created_date', $this->date, $this->ID, $this ); |
|
| 1605 | + return apply_filters('wpinv_created_date', $this->date, $this->ID, $this); |
|
| 1606 | 1606 | } |
| 1607 | 1607 | |
| 1608 | - public function get_due_date( $display = false ) { |
|
| 1609 | - $due_date = apply_filters( 'wpinv_due_date', $this->due_date, $this->ID, $this ); |
|
| 1608 | + public function get_due_date($display = false) { |
|
| 1609 | + $due_date = apply_filters('wpinv_due_date', $this->due_date, $this->ID, $this); |
|
| 1610 | 1610 | |
| 1611 | - if ( !$display || empty( $due_date ) ) { |
|
| 1611 | + if (!$display || empty($due_date)) { |
|
| 1612 | 1612 | return $due_date; |
| 1613 | 1613 | } |
| 1614 | 1614 | |
| 1615 | - return date_i18n( get_option( 'date_format' ), strtotime( $due_date ) ); |
|
| 1615 | + return date_i18n(get_option('date_format'), strtotime($due_date)); |
|
| 1616 | 1616 | } |
| 1617 | 1617 | |
| 1618 | 1618 | public function get_completed_date() { |
| 1619 | - return apply_filters( 'wpinv_completed_date', $this->completed_date, $this->ID, $this ); |
|
| 1619 | + return apply_filters('wpinv_completed_date', $this->completed_date, $this->ID, $this); |
|
| 1620 | 1620 | } |
| 1621 | 1621 | |
| 1622 | - public function get_invoice_date( $formatted = true ) { |
|
| 1622 | + public function get_invoice_date($formatted = true) { |
|
| 1623 | 1623 | $date_completed = $this->completed_date; |
| 1624 | 1624 | $invoice_date = $date_completed != '' && $date_completed != '0000-00-00 00:00:00' ? $date_completed : ''; |
| 1625 | 1625 | |
| 1626 | - if ( $invoice_date == '' ) { |
|
| 1626 | + if ($invoice_date == '') { |
|
| 1627 | 1627 | $date_created = $this->date; |
| 1628 | 1628 | $invoice_date = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? $date_created : ''; |
| 1629 | 1629 | } |
| 1630 | 1630 | |
| 1631 | - if ( $formatted && $invoice_date ) { |
|
| 1632 | - $invoice_date = date_i18n( get_option( 'date_format' ), strtotime( $invoice_date ) ); |
|
| 1631 | + if ($formatted && $invoice_date) { |
|
| 1632 | + $invoice_date = date_i18n(get_option('date_format'), strtotime($invoice_date)); |
|
| 1633 | 1633 | } |
| 1634 | 1634 | |
| 1635 | - return apply_filters( 'wpinv_get_invoice_date', $invoice_date, $formatted, $this->ID, $this ); |
|
| 1635 | + return apply_filters('wpinv_get_invoice_date', $invoice_date, $formatted, $this->ID, $this); |
|
| 1636 | 1636 | } |
| 1637 | 1637 | |
| 1638 | 1638 | public function get_ip() { |
| 1639 | - return apply_filters( 'wpinv_user_ip', $this->ip, $this->ID, $this ); |
|
| 1639 | + return apply_filters('wpinv_user_ip', $this->ip, $this->ID, $this); |
|
| 1640 | 1640 | } |
| 1641 | 1641 | |
| 1642 | - public function has_status( $status ) { |
|
| 1643 | - return apply_filters( 'wpinv_has_status', ( is_array( $status ) && in_array( $this->get_status(), $status ) ) || $this->get_status() === $status ? true : false, $this, $status ); |
|
| 1642 | + public function has_status($status) { |
|
| 1643 | + return apply_filters('wpinv_has_status', (is_array($status) && in_array($this->get_status(), $status)) || $this->get_status() === $status ? true : false, $this, $status); |
|
| 1644 | 1644 | } |
| 1645 | 1645 | |
| 1646 | - public function add_item( $item_id = 0, $args = array() ) { |
|
| 1646 | + public function add_item($item_id = 0, $args = array()) { |
|
| 1647 | 1647 | global $wpi_current_id, $wpi_item_id; |
| 1648 | 1648 | |
| 1649 | - $item = new WPInv_Item( $item_id ); |
|
| 1649 | + $item = new WPInv_Item($item_id); |
|
| 1650 | 1650 | |
| 1651 | 1651 | // Bail if this post isn't a item |
| 1652 | - if( !$item || $item->post_type !== 'wpi_item' ) { |
|
| 1652 | + if (!$item || $item->post_type !== 'wpi_item') { |
|
| 1653 | 1653 | return false; |
| 1654 | 1654 | } |
| 1655 | 1655 | |
@@ -1668,8 +1668,8 @@ discard block |
||
| 1668 | 1668 | 'fees' => array() |
| 1669 | 1669 | ); |
| 1670 | 1670 | |
| 1671 | - $args = wp_parse_args( apply_filters( 'wpinv_add_item_args', $args, $item->ID ), $defaults ); |
|
| 1672 | - $args['quantity'] = $has_quantities && $args['quantity'] > 0 ? absint( $args['quantity'] ) : 1; |
|
| 1671 | + $args = wp_parse_args(apply_filters('wpinv_add_item_args', $args, $item->ID), $defaults); |
|
| 1672 | + $args['quantity'] = $has_quantities && $args['quantity'] > 0 ? absint($args['quantity']) : 1; |
|
| 1673 | 1673 | |
| 1674 | 1674 | $wpi_current_id = $this->ID; |
| 1675 | 1675 | $wpi_item_id = $item->ID; |
@@ -1681,19 +1681,19 @@ discard block |
||
| 1681 | 1681 | $found_cart_key = false; |
| 1682 | 1682 | |
| 1683 | 1683 | if ($has_quantities) { |
| 1684 | - $this->cart_details = !empty( $this->cart_details ) ? array_values( $this->cart_details ) : $this->cart_details; |
|
| 1684 | + $this->cart_details = !empty($this->cart_details) ? array_values($this->cart_details) : $this->cart_details; |
|
| 1685 | 1685 | |
| 1686 | - foreach ( $this->items as $key => $cart_item ) { |
|
| 1687 | - if ( (int)$item_id !== (int)$cart_item['id'] ) { |
|
| 1686 | + foreach ($this->items as $key => $cart_item) { |
|
| 1687 | + if ((int) $item_id !== (int) $cart_item['id']) { |
|
| 1688 | 1688 | continue; |
| 1689 | 1689 | } |
| 1690 | 1690 | |
| 1691 | - $this->items[ $key ]['quantity'] += $args['quantity']; |
|
| 1691 | + $this->items[$key]['quantity'] += $args['quantity']; |
|
| 1692 | 1692 | break; |
| 1693 | 1693 | } |
| 1694 | 1694 | |
| 1695 | - foreach ( $this->cart_details as $cart_key => $cart_item ) { |
|
| 1696 | - if ( $item_id != $cart_item['id'] ) { |
|
| 1695 | + foreach ($this->cart_details as $cart_key => $cart_item) { |
|
| 1696 | + if ($item_id != $cart_item['id']) { |
|
| 1697 | 1697 | continue; |
| 1698 | 1698 | } |
| 1699 | 1699 | |
@@ -1705,29 +1705,29 @@ discard block |
||
| 1705 | 1705 | if ($has_quantities && $found_cart_key !== false) { |
| 1706 | 1706 | $cart_item = $this->cart_details[$found_cart_key]; |
| 1707 | 1707 | $item_price = $cart_item['item_price']; |
| 1708 | - $quantity = !empty( $cart_item['quantity'] ) ? $cart_item['quantity'] : 1; |
|
| 1709 | - $tax_rate = !empty( $cart_item['vat_rate'] ) ? $cart_item['vat_rate'] : 0; |
|
| 1708 | + $quantity = !empty($cart_item['quantity']) ? $cart_item['quantity'] : 1; |
|
| 1709 | + $tax_rate = !empty($cart_item['vat_rate']) ? $cart_item['vat_rate'] : 0; |
|
| 1710 | 1710 | |
| 1711 | 1711 | $new_quantity = $quantity + $args['quantity']; |
| 1712 | 1712 | $subtotal = $item_price * $new_quantity; |
| 1713 | 1713 | |
| 1714 | 1714 | $args['quantity'] = $new_quantity; |
| 1715 | - $discount = !empty( $args['discount'] ) ? $args['discount'] : 0; |
|
| 1716 | - $tax = $subtotal > 0 && $tax_rate > 0 ? ( ( $subtotal - $discount ) * 0.01 * (float)$tax_rate ) : 0; |
|
| 1715 | + $discount = !empty($args['discount']) ? $args['discount'] : 0; |
|
| 1716 | + $tax = $subtotal > 0 && $tax_rate > 0 ? (($subtotal - $discount) * 0.01 * (float) $tax_rate) : 0; |
|
| 1717 | 1717 | |
| 1718 | - $discount_increased = $discount > 0 && $subtotal > 0 && $discount > (float)$cart_item['discount'] ? $discount - (float)$cart_item['discount'] : 0; |
|
| 1719 | - $tax_increased = $tax > 0 && $subtotal > 0 && $tax > (float)$cart_item['tax'] ? $tax - (float)$cart_item['tax'] : 0; |
|
| 1718 | + $discount_increased = $discount > 0 && $subtotal > 0 && $discount > (float) $cart_item['discount'] ? $discount - (float) $cart_item['discount'] : 0; |
|
| 1719 | + $tax_increased = $tax > 0 && $subtotal > 0 && $tax > (float) $cart_item['tax'] ? $tax - (float) $cart_item['tax'] : 0; |
|
| 1720 | 1720 | // The total increase equals the number removed * the item_price |
| 1721 | - $total_increased = wpinv_round_amount( $item_price ); |
|
| 1721 | + $total_increased = wpinv_round_amount($item_price); |
|
| 1722 | 1722 | |
| 1723 | - if ( wpinv_prices_include_tax() ) { |
|
| 1724 | - $subtotal -= wpinv_round_amount( $tax ); |
|
| 1723 | + if (wpinv_prices_include_tax()) { |
|
| 1724 | + $subtotal -= wpinv_round_amount($tax); |
|
| 1725 | 1725 | } |
| 1726 | 1726 | |
| 1727 | - $total = $subtotal - $discount + $tax; |
|
| 1727 | + $total = $subtotal - $discount + $tax; |
|
| 1728 | 1728 | |
| 1729 | 1729 | // Do not allow totals to go negative |
| 1730 | - if( $total < 0 ) { |
|
| 1730 | + if ($total < 0) { |
|
| 1731 | 1731 | $total = 0; |
| 1732 | 1732 | } |
| 1733 | 1733 | |
@@ -1743,25 +1743,25 @@ discard block |
||
| 1743 | 1743 | $this->cart_details[$found_cart_key] = $cart_item; |
| 1744 | 1744 | } else { |
| 1745 | 1745 | // Set custom price. |
| 1746 | - if ( $args['custom_price'] !== '' ) { |
|
| 1746 | + if ($args['custom_price'] !== '') { |
|
| 1747 | 1747 | $item_price = $args['custom_price']; |
| 1748 | 1748 | } else { |
| 1749 | 1749 | // Allow overriding the price |
| 1750 | - if ( false !== $args['item_price'] ) { |
|
| 1750 | + if (false !== $args['item_price']) { |
|
| 1751 | 1751 | $item_price = $args['item_price']; |
| 1752 | 1752 | } else { |
| 1753 | - $item_price = wpinv_get_item_price( $item->ID ); |
|
| 1753 | + $item_price = wpinv_get_item_price($item->ID); |
|
| 1754 | 1754 | } |
| 1755 | 1755 | } |
| 1756 | 1756 | |
| 1757 | 1757 | // Sanitizing the price here so we don't have a dozen calls later |
| 1758 | - $item_price = wpinv_sanitize_amount( $item_price ); |
|
| 1759 | - $subtotal = wpinv_round_amount( $item_price * $args['quantity'] ); |
|
| 1758 | + $item_price = wpinv_sanitize_amount($item_price); |
|
| 1759 | + $subtotal = wpinv_round_amount($item_price * $args['quantity']); |
|
| 1760 | 1760 | |
| 1761 | - $discount = !empty( $args['discount'] ) ? $args['discount'] : 0; |
|
| 1762 | - $tax_class = !empty( $args['vat_class'] ) ? $args['vat_class'] : ''; |
|
| 1763 | - $tax_rate = !empty( $args['vat_rate'] ) ? $args['vat_rate'] : 0; |
|
| 1764 | - $tax = $subtotal > 0 && $tax_rate > 0 ? ( ( $subtotal - $discount ) * 0.01 * (float)$tax_rate ) : 0; |
|
| 1761 | + $discount = !empty($args['discount']) ? $args['discount'] : 0; |
|
| 1762 | + $tax_class = !empty($args['vat_class']) ? $args['vat_class'] : ''; |
|
| 1763 | + $tax_rate = !empty($args['vat_rate']) ? $args['vat_rate'] : 0; |
|
| 1764 | + $tax = $subtotal > 0 && $tax_rate > 0 ? (($subtotal - $discount) * 0.01 * (float) $tax_rate) : 0; |
|
| 1765 | 1765 | |
| 1766 | 1766 | // Setup the items meta item |
| 1767 | 1767 | $new_item = array( |
@@ -1769,29 +1769,29 @@ discard block |
||
| 1769 | 1769 | 'quantity' => $args['quantity'], |
| 1770 | 1770 | ); |
| 1771 | 1771 | |
| 1772 | - $this->items[] = $new_item; |
|
| 1772 | + $this->items[] = $new_item; |
|
| 1773 | 1773 | |
| 1774 | - if ( wpinv_prices_include_tax() ) { |
|
| 1775 | - $subtotal -= wpinv_round_amount( $tax ); |
|
| 1774 | + if (wpinv_prices_include_tax()) { |
|
| 1775 | + $subtotal -= wpinv_round_amount($tax); |
|
| 1776 | 1776 | } |
| 1777 | 1777 | |
| 1778 | - $total = $subtotal - $discount + $tax; |
|
| 1778 | + $total = $subtotal - $discount + $tax; |
|
| 1779 | 1779 | |
| 1780 | 1780 | // Do not allow totals to go negative |
| 1781 | - if( $total < 0 ) { |
|
| 1781 | + if ($total < 0) { |
|
| 1782 | 1782 | $total = 0; |
| 1783 | 1783 | } |
| 1784 | 1784 | |
| 1785 | 1785 | $this->cart_details[] = array( |
| 1786 | 1786 | 'name' => !empty($args['name']) ? $args['name'] : $item->get_name(), |
| 1787 | 1787 | 'id' => $item->ID, |
| 1788 | - 'item_price' => wpinv_round_amount( $item_price ), |
|
| 1789 | - 'custom_price' => ( $args['custom_price'] !== '' ? wpinv_round_amount( $args['custom_price'] ) : '' ), |
|
| 1788 | + 'item_price' => wpinv_round_amount($item_price), |
|
| 1789 | + 'custom_price' => ($args['custom_price'] !== '' ? wpinv_round_amount($args['custom_price']) : ''), |
|
| 1790 | 1790 | 'quantity' => $args['quantity'], |
| 1791 | 1791 | 'discount' => $discount, |
| 1792 | - 'subtotal' => wpinv_round_amount( $subtotal ), |
|
| 1793 | - 'tax' => wpinv_round_amount( $tax ), |
|
| 1794 | - 'price' => wpinv_round_amount( $total ), |
|
| 1792 | + 'subtotal' => wpinv_round_amount($subtotal), |
|
| 1793 | + 'tax' => wpinv_round_amount($tax), |
|
| 1794 | + 'price' => wpinv_round_amount($total), |
|
| 1795 | 1795 | 'vat_rate' => $tax_rate, |
| 1796 | 1796 | 'vat_class' => $tax_class, |
| 1797 | 1797 | 'meta' => $args['meta'], |
@@ -1801,18 +1801,18 @@ discard block |
||
| 1801 | 1801 | $subtotal = $subtotal - $discount; |
| 1802 | 1802 | } |
| 1803 | 1803 | |
| 1804 | - $added_item = end( $this->cart_details ); |
|
| 1805 | - $added_item['action'] = 'add'; |
|
| 1804 | + $added_item = end($this->cart_details); |
|
| 1805 | + $added_item['action'] = 'add'; |
|
| 1806 | 1806 | |
| 1807 | 1807 | $this->pending['items'][] = $added_item; |
| 1808 | 1808 | |
| 1809 | - $this->increase_subtotal( $subtotal ); |
|
| 1810 | - $this->increase_tax( $tax ); |
|
| 1809 | + $this->increase_subtotal($subtotal); |
|
| 1810 | + $this->increase_tax($tax); |
|
| 1811 | 1811 | |
| 1812 | 1812 | return true; |
| 1813 | 1813 | } |
| 1814 | 1814 | |
| 1815 | - public function remove_item( $item_id, $args = array() ) { |
|
| 1815 | + public function remove_item($item_id, $args = array()) { |
|
| 1816 | 1816 | |
| 1817 | 1817 | // Set some defaults |
| 1818 | 1818 | $defaults = array( |
@@ -1821,51 +1821,51 @@ discard block |
||
| 1821 | 1821 | 'custom_price' => '', |
| 1822 | 1822 | 'cart_index' => false, |
| 1823 | 1823 | ); |
| 1824 | - $args = wp_parse_args( $args, $defaults ); |
|
| 1824 | + $args = wp_parse_args($args, $defaults); |
|
| 1825 | 1825 | |
| 1826 | 1826 | // Bail if this post isn't a item |
| 1827 | - if ( get_post_type( $item_id ) !== 'wpi_item' ) { |
|
| 1827 | + if (get_post_type($item_id) !== 'wpi_item') { |
|
| 1828 | 1828 | return false; |
| 1829 | 1829 | } |
| 1830 | 1830 | |
| 1831 | - $this->cart_details = !empty( $this->cart_details ) ? array_values( $this->cart_details ) : $this->cart_details; |
|
| 1831 | + $this->cart_details = !empty($this->cart_details) ? array_values($this->cart_details) : $this->cart_details; |
|
| 1832 | 1832 | |
| 1833 | - foreach ( $this->items as $key => $item ) { |
|
| 1834 | - if ( !empty($item['id']) && (int)$item_id !== (int)$item['id'] ) { |
|
| 1833 | + foreach ($this->items as $key => $item) { |
|
| 1834 | + if (!empty($item['id']) && (int) $item_id !== (int) $item['id']) { |
|
| 1835 | 1835 | continue; |
| 1836 | 1836 | } |
| 1837 | 1837 | |
| 1838 | - if ( false !== $args['cart_index'] ) { |
|
| 1839 | - $cart_index = absint( $args['cart_index'] ); |
|
| 1840 | - $cart_item = ! empty( $this->cart_details[ $cart_index ] ) ? $this->cart_details[ $cart_index ] : false; |
|
| 1838 | + if (false !== $args['cart_index']) { |
|
| 1839 | + $cart_index = absint($args['cart_index']); |
|
| 1840 | + $cart_item = !empty($this->cart_details[$cart_index]) ? $this->cart_details[$cart_index] : false; |
|
| 1841 | 1841 | |
| 1842 | - if ( ! empty( $cart_item ) ) { |
|
| 1842 | + if (!empty($cart_item)) { |
|
| 1843 | 1843 | // If the cart index item isn't the same item ID, don't remove it |
| 1844 | - if ( !empty($cart_item['id']) && $cart_item['id'] != $item['id'] ) { |
|
| 1844 | + if (!empty($cart_item['id']) && $cart_item['id'] != $item['id']) { |
|
| 1845 | 1845 | continue; |
| 1846 | 1846 | } |
| 1847 | 1847 | } |
| 1848 | 1848 | } |
| 1849 | 1849 | |
| 1850 | - $item_quantity = $this->items[ $key ]['quantity']; |
|
| 1851 | - if ( $item_quantity > $args['quantity'] ) { |
|
| 1852 | - $this->items[ $key ]['quantity'] -= $args['quantity']; |
|
| 1850 | + $item_quantity = $this->items[$key]['quantity']; |
|
| 1851 | + if ($item_quantity > $args['quantity']) { |
|
| 1852 | + $this->items[$key]['quantity'] -= $args['quantity']; |
|
| 1853 | 1853 | break; |
| 1854 | 1854 | } else { |
| 1855 | - unset( $this->items[ $key ] ); |
|
| 1855 | + unset($this->items[$key]); |
|
| 1856 | 1856 | break; |
| 1857 | 1857 | } |
| 1858 | 1858 | } |
| 1859 | 1859 | |
| 1860 | 1860 | $found_cart_key = false; |
| 1861 | - if ( false === $args['cart_index'] ) { |
|
| 1862 | - foreach ( $this->cart_details as $cart_key => $item ) { |
|
| 1863 | - if ( $item_id != $item['id'] ) { |
|
| 1861 | + if (false === $args['cart_index']) { |
|
| 1862 | + foreach ($this->cart_details as $cart_key => $item) { |
|
| 1863 | + if ($item_id != $item['id']) { |
|
| 1864 | 1864 | continue; |
| 1865 | 1865 | } |
| 1866 | 1866 | |
| 1867 | - if ( false !== $args['item_price'] ) { |
|
| 1868 | - if ( isset( $item['item_price'] ) && (float) $args['item_price'] != (float) $item['item_price'] ) { |
|
| 1867 | + if (false !== $args['item_price']) { |
|
| 1868 | + if (isset($item['item_price']) && (float) $args['item_price'] != (float) $item['item_price']) { |
|
| 1869 | 1869 | continue; |
| 1870 | 1870 | } |
| 1871 | 1871 | } |
@@ -1874,13 +1874,13 @@ discard block |
||
| 1874 | 1874 | break; |
| 1875 | 1875 | } |
| 1876 | 1876 | } else { |
| 1877 | - $cart_index = absint( $args['cart_index'] ); |
|
| 1877 | + $cart_index = absint($args['cart_index']); |
|
| 1878 | 1878 | |
| 1879 | - if ( ! array_key_exists( $cart_index, $this->cart_details ) ) { |
|
| 1879 | + if (!array_key_exists($cart_index, $this->cart_details)) { |
|
| 1880 | 1880 | return false; // Invalid cart index passed. |
| 1881 | 1881 | } |
| 1882 | 1882 | |
| 1883 | - if ( (int) $this->cart_details[ $cart_index ]['id'] > 0 && (int) $this->cart_details[ $cart_index ]['id'] !== (int) $item_id ) { |
|
| 1883 | + if ((int) $this->cart_details[$cart_index]['id'] > 0 && (int) $this->cart_details[$cart_index]['id'] !== (int) $item_id) { |
|
| 1884 | 1884 | return false; // We still need the proper Item ID to be sure. |
| 1885 | 1885 | } |
| 1886 | 1886 | |
@@ -1888,41 +1888,41 @@ discard block |
||
| 1888 | 1888 | } |
| 1889 | 1889 | |
| 1890 | 1890 | $cart_item = $this->cart_details[$found_cart_key]; |
| 1891 | - $quantity = !empty( $cart_item['quantity'] ) ? $cart_item['quantity'] : 1; |
|
| 1891 | + $quantity = !empty($cart_item['quantity']) ? $cart_item['quantity'] : 1; |
|
| 1892 | 1892 | |
| 1893 | - if ( count( $this->cart_details ) == 1 && ( $quantity - $args['quantity'] ) < 1 ) { |
|
| 1893 | + if (count($this->cart_details) == 1 && ($quantity - $args['quantity']) < 1) { |
|
| 1894 | 1894 | //return false; // Invoice must contain at least one item. |
| 1895 | 1895 | } |
| 1896 | 1896 | |
| 1897 | - $discounts = $this->get_discounts(); |
|
| 1897 | + $discounts = $this->get_discounts(); |
|
| 1898 | 1898 | |
| 1899 | - if ( $quantity > $args['quantity'] ) { |
|
| 1899 | + if ($quantity > $args['quantity']) { |
|
| 1900 | 1900 | $item_price = $cart_item['item_price']; |
| 1901 | - $tax_rate = !empty( $cart_item['vat_rate'] ) ? $cart_item['vat_rate'] : 0; |
|
| 1901 | + $tax_rate = !empty($cart_item['vat_rate']) ? $cart_item['vat_rate'] : 0; |
|
| 1902 | 1902 | |
| 1903 | - $new_quantity = max( $quantity - $args['quantity'], 1); |
|
| 1903 | + $new_quantity = max($quantity - $args['quantity'], 1); |
|
| 1904 | 1904 | $subtotal = $item_price * $new_quantity; |
| 1905 | 1905 | |
| 1906 | 1906 | $args['quantity'] = $new_quantity; |
| 1907 | - $discount = !empty( $cart_item['discount'] ) ? $cart_item['discount'] : 0; |
|
| 1908 | - $tax = $subtotal > 0 && $tax_rate > 0 ? ( ( $subtotal - $discount ) * 0.01 * (float)$tax_rate ) : 0; |
|
| 1907 | + $discount = !empty($cart_item['discount']) ? $cart_item['discount'] : 0; |
|
| 1908 | + $tax = $subtotal > 0 && $tax_rate > 0 ? (($subtotal - $discount) * 0.01 * (float) $tax_rate) : 0; |
|
| 1909 | 1909 | |
| 1910 | - $discount_decrease = (float)$cart_item['discount'] > 0 && $quantity > 0 ? wpinv_round_amount( ( (float)$cart_item['discount'] / $quantity ) ) : 0; |
|
| 1911 | - $discount_decrease = $discount > 0 && $subtotal > 0 && (float)$cart_item['discount'] > $discount ? (float)$cart_item['discount'] - $discount : $discount_decrease; |
|
| 1912 | - $tax_decrease = (float)$cart_item['tax'] > 0 && $quantity > 0 ? wpinv_round_amount( ( (float)$cart_item['tax'] / $quantity ) ) : 0; |
|
| 1913 | - $tax_decrease = $tax > 0 && $subtotal > 0 && (float)$cart_item['tax'] > $tax ? (float)$cart_item['tax'] - $tax : $tax_decrease; |
|
| 1910 | + $discount_decrease = (float) $cart_item['discount'] > 0 && $quantity > 0 ? wpinv_round_amount(((float) $cart_item['discount'] / $quantity)) : 0; |
|
| 1911 | + $discount_decrease = $discount > 0 && $subtotal > 0 && (float) $cart_item['discount'] > $discount ? (float) $cart_item['discount'] - $discount : $discount_decrease; |
|
| 1912 | + $tax_decrease = (float) $cart_item['tax'] > 0 && $quantity > 0 ? wpinv_round_amount(((float) $cart_item['tax'] / $quantity)) : 0; |
|
| 1913 | + $tax_decrease = $tax > 0 && $subtotal > 0 && (float) $cart_item['tax'] > $tax ? (float) $cart_item['tax'] - $tax : $tax_decrease; |
|
| 1914 | 1914 | |
| 1915 | 1915 | // The total increase equals the number removed * the item_price |
| 1916 | - $total_decrease = wpinv_round_amount( $item_price ); |
|
| 1916 | + $total_decrease = wpinv_round_amount($item_price); |
|
| 1917 | 1917 | |
| 1918 | - if ( wpinv_prices_include_tax() ) { |
|
| 1919 | - $subtotal -= wpinv_round_amount( $tax ); |
|
| 1918 | + if (wpinv_prices_include_tax()) { |
|
| 1919 | + $subtotal -= wpinv_round_amount($tax); |
|
| 1920 | 1920 | } |
| 1921 | 1921 | |
| 1922 | - $total = $subtotal - $discount + $tax; |
|
| 1922 | + $total = $subtotal - $discount + $tax; |
|
| 1923 | 1923 | |
| 1924 | 1924 | // Do not allow totals to go negative |
| 1925 | - if( $total < 0 ) { |
|
| 1925 | + if ($total < 0) { |
|
| 1926 | 1926 | $total = 0; |
| 1927 | 1927 | } |
| 1928 | 1928 | |
@@ -1941,16 +1941,16 @@ discard block |
||
| 1941 | 1941 | |
| 1942 | 1942 | $this->cart_details[$found_cart_key] = $cart_item; |
| 1943 | 1943 | |
| 1944 | - $remove_item = end( $this->cart_details ); |
|
| 1944 | + $remove_item = end($this->cart_details); |
|
| 1945 | 1945 | } else { |
| 1946 | 1946 | $item_price = $cart_item['item_price']; |
| 1947 | - $discount = !empty( $cart_item['discount'] ) ? $cart_item['discount'] : 0; |
|
| 1948 | - $tax = !empty( $cart_item['tax'] ) ? $cart_item['tax'] : 0; |
|
| 1947 | + $discount = !empty($cart_item['discount']) ? $cart_item['discount'] : 0; |
|
| 1948 | + $tax = !empty($cart_item['tax']) ? $cart_item['tax'] : 0; |
|
| 1949 | 1949 | |
| 1950 | - $subtotal_decrease = ( $item_price * $quantity ) - $discount; |
|
| 1950 | + $subtotal_decrease = ($item_price * $quantity) - $discount; |
|
| 1951 | 1951 | $tax_decrease = $tax; |
| 1952 | 1952 | |
| 1953 | - unset( $this->cart_details[$found_cart_key] ); |
|
| 1953 | + unset($this->cart_details[$found_cart_key]); |
|
| 1954 | 1954 | |
| 1955 | 1955 | $remove_item = $args; |
| 1956 | 1956 | $remove_item['id'] = $item_id; |
@@ -1961,8 +1961,8 @@ discard block |
||
| 1961 | 1961 | $remove_item['action'] = 'remove'; |
| 1962 | 1962 | $this->pending['items'][] = $remove_item; |
| 1963 | 1963 | |
| 1964 | - $this->decrease_subtotal( $subtotal_decrease ); |
|
| 1965 | - $this->decrease_tax( $tax_decrease ); |
|
| 1964 | + $this->decrease_subtotal($subtotal_decrease); |
|
| 1965 | + $this->decrease_tax($tax_decrease); |
|
| 1966 | 1966 | |
| 1967 | 1967 | return true; |
| 1968 | 1968 | } |
@@ -1970,7 +1970,7 @@ discard block |
||
| 1970 | 1970 | public function update_items($temp = false) { |
| 1971 | 1971 | global $wpinv_euvat, $wpi_current_id, $wpi_item_id, $wpi_nosave; |
| 1972 | 1972 | |
| 1973 | - if ( ! empty( $this->cart_details ) ) { |
|
| 1973 | + if (!empty($this->cart_details)) { |
|
| 1974 | 1974 | $wpi_nosave = $temp; |
| 1975 | 1975 | $cart_subtotal = 0; |
| 1976 | 1976 | $cart_discount = 0; |
@@ -1980,46 +1980,46 @@ discard block |
||
| 1980 | 1980 | $_POST['wpinv_country'] = $this->country; |
| 1981 | 1981 | $_POST['wpinv_state'] = $this->state; |
| 1982 | 1982 | |
| 1983 | - foreach ( $this->cart_details as $item ) { |
|
| 1983 | + foreach ($this->cart_details as $item) { |
|
| 1984 | 1984 | $item_price = $item['item_price']; |
| 1985 | - $quantity = wpinv_item_quantities_enabled() && $item['quantity'] > 0 ? absint( $item['quantity'] ) : 1; |
|
| 1986 | - $amount = wpinv_round_amount( $item_price * $quantity ); |
|
| 1985 | + $quantity = wpinv_item_quantities_enabled() && $item['quantity'] > 0 ? absint($item['quantity']) : 1; |
|
| 1986 | + $amount = wpinv_round_amount($item_price * $quantity); |
|
| 1987 | 1987 | $subtotal = $item_price * $quantity; |
| 1988 | 1988 | |
| 1989 | 1989 | $wpi_current_id = $this->ID; |
| 1990 | 1990 | $wpi_item_id = $item['id']; |
| 1991 | 1991 | |
| 1992 | - $discount = wpinv_get_cart_item_discount_amount( $item, $this->get_discounts() ); |
|
| 1992 | + $discount = wpinv_get_cart_item_discount_amount($item, $this->get_discounts()); |
|
| 1993 | 1993 | |
| 1994 | - $tax_rate = wpinv_get_tax_rate( $this->country, $this->state, $wpi_item_id ); |
|
| 1995 | - $tax_class = $wpinv_euvat->get_item_class( $wpi_item_id ); |
|
| 1996 | - $tax = $item_price > 0 ? ( ( $subtotal - $discount ) * 0.01 * (float)$tax_rate ) : 0; |
|
| 1994 | + $tax_rate = wpinv_get_tax_rate($this->country, $this->state, $wpi_item_id); |
|
| 1995 | + $tax_class = $wpinv_euvat->get_item_class($wpi_item_id); |
|
| 1996 | + $tax = $item_price > 0 ? (($subtotal - $discount) * 0.01 * (float) $tax_rate) : 0; |
|
| 1997 | 1997 | |
| 1998 | - if ( ! $this->is_taxable() ) { |
|
| 1998 | + if (!$this->is_taxable()) { |
|
| 1999 | 1999 | $tax = 0; |
| 2000 | 2000 | } |
| 2001 | 2001 | |
| 2002 | - if ( wpinv_prices_include_tax() ) { |
|
| 2003 | - $subtotal -= wpinv_round_amount( $tax ); |
|
| 2002 | + if (wpinv_prices_include_tax()) { |
|
| 2003 | + $subtotal -= wpinv_round_amount($tax); |
|
| 2004 | 2004 | } |
| 2005 | 2005 | |
| 2006 | - $total = $subtotal - $discount + $tax; |
|
| 2006 | + $total = $subtotal - $discount + $tax; |
|
| 2007 | 2007 | |
| 2008 | 2008 | // Do not allow totals to go negative |
| 2009 | - if( $total < 0 ) { |
|
| 2009 | + if ($total < 0) { |
|
| 2010 | 2010 | $total = 0; |
| 2011 | 2011 | } |
| 2012 | 2012 | |
| 2013 | 2013 | $cart_details[] = array( |
| 2014 | 2014 | 'id' => $item['id'], |
| 2015 | 2015 | 'name' => $item['name'], |
| 2016 | - 'item_price' => wpinv_round_amount( $item_price ), |
|
| 2017 | - 'custom_price'=> ( isset( $item['custom_price'] ) ? $item['custom_price'] : '' ), |
|
| 2016 | + 'item_price' => wpinv_round_amount($item_price), |
|
| 2017 | + 'custom_price'=> (isset($item['custom_price']) ? $item['custom_price'] : ''), |
|
| 2018 | 2018 | 'quantity' => $quantity, |
| 2019 | 2019 | 'discount' => $discount, |
| 2020 | - 'subtotal' => wpinv_round_amount( $subtotal ), |
|
| 2021 | - 'tax' => wpinv_round_amount( $tax ), |
|
| 2022 | - 'price' => wpinv_round_amount( $total ), |
|
| 2020 | + 'subtotal' => wpinv_round_amount($subtotal), |
|
| 2021 | + 'tax' => wpinv_round_amount($tax), |
|
| 2022 | + 'price' => wpinv_round_amount($total), |
|
| 2023 | 2023 | 'vat_rate' => $tax_rate, |
| 2024 | 2024 | 'vat_class' => $tax_class, |
| 2025 | 2025 | 'meta' => isset($item['meta']) ? $item['meta'] : array(), |
@@ -2031,21 +2031,21 @@ discard block |
||
| 2031 | 2031 | $cart_tax += (float) $tax; |
| 2032 | 2032 | } |
| 2033 | 2033 | |
| 2034 | - if ( $cart_subtotal < 0 ) { |
|
| 2034 | + if ($cart_subtotal < 0) { |
|
| 2035 | 2035 | $cart_subtotal = 0; |
| 2036 | 2036 | } |
| 2037 | 2037 | |
| 2038 | - if ( $cart_discount < 0 ) { |
|
| 2038 | + if ($cart_discount < 0) { |
|
| 2039 | 2039 | $cart_discount = 0; |
| 2040 | 2040 | } |
| 2041 | 2041 | |
| 2042 | - if ( $cart_tax < 0 ) { |
|
| 2042 | + if ($cart_tax < 0) { |
|
| 2043 | 2043 | $cart_tax = 0; |
| 2044 | 2044 | } |
| 2045 | 2045 | |
| 2046 | - $this->subtotal = wpinv_round_amount( $cart_subtotal ); |
|
| 2047 | - $this->tax = wpinv_round_amount( $cart_tax ); |
|
| 2048 | - $this->discount = wpinv_round_amount( $cart_discount ); |
|
| 2046 | + $this->subtotal = wpinv_round_amount($cart_subtotal); |
|
| 2047 | + $this->tax = wpinv_round_amount($cart_tax); |
|
| 2048 | + $this->discount = wpinv_round_amount($cart_discount); |
|
| 2049 | 2049 | |
| 2050 | 2050 | $this->recalculate_total(); |
| 2051 | 2051 | |
@@ -2060,13 +2060,13 @@ discard block |
||
| 2060 | 2060 | */ |
| 2061 | 2061 | public function validate_discount() { |
| 2062 | 2062 | |
| 2063 | - $discounts = $this->get_discounts( true ); |
|
| 2063 | + $discounts = $this->get_discounts(true); |
|
| 2064 | 2064 | |
| 2065 | - if ( empty( $discounts ) ) { |
|
| 2065 | + if (empty($discounts)) { |
|
| 2066 | 2066 | return false; |
| 2067 | 2067 | } |
| 2068 | 2068 | |
| 2069 | - $discount = wpinv_get_discount_obj( $discounts[0] ); |
|
| 2069 | + $discount = wpinv_get_discount_obj($discounts[0]); |
|
| 2070 | 2070 | |
| 2071 | 2071 | // Ensure it is active. |
| 2072 | 2072 | return $discount->exists(); |
@@ -2075,78 +2075,78 @@ discard block |
||
| 2075 | 2075 | |
| 2076 | 2076 | public function recalculate_totals($temp = false) { |
| 2077 | 2077 | $this->update_items($temp); |
| 2078 | - $this->save( true ); |
|
| 2078 | + $this->save(true); |
|
| 2079 | 2079 | |
| 2080 | 2080 | return $this; |
| 2081 | 2081 | } |
| 2082 | 2082 | |
| 2083 | 2083 | public function needs_payment() { |
| 2084 | - $valid_invoice_statuses = apply_filters( 'wpinv_valid_invoice_statuses_for_payment', array( 'wpi-pending' ), $this ); |
|
| 2084 | + $valid_invoice_statuses = apply_filters('wpinv_valid_invoice_statuses_for_payment', array('wpi-pending'), $this); |
|
| 2085 | 2085 | |
| 2086 | - if ( $this->has_status( $valid_invoice_statuses ) && ( $this->get_total() > 0 || $this->is_free_trial() || $this->is_free() || $this->is_initial_free() ) ) { |
|
| 2086 | + if ($this->has_status($valid_invoice_statuses) && ($this->get_total() > 0 || $this->is_free_trial() || $this->is_free() || $this->is_initial_free())) { |
|
| 2087 | 2087 | $needs_payment = true; |
| 2088 | 2088 | } else { |
| 2089 | 2089 | $needs_payment = false; |
| 2090 | 2090 | } |
| 2091 | 2091 | |
| 2092 | - return apply_filters( 'wpinv_needs_payment', $needs_payment, $this, $valid_invoice_statuses ); |
|
| 2092 | + return apply_filters('wpinv_needs_payment', $needs_payment, $this, $valid_invoice_statuses); |
|
| 2093 | 2093 | } |
| 2094 | 2094 | |
| 2095 | - public function get_checkout_payment_url( $with_key = false, $secret = false ) { |
|
| 2095 | + public function get_checkout_payment_url($with_key = false, $secret = false) { |
|
| 2096 | 2096 | $pay_url = wpinv_get_checkout_uri(); |
| 2097 | 2097 | |
| 2098 | - if ( is_ssl() ) { |
|
| 2099 | - $pay_url = str_replace( 'http:', 'https:', $pay_url ); |
|
| 2098 | + if (is_ssl()) { |
|
| 2099 | + $pay_url = str_replace('http:', 'https:', $pay_url); |
|
| 2100 | 2100 | } |
| 2101 | 2101 | |
| 2102 | 2102 | $key = $this->get_key(); |
| 2103 | 2103 | |
| 2104 | - if ( $with_key ) { |
|
| 2105 | - $pay_url = add_query_arg( 'invoice_key', $key, $pay_url ); |
|
| 2104 | + if ($with_key) { |
|
| 2105 | + $pay_url = add_query_arg('invoice_key', $key, $pay_url); |
|
| 2106 | 2106 | } else { |
| 2107 | - $pay_url = add_query_arg( array( 'wpi_action' => 'pay_for_invoice', 'invoice_key' => $key ), $pay_url ); |
|
| 2107 | + $pay_url = add_query_arg(array('wpi_action' => 'pay_for_invoice', 'invoice_key' => $key), $pay_url); |
|
| 2108 | 2108 | } |
| 2109 | 2109 | |
| 2110 | - if ( $secret ) { |
|
| 2111 | - $pay_url = add_query_arg( array( '_wpipay' => md5( $this->get_user_id() . '::' . $this->get_email() . '::' . $key ) ), $pay_url ); |
|
| 2110 | + if ($secret) { |
|
| 2111 | + $pay_url = add_query_arg(array('_wpipay' => md5($this->get_user_id() . '::' . $this->get_email() . '::' . $key)), $pay_url); |
|
| 2112 | 2112 | } |
| 2113 | 2113 | |
| 2114 | - return apply_filters( 'wpinv_get_checkout_payment_url', $pay_url, $this, $with_key, $secret ); |
|
| 2114 | + return apply_filters('wpinv_get_checkout_payment_url', $pay_url, $this, $with_key, $secret); |
|
| 2115 | 2115 | } |
| 2116 | 2116 | |
| 2117 | - public function get_view_url( $with_key = false ) { |
|
| 2118 | - $invoice_url = get_permalink( $this->ID ); |
|
| 2117 | + public function get_view_url($with_key = false) { |
|
| 2118 | + $invoice_url = get_permalink($this->ID); |
|
| 2119 | 2119 | |
| 2120 | - if ( $with_key ) { |
|
| 2121 | - $invoice_url = add_query_arg( 'invoice_key', $this->get_key(), $invoice_url ); |
|
| 2120 | + if ($with_key) { |
|
| 2121 | + $invoice_url = add_query_arg('invoice_key', $this->get_key(), $invoice_url); |
|
| 2122 | 2122 | } |
| 2123 | 2123 | |
| 2124 | - return apply_filters( 'wpinv_get_view_url', $invoice_url, $this, $with_key ); |
|
| 2124 | + return apply_filters('wpinv_get_view_url', $invoice_url, $this, $with_key); |
|
| 2125 | 2125 | } |
| 2126 | 2126 | |
| 2127 | - public function generate_key( $string = '' ) { |
|
| 2128 | - $auth_key = defined( 'AUTH_KEY' ) ? AUTH_KEY : ''; |
|
| 2129 | - return strtolower( md5( $string . date( 'Y-m-d H:i:s' ) . $auth_key . uniqid( 'wpinv', true ) ) ); // Unique key |
|
| 2127 | + public function generate_key($string = '') { |
|
| 2128 | + $auth_key = defined('AUTH_KEY') ? AUTH_KEY : ''; |
|
| 2129 | + return strtolower(md5($string . date('Y-m-d H:i:s') . $auth_key . uniqid('wpinv', true))); // Unique key |
|
| 2130 | 2130 | } |
| 2131 | 2131 | |
| 2132 | 2132 | public function is_recurring() { |
| 2133 | - if ( empty( $this->cart_details ) ) { |
|
| 2133 | + if (empty($this->cart_details)) { |
|
| 2134 | 2134 | return false; |
| 2135 | 2135 | } |
| 2136 | 2136 | |
| 2137 | 2137 | $has_subscription = false; |
| 2138 | - foreach( $this->cart_details as $cart_item ) { |
|
| 2139 | - if ( !empty( $cart_item['id'] ) && wpinv_is_recurring_item( $cart_item['id'] ) ) { |
|
| 2138 | + foreach ($this->cart_details as $cart_item) { |
|
| 2139 | + if (!empty($cart_item['id']) && wpinv_is_recurring_item($cart_item['id'])) { |
|
| 2140 | 2140 | $has_subscription = true; |
| 2141 | 2141 | break; |
| 2142 | 2142 | } |
| 2143 | 2143 | } |
| 2144 | 2144 | |
| 2145 | - if ( count( $this->cart_details ) > 1 ) { |
|
| 2145 | + if (count($this->cart_details) > 1) { |
|
| 2146 | 2146 | $has_subscription = false; |
| 2147 | 2147 | } |
| 2148 | 2148 | |
| 2149 | - return apply_filters( 'wpinv_invoice_has_recurring_item', $has_subscription, $this->cart_details ); |
|
| 2149 | + return apply_filters('wpinv_invoice_has_recurring_item', $has_subscription, $this->cart_details); |
|
| 2150 | 2150 | } |
| 2151 | 2151 | |
| 2152 | 2152 | /** |
@@ -2157,13 +2157,13 @@ discard block |
||
| 2157 | 2157 | public function is_free_trial() { |
| 2158 | 2158 | $is_free_trial = false; |
| 2159 | 2159 | |
| 2160 | - if ( $this->is_parent() && $item = $this->get_recurring( true ) ) { |
|
| 2161 | - if ( ! empty( $item ) && ( $item->has_free_trial() || ( $this->total == 0 && $this->discount_first_payment_only() ) ) ) { |
|
| 2160 | + if ($this->is_parent() && $item = $this->get_recurring(true)) { |
|
| 2161 | + if (!empty($item) && ($item->has_free_trial() || ($this->total == 0 && $this->discount_first_payment_only()))) { |
|
| 2162 | 2162 | $is_free_trial = true; |
| 2163 | 2163 | } |
| 2164 | 2164 | } |
| 2165 | 2165 | |
| 2166 | - return apply_filters( 'wpinv_invoice_is_free_trial', $is_free_trial, $this->cart_details, $this ); |
|
| 2166 | + return apply_filters('wpinv_invoice_is_free_trial', $is_free_trial, $this->cart_details, $this); |
|
| 2167 | 2167 | } |
| 2168 | 2168 | |
| 2169 | 2169 | /** |
@@ -2173,12 +2173,12 @@ discard block |
||
| 2173 | 2173 | |
| 2174 | 2174 | $parent = $this; |
| 2175 | 2175 | |
| 2176 | - if ( $this->is_renewal() ) { |
|
| 2176 | + if ($this->is_renewal()) { |
|
| 2177 | 2177 | $parent = $this->get_parent_payment(); |
| 2178 | 2178 | } |
| 2179 | 2179 | |
| 2180 | - if ( $parent && $item = $parent->get_recurring( true ) ) { |
|
| 2181 | - return ! ( ! empty( $item ) && $item->has_free_trial() ); |
|
| 2180 | + if ($parent && $item = $parent->get_recurring(true)) { |
|
| 2181 | + return !(!empty($item) && $item->has_free_trial()); |
|
| 2182 | 2182 | } |
| 2183 | 2183 | return false; |
| 2184 | 2184 | |
@@ -2189,104 +2189,104 @@ discard block |
||
| 2189 | 2189 | */ |
| 2190 | 2190 | public function discount_first_payment_only() { |
| 2191 | 2191 | |
| 2192 | - if ( empty( $this->discounts ) || ! $this->is_recurring() ) { |
|
| 2192 | + if (empty($this->discounts) || !$this->is_recurring()) { |
|
| 2193 | 2193 | return true; |
| 2194 | 2194 | } |
| 2195 | 2195 | |
| 2196 | - $discount = wpinv_get_discount_obj( $this->discounts[0] ); |
|
| 2196 | + $discount = wpinv_get_discount_obj($this->discounts[0]); |
|
| 2197 | 2197 | |
| 2198 | - if ( ! $discount || ! $discount->exists() ) { |
|
| 2198 | + if (!$discount || !$discount->exists()) { |
|
| 2199 | 2199 | return true; |
| 2200 | 2200 | } |
| 2201 | 2201 | |
| 2202 | - return ! $discount->get_is_recurring(); |
|
| 2202 | + return !$discount->get_is_recurring(); |
|
| 2203 | 2203 | } |
| 2204 | 2204 | |
| 2205 | 2205 | public function is_initial_free() { |
| 2206 | 2206 | $is_initial_free = false; |
| 2207 | 2207 | |
| 2208 | - if ( ! ( (float)wpinv_round_amount( $this->get_total() ) > 0 ) && $this->is_parent() && $this->is_recurring() && ! $this->is_free_trial() && ! $this->is_free() ) { |
|
| 2208 | + if (!((float) wpinv_round_amount($this->get_total()) > 0) && $this->is_parent() && $this->is_recurring() && !$this->is_free_trial() && !$this->is_free()) { |
|
| 2209 | 2209 | $is_initial_free = true; |
| 2210 | 2210 | } |
| 2211 | 2211 | |
| 2212 | - return apply_filters( 'wpinv_invoice_is_initial_free', $is_initial_free, $this->cart_details ); |
|
| 2212 | + return apply_filters('wpinv_invoice_is_initial_free', $is_initial_free, $this->cart_details); |
|
| 2213 | 2213 | } |
| 2214 | 2214 | |
| 2215 | - public function get_recurring( $object = false ) { |
|
| 2215 | + public function get_recurring($object = false) { |
|
| 2216 | 2216 | $item = NULL; |
| 2217 | 2217 | |
| 2218 | - if ( empty( $this->cart_details ) ) { |
|
| 2218 | + if (empty($this->cart_details)) { |
|
| 2219 | 2219 | return $item; |
| 2220 | 2220 | } |
| 2221 | 2221 | |
| 2222 | - foreach( $this->cart_details as $cart_item ) { |
|
| 2223 | - if ( !empty( $cart_item['id'] ) && wpinv_is_recurring_item( $cart_item['id'] ) ) { |
|
| 2222 | + foreach ($this->cart_details as $cart_item) { |
|
| 2223 | + if (!empty($cart_item['id']) && wpinv_is_recurring_item($cart_item['id'])) { |
|
| 2224 | 2224 | $item = $cart_item['id']; |
| 2225 | 2225 | break; |
| 2226 | 2226 | } |
| 2227 | 2227 | } |
| 2228 | 2228 | |
| 2229 | - if ( $object ) { |
|
| 2230 | - $item = $item ? new WPInv_Item( $item ) : NULL; |
|
| 2229 | + if ($object) { |
|
| 2230 | + $item = $item ? new WPInv_Item($item) : NULL; |
|
| 2231 | 2231 | |
| 2232 | - apply_filters( 'wpinv_invoice_get_recurring_item', $item, $this ); |
|
| 2232 | + apply_filters('wpinv_invoice_get_recurring_item', $item, $this); |
|
| 2233 | 2233 | } |
| 2234 | 2234 | |
| 2235 | - return apply_filters( 'wpinv_invoice_get_recurring_item_id', $item, $this ); |
|
| 2235 | + return apply_filters('wpinv_invoice_get_recurring_item_id', $item, $this); |
|
| 2236 | 2236 | } |
| 2237 | 2237 | |
| 2238 | 2238 | public function get_subscription_name() { |
| 2239 | - $item = $this->get_recurring( true ); |
|
| 2239 | + $item = $this->get_recurring(true); |
|
| 2240 | 2240 | |
| 2241 | - if ( empty( $item ) ) { |
|
| 2241 | + if (empty($item)) { |
|
| 2242 | 2242 | return NULL; |
| 2243 | 2243 | } |
| 2244 | 2244 | |
| 2245 | - if ( !($name = $item->get_name()) ) { |
|
| 2245 | + if (!($name = $item->get_name())) { |
|
| 2246 | 2246 | $name = $item->post_name; |
| 2247 | 2247 | } |
| 2248 | 2248 | |
| 2249 | - return apply_filters( 'wpinv_invoice_get_subscription_name', $name, $this ); |
|
| 2249 | + return apply_filters('wpinv_invoice_get_subscription_name', $name, $this); |
|
| 2250 | 2250 | } |
| 2251 | 2251 | |
| 2252 | 2252 | public function get_subscription_id() { |
| 2253 | - $subscription_id = $this->get_meta( '_wpinv_subscr_profile_id', true ); |
|
| 2253 | + $subscription_id = $this->get_meta('_wpinv_subscr_profile_id', true); |
|
| 2254 | 2254 | |
| 2255 | - if ( empty( $subscription_id ) && !empty( $this->parent_invoice ) ) { |
|
| 2256 | - $parent_invoice = wpinv_get_invoice( $this->parent_invoice ); |
|
| 2255 | + if (empty($subscription_id) && !empty($this->parent_invoice)) { |
|
| 2256 | + $parent_invoice = wpinv_get_invoice($this->parent_invoice); |
|
| 2257 | 2257 | |
| 2258 | - $subscription_id = $parent_invoice->get_meta( '_wpinv_subscr_profile_id', true ); |
|
| 2258 | + $subscription_id = $parent_invoice->get_meta('_wpinv_subscr_profile_id', true); |
|
| 2259 | 2259 | } |
| 2260 | 2260 | |
| 2261 | 2261 | return $subscription_id; |
| 2262 | 2262 | } |
| 2263 | 2263 | |
| 2264 | 2264 | public function is_parent() { |
| 2265 | - $is_parent = empty( $this->parent_invoice ) ? true : false; |
|
| 2265 | + $is_parent = empty($this->parent_invoice) ? true : false; |
|
| 2266 | 2266 | |
| 2267 | - return apply_filters( 'wpinv_invoice_is_parent', $is_parent, $this ); |
|
| 2267 | + return apply_filters('wpinv_invoice_is_parent', $is_parent, $this); |
|
| 2268 | 2268 | } |
| 2269 | 2269 | |
| 2270 | 2270 | public function is_renewal() { |
| 2271 | 2271 | $is_renewal = $this->parent_invoice && $this->parent_invoice != $this->ID ? true : false; |
| 2272 | 2272 | |
| 2273 | - return apply_filters( 'wpinv_invoice_is_renewal', $is_renewal, $this ); |
|
| 2273 | + return apply_filters('wpinv_invoice_is_renewal', $is_renewal, $this); |
|
| 2274 | 2274 | } |
| 2275 | 2275 | |
| 2276 | 2276 | public function get_parent_payment() { |
| 2277 | 2277 | $parent_payment = NULL; |
| 2278 | 2278 | |
| 2279 | - if ( $this->is_renewal() ) { |
|
| 2280 | - $parent_payment = wpinv_get_invoice( $this->parent_invoice ); |
|
| 2279 | + if ($this->is_renewal()) { |
|
| 2280 | + $parent_payment = wpinv_get_invoice($this->parent_invoice); |
|
| 2281 | 2281 | } |
| 2282 | 2282 | |
| 2283 | 2283 | return $parent_payment; |
| 2284 | 2284 | } |
| 2285 | 2285 | |
| 2286 | 2286 | public function is_paid() { |
| 2287 | - $is_paid = $this->has_status( array( 'publish', 'wpi-processing', 'wpi-renewal' ) ); |
|
| 2287 | + $is_paid = $this->has_status(array('publish', 'wpi-processing', 'wpi-renewal')); |
|
| 2288 | 2288 | |
| 2289 | - return apply_filters( 'wpinv_invoice_is_paid', $is_paid, $this ); |
|
| 2289 | + return apply_filters('wpinv_invoice_is_paid', $is_paid, $this); |
|
| 2290 | 2290 | } |
| 2291 | 2291 | |
| 2292 | 2292 | /** |
@@ -2299,23 +2299,23 @@ discard block |
||
| 2299 | 2299 | } |
| 2300 | 2300 | |
| 2301 | 2301 | public function is_refunded() { |
| 2302 | - $is_refunded = $this->has_status( array( 'wpi-refunded' ) ); |
|
| 2302 | + $is_refunded = $this->has_status(array('wpi-refunded')); |
|
| 2303 | 2303 | |
| 2304 | - return apply_filters( 'wpinv_invoice_is_refunded', $is_refunded, $this ); |
|
| 2304 | + return apply_filters('wpinv_invoice_is_refunded', $is_refunded, $this); |
|
| 2305 | 2305 | } |
| 2306 | 2306 | |
| 2307 | 2307 | public function is_free() { |
| 2308 | 2308 | $is_free = false; |
| 2309 | 2309 | |
| 2310 | - if ( !( (float)wpinv_round_amount( $this->get_total() ) > 0 ) ) { |
|
| 2311 | - if ( $this->is_parent() && $this->is_recurring() ) { |
|
| 2312 | - $is_free = (float)wpinv_round_amount( $this->get_recurring_details( 'total' ) ) > 0 ? false : true; |
|
| 2310 | + if (!((float) wpinv_round_amount($this->get_total()) > 0)) { |
|
| 2311 | + if ($this->is_parent() && $this->is_recurring()) { |
|
| 2312 | + $is_free = (float) wpinv_round_amount($this->get_recurring_details('total')) > 0 ? false : true; |
|
| 2313 | 2313 | } else { |
| 2314 | 2314 | $is_free = true; |
| 2315 | 2315 | } |
| 2316 | 2316 | } |
| 2317 | 2317 | |
| 2318 | - return apply_filters( 'wpinv_invoice_is_free', $is_free, $this ); |
|
| 2318 | + return apply_filters('wpinv_invoice_is_free', $is_free, $this); |
|
| 2319 | 2319 | } |
| 2320 | 2320 | |
| 2321 | 2321 | public function has_vat() { |
@@ -2323,41 +2323,41 @@ discard block |
||
| 2323 | 2323 | |
| 2324 | 2324 | $requires_vat = false; |
| 2325 | 2325 | |
| 2326 | - if ( $this->country ) { |
|
| 2326 | + if ($this->country) { |
|
| 2327 | 2327 | $wpi_country = $this->country; |
| 2328 | 2328 | |
| 2329 | - $requires_vat = $wpinv_euvat->requires_vat( $requires_vat, $this->get_user_id(), $wpinv_euvat->invoice_has_digital_rule( $this ) ); |
|
| 2329 | + $requires_vat = $wpinv_euvat->requires_vat($requires_vat, $this->get_user_id(), $wpinv_euvat->invoice_has_digital_rule($this)); |
|
| 2330 | 2330 | } |
| 2331 | 2331 | |
| 2332 | - return apply_filters( 'wpinv_invoice_has_vat', $requires_vat, $this ); |
|
| 2332 | + return apply_filters('wpinv_invoice_has_vat', $requires_vat, $this); |
|
| 2333 | 2333 | } |
| 2334 | 2334 | |
| 2335 | 2335 | public function refresh_item_ids() { |
| 2336 | 2336 | $item_ids = array(); |
| 2337 | 2337 | |
| 2338 | - if ( ! empty( $this->cart_details ) ) { |
|
| 2339 | - foreach ( array_keys( $this->cart_details ) as $item ) { |
|
| 2340 | - if ( ! empty( $item['id'] ) ) { |
|
| 2338 | + if (!empty($this->cart_details)) { |
|
| 2339 | + foreach (array_keys($this->cart_details) as $item) { |
|
| 2340 | + if (!empty($item['id'])) { |
|
| 2341 | 2341 | $item_ids[] = $item['id']; |
| 2342 | 2342 | } |
| 2343 | 2343 | } |
| 2344 | 2344 | } |
| 2345 | 2345 | |
| 2346 | - $item_ids = !empty( $item_ids ) ? implode( ',', array_unique( $item_ids ) ) : ''; |
|
| 2346 | + $item_ids = !empty($item_ids) ? implode(',', array_unique($item_ids)) : ''; |
|
| 2347 | 2347 | |
| 2348 | - update_post_meta( $this->ID, '_wpinv_item_ids', $item_ids ); |
|
| 2348 | + update_post_meta($this->ID, '_wpinv_item_ids', $item_ids); |
|
| 2349 | 2349 | } |
| 2350 | 2350 | |
| 2351 | - public function get_invoice_quote_type( $post_id ) { |
|
| 2352 | - if ( empty( $post_id ) ) { |
|
| 2351 | + public function get_invoice_quote_type($post_id) { |
|
| 2352 | + if (empty($post_id)) { |
|
| 2353 | 2353 | return ''; |
| 2354 | 2354 | } |
| 2355 | 2355 | |
| 2356 | - $type = get_post_type( $post_id ); |
|
| 2356 | + $type = get_post_type($post_id); |
|
| 2357 | 2357 | |
| 2358 | - if ( 'wpi_invoice' === $type ) { |
|
| 2358 | + if ('wpi_invoice' === $type) { |
|
| 2359 | 2359 | $post_type = __('Invoice', 'invoicing'); |
| 2360 | - } else{ |
|
| 2360 | + } else { |
|
| 2361 | 2361 | $post_type = __('Quote', 'invoicing'); |
| 2362 | 2362 | } |
| 2363 | 2363 | |
@@ -7,28 +7,28 @@ discard block |
||
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | 9 | // MUST have WordPress. |
| 10 | -if ( !defined( 'WPINC' ) ) { |
|
| 11 | - exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) ); |
|
| 10 | +if (!defined('WPINC')) { |
|
| 11 | + exit('Do NOT access this file directly: ' . basename(__FILE__)); |
|
| 12 | 12 | } |
| 13 | 13 | |
| 14 | 14 | class WPInv_Ajax { |
| 15 | 15 | public static function init() { |
| 16 | - add_action( 'init', array( __CLASS__, 'define_ajax' ), 0 ); |
|
| 17 | - add_action( 'template_redirect', array( __CLASS__, 'do_wpinv_ajax' ), 0 ); |
|
| 16 | + add_action('init', array(__CLASS__, 'define_ajax'), 0); |
|
| 17 | + add_action('template_redirect', array(__CLASS__, 'do_wpinv_ajax'), 0); |
|
| 18 | 18 | self::add_ajax_events(); |
| 19 | 19 | } |
| 20 | 20 | |
| 21 | 21 | public static function define_ajax() { |
| 22 | - if ( !empty( $_GET['wpinv-ajax'] ) ) { |
|
| 23 | - if ( ! defined( 'DOING_AJAX' ) ) { |
|
| 24 | - define( 'DOING_AJAX', true ); |
|
| 22 | + if (!empty($_GET['wpinv-ajax'])) { |
|
| 23 | + if (!defined('DOING_AJAX')) { |
|
| 24 | + define('DOING_AJAX', true); |
|
| 25 | 25 | } |
| 26 | - if ( ! defined( 'WC_DOING_AJAX' ) ) { |
|
| 27 | - define( 'WC_DOING_AJAX', true ); |
|
| 26 | + if (!defined('WC_DOING_AJAX')) { |
|
| 27 | + define('WC_DOING_AJAX', true); |
|
| 28 | 28 | } |
| 29 | 29 | // Turn off display_errors during AJAX events to prevent malformed JSON |
| 30 | - if ( ! WP_DEBUG || ( WP_DEBUG && ! WP_DEBUG_DISPLAY ) ) { |
|
| 31 | - /** @scrutinizer ignore-unhandled */ @ini_set( 'display_errors', 0 ); |
|
| 30 | + if (!WP_DEBUG || (WP_DEBUG && !WP_DEBUG_DISPLAY)) { |
|
| 31 | + /** @scrutinizer ignore-unhandled */ @ini_set('display_errors', 0); |
|
| 32 | 32 | } |
| 33 | 33 | $GLOBALS['wpdb']->hide_errors(); |
| 34 | 34 | } |
@@ -37,24 +37,24 @@ discard block |
||
| 37 | 37 | public static function do_wpinv_ajax() { |
| 38 | 38 | global $wp_query; |
| 39 | 39 | |
| 40 | - if ( !empty( $_GET['wpinv-ajax'] ) ) { |
|
| 41 | - $wp_query->set( 'wpinv-ajax', sanitize_text_field( $_GET['wpinv-ajax'] ) ); |
|
| 40 | + if (!empty($_GET['wpinv-ajax'])) { |
|
| 41 | + $wp_query->set('wpinv-ajax', sanitize_text_field($_GET['wpinv-ajax'])); |
|
| 42 | 42 | } |
| 43 | 43 | |
| 44 | - if ( $action = $wp_query->get( 'wpinv-ajax' ) ) { |
|
| 44 | + if ($action = $wp_query->get('wpinv-ajax')) { |
|
| 45 | 45 | self::wpinv_ajax_headers(); |
| 46 | - do_action( 'wpinv_ajax_' . sanitize_text_field( $action ) ); |
|
| 46 | + do_action('wpinv_ajax_' . sanitize_text_field($action)); |
|
| 47 | 47 | die(); |
| 48 | 48 | } |
| 49 | 49 | } |
| 50 | 50 | |
| 51 | 51 | private static function wpinv_ajax_headers() { |
| 52 | 52 | send_origin_headers(); |
| 53 | - /** @scrutinizer ignore-unhandled */ @header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) ); |
|
| 54 | - /** @scrutinizer ignore-unhandled */ @header( 'X-Robots-Tag: noindex' ); |
|
| 53 | + /** @scrutinizer ignore-unhandled */ @header('Content-Type: text/html; charset=' . get_option('blog_charset')); |
|
| 54 | + /** @scrutinizer ignore-unhandled */ @header('X-Robots-Tag: noindex'); |
|
| 55 | 55 | send_nosniff_header(); |
| 56 | 56 | nocache_headers(); |
| 57 | - status_header( 200 ); |
|
| 57 | + status_header(200); |
|
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | public static function add_ajax_events() { |
@@ -82,41 +82,41 @@ discard block |
||
| 82 | 82 | 'buy_items' => true, |
| 83 | 83 | ); |
| 84 | 84 | |
| 85 | - foreach ( $ajax_events as $ajax_event => $nopriv ) { |
|
| 86 | - add_action( 'wp_ajax_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
| 87 | - add_action( 'wp_ajax_getpaid_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
| 85 | + foreach ($ajax_events as $ajax_event => $nopriv) { |
|
| 86 | + add_action('wp_ajax_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
| 87 | + add_action('wp_ajax_getpaid_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
| 88 | 88 | |
| 89 | - if ( !defined( 'WPI_AJAX_' . strtoupper( $nopriv ) ) ) { |
|
| 90 | - define( 'WPI_AJAX_' . strtoupper( $nopriv ), 1 ); |
|
| 89 | + if (!defined('WPI_AJAX_' . strtoupper($nopriv))) { |
|
| 90 | + define('WPI_AJAX_' . strtoupper($nopriv), 1); |
|
| 91 | 91 | } |
| 92 | 92 | |
| 93 | - if ( $nopriv ) { |
|
| 94 | - add_action( 'wp_ajax_nopriv_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
| 95 | - add_action( 'wp_ajax_nopriv_getpaid_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
| 93 | + if ($nopriv) { |
|
| 94 | + add_action('wp_ajax_nopriv_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
| 95 | + add_action('wp_ajax_nopriv_getpaid_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
| 96 | 96 | |
| 97 | - add_action( 'wpinv_ajax_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
| 97 | + add_action('wpinv_ajax_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
| 98 | 98 | } |
| 99 | 99 | } |
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | public static function add_note() { |
| 103 | - check_ajax_referer( 'add-invoice-note', '_nonce' ); |
|
| 103 | + check_ajax_referer('add-invoice-note', '_nonce'); |
|
| 104 | 104 | |
| 105 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
| 105 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
| 106 | 106 | die(-1); |
| 107 | 107 | } |
| 108 | 108 | |
| 109 | - $post_id = absint( $_POST['post_id'] ); |
|
| 110 | - $note = wp_kses_post( trim( stripslashes( $_POST['note'] ) ) ); |
|
| 111 | - $note_type = sanitize_text_field( $_POST['note_type'] ); |
|
| 109 | + $post_id = absint($_POST['post_id']); |
|
| 110 | + $note = wp_kses_post(trim(stripslashes($_POST['note']))); |
|
| 111 | + $note_type = sanitize_text_field($_POST['note_type']); |
|
| 112 | 112 | |
| 113 | 113 | $is_customer_note = $note_type == 'customer' ? 1 : 0; |
| 114 | 114 | |
| 115 | - if ( $post_id > 0 ) { |
|
| 116 | - $note_id = wpinv_insert_payment_note( $post_id, $note, $is_customer_note ); |
|
| 115 | + if ($post_id > 0) { |
|
| 116 | + $note_id = wpinv_insert_payment_note($post_id, $note, $is_customer_note); |
|
| 117 | 117 | |
| 118 | - if ( $note_id > 0 && !is_wp_error( $note_id ) ) { |
|
| 119 | - wpinv_get_invoice_note_line_item( $note_id ); |
|
| 118 | + if ($note_id > 0 && !is_wp_error($note_id)) { |
|
| 119 | + wpinv_get_invoice_note_line_item($note_id); |
|
| 120 | 120 | } |
| 121 | 121 | } |
| 122 | 122 | |
@@ -124,16 +124,16 @@ discard block |
||
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | public static function delete_note() { |
| 127 | - check_ajax_referer( 'delete-invoice-note', '_nonce' ); |
|
| 127 | + check_ajax_referer('delete-invoice-note', '_nonce'); |
|
| 128 | 128 | |
| 129 | - if ( !wpinv_current_user_can_manage_invoicing() ) { |
|
| 129 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
| 130 | 130 | die(-1); |
| 131 | 131 | } |
| 132 | 132 | |
| 133 | - $note_id = (int)$_POST['note_id']; |
|
| 133 | + $note_id = (int) $_POST['note_id']; |
|
| 134 | 134 | |
| 135 | - if ( $note_id > 0 ) { |
|
| 136 | - wp_delete_comment( $note_id, true ); |
|
| 135 | + if ($note_id > 0) { |
|
| 136 | + wp_delete_comment($note_id, true); |
|
| 137 | 137 | } |
| 138 | 138 | |
| 139 | 139 | die(); |
@@ -146,8 +146,8 @@ discard block |
||
| 146 | 146 | } |
| 147 | 147 | |
| 148 | 148 | public static function checkout() { |
| 149 | - if ( ! defined( 'WPINV_CHECKOUT' ) ) { |
|
| 150 | - define( 'WPINV_CHECKOUT', true ); |
|
| 149 | + if (!defined('WPINV_CHECKOUT')) { |
|
| 150 | + define('WPINV_CHECKOUT', true); |
|
| 151 | 151 | } |
| 152 | 152 | |
| 153 | 153 | wpinv_process_checkout(); |
@@ -156,53 +156,53 @@ discard block |
||
| 156 | 156 | |
| 157 | 157 | public static function add_invoice_item() { |
| 158 | 158 | global $wpi_userID, $wpinv_ip_address_country; |
| 159 | - check_ajax_referer( 'invoice-item', '_nonce' ); |
|
| 160 | - if ( !wpinv_current_user_can_manage_invoicing() ) { |
|
| 159 | + check_ajax_referer('invoice-item', '_nonce'); |
|
| 160 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
| 161 | 161 | die(-1); |
| 162 | 162 | } |
| 163 | 163 | |
| 164 | - $item_id = sanitize_text_field( $_POST['item_id'] ); |
|
| 165 | - $invoice_id = absint( $_POST['invoice_id'] ); |
|
| 164 | + $item_id = sanitize_text_field($_POST['item_id']); |
|
| 165 | + $invoice_id = absint($_POST['invoice_id']); |
|
| 166 | 166 | |
| 167 | - if ( !is_numeric( $invoice_id ) || !is_numeric( $item_id ) ) { |
|
| 167 | + if (!is_numeric($invoice_id) || !is_numeric($item_id)) { |
|
| 168 | 168 | die(); |
| 169 | 169 | } |
| 170 | 170 | |
| 171 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
| 172 | - if ( empty( $invoice ) ) { |
|
| 171 | + $invoice = wpinv_get_invoice($invoice_id); |
|
| 172 | + if (empty($invoice)) { |
|
| 173 | 173 | die(); |
| 174 | 174 | } |
| 175 | 175 | |
| 176 | - if ( $invoice->is_paid() || $invoice->is_refunded() ) { |
|
| 176 | + if ($invoice->is_paid() || $invoice->is_refunded()) { |
|
| 177 | 177 | die(); // Don't allow modify items for paid invoice. |
| 178 | 178 | } |
| 179 | 179 | |
| 180 | - if ( !empty( $_POST['user_id'] ) ) { |
|
| 181 | - $wpi_userID = absint( $_POST['user_id'] ); |
|
| 180 | + if (!empty($_POST['user_id'])) { |
|
| 181 | + $wpi_userID = absint($_POST['user_id']); |
|
| 182 | 182 | } |
| 183 | 183 | |
| 184 | - $item = new WPInv_Item( $item_id ); |
|
| 185 | - if ( !( !empty( $item ) && $item->post_type == 'wpi_item' ) ) { |
|
| 184 | + $item = new WPInv_Item($item_id); |
|
| 185 | + if (!(!empty($item) && $item->post_type == 'wpi_item')) { |
|
| 186 | 186 | die(); |
| 187 | 187 | } |
| 188 | 188 | |
| 189 | 189 | // Validate item before adding to invoice because recurring item must be paid individually. |
| 190 | - if ( !empty( $invoice->cart_details ) ) { |
|
| 190 | + if (!empty($invoice->cart_details)) { |
|
| 191 | 191 | $valid = true; |
| 192 | 192 | |
| 193 | - if ( $recurring_item = $invoice->get_recurring() ) { |
|
| 194 | - if ( $recurring_item != $item_id ) { |
|
| 193 | + if ($recurring_item = $invoice->get_recurring()) { |
|
| 194 | + if ($recurring_item != $item_id) { |
|
| 195 | 195 | $valid = false; |
| 196 | 196 | } |
| 197 | - } else if ( wpinv_is_recurring_item( $item_id ) ) { |
|
| 197 | + } else if (wpinv_is_recurring_item($item_id)) { |
|
| 198 | 198 | $valid = false; |
| 199 | 199 | } |
| 200 | 200 | |
| 201 | - if ( !$valid ) { |
|
| 201 | + if (!$valid) { |
|
| 202 | 202 | $response = array(); |
| 203 | 203 | $response['success'] = false; |
| 204 | - $response['msg'] = __( 'You can not add item because recurring item must be paid individually!', 'invoicing' ); |
|
| 205 | - wp_send_json( $response ); |
|
| 204 | + $response['msg'] = __('You can not add item because recurring item must be paid individually!', 'invoicing'); |
|
| 205 | + wp_send_json($response); |
|
| 206 | 206 | } |
| 207 | 207 | } |
| 208 | 208 | |
@@ -210,11 +210,11 @@ discard block |
||
| 210 | 210 | |
| 211 | 211 | $data = array(); |
| 212 | 212 | $data['invoice_id'] = $invoice_id; |
| 213 | - $data['cart_discounts'] = $invoice->get_discounts( true ); |
|
| 213 | + $data['cart_discounts'] = $invoice->get_discounts(true); |
|
| 214 | 214 | |
| 215 | - wpinv_set_checkout_session( $data ); |
|
| 215 | + wpinv_set_checkout_session($data); |
|
| 216 | 216 | |
| 217 | - $quantity = wpinv_item_quantities_enabled() && !empty($_POST['qty']) && (int)$_POST['qty'] > 0 ? (int)$_POST['qty'] : 1; |
|
| 217 | + $quantity = wpinv_item_quantities_enabled() && !empty($_POST['qty']) && (int) $_POST['qty'] > 0 ? (int) $_POST['qty'] : 1; |
|
| 218 | 218 | |
| 219 | 219 | $args = array( |
| 220 | 220 | 'id' => $item_id, |
@@ -227,21 +227,21 @@ discard block |
||
| 227 | 227 | 'fees' => array() |
| 228 | 228 | ); |
| 229 | 229 | |
| 230 | - $invoice->add_item( $item_id, $args ); |
|
| 230 | + $invoice->add_item($item_id, $args); |
|
| 231 | 231 | $invoice->save(); |
| 232 | 232 | |
| 233 | - if ( empty( $_POST['country'] ) ) { |
|
| 233 | + if (empty($_POST['country'])) { |
|
| 234 | 234 | $_POST['country'] = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country(); |
| 235 | 235 | } |
| 236 | - if ( empty( $_POST['state'] ) ) { |
|
| 236 | + if (empty($_POST['state'])) { |
|
| 237 | 237 | $_POST['state'] = $invoice->state; |
| 238 | 238 | } |
| 239 | 239 | |
| 240 | - $invoice->country = sanitize_text_field( $_POST['country'] ); |
|
| 241 | - $invoice->state = sanitize_text_field( $_POST['state'] ); |
|
| 240 | + $invoice->country = sanitize_text_field($_POST['country']); |
|
| 241 | + $invoice->state = sanitize_text_field($_POST['state']); |
|
| 242 | 242 | |
| 243 | - $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) ); |
|
| 244 | - $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) ); |
|
| 243 | + $invoice->set('country', sanitize_text_field($_POST['country'])); |
|
| 244 | + $invoice->set('state', sanitize_text_field($_POST['state'])); |
|
| 245 | 245 | |
| 246 | 246 | $wpinv_ip_address_country = $invoice->country; |
| 247 | 247 | |
@@ -249,7 +249,7 @@ discard block |
||
| 249 | 249 | |
| 250 | 250 | $response = array(); |
| 251 | 251 | $response['success'] = true; |
| 252 | - $response['data']['items'] = wpinv_admin_get_line_items( $invoice ); |
|
| 252 | + $response['data']['items'] = wpinv_admin_get_line_items($invoice); |
|
| 253 | 253 | $response['data']['subtotal'] = $invoice->get_subtotal(); |
| 254 | 254 | $response['data']['subtotalf'] = $invoice->get_subtotal(true); |
| 255 | 255 | $response['data']['tax'] = $invoice->get_tax(); |
@@ -261,41 +261,41 @@ discard block |
||
| 261 | 261 | |
| 262 | 262 | wpinv_set_checkout_session($checkout_session); |
| 263 | 263 | |
| 264 | - wp_send_json( $response ); |
|
| 264 | + wp_send_json($response); |
|
| 265 | 265 | } |
| 266 | 266 | |
| 267 | 267 | |
| 268 | 268 | public static function remove_invoice_item() { |
| 269 | 269 | global $wpi_userID, $wpinv_ip_address_country; |
| 270 | 270 | |
| 271 | - check_ajax_referer( 'invoice-item', '_nonce' ); |
|
| 272 | - if ( !wpinv_current_user_can_manage_invoicing() ) { |
|
| 271 | + check_ajax_referer('invoice-item', '_nonce'); |
|
| 272 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
| 273 | 273 | die(-1); |
| 274 | 274 | } |
| 275 | 275 | |
| 276 | - $item_id = sanitize_text_field( $_POST['item_id'] ); |
|
| 277 | - $invoice_id = absint( $_POST['invoice_id'] ); |
|
| 278 | - $cart_index = isset( $_POST['index'] ) && $_POST['index'] >= 0 ? $_POST['index'] : false; |
|
| 276 | + $item_id = sanitize_text_field($_POST['item_id']); |
|
| 277 | + $invoice_id = absint($_POST['invoice_id']); |
|
| 278 | + $cart_index = isset($_POST['index']) && $_POST['index'] >= 0 ? $_POST['index'] : false; |
|
| 279 | 279 | |
| 280 | - if ( !is_numeric( $invoice_id ) || !is_numeric( $item_id ) ) { |
|
| 280 | + if (!is_numeric($invoice_id) || !is_numeric($item_id)) { |
|
| 281 | 281 | die(); |
| 282 | 282 | } |
| 283 | 283 | |
| 284 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
| 285 | - if ( empty( $invoice ) ) { |
|
| 284 | + $invoice = wpinv_get_invoice($invoice_id); |
|
| 285 | + if (empty($invoice)) { |
|
| 286 | 286 | die(); |
| 287 | 287 | } |
| 288 | 288 | |
| 289 | - if ( $invoice->is_paid() || $invoice->is_refunded() ) { |
|
| 289 | + if ($invoice->is_paid() || $invoice->is_refunded()) { |
|
| 290 | 290 | die(); // Don't allow modify items for paid invoice. |
| 291 | 291 | } |
| 292 | 292 | |
| 293 | - if ( !empty( $_POST['user_id'] ) ) { |
|
| 294 | - $wpi_userID = absint( $_POST['user_id'] ); |
|
| 293 | + if (!empty($_POST['user_id'])) { |
|
| 294 | + $wpi_userID = absint($_POST['user_id']); |
|
| 295 | 295 | } |
| 296 | 296 | |
| 297 | - $item = new WPInv_Item( $item_id ); |
|
| 298 | - if ( !( !empty( $item ) && $item->post_type == 'wpi_item' ) ) { |
|
| 297 | + $item = new WPInv_Item($item_id); |
|
| 298 | + if (!(!empty($item) && $item->post_type == 'wpi_item')) { |
|
| 299 | 299 | die(); |
| 300 | 300 | } |
| 301 | 301 | |
@@ -303,9 +303,9 @@ discard block |
||
| 303 | 303 | |
| 304 | 304 | $data = array(); |
| 305 | 305 | $data['invoice_id'] = $invoice_id; |
| 306 | - $data['cart_discounts'] = $invoice->get_discounts( true ); |
|
| 306 | + $data['cart_discounts'] = $invoice->get_discounts(true); |
|
| 307 | 307 | |
| 308 | - wpinv_set_checkout_session( $data ); |
|
| 308 | + wpinv_set_checkout_session($data); |
|
| 309 | 309 | |
| 310 | 310 | $args = array( |
| 311 | 311 | 'id' => $item_id, |
@@ -313,21 +313,21 @@ discard block |
||
| 313 | 313 | 'cart_index' => $cart_index |
| 314 | 314 | ); |
| 315 | 315 | |
| 316 | - $invoice->remove_item( $item_id, $args ); |
|
| 316 | + $invoice->remove_item($item_id, $args); |
|
| 317 | 317 | $invoice->save(); |
| 318 | 318 | |
| 319 | - if ( empty( $_POST['country'] ) ) { |
|
| 319 | + if (empty($_POST['country'])) { |
|
| 320 | 320 | $_POST['country'] = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country(); |
| 321 | 321 | } |
| 322 | - if ( empty( $_POST['state'] ) ) { |
|
| 322 | + if (empty($_POST['state'])) { |
|
| 323 | 323 | $_POST['state'] = $invoice->state; |
| 324 | 324 | } |
| 325 | 325 | |
| 326 | - $invoice->country = sanitize_text_field( $_POST['country'] ); |
|
| 327 | - $invoice->state = sanitize_text_field( $_POST['state'] ); |
|
| 326 | + $invoice->country = sanitize_text_field($_POST['country']); |
|
| 327 | + $invoice->state = sanitize_text_field($_POST['state']); |
|
| 328 | 328 | |
| 329 | - $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) ); |
|
| 330 | - $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) ); |
|
| 329 | + $invoice->set('country', sanitize_text_field($_POST['country'])); |
|
| 330 | + $invoice->set('state', sanitize_text_field($_POST['state'])); |
|
| 331 | 331 | |
| 332 | 332 | $wpinv_ip_address_country = $invoice->country; |
| 333 | 333 | |
@@ -335,7 +335,7 @@ discard block |
||
| 335 | 335 | |
| 336 | 336 | $response = array(); |
| 337 | 337 | $response['success'] = true; |
| 338 | - $response['data']['items'] = wpinv_admin_get_line_items( $invoice ); |
|
| 338 | + $response['data']['items'] = wpinv_admin_get_line_items($invoice); |
|
| 339 | 339 | $response['data']['subtotal'] = $invoice->get_subtotal(); |
| 340 | 340 | $response['data']['subtotalf'] = $invoice->get_subtotal(true); |
| 341 | 341 | $response['data']['tax'] = $invoice->get_tax(); |
@@ -347,55 +347,55 @@ discard block |
||
| 347 | 347 | |
| 348 | 348 | wpinv_set_checkout_session($checkout_session); |
| 349 | 349 | |
| 350 | - wp_send_json( $response ); |
|
| 350 | + wp_send_json($response); |
|
| 351 | 351 | } |
| 352 | 352 | |
| 353 | 353 | public static function create_invoice_item() { |
| 354 | - check_ajax_referer( 'invoice-item', '_nonce' ); |
|
| 355 | - if ( !wpinv_current_user_can_manage_invoicing() ) { |
|
| 354 | + check_ajax_referer('invoice-item', '_nonce'); |
|
| 355 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
| 356 | 356 | die(-1); |
| 357 | 357 | } |
| 358 | 358 | |
| 359 | - $invoice_id = absint( $_POST['invoice_id'] ); |
|
| 359 | + $invoice_id = absint($_POST['invoice_id']); |
|
| 360 | 360 | |
| 361 | 361 | // Find the item |
| 362 | - if ( !is_numeric( $invoice_id ) ) { |
|
| 362 | + if (!is_numeric($invoice_id)) { |
|
| 363 | 363 | die(); |
| 364 | 364 | } |
| 365 | 365 | |
| 366 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
| 367 | - if ( empty( $invoice ) ) { |
|
| 366 | + $invoice = wpinv_get_invoice($invoice_id); |
|
| 367 | + if (empty($invoice)) { |
|
| 368 | 368 | die(); |
| 369 | 369 | } |
| 370 | 370 | |
| 371 | 371 | // Validate item before adding to invoice because recurring item must be paid individually. |
| 372 | - if ( !empty( $invoice->cart_details ) && $invoice->get_recurring() ) { |
|
| 372 | + if (!empty($invoice->cart_details) && $invoice->get_recurring()) { |
|
| 373 | 373 | $response = array(); |
| 374 | 374 | $response['success'] = false; |
| 375 | - $response['msg'] = __( 'You can not add item because recurring item must be paid individually!', 'invoicing' ); |
|
| 376 | - wp_send_json( $response ); |
|
| 375 | + $response['msg'] = __('You can not add item because recurring item must be paid individually!', 'invoicing'); |
|
| 376 | + wp_send_json($response); |
|
| 377 | 377 | } |
| 378 | 378 | |
| 379 | - $save_item = wp_unslash( $_POST['_wpinv_quick'] ); |
|
| 379 | + $save_item = wp_unslash($_POST['_wpinv_quick']); |
|
| 380 | 380 | |
| 381 | 381 | $meta = array(); |
| 382 | 382 | $meta['type'] = !empty($save_item['type']) ? sanitize_text_field($save_item['type']) : 'custom'; |
| 383 | - $meta['price'] = !empty($save_item['price']) ? wpinv_sanitize_amount( $save_item['price'] ) : 0; |
|
| 383 | + $meta['price'] = !empty($save_item['price']) ? wpinv_sanitize_amount($save_item['price']) : 0; |
|
| 384 | 384 | $meta['vat_rule'] = !empty($save_item['vat_rule']) ? sanitize_text_field($save_item['vat_rule']) : 'digital'; |
| 385 | 385 | $meta['vat_class'] = !empty($save_item['vat_class']) ? sanitize_text_field($save_item['vat_class']) : '_standard'; |
| 386 | 386 | |
| 387 | 387 | $data = array(); |
| 388 | 388 | $data['post_title'] = sanitize_text_field($save_item['name']); |
| 389 | 389 | $data['post_status'] = 'publish'; |
| 390 | - $data['post_excerpt'] = ! empty( $save_item['excerpt'] ) ? wp_kses_post( $save_item['excerpt'] ) : ''; |
|
| 390 | + $data['post_excerpt'] = !empty($save_item['excerpt']) ? wp_kses_post($save_item['excerpt']) : ''; |
|
| 391 | 391 | $data['meta'] = $meta; |
| 392 | 392 | |
| 393 | 393 | $item = new WPInv_Item(); |
| 394 | - $item->create( $data ); |
|
| 394 | + $item->create($data); |
|
| 395 | 395 | |
| 396 | - if ( !empty( $item ) ) { |
|
| 396 | + if (!empty($item)) { |
|
| 397 | 397 | $_POST['item_id'] = $item->ID; |
| 398 | - $_POST['qty'] = !empty($save_item['qty']) && $save_item['qty'] > 0 ? (int)$save_item['qty'] : 1; |
|
| 398 | + $_POST['qty'] = !empty($save_item['qty']) && $save_item['qty'] > 0 ? (int) $save_item['qty'] : 1; |
|
| 399 | 399 | |
| 400 | 400 | self::add_invoice_item(); |
| 401 | 401 | } |
@@ -403,15 +403,15 @@ discard block |
||
| 403 | 403 | } |
| 404 | 404 | |
| 405 | 405 | public static function get_billing_details() { |
| 406 | - check_ajax_referer( 'get-billing-details', '_nonce' ); |
|
| 406 | + check_ajax_referer('get-billing-details', '_nonce'); |
|
| 407 | 407 | |
| 408 | - if ( !wpinv_current_user_can_manage_invoicing() ) { |
|
| 408 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
| 409 | 409 | die(-1); |
| 410 | 410 | } |
| 411 | 411 | |
| 412 | - $user_id = (int)$_POST['user_id']; |
|
| 412 | + $user_id = (int) $_POST['user_id']; |
|
| 413 | 413 | $billing_details = wpinv_get_user_address($user_id); |
| 414 | - $billing_details = apply_filters( 'wpinv_fill_billing_details', $billing_details, $user_id ); |
|
| 414 | + $billing_details = apply_filters('wpinv_fill_billing_details', $billing_details, $user_id); |
|
| 415 | 415 | |
| 416 | 416 | if (isset($billing_details['user_id'])) { |
| 417 | 417 | unset($billing_details['user_id']); |
@@ -425,20 +425,20 @@ discard block |
||
| 425 | 425 | $response['success'] = true; |
| 426 | 426 | $response['data']['billing_details'] = $billing_details; |
| 427 | 427 | |
| 428 | - wp_send_json( $response ); |
|
| 428 | + wp_send_json($response); |
|
| 429 | 429 | } |
| 430 | 430 | |
| 431 | 431 | public static function admin_recalculate_totals() { |
| 432 | 432 | global $wpi_userID, $wpinv_ip_address_country; |
| 433 | 433 | |
| 434 | - check_ajax_referer( 'wpinv-nonce', '_nonce' ); |
|
| 435 | - if ( !wpinv_current_user_can_manage_invoicing() ) { |
|
| 434 | + check_ajax_referer('wpinv-nonce', '_nonce'); |
|
| 435 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
| 436 | 436 | die(-1); |
| 437 | 437 | } |
| 438 | 438 | |
| 439 | - $invoice_id = absint( $_POST['invoice_id'] ); |
|
| 440 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
| 441 | - if ( empty( $invoice ) ) { |
|
| 439 | + $invoice_id = absint($_POST['invoice_id']); |
|
| 440 | + $invoice = wpinv_get_invoice($invoice_id); |
|
| 441 | + if (empty($invoice)) { |
|
| 442 | 442 | die(); |
| 443 | 443 | } |
| 444 | 444 | |
@@ -446,29 +446,29 @@ discard block |
||
| 446 | 446 | |
| 447 | 447 | $data = array(); |
| 448 | 448 | $data['invoice_id'] = $invoice_id; |
| 449 | - $data['cart_discounts'] = $invoice->get_discounts( true ); |
|
| 449 | + $data['cart_discounts'] = $invoice->get_discounts(true); |
|
| 450 | 450 | |
| 451 | - wpinv_set_checkout_session( $data ); |
|
| 451 | + wpinv_set_checkout_session($data); |
|
| 452 | 452 | |
| 453 | - if ( !empty( $_POST['user_id'] ) ) { |
|
| 454 | - $wpi_userID = absint( $_POST['user_id'] ); |
|
| 453 | + if (!empty($_POST['user_id'])) { |
|
| 454 | + $wpi_userID = absint($_POST['user_id']); |
|
| 455 | 455 | } |
| 456 | 456 | |
| 457 | - if ( empty( $_POST['country'] ) ) { |
|
| 457 | + if (empty($_POST['country'])) { |
|
| 458 | 458 | $_POST['country'] = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country(); |
| 459 | 459 | } |
| 460 | 460 | |
| 461 | 461 | $disable_taxes = 0; |
| 462 | - if ( ! empty( $_POST['disable_taxes'] ) ) { |
|
| 462 | + if (!empty($_POST['disable_taxes'])) { |
|
| 463 | 463 | $disable_taxes = 1; |
| 464 | 464 | } |
| 465 | - $invoice->set( 'disable_taxes', $disable_taxes ); |
|
| 465 | + $invoice->set('disable_taxes', $disable_taxes); |
|
| 466 | 466 | |
| 467 | - $invoice->country = sanitize_text_field( $_POST['country'] ); |
|
| 468 | - $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) ); |
|
| 469 | - if ( isset( $_POST['state'] ) ) { |
|
| 470 | - $invoice->state = sanitize_text_field( $_POST['state'] ); |
|
| 471 | - $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) ); |
|
| 467 | + $invoice->country = sanitize_text_field($_POST['country']); |
|
| 468 | + $invoice->set('country', sanitize_text_field($_POST['country'])); |
|
| 469 | + if (isset($_POST['state'])) { |
|
| 470 | + $invoice->state = sanitize_text_field($_POST['state']); |
|
| 471 | + $invoice->set('state', sanitize_text_field($_POST['state'])); |
|
| 472 | 472 | } |
| 473 | 473 | |
| 474 | 474 | $wpinv_ip_address_country = $invoice->country; |
@@ -477,7 +477,7 @@ discard block |
||
| 477 | 477 | |
| 478 | 478 | $response = array(); |
| 479 | 479 | $response['success'] = true; |
| 480 | - $response['data']['items'] = wpinv_admin_get_line_items( $invoice ); |
|
| 480 | + $response['data']['items'] = wpinv_admin_get_line_items($invoice); |
|
| 481 | 481 | $response['data']['subtotal'] = $invoice->get_subtotal(); |
| 482 | 482 | $response['data']['subtotalf'] = $invoice->get_subtotal(true); |
| 483 | 483 | $response['data']['tax'] = $invoice->get_tax(); |
@@ -489,25 +489,25 @@ discard block |
||
| 489 | 489 | |
| 490 | 490 | wpinv_set_checkout_session($checkout_session); |
| 491 | 491 | |
| 492 | - wp_send_json( $response ); |
|
| 492 | + wp_send_json($response); |
|
| 493 | 493 | } |
| 494 | 494 | |
| 495 | 495 | public static function admin_apply_discount() { |
| 496 | 496 | global $wpi_userID; |
| 497 | 497 | |
| 498 | - check_ajax_referer( 'wpinv-nonce', '_nonce' ); |
|
| 499 | - if ( !wpinv_current_user_can_manage_invoicing() ) { |
|
| 498 | + check_ajax_referer('wpinv-nonce', '_nonce'); |
|
| 499 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
| 500 | 500 | die(-1); |
| 501 | 501 | } |
| 502 | 502 | |
| 503 | - $invoice_id = absint( $_POST['invoice_id'] ); |
|
| 504 | - $discount_code = sanitize_text_field( $_POST['code'] ); |
|
| 505 | - if ( empty( $invoice_id ) || empty( $discount_code ) ) { |
|
| 503 | + $invoice_id = absint($_POST['invoice_id']); |
|
| 504 | + $discount_code = sanitize_text_field($_POST['code']); |
|
| 505 | + if (empty($invoice_id) || empty($discount_code)) { |
|
| 506 | 506 | die(); |
| 507 | 507 | } |
| 508 | 508 | |
| 509 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
| 510 | - if ( empty( $invoice ) || ( !empty( $invoice ) && ( $invoice->is_paid() || $invoice->is_refunded() ) ) ) { |
|
| 509 | + $invoice = wpinv_get_invoice($invoice_id); |
|
| 510 | + if (empty($invoice) || (!empty($invoice) && ($invoice->is_paid() || $invoice->is_refunded()))) { |
|
| 511 | 511 | die(); |
| 512 | 512 | } |
| 513 | 513 | |
@@ -515,49 +515,49 @@ discard block |
||
| 515 | 515 | |
| 516 | 516 | $data = array(); |
| 517 | 517 | $data['invoice_id'] = $invoice_id; |
| 518 | - $data['cart_discounts'] = $invoice->get_discounts( true ); |
|
| 518 | + $data['cart_discounts'] = $invoice->get_discounts(true); |
|
| 519 | 519 | |
| 520 | - wpinv_set_checkout_session( $data ); |
|
| 520 | + wpinv_set_checkout_session($data); |
|
| 521 | 521 | |
| 522 | 522 | $response = array(); |
| 523 | 523 | $response['success'] = false; |
| 524 | - $response['msg'] = __( 'This discount is invalid.', 'invoicing' ); |
|
| 524 | + $response['msg'] = __('This discount is invalid.', 'invoicing'); |
|
| 525 | 525 | $response['data']['code'] = $discount_code; |
| 526 | 526 | |
| 527 | - if ( wpinv_is_discount_valid( $discount_code, $invoice->get_user_id() ) ) { |
|
| 528 | - $discounts = wpinv_set_cart_discount( $discount_code ); |
|
| 527 | + if (wpinv_is_discount_valid($discount_code, $invoice->get_user_id())) { |
|
| 528 | + $discounts = wpinv_set_cart_discount($discount_code); |
|
| 529 | 529 | |
| 530 | 530 | $response['success'] = true; |
| 531 | - $response['msg'] = __( 'Discount has been applied successfully.', 'invoicing' ); |
|
| 532 | - } else { |
|
| 531 | + $response['msg'] = __('Discount has been applied successfully.', 'invoicing'); |
|
| 532 | + } else { |
|
| 533 | 533 | $errors = wpinv_get_errors(); |
| 534 | - if ( !empty( $errors['wpinv-discount-error'] ) ) { |
|
| 534 | + if (!empty($errors['wpinv-discount-error'])) { |
|
| 535 | 535 | $response['msg'] = $errors['wpinv-discount-error']; |
| 536 | 536 | } |
| 537 | - wpinv_unset_error( 'wpinv-discount-error' ); |
|
| 537 | + wpinv_unset_error('wpinv-discount-error'); |
|
| 538 | 538 | } |
| 539 | 539 | |
| 540 | 540 | wpinv_set_checkout_session($checkout_session); |
| 541 | 541 | |
| 542 | - wp_send_json( $response ); |
|
| 542 | + wp_send_json($response); |
|
| 543 | 543 | } |
| 544 | 544 | |
| 545 | 545 | public static function admin_remove_discount() { |
| 546 | 546 | global $wpi_userID; |
| 547 | 547 | |
| 548 | - check_ajax_referer( 'wpinv-nonce', '_nonce' ); |
|
| 549 | - if ( !wpinv_current_user_can_manage_invoicing() ) { |
|
| 548 | + check_ajax_referer('wpinv-nonce', '_nonce'); |
|
| 549 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
| 550 | 550 | die(-1); |
| 551 | 551 | } |
| 552 | 552 | |
| 553 | - $invoice_id = absint( $_POST['invoice_id'] ); |
|
| 554 | - $discount_code = sanitize_text_field( $_POST['code'] ); |
|
| 555 | - if ( empty( $invoice_id ) || empty( $discount_code ) ) { |
|
| 553 | + $invoice_id = absint($_POST['invoice_id']); |
|
| 554 | + $discount_code = sanitize_text_field($_POST['code']); |
|
| 555 | + if (empty($invoice_id) || empty($discount_code)) { |
|
| 556 | 556 | die(); |
| 557 | 557 | } |
| 558 | 558 | |
| 559 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
| 560 | - if ( empty( $invoice ) || ( !empty( $invoice ) && ( $invoice->is_paid() || $invoice->is_refunded() ) ) ) { |
|
| 559 | + $invoice = wpinv_get_invoice($invoice_id); |
|
| 560 | + if (empty($invoice) || (!empty($invoice) && ($invoice->is_paid() || $invoice->is_refunded()))) { |
|
| 561 | 561 | die(); |
| 562 | 562 | } |
| 563 | 563 | |
@@ -565,38 +565,38 @@ discard block |
||
| 565 | 565 | |
| 566 | 566 | $data = array(); |
| 567 | 567 | $data['invoice_id'] = $invoice_id; |
| 568 | - $data['cart_discounts'] = $invoice->get_discounts( true ); |
|
| 568 | + $data['cart_discounts'] = $invoice->get_discounts(true); |
|
| 569 | 569 | |
| 570 | - wpinv_set_checkout_session( $data ); |
|
| 570 | + wpinv_set_checkout_session($data); |
|
| 571 | 571 | |
| 572 | 572 | $response = array(); |
| 573 | 573 | $response['success'] = false; |
| 574 | 574 | $response['msg'] = NULL; |
| 575 | 575 | |
| 576 | - $discounts = wpinv_unset_cart_discount( $discount_code ); |
|
| 576 | + $discounts = wpinv_unset_cart_discount($discount_code); |
|
| 577 | 577 | $response['success'] = true; |
| 578 | - $response['msg'] = __( 'Discount has been removed successfully.', 'invoicing' ); |
|
| 578 | + $response['msg'] = __('Discount has been removed successfully.', 'invoicing'); |
|
| 579 | 579 | |
| 580 | 580 | wpinv_set_checkout_session($checkout_session); |
| 581 | 581 | |
| 582 | - wp_send_json( $response ); |
|
| 582 | + wp_send_json($response); |
|
| 583 | 583 | } |
| 584 | 584 | |
| 585 | 585 | public static function check_email() { |
| 586 | - check_ajax_referer( 'wpinv-nonce', '_nonce' ); |
|
| 587 | - if ( !wpinv_current_user_can_manage_invoicing() ) { |
|
| 586 | + check_ajax_referer('wpinv-nonce', '_nonce'); |
|
| 587 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
| 588 | 588 | die(-1); |
| 589 | 589 | } |
| 590 | 590 | |
| 591 | - $email = sanitize_text_field( $_POST['email'] ); |
|
| 591 | + $email = sanitize_text_field($_POST['email']); |
|
| 592 | 592 | |
| 593 | 593 | $response = array(); |
| 594 | - if ( is_email( $email ) && email_exists( $email ) && $user_data = get_user_by( 'email', $email ) ) { |
|
| 594 | + if (is_email($email) && email_exists($email) && $user_data = get_user_by('email', $email)) { |
|
| 595 | 595 | $user_id = $user_data->ID; |
| 596 | 596 | $user_login = $user_data->user_login; |
| 597 | 597 | $display_name = $user_data->display_name ? $user_data->display_name : $user_login; |
| 598 | 598 | $billing_details = wpinv_get_user_address($user_id); |
| 599 | - $billing_details = apply_filters( 'wpinv_fill_billing_details', $billing_details, $user_id ); |
|
| 599 | + $billing_details = apply_filters('wpinv_fill_billing_details', $billing_details, $user_id); |
|
| 600 | 600 | |
| 601 | 601 | if (isset($billing_details['user_id'])) { |
| 602 | 602 | unset($billing_details['user_id']); |
@@ -612,54 +612,54 @@ discard block |
||
| 612 | 612 | $response['data']['billing_details'] = $billing_details; |
| 613 | 613 | } |
| 614 | 614 | |
| 615 | - wp_send_json( $response ); |
|
| 615 | + wp_send_json($response); |
|
| 616 | 616 | } |
| 617 | 617 | |
| 618 | 618 | public static function run_tool() { |
| 619 | - check_ajax_referer( 'wpinv-nonce', '_nonce' ); |
|
| 620 | - if ( !wpinv_current_user_can_manage_invoicing() ) { |
|
| 619 | + check_ajax_referer('wpinv-nonce', '_nonce'); |
|
| 620 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
| 621 | 621 | die(-1); |
| 622 | 622 | } |
| 623 | 623 | |
| 624 | - $tool = sanitize_text_field( $_POST['tool'] ); |
|
| 624 | + $tool = sanitize_text_field($_POST['tool']); |
|
| 625 | 625 | |
| 626 | - do_action( 'wpinv_run_tool' ); |
|
| 626 | + do_action('wpinv_run_tool'); |
|
| 627 | 627 | |
| 628 | - if ( !empty( $tool ) ) { |
|
| 629 | - do_action( 'wpinv_tool_' . $tool ); |
|
| 628 | + if (!empty($tool)) { |
|
| 629 | + do_action('wpinv_tool_' . $tool); |
|
| 630 | 630 | } |
| 631 | 631 | } |
| 632 | 632 | |
| 633 | 633 | public static function apply_discount() { |
| 634 | 634 | global $wpi_userID; |
| 635 | 635 | |
| 636 | - check_ajax_referer( 'wpinv-nonce', '_nonce' ); |
|
| 636 | + check_ajax_referer('wpinv-nonce', '_nonce'); |
|
| 637 | 637 | |
| 638 | 638 | $response = array(); |
| 639 | 639 | |
| 640 | - if ( isset( $_POST['code'] ) ) { |
|
| 641 | - $discount_code = sanitize_text_field( $_POST['code'] ); |
|
| 640 | + if (isset($_POST['code'])) { |
|
| 641 | + $discount_code = sanitize_text_field($_POST['code']); |
|
| 642 | 642 | |
| 643 | 643 | $response['success'] = false; |
| 644 | 644 | $response['msg'] = ''; |
| 645 | 645 | $response['data']['code'] = $discount_code; |
| 646 | 646 | |
| 647 | 647 | $invoice = wpinv_get_invoice_cart(); |
| 648 | - if ( empty( $invoice->ID ) ) { |
|
| 649 | - $response['msg'] = __( 'Invalid checkout request.', 'invoicing' ); |
|
| 650 | - wp_send_json( $response ); |
|
| 648 | + if (empty($invoice->ID)) { |
|
| 649 | + $response['msg'] = __('Invalid checkout request.', 'invoicing'); |
|
| 650 | + wp_send_json($response); |
|
| 651 | 651 | } |
| 652 | 652 | |
| 653 | 653 | $wpi_userID = $invoice->get_user_id(); |
| 654 | 654 | |
| 655 | - if ( wpinv_is_discount_valid( $discount_code, $wpi_userID ) ) { |
|
| 656 | - $discount = wpinv_get_discount_by_code( $discount_code ); |
|
| 657 | - $discounts = wpinv_set_cart_discount( $discount_code ); |
|
| 658 | - $amount = wpinv_format_discount_rate( wpinv_get_discount_type( $discount->ID ), wpinv_get_discount_amount( $discount->ID ) ); |
|
| 659 | - $total = wpinv_get_cart_total( null, $discounts ); |
|
| 660 | - $cart_totals = wpinv_recalculate_tax( true ); |
|
| 655 | + if (wpinv_is_discount_valid($discount_code, $wpi_userID)) { |
|
| 656 | + $discount = wpinv_get_discount_by_code($discount_code); |
|
| 657 | + $discounts = wpinv_set_cart_discount($discount_code); |
|
| 658 | + $amount = wpinv_format_discount_rate(wpinv_get_discount_type($discount->ID), wpinv_get_discount_amount($discount->ID)); |
|
| 659 | + $total = wpinv_get_cart_total(null, $discounts); |
|
| 660 | + $cart_totals = wpinv_recalculate_tax(true); |
|
| 661 | 661 | |
| 662 | - if ( !empty( $cart_totals ) ) { |
|
| 662 | + if (!empty($cart_totals)) { |
|
| 663 | 663 | $response['success'] = true; |
| 664 | 664 | $response['data'] = $cart_totals; |
| 665 | 665 | $response['data']['code'] = $discount_code; |
@@ -668,29 +668,29 @@ discard block |
||
| 668 | 668 | } |
| 669 | 669 | } else { |
| 670 | 670 | $errors = wpinv_get_errors(); |
| 671 | - $response['msg'] = $errors['wpinv-discount-error']; |
|
| 672 | - wpinv_unset_error( 'wpinv-discount-error' ); |
|
| 671 | + $response['msg'] = $errors['wpinv-discount-error']; |
|
| 672 | + wpinv_unset_error('wpinv-discount-error'); |
|
| 673 | 673 | } |
| 674 | 674 | |
| 675 | 675 | // Allow for custom discount code handling |
| 676 | - $response = apply_filters( 'wpinv_ajax_discount_response', $response ); |
|
| 676 | + $response = apply_filters('wpinv_ajax_discount_response', $response); |
|
| 677 | 677 | } |
| 678 | 678 | |
| 679 | - wp_send_json( $response ); |
|
| 679 | + wp_send_json($response); |
|
| 680 | 680 | } |
| 681 | 681 | |
| 682 | 682 | public static function remove_discount() { |
| 683 | - check_ajax_referer( 'wpinv-nonce', '_nonce' ); |
|
| 683 | + check_ajax_referer('wpinv-nonce', '_nonce'); |
|
| 684 | 684 | |
| 685 | 685 | $response = array(); |
| 686 | 686 | |
| 687 | - if ( isset( $_POST['code'] ) ) { |
|
| 688 | - $discount_code = sanitize_text_field( $_POST['code'] ); |
|
| 689 | - $discounts = wpinv_unset_cart_discount( $discount_code ); |
|
| 690 | - $total = wpinv_get_cart_total( null, $discounts ); |
|
| 691 | - $cart_totals = wpinv_recalculate_tax( true ); |
|
| 687 | + if (isset($_POST['code'])) { |
|
| 688 | + $discount_code = sanitize_text_field($_POST['code']); |
|
| 689 | + $discounts = wpinv_unset_cart_discount($discount_code); |
|
| 690 | + $total = wpinv_get_cart_total(null, $discounts); |
|
| 691 | + $cart_totals = wpinv_recalculate_tax(true); |
|
| 692 | 692 | |
| 693 | - if ( !empty( $cart_totals ) ) { |
|
| 693 | + if (!empty($cart_totals)) { |
|
| 694 | 694 | $response['success'] = true; |
| 695 | 695 | $response['data'] = $cart_totals; |
| 696 | 696 | $response['data']['code'] = $discount_code; |
@@ -699,10 +699,10 @@ discard block |
||
| 699 | 699 | } |
| 700 | 700 | |
| 701 | 701 | // Allow for custom discount code handling |
| 702 | - $response = apply_filters( 'wpinv_ajax_discount_response', $response ); |
|
| 702 | + $response = apply_filters('wpinv_ajax_discount_response', $response); |
|
| 703 | 703 | } |
| 704 | 704 | |
| 705 | - wp_send_json( $response ); |
|
| 705 | + wp_send_json($response); |
|
| 706 | 706 | } |
| 707 | 707 | |
| 708 | 708 | /** |
@@ -711,30 +711,30 @@ discard block |
||
| 711 | 711 | public static function get_payment_form() { |
| 712 | 712 | |
| 713 | 713 | // Check nonce. |
| 714 | - if ( ! isset( $_GET['nonce'] ) || ! wp_verify_nonce( $_GET['nonce'], 'getpaid_ajax_form' ) ) { |
|
| 715 | - _e( 'Error: Reload the page and try again.', 'invoicing' ); |
|
| 714 | + if (!isset($_GET['nonce']) || !wp_verify_nonce($_GET['nonce'], 'getpaid_ajax_form')) { |
|
| 715 | + _e('Error: Reload the page and try again.', 'invoicing'); |
|
| 716 | 716 | exit; |
| 717 | 717 | } |
| 718 | 718 | |
| 719 | 719 | // Is the request set up correctly? |
| 720 | - if ( empty( $_GET['form'] ) && empty( $_GET['item'] ) ) { |
|
| 720 | + if (empty($_GET['form']) && empty($_GET['item'])) { |
|
| 721 | 721 | echo aui()->alert( |
| 722 | 722 | array( |
| 723 | 723 | 'type' => 'warning', |
| 724 | - 'content' => __( 'No payment form or item provided', 'invoicing' ), |
|
| 724 | + 'content' => __('No payment form or item provided', 'invoicing'), |
|
| 725 | 725 | ) |
| 726 | 726 | ); |
| 727 | 727 | exit; |
| 728 | 728 | } |
| 729 | 729 | |
| 730 | 730 | // Payment form or button? |
| 731 | - if ( ! empty( $_GET['form'] ) ) { |
|
| 732 | - echo getpaid_display_payment_form( $_GET['form'] ); |
|
| 733 | - } else if( $_GET['invoice'] ) { |
|
| 734 | - echo getpaid_display_invoice_payment_form( $_GET['invoice'] ); |
|
| 731 | + if (!empty($_GET['form'])) { |
|
| 732 | + echo getpaid_display_payment_form($_GET['form']); |
|
| 733 | + } else if ($_GET['invoice']) { |
|
| 734 | + echo getpaid_display_invoice_payment_form($_GET['invoice']); |
|
| 735 | 735 | } else { |
| 736 | - $items = getpaid_convert_items_to_array( $_GET['item'] ); |
|
| 737 | - echo getpaid_display_item_payment_form( $items ); |
|
| 736 | + $items = getpaid_convert_items_to_array($_GET['item']); |
|
| 737 | + echo getpaid_display_item_payment_form($items); |
|
| 738 | 738 | } |
| 739 | 739 | |
| 740 | 740 | exit; |
@@ -750,72 +750,72 @@ discard block |
||
| 750 | 750 | global $invoicing, $wpi_checkout_id, $cart_total; |
| 751 | 751 | |
| 752 | 752 | // Check nonce. |
| 753 | - if ( ! isset( $_POST['wpinv_payment_form'] ) || ! wp_verify_nonce( $_POST['wpinv_payment_form'], 'wpinv_payment_form' ) ) { |
|
| 754 | - wp_send_json_error( __( 'Security checks failed.', 'invoicing' ) ); |
|
| 753 | + if (!isset($_POST['wpinv_payment_form']) || !wp_verify_nonce($_POST['wpinv_payment_form'], 'wpinv_payment_form')) { |
|
| 754 | + wp_send_json_error(__('Security checks failed.', 'invoicing')); |
|
| 755 | 755 | } |
| 756 | 756 | |
| 757 | 757 | // Prepare submitted data... |
| 758 | - $data = wp_unslash( $_POST ); |
|
| 758 | + $data = wp_unslash($_POST); |
|
| 759 | 759 | |
| 760 | 760 | // ... form fields... |
| 761 | - if ( empty( $data['form_id'] ) || 'publish' != get_post_status( $data['form_id'] ) ) { |
|
| 762 | - wp_send_json_error( __( 'This payment form is no longer active.', 'invoicing' ) ); |
|
| 761 | + if (empty($data['form_id']) || 'publish' != get_post_status($data['form_id'])) { |
|
| 762 | + wp_send_json_error(__('This payment form is no longer active.', 'invoicing')); |
|
| 763 | 763 | } |
| 764 | 764 | |
| 765 | - if ( empty( $data['billing_email'] ) || ! is_email( $data['billing_email'] ) ) { |
|
| 766 | - wp_send_json_error( __( 'Provide a valid billing email.', 'invoicing' ) ); |
|
| 765 | + if (empty($data['billing_email']) || !is_email($data['billing_email'])) { |
|
| 766 | + wp_send_json_error(__('Provide a valid billing email.', 'invoicing')); |
|
| 767 | 767 | } |
| 768 | 768 | |
| 769 | 769 | $prepared = array( |
| 770 | - 'billing_email' => sanitize_email( $data['billing_email'] ), |
|
| 771 | - __( 'Billing Email', 'invoicing' ) => sanitize_email( $data['billing_email'] ), |
|
| 772 | - __( 'Form Id', 'invoicing' ) => absint( $data['form_id'] ), |
|
| 770 | + 'billing_email' => sanitize_email($data['billing_email']), |
|
| 771 | + __('Billing Email', 'invoicing') => sanitize_email($data['billing_email']), |
|
| 772 | + __('Form Id', 'invoicing') => absint($data['form_id']), |
|
| 773 | 773 | ); |
| 774 | 774 | |
| 775 | 775 | // Do we have a discount? |
| 776 | 776 | $discount = 0; |
| 777 | - if ( ! empty( $data['discount'] ) ) { |
|
| 777 | + if (!empty($data['discount'])) { |
|
| 778 | 778 | |
| 779 | 779 | // Validate discount. |
| 780 | - $discount = self::payment_form_validate_discount( $data ); |
|
| 780 | + $discount = self::payment_form_validate_discount($data); |
|
| 781 | 781 | |
| 782 | - if ( is_string( $discount ) ){ |
|
| 783 | - wp_send_json_error( $discount ); |
|
| 782 | + if (is_string($discount)) { |
|
| 783 | + wp_send_json_error($discount); |
|
| 784 | 784 | } |
| 785 | 785 | |
| 786 | - if ( is_array( $discount ) ){ |
|
| 787 | - $discount = $discount[ 'discount' ]; |
|
| 786 | + if (is_array($discount)) { |
|
| 787 | + $discount = $discount['discount']; |
|
| 788 | 788 | } |
| 789 | 789 | |
| 790 | - if ( ! $discount ) { |
|
| 790 | + if (!$discount) { |
|
| 791 | 791 | $discount = 0; |
| 792 | 792 | } |
| 793 | 793 | |
| 794 | 794 | } |
| 795 | 795 | |
| 796 | - $fields = $invoicing->form_elements->get_form_elements( $data['form_id'] ); |
|
| 796 | + $fields = $invoicing->form_elements->get_form_elements($data['form_id']); |
|
| 797 | 797 | |
| 798 | 798 | // ... and form items. |
| 799 | - if ( ! empty( $data['invoice_id'] ) ) { |
|
| 800 | - $invoice = wpinv_get_invoice( $data['invoice_id'] ); |
|
| 799 | + if (!empty($data['invoice_id'])) { |
|
| 800 | + $invoice = wpinv_get_invoice($data['invoice_id']); |
|
| 801 | 801 | |
| 802 | - if ( empty( $invoice ) ) { |
|
| 803 | - wp_send_json_error( __( 'Invalid invoice.', 'invoicing' ) ); |
|
| 802 | + if (empty($invoice)) { |
|
| 803 | + wp_send_json_error(__('Invalid invoice.', 'invoicing')); |
|
| 804 | 804 | } |
| 805 | 805 | |
| 806 | - if ( $invoice->is_paid() ) { |
|
| 807 | - wp_send_json_error( __( 'This invoice has already been paid.', 'invoicing' ) ); |
|
| 806 | + if ($invoice->is_paid()) { |
|
| 807 | + wp_send_json_error(__('This invoice has already been paid.', 'invoicing')); |
|
| 808 | 808 | } |
| 809 | 809 | |
| 810 | - $items = $invoicing->form_elements->convert_checkout_items( $invoice->cart_details, $invoice ); |
|
| 810 | + $items = $invoicing->form_elements->convert_checkout_items($invoice->cart_details, $invoice); |
|
| 811 | 811 | |
| 812 | 812 | } else { |
| 813 | 813 | |
| 814 | - if ( isset( $data['form_items'] ) ) { |
|
| 815 | - $items = getpaid_convert_items_to_array( $data['form_items'] ); |
|
| 816 | - $items = $invoicing->form_elements->convert_normal_items( $items ); |
|
| 814 | + if (isset($data['form_items'])) { |
|
| 815 | + $items = getpaid_convert_items_to_array($data['form_items']); |
|
| 816 | + $items = $invoicing->form_elements->convert_normal_items($items); |
|
| 817 | 817 | } else { |
| 818 | - $items = $invoicing->form_elements->get_form_items( $data['form_id'] ); |
|
| 818 | + $items = $invoicing->form_elements->get_form_items($data['form_id']); |
|
| 819 | 819 | } |
| 820 | 820 | |
| 821 | 821 | $invoice = 0; |
@@ -825,48 +825,48 @@ discard block |
||
| 825 | 825 | $address_fields = array(); |
| 826 | 826 | $has_recurring = false; |
| 827 | 827 | |
| 828 | - if ( ! empty( $data['wpinv-items'] ) ) { |
|
| 828 | + if (!empty($data['wpinv-items'])) { |
|
| 829 | 829 | |
| 830 | - $selected_items = wpinv_clean( $data['wpinv-items'] ); |
|
| 830 | + $selected_items = wpinv_clean($data['wpinv-items']); |
|
| 831 | 831 | |
| 832 | - foreach ( $items as $item ) { |
|
| 832 | + foreach ($items as $item) { |
|
| 833 | 833 | |
| 834 | - if ( ! empty( $item['required'] ) && ! isset( $selected_items[ $item['id'] ] ) ) { |
|
| 835 | - wp_send_json_error( __( 'A required item is missing.', 'invoicing' ) ); |
|
| 834 | + if (!empty($item['required']) && !isset($selected_items[$item['id']])) { |
|
| 835 | + wp_send_json_error(__('A required item is missing.', 'invoicing')); |
|
| 836 | 836 | } |
| 837 | 837 | |
| 838 | - if ( ! isset( $selected_items[ $item['id'] ] ) ) { |
|
| 838 | + if (!isset($selected_items[$item['id']])) { |
|
| 839 | 839 | continue; |
| 840 | 840 | } |
| 841 | 841 | |
| 842 | - if ( ! empty( $item['recurring'] ) ) { |
|
| 843 | - $has_recurring = true; |
|
| 842 | + if (!empty($item['recurring'])) { |
|
| 843 | + $has_recurring = true; |
|
| 844 | 844 | } |
| 845 | 845 | |
| 846 | - $quantity = empty( $item['quantity'] ) ? 1 : absint( $item['quantity'] ); |
|
| 846 | + $quantity = empty($item['quantity']) ? 1 : absint($item['quantity']); |
|
| 847 | 847 | |
| 848 | - if ( ! empty( $item['allow_quantities'] ) && ! empty( $data["wpinv-item-{$item['id']}-quantity"] ) ) { |
|
| 848 | + if (!empty($item['allow_quantities']) && !empty($data["wpinv-item-{$item['id']}-quantity"])) { |
|
| 849 | 849 | |
| 850 | - $_quantity = intval( $data["wpinv-item-{$item['id']}-quantity"] ); |
|
| 850 | + $_quantity = intval($data["wpinv-item-{$item['id']}-quantity"]); |
|
| 851 | 851 | |
| 852 | - if ( ! empty( $_quantity ) ) { |
|
| 852 | + if (!empty($_quantity)) { |
|
| 853 | 853 | $quantity = $_quantity; |
| 854 | 854 | } |
| 855 | 855 | } |
| 856 | 856 | |
| 857 | 857 | // Custom pricing. |
| 858 | - if ( ! empty( $item['custom_price'] ) ) { |
|
| 858 | + if (!empty($item['custom_price'])) { |
|
| 859 | 859 | |
| 860 | - $minimum_price = wpinv_sanitize_amount( $item['minimum_price'] ); |
|
| 861 | - $set_price = wpinv_sanitize_amount( $selected_items[ $item['id'] ] ); |
|
| 860 | + $minimum_price = wpinv_sanitize_amount($item['minimum_price']); |
|
| 861 | + $set_price = wpinv_sanitize_amount($selected_items[$item['id']]); |
|
| 862 | 862 | |
| 863 | - if ( $set_price < $minimum_price ) { |
|
| 864 | - wp_send_json_error( __( 'The provided amount is less than the minimum allowed value.', 'invoicing' ) ); |
|
| 863 | + if ($set_price < $minimum_price) { |
|
| 864 | + wp_send_json_error(__('The provided amount is less than the minimum allowed value.', 'invoicing')); |
|
| 865 | 865 | } |
| 866 | 866 | |
| 867 | 867 | $prepared_items[] = array( |
| 868 | 868 | 'id' =>$item['id'], |
| 869 | - 'item_price' => wpinv_sanitize_amount( $item['price'] ), |
|
| 869 | + 'item_price' => wpinv_sanitize_amount($item['price']), |
|
| 870 | 870 | 'custom_price' => $set_price, |
| 871 | 871 | 'name' => $item['title'], |
| 872 | 872 | 'quantity' => $quantity, |
@@ -876,8 +876,8 @@ discard block |
||
| 876 | 876 | |
| 877 | 877 | $prepared_items[] = array( |
| 878 | 878 | 'id' => $item['id'], |
| 879 | - 'item_price' => wpinv_sanitize_amount( $item['price'] ), |
|
| 880 | - 'custom_price' => wpinv_sanitize_amount( $item['price'] ), |
|
| 879 | + 'item_price' => wpinv_sanitize_amount($item['price']), |
|
| 880 | + 'custom_price' => wpinv_sanitize_amount($item['price']), |
|
| 881 | 881 | 'name' => $item['title'], |
| 882 | 882 | 'quantity' => $quantity, |
| 883 | 883 | ); |
@@ -888,76 +888,76 @@ discard block |
||
| 888 | 888 | |
| 889 | 889 | } else { |
| 890 | 890 | |
| 891 | - wp_send_json_error( __( 'You have not selected any items.', 'invoicing' ) ); |
|
| 891 | + wp_send_json_error(__('You have not selected any items.', 'invoicing')); |
|
| 892 | 892 | |
| 893 | 893 | } |
| 894 | 894 | |
| 895 | - if ( $has_recurring && 1 != count( $prepared_items ) ) { |
|
| 896 | - wp_send_json_error( __( 'Recurring items should be bought individually.', 'invoicing' ) ); |
|
| 895 | + if ($has_recurring && 1 != count($prepared_items)) { |
|
| 896 | + wp_send_json_error(__('Recurring items should be bought individually.', 'invoicing')); |
|
| 897 | 897 | } |
| 898 | 898 | |
| 899 | 899 | // Are all required fields provided? |
| 900 | - foreach ( $fields as $field ) { |
|
| 900 | + foreach ($fields as $field) { |
|
| 901 | 901 | |
| 902 | - if ( ! empty( $field['premade'] ) ) { |
|
| 902 | + if (!empty($field['premade'])) { |
|
| 903 | 903 | continue; |
| 904 | 904 | } |
| 905 | 905 | |
| 906 | - if ( ! empty( $field['required'] ) && empty( $data[ $field['id'] ] ) ) { |
|
| 907 | - wp_send_json_error( __( 'Some required fields have not been filled.', 'invoicing' ) ); |
|
| 906 | + if (!empty($field['required']) && empty($data[$field['id']])) { |
|
| 907 | + wp_send_json_error(__('Some required fields have not been filled.', 'invoicing')); |
|
| 908 | 908 | } |
| 909 | 909 | |
| 910 | - if ( $field['type'] == 'address' ) { |
|
| 910 | + if ($field['type'] == 'address') { |
|
| 911 | 911 | |
| 912 | - foreach ( $field['fields'] as $address_field ) { |
|
| 912 | + foreach ($field['fields'] as $address_field) { |
|
| 913 | 913 | |
| 914 | - if ( empty( $address_field['visible'] ) ) { |
|
| 914 | + if (empty($address_field['visible'])) { |
|
| 915 | 915 | continue; |
| 916 | 916 | } |
| 917 | 917 | |
| 918 | - if ( ! empty( $address_field['required'] ) && empty( $data[ $address_field['name'] ] ) ) { |
|
| 919 | - wp_send_json_error( __( 'Some required fields have not been filled.', 'invoicing' ) ); |
|
| 918 | + if (!empty($address_field['required']) && empty($data[$address_field['name']])) { |
|
| 919 | + wp_send_json_error(__('Some required fields have not been filled.', 'invoicing')); |
|
| 920 | 920 | } |
| 921 | 921 | |
| 922 | - if ( isset( $data[ $address_field['name'] ] ) ) { |
|
| 923 | - $label = str_replace( 'wpinv_', '', $address_field['name'] ); |
|
| 924 | - $address_fields[ $label ] = wpinv_clean( $data[ $address_field['name'] ] ); |
|
| 922 | + if (isset($data[$address_field['name']])) { |
|
| 923 | + $label = str_replace('wpinv_', '', $address_field['name']); |
|
| 924 | + $address_fields[$label] = wpinv_clean($data[$address_field['name']]); |
|
| 925 | 925 | } |
| 926 | 926 | |
| 927 | 927 | } |
| 928 | 928 | |
| 929 | - } else if ( isset( $data[ $field['id'] ] ) ) { |
|
| 929 | + } else if (isset($data[$field['id']])) { |
|
| 930 | 930 | $label = $field['id']; |
| 931 | 931 | |
| 932 | - if ( isset( $field['label'] ) ) { |
|
| 932 | + if (isset($field['label'])) { |
|
| 933 | 933 | $label = $field['label']; |
| 934 | 934 | } |
| 935 | 935 | |
| 936 | - $prepared[ wpinv_clean( $label ) ] = wpinv_clean( $data[ $field['id'] ] ); |
|
| 936 | + $prepared[wpinv_clean($label)] = wpinv_clean($data[$field['id']]); |
|
| 937 | 937 | } |
| 938 | 938 | |
| 939 | 939 | } |
| 940 | 940 | |
| 941 | - $user = get_user_by( 'email', $prepared['billing_email'] ); |
|
| 941 | + $user = get_user_by('email', $prepared['billing_email']); |
|
| 942 | 942 | |
| 943 | - if ( empty( $user ) ) { |
|
| 944 | - $user = wpinv_create_user( $prepared['billing_email'] ); |
|
| 943 | + if (empty($user)) { |
|
| 944 | + $user = wpinv_create_user($prepared['billing_email']); |
|
| 945 | 945 | } |
| 946 | 946 | |
| 947 | - if ( is_wp_error( $user ) ) { |
|
| 948 | - wp_send_json_error( $user->get_error_message() ); |
|
| 947 | + if (is_wp_error($user)) { |
|
| 948 | + wp_send_json_error($user->get_error_message()); |
|
| 949 | 949 | } |
| 950 | 950 | |
| 951 | - if ( is_numeric( $user ) ) { |
|
| 952 | - $user = get_user_by( 'id', $user ); |
|
| 951 | + if (is_numeric($user)) { |
|
| 952 | + $user = get_user_by('id', $user); |
|
| 953 | 953 | } |
| 954 | 954 | |
| 955 | - if ( $discount ) { |
|
| 956 | - $address_fields['discount'] = array( $data['discount'] ); |
|
| 955 | + if ($discount) { |
|
| 956 | + $address_fields['discount'] = array($data['discount']); |
|
| 957 | 957 | } |
| 958 | 958 | |
| 959 | 959 | // Create the invoice. |
| 960 | - if ( empty( $invoice ) ) { |
|
| 960 | + if (empty($invoice)) { |
|
| 961 | 961 | |
| 962 | 962 | $invoice = wpinv_insert_invoice( |
| 963 | 963 | array( |
@@ -984,34 +984,34 @@ discard block |
||
| 984 | 984 | |
| 985 | 985 | } |
| 986 | 986 | |
| 987 | - if ( is_wp_error( $invoice ) ) { |
|
| 988 | - wp_send_json_error( $invoice->get_error_message() ); |
|
| 987 | + if (is_wp_error($invoice)) { |
|
| 988 | + wp_send_json_error($invoice->get_error_message()); |
|
| 989 | 989 | } |
| 990 | 990 | |
| 991 | - if ( empty( $invoice ) ) { |
|
| 992 | - wp_send_json_error( __( 'Could not create your invoice.', 'invoicing' ) ); |
|
| 991 | + if (empty($invoice)) { |
|
| 992 | + wp_send_json_error(__('Could not create your invoice.', 'invoicing')); |
|
| 993 | 993 | } |
| 994 | 994 | |
| 995 | - unset( $prepared['billing_email'] ); |
|
| 996 | - update_post_meta( $invoice->ID, 'payment_form_data', $prepared ); |
|
| 995 | + unset($prepared['billing_email']); |
|
| 996 | + update_post_meta($invoice->ID, 'payment_form_data', $prepared); |
|
| 997 | 997 | |
| 998 | 998 | $wpi_checkout_id = $invoice->ID; |
| 999 | 999 | $cart_total = wpinv_price( |
| 1000 | 1000 | wpinv_format_amount( |
| 1001 | - wpinv_get_cart_total( $invoice->get_cart_details(), NULL, $invoice ) ), |
|
| 1001 | + wpinv_get_cart_total($invoice->get_cart_details(), NULL, $invoice) ), |
|
| 1002 | 1002 | $invoice->get_currency() |
| 1003 | 1003 | ); |
| 1004 | 1004 | |
| 1005 | 1005 | $data = array(); |
| 1006 | 1006 | $data['invoice_id'] = $invoice->ID; |
| 1007 | - $data['cart_discounts'] = $invoice->get_discounts( true ); |
|
| 1007 | + $data['cart_discounts'] = $invoice->get_discounts(true); |
|
| 1008 | 1008 | |
| 1009 | - wpinv_set_checkout_session( $data ); |
|
| 1010 | - add_filter( 'wp_redirect', array( $invoicing->form_elements, 'send_redirect_response' ) ); |
|
| 1011 | - add_action( 'wpinv_pre_send_back_to_checkout', array( $invoicing->form_elements, 'checkout_error' ) ); |
|
| 1009 | + wpinv_set_checkout_session($data); |
|
| 1010 | + add_filter('wp_redirect', array($invoicing->form_elements, 'send_redirect_response')); |
|
| 1011 | + add_action('wpinv_pre_send_back_to_checkout', array($invoicing->form_elements, 'checkout_error')); |
|
| 1012 | 1012 | |
| 1013 | - if ( ! defined( 'WPINV_CHECKOUT' ) ) { |
|
| 1014 | - define( 'WPINV_CHECKOUT', true ); |
|
| 1013 | + if (!defined('WPINV_CHECKOUT')) { |
|
| 1014 | + define('WPINV_CHECKOUT', true); |
|
| 1015 | 1015 | } |
| 1016 | 1016 | |
| 1017 | 1017 | wpinv_process_checkout(); |
@@ -1029,51 +1029,51 @@ discard block |
||
| 1029 | 1029 | public static function get_payment_form_states_field() { |
| 1030 | 1030 | global $invoicing; |
| 1031 | 1031 | |
| 1032 | - if ( empty( $_GET['country'] ) || empty( $_GET['form'] ) ) { |
|
| 1032 | + if (empty($_GET['country']) || empty($_GET['form'])) { |
|
| 1033 | 1033 | exit; |
| 1034 | 1034 | } |
| 1035 | 1035 | |
| 1036 | - $elements = $invoicing->form_elements->get_form_elements( $_GET['form'] ); |
|
| 1036 | + $elements = $invoicing->form_elements->get_form_elements($_GET['form']); |
|
| 1037 | 1037 | |
| 1038 | - if ( empty( $elements ) ) { |
|
| 1038 | + if (empty($elements)) { |
|
| 1039 | 1039 | exit; |
| 1040 | 1040 | } |
| 1041 | 1041 | |
| 1042 | 1042 | $address_fields = array(); |
| 1043 | - foreach ( $elements as $element ) { |
|
| 1044 | - if ( 'address' === $element['type'] ) { |
|
| 1043 | + foreach ($elements as $element) { |
|
| 1044 | + if ('address' === $element['type']) { |
|
| 1045 | 1045 | $address_fields = $element; |
| 1046 | 1046 | break; |
| 1047 | 1047 | } |
| 1048 | 1048 | } |
| 1049 | 1049 | |
| 1050 | - if ( empty( $address_fields ) ) { |
|
| 1050 | + if (empty($address_fields)) { |
|
| 1051 | 1051 | exit; |
| 1052 | 1052 | } |
| 1053 | 1053 | |
| 1054 | - foreach( $address_fields['fields'] as $address_field ) { |
|
| 1054 | + foreach ($address_fields['fields'] as $address_field) { |
|
| 1055 | 1055 | |
| 1056 | - if ( 'wpinv_state' == $address_field['name'] ) { |
|
| 1056 | + if ('wpinv_state' == $address_field['name']) { |
|
| 1057 | 1057 | |
| 1058 | 1058 | $label = $address_field['label']; |
| 1059 | 1059 | |
| 1060 | - if ( ! empty( $address_field['required'] ) ) { |
|
| 1060 | + if (!empty($address_field['required'])) { |
|
| 1061 | 1061 | $label .= "<span class='text-danger'> *</span>"; |
| 1062 | 1062 | } |
| 1063 | 1063 | |
| 1064 | - $states = wpinv_get_country_states( $_GET['country'] ); |
|
| 1064 | + $states = wpinv_get_country_states($_GET['country']); |
|
| 1065 | 1065 | |
| 1066 | - if ( ! empty( $states ) ) { |
|
| 1066 | + if (!empty($states)) { |
|
| 1067 | 1067 | |
| 1068 | 1068 | $html = aui()->select( |
| 1069 | 1069 | array( |
| 1070 | 1070 | 'options' => $states, |
| 1071 | - 'name' => esc_attr( $address_field['name'] ), |
|
| 1072 | - 'id' => esc_attr( $address_field['name'] ), |
|
| 1073 | - 'placeholder' => esc_attr( $address_field['placeholder'] ), |
|
| 1071 | + 'name' => esc_attr($address_field['name']), |
|
| 1072 | + 'id' => esc_attr($address_field['name']), |
|
| 1073 | + 'placeholder' => esc_attr($address_field['placeholder']), |
|
| 1074 | 1074 | 'required' => (bool) $address_field['required'], |
| 1075 | 1075 | 'no_wrap' => true, |
| 1076 | - 'label' => wp_kses_post( $label ), |
|
| 1076 | + 'label' => wp_kses_post($label), |
|
| 1077 | 1077 | 'select2' => false, |
| 1078 | 1078 | ) |
| 1079 | 1079 | ); |
@@ -1082,10 +1082,10 @@ discard block |
||
| 1082 | 1082 | |
| 1083 | 1083 | $html = aui()->input( |
| 1084 | 1084 | array( |
| 1085 | - 'name' => esc_attr( $address_field['name'] ), |
|
| 1086 | - 'id' => esc_attr( $address_field['name'] ), |
|
| 1085 | + 'name' => esc_attr($address_field['name']), |
|
| 1086 | + 'id' => esc_attr($address_field['name']), |
|
| 1087 | 1087 | 'required' => (bool) $address_field['required'], |
| 1088 | - 'label' => wp_kses_post( $label ), |
|
| 1088 | + 'label' => wp_kses_post($label), |
|
| 1089 | 1089 | 'no_wrap' => true, |
| 1090 | 1090 | 'type' => 'text', |
| 1091 | 1091 | ) |
@@ -1093,7 +1093,7 @@ discard block |
||
| 1093 | 1093 | |
| 1094 | 1094 | } |
| 1095 | 1095 | |
| 1096 | - wp_send_json_success( str_replace( 'sr-only', '', $html ) ); |
|
| 1096 | + wp_send_json_success(str_replace('sr-only', '', $html)); |
|
| 1097 | 1097 | exit; |
| 1098 | 1098 | |
| 1099 | 1099 | } |
@@ -1112,51 +1112,51 @@ discard block |
||
| 1112 | 1112 | global $invoicing; |
| 1113 | 1113 | |
| 1114 | 1114 | // Check nonce. |
| 1115 | - check_ajax_referer( 'wpinv_payment_form', 'wpinv_payment_form' ); |
|
| 1115 | + check_ajax_referer('wpinv_payment_form', 'wpinv_payment_form'); |
|
| 1116 | 1116 | |
| 1117 | 1117 | // Prepare submitted data... |
| 1118 | - $data = wp_unslash( $_POST ); |
|
| 1118 | + $data = wp_unslash($_POST); |
|
| 1119 | 1119 | |
| 1120 | 1120 | // ... form fields... |
| 1121 | - if ( empty( $data['form_id'] ) || 'publish' != get_post_status( $data['form_id'] ) ) { |
|
| 1121 | + if (empty($data['form_id']) || 'publish' != get_post_status($data['form_id'])) { |
|
| 1122 | 1122 | exit; |
| 1123 | 1123 | } |
| 1124 | 1124 | |
| 1125 | 1125 | // Do we have a discount? |
| 1126 | - if ( ! empty( $data['discount'] ) ) { |
|
| 1126 | + if (!empty($data['discount'])) { |
|
| 1127 | 1127 | |
| 1128 | 1128 | // Validate discount. |
| 1129 | - $discount = self::payment_form_validate_discount( $data ); |
|
| 1130 | - |
|
| 1131 | - if ( is_array( $discount ) ){ |
|
| 1132 | - $data['total'] = wpinv_price( wpinv_format_amount( $discount['total'] ) ); |
|
| 1133 | - $data['sub_total'] = wpinv_price( wpinv_format_amount( $discount['sub_total'] ) ); |
|
| 1134 | - $data['discount'] = wpinv_price( wpinv_format_amount( $discount['discount'] ) ); |
|
| 1135 | - $data['tax'] = wpinv_price( wpinv_format_amount( $discount['tax'] ) ); |
|
| 1136 | - wp_send_json_success( $discount ); |
|
| 1129 | + $discount = self::payment_form_validate_discount($data); |
|
| 1130 | + |
|
| 1131 | + if (is_array($discount)) { |
|
| 1132 | + $data['total'] = wpinv_price(wpinv_format_amount($discount['total'])); |
|
| 1133 | + $data['sub_total'] = wpinv_price(wpinv_format_amount($discount['sub_total'])); |
|
| 1134 | + $data['discount'] = wpinv_price(wpinv_format_amount($discount['discount'])); |
|
| 1135 | + $data['tax'] = wpinv_price(wpinv_format_amount($discount['tax'])); |
|
| 1136 | + wp_send_json_success($discount); |
|
| 1137 | 1137 | } |
| 1138 | 1138 | |
| 1139 | 1139 | } |
| 1140 | 1140 | |
| 1141 | 1141 | // For existing invoices. |
| 1142 | - if ( ! empty( $data['invoice_id'] ) ) { |
|
| 1143 | - $invoice = wpinv_get_invoice( $data['invoice_id'] ); |
|
| 1142 | + if (!empty($data['invoice_id'])) { |
|
| 1143 | + $invoice = wpinv_get_invoice($data['invoice_id']); |
|
| 1144 | 1144 | |
| 1145 | - if ( empty( $invoice ) ) { |
|
| 1145 | + if (empty($invoice)) { |
|
| 1146 | 1146 | exit; |
| 1147 | 1147 | } |
| 1148 | 1148 | |
| 1149 | - $items = $invoicing->form_elements->convert_checkout_items( $invoice->cart_details, $invoice ); |
|
| 1149 | + $items = $invoicing->form_elements->convert_checkout_items($invoice->cart_details, $invoice); |
|
| 1150 | 1150 | $country = $invoice->country; |
| 1151 | 1151 | $state = $invoice->state; |
| 1152 | 1152 | |
| 1153 | 1153 | } else { |
| 1154 | 1154 | |
| 1155 | - if ( isset( $data['form_items'] ) ) { |
|
| 1156 | - $items = getpaid_convert_items_to_array( $data['form_items'] ); |
|
| 1157 | - $items = $invoicing->form_elements->convert_normal_items( $items ); |
|
| 1155 | + if (isset($data['form_items'])) { |
|
| 1156 | + $items = getpaid_convert_items_to_array($data['form_items']); |
|
| 1157 | + $items = $invoicing->form_elements->convert_normal_items($items); |
|
| 1158 | 1158 | } else { |
| 1159 | - $items = $invoicing->form_elements->get_form_items( $data['form_id'] ); |
|
| 1159 | + $items = $invoicing->form_elements->get_form_items($data['form_id']); |
|
| 1160 | 1160 | } |
| 1161 | 1161 | |
| 1162 | 1162 | $country = wpinv_default_billing_country(); |
@@ -1168,64 +1168,64 @@ discard block |
||
| 1168 | 1168 | $tax = 0; |
| 1169 | 1169 | $sub_total = 0; |
| 1170 | 1170 | |
| 1171 | - if ( ! empty( $data['wpinv_country'] ) ) { |
|
| 1171 | + if (!empty($data['wpinv_country'])) { |
|
| 1172 | 1172 | $country = $data['wpinv_country']; |
| 1173 | 1173 | } |
| 1174 | 1174 | |
| 1175 | - if ( ! empty( $data['wpinv_state'] ) ) { |
|
| 1175 | + if (!empty($data['wpinv_state'])) { |
|
| 1176 | 1176 | $state = $data['wpinv_state']; |
| 1177 | 1177 | } |
| 1178 | 1178 | |
| 1179 | - $has_recurring = false; |
|
| 1180 | - if ( ! empty( $data['wpinv-items'] ) ) { |
|
| 1179 | + $has_recurring = false; |
|
| 1180 | + if (!empty($data['wpinv-items'])) { |
|
| 1181 | 1181 | |
| 1182 | - $selected_items = wpinv_clean( $data['wpinv-items'] ); |
|
| 1182 | + $selected_items = wpinv_clean($data['wpinv-items']); |
|
| 1183 | 1183 | |
| 1184 | - foreach ( $items as $item ) { |
|
| 1184 | + foreach ($items as $item) { |
|
| 1185 | 1185 | |
| 1186 | - if ( ! isset( $selected_items[ $item['id'] ] ) ) { |
|
| 1186 | + if (!isset($selected_items[$item['id']])) { |
|
| 1187 | 1187 | continue; |
| 1188 | 1188 | } |
| 1189 | 1189 | |
| 1190 | - if ( ! empty( $item['recurring'] ) ) { |
|
| 1191 | - $has_recurring = true; |
|
| 1190 | + if (!empty($item['recurring'])) { |
|
| 1191 | + $has_recurring = true; |
|
| 1192 | 1192 | } |
| 1193 | 1193 | |
| 1194 | - $quantity = empty( $item['quantity'] ) ? 1 : absint( $item['quantity'] ); |
|
| 1194 | + $quantity = empty($item['quantity']) ? 1 : absint($item['quantity']); |
|
| 1195 | 1195 | |
| 1196 | - if ( ! empty( $item['allow_quantities'] ) && ! empty( $data["wpinv-item-{$item['id']}-quantity"] ) ) { |
|
| 1196 | + if (!empty($item['allow_quantities']) && !empty($data["wpinv-item-{$item['id']}-quantity"])) { |
|
| 1197 | 1197 | |
| 1198 | - $quantity = intval( $data["wpinv-item-{$item['id']}-quantity"] ); |
|
| 1198 | + $quantity = intval($data["wpinv-item-{$item['id']}-quantity"]); |
|
| 1199 | 1199 | |
| 1200 | - if ( 1 > $quantity ) { |
|
| 1200 | + if (1 > $quantity) { |
|
| 1201 | 1201 | $quantity = 1; |
| 1202 | 1202 | } |
| 1203 | 1203 | |
| 1204 | 1204 | } |
| 1205 | 1205 | |
| 1206 | 1206 | // Custom pricing. |
| 1207 | - $price = wpinv_sanitize_amount( $item['price'] ); |
|
| 1208 | - if ( ! empty( $item['custom_price'] ) ) { |
|
| 1207 | + $price = wpinv_sanitize_amount($item['price']); |
|
| 1208 | + if (!empty($item['custom_price'])) { |
|
| 1209 | 1209 | |
| 1210 | - $minimum_price = wpinv_sanitize_amount( $item['minimum_price'] ); |
|
| 1211 | - $set_price = wpinv_sanitize_amount( $selected_items[ $item['id'] ] ); |
|
| 1210 | + $minimum_price = wpinv_sanitize_amount($item['minimum_price']); |
|
| 1211 | + $set_price = wpinv_sanitize_amount($selected_items[$item['id']]); |
|
| 1212 | 1212 | |
| 1213 | - if ( $set_price < $minimum_price ) { |
|
| 1213 | + if ($set_price < $minimum_price) { |
|
| 1214 | 1214 | $set_price = $minimum_price; |
| 1215 | 1215 | } |
| 1216 | 1216 | |
| 1217 | - $price = wpinv_sanitize_amount( $set_price ); |
|
| 1217 | + $price = wpinv_sanitize_amount($set_price); |
|
| 1218 | 1218 | |
| 1219 | 1219 | } |
| 1220 | 1220 | |
| 1221 | - $price = $quantity * floatval( $price ); |
|
| 1221 | + $price = $quantity * floatval($price); |
|
| 1222 | 1222 | |
| 1223 | - if ( wpinv_use_taxes() ) { |
|
| 1223 | + if (wpinv_use_taxes()) { |
|
| 1224 | 1224 | |
| 1225 | - $rate = wpinv_get_tax_rate( $country, $state, (int) $item['id'] ); |
|
| 1225 | + $rate = wpinv_get_tax_rate($country, $state, (int) $item['id']); |
|
| 1226 | 1226 | |
| 1227 | - if ( wpinv_prices_include_tax() ) { |
|
| 1228 | - $pre_tax = ( $price - $price * $rate * 0.01 ); |
|
| 1227 | + if (wpinv_prices_include_tax()) { |
|
| 1228 | + $pre_tax = ($price - $price * $rate * 0.01); |
|
| 1229 | 1229 | $item_tax = $price - $pre_tax; |
| 1230 | 1230 | } else { |
| 1231 | 1231 | $pre_tax = $price; |
@@ -1237,18 +1237,18 @@ discard block |
||
| 1237 | 1237 | $total = $sub_total + $tax; |
| 1238 | 1238 | |
| 1239 | 1239 | } else { |
| 1240 | - $total = $total + $price; |
|
| 1240 | + $total = $total + $price; |
|
| 1241 | 1241 | } |
| 1242 | 1242 | |
| 1243 | 1243 | } |
| 1244 | 1244 | |
| 1245 | 1245 | } |
| 1246 | 1246 | |
| 1247 | - wp_send_json_success( array( |
|
| 1247 | + wp_send_json_success(array( |
|
| 1248 | 1248 | 'free' => $total == 0, |
| 1249 | - 'total' => wpinv_price( wpinv_format_amount( $total ) ), |
|
| 1250 | - 'tax' => wpinv_price( wpinv_format_amount( $tax ) ), |
|
| 1251 | - 'sub_total' => wpinv_price( wpinv_format_amount( $sub_total ) ), |
|
| 1249 | + 'total' => wpinv_price(wpinv_format_amount($total)), |
|
| 1250 | + 'tax' => wpinv_price(wpinv_format_amount($tax)), |
|
| 1251 | + 'sub_total' => wpinv_price(wpinv_format_amount($sub_total)), |
|
| 1252 | 1252 | 'has_recurring' => false, |
| 1253 | 1253 | 'discount' => false, |
| 1254 | 1254 | )); |
@@ -1263,41 +1263,41 @@ discard block |
||
| 1263 | 1263 | public static function payment_form_discount() { |
| 1264 | 1264 | |
| 1265 | 1265 | // Check nonce. |
| 1266 | - check_ajax_referer( 'wpinv_payment_form', 'wpinv_payment_form' ); |
|
| 1266 | + check_ajax_referer('wpinv_payment_form', 'wpinv_payment_form'); |
|
| 1267 | 1267 | |
| 1268 | 1268 | // Prepare submitted data... |
| 1269 | - $data = wp_unslash( $_POST ); |
|
| 1269 | + $data = wp_unslash($_POST); |
|
| 1270 | 1270 | |
| 1271 | 1271 | // ... form fields... |
| 1272 | - if ( empty( $data['form_id'] ) || 'publish' != get_post_status( $data['form_id'] ) ) { |
|
| 1272 | + if (empty($data['form_id']) || 'publish' != get_post_status($data['form_id'])) { |
|
| 1273 | 1273 | exit; |
| 1274 | 1274 | } |
| 1275 | 1275 | |
| 1276 | 1276 | // Do we have a discount? |
| 1277 | - if ( empty( $data['discount'] ) ) { |
|
| 1278 | - _e( 'Please enter your discount code', 'invoicing' ); |
|
| 1277 | + if (empty($data['discount'])) { |
|
| 1278 | + _e('Please enter your discount code', 'invoicing'); |
|
| 1279 | 1279 | exit; |
| 1280 | 1280 | } |
| 1281 | 1281 | |
| 1282 | 1282 | // Validate discount. |
| 1283 | - $data = self::payment_form_validate_discount( $data ); |
|
| 1283 | + $data = self::payment_form_validate_discount($data); |
|
| 1284 | 1284 | |
| 1285 | - if ( false === $data ) { |
|
| 1286 | - _e( 'There was an error applying your discount code', 'invoicing' ); |
|
| 1285 | + if (false === $data) { |
|
| 1286 | + _e('There was an error applying your discount code', 'invoicing'); |
|
| 1287 | 1287 | exit; |
| 1288 | 1288 | } |
| 1289 | 1289 | |
| 1290 | - if ( is_string( $data ) ) { |
|
| 1290 | + if (is_string($data)) { |
|
| 1291 | 1291 | echo $data; |
| 1292 | 1292 | exit; |
| 1293 | 1293 | } |
| 1294 | 1294 | |
| 1295 | - $data['total'] = wpinv_price( wpinv_format_amount( $data['total'] ) ); |
|
| 1296 | - $data['sub_total'] = wpinv_price( wpinv_format_amount( $data['sub_total'] ) ); |
|
| 1297 | - $data['discount'] = wpinv_price( wpinv_format_amount( $data['discount'] ) ); |
|
| 1298 | - $data['tax'] = wpinv_price( wpinv_format_amount( $data['tax'] ) ); |
|
| 1295 | + $data['total'] = wpinv_price(wpinv_format_amount($data['total'])); |
|
| 1296 | + $data['sub_total'] = wpinv_price(wpinv_format_amount($data['sub_total'])); |
|
| 1297 | + $data['discount'] = wpinv_price(wpinv_format_amount($data['discount'])); |
|
| 1298 | + $data['tax'] = wpinv_price(wpinv_format_amount($data['tax'])); |
|
| 1299 | 1299 | |
| 1300 | - wp_send_json_success( $data ); |
|
| 1300 | + wp_send_json_success($data); |
|
| 1301 | 1301 | exit; |
| 1302 | 1302 | |
| 1303 | 1303 | } |
@@ -1307,54 +1307,54 @@ discard block |
||
| 1307 | 1307 | * |
| 1308 | 1308 | * @since 1.0.19 |
| 1309 | 1309 | */ |
| 1310 | - public static function payment_form_validate_discount( $data ) { |
|
| 1310 | + public static function payment_form_validate_discount($data) { |
|
| 1311 | 1311 | global $invoicing; |
| 1312 | 1312 | |
| 1313 | 1313 | // Do we have a discount? |
| 1314 | - if ( empty( $data['discount'] ) ) { |
|
| 1314 | + if (empty($data['discount'])) { |
|
| 1315 | 1315 | return false; |
| 1316 | 1316 | } |
| 1317 | 1317 | |
| 1318 | 1318 | // If yes, ensure that it exists. |
| 1319 | - $discount = wpinv_get_discount_obj( $data['discount'] ); |
|
| 1319 | + $discount = wpinv_get_discount_obj($data['discount']); |
|
| 1320 | 1320 | |
| 1321 | 1321 | // Ensure it is active. |
| 1322 | - if ( ! $discount->exists() || ! $discount->is_active() || ! $discount->has_started() || $discount->is_expired() ) { |
|
| 1323 | - return __( 'This discount code is not valid', 'invoicing' ); |
|
| 1322 | + if (!$discount->exists() || !$discount->is_active() || !$discount->has_started() || $discount->is_expired()) { |
|
| 1323 | + return __('This discount code is not valid', 'invoicing'); |
|
| 1324 | 1324 | } |
| 1325 | 1325 | |
| 1326 | 1326 | // If it can only be used once per user... |
| 1327 | - if ( $discount->is_single_use ) { |
|
| 1327 | + if ($discount->is_single_use) { |
|
| 1328 | 1328 | |
| 1329 | - if ( empty( $data['billing_email'] ) ) { |
|
| 1330 | - return __( 'Please enter your billing email before applying this discount', 'invoicing' ); |
|
| 1329 | + if (empty($data['billing_email'])) { |
|
| 1330 | + return __('Please enter your billing email before applying this discount', 'invoicing'); |
|
| 1331 | 1331 | } |
| 1332 | 1332 | |
| 1333 | - if ( ! $discount->is_valid_for_user( $data['billing_email'] ) ) { |
|
| 1334 | - return __( 'You have already used this discount', 'invoicing' ); |
|
| 1333 | + if (!$discount->is_valid_for_user($data['billing_email'])) { |
|
| 1334 | + return __('You have already used this discount', 'invoicing'); |
|
| 1335 | 1335 | } |
| 1336 | 1336 | |
| 1337 | 1337 | } |
| 1338 | 1338 | |
| 1339 | 1339 | // Prepare items. |
| 1340 | - if ( ! empty( $data['invoice_id'] ) ) { |
|
| 1341 | - $invoice = wpinv_get_invoice( $data['invoice_id'] ); |
|
| 1340 | + if (!empty($data['invoice_id'])) { |
|
| 1341 | + $invoice = wpinv_get_invoice($data['invoice_id']); |
|
| 1342 | 1342 | |
| 1343 | - if ( empty( $invoice ) ) { |
|
| 1343 | + if (empty($invoice)) { |
|
| 1344 | 1344 | return false; |
| 1345 | 1345 | } |
| 1346 | 1346 | |
| 1347 | 1347 | $country = $invoice->country; |
| 1348 | 1348 | $state = $invoice->state; |
| 1349 | - $items = $invoicing->form_elements->convert_checkout_items( $invoice->cart_details, $invoice ); |
|
| 1349 | + $items = $invoicing->form_elements->convert_checkout_items($invoice->cart_details, $invoice); |
|
| 1350 | 1350 | |
| 1351 | 1351 | } else { |
| 1352 | 1352 | |
| 1353 | - if ( isset( $data['form_items'] ) ) { |
|
| 1354 | - $items = getpaid_convert_items_to_array( $data['form_items'] ); |
|
| 1355 | - $items = $invoicing->form_elements->convert_normal_items( $items ); |
|
| 1353 | + if (isset($data['form_items'])) { |
|
| 1354 | + $items = getpaid_convert_items_to_array($data['form_items']); |
|
| 1355 | + $items = $invoicing->form_elements->convert_normal_items($items); |
|
| 1356 | 1356 | } else { |
| 1357 | - $items = $invoicing->form_elements->get_form_items( $data['form_id'] ); |
|
| 1357 | + $items = $invoicing->form_elements->get_form_items($data['form_id']); |
|
| 1358 | 1358 | } |
| 1359 | 1359 | |
| 1360 | 1360 | $country = wpinv_default_billing_country(); |
@@ -1367,69 +1367,69 @@ discard block |
||
| 1367 | 1367 | $tax = 0; |
| 1368 | 1368 | $sub_total = 0; |
| 1369 | 1369 | |
| 1370 | - if ( ! empty( $data['wpinv_country'] ) ) { |
|
| 1370 | + if (!empty($data['wpinv_country'])) { |
|
| 1371 | 1371 | $country = $data['wpinv_country']; |
| 1372 | 1372 | } |
| 1373 | 1373 | |
| 1374 | - if ( ! empty( $data['wpinv_state'] ) ) { |
|
| 1374 | + if (!empty($data['wpinv_state'])) { |
|
| 1375 | 1375 | $state = $data['wpinv_state']; |
| 1376 | 1376 | } |
| 1377 | 1377 | |
| 1378 | - if ( ! empty( $data['wpinv-items'] ) ) { |
|
| 1378 | + if (!empty($data['wpinv-items'])) { |
|
| 1379 | 1379 | |
| 1380 | - $selected_items = wpinv_clean( $data['wpinv-items'] ); |
|
| 1380 | + $selected_items = wpinv_clean($data['wpinv-items']); |
|
| 1381 | 1381 | |
| 1382 | 1382 | // Check if it is valid for the selected items. |
| 1383 | - if ( ! $discount->is_valid_for_items( array_keys( $selected_items ) ) ) { |
|
| 1384 | - return __( 'This discount is not valid for the items in your cart', 'invoicing' ); |
|
| 1383 | + if (!$discount->is_valid_for_items(array_keys($selected_items))) { |
|
| 1384 | + return __('This discount is not valid for the items in your cart', 'invoicing'); |
|
| 1385 | 1385 | } |
| 1386 | 1386 | |
| 1387 | - $has_recurring = false; |
|
| 1388 | - foreach ( $items as $item ) { |
|
| 1387 | + $has_recurring = false; |
|
| 1388 | + foreach ($items as $item) { |
|
| 1389 | 1389 | |
| 1390 | - if ( ! isset( $selected_items[ $item['id'] ] ) ) { |
|
| 1390 | + if (!isset($selected_items[$item['id']])) { |
|
| 1391 | 1391 | continue; |
| 1392 | 1392 | } |
| 1393 | 1393 | |
| 1394 | - $quantity = empty( $item['quantity'] ) ? 1 : absint( $item['quantity'] ); |
|
| 1394 | + $quantity = empty($item['quantity']) ? 1 : absint($item['quantity']); |
|
| 1395 | 1395 | |
| 1396 | - if ( ! empty( $item['recurring'] ) ) { |
|
| 1397 | - $has_recurring = true; |
|
| 1396 | + if (!empty($item['recurring'])) { |
|
| 1397 | + $has_recurring = true; |
|
| 1398 | 1398 | } |
| 1399 | 1399 | |
| 1400 | - if ( ! empty( $item['allow_quantities'] ) && ! empty( $data["wpinv-item-{$item['id']}-quantity"] ) ) { |
|
| 1400 | + if (!empty($item['allow_quantities']) && !empty($data["wpinv-item-{$item['id']}-quantity"])) { |
|
| 1401 | 1401 | |
| 1402 | - $quantity = intval( $data["wpinv-item-{$item['id']}-quantity"] ); |
|
| 1402 | + $quantity = intval($data["wpinv-item-{$item['id']}-quantity"]); |
|
| 1403 | 1403 | |
| 1404 | - if ( 1 > $quantity ) { |
|
| 1404 | + if (1 > $quantity) { |
|
| 1405 | 1405 | $quantity = 1; |
| 1406 | 1406 | } |
| 1407 | 1407 | |
| 1408 | 1408 | } |
| 1409 | 1409 | |
| 1410 | 1410 | // Custom pricing. |
| 1411 | - $price = wpinv_sanitize_amount( $item['price'] ); |
|
| 1412 | - if ( ! empty( $item['custom_price'] ) ) { |
|
| 1411 | + $price = wpinv_sanitize_amount($item['price']); |
|
| 1412 | + if (!empty($item['custom_price'])) { |
|
| 1413 | 1413 | |
| 1414 | - $minimum_price = wpinv_sanitize_amount( $item['minimum_price'] ); |
|
| 1415 | - $set_price = wpinv_sanitize_amount( $selected_items[ $item['id'] ] ); |
|
| 1414 | + $minimum_price = wpinv_sanitize_amount($item['minimum_price']); |
|
| 1415 | + $set_price = wpinv_sanitize_amount($selected_items[$item['id']]); |
|
| 1416 | 1416 | |
| 1417 | - if ( $set_price < $minimum_price ) { |
|
| 1417 | + if ($set_price < $minimum_price) { |
|
| 1418 | 1418 | $set_price = $minimum_price; |
| 1419 | 1419 | } |
| 1420 | 1420 | |
| 1421 | - $price = wpinv_sanitize_amount( $set_price ); |
|
| 1421 | + $price = wpinv_sanitize_amount($set_price); |
|
| 1422 | 1422 | |
| 1423 | 1423 | } |
| 1424 | 1424 | |
| 1425 | - $price = $quantity * floatval( $price ); |
|
| 1425 | + $price = $quantity * floatval($price); |
|
| 1426 | 1426 | |
| 1427 | - if ( wpinv_use_taxes() ) { |
|
| 1427 | + if (wpinv_use_taxes()) { |
|
| 1428 | 1428 | |
| 1429 | - $rate = wpinv_get_tax_rate( $country, $state, (int) $item['id'] ); |
|
| 1429 | + $rate = wpinv_get_tax_rate($country, $state, (int) $item['id']); |
|
| 1430 | 1430 | |
| 1431 | - if ( wpinv_prices_include_tax() ) { |
|
| 1432 | - $pre_tax = ( $price - $price * $rate * 0.01 ); |
|
| 1431 | + if (wpinv_prices_include_tax()) { |
|
| 1432 | + $pre_tax = ($price - $price * $rate * 0.01); |
|
| 1433 | 1433 | $item_tax = $price - $pre_tax; |
| 1434 | 1434 | } else { |
| 1435 | 1435 | $pre_tax = $price; |
@@ -1441,33 +1441,33 @@ discard block |
||
| 1441 | 1441 | $total = $sub_total + $tax; |
| 1442 | 1442 | |
| 1443 | 1443 | } else { |
| 1444 | - $total = $total + $price; |
|
| 1444 | + $total = $total + $price; |
|
| 1445 | 1445 | } |
| 1446 | 1446 | |
| 1447 | 1447 | } |
| 1448 | 1448 | |
| 1449 | 1449 | } |
| 1450 | 1450 | |
| 1451 | - if ( ! $discount->is_minimum_amount_met( $total ) ) { |
|
| 1452 | - $min = wpinv_price( wpinv_format_amount( $discount->min_total ) ); |
|
| 1453 | - return sprintf( __( 'The minimum total for using this discount is %s', 'invoicing' ), $min ); |
|
| 1451 | + if (!$discount->is_minimum_amount_met($total)) { |
|
| 1452 | + $min = wpinv_price(wpinv_format_amount($discount->min_total)); |
|
| 1453 | + return sprintf(__('The minimum total for using this discount is %s', 'invoicing'), $min); |
|
| 1454 | 1454 | } |
| 1455 | 1455 | |
| 1456 | - if ( ! $discount->is_maximum_amount_met( $total ) ) { |
|
| 1457 | - $max = wpinv_price( wpinv_format_amount( $discount->max_total ) ); |
|
| 1458 | - return sprintf( __( 'The maximum total for using this discount is %s', 'invoicing' ), $max ); |
|
| 1456 | + if (!$discount->is_maximum_amount_met($total)) { |
|
| 1457 | + $max = wpinv_price(wpinv_format_amount($discount->max_total)); |
|
| 1458 | + return sprintf(__('The maximum total for using this discount is %s', 'invoicing'), $max); |
|
| 1459 | 1459 | } |
| 1460 | 1460 | |
| 1461 | 1461 | $recurring_discount = $discount->get_is_recurring() && $has_recurring; |
| 1462 | - $discount = $discount->get_discounted_amount( $total ); |
|
| 1462 | + $discount = $discount->get_discounted_amount($total); |
|
| 1463 | 1463 | $total = $total - $discount; |
| 1464 | 1464 | $free = false; |
| 1465 | 1465 | |
| 1466 | - if ( $total == 0 ) { |
|
| 1466 | + if ($total == 0) { |
|
| 1467 | 1467 | $free = true; |
| 1468 | 1468 | } |
| 1469 | 1469 | |
| 1470 | - return compact( 'total', 'tax', 'sub_total', 'discount', 'recurring_discount', 'free', 'has_recurring' ); |
|
| 1470 | + return compact('total', 'tax', 'sub_total', 'discount', 'recurring_discount', 'free', 'has_recurring'); |
|
| 1471 | 1471 | |
| 1472 | 1472 | } |
| 1473 | 1473 | |
@@ -1479,53 +1479,53 @@ discard block |
||
| 1479 | 1479 | public static function buy_items() { |
| 1480 | 1480 | $user_id = get_current_user_id(); |
| 1481 | 1481 | |
| 1482 | - if ( empty( $user_id ) ) { // If not logged in then lets redirect to the login page |
|
| 1483 | - wp_send_json( array( |
|
| 1484 | - 'success' => wp_login_url( wp_get_referer() ) |
|
| 1485 | - ) ); |
|
| 1482 | + if (empty($user_id)) { // If not logged in then lets redirect to the login page |
|
| 1483 | + wp_send_json(array( |
|
| 1484 | + 'success' => wp_login_url(wp_get_referer()) |
|
| 1485 | + )); |
|
| 1486 | 1486 | } else { |
| 1487 | 1487 | // Only check nonce if logged in as it could be cached when logged out. |
| 1488 | - if ( ! isset( $_POST['wpinv_buy_nonce'] ) || ! wp_verify_nonce( $_POST['wpinv_buy_nonce'], 'wpinv_buy_items' ) ) { |
|
| 1489 | - wp_send_json( array( |
|
| 1490 | - 'error' => __( 'Security checks failed.', 'invoicing' ) |
|
| 1491 | - ) ); |
|
| 1488 | + if (!isset($_POST['wpinv_buy_nonce']) || !wp_verify_nonce($_POST['wpinv_buy_nonce'], 'wpinv_buy_items')) { |
|
| 1489 | + wp_send_json(array( |
|
| 1490 | + 'error' => __('Security checks failed.', 'invoicing') |
|
| 1491 | + )); |
|
| 1492 | 1492 | wp_die(); |
| 1493 | 1493 | } |
| 1494 | 1494 | |
| 1495 | 1495 | // allow to set a custom price through post_id |
| 1496 | 1496 | $items = $_POST['items']; |
| 1497 | - $related_post_id = isset( $_POST['post_id'] ) ? (int)$_POST['post_id'] : 0; |
|
| 1498 | - $custom_item_price = $related_post_id ? abs( get_post_meta( $related_post_id, '_wpi_custom_price', true ) ) : 0; |
|
| 1497 | + $related_post_id = isset($_POST['post_id']) ? (int) $_POST['post_id'] : 0; |
|
| 1498 | + $custom_item_price = $related_post_id ? abs(get_post_meta($related_post_id, '_wpi_custom_price', true)) : 0; |
|
| 1499 | 1499 | |
| 1500 | 1500 | $cart_items = array(); |
| 1501 | - if ( $items ) { |
|
| 1502 | - $items = explode( ',', $items ); |
|
| 1501 | + if ($items) { |
|
| 1502 | + $items = explode(',', $items); |
|
| 1503 | 1503 | |
| 1504 | - foreach( $items as $item ) { |
|
| 1504 | + foreach ($items as $item) { |
|
| 1505 | 1505 | $item_id = $item; |
| 1506 | 1506 | $quantity = 1; |
| 1507 | 1507 | |
| 1508 | - if ( strpos( $item, '|' ) !== false ) { |
|
| 1509 | - $item_parts = explode( '|', $item ); |
|
| 1508 | + if (strpos($item, '|') !== false) { |
|
| 1509 | + $item_parts = explode('|', $item); |
|
| 1510 | 1510 | $item_id = $item_parts[0]; |
| 1511 | 1511 | $quantity = $item_parts[1]; |
| 1512 | 1512 | } |
| 1513 | 1513 | |
| 1514 | - if ( $item_id && $quantity ) { |
|
| 1514 | + if ($item_id && $quantity) { |
|
| 1515 | 1515 | $cart_items_arr = array( |
| 1516 | - 'id' => (int)$item_id, |
|
| 1517 | - 'quantity' => (int)$quantity |
|
| 1516 | + 'id' => (int) $item_id, |
|
| 1517 | + 'quantity' => (int) $quantity |
|
| 1518 | 1518 | ); |
| 1519 | 1519 | |
| 1520 | 1520 | // If there is a related post id then add it to meta |
| 1521 | - if ( $related_post_id ) { |
|
| 1521 | + if ($related_post_id) { |
|
| 1522 | 1522 | $cart_items_arr['meta'] = array( |
| 1523 | 1523 | 'post_id' => $related_post_id |
| 1524 | 1524 | ); |
| 1525 | 1525 | } |
| 1526 | 1526 | |
| 1527 | 1527 | // If there is a custom price then set it. |
| 1528 | - if ( $custom_item_price ) { |
|
| 1528 | + if ($custom_item_price) { |
|
| 1529 | 1529 | $cart_items_arr['custom_price'] = $custom_item_price; |
| 1530 | 1530 | } |
| 1531 | 1531 | |
@@ -1541,37 +1541,37 @@ discard block |
||
| 1541 | 1541 | * @param int $related_post_id The related post id if any. |
| 1542 | 1542 | * @since 1.0.0 |
| 1543 | 1543 | */ |
| 1544 | - $cart_items = apply_filters( 'wpinv_buy_cart_items', $cart_items, $related_post_id ); |
|
| 1544 | + $cart_items = apply_filters('wpinv_buy_cart_items', $cart_items, $related_post_id); |
|
| 1545 | 1545 | |
| 1546 | 1546 | // Make sure its not in the cart already, if it is then redirect to checkout. |
| 1547 | 1547 | $cart_invoice = wpinv_get_invoice_cart(); |
| 1548 | 1548 | |
| 1549 | - if ( isset( $cart_invoice->items ) && !empty( $cart_invoice->items ) && !empty( $cart_items ) && serialize( $cart_invoice->items ) == serialize( $cart_items ) ) { |
|
| 1550 | - wp_send_json( array( |
|
| 1549 | + if (isset($cart_invoice->items) && !empty($cart_invoice->items) && !empty($cart_items) && serialize($cart_invoice->items) == serialize($cart_items)) { |
|
| 1550 | + wp_send_json(array( |
|
| 1551 | 1551 | 'success' => $cart_invoice->get_checkout_payment_url() |
| 1552 | - ) ); |
|
| 1552 | + )); |
|
| 1553 | 1553 | wp_die(); |
| 1554 | 1554 | } |
| 1555 | 1555 | |
| 1556 | 1556 | // Check if user has invoice with same items waiting to be paid. |
| 1557 | - $user_invoices = wpinv_get_users_invoices( $user_id , 10 , false , 'wpi-pending' ); |
|
| 1558 | - if ( !empty( $user_invoices ) ) { |
|
| 1559 | - foreach( $user_invoices as $user_invoice ) { |
|
| 1557 | + $user_invoices = wpinv_get_users_invoices($user_id, 10, false, 'wpi-pending'); |
|
| 1558 | + if (!empty($user_invoices)) { |
|
| 1559 | + foreach ($user_invoices as $user_invoice) { |
|
| 1560 | 1560 | $user_cart_details = array(); |
| 1561 | - $invoice = wpinv_get_invoice( $user_invoice->ID ); |
|
| 1561 | + $invoice = wpinv_get_invoice($user_invoice->ID); |
|
| 1562 | 1562 | $cart_details = $invoice->get_cart_details(); |
| 1563 | 1563 | |
| 1564 | - if ( !empty( $cart_details ) ) { |
|
| 1565 | - foreach ( $cart_details as $invoice_item ) { |
|
| 1564 | + if (!empty($cart_details)) { |
|
| 1565 | + foreach ($cart_details as $invoice_item) { |
|
| 1566 | 1566 | $ii_arr = array(); |
| 1567 | - $ii_arr['id'] = (int)$invoice_item['id']; |
|
| 1568 | - $ii_arr['quantity'] = (int)$invoice_item['quantity']; |
|
| 1567 | + $ii_arr['id'] = (int) $invoice_item['id']; |
|
| 1568 | + $ii_arr['quantity'] = (int) $invoice_item['quantity']; |
|
| 1569 | 1569 | |
| 1570 | - if (isset( $invoice_item['meta'] ) && !empty( $invoice_item['meta'] ) ) { |
|
| 1570 | + if (isset($invoice_item['meta']) && !empty($invoice_item['meta'])) { |
|
| 1571 | 1571 | $ii_arr['meta'] = $invoice_item['meta']; |
| 1572 | 1572 | } |
| 1573 | 1573 | |
| 1574 | - if ( isset( $invoice_item['custom_price'] ) && !empty( $invoice_item['custom_price'] ) ) { |
|
| 1574 | + if (isset($invoice_item['custom_price']) && !empty($invoice_item['custom_price'])) { |
|
| 1575 | 1575 | $ii_arr['custom_price'] = $invoice_item['custom_price']; |
| 1576 | 1576 | } |
| 1577 | 1577 | |
@@ -1579,17 +1579,17 @@ discard block |
||
| 1579 | 1579 | } |
| 1580 | 1580 | } |
| 1581 | 1581 | |
| 1582 | - if ( !empty( $user_cart_details ) && serialize( $cart_items ) == serialize( $user_cart_details ) ) { |
|
| 1583 | - wp_send_json( array( |
|
| 1582 | + if (!empty($user_cart_details) && serialize($cart_items) == serialize($user_cart_details)) { |
|
| 1583 | + wp_send_json(array( |
|
| 1584 | 1584 | 'success' => $invoice->get_checkout_payment_url() |
| 1585 | - ) ); |
|
| 1585 | + )); |
|
| 1586 | 1586 | wp_die(); |
| 1587 | 1587 | } |
| 1588 | 1588 | } |
| 1589 | 1589 | } |
| 1590 | 1590 | |
| 1591 | 1591 | // Create invoice and send user to checkout |
| 1592 | - if ( !empty( $cart_items ) ) { |
|
| 1592 | + if (!empty($cart_items)) { |
|
| 1593 | 1593 | $invoice_data = array( |
| 1594 | 1594 | 'status' => 'wpi-pending', |
| 1595 | 1595 | 'created_via' => 'wpi', |
@@ -1597,21 +1597,21 @@ discard block |
||
| 1597 | 1597 | 'cart_details' => $cart_items, |
| 1598 | 1598 | ); |
| 1599 | 1599 | |
| 1600 | - $invoice = wpinv_insert_invoice( $invoice_data, true ); |
|
| 1600 | + $invoice = wpinv_insert_invoice($invoice_data, true); |
|
| 1601 | 1601 | |
| 1602 | - if ( !empty( $invoice ) && isset( $invoice->ID ) ) { |
|
| 1603 | - wp_send_json( array( |
|
| 1602 | + if (!empty($invoice) && isset($invoice->ID)) { |
|
| 1603 | + wp_send_json(array( |
|
| 1604 | 1604 | 'success' => $invoice->get_checkout_payment_url() |
| 1605 | - ) ); |
|
| 1605 | + )); |
|
| 1606 | 1606 | } else { |
| 1607 | - wp_send_json( array( |
|
| 1608 | - 'error' => __( 'Invoice failed to create', 'invoicing' ) |
|
| 1609 | - ) ); |
|
| 1607 | + wp_send_json(array( |
|
| 1608 | + 'error' => __('Invoice failed to create', 'invoicing') |
|
| 1609 | + )); |
|
| 1610 | 1610 | } |
| 1611 | 1611 | } else { |
| 1612 | - wp_send_json( array( |
|
| 1613 | - 'error' => __( 'Items not valid.', 'invoicing' ) |
|
| 1614 | - ) ); |
|
| 1612 | + wp_send_json(array( |
|
| 1613 | + 'error' => __('Items not valid.', 'invoicing') |
|
| 1614 | + )); |
|
| 1615 | 1615 | } |
| 1616 | 1616 | } |
| 1617 | 1617 | |
@@ -1,11 +1,11 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | // Exit if accessed directly. |
| 3 | -if (!defined( 'ABSPATH' ) ) exit; |
|
| 3 | +if (!defined('ABSPATH')) exit; |
|
| 4 | 4 | |
| 5 | 5 | function wpinv_subscription_init() { |
| 6 | 6 | return WPInv_Subscriptions::instance(); |
| 7 | 7 | } |
| 8 | -add_action( 'plugins_loaded', 'wpinv_subscription_init', 100 ); |
|
| 8 | +add_action('plugins_loaded', 'wpinv_subscription_init', 100); |
|
| 9 | 9 | |
| 10 | 10 | /** |
| 11 | 11 | * WPInv_Subscriptions Class. |
@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | * Main WPInv_Subscriptions Instance |
| 21 | 21 | */ |
| 22 | 22 | public static function instance() { |
| 23 | - if ( ! isset( self::$instance ) ) { |
|
| 23 | + if (!isset(self::$instance)) { |
|
| 24 | 24 | self::$instance = new WPInv_Subscriptions; |
| 25 | 25 | |
| 26 | 26 | self::$instance->init(); |
@@ -34,7 +34,7 @@ discard block |
||
| 34 | 34 | * |
| 35 | 35 | * @since 1.0.0 |
| 36 | 36 | */ |
| 37 | - private function __construct(){ |
|
| 37 | + private function __construct() { |
|
| 38 | 38 | |
| 39 | 39 | } |
| 40 | 40 | |
@@ -63,8 +63,8 @@ discard block |
||
| 63 | 63 | private function setup_constants() { |
| 64 | 64 | |
| 65 | 65 | // Make sure CAL_GREGORIAN is defined. |
| 66 | - if ( ! defined( 'CAL_GREGORIAN' ) ) { |
|
| 67 | - define( 'CAL_GREGORIAN', 1 ); |
|
| 66 | + if (!defined('CAL_GREGORIAN')) { |
|
| 67 | + define('CAL_GREGORIAN', 1); |
|
| 68 | 68 | } |
| 69 | 69 | } |
| 70 | 70 | |
@@ -76,13 +76,13 @@ discard block |
||
| 76 | 76 | */ |
| 77 | 77 | private function actions() { |
| 78 | 78 | |
| 79 | - add_action( 'admin_menu', array( $this, 'wpinv_subscriptions_list' ), 40 ); |
|
| 80 | - add_action( 'admin_notices', array( $this, 'notices' ) ); |
|
| 81 | - add_action( 'init', array( $this, 'wpinv_post_actions' ) ); |
|
| 82 | - add_action( 'init', array( $this, 'wpinv_get_actions' ) ); |
|
| 83 | - add_action( 'wpinv_cancel_subscription', array( $this, 'wpinv_process_cancellation' ) ); |
|
| 84 | - add_action( 'wpinv_checkout_before_send_to_gateway', array( $this, 'wpinv_checkout_add_subscription' ), -999, 2 ); |
|
| 85 | - add_action( 'wpinv_subscriptions_front_notices', array( $this, 'notices' ) ); |
|
| 79 | + add_action('admin_menu', array($this, 'wpinv_subscriptions_list'), 40); |
|
| 80 | + add_action('admin_notices', array($this, 'notices')); |
|
| 81 | + add_action('init', array($this, 'wpinv_post_actions')); |
|
| 82 | + add_action('init', array($this, 'wpinv_get_actions')); |
|
| 83 | + add_action('wpinv_cancel_subscription', array($this, 'wpinv_process_cancellation')); |
|
| 84 | + add_action('wpinv_checkout_before_send_to_gateway', array($this, 'wpinv_checkout_add_subscription'), -999, 2); |
|
| 85 | + add_action('wpinv_subscriptions_front_notices', array($this, 'notices')); |
|
| 86 | 86 | } |
| 87 | 87 | |
| 88 | 88 | /** |
@@ -104,8 +104,8 @@ discard block |
||
| 104 | 104 | public function wpinv_subscriptions_list() { |
| 105 | 105 | add_submenu_page( |
| 106 | 106 | 'wpinv', |
| 107 | - __( 'Subscriptions', 'invoicing' ), |
|
| 108 | - __( 'Subscriptions', 'invoicing' ), |
|
| 107 | + __('Subscriptions', 'invoicing'), |
|
| 108 | + __('Subscriptions', 'invoicing'), |
|
| 109 | 109 | wpinv_get_capability(), |
| 110 | 110 | 'wpinv-subscriptions', |
| 111 | 111 | 'wpinv_subscriptions_page' |
@@ -114,37 +114,37 @@ discard block |
||
| 114 | 114 | |
| 115 | 115 | public function notices() { |
| 116 | 116 | |
| 117 | - if( empty( $_GET['wpinv-message'] ) ) { |
|
| 117 | + if (empty($_GET['wpinv-message'])) { |
|
| 118 | 118 | return; |
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | $type = 'updated'; |
| 122 | 122 | $message = ''; |
| 123 | 123 | |
| 124 | - switch( strtolower( $_GET['wpinv-message'] ) ) { |
|
| 124 | + switch (strtolower($_GET['wpinv-message'])) { |
|
| 125 | 125 | |
| 126 | 126 | case 'updated' : |
| 127 | 127 | |
| 128 | - $message = __( 'Subscription updated successfully.', 'invoicing' ); |
|
| 128 | + $message = __('Subscription updated successfully.', 'invoicing'); |
|
| 129 | 129 | |
| 130 | 130 | break; |
| 131 | 131 | |
| 132 | 132 | case 'deleted' : |
| 133 | 133 | |
| 134 | - $message = __( 'Subscription deleted successfully.', 'invoicing' ); |
|
| 134 | + $message = __('Subscription deleted successfully.', 'invoicing'); |
|
| 135 | 135 | |
| 136 | 136 | break; |
| 137 | 137 | |
| 138 | 138 | case 'cancelled' : |
| 139 | 139 | |
| 140 | - $message = __( 'Subscription cancelled successfully.', 'invoicing' ); |
|
| 140 | + $message = __('Subscription cancelled successfully.', 'invoicing'); |
|
| 141 | 141 | |
| 142 | 142 | break; |
| 143 | 143 | |
| 144 | 144 | } |
| 145 | 145 | |
| 146 | - if ( ! empty( $message ) ) { |
|
| 147 | - echo '<div class="' . esc_attr( $type ) . '"><p>' . $message . '</p></div>'; |
|
| 146 | + if (!empty($message)) { |
|
| 147 | + echo '<div class="' . esc_attr($type) . '"><p>' . $message . '</p></div>'; |
|
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | } |
@@ -157,8 +157,8 @@ discard block |
||
| 157 | 157 | * @return void |
| 158 | 158 | */ |
| 159 | 159 | function wpinv_get_actions() { |
| 160 | - if ( isset( $_GET['wpinv_action'] ) ) { |
|
| 161 | - do_action( 'wpinv_' . $_GET['wpinv_action'], $_GET ); |
|
| 160 | + if (isset($_GET['wpinv_action'])) { |
|
| 161 | + do_action('wpinv_' . $_GET['wpinv_action'], $_GET); |
|
| 162 | 162 | } |
| 163 | 163 | } |
| 164 | 164 | |
@@ -170,8 +170,8 @@ discard block |
||
| 170 | 170 | * @return void |
| 171 | 171 | */ |
| 172 | 172 | function wpinv_post_actions() { |
| 173 | - if ( isset( $_POST['wpinv_action'] ) ) { |
|
| 174 | - do_action( 'wpinv_' . $_POST['wpinv_action'], $_POST ); |
|
| 173 | + if (isset($_POST['wpinv_action'])) { |
|
| 174 | + do_action('wpinv_' . $_POST['wpinv_action'], $_POST); |
|
| 175 | 175 | } |
| 176 | 176 | } |
| 177 | 177 | |
@@ -182,24 +182,24 @@ discard block |
||
| 182 | 182 | * @param int $frequency_count The frequency of the period. |
| 183 | 183 | * @return mixed|string|void |
| 184 | 184 | */ |
| 185 | - public static function wpinv_get_pretty_subscription_frequency( $period, $frequency_count = 1) { |
|
| 185 | + public static function wpinv_get_pretty_subscription_frequency($period, $frequency_count = 1) { |
|
| 186 | 186 | $frequency = ''; |
| 187 | 187 | //Format period details |
| 188 | - switch ( $period ) { |
|
| 188 | + switch ($period) { |
|
| 189 | 189 | case 'day' : |
| 190 | - $frequency = sprintf( _n('%d Day', '%d Days', $frequency_count, 'invoicing'), $frequency_count); |
|
| 190 | + $frequency = sprintf(_n('%d Day', '%d Days', $frequency_count, 'invoicing'), $frequency_count); |
|
| 191 | 191 | break; |
| 192 | 192 | case 'week' : |
| 193 | - $frequency = sprintf( _n('%d Week', '%d Weeks', $frequency_count, 'invoicing'), $frequency_count); |
|
| 193 | + $frequency = sprintf(_n('%d Week', '%d Weeks', $frequency_count, 'invoicing'), $frequency_count); |
|
| 194 | 194 | break; |
| 195 | 195 | case 'month' : |
| 196 | - $frequency = sprintf( _n('%d Month', '%d Months', $frequency_count, 'invoicing'), $frequency_count); |
|
| 196 | + $frequency = sprintf(_n('%d Month', '%d Months', $frequency_count, 'invoicing'), $frequency_count); |
|
| 197 | 197 | break; |
| 198 | 198 | case 'year' : |
| 199 | - $frequency = sprintf( _n('%d Year', '%d Years', $frequency_count, 'invoicing'), $frequency_count); |
|
| 199 | + $frequency = sprintf(_n('%d Year', '%d Years', $frequency_count, 'invoicing'), $frequency_count); |
|
| 200 | 200 | break; |
| 201 | 201 | default : |
| 202 | - $frequency = apply_filters( 'wpinv_recurring_subscription_frequency', $frequency, $period, $frequency_count ); |
|
| 202 | + $frequency = apply_filters('wpinv_recurring_subscription_frequency', $frequency, $period, $frequency_count); |
|
| 203 | 203 | break; |
| 204 | 204 | } |
| 205 | 205 | |
@@ -214,50 +214,50 @@ discard block |
||
| 214 | 214 | * @since 1.0.0 |
| 215 | 215 | * @return void |
| 216 | 216 | */ |
| 217 | - public function wpinv_process_cancellation( $data ) { |
|
| 217 | + public function wpinv_process_cancellation($data) { |
|
| 218 | 218 | |
| 219 | 219 | |
| 220 | - if( empty( $data['sub_id'] ) ) { |
|
| 220 | + if (empty($data['sub_id'])) { |
|
| 221 | 221 | return; |
| 222 | 222 | } |
| 223 | 223 | |
| 224 | - if( ! is_user_logged_in() ) { |
|
| 224 | + if (!is_user_logged_in()) { |
|
| 225 | 225 | return; |
| 226 | 226 | } |
| 227 | 227 | |
| 228 | - if( ! wp_verify_nonce( $data['_wpnonce'], 'wpinv-recurring-cancel' ) ) { |
|
| 229 | - wp_die( __( 'Error', 'invoicing' ), __( 'Nonce verification failed', 'invoicing' ), array( 'response' => 403 ) ); |
|
| 228 | + if (!wp_verify_nonce($data['_wpnonce'], 'wpinv-recurring-cancel')) { |
|
| 229 | + wp_die(__('Error', 'invoicing'), __('Nonce verification failed', 'invoicing'), array('response' => 403)); |
|
| 230 | 230 | } |
| 231 | 231 | |
| 232 | - $data['sub_id'] = absint( $data['sub_id'] ); |
|
| 233 | - $subscription = new WPInv_Subscription( $data['sub_id'] ); |
|
| 232 | + $data['sub_id'] = absint($data['sub_id']); |
|
| 233 | + $subscription = new WPInv_Subscription($data['sub_id']); |
|
| 234 | 234 | |
| 235 | - if( ! $subscription->can_cancel() ) { |
|
| 236 | - wp_die( __( 'Error', 'invoicing' ), __( 'This subscription cannot be cancelled', 'invoicing' ), array( 'response' => 403 ) ); |
|
| 235 | + if (!$subscription->can_cancel()) { |
|
| 236 | + wp_die(__('Error', 'invoicing'), __('This subscription cannot be cancelled', 'invoicing'), array('response' => 403)); |
|
| 237 | 237 | } |
| 238 | 238 | |
| 239 | 239 | try { |
| 240 | 240 | |
| 241 | - do_action( 'wpinv_recurring_cancel_' . $subscription->gateway . '_subscription', $subscription, true ); |
|
| 241 | + do_action('wpinv_recurring_cancel_' . $subscription->gateway . '_subscription', $subscription, true); |
|
| 242 | 242 | |
| 243 | 243 | $subscription->cancel(); |
| 244 | 244 | |
| 245 | - if( is_admin() ) { |
|
| 245 | + if (is_admin()) { |
|
| 246 | 246 | |
| 247 | - wp_redirect( admin_url( 'admin.php?page=wpinv-subscriptions&wpinv-message=cancelled&id=' . $subscription->id ) ); |
|
| 247 | + wp_redirect(admin_url('admin.php?page=wpinv-subscriptions&wpinv-message=cancelled&id=' . $subscription->id)); |
|
| 248 | 248 | exit; |
| 249 | 249 | |
| 250 | 250 | } else { |
| 251 | 251 | |
| 252 | - $redirect = remove_query_arg( array( '_wpnonce', 'wpinv_action', 'sub_id' ), add_query_arg( array( 'wpinv-message' => 'cancelled' ) ) ); |
|
| 253 | - $redirect = apply_filters( 'wpinv_recurring_cancellation_redirect', $redirect, $subscription ); |
|
| 254 | - wp_safe_redirect( $redirect ); |
|
| 252 | + $redirect = remove_query_arg(array('_wpnonce', 'wpinv_action', 'sub_id'), add_query_arg(array('wpinv-message' => 'cancelled'))); |
|
| 253 | + $redirect = apply_filters('wpinv_recurring_cancellation_redirect', $redirect, $subscription); |
|
| 254 | + wp_safe_redirect($redirect); |
|
| 255 | 255 | exit; |
| 256 | 256 | |
| 257 | 257 | } |
| 258 | 258 | |
| 259 | - } catch ( Exception $e ) { |
|
| 260 | - wp_die( __( 'Error', 'invoicing' ), $e->getMessage(), array( 'response' => 403 ) ); |
|
| 259 | + } catch (Exception $e) { |
|
| 260 | + wp_die(__('Error', 'invoicing'), $e->getMessage(), array('response' => 403)); |
|
| 261 | 261 | } |
| 262 | 262 | |
| 263 | 263 | } |
@@ -270,40 +270,40 @@ discard block |
||
| 270 | 270 | * @since 1.0.0 |
| 271 | 271 | * @return void |
| 272 | 272 | */ |
| 273 | - public function wpinv_checkout_add_subscription( $invoice, $invoice_data ) { |
|
| 274 | - if ( ! ( ! empty( $invoice->ID ) && $invoice->is_recurring() ) ) { |
|
| 273 | + public function wpinv_checkout_add_subscription($invoice, $invoice_data) { |
|
| 274 | + if (!(!empty($invoice->ID) && $invoice->is_recurring())) { |
|
| 275 | 275 | return; |
| 276 | 276 | } |
| 277 | 277 | |
| 278 | 278 | // Should we create a subscription for the invoice? |
| 279 | - if ( apply_filters( 'wpinv_skip_invoice_subscription_creation', false, $invoice ) ) { |
|
| 279 | + if (apply_filters('wpinv_skip_invoice_subscription_creation', false, $invoice)) { |
|
| 280 | 280 | return; |
| 281 | 281 | } |
| 282 | 282 | |
| 283 | - $item = $invoice->get_recurring( true ); |
|
| 284 | - if ( empty( $item ) ) { |
|
| 283 | + $item = $invoice->get_recurring(true); |
|
| 284 | + if (empty($item)) { |
|
| 285 | 285 | return; |
| 286 | 286 | } |
| 287 | 287 | |
| 288 | - $invoice_date = $invoice->get_invoice_date( false ); |
|
| 288 | + $invoice_date = $invoice->get_invoice_date(false); |
|
| 289 | 289 | $status = 'pending'; |
| 290 | 290 | |
| 291 | - $period = $item->get_recurring_period( true ); |
|
| 291 | + $period = $item->get_recurring_period(true); |
|
| 292 | 292 | $interval = $item->get_recurring_interval(); |
| 293 | - $bill_times = (int)$item->get_recurring_limit(); |
|
| 293 | + $bill_times = (int) $item->get_recurring_limit(); |
|
| 294 | 294 | $add_period = $interval . ' ' . $period; |
| 295 | 295 | $trial_period = ''; |
| 296 | 296 | |
| 297 | - if ( $invoice->is_free_trial() ) { |
|
| 297 | + if ($invoice->is_free_trial()) { |
|
| 298 | 298 | $status = 'trialling'; |
| 299 | 299 | |
| 300 | - if ( $invoice->is_free_trial_from_discount() ) { |
|
| 300 | + if ($invoice->is_free_trial_from_discount()) { |
|
| 301 | 301 | |
| 302 | - $trial_period = $item->get_recurring_period( true ); |
|
| 302 | + $trial_period = $item->get_recurring_period(true); |
|
| 303 | 303 | $free_interval = $item->get_recurring_interval(); |
| 304 | 304 | |
| 305 | 305 | } else { |
| 306 | - $trial_period = $item->get_trial_period( true ); |
|
| 306 | + $trial_period = $item->get_trial_period(true); |
|
| 307 | 307 | $free_interval = $item->get_trial_interval(); |
| 308 | 308 | } |
| 309 | 309 | |
@@ -312,7 +312,7 @@ discard block |
||
| 312 | 312 | $add_period = $trial_period; |
| 313 | 313 | } |
| 314 | 314 | |
| 315 | - $expiration = date_i18n( 'Y-m-d H:i:s', strtotime( '+' . $add_period . ' 23:59:59', strtotime( $invoice_date ) ) ); |
|
| 315 | + $expiration = date_i18n('Y-m-d H:i:s', strtotime('+' . $add_period . ' 23:59:59', strtotime($invoice_date))); |
|
| 316 | 316 | |
| 317 | 317 | $args = array( |
| 318 | 318 | 'product_id' => $item->ID, |
@@ -322,7 +322,7 @@ discard block |
||
| 322 | 322 | 'frequency' => $interval, |
| 323 | 323 | 'period' => $period, |
| 324 | 324 | 'initial_amount' => $invoice->get_total(), |
| 325 | - 'recurring_amount' => $invoice->get_recurring_details( 'total' ), |
|
| 325 | + 'recurring_amount' => $invoice->get_recurring_details('total'), |
|
| 326 | 326 | 'bill_times' => $bill_times, |
| 327 | 327 | 'created' => $invoice_date, |
| 328 | 328 | 'expiration' => $expiration, |
@@ -331,11 +331,11 @@ discard block |
||
| 331 | 331 | 'transaction_id' => '', |
| 332 | 332 | ); |
| 333 | 333 | |
| 334 | - $subscription = wpinv_get_subscription( $invoice ); |
|
| 334 | + $subscription = wpinv_get_subscription($invoice); |
|
| 335 | 335 | |
| 336 | - if ( empty( $subscription ) ) { |
|
| 336 | + if (empty($subscription)) { |
|
| 337 | 337 | $subscription = new WPInv_Subscription(); |
| 338 | - $subscription->create( $args ); |
|
| 338 | + $subscription->create($args); |
|
| 339 | 339 | } |
| 340 | 340 | |
| 341 | 341 | return $subscription; |
@@ -7,206 +7,206 @@ discard block |
||
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | 9 | // MUST have WordPress. |
| 10 | -if ( !defined( 'WPINC' ) ) { |
|
| 11 | - exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) ); |
|
| 10 | +if (!defined('WPINC')) { |
|
| 11 | + exit('Do NOT access this file directly: ' . basename(__FILE__)); |
|
| 12 | 12 | } |
| 13 | 13 | |
| 14 | 14 | function wpinv_get_payment_gateways() { |
| 15 | 15 | // Default, built-in gateways |
| 16 | 16 | $gateways = array( |
| 17 | 17 | 'paypal' => array( |
| 18 | - 'admin_label' => __( 'PayPal Standard', 'invoicing' ), |
|
| 19 | - 'checkout_label' => __( 'PayPal Standard', 'invoicing' ), |
|
| 18 | + 'admin_label' => __('PayPal Standard', 'invoicing'), |
|
| 19 | + 'checkout_label' => __('PayPal Standard', 'invoicing'), |
|
| 20 | 20 | 'ordering' => 1, |
| 21 | 21 | ), |
| 22 | 22 | 'authorizenet' => array( |
| 23 | - 'admin_label' => __( 'Authorize.Net (AIM)', 'invoicing' ), |
|
| 24 | - 'checkout_label' => __( 'Authorize.Net - Credit Card / Debit Card', 'invoicing' ), |
|
| 23 | + 'admin_label' => __('Authorize.Net (AIM)', 'invoicing'), |
|
| 24 | + 'checkout_label' => __('Authorize.Net - Credit Card / Debit Card', 'invoicing'), |
|
| 25 | 25 | 'ordering' => 4, |
| 26 | 26 | ), |
| 27 | 27 | 'worldpay' => array( |
| 28 | - 'admin_label' => __( 'Worldpay', 'invoicing' ), |
|
| 29 | - 'checkout_label' => __( 'Worldpay - Credit Card / Debit Card', 'invoicing' ), |
|
| 28 | + 'admin_label' => __('Worldpay', 'invoicing'), |
|
| 29 | + 'checkout_label' => __('Worldpay - Credit Card / Debit Card', 'invoicing'), |
|
| 30 | 30 | 'ordering' => 5, |
| 31 | 31 | ), |
| 32 | 32 | 'bank_transfer' => array( |
| 33 | - 'admin_label' => __( 'Pre Bank Transfer', 'invoicing' ), |
|
| 34 | - 'checkout_label' => __( 'Pre Bank Transfer', 'invoicing' ), |
|
| 33 | + 'admin_label' => __('Pre Bank Transfer', 'invoicing'), |
|
| 34 | + 'checkout_label' => __('Pre Bank Transfer', 'invoicing'), |
|
| 35 | 35 | 'ordering' => 11, |
| 36 | 36 | ), |
| 37 | 37 | 'manual' => array( |
| 38 | - 'admin_label' => __( 'Manual Payment', 'invoicing' ), |
|
| 39 | - 'checkout_label' => __( 'Manual Payment', 'invoicing' ), |
|
| 38 | + 'admin_label' => __('Manual Payment', 'invoicing'), |
|
| 39 | + 'checkout_label' => __('Manual Payment', 'invoicing'), |
|
| 40 | 40 | 'ordering' => 12, |
| 41 | 41 | ), |
| 42 | 42 | ); |
| 43 | 43 | |
| 44 | - return apply_filters( 'wpinv_payment_gateways', $gateways ); |
|
| 44 | + return apply_filters('wpinv_payment_gateways', $gateways); |
|
| 45 | 45 | } |
| 46 | 46 | |
| 47 | -function wpinv_payment_gateway_titles( $all_gateways ) { |
|
| 47 | +function wpinv_payment_gateway_titles($all_gateways) { |
|
| 48 | 48 | global $wpinv_options; |
| 49 | 49 | |
| 50 | 50 | $gateways = array(); |
| 51 | - foreach ( $all_gateways as $key => $gateway ) { |
|
| 52 | - if ( !empty( $wpinv_options[$key . '_title'] ) ) { |
|
| 53 | - $all_gateways[$key]['checkout_label'] = __( $wpinv_options[$key . '_title'], 'invoicing' ); |
|
| 51 | + foreach ($all_gateways as $key => $gateway) { |
|
| 52 | + if (!empty($wpinv_options[$key . '_title'])) { |
|
| 53 | + $all_gateways[$key]['checkout_label'] = __($wpinv_options[$key . '_title'], 'invoicing'); |
|
| 54 | 54 | } |
| 55 | 55 | |
| 56 | - $gateways[$key] = isset( $wpinv_options[$key . '_ordering'] ) ? $wpinv_options[$key . '_ordering'] : ( isset( $gateway['ordering'] ) ? $gateway['ordering'] : '' ); |
|
| 56 | + $gateways[$key] = isset($wpinv_options[$key . '_ordering']) ? $wpinv_options[$key . '_ordering'] : (isset($gateway['ordering']) ? $gateway['ordering'] : ''); |
|
| 57 | 57 | } |
| 58 | 58 | |
| 59 | - asort( $gateways ); |
|
| 59 | + asort($gateways); |
|
| 60 | 60 | |
| 61 | - foreach ( $gateways as $gateway => $key ) { |
|
| 61 | + foreach ($gateways as $gateway => $key) { |
|
| 62 | 62 | $gateways[$gateway] = $all_gateways[$gateway]; |
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | return $gateways; |
| 66 | 66 | } |
| 67 | -add_filter( 'wpinv_payment_gateways', 'wpinv_payment_gateway_titles', 1000, 1 ); |
|
| 67 | +add_filter('wpinv_payment_gateways', 'wpinv_payment_gateway_titles', 1000, 1); |
|
| 68 | 68 | |
| 69 | -function wpinv_get_enabled_payment_gateways( $sort = false ) { |
|
| 69 | +function wpinv_get_enabled_payment_gateways($sort = false) { |
|
| 70 | 70 | $gateways = wpinv_get_payment_gateways(); |
| 71 | - $enabled = wpinv_get_option( 'gateways', false ); |
|
| 71 | + $enabled = wpinv_get_option('gateways', false); |
|
| 72 | 72 | |
| 73 | 73 | $gateway_list = array(); |
| 74 | 74 | |
| 75 | - foreach ( $gateways as $key => $gateway ) { |
|
| 76 | - if ( isset( $enabled[ $key ] ) && $enabled[ $key ] == 1 ) { |
|
| 77 | - $gateway_list[ $key ] = $gateway; |
|
| 75 | + foreach ($gateways as $key => $gateway) { |
|
| 76 | + if (isset($enabled[$key]) && $enabled[$key] == 1) { |
|
| 77 | + $gateway_list[$key] = $gateway; |
|
| 78 | 78 | } |
| 79 | 79 | } |
| 80 | 80 | |
| 81 | - if ( true === $sort ) { |
|
| 82 | - uasort( $gateway_list, 'wpinv_sort_gateway_order' ); |
|
| 81 | + if (true === $sort) { |
|
| 82 | + uasort($gateway_list, 'wpinv_sort_gateway_order'); |
|
| 83 | 83 | |
| 84 | 84 | // Reorder our gateways so the default is first |
| 85 | 85 | $default_gateway_id = wpinv_get_default_gateway(); |
| 86 | 86 | |
| 87 | - if ( wpinv_is_gateway_active( $default_gateway_id ) ) { |
|
| 88 | - $default_gateway = array( $default_gateway_id => $gateway_list[ $default_gateway_id ] ); |
|
| 89 | - unset( $gateway_list[ $default_gateway_id ] ); |
|
| 87 | + if (wpinv_is_gateway_active($default_gateway_id)) { |
|
| 88 | + $default_gateway = array($default_gateway_id => $gateway_list[$default_gateway_id]); |
|
| 89 | + unset($gateway_list[$default_gateway_id]); |
|
| 90 | 90 | |
| 91 | - $gateway_list = array_merge( $default_gateway, $gateway_list ); |
|
| 91 | + $gateway_list = array_merge($default_gateway, $gateway_list); |
|
| 92 | 92 | } |
| 93 | 93 | } |
| 94 | 94 | |
| 95 | - return apply_filters( 'wpinv_enabled_payment_gateways', $gateway_list ); |
|
| 95 | + return apply_filters('wpinv_enabled_payment_gateways', $gateway_list); |
|
| 96 | 96 | } |
| 97 | 97 | |
| 98 | -function wpinv_sort_gateway_order( $a, $b ) { |
|
| 98 | +function wpinv_sort_gateway_order($a, $b) { |
|
| 99 | 99 | return $a['ordering'] - $b['ordering']; |
| 100 | 100 | } |
| 101 | 101 | |
| 102 | -function wpinv_is_gateway_active( $gateway ) { |
|
| 102 | +function wpinv_is_gateway_active($gateway) { |
|
| 103 | 103 | $gateways = wpinv_get_enabled_payment_gateways(); |
| 104 | 104 | |
| 105 | - $ret = is_array($gateways) && $gateway ? array_key_exists( $gateway, $gateways ) : false; |
|
| 105 | + $ret = is_array($gateways) && $gateway ? array_key_exists($gateway, $gateways) : false; |
|
| 106 | 106 | |
| 107 | - return apply_filters( 'wpinv_is_gateway_active', $ret, $gateway, $gateways ); |
|
| 107 | + return apply_filters('wpinv_is_gateway_active', $ret, $gateway, $gateways); |
|
| 108 | 108 | } |
| 109 | 109 | |
| 110 | 110 | function wpinv_get_default_gateway() { |
| 111 | - $default = wpinv_get_option( 'default_gateway', 'paypal' ); |
|
| 111 | + $default = wpinv_get_option('default_gateway', 'paypal'); |
|
| 112 | 112 | |
| 113 | - if ( !wpinv_is_gateway_active( $default ) ) { |
|
| 113 | + if (!wpinv_is_gateway_active($default)) { |
|
| 114 | 114 | $gateways = wpinv_get_enabled_payment_gateways(); |
| 115 | - $gateways = array_keys( $gateways ); |
|
| 116 | - $default = reset( $gateways ); |
|
| 115 | + $gateways = array_keys($gateways); |
|
| 116 | + $default = reset($gateways); |
|
| 117 | 117 | } |
| 118 | 118 | |
| 119 | - return apply_filters( 'wpinv_default_gateway', $default ); |
|
| 119 | + return apply_filters('wpinv_default_gateway', $default); |
|
| 120 | 120 | } |
| 121 | 121 | |
| 122 | -function wpinv_get_gateway_admin_label( $gateway ) { |
|
| 122 | +function wpinv_get_gateway_admin_label($gateway) { |
|
| 123 | 123 | $gateways = wpinv_get_payment_gateways(); |
| 124 | - $label = isset( $gateways[ $gateway ] ) ? $gateways[ $gateway ]['admin_label'] : $gateway; |
|
| 125 | - $payment = isset( $_GET['id'] ) ? absint( $_GET['id'] ) : false; |
|
| 124 | + $label = isset($gateways[$gateway]) ? $gateways[$gateway]['admin_label'] : $gateway; |
|
| 125 | + $payment = isset($_GET['id']) ? absint($_GET['id']) : false; |
|
| 126 | 126 | |
| 127 | - if( $gateway == 'manual' && $payment ) { |
|
| 128 | - if( !( (float)wpinv_payment_total( $payment ) > 0 ) ) { |
|
| 129 | - $label = __( 'Free Purchase', 'invoicing' ); |
|
| 127 | + if ($gateway == 'manual' && $payment) { |
|
| 128 | + if (!((float) wpinv_payment_total($payment) > 0)) { |
|
| 129 | + $label = __('Free Purchase', 'invoicing'); |
|
| 130 | 130 | } |
| 131 | 131 | } |
| 132 | 132 | |
| 133 | - return apply_filters( 'wpinv_gateway_admin_label', $label, $gateway ); |
|
| 133 | + return apply_filters('wpinv_gateway_admin_label', $label, $gateway); |
|
| 134 | 134 | } |
| 135 | 135 | |
| 136 | -function wpinv_get_gateway_description( $gateway ) { |
|
| 136 | +function wpinv_get_gateway_description($gateway) { |
|
| 137 | 137 | global $wpinv_options; |
| 138 | 138 | |
| 139 | - $description = isset( $wpinv_options[$gateway . '_desc'] ) ? $wpinv_options[$gateway . '_desc'] : ''; |
|
| 139 | + $description = isset($wpinv_options[$gateway . '_desc']) ? $wpinv_options[$gateway . '_desc'] : ''; |
|
| 140 | 140 | |
| 141 | - return apply_filters( 'wpinv_gateway_description', $description, $gateway ); |
|
| 141 | + return apply_filters('wpinv_gateway_description', $description, $gateway); |
|
| 142 | 142 | } |
| 143 | 143 | |
| 144 | -function wpinv_get_gateway_button_label( $gateway ) { |
|
| 145 | - return apply_filters( 'wpinv_gateway_' . $gateway . '_button_label', '' ); |
|
| 144 | +function wpinv_get_gateway_button_label($gateway) { |
|
| 145 | + return apply_filters('wpinv_gateway_' . $gateway . '_button_label', ''); |
|
| 146 | 146 | } |
| 147 | 147 | |
| 148 | -function wpinv_get_gateway_checkout_label( $gateway ) { |
|
| 148 | +function wpinv_get_gateway_checkout_label($gateway) { |
|
| 149 | 149 | $gateways = wpinv_get_payment_gateways(); |
| 150 | - $label = isset( $gateways[ $gateway ] ) ? $gateways[ $gateway ]['checkout_label'] : $gateway; |
|
| 150 | + $label = isset($gateways[$gateway]) ? $gateways[$gateway]['checkout_label'] : $gateway; |
|
| 151 | 151 | |
| 152 | - if( $gateway == 'manual' ) { |
|
| 153 | - $label = __( 'Manual Payment', 'invoicing' ); |
|
| 152 | + if ($gateway == 'manual') { |
|
| 153 | + $label = __('Manual Payment', 'invoicing'); |
|
| 154 | 154 | } |
| 155 | 155 | |
| 156 | - return apply_filters( 'wpinv_gateway_checkout_label', $label, $gateway ); |
|
| 156 | + return apply_filters('wpinv_gateway_checkout_label', $label, $gateway); |
|
| 157 | 157 | } |
| 158 | 158 | |
| 159 | -function wpinv_settings_sections_gateways( $settings ) { |
|
| 159 | +function wpinv_settings_sections_gateways($settings) { |
|
| 160 | 160 | $gateways = wpinv_get_payment_gateways(); |
| 161 | 161 | |
| 162 | 162 | if (!empty($gateways)) { |
| 163 | - foreach ($gateways as $key => $gateway) { |
|
| 163 | + foreach ($gateways as $key => $gateway) { |
|
| 164 | 164 | $settings[$key] = $gateway['admin_label']; |
| 165 | 165 | } |
| 166 | 166 | } |
| 167 | 167 | |
| 168 | 168 | return $settings; |
| 169 | 169 | } |
| 170 | -add_filter( 'wpinv_settings_sections_gateways', 'wpinv_settings_sections_gateways', 10, 1 ); |
|
| 170 | +add_filter('wpinv_settings_sections_gateways', 'wpinv_settings_sections_gateways', 10, 1); |
|
| 171 | 171 | |
| 172 | -function wpinv_settings_gateways( $settings ) { |
|
| 172 | +function wpinv_settings_gateways($settings) { |
|
| 173 | 173 | $gateways = wpinv_get_payment_gateways(); |
| 174 | 174 | |
| 175 | 175 | if (!empty($gateways)) { |
| 176 | - foreach ($gateways as $key => $gateway) { |
|
| 176 | + foreach ($gateways as $key => $gateway) { |
|
| 177 | 177 | $setting = array(); |
| 178 | 178 | $setting[$key . '_header'] = array( |
| 179 | 179 | 'id' => 'gateway_header', |
| 180 | - 'name' => '<h3>' . wp_sprintf( __( '%s Settings', 'invoicing' ), $gateway['admin_label'] ) . '</h3>', |
|
| 180 | + 'name' => '<h3>' . wp_sprintf(__('%s Settings', 'invoicing'), $gateway['admin_label']) . '</h3>', |
|
| 181 | 181 | 'custom' => $key, |
| 182 | 182 | 'type' => 'gateway_header', |
| 183 | 183 | ); |
| 184 | 184 | $setting[$key . '_active'] = array( |
| 185 | 185 | 'id' => $key . '_active', |
| 186 | - 'name' => __( 'Active', 'invoicing' ), |
|
| 187 | - 'desc' => wp_sprintf( __( 'Enable %s', 'invoicing' ), $gateway['admin_label'] ), |
|
| 186 | + 'name' => __('Active', 'invoicing'), |
|
| 187 | + 'desc' => wp_sprintf(__('Enable %s', 'invoicing'), $gateway['admin_label']), |
|
| 188 | 188 | 'type' => 'checkbox', |
| 189 | 189 | ); |
| 190 | 190 | |
| 191 | 191 | $setting[$key . '_title'] = array( |
| 192 | 192 | 'id' => $key . '_title', |
| 193 | - 'name' => __( 'Title', 'invoicing' ), |
|
| 194 | - 'desc' => __( 'This controls the title which the user sees during checkout.', 'invoicing' ), |
|
| 193 | + 'name' => __('Title', 'invoicing'), |
|
| 194 | + 'desc' => __('This controls the title which the user sees during checkout.', 'invoicing'), |
|
| 195 | 195 | 'type' => 'text', |
| 196 | 196 | 'std' => isset($gateway['checkout_label']) ? $gateway['checkout_label'] : '' |
| 197 | 197 | ); |
| 198 | 198 | |
| 199 | 199 | $setting[$key . '_desc'] = array( |
| 200 | 200 | 'id' => $key . '_desc', |
| 201 | - 'name' => __( 'Description', 'invoicing' ), |
|
| 202 | - 'desc' => __( 'This controls the description which the user sees during checkout.', 'invoicing' ), |
|
| 201 | + 'name' => __('Description', 'invoicing'), |
|
| 202 | + 'desc' => __('This controls the description which the user sees during checkout.', 'invoicing'), |
|
| 203 | 203 | 'type' => 'text', |
| 204 | 204 | 'size' => 'large' |
| 205 | 205 | ); |
| 206 | 206 | |
| 207 | 207 | $setting[$key . '_ordering'] = array( |
| 208 | 208 | 'id' => $key . '_ordering', |
| 209 | - 'name' => __( 'Display Order', 'invoicing' ), |
|
| 209 | + 'name' => __('Display Order', 'invoicing'), |
|
| 210 | 210 | 'type' => 'number', |
| 211 | 211 | 'size' => 'small', |
| 212 | 212 | 'std' => isset($gateway['ordering']) ? $gateway['ordering'] : '10', |
@@ -215,8 +215,8 @@ discard block |
||
| 215 | 215 | 'step' => '1' |
| 216 | 216 | ); |
| 217 | 217 | |
| 218 | - $setting = apply_filters( 'wpinv_gateway_settings', $setting, $key ); |
|
| 219 | - $setting = apply_filters( 'wpinv_gateway_settings_' . $key, $setting ); |
|
| 218 | + $setting = apply_filters('wpinv_gateway_settings', $setting, $key); |
|
| 219 | + $setting = apply_filters('wpinv_gateway_settings_' . $key, $setting); |
|
| 220 | 220 | |
| 221 | 221 | $settings[$key] = $setting; |
| 222 | 222 | } |
@@ -224,106 +224,106 @@ discard block |
||
| 224 | 224 | |
| 225 | 225 | return $settings; |
| 226 | 226 | } |
| 227 | -add_filter( 'wpinv_settings_gateways', 'wpinv_settings_gateways', 10, 1 ); |
|
| 227 | +add_filter('wpinv_settings_gateways', 'wpinv_settings_gateways', 10, 1); |
|
| 228 | 228 | |
| 229 | -function wpinv_gateway_header_callback( $args ) { |
|
| 230 | - echo '<input type="hidden" id="wpinv_settings[save_gateway]" name="wpinv_settings[save_gateway]" value="' . esc_attr( $args['custom'] ) . '" />'; |
|
| 229 | +function wpinv_gateway_header_callback($args) { |
|
| 230 | + echo '<input type="hidden" id="wpinv_settings[save_gateway]" name="wpinv_settings[save_gateway]" value="' . esc_attr($args['custom']) . '" />'; |
|
| 231 | 231 | } |
| 232 | 232 | |
| 233 | -function wpinv_get_gateway_supports( $gateway ) { |
|
| 233 | +function wpinv_get_gateway_supports($gateway) { |
|
| 234 | 234 | $gateways = wpinv_get_enabled_payment_gateways(); |
| 235 | - $supports = isset( $gateways[ $gateway ]['supports'] ) ? $gateways[ $gateway ]['supports'] : array(); |
|
| 236 | - return apply_filters( 'wpinv_gateway_supports', $supports, $gateway ); |
|
| 235 | + $supports = isset($gateways[$gateway]['supports']) ? $gateways[$gateway]['supports'] : array(); |
|
| 236 | + return apply_filters('wpinv_gateway_supports', $supports, $gateway); |
|
| 237 | 237 | } |
| 238 | 238 | |
| 239 | -function wpinv_gateway_supports_buy_now( $gateway ) { |
|
| 240 | - $supports = wpinv_get_gateway_supports( $gateway ); |
|
| 241 | - $ret = in_array( 'buy_now', $supports ); |
|
| 242 | - return apply_filters( 'wpinv_gateway_supports_buy_now', $ret, $gateway ); |
|
| 239 | +function wpinv_gateway_supports_buy_now($gateway) { |
|
| 240 | + $supports = wpinv_get_gateway_supports($gateway); |
|
| 241 | + $ret = in_array('buy_now', $supports); |
|
| 242 | + return apply_filters('wpinv_gateway_supports_buy_now', $ret, $gateway); |
|
| 243 | 243 | } |
| 244 | 244 | |
| 245 | 245 | function wpinv_shop_supports_buy_now() { |
| 246 | 246 | $gateways = wpinv_get_enabled_payment_gateways(); |
| 247 | 247 | $ret = false; |
| 248 | 248 | |
| 249 | - if ( !wpinv_use_taxes() && $gateways ) { |
|
| 250 | - foreach ( $gateways as $gateway_id => $gateway ) { |
|
| 251 | - if ( wpinv_gateway_supports_buy_now( $gateway_id ) ) { |
|
| 249 | + if (!wpinv_use_taxes() && $gateways) { |
|
| 250 | + foreach ($gateways as $gateway_id => $gateway) { |
|
| 251 | + if (wpinv_gateway_supports_buy_now($gateway_id)) { |
|
| 252 | 252 | $ret = true; |
| 253 | 253 | break; |
| 254 | 254 | } |
| 255 | 255 | } |
| 256 | 256 | } |
| 257 | 257 | |
| 258 | - return apply_filters( 'wpinv_shop_supports_buy_now', $ret ); |
|
| 258 | + return apply_filters('wpinv_shop_supports_buy_now', $ret); |
|
| 259 | 259 | } |
| 260 | 260 | |
| 261 | -function wpinv_send_to_gateway( $gateway, $payment_data ) { |
|
| 262 | - $payment_data['gateway_nonce'] = wp_create_nonce( 'wpi-gateway' ); |
|
| 261 | +function wpinv_send_to_gateway($gateway, $payment_data) { |
|
| 262 | + $payment_data['gateway_nonce'] = wp_create_nonce('wpi-gateway'); |
|
| 263 | 263 | |
| 264 | 264 | // $gateway must match the ID used when registering the gateway |
| 265 | - do_action( 'wpinv_gateway_' . $gateway, $payment_data ); |
|
| 265 | + do_action('wpinv_gateway_' . $gateway, $payment_data); |
|
| 266 | 266 | } |
| 267 | 267 | |
| 268 | 268 | function wpinv_show_gateways() { |
| 269 | 269 | $gateways = wpinv_get_enabled_payment_gateways(); |
| 270 | 270 | $show_gateways = false; |
| 271 | 271 | |
| 272 | - $chosen_gateway = isset( $_GET['payment-mode'] ) ? preg_replace('/[^a-zA-Z0-9-_]+/', '', $_GET['payment-mode'] ) : false; |
|
| 272 | + $chosen_gateway = isset($_GET['payment-mode']) ? preg_replace('/[^a-zA-Z0-9-_]+/', '', $_GET['payment-mode']) : false; |
|
| 273 | 273 | |
| 274 | - if ( count( $gateways ) > 1 && empty( $chosen_gateway ) ) { |
|
| 274 | + if (count($gateways) > 1 && empty($chosen_gateway)) { |
|
| 275 | 275 | $show_gateways = true; |
| 276 | - if ( wpinv_get_cart_total() <= 0 ) { |
|
| 276 | + if (wpinv_get_cart_total() <= 0) { |
|
| 277 | 277 | $show_gateways = false; |
| 278 | 278 | } |
| 279 | 279 | } |
| 280 | 280 | |
| 281 | - if ( !$show_gateways && wpinv_cart_has_recurring_item() ) { |
|
| 281 | + if (!$show_gateways && wpinv_cart_has_recurring_item()) { |
|
| 282 | 282 | $show_gateways = true; |
| 283 | 283 | } |
| 284 | 284 | |
| 285 | - return apply_filters( 'wpinv_show_gateways', $show_gateways ); |
|
| 285 | + return apply_filters('wpinv_show_gateways', $show_gateways); |
|
| 286 | 286 | } |
| 287 | 287 | |
| 288 | -function wpinv_get_chosen_gateway( $invoice_id = 0 ) { |
|
| 289 | - $gateways = array_keys( wpinv_get_enabled_payment_gateways() ); |
|
| 288 | +function wpinv_get_chosen_gateway($invoice_id = 0) { |
|
| 289 | + $gateways = array_keys(wpinv_get_enabled_payment_gateways()); |
|
| 290 | 290 | |
| 291 | 291 | $chosen = false; |
| 292 | - if ( $invoice_id > 0 && $invoice = wpinv_get_invoice( $invoice_id ) ) { |
|
| 292 | + if ($invoice_id > 0 && $invoice = wpinv_get_invoice($invoice_id)) { |
|
| 293 | 293 | $chosen = $invoice->get_gateway(); |
| 294 | 294 | } |
| 295 | 295 | |
| 296 | - $chosen = isset( $_REQUEST['payment-mode'] ) ? sanitize_text_field( $_REQUEST['payment-mode'] ) : $chosen; |
|
| 296 | + $chosen = isset($_REQUEST['payment-mode']) ? sanitize_text_field($_REQUEST['payment-mode']) : $chosen; |
|
| 297 | 297 | |
| 298 | - if ( false !== $chosen ) { |
|
| 299 | - $chosen = preg_replace('/[^a-zA-Z0-9-_]+/', '', $chosen ); |
|
| 298 | + if (false !== $chosen) { |
|
| 299 | + $chosen = preg_replace('/[^a-zA-Z0-9-_]+/', '', $chosen); |
|
| 300 | 300 | } |
| 301 | 301 | |
| 302 | - if ( ! empty ( $chosen ) ) { |
|
| 303 | - $enabled_gateway = urldecode( $chosen ); |
|
| 304 | - } else if ( !empty( $invoice ) && (float)$invoice->get_subtotal() <= 0 ) { |
|
| 302 | + if (!empty ($chosen)) { |
|
| 303 | + $enabled_gateway = urldecode($chosen); |
|
| 304 | + } else if (!empty($invoice) && (float) $invoice->get_subtotal() <= 0) { |
|
| 305 | 305 | $enabled_gateway = 'manual'; |
| 306 | 306 | } else { |
| 307 | 307 | $enabled_gateway = wpinv_get_default_gateway(); |
| 308 | 308 | } |
| 309 | 309 | |
| 310 | - if ( !wpinv_is_gateway_active( $enabled_gateway ) && !empty( $gateways ) ) { |
|
| 311 | - if(wpinv_is_gateway_active( wpinv_get_default_gateway()) ){ |
|
| 310 | + if (!wpinv_is_gateway_active($enabled_gateway) && !empty($gateways)) { |
|
| 311 | + if (wpinv_is_gateway_active(wpinv_get_default_gateway())) { |
|
| 312 | 312 | $enabled_gateway = wpinv_get_default_gateway(); |
| 313 | - }else{ |
|
| 313 | + } else { |
|
| 314 | 314 | $enabled_gateway = $gateways[0]; |
| 315 | 315 | } |
| 316 | 316 | |
| 317 | 317 | } |
| 318 | 318 | |
| 319 | - return apply_filters( 'wpinv_chosen_gateway', $enabled_gateway ); |
|
| 319 | + return apply_filters('wpinv_chosen_gateway', $enabled_gateway); |
|
| 320 | 320 | } |
| 321 | 321 | |
| 322 | -function wpinv_record_gateway_error( $title = '', $message = '', $parent = 0 ) { |
|
| 323 | - return wpinv_error_log( $message, $title ); |
|
| 322 | +function wpinv_record_gateway_error($title = '', $message = '', $parent = 0) { |
|
| 323 | + return wpinv_error_log($message, $title); |
|
| 324 | 324 | } |
| 325 | 325 | |
| 326 | -function wpinv_count_sales_by_gateway( $gateway_id = 'paypal', $status = 'publish' ) { |
|
| 326 | +function wpinv_count_sales_by_gateway($gateway_id = 'paypal', $status = 'publish') { |
|
| 327 | 327 | $ret = 0; |
| 328 | 328 | $args = array( |
| 329 | 329 | 'meta_key' => '_wpinv_gateway', |
@@ -334,48 +334,48 @@ discard block |
||
| 334 | 334 | 'fields' => 'ids' |
| 335 | 335 | ); |
| 336 | 336 | |
| 337 | - $payments = new WP_Query( $args ); |
|
| 337 | + $payments = new WP_Query($args); |
|
| 338 | 338 | |
| 339 | - if( $payments ) |
|
| 339 | + if ($payments) |
|
| 340 | 340 | $ret = $payments->post_count; |
| 341 | 341 | return $ret; |
| 342 | 342 | } |
| 343 | 343 | |
| 344 | -function wpinv_settings_update_gateways( $input ) { |
|
| 344 | +function wpinv_settings_update_gateways($input) { |
|
| 345 | 345 | global $wpinv_options; |
| 346 | 346 | |
| 347 | - if ( !empty( $input['save_gateway'] ) ) { |
|
| 348 | - $gateways = wpinv_get_option( 'gateways', false ); |
|
| 347 | + if (!empty($input['save_gateway'])) { |
|
| 348 | + $gateways = wpinv_get_option('gateways', false); |
|
| 349 | 349 | $gateways = !empty($gateways) ? $gateways : array(); |
| 350 | 350 | $gateway = $input['save_gateway']; |
| 351 | 351 | |
| 352 | - if ( !empty( $input[$gateway . '_active'] ) ) { |
|
| 352 | + if (!empty($input[$gateway . '_active'])) { |
|
| 353 | 353 | $gateways[$gateway] = 1; |
| 354 | 354 | } else { |
| 355 | - if ( isset( $gateways[$gateway] ) ) { |
|
| 356 | - unset( $gateways[$gateway] ); |
|
| 355 | + if (isset($gateways[$gateway])) { |
|
| 356 | + unset($gateways[$gateway]); |
|
| 357 | 357 | } |
| 358 | 358 | } |
| 359 | 359 | |
| 360 | 360 | $input['gateways'] = $gateways; |
| 361 | 361 | } |
| 362 | 362 | |
| 363 | - if ( !empty( $input['default_gateway'] ) ) { |
|
| 363 | + if (!empty($input['default_gateway'])) { |
|
| 364 | 364 | $gateways = wpinv_get_payment_gateways(); |
| 365 | 365 | |
| 366 | - foreach ( $gateways as $key => $gateway ) { |
|
| 367 | - $active = 0; |
|
| 368 | - if ( !empty( $input['gateways'] ) && !empty( $input['gateways'][$key] ) ) { |
|
| 366 | + foreach ($gateways as $key => $gateway) { |
|
| 367 | + $active = 0; |
|
| 368 | + if (!empty($input['gateways']) && !empty($input['gateways'][$key])) { |
|
| 369 | 369 | $active = 1; |
| 370 | 370 | } |
| 371 | 371 | |
| 372 | 372 | $input[$key . '_active'] = $active; |
| 373 | 373 | |
| 374 | - if ( empty( $wpinv_options[$key . '_title'] ) ) { |
|
| 374 | + if (empty($wpinv_options[$key . '_title'])) { |
|
| 375 | 375 | $input[$key . '_title'] = $gateway['checkout_label']; |
| 376 | 376 | } |
| 377 | 377 | |
| 378 | - if ( !isset( $wpinv_options[$key . '_ordering'] ) && isset( $gateway['ordering'] ) ) { |
|
| 378 | + if (!isset($wpinv_options[$key . '_ordering']) && isset($gateway['ordering'])) { |
|
| 379 | 379 | $input[$key . '_ordering'] = $gateway['ordering']; |
| 380 | 380 | } |
| 381 | 381 | } |
@@ -383,27 +383,27 @@ discard block |
||
| 383 | 383 | |
| 384 | 384 | return $input; |
| 385 | 385 | } |
| 386 | -add_filter( 'wpinv_settings_tab_gateways_sanitize', 'wpinv_settings_update_gateways', 10, 1 ); |
|
| 386 | +add_filter('wpinv_settings_tab_gateways_sanitize', 'wpinv_settings_update_gateways', 10, 1); |
|
| 387 | 387 | |
| 388 | 388 | // PayPal Standard settings |
| 389 | -function wpinv_gateway_settings_paypal( $setting ) { |
|
| 390 | - $setting['paypal_active']['desc'] = $setting['paypal_active']['desc'] . ' ' . __( '( Supported Currencies: AUD, BRL, CAD, CZK, DKK, EUR, HKD, HUF, ILS, JPY, MYR, MXN, NOK, NZD, PHP, PLN, GBP, SGD, SEK, CHF, TWD, THB, USD )', 'invoicing' ); |
|
| 391 | - $setting['paypal_desc']['std'] = __( 'Pay via PayPal: you can pay with your credit card if you don\'t have a PayPal account.', 'invoicing' ); |
|
| 389 | +function wpinv_gateway_settings_paypal($setting) { |
|
| 390 | + $setting['paypal_active']['desc'] = $setting['paypal_active']['desc'] . ' ' . __('( Supported Currencies: AUD, BRL, CAD, CZK, DKK, EUR, HKD, HUF, ILS, JPY, MYR, MXN, NOK, NZD, PHP, PLN, GBP, SGD, SEK, CHF, TWD, THB, USD )', 'invoicing'); |
|
| 391 | + $setting['paypal_desc']['std'] = __('Pay via PayPal: you can pay with your credit card if you don\'t have a PayPal account.', 'invoicing'); |
|
| 392 | 392 | |
| 393 | 393 | $setting['paypal_sandbox'] = array( |
| 394 | 394 | 'type' => 'checkbox', |
| 395 | 395 | 'id' => 'paypal_sandbox', |
| 396 | - 'name' => __( 'PayPal Sandbox', 'invoicing' ), |
|
| 397 | - 'desc' => __( 'PayPal sandbox can be used to test payments.', 'invoicing' ), |
|
| 396 | + 'name' => __('PayPal Sandbox', 'invoicing'), |
|
| 397 | + 'desc' => __('PayPal sandbox can be used to test payments.', 'invoicing'), |
|
| 398 | 398 | 'std' => 1 |
| 399 | 399 | ); |
| 400 | 400 | |
| 401 | 401 | $setting['paypal_email'] = array( |
| 402 | 402 | 'type' => 'text', |
| 403 | 403 | 'id' => 'paypal_email', |
| 404 | - 'name' => __( 'PayPal Email', 'invoicing' ), |
|
| 405 | - 'desc' => __( 'Please enter your PayPal account\'s email address. Ex: [email protected]', 'invoicing' ), |
|
| 406 | - 'std' => __( '[email protected]', 'invoicing' ), |
|
| 404 | + 'name' => __('PayPal Email', 'invoicing'), |
|
| 405 | + 'desc' => __('Please enter your PayPal account\'s email address. Ex: [email protected]', 'invoicing'), |
|
| 406 | + 'std' => __('[email protected]', 'invoicing'), |
|
| 407 | 407 | ); |
| 408 | 408 | /* |
| 409 | 409 | $setting['paypal_ipn_url'] = array( |
@@ -417,139 +417,139 @@ discard block |
||
| 417 | 417 | |
| 418 | 418 | return $setting; |
| 419 | 419 | } |
| 420 | -add_filter( 'wpinv_gateway_settings_paypal', 'wpinv_gateway_settings_paypal', 10, 1 ); |
|
| 420 | +add_filter('wpinv_gateway_settings_paypal', 'wpinv_gateway_settings_paypal', 10, 1); |
|
| 421 | 421 | |
| 422 | 422 | // Pre Bank Transfer settings |
| 423 | -function wpinv_gateway_settings_bank_transfer( $setting ) { |
|
| 424 | - $setting['bank_transfer_desc']['std'] = __( 'Make your payment directly into our bank account. Please use your Invoice ID as the payment reference. Your invoice won\'t be processed until the funds have cleared in our account.', 'invoicing' ); |
|
| 423 | +function wpinv_gateway_settings_bank_transfer($setting) { |
|
| 424 | + $setting['bank_transfer_desc']['std'] = __('Make your payment directly into our bank account. Please use your Invoice ID as the payment reference. Your invoice won\'t be processed until the funds have cleared in our account.', 'invoicing'); |
|
| 425 | 425 | |
| 426 | 426 | $setting['bank_transfer_ac_name'] = array( |
| 427 | 427 | 'type' => 'text', |
| 428 | 428 | 'id' => 'bank_transfer_ac_name', |
| 429 | - 'name' => __( 'Account Name', 'invoicing' ), |
|
| 430 | - 'desc' => __( 'Enter the bank account name to which you want to transfer payment.', 'invoicing' ), |
|
| 431 | - 'std' => __( 'Mr. John Martin', 'invoicing' ), |
|
| 429 | + 'name' => __('Account Name', 'invoicing'), |
|
| 430 | + 'desc' => __('Enter the bank account name to which you want to transfer payment.', 'invoicing'), |
|
| 431 | + 'std' => __('Mr. John Martin', 'invoicing'), |
|
| 432 | 432 | ); |
| 433 | 433 | |
| 434 | 434 | $setting['bank_transfer_ac_no'] = array( |
| 435 | 435 | 'type' => 'text', |
| 436 | 436 | 'id' => 'bank_transfer_ac_no', |
| 437 | - 'name' => __( 'Account Number', 'invoicing' ), |
|
| 438 | - 'desc' => __( 'Enter your bank account number.', 'invoicing' ), |
|
| 439 | - 'std' => __( 'TEST1234567890', 'invoicing' ), |
|
| 437 | + 'name' => __('Account Number', 'invoicing'), |
|
| 438 | + 'desc' => __('Enter your bank account number.', 'invoicing'), |
|
| 439 | + 'std' => __('TEST1234567890', 'invoicing'), |
|
| 440 | 440 | ); |
| 441 | 441 | |
| 442 | 442 | $setting['bank_transfer_bank_name'] = array( |
| 443 | 443 | 'type' => 'text', |
| 444 | 444 | 'id' => 'bank_transfer_bank_name', |
| 445 | - 'name' => __( 'Bank Name', 'invoicing' ), |
|
| 446 | - 'desc' => __( 'Enter the bank name to which you want to transfer payment.', 'invoicing' ), |
|
| 447 | - 'std' => __( 'ICICI Bank', 'invoicing' ), |
|
| 445 | + 'name' => __('Bank Name', 'invoicing'), |
|
| 446 | + 'desc' => __('Enter the bank name to which you want to transfer payment.', 'invoicing'), |
|
| 447 | + 'std' => __('ICICI Bank', 'invoicing'), |
|
| 448 | 448 | ); |
| 449 | 449 | |
| 450 | 450 | $setting['bank_transfer_ifsc'] = array( |
| 451 | 451 | 'type' => 'text', |
| 452 | 452 | 'id' => 'bank_transfer_ifsc', |
| 453 | - 'name' => __( 'IFSC Code', 'invoicing' ), |
|
| 454 | - 'desc' => __( 'Enter your bank IFSC code.', 'invoicing' ), |
|
| 455 | - 'std' => __( 'ICIC0001234', 'invoicing' ), |
|
| 453 | + 'name' => __('IFSC Code', 'invoicing'), |
|
| 454 | + 'desc' => __('Enter your bank IFSC code.', 'invoicing'), |
|
| 455 | + 'std' => __('ICIC0001234', 'invoicing'), |
|
| 456 | 456 | ); |
| 457 | 457 | |
| 458 | 458 | $setting['bank_transfer_iban'] = array( |
| 459 | 459 | 'type' => 'text', |
| 460 | 460 | 'id' => 'bank_transfer_iban', |
| 461 | - 'name' => __( 'IBAN', 'invoicing' ), |
|
| 462 | - 'desc' => __( 'Enter your International Bank Account Number(IBAN).', 'invoicing' ), |
|
| 463 | - 'std' => __( 'GB29NWBK60161331926819', 'invoicing' ), |
|
| 461 | + 'name' => __('IBAN', 'invoicing'), |
|
| 462 | + 'desc' => __('Enter your International Bank Account Number(IBAN).', 'invoicing'), |
|
| 463 | + 'std' => __('GB29NWBK60161331926819', 'invoicing'), |
|
| 464 | 464 | ); |
| 465 | 465 | |
| 466 | 466 | $setting['bank_transfer_bic'] = array( |
| 467 | 467 | 'type' => 'text', |
| 468 | 468 | 'id' => 'bank_transfer_bic', |
| 469 | - 'name' => __( 'BIC/Swift Code', 'invoicing' ), |
|
| 470 | - 'std' => __( 'ICICGB2L129', 'invoicing' ), |
|
| 469 | + 'name' => __('BIC/Swift Code', 'invoicing'), |
|
| 470 | + 'std' => __('ICICGB2L129', 'invoicing'), |
|
| 471 | 471 | ); |
| 472 | 472 | |
| 473 | 473 | $setting['bank_transfer_sort_code'] = array( |
| 474 | 474 | 'type' => 'text', |
| 475 | 475 | 'id' => 'bank_transfer_sort_code', |
| 476 | - 'name' => __( 'Sort Code', 'invoicing' ), |
|
| 477 | - 'std' => __( '12-34-56', 'invoicing' ), |
|
| 476 | + 'name' => __('Sort Code', 'invoicing'), |
|
| 477 | + 'std' => __('12-34-56', 'invoicing'), |
|
| 478 | 478 | ); |
| 479 | 479 | |
| 480 | 480 | $setting['bank_transfer_info'] = array( |
| 481 | 481 | 'id' => 'bank_transfer_info', |
| 482 | - 'name' => __( 'Instructions', 'invoicing' ), |
|
| 483 | - 'desc' => __( 'Instructions that will be added to the thank you page and emails.', 'invoicing' ), |
|
| 482 | + 'name' => __('Instructions', 'invoicing'), |
|
| 483 | + 'desc' => __('Instructions that will be added to the thank you page and emails.', 'invoicing'), |
|
| 484 | 484 | 'type' => 'textarea', |
| 485 | - 'std' => __( 'Make your payment directly into our bank account. Please use your Invoice ID as the payment reference. Your invoice won\'t be processed until the funds have cleared in our account.', 'invoicing' ), |
|
| 485 | + 'std' => __('Make your payment directly into our bank account. Please use your Invoice ID as the payment reference. Your invoice won\'t be processed until the funds have cleared in our account.', 'invoicing'), |
|
| 486 | 486 | 'cols' => 37, |
| 487 | 487 | 'rows' => 5 |
| 488 | 488 | ); |
| 489 | 489 | |
| 490 | 490 | return $setting; |
| 491 | 491 | } |
| 492 | -add_filter( 'wpinv_gateway_settings_bank_transfer', 'wpinv_gateway_settings_bank_transfer', 10, 1 ); |
|
| 492 | +add_filter('wpinv_gateway_settings_bank_transfer', 'wpinv_gateway_settings_bank_transfer', 10, 1); |
|
| 493 | 493 | |
| 494 | 494 | // Authorize.Net settings |
| 495 | -function wpinv_gateway_settings_authorizenet( $setting ) { |
|
| 496 | - $setting['authorizenet_active']['desc'] = $setting['authorizenet_active']['desc'] . ' ' . __( '( Supported Currencies: AUD, CAD, CHF, DKK, EUR, GBP, JPY, NOK, NZD, PLN, SEK, USD, ZAR )', 'invoicing' ); |
|
| 497 | - $setting['authorizenet_desc']['std'] = __( 'Pay using a Authorize.Net to process Credit card / Debit card transactions.', 'invoicing' ); |
|
| 495 | +function wpinv_gateway_settings_authorizenet($setting) { |
|
| 496 | + $setting['authorizenet_active']['desc'] = $setting['authorizenet_active']['desc'] . ' ' . __('( Supported Currencies: AUD, CAD, CHF, DKK, EUR, GBP, JPY, NOK, NZD, PLN, SEK, USD, ZAR )', 'invoicing'); |
|
| 497 | + $setting['authorizenet_desc']['std'] = __('Pay using a Authorize.Net to process Credit card / Debit card transactions.', 'invoicing'); |
|
| 498 | 498 | |
| 499 | 499 | $setting['authorizenet_sandbox'] = array( |
| 500 | 500 | 'type' => 'checkbox', |
| 501 | 501 | 'id' => 'authorizenet_sandbox', |
| 502 | - 'name' => __( 'Authorize.Net Test Mode', 'invoicing' ), |
|
| 503 | - 'desc' => __( 'Enable Authorize.Net test mode to test payments.', 'invoicing' ), |
|
| 502 | + 'name' => __('Authorize.Net Test Mode', 'invoicing'), |
|
| 503 | + 'desc' => __('Enable Authorize.Net test mode to test payments.', 'invoicing'), |
|
| 504 | 504 | 'std' => 1 |
| 505 | 505 | ); |
| 506 | 506 | |
| 507 | 507 | $setting['authorizenet_login_id'] = array( |
| 508 | 508 | 'type' => 'text', |
| 509 | 509 | 'id' => 'authorizenet_login_id', |
| 510 | - 'name' => __( 'API Login ID', 'invoicing' ), |
|
| 511 | - 'desc' => __( 'API Login ID can be obtained from Authorize.Net Account > Settings > Security Settings > General Security Settings > API Credentials & Keys. Example : 2j4rBekUnD', 'invoicing' ), |
|
| 510 | + 'name' => __('API Login ID', 'invoicing'), |
|
| 511 | + 'desc' => __('API Login ID can be obtained from Authorize.Net Account > Settings > Security Settings > General Security Settings > API Credentials & Keys. Example : 2j4rBekUnD', 'invoicing'), |
|
| 512 | 512 | 'std' => '2j4rBekUnD', |
| 513 | 513 | ); |
| 514 | 514 | |
| 515 | 515 | $setting['authorizenet_transaction_key'] = array( |
| 516 | 516 | 'type' => 'text', |
| 517 | 517 | 'id' => 'authorizenet_transaction_key', |
| 518 | - 'name' => __( 'Transaction Key', 'invoicing' ), |
|
| 519 | - 'desc' => __( 'Transaction Key can be obtained from Authorize.Net Account > Settings > Security Settings > General Security Settings > API Credentials & Keys. Example : 4vyBUOJgR74679xa', 'invoicing' ), |
|
| 518 | + 'name' => __('Transaction Key', 'invoicing'), |
|
| 519 | + 'desc' => __('Transaction Key can be obtained from Authorize.Net Account > Settings > Security Settings > General Security Settings > API Credentials & Keys. Example : 4vyBUOJgR74679xa', 'invoicing'), |
|
| 520 | 520 | 'std' => '4vyBUOJgR74679xa', |
| 521 | 521 | ); |
| 522 | 522 | |
| 523 | 523 | $setting['authorizenet_md5_hash'] = array( |
| 524 | 524 | 'type' => 'text', |
| 525 | 525 | 'id' => 'authorizenet_md5_hash', |
| 526 | - 'name' => __( 'MD5-Hash', 'invoicing' ), |
|
| 527 | - 'desc' => __( 'The MD5 Hash security feature allows to authenticate transaction responses from the Authorize.Net for recurring payments. It can be obtained from Authorize.Net Account > Settings > Security Settings > General Settings > MD5 Hash.', 'invoicing' ), |
|
| 526 | + 'name' => __('MD5-Hash', 'invoicing'), |
|
| 527 | + 'desc' => __('The MD5 Hash security feature allows to authenticate transaction responses from the Authorize.Net for recurring payments. It can be obtained from Authorize.Net Account > Settings > Security Settings > General Settings > MD5 Hash.', 'invoicing'), |
|
| 528 | 528 | 'std' => '', |
| 529 | 529 | ); |
| 530 | 530 | |
| 531 | 531 | $setting['authorizenet_transaction_type'] = array( |
| 532 | 532 | 'id' => 'authorizenet_transaction_type', |
| 533 | - 'name' => __( 'Transaction Type', 'invoicing' ), |
|
| 534 | - 'desc' => __( 'Choose transaction type.', 'invoicing' ), |
|
| 533 | + 'name' => __('Transaction Type', 'invoicing'), |
|
| 534 | + 'desc' => __('Choose transaction type.', 'invoicing'), |
|
| 535 | 535 | 'type' => 'select', |
| 536 | 536 | 'class' => 'wpi_select2', |
| 537 | 537 | 'options' => array( |
| 538 | - 'authorize_capture' => __( 'Authorize And Capture', 'invoicing' ), |
|
| 539 | - 'authorize_only' => __( 'Authorize Only', 'invoicing' ), |
|
| 538 | + 'authorize_capture' => __('Authorize And Capture', 'invoicing'), |
|
| 539 | + 'authorize_only' => __('Authorize Only', 'invoicing'), |
|
| 540 | 540 | ), |
| 541 | 541 | 'std' => 'authorize_capture' |
| 542 | 542 | ); |
| 543 | 543 | |
| 544 | 544 | $setting['authorizenet_transaction_type_recurring'] = array( |
| 545 | 545 | 'id' => 'authorizenet_transaction_type_recurring', |
| 546 | - 'name' => __( 'Transaction Type for Recurring', 'invoicing' ), |
|
| 547 | - 'desc' => __( 'Choose transaction type for recurring payments.', 'invoicing' ), |
|
| 546 | + 'name' => __('Transaction Type for Recurring', 'invoicing'), |
|
| 547 | + 'desc' => __('Choose transaction type for recurring payments.', 'invoicing'), |
|
| 548 | 548 | 'type' => 'select', |
| 549 | 549 | 'class' => 'wpi_select2', |
| 550 | 550 | 'options' => array( |
| 551 | - 'authorize_capture' => __( 'Authorize And Capture', 'invoicing' ), |
|
| 552 | - 'authorize_only' => __( 'Authorize Only', 'invoicing' ), |
|
| 551 | + 'authorize_capture' => __('Authorize And Capture', 'invoicing'), |
|
| 552 | + 'authorize_only' => __('Authorize Only', 'invoicing'), |
|
| 553 | 553 | ), |
| 554 | 554 | 'std' => 'authorize_only' |
| 555 | 555 | ); |
@@ -557,9 +557,9 @@ discard block |
||
| 557 | 557 | $setting['authorizenet_ipn_url'] = array( |
| 558 | 558 | 'type' => 'ipn_url', |
| 559 | 559 | 'id' => 'authorizenet_ipn_url', |
| 560 | - 'name' => __( 'Silent Post URL', 'invoicing' ), |
|
| 561 | - 'std' => wpinv_get_ipn_url( 'authorizenet' ), |
|
| 562 | - 'desc' => __( 'If you are accepting recurring payments then you must set this url at Authorize.Net Account > Settings > Transaction Format Settings > Transaction Response Settings > Silent Post URL.', 'invoicing' ), |
|
| 560 | + 'name' => __('Silent Post URL', 'invoicing'), |
|
| 561 | + 'std' => wpinv_get_ipn_url('authorizenet'), |
|
| 562 | + 'desc' => __('If you are accepting recurring payments then you must set this url at Authorize.Net Account > Settings > Transaction Format Settings > Transaction Response Settings > Silent Post URL.', 'invoicing'), |
|
| 563 | 563 | 'size' => 'large', |
| 564 | 564 | 'custom' => 'authorizenet', |
| 565 | 565 | 'readonly' => true |
@@ -567,26 +567,26 @@ discard block |
||
| 567 | 567 | |
| 568 | 568 | return $setting; |
| 569 | 569 | } |
| 570 | -add_filter( 'wpinv_gateway_settings_authorizenet', 'wpinv_gateway_settings_authorizenet', 10, 1 ); |
|
| 570 | +add_filter('wpinv_gateway_settings_authorizenet', 'wpinv_gateway_settings_authorizenet', 10, 1); |
|
| 571 | 571 | |
| 572 | 572 | // Worldpay settings |
| 573 | -function wpinv_gateway_settings_worldpay( $setting ) { |
|
| 574 | - $setting['worldpay_active']['desc'] = $setting['worldpay_active']['desc'] . ' ' . __( '( Supported Currencies: AUD, ARS, CAD, CHF, DKK, EUR, HKD, MYR, GBP, NZD, NOK, SGD, LKR, SEK, TRY, USD, ZAR )', 'invoicing' ); |
|
| 575 | - $setting['worldpay_desc']['std'] = __( 'Pay using a Worldpay account to process Credit card / Debit card transactions.', 'invoicing' ); |
|
| 573 | +function wpinv_gateway_settings_worldpay($setting) { |
|
| 574 | + $setting['worldpay_active']['desc'] = $setting['worldpay_active']['desc'] . ' ' . __('( Supported Currencies: AUD, ARS, CAD, CHF, DKK, EUR, HKD, MYR, GBP, NZD, NOK, SGD, LKR, SEK, TRY, USD, ZAR )', 'invoicing'); |
|
| 575 | + $setting['worldpay_desc']['std'] = __('Pay using a Worldpay account to process Credit card / Debit card transactions.', 'invoicing'); |
|
| 576 | 576 | |
| 577 | 577 | $setting['worldpay_sandbox'] = array( |
| 578 | 578 | 'type' => 'checkbox', |
| 579 | 579 | 'id' => 'worldpay_sandbox', |
| 580 | - 'name' => __( 'Worldpay Test Mode', 'invoicing' ), |
|
| 581 | - 'desc' => __( 'This provides a special Test Environment to enable you to test your installation and integration to your website before going live.', 'invoicing' ), |
|
| 580 | + 'name' => __('Worldpay Test Mode', 'invoicing'), |
|
| 581 | + 'desc' => __('This provides a special Test Environment to enable you to test your installation and integration to your website before going live.', 'invoicing'), |
|
| 582 | 582 | 'std' => 1 |
| 583 | 583 | ); |
| 584 | 584 | |
| 585 | 585 | $setting['worldpay_instId'] = array( |
| 586 | 586 | 'type' => 'text', |
| 587 | 587 | 'id' => 'worldpay_instId', |
| 588 | - 'name' => __( 'Installation Id', 'invoicing' ), |
|
| 589 | - 'desc' => __( 'Your installation id. Ex: 211616', 'invoicing' ), |
|
| 588 | + 'name' => __('Installation Id', 'invoicing'), |
|
| 589 | + 'desc' => __('Your installation id. Ex: 211616', 'invoicing'), |
|
| 590 | 590 | 'std' => '211616', |
| 591 | 591 | ); |
| 592 | 592 | /* |
@@ -602,9 +602,9 @@ discard block |
||
| 602 | 602 | $setting['worldpay_ipn_url'] = array( |
| 603 | 603 | 'type' => 'ipn_url', |
| 604 | 604 | 'id' => 'worldpay_ipn_url', |
| 605 | - 'name' => __( 'Worldpay Callback Url', 'invoicing' ), |
|
| 606 | - 'std' => wpinv_get_ipn_url( 'worldpay' ), |
|
| 607 | - 'desc' => wp_sprintf( __( 'Login to your Worldpay Merchant Interface then enable Payment Response & Shopper Response. Next, go to the Payment Response URL field and type "%s" or "%s" for a dynamic payment response.', 'invoicing' ), '<font style="color:#000;font-style:normal">' . wpinv_get_ipn_url( 'worldpay' ) . '</font>', '<font style="color:#000;font-style:normal"><wpdisplay item=MC_callback></font>' ), |
|
| 605 | + 'name' => __('Worldpay Callback Url', 'invoicing'), |
|
| 606 | + 'std' => wpinv_get_ipn_url('worldpay'), |
|
| 607 | + 'desc' => wp_sprintf(__('Login to your Worldpay Merchant Interface then enable Payment Response & Shopper Response. Next, go to the Payment Response URL field and type "%s" or "%s" for a dynamic payment response.', 'invoicing'), '<font style="color:#000;font-style:normal">' . wpinv_get_ipn_url('worldpay') . '</font>', '<font style="color:#000;font-style:normal"><wpdisplay item=MC_callback></font>'), |
|
| 608 | 608 | 'size' => 'large', |
| 609 | 609 | 'custom' => 'worldpay', |
| 610 | 610 | 'readonly' => true |
@@ -612,99 +612,99 @@ discard block |
||
| 612 | 612 | |
| 613 | 613 | return $setting; |
| 614 | 614 | } |
| 615 | -add_filter( 'wpinv_gateway_settings_worldpay', 'wpinv_gateway_settings_worldpay', 10, 1 ); |
|
| 615 | +add_filter('wpinv_gateway_settings_worldpay', 'wpinv_gateway_settings_worldpay', 10, 1); |
|
| 616 | 616 | |
| 617 | -function wpinv_ipn_url_callback( $args ) { |
|
| 618 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
| 617 | +function wpinv_ipn_url_callback($args) { |
|
| 618 | + $sanitize_id = wpinv_sanitize_key($args['id']); |
|
| 619 | 619 | |
| 620 | 620 | $attrs = $args['readonly'] ? ' readonly' : ''; |
| 621 | 621 | |
| 622 | - $html = '<input style="background-color:#fefefe" type="text" ' . $attrs . ' value="' . esc_attr( $args['std'] ) . '" name="wpinv_settings[' . $sanitize_id . ']" id="wpinv_settings[' . $sanitize_id . ']" class="large-text">'; |
|
| 623 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']">' . $args['desc'] . '</label>'; |
|
| 622 | + $html = '<input style="background-color:#fefefe" type="text" ' . $attrs . ' value="' . esc_attr($args['std']) . '" name="wpinv_settings[' . $sanitize_id . ']" id="wpinv_settings[' . $sanitize_id . ']" class="large-text">'; |
|
| 623 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']">' . $args['desc'] . '</label>'; |
|
| 624 | 624 | |
| 625 | 625 | echo $html; |
| 626 | 626 | } |
| 627 | 627 | |
| 628 | -function wpinv_is_test_mode( $gateway = '' ) { |
|
| 629 | - if ( empty( $gateway ) ) { |
|
| 628 | +function wpinv_is_test_mode($gateway = '') { |
|
| 629 | + if (empty($gateway)) { |
|
| 630 | 630 | return false; |
| 631 | 631 | } |
| 632 | 632 | |
| 633 | - $is_test_mode = wpinv_get_option( $gateway . '_sandbox', false ); |
|
| 633 | + $is_test_mode = wpinv_get_option($gateway . '_sandbox', false); |
|
| 634 | 634 | |
| 635 | - return apply_filters( 'wpinv_is_test_mode', $is_test_mode, $gateway ); |
|
| 635 | + return apply_filters('wpinv_is_test_mode', $is_test_mode, $gateway); |
|
| 636 | 636 | } |
| 637 | 637 | |
| 638 | -function wpinv_get_ipn_url( $gateway = '', $args = array() ) { |
|
| 639 | - $data = array( 'wpi-listener' => 'IPN' ); |
|
| 638 | +function wpinv_get_ipn_url($gateway = '', $args = array()) { |
|
| 639 | + $data = array('wpi-listener' => 'IPN'); |
|
| 640 | 640 | |
| 641 | - if ( !empty( $gateway ) ) { |
|
| 642 | - $data['wpi-gateway'] = wpinv_sanitize_key( $gateway ); |
|
| 641 | + if (!empty($gateway)) { |
|
| 642 | + $data['wpi-gateway'] = wpinv_sanitize_key($gateway); |
|
| 643 | 643 | } |
| 644 | 644 | |
| 645 | - $args = !empty( $args ) && is_array( $args ) ? array_merge( $data, $args ) : $data; |
|
| 645 | + $args = !empty($args) && is_array($args) ? array_merge($data, $args) : $data; |
|
| 646 | 646 | |
| 647 | - $ipn_url = add_query_arg( $args, home_url( 'index.php' ) ); |
|
| 647 | + $ipn_url = add_query_arg($args, home_url('index.php')); |
|
| 648 | 648 | |
| 649 | - return apply_filters( 'wpinv_ipn_url', $ipn_url ); |
|
| 649 | + return apply_filters('wpinv_ipn_url', $ipn_url); |
|
| 650 | 650 | } |
| 651 | 651 | |
| 652 | 652 | function wpinv_listen_for_payment_ipn() { |
| 653 | 653 | // Regular PayPal IPN |
| 654 | - if ( isset( $_GET['wpi-listener'] ) && $_GET['wpi-listener'] == 'IPN' ) { |
|
| 655 | - do_action( 'wpinv_verify_payment_ipn' ); |
|
| 654 | + if (isset($_GET['wpi-listener']) && $_GET['wpi-listener'] == 'IPN') { |
|
| 655 | + do_action('wpinv_verify_payment_ipn'); |
|
| 656 | 656 | |
| 657 | - if ( !empty( $_GET['wpi-gateway'] ) ) { |
|
| 658 | - wpinv_error_log( sanitize_text_field( $_GET['wpi-gateway'] ), 'WP Invoicing IPN', __FILE__, __LINE__ ); |
|
| 659 | - do_action( 'wpinv_verify_' . sanitize_text_field( $_GET['wpi-gateway'] ) . '_ipn' ); |
|
| 657 | + if (!empty($_GET['wpi-gateway'])) { |
|
| 658 | + wpinv_error_log(sanitize_text_field($_GET['wpi-gateway']), 'WP Invoicing IPN', __FILE__, __LINE__); |
|
| 659 | + do_action('wpinv_verify_' . sanitize_text_field($_GET['wpi-gateway']) . '_ipn'); |
|
| 660 | 660 | } |
| 661 | 661 | } |
| 662 | 662 | } |
| 663 | -add_action( 'init', 'wpinv_listen_for_payment_ipn' ); |
|
| 663 | +add_action('init', 'wpinv_listen_for_payment_ipn'); |
|
| 664 | 664 | |
| 665 | 665 | function wpinv_get_bank_instructions() { |
| 666 | - $bank_instructions = wpinv_get_option( 'bank_transfer_info' ); |
|
| 666 | + $bank_instructions = wpinv_get_option('bank_transfer_info'); |
|
| 667 | 667 | |
| 668 | - return apply_filters( 'wpinv_bank_instructions', $bank_instructions ); |
|
| 668 | + return apply_filters('wpinv_bank_instructions', $bank_instructions); |
|
| 669 | 669 | } |
| 670 | 670 | |
| 671 | -function wpinv_get_bank_info( $filtered = false ) { |
|
| 671 | +function wpinv_get_bank_info($filtered = false) { |
|
| 672 | 672 | $bank_fields = array( |
| 673 | - 'bank_transfer_ac_name' => __( 'Account Name', 'invoicing' ), |
|
| 674 | - 'bank_transfer_ac_no' => __( 'Account Number', 'invoicing' ), |
|
| 675 | - 'bank_transfer_bank_name' => __( 'Bank Name', 'invoicing' ), |
|
| 676 | - 'bank_transfer_ifsc' => __( 'IFSC code', 'invoicing' ), |
|
| 677 | - 'bank_transfer_iban' => __( 'IBAN', 'invoicing' ), |
|
| 678 | - 'bank_transfer_bic' => __( 'BIC/Swift code', 'invoicing' ), |
|
| 679 | - 'bank_transfer_sort_code' => __( 'Sort Code', 'invoicing' ) |
|
| 673 | + 'bank_transfer_ac_name' => __('Account Name', 'invoicing'), |
|
| 674 | + 'bank_transfer_ac_no' => __('Account Number', 'invoicing'), |
|
| 675 | + 'bank_transfer_bank_name' => __('Bank Name', 'invoicing'), |
|
| 676 | + 'bank_transfer_ifsc' => __('IFSC code', 'invoicing'), |
|
| 677 | + 'bank_transfer_iban' => __('IBAN', 'invoicing'), |
|
| 678 | + 'bank_transfer_bic' => __('BIC/Swift code', 'invoicing'), |
|
| 679 | + 'bank_transfer_sort_code' => __('Sort Code', 'invoicing') |
|
| 680 | 680 | ); |
| 681 | 681 | |
| 682 | 682 | $bank_info = array(); |
| 683 | - foreach ( $bank_fields as $field => $label ) { |
|
| 684 | - if ( $filtered && !( $value = wpinv_get_option( $field ) ) ) { |
|
| 683 | + foreach ($bank_fields as $field => $label) { |
|
| 684 | + if ($filtered && !($value = wpinv_get_option($field))) { |
|
| 685 | 685 | continue; |
| 686 | 686 | } |
| 687 | 687 | |
| 688 | - $bank_info[$field] = array( 'label' => $label, 'value' => $value ); |
|
| 688 | + $bank_info[$field] = array('label' => $label, 'value' => $value); |
|
| 689 | 689 | } |
| 690 | 690 | |
| 691 | - return apply_filters( 'wpinv_bank_info', $bank_info, $filtered ); |
|
| 691 | + return apply_filters('wpinv_bank_info', $bank_info, $filtered); |
|
| 692 | 692 | } |
| 693 | 693 | |
| 694 | -function wpinv_get_post_data( $method = 'request' ) { |
|
| 694 | +function wpinv_get_post_data($method = 'request') { |
|
| 695 | 695 | $data = array(); |
| 696 | 696 | $request = $_REQUEST; |
| 697 | 697 | |
| 698 | - if ( $method == 'post' ) { |
|
| 699 | - if ( isset( $_SERVER['REQUEST_METHOD'] ) && $_SERVER['REQUEST_METHOD'] != 'POST' ) { |
|
| 698 | + if ($method == 'post') { |
|
| 699 | + if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] != 'POST') { |
|
| 700 | 700 | return $data; |
| 701 | 701 | } |
| 702 | 702 | |
| 703 | 703 | $request = $_POST; |
| 704 | 704 | } |
| 705 | 705 | |
| 706 | - if ( $method == 'get' ) { |
|
| 707 | - if ( isset( $_SERVER['REQUEST_METHOD'] ) && $_SERVER['REQUEST_METHOD'] != 'GET' ) { |
|
| 706 | + if ($method == 'get') { |
|
| 707 | + if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] != 'GET') { |
|
| 708 | 708 | return $data; |
| 709 | 709 | } |
| 710 | 710 | |
@@ -715,11 +715,11 @@ discard block |
||
| 715 | 715 | $post_data = ''; |
| 716 | 716 | |
| 717 | 717 | // Fallback just in case post_max_size is lower than needed |
| 718 | - if ( ini_get( 'allow_url_fopen' ) ) { |
|
| 719 | - $post_data = file_get_contents( 'php://input' ); |
|
| 718 | + if (ini_get('allow_url_fopen')) { |
|
| 719 | + $post_data = file_get_contents('php://input'); |
|
| 720 | 720 | } else { |
| 721 | 721 | // If allow_url_fopen is not enabled, then make sure that post_max_size is large enough |
| 722 | - ini_set( 'post_max_size', '12M' ); |
|
| 722 | + ini_set('post_max_size', '12M'); |
|
| 723 | 723 | } |
| 724 | 724 | // Start the encoded data collection with notification command |
| 725 | 725 | $encoded_data = 'cmd=_notify-validate'; |
@@ -728,58 +728,58 @@ discard block |
||
| 728 | 728 | $arg_separator = wpinv_get_php_arg_separator_output(); |
| 729 | 729 | |
| 730 | 730 | // Verify there is a post_data |
| 731 | - if ( $post_data || strlen( $post_data ) > 0 ) { |
|
| 731 | + if ($post_data || strlen($post_data) > 0) { |
|
| 732 | 732 | // Append the data |
| 733 | 733 | $encoded_data .= $arg_separator . $post_data; |
| 734 | 734 | } else { |
| 735 | 735 | // Check if POST is empty |
| 736 | - if ( empty( $request ) ) { |
|
| 736 | + if (empty($request)) { |
|
| 737 | 737 | // Nothing to do |
| 738 | 738 | return; |
| 739 | 739 | } else { |
| 740 | 740 | // Loop through each POST |
| 741 | - foreach ( $request as $key => $value ) { |
|
| 741 | + foreach ($request as $key => $value) { |
|
| 742 | 742 | // Encode the value and append the data |
| 743 | - $encoded_data .= $arg_separator . "$key=" . urlencode( $value ); |
|
| 743 | + $encoded_data .= $arg_separator . "$key=" . urlencode($value); |
|
| 744 | 744 | } |
| 745 | 745 | } |
| 746 | 746 | } |
| 747 | 747 | |
| 748 | 748 | // Convert collected post data to an array |
| 749 | - wp_parse_str( $encoded_data, $data ); |
|
| 749 | + wp_parse_str($encoded_data, $data); |
|
| 750 | 750 | |
| 751 | - foreach ( $data as $key => $value ) { |
|
| 752 | - if ( false !== strpos( $key, 'amp;' ) ) { |
|
| 753 | - $new_key = str_replace( '&', '&', $key ); |
|
| 754 | - $new_key = str_replace( 'amp;', '&' , $new_key ); |
|
| 751 | + foreach ($data as $key => $value) { |
|
| 752 | + if (false !== strpos($key, 'amp;')) { |
|
| 753 | + $new_key = str_replace('&', '&', $key); |
|
| 754 | + $new_key = str_replace('amp;', '&', $new_key); |
|
| 755 | 755 | |
| 756 | - unset( $data[ $key ] ); |
|
| 757 | - $data[ $new_key ] = sanitize_text_field( $value ); |
|
| 756 | + unset($data[$key]); |
|
| 757 | + $data[$new_key] = sanitize_text_field($value); |
|
| 758 | 758 | } |
| 759 | 759 | } |
| 760 | 760 | |
| 761 | 761 | return $data; |
| 762 | 762 | } |
| 763 | 763 | |
| 764 | -function wpinv_gateway_support_subscription( $gateway ) { |
|
| 764 | +function wpinv_gateway_support_subscription($gateway) { |
|
| 765 | 765 | $return = false; |
| 766 | 766 | |
| 767 | - if ( wpinv_is_gateway_active( $gateway ) ) { |
|
| 768 | - $return = apply_filters( 'wpinv_' . $gateway . '_support_subscription', false ); |
|
| 767 | + if (wpinv_is_gateway_active($gateway)) { |
|
| 768 | + $return = apply_filters('wpinv_' . $gateway . '_support_subscription', false); |
|
| 769 | 769 | } |
| 770 | 770 | |
| 771 | 771 | return $return; |
| 772 | 772 | } |
| 773 | 773 | |
| 774 | -function wpinv_payment_gateways_on_cart( $gateways = array() ) { |
|
| 775 | - if ( !empty( $gateways ) && wpinv_cart_has_recurring_item() ) { |
|
| 776 | - foreach ( $gateways as $gateway => $info ) { |
|
| 777 | - if ( !wpinv_gateway_support_subscription( $gateway ) ) { |
|
| 778 | - unset( $gateways[$gateway] ); |
|
| 774 | +function wpinv_payment_gateways_on_cart($gateways = array()) { |
|
| 775 | + if (!empty($gateways) && wpinv_cart_has_recurring_item()) { |
|
| 776 | + foreach ($gateways as $gateway => $info) { |
|
| 777 | + if (!wpinv_gateway_support_subscription($gateway)) { |
|
| 778 | + unset($gateways[$gateway]); |
|
| 779 | 779 | } |
| 780 | 780 | } |
| 781 | 781 | } |
| 782 | 782 | |
| 783 | 783 | return $gateways; |
| 784 | 784 | } |
| 785 | -add_filter( 'wpinv_payment_gateways_on_cart', 'wpinv_payment_gateways_on_cart', 10, 1 ); |
|
| 786 | 785 | \ No newline at end of file |
| 786 | +add_filter('wpinv_payment_gateways_on_cart', 'wpinv_payment_gateways_on_cart', 10, 1); |
|
| 787 | 787 | \ No newline at end of file |
@@ -7,110 +7,110 @@ discard block |
||
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | 9 | // MUST have WordPress. |
| 10 | -if ( !defined( 'WPINC' ) ) { |
|
| 11 | - exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) ); |
|
| 10 | +if (!defined('WPINC')) { |
|
| 11 | + exit('Do NOT access this file directly: ' . basename(__FILE__)); |
|
| 12 | 12 | } |
| 13 | 13 | |
| 14 | 14 | function wpinv_get_discount_types() { |
| 15 | 15 | $discount_types = array( |
| 16 | - 'percent' => __( 'Percentage', 'invoicing' ), |
|
| 17 | - 'flat' => __( 'Flat Amount', 'invoicing' ), |
|
| 16 | + 'percent' => __('Percentage', 'invoicing'), |
|
| 17 | + 'flat' => __('Flat Amount', 'invoicing'), |
|
| 18 | 18 | ); |
| 19 | - return (array)apply_filters( 'wpinv_discount_types', $discount_types ); |
|
| 19 | + return (array) apply_filters('wpinv_discount_types', $discount_types); |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | -function wpinv_get_discount_type_name( $type = '' ) { |
|
| 22 | +function wpinv_get_discount_type_name($type = '') { |
|
| 23 | 23 | $types = wpinv_get_discount_types(); |
| 24 | - return isset( $types[ $type ] ) ? $types[ $type ] : ''; |
|
| 24 | + return isset($types[$type]) ? $types[$type] : ''; |
|
| 25 | 25 | } |
| 26 | 26 | |
| 27 | -function wpinv_delete_discount( $data ) { |
|
| 28 | - if ( ! isset( $data['_wpnonce'] ) || ! wp_verify_nonce( $data['_wpnonce'], 'wpinv_discount_nonce' ) ) { |
|
| 29 | - wp_die( __( 'Trying to cheat or something?', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
| 27 | +function wpinv_delete_discount($data) { |
|
| 28 | + if (!isset($data['_wpnonce']) || !wp_verify_nonce($data['_wpnonce'], 'wpinv_discount_nonce')) { |
|
| 29 | + wp_die(__('Trying to cheat or something?', 'invoicing'), __('Error', 'invoicing'), array('response' => 403)); |
|
| 30 | 30 | } |
| 31 | 31 | |
| 32 | - if( ! wpinv_current_user_can_manage_invoicing() ) { |
|
| 33 | - wp_die( __( 'You do not have permission to delete discount codes', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
| 32 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
| 33 | + wp_die(__('You do not have permission to delete discount codes', 'invoicing'), __('Error', 'invoicing'), array('response' => 403)); |
|
| 34 | 34 | } |
| 35 | 35 | |
| 36 | 36 | $discount_id = $data['discount']; |
| 37 | - wpinv_remove_discount( $discount_id ); |
|
| 37 | + wpinv_remove_discount($discount_id); |
|
| 38 | 38 | } |
| 39 | -add_action( 'wpinv_delete_discount', 'wpinv_delete_discount' ); |
|
| 39 | +add_action('wpinv_delete_discount', 'wpinv_delete_discount'); |
|
| 40 | 40 | |
| 41 | -function wpinv_activate_discount( $data ) { |
|
| 42 | - if ( ! isset( $data['_wpnonce'] ) || ! wp_verify_nonce( $data['_wpnonce'], 'wpinv_discount_nonce' ) ) { |
|
| 43 | - wp_die( __( 'Trying to cheat or something?', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
| 41 | +function wpinv_activate_discount($data) { |
|
| 42 | + if (!isset($data['_wpnonce']) || !wp_verify_nonce($data['_wpnonce'], 'wpinv_discount_nonce')) { |
|
| 43 | + wp_die(__('Trying to cheat or something?', 'invoicing'), __('Error', 'invoicing'), array('response' => 403)); |
|
| 44 | 44 | } |
| 45 | 45 | |
| 46 | - if( ! wpinv_current_user_can_manage_invoicing() ) { |
|
| 47 | - wp_die( __( 'You do not have permission to edit discount codes', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
| 46 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
| 47 | + wp_die(__('You do not have permission to edit discount codes', 'invoicing'), __('Error', 'invoicing'), array('response' => 403)); |
|
| 48 | 48 | } |
| 49 | 49 | |
| 50 | - $id = absint( $data['discount'] ); |
|
| 51 | - wpinv_update_discount_status( $id, 'publish' ); |
|
| 50 | + $id = absint($data['discount']); |
|
| 51 | + wpinv_update_discount_status($id, 'publish'); |
|
| 52 | 52 | } |
| 53 | -add_action( 'wpinv_activate_discount', 'wpinv_activate_discount' ); |
|
| 53 | +add_action('wpinv_activate_discount', 'wpinv_activate_discount'); |
|
| 54 | 54 | |
| 55 | -function wpinv_deactivate_discount( $data ) { |
|
| 56 | - if ( ! isset( $data['_wpnonce'] ) || ! wp_verify_nonce( $data['_wpnonce'], 'wpinv_discount_nonce' ) ) { |
|
| 57 | - wp_die( __( 'Trying to cheat or something?', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
| 55 | +function wpinv_deactivate_discount($data) { |
|
| 56 | + if (!isset($data['_wpnonce']) || !wp_verify_nonce($data['_wpnonce'], 'wpinv_discount_nonce')) { |
|
| 57 | + wp_die(__('Trying to cheat or something?', 'invoicing'), __('Error', 'invoicing'), array('response' => 403)); |
|
| 58 | 58 | } |
| 59 | 59 | |
| 60 | - if( ! wpinv_current_user_can_manage_invoicing() ) { |
|
| 61 | - wp_die( __( 'You do not have permission to create discount codes', 'invoicing' ), array( 'response' => 403 ) ); |
|
| 60 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
| 61 | + wp_die(__('You do not have permission to create discount codes', 'invoicing'), array('response' => 403)); |
|
| 62 | 62 | } |
| 63 | 63 | |
| 64 | - $id = absint( $data['discount'] ); |
|
| 65 | - wpinv_update_discount_status( $id, 'pending' ); |
|
| 64 | + $id = absint($data['discount']); |
|
| 65 | + wpinv_update_discount_status($id, 'pending'); |
|
| 66 | 66 | } |
| 67 | -add_action( 'wpinv_deactivate_discount', 'wpinv_deactivate_discount' ); |
|
| 67 | +add_action('wpinv_deactivate_discount', 'wpinv_deactivate_discount'); |
|
| 68 | 68 | |
| 69 | -function wpinv_get_discounts( $args = array() ) { |
|
| 69 | +function wpinv_get_discounts($args = array()) { |
|
| 70 | 70 | $defaults = array( |
| 71 | 71 | 'post_type' => 'wpi_discount', |
| 72 | 72 | 'posts_per_page' => 20, |
| 73 | 73 | 'paged' => null, |
| 74 | - 'post_status' => array( 'publish', 'pending', 'draft', 'expired' ) |
|
| 74 | + 'post_status' => array('publish', 'pending', 'draft', 'expired') |
|
| 75 | 75 | ); |
| 76 | 76 | |
| 77 | - $args = wp_parse_args( $args, $defaults ); |
|
| 77 | + $args = wp_parse_args($args, $defaults); |
|
| 78 | 78 | |
| 79 | - $discounts = get_posts( $args ); |
|
| 79 | + $discounts = get_posts($args); |
|
| 80 | 80 | |
| 81 | - if ( $discounts ) { |
|
| 81 | + if ($discounts) { |
|
| 82 | 82 | return $discounts; |
| 83 | 83 | } |
| 84 | 84 | |
| 85 | - if( ! $discounts && ! empty( $args['s'] ) ) { |
|
| 85 | + if (!$discounts && !empty($args['s'])) { |
|
| 86 | 86 | $args['meta_key'] = '_wpi_discount_code'; |
| 87 | 87 | $args['meta_value'] = $args['s']; |
| 88 | 88 | $args['meta_compare'] = 'LIKE'; |
| 89 | - unset( $args['s'] ); |
|
| 90 | - $discounts = get_posts( $args ); |
|
| 89 | + unset($args['s']); |
|
| 90 | + $discounts = get_posts($args); |
|
| 91 | 91 | } |
| 92 | 92 | |
| 93 | - if( $discounts ) { |
|
| 93 | + if ($discounts) { |
|
| 94 | 94 | return $discounts; |
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | return false; |
| 98 | 98 | } |
| 99 | 99 | |
| 100 | -function wpinv_get_all_discounts( $args = array() ) { |
|
| 100 | +function wpinv_get_all_discounts($args = array()) { |
|
| 101 | 101 | |
| 102 | - $args = wp_parse_args( $args, array( |
|
| 103 | - 'status' => array( 'publish' ), |
|
| 104 | - 'limit' => get_option( 'posts_per_page' ), |
|
| 102 | + $args = wp_parse_args($args, array( |
|
| 103 | + 'status' => array('publish'), |
|
| 104 | + 'limit' => get_option('posts_per_page'), |
|
| 105 | 105 | 'page' => 1, |
| 106 | 106 | 'exclude' => array(), |
| 107 | 107 | 'orderby' => 'date', |
| 108 | 108 | 'order' => 'DESC', |
| 109 | - 'type' => array_keys( wpinv_get_discount_types() ), |
|
| 109 | + 'type' => array_keys(wpinv_get_discount_types()), |
|
| 110 | 110 | 'meta_query' => array(), |
| 111 | 111 | 'return' => 'objects', |
| 112 | 112 | 'paginate' => false, |
| 113 | - ) ); |
|
| 113 | + )); |
|
| 114 | 114 | |
| 115 | 115 | $wp_query_args = array( |
| 116 | 116 | 'post_type' => 'wpi_discount', |
@@ -120,18 +120,18 @@ discard block |
||
| 120 | 120 | 'fields' => 'ids', |
| 121 | 121 | 'orderby' => $args['orderby'], |
| 122 | 122 | 'order' => $args['order'], |
| 123 | - 'paged' => absint( $args['page'] ), |
|
| 123 | + 'paged' => absint($args['page']), |
|
| 124 | 124 | ); |
| 125 | 125 | |
| 126 | - if ( ! empty( $args['exclude'] ) ) { |
|
| 127 | - $wp_query_args['post__not_in'] = array_map( 'absint', $args['exclude'] ); |
|
| 126 | + if (!empty($args['exclude'])) { |
|
| 127 | + $wp_query_args['post__not_in'] = array_map('absint', $args['exclude']); |
|
| 128 | 128 | } |
| 129 | 129 | |
| 130 | - if ( ! $args['paginate' ] ) { |
|
| 130 | + if (!$args['paginate']) { |
|
| 131 | 131 | $wp_query_args['no_found_rows'] = true; |
| 132 | 132 | } |
| 133 | 133 | |
| 134 | - if ( ! empty( $args['search'] ) ) { |
|
| 134 | + if (!empty($args['search'])) { |
|
| 135 | 135 | |
| 136 | 136 | $wp_query_args['meta_query'][] = array( |
| 137 | 137 | 'key' => '_wpi_discount_code', |
@@ -141,11 +141,11 @@ discard block |
||
| 141 | 141 | |
| 142 | 142 | } |
| 143 | 143 | |
| 144 | - if ( ! empty( $args['type'] ) ) { |
|
| 145 | - $types = wpinv_parse_list( $args['type'] ); |
|
| 144 | + if (!empty($args['type'])) { |
|
| 145 | + $types = wpinv_parse_list($args['type']); |
|
| 146 | 146 | $wp_query_args['meta_query'][] = array( |
| 147 | 147 | 'key' => '_wpi_discount_type', |
| 148 | - 'value' => implode( ',', $types ), |
|
| 148 | + 'value' => implode(',', $types), |
|
| 149 | 149 | 'compare' => 'IN', |
| 150 | 150 | ); |
| 151 | 151 | } |
@@ -153,17 +153,17 @@ discard block |
||
| 153 | 153 | $wp_query_args = apply_filters('wpinv_get_discount_args', $wp_query_args, $args); |
| 154 | 154 | |
| 155 | 155 | // Get results. |
| 156 | - $discounts = new WP_Query( $wp_query_args ); |
|
| 156 | + $discounts = new WP_Query($wp_query_args); |
|
| 157 | 157 | |
| 158 | - if ( 'objects' === $args['return'] ) { |
|
| 159 | - $return = array_map( 'get_post', $discounts->posts ); |
|
| 160 | - } elseif ( 'self' === $args['return'] ) { |
|
| 158 | + if ('objects' === $args['return']) { |
|
| 159 | + $return = array_map('get_post', $discounts->posts); |
|
| 160 | + } elseif ('self' === $args['return']) { |
|
| 161 | 161 | return $discounts; |
| 162 | 162 | } else { |
| 163 | 163 | $return = $discounts->posts; |
| 164 | 164 | } |
| 165 | 165 | |
| 166 | - if ( $args['paginate' ] ) { |
|
| 166 | + if ($args['paginate']) { |
|
| 167 | 167 | return (object) array( |
| 168 | 168 | 'discounts' => $return, |
| 169 | 169 | 'total' => $discounts->found_posts, |
@@ -180,9 +180,9 @@ discard block |
||
| 180 | 180 | |
| 181 | 181 | $discounts = wpinv_get_discounts(); |
| 182 | 182 | |
| 183 | - if ( $discounts) { |
|
| 184 | - foreach ( $discounts as $discount ) { |
|
| 185 | - if ( wpinv_is_discount_active( $discount->ID ) ) { |
|
| 183 | + if ($discounts) { |
|
| 184 | + foreach ($discounts as $discount) { |
|
| 185 | + if (wpinv_is_discount_active($discount->ID)) { |
|
| 186 | 186 | $has_active = true; |
| 187 | 187 | break; |
| 188 | 188 | } |
@@ -191,16 +191,16 @@ discard block |
||
| 191 | 191 | return $has_active; |
| 192 | 192 | } |
| 193 | 193 | |
| 194 | -function wpinv_get_discount( $discount_id = 0 ) { |
|
| 195 | - if( empty( $discount_id ) ) { |
|
| 194 | +function wpinv_get_discount($discount_id = 0) { |
|
| 195 | + if (empty($discount_id)) { |
|
| 196 | 196 | return false; |
| 197 | 197 | } |
| 198 | 198 | |
| 199 | - if ( get_post_type( $discount_id ) != 'wpi_discount' ) { |
|
| 199 | + if (get_post_type($discount_id) != 'wpi_discount') { |
|
| 200 | 200 | return false; |
| 201 | 201 | } |
| 202 | 202 | |
| 203 | - $discount = get_post( $discount_id ); |
|
| 203 | + $discount = get_post($discount_id); |
|
| 204 | 204 | |
| 205 | 205 | return $discount; |
| 206 | 206 | } |
@@ -212,8 +212,8 @@ discard block |
||
| 212 | 212 | * @since 1.0.15 |
| 213 | 213 | * @return WPInv_Discount |
| 214 | 214 | */ |
| 215 | -function wpinv_get_discount_obj( $discount = 0 ) { |
|
| 216 | - return new WPInv_Discount( $discount ); |
|
| 215 | +function wpinv_get_discount_obj($discount = 0) { |
|
| 216 | + return new WPInv_Discount($discount); |
|
| 217 | 217 | } |
| 218 | 218 | |
| 219 | 219 | /** |
@@ -222,8 +222,8 @@ discard block |
||
| 222 | 222 | * @param string $code The discount code. |
| 223 | 223 | * @return bool|WP_Post |
| 224 | 224 | */ |
| 225 | -function wpinv_get_discount_by_code( $code = '' ) { |
|
| 226 | - return wpinv_get_discount_by( 'code', $code ); |
|
| 225 | +function wpinv_get_discount_by_code($code = '') { |
|
| 226 | + return wpinv_get_discount_by('code', $code); |
|
| 227 | 227 | } |
| 228 | 228 | |
| 229 | 229 | /** |
@@ -233,13 +233,13 @@ discard block |
||
| 233 | 233 | * @param string|int $value The field value |
| 234 | 234 | * @return bool|WP_Post |
| 235 | 235 | */ |
| 236 | -function wpinv_get_discount_by( $field = '', $value = '' ) { |
|
| 237 | - $data = WPInv_Discount::get_data_by( $field, $value ); |
|
| 238 | - if( empty( $data ) ) { |
|
| 236 | +function wpinv_get_discount_by($field = '', $value = '') { |
|
| 237 | + $data = WPInv_Discount::get_data_by($field, $value); |
|
| 238 | + if (empty($data)) { |
|
| 239 | 239 | return false; |
| 240 | 240 | } |
| 241 | 241 | |
| 242 | - return get_post( $data['ID'] ); |
|
| 242 | + return get_post($data['ID']); |
|
| 243 | 243 | } |
| 244 | 244 | |
| 245 | 245 | /** |
@@ -249,68 +249,68 @@ discard block |
||
| 249 | 249 | * @param array $data The discount's properties. |
| 250 | 250 | * @return bool |
| 251 | 251 | */ |
| 252 | -function wpinv_store_discount( $post_id, $data, $post, $update = false ) { |
|
| 252 | +function wpinv_store_discount($post_id, $data, $post, $update = false) { |
|
| 253 | 253 | $meta = array( |
| 254 | - 'code' => isset( $data['code'] ) ? sanitize_text_field( $data['code'] ) : '', |
|
| 255 | - 'type' => isset( $data['type'] ) ? sanitize_text_field( $data['type'] ) : 'percent', |
|
| 256 | - 'amount' => isset( $data['amount'] ) ? wpinv_sanitize_amount( $data['amount'] ) : '', |
|
| 257 | - 'start' => isset( $data['start'] ) ? sanitize_text_field( $data['start'] ) : '', |
|
| 258 | - 'expiration' => isset( $data['expiration'] ) ? sanitize_text_field( $data['expiration'] ) : '', |
|
| 259 | - 'min_total' => isset( $data['min_total'] ) ? wpinv_sanitize_amount( $data['min_total'] ) : '', |
|
| 260 | - 'max_total' => isset( $data['max_total'] ) ? wpinv_sanitize_amount( $data['max_total'] ) : '', |
|
| 261 | - 'max_uses' => isset( $data['max_uses'] ) ? absint( $data['max_uses'] ) : '', |
|
| 262 | - 'items' => isset( $data['items'] ) ? $data['items'] : array(), |
|
| 263 | - 'excluded_items' => isset( $data['excluded_items'] ) ? $data['excluded_items'] : array(), |
|
| 264 | - 'is_recurring' => isset( $data['recurring'] ) ? (bool)$data['recurring'] : false, |
|
| 265 | - 'is_single_use' => isset( $data['single_use'] ) ? (bool)$data['single_use'] : false, |
|
| 266 | - 'uses' => isset( $data['uses'] ) ? (int)$data['uses'] : false, |
|
| 254 | + 'code' => isset($data['code']) ? sanitize_text_field($data['code']) : '', |
|
| 255 | + 'type' => isset($data['type']) ? sanitize_text_field($data['type']) : 'percent', |
|
| 256 | + 'amount' => isset($data['amount']) ? wpinv_sanitize_amount($data['amount']) : '', |
|
| 257 | + 'start' => isset($data['start']) ? sanitize_text_field($data['start']) : '', |
|
| 258 | + 'expiration' => isset($data['expiration']) ? sanitize_text_field($data['expiration']) : '', |
|
| 259 | + 'min_total' => isset($data['min_total']) ? wpinv_sanitize_amount($data['min_total']) : '', |
|
| 260 | + 'max_total' => isset($data['max_total']) ? wpinv_sanitize_amount($data['max_total']) : '', |
|
| 261 | + 'max_uses' => isset($data['max_uses']) ? absint($data['max_uses']) : '', |
|
| 262 | + 'items' => isset($data['items']) ? $data['items'] : array(), |
|
| 263 | + 'excluded_items' => isset($data['excluded_items']) ? $data['excluded_items'] : array(), |
|
| 264 | + 'is_recurring' => isset($data['recurring']) ? (bool) $data['recurring'] : false, |
|
| 265 | + 'is_single_use' => isset($data['single_use']) ? (bool) $data['single_use'] : false, |
|
| 266 | + 'uses' => isset($data['uses']) ? (int) $data['uses'] : false, |
|
| 267 | 267 | ); |
| 268 | 268 | |
| 269 | - if ( $meta['type'] == 'percent' && (float)$meta['amount'] > 100 ) { |
|
| 269 | + if ($meta['type'] == 'percent' && (float) $meta['amount'] > 100) { |
|
| 270 | 270 | $meta['amount'] = 100; |
| 271 | 271 | } |
| 272 | 272 | |
| 273 | - if ( !empty( $meta['start'] ) ) { |
|
| 274 | - $meta['start'] = date_i18n( 'Y-m-d H:i:s', strtotime( $meta['start'] ) ); |
|
| 273 | + if (!empty($meta['start'])) { |
|
| 274 | + $meta['start'] = date_i18n('Y-m-d H:i:s', strtotime($meta['start'])); |
|
| 275 | 275 | } |
| 276 | 276 | |
| 277 | - if ( !empty( $meta['expiration'] ) ) { |
|
| 278 | - $meta['expiration'] = date_i18n( 'Y-m-d H:i:s', strtotime( $meta['expiration'] ) ); |
|
| 277 | + if (!empty($meta['expiration'])) { |
|
| 278 | + $meta['expiration'] = date_i18n('Y-m-d H:i:s', strtotime($meta['expiration'])); |
|
| 279 | 279 | |
| 280 | - if ( !empty( $meta['start'] ) && strtotime( $meta['start'] ) > strtotime( $meta['expiration'] ) ) { |
|
| 280 | + if (!empty($meta['start']) && strtotime($meta['start']) > strtotime($meta['expiration'])) { |
|
| 281 | 281 | $meta['expiration'] = $meta['start']; |
| 282 | 282 | } |
| 283 | 283 | } |
| 284 | 284 | |
| 285 | - if ( $meta['uses'] === false ) { |
|
| 286 | - unset( $meta['uses'] ); |
|
| 285 | + if ($meta['uses'] === false) { |
|
| 286 | + unset($meta['uses']); |
|
| 287 | 287 | } |
| 288 | 288 | |
| 289 | - if ( ! empty( $meta['items'] ) ) { |
|
| 290 | - foreach ( $meta['items'] as $key => $item ) { |
|
| 291 | - if ( 0 === intval( $item ) ) { |
|
| 292 | - unset( $meta['items'][ $key ] ); |
|
| 289 | + if (!empty($meta['items'])) { |
|
| 290 | + foreach ($meta['items'] as $key => $item) { |
|
| 291 | + if (0 === intval($item)) { |
|
| 292 | + unset($meta['items'][$key]); |
|
| 293 | 293 | } |
| 294 | 294 | } |
| 295 | 295 | } |
| 296 | 296 | |
| 297 | - if ( ! empty( $meta['excluded_items'] ) ) { |
|
| 298 | - foreach ( $meta['excluded_items'] as $key => $item ) { |
|
| 299 | - if ( 0 === intval( $item ) ) { |
|
| 300 | - unset( $meta['excluded_items'][ $key ] ); |
|
| 297 | + if (!empty($meta['excluded_items'])) { |
|
| 298 | + foreach ($meta['excluded_items'] as $key => $item) { |
|
| 299 | + if (0 === intval($item)) { |
|
| 300 | + unset($meta['excluded_items'][$key]); |
|
| 301 | 301 | } |
| 302 | 302 | } |
| 303 | 303 | } |
| 304 | 304 | |
| 305 | - $meta = apply_filters( 'wpinv_update_discount', $meta, $post_id, $post ); |
|
| 305 | + $meta = apply_filters('wpinv_update_discount', $meta, $post_id, $post); |
|
| 306 | 306 | |
| 307 | - do_action( 'wpinv_pre_update_discount', $meta, $post_id, $post ); |
|
| 307 | + do_action('wpinv_pre_update_discount', $meta, $post_id, $post); |
|
| 308 | 308 | |
| 309 | - foreach( $meta as $key => $value ) { |
|
| 310 | - update_post_meta( $post_id, '_wpi_discount_' . $key, $value ); |
|
| 309 | + foreach ($meta as $key => $value) { |
|
| 310 | + update_post_meta($post_id, '_wpi_discount_' . $key, $value); |
|
| 311 | 311 | } |
| 312 | 312 | |
| 313 | - do_action( 'wpinv_post_update_discount', $meta, $post_id, $post ); |
|
| 313 | + do_action('wpinv_post_update_discount', $meta, $post_id, $post); |
|
| 314 | 314 | |
| 315 | 315 | return $post_id; |
| 316 | 316 | } |
@@ -321,10 +321,10 @@ discard block |
||
| 321 | 321 | * @param int|array|string|WPInv_Discount $discount discount data, object, ID or code. |
| 322 | 322 | * @return bool |
| 323 | 323 | */ |
| 324 | -function wpinv_remove_discount( $discount = 0 ) { |
|
| 324 | +function wpinv_remove_discount($discount = 0) { |
|
| 325 | 325 | |
| 326 | - $discount = wpinv_get_discount_obj( $discount ); |
|
| 327 | - if( ! $discount->exists() ) { |
|
| 326 | + $discount = wpinv_get_discount_obj($discount); |
|
| 327 | + if (!$discount->exists()) { |
|
| 328 | 328 | return false; |
| 329 | 329 | } |
| 330 | 330 | |
@@ -339,9 +339,9 @@ discard block |
||
| 339 | 339 | * @param string $new_status |
| 340 | 340 | * @return bool |
| 341 | 341 | */ |
| 342 | -function wpinv_update_discount_status( $discount = 0, $new_status = 'publish' ) { |
|
| 343 | - $discount = wpinv_get_discount_obj( $discount ); |
|
| 344 | - return $discount->update_status( $new_status ); |
|
| 342 | +function wpinv_update_discount_status($discount = 0, $new_status = 'publish') { |
|
| 343 | + $discount = wpinv_get_discount_obj($discount); |
|
| 344 | + return $discount->update_status($new_status); |
|
| 345 | 345 | } |
| 346 | 346 | |
| 347 | 347 | /** |
@@ -350,48 +350,48 @@ discard block |
||
| 350 | 350 | * @param int|array|string|WPInv_Discount $discount discount data, object, ID or code. |
| 351 | 351 | * @return bool |
| 352 | 352 | */ |
| 353 | -function wpinv_discount_exists( $discount ) { |
|
| 354 | - $discount = wpinv_get_discount_obj( $discount ); |
|
| 353 | +function wpinv_discount_exists($discount) { |
|
| 354 | + $discount = wpinv_get_discount_obj($discount); |
|
| 355 | 355 | return $discount->exists(); |
| 356 | 356 | } |
| 357 | 357 | |
| 358 | -function wpinv_is_discount_active( $code_id = null ) { |
|
| 359 | - $discount = wpinv_get_discount( $code_id ); |
|
| 358 | +function wpinv_is_discount_active($code_id = null) { |
|
| 359 | + $discount = wpinv_get_discount($code_id); |
|
| 360 | 360 | $return = false; |
| 361 | 361 | |
| 362 | - if ( $discount ) { |
|
| 363 | - if ( wpinv_is_discount_expired( $code_id ) ) { |
|
| 364 | - if( defined( 'DOING_AJAX' ) ) { |
|
| 365 | - wpinv_set_error( 'wpinv-discount-error', __( 'This discount is expired.', 'invoicing' ) ); |
|
| 362 | + if ($discount) { |
|
| 363 | + if (wpinv_is_discount_expired($code_id)) { |
|
| 364 | + if (defined('DOING_AJAX')) { |
|
| 365 | + wpinv_set_error('wpinv-discount-error', __('This discount is expired.', 'invoicing')); |
|
| 366 | 366 | } |
| 367 | - } elseif ( $discount->post_status == 'publish' ) { |
|
| 367 | + } elseif ($discount->post_status == 'publish') { |
|
| 368 | 368 | $return = true; |
| 369 | 369 | } else { |
| 370 | - if( defined( 'DOING_AJAX' ) ) { |
|
| 371 | - wpinv_set_error( 'wpinv-discount-error', __( 'This discount is not active.', 'invoicing' ) ); |
|
| 370 | + if (defined('DOING_AJAX')) { |
|
| 371 | + wpinv_set_error('wpinv-discount-error', __('This discount is not active.', 'invoicing')); |
|
| 372 | 372 | } |
| 373 | 373 | } |
| 374 | 374 | } |
| 375 | 375 | |
| 376 | - return apply_filters( 'wpinv_is_discount_active', $return, $code_id ); |
|
| 376 | + return apply_filters('wpinv_is_discount_active', $return, $code_id); |
|
| 377 | 377 | } |
| 378 | 378 | |
| 379 | -function wpinv_get_discount_code( $code_id = null ) { |
|
| 380 | - $code = get_post_meta( $code_id, '_wpi_discount_code', true ); |
|
| 379 | +function wpinv_get_discount_code($code_id = null) { |
|
| 380 | + $code = get_post_meta($code_id, '_wpi_discount_code', true); |
|
| 381 | 381 | |
| 382 | - return apply_filters( 'wpinv_get_discount_code', $code, $code_id ); |
|
| 382 | + return apply_filters('wpinv_get_discount_code', $code, $code_id); |
|
| 383 | 383 | } |
| 384 | 384 | |
| 385 | -function wpinv_get_discount_start_date( $code_id = null ) { |
|
| 386 | - $start_date = get_post_meta( $code_id, '_wpi_discount_start', true ); |
|
| 385 | +function wpinv_get_discount_start_date($code_id = null) { |
|
| 386 | + $start_date = get_post_meta($code_id, '_wpi_discount_start', true); |
|
| 387 | 387 | |
| 388 | - return apply_filters( 'wpinv_get_discount_start_date', $start_date, $code_id ); |
|
| 388 | + return apply_filters('wpinv_get_discount_start_date', $start_date, $code_id); |
|
| 389 | 389 | } |
| 390 | 390 | |
| 391 | -function wpinv_get_discount_expiration( $code_id = null ) { |
|
| 392 | - $expiration = get_post_meta( $code_id, '_wpi_discount_expiration', true ); |
|
| 391 | +function wpinv_get_discount_expiration($code_id = null) { |
|
| 392 | + $expiration = get_post_meta($code_id, '_wpi_discount_expiration', true); |
|
| 393 | 393 | |
| 394 | - return apply_filters( 'wpinv_get_discount_expiration', $expiration, $code_id ); |
|
| 394 | + return apply_filters('wpinv_get_discount_expiration', $expiration, $code_id); |
|
| 395 | 395 | } |
| 396 | 396 | |
| 397 | 397 | /** |
@@ -400,8 +400,8 @@ discard block |
||
| 400 | 400 | * @param int|array|string|WPInv_Discount $discount discount data, object, ID or code. |
| 401 | 401 | * @return int |
| 402 | 402 | */ |
| 403 | -function wpinv_get_discount_max_uses( $discount = array() ) { |
|
| 404 | - $discount = wpinv_get_discount_obj( $discount ); |
|
| 403 | +function wpinv_get_discount_max_uses($discount = array()) { |
|
| 404 | + $discount = wpinv_get_discount_obj($discount); |
|
| 405 | 405 | return (int) $discount->max_uses; |
| 406 | 406 | } |
| 407 | 407 | |
@@ -411,8 +411,8 @@ discard block |
||
| 411 | 411 | * @param int|array|string|WPInv_Discount $discount discount data, object, ID or code. |
| 412 | 412 | * @return int |
| 413 | 413 | */ |
| 414 | -function wpinv_get_discount_uses( $discount = array() ) { |
|
| 415 | - $discount = wpinv_get_discount_obj( $discount ); |
|
| 414 | +function wpinv_get_discount_uses($discount = array()) { |
|
| 415 | + $discount = wpinv_get_discount_obj($discount); |
|
| 416 | 416 | return (int) $discount->uses; |
| 417 | 417 | } |
| 418 | 418 | |
@@ -422,8 +422,8 @@ discard block |
||
| 422 | 422 | * @param int|array|string|WPInv_Discount $discount discount data, object, ID or code. |
| 423 | 423 | * @return float |
| 424 | 424 | */ |
| 425 | -function wpinv_get_discount_min_total( $discount = array() ) { |
|
| 426 | - $discount = wpinv_get_discount_obj( $discount ); |
|
| 425 | +function wpinv_get_discount_min_total($discount = array()) { |
|
| 426 | + $discount = wpinv_get_discount_obj($discount); |
|
| 427 | 427 | return (float) $discount->min_total; |
| 428 | 428 | } |
| 429 | 429 | |
@@ -433,8 +433,8 @@ discard block |
||
| 433 | 433 | * @param int|array|string|WPInv_Discount $discount discount data, object, ID or code. |
| 434 | 434 | * @return float |
| 435 | 435 | */ |
| 436 | -function wpinv_get_discount_max_total( $discount = array() ) { |
|
| 437 | - $discount = wpinv_get_discount_obj( $discount ); |
|
| 436 | +function wpinv_get_discount_max_total($discount = array()) { |
|
| 437 | + $discount = wpinv_get_discount_obj($discount); |
|
| 438 | 438 | return (float) $discount->max_total; |
| 439 | 439 | } |
| 440 | 440 | |
@@ -444,8 +444,8 @@ discard block |
||
| 444 | 444 | * @param int|array|string|WPInv_Discount $discount discount data, object, ID or code. |
| 445 | 445 | * @return float |
| 446 | 446 | */ |
| 447 | -function wpinv_get_discount_amount( $discount = array() ) { |
|
| 448 | - $discount = wpinv_get_discount_obj( $discount ); |
|
| 447 | +function wpinv_get_discount_amount($discount = array()) { |
|
| 448 | + $discount = wpinv_get_discount_obj($discount); |
|
| 449 | 449 | return (float) $discount->amount; |
| 450 | 450 | } |
| 451 | 451 | |
@@ -456,28 +456,28 @@ discard block |
||
| 456 | 456 | * @param bool $name |
| 457 | 457 | * @return string |
| 458 | 458 | */ |
| 459 | -function wpinv_get_discount_type( $discount = array(), $name = false ) { |
|
| 460 | - $discount = wpinv_get_discount_obj( $discount ); |
|
| 459 | +function wpinv_get_discount_type($discount = array(), $name = false) { |
|
| 460 | + $discount = wpinv_get_discount_obj($discount); |
|
| 461 | 461 | |
| 462 | 462 | // Are we returning the name or just the type. |
| 463 | - if( $name ) { |
|
| 463 | + if ($name) { |
|
| 464 | 464 | return $discount->type_name; |
| 465 | 465 | } |
| 466 | 466 | |
| 467 | 467 | return $discount->type; |
| 468 | 468 | } |
| 469 | 469 | |
| 470 | -function wpinv_discount_status( $status ) { |
|
| 471 | - switch( $status ){ |
|
| 470 | +function wpinv_discount_status($status) { |
|
| 471 | + switch ($status) { |
|
| 472 | 472 | case 'expired' : |
| 473 | - $name = __( 'Expired', 'invoicing' ); |
|
| 473 | + $name = __('Expired', 'invoicing'); |
|
| 474 | 474 | break; |
| 475 | 475 | case 'publish' : |
| 476 | 476 | case 'active' : |
| 477 | - $name = __( 'Active', 'invoicing' ); |
|
| 477 | + $name = __('Active', 'invoicing'); |
|
| 478 | 478 | break; |
| 479 | 479 | default : |
| 480 | - $name = __( 'Inactive', 'invoicing' ); |
|
| 480 | + $name = __('Inactive', 'invoicing'); |
|
| 481 | 481 | break; |
| 482 | 482 | } |
| 483 | 483 | return $name; |
@@ -489,8 +489,8 @@ discard block |
||
| 489 | 489 | * @param int|array|string|WPInv_Discount $discount discount data, object, ID or code. |
| 490 | 490 | * @return array |
| 491 | 491 | */ |
| 492 | -function wpinv_get_discount_excluded_items( $discount = array() ) { |
|
| 493 | - $discount = wpinv_get_discount_obj( $discount ); |
|
| 492 | +function wpinv_get_discount_excluded_items($discount = array()) { |
|
| 493 | + $discount = wpinv_get_discount_obj($discount); |
|
| 494 | 494 | return $discount->excluded_items; |
| 495 | 495 | } |
| 496 | 496 | |
@@ -500,17 +500,17 @@ discard block |
||
| 500 | 500 | * @param int|array|string|WPInv_Discount $discount discount data, object, ID or code. |
| 501 | 501 | * @return array |
| 502 | 502 | */ |
| 503 | -function wpinv_get_discount_item_reqs( $discount = array() ) { |
|
| 504 | - $discount = wpinv_get_discount_obj( $discount ); |
|
| 503 | +function wpinv_get_discount_item_reqs($discount = array()) { |
|
| 504 | + $discount = wpinv_get_discount_obj($discount); |
|
| 505 | 505 | return $discount->items; |
| 506 | 506 | } |
| 507 | 507 | |
| 508 | -function wpinv_get_discount_item_condition( $code_id = 0 ) { |
|
| 509 | - return get_post_meta( $code_id, '_wpi_discount_item_condition', true ); |
|
| 508 | +function wpinv_get_discount_item_condition($code_id = 0) { |
|
| 509 | + return get_post_meta($code_id, '_wpi_discount_item_condition', true); |
|
| 510 | 510 | } |
| 511 | 511 | |
| 512 | -function wpinv_is_discount_not_global( $code_id = 0 ) { |
|
| 513 | - return (bool) get_post_meta( $code_id, '_wpi_discount_is_not_global', true ); |
|
| 512 | +function wpinv_is_discount_not_global($code_id = 0) { |
|
| 513 | + return (bool) get_post_meta($code_id, '_wpi_discount_is_not_global', true); |
|
| 514 | 514 | } |
| 515 | 515 | |
| 516 | 516 | /** |
@@ -519,14 +519,14 @@ discard block |
||
| 519 | 519 | * @param int|array|string|WPInv_Discount $discount discount data, object, ID or code. |
| 520 | 520 | * @return bool |
| 521 | 521 | */ |
| 522 | -function wpinv_is_discount_expired( $discount = array() ) { |
|
| 523 | - $discount = wpinv_get_discount_obj( $discount ); |
|
| 522 | +function wpinv_is_discount_expired($discount = array()) { |
|
| 523 | + $discount = wpinv_get_discount_obj($discount); |
|
| 524 | 524 | |
| 525 | - if ( $discount->is_expired() ) { |
|
| 526 | - $discount->update_status( 'pending' ); |
|
| 525 | + if ($discount->is_expired()) { |
|
| 526 | + $discount->update_status('pending'); |
|
| 527 | 527 | |
| 528 | - if( empty( $started ) ) { |
|
| 529 | - wpinv_set_error( 'wpinv-discount-error', __( 'This discount has expired.', 'invoicing' ) ); |
|
| 528 | + if (empty($started)) { |
|
| 529 | + wpinv_set_error('wpinv-discount-error', __('This discount has expired.', 'invoicing')); |
|
| 530 | 530 | } |
| 531 | 531 | return true; |
| 532 | 532 | } |
@@ -540,12 +540,12 @@ discard block |
||
| 540 | 540 | * @param int|array|string|WPInv_Discount $discount discount data, object, ID or code. |
| 541 | 541 | * @return bool |
| 542 | 542 | */ |
| 543 | -function wpinv_is_discount_started( $discount = array() ) { |
|
| 544 | - $discount = wpinv_get_discount_obj( $discount ); |
|
| 543 | +function wpinv_is_discount_started($discount = array()) { |
|
| 544 | + $discount = wpinv_get_discount_obj($discount); |
|
| 545 | 545 | $started = $discount->has_started(); |
| 546 | 546 | |
| 547 | - if( empty( $started ) ) { |
|
| 548 | - wpinv_set_error( 'wpinv-discount-error', __( 'This discount is not active yet.', 'invoicing' ) ); |
|
| 547 | + if (empty($started)) { |
|
| 548 | + wpinv_set_error('wpinv-discount-error', __('This discount is not active yet.', 'invoicing')); |
|
| 549 | 549 | } |
| 550 | 550 | |
| 551 | 551 | return $started; |
@@ -557,10 +557,10 @@ discard block |
||
| 557 | 557 | * @param int|array|string|WPInv_Discount $discount discount data, object, ID or code. |
| 558 | 558 | * @return bool |
| 559 | 559 | */ |
| 560 | -function wpinv_check_discount_dates( $discount ) { |
|
| 561 | - $discount = wpinv_get_discount_obj( $discount ); |
|
| 562 | - $return = wpinv_is_discount_started( $discount ) && ! wpinv_is_discount_expired( $discount ); |
|
| 563 | - return apply_filters( 'wpinv_check_discount_dates', $return, $discount->ID, $discount, $discount->code ); |
|
| 560 | +function wpinv_check_discount_dates($discount) { |
|
| 561 | + $discount = wpinv_get_discount_obj($discount); |
|
| 562 | + $return = wpinv_is_discount_started($discount) && !wpinv_is_discount_expired($discount); |
|
| 563 | + return apply_filters('wpinv_check_discount_dates', $return, $discount->ID, $discount, $discount->code); |
|
| 564 | 564 | } |
| 565 | 565 | |
| 566 | 566 | /** |
@@ -569,12 +569,12 @@ discard block |
||
| 569 | 569 | * @param int|array|string|WPInv_Discount $discount discount data, object, ID or code. |
| 570 | 570 | * @return bool |
| 571 | 571 | */ |
| 572 | -function wpinv_is_discount_maxed_out( $discount ) { |
|
| 573 | - $discount = wpinv_get_discount_obj( $discount ); |
|
| 572 | +function wpinv_is_discount_maxed_out($discount) { |
|
| 573 | + $discount = wpinv_get_discount_obj($discount); |
|
| 574 | 574 | $maxed_out = $discount->has_exceeded_limit(); |
| 575 | 575 | |
| 576 | - if ( $maxed_out ) { |
|
| 577 | - wpinv_set_error( 'wpinv-discount-error', __( 'This discount has reached its maximum usage.', 'invoicing' ) ); |
|
| 576 | + if ($maxed_out) { |
|
| 577 | + wpinv_set_error('wpinv-discount-error', __('This discount has reached its maximum usage.', 'invoicing')); |
|
| 578 | 578 | } |
| 579 | 579 | |
| 580 | 580 | return $maxed_out; |
@@ -586,13 +586,13 @@ discard block |
||
| 586 | 586 | * @param int|array|string|WPInv_Discount $discount discount data, object, ID or code. |
| 587 | 587 | * @return bool |
| 588 | 588 | */ |
| 589 | -function wpinv_discount_is_min_met( $discount ) { |
|
| 590 | - $discount = wpinv_get_discount_obj( $discount ); |
|
| 591 | - $cart_amount = (float)wpinv_get_cart_discountable_subtotal( $discount->ID ); |
|
| 592 | - $min_met = $discount->is_minimum_amount_met( $cart_amount ); |
|
| 589 | +function wpinv_discount_is_min_met($discount) { |
|
| 590 | + $discount = wpinv_get_discount_obj($discount); |
|
| 591 | + $cart_amount = (float) wpinv_get_cart_discountable_subtotal($discount->ID); |
|
| 592 | + $min_met = $discount->is_minimum_amount_met($cart_amount); |
|
| 593 | 593 | |
| 594 | - if ( ! $min_met ) { |
|
| 595 | - wpinv_set_error( 'wpinv-discount-error', sprintf( __( 'Minimum invoice amount should be %s', 'invoicing' ), wpinv_price( wpinv_format_amount( $discount->min_total ) ) ) ); |
|
| 594 | + if (!$min_met) { |
|
| 595 | + wpinv_set_error('wpinv-discount-error', sprintf(__('Minimum invoice amount should be %s', 'invoicing'), wpinv_price(wpinv_format_amount($discount->min_total)))); |
|
| 596 | 596 | } |
| 597 | 597 | |
| 598 | 598 | return $min_met; |
@@ -604,13 +604,13 @@ discard block |
||
| 604 | 604 | * @param int|array|string|WPInv_Discount $discount discount data, object, ID or code. |
| 605 | 605 | * @return bool |
| 606 | 606 | */ |
| 607 | -function wpinv_discount_is_max_met( $discount ) { |
|
| 608 | - $discount = wpinv_get_discount_obj( $discount ); |
|
| 609 | - $cart_amount = (float)wpinv_get_cart_discountable_subtotal( $discount->ID ); |
|
| 610 | - $max_met = $discount->is_maximum_amount_met( $cart_amount ); |
|
| 607 | +function wpinv_discount_is_max_met($discount) { |
|
| 608 | + $discount = wpinv_get_discount_obj($discount); |
|
| 609 | + $cart_amount = (float) wpinv_get_cart_discountable_subtotal($discount->ID); |
|
| 610 | + $max_met = $discount->is_maximum_amount_met($cart_amount); |
|
| 611 | 611 | |
| 612 | - if ( ! $max_met ) { |
|
| 613 | - wpinv_set_error( 'wpinv-discount-error', sprintf( __( 'Maximum invoice amount should be %s', 'invoicing' ), wpinv_price( wpinv_format_amount( $discount->max_total ) ) ) ); |
|
| 612 | + if (!$max_met) { |
|
| 613 | + wpinv_set_error('wpinv-discount-error', sprintf(__('Maximum invoice amount should be %s', 'invoicing'), wpinv_price(wpinv_format_amount($discount->max_total)))); |
|
| 614 | 614 | } |
| 615 | 615 | |
| 616 | 616 | return $max_met; |
@@ -622,8 +622,8 @@ discard block |
||
| 622 | 622 | * @param int|array|string|WPInv_Discount $discount discount data, object, ID or code. |
| 623 | 623 | * @return bool |
| 624 | 624 | */ |
| 625 | -function wpinv_discount_is_single_use( $discount ) { |
|
| 626 | - $discount = wpinv_get_discount_obj( $discount ); |
|
| 625 | +function wpinv_discount_is_single_use($discount) { |
|
| 626 | + $discount = wpinv_get_discount_obj($discount); |
|
| 627 | 627 | return $discount->is_single_use; |
| 628 | 628 | } |
| 629 | 629 | |
@@ -634,53 +634,53 @@ discard block |
||
| 634 | 634 | * @param int|array|string|WPInv_Discount $code discount data, object, ID or code. |
| 635 | 635 | * @return bool |
| 636 | 636 | */ |
| 637 | -function wpinv_discount_is_recurring( $discount = 0, $code = 0 ) { |
|
| 637 | +function wpinv_discount_is_recurring($discount = 0, $code = 0) { |
|
| 638 | 638 | |
| 639 | - if( ! empty( $discount ) ) { |
|
| 640 | - $discount = wpinv_get_discount_obj( $discount ); |
|
| 639 | + if (!empty($discount)) { |
|
| 640 | + $discount = wpinv_get_discount_obj($discount); |
|
| 641 | 641 | } else { |
| 642 | - $discount = wpinv_get_discount_obj( $code ); |
|
| 642 | + $discount = wpinv_get_discount_obj($code); |
|
| 643 | 643 | } |
| 644 | 644 | |
| 645 | 645 | return $discount->get_is_recurring(); |
| 646 | 646 | } |
| 647 | 647 | |
| 648 | -function wpinv_discount_item_reqs_met( $code_id = null ) { |
|
| 649 | - $item_reqs = wpinv_get_discount_item_reqs( $code_id ); |
|
| 650 | - $condition = wpinv_get_discount_item_condition( $code_id ); |
|
| 651 | - $excluded_ps = wpinv_get_discount_excluded_items( $code_id ); |
|
| 648 | +function wpinv_discount_item_reqs_met($code_id = null) { |
|
| 649 | + $item_reqs = wpinv_get_discount_item_reqs($code_id); |
|
| 650 | + $condition = wpinv_get_discount_item_condition($code_id); |
|
| 651 | + $excluded_ps = wpinv_get_discount_excluded_items($code_id); |
|
| 652 | 652 | $cart_items = wpinv_get_cart_contents(); |
| 653 | - $cart_ids = $cart_items ? wp_list_pluck( $cart_items, 'id' ) : null; |
|
| 653 | + $cart_ids = $cart_items ? wp_list_pluck($cart_items, 'id') : null; |
|
| 654 | 654 | $ret = false; |
| 655 | 655 | |
| 656 | - if ( empty( $item_reqs ) && empty( $excluded_ps ) ) { |
|
| 656 | + if (empty($item_reqs) && empty($excluded_ps)) { |
|
| 657 | 657 | $ret = true; |
| 658 | 658 | } |
| 659 | 659 | |
| 660 | 660 | // Normalize our data for item requirements, exclusions and cart data |
| 661 | 661 | // First absint the items, then sort, and reset the array keys |
| 662 | - $item_reqs = array_map( 'absint', $item_reqs ); |
|
| 663 | - asort( $item_reqs ); |
|
| 664 | - $item_reqs = array_values( $item_reqs ); |
|
| 662 | + $item_reqs = array_map('absint', $item_reqs); |
|
| 663 | + asort($item_reqs); |
|
| 664 | + $item_reqs = array_values($item_reqs); |
|
| 665 | 665 | |
| 666 | - $excluded_ps = array_map( 'absint', $excluded_ps ); |
|
| 667 | - asort( $excluded_ps ); |
|
| 668 | - $excluded_ps = array_values( $excluded_ps ); |
|
| 666 | + $excluded_ps = array_map('absint', $excluded_ps); |
|
| 667 | + asort($excluded_ps); |
|
| 668 | + $excluded_ps = array_values($excluded_ps); |
|
| 669 | 669 | |
| 670 | - $cart_ids = array_map( 'absint', $cart_ids ); |
|
| 671 | - asort( $cart_ids ); |
|
| 672 | - $cart_ids = array_values( $cart_ids ); |
|
| 670 | + $cart_ids = array_map('absint', $cart_ids); |
|
| 671 | + asort($cart_ids); |
|
| 672 | + $cart_ids = array_values($cart_ids); |
|
| 673 | 673 | |
| 674 | 674 | // Ensure we have requirements before proceeding |
| 675 | - if ( !$ret && ! empty( $item_reqs ) ) { |
|
| 676 | - switch( $condition ) { |
|
| 675 | + if (!$ret && !empty($item_reqs)) { |
|
| 676 | + switch ($condition) { |
|
| 677 | 677 | case 'all' : |
| 678 | 678 | // Default back to true |
| 679 | 679 | $ret = true; |
| 680 | 680 | |
| 681 | - foreach ( $item_reqs as $item_id ) { |
|
| 682 | - if ( !wpinv_item_in_cart( $item_id ) ) { |
|
| 683 | - wpinv_set_error( 'wpinv-discount-error', __( 'The item requirements for this discount are not met.', 'invoicing' ) ); |
|
| 681 | + foreach ($item_reqs as $item_id) { |
|
| 682 | + if (!wpinv_item_in_cart($item_id)) { |
|
| 683 | + wpinv_set_error('wpinv-discount-error', __('The item requirements for this discount are not met.', 'invoicing')); |
|
| 684 | 684 | $ret = false; |
| 685 | 685 | break; |
| 686 | 686 | } |
@@ -689,15 +689,15 @@ discard block |
||
| 689 | 689 | break; |
| 690 | 690 | |
| 691 | 691 | default : // Any |
| 692 | - foreach ( $item_reqs as $item_id ) { |
|
| 693 | - if ( wpinv_item_in_cart( $item_id ) ) { |
|
| 692 | + foreach ($item_reqs as $item_id) { |
|
| 693 | + if (wpinv_item_in_cart($item_id)) { |
|
| 694 | 694 | $ret = true; |
| 695 | 695 | break; |
| 696 | 696 | } |
| 697 | 697 | } |
| 698 | 698 | |
| 699 | - if( ! $ret ) { |
|
| 700 | - wpinv_set_error( 'wpinv-discount-error', __( 'The item requirements for this discount are not met.', 'invoicing' ) ); |
|
| 699 | + if (!$ret) { |
|
| 700 | + wpinv_set_error('wpinv-discount-error', __('The item requirements for this discount are not met.', 'invoicing')); |
|
| 701 | 701 | } |
| 702 | 702 | |
| 703 | 703 | break; |
@@ -706,15 +706,15 @@ discard block |
||
| 706 | 706 | $ret = true; |
| 707 | 707 | } |
| 708 | 708 | |
| 709 | - if( ! empty( $excluded_ps ) ) { |
|
| 709 | + if (!empty($excluded_ps)) { |
|
| 710 | 710 | // Check that there are items other than excluded ones in the cart |
| 711 | - if( $cart_ids == $excluded_ps ) { |
|
| 712 | - wpinv_set_error( 'wpinv-discount-error', __( 'This discount is not valid for the cart contents.', 'invoicing' ) ); |
|
| 711 | + if ($cart_ids == $excluded_ps) { |
|
| 712 | + wpinv_set_error('wpinv-discount-error', __('This discount is not valid for the cart contents.', 'invoicing')); |
|
| 713 | 713 | $ret = false; |
| 714 | 714 | } |
| 715 | 715 | } |
| 716 | 716 | |
| 717 | - return (bool) apply_filters( 'wpinv_is_discount_item_req_met', $ret, $code_id, $condition ); |
|
| 717 | + return (bool) apply_filters('wpinv_is_discount_item_req_met', $ret, $code_id, $condition); |
|
| 718 | 718 | } |
| 719 | 719 | |
| 720 | 720 | /** |
@@ -725,53 +725,53 @@ discard block |
||
| 725 | 725 | * @param int|array|string|WPInv_Discount $code_id discount data, object, ID or code. |
| 726 | 726 | * @return bool |
| 727 | 727 | */ |
| 728 | -function wpinv_is_discount_used( $discount = array(), $user = '', $code_id = array() ) { |
|
| 728 | +function wpinv_is_discount_used($discount = array(), $user = '', $code_id = array()) { |
|
| 729 | 729 | |
| 730 | - if( ! empty( $discount ) ) { |
|
| 731 | - $discount = wpinv_get_discount_obj( $discount ); |
|
| 730 | + if (!empty($discount)) { |
|
| 731 | + $discount = wpinv_get_discount_obj($discount); |
|
| 732 | 732 | } else { |
| 733 | - $discount = wpinv_get_discount_obj( $code_id ); |
|
| 733 | + $discount = wpinv_get_discount_obj($code_id); |
|
| 734 | 734 | } |
| 735 | 735 | |
| 736 | - $is_used = ! $discount->is_valid_for_user( $user ); |
|
| 737 | - $is_used = apply_filters( 'wpinv_is_discount_used', $is_used, $discount->code, $user, $discount->ID, $discount ); |
|
| 736 | + $is_used = !$discount->is_valid_for_user($user); |
|
| 737 | + $is_used = apply_filters('wpinv_is_discount_used', $is_used, $discount->code, $user, $discount->ID, $discount); |
|
| 738 | 738 | |
| 739 | - if( $is_used ) { |
|
| 740 | - wpinv_set_error( 'wpinv-discount-error', __( 'This discount has already been redeemed.', 'invoicing' ) ); |
|
| 739 | + if ($is_used) { |
|
| 740 | + wpinv_set_error('wpinv-discount-error', __('This discount has already been redeemed.', 'invoicing')); |
|
| 741 | 741 | } |
| 742 | 742 | |
| 743 | 743 | return $is_used; |
| 744 | 744 | } |
| 745 | 745 | |
| 746 | -function wpinv_is_discount_valid( $code = '', $user = '', $set_error = true ) { |
|
| 746 | +function wpinv_is_discount_valid($code = '', $user = '', $set_error = true) { |
|
| 747 | 747 | $return = false; |
| 748 | - $discount_id = wpinv_get_discount_id_by_code( $code ); |
|
| 749 | - $user = trim( $user ); |
|
| 748 | + $discount_id = wpinv_get_discount_id_by_code($code); |
|
| 749 | + $user = trim($user); |
|
| 750 | 750 | |
| 751 | - if ( wpinv_get_cart_contents() ) { |
|
| 752 | - if ( $discount_id !== false ) { |
|
| 751 | + if (wpinv_get_cart_contents()) { |
|
| 752 | + if ($discount_id !== false) { |
|
| 753 | 753 | if ( |
| 754 | - wpinv_is_discount_active( $discount_id ) && |
|
| 755 | - wpinv_check_discount_dates( $discount_id ) && |
|
| 756 | - !wpinv_is_discount_maxed_out( $discount_id ) && |
|
| 757 | - !wpinv_is_discount_used( $code, $user, $discount_id ) && |
|
| 758 | - wpinv_discount_is_min_met( $discount_id ) && |
|
| 759 | - wpinv_discount_is_max_met( $discount_id ) && |
|
| 760 | - wpinv_discount_item_reqs_met( $discount_id ) |
|
| 754 | + wpinv_is_discount_active($discount_id) && |
|
| 755 | + wpinv_check_discount_dates($discount_id) && |
|
| 756 | + !wpinv_is_discount_maxed_out($discount_id) && |
|
| 757 | + !wpinv_is_discount_used($code, $user, $discount_id) && |
|
| 758 | + wpinv_discount_is_min_met($discount_id) && |
|
| 759 | + wpinv_discount_is_max_met($discount_id) && |
|
| 760 | + wpinv_discount_item_reqs_met($discount_id) |
|
| 761 | 761 | ) { |
| 762 | 762 | $return = true; |
| 763 | 763 | } |
| 764 | - } elseif( $set_error ) { |
|
| 765 | - wpinv_set_error( 'wpinv-discount-error', __( 'This discount is invalid.', 'invoicing' ) ); |
|
| 764 | + } elseif ($set_error) { |
|
| 765 | + wpinv_set_error('wpinv-discount-error', __('This discount is invalid.', 'invoicing')); |
|
| 766 | 766 | } |
| 767 | 767 | } |
| 768 | 768 | |
| 769 | - return apply_filters( 'wpinv_is_discount_valid', $return, $discount_id, $code, $user ); |
|
| 769 | + return apply_filters('wpinv_is_discount_valid', $return, $discount_id, $code, $user); |
|
| 770 | 770 | } |
| 771 | 771 | |
| 772 | -function wpinv_get_discount_id_by_code( $code ) { |
|
| 773 | - $discount = wpinv_get_discount_by_code( $code ); |
|
| 774 | - if( $discount ) { |
|
| 772 | +function wpinv_get_discount_id_by_code($code) { |
|
| 773 | + $discount = wpinv_get_discount_by_code($code); |
|
| 774 | + if ($discount) { |
|
| 775 | 775 | return $discount->ID; |
| 776 | 776 | } |
| 777 | 777 | return false; |
@@ -784,9 +784,9 @@ discard block |
||
| 784 | 784 | * @param float $base_price The number of usages to increase by |
| 785 | 785 | * @return float |
| 786 | 786 | */ |
| 787 | -function wpinv_get_discounted_amount( $discount, $base_price ) { |
|
| 788 | - $discount = wpinv_get_discount_obj( $discount ); |
|
| 789 | - return $discount->get_discounted_amount( $base_price ); |
|
| 787 | +function wpinv_get_discounted_amount($discount, $base_price) { |
|
| 788 | + $discount = wpinv_get_discount_obj($discount); |
|
| 789 | + return $discount->get_discounted_amount($base_price); |
|
| 790 | 790 | } |
| 791 | 791 | |
| 792 | 792 | /** |
@@ -796,9 +796,9 @@ discard block |
||
| 796 | 796 | * @param int $by The number of usages to increase by. |
| 797 | 797 | * @return int the new number of uses. |
| 798 | 798 | */ |
| 799 | -function wpinv_increase_discount_usage( $discount, $by = 1 ) { |
|
| 800 | - $discount = wpinv_get_discount_obj( $discount ); |
|
| 801 | - return $discount->increase_usage( $by ); |
|
| 799 | +function wpinv_increase_discount_usage($discount, $by = 1) { |
|
| 800 | + $discount = wpinv_get_discount_obj($discount); |
|
| 801 | + return $discount->increase_usage($by); |
|
| 802 | 802 | } |
| 803 | 803 | |
| 804 | 804 | /** |
@@ -808,72 +808,72 @@ discard block |
||
| 808 | 808 | * @param int $by The number of usages to decrease by. |
| 809 | 809 | * @return int the new number of uses. |
| 810 | 810 | */ |
| 811 | -function wpinv_decrease_discount_usage( $discount, $by = 1 ) { |
|
| 812 | - $discount = wpinv_get_discount_obj( $discount ); |
|
| 813 | - return $discount->increase_usage( 0 - $by ); |
|
| 811 | +function wpinv_decrease_discount_usage($discount, $by = 1) { |
|
| 812 | + $discount = wpinv_get_discount_obj($discount); |
|
| 813 | + return $discount->increase_usage(0 - $by); |
|
| 814 | 814 | } |
| 815 | 815 | |
| 816 | -function wpinv_format_discount_rate( $type, $amount ) { |
|
| 817 | - if ( $type == 'flat' ) { |
|
| 818 | - $rate = wpinv_price( wpinv_format_amount( $amount ) ); |
|
| 816 | +function wpinv_format_discount_rate($type, $amount) { |
|
| 817 | + if ($type == 'flat') { |
|
| 818 | + $rate = wpinv_price(wpinv_format_amount($amount)); |
|
| 819 | 819 | } else { |
| 820 | 820 | $rate = $amount . '%'; |
| 821 | 821 | } |
| 822 | 822 | |
| 823 | - return apply_filters( 'wpinv_format_discount_rate', $rate, $type, $amount ); |
|
| 823 | + return apply_filters('wpinv_format_discount_rate', $rate, $type, $amount); |
|
| 824 | 824 | } |
| 825 | 825 | |
| 826 | -function wpinv_set_cart_discount( $code = '' ) { |
|
| 827 | - if ( wpinv_multiple_discounts_allowed() ) { |
|
| 826 | +function wpinv_set_cart_discount($code = '') { |
|
| 827 | + if (wpinv_multiple_discounts_allowed()) { |
|
| 828 | 828 | // Get all active cart discounts |
| 829 | 829 | $discounts = wpinv_get_cart_discounts(); |
| 830 | 830 | } else { |
| 831 | 831 | $discounts = false; // Only one discount allowed per purchase, so override any existing |
| 832 | 832 | } |
| 833 | 833 | |
| 834 | - if ( $discounts ) { |
|
| 835 | - $key = array_search( strtolower( $code ), array_map( 'strtolower', $discounts ) ); |
|
| 836 | - if( false !== $key ) { |
|
| 837 | - unset( $discounts[ $key ] ); // Can't set the same discount more than once |
|
| 834 | + if ($discounts) { |
|
| 835 | + $key = array_search(strtolower($code), array_map('strtolower', $discounts)); |
|
| 836 | + if (false !== $key) { |
|
| 837 | + unset($discounts[$key]); // Can't set the same discount more than once |
|
| 838 | 838 | } |
| 839 | 839 | $discounts[] = $code; |
| 840 | 840 | } else { |
| 841 | 841 | $discounts = array(); |
| 842 | 842 | $discounts[] = $code; |
| 843 | 843 | } |
| 844 | - $discounts = array_values( $discounts ); |
|
| 844 | + $discounts = array_values($discounts); |
|
| 845 | 845 | |
| 846 | 846 | $data = wpinv_get_checkout_session(); |
| 847 | - if ( empty( $data ) ) { |
|
| 847 | + if (empty($data)) { |
|
| 848 | 848 | $data = array(); |
| 849 | 849 | } else { |
| 850 | - if ( !empty( $data['invoice_id'] ) && $payment_meta = wpinv_get_invoice_meta( $data['invoice_id'] ) ) { |
|
| 851 | - $payment_meta['user_info']['discount'] = implode( ',', $discounts ); |
|
| 852 | - update_post_meta( $data['invoice_id'], '_wpinv_payment_meta', $payment_meta ); |
|
| 850 | + if (!empty($data['invoice_id']) && $payment_meta = wpinv_get_invoice_meta($data['invoice_id'])) { |
|
| 851 | + $payment_meta['user_info']['discount'] = implode(',', $discounts); |
|
| 852 | + update_post_meta($data['invoice_id'], '_wpinv_payment_meta', $payment_meta); |
|
| 853 | 853 | } |
| 854 | 854 | } |
| 855 | 855 | $data['cart_discounts'] = $discounts; |
| 856 | 856 | |
| 857 | - wpinv_set_checkout_session( $data ); |
|
| 857 | + wpinv_set_checkout_session($data); |
|
| 858 | 858 | |
| 859 | 859 | return $discounts; |
| 860 | 860 | } |
| 861 | 861 | |
| 862 | -function wpinv_unset_cart_discount( $code = '' ) { |
|
| 862 | +function wpinv_unset_cart_discount($code = '') { |
|
| 863 | 863 | $discounts = wpinv_get_cart_discounts(); |
| 864 | 864 | |
| 865 | - if ( $code && !empty( $discounts ) && in_array( $code, $discounts ) ) { |
|
| 866 | - $key = array_search( $code, $discounts ); |
|
| 867 | - unset( $discounts[ $key ] ); |
|
| 865 | + if ($code && !empty($discounts) && in_array($code, $discounts)) { |
|
| 866 | + $key = array_search($code, $discounts); |
|
| 867 | + unset($discounts[$key]); |
|
| 868 | 868 | |
| 869 | 869 | $data = wpinv_get_checkout_session(); |
| 870 | 870 | $data['cart_discounts'] = $discounts; |
| 871 | - if ( !empty( $data['invoice_id'] ) && $payment_meta = wpinv_get_invoice_meta( $data['invoice_id'] ) ) { |
|
| 872 | - $payment_meta['user_info']['discount'] = !empty( $discounts ) ? implode( ',', $discounts ) : ''; |
|
| 873 | - update_post_meta( $data['invoice_id'], '_wpinv_payment_meta', $payment_meta ); |
|
| 871 | + if (!empty($data['invoice_id']) && $payment_meta = wpinv_get_invoice_meta($data['invoice_id'])) { |
|
| 872 | + $payment_meta['user_info']['discount'] = !empty($discounts) ? implode(',', $discounts) : ''; |
|
| 873 | + update_post_meta($data['invoice_id'], '_wpinv_payment_meta', $payment_meta); |
|
| 874 | 874 | } |
| 875 | 875 | |
| 876 | - wpinv_set_checkout_session( $data ); |
|
| 876 | + wpinv_set_checkout_session($data); |
|
| 877 | 877 | } |
| 878 | 878 | |
| 879 | 879 | return $discounts; |
@@ -882,10 +882,10 @@ discard block |
||
| 882 | 882 | function wpinv_unset_all_cart_discounts() { |
| 883 | 883 | $data = wpinv_get_checkout_session(); |
| 884 | 884 | |
| 885 | - if ( !empty( $data ) && isset( $data['cart_discounts'] ) ) { |
|
| 886 | - unset( $data['cart_discounts'] ); |
|
| 885 | + if (!empty($data) && isset($data['cart_discounts'])) { |
|
| 886 | + unset($data['cart_discounts']); |
|
| 887 | 887 | |
| 888 | - wpinv_set_checkout_session( $data ); |
|
| 888 | + wpinv_set_checkout_session($data); |
|
| 889 | 889 | return true; |
| 890 | 890 | } |
| 891 | 891 | |
@@ -894,13 +894,13 @@ discard block |
||
| 894 | 894 | |
| 895 | 895 | function wpinv_get_cart_discounts() { |
| 896 | 896 | $session = wpinv_get_checkout_session(); |
| 897 | - return empty( $session['cart_discounts'] ) ? false : $session['cart_discounts']; |
|
| 897 | + return empty($session['cart_discounts']) ? false : $session['cart_discounts']; |
|
| 898 | 898 | } |
| 899 | 899 | |
| 900 | -function wpinv_cart_has_discounts( $items = array() ) { |
|
| 900 | +function wpinv_cart_has_discounts($items = array()) { |
|
| 901 | 901 | $ret = false; |
| 902 | 902 | |
| 903 | - if ( wpinv_get_cart_discounts( $items ) ) { |
|
| 903 | + if (wpinv_get_cart_discounts($items)) { |
|
| 904 | 904 | $ret = true; |
| 905 | 905 | } |
| 906 | 906 | |
@@ -911,131 +911,131 @@ discard block |
||
| 911 | 911 | } |
| 912 | 912 | */ |
| 913 | 913 | |
| 914 | - return apply_filters( 'wpinv_cart_has_discounts', $ret ); |
|
| 914 | + return apply_filters('wpinv_cart_has_discounts', $ret); |
|
| 915 | 915 | } |
| 916 | 916 | |
| 917 | -function wpinv_get_cart_discounted_amount( $items = array(), $discounts = false ) { |
|
| 917 | +function wpinv_get_cart_discounted_amount($items = array(), $discounts = false) { |
|
| 918 | 918 | $amount = 0.00; |
| 919 | - $items = !empty( $items ) ? $items : wpinv_get_cart_content_details(); |
|
| 919 | + $items = !empty($items) ? $items : wpinv_get_cart_content_details(); |
|
| 920 | 920 | |
| 921 | - if ( $items ) { |
|
| 922 | - $discounts = wp_list_pluck( $items, 'discount' ); |
|
| 921 | + if ($items) { |
|
| 922 | + $discounts = wp_list_pluck($items, 'discount'); |
|
| 923 | 923 | |
| 924 | - if ( is_array( $discounts ) ) { |
|
| 925 | - $discounts = array_map( 'floatval', $discounts ); |
|
| 926 | - $amount = array_sum( $discounts ); |
|
| 924 | + if (is_array($discounts)) { |
|
| 925 | + $discounts = array_map('floatval', $discounts); |
|
| 926 | + $amount = array_sum($discounts); |
|
| 927 | 927 | } |
| 928 | 928 | } |
| 929 | 929 | |
| 930 | - return apply_filters( 'wpinv_get_cart_discounted_amount', $amount ); |
|
| 930 | + return apply_filters('wpinv_get_cart_discounted_amount', $amount); |
|
| 931 | 931 | } |
| 932 | 932 | |
| 933 | -function wpinv_get_cart_items_discount_amount( $items = array(), $discount = false ) { |
|
| 934 | - $items = !empty( $items ) ? $items : wpinv_get_cart_content_details(); |
|
| 933 | +function wpinv_get_cart_items_discount_amount($items = array(), $discount = false) { |
|
| 934 | + $items = !empty($items) ? $items : wpinv_get_cart_content_details(); |
|
| 935 | 935 | |
| 936 | - if ( empty( $discount ) || empty( $items ) ) { |
|
| 936 | + if (empty($discount) || empty($items)) { |
|
| 937 | 937 | return 0; |
| 938 | 938 | } |
| 939 | 939 | |
| 940 | 940 | $amount = 0; |
| 941 | 941 | |
| 942 | - foreach ( $items as $item ) { |
|
| 943 | - $amount += wpinv_get_cart_item_discount_amount( $item, $discount ); |
|
| 942 | + foreach ($items as $item) { |
|
| 943 | + $amount += wpinv_get_cart_item_discount_amount($item, $discount); |
|
| 944 | 944 | } |
| 945 | 945 | |
| 946 | - $amount = wpinv_round_amount( $amount ); |
|
| 946 | + $amount = wpinv_round_amount($amount); |
|
| 947 | 947 | |
| 948 | 948 | return $amount; |
| 949 | 949 | } |
| 950 | 950 | |
| 951 | -function wpinv_get_cart_item_discount_amount( $item = array(), $discount = false ) { |
|
| 951 | +function wpinv_get_cart_item_discount_amount($item = array(), $discount = false) { |
|
| 952 | 952 | global $wpinv_is_last_cart_item, $wpinv_flat_discount_total; |
| 953 | 953 | |
| 954 | 954 | $amount = 0; |
| 955 | 955 | |
| 956 | - if ( empty( $item ) || empty( $item['id'] ) ) { |
|
| 956 | + if (empty($item) || empty($item['id'])) { |
|
| 957 | 957 | return $amount; |
| 958 | 958 | } |
| 959 | 959 | |
| 960 | - if ( empty( $item['quantity'] ) ) { |
|
| 960 | + if (empty($item['quantity'])) { |
|
| 961 | 961 | return $amount; |
| 962 | 962 | } |
| 963 | 963 | |
| 964 | - if ( empty( $item['options'] ) ) { |
|
| 964 | + if (empty($item['options'])) { |
|
| 965 | 965 | $item['options'] = array(); |
| 966 | 966 | } |
| 967 | 967 | |
| 968 | - $price = wpinv_get_cart_item_price( $item['id'], $item, $item['options'] ); |
|
| 968 | + $price = wpinv_get_cart_item_price($item['id'], $item, $item['options']); |
|
| 969 | 969 | $discounted_price = $price; |
| 970 | 970 | |
| 971 | 971 | $discounts = false === $discount ? wpinv_get_cart_discounts() : $discount; |
| 972 | - if ( empty( $discounts ) ) { |
|
| 972 | + if (empty($discounts)) { |
|
| 973 | 973 | return $amount; |
| 974 | 974 | } |
| 975 | 975 | |
| 976 | - if ( $discounts ) { |
|
| 977 | - if ( is_array( $discounts ) ) { |
|
| 978 | - $discounts = array_values( $discounts ); |
|
| 976 | + if ($discounts) { |
|
| 977 | + if (is_array($discounts)) { |
|
| 978 | + $discounts = array_values($discounts); |
|
| 979 | 979 | } else { |
| 980 | - $discounts = explode( ',', $discounts ); |
|
| 980 | + $discounts = explode(',', $discounts); |
|
| 981 | 981 | } |
| 982 | 982 | } |
| 983 | 983 | |
| 984 | - if( $discounts ) { |
|
| 985 | - foreach ( $discounts as $discount ) { |
|
| 986 | - $code_id = wpinv_get_discount_id_by_code( $discount ); |
|
| 984 | + if ($discounts) { |
|
| 985 | + foreach ($discounts as $discount) { |
|
| 986 | + $code_id = wpinv_get_discount_id_by_code($discount); |
|
| 987 | 987 | |
| 988 | 988 | // Check discount exists |
| 989 | - if( $code_id === false ) { |
|
| 989 | + if ($code_id === false) { |
|
| 990 | 990 | continue; |
| 991 | 991 | } |
| 992 | 992 | |
| 993 | - $reqs = wpinv_get_discount_item_reqs( $code_id ); |
|
| 994 | - $excluded_items = wpinv_get_discount_excluded_items( $code_id ); |
|
| 993 | + $reqs = wpinv_get_discount_item_reqs($code_id); |
|
| 994 | + $excluded_items = wpinv_get_discount_excluded_items($code_id); |
|
| 995 | 995 | |
| 996 | 996 | // Make sure requirements are set and that this discount shouldn't apply to the whole cart |
| 997 | - if ( !empty( $reqs ) && wpinv_is_discount_not_global( $code_id ) ) { |
|
| 998 | - foreach ( $reqs as $item_id ) { |
|
| 999 | - if ( $item_id == $item['id'] && ! in_array( $item['id'], $excluded_items ) ) { |
|
| 1000 | - $discounted_price -= wpinv_get_discounted_amount( $discount, $price ); |
|
| 997 | + if (!empty($reqs) && wpinv_is_discount_not_global($code_id)) { |
|
| 998 | + foreach ($reqs as $item_id) { |
|
| 999 | + if ($item_id == $item['id'] && !in_array($item['id'], $excluded_items)) { |
|
| 1000 | + $discounted_price -= wpinv_get_discounted_amount($discount, $price); |
|
| 1001 | 1001 | } |
| 1002 | 1002 | } |
| 1003 | 1003 | } else { |
| 1004 | 1004 | // This is a global cart discount |
| 1005 | - if ( !in_array( $item['id'], $excluded_items ) ) { |
|
| 1006 | - if ( 'flat' === wpinv_get_discount_type( $code_id ) ) { |
|
| 1005 | + if (!in_array($item['id'], $excluded_items)) { |
|
| 1006 | + if ('flat' === wpinv_get_discount_type($code_id)) { |
|
| 1007 | 1007 | $items_subtotal = 0.00; |
| 1008 | 1008 | $cart_items = wpinv_get_cart_contents(); |
| 1009 | 1009 | |
| 1010 | - foreach ( $cart_items as $cart_item ) { |
|
| 1011 | - if ( ! in_array( $cart_item['id'], $excluded_items ) ) { |
|
| 1012 | - $options = !empty( $cart_item['options'] ) ? $cart_item['options'] : array(); |
|
| 1013 | - $item_price = wpinv_get_cart_item_price( $cart_item['id'], $cart_item, $options ); |
|
| 1010 | + foreach ($cart_items as $cart_item) { |
|
| 1011 | + if (!in_array($cart_item['id'], $excluded_items)) { |
|
| 1012 | + $options = !empty($cart_item['options']) ? $cart_item['options'] : array(); |
|
| 1013 | + $item_price = wpinv_get_cart_item_price($cart_item['id'], $cart_item, $options); |
|
| 1014 | 1014 | $items_subtotal += $item_price * $cart_item['quantity']; |
| 1015 | 1015 | } |
| 1016 | 1016 | } |
| 1017 | 1017 | |
| 1018 | - $subtotal_percent = ( ( $price * $item['quantity'] ) / $items_subtotal ); |
|
| 1019 | - $code_amount = wpinv_get_discount_amount( $code_id ); |
|
| 1018 | + $subtotal_percent = (($price * $item['quantity']) / $items_subtotal); |
|
| 1019 | + $code_amount = wpinv_get_discount_amount($code_id); |
|
| 1020 | 1020 | $discounted_amount = $code_amount * $subtotal_percent; |
| 1021 | 1021 | $discounted_price -= $discounted_amount; |
| 1022 | 1022 | |
| 1023 | - $wpinv_flat_discount_total += round( $discounted_amount, wpinv_currency_decimal_filter() ); |
|
| 1023 | + $wpinv_flat_discount_total += round($discounted_amount, wpinv_currency_decimal_filter()); |
|
| 1024 | 1024 | |
| 1025 | - if ( $wpinv_is_last_cart_item && $wpinv_flat_discount_total < $code_amount ) { |
|
| 1025 | + if ($wpinv_is_last_cart_item && $wpinv_flat_discount_total < $code_amount) { |
|
| 1026 | 1026 | $adjustment = $code_amount - $wpinv_flat_discount_total; |
| 1027 | 1027 | $discounted_price -= $adjustment; |
| 1028 | 1028 | } |
| 1029 | 1029 | } else { |
| 1030 | - $discounted_price -= wpinv_get_discounted_amount( $discount, $price ); |
|
| 1030 | + $discounted_price -= wpinv_get_discounted_amount($discount, $price); |
|
| 1031 | 1031 | } |
| 1032 | 1032 | } |
| 1033 | 1033 | } |
| 1034 | 1034 | } |
| 1035 | 1035 | |
| 1036 | - $amount = ( $price - apply_filters( 'wpinv_get_cart_item_discounted_amount', $discounted_price, $discounts, $item, $price ) ); |
|
| 1036 | + $amount = ($price - apply_filters('wpinv_get_cart_item_discounted_amount', $discounted_price, $discounts, $item, $price)); |
|
| 1037 | 1037 | |
| 1038 | - if ( 'flat' !== wpinv_get_discount_type( $code_id ) ) { |
|
| 1038 | + if ('flat' !== wpinv_get_discount_type($code_id)) { |
|
| 1039 | 1039 | $amount = $amount * $item['quantity']; |
| 1040 | 1040 | } |
| 1041 | 1041 | } |
@@ -1043,59 +1043,59 @@ discard block |
||
| 1043 | 1043 | return $amount; |
| 1044 | 1044 | } |
| 1045 | 1045 | |
| 1046 | -function wpinv_cart_discounts_html( $items = array() ) { |
|
| 1047 | - echo wpinv_get_cart_discounts_html( $items ); |
|
| 1046 | +function wpinv_cart_discounts_html($items = array()) { |
|
| 1047 | + echo wpinv_get_cart_discounts_html($items); |
|
| 1048 | 1048 | } |
| 1049 | 1049 | |
| 1050 | -function wpinv_get_cart_discounts_html( $items = array(), $discounts = false ) { |
|
| 1050 | +function wpinv_get_cart_discounts_html($items = array(), $discounts = false) { |
|
| 1051 | 1051 | global $wpi_cart_columns; |
| 1052 | 1052 | |
| 1053 | - $items = !empty( $items ) ? $items : wpinv_get_cart_content_details(); |
|
| 1053 | + $items = !empty($items) ? $items : wpinv_get_cart_content_details(); |
|
| 1054 | 1054 | |
| 1055 | - if ( !$discounts ) { |
|
| 1056 | - $discounts = wpinv_get_cart_discounts( $items ); |
|
| 1055 | + if (!$discounts) { |
|
| 1056 | + $discounts = wpinv_get_cart_discounts($items); |
|
| 1057 | 1057 | } |
| 1058 | 1058 | |
| 1059 | - if ( !$discounts ) { |
|
| 1059 | + if (!$discounts) { |
|
| 1060 | 1060 | return; |
| 1061 | 1061 | } |
| 1062 | 1062 | |
| 1063 | - $discounts = is_array( $discounts ) ? $discounts : array( $discounts ); |
|
| 1063 | + $discounts = is_array($discounts) ? $discounts : array($discounts); |
|
| 1064 | 1064 | |
| 1065 | 1065 | $html = ''; |
| 1066 | 1066 | |
| 1067 | - foreach ( $discounts as $discount ) { |
|
| 1068 | - $discount_id = wpinv_get_discount_id_by_code( $discount ); |
|
| 1069 | - $discount_value = wpinv_get_discount_amount( $discount_id ); |
|
| 1070 | - $rate = wpinv_format_discount_rate( wpinv_get_discount_type( $discount_id ), $discount_value ); |
|
| 1071 | - $amount = wpinv_get_cart_items_discount_amount( $items, $discount ); |
|
| 1072 | - $remove_btn = '<a title="' . esc_attr__( 'Remove discount', 'invoicing' ) . '" data-code="' . $discount . '" data-value="' . $discount_value . '" class="wpi-discount-remove" href="javascript:void(0);">[<i class="fa fa-times" aria-hidden="true"></i>]</a> '; |
|
| 1067 | + foreach ($discounts as $discount) { |
|
| 1068 | + $discount_id = wpinv_get_discount_id_by_code($discount); |
|
| 1069 | + $discount_value = wpinv_get_discount_amount($discount_id); |
|
| 1070 | + $rate = wpinv_format_discount_rate(wpinv_get_discount_type($discount_id), $discount_value); |
|
| 1071 | + $amount = wpinv_get_cart_items_discount_amount($items, $discount); |
|
| 1072 | + $remove_btn = '<a title="' . esc_attr__('Remove discount', 'invoicing') . '" data-code="' . $discount . '" data-value="' . $discount_value . '" class="wpi-discount-remove" href="javascript:void(0);">[<i class="fa fa-times" aria-hidden="true"></i>]</a> '; |
|
| 1073 | 1073 | |
| 1074 | 1074 | $html .= '<tr class="wpinv_cart_footer_row wpinv_cart_discount_row">'; |
| 1075 | 1075 | ob_start(); |
| 1076 | - do_action( 'wpinv_checkout_table_discount_first', $items ); |
|
| 1076 | + do_action('wpinv_checkout_table_discount_first', $items); |
|
| 1077 | 1077 | $html .= ob_get_clean(); |
| 1078 | - $html .= '<td class="wpinv_cart_discount_label text-right" colspan="' . $wpi_cart_columns . '">' . $remove_btn . '<strong>' . wpinv_cart_discount_label( $discount, $rate, false ) . '</strong></td><td class="wpinv_cart_discount text-right"><span data-discount="' . $amount . '" class="wpinv_cart_discount_amount">–' . wpinv_price( wpinv_format_amount( $amount ) ) . '</span></td>'; |
|
| 1078 | + $html .= '<td class="wpinv_cart_discount_label text-right" colspan="' . $wpi_cart_columns . '">' . $remove_btn . '<strong>' . wpinv_cart_discount_label($discount, $rate, false) . '</strong></td><td class="wpinv_cart_discount text-right"><span data-discount="' . $amount . '" class="wpinv_cart_discount_amount">–' . wpinv_price(wpinv_format_amount($amount)) . '</span></td>'; |
|
| 1079 | 1079 | ob_start(); |
| 1080 | - do_action( 'wpinv_checkout_table_discount_last', $items ); |
|
| 1080 | + do_action('wpinv_checkout_table_discount_last', $items); |
|
| 1081 | 1081 | $html .= ob_get_clean(); |
| 1082 | 1082 | $html .= '</tr>'; |
| 1083 | 1083 | } |
| 1084 | 1084 | |
| 1085 | - return apply_filters( 'wpinv_get_cart_discounts_html', $html, $discounts, $rate ); |
|
| 1085 | + return apply_filters('wpinv_get_cart_discounts_html', $html, $discounts, $rate); |
|
| 1086 | 1086 | } |
| 1087 | 1087 | |
| 1088 | -function wpinv_display_cart_discount( /** @scrutinizer ignore-unused */ $formatted = false, $echo = false ) { |
|
| 1088 | +function wpinv_display_cart_discount(/** @scrutinizer ignore-unused */ $formatted = false, $echo = false) { |
|
| 1089 | 1089 | $discounts = wpinv_get_cart_discounts(); |
| 1090 | 1090 | |
| 1091 | - if ( empty( $discounts ) ) { |
|
| 1091 | + if (empty($discounts)) { |
|
| 1092 | 1092 | return false; |
| 1093 | 1093 | } |
| 1094 | 1094 | |
| 1095 | - $discount_id = wpinv_get_discount_id_by_code( $discounts[0] ); |
|
| 1096 | - $amount = wpinv_format_discount_rate( wpinv_get_discount_type( $discount_id ), wpinv_get_discount_amount( $discount_id ) ); |
|
| 1095 | + $discount_id = wpinv_get_discount_id_by_code($discounts[0]); |
|
| 1096 | + $amount = wpinv_format_discount_rate(wpinv_get_discount_type($discount_id), wpinv_get_discount_amount($discount_id)); |
|
| 1097 | 1097 | |
| 1098 | - if ( $echo ) { |
|
| 1098 | + if ($echo) { |
|
| 1099 | 1099 | echo $amount; |
| 1100 | 1100 | } |
| 1101 | 1101 | |
@@ -1103,101 +1103,101 @@ discard block |
||
| 1103 | 1103 | } |
| 1104 | 1104 | |
| 1105 | 1105 | function wpinv_remove_cart_discount() { |
| 1106 | - if ( !isset( $_GET['discount_id'] ) || ! isset( $_GET['discount_code'] ) ) { |
|
| 1106 | + if (!isset($_GET['discount_id']) || !isset($_GET['discount_code'])) { |
|
| 1107 | 1107 | return; |
| 1108 | 1108 | } |
| 1109 | 1109 | |
| 1110 | - do_action( 'wpinv_pre_remove_cart_discount', absint( $_GET['discount_id'] ) ); |
|
| 1110 | + do_action('wpinv_pre_remove_cart_discount', absint($_GET['discount_id'])); |
|
| 1111 | 1111 | |
| 1112 | - wpinv_unset_cart_discount( urldecode( $_GET['discount_code'] ) ); |
|
| 1112 | + wpinv_unset_cart_discount(urldecode($_GET['discount_code'])); |
|
| 1113 | 1113 | |
| 1114 | - do_action( 'wpinv_post_remove_cart_discount', absint( $_GET['discount_id'] ) ); |
|
| 1114 | + do_action('wpinv_post_remove_cart_discount', absint($_GET['discount_id'])); |
|
| 1115 | 1115 | |
| 1116 | - wp_redirect( wpinv_get_checkout_uri() ); wpinv_die(); |
|
| 1116 | + wp_redirect(wpinv_get_checkout_uri()); wpinv_die(); |
|
| 1117 | 1117 | } |
| 1118 | -add_action( 'wpinv_remove_cart_discount', 'wpinv_remove_cart_discount' ); |
|
| 1118 | +add_action('wpinv_remove_cart_discount', 'wpinv_remove_cart_discount'); |
|
| 1119 | 1119 | |
| 1120 | 1120 | function wpinv_maybe_remove_cart_discount() { |
| 1121 | 1121 | $discounts = wpinv_get_cart_discounts(); |
| 1122 | 1122 | |
| 1123 | - if ( !$discounts ) { |
|
| 1123 | + if (!$discounts) { |
|
| 1124 | 1124 | return; |
| 1125 | 1125 | } |
| 1126 | 1126 | |
| 1127 | - foreach ( $discounts as $discount ) { |
|
| 1128 | - if ( !wpinv_is_discount_valid( $discount ) ) { |
|
| 1129 | - wpinv_unset_cart_discount( $discount ); |
|
| 1127 | + foreach ($discounts as $discount) { |
|
| 1128 | + if (!wpinv_is_discount_valid($discount)) { |
|
| 1129 | + wpinv_unset_cart_discount($discount); |
|
| 1130 | 1130 | } |
| 1131 | 1131 | } |
| 1132 | 1132 | } |
| 1133 | -add_action( 'wpinv_post_remove_from_cart', 'wpinv_maybe_remove_cart_discount' ); |
|
| 1133 | +add_action('wpinv_post_remove_from_cart', 'wpinv_maybe_remove_cart_discount'); |
|
| 1134 | 1134 | |
| 1135 | 1135 | function wpinv_multiple_discounts_allowed() { |
| 1136 | - $ret = wpinv_get_option( 'allow_multiple_discounts', false ); |
|
| 1137 | - return (bool) apply_filters( 'wpinv_multiple_discounts_allowed', $ret ); |
|
| 1136 | + $ret = wpinv_get_option('allow_multiple_discounts', false); |
|
| 1137 | + return (bool) apply_filters('wpinv_multiple_discounts_allowed', $ret); |
|
| 1138 | 1138 | } |
| 1139 | 1139 | |
| 1140 | -function wpinv_get_discount_label( $code, $echo = true ) { |
|
| 1141 | - $label = wp_sprintf( __( 'Discount%1$s', 'invoicing' ), ( $code != '' && $code != 'none' ? ' (<code>' . $code . '</code>)': '' ) ); |
|
| 1142 | - $label = apply_filters( 'wpinv_get_discount_label', $label, $code ); |
|
| 1140 | +function wpinv_get_discount_label($code, $echo = true) { |
|
| 1141 | + $label = wp_sprintf(__('Discount%1$s', 'invoicing'), ($code != '' && $code != 'none' ? ' (<code>' . $code . '</code>)' : '')); |
|
| 1142 | + $label = apply_filters('wpinv_get_discount_label', $label, $code); |
|
| 1143 | 1143 | |
| 1144 | - if ( $echo ) { |
|
| 1144 | + if ($echo) { |
|
| 1145 | 1145 | echo $label; |
| 1146 | 1146 | } else { |
| 1147 | 1147 | return $label; |
| 1148 | 1148 | } |
| 1149 | 1149 | } |
| 1150 | 1150 | |
| 1151 | -function wpinv_cart_discount_label( $code, $rate, $echo = true ) { |
|
| 1152 | - $label = wp_sprintf( __( 'Discount: %s', 'invoicing' ), $code ); |
|
| 1153 | - $label = apply_filters( 'wpinv_cart_discount_label', $label, $code, $rate ); |
|
| 1151 | +function wpinv_cart_discount_label($code, $rate, $echo = true) { |
|
| 1152 | + $label = wp_sprintf(__('Discount: %s', 'invoicing'), $code); |
|
| 1153 | + $label = apply_filters('wpinv_cart_discount_label', $label, $code, $rate); |
|
| 1154 | 1154 | |
| 1155 | - if ( $echo ) { |
|
| 1155 | + if ($echo) { |
|
| 1156 | 1156 | echo $label; |
| 1157 | 1157 | } else { |
| 1158 | 1158 | return $label; |
| 1159 | 1159 | } |
| 1160 | 1160 | } |
| 1161 | 1161 | |
| 1162 | -function wpinv_check_delete_discount( $check, $post ) { |
|
| 1163 | - if ( $post->post_type == 'wpi_discount' && wpinv_get_discount_uses( $post->ID ) > 0 ) { |
|
| 1162 | +function wpinv_check_delete_discount($check, $post) { |
|
| 1163 | + if ($post->post_type == 'wpi_discount' && wpinv_get_discount_uses($post->ID) > 0) { |
|
| 1164 | 1164 | return true; |
| 1165 | 1165 | } |
| 1166 | 1166 | |
| 1167 | 1167 | return $check; |
| 1168 | 1168 | } |
| 1169 | -add_filter( 'pre_delete_post', 'wpinv_check_delete_discount', 10, 2 ); |
|
| 1169 | +add_filter('pre_delete_post', 'wpinv_check_delete_discount', 10, 2); |
|
| 1170 | 1170 | |
| 1171 | 1171 | function wpinv_checkout_form_validate_discounts() { |
| 1172 | 1172 | global $wpi_checkout_id; |
| 1173 | 1173 | |
| 1174 | 1174 | $discounts = wpinv_get_cart_discounts(); |
| 1175 | 1175 | |
| 1176 | - if ( !empty( $discounts ) ) { |
|
| 1176 | + if (!empty($discounts)) { |
|
| 1177 | 1177 | $invalid = false; |
| 1178 | 1178 | |
| 1179 | - foreach ( $discounts as $key => $code ) { |
|
| 1180 | - if ( !wpinv_is_discount_valid( $code, (int)wpinv_get_user_id( $wpi_checkout_id ) ) ) { |
|
| 1179 | + foreach ($discounts as $key => $code) { |
|
| 1180 | + if (!wpinv_is_discount_valid($code, (int) wpinv_get_user_id($wpi_checkout_id))) { |
|
| 1181 | 1181 | $invalid = true; |
| 1182 | 1182 | |
| 1183 | - wpinv_unset_cart_discount( $code ); |
|
| 1183 | + wpinv_unset_cart_discount($code); |
|
| 1184 | 1184 | } |
| 1185 | 1185 | } |
| 1186 | 1186 | |
| 1187 | - if ( $invalid ) { |
|
| 1187 | + if ($invalid) { |
|
| 1188 | 1188 | $errors = wpinv_get_errors(); |
| 1189 | - $error = !empty( $errors['wpinv-discount-error'] ) ? $errors['wpinv-discount-error'] . ' ' : ''; |
|
| 1190 | - $error .= __( 'The discount has been removed from cart.', 'invoicing' ); |
|
| 1191 | - wpinv_set_error( 'wpinv-discount-error', $error ); |
|
| 1189 | + $error = !empty($errors['wpinv-discount-error']) ? $errors['wpinv-discount-error'] . ' ' : ''; |
|
| 1190 | + $error .= __('The discount has been removed from cart.', 'invoicing'); |
|
| 1191 | + wpinv_set_error('wpinv-discount-error', $error); |
|
| 1192 | 1192 | |
| 1193 | - wpinv_recalculate_tax( true ); |
|
| 1193 | + wpinv_recalculate_tax(true); |
|
| 1194 | 1194 | } |
| 1195 | 1195 | } |
| 1196 | 1196 | } |
| 1197 | -add_action( 'wpinv_before_checkout_form', 'wpinv_checkout_form_validate_discounts', -10 ); |
|
| 1197 | +add_action('wpinv_before_checkout_form', 'wpinv_checkout_form_validate_discounts', -10); |
|
| 1198 | 1198 | |
| 1199 | 1199 | function wpinv_discount_amount() { |
| 1200 | 1200 | $output = 0.00; |
| 1201 | 1201 | |
| 1202 | - return apply_filters( 'wpinv_discount_amount', $output ); |
|
| 1202 | + return apply_filters('wpinv_discount_amount', $output); |
|
| 1203 | 1203 | } |
| 1204 | 1204 | \ No newline at end of file |
@@ -1,13 +1,13 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | // Exit if accessed directly |
| 3 | -if ( ! defined( 'ABSPATH' ) ) exit; |
|
| 3 | +if (!defined('ABSPATH')) exit; |
|
| 4 | 4 | |
| 5 | -add_action( 'wpinv_manual_cc_form', '__return_false' ); |
|
| 6 | -add_filter( 'wpinv_manual_support_subscription', '__return_true' ); |
|
| 5 | +add_action('wpinv_manual_cc_form', '__return_false'); |
|
| 6 | +add_filter('wpinv_manual_support_subscription', '__return_true'); |
|
| 7 | 7 | |
| 8 | -function wpinv_process_manual_payment( $purchase_data ) { |
|
| 9 | - if( ! wp_verify_nonce( $purchase_data['gateway_nonce'], 'wpi-gateway' ) ) { |
|
| 10 | - wp_die( __( 'Nonce verification has failed', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
| 8 | +function wpinv_process_manual_payment($purchase_data) { |
|
| 9 | + if (!wp_verify_nonce($purchase_data['gateway_nonce'], 'wpi-gateway')) { |
|
| 10 | + wp_die(__('Nonce verification has failed', 'invoicing'), __('Error', 'invoicing'), array('response' => 403)); |
|
| 11 | 11 | } |
| 12 | 12 | |
| 13 | 13 | // Collect payment data |
@@ -25,45 +25,45 @@ discard block |
||
| 25 | 25 | ); |
| 26 | 26 | |
| 27 | 27 | // Record the pending payment |
| 28 | - $invoice = wpinv_get_invoice( $purchase_data['invoice_id'] ); |
|
| 28 | + $invoice = wpinv_get_invoice($purchase_data['invoice_id']); |
|
| 29 | 29 | |
| 30 | - if ( !empty( $invoice ) ) { |
|
| 31 | - wpinv_set_payment_transaction_id( $invoice->ID, $invoice->generate_key() ); |
|
| 32 | - wpinv_update_payment_status( $invoice, 'publish' ); |
|
| 30 | + if (!empty($invoice)) { |
|
| 31 | + wpinv_set_payment_transaction_id($invoice->ID, $invoice->generate_key()); |
|
| 32 | + wpinv_update_payment_status($invoice, 'publish'); |
|
| 33 | 33 | |
| 34 | 34 | // Empty the shopping cart |
| 35 | 35 | wpinv_empty_cart(); |
| 36 | 36 | |
| 37 | 37 | // (Maybe) set recurring hooks. |
| 38 | - wpinv_start_manual_subscription_profile( $purchase_data['invoice_id'] ); |
|
| 38 | + wpinv_start_manual_subscription_profile($purchase_data['invoice_id']); |
|
| 39 | 39 | |
| 40 | - do_action( 'wpinv_send_to_success_page', $invoice->ID, $payment_data ); |
|
| 40 | + do_action('wpinv_send_to_success_page', $invoice->ID, $payment_data); |
|
| 41 | 41 | |
| 42 | - wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
| 42 | + wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key())); |
|
| 43 | 43 | } else { |
| 44 | - wpinv_record_gateway_error( __( 'Payment Error', 'invoicing' ), sprintf( __( 'Payment creation failed while processing a manual (free or test) purchase. Payment data: %s', 'invoicing' ), json_encode( $payment_data ) ), $invoice ); |
|
| 44 | + wpinv_record_gateway_error(__('Payment Error', 'invoicing'), sprintf(__('Payment creation failed while processing a manual (free or test) purchase. Payment data: %s', 'invoicing'), json_encode($payment_data)), $invoice); |
|
| 45 | 45 | // If errors are present, send the user back to the purchase page so they can be corrected |
| 46 | - wpinv_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['wpi-gateway'] ); |
|
| 46 | + wpinv_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['wpi-gateway']); |
|
| 47 | 47 | } |
| 48 | 48 | } |
| 49 | -add_action( 'wpinv_gateway_manual', 'wpinv_process_manual_payment' ); |
|
| 49 | +add_action('wpinv_gateway_manual', 'wpinv_process_manual_payment'); |
|
| 50 | 50 | |
| 51 | 51 | /** |
| 52 | 52 | * Starts a manual subscription profile. |
| 53 | 53 | */ |
| 54 | -function wpinv_start_manual_subscription_profile( $invoice_id ) { |
|
| 54 | +function wpinv_start_manual_subscription_profile($invoice_id) { |
|
| 55 | 55 | |
| 56 | 56 | // Retrieve the subscription. |
| 57 | - $subscription = wpinv_get_subscription( $invoice_id ); |
|
| 58 | - if ( empty( $subscription ) ) { |
|
| 57 | + $subscription = wpinv_get_subscription($invoice_id); |
|
| 58 | + if (empty($subscription)) { |
|
| 59 | 59 | return; |
| 60 | 60 | } |
| 61 | 61 | |
| 62 | 62 | // Schedule an action to run when the subscription expires. |
| 63 | 63 | $action_id = as_schedule_single_action( |
| 64 | - strtotime( $subscription->expiration ), |
|
| 64 | + strtotime($subscription->expiration), |
|
| 65 | 65 | 'wpinv_renew_manual_subscription_profile', |
| 66 | - array( $invoice_id ), |
|
| 66 | + array($invoice_id), |
|
| 67 | 67 | 'invoicing' |
| 68 | 68 | ); |
| 69 | 69 | |
@@ -80,11 +80,11 @@ discard block |
||
| 80 | 80 | /** |
| 81 | 81 | * Renews a manual subscription profile. |
| 82 | 82 | */ |
| 83 | -function wpinv_renew_manual_subscription_profile( $invoice_id ) { |
|
| 83 | +function wpinv_renew_manual_subscription_profile($invoice_id) { |
|
| 84 | 84 | |
| 85 | 85 | // Retrieve the subscription. |
| 86 | - $subscription = wpinv_get_subscription( $invoice_id ); |
|
| 87 | - if ( empty( $subscription ) ) { |
|
| 86 | + $subscription = wpinv_get_subscription($invoice_id); |
|
| 87 | + if (empty($subscription)) { |
|
| 88 | 88 | return; |
| 89 | 89 | } |
| 90 | 90 | |
@@ -92,29 +92,29 @@ discard block |
||
| 92 | 92 | $max_bills = $subscription->bill_times; |
| 93 | 93 | |
| 94 | 94 | // If we have not maxed out on bill times... |
| 95 | - if ( empty( $bill_times ) || $times_billed > $max_bills ) { |
|
| 95 | + if (empty($bill_times) || $times_billed > $max_bills) { |
|
| 96 | 96 | |
| 97 | 97 | // Renew the subscription. |
| 98 | - $subscription->add_payment( array( |
|
| 98 | + $subscription->add_payment(array( |
|
| 99 | 99 | 'amount' => $subscription->recurring_amount, |
| 100 | 100 | 'transaction_id' => time(), |
| 101 | 101 | 'gateway' => 'manual' |
| 102 | - ) ); |
|
| 102 | + )); |
|
| 103 | 103 | |
| 104 | 104 | // Calculate the new expiration. |
| 105 | - $new_expiration = strtotime( "+ {$subscription->frequency} {$subscription->period}", strtotime( $subscription->expiration ) ); |
|
| 105 | + $new_expiration = strtotime("+ {$subscription->frequency} {$subscription->period}", strtotime($subscription->expiration)); |
|
| 106 | 106 | |
| 107 | 107 | // Schedule an action to run when the subscription expires. |
| 108 | 108 | $action_id = as_schedule_single_action( |
| 109 | 109 | $new_expiration, |
| 110 | 110 | 'wpinv_renew_manual_subscription_profile', |
| 111 | - array( $invoice_id ), |
|
| 111 | + array($invoice_id), |
|
| 112 | 112 | 'invoicing' |
| 113 | 113 | ); |
| 114 | 114 | |
| 115 | 115 | $subscription->update( |
| 116 | 116 | array( |
| 117 | - 'expiration' => date_i18n( 'Y-m-d H:i:s', $new_expiration ), |
|
| 117 | + 'expiration' => date_i18n('Y-m-d H:i:s', $new_expiration), |
|
| 118 | 118 | 'status' => 'active', |
| 119 | 119 | 'profile_id' => $action_id, |
| 120 | 120 | ) |
@@ -132,4 +132,4 @@ discard block |
||
| 132 | 132 | } |
| 133 | 133 | |
| 134 | 134 | } |
| 135 | -add_action( 'wpinv_renew_manual_subscription_profile', 'wpinv_renew_manual_subscription_profile' ); |
|
| 135 | +add_action('wpinv_renew_manual_subscription_profile', 'wpinv_renew_manual_subscription_profile'); |
|
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 3 | +if (!defined('ABSPATH')) { |
|
| 4 | 4 | exit; // Exit if accessed directly |
| 5 | 5 | } |
| 6 | 6 | |
@@ -13,19 +13,19 @@ discard block |
||
| 13 | 13 | |
| 14 | 14 | public function __construct() { |
| 15 | 15 | |
| 16 | - foreach( $this->get_elements() as $element ) { |
|
| 16 | + foreach ($this->get_elements() as $element) { |
|
| 17 | 17 | $element = $element['type']; |
| 18 | 18 | |
| 19 | - if ( method_exists( $this, "render_{$element}_template" ) ) { |
|
| 20 | - add_action( 'wpinv_payment_form_render_element_template', array( $this, "render_{$element}_template" ), 10, 2 ); |
|
| 19 | + if (method_exists($this, "render_{$element}_template")) { |
|
| 20 | + add_action('wpinv_payment_form_render_element_template', array($this, "render_{$element}_template"), 10, 2); |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | - if ( method_exists( $this, "edit_{$element}_template" ) ) { |
|
| 24 | - add_action( 'wpinv_payment_form_edit_element_template', array( $this, "edit_{$element}_template" ), 10, 2 ); |
|
| 23 | + if (method_exists($this, "edit_{$element}_template")) { |
|
| 24 | + add_action('wpinv_payment_form_edit_element_template', array($this, "edit_{$element}_template"), 10, 2); |
|
| 25 | 25 | } |
| 26 | 26 | |
| 27 | - if ( method_exists( $this, "frontend_render_{$element}_template" ) ) { |
|
| 28 | - add_action( "wpinv_frontend_render_payment_form_$element", array( $this, "frontend_render_{$element}_template" ), 10, 3 ); |
|
| 27 | + if (method_exists($this, "frontend_render_{$element}_template")) { |
|
| 28 | + add_action("wpinv_frontend_render_payment_form_$element", array($this, "frontend_render_{$element}_template"), 10, 3); |
|
| 29 | 29 | } |
| 30 | 30 | |
| 31 | 31 | } |
@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | */ |
| 38 | 38 | public function get_elements() { |
| 39 | 39 | |
| 40 | - if ( ! empty( $this->elements ) ) { |
|
| 40 | + if (!empty($this->elements)) { |
|
| 41 | 41 | return $this->elements; |
| 42 | 42 | } |
| 43 | 43 | |
@@ -45,28 +45,28 @@ discard block |
||
| 45 | 45 | |
| 46 | 46 | array( |
| 47 | 47 | 'type' => 'heading', |
| 48 | - 'name' => __( 'Heading', 'invoicing' ), |
|
| 48 | + 'name' => __('Heading', 'invoicing'), |
|
| 49 | 49 | 'defaults' => array( |
| 50 | 50 | 'level' => 'h2', |
| 51 | - 'text' => __( 'Heading', 'invoicing' ), |
|
| 51 | + 'text' => __('Heading', 'invoicing'), |
|
| 52 | 52 | ) |
| 53 | 53 | ), |
| 54 | 54 | |
| 55 | 55 | array( |
| 56 | 56 | 'type' => 'paragraph', |
| 57 | - 'name' => __( 'Paragraph', 'invoicing' ), |
|
| 57 | + 'name' => __('Paragraph', 'invoicing'), |
|
| 58 | 58 | 'defaults' => array( |
| 59 | - 'text' => __( 'Paragraph text', 'invoicing' ), |
|
| 59 | + 'text' => __('Paragraph text', 'invoicing'), |
|
| 60 | 60 | ) |
| 61 | 61 | ), |
| 62 | 62 | |
| 63 | 63 | array( |
| 64 | 64 | 'type' => 'alert', |
| 65 | - 'name' => __( 'Alert', 'invoicing' ), |
|
| 65 | + 'name' => __('Alert', 'invoicing'), |
|
| 66 | 66 | 'defaults' => array( |
| 67 | 67 | 'value' => '', |
| 68 | 68 | 'class' => 'alert-warning', |
| 69 | - 'text' => __( 'Alert', 'invoicing' ), |
|
| 69 | + 'text' => __('Alert', 'invoicing'), |
|
| 70 | 70 | 'dismissible' => false, |
| 71 | 71 | ) |
| 72 | 72 | ), |
@@ -82,11 +82,11 @@ discard block |
||
| 82 | 82 | |
| 83 | 83 | array( |
| 84 | 84 | 'type' => 'text', |
| 85 | - 'name' => __( 'Text Input', 'invoicing' ), |
|
| 85 | + 'name' => __('Text Input', 'invoicing'), |
|
| 86 | 86 | 'defaults' => array( |
| 87 | - 'placeholder' => __( 'Enter some text', 'invoicing' ), |
|
| 87 | + 'placeholder' => __('Enter some text', 'invoicing'), |
|
| 88 | 88 | 'value' => '', |
| 89 | - 'label' => __( 'Field Label', 'invoicing' ), |
|
| 89 | + 'label' => __('Field Label', 'invoicing'), |
|
| 90 | 90 | 'description' => '', |
| 91 | 91 | 'required' => false, |
| 92 | 92 | ) |
@@ -94,11 +94,11 @@ discard block |
||
| 94 | 94 | |
| 95 | 95 | array( |
| 96 | 96 | 'type' => 'textarea', |
| 97 | - 'name' => __( 'Textarea', 'invoicing' ), |
|
| 97 | + 'name' => __('Textarea', 'invoicing'), |
|
| 98 | 98 | 'defaults' => array( |
| 99 | - 'placeholder' => __( 'Enter your text hear', 'invoicing' ), |
|
| 99 | + 'placeholder' => __('Enter your text hear', 'invoicing'), |
|
| 100 | 100 | 'value' => '', |
| 101 | - 'label' => __( 'Textarea Label', 'invoicing' ), |
|
| 101 | + 'label' => __('Textarea Label', 'invoicing'), |
|
| 102 | 102 | 'description' => '', |
| 103 | 103 | 'required' => false, |
| 104 | 104 | ) |
@@ -106,27 +106,27 @@ discard block |
||
| 106 | 106 | |
| 107 | 107 | array( |
| 108 | 108 | 'type' => 'select', |
| 109 | - 'name' => __( 'Dropdown', 'invoicing' ), |
|
| 109 | + 'name' => __('Dropdown', 'invoicing'), |
|
| 110 | 110 | 'defaults' => array( |
| 111 | - 'placeholder' => __( 'Select a value', 'invoicing' ), |
|
| 111 | + 'placeholder' => __('Select a value', 'invoicing'), |
|
| 112 | 112 | 'value' => '', |
| 113 | - 'label' => __( 'Dropdown Label', 'invoicing' ), |
|
| 113 | + 'label' => __('Dropdown Label', 'invoicing'), |
|
| 114 | 114 | 'description' => '', |
| 115 | 115 | 'required' => false, |
| 116 | 116 | 'options' => array( |
| 117 | - esc_attr__( 'Option One', 'invoicing' ), |
|
| 118 | - esc_attr__( 'Option Two', 'invoicing' ), |
|
| 119 | - esc_attr__( 'Option Three', 'invoicing' ) |
|
| 117 | + esc_attr__('Option One', 'invoicing'), |
|
| 118 | + esc_attr__('Option Two', 'invoicing'), |
|
| 119 | + esc_attr__('Option Three', 'invoicing') |
|
| 120 | 120 | ), |
| 121 | 121 | ) |
| 122 | 122 | ), |
| 123 | 123 | |
| 124 | 124 | array( |
| 125 | 125 | 'type' => 'checkbox', |
| 126 | - 'name' => __( 'Checkbox', 'invoicing' ), |
|
| 126 | + 'name' => __('Checkbox', 'invoicing'), |
|
| 127 | 127 | 'defaults' => array( |
| 128 | 128 | 'value' => '', |
| 129 | - 'label' => __( 'Checkbox Label', 'invoicing' ), |
|
| 129 | + 'label' => __('Checkbox Label', 'invoicing'), |
|
| 130 | 130 | 'description' => '', |
| 131 | 131 | 'required' => false, |
| 132 | 132 | ) |
@@ -134,23 +134,23 @@ discard block |
||
| 134 | 134 | |
| 135 | 135 | array( |
| 136 | 136 | 'type' => 'radio', |
| 137 | - 'name' => __( 'Multiple Choice', 'invoicing' ), |
|
| 137 | + 'name' => __('Multiple Choice', 'invoicing'), |
|
| 138 | 138 | 'defaults' => array( |
| 139 | - 'label' => __( 'Select one choice', 'invoicing' ), |
|
| 139 | + 'label' => __('Select one choice', 'invoicing'), |
|
| 140 | 140 | 'options' => array( |
| 141 | - esc_attr__( 'Choice One', 'invoicing' ), |
|
| 142 | - esc_attr__( 'Choice Two', 'invoicing' ), |
|
| 143 | - esc_attr__( 'Choice Three', 'invoicing' ) |
|
| 141 | + esc_attr__('Choice One', 'invoicing'), |
|
| 142 | + esc_attr__('Choice Two', 'invoicing'), |
|
| 143 | + esc_attr__('Choice Three', 'invoicing') |
|
| 144 | 144 | ), |
| 145 | 145 | ) |
| 146 | 146 | ), |
| 147 | 147 | |
| 148 | 148 | array( |
| 149 | 149 | 'type' => 'date', |
| 150 | - 'name' => __( 'Date', 'invoicing' ), |
|
| 150 | + 'name' => __('Date', 'invoicing'), |
|
| 151 | 151 | 'defaults' => array( |
| 152 | 152 | 'value' => '', |
| 153 | - 'label' => __( 'Date', 'invoicing' ), |
|
| 153 | + 'label' => __('Date', 'invoicing'), |
|
| 154 | 154 | 'description' => '', |
| 155 | 155 | 'required' => false, |
| 156 | 156 | ) |
@@ -158,10 +158,10 @@ discard block |
||
| 158 | 158 | |
| 159 | 159 | array( |
| 160 | 160 | 'type' => 'time', |
| 161 | - 'name' => __( 'Time', 'invoicing' ), |
|
| 161 | + 'name' => __('Time', 'invoicing'), |
|
| 162 | 162 | 'defaults' => array( |
| 163 | 163 | 'value' => '', |
| 164 | - 'label' => __( 'Time', 'invoicing' ), |
|
| 164 | + 'label' => __('Time', 'invoicing'), |
|
| 165 | 165 | 'description' => '', |
| 166 | 166 | 'required' => false, |
| 167 | 167 | ) |
@@ -169,11 +169,11 @@ discard block |
||
| 169 | 169 | |
| 170 | 170 | array( |
| 171 | 171 | 'type' => 'number', |
| 172 | - 'name' => __( 'Number', 'invoicing' ), |
|
| 172 | + 'name' => __('Number', 'invoicing'), |
|
| 173 | 173 | 'defaults' => array( |
| 174 | 174 | 'placeholder' => '', |
| 175 | 175 | 'value' => '', |
| 176 | - 'label' => __( 'Number', 'invoicing' ), |
|
| 176 | + 'label' => __('Number', 'invoicing'), |
|
| 177 | 177 | 'description' => '', |
| 178 | 178 | 'required' => false, |
| 179 | 179 | ) |
@@ -181,11 +181,11 @@ discard block |
||
| 181 | 181 | |
| 182 | 182 | array( |
| 183 | 183 | 'type' => 'website', |
| 184 | - 'name' => __( 'Website', 'invoicing' ), |
|
| 184 | + 'name' => __('Website', 'invoicing'), |
|
| 185 | 185 | 'defaults' => array( |
| 186 | 186 | 'placeholder' => 'http://example.com', |
| 187 | 187 | 'value' => '', |
| 188 | - 'label' => __( 'Website', 'invoicing' ), |
|
| 188 | + 'label' => __('Website', 'invoicing'), |
|
| 189 | 189 | 'description' => '', |
| 190 | 190 | 'required' => false, |
| 191 | 191 | ) |
@@ -193,11 +193,11 @@ discard block |
||
| 193 | 193 | |
| 194 | 194 | array( |
| 195 | 195 | 'type' => 'email', |
| 196 | - 'name' => __( 'Email', 'invoicing' ), |
|
| 196 | + 'name' => __('Email', 'invoicing'), |
|
| 197 | 197 | 'defaults' => array( |
| 198 | 198 | 'placeholder' => '[email protected]', |
| 199 | 199 | 'value' => '', |
| 200 | - 'label' => __( 'Email Address', 'invoicing' ), |
|
| 200 | + 'label' => __('Email Address', 'invoicing'), |
|
| 201 | 201 | 'description' => '', |
| 202 | 202 | 'required' => false, |
| 203 | 203 | ) |
@@ -205,14 +205,14 @@ discard block |
||
| 205 | 205 | |
| 206 | 206 | array( |
| 207 | 207 | 'type' => 'address', |
| 208 | - 'name' => __( 'Address', 'invoicing' ), |
|
| 208 | + 'name' => __('Address', 'invoicing'), |
|
| 209 | 209 | 'defaults' => array( |
| 210 | 210 | |
| 211 | 211 | 'fields' => array( |
| 212 | 212 | array( |
| 213 | 213 | 'placeholder' => 'Jon', |
| 214 | 214 | 'value' => '', |
| 215 | - 'label' => __( 'First Name', 'invoicing' ), |
|
| 215 | + 'label' => __('First Name', 'invoicing'), |
|
| 216 | 216 | 'description' => '', |
| 217 | 217 | 'required' => false, |
| 218 | 218 | 'visible' => true, |
@@ -222,7 +222,7 @@ discard block |
||
| 222 | 222 | array( |
| 223 | 223 | 'placeholder' => 'Snow', |
| 224 | 224 | 'value' => '', |
| 225 | - 'label' => __( 'Last Name', 'invoicing' ), |
|
| 225 | + 'label' => __('Last Name', 'invoicing'), |
|
| 226 | 226 | 'description' => '', |
| 227 | 227 | 'required' => false, |
| 228 | 228 | 'visible' => true, |
@@ -232,7 +232,7 @@ discard block |
||
| 232 | 232 | array( |
| 233 | 233 | 'placeholder' => '', |
| 234 | 234 | 'value' => '', |
| 235 | - 'label' => __( 'Address', 'invoicing' ), |
|
| 235 | + 'label' => __('Address', 'invoicing'), |
|
| 236 | 236 | 'description' => '', |
| 237 | 237 | 'required' => false, |
| 238 | 238 | 'visible' => true, |
@@ -242,7 +242,7 @@ discard block |
||
| 242 | 242 | array( |
| 243 | 243 | 'placeholder' => '', |
| 244 | 244 | 'value' => '', |
| 245 | - 'label' => __( 'City', 'invoicing' ), |
|
| 245 | + 'label' => __('City', 'invoicing'), |
|
| 246 | 246 | 'description' => '', |
| 247 | 247 | 'required' => false, |
| 248 | 248 | 'visible' => true, |
@@ -250,9 +250,9 @@ discard block |
||
| 250 | 250 | ), |
| 251 | 251 | |
| 252 | 252 | array( |
| 253 | - 'placeholder' => __( 'Select your country' ), |
|
| 253 | + 'placeholder' => __('Select your country'), |
|
| 254 | 254 | 'value' => '', |
| 255 | - 'label' => __( 'Country', 'invoicing' ), |
|
| 255 | + 'label' => __('Country', 'invoicing'), |
|
| 256 | 256 | 'description' => '', |
| 257 | 257 | 'required' => false, |
| 258 | 258 | 'visible' => true, |
@@ -260,9 +260,9 @@ discard block |
||
| 260 | 260 | ), |
| 261 | 261 | |
| 262 | 262 | array( |
| 263 | - 'placeholder' => __( 'Choose a state', 'invoicing' ), |
|
| 263 | + 'placeholder' => __('Choose a state', 'invoicing'), |
|
| 264 | 264 | 'value' => '', |
| 265 | - 'label' => __( 'State / Province', 'invoicing' ), |
|
| 265 | + 'label' => __('State / Province', 'invoicing'), |
|
| 266 | 266 | 'description' => '', |
| 267 | 267 | 'required' => false, |
| 268 | 268 | 'visible' => true, |
@@ -272,7 +272,7 @@ discard block |
||
| 272 | 272 | array( |
| 273 | 273 | 'placeholder' => '', |
| 274 | 274 | 'value' => '', |
| 275 | - 'label' => __( 'ZIP / Postcode', 'invoicing' ), |
|
| 275 | + 'label' => __('ZIP / Postcode', 'invoicing'), |
|
| 276 | 276 | 'description' => '', |
| 277 | 277 | 'required' => false, |
| 278 | 278 | 'visible' => true, |
@@ -282,7 +282,7 @@ discard block |
||
| 282 | 282 | array( |
| 283 | 283 | 'placeholder' => '', |
| 284 | 284 | 'value' => '', |
| 285 | - 'label' => __( 'Phone', 'invoicing' ), |
|
| 285 | + 'label' => __('Phone', 'invoicing'), |
|
| 286 | 286 | 'description' => '', |
| 287 | 287 | 'required' => false, |
| 288 | 288 | 'visible' => true, |
@@ -292,7 +292,7 @@ discard block |
||
| 292 | 292 | array( |
| 293 | 293 | 'placeholder' => '', |
| 294 | 294 | 'value' => '', |
| 295 | - 'label' => __( 'Company', 'invoicing' ), |
|
| 295 | + 'label' => __('Company', 'invoicing'), |
|
| 296 | 296 | 'description' => '', |
| 297 | 297 | 'required' => false, |
| 298 | 298 | 'visible' => false, |
@@ -302,7 +302,7 @@ discard block |
||
| 302 | 302 | array( |
| 303 | 303 | 'placeholder' => '', |
| 304 | 304 | 'value' => '', |
| 305 | - 'label' => __( 'VAT Number', 'invoicing' ), |
|
| 305 | + 'label' => __('VAT Number', 'invoicing'), |
|
| 306 | 306 | 'description' => '', |
| 307 | 307 | 'required' => false, |
| 308 | 308 | 'visible' => false, |
@@ -314,11 +314,11 @@ discard block |
||
| 314 | 314 | |
| 315 | 315 | array( |
| 316 | 316 | 'type' => 'billing_email', |
| 317 | - 'name' => __( 'Billing Email', 'invoicing' ), |
|
| 317 | + 'name' => __('Billing Email', 'invoicing'), |
|
| 318 | 318 | 'defaults' => array( |
| 319 | 319 | 'placeholder' => '[email protected]', |
| 320 | 320 | 'value' => '', |
| 321 | - 'label' => __( 'Billing Email', 'invoicing' ), |
|
| 321 | + 'label' => __('Billing Email', 'invoicing'), |
|
| 322 | 322 | 'description' => '', |
| 323 | 323 | 'premade' => true, |
| 324 | 324 | ) |
@@ -326,18 +326,18 @@ discard block |
||
| 326 | 326 | |
| 327 | 327 | array( |
| 328 | 328 | 'type' => 'discount', |
| 329 | - 'name' => __( 'Discount Input', 'invoicing' ), |
|
| 329 | + 'name' => __('Discount Input', 'invoicing'), |
|
| 330 | 330 | 'defaults' => array( |
| 331 | 331 | 'value' => '', |
| 332 | - 'input_label' => __( 'Coupon Code', 'invoicing' ), |
|
| 333 | - 'button_label' => __( 'Apply Coupon', 'invoicing' ), |
|
| 334 | - 'description' => __( 'Have a discount code? Enter it above.', 'invoicing' ), |
|
| 332 | + 'input_label' => __('Coupon Code', 'invoicing'), |
|
| 333 | + 'button_label' => __('Apply Coupon', 'invoicing'), |
|
| 334 | + 'description' => __('Have a discount code? Enter it above.', 'invoicing'), |
|
| 335 | 335 | ) |
| 336 | 336 | ), |
| 337 | 337 | |
| 338 | 338 | array( |
| 339 | 339 | 'type' => 'items', |
| 340 | - 'name' => __( 'Items', 'invoicing' ), |
|
| 340 | + 'name' => __('Items', 'invoicing'), |
|
| 341 | 341 | 'defaults' => array( |
| 342 | 342 | 'value' => '', |
| 343 | 343 | 'items_type' => 'total', |
@@ -348,10 +348,10 @@ discard block |
||
| 348 | 348 | |
| 349 | 349 | array( |
| 350 | 350 | 'type' => 'terms', |
| 351 | - 'name' => __( 'Terms', 'invoicing' ), |
|
| 351 | + 'name' => __('Terms', 'invoicing'), |
|
| 352 | 352 | 'defaults' => array( |
| 353 | 353 | 'value' => '', |
| 354 | - 'text' => __( 'I\'ve read and accept the <a href="" target="_blank">terms & conditions</a>', 'invoicing' ), |
|
| 354 | + 'text' => __('I\'ve read and accept the <a href="" target="_blank">terms & conditions</a>', 'invoicing'), |
|
| 355 | 355 | 'description' => '', |
| 356 | 356 | 'required' => true, |
| 357 | 357 | ) |
@@ -359,34 +359,34 @@ discard block |
||
| 359 | 359 | |
| 360 | 360 | array( |
| 361 | 361 | 'type' => 'privacy', |
| 362 | - 'name' => __( 'Privacy', 'invoicing' ), |
|
| 362 | + 'name' => __('Privacy', 'invoicing'), |
|
| 363 | 363 | 'defaults' => array( |
| 364 | 364 | 'value' => '', |
| 365 | - 'text' => __( 'Your personal data will be used to process your invoice, payment and for other purposes described in our privacy policy.', 'invoicing' ), |
|
| 365 | + 'text' => __('Your personal data will be used to process your invoice, payment and for other purposes described in our privacy policy.', 'invoicing'), |
|
| 366 | 366 | ) |
| 367 | 367 | ), |
| 368 | 368 | |
| 369 | 369 | array( |
| 370 | 370 | 'type' => 'pay_button', |
| 371 | - 'name' => __( 'Payment Button', 'invoicing' ), |
|
| 371 | + 'name' => __('Payment Button', 'invoicing'), |
|
| 372 | 372 | 'defaults' => array( |
| 373 | 373 | 'value' => '', |
| 374 | 374 | 'class' => 'btn-primary', |
| 375 | - 'label' => __( 'Pay Now »', 'invoicing' ), |
|
| 376 | - 'description' => __( 'By continuing with our payment, you are agreeing to our privacy policy and terms of service.', 'invoicing' ), |
|
| 375 | + 'label' => __('Pay Now »', 'invoicing'), |
|
| 376 | + 'description' => __('By continuing with our payment, you are agreeing to our privacy policy and terms of service.', 'invoicing'), |
|
| 377 | 377 | 'premade' => true, |
| 378 | 378 | ) |
| 379 | 379 | ) |
| 380 | 380 | ); |
| 381 | 381 | |
| 382 | - $this->elements = apply_filters( 'wpinv_filter_core_payment_form_elements', $this->elements ); |
|
| 382 | + $this->elements = apply_filters('wpinv_filter_core_payment_form_elements', $this->elements); |
|
| 383 | 383 | return $this->elements; |
| 384 | 384 | } |
| 385 | 385 | |
| 386 | 386 | /** |
| 387 | 387 | * Returns the restrict markup. |
| 388 | 388 | */ |
| 389 | - public function get_restrict_markup( $field, $field_type ) { |
|
| 389 | + public function get_restrict_markup($field, $field_type) { |
|
| 390 | 390 | $restrict = "$field.type=='$field_type'"; |
| 391 | 391 | return "v-if=\"$restrict\""; |
| 392 | 392 | } |
@@ -394,15 +394,15 @@ discard block |
||
| 394 | 394 | /** |
| 395 | 395 | * Renders the title element template. |
| 396 | 396 | */ |
| 397 | - public function render_heading_template( $field ) { |
|
| 398 | - $restrict = $this->get_restrict_markup( $field, 'heading' ); |
|
| 397 | + public function render_heading_template($field) { |
|
| 398 | + $restrict = $this->get_restrict_markup($field, 'heading'); |
|
| 399 | 399 | echo "<component :is='$field.level' $restrict v-html='$field.text'></component>"; |
| 400 | 400 | } |
| 401 | 401 | |
| 402 | 402 | /** |
| 403 | 403 | * Renders the title element on the frontend. |
| 404 | 404 | */ |
| 405 | - public function frontend_render_heading_template( $field ) { |
|
| 405 | + public function frontend_render_heading_template($field) { |
|
| 406 | 406 | $tag = $field['level']; |
| 407 | 407 | echo "<$tag>{$field['text']}</$tag>"; |
| 408 | 408 | } |
@@ -410,10 +410,10 @@ discard block |
||
| 410 | 410 | /** |
| 411 | 411 | * Renders the edit title element template. |
| 412 | 412 | */ |
| 413 | - public function edit_heading_template( $field ) { |
|
| 414 | - $restrict = $this->get_restrict_markup( $field, 'heading' ); |
|
| 415 | - $label = __( 'Heading', 'invoicing' ); |
|
| 416 | - $label2 = __( 'Select Heading Level', 'invoicing' ); |
|
| 413 | + public function edit_heading_template($field) { |
|
| 414 | + $restrict = $this->get_restrict_markup($field, 'heading'); |
|
| 415 | + $label = __('Heading', 'invoicing'); |
|
| 416 | + $label2 = __('Select Heading Level', 'invoicing'); |
|
| 417 | 417 | $id = $field . '.id + "_edit"'; |
| 418 | 418 | $id2 = $field . '.id + "_edit2"'; |
| 419 | 419 | |
@@ -445,8 +445,8 @@ discard block |
||
| 445 | 445 | /** |
| 446 | 446 | * Renders a paragraph element template. |
| 447 | 447 | */ |
| 448 | - public function render_paragraph_template( $field ) { |
|
| 449 | - $restrict = $this->get_restrict_markup( $field, 'paragraph' ); |
|
| 448 | + public function render_paragraph_template($field) { |
|
| 449 | + $restrict = $this->get_restrict_markup($field, 'paragraph'); |
|
| 450 | 450 | $label = "$field.text"; |
| 451 | 451 | echo "<p $restrict v-html='$label' style='font-size: 16px;'></p>"; |
| 452 | 452 | } |
@@ -454,8 +454,8 @@ discard block |
||
| 454 | 454 | /** |
| 455 | 455 | * Renders a privacy element template. |
| 456 | 456 | */ |
| 457 | - public function render_privacy_template( $field ) { |
|
| 458 | - $restrict = $this->get_restrict_markup( $field, 'privacy' ); |
|
| 457 | + public function render_privacy_template($field) { |
|
| 458 | + $restrict = $this->get_restrict_markup($field, 'privacy'); |
|
| 459 | 459 | $label = "$field.text"; |
| 460 | 460 | echo "<p $restrict v-html='$label' style='font-size: 16px;'></p>"; |
| 461 | 461 | } |
@@ -463,23 +463,23 @@ discard block |
||
| 463 | 463 | /** |
| 464 | 464 | * Renders the paragraph element on the frontend. |
| 465 | 465 | */ |
| 466 | - public function frontend_render_paragraph_template( $field ) { |
|
| 466 | + public function frontend_render_paragraph_template($field) { |
|
| 467 | 467 | echo "<p>{$field['text']}</p>"; |
| 468 | 468 | } |
| 469 | 469 | |
| 470 | 470 | /** |
| 471 | 471 | * Renders the privacy element on the frontend. |
| 472 | 472 | */ |
| 473 | - public function frontend_render_privacy_template( $field ) { |
|
| 473 | + public function frontend_render_privacy_template($field) { |
|
| 474 | 474 | echo "<p>{$field['text']}</p>"; |
| 475 | 475 | } |
| 476 | 476 | |
| 477 | 477 | /** |
| 478 | 478 | * Renders the edit paragraph element template. |
| 479 | 479 | */ |
| 480 | - public function edit_paragraph_template( $field ) { |
|
| 481 | - $restrict = $this->get_restrict_markup( $field, 'paragraph' ); |
|
| 482 | - $label = __( 'Enter your text', 'invoicing' ); |
|
| 480 | + public function edit_paragraph_template($field) { |
|
| 481 | + $restrict = $this->get_restrict_markup($field, 'paragraph'); |
|
| 482 | + $label = __('Enter your text', 'invoicing'); |
|
| 483 | 483 | $id = $field . '.id + "_edit"'; |
| 484 | 484 | echo " |
| 485 | 485 | <div $restrict> |
@@ -495,9 +495,9 @@ discard block |
||
| 495 | 495 | /** |
| 496 | 496 | * Renders the edit privacy element template. |
| 497 | 497 | */ |
| 498 | - public function edit_privacy_template( $field ) { |
|
| 499 | - $restrict = $this->get_restrict_markup( $field, 'privacy' ); |
|
| 500 | - $label = __( 'Privacy Text', 'invoicing' ); |
|
| 498 | + public function edit_privacy_template($field) { |
|
| 499 | + $restrict = $this->get_restrict_markup($field, 'privacy'); |
|
| 500 | + $label = __('Privacy Text', 'invoicing'); |
|
| 501 | 501 | $id = $field . '.id + "_edit"'; |
| 502 | 502 | echo " |
| 503 | 503 | <div $restrict> |
@@ -513,8 +513,8 @@ discard block |
||
| 513 | 513 | /** |
| 514 | 514 | * Renders the text element template. |
| 515 | 515 | */ |
| 516 | - public function render_text_template( $field ) { |
|
| 517 | - $restrict = $this->get_restrict_markup( $field, 'text' ); |
|
| 516 | + public function render_text_template($field) { |
|
| 517 | + $restrict = $this->get_restrict_markup($field, 'text'); |
|
| 518 | 518 | $label = "$field.label"; |
| 519 | 519 | echo " |
| 520 | 520 | <div $restrict class='wpinv-payment-form-field-preview'> |
@@ -529,23 +529,23 @@ discard block |
||
| 529 | 529 | /** |
| 530 | 530 | * Renders the text element on the frontend. |
| 531 | 531 | */ |
| 532 | - public function frontend_render_text_template( $field ) { |
|
| 532 | + public function frontend_render_text_template($field) { |
|
| 533 | 533 | |
| 534 | 534 | echo "<div class='form-group'>"; |
| 535 | 535 | |
| 536 | 536 | echo aui()->input( |
| 537 | 537 | array( |
| 538 | - 'name' => esc_attr( $field['id'] ), |
|
| 539 | - 'id' => esc_attr( $field['id'] ), |
|
| 540 | - 'placeholder'=> esc_attr( $field['placeholder'] ), |
|
| 538 | + 'name' => esc_attr($field['id']), |
|
| 539 | + 'id' => esc_attr($field['id']), |
|
| 540 | + 'placeholder'=> esc_attr($field['placeholder']), |
|
| 541 | 541 | 'required' => (bool) $field['required'], |
| 542 | - 'label' => wp_kses_post( $field['label'] ), |
|
| 542 | + 'label' => wp_kses_post($field['label']), |
|
| 543 | 543 | 'no_wrap' => true, |
| 544 | 544 | ) |
| 545 | 545 | ); |
| 546 | 546 | |
| 547 | - if ( ! empty( $field['description'] ) ) { |
|
| 548 | - $description = wp_kses_post( $field['description'] ); |
|
| 547 | + if (!empty($field['description'])) { |
|
| 548 | + $description = wp_kses_post($field['description']); |
|
| 549 | 549 | echo "<small class='form-text text-muted'>$description</small>"; |
| 550 | 550 | } |
| 551 | 551 | |
@@ -556,16 +556,16 @@ discard block |
||
| 556 | 556 | /** |
| 557 | 557 | * Renders the edit text element template. |
| 558 | 558 | */ |
| 559 | - public function edit_text_template( $field ) { |
|
| 560 | - $restrict = $this->get_restrict_markup( $field, 'text' ); |
|
| 561 | - $label = __( 'Field Label', 'invoicing' ); |
|
| 559 | + public function edit_text_template($field) { |
|
| 560 | + $restrict = $this->get_restrict_markup($field, 'text'); |
|
| 561 | + $label = __('Field Label', 'invoicing'); |
|
| 562 | 562 | $id = $field . '.id + "_edit"'; |
| 563 | - $label2 = __( 'Placeholder text', 'invoicing' ); |
|
| 563 | + $label2 = __('Placeholder text', 'invoicing'); |
|
| 564 | 564 | $id2 = $field . '.id + "_edit2"'; |
| 565 | - $label3 = __( 'Help text', 'invoicing' ); |
|
| 566 | - $label4 = esc_attr__( 'Add some help text for this field', 'invoicing' ); |
|
| 565 | + $label3 = __('Help text', 'invoicing'); |
|
| 566 | + $label4 = esc_attr__('Add some help text for this field', 'invoicing'); |
|
| 567 | 567 | $id3 = $field . '.id + "_edit3"'; |
| 568 | - $label5 = __( 'Is this field required?', 'invoicing' ); |
|
| 568 | + $label5 = __('Is this field required?', 'invoicing'); |
|
| 569 | 569 | $id4 = $field . '.id + "_edit4"'; |
| 570 | 570 | echo " |
| 571 | 571 | <div $restrict> |
@@ -593,8 +593,8 @@ discard block |
||
| 593 | 593 | /** |
| 594 | 594 | * Renders the textarea element template. |
| 595 | 595 | */ |
| 596 | - public function render_textarea_template( $field ) { |
|
| 597 | - $restrict = $this->get_restrict_markup( $field, 'textarea' ); |
|
| 596 | + public function render_textarea_template($field) { |
|
| 597 | + $restrict = $this->get_restrict_markup($field, 'textarea'); |
|
| 598 | 598 | $label = "$field.label"; |
| 599 | 599 | echo " |
| 600 | 600 | <div $restrict class='wpinv-payment-form-field-preview'> |
@@ -609,24 +609,24 @@ discard block |
||
| 609 | 609 | /** |
| 610 | 610 | * Renders the textarea element on the frontend. |
| 611 | 611 | */ |
| 612 | - public function frontend_render_textarea_template( $field ) { |
|
| 612 | + public function frontend_render_textarea_template($field) { |
|
| 613 | 613 | |
| 614 | 614 | echo "<div class='form-group'>"; |
| 615 | 615 | |
| 616 | 616 | echo aui()->textarea( |
| 617 | 617 | array( |
| 618 | - 'name' => esc_attr( $field['id'] ), |
|
| 619 | - 'id' => esc_attr( $field['id'] ), |
|
| 620 | - 'placeholder'=> esc_attr( $field['placeholder'] ), |
|
| 618 | + 'name' => esc_attr($field['id']), |
|
| 619 | + 'id' => esc_attr($field['id']), |
|
| 620 | + 'placeholder'=> esc_attr($field['placeholder']), |
|
| 621 | 621 | 'required' => (bool) $field['required'], |
| 622 | - 'label' => wp_kses_post( $field['label'] ), |
|
| 622 | + 'label' => wp_kses_post($field['label']), |
|
| 623 | 623 | 'no_wrap' => true, |
| 624 | 624 | 'rows' => 3, |
| 625 | 625 | ) |
| 626 | 626 | ); |
| 627 | 627 | |
| 628 | - if ( ! empty( $field['description'] ) ) { |
|
| 629 | - $description = wp_kses_post( $field['description'] ); |
|
| 628 | + if (!empty($field['description'])) { |
|
| 629 | + $description = wp_kses_post($field['description']); |
|
| 630 | 630 | echo "<small class='form-text text-muted'>$description</small>"; |
| 631 | 631 | } |
| 632 | 632 | |
@@ -637,16 +637,16 @@ discard block |
||
| 637 | 637 | /** |
| 638 | 638 | * Renders the edit textarea element template. |
| 639 | 639 | */ |
| 640 | - public function edit_textarea_template( $field ) { |
|
| 641 | - $restrict = $this->get_restrict_markup( $field, 'textarea' ); |
|
| 642 | - $label = __( 'Field Label', 'invoicing' ); |
|
| 640 | + public function edit_textarea_template($field) { |
|
| 641 | + $restrict = $this->get_restrict_markup($field, 'textarea'); |
|
| 642 | + $label = __('Field Label', 'invoicing'); |
|
| 643 | 643 | $id = $field . '.id + "_edit"'; |
| 644 | - $label2 = __( 'Placeholder text', 'invoicing' ); |
|
| 644 | + $label2 = __('Placeholder text', 'invoicing'); |
|
| 645 | 645 | $id2 = $field . '.id + "_edit2"'; |
| 646 | - $label3 = __( 'Help text', 'invoicing' ); |
|
| 647 | - $label4 = esc_attr__( 'Add some help text for this field', 'invoicing' ); |
|
| 646 | + $label3 = __('Help text', 'invoicing'); |
|
| 647 | + $label4 = esc_attr__('Add some help text for this field', 'invoicing'); |
|
| 648 | 648 | $id3 = $field . '.id + "_edit3"'; |
| 649 | - $label5 = __( 'Is this field required?', 'invoicing' ); |
|
| 649 | + $label5 = __('Is this field required?', 'invoicing'); |
|
| 650 | 650 | $id4 = $field . '.id + "_edit4"'; |
| 651 | 651 | echo " |
| 652 | 652 | <div $restrict> |
@@ -674,8 +674,8 @@ discard block |
||
| 674 | 674 | /** |
| 675 | 675 | * Renders the select element template. |
| 676 | 676 | */ |
| 677 | - public function render_select_template( $field ) { |
|
| 678 | - $restrict = $this->get_restrict_markup( $field, 'select' ); |
|
| 677 | + public function render_select_template($field) { |
|
| 678 | + $restrict = $this->get_restrict_markup($field, 'select'); |
|
| 679 | 679 | $label = "$field.label"; |
| 680 | 680 | $placeholder = "$field.placeholder"; |
| 681 | 681 | $id = $field . '.id'; |
@@ -695,24 +695,24 @@ discard block |
||
| 695 | 695 | /** |
| 696 | 696 | * Renders the select element on the frontend. |
| 697 | 697 | */ |
| 698 | - public function frontend_render_select_template( $field ) { |
|
| 698 | + public function frontend_render_select_template($field) { |
|
| 699 | 699 | |
| 700 | 700 | echo "<div class='form-group'>"; |
| 701 | 701 | |
| 702 | 702 | echo aui()->select( |
| 703 | 703 | array( |
| 704 | - 'name' => esc_attr( $field['id'] ), |
|
| 705 | - 'id' => esc_attr( $field['id'] ), |
|
| 706 | - 'placeholder'=> esc_attr( $field['placeholder'] ), |
|
| 704 | + 'name' => esc_attr($field['id']), |
|
| 705 | + 'id' => esc_attr($field['id']), |
|
| 706 | + 'placeholder'=> esc_attr($field['placeholder']), |
|
| 707 | 707 | 'required' => (bool) $field['required'], |
| 708 | - 'label' => wp_kses_post( $field['label'] ), |
|
| 708 | + 'label' => wp_kses_post($field['label']), |
|
| 709 | 709 | 'no_wrap' => true, |
| 710 | - 'options' => array_combine( $field['options'], $field['options'] ), |
|
| 710 | + 'options' => array_combine($field['options'], $field['options']), |
|
| 711 | 711 | ) |
| 712 | 712 | ); |
| 713 | 713 | |
| 714 | - if ( ! empty( $field['description'] ) ) { |
|
| 715 | - $description = wp_kses_post( $field['description'] ); |
|
| 714 | + if (!empty($field['description'])) { |
|
| 715 | + $description = wp_kses_post($field['description']); |
|
| 716 | 716 | echo "<small class='form-text text-muted'>$description</small>"; |
| 717 | 717 | } |
| 718 | 718 | |
@@ -723,18 +723,18 @@ discard block |
||
| 723 | 723 | /** |
| 724 | 724 | * Renders the edit select element template. |
| 725 | 725 | */ |
| 726 | - public function edit_select_template( $field ) { |
|
| 727 | - $restrict = $this->get_restrict_markup( $field, 'select' ); |
|
| 728 | - $label = __( 'Field Label', 'invoicing' ); |
|
| 726 | + public function edit_select_template($field) { |
|
| 727 | + $restrict = $this->get_restrict_markup($field, 'select'); |
|
| 728 | + $label = __('Field Label', 'invoicing'); |
|
| 729 | 729 | $id = $field . '.id + "_edit"'; |
| 730 | - $label2 = __( 'Placeholder text', 'invoicing' ); |
|
| 730 | + $label2 = __('Placeholder text', 'invoicing'); |
|
| 731 | 731 | $id2 = $field . '.id + "_edit2"'; |
| 732 | - $label3 = __( 'Help text', 'invoicing' ); |
|
| 733 | - $label4 = esc_attr__( 'Add some help text for this field', 'invoicing' ); |
|
| 732 | + $label3 = __('Help text', 'invoicing'); |
|
| 733 | + $label4 = esc_attr__('Add some help text for this field', 'invoicing'); |
|
| 734 | 734 | $id3 = $field . '.id + "_edit3"'; |
| 735 | - $label5 = __( 'Is this field required?', 'invoicing' ); |
|
| 735 | + $label5 = __('Is this field required?', 'invoicing'); |
|
| 736 | 736 | $id4 = $field . '.id + "_edit4"'; |
| 737 | - $label6 = __( 'Available Options', 'invoicing' ); |
|
| 737 | + $label6 = __('Available Options', 'invoicing'); |
|
| 738 | 738 | echo " |
| 739 | 739 | <div $restrict> |
| 740 | 740 | <div class='form-group'> |
@@ -772,8 +772,8 @@ discard block |
||
| 772 | 772 | /** |
| 773 | 773 | * Renders the checkbox element template. |
| 774 | 774 | */ |
| 775 | - public function render_checkbox_template( $field ) { |
|
| 776 | - $restrict = $this->get_restrict_markup( $field, 'checkbox' ); |
|
| 775 | + public function render_checkbox_template($field) { |
|
| 776 | + $restrict = $this->get_restrict_markup($field, 'checkbox'); |
|
| 777 | 777 | echo " |
| 778 | 778 | <div class='form-check' $restrict> |
| 779 | 779 | <div class='wpinv-payment-form-field-preview-overlay'></div> |
@@ -787,8 +787,8 @@ discard block |
||
| 787 | 787 | /** |
| 788 | 788 | * Renders the terms element template. |
| 789 | 789 | */ |
| 790 | - public function render_terms_template( $field ) { |
|
| 791 | - $restrict = $this->get_restrict_markup( $field, 'terms' ); |
|
| 790 | + public function render_terms_template($field) { |
|
| 791 | + $restrict = $this->get_restrict_markup($field, 'terms'); |
|
| 792 | 792 | echo " |
| 793 | 793 | <div class='form-check' $restrict> |
| 794 | 794 | <div class='wpinv-payment-form-field-preview-overlay'></div> |
@@ -802,24 +802,24 @@ discard block |
||
| 802 | 802 | /** |
| 803 | 803 | * Renders the checkbox element on the frontend. |
| 804 | 804 | */ |
| 805 | - public function frontend_render_checkbox_template( $field ) { |
|
| 805 | + public function frontend_render_checkbox_template($field) { |
|
| 806 | 806 | |
| 807 | 807 | echo "<div class='form-group'>"; |
| 808 | 808 | |
| 809 | 809 | echo aui()->input( |
| 810 | 810 | array( |
| 811 | - 'name' => esc_attr( $field['id'] ), |
|
| 812 | - 'id' => esc_attr( $field['id'] ), |
|
| 811 | + 'name' => esc_attr($field['id']), |
|
| 812 | + 'id' => esc_attr($field['id']), |
|
| 813 | 813 | 'required' => (bool) $field['required'], |
| 814 | - 'label' => wp_kses_post( $field['label'] ), |
|
| 814 | + 'label' => wp_kses_post($field['label']), |
|
| 815 | 815 | 'no_wrap' => true, |
| 816 | - 'value' => esc_attr__( 'Yes', 'invoicing' ), |
|
| 816 | + 'value' => esc_attr__('Yes', 'invoicing'), |
|
| 817 | 817 | 'type' => 'checkbox', |
| 818 | 818 | ) |
| 819 | 819 | ); |
| 820 | 820 | |
| 821 | - if ( ! empty( $field['description'] ) ) { |
|
| 822 | - $description = wp_kses_post( $field['description'] ); |
|
| 821 | + if (!empty($field['description'])) { |
|
| 822 | + $description = wp_kses_post($field['description']); |
|
| 823 | 823 | echo "<small class='form-text text-muted'>$description</small>"; |
| 824 | 824 | } |
| 825 | 825 | |
@@ -830,24 +830,24 @@ discard block |
||
| 830 | 830 | /** |
| 831 | 831 | * Renders the terms element on the frontend. |
| 832 | 832 | */ |
| 833 | - public function frontend_render_terms_template( $field ) { |
|
| 833 | + public function frontend_render_terms_template($field) { |
|
| 834 | 834 | |
| 835 | 835 | echo "<div class='form-group'>"; |
| 836 | 836 | |
| 837 | 837 | echo aui()->input( |
| 838 | 838 | array( |
| 839 | - 'name' => esc_attr( $field['id'] ), |
|
| 840 | - 'id' => esc_attr( $field['id'] ), |
|
| 839 | + 'name' => esc_attr($field['id']), |
|
| 840 | + 'id' => esc_attr($field['id']), |
|
| 841 | 841 | 'required' => (bool) $field['required'], |
| 842 | - 'label' => wp_kses_post( $field['text'] ), |
|
| 842 | + 'label' => wp_kses_post($field['text']), |
|
| 843 | 843 | 'no_wrap' => true, |
| 844 | - 'value' => esc_attr__( 'Yes', 'invoicing' ), |
|
| 844 | + 'value' => esc_attr__('Yes', 'invoicing'), |
|
| 845 | 845 | 'type' => 'checkbox', |
| 846 | 846 | ) |
| 847 | 847 | ); |
| 848 | 848 | |
| 849 | - if ( ! empty( $field['description'] ) ) { |
|
| 850 | - $description = wp_kses_post( $field['description'] ); |
|
| 849 | + if (!empty($field['description'])) { |
|
| 850 | + $description = wp_kses_post($field['description']); |
|
| 851 | 851 | echo "<small class='form-text text-muted'>$description</small>"; |
| 852 | 852 | } |
| 853 | 853 | |
@@ -858,14 +858,14 @@ discard block |
||
| 858 | 858 | /** |
| 859 | 859 | * Renders the edit checkbox element template. |
| 860 | 860 | */ |
| 861 | - public function edit_checkbox_template( $field ) { |
|
| 862 | - $restrict = $this->get_restrict_markup( $field, 'checkbox' ); |
|
| 863 | - $label = __( 'Field Label', 'invoicing' ); |
|
| 861 | + public function edit_checkbox_template($field) { |
|
| 862 | + $restrict = $this->get_restrict_markup($field, 'checkbox'); |
|
| 863 | + $label = __('Field Label', 'invoicing'); |
|
| 864 | 864 | $id = $field . '.id + "_edit"'; |
| 865 | - $label2 = __( 'Help text', 'invoicing' ); |
|
| 866 | - $label3 = esc_attr__( 'Add some help text for this field', 'invoicing' ); |
|
| 865 | + $label2 = __('Help text', 'invoicing'); |
|
| 866 | + $label3 = esc_attr__('Add some help text for this field', 'invoicing'); |
|
| 867 | 867 | $id2 = $field . '.id + "_edit2"'; |
| 868 | - $label4 = __( 'Is this field required?', 'invoicing' ); |
|
| 868 | + $label4 = __('Is this field required?', 'invoicing'); |
|
| 869 | 869 | $id3 = $field . '.id + "_edit3"'; |
| 870 | 870 | echo " |
| 871 | 871 | <div $restrict> |
@@ -889,14 +889,14 @@ discard block |
||
| 889 | 889 | /** |
| 890 | 890 | * Renders the edit terms element template. |
| 891 | 891 | */ |
| 892 | - public function edit_terms_template( $field ) { |
|
| 893 | - $restrict = $this->get_restrict_markup( $field, 'terms' ); |
|
| 894 | - $label = __( 'Field Label', 'invoicing' ); |
|
| 892 | + public function edit_terms_template($field) { |
|
| 893 | + $restrict = $this->get_restrict_markup($field, 'terms'); |
|
| 894 | + $label = __('Field Label', 'invoicing'); |
|
| 895 | 895 | $id = $field . '.id + "_edit"'; |
| 896 | - $label2 = __( 'Help text', 'invoicing' ); |
|
| 897 | - $label3 = esc_attr__( 'Add some help text for this field', 'invoicing' ); |
|
| 896 | + $label2 = __('Help text', 'invoicing'); |
|
| 897 | + $label3 = esc_attr__('Add some help text for this field', 'invoicing'); |
|
| 898 | 898 | $id2 = $field . '.id + "_edit2"'; |
| 899 | - $label4 = __( 'Is this field required?', 'invoicing' ); |
|
| 899 | + $label4 = __('Is this field required?', 'invoicing'); |
|
| 900 | 900 | $id3 = $field . '.id + "_edit3"'; |
| 901 | 901 | echo " |
| 902 | 902 | <div $restrict> |
@@ -920,8 +920,8 @@ discard block |
||
| 920 | 920 | /** |
| 921 | 921 | * Renders the radio element template. |
| 922 | 922 | */ |
| 923 | - public function render_radio_template( $field ) { |
|
| 924 | - $restrict = $this->get_restrict_markup( $field, 'radio' ); |
|
| 923 | + public function render_radio_template($field) { |
|
| 924 | + $restrict = $this->get_restrict_markup($field, 'radio'); |
|
| 925 | 925 | $label = "$field.label"; |
| 926 | 926 | $id = $field . '.id'; |
| 927 | 927 | echo " |
@@ -940,20 +940,20 @@ discard block |
||
| 940 | 940 | /** |
| 941 | 941 | * Renders the radio element on the frontend. |
| 942 | 942 | */ |
| 943 | - public function frontend_render_radio_template( $field ) { |
|
| 943 | + public function frontend_render_radio_template($field) { |
|
| 944 | 944 | |
| 945 | 945 | echo "<div class='form-group'>"; |
| 946 | 946 | |
| 947 | - if ( ! empty( $field['label'] ) ) { |
|
| 948 | - $label = wp_kses_post( $field['label'] ); |
|
| 947 | + if (!empty($field['label'])) { |
|
| 948 | + $label = wp_kses_post($field['label']); |
|
| 949 | 949 | echo "<legend class='col-form-label'>$label</legend>"; |
| 950 | 950 | } |
| 951 | 951 | |
| 952 | - foreach( $field['options'] as $index => $option ) { |
|
| 952 | + foreach ($field['options'] as $index => $option) { |
|
| 953 | 953 | $id = $field['id'] . $index; |
| 954 | 954 | $name = $field['id']; |
| 955 | - $value = esc_attr( $option ); |
|
| 956 | - $label = wp_kses_post( $option ); |
|
| 955 | + $value = esc_attr($option); |
|
| 956 | + $label = wp_kses_post($option); |
|
| 957 | 957 | |
| 958 | 958 | echo " |
| 959 | 959 | <div class='form-check'> |
@@ -963,8 +963,8 @@ discard block |
||
| 963 | 963 | "; |
| 964 | 964 | } |
| 965 | 965 | |
| 966 | - if ( ! empty( $field['description'] ) ) { |
|
| 967 | - $description = wp_kses_post( $field['description'] ); |
|
| 966 | + if (!empty($field['description'])) { |
|
| 967 | + $description = wp_kses_post($field['description']); |
|
| 968 | 968 | echo "<small class='form-text text-muted'>$description</small>"; |
| 969 | 969 | } |
| 970 | 970 | |
@@ -975,16 +975,16 @@ discard block |
||
| 975 | 975 | /** |
| 976 | 976 | * Renders the edit radio element template. |
| 977 | 977 | */ |
| 978 | - public function edit_radio_template( $field ) { |
|
| 979 | - $restrict = $this->get_restrict_markup( $field, 'radio' ); |
|
| 980 | - $label = __( 'Field Label', 'invoicing' ); |
|
| 978 | + public function edit_radio_template($field) { |
|
| 979 | + $restrict = $this->get_restrict_markup($field, 'radio'); |
|
| 980 | + $label = __('Field Label', 'invoicing'); |
|
| 981 | 981 | $id = $field . '.id + "_edit"'; |
| 982 | - $label2 = __( 'Help text', 'invoicing' ); |
|
| 983 | - $label3 = esc_attr__( 'Add some help text for this field', 'invoicing' ); |
|
| 982 | + $label2 = __('Help text', 'invoicing'); |
|
| 983 | + $label3 = esc_attr__('Add some help text for this field', 'invoicing'); |
|
| 984 | 984 | $id2 = $field . '.id + "_edit3"'; |
| 985 | - $label4 = __( 'Is this field required?', 'invoicing' ); |
|
| 985 | + $label4 = __('Is this field required?', 'invoicing'); |
|
| 986 | 986 | $id3 = $field . '.id + "_edit4"'; |
| 987 | - $label5 = __( 'Available Options', 'invoicing' ); |
|
| 987 | + $label5 = __('Available Options', 'invoicing'); |
|
| 988 | 988 | echo " |
| 989 | 989 | <div $restrict> |
| 990 | 990 | <div class='form-group'> |
@@ -1018,8 +1018,8 @@ discard block |
||
| 1018 | 1018 | /** |
| 1019 | 1019 | * Renders the address element template. |
| 1020 | 1020 | */ |
| 1021 | - public function render_address_template( $field ) { |
|
| 1022 | - $restrict = $this->get_restrict_markup( $field, 'address' ); |
|
| 1021 | + public function render_address_template($field) { |
|
| 1022 | + $restrict = $this->get_restrict_markup($field, 'address'); |
|
| 1023 | 1023 | |
| 1024 | 1024 | echo " |
| 1025 | 1025 | <div class='wpinv-address-wrapper' $restrict> |
@@ -1041,75 +1041,75 @@ discard block |
||
| 1041 | 1041 | /** |
| 1042 | 1042 | * Renders the address element on the frontend. |
| 1043 | 1043 | */ |
| 1044 | - public function frontend_render_address_template( $field ) { |
|
| 1044 | + public function frontend_render_address_template($field) { |
|
| 1045 | 1045 | |
| 1046 | 1046 | echo "<div class='wpinv-address-fields'>"; |
| 1047 | 1047 | |
| 1048 | 1048 | $country = ''; |
| 1049 | - if ( is_user_logged_in() ) { |
|
| 1050 | - $user = wp_get_current_user(); |
|
| 1051 | - $country = sanitize_text_field( get_user_meta( $user->ID, '_wpinv_country', true ) ); |
|
| 1049 | + if (is_user_logged_in()) { |
|
| 1050 | + $user = wp_get_current_user(); |
|
| 1051 | + $country = sanitize_text_field(get_user_meta($user->ID, '_wpinv_country', true)); |
|
| 1052 | 1052 | } |
| 1053 | 1053 | |
| 1054 | - if ( empty( $country ) ) { |
|
| 1054 | + if (empty($country)) { |
|
| 1055 | 1055 | $country = wpinv_get_default_country(); |
| 1056 | 1056 | } |
| 1057 | 1057 | |
| 1058 | - foreach( $field['fields'] as $address_field ) { |
|
| 1058 | + foreach ($field['fields'] as $address_field) { |
|
| 1059 | 1059 | |
| 1060 | - if ( empty( $address_field['visible'] ) ) { |
|
| 1060 | + if (empty($address_field['visible'])) { |
|
| 1061 | 1061 | continue; |
| 1062 | 1062 | } |
| 1063 | 1063 | |
| 1064 | - $class = esc_attr( $address_field['name'] ); |
|
| 1064 | + $class = esc_attr($address_field['name']); |
|
| 1065 | 1065 | echo "<div class='form-group $class'>"; |
| 1066 | 1066 | |
| 1067 | 1067 | $label = $address_field['label']; |
| 1068 | 1068 | |
| 1069 | - if ( ! empty( $address_field['required'] ) ) { |
|
| 1069 | + if (!empty($address_field['required'])) { |
|
| 1070 | 1070 | $label .= "<span class='text-danger'> *</span>"; |
| 1071 | 1071 | } |
| 1072 | 1072 | |
| 1073 | 1073 | // Default value. |
| 1074 | 1074 | $value = ''; |
| 1075 | - if ( is_user_logged_in() ) { |
|
| 1075 | + if (is_user_logged_in()) { |
|
| 1076 | 1076 | $user = wp_get_current_user(); |
| 1077 | - $value = sanitize_text_field( get_user_meta( $user->ID, '_' . $address_field['name'], true ) ); |
|
| 1077 | + $value = sanitize_text_field(get_user_meta($user->ID, '_' . $address_field['name'], true)); |
|
| 1078 | 1078 | } |
| 1079 | 1079 | |
| 1080 | - if ( 'wpinv_country' == $address_field['name'] ) { |
|
| 1080 | + if ('wpinv_country' == $address_field['name']) { |
|
| 1081 | 1081 | |
| 1082 | - echo aui()->select( array( |
|
| 1082 | + echo aui()->select(array( |
|
| 1083 | 1083 | 'options' => wpinv_get_country_list(), |
| 1084 | - 'name' => esc_attr( $address_field['name'] ), |
|
| 1085 | - 'id' => esc_attr( $address_field['name'] ), |
|
| 1084 | + 'name' => esc_attr($address_field['name']), |
|
| 1085 | + 'id' => esc_attr($address_field['name']), |
|
| 1086 | 1086 | 'value' => $country, |
| 1087 | - 'placeholder' => esc_attr( $address_field['placeholder'] ), |
|
| 1087 | + 'placeholder' => esc_attr($address_field['placeholder']), |
|
| 1088 | 1088 | 'required' => (bool) $address_field['required'], |
| 1089 | 1089 | 'no_wrap' => true, |
| 1090 | - 'label' => wp_kses_post( $label ), |
|
| 1090 | + 'label' => wp_kses_post($label), |
|
| 1091 | 1091 | 'select2' => false, |
| 1092 | 1092 | )); |
| 1093 | 1093 | |
| 1094 | - } else if ( 'wpinv_state' == $address_field['name'] ) { |
|
| 1094 | + } else if ('wpinv_state' == $address_field['name']) { |
|
| 1095 | 1095 | |
| 1096 | - $states = wpinv_get_country_states( $country ); |
|
| 1096 | + $states = wpinv_get_country_states($country); |
|
| 1097 | 1097 | |
| 1098 | - if ( empty( $value ) ) { |
|
| 1098 | + if (empty($value)) { |
|
| 1099 | 1099 | $value = wpinv_get_default_state(); |
| 1100 | 1100 | } |
| 1101 | 1101 | |
| 1102 | - if ( ! empty( $states ) ) { |
|
| 1102 | + if (!empty($states)) { |
|
| 1103 | 1103 | |
| 1104 | - echo aui()->select( array( |
|
| 1104 | + echo aui()->select(array( |
|
| 1105 | 1105 | 'options' => $states, |
| 1106 | - 'name' => esc_attr( $address_field['name'] ), |
|
| 1107 | - 'id' => esc_attr( $address_field['name'] ), |
|
| 1106 | + 'name' => esc_attr($address_field['name']), |
|
| 1107 | + 'id' => esc_attr($address_field['name']), |
|
| 1108 | 1108 | 'value' => $value, |
| 1109 | - 'placeholder' => esc_attr( $address_field['placeholder'] ), |
|
| 1109 | + 'placeholder' => esc_attr($address_field['placeholder']), |
|
| 1110 | 1110 | 'required' => (bool) $address_field['required'], |
| 1111 | 1111 | 'no_wrap' => true, |
| 1112 | - 'label' => wp_kses_post( $label ), |
|
| 1112 | + 'label' => wp_kses_post($label), |
|
| 1113 | 1113 | 'select2' => false, |
| 1114 | 1114 | )); |
| 1115 | 1115 | |
@@ -1117,10 +1117,10 @@ discard block |
||
| 1117 | 1117 | |
| 1118 | 1118 | echo aui()->input( |
| 1119 | 1119 | array( |
| 1120 | - 'name' => esc_attr( $address_field['name'] ), |
|
| 1121 | - 'id' => esc_attr( $address_field['name'] ), |
|
| 1120 | + 'name' => esc_attr($address_field['name']), |
|
| 1121 | + 'id' => esc_attr($address_field['name']), |
|
| 1122 | 1122 | 'required' => (bool) $address_field['required'], |
| 1123 | - 'label' => wp_kses_post( $label ), |
|
| 1123 | + 'label' => wp_kses_post($label), |
|
| 1124 | 1124 | 'no_wrap' => true, |
| 1125 | 1125 | 'type' => 'text', |
| 1126 | 1126 | 'value' => $value, |
@@ -1133,12 +1133,12 @@ discard block |
||
| 1133 | 1133 | |
| 1134 | 1134 | echo aui()->input( |
| 1135 | 1135 | array( |
| 1136 | - 'name' => esc_attr( $address_field['name'] ), |
|
| 1137 | - 'id' => esc_attr( $address_field['name'] ), |
|
| 1136 | + 'name' => esc_attr($address_field['name']), |
|
| 1137 | + 'id' => esc_attr($address_field['name']), |
|
| 1138 | 1138 | 'required' => (bool) $address_field['required'], |
| 1139 | - 'label' => wp_kses_post( $label ), |
|
| 1139 | + 'label' => wp_kses_post($label), |
|
| 1140 | 1140 | 'no_wrap' => true, |
| 1141 | - 'placeholder' => esc_attr( $address_field['placeholder'] ), |
|
| 1141 | + 'placeholder' => esc_attr($address_field['placeholder']), |
|
| 1142 | 1142 | 'type' => 'text', |
| 1143 | 1143 | 'value' => $value, |
| 1144 | 1144 | ) |
@@ -1147,8 +1147,8 @@ discard block |
||
| 1147 | 1147 | } |
| 1148 | 1148 | |
| 1149 | 1149 | |
| 1150 | - if ( ! empty( $address_field['description'] ) ) { |
|
| 1151 | - $description = wp_kses_post( $address_field['description'] ); |
|
| 1150 | + if (!empty($address_field['description'])) { |
|
| 1151 | + $description = wp_kses_post($address_field['description']); |
|
| 1152 | 1152 | echo "<small class='form-text text-muted'>$description</small>"; |
| 1153 | 1153 | } |
| 1154 | 1154 | |
@@ -1163,13 +1163,13 @@ discard block |
||
| 1163 | 1163 | /** |
| 1164 | 1164 | * Renders the edit address element template. |
| 1165 | 1165 | */ |
| 1166 | - public function edit_address_template( $field ) { |
|
| 1167 | - $restrict = $this->get_restrict_markup( $field, 'address' ); |
|
| 1168 | - $label = __( 'Field Label', 'invoicing' ); |
|
| 1169 | - $label2 = __( 'Placeholder', 'invoicing' ); |
|
| 1170 | - $label3 = __( 'Description', 'invoicing' ); |
|
| 1171 | - $label4 = __( 'Is required', 'invoicing' ); |
|
| 1172 | - $label5 = __( 'Is visible', 'invoicing' ); |
|
| 1166 | + public function edit_address_template($field) { |
|
| 1167 | + $restrict = $this->get_restrict_markup($field, 'address'); |
|
| 1168 | + $label = __('Field Label', 'invoicing'); |
|
| 1169 | + $label2 = __('Placeholder', 'invoicing'); |
|
| 1170 | + $label3 = __('Description', 'invoicing'); |
|
| 1171 | + $label4 = __('Is required', 'invoicing'); |
|
| 1172 | + $label5 = __('Is visible', 'invoicing'); |
|
| 1173 | 1173 | $id = $field . '.id + "_edit_label"'; |
| 1174 | 1174 | $id2 = $field . '.id + "_edit_placeholder"'; |
| 1175 | 1175 | $id3 = $field . '.id + "_edit_description"'; |
@@ -1237,8 +1237,8 @@ discard block |
||
| 1237 | 1237 | /** |
| 1238 | 1238 | * Renders the email element template. |
| 1239 | 1239 | */ |
| 1240 | - public function render_email_template( $field ) { |
|
| 1241 | - $restrict = $this->get_restrict_markup( $field, 'email' ); |
|
| 1240 | + public function render_email_template($field) { |
|
| 1241 | + $restrict = $this->get_restrict_markup($field, 'email'); |
|
| 1242 | 1242 | $label = "$field.label"; |
| 1243 | 1243 | echo " |
| 1244 | 1244 | <div $restrict class='wpinv-payment-form-field-preview'> |
@@ -1253,8 +1253,8 @@ discard block |
||
| 1253 | 1253 | /** |
| 1254 | 1254 | * Renders the billing_email element template. |
| 1255 | 1255 | */ |
| 1256 | - public function render_billing_email_template( $field ) { |
|
| 1257 | - $restrict = $this->get_restrict_markup( $field, 'billing_email' ); |
|
| 1256 | + public function render_billing_email_template($field) { |
|
| 1257 | + $restrict = $this->get_restrict_markup($field, 'billing_email'); |
|
| 1258 | 1258 | $label = "$field.label"; |
| 1259 | 1259 | echo " |
| 1260 | 1260 | <div $restrict> |
@@ -1268,24 +1268,24 @@ discard block |
||
| 1268 | 1268 | /** |
| 1269 | 1269 | * Renders the email element on the frontend. |
| 1270 | 1270 | */ |
| 1271 | - public function frontend_render_email_template( $field ) { |
|
| 1271 | + public function frontend_render_email_template($field) { |
|
| 1272 | 1272 | |
| 1273 | 1273 | echo "<div class='form-group'>"; |
| 1274 | 1274 | |
| 1275 | 1275 | echo aui()->input( |
| 1276 | 1276 | array( |
| 1277 | - 'name' => esc_attr( $field['id'] ), |
|
| 1278 | - 'id' => esc_attr( $field['id'] ), |
|
| 1277 | + 'name' => esc_attr($field['id']), |
|
| 1278 | + 'id' => esc_attr($field['id']), |
|
| 1279 | 1279 | 'required' => (bool) $field['required'], |
| 1280 | - 'label' => wp_kses_post( $field['label'] ), |
|
| 1280 | + 'label' => wp_kses_post($field['label']), |
|
| 1281 | 1281 | 'no_wrap' => true, |
| 1282 | - 'placeholder' => esc_attr( $field['placeholder'] ), |
|
| 1282 | + 'placeholder' => esc_attr($field['placeholder']), |
|
| 1283 | 1283 | 'type' => 'email', |
| 1284 | 1284 | ) |
| 1285 | 1285 | ); |
| 1286 | 1286 | |
| 1287 | - if ( ! empty( $field['description'] ) ) { |
|
| 1288 | - $description = wp_kses_post( $field['description'] ); |
|
| 1287 | + if (!empty($field['description'])) { |
|
| 1288 | + $description = wp_kses_post($field['description']); |
|
| 1289 | 1289 | echo "<small class='form-text text-muted'>$description</small>"; |
| 1290 | 1290 | } |
| 1291 | 1291 | |
@@ -1296,30 +1296,30 @@ discard block |
||
| 1296 | 1296 | /** |
| 1297 | 1297 | * Renders the billing email element on the frontend. |
| 1298 | 1298 | */ |
| 1299 | - public function frontend_render_billing_email_template( $field ) { |
|
| 1299 | + public function frontend_render_billing_email_template($field) { |
|
| 1300 | 1300 | |
| 1301 | 1301 | echo "<div class='form-group'>"; |
| 1302 | 1302 | $value = ''; |
| 1303 | 1303 | |
| 1304 | - if ( is_user_logged_in() ) { |
|
| 1304 | + if (is_user_logged_in()) { |
|
| 1305 | 1305 | $user = wp_get_current_user(); |
| 1306 | - $value = sanitize_email( $user->user_email ); |
|
| 1306 | + $value = sanitize_email($user->user_email); |
|
| 1307 | 1307 | } |
| 1308 | 1308 | echo aui()->input( |
| 1309 | 1309 | array( |
| 1310 | 1310 | 'name' => 'billing_email', |
| 1311 | 1311 | 'value' => $value, |
| 1312 | - 'id' => esc_attr( $field['id'] ), |
|
| 1312 | + 'id' => esc_attr($field['id']), |
|
| 1313 | 1313 | 'required' => true, |
| 1314 | - 'label' => wp_kses_post( $field['label'] ), |
|
| 1314 | + 'label' => wp_kses_post($field['label']), |
|
| 1315 | 1315 | 'no_wrap' => true, |
| 1316 | - 'placeholder' => esc_attr( $field['placeholder'] ), |
|
| 1316 | + 'placeholder' => esc_attr($field['placeholder']), |
|
| 1317 | 1317 | 'type' => 'email', |
| 1318 | 1318 | ) |
| 1319 | 1319 | ); |
| 1320 | 1320 | |
| 1321 | - if ( ! empty( $field['description'] ) ) { |
|
| 1322 | - $description = wp_kses_post( $field['description'] ); |
|
| 1321 | + if (!empty($field['description'])) { |
|
| 1322 | + $description = wp_kses_post($field['description']); |
|
| 1323 | 1323 | echo "<small class='form-text text-muted'>$description</small>"; |
| 1324 | 1324 | } |
| 1325 | 1325 | |
@@ -1330,16 +1330,16 @@ discard block |
||
| 1330 | 1330 | /** |
| 1331 | 1331 | * Renders the edit email element template. |
| 1332 | 1332 | */ |
| 1333 | - public function edit_email_template( $field ) { |
|
| 1334 | - $restrict = $this->get_restrict_markup( $field, 'email' ); |
|
| 1335 | - $label = __( 'Field Label', 'invoicing' ); |
|
| 1333 | + public function edit_email_template($field) { |
|
| 1334 | + $restrict = $this->get_restrict_markup($field, 'email'); |
|
| 1335 | + $label = __('Field Label', 'invoicing'); |
|
| 1336 | 1336 | $id = $field . '.id + "_edit"'; |
| 1337 | - $label2 = __( 'Placeholder text', 'invoicing' ); |
|
| 1337 | + $label2 = __('Placeholder text', 'invoicing'); |
|
| 1338 | 1338 | $id2 = $field . '.id + "_edit2"'; |
| 1339 | - $label3 = __( 'Help text', 'invoicing' ); |
|
| 1340 | - $label4 = esc_attr__( 'Add some help text for this field', 'invoicing' ); |
|
| 1339 | + $label3 = __('Help text', 'invoicing'); |
|
| 1340 | + $label4 = esc_attr__('Add some help text for this field', 'invoicing'); |
|
| 1341 | 1341 | $id3 = $field . '.id + "_edit3"'; |
| 1342 | - $label5 = __( 'Is this field required?', 'invoicing' ); |
|
| 1342 | + $label5 = __('Is this field required?', 'invoicing'); |
|
| 1343 | 1343 | $id4 = $field . '.id + "_edit4"'; |
| 1344 | 1344 | echo " |
| 1345 | 1345 | <div $restrict> |
@@ -1367,16 +1367,16 @@ discard block |
||
| 1367 | 1367 | /** |
| 1368 | 1368 | * Renders the edit billing_email element template. |
| 1369 | 1369 | */ |
| 1370 | - public function edit_billing_email_template( $field ) { |
|
| 1371 | - $restrict = $this->get_restrict_markup( $field, 'billing_email' ); |
|
| 1372 | - $label = __( 'Field Label', 'invoicing' ); |
|
| 1370 | + public function edit_billing_email_template($field) { |
|
| 1371 | + $restrict = $this->get_restrict_markup($field, 'billing_email'); |
|
| 1372 | + $label = __('Field Label', 'invoicing'); |
|
| 1373 | 1373 | $id = $field . '.id + "_edit"'; |
| 1374 | - $label2 = __( 'Placeholder text', 'invoicing' ); |
|
| 1374 | + $label2 = __('Placeholder text', 'invoicing'); |
|
| 1375 | 1375 | $id2 = $field . '.id + "_edit2"'; |
| 1376 | - $label3 = __( 'Help text', 'invoicing' ); |
|
| 1377 | - $label4 = esc_attr__( 'Add some help text for this field', 'invoicing' ); |
|
| 1376 | + $label3 = __('Help text', 'invoicing'); |
|
| 1377 | + $label4 = esc_attr__('Add some help text for this field', 'invoicing'); |
|
| 1378 | 1378 | $id3 = $field . '.id + "_edit3"'; |
| 1379 | - $label5 = __( 'Is this field required?', 'invoicing' ); |
|
| 1379 | + $label5 = __('Is this field required?', 'invoicing'); |
|
| 1380 | 1380 | $id4 = $field . '.id + "_edit4"'; |
| 1381 | 1381 | echo " |
| 1382 | 1382 | <div $restrict> |
@@ -1400,8 +1400,8 @@ discard block |
||
| 1400 | 1400 | /** |
| 1401 | 1401 | * Renders the website element template. |
| 1402 | 1402 | */ |
| 1403 | - public function render_website_template( $field ) { |
|
| 1404 | - $restrict = $this->get_restrict_markup( $field, 'website' ); |
|
| 1403 | + public function render_website_template($field) { |
|
| 1404 | + $restrict = $this->get_restrict_markup($field, 'website'); |
|
| 1405 | 1405 | $label = "$field.label"; |
| 1406 | 1406 | echo " |
| 1407 | 1407 | <div $restrict class='wpinv-payment-form-field-preview'> |
@@ -1416,24 +1416,24 @@ discard block |
||
| 1416 | 1416 | /** |
| 1417 | 1417 | * Renders the website element on the frontend. |
| 1418 | 1418 | */ |
| 1419 | - public function frontend_render_website_template( $field ) { |
|
| 1419 | + public function frontend_render_website_template($field) { |
|
| 1420 | 1420 | |
| 1421 | 1421 | echo "<div class='form-group'>"; |
| 1422 | 1422 | |
| 1423 | 1423 | echo aui()->input( |
| 1424 | 1424 | array( |
| 1425 | - 'name' => esc_attr( $field['id'] ), |
|
| 1426 | - 'id' => esc_attr( $field['id'] ), |
|
| 1425 | + 'name' => esc_attr($field['id']), |
|
| 1426 | + 'id' => esc_attr($field['id']), |
|
| 1427 | 1427 | 'required' => (bool) $field['required'], |
| 1428 | - 'label' => wp_kses_post( $field['label'] ), |
|
| 1428 | + 'label' => wp_kses_post($field['label']), |
|
| 1429 | 1429 | 'no_wrap' => true, |
| 1430 | - 'placeholder' => esc_attr( $field['placeholder'] ), |
|
| 1430 | + 'placeholder' => esc_attr($field['placeholder']), |
|
| 1431 | 1431 | 'type' => 'url', |
| 1432 | 1432 | ) |
| 1433 | 1433 | ); |
| 1434 | 1434 | |
| 1435 | - if ( ! empty( $field['description'] ) ) { |
|
| 1436 | - $description = wp_kses_post( $field['description'] ); |
|
| 1435 | + if (!empty($field['description'])) { |
|
| 1436 | + $description = wp_kses_post($field['description']); |
|
| 1437 | 1437 | echo "<small class='form-text text-muted'>$description</small>"; |
| 1438 | 1438 | } |
| 1439 | 1439 | |
@@ -1444,16 +1444,16 @@ discard block |
||
| 1444 | 1444 | /** |
| 1445 | 1445 | * Renders the edit website element template. |
| 1446 | 1446 | */ |
| 1447 | - public function edit_website_template( $field ) { |
|
| 1448 | - $restrict = $this->get_restrict_markup( $field, 'website' ); |
|
| 1449 | - $label = __( 'Field Label', 'invoicing' ); |
|
| 1447 | + public function edit_website_template($field) { |
|
| 1448 | + $restrict = $this->get_restrict_markup($field, 'website'); |
|
| 1449 | + $label = __('Field Label', 'invoicing'); |
|
| 1450 | 1450 | $id = $field . '.id + "_edit"'; |
| 1451 | - $label2 = __( 'Placeholder text', 'invoicing' ); |
|
| 1451 | + $label2 = __('Placeholder text', 'invoicing'); |
|
| 1452 | 1452 | $id2 = $field . '.id + "_edit2"'; |
| 1453 | - $label3 = __( 'Help text', 'invoicing' ); |
|
| 1454 | - $label4 = esc_attr__( 'Add some help text for this field', 'invoicing' ); |
|
| 1453 | + $label3 = __('Help text', 'invoicing'); |
|
| 1454 | + $label4 = esc_attr__('Add some help text for this field', 'invoicing'); |
|
| 1455 | 1455 | $id3 = $field . '.id + "_edit3"'; |
| 1456 | - $label5 = __( 'Is this field required?', 'invoicing' ); |
|
| 1456 | + $label5 = __('Is this field required?', 'invoicing'); |
|
| 1457 | 1457 | $id4 = $field . '.id + "_edit4"'; |
| 1458 | 1458 | echo " |
| 1459 | 1459 | <div $restrict> |
@@ -1481,8 +1481,8 @@ discard block |
||
| 1481 | 1481 | /** |
| 1482 | 1482 | * Renders the date element template. |
| 1483 | 1483 | */ |
| 1484 | - public function render_date_template( $field ) { |
|
| 1485 | - $restrict = $this->get_restrict_markup( $field, 'date' ); |
|
| 1484 | + public function render_date_template($field) { |
|
| 1485 | + $restrict = $this->get_restrict_markup($field, 'date'); |
|
| 1486 | 1486 | $label = "$field.label"; |
| 1487 | 1487 | echo " |
| 1488 | 1488 | <div $restrict class='wpinv-payment-form-field-preview'> |
@@ -1497,23 +1497,23 @@ discard block |
||
| 1497 | 1497 | /** |
| 1498 | 1498 | * Renders the date element on the frontend. |
| 1499 | 1499 | */ |
| 1500 | - public function frontend_render_date_template( $field ) { |
|
| 1500 | + public function frontend_render_date_template($field) { |
|
| 1501 | 1501 | |
| 1502 | 1502 | echo "<div class='form-group'>"; |
| 1503 | 1503 | |
| 1504 | 1504 | echo aui()->input( |
| 1505 | 1505 | array( |
| 1506 | - 'name' => esc_attr( $field['id'] ), |
|
| 1507 | - 'id' => esc_attr( $field['id'] ), |
|
| 1506 | + 'name' => esc_attr($field['id']), |
|
| 1507 | + 'id' => esc_attr($field['id']), |
|
| 1508 | 1508 | 'required' => (bool) $field['required'], |
| 1509 | - 'label' => wp_kses_post( $field['label'] ), |
|
| 1509 | + 'label' => wp_kses_post($field['label']), |
|
| 1510 | 1510 | 'no_wrap' => true, |
| 1511 | 1511 | 'type' => 'date', |
| 1512 | 1512 | ) |
| 1513 | 1513 | ); |
| 1514 | 1514 | |
| 1515 | - if ( ! empty( $field['description'] ) ) { |
|
| 1516 | - $description = wp_kses_post( $field['description'] ); |
|
| 1515 | + if (!empty($field['description'])) { |
|
| 1516 | + $description = wp_kses_post($field['description']); |
|
| 1517 | 1517 | echo "<small class='form-text text-muted'>$description</small>"; |
| 1518 | 1518 | } |
| 1519 | 1519 | |
@@ -1524,14 +1524,14 @@ discard block |
||
| 1524 | 1524 | /** |
| 1525 | 1525 | * Renders the edit date element template. |
| 1526 | 1526 | */ |
| 1527 | - public function edit_date_template( $field ) { |
|
| 1528 | - $restrict = $this->get_restrict_markup( $field, 'date' ); |
|
| 1529 | - $label = __( 'Field Label', 'invoicing' ); |
|
| 1527 | + public function edit_date_template($field) { |
|
| 1528 | + $restrict = $this->get_restrict_markup($field, 'date'); |
|
| 1529 | + $label = __('Field Label', 'invoicing'); |
|
| 1530 | 1530 | $id = $field . '.id + "_edit"'; |
| 1531 | - $label3 = __( 'Help text', 'invoicing' ); |
|
| 1532 | - $label4 = esc_attr__( 'Add some help text for this field', 'invoicing' ); |
|
| 1531 | + $label3 = __('Help text', 'invoicing'); |
|
| 1532 | + $label4 = esc_attr__('Add some help text for this field', 'invoicing'); |
|
| 1533 | 1533 | $id3 = $field . '.id + "_edit3"'; |
| 1534 | - $label5 = __( 'Is this field required?', 'invoicing' ); |
|
| 1534 | + $label5 = __('Is this field required?', 'invoicing'); |
|
| 1535 | 1535 | $id4 = $field . '.id + "_edit4"'; |
| 1536 | 1536 | echo " |
| 1537 | 1537 | <div $restrict> |
@@ -1555,8 +1555,8 @@ discard block |
||
| 1555 | 1555 | /** |
| 1556 | 1556 | * Renders the time element template. |
| 1557 | 1557 | */ |
| 1558 | - public function render_time_template( $field ) { |
|
| 1559 | - $restrict = $this->get_restrict_markup( $field, 'time' ); |
|
| 1558 | + public function render_time_template($field) { |
|
| 1559 | + $restrict = $this->get_restrict_markup($field, 'time'); |
|
| 1560 | 1560 | $label = "$field.label"; |
| 1561 | 1561 | echo " |
| 1562 | 1562 | <div $restrict class='wpinv-payment-form-field-preview'> |
@@ -1571,23 +1571,23 @@ discard block |
||
| 1571 | 1571 | /** |
| 1572 | 1572 | * Renders the time element on the frontend. |
| 1573 | 1573 | */ |
| 1574 | - public function frontend_render_time_template( $field ) { |
|
| 1574 | + public function frontend_render_time_template($field) { |
|
| 1575 | 1575 | |
| 1576 | 1576 | echo "<div class='form-group'>"; |
| 1577 | 1577 | |
| 1578 | 1578 | echo aui()->input( |
| 1579 | 1579 | array( |
| 1580 | - 'name' => esc_attr( $field['id'] ), |
|
| 1581 | - 'id' => esc_attr( $field['id'] ), |
|
| 1580 | + 'name' => esc_attr($field['id']), |
|
| 1581 | + 'id' => esc_attr($field['id']), |
|
| 1582 | 1582 | 'required' => (bool) $field['required'], |
| 1583 | - 'label' => wp_kses_post( $field['label'] ), |
|
| 1583 | + 'label' => wp_kses_post($field['label']), |
|
| 1584 | 1584 | 'no_wrap' => true, |
| 1585 | 1585 | 'type' => 'time', |
| 1586 | 1586 | ) |
| 1587 | 1587 | ); |
| 1588 | 1588 | |
| 1589 | - if ( ! empty( $field['description'] ) ) { |
|
| 1590 | - $description = wp_kses_post( $field['description'] ); |
|
| 1589 | + if (!empty($field['description'])) { |
|
| 1590 | + $description = wp_kses_post($field['description']); |
|
| 1591 | 1591 | echo "<small class='form-text text-muted'>$description</small>"; |
| 1592 | 1592 | } |
| 1593 | 1593 | |
@@ -1598,14 +1598,14 @@ discard block |
||
| 1598 | 1598 | /** |
| 1599 | 1599 | * Renders the edit time element template. |
| 1600 | 1600 | */ |
| 1601 | - public function edit_time_template( $field ) { |
|
| 1602 | - $restrict = $this->get_restrict_markup( $field, 'time' ); |
|
| 1603 | - $label = __( 'Field Label', 'invoicing' ); |
|
| 1601 | + public function edit_time_template($field) { |
|
| 1602 | + $restrict = $this->get_restrict_markup($field, 'time'); |
|
| 1603 | + $label = __('Field Label', 'invoicing'); |
|
| 1604 | 1604 | $id = $field . '.id + "_edit"'; |
| 1605 | - $label3 = __( 'Help text', 'invoicing' ); |
|
| 1606 | - $label4 = esc_attr__( 'Add some help text for this field', 'invoicing' ); |
|
| 1605 | + $label3 = __('Help text', 'invoicing'); |
|
| 1606 | + $label4 = esc_attr__('Add some help text for this field', 'invoicing'); |
|
| 1607 | 1607 | $id3 = $field . '.id + "_edit3"'; |
| 1608 | - $label5 = __( 'Is this field required?', 'invoicing' ); |
|
| 1608 | + $label5 = __('Is this field required?', 'invoicing'); |
|
| 1609 | 1609 | $id4 = $field . '.id + "_edit4"'; |
| 1610 | 1610 | echo " |
| 1611 | 1611 | <div $restrict> |
@@ -1629,8 +1629,8 @@ discard block |
||
| 1629 | 1629 | /** |
| 1630 | 1630 | * Renders the number element template. |
| 1631 | 1631 | */ |
| 1632 | - public function render_number_template( $field ) { |
|
| 1633 | - $restrict = $this->get_restrict_markup( $field, 'number' ); |
|
| 1632 | + public function render_number_template($field) { |
|
| 1633 | + $restrict = $this->get_restrict_markup($field, 'number'); |
|
| 1634 | 1634 | $label = "$field.label"; |
| 1635 | 1635 | echo " |
| 1636 | 1636 | <div $restrict class='wpinv-payment-form-field-preview'> |
@@ -1645,24 +1645,24 @@ discard block |
||
| 1645 | 1645 | /** |
| 1646 | 1646 | * Renders the number element on the frontend. |
| 1647 | 1647 | */ |
| 1648 | - public function frontend_render_number_template( $field ) { |
|
| 1648 | + public function frontend_render_number_template($field) { |
|
| 1649 | 1649 | |
| 1650 | 1650 | echo "<div class='form-group'>"; |
| 1651 | 1651 | |
| 1652 | 1652 | echo aui()->input( |
| 1653 | 1653 | array( |
| 1654 | - 'name' => esc_attr( $field['id'] ), |
|
| 1655 | - 'id' => esc_attr( $field['id'] ), |
|
| 1654 | + 'name' => esc_attr($field['id']), |
|
| 1655 | + 'id' => esc_attr($field['id']), |
|
| 1656 | 1656 | 'required' => (bool) $field['required'], |
| 1657 | - 'label' => wp_kses_post( $field['label'] ), |
|
| 1658 | - 'placeholder' => esc_attr( $field['placeholder'] ), |
|
| 1657 | + 'label' => wp_kses_post($field['label']), |
|
| 1658 | + 'placeholder' => esc_attr($field['placeholder']), |
|
| 1659 | 1659 | 'no_wrap' => true, |
| 1660 | 1660 | 'type' => 'number', |
| 1661 | 1661 | ) |
| 1662 | 1662 | ); |
| 1663 | 1663 | |
| 1664 | - if ( ! empty( $field['description'] ) ) { |
|
| 1665 | - $description = wp_kses_post( $field['description'] ); |
|
| 1664 | + if (!empty($field['description'])) { |
|
| 1665 | + $description = wp_kses_post($field['description']); |
|
| 1666 | 1666 | echo "<small class='form-text text-muted'>$description</small>"; |
| 1667 | 1667 | } |
| 1668 | 1668 | |
@@ -1673,16 +1673,16 @@ discard block |
||
| 1673 | 1673 | /** |
| 1674 | 1674 | * Renders the edit number element template. |
| 1675 | 1675 | */ |
| 1676 | - public function edit_number_template( $field ) { |
|
| 1677 | - $restrict = $this->get_restrict_markup( $field, 'number' ); |
|
| 1678 | - $label = __( 'Field Label', 'invoicing' ); |
|
| 1676 | + public function edit_number_template($field) { |
|
| 1677 | + $restrict = $this->get_restrict_markup($field, 'number'); |
|
| 1678 | + $label = __('Field Label', 'invoicing'); |
|
| 1679 | 1679 | $id = $field . '.id + "_edit"'; |
| 1680 | - $label2 = __( 'Placeholder text', 'invoicing' ); |
|
| 1680 | + $label2 = __('Placeholder text', 'invoicing'); |
|
| 1681 | 1681 | $id2 = $field . '.id + "_edit2"'; |
| 1682 | - $label3 = __( 'Help text', 'invoicing' ); |
|
| 1683 | - $label4 = esc_attr__( 'Add some help text for this field', 'invoicing' ); |
|
| 1682 | + $label3 = __('Help text', 'invoicing'); |
|
| 1683 | + $label4 = esc_attr__('Add some help text for this field', 'invoicing'); |
|
| 1684 | 1684 | $id3 = $field . '.id + "_edit3"'; |
| 1685 | - $label5 = __( 'Is this field required?', 'invoicing' ); |
|
| 1685 | + $label5 = __('Is this field required?', 'invoicing'); |
|
| 1686 | 1686 | $id4 = $field . '.id + "_edit4"'; |
| 1687 | 1687 | echo " |
| 1688 | 1688 | <div $restrict> |
@@ -1710,23 +1710,23 @@ discard block |
||
| 1710 | 1710 | /** |
| 1711 | 1711 | * Renders the separator element template. |
| 1712 | 1712 | */ |
| 1713 | - public function render_separator_template( $field ) { |
|
| 1714 | - $restrict = $this->get_restrict_markup( $field, 'separator' ); |
|
| 1713 | + public function render_separator_template($field) { |
|
| 1714 | + $restrict = $this->get_restrict_markup($field, 'separator'); |
|
| 1715 | 1715 | echo "<hr class='featurette-divider mt-0 mb-2' $restrict>"; |
| 1716 | 1716 | } |
| 1717 | 1717 | |
| 1718 | 1718 | /** |
| 1719 | 1719 | * Renders the separator element on the frontend. |
| 1720 | 1720 | */ |
| 1721 | - public function frontend_render_separator_template( $field ) { |
|
| 1721 | + public function frontend_render_separator_template($field) { |
|
| 1722 | 1722 | echo '<hr class="featurette-divider mt-0 mb-2" />'; |
| 1723 | 1723 | } |
| 1724 | 1724 | |
| 1725 | 1725 | /** |
| 1726 | 1726 | * Renders the pay button element template. |
| 1727 | 1727 | */ |
| 1728 | - public function render_pay_button_template( $field ) { |
|
| 1729 | - $restrict = $this->get_restrict_markup( $field, 'pay_button' ); |
|
| 1728 | + public function render_pay_button_template($field) { |
|
| 1729 | + $restrict = $this->get_restrict_markup($field, 'pay_button'); |
|
| 1730 | 1730 | $label = "$field.label"; |
| 1731 | 1731 | echo " |
| 1732 | 1732 | <div $restrict> |
@@ -1739,28 +1739,28 @@ discard block |
||
| 1739 | 1739 | /** |
| 1740 | 1740 | * Renders the pay_button element on the frontend. |
| 1741 | 1741 | */ |
| 1742 | - public function frontend_render_pay_button_template( $field ) { |
|
| 1742 | + public function frontend_render_pay_button_template($field) { |
|
| 1743 | 1743 | |
| 1744 | 1744 | echo "<div class='mt-4 mb-4'>"; |
| 1745 | - do_action( 'wpinv_payment_mode_select' ); |
|
| 1745 | + do_action('wpinv_payment_mode_select'); |
|
| 1746 | 1746 | echo "</div>"; |
| 1747 | 1747 | |
| 1748 | 1748 | echo "<div class='form-group'>"; |
| 1749 | 1749 | |
| 1750 | - $class = 'wpinv-payment-form-submit btn btn-block submit-button ' . sanitize_html_class( $field['class'] ); |
|
| 1750 | + $class = 'wpinv-payment-form-submit btn btn-block submit-button ' . sanitize_html_class($field['class']); |
|
| 1751 | 1751 | echo aui()->input( |
| 1752 | 1752 | array( |
| 1753 | - 'name' => esc_attr( $field['id'] ), |
|
| 1754 | - 'id' => esc_attr( $field['id'] ), |
|
| 1755 | - 'value' => esc_attr( $field['label'] ), |
|
| 1753 | + 'name' => esc_attr($field['id']), |
|
| 1754 | + 'id' => esc_attr($field['id']), |
|
| 1755 | + 'value' => esc_attr($field['label']), |
|
| 1756 | 1756 | 'no_wrap' => true, |
| 1757 | 1757 | 'type' => 'submit', |
| 1758 | 1758 | 'class' => $class, |
| 1759 | 1759 | ) |
| 1760 | 1760 | ); |
| 1761 | 1761 | |
| 1762 | - if ( ! empty( $field['description'] ) ) { |
|
| 1763 | - $description = wp_kses_post( $field['description'] ); |
|
| 1762 | + if (!empty($field['description'])) { |
|
| 1763 | + $description = wp_kses_post($field['description']); |
|
| 1764 | 1764 | echo "<small class='form-text text-muted'>$description</small>"; |
| 1765 | 1765 | } |
| 1766 | 1766 | |
@@ -1771,14 +1771,14 @@ discard block |
||
| 1771 | 1771 | /** |
| 1772 | 1772 | * Renders the pay button element template. |
| 1773 | 1773 | */ |
| 1774 | - public function edit_pay_button_template( $field ) { |
|
| 1775 | - $restrict = $this->get_restrict_markup( $field, 'pay_button' ); |
|
| 1776 | - $label = __( 'Button Text', 'invoicing' ); |
|
| 1774 | + public function edit_pay_button_template($field) { |
|
| 1775 | + $restrict = $this->get_restrict_markup($field, 'pay_button'); |
|
| 1776 | + $label = __('Button Text', 'invoicing'); |
|
| 1777 | 1777 | $id = $field . '.id + "_edit"'; |
| 1778 | - $label2 = __( 'Help text', 'invoicing' ); |
|
| 1779 | - $label3 = esc_attr__( 'Add some help text for this field', 'invoicing' ); |
|
| 1778 | + $label2 = __('Help text', 'invoicing'); |
|
| 1779 | + $label3 = esc_attr__('Add some help text for this field', 'invoicing'); |
|
| 1780 | 1780 | $id2 = $field . '.id + "_edit2"'; |
| 1781 | - $label4 = esc_attr__( 'Button Type', 'invoicing' ); |
|
| 1781 | + $label4 = esc_attr__('Button Type', 'invoicing'); |
|
| 1782 | 1782 | $id3 = $field . '.id + "_edit3"'; |
| 1783 | 1783 | echo " |
| 1784 | 1784 | <div $restrict> |
@@ -1794,15 +1794,15 @@ discard block |
||
| 1794 | 1794 | <label :for='$id3'>$label4</label> |
| 1795 | 1795 | |
| 1796 | 1796 | <select class='form-control custom-select' :id='$id3' v-model='$field.class'> |
| 1797 | - <option value='btn-primary'>" . __( 'Primary', 'invoicing' ) ."</option> |
|
| 1798 | - <option value='btn-secondary'>" . __( 'Secondary', 'invoicing' ) ."</option> |
|
| 1799 | - <option value='btn-success'>" . __( 'Success', 'invoicing' ) ."</option> |
|
| 1800 | - <option value='btn-danger'>" . __( 'Danger', 'invoicing' ) ."</option> |
|
| 1801 | - <option value='btn-warning'>" . __( 'Warning', 'invoicing' ) ."</option> |
|
| 1802 | - <option value='btn-info'>" . __( 'Info', 'invoicing' ) ."</option> |
|
| 1803 | - <option value='btn-light'>" . __( 'Light', 'invoicing' ) ."</option> |
|
| 1804 | - <option value='btn-dark'>" . __( 'Dark', 'invoicing' ) ."</option> |
|
| 1805 | - <option value='btn-link'>" . __( 'Link', 'invoicing' ) ."</option> |
|
| 1797 | + <option value='btn-primary'>" . __('Primary', 'invoicing') . "</option> |
|
| 1798 | + <option value='btn-secondary'>" . __('Secondary', 'invoicing') . "</option> |
|
| 1799 | + <option value='btn-success'>" . __('Success', 'invoicing') . "</option> |
|
| 1800 | + <option value='btn-danger'>" . __('Danger', 'invoicing') . "</option> |
|
| 1801 | + <option value='btn-warning'>" . __('Warning', 'invoicing') . "</option> |
|
| 1802 | + <option value='btn-info'>" . __('Info', 'invoicing') . "</option> |
|
| 1803 | + <option value='btn-light'>" . __('Light', 'invoicing') . "</option> |
|
| 1804 | + <option value='btn-dark'>" . __('Dark', 'invoicing') . "</option> |
|
| 1805 | + <option value='btn-link'>" . __('Link', 'invoicing') . "</option> |
|
| 1806 | 1806 | </select> |
| 1807 | 1807 | </div> |
| 1808 | 1808 | </div> |
@@ -1813,8 +1813,8 @@ discard block |
||
| 1813 | 1813 | /** |
| 1814 | 1814 | * Renders the alert element template. |
| 1815 | 1815 | */ |
| 1816 | - public function render_alert_template( $field ) { |
|
| 1817 | - $restrict = $this->get_restrict_markup( $field, 'alert' ); |
|
| 1816 | + public function render_alert_template($field) { |
|
| 1817 | + $restrict = $this->get_restrict_markup($field, 'alert'); |
|
| 1818 | 1818 | $text = "$field.text"; |
| 1819 | 1819 | echo " |
| 1820 | 1820 | <div $restrict class='alert' :class='$field.class' role='alert'> |
@@ -1829,15 +1829,15 @@ discard block |
||
| 1829 | 1829 | /** |
| 1830 | 1830 | * Renders the alert element on the frontend. |
| 1831 | 1831 | */ |
| 1832 | - public function frontend_render_alert_template( $field ) { |
|
| 1832 | + public function frontend_render_alert_template($field) { |
|
| 1833 | 1833 | |
| 1834 | 1834 | echo "<div class='form-group'>"; |
| 1835 | 1835 | |
| 1836 | 1836 | echo aui()->alert( |
| 1837 | 1837 | array( |
| 1838 | - 'content' => wp_kses_post( $field['text'] ), |
|
| 1838 | + 'content' => wp_kses_post($field['text']), |
|
| 1839 | 1839 | 'dismissible' => $field['dismissible'], |
| 1840 | - 'type' => str_replace( 'alert-', '', $field['class'] ), |
|
| 1840 | + 'type' => str_replace('alert-', '', $field['class']), |
|
| 1841 | 1841 | ) |
| 1842 | 1842 | ); |
| 1843 | 1843 | |
@@ -1848,14 +1848,14 @@ discard block |
||
| 1848 | 1848 | /** |
| 1849 | 1849 | * Renders the alert element template. |
| 1850 | 1850 | */ |
| 1851 | - public function edit_alert_template( $field ) { |
|
| 1852 | - $restrict = $this->get_restrict_markup( $field, 'alert' ); |
|
| 1853 | - $label = __( 'Alert Text', 'invoicing' ); |
|
| 1854 | - $label2 = esc_attr__( 'Enter your alert text here', 'invoicing' ); |
|
| 1851 | + public function edit_alert_template($field) { |
|
| 1852 | + $restrict = $this->get_restrict_markup($field, 'alert'); |
|
| 1853 | + $label = __('Alert Text', 'invoicing'); |
|
| 1854 | + $label2 = esc_attr__('Enter your alert text here', 'invoicing'); |
|
| 1855 | 1855 | $id = $field . '.id + "_edit"'; |
| 1856 | - $label3 = __( 'Is Dismissible?', 'invoicing' ); |
|
| 1856 | + $label3 = __('Is Dismissible?', 'invoicing'); |
|
| 1857 | 1857 | $id2 = $field . '.id + "_edit2"'; |
| 1858 | - $label4 = esc_attr__( 'Alert Type', 'invoicing' ); |
|
| 1858 | + $label4 = esc_attr__('Alert Type', 'invoicing'); |
|
| 1859 | 1859 | $id3 = $field . '.id + "_edit3"'; |
| 1860 | 1860 | echo " |
| 1861 | 1861 | <div $restrict> |
@@ -1871,14 +1871,14 @@ discard block |
||
| 1871 | 1871 | <label :for='$id3'>$label4</label> |
| 1872 | 1872 | |
| 1873 | 1873 | <select class='form-control custom-select' :id='$id3' v-model='$field.class'> |
| 1874 | - <option value='alert-primary'>" . __( 'Primary', 'invoicing' ) ."</option> |
|
| 1875 | - <option value='alert-secondary'>" . __( 'Secondary', 'invoicing' ) ."</option> |
|
| 1876 | - <option value='alert-success'>" . __( 'Success', 'invoicing' ) ."</option> |
|
| 1877 | - <option value='alert-danger'>" . __( 'Danger', 'invoicing' ) ."</option> |
|
| 1878 | - <option value='alert-warning'>" . __( 'Warning', 'invoicing' ) ."</option> |
|
| 1879 | - <option value='alert-info'>" . __( 'Info', 'invoicing' ) ."</option> |
|
| 1880 | - <option value='alert-light'>" . __( 'Light', 'invoicing' ) ."</option> |
|
| 1881 | - <option value='alert-dark'>" . __( 'Dark', 'invoicing' ) ."</option> |
|
| 1874 | + <option value='alert-primary'>" . __('Primary', 'invoicing') . "</option> |
|
| 1875 | + <option value='alert-secondary'>" . __('Secondary', 'invoicing') . "</option> |
|
| 1876 | + <option value='alert-success'>" . __('Success', 'invoicing') . "</option> |
|
| 1877 | + <option value='alert-danger'>" . __('Danger', 'invoicing') . "</option> |
|
| 1878 | + <option value='alert-warning'>" . __('Warning', 'invoicing') . "</option> |
|
| 1879 | + <option value='alert-info'>" . __('Info', 'invoicing') . "</option> |
|
| 1880 | + <option value='alert-light'>" . __('Light', 'invoicing') . "</option> |
|
| 1881 | + <option value='alert-dark'>" . __('Dark', 'invoicing') . "</option> |
|
| 1882 | 1882 | </select> |
| 1883 | 1883 | </div> |
| 1884 | 1884 | </div> |
@@ -1889,8 +1889,8 @@ discard block |
||
| 1889 | 1889 | /** |
| 1890 | 1890 | * Renders the discount element template. |
| 1891 | 1891 | */ |
| 1892 | - public function render_discount_template( $field ) { |
|
| 1893 | - $restrict = $this->get_restrict_markup( $field, 'discount' ); |
|
| 1892 | + public function render_discount_template($field) { |
|
| 1893 | + $restrict = $this->get_restrict_markup($field, 'discount'); |
|
| 1894 | 1894 | ?> |
| 1895 | 1895 | |
| 1896 | 1896 | <div <?php echo $restrict; ?> class="discount_field border rounded p-3 wpinv-payment-form-field-preview"> |
@@ -1908,13 +1908,13 @@ discard block |
||
| 1908 | 1908 | /** |
| 1909 | 1909 | * Renders the discount element on the frontend. |
| 1910 | 1910 | */ |
| 1911 | - public function frontend_render_discount_template( $field ) { |
|
| 1911 | + public function frontend_render_discount_template($field) { |
|
| 1912 | 1912 | |
| 1913 | - $placeholder = esc_attr( $field['input_label'] ); |
|
| 1914 | - $label = sanitize_text_field( $field['button_label'] ); |
|
| 1913 | + $placeholder = esc_attr($field['input_label']); |
|
| 1914 | + $label = sanitize_text_field($field['button_label']); |
|
| 1915 | 1915 | $description = ''; |
| 1916 | 1916 | |
| 1917 | - if ( ! empty( $field['description'] ) ) { |
|
| 1917 | + if (!empty($field['description'])) { |
|
| 1918 | 1918 | $description = "<small class='form-text text-muted'>{$field['description']}</small>"; |
| 1919 | 1919 | } |
| 1920 | 1920 | ?> |
@@ -1936,12 +1936,12 @@ discard block |
||
| 1936 | 1936 | /** |
| 1937 | 1937 | * Renders the discount element template. |
| 1938 | 1938 | */ |
| 1939 | - public function edit_discount_template( $field ) { |
|
| 1940 | - $restrict = $this->get_restrict_markup( $field, 'discount' ); |
|
| 1941 | - $label = __( 'Discount Input Placeholder', 'invoicing' ); |
|
| 1942 | - $label2 = __( 'Help Text', 'invoicing' ); |
|
| 1943 | - $label3 = esc_attr__( 'Add some help text for this field', 'invoicing' ); |
|
| 1944 | - $label4 = __( 'Button Text', 'invoicing' ); |
|
| 1939 | + public function edit_discount_template($field) { |
|
| 1940 | + $restrict = $this->get_restrict_markup($field, 'discount'); |
|
| 1941 | + $label = __('Discount Input Placeholder', 'invoicing'); |
|
| 1942 | + $label2 = __('Help Text', 'invoicing'); |
|
| 1943 | + $label3 = esc_attr__('Add some help text for this field', 'invoicing'); |
|
| 1944 | + $label4 = __('Button Text', 'invoicing'); |
|
| 1945 | 1945 | $id = $field . '.id + "_edit"'; |
| 1946 | 1946 | $id2 = $field . '.id + "_edit2"'; |
| 1947 | 1947 | $id3 = $field . '.id + "_edit3"'; |
@@ -1970,12 +1970,12 @@ discard block |
||
| 1970 | 1970 | /** |
| 1971 | 1971 | * Renders the items element template. |
| 1972 | 1972 | */ |
| 1973 | - public function render_items_template( $field ) { |
|
| 1974 | - $restrict = $this->get_restrict_markup( $field, 'items' ); |
|
| 1975 | - $label = __( 'Item totals will appear here. Click to set items.', 'invoicing' ); |
|
| 1976 | - $label2 = __( 'Your form allows customers to buy several recurring items. This is not supported and will lead to unexpected behaviour.', 'invoicing' ); |
|
| 1977 | - $label2 .= ' ' . __( 'To prevent this, limit customers to selecting a single item.', 'invoicing' ); |
|
| 1978 | - $label3 = __( 'Item totals will appear here.', 'invoicing' ); |
|
| 1973 | + public function render_items_template($field) { |
|
| 1974 | + $restrict = $this->get_restrict_markup($field, 'items'); |
|
| 1975 | + $label = __('Item totals will appear here. Click to set items.', 'invoicing'); |
|
| 1976 | + $label2 = __('Your form allows customers to buy several recurring items. This is not supported and will lead to unexpected behaviour.', 'invoicing'); |
|
| 1977 | + $label2 .= ' ' . __('To prevent this, limit customers to selecting a single item.', 'invoicing'); |
|
| 1978 | + $label3 = __('Item totals will appear here.', 'invoicing'); |
|
| 1979 | 1979 | echo " |
| 1980 | 1980 | <div $restrict class='item_totals text-center'> |
| 1981 | 1981 | <div v-if='!is_default'> |
@@ -1992,17 +1992,17 @@ discard block |
||
| 1992 | 1992 | /** |
| 1993 | 1993 | * Renders the items element on the frontend. |
| 1994 | 1994 | */ |
| 1995 | - public function frontend_render_items_template( $field, $items ) { |
|
| 1995 | + public function frontend_render_items_template($field, $items) { |
|
| 1996 | 1996 | |
| 1997 | 1997 | echo "<div class='form-group item_totals'>"; |
| 1998 | 1998 | |
| 1999 | - $id = esc_attr( $field['id'] ); |
|
| 1999 | + $id = esc_attr($field['id']); |
|
| 2000 | 2000 | |
| 2001 | - if ( empty( $field[ 'items_type' ] ) ) { |
|
| 2002 | - $field[ 'items_type' ] = 'total'; |
|
| 2001 | + if (empty($field['items_type'])) { |
|
| 2002 | + $field['items_type'] = 'total'; |
|
| 2003 | 2003 | } |
| 2004 | 2004 | |
| 2005 | - if ( 'total' == $field[ 'items_type' ] ) { |
|
| 2005 | + if ('total' == $field['items_type']) { |
|
| 2006 | 2006 | $total = 0; |
| 2007 | 2007 | $tax = 0; |
| 2008 | 2008 | $sub_total = 0; |
@@ -2011,16 +2011,16 @@ discard block |
||
| 2011 | 2011 | <div class="border item_totals_type_total"> |
| 2012 | 2012 | |
| 2013 | 2013 | <?php |
| 2014 | - foreach( $items as $item ) { |
|
| 2014 | + foreach ($items as $item) { |
|
| 2015 | 2015 | |
| 2016 | - $amount = floatval( $item['price'] ); |
|
| 2016 | + $amount = floatval($item['price']); |
|
| 2017 | 2017 | |
| 2018 | - if ( wpinv_use_taxes() ) { |
|
| 2018 | + if (wpinv_use_taxes()) { |
|
| 2019 | 2019 | |
| 2020 | - $rate = wpinv_get_tax_rate( wpinv_get_default_country(), false, (int) $item['id'] ); |
|
| 2020 | + $rate = wpinv_get_tax_rate(wpinv_get_default_country(), false, (int) $item['id']); |
|
| 2021 | 2021 | |
| 2022 | - if ( wpinv_prices_include_tax() ) { |
|
| 2023 | - $pre_tax = ( $amount - $amount * $rate * 0.01 ); |
|
| 2022 | + if (wpinv_prices_include_tax()) { |
|
| 2023 | + $pre_tax = ($amount - $amount * $rate * 0.01); |
|
| 2024 | 2024 | $item_tax = $amount - $pre_tax; |
| 2025 | 2025 | } else { |
| 2026 | 2026 | $pre_tax = $amount; |
@@ -2032,32 +2032,32 @@ discard block |
||
| 2032 | 2032 | $total = $sub_total + $tax; |
| 2033 | 2033 | |
| 2034 | 2034 | } else { |
| 2035 | - $total = $total + $amount; |
|
| 2035 | + $total = $total + $amount; |
|
| 2036 | 2036 | } |
| 2037 | 2037 | |
| 2038 | 2038 | $class = 'col-8'; |
| 2039 | 2039 | $class2 = ''; |
| 2040 | 2040 | |
| 2041 | - if ( ! empty( $item['allow_quantities'] ) ) { |
|
| 2041 | + if (!empty($item['allow_quantities'])) { |
|
| 2042 | 2042 | $class = 'col-6 pt-2'; |
| 2043 | 2043 | $class2 = 'pt-2'; |
| 2044 | 2044 | } |
| 2045 | 2045 | |
| 2046 | - if ( ! empty( $item['custom_price'] ) ) { |
|
| 2046 | + if (!empty($item['custom_price'])) { |
|
| 2047 | 2047 | $class .= ' pt-2'; |
| 2048 | 2048 | } |
| 2049 | 2049 | |
| 2050 | 2050 | $quantity = 1; |
| 2051 | - if ( ! empty( $item['quantity'] ) ) { |
|
| 2052 | - $quantity = absint( $item['quantity'] ); |
|
| 2051 | + if (!empty($item['quantity'])) { |
|
| 2052 | + $quantity = absint($item['quantity']); |
|
| 2053 | 2053 | } |
| 2054 | 2054 | |
| 2055 | 2055 | ?> |
| 2056 | 2056 | <div class="item_totals_item"> |
| 2057 | 2057 | <div class='row pl-2 pr-2 pt-2'> |
| 2058 | - <div class='<?php echo $class; ?>'><?php echo sanitize_text_field( $item['title'] ) ?></div> |
|
| 2058 | + <div class='<?php echo $class; ?>'><?php echo sanitize_text_field($item['title']) ?></div> |
|
| 2059 | 2059 | |
| 2060 | - <?php if ( ! empty( $item['allow_quantities'] ) ) { ?> |
|
| 2060 | + <?php if (!empty($item['allow_quantities'])) { ?> |
|
| 2061 | 2061 | |
| 2062 | 2062 | <div class='col-2'> |
| 2063 | 2063 | <input name='wpinv-item-<?php echo (int) $item['id']; ?>-quantity' type='number' class='form-control wpinv-item-quantity-input pr-1' value='<?php echo $quantity ?>' min='1' required> |
@@ -2065,11 +2065,11 @@ discard block |
||
| 2065 | 2065 | |
| 2066 | 2066 | <?php } else { ?> |
| 2067 | 2067 | <input type='hidden' class='wpinv-item-quantity-input' value='<?php echo $quantity ?>'> |
| 2068 | - <?php } if ( empty( $item['custom_price'] ) ) { ?> |
|
| 2068 | + <?php } if (empty($item['custom_price'])) { ?> |
|
| 2069 | 2069 | |
| 2070 | 2070 | <div class='col-4 <?php echo $class2; ?>'> |
| 2071 | - <?php echo wpinv_price( wpinv_format_amount( $item['price'] ) ) ?> |
|
| 2072 | - <input name='wpinv-items[<?php echo (int) $item['id']; ?>]' type='hidden' class='wpinv-item-price-input' value='<?php echo floatval( $item['price'] ); ?>'> |
|
| 2071 | + <?php echo wpinv_price(wpinv_format_amount($item['price'])) ?> |
|
| 2072 | + <input name='wpinv-items[<?php echo (int) $item['id']; ?>]' type='hidden' class='wpinv-item-price-input' value='<?php echo floatval($item['price']); ?>'> |
|
| 2073 | 2073 | </div> |
| 2074 | 2074 | |
| 2075 | 2075 | <?php } else {?> |
@@ -2077,15 +2077,15 @@ discard block |
||
| 2077 | 2077 | <div class='col-4'> |
| 2078 | 2078 | <div class='input-group'> |
| 2079 | 2079 | |
| 2080 | - <?php if ( 'left' == wpinv_currency_position() ) { ?> |
|
| 2080 | + <?php if ('left' == wpinv_currency_position()) { ?> |
|
| 2081 | 2081 | <div class='input-group-prepend'> |
| 2082 | 2082 | <span class='input-group-text'><?php echo wpinv_currency_symbol(); ?></span> |
| 2083 | 2083 | </div> |
| 2084 | 2084 | <?php } ?> |
| 2085 | 2085 | |
| 2086 | - <input type='text' name='wpinv-items[<?php echo (int) $item['id']; ?>]' class='form-control wpinv-item-price-input' placeholder='<?php echo floatval( $item['price'] ); ?>' value='<?php echo floatval( $item['price'] ); ?>' min='<?php echo intval( $item['minimum_price'] ); ?>'> |
|
| 2086 | + <input type='text' name='wpinv-items[<?php echo (int) $item['id']; ?>]' class='form-control wpinv-item-price-input' placeholder='<?php echo floatval($item['price']); ?>' value='<?php echo floatval($item['price']); ?>' min='<?php echo intval($item['minimum_price']); ?>'> |
|
| 2087 | 2087 | |
| 2088 | - <?php if ( 'left' != wpinv_currency_position() ) { ?> |
|
| 2088 | + <?php if ('left' != wpinv_currency_position()) { ?> |
|
| 2089 | 2089 | <div class='input-group-append'> |
| 2090 | 2090 | <span class='input-group-text'><?php echo wpinv_currency_symbol(); ?></span> |
| 2091 | 2091 | </div> |
@@ -2096,8 +2096,8 @@ discard block |
||
| 2096 | 2096 | <?php } ?> |
| 2097 | 2097 | |
| 2098 | 2098 | </div> |
| 2099 | - <?php if ( ! empty( $item['description'] )) { ?> |
|
| 2100 | - <small class='form-text text-muted pl-2 pr-2 m-0'><?php echo wp_kses_post( $item['description'] ); ?></small> |
|
| 2099 | + <?php if (!empty($item['description'])) { ?> |
|
| 2100 | + <small class='form-text text-muted pl-2 pr-2 m-0'><?php echo wp_kses_post($item['description']); ?></small> |
|
| 2101 | 2101 | <?php } ?> |
| 2102 | 2102 | </div> |
| 2103 | 2103 | <?php } ?> |
@@ -2105,25 +2105,25 @@ discard block |
||
| 2105 | 2105 | <div class='mt-4 border-top item_totals_total p-2'> |
| 2106 | 2106 | |
| 2107 | 2107 | <div class='row'> |
| 2108 | - <div class='col-8'><strong class='mr-5'><?php _e( 'Sub Total', 'invoicing' ); ?></strong></div> |
|
| 2109 | - <div class='col-4'><strong class='wpinv-items-sub-total'><?php echo wpinv_price( wpinv_format_amount( $sub_total ) ) ?></strong></div> |
|
| 2108 | + <div class='col-8'><strong class='mr-5'><?php _e('Sub Total', 'invoicing'); ?></strong></div> |
|
| 2109 | + <div class='col-4'><strong class='wpinv-items-sub-total'><?php echo wpinv_price(wpinv_format_amount($sub_total)) ?></strong></div> |
|
| 2110 | 2110 | </div> |
| 2111 | 2111 | |
| 2112 | 2112 | <div class='row' style='display: none;'> |
| 2113 | - <div class='col-8'><strong class='mr-5'><?php _e( 'Discount', 'invoicing' ); ?></strong></div> |
|
| 2114 | - <div class='col-4'><strong class='wpinv-items-discount'><?php echo wpinv_price( wpinv_format_amount( 0 ) ) ?></strong></div> |
|
| 2113 | + <div class='col-8'><strong class='mr-5'><?php _e('Discount', 'invoicing'); ?></strong></div> |
|
| 2114 | + <div class='col-4'><strong class='wpinv-items-discount'><?php echo wpinv_price(wpinv_format_amount(0)) ?></strong></div> |
|
| 2115 | 2115 | </div> |
| 2116 | 2116 | |
| 2117 | - <?php if ( wpinv_use_taxes() ) { ?> |
|
| 2117 | + <?php if (wpinv_use_taxes()) { ?> |
|
| 2118 | 2118 | <div class='row'> |
| 2119 | - <div class='col-8'><strong class='mr-5'><?php _e( 'Tax', 'invoicing' ); ?></strong></div> |
|
| 2120 | - <div class='col-4'><strong class='wpinv-items-tax' ><?php echo wpinv_price( wpinv_format_amount( $tax ) ) ?></strong></div> |
|
| 2119 | + <div class='col-8'><strong class='mr-5'><?php _e('Tax', 'invoicing'); ?></strong></div> |
|
| 2120 | + <div class='col-4'><strong class='wpinv-items-tax' ><?php echo wpinv_price(wpinv_format_amount($tax)) ?></strong></div> |
|
| 2121 | 2121 | </div> |
| 2122 | 2122 | <?php } ?> |
| 2123 | 2123 | |
| 2124 | 2124 | <div class='row'> |
| 2125 | - <div class='col-8'><strong class='mr-5'><?php _e( 'Total', 'invoicing' ); ?></strong></div> |
|
| 2126 | - <div class='col-4'><strong class='wpinv-items-total' data-currency='<?php echo wpinv_currency_symbol(); ?>' data-currency-position='<?php echo wpinv_currency_position(); ?>'><?php echo wpinv_price( wpinv_format_amount( $total ) ) ?></strong></div> |
|
| 2125 | + <div class='col-8'><strong class='mr-5'><?php _e('Total', 'invoicing'); ?></strong></div> |
|
| 2126 | + <div class='col-4'><strong class='wpinv-items-total' data-currency='<?php echo wpinv_currency_symbol(); ?>' data-currency-position='<?php echo wpinv_currency_position(); ?>'><?php echo wpinv_price(wpinv_format_amount($total)) ?></strong></div> |
|
| 2127 | 2127 | </div> |
| 2128 | 2128 | |
| 2129 | 2129 | </div> |
@@ -2131,22 +2131,22 @@ discard block |
||
| 2131 | 2131 | </div> |
| 2132 | 2132 | <?php } ?> |
| 2133 | 2133 | |
| 2134 | - <?php if ( 'radio' == $field[ 'items_type' ] ) { ?> |
|
| 2134 | + <?php if ('radio' == $field['items_type']) { ?> |
|
| 2135 | 2135 | <div class="item_totals_type_radio"> |
| 2136 | 2136 | |
| 2137 | 2137 | <?php |
| 2138 | - foreach( $items as $index => $item ) { |
|
| 2138 | + foreach ($items as $index => $item) { |
|
| 2139 | 2139 | |
| 2140 | - if ( ! empty( $item['required'] ) ) { |
|
| 2140 | + if (!empty($item['required'])) { |
|
| 2141 | 2141 | continue; |
| 2142 | 2142 | } |
| 2143 | 2143 | ?> |
| 2144 | 2144 | <div class="form-check"> |
| 2145 | - <input class='form-check-input wpinv-items-selector' <?php checked( ! isset( $selected_radio_item ) ); $selected_radio_item = 1; ?> type='radio' value='<?php echo $item['id']; ?>' id='<?php echo $id . $index; ?>' name='wpinv-payment-form-selected-item'> |
|
| 2146 | - <label class='form-check-label' for='<?php echo $id . $index; ?>'><?php echo sanitize_text_field( $item['title'] ); ?> <strong><?php echo wpinv_price( wpinv_format_amount( (float) sanitize_text_field( $item['price'] ) ) ); ?></strong></label> |
|
| 2145 | + <input class='form-check-input wpinv-items-selector' <?php checked(!isset($selected_radio_item)); $selected_radio_item = 1; ?> type='radio' value='<?php echo $item['id']; ?>' id='<?php echo $id . $index; ?>' name='wpinv-payment-form-selected-item'> |
|
| 2146 | + <label class='form-check-label' for='<?php echo $id . $index; ?>'><?php echo sanitize_text_field($item['title']); ?> <strong><?php echo wpinv_price(wpinv_format_amount((float) sanitize_text_field($item['price']))); ?></strong></label> |
|
| 2147 | 2147 | </div> |
| 2148 | - <?php if ( ! empty( $item['description'] )) { ?> |
|
| 2149 | - <small class='form-text text-muted pl-4 pr-2 m-0'><?php echo wp_kses_post( $item['description'] ); ?></small> |
|
| 2148 | + <?php if (!empty($item['description'])) { ?> |
|
| 2149 | + <small class='form-text text-muted pl-4 pr-2 m-0'><?php echo wp_kses_post($item['description']); ?></small> |
|
| 2150 | 2150 | <?php } ?> |
| 2151 | 2151 | <?php } ?> |
| 2152 | 2152 | |
@@ -2158,32 +2158,32 @@ discard block |
||
| 2158 | 2158 | $tax = 0; |
| 2159 | 2159 | $sub_total = 0; |
| 2160 | 2160 | |
| 2161 | - foreach ( $items as $item ) { |
|
| 2161 | + foreach ($items as $item) { |
|
| 2162 | 2162 | |
| 2163 | 2163 | $class = 'col-8'; |
| 2164 | 2164 | $class2 = ''; |
| 2165 | 2165 | |
| 2166 | - if ( ! empty( $item['allow_quantities'] ) ) { |
|
| 2166 | + if (!empty($item['allow_quantities'])) { |
|
| 2167 | 2167 | $class = 'col-6 pt-2'; |
| 2168 | 2168 | $class2 = 'pt-2'; |
| 2169 | 2169 | } |
| 2170 | 2170 | |
| 2171 | - if ( ! empty( $item['custom_price'] ) ) { |
|
| 2171 | + if (!empty($item['custom_price'])) { |
|
| 2172 | 2172 | $class .= ' pt-2'; |
| 2173 | 2173 | } |
| 2174 | 2174 | |
| 2175 | 2175 | $class3 = 'd-none'; |
| 2176 | 2176 | $name = ''; |
| 2177 | - if ( ! empty( $item['required'] ) || ! isset( $totals_selected_radio_item ) ) { |
|
| 2177 | + if (!empty($item['required']) || !isset($totals_selected_radio_item)) { |
|
| 2178 | 2178 | |
| 2179 | - $amount = floatval( $item['price'] ); |
|
| 2179 | + $amount = floatval($item['price']); |
|
| 2180 | 2180 | |
| 2181 | - if ( wpinv_use_taxes() ) { |
|
| 2181 | + if (wpinv_use_taxes()) { |
|
| 2182 | 2182 | |
| 2183 | - $rate = wpinv_get_tax_rate( wpinv_get_default_country(), false, (int) $item['id'] ); |
|
| 2183 | + $rate = wpinv_get_tax_rate(wpinv_get_default_country(), false, (int) $item['id']); |
|
| 2184 | 2184 | |
| 2185 | - if ( wpinv_prices_include_tax() ) { |
|
| 2186 | - $pre_tax = ( $amount - $amount * $rate * 0.01 ); |
|
| 2185 | + if (wpinv_prices_include_tax()) { |
|
| 2186 | + $pre_tax = ($amount - $amount * $rate * 0.01); |
|
| 2187 | 2187 | $item_tax = $amount - $pre_tax; |
| 2188 | 2188 | } else { |
| 2189 | 2189 | $pre_tax = $amount; |
@@ -2195,13 +2195,13 @@ discard block |
||
| 2195 | 2195 | $total = $sub_total + $tax; |
| 2196 | 2196 | |
| 2197 | 2197 | } else { |
| 2198 | - $total = $total + $amount; |
|
| 2198 | + $total = $total + $amount; |
|
| 2199 | 2199 | } |
| 2200 | 2200 | |
| 2201 | 2201 | $class3 = ''; |
| 2202 | 2202 | $name = "wpinv-items[{$item['id']}]"; |
| 2203 | 2203 | |
| 2204 | - if ( empty( $item['required'] ) ) { |
|
| 2204 | + if (empty($item['required'])) { |
|
| 2205 | 2205 | $totals_selected_radio_item = 1; |
| 2206 | 2206 | } |
| 2207 | 2207 | |
@@ -2213,9 +2213,9 @@ discard block |
||
| 2213 | 2213 | |
| 2214 | 2214 | <div class="item_totals_item <?php echo $class3; ?>" data-id="<?php echo (int) $item['id']; ?>"> |
| 2215 | 2215 | <div class='row pl-2 pr-2 pt-2'> |
| 2216 | - <div class='<?php echo $class; ?>'><?php echo sanitize_text_field( $item['title'] ) ?></div> |
|
| 2216 | + <div class='<?php echo $class; ?>'><?php echo sanitize_text_field($item['title']) ?></div> |
|
| 2217 | 2217 | |
| 2218 | - <?php if ( ! empty( $item['allow_quantities'] ) ) { ?> |
|
| 2218 | + <?php if (!empty($item['allow_quantities'])) { ?> |
|
| 2219 | 2219 | |
| 2220 | 2220 | <div class='col-2'> |
| 2221 | 2221 | <input name='wpinv-item-<?php echo (int) $item['id']; ?>-quantity' type='number' class='form-control wpinv-item-quantity-input pr-1' value='1' min='1' required> |
@@ -2223,11 +2223,11 @@ discard block |
||
| 2223 | 2223 | |
| 2224 | 2224 | <?php } else { ?> |
| 2225 | 2225 | <input type='hidden' class='wpinv-item-quantity-input' value='1'> |
| 2226 | - <?php } if ( empty( $item['custom_price'] ) ) { ?> |
|
| 2226 | + <?php } if (empty($item['custom_price'])) { ?> |
|
| 2227 | 2227 | |
| 2228 | 2228 | <div class='col-4 <?php echo $class2; ?>'> |
| 2229 | - <?php echo wpinv_price( wpinv_format_amount( $item['price'] ) ) ?> |
|
| 2230 | - <input name='<?php echo $name; ?>' type='hidden' class='wpinv-item-price-input' value='<?php echo floatval( $item['price'] ); ?>'> |
|
| 2229 | + <?php echo wpinv_price(wpinv_format_amount($item['price'])) ?> |
|
| 2230 | + <input name='<?php echo $name; ?>' type='hidden' class='wpinv-item-price-input' value='<?php echo floatval($item['price']); ?>'> |
|
| 2231 | 2231 | </div> |
| 2232 | 2232 | |
| 2233 | 2233 | <?php } else {?> |
@@ -2235,15 +2235,15 @@ discard block |
||
| 2235 | 2235 | <div class='col-4'> |
| 2236 | 2236 | <div class='input-group'> |
| 2237 | 2237 | |
| 2238 | - <?php if ( 'left' == wpinv_currency_position() ) { ?> |
|
| 2238 | + <?php if ('left' == wpinv_currency_position()) { ?> |
|
| 2239 | 2239 | <div class='input-group-prepend'> |
| 2240 | 2240 | <span class='input-group-text'><?php echo wpinv_currency_symbol(); ?></span> |
| 2241 | 2241 | </div> |
| 2242 | 2242 | <?php } ?> |
| 2243 | 2243 | |
| 2244 | - <input type='text' name='<?php echo $name; ?>' class='form-control wpinv-item-price-input' placeholder='<?php echo floatval( $item['price'] ); ?>' value='<?php echo floatval( $item['price'] ); ?>' min='<?php echo intval( $item['minimum_price'] ); ?>'> |
|
| 2244 | + <input type='text' name='<?php echo $name; ?>' class='form-control wpinv-item-price-input' placeholder='<?php echo floatval($item['price']); ?>' value='<?php echo floatval($item['price']); ?>' min='<?php echo intval($item['minimum_price']); ?>'> |
|
| 2245 | 2245 | |
| 2246 | - <?php if ( 'left' != wpinv_currency_position() ) { ?> |
|
| 2246 | + <?php if ('left' != wpinv_currency_position()) { ?> |
|
| 2247 | 2247 | <div class='input-group-append'> |
| 2248 | 2248 | <span class='input-group-text'><?php echo wpinv_currency_symbol(); ?></span> |
| 2249 | 2249 | </div> |
@@ -2254,8 +2254,8 @@ discard block |
||
| 2254 | 2254 | <?php } ?> |
| 2255 | 2255 | |
| 2256 | 2256 | </div> |
| 2257 | - <?php if ( ! empty( $item['description'] )) { ?> |
|
| 2258 | - <small class='form-text text-muted pl-2 pr-2 m-0'><?php echo wp_kses_post( $item['description'] ); ?></small> |
|
| 2257 | + <?php if (!empty($item['description'])) { ?> |
|
| 2258 | + <small class='form-text text-muted pl-2 pr-2 m-0'><?php echo wp_kses_post($item['description']); ?></small> |
|
| 2259 | 2259 | <?php } ?> |
| 2260 | 2260 | </div> |
| 2261 | 2261 | <?php } ?> |
@@ -2263,25 +2263,25 @@ discard block |
||
| 2263 | 2263 | <div class='mt-4 border-top item_totals_total p-2'> |
| 2264 | 2264 | |
| 2265 | 2265 | <div class='row'> |
| 2266 | - <div class='col-8'><strong class='mr-5'><?php _e( 'Sub Total', 'invoicing' ); ?></strong></div> |
|
| 2267 | - <div class='col-4'><strong class='wpinv-items-sub-total'><?php echo wpinv_price( wpinv_format_amount( $sub_total ) ) ?></strong></div> |
|
| 2266 | + <div class='col-8'><strong class='mr-5'><?php _e('Sub Total', 'invoicing'); ?></strong></div> |
|
| 2267 | + <div class='col-4'><strong class='wpinv-items-sub-total'><?php echo wpinv_price(wpinv_format_amount($sub_total)) ?></strong></div> |
|
| 2268 | 2268 | </div> |
| 2269 | 2269 | |
| 2270 | 2270 | <div class='row' style='display: none;'> |
| 2271 | - <div class='col-8'><strong class='mr-5'><?php _e( 'Discount', 'invoicing' ); ?></strong></div> |
|
| 2271 | + <div class='col-8'><strong class='mr-5'><?php _e('Discount', 'invoicing'); ?></strong></div> |
|
| 2272 | 2272 | <div class='col-4'><strong class='wpinv-items-discount'></strong></div> |
| 2273 | 2273 | </div> |
| 2274 | 2274 | |
| 2275 | - <?php if ( wpinv_use_taxes() ) { ?> |
|
| 2275 | + <?php if (wpinv_use_taxes()) { ?> |
|
| 2276 | 2276 | <div class='row'> |
| 2277 | - <div class='col-8'><strong class='mr-5'><?php _e( 'Tax', 'invoicing' ); ?></strong></div> |
|
| 2278 | - <div class='col-4'><strong class='wpinv-items-tax' ><?php echo wpinv_price( wpinv_format_amount( $tax ) ) ?></strong></div> |
|
| 2277 | + <div class='col-8'><strong class='mr-5'><?php _e('Tax', 'invoicing'); ?></strong></div> |
|
| 2278 | + <div class='col-4'><strong class='wpinv-items-tax' ><?php echo wpinv_price(wpinv_format_amount($tax)) ?></strong></div> |
|
| 2279 | 2279 | </div> |
| 2280 | 2280 | <?php } ?> |
| 2281 | 2281 | |
| 2282 | 2282 | <div class='row'> |
| 2283 | - <div class='col-8'><strong class='mr-5'><?php _e( 'Total', 'invoicing' ); ?></strong></div> |
|
| 2284 | - <div class='col-4'><strong class='wpinv-items-total' data-currency='<?php echo wpinv_currency_symbol(); ?>' data-currency-position='<?php echo wpinv_currency_position(); ?>'><?php echo wpinv_price( wpinv_format_amount( $total ) ) ?></strong></div> |
|
| 2283 | + <div class='col-8'><strong class='mr-5'><?php _e('Total', 'invoicing'); ?></strong></div> |
|
| 2284 | + <div class='col-4'><strong class='wpinv-items-total' data-currency='<?php echo wpinv_currency_symbol(); ?>' data-currency-position='<?php echo wpinv_currency_position(); ?>'><?php echo wpinv_price(wpinv_format_amount($total)) ?></strong></div> |
|
| 2285 | 2285 | </div> |
| 2286 | 2286 | </div> |
| 2287 | 2287 | |
@@ -2289,22 +2289,22 @@ discard block |
||
| 2289 | 2289 | </div> |
| 2290 | 2290 | <?php } ?> |
| 2291 | 2291 | |
| 2292 | - <?php if ( 'checkbox' == $field[ 'items_type' ] ) { ?> |
|
| 2292 | + <?php if ('checkbox' == $field['items_type']) { ?> |
|
| 2293 | 2293 | |
| 2294 | 2294 | <div class="item_totals_type_checkbox"> |
| 2295 | 2295 | |
| 2296 | 2296 | <?php |
| 2297 | - foreach ( $items as $index => $item ) { |
|
| 2297 | + foreach ($items as $index => $item) { |
|
| 2298 | 2298 | |
| 2299 | - if ( ! empty( $item['required'] ) ) { |
|
| 2299 | + if (!empty($item['required'])) { |
|
| 2300 | 2300 | continue; |
| 2301 | 2301 | } |
| 2302 | 2302 | |
| 2303 | - $title = sanitize_text_field( $item['title'] ); |
|
| 2304 | - $price = wpinv_price( wpinv_format_amount( (float) sanitize_text_field( $item['price'] ) ) ); |
|
| 2305 | - $item_id = esc_attr( $id . "_$index" ); |
|
| 2306 | - $value = esc_attr( $item['id'] ); |
|
| 2307 | - $checked = checked( ! isset( $selected_checkbox_item ), true, false ); |
|
| 2303 | + $title = sanitize_text_field($item['title']); |
|
| 2304 | + $price = wpinv_price(wpinv_format_amount((float) sanitize_text_field($item['price']))); |
|
| 2305 | + $item_id = esc_attr($id . "_$index"); |
|
| 2306 | + $value = esc_attr($item['id']); |
|
| 2307 | + $checked = checked(!isset($selected_checkbox_item), true, false); |
|
| 2308 | 2308 | $selected_checkbox_item = 1; |
| 2309 | 2309 | |
| 2310 | 2310 | echo " |
@@ -2313,7 +2313,7 @@ discard block |
||
| 2313 | 2313 | <label for='$item_id' class='custom-control-label'>$title ($price)</label> |
| 2314 | 2314 | </div>"; |
| 2315 | 2315 | |
| 2316 | - if ( ! empty( $item['description'] ) ) { |
|
| 2316 | + if (!empty($item['description'])) { |
|
| 2317 | 2317 | echo "<small class='form-text text-muted'>{$item['description']}</small>"; |
| 2318 | 2318 | } |
| 2319 | 2319 | } |
@@ -2327,31 +2327,31 @@ discard block |
||
| 2327 | 2327 | $tax = 0; |
| 2328 | 2328 | $sub_total = 0; |
| 2329 | 2329 | |
| 2330 | - foreach ( $items as $item ) { |
|
| 2330 | + foreach ($items as $item) { |
|
| 2331 | 2331 | |
| 2332 | 2332 | $class = 'col-8'; |
| 2333 | 2333 | $class2 = ''; |
| 2334 | 2334 | |
| 2335 | - if ( ! empty( $item['allow_quantities'] ) ) { |
|
| 2335 | + if (!empty($item['allow_quantities'])) { |
|
| 2336 | 2336 | $class = 'col-6 pt-2'; |
| 2337 | 2337 | $class2 = 'pt-2'; |
| 2338 | 2338 | } |
| 2339 | 2339 | |
| 2340 | - if ( ! empty( $item['custom_price'] ) ) { |
|
| 2340 | + if (!empty($item['custom_price'])) { |
|
| 2341 | 2341 | $class .= ' pt-2'; |
| 2342 | 2342 | } |
| 2343 | 2343 | |
| 2344 | 2344 | $class3 = 'd-none'; |
| 2345 | - $name = ''; |
|
| 2346 | - if ( ! empty( $item['required'] ) || ! isset( $totals_selected_checkbox_item ) ) { |
|
| 2345 | + $name = ''; |
|
| 2346 | + if (!empty($item['required']) || !isset($totals_selected_checkbox_item)) { |
|
| 2347 | 2347 | |
| 2348 | - $amount = floatval( $item['price'] ); |
|
| 2349 | - if ( wpinv_use_taxes() ) { |
|
| 2348 | + $amount = floatval($item['price']); |
|
| 2349 | + if (wpinv_use_taxes()) { |
|
| 2350 | 2350 | |
| 2351 | - $rate = wpinv_get_tax_rate( wpinv_get_default_country(), false, (int) $item['id'] ); |
|
| 2351 | + $rate = wpinv_get_tax_rate(wpinv_get_default_country(), false, (int) $item['id']); |
|
| 2352 | 2352 | |
| 2353 | - if ( wpinv_prices_include_tax() ) { |
|
| 2354 | - $pre_tax = ( $amount - $amount * $rate * 0.01 ); |
|
| 2353 | + if (wpinv_prices_include_tax()) { |
|
| 2354 | + $pre_tax = ($amount - $amount * $rate * 0.01); |
|
| 2355 | 2355 | $item_tax = $amount - $pre_tax; |
| 2356 | 2356 | } else { |
| 2357 | 2357 | $pre_tax = $amount; |
@@ -2363,13 +2363,13 @@ discard block |
||
| 2363 | 2363 | $total = $sub_total + $tax; |
| 2364 | 2364 | |
| 2365 | 2365 | } else { |
| 2366 | - $total = $total + $amount; |
|
| 2366 | + $total = $total + $amount; |
|
| 2367 | 2367 | } |
| 2368 | 2368 | |
| 2369 | 2369 | $class3 = ''; |
| 2370 | - $name = "wpinv-items[{$item['id']}]"; |
|
| 2370 | + $name = "wpinv-items[{$item['id']}]"; |
|
| 2371 | 2371 | |
| 2372 | - if ( empty( $item['required'] ) ) { |
|
| 2372 | + if (empty($item['required'])) { |
|
| 2373 | 2373 | $totals_selected_checkbox_item = 1; |
| 2374 | 2374 | } |
| 2375 | 2375 | |
@@ -2381,9 +2381,9 @@ discard block |
||
| 2381 | 2381 | |
| 2382 | 2382 | <div class="item_totals_item <?php echo $class3; ?>" data-id="<?php echo (int) $item['id']; ?>"> |
| 2383 | 2383 | <div class='row pl-2 pr-2 pt-2'> |
| 2384 | - <div class='<?php echo $class; ?>'><?php echo sanitize_text_field( $item['title'] ) ?></div> |
|
| 2384 | + <div class='<?php echo $class; ?>'><?php echo sanitize_text_field($item['title']) ?></div> |
|
| 2385 | 2385 | |
| 2386 | - <?php if ( ! empty( $item['allow_quantities'] ) ) { ?> |
|
| 2386 | + <?php if (!empty($item['allow_quantities'])) { ?> |
|
| 2387 | 2387 | |
| 2388 | 2388 | <div class='col-2'> |
| 2389 | 2389 | <input name='wpinv-item-<?php echo (int) $item['id']; ?>-quantity' type='number' class='form-control wpinv-item-quantity-input pr-1' value='1' min='1' required> |
@@ -2391,11 +2391,11 @@ discard block |
||
| 2391 | 2391 | |
| 2392 | 2392 | <?php } else { ?> |
| 2393 | 2393 | <input type='hidden' class='wpinv-item-quantity-input' value='1'> |
| 2394 | - <?php } if ( empty( $item['custom_price'] ) ) { ?> |
|
| 2394 | + <?php } if (empty($item['custom_price'])) { ?> |
|
| 2395 | 2395 | |
| 2396 | 2396 | <div class='col-4 <?php echo $class2; ?>'> |
| 2397 | - <?php echo wpinv_price( wpinv_format_amount( $item['price'] ) ) ?> |
|
| 2398 | - <input name='<?php echo $name; ?>' type='hidden' class='wpinv-item-price-input' value='<?php echo floatval( $item['price'] ); ?>'> |
|
| 2397 | + <?php echo wpinv_price(wpinv_format_amount($item['price'])) ?> |
|
| 2398 | + <input name='<?php echo $name; ?>' type='hidden' class='wpinv-item-price-input' value='<?php echo floatval($item['price']); ?>'> |
|
| 2399 | 2399 | </div> |
| 2400 | 2400 | |
| 2401 | 2401 | <?php } else {?> |
@@ -2403,15 +2403,15 @@ discard block |
||
| 2403 | 2403 | <div class='col-4'> |
| 2404 | 2404 | <div class='input-group'> |
| 2405 | 2405 | |
| 2406 | - <?php if ( 'left' == wpinv_currency_position() ) { ?> |
|
| 2406 | + <?php if ('left' == wpinv_currency_position()) { ?> |
|
| 2407 | 2407 | <div class='input-group-prepend'> |
| 2408 | 2408 | <span class='input-group-text'><?php echo wpinv_currency_symbol(); ?></span> |
| 2409 | 2409 | </div> |
| 2410 | 2410 | <?php } ?> |
| 2411 | 2411 | |
| 2412 | - <input type='text' name='<?php echo $name; ?>' class='form-control wpinv-item-price-input' placeholder='<?php echo floatval( $item['price'] ); ?>' value='<?php echo floatval( $item['price'] ); ?>' min='<?php echo intval( $item['minimum_price'] ); ?>'> |
|
| 2412 | + <input type='text' name='<?php echo $name; ?>' class='form-control wpinv-item-price-input' placeholder='<?php echo floatval($item['price']); ?>' value='<?php echo floatval($item['price']); ?>' min='<?php echo intval($item['minimum_price']); ?>'> |
|
| 2413 | 2413 | |
| 2414 | - <?php if ( 'left' != wpinv_currency_position() ) { ?> |
|
| 2414 | + <?php if ('left' != wpinv_currency_position()) { ?> |
|
| 2415 | 2415 | <div class='input-group-append'> |
| 2416 | 2416 | <span class='input-group-text'><?php echo wpinv_currency_symbol(); ?></span> |
| 2417 | 2417 | </div> |
@@ -2422,8 +2422,8 @@ discard block |
||
| 2422 | 2422 | <?php } ?> |
| 2423 | 2423 | |
| 2424 | 2424 | </div> |
| 2425 | - <?php if ( ! empty( $item['description'] )) { ?> |
|
| 2426 | - <small class='form-text text-muted pl-2 pr-2 m-0'><?php echo wp_kses_post( $item['description'] ); ?></small> |
|
| 2425 | + <?php if (!empty($item['description'])) { ?> |
|
| 2426 | + <small class='form-text text-muted pl-2 pr-2 m-0'><?php echo wp_kses_post($item['description']); ?></small> |
|
| 2427 | 2427 | <?php } ?> |
| 2428 | 2428 | </div> |
| 2429 | 2429 | <?php } ?> |
@@ -2431,32 +2431,32 @@ discard block |
||
| 2431 | 2431 | <div class='mt-4 border-top item_totals_total p-2'> |
| 2432 | 2432 | |
| 2433 | 2433 | <div class='row'> |
| 2434 | - <div class='col-8'><strong class='mr-5'><?php _e( 'Sub Total', 'invoicing' ); ?></strong></div> |
|
| 2435 | - <div class='col-4'><strong class='wpinv-items-sub-total'><?php echo wpinv_price( wpinv_format_amount( $sub_total ) ) ?></strong></div> |
|
| 2434 | + <div class='col-8'><strong class='mr-5'><?php _e('Sub Total', 'invoicing'); ?></strong></div> |
|
| 2435 | + <div class='col-4'><strong class='wpinv-items-sub-total'><?php echo wpinv_price(wpinv_format_amount($sub_total)) ?></strong></div> |
|
| 2436 | 2436 | </div> |
| 2437 | 2437 | |
| 2438 | 2438 | <div class='row' style='display: none;'> |
| 2439 | - <div class='col-8'><strong class='mr-5'><?php _e( 'Discount', 'invoicing' ); ?></strong></div> |
|
| 2440 | - <div class='col-4'><strong class='wpinv-items-discount'><?php echo wpinv_price( wpinv_format_amount( 0 ) ) ?></strong></div> |
|
| 2439 | + <div class='col-8'><strong class='mr-5'><?php _e('Discount', 'invoicing'); ?></strong></div> |
|
| 2440 | + <div class='col-4'><strong class='wpinv-items-discount'><?php echo wpinv_price(wpinv_format_amount(0)) ?></strong></div> |
|
| 2441 | 2441 | </div> |
| 2442 | 2442 | |
| 2443 | - <?php if ( wpinv_use_taxes() ) { ?> |
|
| 2443 | + <?php if (wpinv_use_taxes()) { ?> |
|
| 2444 | 2444 | <div class='row'> |
| 2445 | - <div class='col-8'><strong class='mr-5'><?php _e( 'Tax', 'invoicing' ); ?></strong></div> |
|
| 2446 | - <div class='col-4'><strong class='wpinv-items-tax' ><?php echo wpinv_price( wpinv_format_amount( $tax ) ) ?></strong></div> |
|
| 2445 | + <div class='col-8'><strong class='mr-5'><?php _e('Tax', 'invoicing'); ?></strong></div> |
|
| 2446 | + <div class='col-4'><strong class='wpinv-items-tax' ><?php echo wpinv_price(wpinv_format_amount($tax)) ?></strong></div> |
|
| 2447 | 2447 | </div> |
| 2448 | 2448 | <?php } ?> |
| 2449 | 2449 | |
| 2450 | 2450 | <div class='row'> |
| 2451 | - <div class='col-8'><strong class='mr-5'><?php _e( 'Total', 'invoicing' ); ?></strong></div> |
|
| 2452 | - <div class='col-4'><strong class='wpinv-items-total' data-currency='<?php echo wpinv_currency_symbol(); ?>' data-currency-position='<?php echo wpinv_currency_position(); ?>'><?php echo wpinv_price( wpinv_format_amount( $total ) ) ?></strong></div> |
|
| 2451 | + <div class='col-8'><strong class='mr-5'><?php _e('Total', 'invoicing'); ?></strong></div> |
|
| 2452 | + <div class='col-4'><strong class='wpinv-items-total' data-currency='<?php echo wpinv_currency_symbol(); ?>' data-currency-position='<?php echo wpinv_currency_position(); ?>'><?php echo wpinv_price(wpinv_format_amount($total)) ?></strong></div> |
|
| 2453 | 2453 | </div> |
| 2454 | 2454 | </div> |
| 2455 | 2455 | </div> |
| 2456 | 2456 | </div> |
| 2457 | 2457 | <?php } ?> |
| 2458 | 2458 | |
| 2459 | - <?php if ( 'select' == $field[ 'items_type' ] ) { ?> |
|
| 2459 | + <?php if ('select' == $field['items_type']) { ?> |
|
| 2460 | 2460 | |
| 2461 | 2461 | <div class="item_totals_type_select"> |
| 2462 | 2462 | |
@@ -2464,17 +2464,17 @@ discard block |
||
| 2464 | 2464 | |
| 2465 | 2465 | $options = array(); |
| 2466 | 2466 | $selected = ''; |
| 2467 | - foreach ( $items as $index => $item ) { |
|
| 2467 | + foreach ($items as $index => $item) { |
|
| 2468 | 2468 | |
| 2469 | - if ( ! empty( $item['required'] ) ) { |
|
| 2469 | + if (!empty($item['required'])) { |
|
| 2470 | 2470 | continue; |
| 2471 | 2471 | } |
| 2472 | 2472 | |
| 2473 | - $title = sanitize_text_field( $item['title'] ); |
|
| 2474 | - $price = wpinv_price( wpinv_format_amount( (float) sanitize_text_field( $item['price'] ) ) ); |
|
| 2475 | - $options[ $item['id'] ] = "$title ($price)"; |
|
| 2473 | + $title = sanitize_text_field($item['title']); |
|
| 2474 | + $price = wpinv_price(wpinv_format_amount((float) sanitize_text_field($item['price']))); |
|
| 2475 | + $options[$item['id']] = "$title ($price)"; |
|
| 2476 | 2476 | |
| 2477 | - if ( ! isset( $selected_item ) ) { |
|
| 2477 | + if (!isset($selected_item)) { |
|
| 2478 | 2478 | $selected = $item['id']; |
| 2479 | 2479 | $selected_item = 1; |
| 2480 | 2480 | } |
@@ -2485,7 +2485,7 @@ discard block |
||
| 2485 | 2485 | array( |
| 2486 | 2486 | 'name' => 'payment-form-items', |
| 2487 | 2487 | 'id' => $id, |
| 2488 | - 'placeholder' => __( 'Select an item', 'invoicing' ), |
|
| 2488 | + 'placeholder' => __('Select an item', 'invoicing'), |
|
| 2489 | 2489 | 'no_wrap' => true, |
| 2490 | 2490 | 'options' => $options, |
| 2491 | 2491 | 'class' => 'wpi_select2 wpinv-items-select-selector', |
@@ -2502,31 +2502,31 @@ discard block |
||
| 2502 | 2502 | $tax = 0; |
| 2503 | 2503 | $sub_total = 0; |
| 2504 | 2504 | |
| 2505 | - foreach ( $items as $item ) { |
|
| 2505 | + foreach ($items as $item) { |
|
| 2506 | 2506 | |
| 2507 | 2507 | $class = 'col-8'; |
| 2508 | 2508 | $class2 = ''; |
| 2509 | 2509 | |
| 2510 | - if ( ! empty( $item['allow_quantities'] ) ) { |
|
| 2510 | + if (!empty($item['allow_quantities'])) { |
|
| 2511 | 2511 | $class = 'col-6 pt-2'; |
| 2512 | 2512 | $class2 = 'pt-2'; |
| 2513 | 2513 | } |
| 2514 | 2514 | |
| 2515 | - if ( ! empty( $item['custom_price'] ) ) { |
|
| 2515 | + if (!empty($item['custom_price'])) { |
|
| 2516 | 2516 | $class .= ' pt-2'; |
| 2517 | 2517 | } |
| 2518 | 2518 | |
| 2519 | 2519 | $class3 = 'd-none'; |
| 2520 | - $name = ''; |
|
| 2521 | - if ( ! empty( $item['required'] ) || ! isset( $totals_selected_select_item ) ) { |
|
| 2520 | + $name = ''; |
|
| 2521 | + if (!empty($item['required']) || !isset($totals_selected_select_item)) { |
|
| 2522 | 2522 | |
| 2523 | - $amount = floatval( $item['price'] ); |
|
| 2524 | - if ( wpinv_use_taxes() ) { |
|
| 2523 | + $amount = floatval($item['price']); |
|
| 2524 | + if (wpinv_use_taxes()) { |
|
| 2525 | 2525 | |
| 2526 | - $rate = wpinv_get_tax_rate( wpinv_get_default_country(), false, (int) $item['id'] ); |
|
| 2526 | + $rate = wpinv_get_tax_rate(wpinv_get_default_country(), false, (int) $item['id']); |
|
| 2527 | 2527 | |
| 2528 | - if ( wpinv_prices_include_tax() ) { |
|
| 2529 | - $pre_tax = ( $amount - $amount * $rate * 0.01 ); |
|
| 2528 | + if (wpinv_prices_include_tax()) { |
|
| 2529 | + $pre_tax = ($amount - $amount * $rate * 0.01); |
|
| 2530 | 2530 | $item_tax = $amount - $pre_tax; |
| 2531 | 2531 | } else { |
| 2532 | 2532 | $pre_tax = $amount; |
@@ -2538,13 +2538,13 @@ discard block |
||
| 2538 | 2538 | $total = $sub_total + $tax; |
| 2539 | 2539 | |
| 2540 | 2540 | } else { |
| 2541 | - $total = $total + $amount; |
|
| 2541 | + $total = $total + $amount; |
|
| 2542 | 2542 | } |
| 2543 | 2543 | |
| 2544 | 2544 | $class3 = ''; |
| 2545 | - $name = "wpinv-items[{$item['id']}]"; |
|
| 2545 | + $name = "wpinv-items[{$item['id']}]"; |
|
| 2546 | 2546 | |
| 2547 | - if ( empty( $item['required'] ) ) { |
|
| 2547 | + if (empty($item['required'])) { |
|
| 2548 | 2548 | $totals_selected_select_item = 1; |
| 2549 | 2549 | } |
| 2550 | 2550 | |
@@ -2556,9 +2556,9 @@ discard block |
||
| 2556 | 2556 | |
| 2557 | 2557 | <div class="item_totals_item <?php echo $class3; ?>" data-id="<?php echo (int) $item['id']; ?>"> |
| 2558 | 2558 | <div class='row pl-2 pr-2 pt-2'> |
| 2559 | - <div class='<?php echo $class; ?>'><?php echo sanitize_text_field( $item['title'] ) ?></div> |
|
| 2559 | + <div class='<?php echo $class; ?>'><?php echo sanitize_text_field($item['title']) ?></div> |
|
| 2560 | 2560 | |
| 2561 | - <?php if ( ! empty( $item['allow_quantities'] ) ) { ?> |
|
| 2561 | + <?php if (!empty($item['allow_quantities'])) { ?> |
|
| 2562 | 2562 | |
| 2563 | 2563 | <div class='col-2'> |
| 2564 | 2564 | <input name='wpinv-item-<?php echo (int) $item['id']; ?>-quantity' type='number' class='form-control wpinv-item-quantity-input pr-1' value='1' min='1' required> |
@@ -2566,11 +2566,11 @@ discard block |
||
| 2566 | 2566 | |
| 2567 | 2567 | <?php } else { ?> |
| 2568 | 2568 | <input type='hidden' class='wpinv-item-quantity-input' value='1'> |
| 2569 | - <?php } if ( empty( $item['custom_price'] ) ) { ?> |
|
| 2569 | + <?php } if (empty($item['custom_price'])) { ?> |
|
| 2570 | 2570 | |
| 2571 | 2571 | <div class='col-4 <?php echo $class2; ?>'> |
| 2572 | - <?php echo wpinv_price( wpinv_format_amount( $item['price'] ) ) ?> |
|
| 2573 | - <input name='<?php echo $name; ?>' type='hidden' class='wpinv-item-price-input' value='<?php echo floatval( $item['price'] ); ?>'> |
|
| 2572 | + <?php echo wpinv_price(wpinv_format_amount($item['price'])) ?> |
|
| 2573 | + <input name='<?php echo $name; ?>' type='hidden' class='wpinv-item-price-input' value='<?php echo floatval($item['price']); ?>'> |
|
| 2574 | 2574 | </div> |
| 2575 | 2575 | |
| 2576 | 2576 | <?php } else {?> |
@@ -2578,15 +2578,15 @@ discard block |
||
| 2578 | 2578 | <div class='col-4'> |
| 2579 | 2579 | <div class='input-group'> |
| 2580 | 2580 | |
| 2581 | - <?php if ( 'left' == wpinv_currency_position() ) { ?> |
|
| 2581 | + <?php if ('left' == wpinv_currency_position()) { ?> |
|
| 2582 | 2582 | <div class='input-group-prepend'> |
| 2583 | 2583 | <span class='input-group-text'><?php echo wpinv_currency_symbol(); ?></span> |
| 2584 | 2584 | </div> |
| 2585 | 2585 | <?php } ?> |
| 2586 | 2586 | |
| 2587 | - <input type='text' name='<?php echo $name; ?>' class='form-control wpinv-item-price-input' placeholder='<?php echo floatval( $item['price'] ); ?>' value='<?php echo floatval( $item['price'] ); ?>' min='<?php echo intval( $item['minimum_price'] ); ?>'> |
|
| 2587 | + <input type='text' name='<?php echo $name; ?>' class='form-control wpinv-item-price-input' placeholder='<?php echo floatval($item['price']); ?>' value='<?php echo floatval($item['price']); ?>' min='<?php echo intval($item['minimum_price']); ?>'> |
|
| 2588 | 2588 | |
| 2589 | - <?php if ( 'left' != wpinv_currency_position() ) { ?> |
|
| 2589 | + <?php if ('left' != wpinv_currency_position()) { ?> |
|
| 2590 | 2590 | <div class='input-group-append'> |
| 2591 | 2591 | <span class='input-group-text'><?php echo wpinv_currency_symbol(); ?></span> |
| 2592 | 2592 | </div> |
@@ -2597,8 +2597,8 @@ discard block |
||
| 2597 | 2597 | <?php } ?> |
| 2598 | 2598 | |
| 2599 | 2599 | </div> |
| 2600 | - <?php if ( ! empty( $item['description'] )) { ?> |
|
| 2601 | - <small class='form-text text-muted pl-2 pr-2 m-0'><?php echo wp_kses_post( $item['description'] ); ?></small> |
|
| 2600 | + <?php if (!empty($item['description'])) { ?> |
|
| 2601 | + <small class='form-text text-muted pl-2 pr-2 m-0'><?php echo wp_kses_post($item['description']); ?></small> |
|
| 2602 | 2602 | <?php } ?> |
| 2603 | 2603 | </div> |
| 2604 | 2604 | <?php } ?> |
@@ -2606,31 +2606,31 @@ discard block |
||
| 2606 | 2606 | <div class='mt-4 border-top item_totals_total p-2'> |
| 2607 | 2607 | |
| 2608 | 2608 | <div class='row'> |
| 2609 | - <div class='col-8'><strong class='mr-5'><?php _e( 'Sub Total', 'invoicing' ); ?></strong></div> |
|
| 2610 | - <div class='col-4'><strong class='wpinv-items-sub-total'><?php echo wpinv_price( wpinv_format_amount( $sub_total ) ) ?></strong></div> |
|
| 2609 | + <div class='col-8'><strong class='mr-5'><?php _e('Sub Total', 'invoicing'); ?></strong></div> |
|
| 2610 | + <div class='col-4'><strong class='wpinv-items-sub-total'><?php echo wpinv_price(wpinv_format_amount($sub_total)) ?></strong></div> |
|
| 2611 | 2611 | </div> |
| 2612 | 2612 | |
| 2613 | 2613 | <div class='row' style='display: none;'> |
| 2614 | - <div class='col-8'><strong class='mr-5'><?php _e( 'Discount', 'invoicing' ); ?></strong></div> |
|
| 2615 | - <div class='col-4'><strong class='wpinv-items-discount'><?php echo wpinv_price( wpinv_format_amount( 0 ) ) ?></strong></div> |
|
| 2614 | + <div class='col-8'><strong class='mr-5'><?php _e('Discount', 'invoicing'); ?></strong></div> |
|
| 2615 | + <div class='col-4'><strong class='wpinv-items-discount'><?php echo wpinv_price(wpinv_format_amount(0)) ?></strong></div> |
|
| 2616 | 2616 | </div> |
| 2617 | 2617 | |
| 2618 | - <?php if ( wpinv_use_taxes() ) { ?> |
|
| 2618 | + <?php if (wpinv_use_taxes()) { ?> |
|
| 2619 | 2619 | <div class='row'> |
| 2620 | - <div class='col-8'><strong class='mr-5'><?php _e( 'Tax', 'invoicing' ); ?></strong></div> |
|
| 2621 | - <div class='col-4'><strong class='wpinv-items-tax' ><?php echo wpinv_price( wpinv_format_amount( $tax ) ) ?></strong></div> |
|
| 2620 | + <div class='col-8'><strong class='mr-5'><?php _e('Tax', 'invoicing'); ?></strong></div> |
|
| 2621 | + <div class='col-4'><strong class='wpinv-items-tax' ><?php echo wpinv_price(wpinv_format_amount($tax)) ?></strong></div> |
|
| 2622 | 2622 | </div> |
| 2623 | 2623 | <?php } ?> |
| 2624 | 2624 | <div class='row'> |
| 2625 | - <div class='col-8'><strong class='mr-5'><?php _e( 'Total', 'invoicing' ); ?></strong></div> |
|
| 2626 | - <div class='col-4'><strong class='wpinv-items-total' data-currency='<?php echo wpinv_currency_symbol(); ?>' data-currency-position='<?php echo wpinv_currency_position(); ?>'><?php echo wpinv_price( wpinv_format_amount( $total ) ) ?></strong></div> |
|
| 2625 | + <div class='col-8'><strong class='mr-5'><?php _e('Total', 'invoicing'); ?></strong></div> |
|
| 2626 | + <div class='col-4'><strong class='wpinv-items-total' data-currency='<?php echo wpinv_currency_symbol(); ?>' data-currency-position='<?php echo wpinv_currency_position(); ?>'><?php echo wpinv_price(wpinv_format_amount($total)) ?></strong></div> |
|
| 2627 | 2627 | </div> |
| 2628 | 2628 | </div> |
| 2629 | 2629 | |
| 2630 | 2630 | </div> |
| 2631 | 2631 | <?php } ?> |
| 2632 | 2632 | |
| 2633 | - <?php if ( 'multi_select' == $field[ 'items_type' ] ) { ?> |
|
| 2633 | + <?php if ('multi_select' == $field['items_type']) { ?> |
|
| 2634 | 2634 | |
| 2635 | 2635 | <div class="item_totals_type_multi_select"> |
| 2636 | 2636 | |
@@ -2639,18 +2639,18 @@ discard block |
||
| 2639 | 2639 | $options = array(); |
| 2640 | 2640 | $selected = array(); |
| 2641 | 2641 | |
| 2642 | - foreach ( $items as $index => $item ) { |
|
| 2642 | + foreach ($items as $index => $item) { |
|
| 2643 | 2643 | |
| 2644 | - if ( ! empty( $item['required'] ) ) { |
|
| 2644 | + if (!empty($item['required'])) { |
|
| 2645 | 2645 | continue; |
| 2646 | 2646 | } |
| 2647 | 2647 | |
| 2648 | - $title = sanitize_text_field( $item['title'] ); |
|
| 2649 | - $price = wpinv_price( wpinv_format_amount( (float) sanitize_text_field( $item['price'] ) ) ); |
|
| 2650 | - $options[ $item['id'] ] = "$title ($price)"; |
|
| 2648 | + $title = sanitize_text_field($item['title']); |
|
| 2649 | + $price = wpinv_price(wpinv_format_amount((float) sanitize_text_field($item['price']))); |
|
| 2650 | + $options[$item['id']] = "$title ($price)"; |
|
| 2651 | 2651 | |
| 2652 | - if ( ! isset( $selected_item ) ) { |
|
| 2653 | - $selected = array( $item['id'] ); |
|
| 2652 | + if (!isset($selected_item)) { |
|
| 2653 | + $selected = array($item['id']); |
|
| 2654 | 2654 | $selected_item = 1; |
| 2655 | 2655 | } |
| 2656 | 2656 | |
@@ -2677,31 +2677,31 @@ discard block |
||
| 2677 | 2677 | $tax = 0; |
| 2678 | 2678 | $sub_total = 0; |
| 2679 | 2679 | |
| 2680 | - foreach ( $items as $item ) { |
|
| 2680 | + foreach ($items as $item) { |
|
| 2681 | 2681 | |
| 2682 | 2682 | $class = 'col-8'; |
| 2683 | 2683 | $class2 = ''; |
| 2684 | 2684 | |
| 2685 | - if ( ! empty( $item['allow_quantities'] ) ) { |
|
| 2685 | + if (!empty($item['allow_quantities'])) { |
|
| 2686 | 2686 | $class = 'col-6 pt-2'; |
| 2687 | 2687 | $class2 = 'pt-2'; |
| 2688 | 2688 | } |
| 2689 | 2689 | |
| 2690 | - if ( ! empty( $item['custom_price'] ) ) { |
|
| 2690 | + if (!empty($item['custom_price'])) { |
|
| 2691 | 2691 | $class .= ' pt-2'; |
| 2692 | 2692 | } |
| 2693 | 2693 | |
| 2694 | 2694 | $class3 = 'd-none'; |
| 2695 | - $name = ''; |
|
| 2696 | - if ( ! empty( $item['required'] ) || ! isset( $totals_selected_select_item ) ) { |
|
| 2695 | + $name = ''; |
|
| 2696 | + if (!empty($item['required']) || !isset($totals_selected_select_item)) { |
|
| 2697 | 2697 | |
| 2698 | - $amount = floatval( $item['price'] ); |
|
| 2699 | - if ( wpinv_use_taxes() ) { |
|
| 2698 | + $amount = floatval($item['price']); |
|
| 2699 | + if (wpinv_use_taxes()) { |
|
| 2700 | 2700 | |
| 2701 | - $rate = wpinv_get_tax_rate( wpinv_get_default_country(), false, (int) $item['id'] ); |
|
| 2701 | + $rate = wpinv_get_tax_rate(wpinv_get_default_country(), false, (int) $item['id']); |
|
| 2702 | 2702 | |
| 2703 | - if ( wpinv_prices_include_tax() ) { |
|
| 2704 | - $pre_tax = ( $amount - $amount * $rate * 0.01 ); |
|
| 2703 | + if (wpinv_prices_include_tax()) { |
|
| 2704 | + $pre_tax = ($amount - $amount * $rate * 0.01); |
|
| 2705 | 2705 | $item_tax = $amount - $pre_tax; |
| 2706 | 2706 | } else { |
| 2707 | 2707 | $pre_tax = $amount; |
@@ -2713,13 +2713,13 @@ discard block |
||
| 2713 | 2713 | $total = $sub_total + $tax; |
| 2714 | 2714 | |
| 2715 | 2715 | } else { |
| 2716 | - $total = $total + $amount; |
|
| 2716 | + $total = $total + $amount; |
|
| 2717 | 2717 | } |
| 2718 | 2718 | |
| 2719 | 2719 | $class3 = ''; |
| 2720 | - $name = "wpinv-items[{$item['id']}]"; |
|
| 2720 | + $name = "wpinv-items[{$item['id']}]"; |
|
| 2721 | 2721 | |
| 2722 | - if ( empty( $item['required'] ) ) { |
|
| 2722 | + if (empty($item['required'])) { |
|
| 2723 | 2723 | $totals_selected_select_item = 1; |
| 2724 | 2724 | } |
| 2725 | 2725 | |
@@ -2731,9 +2731,9 @@ discard block |
||
| 2731 | 2731 | |
| 2732 | 2732 | <div class="item_totals_item <?php echo $class3; ?>" data-id="<?php echo (int) $item['id']; ?>"> |
| 2733 | 2733 | <div class='row pl-2 pr-2 pt-2'> |
| 2734 | - <div class='<?php echo $class; ?>'><?php echo sanitize_text_field( $item['title'] ) ?></div> |
|
| 2734 | + <div class='<?php echo $class; ?>'><?php echo sanitize_text_field($item['title']) ?></div> |
|
| 2735 | 2735 | |
| 2736 | - <?php if ( ! empty( $item['allow_quantities'] ) ) { ?> |
|
| 2736 | + <?php if (!empty($item['allow_quantities'])) { ?> |
|
| 2737 | 2737 | |
| 2738 | 2738 | <div class='col-2'> |
| 2739 | 2739 | <input name='wpinv-item-<?php echo (int) $item['id']; ?>-quantity' type='number' class='form-control wpinv-item-quantity-input pr-1' value='1' min='1' required> |
@@ -2741,11 +2741,11 @@ discard block |
||
| 2741 | 2741 | |
| 2742 | 2742 | <?php } else { ?> |
| 2743 | 2743 | <input type='hidden' class='wpinv-item-quantity-input' value='1'> |
| 2744 | - <?php } if ( empty( $item['custom_price'] ) ) { ?> |
|
| 2744 | + <?php } if (empty($item['custom_price'])) { ?> |
|
| 2745 | 2745 | |
| 2746 | 2746 | <div class='col-4 <?php echo $class2; ?>'> |
| 2747 | - <?php echo wpinv_price( wpinv_format_amount( $item['price'] ) ) ?> |
|
| 2748 | - <input name='<?php echo $name; ?>' type='hidden' class='wpinv-item-price-input' value='<?php echo floatval( $item['price'] ); ?>'> |
|
| 2747 | + <?php echo wpinv_price(wpinv_format_amount($item['price'])) ?> |
|
| 2748 | + <input name='<?php echo $name; ?>' type='hidden' class='wpinv-item-price-input' value='<?php echo floatval($item['price']); ?>'> |
|
| 2749 | 2749 | </div> |
| 2750 | 2750 | |
| 2751 | 2751 | <?php } else {?> |
@@ -2753,15 +2753,15 @@ discard block |
||
| 2753 | 2753 | <div class='col-4'> |
| 2754 | 2754 | <div class='input-group'> |
| 2755 | 2755 | |
| 2756 | - <?php if ( 'left' == wpinv_currency_position() ) { ?> |
|
| 2756 | + <?php if ('left' == wpinv_currency_position()) { ?> |
|
| 2757 | 2757 | <div class='input-group-prepend'> |
| 2758 | 2758 | <span class='input-group-text'><?php echo wpinv_currency_symbol(); ?></span> |
| 2759 | 2759 | </div> |
| 2760 | 2760 | <?php } ?> |
| 2761 | 2761 | |
| 2762 | - <input type='text' name='<?php echo $name; ?>' class='form-control wpinv-item-price-input' placeholder='<?php echo floatval( $item['price'] ); ?>' value='<?php echo floatval( $item['price'] ); ?>' min='<?php echo intval( $item['minimum_price'] ); ?>'> |
|
| 2762 | + <input type='text' name='<?php echo $name; ?>' class='form-control wpinv-item-price-input' placeholder='<?php echo floatval($item['price']); ?>' value='<?php echo floatval($item['price']); ?>' min='<?php echo intval($item['minimum_price']); ?>'> |
|
| 2763 | 2763 | |
| 2764 | - <?php if ( 'left' != wpinv_currency_position() ) { ?> |
|
| 2764 | + <?php if ('left' != wpinv_currency_position()) { ?> |
|
| 2765 | 2765 | <div class='input-group-append'> |
| 2766 | 2766 | <span class='input-group-text'><?php echo wpinv_currency_symbol(); ?></span> |
| 2767 | 2767 | </div> |
@@ -2772,8 +2772,8 @@ discard block |
||
| 2772 | 2772 | <?php } ?> |
| 2773 | 2773 | |
| 2774 | 2774 | </div> |
| 2775 | - <?php if ( ! empty( $item['description'] )) { ?> |
|
| 2776 | - <small class='form-text text-muted pl-2 pr-2 m-0'><?php echo wp_kses_post( $item['description'] ); ?></small> |
|
| 2775 | + <?php if (!empty($item['description'])) { ?> |
|
| 2776 | + <small class='form-text text-muted pl-2 pr-2 m-0'><?php echo wp_kses_post($item['description']); ?></small> |
|
| 2777 | 2777 | <?php } ?> |
| 2778 | 2778 | </div> |
| 2779 | 2779 | <?php } ?> |
@@ -2781,32 +2781,32 @@ discard block |
||
| 2781 | 2781 | <div class='mt-4 border-top item_totals_total p-2'> |
| 2782 | 2782 | |
| 2783 | 2783 | <div class='row'> |
| 2784 | - <div class='col-8'><strong class='mr-5'><?php _e( 'Sub Total', 'invoicing' ); ?></strong></div> |
|
| 2785 | - <div class='col-4'><strong class='wpinv-items-sub-total'><?php echo wpinv_price( wpinv_format_amount( $sub_total ) ) ?></strong></div> |
|
| 2784 | + <div class='col-8'><strong class='mr-5'><?php _e('Sub Total', 'invoicing'); ?></strong></div> |
|
| 2785 | + <div class='col-4'><strong class='wpinv-items-sub-total'><?php echo wpinv_price(wpinv_format_amount($sub_total)) ?></strong></div> |
|
| 2786 | 2786 | </div> |
| 2787 | 2787 | |
| 2788 | 2788 | <div class='row' style='display: none;'> |
| 2789 | - <div class='col-8'><strong class='mr-5'><?php _e( 'Discount', 'invoicing' ); ?></strong></div> |
|
| 2790 | - <div class='col-4'><strong class='wpinv-items-discount'><?php echo wpinv_price( wpinv_format_amount( 0 ) ) ?></strong></div> |
|
| 2789 | + <div class='col-8'><strong class='mr-5'><?php _e('Discount', 'invoicing'); ?></strong></div> |
|
| 2790 | + <div class='col-4'><strong class='wpinv-items-discount'><?php echo wpinv_price(wpinv_format_amount(0)) ?></strong></div> |
|
| 2791 | 2791 | </div> |
| 2792 | 2792 | |
| 2793 | - <?php if ( wpinv_use_taxes() ) { ?> |
|
| 2793 | + <?php if (wpinv_use_taxes()) { ?> |
|
| 2794 | 2794 | <div class='row'> |
| 2795 | - <div class='col-8'><strong class='mr-5'><?php _e( 'Tax', 'invoicing' ); ?></strong></div> |
|
| 2796 | - <div class='col-4'><strong class='wpinv-items-tax' ><?php echo wpinv_price( wpinv_format_amount( $tax ) ) ?></strong></div> |
|
| 2795 | + <div class='col-8'><strong class='mr-5'><?php _e('Tax', 'invoicing'); ?></strong></div> |
|
| 2796 | + <div class='col-4'><strong class='wpinv-items-tax' ><?php echo wpinv_price(wpinv_format_amount($tax)) ?></strong></div> |
|
| 2797 | 2797 | </div> |
| 2798 | 2798 | <?php } ?> |
| 2799 | 2799 | |
| 2800 | 2800 | <div class='row'> |
| 2801 | - <div class='col-8'><strong class='mr-5'><?php _e( 'Total', 'invoicing' ); ?></strong></div> |
|
| 2802 | - <div class='col-4'><strong class='wpinv-items-total' data-currency='<?php echo wpinv_currency_symbol(); ?>' data-currency-position='<?php echo wpinv_currency_position(); ?>'><?php echo wpinv_price( wpinv_format_amount( $total ) ) ?></strong></div> |
|
| 2801 | + <div class='col-8'><strong class='mr-5'><?php _e('Total', 'invoicing'); ?></strong></div> |
|
| 2802 | + <div class='col-4'><strong class='wpinv-items-total' data-currency='<?php echo wpinv_currency_symbol(); ?>' data-currency-position='<?php echo wpinv_currency_position(); ?>'><?php echo wpinv_price(wpinv_format_amount($total)) ?></strong></div> |
|
| 2803 | 2803 | </div> |
| 2804 | 2804 | </div> |
| 2805 | 2805 | |
| 2806 | 2806 | </div> |
| 2807 | 2807 | <?php } ?> |
| 2808 | - <?php if ( ! empty( $field[ 'description' ] ) ) { ?> |
|
| 2809 | - <small class='form-text text-muted'><?php echo wp_kses_post( $field[ 'description' ] ); ?></small> |
|
| 2808 | + <?php if (!empty($field['description'])) { ?> |
|
| 2809 | + <small class='form-text text-muted'><?php echo wp_kses_post($field['description']); ?></small> |
|
| 2810 | 2810 | <?php } ?> |
| 2811 | 2811 | </div> |
| 2812 | 2812 | <?php |
@@ -2815,57 +2815,57 @@ discard block |
||
| 2815 | 2815 | /** |
| 2816 | 2816 | * Renders the items element template. |
| 2817 | 2817 | */ |
| 2818 | - public function edit_items_template( $field ) { |
|
| 2818 | + public function edit_items_template($field) { |
|
| 2819 | 2819 | global $wpinv_euvat, $post; |
| 2820 | 2820 | |
| 2821 | - $restrict = $this->get_restrict_markup( $field, 'items' ); |
|
| 2822 | - $label = __( 'Let customers...', 'invoicing' ); |
|
| 2823 | - $label2 = __( 'Available Items', 'invoicing' ); |
|
| 2824 | - $label3 = esc_attr__( 'Add some help text for this element', 'invoicing' ); |
|
| 2821 | + $restrict = $this->get_restrict_markup($field, 'items'); |
|
| 2822 | + $label = __('Let customers...', 'invoicing'); |
|
| 2823 | + $label2 = __('Available Items', 'invoicing'); |
|
| 2824 | + $label3 = esc_attr__('Add some help text for this element', 'invoicing'); |
|
| 2825 | 2825 | $id = $field . '.id + "_edit"'; |
| 2826 | 2826 | $id2 = $field . '.id + "_edit2"'; |
| 2827 | 2827 | $id3 = $field . '.id + "_edit3"'; |
| 2828 | 2828 | $id4 = $field . '.id + "_edit4"'; |
| 2829 | - $label4 = esc_attr__( 'This will be shown to the customer as the recommended price', 'invoicing' ); |
|
| 2830 | - $label5 = esc_attr__( 'Allow users to pay what they want', 'invoicing' ); |
|
| 2831 | - $label6 = esc_attr__( 'Enter the minimum price that a user can pay', 'invoicing' ); |
|
| 2832 | - $label7 = esc_attr__( 'Allow users to buy several quantities', 'invoicing' ); |
|
| 2833 | - $label8 = esc_attr__( 'This item is required', 'invoicing' ); |
|
| 2829 | + $label4 = esc_attr__('This will be shown to the customer as the recommended price', 'invoicing'); |
|
| 2830 | + $label5 = esc_attr__('Allow users to pay what they want', 'invoicing'); |
|
| 2831 | + $label6 = esc_attr__('Enter the minimum price that a user can pay', 'invoicing'); |
|
| 2832 | + $label7 = esc_attr__('Allow users to buy several quantities', 'invoicing'); |
|
| 2833 | + $label8 = esc_attr__('This item is required', 'invoicing'); |
|
| 2834 | 2834 | |
| 2835 | 2835 | // Item types. |
| 2836 | - $item_types = apply_filters( 'wpinv_item_types_for_quick_add_item', wpinv_get_item_types(), $post ); |
|
| 2836 | + $item_types = apply_filters('wpinv_item_types_for_quick_add_item', wpinv_get_item_types(), $post); |
|
| 2837 | 2837 | $item_types_html = ''; |
| 2838 | 2838 | |
| 2839 | - foreach ( $item_types as $type => $_label ) { |
|
| 2840 | - $type = esc_attr( $type ); |
|
| 2841 | - $_label = esc_html( $_label ); |
|
| 2839 | + foreach ($item_types as $type => $_label) { |
|
| 2840 | + $type = esc_attr($type); |
|
| 2841 | + $_label = esc_html($_label); |
|
| 2842 | 2842 | $item_types_html .= "<option value='$type'>$_label</type>"; |
| 2843 | 2843 | } |
| 2844 | 2844 | |
| 2845 | 2845 | // Taxes. |
| 2846 | 2846 | $taxes = ''; |
| 2847 | - if ( $wpinv_euvat->allow_vat_rules() ) { |
|
| 2847 | + if ($wpinv_euvat->allow_vat_rules()) { |
|
| 2848 | 2848 | $taxes .= "<div class='form-group'> <label :for='$id + item.id + \"rule\"'>"; |
| 2849 | - $taxes .= __( 'VAT rule type', 'invoicing' ); |
|
| 2849 | + $taxes .= __('VAT rule type', 'invoicing'); |
|
| 2850 | 2850 | $taxes .= "</label><select :id='$id + item.id + \"rule\"' class='form-control custom-select' v-model='item.rule'>"; |
| 2851 | 2851 | |
| 2852 | - foreach ( $wpinv_euvat->get_rules() as $type => $_label ) { |
|
| 2853 | - $type = esc_attr( $type ); |
|
| 2854 | - $_label = esc_html( $_label ); |
|
| 2852 | + foreach ($wpinv_euvat->get_rules() as $type => $_label) { |
|
| 2853 | + $type = esc_attr($type); |
|
| 2854 | + $_label = esc_html($_label); |
|
| 2855 | 2855 | $taxes .= "<option value='$type'>$_label</type>"; |
| 2856 | 2856 | } |
| 2857 | 2857 | |
| 2858 | 2858 | $taxes .= '</select></div>'; |
| 2859 | 2859 | } |
| 2860 | 2860 | |
| 2861 | - if ( $wpinv_euvat->allow_vat_classes() ) { |
|
| 2861 | + if ($wpinv_euvat->allow_vat_classes()) { |
|
| 2862 | 2862 | $taxes .= "<div class='form-group'> <label :for='$id + item.id + \"class\"'>"; |
| 2863 | - $taxes .= __( 'VAT class', 'invoicing' ); |
|
| 2863 | + $taxes .= __('VAT class', 'invoicing'); |
|
| 2864 | 2864 | $taxes .= "</label><select :id='$id + item.id + \"class\"' class='form-control custom-select' v-model='item.class'>"; |
| 2865 | 2865 | |
| 2866 | - foreach ( $wpinv_euvat->get_all_classes() as $type => $_label ) { |
|
| 2867 | - $type = esc_attr( $type ); |
|
| 2868 | - $_label = esc_html( $_label ); |
|
| 2866 | + foreach ($wpinv_euvat->get_all_classes() as $type => $_label) { |
|
| 2867 | + $type = esc_attr($type); |
|
| 2868 | + $_label = esc_html($_label); |
|
| 2869 | 2869 | $taxes .= "<option value='$type'>$_label</type>"; |
| 2870 | 2870 | } |
| 2871 | 2871 | |
@@ -2950,7 +2950,7 @@ discard block |
||
| 2950 | 2950 | <div class='form-group mt-2' v-if='!is_default'> |
| 2951 | 2951 | |
| 2952 | 2952 | <select class='form-control custom-select' v-model='selected_item' @change='addSelectedItem'> |
| 2953 | - <option value=''>" . __( 'Add an existing item to the form', 'invoicing' ) ."</option> |
|
| 2953 | + <option value=''>" . __('Add an existing item to the form', 'invoicing') . "</option> |
|
| 2954 | 2954 | <option v-for='(item, index) in all_items' :value='index'>{{item.title}}</option> |
| 2955 | 2955 | </select> |
| 2956 | 2956 | |
@@ -2965,11 +2965,11 @@ discard block |
||
| 2965 | 2965 | <label :for='$id2'>$label</label> |
| 2966 | 2966 | |
| 2967 | 2967 | <select class='form-control custom-select' :id='$id2' v-model='$field.items_type'> |
| 2968 | - <option value='total' :disabled='canCheckoutSeveralSubscriptions($field)'>" . __( 'Buy all items on the list', 'invoicing' ) ."</option> |
|
| 2969 | - <option value='radio'>" . __( 'Select a single item from the list', 'invoicing' ) ."</option> |
|
| 2970 | - <option value='checkbox' :disabled='canCheckoutSeveralSubscriptions($field)'>" . __( 'Select one or more items on the list', 'invoicing' ) ."</option> |
|
| 2971 | - <option value='select'>" . __( 'Select a single item from a dropdown', 'invoicing' ) ."</option> |
|
| 2972 | - <option value='multi_select' :disabled='canCheckoutSeveralSubscriptions($field)'>" . __( 'Select a one or more items from a dropdown', 'invoicing' ) ."</option> |
|
| 2968 | + <option value='total' :disabled='canCheckoutSeveralSubscriptions($field)'>" . __('Buy all items on the list', 'invoicing') . "</option> |
|
| 2969 | + <option value='radio'>" . __('Select a single item from the list', 'invoicing') . "</option> |
|
| 2970 | + <option value='checkbox' :disabled='canCheckoutSeveralSubscriptions($field)'>" . __('Select one or more items on the list', 'invoicing') . "</option> |
|
| 2971 | + <option value='select'>" . __('Select a single item from a dropdown', 'invoicing') . "</option> |
|
| 2972 | + <option value='multi_select' :disabled='canCheckoutSeveralSubscriptions($field)'>" . __('Select a one or more items from a dropdown', 'invoicing') . "</option> |
|
| 2973 | 2973 | </select> |
| 2974 | 2974 | |
| 2975 | 2975 | </div> |
@@ -2994,7 +2994,7 @@ discard block |
||
| 2994 | 2994 | 'orderby' => 'title', |
| 2995 | 2995 | 'order' => 'ASC', |
| 2996 | 2996 | 'posts_per_page' => -1, |
| 2997 | - 'post_status' => array( 'publish' ), |
|
| 2997 | + 'post_status' => array('publish'), |
|
| 2998 | 2998 | 'meta_query' => array( |
| 2999 | 2999 | array( |
| 3000 | 3000 | 'key' => '_wpinv_type', |
@@ -3004,24 +3004,24 @@ discard block |
||
| 3004 | 3004 | ) |
| 3005 | 3005 | ); |
| 3006 | 3006 | |
| 3007 | - $items = get_posts( apply_filters( 'wpinv_payment_form_item_dropdown_query_args', $item_args ) ); |
|
| 3007 | + $items = get_posts(apply_filters('wpinv_payment_form_item_dropdown_query_args', $item_args)); |
|
| 3008 | 3008 | |
| 3009 | - if ( empty( $items ) ) { |
|
| 3009 | + if (empty($items)) { |
|
| 3010 | 3010 | return array(); |
| 3011 | 3011 | } |
| 3012 | 3012 | |
| 3013 | - $options = array(); |
|
| 3014 | - foreach ( $items as $item ) { |
|
| 3015 | - $title = esc_html( $item->post_title ); |
|
| 3016 | - $title .= wpinv_get_item_suffix( $item->ID, false ); |
|
| 3017 | - $id = absint( $item->ID ); |
|
| 3018 | - $price = wpinv_sanitize_amount( get_post_meta( $id, '_wpinv_price', true ) ); |
|
| 3019 | - $recurring = (bool) get_post_meta( $id, '_wpinv_is_recurring', true ); |
|
| 3013 | + $options = array(); |
|
| 3014 | + foreach ($items as $item) { |
|
| 3015 | + $title = esc_html($item->post_title); |
|
| 3016 | + $title .= wpinv_get_item_suffix($item->ID, false); |
|
| 3017 | + $id = absint($item->ID); |
|
| 3018 | + $price = wpinv_sanitize_amount(get_post_meta($id, '_wpinv_price', true)); |
|
| 3019 | + $recurring = (bool) get_post_meta($id, '_wpinv_is_recurring', true); |
|
| 3020 | 3020 | $description = $item->post_excerpt; |
| 3021 | - $custom_price = (bool) get_post_meta( $id, '_wpinv_dynamic_pricing', true ); |
|
| 3022 | - $minimum_price = (float) get_post_meta( $id, '_minimum_price', true ); |
|
| 3021 | + $custom_price = (bool) get_post_meta($id, '_wpinv_dynamic_pricing', true); |
|
| 3022 | + $minimum_price = (float) get_post_meta($id, '_minimum_price', true); |
|
| 3023 | 3023 | $allow_quantities = false; |
| 3024 | - $options[] = compact( 'title', 'id', 'price', 'recurring', 'description', 'custom_price', 'minimum_price', 'allow_quantities' ); |
|
| 3024 | + $options[] = compact('title', 'id', 'price', 'recurring', 'description', 'custom_price', 'minimum_price', 'allow_quantities'); |
|
| 3025 | 3025 | |
| 3026 | 3026 | } |
| 3027 | 3027 | return $options; |
@@ -3031,44 +3031,44 @@ discard block |
||
| 3031 | 3031 | /** |
| 3032 | 3032 | * Returns an array of items for the currently being edited form. |
| 3033 | 3033 | */ |
| 3034 | - public function get_form_items( $id = false ) { |
|
| 3034 | + public function get_form_items($id = false) { |
|
| 3035 | 3035 | |
| 3036 | - if ( empty( $id ) ) { |
|
| 3037 | - return wpinv_get_data( 'sample-payment-form-items' ); |
|
| 3036 | + if (empty($id)) { |
|
| 3037 | + return wpinv_get_data('sample-payment-form-items'); |
|
| 3038 | 3038 | } |
| 3039 | 3039 | |
| 3040 | - $form_elements = get_post_meta( $id, 'wpinv_form_items', true ); |
|
| 3040 | + $form_elements = get_post_meta($id, 'wpinv_form_items', true); |
|
| 3041 | 3041 | |
| 3042 | - if ( is_array( $form_elements ) ) { |
|
| 3042 | + if (is_array($form_elements)) { |
|
| 3043 | 3043 | return $form_elements; |
| 3044 | 3044 | } |
| 3045 | 3045 | |
| 3046 | - return wpinv_get_data( 'sample-payment-form-items' ); |
|
| 3046 | + return wpinv_get_data('sample-payment-form-items'); |
|
| 3047 | 3047 | |
| 3048 | 3048 | } |
| 3049 | 3049 | |
| 3050 | 3050 | /** |
| 3051 | 3051 | * Converts form items for use. |
| 3052 | 3052 | */ |
| 3053 | - public function convert_checkout_items( $items, $invoice ) { |
|
| 3053 | + public function convert_checkout_items($items, $invoice) { |
|
| 3054 | 3054 | |
| 3055 | 3055 | $converted = array(); |
| 3056 | - foreach ( $items as $item ) { |
|
| 3056 | + foreach ($items as $item) { |
|
| 3057 | 3057 | |
| 3058 | 3058 | $item_id = $item['id']; |
| 3059 | - $_item = new WPInv_Item( $item_id ); |
|
| 3059 | + $_item = new WPInv_Item($item_id); |
|
| 3060 | 3060 | |
| 3061 | - if( ! $_item ) { |
|
| 3061 | + if (!$_item) { |
|
| 3062 | 3062 | continue; |
| 3063 | 3063 | } |
| 3064 | 3064 | |
| 3065 | 3065 | $converted[] = array( |
| 3066 | - 'title' => esc_html( wpinv_get_cart_item_name( $item ) ) . wpinv_get_item_suffix( $_item ), |
|
| 3066 | + 'title' => esc_html(wpinv_get_cart_item_name($item)) . wpinv_get_item_suffix($_item), |
|
| 3067 | 3067 | 'id' => $item['id'], |
| 3068 | 3068 | 'price' => $item['subtotal'], |
| 3069 | 3069 | 'custom_price' => $_item->get_is_dynamic_pricing(), |
| 3070 | 3070 | 'recurring' => $_item->is_recurring(), |
| 3071 | - 'description' => apply_filters( 'wpinv_checkout_cart_line_item_summary', '', $item, $_item, $invoice ), |
|
| 3071 | + 'description' => apply_filters('wpinv_checkout_cart_line_item_summary', '', $item, $_item, $invoice), |
|
| 3072 | 3072 | 'minimum_price' => $_item->get_minimum_price(), |
| 3073 | 3073 | 'allow_quantities' => false, |
| 3074 | 3074 | 'quantity' => $item['quantity'], |
@@ -3082,27 +3082,27 @@ discard block |
||
| 3082 | 3082 | /** |
| 3083 | 3083 | * Converts an array of id => quantity for use. |
| 3084 | 3084 | */ |
| 3085 | - public function convert_normal_items( $items ) { |
|
| 3085 | + public function convert_normal_items($items) { |
|
| 3086 | 3086 | |
| 3087 | 3087 | $converted = array(); |
| 3088 | - foreach ( $items as $item_id => $quantity ) { |
|
| 3088 | + foreach ($items as $item_id => $quantity) { |
|
| 3089 | 3089 | |
| 3090 | - $item = new WPInv_Item( $item_id ); |
|
| 3090 | + $item = new WPInv_Item($item_id); |
|
| 3091 | 3091 | |
| 3092 | - if( ! $item ) { |
|
| 3092 | + if (!$item) { |
|
| 3093 | 3093 | continue; |
| 3094 | 3094 | } |
| 3095 | 3095 | |
| 3096 | 3096 | $converted[] = array( |
| 3097 | - 'title' => esc_html( $item->get_name() ) . wpinv_get_item_suffix( $item ), |
|
| 3097 | + 'title' => esc_html($item->get_name()) . wpinv_get_item_suffix($item), |
|
| 3098 | 3098 | 'id' => $item_id, |
| 3099 | 3099 | 'price' => $item->get_price(), |
| 3100 | 3100 | 'custom_price' => $item->get_is_dynamic_pricing(), |
| 3101 | 3101 | 'recurring' => $item->is_recurring(), |
| 3102 | 3102 | 'description' => $item->get_summary(), |
| 3103 | 3103 | 'minimum_price' => $item->get_minimum_price(), |
| 3104 | - 'allow_quantities' => ! empty( $quantity ), |
|
| 3105 | - 'quantity' => empty( $quantity ) ? 1 : $quantity, |
|
| 3104 | + 'allow_quantities' => !empty($quantity), |
|
| 3105 | + 'quantity' => empty($quantity) ? 1 : $quantity, |
|
| 3106 | 3106 | 'required' => true, |
| 3107 | 3107 | ); |
| 3108 | 3108 | |
@@ -3115,28 +3115,28 @@ discard block |
||
| 3115 | 3115 | /** |
| 3116 | 3116 | * Returns an array of elements for the currently being edited form. |
| 3117 | 3117 | */ |
| 3118 | - public function get_form_elements( $id = false ) { |
|
| 3118 | + public function get_form_elements($id = false) { |
|
| 3119 | 3119 | |
| 3120 | - if ( empty( $id ) ) { |
|
| 3121 | - return wpinv_get_data( 'sample-payment-form' ); |
|
| 3120 | + if (empty($id)) { |
|
| 3121 | + return wpinv_get_data('sample-payment-form'); |
|
| 3122 | 3122 | } |
| 3123 | 3123 | |
| 3124 | - $form_elements = get_post_meta( $id, 'wpinv_form_elements', true ); |
|
| 3124 | + $form_elements = get_post_meta($id, 'wpinv_form_elements', true); |
|
| 3125 | 3125 | |
| 3126 | - if ( is_array( $form_elements ) ) { |
|
| 3126 | + if (is_array($form_elements)) { |
|
| 3127 | 3127 | return $form_elements; |
| 3128 | 3128 | } |
| 3129 | 3129 | |
| 3130 | - return wpinv_get_data( 'sample-payment-form' ); |
|
| 3130 | + return wpinv_get_data('sample-payment-form'); |
|
| 3131 | 3131 | } |
| 3132 | 3132 | |
| 3133 | 3133 | /** |
| 3134 | 3134 | * Sends a redrect response to payment details. |
| 3135 | 3135 | * |
| 3136 | 3136 | */ |
| 3137 | - public function send_redirect_response( $url ) { |
|
| 3138 | - $url = urlencode( $url ); |
|
| 3139 | - wp_send_json_success( $url ); |
|
| 3137 | + public function send_redirect_response($url) { |
|
| 3138 | + $url = urlencode($url); |
|
| 3139 | + wp_send_json_success($url); |
|
| 3140 | 3140 | } |
| 3141 | 3141 | |
| 3142 | 3142 | /** |
@@ -3147,12 +3147,12 @@ discard block |
||
| 3147 | 3147 | |
| 3148 | 3148 | $errors = wpinv_get_errors(); |
| 3149 | 3149 | |
| 3150 | - if ( ! empty( $errors ) ) { |
|
| 3150 | + if (!empty($errors)) { |
|
| 3151 | 3151 | wpinv_print_errors(); |
| 3152 | 3152 | exit; |
| 3153 | 3153 | } |
| 3154 | 3154 | |
| 3155 | - wp_send_json_error( __( 'An error occured while processing your payment. Please try again.', 'invoicing' ) ); |
|
| 3155 | + wp_send_json_error(__('An error occured while processing your payment. Please try again.', 'invoicing')); |
|
| 3156 | 3156 | exit; |
| 3157 | 3157 | |
| 3158 | 3158 | } |
@@ -700,7 +700,7 @@ discard block |
||
| 700 | 700 | } |
| 701 | 701 | |
| 702 | 702 | function wpinv_get_payment_key( $invoice_id = 0 ) { |
| 703 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
| 703 | + $invoice = new WPInv_Invoice( $invoice_id ); |
|
| 704 | 704 | return $invoice->get_key(); |
| 705 | 705 | } |
| 706 | 706 | |
@@ -966,7 +966,7 @@ discard block |
||
| 966 | 966 | return false; |
| 967 | 967 | } |
| 968 | 968 | $invoice = wpinv_get_invoice_cart(); |
| 969 | - if ( empty( $invoice ) ) { |
|
| 969 | + if ( empty( $invoice ) ) { |
|
| 970 | 970 | return false; |
| 971 | 971 | } |
| 972 | 972 | |
@@ -1259,20 +1259,20 @@ discard block |
||
| 1259 | 1259 | } |
| 1260 | 1260 | |
| 1261 | 1261 | function wpinv_checkout_get_cc_info() { |
| 1262 | - $cc_info = array(); |
|
| 1263 | - $cc_info['card_name'] = isset( $_POST['card_name'] ) ? sanitize_text_field( $_POST['card_name'] ) : ''; |
|
| 1264 | - $cc_info['card_number'] = isset( $_POST['card_number'] ) ? sanitize_text_field( $_POST['card_number'] ) : ''; |
|
| 1265 | - $cc_info['card_cvc'] = isset( $_POST['card_cvc'] ) ? sanitize_text_field( $_POST['card_cvc'] ) : ''; |
|
| 1266 | - $cc_info['card_exp_month'] = isset( $_POST['card_exp_month'] ) ? sanitize_text_field( $_POST['card_exp_month'] ) : ''; |
|
| 1267 | - $cc_info['card_exp_year'] = isset( $_POST['card_exp_year'] ) ? sanitize_text_field( $_POST['card_exp_year'] ) : ''; |
|
| 1268 | - $cc_info['card_address'] = isset( $_POST['wpinv_address'] ) ? sanitize_text_field( $_POST['wpinv_address'] ) : ''; |
|
| 1269 | - $cc_info['card_city'] = isset( $_POST['wpinv_city'] ) ? sanitize_text_field( $_POST['wpinv_city'] ) : ''; |
|
| 1270 | - $cc_info['card_state'] = isset( $_POST['wpinv_state'] ) ? sanitize_text_field( $_POST['wpinv_state'] ) : ''; |
|
| 1271 | - $cc_info['card_country'] = isset( $_POST['wpinv_country'] ) ? sanitize_text_field( $_POST['wpinv_country'] ) : ''; |
|
| 1272 | - $cc_info['card_zip'] = isset( $_POST['wpinv_zip'] ) ? sanitize_text_field( $_POST['wpinv_zip'] ) : ''; |
|
| 1273 | - |
|
| 1274 | - // Return cc info |
|
| 1275 | - return $cc_info; |
|
| 1262 | + $cc_info = array(); |
|
| 1263 | + $cc_info['card_name'] = isset( $_POST['card_name'] ) ? sanitize_text_field( $_POST['card_name'] ) : ''; |
|
| 1264 | + $cc_info['card_number'] = isset( $_POST['card_number'] ) ? sanitize_text_field( $_POST['card_number'] ) : ''; |
|
| 1265 | + $cc_info['card_cvc'] = isset( $_POST['card_cvc'] ) ? sanitize_text_field( $_POST['card_cvc'] ) : ''; |
|
| 1266 | + $cc_info['card_exp_month'] = isset( $_POST['card_exp_month'] ) ? sanitize_text_field( $_POST['card_exp_month'] ) : ''; |
|
| 1267 | + $cc_info['card_exp_year'] = isset( $_POST['card_exp_year'] ) ? sanitize_text_field( $_POST['card_exp_year'] ) : ''; |
|
| 1268 | + $cc_info['card_address'] = isset( $_POST['wpinv_address'] ) ? sanitize_text_field( $_POST['wpinv_address'] ) : ''; |
|
| 1269 | + $cc_info['card_city'] = isset( $_POST['wpinv_city'] ) ? sanitize_text_field( $_POST['wpinv_city'] ) : ''; |
|
| 1270 | + $cc_info['card_state'] = isset( $_POST['wpinv_state'] ) ? sanitize_text_field( $_POST['wpinv_state'] ) : ''; |
|
| 1271 | + $cc_info['card_country'] = isset( $_POST['wpinv_country'] ) ? sanitize_text_field( $_POST['wpinv_country'] ) : ''; |
|
| 1272 | + $cc_info['card_zip'] = isset( $_POST['wpinv_zip'] ) ? sanitize_text_field( $_POST['wpinv_zip'] ) : ''; |
|
| 1273 | + |
|
| 1274 | + // Return cc info |
|
| 1275 | + return $cc_info; |
|
| 1276 | 1276 | } |
| 1277 | 1277 | |
| 1278 | 1278 | function wpinv_checkout_validate_cc_zip( $zip = 0, $country_code = '' ) { |
@@ -1479,7 +1479,7 @@ discard block |
||
| 1479 | 1479 | $required_fields = wpinv_checkout_required_fields(); |
| 1480 | 1480 | |
| 1481 | 1481 | // Loop through required fields and show error messages |
| 1482 | - if ( !empty( $required_fields ) ) { |
|
| 1482 | + if ( !empty( $required_fields ) ) { |
|
| 1483 | 1483 | foreach ( $required_fields as $field_name => $value ) { |
| 1484 | 1484 | if ( in_array( $value, $required_fields ) && empty( $_POST[ 'wpinv_' . $field_name ] ) ) { |
| 1485 | 1485 | wpinv_set_error( $value['error_id'], $value['error_message'] ); |
@@ -1582,7 +1582,7 @@ discard block |
||
| 1582 | 1582 | } |
| 1583 | 1583 | |
| 1584 | 1584 | function wpinv_get_checkout_session() { |
| 1585 | - global $wpi_session; |
|
| 1585 | + global $wpi_session; |
|
| 1586 | 1586 | |
| 1587 | 1587 | return $wpi_session->get( 'wpinv_checkout' ); |
| 1588 | 1588 | } |
@@ -1663,7 +1663,7 @@ discard block |
||
| 1663 | 1663 | $response['data']['taxf'] = $invoice->get_tax( true ); |
| 1664 | 1664 | $response['data']['total'] = $invoice->get_total(); |
| 1665 | 1665 | $response['data']['totalf'] = $invoice->get_total( true ); |
| 1666 | - $response['data']['free'] = $invoice->is_free() && ( ! ( (float) $response['data']['total'] > 0 ) || $invoice->is_free_trial() ) ? true : false; |
|
| 1666 | + $response['data']['free'] = $invoice->is_free() && ( ! ( (float) $response['data']['total'] > 0 ) || $invoice->is_free_trial() ) ? true : false; |
|
| 1667 | 1667 | |
| 1668 | 1668 | wp_send_json( $response ); |
| 1669 | 1669 | } |
@@ -1733,8 +1733,8 @@ discard block |
||
| 1733 | 1733 | // Allow themes and plugins to hook before the gateway |
| 1734 | 1734 | do_action( 'wpinv_checkout_before_gateway', $_POST, $user_info, $valid_data ); |
| 1735 | 1735 | |
| 1736 | - // If it is free, abort. |
|
| 1737 | - if ( $invoice->is_free() && ( ! $invoice->is_recurring() || 0 == $invoice->get_recurring_details( 'total' ) ) ) { |
|
| 1736 | + // If it is free, abort. |
|
| 1737 | + if ( $invoice->is_free() && ( ! $invoice->is_recurring() || 0 == $invoice->get_recurring_details( 'total' ) ) ) { |
|
| 1738 | 1738 | $invoice_data['gateway'] = 'manual'; |
| 1739 | 1739 | $_POST['wpi-gateway'] = 'manual'; |
| 1740 | 1740 | } |
@@ -1949,52 +1949,52 @@ discard block |
||
| 1949 | 1949 | * Given an invoice key, this function returns the id. |
| 1950 | 1950 | */ |
| 1951 | 1951 | function wpinv_get_invoice_id_by_key( $key ) { |
| 1952 | - global $wpdb; |
|
| 1952 | + global $wpdb; |
|
| 1953 | 1953 | $table = $wpdb->prefix . 'getpaid_invoices'; |
| 1954 | - return (int) $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $table WHERE`key` = %s LIMIT 1", $key ) ); |
|
| 1954 | + return (int) $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $table WHERE`key` = %s LIMIT 1", $key ) ); |
|
| 1955 | 1955 | } |
| 1956 | 1956 | |
| 1957 | 1957 | function wpinv_can_view_receipt( $invoice_key = '' ) { |
| 1958 | - $return = false; |
|
| 1958 | + $return = false; |
|
| 1959 | 1959 | |
| 1960 | - if ( empty( $invoice_key ) ) { |
|
| 1961 | - return $return; |
|
| 1962 | - } |
|
| 1960 | + if ( empty( $invoice_key ) ) { |
|
| 1961 | + return $return; |
|
| 1962 | + } |
|
| 1963 | 1963 | |
| 1964 | - global $wpinv_receipt_args; |
|
| 1964 | + global $wpinv_receipt_args; |
|
| 1965 | 1965 | |
| 1966 | - $wpinv_receipt_args['id'] = wpinv_get_invoice_id_by_key( $invoice_key ); |
|
| 1967 | - if ( isset( $_GET['invoice-id'] ) ) { |
|
| 1968 | - $wpinv_receipt_args['id'] = $invoice_key == wpinv_get_payment_key( (int)$_GET['invoice-id'] ) ? (int)$_GET['invoice-id'] : 0; |
|
| 1969 | - } |
|
| 1966 | + $wpinv_receipt_args['id'] = wpinv_get_invoice_id_by_key( $invoice_key ); |
|
| 1967 | + if ( isset( $_GET['invoice-id'] ) ) { |
|
| 1968 | + $wpinv_receipt_args['id'] = $invoice_key == wpinv_get_payment_key( (int)$_GET['invoice-id'] ) ? (int)$_GET['invoice-id'] : 0; |
|
| 1969 | + } |
|
| 1970 | 1970 | |
| 1971 | - if ( empty( $wpinv_receipt_args['id'] ) ) { |
|
| 1972 | - return $return; |
|
| 1973 | - } |
|
| 1971 | + if ( empty( $wpinv_receipt_args['id'] ) ) { |
|
| 1972 | + return $return; |
|
| 1973 | + } |
|
| 1974 | 1974 | |
| 1975 | - $invoice = wpinv_get_invoice( $wpinv_receipt_args['id'] ); |
|
| 1976 | - if ( !( !empty( $invoice->ID ) && $invoice->get_key() === $invoice_key ) ) { |
|
| 1977 | - return $return; |
|
| 1978 | - } |
|
| 1975 | + $invoice = wpinv_get_invoice( $wpinv_receipt_args['id'] ); |
|
| 1976 | + if ( !( !empty( $invoice->ID ) && $invoice->get_key() === $invoice_key ) ) { |
|
| 1977 | + return $return; |
|
| 1978 | + } |
|
| 1979 | 1979 | |
| 1980 | - if ( is_user_logged_in() ) { |
|
| 1981 | - if ( (int)$invoice->get_user_id() === (int) get_current_user_id() ) { |
|
| 1982 | - $return = true; |
|
| 1983 | - } |
|
| 1984 | - } |
|
| 1980 | + if ( is_user_logged_in() ) { |
|
| 1981 | + if ( (int)$invoice->get_user_id() === (int) get_current_user_id() ) { |
|
| 1982 | + $return = true; |
|
| 1983 | + } |
|
| 1984 | + } |
|
| 1985 | 1985 | |
| 1986 | - $session = wpinv_get_checkout_session(); |
|
| 1987 | - if ( isset( $_GET['invoice_key'] ) || ( $session && isset( $session['invoice_key'] ) ) ) { |
|
| 1988 | - $check_key = isset( $_GET['invoice_key'] ) ? $_GET['invoice_key'] : $session['invoice_key']; |
|
| 1986 | + $session = wpinv_get_checkout_session(); |
|
| 1987 | + if ( isset( $_GET['invoice_key'] ) || ( $session && isset( $session['invoice_key'] ) ) ) { |
|
| 1988 | + $check_key = isset( $_GET['invoice_key'] ) ? $_GET['invoice_key'] : $session['invoice_key']; |
|
| 1989 | 1989 | |
| 1990 | - if ( wpinv_require_login_to_checkout() ) { |
|
| 1991 | - $return = $return && $check_key === $invoice_key; |
|
| 1992 | - } else { |
|
| 1993 | - $return = $check_key === $invoice_key; |
|
| 1994 | - } |
|
| 1995 | - } |
|
| 1990 | + if ( wpinv_require_login_to_checkout() ) { |
|
| 1991 | + $return = $return && $check_key === $invoice_key; |
|
| 1992 | + } else { |
|
| 1993 | + $return = $check_key === $invoice_key; |
|
| 1994 | + } |
|
| 1995 | + } |
|
| 1996 | 1996 | |
| 1997 | - return (bool) apply_filters( 'wpinv_can_view_receipt', $return, $invoice_key ); |
|
| 1997 | + return (bool) apply_filters( 'wpinv_can_view_receipt', $return, $invoice_key ); |
|
| 1998 | 1998 | } |
| 1999 | 1999 | |
| 2000 | 2000 | function wpinv_pay_for_invoice() { |
@@ -2304,14 +2304,14 @@ discard block |
||
| 2304 | 2304 | |
| 2305 | 2305 | if ( isset( $_GET['invoice_key'] ) || is_singular( 'wpi_invoice' ) || is_singular( 'wpi_quote' ) ) { |
| 2306 | 2306 | $invoice_key = isset( $_GET['invoice_key'] ) ? urldecode($_GET['invoice_key']) : ''; |
| 2307 | - global $post; |
|
| 2307 | + global $post; |
|
| 2308 | 2308 | |
| 2309 | 2309 | if(!empty($invoice_key)){ |
| 2310 | - $invoice_id = wpinv_get_invoice_id_by_key($invoice_key); |
|
| 2310 | + $invoice_id = wpinv_get_invoice_id_by_key($invoice_key); |
|
| 2311 | 2311 | } else if(!empty( $post ) && ($post->post_type == 'wpi_invoice' || $post->post_type == 'wpi_quote')) { |
| 2312 | - $invoice_id = $post->ID; |
|
| 2312 | + $invoice_id = $post->ID; |
|
| 2313 | 2313 | } else { |
| 2314 | - return; |
|
| 2314 | + return; |
|
| 2315 | 2315 | } |
| 2316 | 2316 | |
| 2317 | 2317 | $invoice = new WPInv_Invoice($invoice_id); |
@@ -2320,17 +2320,17 @@ discard block |
||
| 2320 | 2320 | return; |
| 2321 | 2321 | } |
| 2322 | 2322 | |
| 2323 | - if ( is_user_logged_in() ) { |
|
| 2324 | - if ( (int)$invoice->get_user_id() === get_current_user_id() ) { |
|
| 2325 | - update_post_meta($invoice_id,'_wpinv_is_viewed', 1); |
|
| 2326 | - } else if ( !wpinv_require_login_to_checkout() && isset( $_GET['invoice_key'] ) && $_GET['invoice_key'] === $invoice->get_key() ) { |
|
| 2327 | - update_post_meta($invoice_id,'_wpinv_is_viewed', 1); |
|
| 2328 | - } |
|
| 2329 | - } else { |
|
| 2330 | - if ( !wpinv_require_login_to_checkout() && isset( $_GET['invoice_key'] ) && $_GET['invoice_key'] === $invoice->get_key() ) { |
|
| 2331 | - update_post_meta($invoice_id,'_wpinv_is_viewed', 1); |
|
| 2332 | - } |
|
| 2333 | - } |
|
| 2323 | + if ( is_user_logged_in() ) { |
|
| 2324 | + if ( (int)$invoice->get_user_id() === get_current_user_id() ) { |
|
| 2325 | + update_post_meta($invoice_id,'_wpinv_is_viewed', 1); |
|
| 2326 | + } else if ( !wpinv_require_login_to_checkout() && isset( $_GET['invoice_key'] ) && $_GET['invoice_key'] === $invoice->get_key() ) { |
|
| 2327 | + update_post_meta($invoice_id,'_wpinv_is_viewed', 1); |
|
| 2328 | + } |
|
| 2329 | + } else { |
|
| 2330 | + if ( !wpinv_require_login_to_checkout() && isset( $_GET['invoice_key'] ) && $_GET['invoice_key'] === $invoice->get_key() ) { |
|
| 2331 | + update_post_meta($invoice_id,'_wpinv_is_viewed', 1); |
|
| 2332 | + } |
|
| 2333 | + } |
|
| 2334 | 2334 | } |
| 2335 | 2335 | |
| 2336 | 2336 | } |
@@ -7,14 +7,14 @@ discard block |
||
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | 9 | // MUST have WordPress. |
| 10 | -if ( !defined( 'WPINC' ) ) { |
|
| 11 | - exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) ); |
|
| 10 | +if (!defined('WPINC')) { |
|
| 11 | + exit('Do NOT access this file directly: ' . basename(__FILE__)); |
|
| 12 | 12 | } |
| 13 | 13 | |
| 14 | 14 | function wpinv_get_invoice_cart_id() { |
| 15 | 15 | $wpinv_checkout = wpinv_get_checkout_session(); |
| 16 | 16 | |
| 17 | - if ( !empty( $wpinv_checkout['invoice_id'] ) ) { |
|
| 17 | + if (!empty($wpinv_checkout['invoice_id'])) { |
|
| 18 | 18 | return $wpinv_checkout['invoice_id']; |
| 19 | 19 | } |
| 20 | 20 | |
@@ -28,48 +28,48 @@ discard block |
||
| 28 | 28 | * @param bool $wp_error Whether to return false or WP_Error on failure. |
| 29 | 29 | * @return int|WP_Error|WPInv_Invoice The value 0 or WP_Error on failure. The WPInv_Invoice object on success. |
| 30 | 30 | */ |
| 31 | -function wpinv_insert_invoice( $invoice_data = array(), $wp_error = false ) { |
|
| 32 | - if ( empty( $invoice_data ) ) { |
|
| 31 | +function wpinv_insert_invoice($invoice_data = array(), $wp_error = false) { |
|
| 32 | + if (empty($invoice_data)) { |
|
| 33 | 33 | return false; |
| 34 | 34 | } |
| 35 | 35 | |
| 36 | - if ( !( !empty( $invoice_data['cart_details'] ) && is_array( $invoice_data['cart_details'] ) ) ) { |
|
| 37 | - return $wp_error ? new WP_Error( 'wpinv_invalid_items', __( 'Invoice must have atleast one item.', 'invoicing' ) ) : 0; |
|
| 36 | + if (!(!empty($invoice_data['cart_details']) && is_array($invoice_data['cart_details']))) { |
|
| 37 | + return $wp_error ? new WP_Error('wpinv_invalid_items', __('Invoice must have atleast one item.', 'invoicing')) : 0; |
|
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | // If no user id is provided, default to the current user id |
| 41 | - if ( empty( $invoice_data['user_id'] ) ) { |
|
| 41 | + if (empty($invoice_data['user_id'])) { |
|
| 42 | 42 | $invoice_data['user_id'] = get_current_user_id(); |
| 43 | 43 | } |
| 44 | 44 | |
| 45 | - $invoice_data['invoice_id'] = !empty( $invoice_data['invoice_id'] ) ? (int)$invoice_data['invoice_id'] : 0; |
|
| 45 | + $invoice_data['invoice_id'] = !empty($invoice_data['invoice_id']) ? (int) $invoice_data['invoice_id'] : 0; |
|
| 46 | 46 | |
| 47 | - if ( empty( $invoice_data['status'] ) ) { |
|
| 47 | + if (empty($invoice_data['status'])) { |
|
| 48 | 48 | $invoice_data['status'] = 'wpi-pending'; |
| 49 | 49 | } |
| 50 | 50 | |
| 51 | - if ( empty( $invoice_data['post_type'] ) ) { |
|
| 51 | + if (empty($invoice_data['post_type'])) { |
|
| 52 | 52 | $invoice_data['post_type'] = 'wpi_invoice'; |
| 53 | 53 | } |
| 54 | 54 | |
| 55 | - if ( empty( $invoice_data['ip'] ) ) { |
|
| 55 | + if (empty($invoice_data['ip'])) { |
|
| 56 | 56 | $invoice_data['ip'] = wpinv_get_ip(); |
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | // default invoice args, note that status is checked for validity in wpinv_create_invoice() |
| 60 | 60 | $default_args = array( |
| 61 | - 'invoice_id' => (int)$invoice_data['invoice_id'], |
|
| 62 | - 'user_id' => (int)$invoice_data['user_id'], |
|
| 61 | + 'invoice_id' => (int) $invoice_data['invoice_id'], |
|
| 62 | + 'user_id' => (int) $invoice_data['user_id'], |
|
| 63 | 63 | 'status' => $invoice_data['status'], |
| 64 | 64 | 'post_type' => $invoice_data['post_type'], |
| 65 | 65 | ); |
| 66 | 66 | |
| 67 | - $invoice = wpinv_create_invoice( $default_args, $invoice_data, true ); |
|
| 68 | - if ( is_wp_error( $invoice ) ) { |
|
| 67 | + $invoice = wpinv_create_invoice($default_args, $invoice_data, true); |
|
| 68 | + if (is_wp_error($invoice)) { |
|
| 69 | 69 | return $wp_error ? $invoice : 0; |
| 70 | 70 | } |
| 71 | 71 | |
| 72 | - if ( empty( $invoice_data['invoice_id'] ) ) { |
|
| 72 | + if (empty($invoice_data['invoice_id'])) { |
|
| 73 | 73 | //$invoice->add_note( wp_sprintf( __( 'Invoice is created with status %s.', 'invoicing' ), wpinv_status_nicename( $invoice->status ) ) ); |
| 74 | 74 | } |
| 75 | 75 | |
@@ -92,24 +92,24 @@ discard block |
||
| 92 | 92 | 'discount' => array(), |
| 93 | 93 | ); |
| 94 | 94 | |
| 95 | - if ( $user_id = (int)$invoice->get_user_id() ) { |
|
| 96 | - if ( $user_address = wpinv_get_user_address( $user_id ) ) { |
|
| 97 | - $default_user_info = wp_parse_args( $user_address, $default_user_info ); |
|
| 95 | + if ($user_id = (int) $invoice->get_user_id()) { |
|
| 96 | + if ($user_address = wpinv_get_user_address($user_id)) { |
|
| 97 | + $default_user_info = wp_parse_args($user_address, $default_user_info); |
|
| 98 | 98 | } |
| 99 | 99 | } |
| 100 | 100 | |
| 101 | - if ( empty( $invoice_data['user_info'] ) ) { |
|
| 101 | + if (empty($invoice_data['user_info'])) { |
|
| 102 | 102 | $invoice_data['user_info'] = array(); |
| 103 | 103 | } |
| 104 | 104 | |
| 105 | - $user_info = wp_parse_args( $invoice_data['user_info'], $default_user_info ); |
|
| 105 | + $user_info = wp_parse_args($invoice_data['user_info'], $default_user_info); |
|
| 106 | 106 | |
| 107 | - if ( empty( $user_info['first_name'] ) ) { |
|
| 107 | + if (empty($user_info['first_name'])) { |
|
| 108 | 108 | $user_info['first_name'] = $default_user_info['first_name']; |
| 109 | 109 | $user_info['last_name'] = $default_user_info['last_name']; |
| 110 | 110 | } |
| 111 | 111 | |
| 112 | - if ( empty( $user_info['country'] ) ) { |
|
| 112 | + if (empty($user_info['country'])) { |
|
| 113 | 113 | $user_info['country'] = $default_user_info['country']; |
| 114 | 114 | $user_info['state'] = $default_user_info['state']; |
| 115 | 115 | $user_info['city'] = $default_user_info['city']; |
@@ -118,13 +118,13 @@ discard block |
||
| 118 | 118 | $user_info['phone'] = $default_user_info['phone']; |
| 119 | 119 | } |
| 120 | 120 | |
| 121 | - if ( !empty( $user_info['discount'] ) && !is_array( $user_info['discount'] ) ) { |
|
| 122 | - $user_info['discount'] = (array)$user_info['discount']; |
|
| 121 | + if (!empty($user_info['discount']) && !is_array($user_info['discount'])) { |
|
| 122 | + $user_info['discount'] = (array) $user_info['discount']; |
|
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | // Payment details |
| 126 | 126 | $payment_details = array(); |
| 127 | - if ( !empty( $invoice_data['payment_details'] ) ) { |
|
| 127 | + if (!empty($invoice_data['payment_details'])) { |
|
| 128 | 128 | $default_payment_details = array( |
| 129 | 129 | 'gateway' => 'manual', |
| 130 | 130 | 'gateway_title' => '', |
@@ -132,56 +132,56 @@ discard block |
||
| 132 | 132 | 'transaction_id' => '', |
| 133 | 133 | ); |
| 134 | 134 | |
| 135 | - $payment_details = wp_parse_args( $invoice_data['payment_details'], $default_payment_details ); |
|
| 135 | + $payment_details = wp_parse_args($invoice_data['payment_details'], $default_payment_details); |
|
| 136 | 136 | |
| 137 | - if ( empty( $payment_details['gateway'] ) ) { |
|
| 137 | + if (empty($payment_details['gateway'])) { |
|
| 138 | 138 | $payment_details['gateway'] = 'manual'; |
| 139 | 139 | } |
| 140 | 140 | |
| 141 | - if ( empty( $payment_details['currency'] ) ) { |
|
| 141 | + if (empty($payment_details['currency'])) { |
|
| 142 | 142 | $payment_details['currency'] = wpinv_get_default_country(); |
| 143 | 143 | } |
| 144 | 144 | |
| 145 | - if ( empty( $payment_details['gateway_title'] ) ) { |
|
| 146 | - $payment_details['gateway_title'] = wpinv_get_gateway_checkout_label( $payment_details['gateway'] ); |
|
| 145 | + if (empty($payment_details['gateway_title'])) { |
|
| 146 | + $payment_details['gateway_title'] = wpinv_get_gateway_checkout_label($payment_details['gateway']); |
|
| 147 | 147 | } |
| 148 | 148 | } |
| 149 | 149 | |
| 150 | - $invoice->set( 'status', ( !empty( $invoice_data['status'] ) ? $invoice_data['status'] : 'wpi-pending' ) ); |
|
| 151 | - |
|
| 152 | - if ( !empty( $payment_details ) ) { |
|
| 153 | - $invoice->set( 'currency', $payment_details['currency'] ); |
|
| 154 | - $invoice->set( 'gateway', $payment_details['gateway'] ); |
|
| 155 | - $invoice->set( 'gateway_title', $payment_details['gateway_title'] ); |
|
| 156 | - $invoice->set( 'transaction_id', $payment_details['transaction_id'] ); |
|
| 157 | - } |
|
| 158 | - |
|
| 159 | - $invoice->set( 'user_info', $user_info ); |
|
| 160 | - $invoice->set( 'first_name', $user_info['first_name'] ); |
|
| 161 | - $invoice->set( 'last_name', $user_info['last_name'] ); |
|
| 162 | - $invoice->set( 'address', $user_info['address'] ); |
|
| 163 | - $invoice->set( 'company', $user_info['company'] ); |
|
| 164 | - $invoice->set( 'vat_number', $user_info['vat_number'] ); |
|
| 165 | - $invoice->set( 'phone', $user_info['phone'] ); |
|
| 166 | - $invoice->set( 'city', $user_info['city'] ); |
|
| 167 | - $invoice->set( 'country', $user_info['country'] ); |
|
| 168 | - $invoice->set( 'state', $user_info['state'] ); |
|
| 169 | - $invoice->set( 'zip', $user_info['zip'] ); |
|
| 170 | - $invoice->set( 'discounts', $user_info['discount'] ); |
|
| 171 | - $invoice->set( 'ip', ( !empty( $invoice_data['ip'] ) ? $invoice_data['ip'] : wpinv_get_ip() ) ); |
|
| 172 | - $invoice->set( 'mode', ( wpinv_is_test_mode() ? 'test' : 'live' ) ); |
|
| 173 | - $invoice->set( 'parent_invoice', ( !empty( $invoice_data['parent'] ) ? absint( $invoice_data['parent'] ) : '' ) ); |
|
| 174 | - |
|
| 175 | - if ( !empty( $invoice_data['cart_details'] ) && is_array( $invoice_data['cart_details'] ) ) { |
|
| 176 | - foreach ( $invoice_data['cart_details'] as $key => $item ) { |
|
| 177 | - $item_id = !empty( $item['id'] ) ? $item['id'] : 0; |
|
| 178 | - $quantity = !empty( $item['quantity'] ) ? $item['quantity'] : 1; |
|
| 179 | - $name = !empty( $item['name'] ) ? $item['name'] : ''; |
|
| 180 | - $item_price = isset( $item['item_price'] ) ? $item['item_price'] : ''; |
|
| 150 | + $invoice->set('status', (!empty($invoice_data['status']) ? $invoice_data['status'] : 'wpi-pending')); |
|
| 151 | + |
|
| 152 | + if (!empty($payment_details)) { |
|
| 153 | + $invoice->set('currency', $payment_details['currency']); |
|
| 154 | + $invoice->set('gateway', $payment_details['gateway']); |
|
| 155 | + $invoice->set('gateway_title', $payment_details['gateway_title']); |
|
| 156 | + $invoice->set('transaction_id', $payment_details['transaction_id']); |
|
| 157 | + } |
|
| 158 | + |
|
| 159 | + $invoice->set('user_info', $user_info); |
|
| 160 | + $invoice->set('first_name', $user_info['first_name']); |
|
| 161 | + $invoice->set('last_name', $user_info['last_name']); |
|
| 162 | + $invoice->set('address', $user_info['address']); |
|
| 163 | + $invoice->set('company', $user_info['company']); |
|
| 164 | + $invoice->set('vat_number', $user_info['vat_number']); |
|
| 165 | + $invoice->set('phone', $user_info['phone']); |
|
| 166 | + $invoice->set('city', $user_info['city']); |
|
| 167 | + $invoice->set('country', $user_info['country']); |
|
| 168 | + $invoice->set('state', $user_info['state']); |
|
| 169 | + $invoice->set('zip', $user_info['zip']); |
|
| 170 | + $invoice->set('discounts', $user_info['discount']); |
|
| 171 | + $invoice->set('ip', (!empty($invoice_data['ip']) ? $invoice_data['ip'] : wpinv_get_ip())); |
|
| 172 | + $invoice->set('mode', (wpinv_is_test_mode() ? 'test' : 'live')); |
|
| 173 | + $invoice->set('parent_invoice', (!empty($invoice_data['parent']) ? absint($invoice_data['parent']) : '')); |
|
| 174 | + |
|
| 175 | + if (!empty($invoice_data['cart_details']) && is_array($invoice_data['cart_details'])) { |
|
| 176 | + foreach ($invoice_data['cart_details'] as $key => $item) { |
|
| 177 | + $item_id = !empty($item['id']) ? $item['id'] : 0; |
|
| 178 | + $quantity = !empty($item['quantity']) ? $item['quantity'] : 1; |
|
| 179 | + $name = !empty($item['name']) ? $item['name'] : ''; |
|
| 180 | + $item_price = isset($item['item_price']) ? $item['item_price'] : ''; |
|
| 181 | 181 | |
| 182 | - $post_item = new WPInv_Item( $item_id ); |
|
| 183 | - if ( !empty( $post_item ) ) { |
|
| 184 | - $name = !empty( $name ) ? $name : $post_item->get_name(); |
|
| 182 | + $post_item = new WPInv_Item($item_id); |
|
| 183 | + if (!empty($post_item)) { |
|
| 184 | + $name = !empty($name) ? $name : $post_item->get_name(); |
|
| 185 | 185 | $item_price = $item_price !== '' ? $item_price : $post_item->get_price(); |
| 186 | 186 | } else { |
| 187 | 187 | continue; |
@@ -191,262 +191,262 @@ discard block |
||
| 191 | 191 | 'name' => $name, |
| 192 | 192 | 'quantity' => $quantity, |
| 193 | 193 | 'item_price' => $item_price, |
| 194 | - 'custom_price' => isset( $item['custom_price'] ) ? $item['custom_price'] : '', |
|
| 195 | - 'tax' => !empty( $item['tax'] ) ? $item['tax'] : 0.00, |
|
| 196 | - 'discount' => isset( $item['discount'] ) ? $item['discount'] : 0, |
|
| 197 | - 'meta' => isset( $item['meta'] ) ? $item['meta'] : array(), |
|
| 198 | - 'fees' => isset( $item['fees'] ) ? $item['fees'] : array(), |
|
| 194 | + 'custom_price' => isset($item['custom_price']) ? $item['custom_price'] : '', |
|
| 195 | + 'tax' => !empty($item['tax']) ? $item['tax'] : 0.00, |
|
| 196 | + 'discount' => isset($item['discount']) ? $item['discount'] : 0, |
|
| 197 | + 'meta' => isset($item['meta']) ? $item['meta'] : array(), |
|
| 198 | + 'fees' => isset($item['fees']) ? $item['fees'] : array(), |
|
| 199 | 199 | ); |
| 200 | 200 | |
| 201 | - $invoice->add_item( $item_id, $args ); |
|
| 201 | + $invoice->add_item($item_id, $args); |
|
| 202 | 202 | } |
| 203 | 203 | } |
| 204 | 204 | |
| 205 | - $invoice->increase_tax( wpinv_get_cart_fee_tax() ); |
|
| 205 | + $invoice->increase_tax(wpinv_get_cart_fee_tax()); |
|
| 206 | 206 | |
| 207 | - if ( isset( $invoice_data['post_date'] ) ) { |
|
| 208 | - $invoice->set( 'date', $invoice_data['post_date'] ); |
|
| 207 | + if (isset($invoice_data['post_date'])) { |
|
| 208 | + $invoice->set('date', $invoice_data['post_date']); |
|
| 209 | 209 | } |
| 210 | 210 | |
| 211 | 211 | // Invoice due date |
| 212 | - if ( isset( $invoice_data['due_date'] ) ) { |
|
| 213 | - $invoice->set( 'due_date', $invoice_data['due_date'] ); |
|
| 212 | + if (isset($invoice_data['due_date'])) { |
|
| 213 | + $invoice->set('due_date', $invoice_data['due_date']); |
|
| 214 | 214 | } |
| 215 | 215 | |
| 216 | 216 | $invoice->save(); |
| 217 | 217 | |
| 218 | 218 | // Add notes |
| 219 | - if ( !empty( $invoice_data['private_note'] ) ) { |
|
| 220 | - $invoice->add_note( $invoice_data['private_note'] ); |
|
| 219 | + if (!empty($invoice_data['private_note'])) { |
|
| 220 | + $invoice->add_note($invoice_data['private_note']); |
|
| 221 | 221 | } |
| 222 | - if ( !empty( $invoice_data['user_note'] ) ) { |
|
| 223 | - $invoice->add_note( $invoice_data['user_note'], true ); |
|
| 222 | + if (!empty($invoice_data['user_note'])) { |
|
| 223 | + $invoice->add_note($invoice_data['user_note'], true); |
|
| 224 | 224 | } |
| 225 | 225 | |
| 226 | - if ( $invoice->is_quote() ) { |
|
| 226 | + if ($invoice->is_quote()) { |
|
| 227 | 227 | |
| 228 | - if ( isset( $invoice_data['valid_until'] ) ) { |
|
| 229 | - update_post_meta( $invoice->ID, 'wpinv_quote_valid_until', $invoice_data['valid_until'] ); |
|
| 228 | + if (isset($invoice_data['valid_until'])) { |
|
| 229 | + update_post_meta($invoice->ID, 'wpinv_quote_valid_until', $invoice_data['valid_until']); |
|
| 230 | 230 | } |
| 231 | 231 | return $invoice; |
| 232 | 232 | |
| 233 | 233 | } |
| 234 | 234 | |
| 235 | - do_action( 'wpinv_insert_invoice', $invoice->ID, $invoice_data ); |
|
| 235 | + do_action('wpinv_insert_invoice', $invoice->ID, $invoice_data); |
|
| 236 | 236 | |
| 237 | - if ( ! empty( $invoice->ID ) ) { |
|
| 237 | + if (!empty($invoice->ID)) { |
|
| 238 | 238 | global $wpi_userID, $wpinv_ip_address_country; |
| 239 | 239 | |
| 240 | 240 | $checkout_session = wpinv_get_checkout_session(); |
| 241 | 241 | |
| 242 | 242 | $data_session = array(); |
| 243 | 243 | $data_session['invoice_id'] = $invoice->ID; |
| 244 | - $data_session['cart_discounts'] = $invoice->get_discounts( true ); |
|
| 244 | + $data_session['cart_discounts'] = $invoice->get_discounts(true); |
|
| 245 | 245 | |
| 246 | - wpinv_set_checkout_session( $data_session ); |
|
| 246 | + wpinv_set_checkout_session($data_session); |
|
| 247 | 247 | |
| 248 | - $wpi_userID = (int)$invoice->get_user_id(); |
|
| 248 | + $wpi_userID = (int) $invoice->get_user_id(); |
|
| 249 | 249 | |
| 250 | - $_POST['country'] = !empty( $invoice->country ) ? $invoice->country : wpinv_get_default_country(); |
|
| 250 | + $_POST['country'] = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country(); |
|
| 251 | 251 | $_POST['state'] = $invoice->state; |
| 252 | 252 | |
| 253 | - $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) ); |
|
| 254 | - $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) ); |
|
| 253 | + $invoice->set('country', sanitize_text_field($_POST['country'])); |
|
| 254 | + $invoice->set('state', sanitize_text_field($_POST['state'])); |
|
| 255 | 255 | |
| 256 | 256 | $wpinv_ip_address_country = $invoice->country; |
| 257 | 257 | |
| 258 | - $invoice = $invoice->recalculate_totals( true ); |
|
| 258 | + $invoice = $invoice->recalculate_totals(true); |
|
| 259 | 259 | |
| 260 | - wpinv_set_checkout_session( $checkout_session ); |
|
| 260 | + wpinv_set_checkout_session($checkout_session); |
|
| 261 | 261 | |
| 262 | 262 | return $invoice; |
| 263 | 263 | } |
| 264 | 264 | |
| 265 | - if ( $wp_error ) { |
|
| 266 | - if ( is_wp_error( $invoice ) ) { |
|
| 265 | + if ($wp_error) { |
|
| 266 | + if (is_wp_error($invoice)) { |
|
| 267 | 267 | return $invoice; |
| 268 | 268 | } else { |
| 269 | - return new WP_Error( 'wpinv_insert_invoice_error', __( 'Error in insert invoice.', 'invoicing' ) ); |
|
| 269 | + return new WP_Error('wpinv_insert_invoice_error', __('Error in insert invoice.', 'invoicing')); |
|
| 270 | 270 | } |
| 271 | 271 | } else { |
| 272 | 272 | return 0; |
| 273 | 273 | } |
| 274 | 274 | } |
| 275 | 275 | |
| 276 | -function wpinv_update_invoice( $invoice_data = array(), $wp_error = false ) { |
|
| 277 | - $invoice_ID = !empty( $invoice_data['ID'] ) ? absint( $invoice_data['ID'] ) : NULL; |
|
| 276 | +function wpinv_update_invoice($invoice_data = array(), $wp_error = false) { |
|
| 277 | + $invoice_ID = !empty($invoice_data['ID']) ? absint($invoice_data['ID']) : NULL; |
|
| 278 | 278 | |
| 279 | - if ( !$invoice_ID ) { |
|
| 280 | - if ( $wp_error ) { |
|
| 281 | - return new WP_Error( 'invalid_invoice_id', __( 'Invalid invoice ID.', 'invoicing' ) ); |
|
| 279 | + if (!$invoice_ID) { |
|
| 280 | + if ($wp_error) { |
|
| 281 | + return new WP_Error('invalid_invoice_id', __('Invalid invoice ID.', 'invoicing')); |
|
| 282 | 282 | } |
| 283 | 283 | return 0; |
| 284 | 284 | } |
| 285 | 285 | |
| 286 | - $invoice = wpinv_get_invoice( $invoice_ID ); |
|
| 286 | + $invoice = wpinv_get_invoice($invoice_ID); |
|
| 287 | 287 | |
| 288 | - $recurring_item = $invoice->is_recurring() ? $invoice->get_recurring( true ) : NULL; |
|
| 288 | + $recurring_item = $invoice->is_recurring() ? $invoice->get_recurring(true) : NULL; |
|
| 289 | 289 | |
| 290 | - if ( empty( $invoice->ID ) ) { |
|
| 291 | - if ( $wp_error ) { |
|
| 292 | - return new WP_Error( 'invalid_invoice', __( 'Invalid invoice.', 'invoicing' ) ); |
|
| 290 | + if (empty($invoice->ID)) { |
|
| 291 | + if ($wp_error) { |
|
| 292 | + return new WP_Error('invalid_invoice', __('Invalid invoice.', 'invoicing')); |
|
| 293 | 293 | } |
| 294 | 294 | return 0; |
| 295 | 295 | } |
| 296 | 296 | |
| 297 | - if ( ! $invoice->has_status( array( 'wpi-pending' ) ) && ! $invoice->is_quote() ) { |
|
| 298 | - if ( $wp_error ) { |
|
| 299 | - return new WP_Error( 'invalid_invoice_status', __( 'Only invoice with pending payment is allowed to update.', 'invoicing' ) ); |
|
| 297 | + if (!$invoice->has_status(array('wpi-pending')) && !$invoice->is_quote()) { |
|
| 298 | + if ($wp_error) { |
|
| 299 | + return new WP_Error('invalid_invoice_status', __('Only invoice with pending payment is allowed to update.', 'invoicing')); |
|
| 300 | 300 | } |
| 301 | 301 | return 0; |
| 302 | 302 | } |
| 303 | 303 | |
| 304 | 304 | // Invoice status |
| 305 | - if ( !empty( $invoice_data['status'] ) ) { |
|
| 306 | - $invoice->set( 'status', $invoice_data['status'] ); |
|
| 305 | + if (!empty($invoice_data['status'])) { |
|
| 306 | + $invoice->set('status', $invoice_data['status']); |
|
| 307 | 307 | } |
| 308 | 308 | |
| 309 | 309 | // Invoice date |
| 310 | - if ( !empty( $invoice_data['post_date'] ) ) { |
|
| 311 | - $invoice->set( 'date', $invoice_data['post_date'] ); |
|
| 310 | + if (!empty($invoice_data['post_date'])) { |
|
| 311 | + $invoice->set('date', $invoice_data['post_date']); |
|
| 312 | 312 | } |
| 313 | 313 | |
| 314 | 314 | // Invoice due date |
| 315 | - if ( isset( $invoice_data['due_date'] ) ) { |
|
| 316 | - $invoice->set( 'due_date', $invoice_data['due_date'] ); |
|
| 315 | + if (isset($invoice_data['due_date'])) { |
|
| 316 | + $invoice->set('due_date', $invoice_data['due_date']); |
|
| 317 | 317 | } |
| 318 | 318 | |
| 319 | 319 | // Invoice IP address |
| 320 | - if ( !empty( $invoice_data['ip'] ) ) { |
|
| 321 | - $invoice->set( 'ip', $invoice_data['ip'] ); |
|
| 320 | + if (!empty($invoice_data['ip'])) { |
|
| 321 | + $invoice->set('ip', $invoice_data['ip']); |
|
| 322 | 322 | } |
| 323 | 323 | |
| 324 | 324 | // User info |
| 325 | - if ( !empty( $invoice_data['user_info'] ) && is_array( $invoice_data['user_info'] ) ) { |
|
| 326 | - $user_info = wp_parse_args( $invoice_data['user_info'], $invoice->user_info ); |
|
| 325 | + if (!empty($invoice_data['user_info']) && is_array($invoice_data['user_info'])) { |
|
| 326 | + $user_info = wp_parse_args($invoice_data['user_info'], $invoice->user_info); |
|
| 327 | 327 | |
| 328 | - if ( $discounts = $invoice->get_discounts() ) { |
|
| 328 | + if ($discounts = $invoice->get_discounts()) { |
|
| 329 | 329 | $set_discount = $discounts; |
| 330 | 330 | } else { |
| 331 | 331 | $set_discount = ''; |
| 332 | 332 | } |
| 333 | 333 | |
| 334 | 334 | // Manage discount |
| 335 | - if ( !empty( $invoice_data['user_info']['discount'] ) ) { |
|
| 335 | + if (!empty($invoice_data['user_info']['discount'])) { |
|
| 336 | 336 | // Remove discount |
| 337 | - if ( $invoice_data['user_info']['discount'] == 'none' ) { |
|
| 337 | + if ($invoice_data['user_info']['discount'] == 'none') { |
|
| 338 | 338 | $set_discount = ''; |
| 339 | 339 | } else { |
| 340 | 340 | $set_discount = $invoice_data['user_info']['discount']; |
| 341 | 341 | } |
| 342 | 342 | |
| 343 | - $invoice->set( 'discounts', $set_discount ); |
|
| 343 | + $invoice->set('discounts', $set_discount); |
|
| 344 | 344 | } |
| 345 | 345 | |
| 346 | 346 | $user_info['discount'] = $set_discount; |
| 347 | 347 | |
| 348 | - $invoice->set( 'user_info', $user_info ); |
|
| 348 | + $invoice->set('user_info', $user_info); |
|
| 349 | 349 | } |
| 350 | 350 | |
| 351 | - if ( !empty( $invoice_data['cart_details'] ) && is_array( $invoice_data['cart_details'] ) && $cart_details = $invoice_data['cart_details'] ) { |
|
| 352 | - $remove_items = !empty( $cart_details['remove_items'] ) && is_array( $cart_details['remove_items'] ) ? $cart_details['remove_items'] : array(); |
|
| 351 | + if (!empty($invoice_data['cart_details']) && is_array($invoice_data['cart_details']) && $cart_details = $invoice_data['cart_details']) { |
|
| 352 | + $remove_items = !empty($cart_details['remove_items']) && is_array($cart_details['remove_items']) ? $cart_details['remove_items'] : array(); |
|
| 353 | 353 | |
| 354 | - if ( !empty( $remove_items[0]['id'] ) ) { |
|
| 355 | - foreach ( $remove_items as $item ) { |
|
| 356 | - $item_id = !empty( $item['id'] ) ? $item['id'] : 0; |
|
| 357 | - $quantity = !empty( $item['quantity'] ) ? $item['quantity'] : 1; |
|
| 358 | - if ( empty( $item_id ) ) { |
|
| 354 | + if (!empty($remove_items[0]['id'])) { |
|
| 355 | + foreach ($remove_items as $item) { |
|
| 356 | + $item_id = !empty($item['id']) ? $item['id'] : 0; |
|
| 357 | + $quantity = !empty($item['quantity']) ? $item['quantity'] : 1; |
|
| 358 | + if (empty($item_id)) { |
|
| 359 | 359 | continue; |
| 360 | 360 | } |
| 361 | 361 | |
| 362 | - foreach ( $invoice->cart_details as $cart_index => $cart_item ) { |
|
| 363 | - if ( $item_id == $cart_item['id'] ) { |
|
| 362 | + foreach ($invoice->cart_details as $cart_index => $cart_item) { |
|
| 363 | + if ($item_id == $cart_item['id']) { |
|
| 364 | 364 | $args = array( |
| 365 | 365 | 'id' => $item_id, |
| 366 | 366 | 'quantity' => $quantity, |
| 367 | 367 | 'cart_index' => $cart_index |
| 368 | 368 | ); |
| 369 | 369 | |
| 370 | - $invoice->remove_item( $item_id, $args ); |
|
| 370 | + $invoice->remove_item($item_id, $args); |
|
| 371 | 371 | break; |
| 372 | 372 | } |
| 373 | 373 | } |
| 374 | 374 | } |
| 375 | 375 | } |
| 376 | 376 | |
| 377 | - $add_items = !empty( $cart_details['add_items'] ) && is_array( $cart_details['add_items'] ) ? $cart_details['add_items'] : array(); |
|
| 377 | + $add_items = !empty($cart_details['add_items']) && is_array($cart_details['add_items']) ? $cart_details['add_items'] : array(); |
|
| 378 | 378 | |
| 379 | - if ( !empty( $add_items[0]['id'] ) ) { |
|
| 380 | - foreach ( $add_items as $item ) { |
|
| 381 | - $item_id = !empty( $item['id'] ) ? $item['id'] : 0; |
|
| 382 | - $post_item = new WPInv_Item( $item_id ); |
|
| 383 | - if ( empty( $post_item ) ) { |
|
| 379 | + if (!empty($add_items[0]['id'])) { |
|
| 380 | + foreach ($add_items as $item) { |
|
| 381 | + $item_id = !empty($item['id']) ? $item['id'] : 0; |
|
| 382 | + $post_item = new WPInv_Item($item_id); |
|
| 383 | + if (empty($post_item)) { |
|
| 384 | 384 | continue; |
| 385 | 385 | } |
| 386 | 386 | |
| 387 | 387 | $valid_item = true; |
| 388 | - if ( !empty( $recurring_item ) ) { |
|
| 389 | - if ( $recurring_item->ID != $item_id ) { |
|
| 388 | + if (!empty($recurring_item)) { |
|
| 389 | + if ($recurring_item->ID != $item_id) { |
|
| 390 | 390 | $valid_item = false; |
| 391 | 391 | } |
| 392 | - } else if ( wpinv_is_recurring_item( $item_id ) ) { |
|
| 392 | + } else if (wpinv_is_recurring_item($item_id)) { |
|
| 393 | 393 | $valid_item = false; |
| 394 | 394 | } |
| 395 | 395 | |
| 396 | - if ( !$valid_item ) { |
|
| 397 | - if ( $wp_error ) { |
|
| 398 | - return new WP_Error( 'invalid_invoice_item', __( 'You can not add item because recurring item must be paid individually!', 'invoicing' ) ); |
|
| 396 | + if (!$valid_item) { |
|
| 397 | + if ($wp_error) { |
|
| 398 | + return new WP_Error('invalid_invoice_item', __('You can not add item because recurring item must be paid individually!', 'invoicing')); |
|
| 399 | 399 | } |
| 400 | 400 | return 0; |
| 401 | 401 | } |
| 402 | 402 | |
| 403 | - $quantity = !empty( $item['quantity'] ) ? $item['quantity'] : 1; |
|
| 404 | - $name = !empty( $item['name'] ) ? $item['name'] : $post_item->get_name(); |
|
| 405 | - $item_price = isset( $item['item_price'] ) ? $item['item_price'] : $post_item->get_price(); |
|
| 403 | + $quantity = !empty($item['quantity']) ? $item['quantity'] : 1; |
|
| 404 | + $name = !empty($item['name']) ? $item['name'] : $post_item->get_name(); |
|
| 405 | + $item_price = isset($item['item_price']) ? $item['item_price'] : $post_item->get_price(); |
|
| 406 | 406 | |
| 407 | 407 | $args = array( |
| 408 | 408 | 'name' => $name, |
| 409 | 409 | 'quantity' => $quantity, |
| 410 | 410 | 'item_price' => $item_price, |
| 411 | - 'custom_price' => isset( $item['custom_price'] ) ? $item['custom_price'] : '', |
|
| 412 | - 'tax' => !empty( $item['tax'] ) ? $item['tax'] : 0, |
|
| 413 | - 'discount' => isset( $item['discount'] ) ? $item['discount'] : 0, |
|
| 414 | - 'meta' => isset( $item['meta'] ) ? $item['meta'] : array(), |
|
| 415 | - 'fees' => isset( $item['fees'] ) ? $item['fees'] : array(), |
|
| 411 | + 'custom_price' => isset($item['custom_price']) ? $item['custom_price'] : '', |
|
| 412 | + 'tax' => !empty($item['tax']) ? $item['tax'] : 0, |
|
| 413 | + 'discount' => isset($item['discount']) ? $item['discount'] : 0, |
|
| 414 | + 'meta' => isset($item['meta']) ? $item['meta'] : array(), |
|
| 415 | + 'fees' => isset($item['fees']) ? $item['fees'] : array(), |
|
| 416 | 416 | ); |
| 417 | 417 | |
| 418 | - $invoice->add_item( $item_id, $args ); |
|
| 418 | + $invoice->add_item($item_id, $args); |
|
| 419 | 419 | } |
| 420 | 420 | } |
| 421 | 421 | } |
| 422 | 422 | |
| 423 | 423 | // Payment details |
| 424 | - if ( !empty( $invoice_data['payment_details'] ) && $payment_details = $invoice_data['payment_details'] ) { |
|
| 425 | - if ( !empty( $payment_details['gateway'] ) ) { |
|
| 426 | - $invoice->set( 'gateway', $payment_details['gateway'] ); |
|
| 424 | + if (!empty($invoice_data['payment_details']) && $payment_details = $invoice_data['payment_details']) { |
|
| 425 | + if (!empty($payment_details['gateway'])) { |
|
| 426 | + $invoice->set('gateway', $payment_details['gateway']); |
|
| 427 | 427 | } |
| 428 | 428 | |
| 429 | - if ( !empty( $payment_details['transaction_id'] ) ) { |
|
| 430 | - $invoice->set( 'transaction_id', $payment_details['transaction_id'] ); |
|
| 429 | + if (!empty($payment_details['transaction_id'])) { |
|
| 430 | + $invoice->set('transaction_id', $payment_details['transaction_id']); |
|
| 431 | 431 | } |
| 432 | 432 | } |
| 433 | 433 | |
| 434 | - do_action( 'wpinv_pre_update_invoice', $invoice->ID, $invoice_data ); |
|
| 434 | + do_action('wpinv_pre_update_invoice', $invoice->ID, $invoice_data); |
|
| 435 | 435 | |
| 436 | 436 | // Parent invoice |
| 437 | - if ( !empty( $invoice_data['parent'] ) ) { |
|
| 438 | - $invoice->set( 'parent_invoice', $invoice_data['parent'] ); |
|
| 437 | + if (!empty($invoice_data['parent'])) { |
|
| 438 | + $invoice->set('parent_invoice', $invoice_data['parent']); |
|
| 439 | 439 | } |
| 440 | 440 | |
| 441 | 441 | // Save invoice data. |
| 442 | 442 | $invoice->save(); |
| 443 | 443 | |
| 444 | - if ( empty( $invoice->ID ) || is_wp_error( $invoice ) ) { |
|
| 445 | - if ( $wp_error ) { |
|
| 446 | - if ( is_wp_error( $invoice ) ) { |
|
| 444 | + if (empty($invoice->ID) || is_wp_error($invoice)) { |
|
| 445 | + if ($wp_error) { |
|
| 446 | + if (is_wp_error($invoice)) { |
|
| 447 | 447 | return $invoice; |
| 448 | 448 | } else { |
| 449 | - return new WP_Error( 'wpinv_update_invoice_error', __( 'Error in update invoice.', 'invoicing' ) ); |
|
| 449 | + return new WP_Error('wpinv_update_invoice_error', __('Error in update invoice.', 'invoicing')); |
|
| 450 | 450 | } |
| 451 | 451 | } else { |
| 452 | 452 | return 0; |
@@ -454,19 +454,19 @@ discard block |
||
| 454 | 454 | } |
| 455 | 455 | |
| 456 | 456 | // Add private note |
| 457 | - if ( !empty( $invoice_data['private_note'] ) ) { |
|
| 458 | - $invoice->add_note( $invoice_data['private_note'] ); |
|
| 457 | + if (!empty($invoice_data['private_note'])) { |
|
| 458 | + $invoice->add_note($invoice_data['private_note']); |
|
| 459 | 459 | } |
| 460 | 460 | |
| 461 | 461 | // Add user note |
| 462 | - if ( !empty( $invoice_data['user_note'] ) ) { |
|
| 463 | - $invoice->add_note( $invoice_data['user_note'], true ); |
|
| 462 | + if (!empty($invoice_data['user_note'])) { |
|
| 463 | + $invoice->add_note($invoice_data['user_note'], true); |
|
| 464 | 464 | } |
| 465 | 465 | |
| 466 | - if ( $invoice->is_quote() ) { |
|
| 466 | + if ($invoice->is_quote()) { |
|
| 467 | 467 | |
| 468 | - if ( isset( $invoice_data['valid_until'] ) ) { |
|
| 469 | - update_post_meta( $invoice->ID, 'wpinv_quote_valid_until', $invoice_data['valid_until'] ); |
|
| 468 | + if (isset($invoice_data['valid_until'])) { |
|
| 469 | + update_post_meta($invoice->ID, 'wpinv_quote_valid_until', $invoice_data['valid_until']); |
|
| 470 | 470 | } |
| 471 | 471 | return $invoice; |
| 472 | 472 | |
@@ -478,466 +478,466 @@ discard block |
||
| 478 | 478 | |
| 479 | 479 | $data_session = array(); |
| 480 | 480 | $data_session['invoice_id'] = $invoice->ID; |
| 481 | - $data_session['cart_discounts'] = $invoice->get_discounts( true ); |
|
| 481 | + $data_session['cart_discounts'] = $invoice->get_discounts(true); |
|
| 482 | 482 | |
| 483 | - wpinv_set_checkout_session( $data_session ); |
|
| 483 | + wpinv_set_checkout_session($data_session); |
|
| 484 | 484 | |
| 485 | - $wpi_userID = (int)$invoice->get_user_id(); |
|
| 485 | + $wpi_userID = (int) $invoice->get_user_id(); |
|
| 486 | 486 | |
| 487 | - $_POST['country'] = !empty( $invoice->country ) ? $invoice->country : wpinv_get_default_country(); |
|
| 487 | + $_POST['country'] = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country(); |
|
| 488 | 488 | $_POST['state'] = $invoice->state; |
| 489 | 489 | |
| 490 | - $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) ); |
|
| 491 | - $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) ); |
|
| 490 | + $invoice->set('country', sanitize_text_field($_POST['country'])); |
|
| 491 | + $invoice->set('state', sanitize_text_field($_POST['state'])); |
|
| 492 | 492 | |
| 493 | 493 | $wpinv_ip_address_country = $invoice->country; |
| 494 | 494 | |
| 495 | - $invoice = $invoice->recalculate_totals( true ); |
|
| 495 | + $invoice = $invoice->recalculate_totals(true); |
|
| 496 | 496 | |
| 497 | - do_action( 'wpinv_post_update_invoice', $invoice->ID, $invoice_data ); |
|
| 497 | + do_action('wpinv_post_update_invoice', $invoice->ID, $invoice_data); |
|
| 498 | 498 | |
| 499 | - wpinv_set_checkout_session( $checkout_session ); |
|
| 499 | + wpinv_set_checkout_session($checkout_session); |
|
| 500 | 500 | |
| 501 | 501 | return $invoice; |
| 502 | 502 | } |
| 503 | 503 | |
| 504 | -function wpinv_get_invoice( $invoice_id = 0, $cart = false ) { |
|
| 505 | - if ( $cart && empty( $invoice_id ) ) { |
|
| 506 | - $invoice_id = (int)wpinv_get_invoice_cart_id(); |
|
| 504 | +function wpinv_get_invoice($invoice_id = 0, $cart = false) { |
|
| 505 | + if ($cart && empty($invoice_id)) { |
|
| 506 | + $invoice_id = (int) wpinv_get_invoice_cart_id(); |
|
| 507 | 507 | } |
| 508 | 508 | |
| 509 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
| 509 | + $invoice = new WPInv_Invoice($invoice_id); |
|
| 510 | 510 | |
| 511 | - if ( ! empty( $invoice ) && ! empty( $invoice->ID ) ) { |
|
| 511 | + if (!empty($invoice) && !empty($invoice->ID)) { |
|
| 512 | 512 | return $invoice; |
| 513 | 513 | } |
| 514 | 514 | |
| 515 | 515 | return NULL; |
| 516 | 516 | } |
| 517 | 517 | |
| 518 | -function wpinv_get_invoice_cart( $invoice_id = 0 ) { |
|
| 519 | - return wpinv_get_invoice( $invoice_id, true ); |
|
| 518 | +function wpinv_get_invoice_cart($invoice_id = 0) { |
|
| 519 | + return wpinv_get_invoice($invoice_id, true); |
|
| 520 | 520 | } |
| 521 | 521 | |
| 522 | -function wpinv_get_invoice_description( $invoice_id = 0 ) { |
|
| 523 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
| 522 | +function wpinv_get_invoice_description($invoice_id = 0) { |
|
| 523 | + $invoice = new WPInv_Invoice($invoice_id); |
|
| 524 | 524 | return $invoice->get_description(); |
| 525 | 525 | } |
| 526 | 526 | |
| 527 | -function wpinv_get_invoice_currency_code( $invoice_id = 0 ) { |
|
| 528 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
| 527 | +function wpinv_get_invoice_currency_code($invoice_id = 0) { |
|
| 528 | + $invoice = new WPInv_Invoice($invoice_id); |
|
| 529 | 529 | return $invoice->get_currency(); |
| 530 | 530 | } |
| 531 | 531 | |
| 532 | -function wpinv_get_payment_user_email( $invoice_id ) { |
|
| 533 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
| 532 | +function wpinv_get_payment_user_email($invoice_id) { |
|
| 533 | + $invoice = new WPInv_Invoice($invoice_id); |
|
| 534 | 534 | return $invoice->get_email(); |
| 535 | 535 | } |
| 536 | 536 | |
| 537 | -function wpinv_get_user_id( $invoice_id ) { |
|
| 538 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
| 537 | +function wpinv_get_user_id($invoice_id) { |
|
| 538 | + $invoice = new WPInv_Invoice($invoice_id); |
|
| 539 | 539 | return $invoice->get_user_id(); |
| 540 | 540 | } |
| 541 | 541 | |
| 542 | -function wpinv_get_invoice_status( $invoice_id, $return_label = false ) { |
|
| 543 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
| 542 | +function wpinv_get_invoice_status($invoice_id, $return_label = false) { |
|
| 543 | + $invoice = new WPInv_Invoice($invoice_id); |
|
| 544 | 544 | |
| 545 | - return $invoice->get_status( $return_label ); |
|
| 545 | + return $invoice->get_status($return_label); |
|
| 546 | 546 | } |
| 547 | 547 | |
| 548 | -function wpinv_get_payment_gateway( $invoice_id, $return_label = false ) { |
|
| 549 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
| 548 | +function wpinv_get_payment_gateway($invoice_id, $return_label = false) { |
|
| 549 | + $invoice = new WPInv_Invoice($invoice_id); |
|
| 550 | 550 | |
| 551 | - return $invoice->get_gateway( $return_label ); |
|
| 551 | + return $invoice->get_gateway($return_label); |
|
| 552 | 552 | } |
| 553 | 553 | |
| 554 | -function wpinv_get_payment_gateway_name( $invoice_id ) { |
|
| 555 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
| 554 | +function wpinv_get_payment_gateway_name($invoice_id) { |
|
| 555 | + $invoice = new WPInv_Invoice($invoice_id); |
|
| 556 | 556 | |
| 557 | 557 | return $invoice->get_gateway_title(); |
| 558 | 558 | } |
| 559 | 559 | |
| 560 | -function wpinv_get_payment_transaction_id( $invoice_id ) { |
|
| 561 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
| 560 | +function wpinv_get_payment_transaction_id($invoice_id) { |
|
| 561 | + $invoice = new WPInv_Invoice($invoice_id); |
|
| 562 | 562 | |
| 563 | 563 | return $invoice->get_transaction_id(); |
| 564 | 564 | } |
| 565 | 565 | |
| 566 | -function wpinv_get_id_by_transaction_id( $key ) { |
|
| 566 | +function wpinv_get_id_by_transaction_id($key) { |
|
| 567 | 567 | global $wpdb; |
| 568 | 568 | |
| 569 | - $invoice_id = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_transaction_id' AND meta_value = %s LIMIT 1", $key ) ); |
|
| 569 | + $invoice_id = $wpdb->get_var($wpdb->prepare("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_transaction_id' AND meta_value = %s LIMIT 1", $key)); |
|
| 570 | 570 | |
| 571 | - if ( $invoice_id != NULL ) |
|
| 571 | + if ($invoice_id != NULL) |
|
| 572 | 572 | return $invoice_id; |
| 573 | 573 | |
| 574 | 574 | return 0; |
| 575 | 575 | } |
| 576 | 576 | |
| 577 | -function wpinv_get_invoice_meta( $invoice_id = 0, $meta_key = '_wpinv_payment_meta', $single = true ) { |
|
| 578 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
| 577 | +function wpinv_get_invoice_meta($invoice_id = 0, $meta_key = '_wpinv_payment_meta', $single = true) { |
|
| 578 | + $invoice = new WPInv_Invoice($invoice_id); |
|
| 579 | 579 | |
| 580 | - return $invoice->get_meta( $meta_key, $single ); |
|
| 580 | + return $invoice->get_meta($meta_key, $single); |
|
| 581 | 581 | } |
| 582 | 582 | |
| 583 | -function wpinv_update_invoice_meta( $invoice_id = 0, $meta_key = '', $meta_value = '', $prev_value = '' ) { |
|
| 584 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
| 583 | +function wpinv_update_invoice_meta($invoice_id = 0, $meta_key = '', $meta_value = '', $prev_value = '') { |
|
| 584 | + $invoice = new WPInv_Invoice($invoice_id); |
|
| 585 | 585 | |
| 586 | - return $invoice->update_meta( $meta_key, $meta_value, $prev_value ); |
|
| 586 | + return $invoice->update_meta($meta_key, $meta_value, $prev_value); |
|
| 587 | 587 | } |
| 588 | 588 | |
| 589 | -function wpinv_get_items( $invoice_id = 0 ) { |
|
| 590 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
| 589 | +function wpinv_get_items($invoice_id = 0) { |
|
| 590 | + $invoice = wpinv_get_invoice($invoice_id); |
|
| 591 | 591 | |
| 592 | 592 | $items = $invoice->get_items(); |
| 593 | 593 | $invoice_currency = $invoice->get_currency(); |
| 594 | 594 | |
| 595 | - if ( !empty( $items ) && is_array( $items ) ) { |
|
| 596 | - foreach ( $items as $key => $item ) { |
|
| 595 | + if (!empty($items) && is_array($items)) { |
|
| 596 | + foreach ($items as $key => $item) { |
|
| 597 | 597 | $items[$key]['currency'] = $invoice_currency; |
| 598 | 598 | |
| 599 | - if ( !isset( $item['subtotal'] ) ) { |
|
| 599 | + if (!isset($item['subtotal'])) { |
|
| 600 | 600 | $items[$key]['subtotal'] = $items[$key]['amount'] * 1; |
| 601 | 601 | } |
| 602 | 602 | } |
| 603 | 603 | } |
| 604 | 604 | |
| 605 | - return apply_filters( 'wpinv_get_items', $items, $invoice_id ); |
|
| 605 | + return apply_filters('wpinv_get_items', $items, $invoice_id); |
|
| 606 | 606 | } |
| 607 | 607 | |
| 608 | -function wpinv_get_fees( $invoice_id = 0 ) { |
|
| 609 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
| 608 | +function wpinv_get_fees($invoice_id = 0) { |
|
| 609 | + $invoice = wpinv_get_invoice($invoice_id); |
|
| 610 | 610 | $fees = $invoice->get_fees(); |
| 611 | 611 | |
| 612 | - return apply_filters( 'wpinv_get_fees', $fees, $invoice_id ); |
|
| 612 | + return apply_filters('wpinv_get_fees', $fees, $invoice_id); |
|
| 613 | 613 | } |
| 614 | 614 | |
| 615 | -function wpinv_get_invoice_ip( $invoice_id ) { |
|
| 616 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
| 615 | +function wpinv_get_invoice_ip($invoice_id) { |
|
| 616 | + $invoice = new WPInv_Invoice($invoice_id); |
|
| 617 | 617 | return $invoice->get_ip(); |
| 618 | 618 | } |
| 619 | 619 | |
| 620 | -function wpinv_get_invoice_user_info( $invoice_id ) { |
|
| 621 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
| 620 | +function wpinv_get_invoice_user_info($invoice_id) { |
|
| 621 | + $invoice = new WPInv_Invoice($invoice_id); |
|
| 622 | 622 | return $invoice->get_user_info(); |
| 623 | 623 | } |
| 624 | 624 | |
| 625 | -function wpinv_subtotal( $invoice_id = 0, $currency = false ) { |
|
| 626 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
| 625 | +function wpinv_subtotal($invoice_id = 0, $currency = false) { |
|
| 626 | + $invoice = new WPInv_Invoice($invoice_id); |
|
| 627 | 627 | |
| 628 | - return $invoice->get_subtotal( $currency ); |
|
| 628 | + return $invoice->get_subtotal($currency); |
|
| 629 | 629 | } |
| 630 | 630 | |
| 631 | -function wpinv_tax( $invoice_id = 0, $currency = false ) { |
|
| 632 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
| 631 | +function wpinv_tax($invoice_id = 0, $currency = false) { |
|
| 632 | + $invoice = new WPInv_Invoice($invoice_id); |
|
| 633 | 633 | |
| 634 | - return $invoice->get_tax( $currency ); |
|
| 634 | + return $invoice->get_tax($currency); |
|
| 635 | 635 | } |
| 636 | 636 | |
| 637 | -function wpinv_discount( $invoice_id = 0, $currency = false, $dash = false ) { |
|
| 638 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
| 637 | +function wpinv_discount($invoice_id = 0, $currency = false, $dash = false) { |
|
| 638 | + $invoice = wpinv_get_invoice($invoice_id); |
|
| 639 | 639 | |
| 640 | - return $invoice->get_discount( $currency, $dash ); |
|
| 640 | + return $invoice->get_discount($currency, $dash); |
|
| 641 | 641 | } |
| 642 | 642 | |
| 643 | -function wpinv_discount_code( $invoice_id = 0 ) { |
|
| 644 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
| 643 | +function wpinv_discount_code($invoice_id = 0) { |
|
| 644 | + $invoice = new WPInv_Invoice($invoice_id); |
|
| 645 | 645 | |
| 646 | 646 | return $invoice->get_discount_code(); |
| 647 | 647 | } |
| 648 | 648 | |
| 649 | -function wpinv_payment_total( $invoice_id = 0, $currency = false ) { |
|
| 650 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
| 649 | +function wpinv_payment_total($invoice_id = 0, $currency = false) { |
|
| 650 | + $invoice = new WPInv_Invoice($invoice_id); |
|
| 651 | 651 | |
| 652 | - return $invoice->get_total( $currency ); |
|
| 652 | + return $invoice->get_total($currency); |
|
| 653 | 653 | } |
| 654 | 654 | |
| 655 | -function wpinv_get_date_created( $invoice_id = 0, $format = '' ) { |
|
| 656 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
| 655 | +function wpinv_get_date_created($invoice_id = 0, $format = '') { |
|
| 656 | + $invoice = new WPInv_Invoice($invoice_id); |
|
| 657 | 657 | |
| 658 | - $format = !empty( $format ) ? $format : get_option( 'date_format' ); |
|
| 658 | + $format = !empty($format) ? $format : get_option('date_format'); |
|
| 659 | 659 | $date_created = $invoice->get_created_date(); |
| 660 | - $date_created = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? date_i18n( $format, strtotime( $date_created ) ) : ''; |
|
| 660 | + $date_created = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? date_i18n($format, strtotime($date_created)) : ''; |
|
| 661 | 661 | |
| 662 | 662 | return $date_created; |
| 663 | 663 | } |
| 664 | 664 | |
| 665 | -function wpinv_get_invoice_date( $invoice_id = 0, $format = '', $default = true ) { |
|
| 666 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
| 665 | +function wpinv_get_invoice_date($invoice_id = 0, $format = '', $default = true) { |
|
| 666 | + $invoice = new WPInv_Invoice($invoice_id); |
|
| 667 | 667 | |
| 668 | - $format = !empty( $format ) ? $format : get_option( 'date_format' ); |
|
| 668 | + $format = !empty($format) ? $format : get_option('date_format'); |
|
| 669 | 669 | $date_completed = $invoice->get_completed_date(); |
| 670 | - $invoice_date = $date_completed != '' && $date_completed != '0000-00-00 00:00:00' ? date_i18n( $format, strtotime( $date_completed ) ) : ''; |
|
| 671 | - if ( $invoice_date == '' && $default ) { |
|
| 672 | - $invoice_date = wpinv_get_date_created( $invoice_id, $format ); |
|
| 670 | + $invoice_date = $date_completed != '' && $date_completed != '0000-00-00 00:00:00' ? date_i18n($format, strtotime($date_completed)) : ''; |
|
| 671 | + if ($invoice_date == '' && $default) { |
|
| 672 | + $invoice_date = wpinv_get_date_created($invoice_id, $format); |
|
| 673 | 673 | } |
| 674 | 674 | |
| 675 | 675 | return $invoice_date; |
| 676 | 676 | } |
| 677 | 677 | |
| 678 | -function wpinv_get_invoice_vat_number( $invoice_id = 0 ) { |
|
| 679 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
| 678 | +function wpinv_get_invoice_vat_number($invoice_id = 0) { |
|
| 679 | + $invoice = new WPInv_Invoice($invoice_id); |
|
| 680 | 680 | |
| 681 | 681 | return $invoice->vat_number; |
| 682 | 682 | } |
| 683 | 683 | |
| 684 | -function wpinv_insert_payment_note( $invoice_id = 0, $note = '', $user_type = false, $added_by_user = false, $system = false ) { |
|
| 685 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
| 684 | +function wpinv_insert_payment_note($invoice_id = 0, $note = '', $user_type = false, $added_by_user = false, $system = false) { |
|
| 685 | + $invoice = new WPInv_Invoice($invoice_id); |
|
| 686 | 686 | |
| 687 | - return $invoice->add_note( $note, $user_type, $added_by_user, $system ); |
|
| 687 | + return $invoice->add_note($note, $user_type, $added_by_user, $system); |
|
| 688 | 688 | } |
| 689 | 689 | |
| 690 | -function wpinv_get_invoice_notes( $invoice_id = 0, $type = '' ) { |
|
| 690 | +function wpinv_get_invoice_notes($invoice_id = 0, $type = '') { |
|
| 691 | 691 | global $invoicing; |
| 692 | 692 | |
| 693 | - if ( empty( $invoice_id ) ) { |
|
| 693 | + if (empty($invoice_id)) { |
|
| 694 | 694 | return NULL; |
| 695 | 695 | } |
| 696 | 696 | |
| 697 | - $notes = $invoicing->notes->get_invoice_notes( $invoice_id, $type ); |
|
| 697 | + $notes = $invoicing->notes->get_invoice_notes($invoice_id, $type); |
|
| 698 | 698 | |
| 699 | - return apply_filters( 'wpinv_invoice_notes', $notes, $invoice_id, $type ); |
|
| 699 | + return apply_filters('wpinv_invoice_notes', $notes, $invoice_id, $type); |
|
| 700 | 700 | } |
| 701 | 701 | |
| 702 | -function wpinv_get_payment_key( $invoice_id = 0 ) { |
|
| 703 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
| 702 | +function wpinv_get_payment_key($invoice_id = 0) { |
|
| 703 | + $invoice = new WPInv_Invoice($invoice_id); |
|
| 704 | 704 | return $invoice->get_key(); |
| 705 | 705 | } |
| 706 | 706 | |
| 707 | -function wpinv_get_invoice_number( $invoice_id = 0 ) { |
|
| 708 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
| 707 | +function wpinv_get_invoice_number($invoice_id = 0) { |
|
| 708 | + $invoice = new WPInv_Invoice($invoice_id); |
|
| 709 | 709 | return $invoice->get_number(); |
| 710 | 710 | } |
| 711 | 711 | |
| 712 | -function wpinv_get_cart_discountable_subtotal( $code_id ) { |
|
| 712 | +function wpinv_get_cart_discountable_subtotal($code_id) { |
|
| 713 | 713 | $cart_items = wpinv_get_cart_content_details(); |
| 714 | 714 | $items = array(); |
| 715 | 715 | |
| 716 | - $excluded_items = wpinv_get_discount_excluded_items( $code_id ); |
|
| 716 | + $excluded_items = wpinv_get_discount_excluded_items($code_id); |
|
| 717 | 717 | |
| 718 | - if( $cart_items ) { |
|
| 718 | + if ($cart_items) { |
|
| 719 | 719 | |
| 720 | - foreach( $cart_items as $item ) { |
|
| 720 | + foreach ($cart_items as $item) { |
|
| 721 | 721 | |
| 722 | - if( ! in_array( $item['id'], $excluded_items ) ) { |
|
| 723 | - $items[] = $item; |
|
| 722 | + if (!in_array($item['id'], $excluded_items)) { |
|
| 723 | + $items[] = $item; |
|
| 724 | 724 | } |
| 725 | 725 | } |
| 726 | 726 | } |
| 727 | 727 | |
| 728 | - $subtotal = wpinv_get_cart_items_subtotal( $items ); |
|
| 728 | + $subtotal = wpinv_get_cart_items_subtotal($items); |
|
| 729 | 729 | |
| 730 | - return apply_filters( 'wpinv_get_cart_discountable_subtotal', $subtotal ); |
|
| 730 | + return apply_filters('wpinv_get_cart_discountable_subtotal', $subtotal); |
|
| 731 | 731 | } |
| 732 | 732 | |
| 733 | -function wpinv_get_cart_items_subtotal( $items ) { |
|
| 733 | +function wpinv_get_cart_items_subtotal($items) { |
|
| 734 | 734 | $subtotal = 0.00; |
| 735 | 735 | |
| 736 | - if ( is_array( $items ) && ! empty( $items ) ) { |
|
| 737 | - $prices = wp_list_pluck( $items, 'subtotal' ); |
|
| 736 | + if (is_array($items) && !empty($items)) { |
|
| 737 | + $prices = wp_list_pluck($items, 'subtotal'); |
|
| 738 | 738 | |
| 739 | - if( is_array( $prices ) ) { |
|
| 740 | - $subtotal = array_sum( $prices ); |
|
| 739 | + if (is_array($prices)) { |
|
| 740 | + $subtotal = array_sum($prices); |
|
| 741 | 741 | } else { |
| 742 | 742 | $subtotal = 0.00; |
| 743 | 743 | } |
| 744 | 744 | |
| 745 | - if( $subtotal < 0 ) { |
|
| 745 | + if ($subtotal < 0) { |
|
| 746 | 746 | $subtotal = 0.00; |
| 747 | 747 | } |
| 748 | 748 | } |
| 749 | 749 | |
| 750 | - return apply_filters( 'wpinv_get_cart_items_subtotal', $subtotal ); |
|
| 750 | + return apply_filters('wpinv_get_cart_items_subtotal', $subtotal); |
|
| 751 | 751 | } |
| 752 | 752 | |
| 753 | -function wpinv_get_cart_subtotal( $items = array() ) { |
|
| 754 | - $items = !empty( $items ) ? $items : wpinv_get_cart_content_details(); |
|
| 755 | - $subtotal = wpinv_get_cart_items_subtotal( $items ); |
|
| 753 | +function wpinv_get_cart_subtotal($items = array()) { |
|
| 754 | + $items = !empty($items) ? $items : wpinv_get_cart_content_details(); |
|
| 755 | + $subtotal = wpinv_get_cart_items_subtotal($items); |
|
| 756 | 756 | |
| 757 | - return apply_filters( 'wpinv_get_cart_subtotal', $subtotal ); |
|
| 757 | + return apply_filters('wpinv_get_cart_subtotal', $subtotal); |
|
| 758 | 758 | } |
| 759 | 759 | |
| 760 | -function wpinv_cart_subtotal( $items = array(), $currency = '' ) { |
|
| 760 | +function wpinv_cart_subtotal($items = array(), $currency = '') { |
|
| 761 | 761 | |
| 762 | - if( empty( $currency ) ) { |
|
| 762 | + if (empty($currency)) { |
|
| 763 | 763 | $currency = wpinv_get_currency(); |
| 764 | 764 | } |
| 765 | 765 | |
| 766 | - $price = wpinv_price( wpinv_format_amount( wpinv_get_cart_subtotal( $items ) ), $currency ); |
|
| 766 | + $price = wpinv_price(wpinv_format_amount(wpinv_get_cart_subtotal($items)), $currency); |
|
| 767 | 767 | |
| 768 | 768 | return $price; |
| 769 | 769 | } |
| 770 | 770 | |
| 771 | -function wpinv_get_cart_total( $items = array(), $discounts = false, $invoice = array() ) { |
|
| 772 | - $subtotal = (float)wpinv_get_cart_subtotal( $items ); |
|
| 773 | - $discounts = (float)wpinv_get_cart_discounted_amount( $items ); |
|
| 774 | - $cart_tax = (float)wpinv_get_cart_tax( $items, $invoice ); |
|
| 775 | - $fees = (float)wpinv_get_cart_fee_total(); |
|
| 776 | - if ( !empty( $invoice ) && $invoice->is_free_trial() ) { |
|
| 771 | +function wpinv_get_cart_total($items = array(), $discounts = false, $invoice = array()) { |
|
| 772 | + $subtotal = (float) wpinv_get_cart_subtotal($items); |
|
| 773 | + $discounts = (float) wpinv_get_cart_discounted_amount($items); |
|
| 774 | + $cart_tax = (float) wpinv_get_cart_tax($items, $invoice); |
|
| 775 | + $fees = (float) wpinv_get_cart_fee_total(); |
|
| 776 | + if (!empty($invoice) && $invoice->is_free_trial()) { |
|
| 777 | 777 | $total = 0; |
| 778 | 778 | } else { |
| 779 | - $total = $subtotal - $discounts + $cart_tax + $fees; |
|
| 779 | + $total = $subtotal - $discounts + $cart_tax + $fees; |
|
| 780 | 780 | } |
| 781 | 781 | |
| 782 | - if ( $total < 0 ) { |
|
| 782 | + if ($total < 0) { |
|
| 783 | 783 | $total = 0.00; |
| 784 | 784 | } |
| 785 | 785 | |
| 786 | - $total = (float)apply_filters( 'wpinv_get_cart_total', $total, $items ); |
|
| 786 | + $total = (float) apply_filters('wpinv_get_cart_total', $total, $items); |
|
| 787 | 787 | |
| 788 | - return wpinv_sanitize_amount( $total ); |
|
| 788 | + return wpinv_sanitize_amount($total); |
|
| 789 | 789 | } |
| 790 | 790 | |
| 791 | -function wpinv_cart_total( $cart_items = array(), $echo = true, $invoice = array() ) { |
|
| 791 | +function wpinv_cart_total($cart_items = array(), $echo = true, $invoice = array()) { |
|
| 792 | 792 | global $cart_total; |
| 793 | - $total = wpinv_price( wpinv_format_amount( wpinv_get_cart_total( $cart_items, NULL, $invoice ) ), $invoice->get_currency() ); |
|
| 794 | - $total = apply_filters( 'wpinv_cart_total', $total, $cart_items, $invoice ); |
|
| 793 | + $total = wpinv_price(wpinv_format_amount(wpinv_get_cart_total($cart_items, NULL, $invoice)), $invoice->get_currency()); |
|
| 794 | + $total = apply_filters('wpinv_cart_total', $total, $cart_items, $invoice); |
|
| 795 | 795 | |
| 796 | 796 | $cart_total = $total; |
| 797 | 797 | |
| 798 | - if ( !$echo ) { |
|
| 798 | + if (!$echo) { |
|
| 799 | 799 | return $total; |
| 800 | 800 | } |
| 801 | 801 | |
| 802 | 802 | echo $total; |
| 803 | 803 | } |
| 804 | 804 | |
| 805 | -function wpinv_get_cart_tax( $items = array(), $invoice = 0 ) { |
|
| 805 | +function wpinv_get_cart_tax($items = array(), $invoice = 0) { |
|
| 806 | 806 | |
| 807 | - if ( ! empty( $invoice ) && ! $invoice->is_taxable() ) { |
|
| 807 | + if (!empty($invoice) && !$invoice->is_taxable()) { |
|
| 808 | 808 | return 0; |
| 809 | 809 | } |
| 810 | 810 | |
| 811 | 811 | $cart_tax = 0; |
| 812 | - $items = !empty( $items ) ? $items : wpinv_get_cart_content_details(); |
|
| 812 | + $items = !empty($items) ? $items : wpinv_get_cart_content_details(); |
|
| 813 | 813 | |
| 814 | - if ( $items ) { |
|
| 815 | - $taxes = wp_list_pluck( $items, 'tax' ); |
|
| 814 | + if ($items) { |
|
| 815 | + $taxes = wp_list_pluck($items, 'tax'); |
|
| 816 | 816 | |
| 817 | - if( is_array( $taxes ) ) { |
|
| 818 | - $cart_tax = array_sum( $taxes ); |
|
| 817 | + if (is_array($taxes)) { |
|
| 818 | + $cart_tax = array_sum($taxes); |
|
| 819 | 819 | } |
| 820 | 820 | } |
| 821 | 821 | |
| 822 | 822 | $cart_tax += wpinv_get_cart_fee_tax(); |
| 823 | 823 | |
| 824 | - return apply_filters( 'wpinv_get_cart_tax', wpinv_sanitize_amount( $cart_tax ) ); |
|
| 824 | + return apply_filters('wpinv_get_cart_tax', wpinv_sanitize_amount($cart_tax)); |
|
| 825 | 825 | } |
| 826 | 826 | |
| 827 | -function wpinv_cart_tax( $items = array(), $echo = false, $currency = '', $invoice = 0 ) { |
|
| 827 | +function wpinv_cart_tax($items = array(), $echo = false, $currency = '', $invoice = 0) { |
|
| 828 | 828 | |
| 829 | - if ( ! empty( $invoice && ! $invoice->is_taxable() ) ) { |
|
| 830 | - echo wpinv_price( wpinv_format_amount( 0 ), $currency ); |
|
| 829 | + if (!empty($invoice && !$invoice->is_taxable())) { |
|
| 830 | + echo wpinv_price(wpinv_format_amount(0), $currency); |
|
| 831 | 831 | return; |
| 832 | 832 | } |
| 833 | 833 | |
| 834 | - $cart_tax = wpinv_get_cart_tax( $items, $invoice ); |
|
| 835 | - $cart_tax = wpinv_price( wpinv_format_amount( $cart_tax ), $currency ); |
|
| 834 | + $cart_tax = wpinv_get_cart_tax($items, $invoice); |
|
| 835 | + $cart_tax = wpinv_price(wpinv_format_amount($cart_tax), $currency); |
|
| 836 | 836 | |
| 837 | - $tax = apply_filters( 'wpinv_cart_tax', $cart_tax, $items ); |
|
| 837 | + $tax = apply_filters('wpinv_cart_tax', $cart_tax, $items); |
|
| 838 | 838 | |
| 839 | - if ( !$echo ) { |
|
| 839 | + if (!$echo) { |
|
| 840 | 840 | return $tax; |
| 841 | 841 | } |
| 842 | 842 | |
| 843 | 843 | echo $tax; |
| 844 | 844 | } |
| 845 | 845 | |
| 846 | -function wpinv_get_cart_discount_code( $items = array() ) { |
|
| 846 | +function wpinv_get_cart_discount_code($items = array()) { |
|
| 847 | 847 | $invoice = wpinv_get_invoice_cart(); |
| 848 | - $cart_discount_code = !empty( $invoice ) ? $invoice->get_discount_code() : ''; |
|
| 848 | + $cart_discount_code = !empty($invoice) ? $invoice->get_discount_code() : ''; |
|
| 849 | 849 | |
| 850 | - return apply_filters( 'wpinv_get_cart_discount_code', $cart_discount_code ); |
|
| 850 | + return apply_filters('wpinv_get_cart_discount_code', $cart_discount_code); |
|
| 851 | 851 | } |
| 852 | 852 | |
| 853 | -function wpinv_cart_discount_code( $items = array(), $echo = false ) { |
|
| 854 | - $cart_discount_code = wpinv_get_cart_discount_code( $items ); |
|
| 853 | +function wpinv_cart_discount_code($items = array(), $echo = false) { |
|
| 854 | + $cart_discount_code = wpinv_get_cart_discount_code($items); |
|
| 855 | 855 | |
| 856 | - if ( $cart_discount_code != '' ) { |
|
| 856 | + if ($cart_discount_code != '') { |
|
| 857 | 857 | $cart_discount_code = ' (' . $cart_discount_code . ')'; |
| 858 | 858 | } |
| 859 | 859 | |
| 860 | - $discount_code = apply_filters( 'wpinv_cart_discount_code', $cart_discount_code, $items ); |
|
| 860 | + $discount_code = apply_filters('wpinv_cart_discount_code', $cart_discount_code, $items); |
|
| 861 | 861 | |
| 862 | - if ( !$echo ) { |
|
| 862 | + if (!$echo) { |
|
| 863 | 863 | return $discount_code; |
| 864 | 864 | } |
| 865 | 865 | |
| 866 | 866 | echo $discount_code; |
| 867 | 867 | } |
| 868 | 868 | |
| 869 | -function wpinv_get_cart_discount( $items = array() ) { |
|
| 869 | +function wpinv_get_cart_discount($items = array()) { |
|
| 870 | 870 | $invoice = wpinv_get_invoice_cart(); |
| 871 | - $cart_discount = !empty( $invoice ) ? $invoice->get_discount() : 0; |
|
| 871 | + $cart_discount = !empty($invoice) ? $invoice->get_discount() : 0; |
|
| 872 | 872 | |
| 873 | - return apply_filters( 'wpinv_get_cart_discount', wpinv_sanitize_amount( $cart_discount ), $items ); |
|
| 873 | + return apply_filters('wpinv_get_cart_discount', wpinv_sanitize_amount($cart_discount), $items); |
|
| 874 | 874 | } |
| 875 | 875 | |
| 876 | -function wpinv_cart_discount( $items = array(), $echo = false ) { |
|
| 877 | - $cart_discount = wpinv_get_cart_discount( $items ); |
|
| 878 | - $cart_discount = wpinv_price( wpinv_format_amount( $cart_discount ) ); |
|
| 876 | +function wpinv_cart_discount($items = array(), $echo = false) { |
|
| 877 | + $cart_discount = wpinv_get_cart_discount($items); |
|
| 878 | + $cart_discount = wpinv_price(wpinv_format_amount($cart_discount)); |
|
| 879 | 879 | |
| 880 | - $discount = apply_filters( 'wpinv_cart_discount', $cart_discount, $items ); |
|
| 880 | + $discount = apply_filters('wpinv_cart_discount', $cart_discount, $items); |
|
| 881 | 881 | |
| 882 | - if ( !$echo ) { |
|
| 882 | + if (!$echo) { |
|
| 883 | 883 | return $discount; |
| 884 | 884 | } |
| 885 | 885 | |
| 886 | 886 | echo $discount; |
| 887 | 887 | } |
| 888 | 888 | |
| 889 | -function wpinv_get_cart_fees( $type = 'all', $item_id = 0 ) { |
|
| 890 | - $item = new WPInv_Item( $item_id ); |
|
| 889 | +function wpinv_get_cart_fees($type = 'all', $item_id = 0) { |
|
| 890 | + $item = new WPInv_Item($item_id); |
|
| 891 | 891 | |
| 892 | - return $item->get_fees( $type, $item_id ); |
|
| 892 | + return $item->get_fees($type, $item_id); |
|
| 893 | 893 | } |
| 894 | 894 | |
| 895 | 895 | function wpinv_get_cart_fee_total() { |
| 896 | - $total = 0; |
|
| 896 | + $total = 0; |
|
| 897 | 897 | $fees = wpinv_get_cart_fees(); |
| 898 | 898 | |
| 899 | - if ( $fees ) { |
|
| 900 | - foreach ( $fees as $fee_id => $fee ) { |
|
| 899 | + if ($fees) { |
|
| 900 | + foreach ($fees as $fee_id => $fee) { |
|
| 901 | 901 | $total += $fee['amount']; |
| 902 | 902 | } |
| 903 | 903 | } |
| 904 | 904 | |
| 905 | - return apply_filters( 'wpinv_get_cart_fee_total', $total ); |
|
| 905 | + return apply_filters('wpinv_get_cart_fee_total', $total); |
|
| 906 | 906 | } |
| 907 | 907 | |
| 908 | 908 | function wpinv_get_cart_fee_tax() { |
| 909 | 909 | $tax = 0; |
| 910 | 910 | $fees = wpinv_get_cart_fees(); |
| 911 | 911 | |
| 912 | - if ( $fees ) { |
|
| 913 | - foreach ( $fees as $fee_id => $fee ) { |
|
| 914 | - if( ! empty( $fee['no_tax'] ) ) { |
|
| 912 | + if ($fees) { |
|
| 913 | + foreach ($fees as $fee_id => $fee) { |
|
| 914 | + if (!empty($fee['no_tax'])) { |
|
| 915 | 915 | continue; |
| 916 | 916 | } |
| 917 | 917 | |
| 918 | - $tax += wpinv_calculate_tax( $fee['amount'] ); |
|
| 918 | + $tax += wpinv_calculate_tax($fee['amount']); |
|
| 919 | 919 | } |
| 920 | 920 | } |
| 921 | 921 | |
| 922 | - return apply_filters( 'wpinv_get_cart_fee_tax', $tax ); |
|
| 922 | + return apply_filters('wpinv_get_cart_fee_tax', $tax); |
|
| 923 | 923 | } |
| 924 | 924 | |
| 925 | 925 | function wpinv_cart_has_recurring_item() { |
| 926 | 926 | $cart_items = wpinv_get_cart_contents(); |
| 927 | 927 | |
| 928 | - if ( empty( $cart_items ) ) { |
|
| 928 | + if (empty($cart_items)) { |
|
| 929 | 929 | return false; |
| 930 | 930 | } |
| 931 | 931 | |
| 932 | 932 | $has_subscription = false; |
| 933 | - foreach( $cart_items as $cart_item ) { |
|
| 934 | - if ( !empty( $cart_item['id'] ) && wpinv_is_recurring_item( $cart_item['id'] ) ) { |
|
| 933 | + foreach ($cart_items as $cart_item) { |
|
| 934 | + if (!empty($cart_item['id']) && wpinv_is_recurring_item($cart_item['id'])) { |
|
| 935 | 935 | $has_subscription = true; |
| 936 | 936 | break; |
| 937 | 937 | } |
| 938 | 938 | } |
| 939 | 939 | |
| 940 | - return apply_filters( 'wpinv_cart_has_recurring_item', $has_subscription, $cart_items ); |
|
| 940 | + return apply_filters('wpinv_cart_has_recurring_item', $has_subscription, $cart_items); |
|
| 941 | 941 | } |
| 942 | 942 | |
| 943 | 943 | function wpinv_cart_has_free_trial() { |
@@ -945,100 +945,100 @@ discard block |
||
| 945 | 945 | |
| 946 | 946 | $free_trial = false; |
| 947 | 947 | |
| 948 | - if ( !empty( $invoice ) && $invoice->is_free_trial() ) { |
|
| 948 | + if (!empty($invoice) && $invoice->is_free_trial()) { |
|
| 949 | 949 | $free_trial = true; |
| 950 | 950 | } |
| 951 | 951 | |
| 952 | - return apply_filters( 'wpinv_cart_has_free_trial', $free_trial, $invoice ); |
|
| 952 | + return apply_filters('wpinv_cart_has_free_trial', $free_trial, $invoice); |
|
| 953 | 953 | } |
| 954 | 954 | |
| 955 | 955 | function wpinv_get_cart_contents() { |
| 956 | 956 | $cart_details = wpinv_get_cart_details(); |
| 957 | 957 | |
| 958 | - return apply_filters( 'wpinv_get_cart_contents', $cart_details ); |
|
| 958 | + return apply_filters('wpinv_get_cart_contents', $cart_details); |
|
| 959 | 959 | } |
| 960 | 960 | |
| 961 | 961 | function wpinv_get_cart_content_details() { |
| 962 | 962 | global $wpinv_euvat, $wpi_current_id, $wpi_item_id, $wpinv_is_last_cart_item, $wpinv_flat_discount_total; |
| 963 | 963 | $cart_items = wpinv_get_cart_contents(); |
| 964 | 964 | |
| 965 | - if ( empty( $cart_items ) ) { |
|
| 965 | + if (empty($cart_items)) { |
|
| 966 | 966 | return false; |
| 967 | 967 | } |
| 968 | 968 | $invoice = wpinv_get_invoice_cart(); |
| 969 | - if ( empty( $invoice ) ) { |
|
| 969 | + if (empty($invoice)) { |
|
| 970 | 970 | return false; |
| 971 | 971 | } |
| 972 | 972 | |
| 973 | 973 | $details = array(); |
| 974 | - $length = count( $cart_items ) - 1; |
|
| 974 | + $length = count($cart_items) - 1; |
|
| 975 | 975 | |
| 976 | - if ( empty( $_POST['country'] ) ) { |
|
| 976 | + if (empty($_POST['country'])) { |
|
| 977 | 977 | $_POST['country'] = $invoice->country; |
| 978 | 978 | } |
| 979 | - if ( !isset( $_POST['state'] ) ) { |
|
| 979 | + if (!isset($_POST['state'])) { |
|
| 980 | 980 | $_POST['state'] = $invoice->state; |
| 981 | 981 | } |
| 982 | 982 | |
| 983 | - foreach( $cart_items as $key => $item ) { |
|
| 984 | - $item_id = isset( $item['id'] ) ? sanitize_text_field( $item['id'] ) : ''; |
|
| 985 | - if ( empty( $item_id ) ) { |
|
| 983 | + foreach ($cart_items as $key => $item) { |
|
| 984 | + $item_id = isset($item['id']) ? sanitize_text_field($item['id']) : ''; |
|
| 985 | + if (empty($item_id)) { |
|
| 986 | 986 | continue; |
| 987 | 987 | } |
| 988 | 988 | |
| 989 | 989 | $wpi_current_id = $invoice->ID; |
| 990 | 990 | $wpi_item_id = $item_id; |
| 991 | 991 | |
| 992 | - if ( isset( $item['custom_price'] ) && $item['custom_price'] !== '' ) { |
|
| 992 | + if (isset($item['custom_price']) && $item['custom_price'] !== '') { |
|
| 993 | 993 | $item_price = $item['custom_price']; |
| 994 | 994 | } else { |
| 995 | - if ( isset( $item['item_price'] ) && $item['item_price'] !== '' && $item['item_price'] !== false ) { |
|
| 995 | + if (isset($item['item_price']) && $item['item_price'] !== '' && $item['item_price'] !== false) { |
|
| 996 | 996 | $item_price = $item['item_price']; |
| 997 | 997 | } else { |
| 998 | - $item_price = wpinv_get_item_price( $item_id ); |
|
| 998 | + $item_price = wpinv_get_item_price($item_id); |
|
| 999 | 999 | } |
| 1000 | 1000 | } |
| 1001 | - $discount = wpinv_get_cart_item_discount_amount( $item ); |
|
| 1002 | - $discount = apply_filters( 'wpinv_get_cart_content_details_item_discount_amount', $discount, $item ); |
|
| 1003 | - $quantity = wpinv_get_cart_item_quantity( $item ); |
|
| 1004 | - $fees = wpinv_get_cart_fees( 'fee', $item_id ); |
|
| 1001 | + $discount = wpinv_get_cart_item_discount_amount($item); |
|
| 1002 | + $discount = apply_filters('wpinv_get_cart_content_details_item_discount_amount', $discount, $item); |
|
| 1003 | + $quantity = wpinv_get_cart_item_quantity($item); |
|
| 1004 | + $fees = wpinv_get_cart_fees('fee', $item_id); |
|
| 1005 | 1005 | |
| 1006 | 1006 | $subtotal = $item_price * $quantity; |
| 1007 | - $tax_rate = wpinv_get_tax_rate( $_POST['country'], $_POST['state'], $wpi_item_id ); |
|
| 1008 | - $tax_class = $wpinv_euvat->get_item_class( $item_id ); |
|
| 1009 | - $tax = wpinv_get_cart_item_tax( $item_id, $subtotal - $discount ); |
|
| 1007 | + $tax_rate = wpinv_get_tax_rate($_POST['country'], $_POST['state'], $wpi_item_id); |
|
| 1008 | + $tax_class = $wpinv_euvat->get_item_class($item_id); |
|
| 1009 | + $tax = wpinv_get_cart_item_tax($item_id, $subtotal - $discount); |
|
| 1010 | 1010 | |
| 1011 | - if ( ! $invoice->is_taxable() ) { |
|
| 1011 | + if (!$invoice->is_taxable()) { |
|
| 1012 | 1012 | $tax = 0; |
| 1013 | 1013 | } |
| 1014 | - if ( wpinv_prices_include_tax() ) { |
|
| 1015 | - $subtotal -= wpinv_round_amount( $tax ); |
|
| 1014 | + if (wpinv_prices_include_tax()) { |
|
| 1015 | + $subtotal -= wpinv_round_amount($tax); |
|
| 1016 | 1016 | } |
| 1017 | 1017 | |
| 1018 | - $total = $subtotal - $discount + $tax; |
|
| 1018 | + $total = $subtotal - $discount + $tax; |
|
| 1019 | 1019 | |
| 1020 | 1020 | // Do not allow totals to go negatve |
| 1021 | - if( $total < 0 ) { |
|
| 1021 | + if ($total < 0) { |
|
| 1022 | 1022 | $total = 0; |
| 1023 | 1023 | } |
| 1024 | 1024 | |
| 1025 | - $details[ $key ] = array( |
|
| 1025 | + $details[$key] = array( |
|
| 1026 | 1026 | 'id' => $item_id, |
| 1027 | - 'name' => !empty($item['name']) ? $item['name'] : get_the_title( $item_id ), |
|
| 1028 | - 'item_price' => wpinv_round_amount( $item_price ), |
|
| 1029 | - 'custom_price' => isset( $item['custom_price'] ) ? $item['custom_price'] : '', |
|
| 1027 | + 'name' => !empty($item['name']) ? $item['name'] : get_the_title($item_id), |
|
| 1028 | + 'item_price' => wpinv_round_amount($item_price), |
|
| 1029 | + 'custom_price' => isset($item['custom_price']) ? $item['custom_price'] : '', |
|
| 1030 | 1030 | 'quantity' => $quantity, |
| 1031 | - 'discount' => wpinv_round_amount( $discount ), |
|
| 1032 | - 'subtotal' => wpinv_round_amount( $subtotal ), |
|
| 1033 | - 'tax' => wpinv_round_amount( $tax ), |
|
| 1034 | - 'price' => wpinv_round_amount( $total ), |
|
| 1031 | + 'discount' => wpinv_round_amount($discount), |
|
| 1032 | + 'subtotal' => wpinv_round_amount($subtotal), |
|
| 1033 | + 'tax' => wpinv_round_amount($tax), |
|
| 1034 | + 'price' => wpinv_round_amount($total), |
|
| 1035 | 1035 | 'vat_rates_class' => $tax_class, |
| 1036 | 1036 | 'vat_rate' => $tax_rate, |
| 1037 | - 'meta' => isset( $item['meta'] ) ? $item['meta'] : array(), |
|
| 1037 | + 'meta' => isset($item['meta']) ? $item['meta'] : array(), |
|
| 1038 | 1038 | 'fees' => $fees, |
| 1039 | 1039 | ); |
| 1040 | 1040 | |
| 1041 | - if ( $wpinv_is_last_cart_item ) { |
|
| 1041 | + if ($wpinv_is_last_cart_item) { |
|
| 1042 | 1042 | $wpinv_is_last_cart_item = false; |
| 1043 | 1043 | $wpinv_flat_discount_total = 0.00; |
| 1044 | 1044 | } |
@@ -1047,67 +1047,67 @@ discard block |
||
| 1047 | 1047 | return $details; |
| 1048 | 1048 | } |
| 1049 | 1049 | |
| 1050 | -function wpinv_get_cart_details( $invoice_id = 0 ) { |
|
| 1050 | +function wpinv_get_cart_details($invoice_id = 0) { |
|
| 1051 | 1051 | global $ajax_cart_details; |
| 1052 | 1052 | |
| 1053 | - $invoice = wpinv_get_invoice_cart( $invoice_id ); |
|
| 1053 | + $invoice = wpinv_get_invoice_cart($invoice_id); |
|
| 1054 | 1054 | $cart_details = $ajax_cart_details; |
| 1055 | - if ( empty( $cart_details ) && ! empty( $invoice->cart_details ) ) { |
|
| 1055 | + if (empty($cart_details) && !empty($invoice->cart_details)) { |
|
| 1056 | 1056 | $cart_details = $invoice->cart_details; |
| 1057 | 1057 | } |
| 1058 | 1058 | |
| 1059 | - if ( ! empty( $cart_details ) && is_array( $cart_details ) ) { |
|
| 1060 | - $invoice_currency = ! empty( $invoice->currency ) ? $invoice->currency : wpinv_get_default_country(); |
|
| 1059 | + if (!empty($cart_details) && is_array($cart_details)) { |
|
| 1060 | + $invoice_currency = !empty($invoice->currency) ? $invoice->currency : wpinv_get_default_country(); |
|
| 1061 | 1061 | |
| 1062 | - foreach ( $cart_details as $key => $cart_item ) { |
|
| 1063 | - $cart_details[ $key ]['currency'] = $invoice_currency; |
|
| 1062 | + foreach ($cart_details as $key => $cart_item) { |
|
| 1063 | + $cart_details[$key]['currency'] = $invoice_currency; |
|
| 1064 | 1064 | |
| 1065 | - if ( ! isset( $cart_item['subtotal'] ) ) { |
|
| 1066 | - $cart_details[ $key ]['subtotal'] = $cart_item['price']; |
|
| 1065 | + if (!isset($cart_item['subtotal'])) { |
|
| 1066 | + $cart_details[$key]['subtotal'] = $cart_item['price']; |
|
| 1067 | 1067 | } |
| 1068 | 1068 | } |
| 1069 | 1069 | } |
| 1070 | 1070 | |
| 1071 | - return apply_filters( 'wpinv_get_cart_details', $cart_details, $invoice_id ); |
|
| 1071 | + return apply_filters('wpinv_get_cart_details', $cart_details, $invoice_id); |
|
| 1072 | 1072 | } |
| 1073 | 1073 | |
| 1074 | -function wpinv_record_status_change( $invoice_id, $new_status, $old_status ) { |
|
| 1075 | - if ( 'wpi_invoice' != get_post_type( $invoice_id ) ) { |
|
| 1074 | +function wpinv_record_status_change($invoice_id, $new_status, $old_status) { |
|
| 1075 | + if ('wpi_invoice' != get_post_type($invoice_id)) { |
|
| 1076 | 1076 | return; |
| 1077 | 1077 | } |
| 1078 | 1078 | |
| 1079 | - if ( ( $old_status == 'wpi-pending' && $new_status == 'draft' ) || ( $old_status == 'draft' && $new_status == 'wpi-pending' ) ) { |
|
| 1079 | + if (($old_status == 'wpi-pending' && $new_status == 'draft') || ($old_status == 'draft' && $new_status == 'wpi-pending')) { |
|
| 1080 | 1080 | return; |
| 1081 | 1081 | } |
| 1082 | 1082 | |
| 1083 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
| 1083 | + $invoice = wpinv_get_invoice($invoice_id); |
|
| 1084 | 1084 | |
| 1085 | - $old_status = wpinv_status_nicename( $old_status ); |
|
| 1086 | - $new_status = wpinv_status_nicename( $new_status ); |
|
| 1085 | + $old_status = wpinv_status_nicename($old_status); |
|
| 1086 | + $new_status = wpinv_status_nicename($new_status); |
|
| 1087 | 1087 | |
| 1088 | - $status_change = sprintf( __( 'Invoice status changed from %s to %s', 'invoicing' ), $old_status, $new_status ); |
|
| 1088 | + $status_change = sprintf(__('Invoice status changed from %s to %s', 'invoicing'), $old_status, $new_status); |
|
| 1089 | 1089 | |
| 1090 | 1090 | // Add note |
| 1091 | - return $invoice->add_note( $status_change, false, false, true ); |
|
| 1091 | + return $invoice->add_note($status_change, false, false, true); |
|
| 1092 | 1092 | } |
| 1093 | -add_action( 'wpinv_update_status', 'wpinv_record_status_change', 100, 3 ); |
|
| 1093 | +add_action('wpinv_update_status', 'wpinv_record_status_change', 100, 3); |
|
| 1094 | 1094 | |
| 1095 | -function wpinv_complete_payment( $invoice_id, $new_status, $old_status ) { |
|
| 1095 | +function wpinv_complete_payment($invoice_id, $new_status, $old_status) { |
|
| 1096 | 1096 | global $wpi_has_free_trial; |
| 1097 | 1097 | |
| 1098 | 1098 | $wpi_has_free_trial = false; |
| 1099 | 1099 | |
| 1100 | - if ( $old_status == 'publish' ) { |
|
| 1100 | + if ($old_status == 'publish') { |
|
| 1101 | 1101 | return; // Make sure that payments are only paid once |
| 1102 | 1102 | } |
| 1103 | 1103 | |
| 1104 | 1104 | // Make sure the payment completion is only processed when new status is paid |
| 1105 | - if ( $new_status != 'publish' ) { |
|
| 1105 | + if ($new_status != 'publish') { |
|
| 1106 | 1106 | return; |
| 1107 | 1107 | } |
| 1108 | 1108 | |
| 1109 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
| 1110 | - if ( empty( $invoice ) ) { |
|
| 1109 | + $invoice = new WPInv_Invoice($invoice_id); |
|
| 1110 | + if (empty($invoice)) { |
|
| 1111 | 1111 | return; |
| 1112 | 1112 | } |
| 1113 | 1113 | |
@@ -1115,58 +1115,58 @@ discard block |
||
| 1115 | 1115 | $completed_date = $invoice->completed_date; |
| 1116 | 1116 | $cart_details = $invoice->cart_details; |
| 1117 | 1117 | |
| 1118 | - do_action( 'wpinv_pre_complete_payment', $invoice_id ); |
|
| 1118 | + do_action('wpinv_pre_complete_payment', $invoice_id); |
|
| 1119 | 1119 | |
| 1120 | - if ( is_array( $cart_details ) ) { |
|
| 1120 | + if (is_array($cart_details)) { |
|
| 1121 | 1121 | // Increase purchase count and earnings |
| 1122 | - foreach ( $cart_details as $cart_index => $item ) { |
|
| 1122 | + foreach ($cart_details as $cart_index => $item) { |
|
| 1123 | 1123 | // Ensure these actions only run once, ever |
| 1124 | - if ( empty( $completed_date ) ) { |
|
| 1125 | - do_action( 'wpinv_complete_item_payment', $item['id'], $invoice_id, $item, $cart_index ); |
|
| 1124 | + if (empty($completed_date)) { |
|
| 1125 | + do_action('wpinv_complete_item_payment', $item['id'], $invoice_id, $item, $cart_index); |
|
| 1126 | 1126 | } |
| 1127 | 1127 | } |
| 1128 | 1128 | } |
| 1129 | 1129 | |
| 1130 | 1130 | // Check for discount codes and increment their use counts |
| 1131 | - if ( $discounts = $invoice->get_discounts( true ) ) { |
|
| 1132 | - if( ! empty( $discounts ) ) { |
|
| 1133 | - foreach( $discounts as $code ) { |
|
| 1134 | - wpinv_increase_discount_usage( $code ); |
|
| 1131 | + if ($discounts = $invoice->get_discounts(true)) { |
|
| 1132 | + if (!empty($discounts)) { |
|
| 1133 | + foreach ($discounts as $code) { |
|
| 1134 | + wpinv_increase_discount_usage($code); |
|
| 1135 | 1135 | } |
| 1136 | 1136 | } |
| 1137 | 1137 | } |
| 1138 | 1138 | |
| 1139 | 1139 | // Ensure this action only runs once ever |
| 1140 | - if( empty( $completed_date ) ) { |
|
| 1140 | + if (empty($completed_date)) { |
|
| 1141 | 1141 | // Save the completed date |
| 1142 | - $invoice->set( 'completed_date', current_time( 'mysql', 0 ) ); |
|
| 1142 | + $invoice->set('completed_date', current_time('mysql', 0)); |
|
| 1143 | 1143 | $invoice->save(); |
| 1144 | 1144 | |
| 1145 | - do_action( 'wpinv_complete_payment', $invoice_id ); |
|
| 1145 | + do_action('wpinv_complete_payment', $invoice_id); |
|
| 1146 | 1146 | } |
| 1147 | 1147 | |
| 1148 | 1148 | // Empty the shopping cart |
| 1149 | 1149 | wpinv_empty_cart(); |
| 1150 | 1150 | } |
| 1151 | -add_action( 'wpinv_update_status', 'wpinv_complete_payment', 100, 3 ); |
|
| 1151 | +add_action('wpinv_update_status', 'wpinv_complete_payment', 100, 3); |
|
| 1152 | 1152 | |
| 1153 | -function wpinv_update_payment_status( $invoice_id, $new_status = 'publish' ) { |
|
| 1154 | - $invoice = !empty( $invoice_id ) && is_object( $invoice_id ) ? $invoice_id : wpinv_get_invoice( (int)$invoice_id ); |
|
| 1153 | +function wpinv_update_payment_status($invoice_id, $new_status = 'publish') { |
|
| 1154 | + $invoice = !empty($invoice_id) && is_object($invoice_id) ? $invoice_id : wpinv_get_invoice((int) $invoice_id); |
|
| 1155 | 1155 | |
| 1156 | - if ( empty( $invoice ) ) { |
|
| 1156 | + if (empty($invoice)) { |
|
| 1157 | 1157 | return false; |
| 1158 | 1158 | } |
| 1159 | 1159 | |
| 1160 | - return $invoice->update_status( $new_status ); |
|
| 1160 | + return $invoice->update_status($new_status); |
|
| 1161 | 1161 | } |
| 1162 | 1162 | |
| 1163 | -function wpinv_cart_has_fees( $type = 'all' ) { |
|
| 1163 | +function wpinv_cart_has_fees($type = 'all') { |
|
| 1164 | 1164 | return false; |
| 1165 | 1165 | } |
| 1166 | 1166 | |
| 1167 | 1167 | function wpinv_validate_checkout_fields() { |
| 1168 | 1168 | // Check if there is $_POST |
| 1169 | - if ( empty( $_POST ) ) { |
|
| 1169 | + if (empty($_POST)) { |
|
| 1170 | 1170 | return false; |
| 1171 | 1171 | } |
| 1172 | 1172 | |
@@ -1189,28 +1189,28 @@ discard block |
||
| 1189 | 1189 | |
| 1190 | 1190 | $invoice = wpinv_get_invoice_cart(); |
| 1191 | 1191 | $has_subscription = $invoice->is_recurring(); |
| 1192 | - if ( empty( $invoice ) ) { |
|
| 1193 | - wpinv_set_error( 'invalid_invoice', __( 'Your cart is empty.', 'invoicing' ) ); |
|
| 1192 | + if (empty($invoice)) { |
|
| 1193 | + wpinv_set_error('invalid_invoice', __('Your cart is empty.', 'invoicing')); |
|
| 1194 | 1194 | return $gateway; |
| 1195 | 1195 | } |
| 1196 | 1196 | |
| 1197 | 1197 | // Check if a gateway value is present |
| 1198 | - if ( !empty( $_REQUEST['wpi-gateway'] ) ) { |
|
| 1199 | - $gateway = sanitize_text_field( $_REQUEST['wpi-gateway'] ); |
|
| 1198 | + if (!empty($_REQUEST['wpi-gateway'])) { |
|
| 1199 | + $gateway = sanitize_text_field($_REQUEST['wpi-gateway']); |
|
| 1200 | 1200 | |
| 1201 | - if ( $invoice->is_free() ) { |
|
| 1201 | + if ($invoice->is_free()) { |
|
| 1202 | 1202 | $gateway = 'manual'; |
| 1203 | - } elseif ( !wpinv_is_gateway_active( $gateway ) ) { |
|
| 1204 | - wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway is not enabled', 'invoicing' ) ); |
|
| 1205 | - } elseif ( $has_subscription && !wpinv_gateway_support_subscription( $gateway ) ) { |
|
| 1206 | - if ( apply_filters( 'wpinv_reject_non_recurring_gateway', true ) ) { |
|
| 1207 | - wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway does not support subscription payment', 'invoicing' ) ); |
|
| 1203 | + } elseif (!wpinv_is_gateway_active($gateway)) { |
|
| 1204 | + wpinv_set_error('invalid_gateway', __('The selected payment gateway is not enabled', 'invoicing')); |
|
| 1205 | + } elseif ($has_subscription && !wpinv_gateway_support_subscription($gateway)) { |
|
| 1206 | + if (apply_filters('wpinv_reject_non_recurring_gateway', true)) { |
|
| 1207 | + wpinv_set_error('invalid_gateway', __('The selected payment gateway does not support subscription payment', 'invoicing')); |
|
| 1208 | 1208 | } |
| 1209 | 1209 | } |
| 1210 | 1210 | } |
| 1211 | 1211 | |
| 1212 | - if ( $has_subscription && count( wpinv_get_cart_contents() ) > 1 ) { |
|
| 1213 | - wpinv_set_error( 'subscription_invalid', __( 'Only one subscription may be purchased through payment per checkout.', 'invoicing' ) ); |
|
| 1212 | + if ($has_subscription && count(wpinv_get_cart_contents()) > 1) { |
|
| 1213 | + wpinv_set_error('subscription_invalid', __('Only one subscription may be purchased through payment per checkout.', 'invoicing')); |
|
| 1214 | 1214 | } |
| 1215 | 1215 | |
| 1216 | 1216 | return $gateway; |
@@ -1224,10 +1224,10 @@ discard block |
||
| 1224 | 1224 | |
| 1225 | 1225 | $error = false; |
| 1226 | 1226 | // If we have discounts, loop through them |
| 1227 | - if ( ! empty( $discounts ) ) { |
|
| 1228 | - foreach ( $discounts as $discount ) { |
|
| 1227 | + if (!empty($discounts)) { |
|
| 1228 | + foreach ($discounts as $discount) { |
|
| 1229 | 1229 | // Check if valid |
| 1230 | - if ( !wpinv_is_discount_valid( $discount, (int)$wpi_cart->get_user_id() ) ) { |
|
| 1230 | + if (!wpinv_is_discount_valid($discount, (int) $wpi_cart->get_user_id())) { |
|
| 1231 | 1231 | // Discount is not valid |
| 1232 | 1232 | $error = true; |
| 1233 | 1233 | } |
@@ -1237,20 +1237,20 @@ discard block |
||
| 1237 | 1237 | return NULL; |
| 1238 | 1238 | } |
| 1239 | 1239 | |
| 1240 | - if ( $error && !wpinv_get_errors() ) { |
|
| 1241 | - wpinv_set_error( 'invalid_discount', __( 'Discount code you entered is invalid', 'invoicing' ) ); |
|
| 1240 | + if ($error && !wpinv_get_errors()) { |
|
| 1241 | + wpinv_set_error('invalid_discount', __('Discount code you entered is invalid', 'invoicing')); |
|
| 1242 | 1242 | } |
| 1243 | 1243 | |
| 1244 | - return implode( ',', $discounts ); |
|
| 1244 | + return implode(',', $discounts); |
|
| 1245 | 1245 | } |
| 1246 | 1246 | |
| 1247 | 1247 | function wpinv_checkout_validate_cc() { |
| 1248 | 1248 | $card_data = wpinv_checkout_get_cc_info(); |
| 1249 | 1249 | |
| 1250 | 1250 | // Validate the card zip |
| 1251 | - if ( !empty( $card_data['wpinv_zip'] ) ) { |
|
| 1252 | - if ( !wpinv_checkout_validate_cc_zip( $card_data['wpinv_zip'], $card_data['wpinv_country'] ) ) { |
|
| 1253 | - wpinv_set_error( 'invalid_cc_zip', __( 'The zip / postcode you entered for your billing address is invalid', 'invoicing' ) ); |
|
| 1251 | + if (!empty($card_data['wpinv_zip'])) { |
|
| 1252 | + if (!wpinv_checkout_validate_cc_zip($card_data['wpinv_zip'], $card_data['wpinv_country'])) { |
|
| 1253 | + wpinv_set_error('invalid_cc_zip', __('The zip / postcode you entered for your billing address is invalid', 'invoicing')); |
|
| 1254 | 1254 | } |
| 1255 | 1255 | } |
| 1256 | 1256 | |
@@ -1260,28 +1260,28 @@ discard block |
||
| 1260 | 1260 | |
| 1261 | 1261 | function wpinv_checkout_get_cc_info() { |
| 1262 | 1262 | $cc_info = array(); |
| 1263 | - $cc_info['card_name'] = isset( $_POST['card_name'] ) ? sanitize_text_field( $_POST['card_name'] ) : ''; |
|
| 1264 | - $cc_info['card_number'] = isset( $_POST['card_number'] ) ? sanitize_text_field( $_POST['card_number'] ) : ''; |
|
| 1265 | - $cc_info['card_cvc'] = isset( $_POST['card_cvc'] ) ? sanitize_text_field( $_POST['card_cvc'] ) : ''; |
|
| 1266 | - $cc_info['card_exp_month'] = isset( $_POST['card_exp_month'] ) ? sanitize_text_field( $_POST['card_exp_month'] ) : ''; |
|
| 1267 | - $cc_info['card_exp_year'] = isset( $_POST['card_exp_year'] ) ? sanitize_text_field( $_POST['card_exp_year'] ) : ''; |
|
| 1268 | - $cc_info['card_address'] = isset( $_POST['wpinv_address'] ) ? sanitize_text_field( $_POST['wpinv_address'] ) : ''; |
|
| 1269 | - $cc_info['card_city'] = isset( $_POST['wpinv_city'] ) ? sanitize_text_field( $_POST['wpinv_city'] ) : ''; |
|
| 1270 | - $cc_info['card_state'] = isset( $_POST['wpinv_state'] ) ? sanitize_text_field( $_POST['wpinv_state'] ) : ''; |
|
| 1271 | - $cc_info['card_country'] = isset( $_POST['wpinv_country'] ) ? sanitize_text_field( $_POST['wpinv_country'] ) : ''; |
|
| 1272 | - $cc_info['card_zip'] = isset( $_POST['wpinv_zip'] ) ? sanitize_text_field( $_POST['wpinv_zip'] ) : ''; |
|
| 1263 | + $cc_info['card_name'] = isset($_POST['card_name']) ? sanitize_text_field($_POST['card_name']) : ''; |
|
| 1264 | + $cc_info['card_number'] = isset($_POST['card_number']) ? sanitize_text_field($_POST['card_number']) : ''; |
|
| 1265 | + $cc_info['card_cvc'] = isset($_POST['card_cvc']) ? sanitize_text_field($_POST['card_cvc']) : ''; |
|
| 1266 | + $cc_info['card_exp_month'] = isset($_POST['card_exp_month']) ? sanitize_text_field($_POST['card_exp_month']) : ''; |
|
| 1267 | + $cc_info['card_exp_year'] = isset($_POST['card_exp_year']) ? sanitize_text_field($_POST['card_exp_year']) : ''; |
|
| 1268 | + $cc_info['card_address'] = isset($_POST['wpinv_address']) ? sanitize_text_field($_POST['wpinv_address']) : ''; |
|
| 1269 | + $cc_info['card_city'] = isset($_POST['wpinv_city']) ? sanitize_text_field($_POST['wpinv_city']) : ''; |
|
| 1270 | + $cc_info['card_state'] = isset($_POST['wpinv_state']) ? sanitize_text_field($_POST['wpinv_state']) : ''; |
|
| 1271 | + $cc_info['card_country'] = isset($_POST['wpinv_country']) ? sanitize_text_field($_POST['wpinv_country']) : ''; |
|
| 1272 | + $cc_info['card_zip'] = isset($_POST['wpinv_zip']) ? sanitize_text_field($_POST['wpinv_zip']) : ''; |
|
| 1273 | 1273 | |
| 1274 | 1274 | // Return cc info |
| 1275 | 1275 | return $cc_info; |
| 1276 | 1276 | } |
| 1277 | 1277 | |
| 1278 | -function wpinv_checkout_validate_cc_zip( $zip = 0, $country_code = '' ) { |
|
| 1278 | +function wpinv_checkout_validate_cc_zip($zip = 0, $country_code = '') { |
|
| 1279 | 1279 | $ret = false; |
| 1280 | 1280 | |
| 1281 | - if ( empty( $zip ) || empty( $country_code ) ) |
|
| 1281 | + if (empty($zip) || empty($country_code)) |
|
| 1282 | 1282 | return $ret; |
| 1283 | 1283 | |
| 1284 | - $country_code = strtoupper( $country_code ); |
|
| 1284 | + $country_code = strtoupper($country_code); |
|
| 1285 | 1285 | |
| 1286 | 1286 | $zip_regex = array( |
| 1287 | 1287 | "AD" => "AD\d{3}", |
@@ -1441,72 +1441,72 @@ discard block |
||
| 1441 | 1441 | "ZM" => "\d{5}" |
| 1442 | 1442 | ); |
| 1443 | 1443 | |
| 1444 | - if ( ! isset ( $zip_regex[ $country_code ] ) || preg_match( "/" . $zip_regex[ $country_code ] . "/i", $zip ) ) |
|
| 1444 | + if (!isset ($zip_regex[$country_code]) || preg_match("/" . $zip_regex[$country_code] . "/i", $zip)) |
|
| 1445 | 1445 | $ret = true; |
| 1446 | 1446 | |
| 1447 | - return apply_filters( 'wpinv_is_zip_valid', $ret, $zip, $country_code ); |
|
| 1447 | + return apply_filters('wpinv_is_zip_valid', $ret, $zip, $country_code); |
|
| 1448 | 1448 | } |
| 1449 | 1449 | |
| 1450 | 1450 | function wpinv_checkout_validate_agree_to_terms() { |
| 1451 | 1451 | // Validate agree to terms |
| 1452 | - if ( ! isset( $_POST['wpi_agree_to_terms'] ) || $_POST['wpi_agree_to_terms'] != 1 ) { |
|
| 1452 | + if (!isset($_POST['wpi_agree_to_terms']) || $_POST['wpi_agree_to_terms'] != 1) { |
|
| 1453 | 1453 | // User did not agree |
| 1454 | - wpinv_set_error( 'agree_to_terms', apply_filters( 'wpinv_agree_to_terms_text', __( 'You must agree to the terms of use', 'invoicing' ) ) ); |
|
| 1454 | + wpinv_set_error('agree_to_terms', apply_filters('wpinv_agree_to_terms_text', __('You must agree to the terms of use', 'invoicing'))); |
|
| 1455 | 1455 | } |
| 1456 | 1456 | } |
| 1457 | 1457 | |
| 1458 | 1458 | function wpinv_checkout_validate_invoice_user() { |
| 1459 | 1459 | global $wpi_cart, $user_ID; |
| 1460 | 1460 | |
| 1461 | - if(empty($wpi_cart)){ |
|
| 1461 | + if (empty($wpi_cart)) { |
|
| 1462 | 1462 | $wpi_cart = wpinv_get_invoice_cart(); |
| 1463 | 1463 | } |
| 1464 | 1464 | |
| 1465 | - $invoice_user = (int)$wpi_cart->get_user_id(); |
|
| 1465 | + $invoice_user = (int) $wpi_cart->get_user_id(); |
|
| 1466 | 1466 | $valid_user_data = array( |
| 1467 | 1467 | 'user_id' => $invoice_user |
| 1468 | 1468 | ); |
| 1469 | 1469 | |
| 1470 | 1470 | // If guest checkout allowed |
| 1471 | - if ( !wpinv_require_login_to_checkout() ) { |
|
| 1471 | + if (!wpinv_require_login_to_checkout()) { |
|
| 1472 | 1472 | return $valid_user_data; |
| 1473 | 1473 | } |
| 1474 | 1474 | |
| 1475 | 1475 | // Verify there is a user_ID |
| 1476 | - if ( $user_ID == $invoice_user ) { |
|
| 1476 | + if ($user_ID == $invoice_user) { |
|
| 1477 | 1477 | // Get the logged in user data |
| 1478 | - $user_data = get_userdata( $user_ID ); |
|
| 1479 | - $required_fields = wpinv_checkout_required_fields(); |
|
| 1478 | + $user_data = get_userdata($user_ID); |
|
| 1479 | + $required_fields = wpinv_checkout_required_fields(); |
|
| 1480 | 1480 | |
| 1481 | 1481 | // Loop through required fields and show error messages |
| 1482 | - if ( !empty( $required_fields ) ) { |
|
| 1483 | - foreach ( $required_fields as $field_name => $value ) { |
|
| 1484 | - if ( in_array( $value, $required_fields ) && empty( $_POST[ 'wpinv_' . $field_name ] ) ) { |
|
| 1485 | - wpinv_set_error( $value['error_id'], $value['error_message'] ); |
|
| 1482 | + if (!empty($required_fields)) { |
|
| 1483 | + foreach ($required_fields as $field_name => $value) { |
|
| 1484 | + if (in_array($value, $required_fields) && empty($_POST['wpinv_' . $field_name])) { |
|
| 1485 | + wpinv_set_error($value['error_id'], $value['error_message']); |
|
| 1486 | 1486 | } |
| 1487 | 1487 | } |
| 1488 | 1488 | } |
| 1489 | 1489 | |
| 1490 | 1490 | // Verify data |
| 1491 | - if ( $user_data ) { |
|
| 1491 | + if ($user_data) { |
|
| 1492 | 1492 | // Collected logged in user data |
| 1493 | 1493 | $valid_user_data = array( |
| 1494 | 1494 | 'user_id' => $user_ID, |
| 1495 | - 'email' => isset( $_POST['wpinv_email'] ) ? sanitize_email( $_POST['wpinv_email'] ) : $user_data->user_email, |
|
| 1496 | - 'first_name' => isset( $_POST['wpinv_first_name'] ) && ! empty( $_POST['wpinv_first_name'] ) ? sanitize_text_field( $_POST['wpinv_first_name'] ) : $user_data->first_name, |
|
| 1497 | - 'last_name' => isset( $_POST['wpinv_last_name'] ) && ! empty( $_POST['wpinv_last_name'] ) ? sanitize_text_field( $_POST['wpinv_last_name'] ) : $user_data->last_name, |
|
| 1495 | + 'email' => isset($_POST['wpinv_email']) ? sanitize_email($_POST['wpinv_email']) : $user_data->user_email, |
|
| 1496 | + 'first_name' => isset($_POST['wpinv_first_name']) && !empty($_POST['wpinv_first_name']) ? sanitize_text_field($_POST['wpinv_first_name']) : $user_data->first_name, |
|
| 1497 | + 'last_name' => isset($_POST['wpinv_last_name']) && !empty($_POST['wpinv_last_name']) ? sanitize_text_field($_POST['wpinv_last_name']) : $user_data->last_name, |
|
| 1498 | 1498 | ); |
| 1499 | 1499 | |
| 1500 | - if ( !empty( $_POST[ 'wpinv_email' ] ) && !is_email( $_POST[ 'wpinv_email' ] ) ) { |
|
| 1501 | - wpinv_set_error( 'invalid_email', __( 'Please enter a valid email address', 'invoicing' ) ); |
|
| 1500 | + if (!empty($_POST['wpinv_email']) && !is_email($_POST['wpinv_email'])) { |
|
| 1501 | + wpinv_set_error('invalid_email', __('Please enter a valid email address', 'invoicing')); |
|
| 1502 | 1502 | } |
| 1503 | 1503 | } else { |
| 1504 | 1504 | // Set invalid user error |
| 1505 | - wpinv_set_error( 'invalid_user', __( 'The user billing information is invalid', 'invoicing' ) ); |
|
| 1505 | + wpinv_set_error('invalid_user', __('The user billing information is invalid', 'invoicing')); |
|
| 1506 | 1506 | } |
| 1507 | 1507 | } else { |
| 1508 | 1508 | // Set invalid user error |
| 1509 | - wpinv_set_error( 'invalid_user_id', __( 'The invalid invoice user id', 'invoicing' ) ); |
|
| 1509 | + wpinv_set_error('invalid_user_id', __('The invalid invoice user id', 'invoicing')); |
|
| 1510 | 1510 | } |
| 1511 | 1511 | |
| 1512 | 1512 | // Return user data |
@@ -1518,27 +1518,27 @@ discard block |
||
| 1518 | 1518 | |
| 1519 | 1519 | $data = array(); |
| 1520 | 1520 | |
| 1521 | - if ( is_user_logged_in() ) { |
|
| 1522 | - if ( !wpinv_require_login_to_checkout() || ( wpinv_require_login_to_checkout() && (int)$wpi_cart->get_user_id() === (int)get_current_user_id() ) ) { |
|
| 1523 | - $data['user_id'] = (int)get_current_user_id(); |
|
| 1521 | + if (is_user_logged_in()) { |
|
| 1522 | + if (!wpinv_require_login_to_checkout() || (wpinv_require_login_to_checkout() && (int) $wpi_cart->get_user_id() === (int) get_current_user_id())) { |
|
| 1523 | + $data['user_id'] = (int) get_current_user_id(); |
|
| 1524 | 1524 | } else { |
| 1525 | - wpinv_set_error( 'logged_in_only', __( 'You are not allowed to pay for this invoice', 'invoicing' ) ); |
|
| 1525 | + wpinv_set_error('logged_in_only', __('You are not allowed to pay for this invoice', 'invoicing')); |
|
| 1526 | 1526 | } |
| 1527 | 1527 | } else { |
| 1528 | 1528 | // If guest checkout allowed |
| 1529 | - if ( !wpinv_require_login_to_checkout() ) { |
|
| 1529 | + if (!wpinv_require_login_to_checkout()) { |
|
| 1530 | 1530 | $data['user_id'] = 0; |
| 1531 | 1531 | } else { |
| 1532 | - wpinv_set_error( 'logged_in_only', __( 'You must be logged in to pay for this invoice', 'invoicing' ) ); |
|
| 1532 | + wpinv_set_error('logged_in_only', __('You must be logged in to pay for this invoice', 'invoicing')); |
|
| 1533 | 1533 | } |
| 1534 | 1534 | } |
| 1535 | 1535 | |
| 1536 | 1536 | return $data; |
| 1537 | 1537 | } |
| 1538 | 1538 | |
| 1539 | -function wpinv_checkout_form_get_user( $valid_data = array() ) { |
|
| 1539 | +function wpinv_checkout_form_get_user($valid_data = array()) { |
|
| 1540 | 1540 | |
| 1541 | - if ( !empty( $valid_data['current_user']['user_id'] ) ) { |
|
| 1541 | + if (!empty($valid_data['current_user']['user_id'])) { |
|
| 1542 | 1542 | $user = $valid_data['current_user']; |
| 1543 | 1543 | } else { |
| 1544 | 1544 | // Set the valid invoice user |
@@ -1546,7 +1546,7 @@ discard block |
||
| 1546 | 1546 | } |
| 1547 | 1547 | |
| 1548 | 1548 | // Verify invoice have an user |
| 1549 | - if ( false === $user || empty( $user ) ) { |
|
| 1549 | + if (false === $user || empty($user)) { |
|
| 1550 | 1550 | return false; |
| 1551 | 1551 | } |
| 1552 | 1552 | |
@@ -1563,11 +1563,11 @@ discard block |
||
| 1563 | 1563 | 'zip', |
| 1564 | 1564 | ); |
| 1565 | 1565 | |
| 1566 | - foreach ( $address_fields as $field ) { |
|
| 1567 | - $user[$field] = !empty( $_POST['wpinv_' . $field] ) ? sanitize_text_field( $_POST['wpinv_' . $field] ) : false; |
|
| 1566 | + foreach ($address_fields as $field) { |
|
| 1567 | + $user[$field] = !empty($_POST['wpinv_' . $field]) ? sanitize_text_field($_POST['wpinv_' . $field]) : false; |
|
| 1568 | 1568 | |
| 1569 | - if ( !empty( $user['user_id'] ) && !empty( $valid_data['current_user']['user_id'] ) && $valid_data['current_user']['user_id'] == $valid_data['invoice_user']['user_id'] ) { |
|
| 1570 | - update_user_meta( $user['user_id'], '_wpinv_' . $field, $user[$field] ); |
|
| 1569 | + if (!empty($user['user_id']) && !empty($valid_data['current_user']['user_id']) && $valid_data['current_user']['user_id'] == $valid_data['invoice_user']['user_id']) { |
|
| 1570 | + update_user_meta($user['user_id'], '_wpinv_' . $field, $user[$field]); |
|
| 1571 | 1571 | } |
| 1572 | 1572 | } |
| 1573 | 1573 | |
@@ -1575,28 +1575,28 @@ discard block |
||
| 1575 | 1575 | return $user; |
| 1576 | 1576 | } |
| 1577 | 1577 | |
| 1578 | -function wpinv_set_checkout_session( $invoice_data = array() ) { |
|
| 1578 | +function wpinv_set_checkout_session($invoice_data = array()) { |
|
| 1579 | 1579 | global $wpi_session; |
| 1580 | 1580 | |
| 1581 | - return $wpi_session->set( 'wpinv_checkout', $invoice_data ); |
|
| 1581 | + return $wpi_session->set('wpinv_checkout', $invoice_data); |
|
| 1582 | 1582 | } |
| 1583 | 1583 | |
| 1584 | 1584 | function wpinv_get_checkout_session() { |
| 1585 | 1585 | global $wpi_session; |
| 1586 | 1586 | |
| 1587 | - return $wpi_session->get( 'wpinv_checkout' ); |
|
| 1587 | + return $wpi_session->get('wpinv_checkout'); |
|
| 1588 | 1588 | } |
| 1589 | 1589 | |
| 1590 | 1590 | function wpinv_empty_cart() { |
| 1591 | 1591 | global $wpi_session; |
| 1592 | 1592 | |
| 1593 | 1593 | // Remove cart contents |
| 1594 | - $wpi_session->set( 'wpinv_checkout', NULL ); |
|
| 1594 | + $wpi_session->set('wpinv_checkout', NULL); |
|
| 1595 | 1595 | |
| 1596 | 1596 | // Remove all cart fees |
| 1597 | - $wpi_session->set( 'wpi_cart_fees', NULL ); |
|
| 1597 | + $wpi_session->set('wpi_cart_fees', NULL); |
|
| 1598 | 1598 | |
| 1599 | - do_action( 'wpinv_empty_cart' ); |
|
| 1599 | + do_action('wpinv_empty_cart'); |
|
| 1600 | 1600 | } |
| 1601 | 1601 | |
| 1602 | 1602 | function wpinv_process_checkout() { |
@@ -1605,7 +1605,7 @@ discard block |
||
| 1605 | 1605 | wpinv_clear_errors(); |
| 1606 | 1606 | |
| 1607 | 1607 | $invoice = wpinv_get_invoice_cart(); |
| 1608 | - if ( empty( $invoice ) ) { |
|
| 1608 | + if (empty($invoice)) { |
|
| 1609 | 1609 | return false; |
| 1610 | 1610 | } |
| 1611 | 1611 | |
@@ -1613,42 +1613,42 @@ discard block |
||
| 1613 | 1613 | |
| 1614 | 1614 | $wpi_checkout_id = $invoice->ID; |
| 1615 | 1615 | |
| 1616 | - do_action( 'wpinv_pre_process_checkout' ); |
|
| 1616 | + do_action('wpinv_pre_process_checkout'); |
|
| 1617 | 1617 | |
| 1618 | - if ( !wpinv_get_cart_contents() ) { // Make sure the cart isn't empty |
|
| 1618 | + if (!wpinv_get_cart_contents()) { // Make sure the cart isn't empty |
|
| 1619 | 1619 | $valid_data = false; |
| 1620 | - wpinv_set_error( 'empty_cart', __( 'Your cart is empty', 'invoicing' ) ); |
|
| 1620 | + wpinv_set_error('empty_cart', __('Your cart is empty', 'invoicing')); |
|
| 1621 | 1621 | } else { |
| 1622 | 1622 | // Validate the form $_POST data |
| 1623 | 1623 | $valid_data = wpinv_validate_checkout_fields(); |
| 1624 | 1624 | |
| 1625 | 1625 | // Allow themes and plugins to hook to errors |
| 1626 | - do_action( 'wpinv_checkout_error_checks', $valid_data, $_POST ); |
|
| 1626 | + do_action('wpinv_checkout_error_checks', $valid_data, $_POST); |
|
| 1627 | 1627 | } |
| 1628 | 1628 | |
| 1629 | - $is_ajax = defined( 'DOING_AJAX' ) && DOING_AJAX; |
|
| 1629 | + $is_ajax = defined('DOING_AJAX') && DOING_AJAX; |
|
| 1630 | 1630 | |
| 1631 | 1631 | // Validate the user |
| 1632 | - $user = wpinv_checkout_form_get_user( $valid_data ); |
|
| 1632 | + $user = wpinv_checkout_form_get_user($valid_data); |
|
| 1633 | 1633 | |
| 1634 | 1634 | // Let extensions validate fields after user is logged in if user has used login/registration form |
| 1635 | - do_action( 'wpinv_checkout_user_error_checks', $user, $valid_data, $_POST ); |
|
| 1635 | + do_action('wpinv_checkout_user_error_checks', $user, $valid_data, $_POST); |
|
| 1636 | 1636 | |
| 1637 | - if ( false === $valid_data || wpinv_get_errors() || ! $user ) { |
|
| 1638 | - if ( $is_ajax && 'wpinv_payment_form' != $_REQUEST['action'] ) { |
|
| 1639 | - do_action( 'wpinv_ajax_checkout_errors' ); |
|
| 1637 | + if (false === $valid_data || wpinv_get_errors() || !$user) { |
|
| 1638 | + if ($is_ajax && 'wpinv_payment_form' != $_REQUEST['action']) { |
|
| 1639 | + do_action('wpinv_ajax_checkout_errors'); |
|
| 1640 | 1640 | die(); |
| 1641 | 1641 | } else { |
| 1642 | 1642 | return false; |
| 1643 | 1643 | } |
| 1644 | 1644 | } |
| 1645 | 1645 | |
| 1646 | - if ( $is_ajax && 'wpinv_payment_form' != $_REQUEST['action'] ) { |
|
| 1646 | + if ($is_ajax && 'wpinv_payment_form' != $_REQUEST['action']) { |
|
| 1647 | 1647 | // Save address fields. |
| 1648 | - $address_fields = array( 'first_name', 'last_name', 'phone', 'address', 'city', 'country', 'state', 'zip', 'company' ); |
|
| 1649 | - foreach ( $address_fields as $field ) { |
|
| 1650 | - if ( isset( $user[$field] ) ) { |
|
| 1651 | - $invoice->set( $field, $user[$field] ); |
|
| 1648 | + $address_fields = array('first_name', 'last_name', 'phone', 'address', 'city', 'country', 'state', 'zip', 'company'); |
|
| 1649 | + foreach ($address_fields as $field) { |
|
| 1650 | + if (isset($user[$field])) { |
|
| 1651 | + $invoice->set($field, $user[$field]); |
|
| 1652 | 1652 | } |
| 1653 | 1653 | |
| 1654 | 1654 | $invoice->save(); |
@@ -1656,16 +1656,16 @@ discard block |
||
| 1656 | 1656 | |
| 1657 | 1657 | $response['success'] = true; |
| 1658 | 1658 | $response['data']['subtotal'] = $invoice->get_subtotal(); |
| 1659 | - $response['data']['subtotalf'] = $invoice->get_subtotal( true ); |
|
| 1659 | + $response['data']['subtotalf'] = $invoice->get_subtotal(true); |
|
| 1660 | 1660 | $response['data']['discount'] = $invoice->get_discount(); |
| 1661 | - $response['data']['discountf'] = $invoice->get_discount( true ); |
|
| 1661 | + $response['data']['discountf'] = $invoice->get_discount(true); |
|
| 1662 | 1662 | $response['data']['tax'] = $invoice->get_tax(); |
| 1663 | - $response['data']['taxf'] = $invoice->get_tax( true ); |
|
| 1663 | + $response['data']['taxf'] = $invoice->get_tax(true); |
|
| 1664 | 1664 | $response['data']['total'] = $invoice->get_total(); |
| 1665 | - $response['data']['totalf'] = $invoice->get_total( true ); |
|
| 1666 | - $response['data']['free'] = $invoice->is_free() && ( ! ( (float) $response['data']['total'] > 0 ) || $invoice->is_free_trial() ) ? true : false; |
|
| 1665 | + $response['data']['totalf'] = $invoice->get_total(true); |
|
| 1666 | + $response['data']['free'] = $invoice->is_free() && (!((float) $response['data']['total'] > 0) || $invoice->is_free_trial()) ? true : false; |
|
| 1667 | 1667 | |
| 1668 | - wp_send_json( $response ); |
|
| 1668 | + wp_send_json($response); |
|
| 1669 | 1669 | } |
| 1670 | 1670 | |
| 1671 | 1671 | $user_info = array( |
@@ -1687,42 +1687,42 @@ discard block |
||
| 1687 | 1687 | |
| 1688 | 1688 | // Setup invoice information |
| 1689 | 1689 | $invoice_data = array( |
| 1690 | - 'invoice_id' => !empty( $invoice ) ? $invoice->ID : 0, |
|
| 1690 | + 'invoice_id' => !empty($invoice) ? $invoice->ID : 0, |
|
| 1691 | 1691 | 'items' => $cart_items, |
| 1692 | 1692 | 'cart_discounts' => $discounts, |
| 1693 | - 'fees' => wpinv_get_cart_fees(), // Any arbitrary fees that have been added to the cart |
|
| 1694 | - 'subtotal' => wpinv_get_cart_subtotal( $cart_items ), // Amount before taxes and discounts |
|
| 1695 | - 'discount' => wpinv_get_cart_items_discount_amount( $cart_items, $discounts ), // Discounted amount |
|
| 1696 | - 'tax' => wpinv_get_cart_tax( $cart_items, $invoice ), // Taxed amount |
|
| 1697 | - 'price' => wpinv_get_cart_total( $cart_items, $discounts ), // Amount after taxes |
|
| 1693 | + 'fees' => wpinv_get_cart_fees(), // Any arbitrary fees that have been added to the cart |
|
| 1694 | + 'subtotal' => wpinv_get_cart_subtotal($cart_items), // Amount before taxes and discounts |
|
| 1695 | + 'discount' => wpinv_get_cart_items_discount_amount($cart_items, $discounts), // Discounted amount |
|
| 1696 | + 'tax' => wpinv_get_cart_tax($cart_items, $invoice), // Taxed amount |
|
| 1697 | + 'price' => wpinv_get_cart_total($cart_items, $discounts), // Amount after taxes |
|
| 1698 | 1698 | 'invoice_key' => $invoice->get_key() ? $invoice->get_key() : $invoice->generate_key(), |
| 1699 | 1699 | 'user_email' => $invoice->get_email(), |
| 1700 | - 'date' => date( 'Y-m-d H:i:s', current_time( 'timestamp' ) ), |
|
| 1701 | - 'user_info' => stripslashes_deep( $user_info ), |
|
| 1700 | + 'date' => date('Y-m-d H:i:s', current_time('timestamp')), |
|
| 1701 | + 'user_info' => stripslashes_deep($user_info), |
|
| 1702 | 1702 | 'post_data' => $_POST, |
| 1703 | 1703 | 'cart_details' => $cart_items, |
| 1704 | 1704 | 'gateway' => $valid_data['gateway'], |
| 1705 | 1705 | 'card_info' => $valid_data['cc_info'] |
| 1706 | 1706 | ); |
| 1707 | 1707 | |
| 1708 | - $vat_info = $wpinv_euvat->current_vat_data(); |
|
| 1709 | - if ( is_array( $vat_info ) ) { |
|
| 1708 | + $vat_info = $wpinv_euvat->current_vat_data(); |
|
| 1709 | + if (is_array($vat_info)) { |
|
| 1710 | 1710 | $invoice_data['user_info']['vat_number'] = $vat_info['number']; |
| 1711 | 1711 | $invoice_data['user_info']['vat_rate'] = wpinv_get_tax_rate($invoice_data['user_info']['country'], $invoice_data['user_info']['state']); |
| 1712 | - $invoice_data['user_info']['adddress_confirmed'] = isset($vat_info['adddress_confirmed']) ? $vat_info['adddress_confirmed'] : false; |
|
| 1712 | + $invoice_data['user_info']['adddress_confirmed'] = isset($vat_info['adddress_confirmed']) ? $vat_info['adddress_confirmed'] : false; |
|
| 1713 | 1713 | |
| 1714 | 1714 | // Add the VAT rate to each item in the cart |
| 1715 | - foreach( $invoice_data['cart_details'] as $key => $item_data) { |
|
| 1715 | + foreach ($invoice_data['cart_details'] as $key => $item_data) { |
|
| 1716 | 1716 | $rate = wpinv_get_tax_rate($invoice_data['user_info']['country'], $invoice_data['user_info']['state'], $item_data['id']); |
| 1717 | - $invoice_data['cart_details'][$key]['vat_rate'] = wpinv_round_amount( $rate, 4 ); |
|
| 1717 | + $invoice_data['cart_details'][$key]['vat_rate'] = wpinv_round_amount($rate, 4); |
|
| 1718 | 1718 | } |
| 1719 | 1719 | } |
| 1720 | 1720 | |
| 1721 | 1721 | // Save vat fields. |
| 1722 | - $address_fields = array( 'vat_number', 'vat_rate', 'adddress_confirmed' ); |
|
| 1723 | - foreach ( $address_fields as $field ) { |
|
| 1724 | - if ( isset( $invoice_data['user_info'][$field] ) ) { |
|
| 1725 | - $invoice->set( $field, $invoice_data['user_info'][$field] ); |
|
| 1722 | + $address_fields = array('vat_number', 'vat_rate', 'adddress_confirmed'); |
|
| 1723 | + foreach ($address_fields as $field) { |
|
| 1724 | + if (isset($invoice_data['user_info'][$field])) { |
|
| 1725 | + $invoice->set($field, $invoice_data['user_info'][$field]); |
|
| 1726 | 1726 | } |
| 1727 | 1727 | } |
| 1728 | 1728 | $invoice->save(); |
@@ -1731,54 +1731,54 @@ discard block |
||
| 1731 | 1731 | $valid_data['user'] = $user; |
| 1732 | 1732 | |
| 1733 | 1733 | // Allow themes and plugins to hook before the gateway |
| 1734 | - do_action( 'wpinv_checkout_before_gateway', $_POST, $user_info, $valid_data ); |
|
| 1734 | + do_action('wpinv_checkout_before_gateway', $_POST, $user_info, $valid_data); |
|
| 1735 | 1735 | |
| 1736 | 1736 | // If it is free, abort. |
| 1737 | - if ( $invoice->is_free() && ( ! $invoice->is_recurring() || 0 == $invoice->get_recurring_details( 'total' ) ) ) { |
|
| 1737 | + if ($invoice->is_free() && (!$invoice->is_recurring() || 0 == $invoice->get_recurring_details('total'))) { |
|
| 1738 | 1738 | $invoice_data['gateway'] = 'manual'; |
| 1739 | 1739 | $_POST['wpi-gateway'] = 'manual'; |
| 1740 | 1740 | } |
| 1741 | 1741 | |
| 1742 | 1742 | // Allow the invoice data to be modified before it is sent to the gateway |
| 1743 | - $invoice_data = apply_filters( 'wpinv_data_before_gateway', $invoice_data, $valid_data ); |
|
| 1743 | + $invoice_data = apply_filters('wpinv_data_before_gateway', $invoice_data, $valid_data); |
|
| 1744 | 1744 | |
| 1745 | - if ( $invoice_data['price'] && $invoice_data['gateway'] == 'manual' ) { |
|
| 1745 | + if ($invoice_data['price'] && $invoice_data['gateway'] == 'manual') { |
|
| 1746 | 1746 | $mode = 'test'; |
| 1747 | 1747 | } else { |
| 1748 | - $mode = wpinv_is_test_mode( $invoice_data['gateway'] ) ? 'test' : 'live'; |
|
| 1748 | + $mode = wpinv_is_test_mode($invoice_data['gateway']) ? 'test' : 'live'; |
|
| 1749 | 1749 | } |
| 1750 | 1750 | |
| 1751 | 1751 | // Setup the data we're storing in the purchase session |
| 1752 | 1752 | $session_data = $invoice_data; |
| 1753 | 1753 | // Make sure credit card numbers are never stored in sessions |
| 1754 | - if ( !empty( $session_data['card_info']['card_number'] ) ) { |
|
| 1755 | - unset( $session_data['card_info']['card_number'] ); |
|
| 1754 | + if (!empty($session_data['card_info']['card_number'])) { |
|
| 1755 | + unset($session_data['card_info']['card_number']); |
|
| 1756 | 1756 | } |
| 1757 | 1757 | |
| 1758 | 1758 | // Used for showing item links to non logged-in users after purchase, and for other plugins needing purchase data. |
| 1759 | - wpinv_set_checkout_session( $invoice_data ); |
|
| 1759 | + wpinv_set_checkout_session($invoice_data); |
|
| 1760 | 1760 | |
| 1761 | 1761 | // Set gateway |
| 1762 | - $invoice->update_meta( '_wpinv_gateway', $invoice_data['gateway'] ); |
|
| 1763 | - $invoice->update_meta( '_wpinv_mode', $mode ); |
|
| 1764 | - $invoice->update_meta( '_wpinv_checkout', date_i18n( 'Y-m-d H:i:s', current_time( 'timestamp' ) ) ); |
|
| 1762 | + $invoice->update_meta('_wpinv_gateway', $invoice_data['gateway']); |
|
| 1763 | + $invoice->update_meta('_wpinv_mode', $mode); |
|
| 1764 | + $invoice->update_meta('_wpinv_checkout', date_i18n('Y-m-d H:i:s', current_time('timestamp'))); |
|
| 1765 | 1765 | |
| 1766 | - do_action( 'wpinv_checkout_before_send_to_gateway', $invoice, $invoice_data ); |
|
| 1766 | + do_action('wpinv_checkout_before_send_to_gateway', $invoice, $invoice_data); |
|
| 1767 | 1767 | |
| 1768 | 1768 | // Send info to the gateway for payment processing |
| 1769 | - wpinv_send_to_gateway( $invoice_data['gateway'], $invoice_data ); |
|
| 1769 | + wpinv_send_to_gateway($invoice_data['gateway'], $invoice_data); |
|
| 1770 | 1770 | die(); |
| 1771 | 1771 | } |
| 1772 | -add_action( 'wpinv_payment', 'wpinv_process_checkout' ); |
|
| 1772 | +add_action('wpinv_payment', 'wpinv_process_checkout'); |
|
| 1773 | 1773 | |
| 1774 | -function wpinv_get_invoices( $args ) { |
|
| 1775 | - $args = wp_parse_args( $args, array( |
|
| 1776 | - 'status' => array_keys( wpinv_get_invoice_statuses() ), |
|
| 1774 | +function wpinv_get_invoices($args) { |
|
| 1775 | + $args = wp_parse_args($args, array( |
|
| 1776 | + 'status' => array_keys(wpinv_get_invoice_statuses()), |
|
| 1777 | 1777 | 'type' => 'wpi_invoice', |
| 1778 | 1778 | 'parent' => null, |
| 1779 | 1779 | 'user' => null, |
| 1780 | 1780 | 'email' => '', |
| 1781 | - 'limit' => get_option( 'posts_per_page' ), |
|
| 1781 | + 'limit' => get_option('posts_per_page'), |
|
| 1782 | 1782 | 'offset' => null, |
| 1783 | 1783 | 'page' => 1, |
| 1784 | 1784 | 'exclude' => array(), |
@@ -1786,7 +1786,7 @@ discard block |
||
| 1786 | 1786 | 'order' => 'DESC', |
| 1787 | 1787 | 'return' => 'objects', |
| 1788 | 1788 | 'paginate' => false, |
| 1789 | - ) ); |
|
| 1789 | + )); |
|
| 1790 | 1790 | |
| 1791 | 1791 | // Handle some BW compatibility arg names where wp_query args differ in naming. |
| 1792 | 1792 | $map_legacy = array( |
@@ -1799,18 +1799,18 @@ discard block |
||
| 1799 | 1799 | 'paged' => 'page', |
| 1800 | 1800 | ); |
| 1801 | 1801 | |
| 1802 | - foreach ( $map_legacy as $from => $to ) { |
|
| 1803 | - if ( isset( $args[ $from ] ) ) { |
|
| 1804 | - $args[ $to ] = $args[ $from ]; |
|
| 1802 | + foreach ($map_legacy as $from => $to) { |
|
| 1803 | + if (isset($args[$from])) { |
|
| 1804 | + $args[$to] = $args[$from]; |
|
| 1805 | 1805 | } |
| 1806 | 1806 | } |
| 1807 | 1807 | |
| 1808 | - if ( get_query_var( 'paged' ) ) |
|
| 1808 | + if (get_query_var('paged')) |
|
| 1809 | 1809 | $args['page'] = get_query_var('paged'); |
| 1810 | - else if ( get_query_var( 'page' ) ) |
|
| 1811 | - $args['page'] = get_query_var( 'page' ); |
|
| 1812 | - else if ( !empty( $args[ 'page' ] ) ) |
|
| 1813 | - $args['page'] = $args[ 'page' ]; |
|
| 1810 | + else if (get_query_var('page')) |
|
| 1811 | + $args['page'] = get_query_var('page'); |
|
| 1812 | + else if (!empty($args['page'])) |
|
| 1813 | + $args['page'] = $args['page']; |
|
| 1814 | 1814 | else |
| 1815 | 1815 | $args['page'] = 1; |
| 1816 | 1816 | |
@@ -1823,48 +1823,48 @@ discard block |
||
| 1823 | 1823 | 'post_status' => $args['status'], |
| 1824 | 1824 | 'posts_per_page' => $args['limit'], |
| 1825 | 1825 | 'meta_query' => array(), |
| 1826 | - 'date_query' => !empty( $args['date_query'] ) ? $args['date_query'] : array(), |
|
| 1826 | + 'date_query' => !empty($args['date_query']) ? $args['date_query'] : array(), |
|
| 1827 | 1827 | 'fields' => 'ids', |
| 1828 | 1828 | 'orderby' => $args['orderby'], |
| 1829 | 1829 | 'order' => $args['order'], |
| 1830 | 1830 | ); |
| 1831 | 1831 | |
| 1832 | - if ( !empty( $args['user'] ) ) { |
|
| 1833 | - $wp_query_args['author'] = absint( $args['user'] ); |
|
| 1832 | + if (!empty($args['user'])) { |
|
| 1833 | + $wp_query_args['author'] = absint($args['user']); |
|
| 1834 | 1834 | } |
| 1835 | 1835 | |
| 1836 | - if ( ! is_null( $args['parent'] ) ) { |
|
| 1837 | - $wp_query_args['post_parent'] = absint( $args['parent'] ); |
|
| 1836 | + if (!is_null($args['parent'])) { |
|
| 1837 | + $wp_query_args['post_parent'] = absint($args['parent']); |
|
| 1838 | 1838 | } |
| 1839 | 1839 | |
| 1840 | - if ( ! is_null( $args['offset'] ) ) { |
|
| 1841 | - $wp_query_args['offset'] = absint( $args['offset'] ); |
|
| 1840 | + if (!is_null($args['offset'])) { |
|
| 1841 | + $wp_query_args['offset'] = absint($args['offset']); |
|
| 1842 | 1842 | } else { |
| 1843 | - $wp_query_args['paged'] = absint( $args['page'] ); |
|
| 1843 | + $wp_query_args['paged'] = absint($args['page']); |
|
| 1844 | 1844 | } |
| 1845 | 1845 | |
| 1846 | - if ( ! empty( $args['exclude'] ) ) { |
|
| 1847 | - $wp_query_args['post__not_in'] = array_map( 'absint', $args['exclude'] ); |
|
| 1846 | + if (!empty($args['exclude'])) { |
|
| 1847 | + $wp_query_args['post__not_in'] = array_map('absint', $args['exclude']); |
|
| 1848 | 1848 | } |
| 1849 | 1849 | |
| 1850 | - if ( ! $args['paginate' ] ) { |
|
| 1850 | + if (!$args['paginate']) { |
|
| 1851 | 1851 | $wp_query_args['no_found_rows'] = true; |
| 1852 | 1852 | } |
| 1853 | 1853 | |
| 1854 | 1854 | $wp_query_args = apply_filters('wpinv_get_invoices_args', $wp_query_args, $args); |
| 1855 | 1855 | |
| 1856 | 1856 | // Get results. |
| 1857 | - $invoices = new WP_Query( $wp_query_args ); |
|
| 1857 | + $invoices = new WP_Query($wp_query_args); |
|
| 1858 | 1858 | |
| 1859 | - if ( 'objects' === $args['return'] ) { |
|
| 1860 | - $return = array_map( 'wpinv_get_invoice', $invoices->posts ); |
|
| 1861 | - } elseif ( 'self' === $args['return'] ) { |
|
| 1859 | + if ('objects' === $args['return']) { |
|
| 1860 | + $return = array_map('wpinv_get_invoice', $invoices->posts); |
|
| 1861 | + } elseif ('self' === $args['return']) { |
|
| 1862 | 1862 | return $invoices; |
| 1863 | 1863 | } else { |
| 1864 | 1864 | $return = $invoices->posts; |
| 1865 | 1865 | } |
| 1866 | 1866 | |
| 1867 | - if ( $args['paginate' ] ) { |
|
| 1867 | + if ($args['paginate']) { |
|
| 1868 | 1868 | return (object) array( |
| 1869 | 1869 | 'invoices' => $return, |
| 1870 | 1870 | 'total' => $invoices->found_posts, |
@@ -1877,22 +1877,22 @@ discard block |
||
| 1877 | 1877 | |
| 1878 | 1878 | function wpinv_get_user_invoices_columns() { |
| 1879 | 1879 | $columns = array( |
| 1880 | - 'invoice-number' => array( 'title' => __( 'ID', 'invoicing' ), 'class' => 'text-left' ), |
|
| 1881 | - 'created-date' => array( 'title' => __( 'Created Date', 'invoicing' ), 'class' => 'text-left' ), |
|
| 1882 | - 'payment-date' => array( 'title' => __( 'Payment Date', 'invoicing' ), 'class' => 'text-left' ), |
|
| 1883 | - 'invoice-status' => array( 'title' => __( 'Status', 'invoicing' ), 'class' => 'text-center' ), |
|
| 1884 | - 'invoice-total' => array( 'title' => __( 'Total', 'invoicing' ), 'class' => 'text-right' ), |
|
| 1885 | - 'invoice-actions' => array( 'title' => ' ', 'class' => 'text-center' ), |
|
| 1880 | + 'invoice-number' => array('title' => __('ID', 'invoicing'), 'class' => 'text-left'), |
|
| 1881 | + 'created-date' => array('title' => __('Created Date', 'invoicing'), 'class' => 'text-left'), |
|
| 1882 | + 'payment-date' => array('title' => __('Payment Date', 'invoicing'), 'class' => 'text-left'), |
|
| 1883 | + 'invoice-status' => array('title' => __('Status', 'invoicing'), 'class' => 'text-center'), |
|
| 1884 | + 'invoice-total' => array('title' => __('Total', 'invoicing'), 'class' => 'text-right'), |
|
| 1885 | + 'invoice-actions' => array('title' => ' ', 'class' => 'text-center'), |
|
| 1886 | 1886 | ); |
| 1887 | 1887 | |
| 1888 | - return apply_filters( 'wpinv_user_invoices_columns', $columns ); |
|
| 1888 | + return apply_filters('wpinv_user_invoices_columns', $columns); |
|
| 1889 | 1889 | } |
| 1890 | 1890 | |
| 1891 | -function wpinv_payment_receipt( $atts, $content = null ) { |
|
| 1891 | +function wpinv_payment_receipt($atts, $content = null) { |
|
| 1892 | 1892 | global $wpinv_receipt_args; |
| 1893 | 1893 | |
| 1894 | - $wpinv_receipt_args = shortcode_atts( array( |
|
| 1895 | - 'error' => __( 'Sorry, trouble retrieving payment receipt.', 'invoicing' ), |
|
| 1894 | + $wpinv_receipt_args = shortcode_atts(array( |
|
| 1895 | + 'error' => __('Sorry, trouble retrieving payment receipt.', 'invoicing'), |
|
| 1896 | 1896 | 'price' => true, |
| 1897 | 1897 | 'discount' => true, |
| 1898 | 1898 | 'items' => true, |
@@ -1901,44 +1901,44 @@ discard block |
||
| 1901 | 1901 | 'invoice_key' => false, |
| 1902 | 1902 | 'payment_method' => true, |
| 1903 | 1903 | 'invoice_id' => true |
| 1904 | - ), $atts, 'wpinv_receipt' ); |
|
| 1904 | + ), $atts, 'wpinv_receipt'); |
|
| 1905 | 1905 | |
| 1906 | 1906 | $session = wpinv_get_checkout_session(); |
| 1907 | - if ( isset( $_GET['invoice_key'] ) ) { |
|
| 1908 | - $invoice_key = urldecode( $_GET['invoice_key'] ); |
|
| 1909 | - } else if ( $session && isset( $session['invoice_key'] ) ) { |
|
| 1907 | + if (isset($_GET['invoice_key'])) { |
|
| 1908 | + $invoice_key = urldecode($_GET['invoice_key']); |
|
| 1909 | + } else if ($session && isset($session['invoice_key'])) { |
|
| 1910 | 1910 | $invoice_key = $session['invoice_key']; |
| 1911 | - } elseif ( isset( $wpinv_receipt_args['invoice_key'] ) && $wpinv_receipt_args['invoice_key'] ) { |
|
| 1911 | + } elseif (isset($wpinv_receipt_args['invoice_key']) && $wpinv_receipt_args['invoice_key']) { |
|
| 1912 | 1912 | $invoice_key = $wpinv_receipt_args['invoice_key']; |
| 1913 | - } else if ( isset( $_GET['invoice-id'] ) ) { |
|
| 1914 | - $invoice_key = wpinv_get_payment_key( (int)$_GET['invoice-id'] ); |
|
| 1913 | + } else if (isset($_GET['invoice-id'])) { |
|
| 1914 | + $invoice_key = wpinv_get_payment_key((int) $_GET['invoice-id']); |
|
| 1915 | 1915 | } |
| 1916 | 1916 | |
| 1917 | 1917 | // No key found |
| 1918 | - if ( ! isset( $invoice_key ) ) { |
|
| 1918 | + if (!isset($invoice_key)) { |
|
| 1919 | 1919 | return '<p class="alert alert-error">' . $wpinv_receipt_args['error'] . '</p>'; |
| 1920 | 1920 | } |
| 1921 | 1921 | |
| 1922 | - $invoice_id = wpinv_get_invoice_id_by_key( $invoice_key ); |
|
| 1923 | - $user_can_view = wpinv_can_view_receipt( $invoice_key ); |
|
| 1924 | - if ( $user_can_view && isset( $_GET['invoice-id'] ) ) { |
|
| 1925 | - $invoice_id = (int)$_GET['invoice-id']; |
|
| 1926 | - $user_can_view = $invoice_key == wpinv_get_payment_key( (int)$_GET['invoice-id'] ) ? true : false; |
|
| 1922 | + $invoice_id = wpinv_get_invoice_id_by_key($invoice_key); |
|
| 1923 | + $user_can_view = wpinv_can_view_receipt($invoice_key); |
|
| 1924 | + if ($user_can_view && isset($_GET['invoice-id'])) { |
|
| 1925 | + $invoice_id = (int) $_GET['invoice-id']; |
|
| 1926 | + $user_can_view = $invoice_key == wpinv_get_payment_key((int) $_GET['invoice-id']) ? true : false; |
|
| 1927 | 1927 | } |
| 1928 | 1928 | |
| 1929 | 1929 | // Key was provided, but user is logged out. Offer them the ability to login and view the receipt |
| 1930 | - if ( ! $user_can_view && ! empty( $invoice_key ) && ! is_user_logged_in() ) { |
|
| 1930 | + if (!$user_can_view && !empty($invoice_key) && !is_user_logged_in()) { |
|
| 1931 | 1931 | // login redirect |
| 1932 | - return '<p class="alert alert-error">' . __( 'You are not allowed to access this section', 'invoicing' ) . '</p>'; |
|
| 1932 | + return '<p class="alert alert-error">' . __('You are not allowed to access this section', 'invoicing') . '</p>'; |
|
| 1933 | 1933 | } |
| 1934 | 1934 | |
| 1935 | - if ( ! apply_filters( 'wpinv_user_can_view_receipt', $user_can_view, $wpinv_receipt_args ) ) { |
|
| 1935 | + if (!apply_filters('wpinv_user_can_view_receipt', $user_can_view, $wpinv_receipt_args)) { |
|
| 1936 | 1936 | return '<p class="alert alert-error">' . $wpinv_receipt_args['error'] . '</p>'; |
| 1937 | 1937 | } |
| 1938 | 1938 | |
| 1939 | 1939 | ob_start(); |
| 1940 | 1940 | |
| 1941 | - wpinv_get_template_part( 'wpinv-invoice-receipt' ); |
|
| 1941 | + wpinv_get_template_part('wpinv-invoice-receipt'); |
|
| 1942 | 1942 | |
| 1943 | 1943 | $display = ob_get_clean(); |
| 1944 | 1944 | |
@@ -1948,148 +1948,148 @@ discard block |
||
| 1948 | 1948 | /** |
| 1949 | 1949 | * Given an invoice key, this function returns the id. |
| 1950 | 1950 | */ |
| 1951 | -function wpinv_get_invoice_id_by_key( $key ) { |
|
| 1951 | +function wpinv_get_invoice_id_by_key($key) { |
|
| 1952 | 1952 | global $wpdb; |
| 1953 | - $table = $wpdb->prefix . 'getpaid_invoices'; |
|
| 1954 | - return (int) $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $table WHERE`key` = %s LIMIT 1", $key ) ); |
|
| 1953 | + $table = $wpdb->prefix . 'getpaid_invoices'; |
|
| 1954 | + return (int) $wpdb->get_var($wpdb->prepare("SELECT post_id FROM $table WHERE`key` = %s LIMIT 1", $key)); |
|
| 1955 | 1955 | } |
| 1956 | 1956 | |
| 1957 | -function wpinv_can_view_receipt( $invoice_key = '' ) { |
|
| 1957 | +function wpinv_can_view_receipt($invoice_key = '') { |
|
| 1958 | 1958 | $return = false; |
| 1959 | 1959 | |
| 1960 | - if ( empty( $invoice_key ) ) { |
|
| 1960 | + if (empty($invoice_key)) { |
|
| 1961 | 1961 | return $return; |
| 1962 | 1962 | } |
| 1963 | 1963 | |
| 1964 | 1964 | global $wpinv_receipt_args; |
| 1965 | 1965 | |
| 1966 | - $wpinv_receipt_args['id'] = wpinv_get_invoice_id_by_key( $invoice_key ); |
|
| 1967 | - if ( isset( $_GET['invoice-id'] ) ) { |
|
| 1968 | - $wpinv_receipt_args['id'] = $invoice_key == wpinv_get_payment_key( (int)$_GET['invoice-id'] ) ? (int)$_GET['invoice-id'] : 0; |
|
| 1966 | + $wpinv_receipt_args['id'] = wpinv_get_invoice_id_by_key($invoice_key); |
|
| 1967 | + if (isset($_GET['invoice-id'])) { |
|
| 1968 | + $wpinv_receipt_args['id'] = $invoice_key == wpinv_get_payment_key((int) $_GET['invoice-id']) ? (int) $_GET['invoice-id'] : 0; |
|
| 1969 | 1969 | } |
| 1970 | 1970 | |
| 1971 | - if ( empty( $wpinv_receipt_args['id'] ) ) { |
|
| 1971 | + if (empty($wpinv_receipt_args['id'])) { |
|
| 1972 | 1972 | return $return; |
| 1973 | 1973 | } |
| 1974 | 1974 | |
| 1975 | - $invoice = wpinv_get_invoice( $wpinv_receipt_args['id'] ); |
|
| 1976 | - if ( !( !empty( $invoice->ID ) && $invoice->get_key() === $invoice_key ) ) { |
|
| 1975 | + $invoice = wpinv_get_invoice($wpinv_receipt_args['id']); |
|
| 1976 | + if (!(!empty($invoice->ID) && $invoice->get_key() === $invoice_key)) { |
|
| 1977 | 1977 | return $return; |
| 1978 | 1978 | } |
| 1979 | 1979 | |
| 1980 | - if ( is_user_logged_in() ) { |
|
| 1981 | - if ( (int)$invoice->get_user_id() === (int) get_current_user_id() ) { |
|
| 1980 | + if (is_user_logged_in()) { |
|
| 1981 | + if ((int) $invoice->get_user_id() === (int) get_current_user_id()) { |
|
| 1982 | 1982 | $return = true; |
| 1983 | 1983 | } |
| 1984 | 1984 | } |
| 1985 | 1985 | |
| 1986 | 1986 | $session = wpinv_get_checkout_session(); |
| 1987 | - if ( isset( $_GET['invoice_key'] ) || ( $session && isset( $session['invoice_key'] ) ) ) { |
|
| 1988 | - $check_key = isset( $_GET['invoice_key'] ) ? $_GET['invoice_key'] : $session['invoice_key']; |
|
| 1987 | + if (isset($_GET['invoice_key']) || ($session && isset($session['invoice_key']))) { |
|
| 1988 | + $check_key = isset($_GET['invoice_key']) ? $_GET['invoice_key'] : $session['invoice_key']; |
|
| 1989 | 1989 | |
| 1990 | - if ( wpinv_require_login_to_checkout() ) { |
|
| 1990 | + if (wpinv_require_login_to_checkout()) { |
|
| 1991 | 1991 | $return = $return && $check_key === $invoice_key; |
| 1992 | 1992 | } else { |
| 1993 | 1993 | $return = $check_key === $invoice_key; |
| 1994 | 1994 | } |
| 1995 | 1995 | } |
| 1996 | 1996 | |
| 1997 | - return (bool) apply_filters( 'wpinv_can_view_receipt', $return, $invoice_key ); |
|
| 1997 | + return (bool) apply_filters('wpinv_can_view_receipt', $return, $invoice_key); |
|
| 1998 | 1998 | } |
| 1999 | 1999 | |
| 2000 | 2000 | function wpinv_pay_for_invoice() { |
| 2001 | 2001 | global $wpinv_euvat; |
| 2002 | 2002 | |
| 2003 | - if ( isset( $_GET['invoice_key'] ) ) { |
|
| 2003 | + if (isset($_GET['invoice_key'])) { |
|
| 2004 | 2004 | $checkout_uri = wpinv_get_checkout_uri(); |
| 2005 | - $invoice_key = sanitize_text_field( $_GET['invoice_key'] ); |
|
| 2005 | + $invoice_key = sanitize_text_field($_GET['invoice_key']); |
|
| 2006 | 2006 | |
| 2007 | - if ( empty( $invoice_key ) ) { |
|
| 2008 | - wpinv_set_error( 'invalid_invoice', __( 'Invoice not found', 'invoicing' ) ); |
|
| 2009 | - wp_redirect( $checkout_uri ); |
|
| 2007 | + if (empty($invoice_key)) { |
|
| 2008 | + wpinv_set_error('invalid_invoice', __('Invoice not found', 'invoicing')); |
|
| 2009 | + wp_redirect($checkout_uri); |
|
| 2010 | 2010 | exit(); |
| 2011 | 2011 | } |
| 2012 | 2012 | |
| 2013 | - do_action( 'wpinv_check_pay_for_invoice', $invoice_key ); |
|
| 2013 | + do_action('wpinv_check_pay_for_invoice', $invoice_key); |
|
| 2014 | 2014 | |
| 2015 | - $invoice_id = wpinv_get_invoice_id_by_key( $invoice_key ); |
|
| 2016 | - $user_can_view = wpinv_can_view_receipt( $invoice_key ); |
|
| 2017 | - if ( $user_can_view && isset( $_GET['invoice-id'] ) ) { |
|
| 2018 | - $invoice_id = (int)$_GET['invoice-id']; |
|
| 2019 | - $user_can_view = $invoice_key == wpinv_get_payment_key( (int)$_GET['invoice-id'] ) ? true : false; |
|
| 2015 | + $invoice_id = wpinv_get_invoice_id_by_key($invoice_key); |
|
| 2016 | + $user_can_view = wpinv_can_view_receipt($invoice_key); |
|
| 2017 | + if ($user_can_view && isset($_GET['invoice-id'])) { |
|
| 2018 | + $invoice_id = (int) $_GET['invoice-id']; |
|
| 2019 | + $user_can_view = $invoice_key == wpinv_get_payment_key((int) $_GET['invoice-id']) ? true : false; |
|
| 2020 | 2020 | } |
| 2021 | 2021 | |
| 2022 | - if ( $invoice_id && $user_can_view && ( $invoice = wpinv_get_invoice( $invoice_id ) ) ) { |
|
| 2023 | - if ( $invoice->needs_payment() ) { |
|
| 2022 | + if ($invoice_id && $user_can_view && ($invoice = wpinv_get_invoice($invoice_id))) { |
|
| 2023 | + if ($invoice->needs_payment()) { |
|
| 2024 | 2024 | $data = array(); |
| 2025 | 2025 | $data['invoice_id'] = $invoice_id; |
| 2026 | - $data['cart_discounts'] = $invoice->get_discounts( true ); |
|
| 2026 | + $data['cart_discounts'] = $invoice->get_discounts(true); |
|
| 2027 | 2027 | |
| 2028 | - wpinv_set_checkout_session( $data ); |
|
| 2028 | + wpinv_set_checkout_session($data); |
|
| 2029 | 2029 | |
| 2030 | - if ( wpinv_get_option( 'vat_ip_country_default' ) ) { |
|
| 2030 | + if (wpinv_get_option('vat_ip_country_default')) { |
|
| 2031 | 2031 | $_POST['country'] = $wpinv_euvat->get_country_by_ip(); |
| 2032 | 2032 | $_POST['state'] = $_POST['country'] == $invoice->country ? $invoice->state : ''; |
| 2033 | 2033 | |
| 2034 | - wpinv_recalculate_tax( true ); |
|
| 2034 | + wpinv_recalculate_tax(true); |
|
| 2035 | 2035 | } |
| 2036 | 2036 | |
| 2037 | 2037 | } else { |
| 2038 | 2038 | $checkout_uri = $invoice->get_view_url(); |
| 2039 | 2039 | } |
| 2040 | 2040 | } else { |
| 2041 | - wpinv_set_error( 'invalid_invoice', __( 'You are not allowed to view this invoice', 'invoicing' ) ); |
|
| 2041 | + wpinv_set_error('invalid_invoice', __('You are not allowed to view this invoice', 'invoicing')); |
|
| 2042 | 2042 | |
| 2043 | - $checkout_uri = is_user_logged_in() ? wpinv_get_history_page_uri() : wp_login_url( get_permalink() ); |
|
| 2043 | + $checkout_uri = is_user_logged_in() ? wpinv_get_history_page_uri() : wp_login_url(get_permalink()); |
|
| 2044 | 2044 | } |
| 2045 | 2045 | |
| 2046 | - if(wp_redirect( $checkout_uri )){ |
|
| 2046 | + if (wp_redirect($checkout_uri)) { |
|
| 2047 | 2047 | exit; |
| 2048 | 2048 | }; |
| 2049 | 2049 | wpinv_die(); |
| 2050 | 2050 | } |
| 2051 | 2051 | } |
| 2052 | -add_action( 'wpinv_pay_for_invoice', 'wpinv_pay_for_invoice' ); |
|
| 2052 | +add_action('wpinv_pay_for_invoice', 'wpinv_pay_for_invoice'); |
|
| 2053 | 2053 | |
| 2054 | -function wpinv_handle_pay_via_invoice_link( $invoice_key ) { |
|
| 2055 | - if ( !empty( $invoice_key ) && !empty( $_REQUEST['_wpipay'] ) && !is_user_logged_in() && $invoice_id = wpinv_get_invoice_id_by_key( $invoice_key ) ) { |
|
| 2056 | - if ( $invoice = wpinv_get_invoice( $invoice_id ) ) { |
|
| 2054 | +function wpinv_handle_pay_via_invoice_link($invoice_key) { |
|
| 2055 | + if (!empty($invoice_key) && !empty($_REQUEST['_wpipay']) && !is_user_logged_in() && $invoice_id = wpinv_get_invoice_id_by_key($invoice_key)) { |
|
| 2056 | + if ($invoice = wpinv_get_invoice($invoice_id)) { |
|
| 2057 | 2057 | $user_id = $invoice->get_user_id(); |
| 2058 | - $secret = sanitize_text_field( $_GET['_wpipay'] ); |
|
| 2058 | + $secret = sanitize_text_field($_GET['_wpipay']); |
|
| 2059 | 2059 | |
| 2060 | - if ( $secret === md5( $user_id . '::' . $invoice->get_email() . '::' . $invoice_key ) ) { // valid invoice link |
|
| 2061 | - $redirect_to = remove_query_arg( '_wpipay', get_permalink() ); |
|
| 2060 | + if ($secret === md5($user_id . '::' . $invoice->get_email() . '::' . $invoice_key)) { // valid invoice link |
|
| 2061 | + $redirect_to = remove_query_arg('_wpipay', get_permalink()); |
|
| 2062 | 2062 | |
| 2063 | - wpinv_guest_redirect( $redirect_to, $user_id ); |
|
| 2063 | + wpinv_guest_redirect($redirect_to, $user_id); |
|
| 2064 | 2064 | exit(); |
| 2065 | 2065 | } |
| 2066 | 2066 | } |
| 2067 | 2067 | } |
| 2068 | 2068 | } |
| 2069 | -add_action( 'wpinv_check_pay_for_invoice', 'wpinv_handle_pay_via_invoice_link' ); |
|
| 2069 | +add_action('wpinv_check_pay_for_invoice', 'wpinv_handle_pay_via_invoice_link'); |
|
| 2070 | 2070 | |
| 2071 | -function wpinv_set_payment_transaction_id( $invoice_id = 0, $transaction_id = '' ) { |
|
| 2072 | - $invoice_id = is_object( $invoice_id ) && !empty( $invoice_id->ID ) ? $invoice_id : $invoice_id; |
|
| 2071 | +function wpinv_set_payment_transaction_id($invoice_id = 0, $transaction_id = '') { |
|
| 2072 | + $invoice_id = is_object($invoice_id) && !empty($invoice_id->ID) ? $invoice_id : $invoice_id; |
|
| 2073 | 2073 | |
| 2074 | - if ( empty( $invoice_id ) && $invoice_id > 0 ) { |
|
| 2074 | + if (empty($invoice_id) && $invoice_id > 0) { |
|
| 2075 | 2075 | return false; |
| 2076 | 2076 | } |
| 2077 | 2077 | |
| 2078 | - if ( empty( $transaction_id ) ) { |
|
| 2078 | + if (empty($transaction_id)) { |
|
| 2079 | 2079 | $transaction_id = $invoice_id; |
| 2080 | 2080 | } |
| 2081 | 2081 | |
| 2082 | - $transaction_id = apply_filters( 'wpinv_set_payment_transaction_id', $transaction_id, $invoice_id ); |
|
| 2082 | + $transaction_id = apply_filters('wpinv_set_payment_transaction_id', $transaction_id, $invoice_id); |
|
| 2083 | 2083 | |
| 2084 | - return wpinv_update_invoice_meta( $invoice_id, '_wpinv_transaction_id', $transaction_id ); |
|
| 2084 | + return wpinv_update_invoice_meta($invoice_id, '_wpinv_transaction_id', $transaction_id); |
|
| 2085 | 2085 | } |
| 2086 | 2086 | |
| 2087 | -function wpinv_invoice_status_label( $status, $status_display = '' ) { |
|
| 2088 | - if ( empty( $status_display ) ) { |
|
| 2089 | - $status_display = wpinv_status_nicename( $status ); |
|
| 2087 | +function wpinv_invoice_status_label($status, $status_display = '') { |
|
| 2088 | + if (empty($status_display)) { |
|
| 2089 | + $status_display = wpinv_status_nicename($status); |
|
| 2090 | 2090 | } |
| 2091 | 2091 | |
| 2092 | - switch ( $status ) { |
|
| 2092 | + switch ($status) { |
|
| 2093 | 2093 | case 'publish' : |
| 2094 | 2094 | case 'wpi-renewal' : |
| 2095 | 2095 | $class = 'label-success'; |
@@ -2114,201 +2114,201 @@ discard block |
||
| 2114 | 2114 | |
| 2115 | 2115 | $label = '<span class="label label-inv-' . $status . ' ' . $class . '">' . $status_display . '</span>'; |
| 2116 | 2116 | |
| 2117 | - return apply_filters( 'wpinv_invoice_status_label', $label, $status, $status_display ); |
|
| 2117 | + return apply_filters('wpinv_invoice_status_label', $label, $status, $status_display); |
|
| 2118 | 2118 | } |
| 2119 | 2119 | |
| 2120 | -function wpinv_format_invoice_number( $number, $type = '' ) { |
|
| 2121 | - $check = apply_filters( 'wpinv_pre_format_invoice_number', null, $number, $type ); |
|
| 2122 | - if ( null !== $check ) { |
|
| 2120 | +function wpinv_format_invoice_number($number, $type = '') { |
|
| 2121 | + $check = apply_filters('wpinv_pre_format_invoice_number', null, $number, $type); |
|
| 2122 | + if (null !== $check) { |
|
| 2123 | 2123 | return $check; |
| 2124 | 2124 | } |
| 2125 | 2125 | |
| 2126 | - if ( !empty( $number ) && !is_numeric( $number ) ) { |
|
| 2126 | + if (!empty($number) && !is_numeric($number)) { |
|
| 2127 | 2127 | return $number; |
| 2128 | 2128 | } |
| 2129 | 2129 | |
| 2130 | - $padd = wpinv_get_option( 'invoice_number_padd' ); |
|
| 2131 | - $prefix = wpinv_get_option( 'invoice_number_prefix' ); |
|
| 2132 | - $postfix = wpinv_get_option( 'invoice_number_postfix' ); |
|
| 2130 | + $padd = wpinv_get_option('invoice_number_padd'); |
|
| 2131 | + $prefix = wpinv_get_option('invoice_number_prefix'); |
|
| 2132 | + $postfix = wpinv_get_option('invoice_number_postfix'); |
|
| 2133 | 2133 | |
| 2134 | - $padd = absint( $padd ); |
|
| 2135 | - $formatted_number = absint( $number ); |
|
| 2134 | + $padd = absint($padd); |
|
| 2135 | + $formatted_number = absint($number); |
|
| 2136 | 2136 | |
| 2137 | - if ( $padd > 0 ) { |
|
| 2138 | - $formatted_number = zeroise( $formatted_number, $padd ); |
|
| 2137 | + if ($padd > 0) { |
|
| 2138 | + $formatted_number = zeroise($formatted_number, $padd); |
|
| 2139 | 2139 | } |
| 2140 | 2140 | |
| 2141 | 2141 | $formatted_number = $prefix . $formatted_number . $postfix; |
| 2142 | 2142 | |
| 2143 | - return apply_filters( 'wpinv_format_invoice_number', $formatted_number, $number, $prefix, $postfix, $padd ); |
|
| 2143 | + return apply_filters('wpinv_format_invoice_number', $formatted_number, $number, $prefix, $postfix, $padd); |
|
| 2144 | 2144 | } |
| 2145 | 2145 | |
| 2146 | -function wpinv_get_next_invoice_number( $type = '' ) { |
|
| 2147 | - $check = apply_filters( 'wpinv_get_pre_next_invoice_number', null, $type ); |
|
| 2148 | - if ( null !== $check ) { |
|
| 2146 | +function wpinv_get_next_invoice_number($type = '') { |
|
| 2147 | + $check = apply_filters('wpinv_get_pre_next_invoice_number', null, $type); |
|
| 2148 | + if (null !== $check) { |
|
| 2149 | 2149 | return $check; |
| 2150 | 2150 | } |
| 2151 | 2151 | |
| 2152 | - if ( !wpinv_sequential_number_active() ) { |
|
| 2152 | + if (!wpinv_sequential_number_active()) { |
|
| 2153 | 2153 | return false; |
| 2154 | 2154 | } |
| 2155 | 2155 | |
| 2156 | - $number = $last_number = get_option( 'wpinv_last_invoice_number', 0 ); |
|
| 2157 | - $start = wpinv_get_option( 'invoice_sequence_start', 1 ); |
|
| 2158 | - if ( !absint( $start ) > 0 ) { |
|
| 2156 | + $number = $last_number = get_option('wpinv_last_invoice_number', 0); |
|
| 2157 | + $start = wpinv_get_option('invoice_sequence_start', 1); |
|
| 2158 | + if (!absint($start) > 0) { |
|
| 2159 | 2159 | $start = 1; |
| 2160 | 2160 | } |
| 2161 | 2161 | $increment_number = true; |
| 2162 | 2162 | $save_number = false; |
| 2163 | 2163 | |
| 2164 | - if ( !empty( $number ) && !is_numeric( $number ) && $number == wpinv_format_invoice_number( $number ) ) { |
|
| 2165 | - $number = wpinv_clean_invoice_number( $number ); |
|
| 2164 | + if (!empty($number) && !is_numeric($number) && $number == wpinv_format_invoice_number($number)) { |
|
| 2165 | + $number = wpinv_clean_invoice_number($number); |
|
| 2166 | 2166 | } |
| 2167 | 2167 | |
| 2168 | - if ( empty( $number ) ) { |
|
| 2169 | - if ( !( $last_number === 0 || $last_number === '0' ) ) { |
|
| 2170 | - $last_invoice = wpinv_get_invoices( array( 'limit' => 1, 'order' => 'DESC', 'orderby' => 'ID', 'return' => 'posts', 'fields' => 'ids', 'status' => array_keys( wpinv_get_invoice_statuses( true, true ) ) ) ); |
|
| 2168 | + if (empty($number)) { |
|
| 2169 | + if (!($last_number === 0 || $last_number === '0')) { |
|
| 2170 | + $last_invoice = wpinv_get_invoices(array('limit' => 1, 'order' => 'DESC', 'orderby' => 'ID', 'return' => 'posts', 'fields' => 'ids', 'status' => array_keys(wpinv_get_invoice_statuses(true, true)))); |
|
| 2171 | 2171 | |
| 2172 | - if ( !empty( $last_invoice[0] ) && $invoice_number = wpinv_get_invoice_number( $last_invoice[0] ) ) { |
|
| 2173 | - if ( is_numeric( $invoice_number ) ) { |
|
| 2172 | + if (!empty($last_invoice[0]) && $invoice_number = wpinv_get_invoice_number($last_invoice[0])) { |
|
| 2173 | + if (is_numeric($invoice_number)) { |
|
| 2174 | 2174 | $number = $invoice_number; |
| 2175 | 2175 | } else { |
| 2176 | - $number = wpinv_clean_invoice_number( $invoice_number ); |
|
| 2176 | + $number = wpinv_clean_invoice_number($invoice_number); |
|
| 2177 | 2177 | } |
| 2178 | 2178 | } |
| 2179 | 2179 | |
| 2180 | - if ( empty( $number ) ) { |
|
| 2180 | + if (empty($number)) { |
|
| 2181 | 2181 | $increment_number = false; |
| 2182 | 2182 | $number = $start; |
| 2183 | - $save_number = ( $number - 1 ); |
|
| 2183 | + $save_number = ($number - 1); |
|
| 2184 | 2184 | } else { |
| 2185 | 2185 | $save_number = $number; |
| 2186 | 2186 | } |
| 2187 | 2187 | } |
| 2188 | 2188 | } |
| 2189 | 2189 | |
| 2190 | - if ( $start > $number ) { |
|
| 2190 | + if ($start > $number) { |
|
| 2191 | 2191 | $increment_number = false; |
| 2192 | 2192 | $number = $start; |
| 2193 | - $save_number = ( $number - 1 ); |
|
| 2193 | + $save_number = ($number - 1); |
|
| 2194 | 2194 | } |
| 2195 | 2195 | |
| 2196 | - if ( $save_number !== false ) { |
|
| 2197 | - update_option( 'wpinv_last_invoice_number', $save_number ); |
|
| 2196 | + if ($save_number !== false) { |
|
| 2197 | + update_option('wpinv_last_invoice_number', $save_number); |
|
| 2198 | 2198 | } |
| 2199 | 2199 | |
| 2200 | - $increment_number = apply_filters( 'wpinv_increment_payment_number', $increment_number, $number ); |
|
| 2200 | + $increment_number = apply_filters('wpinv_increment_payment_number', $increment_number, $number); |
|
| 2201 | 2201 | |
| 2202 | - if ( $increment_number ) { |
|
| 2202 | + if ($increment_number) { |
|
| 2203 | 2203 | $number++; |
| 2204 | 2204 | } |
| 2205 | 2205 | |
| 2206 | - return apply_filters( 'wpinv_get_next_invoice_number', $number ); |
|
| 2206 | + return apply_filters('wpinv_get_next_invoice_number', $number); |
|
| 2207 | 2207 | } |
| 2208 | 2208 | |
| 2209 | -function wpinv_clean_invoice_number( $number, $type = '' ) { |
|
| 2210 | - $check = apply_filters( 'wpinv_pre_clean_invoice_number', null, $number, $type ); |
|
| 2211 | - if ( null !== $check ) { |
|
| 2209 | +function wpinv_clean_invoice_number($number, $type = '') { |
|
| 2210 | + $check = apply_filters('wpinv_pre_clean_invoice_number', null, $number, $type); |
|
| 2211 | + if (null !== $check) { |
|
| 2212 | 2212 | return $check; |
| 2213 | 2213 | } |
| 2214 | 2214 | |
| 2215 | - $prefix = wpinv_get_option( 'invoice_number_prefix' ); |
|
| 2216 | - $postfix = wpinv_get_option( 'invoice_number_postfix' ); |
|
| 2215 | + $prefix = wpinv_get_option('invoice_number_prefix'); |
|
| 2216 | + $postfix = wpinv_get_option('invoice_number_postfix'); |
|
| 2217 | 2217 | |
| 2218 | - $number = preg_replace( '/' . $prefix . '/', '', $number, 1 ); |
|
| 2218 | + $number = preg_replace('/' . $prefix . '/', '', $number, 1); |
|
| 2219 | 2219 | |
| 2220 | - $length = strlen( $number ); |
|
| 2221 | - $postfix_pos = strrpos( $number, $postfix ); |
|
| 2220 | + $length = strlen($number); |
|
| 2221 | + $postfix_pos = strrpos($number, $postfix); |
|
| 2222 | 2222 | |
| 2223 | - if ( false !== $postfix_pos ) { |
|
| 2224 | - $number = substr_replace( $number, '', $postfix_pos, $length ); |
|
| 2223 | + if (false !== $postfix_pos) { |
|
| 2224 | + $number = substr_replace($number, '', $postfix_pos, $length); |
|
| 2225 | 2225 | } |
| 2226 | 2226 | |
| 2227 | - $number = intval( $number ); |
|
| 2227 | + $number = intval($number); |
|
| 2228 | 2228 | |
| 2229 | - return apply_filters( 'wpinv_clean_invoice_number', $number, $prefix, $postfix ); |
|
| 2229 | + return apply_filters('wpinv_clean_invoice_number', $number, $prefix, $postfix); |
|
| 2230 | 2230 | } |
| 2231 | 2231 | |
| 2232 | -function wpinv_save_number_post_saved( $post_ID, $post, $update ) { |
|
| 2232 | +function wpinv_save_number_post_saved($post_ID, $post, $update) { |
|
| 2233 | 2233 | global $wpdb; |
| 2234 | 2234 | |
| 2235 | - if ( !$update && !get_post_meta( $post_ID, '_wpinv_number', true ) ) { |
|
| 2236 | - wpinv_update_invoice_number( $post_ID, $post->post_status != 'auto-draft', $post->post_type ); |
|
| 2235 | + if (!$update && !get_post_meta($post_ID, '_wpinv_number', true)) { |
|
| 2236 | + wpinv_update_invoice_number($post_ID, $post->post_status != 'auto-draft', $post->post_type); |
|
| 2237 | 2237 | } |
| 2238 | 2238 | |
| 2239 | - if ( !$update ) { |
|
| 2240 | - $wpdb->update( $wpdb->posts, array( 'post_name' => wpinv_generate_post_name( $post_ID ) ), array( 'ID' => $post_ID ) ); |
|
| 2241 | - clean_post_cache( $post_ID ); |
|
| 2239 | + if (!$update) { |
|
| 2240 | + $wpdb->update($wpdb->posts, array('post_name' => wpinv_generate_post_name($post_ID)), array('ID' => $post_ID)); |
|
| 2241 | + clean_post_cache($post_ID); |
|
| 2242 | 2242 | } |
| 2243 | 2243 | } |
| 2244 | -add_action( 'save_post_wpi_invoice', 'wpinv_save_number_post_saved', 1, 3 ); |
|
| 2244 | +add_action('save_post_wpi_invoice', 'wpinv_save_number_post_saved', 1, 3); |
|
| 2245 | 2245 | |
| 2246 | -function wpinv_save_number_post_updated( $post_ID, $post_after, $post_before ) { |
|
| 2247 | - if ( !empty( $post_after->post_type ) && $post_after->post_type == 'wpi_invoice' && $post_before->post_status == 'auto-draft' && $post_after->post_status != $post_before->post_status ) { |
|
| 2248 | - wpinv_update_invoice_number( $post_ID, true, $post_after->post_type ); |
|
| 2246 | +function wpinv_save_number_post_updated($post_ID, $post_after, $post_before) { |
|
| 2247 | + if (!empty($post_after->post_type) && $post_after->post_type == 'wpi_invoice' && $post_before->post_status == 'auto-draft' && $post_after->post_status != $post_before->post_status) { |
|
| 2248 | + wpinv_update_invoice_number($post_ID, true, $post_after->post_type); |
|
| 2249 | 2249 | } |
| 2250 | 2250 | } |
| 2251 | -add_action( 'post_updated', 'wpinv_save_number_post_updated', 1, 3 ); |
|
| 2251 | +add_action('post_updated', 'wpinv_save_number_post_updated', 1, 3); |
|
| 2252 | 2252 | |
| 2253 | -function wpinv_update_invoice_number( $post_ID, $save_sequential = false, $type = '' ) { |
|
| 2253 | +function wpinv_update_invoice_number($post_ID, $save_sequential = false, $type = '') { |
|
| 2254 | 2254 | global $wpdb; |
| 2255 | 2255 | |
| 2256 | - $check = apply_filters( 'wpinv_pre_update_invoice_number', null, $post_ID, $save_sequential, $type ); |
|
| 2257 | - if ( null !== $check ) { |
|
| 2256 | + $check = apply_filters('wpinv_pre_update_invoice_number', null, $post_ID, $save_sequential, $type); |
|
| 2257 | + if (null !== $check) { |
|
| 2258 | 2258 | return $check; |
| 2259 | 2259 | } |
| 2260 | 2260 | |
| 2261 | - if ( wpinv_sequential_number_active() ) { |
|
| 2261 | + if (wpinv_sequential_number_active()) { |
|
| 2262 | 2262 | $number = wpinv_get_next_invoice_number(); |
| 2263 | 2263 | |
| 2264 | - if ( $save_sequential ) { |
|
| 2265 | - update_option( 'wpinv_last_invoice_number', $number ); |
|
| 2264 | + if ($save_sequential) { |
|
| 2265 | + update_option('wpinv_last_invoice_number', $number); |
|
| 2266 | 2266 | } |
| 2267 | 2267 | } else { |
| 2268 | 2268 | $number = $post_ID; |
| 2269 | 2269 | } |
| 2270 | 2270 | |
| 2271 | - $number = wpinv_format_invoice_number( $number ); |
|
| 2271 | + $number = wpinv_format_invoice_number($number); |
|
| 2272 | 2272 | |
| 2273 | - update_post_meta( $post_ID, '_wpinv_number', $number ); |
|
| 2273 | + update_post_meta($post_ID, '_wpinv_number', $number); |
|
| 2274 | 2274 | |
| 2275 | - $wpdb->update( $wpdb->posts, array( 'post_title' => $number ), array( 'ID' => $post_ID ) ); |
|
| 2275 | + $wpdb->update($wpdb->posts, array('post_title' => $number), array('ID' => $post_ID)); |
|
| 2276 | 2276 | |
| 2277 | - clean_post_cache( $post_ID ); |
|
| 2277 | + clean_post_cache($post_ID); |
|
| 2278 | 2278 | |
| 2279 | 2279 | return $number; |
| 2280 | 2280 | } |
| 2281 | 2281 | |
| 2282 | -function wpinv_post_name_prefix( $post_type = 'wpi_invoice' ) { |
|
| 2283 | - return apply_filters( 'wpinv_post_name_prefix', 'inv-', $post_type ); |
|
| 2282 | +function wpinv_post_name_prefix($post_type = 'wpi_invoice') { |
|
| 2283 | + return apply_filters('wpinv_post_name_prefix', 'inv-', $post_type); |
|
| 2284 | 2284 | } |
| 2285 | 2285 | |
| 2286 | -function wpinv_generate_post_name( $post_ID ) { |
|
| 2287 | - $prefix = wpinv_post_name_prefix( get_post_type( $post_ID ) ); |
|
| 2288 | - $post_name = sanitize_title( $prefix . $post_ID ); |
|
| 2286 | +function wpinv_generate_post_name($post_ID) { |
|
| 2287 | + $prefix = wpinv_post_name_prefix(get_post_type($post_ID)); |
|
| 2288 | + $post_name = sanitize_title($prefix . $post_ID); |
|
| 2289 | 2289 | |
| 2290 | - return apply_filters( 'wpinv_generate_post_name', $post_name, $post_ID, $prefix ); |
|
| 2290 | + return apply_filters('wpinv_generate_post_name', $post_name, $post_ID, $prefix); |
|
| 2291 | 2291 | } |
| 2292 | 2292 | |
| 2293 | -function wpinv_is_invoice_viewed( $invoice_id ) { |
|
| 2294 | - if ( empty( $invoice_id ) ) { |
|
| 2293 | +function wpinv_is_invoice_viewed($invoice_id) { |
|
| 2294 | + if (empty($invoice_id)) { |
|
| 2295 | 2295 | return false; |
| 2296 | 2296 | } |
| 2297 | 2297 | |
| 2298 | - $viewed_meta = get_post_meta( $invoice_id, '_wpinv_is_viewed', true ); |
|
| 2298 | + $viewed_meta = get_post_meta($invoice_id, '_wpinv_is_viewed', true); |
|
| 2299 | 2299 | |
| 2300 | - return apply_filters( 'wpinv_is_invoice_viewed', 1 === (int)$viewed_meta, $invoice_id ); |
|
| 2300 | + return apply_filters('wpinv_is_invoice_viewed', 1 === (int) $viewed_meta, $invoice_id); |
|
| 2301 | 2301 | } |
| 2302 | 2302 | |
| 2303 | 2303 | function wpinv_mark_invoice_viewed() { |
| 2304 | 2304 | |
| 2305 | - if ( isset( $_GET['invoice_key'] ) || is_singular( 'wpi_invoice' ) || is_singular( 'wpi_quote' ) ) { |
|
| 2306 | - $invoice_key = isset( $_GET['invoice_key'] ) ? urldecode($_GET['invoice_key']) : ''; |
|
| 2305 | + if (isset($_GET['invoice_key']) || is_singular('wpi_invoice') || is_singular('wpi_quote')) { |
|
| 2306 | + $invoice_key = isset($_GET['invoice_key']) ? urldecode($_GET['invoice_key']) : ''; |
|
| 2307 | 2307 | global $post; |
| 2308 | 2308 | |
| 2309 | - if(!empty($invoice_key)){ |
|
| 2309 | + if (!empty($invoice_key)) { |
|
| 2310 | 2310 | $invoice_id = wpinv_get_invoice_id_by_key($invoice_key); |
| 2311 | - } else if(!empty( $post ) && ($post->post_type == 'wpi_invoice' || $post->post_type == 'wpi_quote')) { |
|
| 2311 | + } else if (!empty($post) && ($post->post_type == 'wpi_invoice' || $post->post_type == 'wpi_quote')) { |
|
| 2312 | 2312 | $invoice_id = $post->ID; |
| 2313 | 2313 | } else { |
| 2314 | 2314 | return; |
@@ -2316,60 +2316,60 @@ discard block |
||
| 2316 | 2316 | |
| 2317 | 2317 | $invoice = new WPInv_Invoice($invoice_id); |
| 2318 | 2318 | |
| 2319 | - if(!$invoice_id){ |
|
| 2319 | + if (!$invoice_id) { |
|
| 2320 | 2320 | return; |
| 2321 | 2321 | } |
| 2322 | 2322 | |
| 2323 | - if ( is_user_logged_in() ) { |
|
| 2324 | - if ( (int)$invoice->get_user_id() === get_current_user_id() ) { |
|
| 2325 | - update_post_meta($invoice_id,'_wpinv_is_viewed', 1); |
|
| 2326 | - } else if ( !wpinv_require_login_to_checkout() && isset( $_GET['invoice_key'] ) && $_GET['invoice_key'] === $invoice->get_key() ) { |
|
| 2327 | - update_post_meta($invoice_id,'_wpinv_is_viewed', 1); |
|
| 2323 | + if (is_user_logged_in()) { |
|
| 2324 | + if ((int) $invoice->get_user_id() === get_current_user_id()) { |
|
| 2325 | + update_post_meta($invoice_id, '_wpinv_is_viewed', 1); |
|
| 2326 | + } else if (!wpinv_require_login_to_checkout() && isset($_GET['invoice_key']) && $_GET['invoice_key'] === $invoice->get_key()) { |
|
| 2327 | + update_post_meta($invoice_id, '_wpinv_is_viewed', 1); |
|
| 2328 | 2328 | } |
| 2329 | 2329 | } else { |
| 2330 | - if ( !wpinv_require_login_to_checkout() && isset( $_GET['invoice_key'] ) && $_GET['invoice_key'] === $invoice->get_key() ) { |
|
| 2331 | - update_post_meta($invoice_id,'_wpinv_is_viewed', 1); |
|
| 2330 | + if (!wpinv_require_login_to_checkout() && isset($_GET['invoice_key']) && $_GET['invoice_key'] === $invoice->get_key()) { |
|
| 2331 | + update_post_meta($invoice_id, '_wpinv_is_viewed', 1); |
|
| 2332 | 2332 | } |
| 2333 | 2333 | } |
| 2334 | 2334 | } |
| 2335 | 2335 | |
| 2336 | 2336 | } |
| 2337 | -add_action( 'template_redirect', 'wpinv_mark_invoice_viewed' ); |
|
| 2337 | +add_action('template_redirect', 'wpinv_mark_invoice_viewed'); |
|
| 2338 | 2338 | |
| 2339 | -function wpinv_get_subscription( $invoice, $by_parent = false ) { |
|
| 2340 | - if ( empty( $invoice ) ) { |
|
| 2339 | +function wpinv_get_subscription($invoice, $by_parent = false) { |
|
| 2340 | + if (empty($invoice)) { |
|
| 2341 | 2341 | return false; |
| 2342 | 2342 | } |
| 2343 | 2343 | |
| 2344 | - if ( ! is_object( $invoice ) && is_scalar( $invoice ) ) { |
|
| 2345 | - $invoice = wpinv_get_invoice( $invoice ); |
|
| 2344 | + if (!is_object($invoice) && is_scalar($invoice)) { |
|
| 2345 | + $invoice = wpinv_get_invoice($invoice); |
|
| 2346 | 2346 | } |
| 2347 | 2347 | |
| 2348 | - if ( !( is_object( $invoice ) && ! empty( $invoice->ID ) && $invoice->is_recurring() ) ) { |
|
| 2348 | + if (!(is_object($invoice) && !empty($invoice->ID) && $invoice->is_recurring())) { |
|
| 2349 | 2349 | return false; |
| 2350 | 2350 | } |
| 2351 | 2351 | |
| 2352 | - $invoice_id = ! $by_parent && ! empty( $invoice->parent_invoice ) ? $invoice->parent_invoice : $invoice->ID; |
|
| 2352 | + $invoice_id = !$by_parent && !empty($invoice->parent_invoice) ? $invoice->parent_invoice : $invoice->ID; |
|
| 2353 | 2353 | |
| 2354 | 2354 | $subs_db = new WPInv_Subscriptions_DB; |
| 2355 | - $subs = $subs_db->get_subscriptions( array( 'parent_payment_id' => $invoice_id, 'number' => 1 ) ); |
|
| 2355 | + $subs = $subs_db->get_subscriptions(array('parent_payment_id' => $invoice_id, 'number' => 1)); |
|
| 2356 | 2356 | |
| 2357 | - if ( ! empty( $subs ) ) { |
|
| 2358 | - return reset( $subs ); |
|
| 2357 | + if (!empty($subs)) { |
|
| 2358 | + return reset($subs); |
|
| 2359 | 2359 | } |
| 2360 | 2360 | |
| 2361 | 2361 | return false; |
| 2362 | 2362 | } |
| 2363 | 2363 | |
| 2364 | -function wpinv_filter_posts_clauses( $clauses, $wp_query ) { |
|
| 2364 | +function wpinv_filter_posts_clauses($clauses, $wp_query) { |
|
| 2365 | 2365 | global $wpdb; |
| 2366 | 2366 | |
| 2367 | - if ( ! empty( $wp_query->query_vars['orderby'] ) && $wp_query->query_vars['orderby'] == 'invoice_date' ) { |
|
| 2368 | - if ( !empty( $clauses['join'] ) ) { |
|
| 2367 | + if (!empty($wp_query->query_vars['orderby']) && $wp_query->query_vars['orderby'] == 'invoice_date') { |
|
| 2368 | + if (!empty($clauses['join'])) { |
|
| 2369 | 2369 | $clauses['join'] .= " "; |
| 2370 | 2370 | } |
| 2371 | 2371 | |
| 2372 | - if ( !empty( $clauses['fields'] ) ) { |
|
| 2372 | + if (!empty($clauses['fields'])) { |
|
| 2373 | 2373 | $clauses['fields'] .= ", "; |
| 2374 | 2374 | } |
| 2375 | 2375 | |
@@ -2380,4 +2380,4 @@ discard block |
||
| 2380 | 2380 | |
| 2381 | 2381 | return $clauses; |
| 2382 | 2382 | } |
| 2383 | -add_filter( 'posts_clauses', 'wpinv_filter_posts_clauses', 10, 2 ); |
|
| 2384 | 2383 | \ No newline at end of file |
| 2384 | +add_filter('posts_clauses', 'wpinv_filter_posts_clauses', 10, 2); |
|
| 2385 | 2385 | \ No newline at end of file |