@@ -7,36 +7,36 @@ discard block |
||
| 7 | 7 | * @version 1.0.19 |
| 8 | 8 | */ |
| 9 | 9 | |
| 10 | -defined( 'ABSPATH' ) || exit; |
|
| 10 | +defined('ABSPATH') || exit; |
|
| 11 | 11 | |
| 12 | 12 | // Cart table columns. |
| 13 | 13 | $columns = array( |
| 14 | - 'name' => __( 'Item', 'invoicing' ), |
|
| 15 | - 'price' => __( 'Price', 'invoicing' ), |
|
| 16 | - 'quantity' => __( 'Qty', 'invoicing' ), |
|
| 17 | - 'subtotal' => __( 'Subtotal', 'invoicing' ), |
|
| 14 | + 'name' => __('Item', 'invoicing'), |
|
| 15 | + 'price' => __('Price', 'invoicing'), |
|
| 16 | + 'quantity' => __('Qty', 'invoicing'), |
|
| 17 | + 'subtotal' => __('Subtotal', 'invoicing'), |
|
| 18 | 18 | ); |
| 19 | 19 | |
| 20 | -if ( ! empty( $form->invoice ) ) { |
|
| 21 | - $columns = getpaid_invoice_item_columns( $form->invoice ); |
|
| 20 | +if (!empty($form->invoice)) { |
|
| 21 | + $columns = getpaid_invoice_item_columns($form->invoice); |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | -if ( isset( $columns['tax_rate'] ) ) { |
|
| 25 | - unset( $columns['tax_rate'] ); |
|
| 24 | +if (isset($columns['tax_rate'])) { |
|
| 25 | + unset($columns['tax_rate']); |
|
| 26 | 26 | } |
| 27 | 27 | |
| 28 | -$columns = apply_filters( 'getpaid_payment_form_cart_table_columns', $columns, $form ); |
|
| 28 | +$columns = apply_filters('getpaid_payment_form_cart_table_columns', $columns, $form); |
|
| 29 | 29 | |
| 30 | -do_action( 'getpaid_before_payment_form_cart', $form ); |
|
| 30 | +do_action('getpaid_before_payment_form_cart', $form); |
|
| 31 | 31 | |
| 32 | 32 | ?> |
| 33 | 33 | <div class="getpaid-payment-form-items-cart border form-group"> |
| 34 | 34 | |
| 35 | 35 | <div class="getpaid-payment-form-items-cart-header font-weight-bold bg-light border-bottom py-2 px-3"> |
| 36 | 36 | <div class="form-row"> |
| 37 | - <?php foreach ( $columns as $key => $label ) : ?> |
|
| 38 | - <div class="<?php echo 'name' == $key ? 'col-6' : 'col' ?> <?php echo ( in_array( $key, array( 'subtotal', 'quantity', 'tax_rate' ) ) ) ? 'd-none d-sm-block' : '' ?> getpaid-form-cart-item-<?php echo sanitize_html_class( $key ); ?>"> |
|
| 39 | - <span><?php echo esc_html( $label ); ?></span> |
|
| 37 | + <?php foreach ($columns as $key => $label) : ?> |
|
| 38 | + <div class="<?php echo 'name' == $key ? 'col-6' : 'col' ?> <?php echo (in_array($key, array('subtotal', 'quantity', 'tax_rate'))) ? 'd-none d-sm-block' : '' ?> getpaid-form-cart-item-<?php echo sanitize_html_class($key); ?>"> |
|
| 39 | + <span><?php echo esc_html($label); ?></span> |
|
| 40 | 40 | </div> |
| 41 | 41 | <?php endforeach; ?> |
| 42 | 42 | </div> |
@@ -45,16 +45,16 @@ discard block |
||
| 45 | 45 | <?php |
| 46 | 46 | |
| 47 | 47 | // Display the item totals. |
| 48 | - foreach ( $form->get_items() as $item ) { |
|
| 49 | - wpinv_get_template( 'payment-forms/cart-item.php', compact( 'form', 'item', 'columns' ) ); |
|
| 48 | + foreach ($form->get_items() as $item) { |
|
| 49 | + wpinv_get_template('payment-forms/cart-item.php', compact('form', 'item', 'columns')); |
|
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | // Display the cart totals. |
| 53 | - wpinv_get_template( 'payment-forms/cart-totals.php', compact( 'form' ) ); |
|
| 53 | + wpinv_get_template('payment-forms/cart-totals.php', compact('form')); |
|
| 54 | 54 | |
| 55 | 55 | ?> |
| 56 | 56 | </div> |
| 57 | 57 | |
| 58 | 58 | <?php |
| 59 | 59 | |
| 60 | -do_action( 'getpaid_after_payment_form_cart', $form ); |
|
| 60 | +do_action('getpaid_after_payment_form_cart', $form); |
|
@@ -7,31 +7,31 @@ |
||
| 7 | 7 | * @version 1.0.19 |
| 8 | 8 | */ |
| 9 | 9 | |
| 10 | -defined( 'ABSPATH' ) || exit; |
|
| 10 | +defined('ABSPATH') || exit; |
|
| 11 | 11 | |
| 12 | 12 | // Prepare the selectable items. |
| 13 | 13 | $selectable = array(); |
| 14 | -foreach ( $form->get_items() as $item ) { |
|
| 15 | - if ( ! $item->is_required ) { |
|
| 16 | - $selectable[$item->get_id()] = $item->get_name() . ' — ' . wpinv_price( $item->get_initial_price() ); |
|
| 14 | +foreach ($form->get_items() as $item) { |
|
| 15 | + if (!$item->is_required) { |
|
| 16 | + $selectable[$item->get_id()] = $item->get_name() . ' — ' . wpinv_price($item->get_initial_price()); |
|
| 17 | 17 | } |
| 18 | 18 | } |
| 19 | 19 | |
| 20 | -if ( empty( $selectable ) ) { |
|
| 20 | +if (empty($selectable)) { |
|
| 21 | 21 | return; |
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | echo '<div class="getpaid-payment-form-items-checkbox form-group">'; |
| 25 | 25 | |
| 26 | -foreach ( $selectable as $item_id => $item_name ) { |
|
| 26 | +foreach ($selectable as $item_id => $item_name) { |
|
| 27 | 27 | |
| 28 | - $is_checked = get_post_meta( $item_id, 'selected_by_default', true ); |
|
| 28 | + $is_checked = get_post_meta($item_id, 'selected_by_default', true); |
|
| 29 | 29 | |
| 30 | 30 | echo aui()->input( |
| 31 | 31 | array( |
| 32 | 32 | 'type' => 'checkbox', |
| 33 | 33 | 'name' => 'getpaid-payment-form-selected-item', |
| 34 | - 'id' => 'getpaid-payment-form-selected-item' . uniqid( '_' ) . $item_id, |
|
| 34 | + 'id' => 'getpaid-payment-form-selected-item' . uniqid('_') . $item_id, |
|
| 35 | 35 | 'label' => $item_name, |
| 36 | 36 | 'value' => $item_id, |
| 37 | 37 | 'no_wrap' => true, |
@@ -7,26 +7,26 @@ discard block |
||
| 7 | 7 | * @version 1.0.19 |
| 8 | 8 | */ |
| 9 | 9 | |
| 10 | -defined( 'ABSPATH' ) || exit; |
|
| 10 | +defined('ABSPATH') || exit; |
|
| 11 | 11 | |
| 12 | 12 | // Make sure that the form is active. |
| 13 | -if ( ! $form->is_active() ) { |
|
| 13 | +if (!$form->is_active()) { |
|
| 14 | 14 | echo aui()->alert( |
| 15 | 15 | array( |
| 16 | 16 | 'type' => 'warning', |
| 17 | - 'content' => __( 'This payment form is no longer active', 'invoicing' ), |
|
| 17 | + 'content' => __('This payment form is no longer active', 'invoicing'), |
|
| 18 | 18 | ) |
| 19 | 19 | ); |
| 20 | 20 | return; |
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | // Require login to checkout. |
| 24 | -if ( wpinv_require_login_to_checkout() && ! get_current_user_id() ) { |
|
| 24 | +if (wpinv_require_login_to_checkout() && !get_current_user_id()) { |
|
| 25 | 25 | |
| 26 | 26 | echo aui()->alert( |
| 27 | 27 | array( |
| 28 | 28 | 'type' => 'danger', |
| 29 | - 'content' => __( 'You must be logged in to checkout.', 'invoicing' ), |
|
| 29 | + 'content' => __('You must be logged in to checkout.', 'invoicing'), |
|
| 30 | 30 | ) |
| 31 | 31 | ); |
| 32 | 32 | return; |
@@ -34,29 +34,29 @@ discard block |
||
| 34 | 34 | } |
| 35 | 35 | |
| 36 | 36 | // Fires before displaying a payment form. |
| 37 | -do_action( 'getpaid_before_payment_form', $form ); |
|
| 37 | +do_action('getpaid_before_payment_form', $form); |
|
| 38 | 38 | ?> |
| 39 | 39 | |
| 40 | -<form class='getpaid-payment-form getpaid-payment-form-<?php echo absint( $form->get_id() ); ?> bsui position-relative' method='POST' data-key='<?php echo uniqid('gpf'); ?>' data-currency='<?php echo esc_attr( empty( $form->invoice ) ? wpinv_get_currency() : $form->invoice->get_currency() ); ?>' novalidate> |
|
| 40 | +<form class='getpaid-payment-form getpaid-payment-form-<?php echo absint($form->get_id()); ?> bsui position-relative' method='POST' data-key='<?php echo uniqid('gpf'); ?>' data-currency='<?php echo esc_attr(empty($form->invoice) ? wpinv_get_currency() : $form->invoice->get_currency()); ?>' novalidate> |
|
| 41 | 41 | |
| 42 | 42 | <?php |
| 43 | 43 | |
| 44 | 44 | // Fires when printing the top of a payment form. |
| 45 | - do_action( 'getpaid_payment_form_top', $form ); |
|
| 45 | + do_action('getpaid_payment_form_top', $form); |
|
| 46 | 46 | |
| 47 | 47 | // And the optional invoice id. |
| 48 | - if ( ! empty( $form->invoice ) ) { |
|
| 49 | - echo getpaid_hidden_field( 'invoice_id', $form->invoice->get_id() ); |
|
| 48 | + if (!empty($form->invoice)) { |
|
| 49 | + echo getpaid_hidden_field('invoice_id', $form->invoice->get_id()); |
|
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | // We also want to include the form id. |
| 53 | - echo getpaid_hidden_field( 'form_id', $form->get_id() ); |
|
| 53 | + echo getpaid_hidden_field('form_id', $form->get_id()); |
|
| 54 | 54 | |
| 55 | 55 | // And an indication that this is a payment form submission. |
| 56 | - echo getpaid_hidden_field( 'getpaid_payment_form_submission', '1' ); |
|
| 56 | + echo getpaid_hidden_field('getpaid_payment_form_submission', '1'); |
|
| 57 | 57 | |
| 58 | 58 | // Fires before displaying payment form elements. |
| 59 | - do_action( 'getpaid_payment_form_before_elements', $form ); |
|
| 59 | + do_action('getpaid_payment_form_before_elements', $form); |
|
| 60 | 60 | |
| 61 | 61 | // Display the elements. |
| 62 | 62 | ?> |
@@ -64,13 +64,13 @@ discard block |
||
| 64 | 64 | <div class="row"> |
| 65 | 65 | <?php |
| 66 | 66 | |
| 67 | - foreach ( $form->get_elements() as $element ) { |
|
| 67 | + foreach ($form->get_elements() as $element) { |
|
| 68 | 68 | |
| 69 | - if ( isset( $element['type'] ) ) { |
|
| 70 | - $grid_class = esc_attr( getpaid_get_form_element_grid_class( $element ) ); |
|
| 69 | + if (isset($element['type'])) { |
|
| 70 | + $grid_class = esc_attr(getpaid_get_form_element_grid_class($element)); |
|
| 71 | 71 | echo "<div class='$grid_class'>"; |
| 72 | - do_action( 'getpaid_payment_form_element', $element, $form ); |
|
| 73 | - do_action( "getpaid_payment_form_element_{$element['type']}_template", $element, $form ); |
|
| 72 | + do_action('getpaid_payment_form_element', $element, $form); |
|
| 73 | + do_action("getpaid_payment_form_element_{$element['type']}_template", $element, $form); |
|
| 74 | 74 | echo "</div>"; |
| 75 | 75 | } |
| 76 | 76 | |
@@ -82,16 +82,16 @@ discard block |
||
| 82 | 82 | |
| 83 | 83 | <?php |
| 84 | 84 | // Fires after displaying payment form elements. |
| 85 | - do_action( 'getpaid_payment_form_after_elements', $form ); |
|
| 85 | + do_action('getpaid_payment_form_after_elements', $form); |
|
| 86 | 86 | |
| 87 | 87 | echo "<div class='getpaid-payment-form-errors alert alert-danger d-none'></div>"; |
| 88 | 88 | |
| 89 | - if ( wpinv_current_user_can_manage_invoicing() ) { |
|
| 89 | + if (wpinv_current_user_can_manage_invoicing()) { |
|
| 90 | 90 | |
| 91 | 91 | edit_post_link( |
| 92 | - __( 'Edit this form.', 'invoicing' ), |
|
| 92 | + __('Edit this form.', 'invoicing'), |
|
| 93 | 93 | '<small class="form-text text-muted">', |
| 94 | - ' ' . __( 'This is only visible to website administators.', 'invoicing' ) . '</small>', |
|
| 94 | + ' ' . __('This is only visible to website administators.', 'invoicing') . '</small>', |
|
| 95 | 95 | $form->get_id(), |
| 96 | 96 | 'text-danger' |
| 97 | 97 | ); |
@@ -103,7 +103,7 @@ discard block |
||
| 103 | 103 | |
| 104 | 104 | <div class="loading_div overlay overlay-black position-absolute row m-0 rounded overflow-hidden" style="height: 100%;width: 100%;top: 0px;z-index: 2;display:none;"> |
| 105 | 105 | <div class="spinner-border mx-auto align-self-center text-white" role="status"> |
| 106 | - <span class="sr-only"><?php _e( 'Loading...', 'invoicing' );?></span> |
|
| 106 | + <span class="sr-only"><?php _e('Loading...', 'invoicing'); ?></span> |
|
| 107 | 107 | </div> |
| 108 | 108 | </div> |
| 109 | 109 | |
@@ -112,4 +112,4 @@ discard block |
||
| 112 | 112 | <?php |
| 113 | 113 | |
| 114 | 114 | // Fires after displaying a payment form. |
| 115 | -do_action( 'getpaid_after_payment_form', $form ); |
|
| 115 | +do_action('getpaid_after_payment_form', $form); |
|
@@ -12,276 +12,276 @@ |
||
| 12 | 12 | */ |
| 13 | 13 | class GetPaid_Metaboxes { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * Only save metaboxes once. |
|
| 17 | - * |
|
| 18 | - * @var boolean |
|
| 19 | - */ |
|
| 20 | - private static $saved_meta_boxes = false; |
|
| 21 | - |
|
| 22 | 15 | /** |
| 23 | - * Hook in methods. |
|
| 24 | - */ |
|
| 25 | - public static function init() { |
|
| 26 | - |
|
| 27 | - // Register metaboxes. |
|
| 28 | - add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::add_meta_boxes', 5, 2 ); |
|
| 29 | - |
|
| 30 | - // Remove metaboxes. |
|
| 31 | - add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::remove_meta_boxes', 30 ); |
|
| 32 | - |
|
| 33 | - // Rename metaboxes. |
|
| 34 | - add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::rename_meta_boxes', 45 ); |
|
| 35 | - |
|
| 36 | - // Save metaboxes. |
|
| 37 | - add_action( 'save_post', 'GetPaid_Metaboxes::save_meta_boxes', 1, 2 ); |
|
| 38 | - } |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * Register core metaboxes. |
|
| 42 | - */ |
|
| 43 | - public static function add_meta_boxes( $post_type, $post ) { |
|
| 44 | - |
|
| 45 | - // For invoices... |
|
| 46 | - self::add_invoice_meta_boxes( $post_type, $post ); |
|
| 47 | - |
|
| 48 | - // For payment forms. |
|
| 49 | - self::add_payment_form_meta_boxes( $post_type, $post ); |
|
| 50 | - |
|
| 51 | - // For invoice items. |
|
| 52 | - self::add_item_meta_boxes( $post_type ); |
|
| 53 | - |
|
| 54 | - // For invoice discounts. |
|
| 55 | - if ( $post_type == 'wpi_discount' ) { |
|
| 56 | - add_meta_box( 'wpinv_discount_details', __( 'Discount Details', 'invoicing' ), 'GetPaid_Meta_Box_Discount_Details::output', 'wpi_discount', 'normal', 'high' ); |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - } |
|
| 16 | + * Only save metaboxes once. |
|
| 17 | + * |
|
| 18 | + * @var boolean |
|
| 19 | + */ |
|
| 20 | + private static $saved_meta_boxes = false; |
|
| 60 | 21 | |
| 61 | - /** |
|
| 62 | - * Register core metaboxes. |
|
| 63 | - */ |
|
| 64 | - protected static function add_payment_form_meta_boxes( $post_type, $post ) { |
|
| 22 | + /** |
|
| 23 | + * Hook in methods. |
|
| 24 | + */ |
|
| 25 | + public static function init() { |
|
| 65 | 26 | |
| 66 | - // For payment forms. |
|
| 67 | - if ( $post_type == 'wpi_payment_form' ) { |
|
| 27 | + // Register metaboxes. |
|
| 28 | + add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::add_meta_boxes', 5, 2 ); |
|
| 68 | 29 | |
| 69 | - // Design payment form. |
|
| 70 | - add_meta_box( 'wpinv-payment-form-design', __( 'Payment Form', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form::output', 'wpi_payment_form', 'normal' ); |
|
| 30 | + // Remove metaboxes. |
|
| 31 | + add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::remove_meta_boxes', 30 ); |
|
| 71 | 32 | |
| 72 | - // Payment form information. |
|
| 73 | - if ( $post->ID != wpinv_get_default_payment_form() ) { |
|
| 74 | - add_meta_box( 'wpinv-payment-form-info', __( 'Details', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form_Info::output', 'wpi_payment_form', 'side' ); |
|
| 75 | - } |
|
| 33 | + // Rename metaboxes. |
|
| 34 | + add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::rename_meta_boxes', 45 ); |
|
| 76 | 35 | |
| 77 | - } |
|
| 36 | + // Save metaboxes. |
|
| 37 | + add_action( 'save_post', 'GetPaid_Metaboxes::save_meta_boxes', 1, 2 ); |
|
| 38 | + } |
|
| 78 | 39 | |
| 79 | - } |
|
| 40 | + /** |
|
| 41 | + * Register core metaboxes. |
|
| 42 | + */ |
|
| 43 | + public static function add_meta_boxes( $post_type, $post ) { |
|
| 80 | 44 | |
| 81 | - /** |
|
| 82 | - * Register core metaboxes. |
|
| 83 | - */ |
|
| 84 | - protected static function add_item_meta_boxes( $post_type ) { |
|
| 45 | + // For invoices... |
|
| 46 | + self::add_invoice_meta_boxes( $post_type, $post ); |
|
| 85 | 47 | |
| 86 | - if ( $post_type == 'wpi_item' ) { |
|
| 48 | + // For payment forms. |
|
| 49 | + self::add_payment_form_meta_boxes( $post_type, $post ); |
|
| 87 | 50 | |
| 88 | - // Item details. |
|
| 89 | - add_meta_box( 'wpinv_item_details', __( 'Item Details', 'invoicing' ), 'GetPaid_Meta_Box_Item_Details::output', 'wpi_item', 'normal', 'high' ); |
|
| 51 | + // For invoice items. |
|
| 52 | + self::add_item_meta_boxes( $post_type ); |
|
| 90 | 53 | |
| 91 | - // If taxes are enabled, register the tax metabox. |
|
| 92 | - if ( wpinv_use_taxes() ) { |
|
| 93 | - add_meta_box( 'wpinv_item_vat', __( 'Tax', 'invoicing' ), 'GetPaid_Meta_Box_Item_VAT::output', 'wpi_item', 'normal', 'high' ); |
|
| 94 | - } |
|
| 54 | + // For invoice discounts. |
|
| 55 | + if ( $post_type == 'wpi_discount' ) { |
|
| 56 | + add_meta_box( 'wpinv_discount_details', __( 'Discount Details', 'invoicing' ), 'GetPaid_Meta_Box_Discount_Details::output', 'wpi_discount', 'normal', 'high' ); |
|
| 57 | + } |
|
| 95 | 58 | |
| 96 | - // Item info. |
|
| 97 | - add_meta_box( 'wpinv_field_item_info', __( 'Item info', 'invoicing' ), 'GetPaid_Meta_Box_Item_Info::output', 'wpi_item', 'side', 'core' ); |
|
| 59 | + } |
|
| 98 | 60 | |
| 99 | - } |
|
| 61 | + /** |
|
| 62 | + * Register core metaboxes. |
|
| 63 | + */ |
|
| 64 | + protected static function add_payment_form_meta_boxes( $post_type, $post ) { |
|
| 100 | 65 | |
| 101 | - } |
|
| 66 | + // For payment forms. |
|
| 67 | + if ( $post_type == 'wpi_payment_form' ) { |
|
| 102 | 68 | |
| 103 | - /** |
|
| 104 | - * Register invoice metaboxes. |
|
| 105 | - */ |
|
| 106 | - protected static function add_invoice_meta_boxes( $post_type, $post ) { |
|
| 69 | + // Design payment form. |
|
| 70 | + add_meta_box( 'wpinv-payment-form-design', __( 'Payment Form', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form::output', 'wpi_payment_form', 'normal' ); |
|
| 107 | 71 | |
| 108 | - // For invoices... |
|
| 109 | - if ( getpaid_is_invoice_post_type( $post_type ) ) { |
|
| 110 | - $invoice = new WPInv_Invoice( $post ); |
|
| 72 | + // Payment form information. |
|
| 73 | + if ( $post->ID != wpinv_get_default_payment_form() ) { |
|
| 74 | + add_meta_box( 'wpinv-payment-form-info', __( 'Details', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form_Info::output', 'wpi_payment_form', 'side' ); |
|
| 75 | + } |
|
| 111 | 76 | |
| 112 | - // Resend invoice. |
|
| 113 | - if ( ! $invoice->is_draft() ) { |
|
| 77 | + } |
|
| 114 | 78 | |
| 115 | - add_meta_box( |
|
| 116 | - 'wpinv-mb-resend-invoice', |
|
| 117 | - sprintf( |
|
| 118 | - __( 'Resend %s', 'invoicing' ), |
|
| 119 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
| 120 | - ), |
|
| 121 | - 'GetPaid_Meta_Box_Resend_Invoice::output', |
|
| 122 | - $post_type, |
|
| 123 | - 'side', |
|
| 124 | - 'low' |
|
| 125 | - ); |
|
| 79 | + } |
|
| 126 | 80 | |
| 127 | - } |
|
| 81 | + /** |
|
| 82 | + * Register core metaboxes. |
|
| 83 | + */ |
|
| 84 | + protected static function add_item_meta_boxes( $post_type ) { |
|
| 128 | 85 | |
| 129 | - // Subscriptions. |
|
| 130 | - $subscriptions = getpaid_get_invoice_subscriptions( $invoice ); |
|
| 131 | - if ( ! empty( $subscriptions ) ) { |
|
| 86 | + if ( $post_type == 'wpi_item' ) { |
|
| 132 | 87 | |
| 133 | - if ( is_array( $subscriptions ) ) { |
|
| 134 | - add_meta_box( 'wpinv-mb-subscriptions', __( 'Related Subscriptions', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output_related', $post_type, 'advanced' ); |
|
| 135 | - } else { |
|
| 136 | - add_meta_box( 'wpinv-mb-subscriptions', __( 'Subscription Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output', $post_type, 'advanced' ); |
|
| 137 | - } |
|
| 88 | + // Item details. |
|
| 89 | + add_meta_box( 'wpinv_item_details', __( 'Item Details', 'invoicing' ), 'GetPaid_Meta_Box_Item_Details::output', 'wpi_item', 'normal', 'high' ); |
|
| 138 | 90 | |
| 139 | - if ( getpaid_count_subscription_invoices( $invoice->is_renewal() ? $invoice->get_parent_id() : $invoice->get_id() ) > 1 ) { |
|
| 140 | - add_meta_box( 'wpinv-mb-subscription-invoices', __( 'Related Payments', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output_invoices', $post_type, 'advanced' ); |
|
| 141 | - } |
|
| 91 | + // If taxes are enabled, register the tax metabox. |
|
| 92 | + if ( wpinv_use_taxes() ) { |
|
| 93 | + add_meta_box( 'wpinv_item_vat', __( 'Tax', 'invoicing' ), 'GetPaid_Meta_Box_Item_VAT::output', 'wpi_item', 'normal', 'high' ); |
|
| 94 | + } |
|
| 142 | 95 | |
| 143 | - } |
|
| 96 | + // Item info. |
|
| 97 | + add_meta_box( 'wpinv_field_item_info', __( 'Item info', 'invoicing' ), 'GetPaid_Meta_Box_Item_Info::output', 'wpi_item', 'side', 'core' ); |
|
| 144 | 98 | |
| 145 | - // Invoice details. |
|
| 146 | - add_meta_box( |
|
| 147 | - 'wpinv-details', |
|
| 148 | - sprintf( |
|
| 149 | - __( '%s Details', 'invoicing' ), |
|
| 150 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
| 151 | - ), |
|
| 152 | - 'GetPaid_Meta_Box_Invoice_Details::output', |
|
| 153 | - $post_type, |
|
| 154 | - 'side' |
|
| 155 | - ); |
|
| 99 | + } |
|
| 156 | 100 | |
| 157 | - // Payment details. |
|
| 158 | - add_meta_box( 'wpinv-payment-meta', __( 'Payment Meta', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Payment_Meta::output', $post_type, 'side', 'default' ); |
|
| 101 | + } |
|
| 159 | 102 | |
| 160 | - // Billing details. |
|
| 161 | - add_meta_box( 'wpinv-address', __( 'Billing Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Address::output', $post_type, 'normal', 'high' ); |
|
| 103 | + /** |
|
| 104 | + * Register invoice metaboxes. |
|
| 105 | + */ |
|
| 106 | + protected static function add_invoice_meta_boxes( $post_type, $post ) { |
|
| 107 | + |
|
| 108 | + // For invoices... |
|
| 109 | + if ( getpaid_is_invoice_post_type( $post_type ) ) { |
|
| 110 | + $invoice = new WPInv_Invoice( $post ); |
|
| 111 | + |
|
| 112 | + // Resend invoice. |
|
| 113 | + if ( ! $invoice->is_draft() ) { |
|
| 114 | + |
|
| 115 | + add_meta_box( |
|
| 116 | + 'wpinv-mb-resend-invoice', |
|
| 117 | + sprintf( |
|
| 118 | + __( 'Resend %s', 'invoicing' ), |
|
| 119 | + ucfirst( $invoice->get_invoice_quote_type() ) |
|
| 120 | + ), |
|
| 121 | + 'GetPaid_Meta_Box_Resend_Invoice::output', |
|
| 122 | + $post_type, |
|
| 123 | + 'side', |
|
| 124 | + 'low' |
|
| 125 | + ); |
|
| 126 | + |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + // Subscriptions. |
|
| 130 | + $subscriptions = getpaid_get_invoice_subscriptions( $invoice ); |
|
| 131 | + if ( ! empty( $subscriptions ) ) { |
|
| 132 | + |
|
| 133 | + if ( is_array( $subscriptions ) ) { |
|
| 134 | + add_meta_box( 'wpinv-mb-subscriptions', __( 'Related Subscriptions', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output_related', $post_type, 'advanced' ); |
|
| 135 | + } else { |
|
| 136 | + add_meta_box( 'wpinv-mb-subscriptions', __( 'Subscription Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output', $post_type, 'advanced' ); |
|
| 137 | + } |
|
| 138 | + |
|
| 139 | + if ( getpaid_count_subscription_invoices( $invoice->is_renewal() ? $invoice->get_parent_id() : $invoice->get_id() ) > 1 ) { |
|
| 140 | + add_meta_box( 'wpinv-mb-subscription-invoices', __( 'Related Payments', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output_invoices', $post_type, 'advanced' ); |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + } |
|
| 144 | + |
|
| 145 | + // Invoice details. |
|
| 146 | + add_meta_box( |
|
| 147 | + 'wpinv-details', |
|
| 148 | + sprintf( |
|
| 149 | + __( '%s Details', 'invoicing' ), |
|
| 150 | + ucfirst( $invoice->get_invoice_quote_type() ) |
|
| 151 | + ), |
|
| 152 | + 'GetPaid_Meta_Box_Invoice_Details::output', |
|
| 153 | + $post_type, |
|
| 154 | + 'side' |
|
| 155 | + ); |
|
| 156 | + |
|
| 157 | + // Payment details. |
|
| 158 | + add_meta_box( 'wpinv-payment-meta', __( 'Payment Meta', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Payment_Meta::output', $post_type, 'side', 'default' ); |
|
| 159 | + |
|
| 160 | + // Billing details. |
|
| 161 | + add_meta_box( 'wpinv-address', __( 'Billing Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Address::output', $post_type, 'normal', 'high' ); |
|
| 162 | 162 | |
| 163 | - // Invoice items. |
|
| 164 | - add_meta_box( |
|
| 165 | - 'wpinv-items', |
|
| 166 | - sprintf( |
|
| 167 | - __( '%s Items', 'invoicing' ), |
|
| 168 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
| 169 | - ), |
|
| 170 | - 'GetPaid_Meta_Box_Invoice_Items::output', |
|
| 171 | - $post_type, |
|
| 172 | - 'normal', |
|
| 173 | - 'high' |
|
| 174 | - ); |
|
| 163 | + // Invoice items. |
|
| 164 | + add_meta_box( |
|
| 165 | + 'wpinv-items', |
|
| 166 | + sprintf( |
|
| 167 | + __( '%s Items', 'invoicing' ), |
|
| 168 | + ucfirst( $invoice->get_invoice_quote_type() ) |
|
| 169 | + ), |
|
| 170 | + 'GetPaid_Meta_Box_Invoice_Items::output', |
|
| 171 | + $post_type, |
|
| 172 | + 'normal', |
|
| 173 | + 'high' |
|
| 174 | + ); |
|
| 175 | 175 | |
| 176 | - // Invoice notes. |
|
| 177 | - add_meta_box( |
|
| 178 | - 'wpinv-notes', |
|
| 179 | - sprintf( |
|
| 180 | - __( '%s Notes', 'invoicing' ), |
|
| 181 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
| 182 | - ), |
|
| 183 | - 'WPInv_Meta_Box_Notes::output', |
|
| 184 | - $post_type, |
|
| 185 | - 'side', |
|
| 186 | - 'low' |
|
| 187 | - ); |
|
| 188 | - |
|
| 189 | - // Shipping Address. |
|
| 190 | - if ( get_post_meta( $invoice->get_id(), 'shipping_address', true ) ) { |
|
| 191 | - add_meta_box( 'wpinv-invoice-shipping-details', __( 'Shipping Address', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Shipping_Address::output', $post_type, 'side', 'high' ); |
|
| 192 | - } |
|
| 193 | - |
|
| 194 | - // Payment form information. |
|
| 195 | - if ( get_post_meta( $invoice->get_id(), 'payment_form_data', true ) ) { |
|
| 196 | - add_meta_box( 'wpinv-invoice-payment-form-details', __( 'Payment Form Details', 'invoicing' ), 'WPInv_Meta_Box_Payment_Form::output_details', $post_type, 'side', 'high' ); |
|
| 197 | - } |
|
| 198 | - |
|
| 199 | - } |
|
| 200 | - |
|
| 201 | - } |
|
| 202 | - |
|
| 203 | - /** |
|
| 204 | - * Remove some metaboxes. |
|
| 205 | - */ |
|
| 206 | - public static function remove_meta_boxes() { |
|
| 207 | - remove_meta_box( 'wpseo_meta', 'wpi_invoice', 'normal' ); |
|
| 208 | - } |
|
| 209 | - |
|
| 210 | - /** |
|
| 211 | - * Rename other metaboxes. |
|
| 212 | - */ |
|
| 213 | - public static function rename_meta_boxes() { |
|
| 176 | + // Invoice notes. |
|
| 177 | + add_meta_box( |
|
| 178 | + 'wpinv-notes', |
|
| 179 | + sprintf( |
|
| 180 | + __( '%s Notes', 'invoicing' ), |
|
| 181 | + ucfirst( $invoice->get_invoice_quote_type() ) |
|
| 182 | + ), |
|
| 183 | + 'WPInv_Meta_Box_Notes::output', |
|
| 184 | + $post_type, |
|
| 185 | + 'side', |
|
| 186 | + 'low' |
|
| 187 | + ); |
|
| 188 | + |
|
| 189 | + // Shipping Address. |
|
| 190 | + if ( get_post_meta( $invoice->get_id(), 'shipping_address', true ) ) { |
|
| 191 | + add_meta_box( 'wpinv-invoice-shipping-details', __( 'Shipping Address', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Shipping_Address::output', $post_type, 'side', 'high' ); |
|
| 192 | + } |
|
| 193 | + |
|
| 194 | + // Payment form information. |
|
| 195 | + if ( get_post_meta( $invoice->get_id(), 'payment_form_data', true ) ) { |
|
| 196 | + add_meta_box( 'wpinv-invoice-payment-form-details', __( 'Payment Form Details', 'invoicing' ), 'WPInv_Meta_Box_Payment_Form::output_details', $post_type, 'side', 'high' ); |
|
| 197 | + } |
|
| 198 | + |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + } |
|
| 202 | + |
|
| 203 | + /** |
|
| 204 | + * Remove some metaboxes. |
|
| 205 | + */ |
|
| 206 | + public static function remove_meta_boxes() { |
|
| 207 | + remove_meta_box( 'wpseo_meta', 'wpi_invoice', 'normal' ); |
|
| 208 | + } |
|
| 209 | + |
|
| 210 | + /** |
|
| 211 | + * Rename other metaboxes. |
|
| 212 | + */ |
|
| 213 | + public static function rename_meta_boxes() { |
|
| 214 | 214 | |
| 215 | - } |
|
| 216 | - |
|
| 217 | - /** |
|
| 218 | - * Check if we're saving, then trigger an action based on the post type. |
|
| 219 | - * |
|
| 220 | - * @param int $post_id Post ID. |
|
| 221 | - * @param object $post Post object. |
|
| 222 | - */ |
|
| 223 | - public static function save_meta_boxes( $post_id, $post ) { |
|
| 224 | - $post_id = absint( $post_id ); |
|
| 225 | - $data = wp_kses_post_deep( wp_unslash( $_POST ) ); |
|
| 226 | - |
|
| 227 | - // Do not save for ajax requests. |
|
| 228 | - if ( ( defined( 'DOING_AJAX') && DOING_AJAX ) || isset( $_REQUEST['bulk_edit'] ) ) { |
|
| 229 | - return; |
|
| 230 | - } |
|
| 231 | - |
|
| 232 | - // $post_id and $post are required |
|
| 233 | - if ( empty( $post_id ) || empty( $post ) || self::$saved_meta_boxes ) { |
|
| 234 | - return; |
|
| 235 | - } |
|
| 236 | - |
|
| 237 | - // Dont' save meta boxes for revisions or autosaves. |
|
| 238 | - if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || is_int( wp_is_post_revision( $post ) ) || is_int( wp_is_post_autosave( $post ) ) ) { |
|
| 239 | - return; |
|
| 240 | - } |
|
| 241 | - |
|
| 242 | - // Check the nonce. |
|
| 243 | - if ( empty( $data['getpaid_meta_nonce'] ) || ! wp_verify_nonce( $data['getpaid_meta_nonce'], 'getpaid_meta_nonce' ) ) { |
|
| 244 | - return; |
|
| 245 | - } |
|
| 246 | - |
|
| 247 | - // Check the post being saved == the $post_id to prevent triggering this call for other save_post events. |
|
| 248 | - if ( empty( $data['post_ID'] ) || absint( $data['post_ID'] ) !== $post_id ) { |
|
| 249 | - return; |
|
| 250 | - } |
|
| 251 | - |
|
| 252 | - // Check user has permission to edit. |
|
| 253 | - if ( ! current_user_can( 'edit_post', $post_id ) ) { |
|
| 254 | - return; |
|
| 255 | - } |
|
| 256 | - |
|
| 257 | - if ( getpaid_is_invoice_post_type( $post->post_type ) ) { |
|
| 258 | - |
|
| 259 | - // We need this save event to run once to avoid potential endless loops. |
|
| 260 | - self::$saved_meta_boxes = true; |
|
| 261 | - |
|
| 262 | - return GetPaid_Meta_Box_Invoice_Address::save( $post_id ); |
|
| 263 | - |
|
| 264 | - } |
|
| 265 | - |
|
| 266 | - // Ensure this is our post type. |
|
| 267 | - $post_types_map = array( |
|
| 268 | - 'wpi_item' => 'GetPaid_Meta_Box_Item_Details', |
|
| 269 | - 'wpi_payment_form' => 'GetPaid_Meta_Box_Payment_Form', |
|
| 270 | - 'wpi_discount' => 'GetPaid_Meta_Box_Discount_Details', |
|
| 271 | - ); |
|
| 272 | - |
|
| 273 | - // Is this our post type? |
|
| 274 | - if ( ! isset( $post_types_map[ $post->post_type ] ) ) { |
|
| 275 | - return; |
|
| 276 | - } |
|
| 277 | - |
|
| 278 | - // We need this save event to run once to avoid potential endless loops. |
|
| 279 | - self::$saved_meta_boxes = true; |
|
| 215 | + } |
|
| 216 | + |
|
| 217 | + /** |
|
| 218 | + * Check if we're saving, then trigger an action based on the post type. |
|
| 219 | + * |
|
| 220 | + * @param int $post_id Post ID. |
|
| 221 | + * @param object $post Post object. |
|
| 222 | + */ |
|
| 223 | + public static function save_meta_boxes( $post_id, $post ) { |
|
| 224 | + $post_id = absint( $post_id ); |
|
| 225 | + $data = wp_kses_post_deep( wp_unslash( $_POST ) ); |
|
| 226 | + |
|
| 227 | + // Do not save for ajax requests. |
|
| 228 | + if ( ( defined( 'DOING_AJAX') && DOING_AJAX ) || isset( $_REQUEST['bulk_edit'] ) ) { |
|
| 229 | + return; |
|
| 230 | + } |
|
| 231 | + |
|
| 232 | + // $post_id and $post are required |
|
| 233 | + if ( empty( $post_id ) || empty( $post ) || self::$saved_meta_boxes ) { |
|
| 234 | + return; |
|
| 235 | + } |
|
| 236 | + |
|
| 237 | + // Dont' save meta boxes for revisions or autosaves. |
|
| 238 | + if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || is_int( wp_is_post_revision( $post ) ) || is_int( wp_is_post_autosave( $post ) ) ) { |
|
| 239 | + return; |
|
| 240 | + } |
|
| 241 | + |
|
| 242 | + // Check the nonce. |
|
| 243 | + if ( empty( $data['getpaid_meta_nonce'] ) || ! wp_verify_nonce( $data['getpaid_meta_nonce'], 'getpaid_meta_nonce' ) ) { |
|
| 244 | + return; |
|
| 245 | + } |
|
| 246 | + |
|
| 247 | + // Check the post being saved == the $post_id to prevent triggering this call for other save_post events. |
|
| 248 | + if ( empty( $data['post_ID'] ) || absint( $data['post_ID'] ) !== $post_id ) { |
|
| 249 | + return; |
|
| 250 | + } |
|
| 251 | + |
|
| 252 | + // Check user has permission to edit. |
|
| 253 | + if ( ! current_user_can( 'edit_post', $post_id ) ) { |
|
| 254 | + return; |
|
| 255 | + } |
|
| 256 | + |
|
| 257 | + if ( getpaid_is_invoice_post_type( $post->post_type ) ) { |
|
| 258 | + |
|
| 259 | + // We need this save event to run once to avoid potential endless loops. |
|
| 260 | + self::$saved_meta_boxes = true; |
|
| 261 | + |
|
| 262 | + return GetPaid_Meta_Box_Invoice_Address::save( $post_id ); |
|
| 263 | + |
|
| 264 | + } |
|
| 265 | + |
|
| 266 | + // Ensure this is our post type. |
|
| 267 | + $post_types_map = array( |
|
| 268 | + 'wpi_item' => 'GetPaid_Meta_Box_Item_Details', |
|
| 269 | + 'wpi_payment_form' => 'GetPaid_Meta_Box_Payment_Form', |
|
| 270 | + 'wpi_discount' => 'GetPaid_Meta_Box_Discount_Details', |
|
| 271 | + ); |
|
| 272 | + |
|
| 273 | + // Is this our post type? |
|
| 274 | + if ( ! isset( $post_types_map[ $post->post_type ] ) ) { |
|
| 275 | + return; |
|
| 276 | + } |
|
| 277 | + |
|
| 278 | + // We need this save event to run once to avoid potential endless loops. |
|
| 279 | + self::$saved_meta_boxes = true; |
|
| 280 | 280 | |
| 281 | - // Save the post. |
|
| 282 | - $class = $post_types_map[ $post->post_type ]; |
|
| 283 | - $class::save( $post_id, $_POST, $post ); |
|
| 281 | + // Save the post. |
|
| 282 | + $class = $post_types_map[ $post->post_type ]; |
|
| 283 | + $class::save( $post_id, $_POST, $post ); |
|
| 284 | 284 | |
| 285 | - } |
|
| 285 | + } |
|
| 286 | 286 | |
| 287 | 287 | } |
@@ -4,7 +4,7 @@ discard block |
||
| 4 | 4 | * |
| 5 | 5 | */ |
| 6 | 6 | |
| 7 | -defined( 'ABSPATH' ) || exit; |
|
| 7 | +defined('ABSPATH') || exit; |
|
| 8 | 8 | |
| 9 | 9 | /** |
| 10 | 10 | * Metaboxes Admin Class |
@@ -25,35 +25,35 @@ discard block |
||
| 25 | 25 | public static function init() { |
| 26 | 26 | |
| 27 | 27 | // Register metaboxes. |
| 28 | - add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::add_meta_boxes', 5, 2 ); |
|
| 28 | + add_action('add_meta_boxes', 'GetPaid_Metaboxes::add_meta_boxes', 5, 2); |
|
| 29 | 29 | |
| 30 | 30 | // Remove metaboxes. |
| 31 | - add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::remove_meta_boxes', 30 ); |
|
| 31 | + add_action('add_meta_boxes', 'GetPaid_Metaboxes::remove_meta_boxes', 30); |
|
| 32 | 32 | |
| 33 | 33 | // Rename metaboxes. |
| 34 | - add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::rename_meta_boxes', 45 ); |
|
| 34 | + add_action('add_meta_boxes', 'GetPaid_Metaboxes::rename_meta_boxes', 45); |
|
| 35 | 35 | |
| 36 | 36 | // Save metaboxes. |
| 37 | - add_action( 'save_post', 'GetPaid_Metaboxes::save_meta_boxes', 1, 2 ); |
|
| 37 | + add_action('save_post', 'GetPaid_Metaboxes::save_meta_boxes', 1, 2); |
|
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | /** |
| 41 | 41 | * Register core metaboxes. |
| 42 | 42 | */ |
| 43 | - public static function add_meta_boxes( $post_type, $post ) { |
|
| 43 | + public static function add_meta_boxes($post_type, $post) { |
|
| 44 | 44 | |
| 45 | 45 | // For invoices... |
| 46 | - self::add_invoice_meta_boxes( $post_type, $post ); |
|
| 46 | + self::add_invoice_meta_boxes($post_type, $post); |
|
| 47 | 47 | |
| 48 | 48 | // For payment forms. |
| 49 | - self::add_payment_form_meta_boxes( $post_type, $post ); |
|
| 49 | + self::add_payment_form_meta_boxes($post_type, $post); |
|
| 50 | 50 | |
| 51 | 51 | // For invoice items. |
| 52 | - self::add_item_meta_boxes( $post_type ); |
|
| 52 | + self::add_item_meta_boxes($post_type); |
|
| 53 | 53 | |
| 54 | 54 | // For invoice discounts. |
| 55 | - if ( $post_type == 'wpi_discount' ) { |
|
| 56 | - add_meta_box( 'wpinv_discount_details', __( 'Discount Details', 'invoicing' ), 'GetPaid_Meta_Box_Discount_Details::output', 'wpi_discount', 'normal', 'high' ); |
|
| 55 | + if ($post_type == 'wpi_discount') { |
|
| 56 | + add_meta_box('wpinv_discount_details', __('Discount Details', 'invoicing'), 'GetPaid_Meta_Box_Discount_Details::output', 'wpi_discount', 'normal', 'high'); |
|
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | } |
@@ -61,17 +61,17 @@ discard block |
||
| 61 | 61 | /** |
| 62 | 62 | * Register core metaboxes. |
| 63 | 63 | */ |
| 64 | - protected static function add_payment_form_meta_boxes( $post_type, $post ) { |
|
| 64 | + protected static function add_payment_form_meta_boxes($post_type, $post) { |
|
| 65 | 65 | |
| 66 | 66 | // For payment forms. |
| 67 | - if ( $post_type == 'wpi_payment_form' ) { |
|
| 67 | + if ($post_type == 'wpi_payment_form') { |
|
| 68 | 68 | |
| 69 | 69 | // Design payment form. |
| 70 | - add_meta_box( 'wpinv-payment-form-design', __( 'Payment Form', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form::output', 'wpi_payment_form', 'normal' ); |
|
| 70 | + add_meta_box('wpinv-payment-form-design', __('Payment Form', 'invoicing'), 'GetPaid_Meta_Box_Payment_Form::output', 'wpi_payment_form', 'normal'); |
|
| 71 | 71 | |
| 72 | 72 | // Payment form information. |
| 73 | - if ( $post->ID != wpinv_get_default_payment_form() ) { |
|
| 74 | - add_meta_box( 'wpinv-payment-form-info', __( 'Details', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form_Info::output', 'wpi_payment_form', 'side' ); |
|
| 73 | + if ($post->ID != wpinv_get_default_payment_form()) { |
|
| 74 | + add_meta_box('wpinv-payment-form-info', __('Details', 'invoicing'), 'GetPaid_Meta_Box_Payment_Form_Info::output', 'wpi_payment_form', 'side'); |
|
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | } |
@@ -81,20 +81,20 @@ discard block |
||
| 81 | 81 | /** |
| 82 | 82 | * Register core metaboxes. |
| 83 | 83 | */ |
| 84 | - protected static function add_item_meta_boxes( $post_type ) { |
|
| 84 | + protected static function add_item_meta_boxes($post_type) { |
|
| 85 | 85 | |
| 86 | - if ( $post_type == 'wpi_item' ) { |
|
| 86 | + if ($post_type == 'wpi_item') { |
|
| 87 | 87 | |
| 88 | 88 | // Item details. |
| 89 | - add_meta_box( 'wpinv_item_details', __( 'Item Details', 'invoicing' ), 'GetPaid_Meta_Box_Item_Details::output', 'wpi_item', 'normal', 'high' ); |
|
| 89 | + add_meta_box('wpinv_item_details', __('Item Details', 'invoicing'), 'GetPaid_Meta_Box_Item_Details::output', 'wpi_item', 'normal', 'high'); |
|
| 90 | 90 | |
| 91 | 91 | // If taxes are enabled, register the tax metabox. |
| 92 | - if ( wpinv_use_taxes() ) { |
|
| 93 | - add_meta_box( 'wpinv_item_vat', __( 'Tax', 'invoicing' ), 'GetPaid_Meta_Box_Item_VAT::output', 'wpi_item', 'normal', 'high' ); |
|
| 92 | + if (wpinv_use_taxes()) { |
|
| 93 | + add_meta_box('wpinv_item_vat', __('Tax', 'invoicing'), 'GetPaid_Meta_Box_Item_VAT::output', 'wpi_item', 'normal', 'high'); |
|
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | // Item info. |
| 97 | - add_meta_box( 'wpinv_field_item_info', __( 'Item info', 'invoicing' ), 'GetPaid_Meta_Box_Item_Info::output', 'wpi_item', 'side', 'core' ); |
|
| 97 | + add_meta_box('wpinv_field_item_info', __('Item info', 'invoicing'), 'GetPaid_Meta_Box_Item_Info::output', 'wpi_item', 'side', 'core'); |
|
| 98 | 98 | |
| 99 | 99 | } |
| 100 | 100 | |
@@ -103,20 +103,20 @@ discard block |
||
| 103 | 103 | /** |
| 104 | 104 | * Register invoice metaboxes. |
| 105 | 105 | */ |
| 106 | - protected static function add_invoice_meta_boxes( $post_type, $post ) { |
|
| 106 | + protected static function add_invoice_meta_boxes($post_type, $post) { |
|
| 107 | 107 | |
| 108 | 108 | // For invoices... |
| 109 | - if ( getpaid_is_invoice_post_type( $post_type ) ) { |
|
| 110 | - $invoice = new WPInv_Invoice( $post ); |
|
| 109 | + if (getpaid_is_invoice_post_type($post_type)) { |
|
| 110 | + $invoice = new WPInv_Invoice($post); |
|
| 111 | 111 | |
| 112 | 112 | // Resend invoice. |
| 113 | - if ( ! $invoice->is_draft() ) { |
|
| 113 | + if (!$invoice->is_draft()) { |
|
| 114 | 114 | |
| 115 | 115 | add_meta_box( |
| 116 | 116 | 'wpinv-mb-resend-invoice', |
| 117 | 117 | sprintf( |
| 118 | - __( 'Resend %s', 'invoicing' ), |
|
| 119 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
| 118 | + __('Resend %s', 'invoicing'), |
|
| 119 | + ucfirst($invoice->get_invoice_quote_type()) |
|
| 120 | 120 | ), |
| 121 | 121 | 'GetPaid_Meta_Box_Resend_Invoice::output', |
| 122 | 122 | $post_type, |
@@ -127,17 +127,17 @@ discard block |
||
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | // Subscriptions. |
| 130 | - $subscriptions = getpaid_get_invoice_subscriptions( $invoice ); |
|
| 131 | - if ( ! empty( $subscriptions ) ) { |
|
| 130 | + $subscriptions = getpaid_get_invoice_subscriptions($invoice); |
|
| 131 | + if (!empty($subscriptions)) { |
|
| 132 | 132 | |
| 133 | - if ( is_array( $subscriptions ) ) { |
|
| 134 | - add_meta_box( 'wpinv-mb-subscriptions', __( 'Related Subscriptions', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output_related', $post_type, 'advanced' ); |
|
| 133 | + if (is_array($subscriptions)) { |
|
| 134 | + add_meta_box('wpinv-mb-subscriptions', __('Related Subscriptions', 'invoicing'), 'GetPaid_Meta_Box_Invoice_Subscription::output_related', $post_type, 'advanced'); |
|
| 135 | 135 | } else { |
| 136 | - add_meta_box( 'wpinv-mb-subscriptions', __( 'Subscription Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output', $post_type, 'advanced' ); |
|
| 136 | + add_meta_box('wpinv-mb-subscriptions', __('Subscription Details', 'invoicing'), 'GetPaid_Meta_Box_Invoice_Subscription::output', $post_type, 'advanced'); |
|
| 137 | 137 | } |
| 138 | 138 | |
| 139 | - if ( getpaid_count_subscription_invoices( $invoice->is_renewal() ? $invoice->get_parent_id() : $invoice->get_id() ) > 1 ) { |
|
| 140 | - add_meta_box( 'wpinv-mb-subscription-invoices', __( 'Related Payments', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output_invoices', $post_type, 'advanced' ); |
|
| 139 | + if (getpaid_count_subscription_invoices($invoice->is_renewal() ? $invoice->get_parent_id() : $invoice->get_id()) > 1) { |
|
| 140 | + add_meta_box('wpinv-mb-subscription-invoices', __('Related Payments', 'invoicing'), 'GetPaid_Meta_Box_Invoice_Subscription::output_invoices', $post_type, 'advanced'); |
|
| 141 | 141 | } |
| 142 | 142 | |
| 143 | 143 | } |
@@ -146,8 +146,8 @@ discard block |
||
| 146 | 146 | add_meta_box( |
| 147 | 147 | 'wpinv-details', |
| 148 | 148 | sprintf( |
| 149 | - __( '%s Details', 'invoicing' ), |
|
| 150 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
| 149 | + __('%s Details', 'invoicing'), |
|
| 150 | + ucfirst($invoice->get_invoice_quote_type()) |
|
| 151 | 151 | ), |
| 152 | 152 | 'GetPaid_Meta_Box_Invoice_Details::output', |
| 153 | 153 | $post_type, |
@@ -155,17 +155,17 @@ discard block |
||
| 155 | 155 | ); |
| 156 | 156 | |
| 157 | 157 | // Payment details. |
| 158 | - add_meta_box( 'wpinv-payment-meta', __( 'Payment Meta', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Payment_Meta::output', $post_type, 'side', 'default' ); |
|
| 158 | + add_meta_box('wpinv-payment-meta', __('Payment Meta', 'invoicing'), 'GetPaid_Meta_Box_Invoice_Payment_Meta::output', $post_type, 'side', 'default'); |
|
| 159 | 159 | |
| 160 | 160 | // Billing details. |
| 161 | - add_meta_box( 'wpinv-address', __( 'Billing Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Address::output', $post_type, 'normal', 'high' ); |
|
| 161 | + add_meta_box('wpinv-address', __('Billing Details', 'invoicing'), 'GetPaid_Meta_Box_Invoice_Address::output', $post_type, 'normal', 'high'); |
|
| 162 | 162 | |
| 163 | 163 | // Invoice items. |
| 164 | 164 | add_meta_box( |
| 165 | 165 | 'wpinv-items', |
| 166 | 166 | sprintf( |
| 167 | - __( '%s Items', 'invoicing' ), |
|
| 168 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
| 167 | + __('%s Items', 'invoicing'), |
|
| 168 | + ucfirst($invoice->get_invoice_quote_type()) |
|
| 169 | 169 | ), |
| 170 | 170 | 'GetPaid_Meta_Box_Invoice_Items::output', |
| 171 | 171 | $post_type, |
@@ -177,8 +177,8 @@ discard block |
||
| 177 | 177 | add_meta_box( |
| 178 | 178 | 'wpinv-notes', |
| 179 | 179 | sprintf( |
| 180 | - __( '%s Notes', 'invoicing' ), |
|
| 181 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
| 180 | + __('%s Notes', 'invoicing'), |
|
| 181 | + ucfirst($invoice->get_invoice_quote_type()) |
|
| 182 | 182 | ), |
| 183 | 183 | 'WPInv_Meta_Box_Notes::output', |
| 184 | 184 | $post_type, |
@@ -187,13 +187,13 @@ discard block |
||
| 187 | 187 | ); |
| 188 | 188 | |
| 189 | 189 | // Shipping Address. |
| 190 | - if ( get_post_meta( $invoice->get_id(), 'shipping_address', true ) ) { |
|
| 191 | - add_meta_box( 'wpinv-invoice-shipping-details', __( 'Shipping Address', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Shipping_Address::output', $post_type, 'side', 'high' ); |
|
| 190 | + if (get_post_meta($invoice->get_id(), 'shipping_address', true)) { |
|
| 191 | + add_meta_box('wpinv-invoice-shipping-details', __('Shipping Address', 'invoicing'), 'GetPaid_Meta_Box_Invoice_Shipping_Address::output', $post_type, 'side', 'high'); |
|
| 192 | 192 | } |
| 193 | 193 | |
| 194 | 194 | // Payment form information. |
| 195 | - if ( get_post_meta( $invoice->get_id(), 'payment_form_data', true ) ) { |
|
| 196 | - add_meta_box( 'wpinv-invoice-payment-form-details', __( 'Payment Form Details', 'invoicing' ), 'WPInv_Meta_Box_Payment_Form::output_details', $post_type, 'side', 'high' ); |
|
| 195 | + if (get_post_meta($invoice->get_id(), 'payment_form_data', true)) { |
|
| 196 | + add_meta_box('wpinv-invoice-payment-form-details', __('Payment Form Details', 'invoicing'), 'WPInv_Meta_Box_Payment_Form::output_details', $post_type, 'side', 'high'); |
|
| 197 | 197 | } |
| 198 | 198 | |
| 199 | 199 | } |
@@ -204,7 +204,7 @@ discard block |
||
| 204 | 204 | * Remove some metaboxes. |
| 205 | 205 | */ |
| 206 | 206 | public static function remove_meta_boxes() { |
| 207 | - remove_meta_box( 'wpseo_meta', 'wpi_invoice', 'normal' ); |
|
| 207 | + remove_meta_box('wpseo_meta', 'wpi_invoice', 'normal'); |
|
| 208 | 208 | } |
| 209 | 209 | |
| 210 | 210 | /** |
@@ -220,46 +220,46 @@ discard block |
||
| 220 | 220 | * @param int $post_id Post ID. |
| 221 | 221 | * @param object $post Post object. |
| 222 | 222 | */ |
| 223 | - public static function save_meta_boxes( $post_id, $post ) { |
|
| 224 | - $post_id = absint( $post_id ); |
|
| 225 | - $data = wp_kses_post_deep( wp_unslash( $_POST ) ); |
|
| 223 | + public static function save_meta_boxes($post_id, $post) { |
|
| 224 | + $post_id = absint($post_id); |
|
| 225 | + $data = wp_kses_post_deep(wp_unslash($_POST)); |
|
| 226 | 226 | |
| 227 | 227 | // Do not save for ajax requests. |
| 228 | - if ( ( defined( 'DOING_AJAX') && DOING_AJAX ) || isset( $_REQUEST['bulk_edit'] ) ) { |
|
| 228 | + if ((defined('DOING_AJAX') && DOING_AJAX) || isset($_REQUEST['bulk_edit'])) { |
|
| 229 | 229 | return; |
| 230 | 230 | } |
| 231 | 231 | |
| 232 | 232 | // $post_id and $post are required |
| 233 | - if ( empty( $post_id ) || empty( $post ) || self::$saved_meta_boxes ) { |
|
| 233 | + if (empty($post_id) || empty($post) || self::$saved_meta_boxes) { |
|
| 234 | 234 | return; |
| 235 | 235 | } |
| 236 | 236 | |
| 237 | 237 | // Dont' save meta boxes for revisions or autosaves. |
| 238 | - if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || is_int( wp_is_post_revision( $post ) ) || is_int( wp_is_post_autosave( $post ) ) ) { |
|
| 238 | + if ((defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) || is_int(wp_is_post_revision($post)) || is_int(wp_is_post_autosave($post))) { |
|
| 239 | 239 | return; |
| 240 | 240 | } |
| 241 | 241 | |
| 242 | 242 | // Check the nonce. |
| 243 | - if ( empty( $data['getpaid_meta_nonce'] ) || ! wp_verify_nonce( $data['getpaid_meta_nonce'], 'getpaid_meta_nonce' ) ) { |
|
| 243 | + if (empty($data['getpaid_meta_nonce']) || !wp_verify_nonce($data['getpaid_meta_nonce'], 'getpaid_meta_nonce')) { |
|
| 244 | 244 | return; |
| 245 | 245 | } |
| 246 | 246 | |
| 247 | 247 | // Check the post being saved == the $post_id to prevent triggering this call for other save_post events. |
| 248 | - if ( empty( $data['post_ID'] ) || absint( $data['post_ID'] ) !== $post_id ) { |
|
| 248 | + if (empty($data['post_ID']) || absint($data['post_ID']) !== $post_id) { |
|
| 249 | 249 | return; |
| 250 | 250 | } |
| 251 | 251 | |
| 252 | 252 | // Check user has permission to edit. |
| 253 | - if ( ! current_user_can( 'edit_post', $post_id ) ) { |
|
| 253 | + if (!current_user_can('edit_post', $post_id)) { |
|
| 254 | 254 | return; |
| 255 | 255 | } |
| 256 | 256 | |
| 257 | - if ( getpaid_is_invoice_post_type( $post->post_type ) ) { |
|
| 257 | + if (getpaid_is_invoice_post_type($post->post_type)) { |
|
| 258 | 258 | |
| 259 | 259 | // We need this save event to run once to avoid potential endless loops. |
| 260 | 260 | self::$saved_meta_boxes = true; |
| 261 | 261 | |
| 262 | - return GetPaid_Meta_Box_Invoice_Address::save( $post_id ); |
|
| 262 | + return GetPaid_Meta_Box_Invoice_Address::save($post_id); |
|
| 263 | 263 | |
| 264 | 264 | } |
| 265 | 265 | |
@@ -271,7 +271,7 @@ discard block |
||
| 271 | 271 | ); |
| 272 | 272 | |
| 273 | 273 | // Is this our post type? |
| 274 | - if ( ! isset( $post_types_map[ $post->post_type ] ) ) { |
|
| 274 | + if (!isset($post_types_map[$post->post_type])) { |
|
| 275 | 275 | return; |
| 276 | 276 | } |
| 277 | 277 | |
@@ -279,8 +279,8 @@ discard block |
||
| 279 | 279 | self::$saved_meta_boxes = true; |
| 280 | 280 | |
| 281 | 281 | // Save the post. |
| 282 | - $class = $post_types_map[ $post->post_type ]; |
|
| 283 | - $class::save( $post_id, $_POST, $post ); |
|
| 282 | + $class = $post_types_map[$post->post_type]; |
|
| 283 | + $class::save($post_id, $_POST, $post); |
|
| 284 | 284 | |
| 285 | 285 | } |
| 286 | 286 | |
@@ -9,41 +9,41 @@ discard block |
||
| 9 | 9 | * @version 1.0.19 |
| 10 | 10 | */ |
| 11 | 11 | |
| 12 | -defined( 'ABSPATH' ) || exit; |
|
| 12 | +defined('ABSPATH') || exit; |
|
| 13 | 13 | |
| 14 | 14 | return array( |
| 15 | 15 | |
| 16 | 16 | array( |
| 17 | 17 | 'type' => 'heading', |
| 18 | - 'name' => __( 'Heading', 'invoicing' ), |
|
| 18 | + 'name' => __('Heading', 'invoicing'), |
|
| 19 | 19 | 'defaults' => array( |
| 20 | 20 | 'level' => 'h2', |
| 21 | - 'text' => __( 'Heading', 'invoicing' ), |
|
| 21 | + 'text' => __('Heading', 'invoicing'), |
|
| 22 | 22 | ) |
| 23 | 23 | ), |
| 24 | 24 | |
| 25 | 25 | array( |
| 26 | 26 | 'type' => 'paragraph', |
| 27 | - 'name' => __( 'Paragraph', 'invoicing' ), |
|
| 27 | + 'name' => __('Paragraph', 'invoicing'), |
|
| 28 | 28 | 'defaults' => array( |
| 29 | - 'text' => __( 'Paragraph text', 'invoicing' ), |
|
| 29 | + 'text' => __('Paragraph text', 'invoicing'), |
|
| 30 | 30 | ) |
| 31 | 31 | ), |
| 32 | 32 | |
| 33 | 33 | array( |
| 34 | 34 | 'type' => 'alert', |
| 35 | - 'name' => __( 'Alert', 'invoicing' ), |
|
| 35 | + 'name' => __('Alert', 'invoicing'), |
|
| 36 | 36 | 'defaults' => array( |
| 37 | 37 | 'value' => '', |
| 38 | 38 | 'class' => 'alert-warning', |
| 39 | - 'text' => __( 'Alert', 'invoicing' ), |
|
| 39 | + 'text' => __('Alert', 'invoicing'), |
|
| 40 | 40 | 'dismissible' => false, |
| 41 | 41 | ) |
| 42 | 42 | ), |
| 43 | 43 | |
| 44 | 44 | array( |
| 45 | 45 | 'type' => 'separator', |
| 46 | - 'name' => __( 'Separator', 'invoicing' ), |
|
| 46 | + 'name' => __('Separator', 'invoicing'), |
|
| 47 | 47 | 'defaults' => array( |
| 48 | 48 | 'value' => '', |
| 49 | 49 | ), |
@@ -51,11 +51,11 @@ discard block |
||
| 51 | 51 | |
| 52 | 52 | array( |
| 53 | 53 | 'type' => 'text', |
| 54 | - 'name' => __( 'Text Input', 'invoicing' ), |
|
| 54 | + 'name' => __('Text Input', 'invoicing'), |
|
| 55 | 55 | 'defaults' => array( |
| 56 | - 'placeholder' => __( 'Enter some text', 'invoicing' ), |
|
| 56 | + 'placeholder' => __('Enter some text', 'invoicing'), |
|
| 57 | 57 | 'value' => '', |
| 58 | - 'label' => __( 'Field Label', 'invoicing' ), |
|
| 58 | + 'label' => __('Field Label', 'invoicing'), |
|
| 59 | 59 | 'description' => '', |
| 60 | 60 | 'required' => false, |
| 61 | 61 | ) |
@@ -63,11 +63,11 @@ discard block |
||
| 63 | 63 | |
| 64 | 64 | array( |
| 65 | 65 | 'type' => 'textarea', |
| 66 | - 'name' => __( 'Textarea', 'invoicing' ), |
|
| 66 | + 'name' => __('Textarea', 'invoicing'), |
|
| 67 | 67 | 'defaults' => array( |
| 68 | - 'placeholder' => __( 'Enter your text here', 'invoicing' ), |
|
| 68 | + 'placeholder' => __('Enter your text here', 'invoicing'), |
|
| 69 | 69 | 'value' => '', |
| 70 | - 'label' => __( 'Textarea Label', 'invoicing' ), |
|
| 70 | + 'label' => __('Textarea Label', 'invoicing'), |
|
| 71 | 71 | 'description' => '', |
| 72 | 72 | 'required' => false, |
| 73 | 73 | ) |
@@ -75,27 +75,27 @@ discard block |
||
| 75 | 75 | |
| 76 | 76 | array( |
| 77 | 77 | 'type' => 'select', |
| 78 | - 'name' => __( 'Dropdown', 'invoicing' ), |
|
| 78 | + 'name' => __('Dropdown', 'invoicing'), |
|
| 79 | 79 | 'defaults' => array( |
| 80 | - 'placeholder' => __( 'Select a value', 'invoicing' ), |
|
| 80 | + 'placeholder' => __('Select a value', 'invoicing'), |
|
| 81 | 81 | 'value' => '', |
| 82 | - 'label' => __( 'Dropdown Label', 'invoicing' ), |
|
| 82 | + 'label' => __('Dropdown Label', 'invoicing'), |
|
| 83 | 83 | 'description' => '', |
| 84 | 84 | 'required' => false, |
| 85 | 85 | 'options' => array( |
| 86 | - esc_attr__( 'Option One', 'invoicing' ), |
|
| 87 | - esc_attr__( 'Option Two', 'invoicing' ), |
|
| 88 | - esc_attr__( 'Option Three', 'invoicing' ) |
|
| 86 | + esc_attr__('Option One', 'invoicing'), |
|
| 87 | + esc_attr__('Option Two', 'invoicing'), |
|
| 88 | + esc_attr__('Option Three', 'invoicing') |
|
| 89 | 89 | ), |
| 90 | 90 | ) |
| 91 | 91 | ), |
| 92 | 92 | |
| 93 | 93 | array( |
| 94 | 94 | 'type' => 'checkbox', |
| 95 | - 'name' => __( 'Checkbox', 'invoicing' ), |
|
| 95 | + 'name' => __('Checkbox', 'invoicing'), |
|
| 96 | 96 | 'defaults' => array( |
| 97 | 97 | 'value' => '', |
| 98 | - 'label' => __( 'Checkbox Label', 'invoicing' ), |
|
| 98 | + 'label' => __('Checkbox Label', 'invoicing'), |
|
| 99 | 99 | 'description' => '', |
| 100 | 100 | 'required' => false, |
| 101 | 101 | ) |
@@ -103,23 +103,23 @@ discard block |
||
| 103 | 103 | |
| 104 | 104 | array( |
| 105 | 105 | 'type' => 'radio', |
| 106 | - 'name' => __( 'Radio', 'invoicing' ), |
|
| 106 | + 'name' => __('Radio', 'invoicing'), |
|
| 107 | 107 | 'defaults' => array( |
| 108 | - 'label' => __( 'Select one choice', 'invoicing' ), |
|
| 108 | + 'label' => __('Select one choice', 'invoicing'), |
|
| 109 | 109 | 'options' => array( |
| 110 | - esc_attr__( 'Choice One', 'invoicing' ), |
|
| 111 | - esc_attr__( 'Choice Two', 'invoicing' ), |
|
| 112 | - esc_attr__( 'Choice Three', 'invoicing' ) |
|
| 110 | + esc_attr__('Choice One', 'invoicing'), |
|
| 111 | + esc_attr__('Choice Two', 'invoicing'), |
|
| 112 | + esc_attr__('Choice Three', 'invoicing') |
|
| 113 | 113 | ), |
| 114 | 114 | ) |
| 115 | 115 | ), |
| 116 | 116 | |
| 117 | 117 | array( |
| 118 | 118 | 'type' => 'date', |
| 119 | - 'name' => __( 'Date', 'invoicing' ), |
|
| 119 | + 'name' => __('Date', 'invoicing'), |
|
| 120 | 120 | 'defaults' => array( |
| 121 | 121 | 'value' => '', |
| 122 | - 'label' => __( 'Date', 'invoicing' ), |
|
| 122 | + 'label' => __('Date', 'invoicing'), |
|
| 123 | 123 | 'description' => '', |
| 124 | 124 | 'single' => 'single', |
| 125 | 125 | 'required' => false, |
@@ -128,10 +128,10 @@ discard block |
||
| 128 | 128 | |
| 129 | 129 | array( |
| 130 | 130 | 'type' => 'time', |
| 131 | - 'name' => __( 'Time', 'invoicing' ), |
|
| 131 | + 'name' => __('Time', 'invoicing'), |
|
| 132 | 132 | 'defaults' => array( |
| 133 | 133 | 'value' => '', |
| 134 | - 'label' => __( 'Time', 'invoicing' ), |
|
| 134 | + 'label' => __('Time', 'invoicing'), |
|
| 135 | 135 | 'description' => '', |
| 136 | 136 | 'required' => false, |
| 137 | 137 | ) |
@@ -139,11 +139,11 @@ discard block |
||
| 139 | 139 | |
| 140 | 140 | array( |
| 141 | 141 | 'type' => 'number', |
| 142 | - 'name' => __( 'Number', 'invoicing' ), |
|
| 142 | + 'name' => __('Number', 'invoicing'), |
|
| 143 | 143 | 'defaults' => array( |
| 144 | 144 | 'placeholder' => '', |
| 145 | 145 | 'value' => '', |
| 146 | - 'label' => __( 'Number', 'invoicing' ), |
|
| 146 | + 'label' => __('Number', 'invoicing'), |
|
| 147 | 147 | 'description' => '', |
| 148 | 148 | 'required' => false, |
| 149 | 149 | ) |
@@ -151,11 +151,11 @@ discard block |
||
| 151 | 151 | |
| 152 | 152 | array( |
| 153 | 153 | 'type' => 'website', |
| 154 | - 'name' => __( 'Website', 'invoicing' ), |
|
| 154 | + 'name' => __('Website', 'invoicing'), |
|
| 155 | 155 | 'defaults' => array( |
| 156 | 156 | 'placeholder' => 'http://example.com', |
| 157 | 157 | 'value' => '', |
| 158 | - 'label' => __( 'Website', 'invoicing' ), |
|
| 158 | + 'label' => __('Website', 'invoicing'), |
|
| 159 | 159 | 'description' => '', |
| 160 | 160 | 'required' => false, |
| 161 | 161 | ) |
@@ -163,11 +163,11 @@ discard block |
||
| 163 | 163 | |
| 164 | 164 | array( |
| 165 | 165 | 'type' => 'email', |
| 166 | - 'name' => __( 'Email', 'invoicing' ), |
|
| 166 | + 'name' => __('Email', 'invoicing'), |
|
| 167 | 167 | 'defaults' => array( |
| 168 | 168 | 'placeholder' => '[email protected]', |
| 169 | 169 | 'value' => '', |
| 170 | - 'label' => __( 'Email Address', 'invoicing' ), |
|
| 170 | + 'label' => __('Email Address', 'invoicing'), |
|
| 171 | 171 | 'description' => '', |
| 172 | 172 | 'required' => false, |
| 173 | 173 | ) |
@@ -175,31 +175,31 @@ discard block |
||
| 175 | 175 | |
| 176 | 176 | array( |
| 177 | 177 | 'type' => 'file_upload', |
| 178 | - 'name' => __( 'File Upload', 'invoicing' ), |
|
| 178 | + 'name' => __('File Upload', 'invoicing'), |
|
| 179 | 179 | 'defaults' => array( |
| 180 | 180 | 'value' => '', |
| 181 | - 'label' => __( 'Upload File', 'invoicing' ), |
|
| 181 | + 'label' => __('Upload File', 'invoicing'), |
|
| 182 | 182 | 'description' => '', |
| 183 | 183 | 'required' => false, |
| 184 | 184 | 'max_file_num' => 1, |
| 185 | - 'file_types' => array( 'jpg|jpeg|jpe', 'gif', 'png' ), |
|
| 185 | + 'file_types' => array('jpg|jpeg|jpe', 'gif', 'png'), |
|
| 186 | 186 | ) |
| 187 | 187 | ), |
| 188 | 188 | |
| 189 | 189 | array( |
| 190 | 190 | 'type' => 'address', |
| 191 | - 'name' => __( 'Address', 'invoicing' ), |
|
| 191 | + 'name' => __('Address', 'invoicing'), |
|
| 192 | 192 | 'defaults' => array( |
| 193 | 193 | |
| 194 | 194 | 'address_type' => 'billing', |
| 195 | - 'billing_address_title' => __( 'Billing Address', 'invoicing' ), |
|
| 196 | - 'shipping_address_title' => __( 'Shipping Address', 'invoicing' ), |
|
| 197 | - 'shipping_address_toggle' => __( 'Same billing & shipping address.', 'invoicing' ), |
|
| 195 | + 'billing_address_title' => __('Billing Address', 'invoicing'), |
|
| 196 | + 'shipping_address_title' => __('Shipping Address', 'invoicing'), |
|
| 197 | + 'shipping_address_toggle' => __('Same billing & shipping address.', 'invoicing'), |
|
| 198 | 198 | 'fields' => array( |
| 199 | 199 | array( |
| 200 | 200 | 'placeholder' => 'Jon', |
| 201 | 201 | 'value' => '', |
| 202 | - 'label' => __( 'First Name', 'invoicing' ), |
|
| 202 | + 'label' => __('First Name', 'invoicing'), |
|
| 203 | 203 | 'description' => '', |
| 204 | 204 | 'required' => false, |
| 205 | 205 | 'visible' => true, |
@@ -210,7 +210,7 @@ discard block |
||
| 210 | 210 | array( |
| 211 | 211 | 'placeholder' => 'Snow', |
| 212 | 212 | 'value' => '', |
| 213 | - 'label' => __( 'Last Name', 'invoicing' ), |
|
| 213 | + 'label' => __('Last Name', 'invoicing'), |
|
| 214 | 214 | 'description' => '', |
| 215 | 215 | 'required' => false, |
| 216 | 216 | 'visible' => true, |
@@ -221,7 +221,7 @@ discard block |
||
| 221 | 221 | array( |
| 222 | 222 | 'placeholder' => '', |
| 223 | 223 | 'value' => '', |
| 224 | - 'label' => __( 'Address', 'invoicing' ), |
|
| 224 | + 'label' => __('Address', 'invoicing'), |
|
| 225 | 225 | 'description' => '', |
| 226 | 226 | 'required' => false, |
| 227 | 227 | 'visible' => true, |
@@ -232,7 +232,7 @@ discard block |
||
| 232 | 232 | array( |
| 233 | 233 | 'placeholder' => '', |
| 234 | 234 | 'value' => '', |
| 235 | - 'label' => __( 'City', 'invoicing' ), |
|
| 235 | + 'label' => __('City', 'invoicing'), |
|
| 236 | 236 | 'description' => '', |
| 237 | 237 | 'required' => false, |
| 238 | 238 | 'visible' => true, |
@@ -241,9 +241,9 @@ discard block |
||
| 241 | 241 | ), |
| 242 | 242 | |
| 243 | 243 | array( |
| 244 | - 'placeholder' => __( 'Select your country' ), |
|
| 244 | + 'placeholder' => __('Select your country'), |
|
| 245 | 245 | 'value' => '', |
| 246 | - 'label' => __( 'Country', 'invoicing' ), |
|
| 246 | + 'label' => __('Country', 'invoicing'), |
|
| 247 | 247 | 'description' => '', |
| 248 | 248 | 'required' => false, |
| 249 | 249 | 'visible' => true, |
@@ -252,9 +252,9 @@ discard block |
||
| 252 | 252 | ), |
| 253 | 253 | |
| 254 | 254 | array( |
| 255 | - 'placeholder' => __( 'Choose a state', 'invoicing' ), |
|
| 255 | + 'placeholder' => __('Choose a state', 'invoicing'), |
|
| 256 | 256 | 'value' => '', |
| 257 | - 'label' => __( 'State / Province', 'invoicing' ), |
|
| 257 | + 'label' => __('State / Province', 'invoicing'), |
|
| 258 | 258 | 'description' => '', |
| 259 | 259 | 'required' => false, |
| 260 | 260 | 'visible' => true, |
@@ -265,7 +265,7 @@ discard block |
||
| 265 | 265 | array( |
| 266 | 266 | 'placeholder' => '', |
| 267 | 267 | 'value' => '', |
| 268 | - 'label' => __( 'ZIP / Postcode', 'invoicing' ), |
|
| 268 | + 'label' => __('ZIP / Postcode', 'invoicing'), |
|
| 269 | 269 | 'description' => '', |
| 270 | 270 | 'required' => false, |
| 271 | 271 | 'visible' => true, |
@@ -276,7 +276,7 @@ discard block |
||
| 276 | 276 | array( |
| 277 | 277 | 'placeholder' => '', |
| 278 | 278 | 'value' => '', |
| 279 | - 'label' => __( 'Phone', 'invoicing' ), |
|
| 279 | + 'label' => __('Phone', 'invoicing'), |
|
| 280 | 280 | 'description' => '', |
| 281 | 281 | 'required' => false, |
| 282 | 282 | 'visible' => true, |
@@ -287,7 +287,7 @@ discard block |
||
| 287 | 287 | array( |
| 288 | 288 | 'placeholder' => '', |
| 289 | 289 | 'value' => '', |
| 290 | - 'label' => __( 'Company', 'invoicing' ), |
|
| 290 | + 'label' => __('Company', 'invoicing'), |
|
| 291 | 291 | 'description' => '', |
| 292 | 292 | 'required' => false, |
| 293 | 293 | 'visible' => false, |
@@ -298,7 +298,7 @@ discard block |
||
| 298 | 298 | array( |
| 299 | 299 | 'placeholder' => '', |
| 300 | 300 | 'value' => '', |
| 301 | - 'label' => __( 'Company ID', 'invoicing' ), |
|
| 301 | + 'label' => __('Company ID', 'invoicing'), |
|
| 302 | 302 | 'description' => '', |
| 303 | 303 | 'required' => false, |
| 304 | 304 | 'visible' => false, |
@@ -309,7 +309,7 @@ discard block |
||
| 309 | 309 | array( |
| 310 | 310 | 'placeholder' => '', |
| 311 | 311 | 'value' => '', |
| 312 | - 'label' => __( 'VAT Number', 'invoicing' ), |
|
| 312 | + 'label' => __('VAT Number', 'invoicing'), |
|
| 313 | 313 | 'description' => '', |
| 314 | 314 | 'required' => false, |
| 315 | 315 | 'visible' => false, |
@@ -322,11 +322,11 @@ discard block |
||
| 322 | 322 | |
| 323 | 323 | array( |
| 324 | 324 | 'type' => 'billing_email', |
| 325 | - 'name' => __( 'Billing Email', 'invoicing' ), |
|
| 325 | + 'name' => __('Billing Email', 'invoicing'), |
|
| 326 | 326 | 'defaults' => array( |
| 327 | 327 | 'placeholder' => '[email protected]', |
| 328 | 328 | 'value' => '', |
| 329 | - 'label' => __( 'Billing Email', 'invoicing' ), |
|
| 329 | + 'label' => __('Billing Email', 'invoicing'), |
|
| 330 | 330 | 'description' => '', |
| 331 | 331 | 'premade' => true, |
| 332 | 332 | ) |
@@ -334,18 +334,18 @@ discard block |
||
| 334 | 334 | |
| 335 | 335 | array( |
| 336 | 336 | 'type' => 'discount', |
| 337 | - 'name' => __( 'Discount Input', 'invoicing' ), |
|
| 337 | + 'name' => __('Discount Input', 'invoicing'), |
|
| 338 | 338 | 'defaults' => array( |
| 339 | 339 | 'value' => '', |
| 340 | - 'input_label' => __( 'Coupon Code', 'invoicing' ), |
|
| 341 | - 'button_label' => __( 'Apply Coupon', 'invoicing' ), |
|
| 342 | - 'description' => __( 'Have a discount code? Enter it above.', 'invoicing' ), |
|
| 340 | + 'input_label' => __('Coupon Code', 'invoicing'), |
|
| 341 | + 'button_label' => __('Apply Coupon', 'invoicing'), |
|
| 342 | + 'description' => __('Have a discount code? Enter it above.', 'invoicing'), |
|
| 343 | 343 | ) |
| 344 | 344 | ), |
| 345 | 345 | |
| 346 | 346 | array( |
| 347 | 347 | 'type' => 'items', |
| 348 | - 'name' => __( 'Items', 'invoicing' ), |
|
| 348 | + 'name' => __('Items', 'invoicing'), |
|
| 349 | 349 | 'defaults' => array( |
| 350 | 350 | 'value' => '', |
| 351 | 351 | 'items_type' => 'total', |
@@ -357,22 +357,22 @@ discard block |
||
| 357 | 357 | |
| 358 | 358 | array( |
| 359 | 359 | 'type' => 'price_input', |
| 360 | - 'name' => __( 'Price Input', 'invoicing' ), |
|
| 360 | + 'name' => __('Price Input', 'invoicing'), |
|
| 361 | 361 | 'defaults' => array( |
| 362 | 362 | 'placeholder' => wpinv_format_amount(0), |
| 363 | 363 | 'value' => wpinv_format_amount(0), |
| 364 | 364 | 'minimum' => wpinv_format_amount(0), |
| 365 | - 'label' => __( 'Enter Amount', 'invoicing' ), |
|
| 365 | + 'label' => __('Enter Amount', 'invoicing'), |
|
| 366 | 366 | 'description' => '', |
| 367 | 367 | ) |
| 368 | 368 | ), |
| 369 | 369 | |
| 370 | 370 | array( |
| 371 | 371 | 'type' => 'price_select', |
| 372 | - 'name' => __( 'Price Select', 'invoicing' ), |
|
| 372 | + 'name' => __('Price Select', 'invoicing'), |
|
| 373 | 373 | 'defaults' => array( |
| 374 | 374 | 'description' => '', |
| 375 | - 'label' => __( 'Select Amount', 'invoicing' ), |
|
| 375 | + 'label' => __('Select Amount', 'invoicing'), |
|
| 376 | 376 | 'options' => 'Option 1|10, Option 2|20', |
| 377 | 377 | 'placeholder' => '', |
| 378 | 378 | 'select_type' => 'select', |
@@ -381,39 +381,39 @@ discard block |
||
| 381 | 381 | |
| 382 | 382 | array( |
| 383 | 383 | 'type' => 'pay_button', |
| 384 | - 'name' => __( 'Payment Button', 'invoicing' ), |
|
| 384 | + 'name' => __('Payment Button', 'invoicing'), |
|
| 385 | 385 | 'defaults' => array( |
| 386 | 386 | 'value' => '', |
| 387 | 387 | 'class' => 'btn-primary', |
| 388 | - 'label' => __( 'Pay %price% »', 'invoicing' ), |
|
| 389 | - 'free' => __( 'Continue »', 'invoicing' ), |
|
| 390 | - 'description' => __( 'By continuing with our payment, you are agreeing to our privacy policy and terms of service.', 'invoicing' ), |
|
| 388 | + 'label' => __('Pay %price% »', 'invoicing'), |
|
| 389 | + 'free' => __('Continue »', 'invoicing'), |
|
| 390 | + 'description' => __('By continuing with our payment, you are agreeing to our privacy policy and terms of service.', 'invoicing'), |
|
| 391 | 391 | 'premade' => true, |
| 392 | 392 | ) |
| 393 | 393 | ), |
| 394 | 394 | |
| 395 | 395 | array( |
| 396 | 396 | 'type' => 'gateway_select', |
| 397 | - 'name' => __( 'Gateway Select', 'invoicing' ), |
|
| 397 | + 'name' => __('Gateway Select', 'invoicing'), |
|
| 398 | 398 | 'defaults' => array( |
| 399 | - 'text' => __( 'Select Payment Method', 'invoicing' ), |
|
| 399 | + 'text' => __('Select Payment Method', 'invoicing'), |
|
| 400 | 400 | 'premade' => true, |
| 401 | 401 | ) |
| 402 | 402 | ), |
| 403 | 403 | |
| 404 | 404 | array( |
| 405 | 405 | 'type' => 'total_payable', |
| 406 | - 'name' => __( 'Total Payable', 'invoicing' ), |
|
| 406 | + 'name' => __('Total Payable', 'invoicing'), |
|
| 407 | 407 | 'defaults' => array( |
| 408 | - 'text' => __( 'Total to pay:', 'invoicing' ), |
|
| 408 | + 'text' => __('Total to pay:', 'invoicing'), |
|
| 409 | 409 | ) |
| 410 | 410 | ), |
| 411 | 411 | |
| 412 | 412 | array( |
| 413 | 413 | 'type' => 'ip_address', |
| 414 | - 'name' => __( 'IP Address', 'invoicing' ), |
|
| 414 | + 'name' => __('IP Address', 'invoicing'), |
|
| 415 | 415 | 'defaults' => array( |
| 416 | - 'text' => __( 'Your IP address is:', 'invoicing' ), |
|
| 416 | + 'text' => __('Your IP address is:', 'invoicing'), |
|
| 417 | 417 | ) |
| 418 | 418 | ) |
| 419 | 419 | ); |
@@ -12,58 +12,58 @@ |
||
| 12 | 12 | $label = empty( $label ) ? '' : wp_kses_post( $label ); |
| 13 | 13 | $label_class = sanitize_key( preg_replace( '/[^A-Za-z0-9_-]/', '-', $label ) ); |
| 14 | 14 | if ( ! empty( $required ) ) { |
| 15 | - $label .= "<span class='text-danger'> *</span>"; |
|
| 15 | + $label .= "<span class='text-danger'> *</span>"; |
|
| 16 | 16 | } |
| 17 | 17 | |
| 18 | 18 | $disable_dates = array(); |
| 19 | 19 | |
| 20 | 20 | if ( ! empty( $disabled_dates ) ) { |
| 21 | - $disabled_dates = preg_replace( '/\s+/', '', $disabled_dates ); |
|
| 22 | - $disabled_dates = str_ireplace( 'today', current_time( 'Y-m-d' ), $disabled_dates ); |
|
| 23 | - $disabled_dates = array_filter( explode( ',', $disabled_dates ) ); |
|
| 21 | + $disabled_dates = preg_replace( '/\s+/', '', $disabled_dates ); |
|
| 22 | + $disabled_dates = str_ireplace( 'today', current_time( 'Y-m-d' ), $disabled_dates ); |
|
| 23 | + $disabled_dates = array_filter( explode( ',', $disabled_dates ) ); |
|
| 24 | 24 | |
| 25 | - foreach ( $disabled_dates as $disabled_date ) { |
|
| 25 | + foreach ( $disabled_dates as $disabled_date ) { |
|
| 26 | 26 | |
| 27 | - $disabled_date = trim( $disabled_date ); |
|
| 27 | + $disabled_date = trim( $disabled_date ); |
|
| 28 | 28 | |
| 29 | - if ( false === strpos( $disabled_date, '|' ) ) { |
|
| 30 | - $disable_dates[] = $disabled_date; |
|
| 31 | - continue; |
|
| 32 | - } |
|
| 29 | + if ( false === strpos( $disabled_date, '|' ) ) { |
|
| 30 | + $disable_dates[] = $disabled_date; |
|
| 31 | + continue; |
|
| 32 | + } |
|
| 33 | 33 | |
| 34 | - $disabled_date = explode( '|', $disabled_date ); |
|
| 35 | - $disable_dates[] = array( |
|
| 36 | - 'from' => trim( $disabled_date[0] ), |
|
| 37 | - 'to' => trim( $disabled_date[1] ), |
|
| 38 | - ); |
|
| 34 | + $disabled_date = explode( '|', $disabled_date ); |
|
| 35 | + $disable_dates[] = array( |
|
| 36 | + 'from' => trim( $disabled_date[0] ), |
|
| 37 | + 'to' => trim( $disabled_date[1] ), |
|
| 38 | + ); |
|
| 39 | 39 | |
| 40 | - } |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | 42 | } |
| 43 | 43 | |
| 44 | 44 | $options = array( |
| 45 | - 'data-default-date' => empty( 'default_date' ) ? false : $default_date, |
|
| 46 | - 'data-min-date' => empty( 'min_date' ) ? false : $min_date, |
|
| 47 | - 'data-max-date' => empty( 'max_date' ) ? false : $max_date, |
|
| 48 | - 'data-mode' => empty( 'mode' ) ? 'single' : $mode, |
|
| 49 | - 'data-alt-format' => get_option( 'date_format', 'F j, Y' ), |
|
| 50 | - 'data-date-format' => 'Y-m-d', |
|
| 51 | - 'data-alt-input' => 'true', |
|
| 52 | - 'data-disable_alt' => empty( $disabled_dates ) ? false : wp_json_encode( $disable_dates ), |
|
| 53 | - 'data-disable_days_alt' => empty( $disable_days ) ? false : wp_json_encode( wp_parse_id_list( $disable_days ) ), |
|
| 45 | + 'data-default-date' => empty( 'default_date' ) ? false : $default_date, |
|
| 46 | + 'data-min-date' => empty( 'min_date' ) ? false : $min_date, |
|
| 47 | + 'data-max-date' => empty( 'max_date' ) ? false : $max_date, |
|
| 48 | + 'data-mode' => empty( 'mode' ) ? 'single' : $mode, |
|
| 49 | + 'data-alt-format' => get_option( 'date_format', 'F j, Y' ), |
|
| 50 | + 'data-date-format' => 'Y-m-d', |
|
| 51 | + 'data-alt-input' => 'true', |
|
| 52 | + 'data-disable_alt' => empty( $disabled_dates ) ? false : wp_json_encode( $disable_dates ), |
|
| 53 | + 'data-disable_days_alt' => empty( $disable_days ) ? false : wp_json_encode( wp_parse_id_list( $disable_days ) ), |
|
| 54 | 54 | ); |
| 55 | 55 | |
| 56 | 56 | echo aui()->input( |
| 57 | - array( |
|
| 58 | - 'name' => esc_attr( $id ), |
|
| 59 | - 'id' => esc_attr( $id ) . uniqid( '_' ), |
|
| 60 | - 'placeholder' => empty( $placeholder ) ? '' : esc_attr( $placeholder ), |
|
| 61 | - 'required' => ! empty( $required ), |
|
| 62 | - 'label' => $label, |
|
| 63 | - 'label_type' => 'vertical', |
|
| 64 | - 'help_text' => empty( $description ) ? '' : wp_kses_post( $description ), |
|
| 65 | - 'type' => 'datepicker', |
|
| 66 | - 'class' => $label_class . ' getpaid-init-flatpickr flatpickr-input', |
|
| 67 | - 'extra_attributes' => array_filter( apply_filters( 'getpaid_date_field_attributes', $options ) ), |
|
| 68 | - ) |
|
| 57 | + array( |
|
| 58 | + 'name' => esc_attr( $id ), |
|
| 59 | + 'id' => esc_attr( $id ) . uniqid( '_' ), |
|
| 60 | + 'placeholder' => empty( $placeholder ) ? '' : esc_attr( $placeholder ), |
|
| 61 | + 'required' => ! empty( $required ), |
|
| 62 | + 'label' => $label, |
|
| 63 | + 'label_type' => 'vertical', |
|
| 64 | + 'help_text' => empty( $description ) ? '' : wp_kses_post( $description ), |
|
| 65 | + 'type' => 'datepicker', |
|
| 66 | + 'class' => $label_class . ' getpaid-init-flatpickr flatpickr-input', |
|
| 67 | + 'extra_attributes' => array_filter( apply_filters( 'getpaid_date_field_attributes', $options ) ), |
|
| 68 | + ) |
|
| 69 | 69 | ); |
@@ -7,34 +7,34 @@ discard block |
||
| 7 | 7 | * @version 1.0.19 |
| 8 | 8 | */ |
| 9 | 9 | |
| 10 | -defined( 'ABSPATH' ) || exit; |
|
| 10 | +defined('ABSPATH') || exit; |
|
| 11 | 11 | |
| 12 | -$label = empty( $label ) ? '' : wp_kses_post( $label ); |
|
| 13 | -$label_class = sanitize_key( preg_replace( '/[^A-Za-z0-9_-]/', '-', $label ) ); |
|
| 14 | -if ( ! empty( $required ) ) { |
|
| 12 | +$label = empty($label) ? '' : wp_kses_post($label); |
|
| 13 | +$label_class = sanitize_key(preg_replace('/[^A-Za-z0-9_-]/', '-', $label)); |
|
| 14 | +if (!empty($required)) { |
|
| 15 | 15 | $label .= "<span class='text-danger'> *</span>"; |
| 16 | 16 | } |
| 17 | 17 | |
| 18 | 18 | $disable_dates = array(); |
| 19 | 19 | |
| 20 | -if ( ! empty( $disabled_dates ) ) { |
|
| 21 | - $disabled_dates = preg_replace( '/\s+/', '', $disabled_dates ); |
|
| 22 | - $disabled_dates = str_ireplace( 'today', current_time( 'Y-m-d' ), $disabled_dates ); |
|
| 23 | - $disabled_dates = array_filter( explode( ',', $disabled_dates ) ); |
|
| 20 | +if (!empty($disabled_dates)) { |
|
| 21 | + $disabled_dates = preg_replace('/\s+/', '', $disabled_dates); |
|
| 22 | + $disabled_dates = str_ireplace('today', current_time('Y-m-d'), $disabled_dates); |
|
| 23 | + $disabled_dates = array_filter(explode(',', $disabled_dates)); |
|
| 24 | 24 | |
| 25 | - foreach ( $disabled_dates as $disabled_date ) { |
|
| 25 | + foreach ($disabled_dates as $disabled_date) { |
|
| 26 | 26 | |
| 27 | - $disabled_date = trim( $disabled_date ); |
|
| 27 | + $disabled_date = trim($disabled_date); |
|
| 28 | 28 | |
| 29 | - if ( false === strpos( $disabled_date, '|' ) ) { |
|
| 29 | + if (false === strpos($disabled_date, '|')) { |
|
| 30 | 30 | $disable_dates[] = $disabled_date; |
| 31 | 31 | continue; |
| 32 | 32 | } |
| 33 | 33 | |
| 34 | - $disabled_date = explode( '|', $disabled_date ); |
|
| 34 | + $disabled_date = explode('|', $disabled_date); |
|
| 35 | 35 | $disable_dates[] = array( |
| 36 | - 'from' => trim( $disabled_date[0] ), |
|
| 37 | - 'to' => trim( $disabled_date[1] ), |
|
| 36 | + 'from' => trim($disabled_date[0]), |
|
| 37 | + 'to' => trim($disabled_date[1]), |
|
| 38 | 38 | ); |
| 39 | 39 | |
| 40 | 40 | } |
@@ -42,28 +42,28 @@ discard block |
||
| 42 | 42 | } |
| 43 | 43 | |
| 44 | 44 | $options = array( |
| 45 | - 'data-default-date' => empty( 'default_date' ) ? false : $default_date, |
|
| 46 | - 'data-min-date' => empty( 'min_date' ) ? false : $min_date, |
|
| 47 | - 'data-max-date' => empty( 'max_date' ) ? false : $max_date, |
|
| 48 | - 'data-mode' => empty( 'mode' ) ? 'single' : $mode, |
|
| 49 | - 'data-alt-format' => get_option( 'date_format', 'F j, Y' ), |
|
| 45 | + 'data-default-date' => empty('default_date') ? false : $default_date, |
|
| 46 | + 'data-min-date' => empty('min_date') ? false : $min_date, |
|
| 47 | + 'data-max-date' => empty('max_date') ? false : $max_date, |
|
| 48 | + 'data-mode' => empty('mode') ? 'single' : $mode, |
|
| 49 | + 'data-alt-format' => get_option('date_format', 'F j, Y'), |
|
| 50 | 50 | 'data-date-format' => 'Y-m-d', |
| 51 | 51 | 'data-alt-input' => 'true', |
| 52 | - 'data-disable_alt' => empty( $disabled_dates ) ? false : wp_json_encode( $disable_dates ), |
|
| 53 | - 'data-disable_days_alt' => empty( $disable_days ) ? false : wp_json_encode( wp_parse_id_list( $disable_days ) ), |
|
| 52 | + 'data-disable_alt' => empty($disabled_dates) ? false : wp_json_encode($disable_dates), |
|
| 53 | + 'data-disable_days_alt' => empty($disable_days) ? false : wp_json_encode(wp_parse_id_list($disable_days)), |
|
| 54 | 54 | ); |
| 55 | 55 | |
| 56 | 56 | echo aui()->input( |
| 57 | 57 | array( |
| 58 | - 'name' => esc_attr( $id ), |
|
| 59 | - 'id' => esc_attr( $id ) . uniqid( '_' ), |
|
| 60 | - 'placeholder' => empty( $placeholder ) ? '' : esc_attr( $placeholder ), |
|
| 61 | - 'required' => ! empty( $required ), |
|
| 58 | + 'name' => esc_attr($id), |
|
| 59 | + 'id' => esc_attr($id) . uniqid('_'), |
|
| 60 | + 'placeholder' => empty($placeholder) ? '' : esc_attr($placeholder), |
|
| 61 | + 'required' => !empty($required), |
|
| 62 | 62 | 'label' => $label, |
| 63 | 63 | 'label_type' => 'vertical', |
| 64 | - 'help_text' => empty( $description ) ? '' : wp_kses_post( $description ), |
|
| 64 | + 'help_text' => empty($description) ? '' : wp_kses_post($description), |
|
| 65 | 65 | 'type' => 'datepicker', |
| 66 | 66 | 'class' => $label_class . ' getpaid-init-flatpickr flatpickr-input', |
| 67 | - 'extra_attributes' => array_filter( apply_filters( 'getpaid_date_field_attributes', $options ) ), |
|
| 67 | + 'extra_attributes' => array_filter(apply_filters('getpaid_date_field_attributes', $options)), |
|
| 68 | 68 | ) |
| 69 | 69 | ); |
@@ -7,104 +7,104 @@ |
||
| 7 | 7 | * @version 1.0.19 |
| 8 | 8 | */ |
| 9 | 9 | |
| 10 | -defined( 'ABSPATH' ) || exit; |
|
| 10 | +defined('ABSPATH') || exit; |
|
| 11 | 11 | |
| 12 | 12 | ?> |
| 13 | 13 | |
| 14 | 14 | <div class='form-group'> |
| 15 | 15 | <label class="d-block"> |
| 16 | - <span><?php esc_html_e( 'Field Label', 'invoicing' ); ?></span> |
|
| 16 | + <span><?php esc_html_e('Field Label', 'invoicing'); ?></span> |
|
| 17 | 17 | <input v-model='active_form_element.label' class='form-control' type="text"/> |
| 18 | 18 | </label> |
| 19 | 19 | </div> |
| 20 | 20 | |
| 21 | 21 | <div class='form-group'> |
| 22 | 22 | <label class="d-block"> |
| 23 | - <span><?php esc_html_e( 'Default Date', 'invoicing' ); ?></span> |
|
| 24 | - <?php echo wpi_help_tip( sprintf( __( 'You can enter the shortcut "today" or enter a date matching the format Y-m-d, e.g %s', 'invoicing' ), current_time( 'Y-m-d' ) ), false, true ); ?> |
|
| 25 | - <input v-model='active_form_element.default_date' placeholder="<?php esc_attr_e( 'None', 'invoicing' ); ?>" class='form-control' type="text"/> |
|
| 23 | + <span><?php esc_html_e('Default Date', 'invoicing'); ?></span> |
|
| 24 | + <?php echo wpi_help_tip(sprintf(__('You can enter the shortcut "today" or enter a date matching the format Y-m-d, e.g %s', 'invoicing'), current_time('Y-m-d')), false, true); ?> |
|
| 25 | + <input v-model='active_form_element.default_date' placeholder="<?php esc_attr_e('None', 'invoicing'); ?>" class='form-control' type="text"/> |
|
| 26 | 26 | </label> |
| 27 | 27 | </div> |
| 28 | 28 | |
| 29 | 29 | <div class='form-group'> |
| 30 | 30 | <label class="d-block"> |
| 31 | - <span><?php esc_html_e( 'Minimum Date', 'invoicing' ); ?></span> |
|
| 32 | - <?php echo wpi_help_tip( sprintf( __( 'You can enter the shortcut "today" or enter a date matching the format Y-m-d, e.g %s', 'invoicing' ), current_time( 'Y-m-d' ) ), false, true ); ?> |
|
| 33 | - <input v-model='active_form_element.min_date' placeholder="<?php esc_attr_e( 'None', 'invoicing' ); ?>" class='form-control' type="text"/> |
|
| 34 | - <small class="form-text text-muted"><?php _e( 'Specify the minimum/earliest date (inclusively) allowed for selection.', 'invoicing' ); ?></small> |
|
| 31 | + <span><?php esc_html_e('Minimum Date', 'invoicing'); ?></span> |
|
| 32 | + <?php echo wpi_help_tip(sprintf(__('You can enter the shortcut "today" or enter a date matching the format Y-m-d, e.g %s', 'invoicing'), current_time('Y-m-d')), false, true); ?> |
|
| 33 | + <input v-model='active_form_element.min_date' placeholder="<?php esc_attr_e('None', 'invoicing'); ?>" class='form-control' type="text"/> |
|
| 34 | + <small class="form-text text-muted"><?php _e('Specify the minimum/earliest date (inclusively) allowed for selection.', 'invoicing'); ?></small> |
|
| 35 | 35 | </label> |
| 36 | 36 | </div> |
| 37 | 37 | |
| 38 | 38 | <div class='form-group'> |
| 39 | 39 | <label class="d-block"> |
| 40 | - <span><?php esc_html_e( 'Maximum Date', 'invoicing' ); ?></span> |
|
| 41 | - <?php echo wpi_help_tip( sprintf( __( 'You can enter the shortcut "today" or enter a date matching the format Y-m-d, e.g %s', 'invoicing' ), current_time( 'Y-m-d' ) ), false, true ); ?> |
|
| 42 | - <input v-model='active_form_element.max_date' placeholder="<?php esc_attr_e( 'None', 'invoicing' ); ?>" class='form-control' type="text"/> |
|
| 43 | - <small class="form-text text-muted"><?php _e( 'Specify the maximum/latest date (inclusively) allowed for selection.', 'invoicing' ); ?></small> |
|
| 40 | + <span><?php esc_html_e('Maximum Date', 'invoicing'); ?></span> |
|
| 41 | + <?php echo wpi_help_tip(sprintf(__('You can enter the shortcut "today" or enter a date matching the format Y-m-d, e.g %s', 'invoicing'), current_time('Y-m-d')), false, true); ?> |
|
| 42 | + <input v-model='active_form_element.max_date' placeholder="<?php esc_attr_e('None', 'invoicing'); ?>" class='form-control' type="text"/> |
|
| 43 | + <small class="form-text text-muted"><?php _e('Specify the maximum/latest date (inclusively) allowed for selection.', 'invoicing'); ?></small> |
|
| 44 | 44 | </label> |
| 45 | 45 | </div> |
| 46 | 46 | |
| 47 | 47 | <div class='form-group'> |
| 48 | 48 | <label class="d-block"> |
| 49 | - <span><?php esc_html_e( 'Disabled Dates', 'invoicing' ); ?></span> |
|
| 50 | - <?php echo wpi_help_tip( sprintf( __( 'You can use the shortcut "today" or enter dates matching the format Y-m-d, e.g %s', 'invoicing' ), current_time( 'Y-m-d' ) ), false, true ); ?> |
|
| 51 | - <input v-model='active_form_element.disabled_dates' placeholder="<?php echo esc_attr( sprintf( __( 'For example, %s', 'invoicing' ), 'today,2025-04-01|2025-05-01,2025-09-01|2025-12-01' ) ); ?>" class='form-control' type="text"/> |
|
| 52 | - <small class="form-text text-muted"><?php _e( 'Specify the dates to ignore. Use commas to separate dates and "|" to separate date ranges.', 'invoicing' ); ?></small> |
|
| 49 | + <span><?php esc_html_e('Disabled Dates', 'invoicing'); ?></span> |
|
| 50 | + <?php echo wpi_help_tip(sprintf(__('You can use the shortcut "today" or enter dates matching the format Y-m-d, e.g %s', 'invoicing'), current_time('Y-m-d')), false, true); ?> |
|
| 51 | + <input v-model='active_form_element.disabled_dates' placeholder="<?php echo esc_attr(sprintf(__('For example, %s', 'invoicing'), 'today,2025-04-01|2025-05-01,2025-09-01|2025-12-01')); ?>" class='form-control' type="text"/> |
|
| 52 | + <small class="form-text text-muted"><?php _e('Specify the dates to ignore. Use commas to separate dates and "|" to separate date ranges.', 'invoicing'); ?></small> |
|
| 53 | 53 | </label> |
| 54 | 54 | </div> |
| 55 | 55 | |
| 56 | 56 | <div class='form-group'> |
| 57 | 57 | <label class="d-block"> |
| 58 | - <span><?php esc_html_e( 'Disable Days', 'invoicing' ) ?></span> |
|
| 58 | + <span><?php esc_html_e('Disable Days', 'invoicing') ?></span> |
|
| 59 | 59 | <gpselect2 class='form-control custom-select' v-model='active_form_element.disable_days' multiple> |
| 60 | - <option value='0'><?php esc_html_e( 'Sundays', 'invoicing' ); ?></option> |
|
| 61 | - <option value='1'><?php esc_html_e( 'Mondays', 'invoicing' ); ?></option> |
|
| 62 | - <option value='2'><?php esc_html_e( 'Tuesdays', 'invoicing' ); ?></option> |
|
| 63 | - <option value='3'><?php esc_html_e( 'Wednesdays', 'invoicing' ); ?></option> |
|
| 64 | - <option value='4'><?php esc_html_e( 'Thursdays', 'invoicing' ); ?></option> |
|
| 65 | - <option value='5'><?php esc_html_e( 'Fridays', 'invoicing' ); ?></option> |
|
| 66 | - <option value='6'><?php esc_html_e( 'Saturdays', 'invoicing' ); ?></option> |
|
| 60 | + <option value='0'><?php esc_html_e('Sundays', 'invoicing'); ?></option> |
|
| 61 | + <option value='1'><?php esc_html_e('Mondays', 'invoicing'); ?></option> |
|
| 62 | + <option value='2'><?php esc_html_e('Tuesdays', 'invoicing'); ?></option> |
|
| 63 | + <option value='3'><?php esc_html_e('Wednesdays', 'invoicing'); ?></option> |
|
| 64 | + <option value='4'><?php esc_html_e('Thursdays', 'invoicing'); ?></option> |
|
| 65 | + <option value='5'><?php esc_html_e('Fridays', 'invoicing'); ?></option> |
|
| 66 | + <option value='6'><?php esc_html_e('Saturdays', 'invoicing'); ?></option> |
|
| 67 | 67 | </gpselect2> |
| 68 | - <small class="form-text text-muted"><?php _e( 'Optionally specify the days of the week to disable.', 'invoicing' ); ?></small> |
|
| 68 | + <small class="form-text text-muted"><?php _e('Optionally specify the days of the week to disable.', 'invoicing'); ?></small> |
|
| 69 | 69 | </label> |
| 70 | 70 | </div> |
| 71 | 71 | |
| 72 | 72 | <div class='form-group'> |
| 73 | 73 | <label class="d-block"> |
| 74 | - <span><?php esc_html_e( 'Mode', 'invoicing' ) ?></span> |
|
| 74 | + <span><?php esc_html_e('Mode', 'invoicing') ?></span> |
|
| 75 | 75 | <select class='form-control custom-select' v-model='active_form_element.mode'> |
| 76 | - <option value='single'><?php esc_html_e( 'Users can only select a single date', 'invoicing' ); ?></option> |
|
| 77 | - <option value='range'><?php esc_html_e( 'Users can select a date range', 'invoicing' ); ?></option> |
|
| 78 | - <option value='multiple'><?php esc_html_e( 'Users can select multiple dates', 'invoicing' ); ?></option> |
|
| 76 | + <option value='single'><?php esc_html_e('Users can only select a single date', 'invoicing'); ?></option> |
|
| 77 | + <option value='range'><?php esc_html_e('Users can select a date range', 'invoicing'); ?></option> |
|
| 78 | + <option value='multiple'><?php esc_html_e('Users can select multiple dates', 'invoicing'); ?></option> |
|
| 79 | 79 | </select> |
| 80 | 80 | </label> |
| 81 | 81 | </div> |
| 82 | 82 | |
| 83 | 83 | <div class='form-group'> |
| 84 | 84 | <label class="d-block"> |
| 85 | - <span><?php esc_html_e( 'Help Text', 'invoicing' ); ?></span> |
|
| 86 | - <textarea placeholder='<?php esc_attr_e( 'Add some help text for this field', 'invoicing' ); ?>' v-model='active_form_element.description' class='form-control' rows='3'></textarea> |
|
| 87 | - <small class="form-text text-muted"><?php _e( 'HTML is allowed', 'invoicing' ); ?></small> |
|
| 85 | + <span><?php esc_html_e('Help Text', 'invoicing'); ?></span> |
|
| 86 | + <textarea placeholder='<?php esc_attr_e('Add some help text for this field', 'invoicing'); ?>' v-model='active_form_element.description' class='form-control' rows='3'></textarea> |
|
| 87 | + <small class="form-text text-muted"><?php _e('HTML is allowed', 'invoicing'); ?></small> |
|
| 88 | 88 | </label> |
| 89 | 89 | </div> |
| 90 | 90 | |
| 91 | 91 | <div class='form-group form-check'> |
| 92 | 92 | <input :id="active_form_element.id + '_edit'" v-model='active_form_element.required' type='checkbox' class='form-check-input' /> |
| 93 | - <label class='form-check-label' :for="active_form_element.id + '_edit'"><?php esc_html_e( 'Is this field required?', 'invoicing' ); ?></label> |
|
| 93 | + <label class='form-check-label' :for="active_form_element.id + '_edit'"><?php esc_html_e('Is this field required?', 'invoicing'); ?></label> |
|
| 94 | 94 | </div> |
| 95 | 95 | |
| 96 | 96 | <div class='form-group form-check'> |
| 97 | 97 | <input :id="active_form_element.id + '_add_meta'" v-model='active_form_element.add_meta' type='checkbox' class='form-check-input' /> |
| 98 | - <label class='form-check-label' :for="active_form_element.id + '_add_meta'"><?php esc_html_e( 'Show this field in receipts and emails?', 'invoicing' ); ?></label> |
|
| 98 | + <label class='form-check-label' :for="active_form_element.id + '_add_meta'"><?php esc_html_e('Show this field in receipts and emails?', 'invoicing'); ?></label> |
|
| 99 | 99 | </div> |
| 100 | 100 | |
| 101 | 101 | <hr class='featurette-divider mt-4'> |
| 102 | 102 | |
| 103 | 103 | <div class='form-group'> |
| 104 | 104 | <label class="d-block"> |
| 105 | - <span><?php esc_html_e( 'Email Merge Tag', 'invoicing' ); ?></span> |
|
| 105 | + <span><?php esc_html_e('Email Merge Tag', 'invoicing'); ?></span> |
|
| 106 | 106 | <input :value='active_form_element.label | formatMergeTag' class='form-control bg-white' type="text" readonly onclick="this.select()" /> |
| 107 | - <span class="form-text text-muted"><?php esc_html_e( 'You can use this merge tag in notification emails', 'invoicing' ); ?></span> |
|
| 107 | + <span class="form-text text-muted"><?php esc_html_e('You can use this merge tag in notification emails', 'invoicing'); ?></span> |
|
| 108 | 108 | </label> |
| 109 | 109 | </div> |
| 110 | 110 | |
@@ -9,26 +9,26 @@ discard block |
||
| 9 | 9 | * @var WPInv_Invoice $invoice |
| 10 | 10 | */ |
| 11 | 11 | |
| 12 | -defined( 'ABSPATH' ) || exit; |
|
| 12 | +defined('ABSPATH') || exit; |
|
| 13 | 13 | |
| 14 | 14 | // Totals rows. |
| 15 | -$totals = getpaid_invoice_totals_rows( $invoice ); |
|
| 15 | +$totals = getpaid_invoice_totals_rows($invoice); |
|
| 16 | 16 | |
| 17 | -do_action( 'getpaid_before_invoice_line_totals', $invoice, $totals ); |
|
| 17 | +do_action('getpaid_before_invoice_line_totals', $invoice, $totals); |
|
| 18 | 18 | |
| 19 | 19 | ?> |
| 20 | 20 | <div class='getpaid-invoice-line-totals'> |
| 21 | 21 | <div class="row"> |
| 22 | 22 | <div class="col-12 offset-sm-6 col-sm-6 border-sm-left pl-sm-0"> |
| 23 | 23 | |
| 24 | - <?php foreach ( $totals as $key => $label ) : ?> |
|
| 24 | + <?php foreach ($totals as $key => $label) : ?> |
|
| 25 | 25 | |
| 26 | - <div class="getpaid-invoice-line-totals-col <?php echo sanitize_html_class( $key ); ?>"> |
|
| 26 | + <div class="getpaid-invoice-line-totals-col <?php echo sanitize_html_class($key); ?>"> |
|
| 27 | 27 | |
| 28 | 28 | <div class="form-row"> |
| 29 | 29 | |
| 30 | 30 | <div class="col-8 getpaid-invoice-line-totals-label"> |
| 31 | - <?php echo esc_html( $label ); ?> |
|
| 31 | + <?php echo esc_html($label); ?> |
|
| 32 | 32 | </div> |
| 33 | 33 | |
| 34 | 34 | <div class="col-4 getpaid-invoice-line-totals-value pl-0"> |
@@ -36,15 +36,15 @@ discard block |
||
| 36 | 36 | <?php |
| 37 | 37 | |
| 38 | 38 | // Total tax. |
| 39 | - if ( 'tax' == $key ) { |
|
| 40 | - echo wpinv_price( $invoice->get_total_tax(), $invoice->get_currency() ); |
|
| 39 | + if ('tax' == $key) { |
|
| 40 | + echo wpinv_price($invoice->get_total_tax(), $invoice->get_currency()); |
|
| 41 | 41 | |
| 42 | - if ( wpinv_use_taxes() && ! $invoice->get_disable_taxes() ) { |
|
| 42 | + if (wpinv_use_taxes() && !$invoice->get_disable_taxes()) { |
|
| 43 | 43 | |
| 44 | 44 | $taxes = $invoice->get_total_tax(); |
| 45 | - if ( empty( $taxes ) && GetPaid_Payment_Form_Submission_Taxes::is_eu_transaction( $invoice->get_country() ) ) { |
|
| 45 | + if (empty($taxes) && GetPaid_Payment_Form_Submission_Taxes::is_eu_transaction($invoice->get_country())) { |
|
| 46 | 46 | echo ' <em class="text-muted small">'; |
| 47 | - _x( '(Reverse charged)','This is a legal term for reverse charging tax in the EU', 'invoicing' ); |
|
| 47 | + _x('(Reverse charged)', 'This is a legal term for reverse charging tax in the EU', 'invoicing'); |
|
| 48 | 48 | echo '</em>'; |
| 49 | 49 | } |
| 50 | 50 | |
@@ -53,32 +53,32 @@ discard block |
||
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | // Total Fee. |
| 56 | - if ( 'fee' == $key ) { |
|
| 57 | - echo wpinv_price( $invoice->get_total_fees(), $invoice->get_currency() ); |
|
| 56 | + if ('fee' == $key) { |
|
| 57 | + echo wpinv_price($invoice->get_total_fees(), $invoice->get_currency()); |
|
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | // Total discount. |
| 61 | - if ( 'discount' == $key ) { |
|
| 62 | - echo wpinv_price( $invoice->get_total_discount(), $invoice->get_currency() ); |
|
| 61 | + if ('discount' == $key) { |
|
| 62 | + echo wpinv_price($invoice->get_total_discount(), $invoice->get_currency()); |
|
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | // Shipping. |
| 66 | - if ( 'shipping' == $key ) { |
|
| 67 | - echo wpinv_price( $invoice->get_shipping(), $invoice->get_currency() ); |
|
| 66 | + if ('shipping' == $key) { |
|
| 67 | + echo wpinv_price($invoice->get_shipping(), $invoice->get_currency()); |
|
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | // Sub total. |
| 71 | - if ( 'subtotal' == $key ) { |
|
| 72 | - echo wpinv_price( $invoice->get_subtotal(), $invoice->get_currency() ); |
|
| 71 | + if ('subtotal' == $key) { |
|
| 72 | + echo wpinv_price($invoice->get_subtotal(), $invoice->get_currency()); |
|
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | // Total. |
| 76 | - if ( 'total' == $key ) { |
|
| 77 | - echo wpinv_price( $invoice->get_total(), $invoice->get_currency() ); |
|
| 76 | + if ('total' == $key) { |
|
| 77 | + echo wpinv_price($invoice->get_total(), $invoice->get_currency()); |
|
| 78 | 78 | } |
| 79 | 79 | |
| 80 | 80 | // Fires when printing a cart total. |
| 81 | - do_action( "getpaid_invoice_cart_totals_$key", $invoice ); |
|
| 81 | + do_action("getpaid_invoice_cart_totals_$key", $invoice); |
|
| 82 | 82 | |
| 83 | 83 | ?> |
| 84 | 84 | |
@@ -92,4 +92,4 @@ discard block |
||
| 92 | 92 | </div> |
| 93 | 93 | </div> <!-- end .getpaid-invoice-line-totals --> |
| 94 | 94 | |
| 95 | -<?php do_action( 'getpaid_after_invoice_line_totals', $invoice, $totals ); ?> |
|
| 95 | +<?php do_action('getpaid_after_invoice_line_totals', $invoice, $totals); ?> |
|
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | if ( ! defined( 'ABSPATH' ) ) { |
| 3 | - exit; |
|
| 3 | + exit; |
|
| 4 | 4 | } |
| 5 | 5 | |
| 6 | 6 | /** |
@@ -10,203 +10,203 @@ discard block |
||
| 10 | 10 | class GetPaid_Payment_Form_Submission { |
| 11 | 11 | |
| 12 | 12 | /** |
| 13 | - * Submission ID |
|
| 14 | - * |
|
| 15 | - * @var string |
|
| 16 | - */ |
|
| 17 | - public $id = null; |
|
| 18 | - |
|
| 19 | - /** |
|
| 20 | - * The raw submission data. |
|
| 21 | - * |
|
| 22 | - * @var array |
|
| 23 | - */ |
|
| 24 | - protected $data = null; |
|
| 25 | - |
|
| 26 | - /** |
|
| 27 | - * Submission totals |
|
| 28 | - * |
|
| 29 | - * @var array |
|
| 30 | - */ |
|
| 31 | - protected $totals = array( |
|
| 32 | - |
|
| 33 | - 'subtotal' => array( |
|
| 34 | - 'initial' => 0, |
|
| 35 | - 'recurring' => 0, |
|
| 36 | - ), |
|
| 37 | - |
|
| 38 | - 'discount' => array( |
|
| 39 | - 'initial' => 0, |
|
| 40 | - 'recurring' => 0, |
|
| 41 | - ), |
|
| 42 | - |
|
| 43 | - 'fees' => array( |
|
| 44 | - 'initial' => 0, |
|
| 45 | - 'recurring' => 0, |
|
| 46 | - ), |
|
| 47 | - |
|
| 48 | - 'taxes' => array( |
|
| 49 | - 'initial' => 0, |
|
| 50 | - 'recurring' => 0, |
|
| 51 | - ), |
|
| 52 | - |
|
| 53 | - 'shipping' => array( |
|
| 54 | - 'initial' => 0, |
|
| 55 | - 'recurring' => 0, |
|
| 56 | - ), |
|
| 57 | - |
|
| 58 | - ); |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * Sets the associated payment form. |
|
| 62 | - * |
|
| 63 | - * @var GetPaid_Payment_Form |
|
| 64 | - */ |
|
| 13 | + * Submission ID |
|
| 14 | + * |
|
| 15 | + * @var string |
|
| 16 | + */ |
|
| 17 | + public $id = null; |
|
| 18 | + |
|
| 19 | + /** |
|
| 20 | + * The raw submission data. |
|
| 21 | + * |
|
| 22 | + * @var array |
|
| 23 | + */ |
|
| 24 | + protected $data = null; |
|
| 25 | + |
|
| 26 | + /** |
|
| 27 | + * Submission totals |
|
| 28 | + * |
|
| 29 | + * @var array |
|
| 30 | + */ |
|
| 31 | + protected $totals = array( |
|
| 32 | + |
|
| 33 | + 'subtotal' => array( |
|
| 34 | + 'initial' => 0, |
|
| 35 | + 'recurring' => 0, |
|
| 36 | + ), |
|
| 37 | + |
|
| 38 | + 'discount' => array( |
|
| 39 | + 'initial' => 0, |
|
| 40 | + 'recurring' => 0, |
|
| 41 | + ), |
|
| 42 | + |
|
| 43 | + 'fees' => array( |
|
| 44 | + 'initial' => 0, |
|
| 45 | + 'recurring' => 0, |
|
| 46 | + ), |
|
| 47 | + |
|
| 48 | + 'taxes' => array( |
|
| 49 | + 'initial' => 0, |
|
| 50 | + 'recurring' => 0, |
|
| 51 | + ), |
|
| 52 | + |
|
| 53 | + 'shipping' => array( |
|
| 54 | + 'initial' => 0, |
|
| 55 | + 'recurring' => 0, |
|
| 56 | + ), |
|
| 57 | + |
|
| 58 | + ); |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * Sets the associated payment form. |
|
| 62 | + * |
|
| 63 | + * @var GetPaid_Payment_Form |
|
| 64 | + */ |
|
| 65 | 65 | protected $payment_form = null; |
| 66 | 66 | |
| 67 | 67 | /** |
| 68 | - * The country for the submission. |
|
| 69 | - * |
|
| 70 | - * @var string |
|
| 71 | - */ |
|
| 72 | - public $country = null; |
|
| 73 | - |
|
| 74 | - /** |
|
| 75 | - * The state for the submission. |
|
| 76 | - * |
|
| 77 | - * @since 1.0.19 |
|
| 78 | - * @var string |
|
| 79 | - */ |
|
| 80 | - public $state = null; |
|
| 81 | - |
|
| 82 | - /** |
|
| 83 | - * The invoice associated with the submission. |
|
| 84 | - * |
|
| 85 | - * @var WPInv_Invoice |
|
| 86 | - */ |
|
| 87 | - protected $invoice = null; |
|
| 88 | - |
|
| 89 | - /** |
|
| 90 | - * The recurring item for the submission. |
|
| 91 | - * |
|
| 92 | - * @var int |
|
| 93 | - */ |
|
| 94 | - public $has_recurring = 0; |
|
| 95 | - |
|
| 96 | - /** |
|
| 97 | - * An array of fees for the submission. |
|
| 98 | - * |
|
| 99 | - * @var array |
|
| 100 | - */ |
|
| 101 | - protected $fees = array(); |
|
| 102 | - |
|
| 103 | - /** |
|
| 104 | - * An array of discounts for the submission. |
|
| 105 | - * |
|
| 106 | - * @var array |
|
| 107 | - */ |
|
| 108 | - protected $discounts = array(); |
|
| 109 | - |
|
| 110 | - /** |
|
| 111 | - * An array of taxes for the submission. |
|
| 112 | - * |
|
| 113 | - * @var array |
|
| 114 | - */ |
|
| 115 | - protected $taxes = array(); |
|
| 116 | - |
|
| 117 | - /** |
|
| 118 | - * An array of items for the submission. |
|
| 119 | - * |
|
| 120 | - * @var GetPaid_Form_Item[] |
|
| 121 | - */ |
|
| 122 | - protected $items = array(); |
|
| 123 | - |
|
| 124 | - /** |
|
| 125 | - * The last error. |
|
| 126 | - * |
|
| 127 | - * @var string |
|
| 128 | - */ |
|
| 129 | - public $last_error = null; |
|
| 130 | - |
|
| 131 | - /** |
|
| 132 | - * The last error code. |
|
| 133 | - * |
|
| 134 | - * @var string |
|
| 135 | - */ |
|
| 136 | - public $last_error_code = null; |
|
| 137 | - |
|
| 138 | - /** |
|
| 139 | - * Class constructor. |
|
| 140 | - * |
|
| 141 | - */ |
|
| 142 | - public function __construct() { |
|
| 143 | - |
|
| 144 | - // Set the state and country to the default state and country. |
|
| 145 | - $this->country = wpinv_default_billing_country(); |
|
| 146 | - $this->state = wpinv_get_default_state(); |
|
| 147 | - |
|
| 148 | - // Do we have an actual submission? |
|
| 149 | - if ( isset( $_POST['getpaid_payment_form_submission'] ) ) { |
|
| 150 | - $this->load_data( $_POST ); |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - /** |
|
| 156 | - * Loads submission data. |
|
| 157 | - * |
|
| 158 | - * @param array $data |
|
| 159 | - */ |
|
| 160 | - public function load_data( $data ) { |
|
| 161 | - |
|
| 162 | - // Remove slashes from the submitted data... |
|
| 163 | - $data = wp_kses_post_deep( wp_unslash( $data ) ); |
|
| 164 | - |
|
| 165 | - // Allow plugins to filter the data. |
|
| 166 | - $data = apply_filters( 'getpaid_submission_data', $data, $this ); |
|
| 167 | - |
|
| 168 | - // Cache it... |
|
| 169 | - $this->data = $data; |
|
| 170 | - |
|
| 171 | - // Then generate a unique id from the data. |
|
| 172 | - $this->id = md5( wp_json_encode( $data ) ); |
|
| 173 | - |
|
| 174 | - // Finally, process the submission. |
|
| 175 | - try { |
|
| 176 | - |
|
| 177 | - // Each process is passed an instance of the class (with reference) |
|
| 178 | - // and should throw an Exception whenever it encounters one. |
|
| 179 | - $processors = apply_filters( |
|
| 180 | - 'getpaid_payment_form_submission_processors', |
|
| 181 | - array( |
|
| 182 | - array( $this, 'process_payment_form' ), |
|
| 183 | - array( $this, 'process_invoice' ), |
|
| 184 | - array( $this, 'process_fees' ), |
|
| 185 | - array( $this, 'process_items' ), |
|
| 186 | - array( $this, 'process_discount' ), |
|
| 187 | - array( $this, 'process_taxes' ), |
|
| 188 | - ), |
|
| 189 | - $this |
|
| 190 | - ); |
|
| 191 | - |
|
| 192 | - foreach ( $processors as $processor ) { |
|
| 193 | - call_user_func_array( $processor, array( &$this ) ); |
|
| 194 | - } |
|
| 195 | - |
|
| 196 | - } catch( GetPaid_Payment_Exception $e ) { |
|
| 197 | - $this->last_error = $e->getMessage(); |
|
| 198 | - $this->last_error_code = $e->getErrorCode(); |
|
| 199 | - } catch ( Exception $e ) { |
|
| 200 | - $this->last_error = $e->getMessage(); |
|
| 201 | - $this->last_error_code = $e->getCode(); |
|
| 202 | - } |
|
| 203 | - |
|
| 204 | - // Fired when we are done processing a submission. |
|
| 205 | - do_action_ref_array( 'getpaid_process_submission', array( &$this ) ); |
|
| 206 | - |
|
| 207 | - } |
|
| 208 | - |
|
| 209 | - /* |
|
| 68 | + * The country for the submission. |
|
| 69 | + * |
|
| 70 | + * @var string |
|
| 71 | + */ |
|
| 72 | + public $country = null; |
|
| 73 | + |
|
| 74 | + /** |
|
| 75 | + * The state for the submission. |
|
| 76 | + * |
|
| 77 | + * @since 1.0.19 |
|
| 78 | + * @var string |
|
| 79 | + */ |
|
| 80 | + public $state = null; |
|
| 81 | + |
|
| 82 | + /** |
|
| 83 | + * The invoice associated with the submission. |
|
| 84 | + * |
|
| 85 | + * @var WPInv_Invoice |
|
| 86 | + */ |
|
| 87 | + protected $invoice = null; |
|
| 88 | + |
|
| 89 | + /** |
|
| 90 | + * The recurring item for the submission. |
|
| 91 | + * |
|
| 92 | + * @var int |
|
| 93 | + */ |
|
| 94 | + public $has_recurring = 0; |
|
| 95 | + |
|
| 96 | + /** |
|
| 97 | + * An array of fees for the submission. |
|
| 98 | + * |
|
| 99 | + * @var array |
|
| 100 | + */ |
|
| 101 | + protected $fees = array(); |
|
| 102 | + |
|
| 103 | + /** |
|
| 104 | + * An array of discounts for the submission. |
|
| 105 | + * |
|
| 106 | + * @var array |
|
| 107 | + */ |
|
| 108 | + protected $discounts = array(); |
|
| 109 | + |
|
| 110 | + /** |
|
| 111 | + * An array of taxes for the submission. |
|
| 112 | + * |
|
| 113 | + * @var array |
|
| 114 | + */ |
|
| 115 | + protected $taxes = array(); |
|
| 116 | + |
|
| 117 | + /** |
|
| 118 | + * An array of items for the submission. |
|
| 119 | + * |
|
| 120 | + * @var GetPaid_Form_Item[] |
|
| 121 | + */ |
|
| 122 | + protected $items = array(); |
|
| 123 | + |
|
| 124 | + /** |
|
| 125 | + * The last error. |
|
| 126 | + * |
|
| 127 | + * @var string |
|
| 128 | + */ |
|
| 129 | + public $last_error = null; |
|
| 130 | + |
|
| 131 | + /** |
|
| 132 | + * The last error code. |
|
| 133 | + * |
|
| 134 | + * @var string |
|
| 135 | + */ |
|
| 136 | + public $last_error_code = null; |
|
| 137 | + |
|
| 138 | + /** |
|
| 139 | + * Class constructor. |
|
| 140 | + * |
|
| 141 | + */ |
|
| 142 | + public function __construct() { |
|
| 143 | + |
|
| 144 | + // Set the state and country to the default state and country. |
|
| 145 | + $this->country = wpinv_default_billing_country(); |
|
| 146 | + $this->state = wpinv_get_default_state(); |
|
| 147 | + |
|
| 148 | + // Do we have an actual submission? |
|
| 149 | + if ( isset( $_POST['getpaid_payment_form_submission'] ) ) { |
|
| 150 | + $this->load_data( $_POST ); |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + /** |
|
| 156 | + * Loads submission data. |
|
| 157 | + * |
|
| 158 | + * @param array $data |
|
| 159 | + */ |
|
| 160 | + public function load_data( $data ) { |
|
| 161 | + |
|
| 162 | + // Remove slashes from the submitted data... |
|
| 163 | + $data = wp_kses_post_deep( wp_unslash( $data ) ); |
|
| 164 | + |
|
| 165 | + // Allow plugins to filter the data. |
|
| 166 | + $data = apply_filters( 'getpaid_submission_data', $data, $this ); |
|
| 167 | + |
|
| 168 | + // Cache it... |
|
| 169 | + $this->data = $data; |
|
| 170 | + |
|
| 171 | + // Then generate a unique id from the data. |
|
| 172 | + $this->id = md5( wp_json_encode( $data ) ); |
|
| 173 | + |
|
| 174 | + // Finally, process the submission. |
|
| 175 | + try { |
|
| 176 | + |
|
| 177 | + // Each process is passed an instance of the class (with reference) |
|
| 178 | + // and should throw an Exception whenever it encounters one. |
|
| 179 | + $processors = apply_filters( |
|
| 180 | + 'getpaid_payment_form_submission_processors', |
|
| 181 | + array( |
|
| 182 | + array( $this, 'process_payment_form' ), |
|
| 183 | + array( $this, 'process_invoice' ), |
|
| 184 | + array( $this, 'process_fees' ), |
|
| 185 | + array( $this, 'process_items' ), |
|
| 186 | + array( $this, 'process_discount' ), |
|
| 187 | + array( $this, 'process_taxes' ), |
|
| 188 | + ), |
|
| 189 | + $this |
|
| 190 | + ); |
|
| 191 | + |
|
| 192 | + foreach ( $processors as $processor ) { |
|
| 193 | + call_user_func_array( $processor, array( &$this ) ); |
|
| 194 | + } |
|
| 195 | + |
|
| 196 | + } catch( GetPaid_Payment_Exception $e ) { |
|
| 197 | + $this->last_error = $e->getMessage(); |
|
| 198 | + $this->last_error_code = $e->getErrorCode(); |
|
| 199 | + } catch ( Exception $e ) { |
|
| 200 | + $this->last_error = $e->getMessage(); |
|
| 201 | + $this->last_error_code = $e->getCode(); |
|
| 202 | + } |
|
| 203 | + |
|
| 204 | + // Fired when we are done processing a submission. |
|
| 205 | + do_action_ref_array( 'getpaid_process_submission', array( &$this ) ); |
|
| 206 | + |
|
| 207 | + } |
|
| 208 | + |
|
| 209 | + /* |
|
| 210 | 210 | |-------------------------------------------------------------------------- |
| 211 | 211 | | Payment Forms. |
| 212 | 212 | |-------------------------------------------------------------------------- |
@@ -215,39 +215,39 @@ discard block |
||
| 215 | 215 | | submission has an active payment form etc. |
| 216 | 216 | */ |
| 217 | 217 | |
| 218 | - /** |
|
| 219 | - * Prepares the submission's payment form. |
|
| 220 | - * |
|
| 221 | - * @since 1.0.19 |
|
| 222 | - */ |
|
| 223 | - public function process_payment_form() { |
|
| 218 | + /** |
|
| 219 | + * Prepares the submission's payment form. |
|
| 220 | + * |
|
| 221 | + * @since 1.0.19 |
|
| 222 | + */ |
|
| 223 | + public function process_payment_form() { |
|
| 224 | 224 | |
| 225 | - // Every submission needs an active payment form. |
|
| 226 | - if ( empty( $this->data['form_id'] ) ) { |
|
| 227 | - throw new Exception( __( 'Missing payment form', 'invoicing' ) ); |
|
| 228 | - } |
|
| 225 | + // Every submission needs an active payment form. |
|
| 226 | + if ( empty( $this->data['form_id'] ) ) { |
|
| 227 | + throw new Exception( __( 'Missing payment form', 'invoicing' ) ); |
|
| 228 | + } |
|
| 229 | 229 | |
| 230 | - // Fetch the payment form. |
|
| 231 | - $this->payment_form = new GetPaid_Payment_Form( $this->data['form_id'] ); |
|
| 230 | + // Fetch the payment form. |
|
| 231 | + $this->payment_form = new GetPaid_Payment_Form( $this->data['form_id'] ); |
|
| 232 | 232 | |
| 233 | - if ( ! $this->payment_form->is_active() ) { |
|
| 234 | - throw new Exception( __( 'Payment form not active', 'invoicing' ) ); |
|
| 235 | - } |
|
| 233 | + if ( ! $this->payment_form->is_active() ) { |
|
| 234 | + throw new Exception( __( 'Payment form not active', 'invoicing' ) ); |
|
| 235 | + } |
|
| 236 | 236 | |
| 237 | - do_action_ref_array( 'getpaid_submissions_process_payment_form', array( &$this ) ); |
|
| 238 | - } |
|
| 237 | + do_action_ref_array( 'getpaid_submissions_process_payment_form', array( &$this ) ); |
|
| 238 | + } |
|
| 239 | 239 | |
| 240 | 240 | /** |
| 241 | - * Returns the payment form. |
|
| 242 | - * |
|
| 243 | - * @since 1.0.19 |
|
| 244 | - * @return GetPaid_Payment_Form |
|
| 245 | - */ |
|
| 246 | - public function get_payment_form() { |
|
| 247 | - return $this->payment_form; |
|
| 248 | - } |
|
| 241 | + * Returns the payment form. |
|
| 242 | + * |
|
| 243 | + * @since 1.0.19 |
|
| 244 | + * @return GetPaid_Payment_Form |
|
| 245 | + */ |
|
| 246 | + public function get_payment_form() { |
|
| 247 | + return $this->payment_form; |
|
| 248 | + } |
|
| 249 | 249 | |
| 250 | - /* |
|
| 250 | + /* |
|
| 251 | 251 | |-------------------------------------------------------------------------- |
| 252 | 252 | | Invoices. |
| 253 | 253 | |-------------------------------------------------------------------------- |
@@ -256,84 +256,84 @@ discard block |
||
| 256 | 256 | | might be for an existing invoice. |
| 257 | 257 | */ |
| 258 | 258 | |
| 259 | - /** |
|
| 260 | - * Prepares the submission's invoice. |
|
| 261 | - * |
|
| 262 | - * @since 1.0.19 |
|
| 263 | - */ |
|
| 264 | - public function process_invoice() { |
|
| 259 | + /** |
|
| 260 | + * Prepares the submission's invoice. |
|
| 261 | + * |
|
| 262 | + * @since 1.0.19 |
|
| 263 | + */ |
|
| 264 | + public function process_invoice() { |
|
| 265 | 265 | |
| 266 | - // Abort if there is no invoice. |
|
| 267 | - if ( empty( $this->data['invoice_id'] ) ) { |
|
| 268 | - return; |
|
| 269 | - } |
|
| 266 | + // Abort if there is no invoice. |
|
| 267 | + if ( empty( $this->data['invoice_id'] ) ) { |
|
| 268 | + return; |
|
| 269 | + } |
|
| 270 | 270 | |
| 271 | - // If the submission is for an existing invoice, ensure that it exists |
|
| 272 | - // and that it is not paid for. |
|
| 273 | - $invoice = wpinv_get_invoice( $this->data['invoice_id'] ); |
|
| 271 | + // If the submission is for an existing invoice, ensure that it exists |
|
| 272 | + // and that it is not paid for. |
|
| 273 | + $invoice = wpinv_get_invoice( $this->data['invoice_id'] ); |
|
| 274 | 274 | |
| 275 | 275 | if ( empty( $invoice ) ) { |
| 276 | - throw new Exception( __( 'Invalid invoice', 'invoicing' ) ); |
|
| 277 | - } |
|
| 276 | + throw new Exception( __( 'Invalid invoice', 'invoicing' ) ); |
|
| 277 | + } |
|
| 278 | 278 | |
| 279 | - if ( $invoice->is_paid() ) { |
|
| 280 | - throw new Exception( __( 'This invoice is already paid for.', 'invoicing' ) ); |
|
| 281 | - } |
|
| 279 | + if ( $invoice->is_paid() ) { |
|
| 280 | + throw new Exception( __( 'This invoice is already paid for.', 'invoicing' ) ); |
|
| 281 | + } |
|
| 282 | 282 | |
| 283 | - $this->payment_form->invoice = $invoice; |
|
| 284 | - if ( ! $this->payment_form->is_default() ) { |
|
| 283 | + $this->payment_form->invoice = $invoice; |
|
| 284 | + if ( ! $this->payment_form->is_default() ) { |
|
| 285 | 285 | |
| 286 | - $items = array(); |
|
| 287 | - $item_ids = array(); |
|
| 286 | + $items = array(); |
|
| 287 | + $item_ids = array(); |
|
| 288 | 288 | |
| 289 | - foreach ( $invoice->get_items() as $item ) { |
|
| 290 | - if ( ! in_array( $item->get_id(), $item_ids ) ) { |
|
| 291 | - $item_ids[] = $item->get_id(); |
|
| 292 | - $items[] = $item; |
|
| 293 | - } |
|
| 294 | - } |
|
| 289 | + foreach ( $invoice->get_items() as $item ) { |
|
| 290 | + if ( ! in_array( $item->get_id(), $item_ids ) ) { |
|
| 291 | + $item_ids[] = $item->get_id(); |
|
| 292 | + $items[] = $item; |
|
| 293 | + } |
|
| 294 | + } |
|
| 295 | 295 | |
| 296 | - foreach ( $this->payment_form->get_items() as $item ) { |
|
| 297 | - if ( ! in_array( $item->get_id(), $item_ids ) ) { |
|
| 298 | - $item_ids[] = $item->get_id(); |
|
| 299 | - $items[] = $item; |
|
| 300 | - } |
|
| 301 | - } |
|
| 296 | + foreach ( $this->payment_form->get_items() as $item ) { |
|
| 297 | + if ( ! in_array( $item->get_id(), $item_ids ) ) { |
|
| 298 | + $item_ids[] = $item->get_id(); |
|
| 299 | + $items[] = $item; |
|
| 300 | + } |
|
| 301 | + } |
|
| 302 | 302 | |
| 303 | - $this->payment_form->set_items( $items ); |
|
| 303 | + $this->payment_form->set_items( $items ); |
|
| 304 | 304 | |
| 305 | - } else { |
|
| 306 | - $this->payment_form->set_items( $invoice->get_items() ); |
|
| 307 | - } |
|
| 308 | - |
|
| 309 | - $this->country = $invoice->get_country(); |
|
| 310 | - $this->state = $invoice->get_state(); |
|
| 311 | - $this->invoice = $invoice; |
|
| 312 | - |
|
| 313 | - do_action_ref_array( 'getpaid_submissions_process_invoice', array( &$this ) ); |
|
| 314 | - } |
|
| 315 | - |
|
| 316 | - /** |
|
| 317 | - * Returns the associated invoice. |
|
| 318 | - * |
|
| 319 | - * @since 1.0.19 |
|
| 320 | - * @return WPInv_Invoice |
|
| 321 | - */ |
|
| 322 | - public function get_invoice() { |
|
| 323 | - return $this->invoice; |
|
| 324 | - } |
|
| 325 | - |
|
| 326 | - /** |
|
| 327 | - * Checks whether there is an invoice associated with this submission. |
|
| 328 | - * |
|
| 329 | - * @since 1.0.19 |
|
| 330 | - * @return bool |
|
| 331 | - */ |
|
| 332 | - public function has_invoice() { |
|
| 333 | - return ! empty( $this->invoice ); |
|
| 334 | - } |
|
| 335 | - |
|
| 336 | - /* |
|
| 305 | + } else { |
|
| 306 | + $this->payment_form->set_items( $invoice->get_items() ); |
|
| 307 | + } |
|
| 308 | + |
|
| 309 | + $this->country = $invoice->get_country(); |
|
| 310 | + $this->state = $invoice->get_state(); |
|
| 311 | + $this->invoice = $invoice; |
|
| 312 | + |
|
| 313 | + do_action_ref_array( 'getpaid_submissions_process_invoice', array( &$this ) ); |
|
| 314 | + } |
|
| 315 | + |
|
| 316 | + /** |
|
| 317 | + * Returns the associated invoice. |
|
| 318 | + * |
|
| 319 | + * @since 1.0.19 |
|
| 320 | + * @return WPInv_Invoice |
|
| 321 | + */ |
|
| 322 | + public function get_invoice() { |
|
| 323 | + return $this->invoice; |
|
| 324 | + } |
|
| 325 | + |
|
| 326 | + /** |
|
| 327 | + * Checks whether there is an invoice associated with this submission. |
|
| 328 | + * |
|
| 329 | + * @since 1.0.19 |
|
| 330 | + * @return bool |
|
| 331 | + */ |
|
| 332 | + public function has_invoice() { |
|
| 333 | + return ! empty( $this->invoice ); |
|
| 334 | + } |
|
| 335 | + |
|
| 336 | + /* |
|
| 337 | 337 | |-------------------------------------------------------------------------- |
| 338 | 338 | | Items. |
| 339 | 339 | |-------------------------------------------------------------------------- |
@@ -342,129 +342,129 @@ discard block |
||
| 342 | 342 | | recurring item. But can have an unlimited number of non-recurring items. |
| 343 | 343 | */ |
| 344 | 344 | |
| 345 | - /** |
|
| 346 | - * Prepares the submission's items. |
|
| 347 | - * |
|
| 348 | - * @since 1.0.19 |
|
| 349 | - */ |
|
| 350 | - public function process_items() { |
|
| 351 | - |
|
| 352 | - $processor = new GetPaid_Payment_Form_Submission_Items( $this ); |
|
| 353 | - |
|
| 354 | - foreach ( $processor->items as $item ) { |
|
| 355 | - $this->add_item( $item ); |
|
| 356 | - } |
|
| 357 | - |
|
| 358 | - do_action_ref_array( 'getpaid_submissions_process_items', array( &$this ) ); |
|
| 359 | - } |
|
| 360 | - |
|
| 361 | - /** |
|
| 362 | - * Adds an item to the submission. |
|
| 363 | - * |
|
| 364 | - * @since 1.0.19 |
|
| 365 | - * @param GetPaid_Form_Item $item |
|
| 366 | - */ |
|
| 367 | - public function add_item( $item ) { |
|
| 368 | - |
|
| 369 | - // Make sure that it is available for purchase. |
|
| 370 | - if ( ! $item->can_purchase() || isset( $this->items[ $item->get_id() ] ) ) { |
|
| 371 | - return; |
|
| 372 | - } |
|
| 373 | - |
|
| 374 | - // Each submission can only contain one recurring item. |
|
| 375 | - if ( $item->is_recurring() ) { |
|
| 376 | - $this->has_recurring = $item->get_id(); |
|
| 377 | - } |
|
| 378 | - |
|
| 379 | - // Update the items and totals. |
|
| 380 | - $this->items[ $item->get_id() ] = $item; |
|
| 381 | - $this->totals['subtotal']['initial'] += $item->get_sub_total(); |
|
| 382 | - $this->totals['subtotal']['recurring'] += $item->get_recurring_sub_total(); |
|
| 383 | - |
|
| 384 | - } |
|
| 385 | - |
|
| 386 | - /** |
|
| 387 | - * Removes a specific item. |
|
| 388 | - * |
|
| 389 | - * You should not call this method after the discounts and taxes |
|
| 390 | - * have been calculated. |
|
| 391 | - * |
|
| 392 | - * @since 1.0.19 |
|
| 393 | - */ |
|
| 394 | - public function remove_item( $item_id ) { |
|
| 395 | - |
|
| 396 | - if ( isset( $this->items[ $item_id ] ) ) { |
|
| 397 | - $this->totals['subtotal']['initial'] -= $this->items[ $item_id ]->get_sub_total(); |
|
| 398 | - $this->totals['subtotal']['recurring'] -= $this->items[ $item_id ]->get_recurring_sub_total(); |
|
| 399 | - |
|
| 400 | - if ( $this->items[ $item_id ]->is_recurring() ) { |
|
| 401 | - $this->has_recurring = 0; |
|
| 402 | - } |
|
| 403 | - |
|
| 404 | - unset( $this->items[ $item_id ] ); |
|
| 405 | - } |
|
| 406 | - |
|
| 407 | - } |
|
| 408 | - |
|
| 409 | - /** |
|
| 410 | - * Returns the subtotal. |
|
| 411 | - * |
|
| 412 | - * @since 1.0.19 |
|
| 413 | - */ |
|
| 414 | - public function get_subtotal() { |
|
| 415 | - |
|
| 416 | - if ( wpinv_prices_include_tax() ) { |
|
| 417 | - return $this->totals['subtotal']['initial'] - $this->totals['taxes']['initial']; |
|
| 418 | - } |
|
| 419 | - |
|
| 420 | - return $this->totals['subtotal']['initial']; |
|
| 421 | - } |
|
| 422 | - |
|
| 423 | - /** |
|
| 424 | - * Returns the recurring subtotal. |
|
| 425 | - * |
|
| 426 | - * @since 1.0.19 |
|
| 427 | - */ |
|
| 428 | - public function get_recurring_subtotal() { |
|
| 429 | - |
|
| 430 | - if ( wpinv_prices_include_tax() ) { |
|
| 431 | - return $this->totals['subtotal']['recurring'] - $this->totals['taxes']['recurring']; |
|
| 432 | - } |
|
| 433 | - |
|
| 434 | - return $this->totals['subtotal']['recurring']; |
|
| 435 | - } |
|
| 436 | - |
|
| 437 | - /** |
|
| 438 | - * Returns all items. |
|
| 439 | - * |
|
| 440 | - * @since 1.0.19 |
|
| 441 | - * @return GetPaid_Form_Item[] |
|
| 442 | - */ |
|
| 443 | - public function get_items() { |
|
| 444 | - return $this->items; |
|
| 445 | - } |
|
| 446 | - |
|
| 447 | - /** |
|
| 448 | - * Checks if there's a single subscription group in the submission. |
|
| 449 | - * |
|
| 450 | - * @since 2.3.0 |
|
| 451 | - * @return bool |
|
| 452 | - */ |
|
| 453 | - public function has_subscription_group() { |
|
| 454 | - return $this->has_recurring && getpaid_should_group_subscriptions( $this ) && 1 == count( getpaid_get_subscription_groups( $this ) ); |
|
| 455 | - } |
|
| 456 | - |
|
| 457 | - /** |
|
| 458 | - * Checks if there are multipe subscription groups in the submission. |
|
| 459 | - * |
|
| 460 | - * @since 2.3.0 |
|
| 461 | - * @return bool |
|
| 462 | - */ |
|
| 463 | - public function has_multiple_subscription_groups() { |
|
| 464 | - return $this->has_recurring && 1 < count( getpaid_get_subscription_groups( $this ) ); |
|
| 465 | - } |
|
| 466 | - |
|
| 467 | - /* |
|
| 345 | + /** |
|
| 346 | + * Prepares the submission's items. |
|
| 347 | + * |
|
| 348 | + * @since 1.0.19 |
|
| 349 | + */ |
|
| 350 | + public function process_items() { |
|
| 351 | + |
|
| 352 | + $processor = new GetPaid_Payment_Form_Submission_Items( $this ); |
|
| 353 | + |
|
| 354 | + foreach ( $processor->items as $item ) { |
|
| 355 | + $this->add_item( $item ); |
|
| 356 | + } |
|
| 357 | + |
|
| 358 | + do_action_ref_array( 'getpaid_submissions_process_items', array( &$this ) ); |
|
| 359 | + } |
|
| 360 | + |
|
| 361 | + /** |
|
| 362 | + * Adds an item to the submission. |
|
| 363 | + * |
|
| 364 | + * @since 1.0.19 |
|
| 365 | + * @param GetPaid_Form_Item $item |
|
| 366 | + */ |
|
| 367 | + public function add_item( $item ) { |
|
| 368 | + |
|
| 369 | + // Make sure that it is available for purchase. |
|
| 370 | + if ( ! $item->can_purchase() || isset( $this->items[ $item->get_id() ] ) ) { |
|
| 371 | + return; |
|
| 372 | + } |
|
| 373 | + |
|
| 374 | + // Each submission can only contain one recurring item. |
|
| 375 | + if ( $item->is_recurring() ) { |
|
| 376 | + $this->has_recurring = $item->get_id(); |
|
| 377 | + } |
|
| 378 | + |
|
| 379 | + // Update the items and totals. |
|
| 380 | + $this->items[ $item->get_id() ] = $item; |
|
| 381 | + $this->totals['subtotal']['initial'] += $item->get_sub_total(); |
|
| 382 | + $this->totals['subtotal']['recurring'] += $item->get_recurring_sub_total(); |
|
| 383 | + |
|
| 384 | + } |
|
| 385 | + |
|
| 386 | + /** |
|
| 387 | + * Removes a specific item. |
|
| 388 | + * |
|
| 389 | + * You should not call this method after the discounts and taxes |
|
| 390 | + * have been calculated. |
|
| 391 | + * |
|
| 392 | + * @since 1.0.19 |
|
| 393 | + */ |
|
| 394 | + public function remove_item( $item_id ) { |
|
| 395 | + |
|
| 396 | + if ( isset( $this->items[ $item_id ] ) ) { |
|
| 397 | + $this->totals['subtotal']['initial'] -= $this->items[ $item_id ]->get_sub_total(); |
|
| 398 | + $this->totals['subtotal']['recurring'] -= $this->items[ $item_id ]->get_recurring_sub_total(); |
|
| 399 | + |
|
| 400 | + if ( $this->items[ $item_id ]->is_recurring() ) { |
|
| 401 | + $this->has_recurring = 0; |
|
| 402 | + } |
|
| 403 | + |
|
| 404 | + unset( $this->items[ $item_id ] ); |
|
| 405 | + } |
|
| 406 | + |
|
| 407 | + } |
|
| 408 | + |
|
| 409 | + /** |
|
| 410 | + * Returns the subtotal. |
|
| 411 | + * |
|
| 412 | + * @since 1.0.19 |
|
| 413 | + */ |
|
| 414 | + public function get_subtotal() { |
|
| 415 | + |
|
| 416 | + if ( wpinv_prices_include_tax() ) { |
|
| 417 | + return $this->totals['subtotal']['initial'] - $this->totals['taxes']['initial']; |
|
| 418 | + } |
|
| 419 | + |
|
| 420 | + return $this->totals['subtotal']['initial']; |
|
| 421 | + } |
|
| 422 | + |
|
| 423 | + /** |
|
| 424 | + * Returns the recurring subtotal. |
|
| 425 | + * |
|
| 426 | + * @since 1.0.19 |
|
| 427 | + */ |
|
| 428 | + public function get_recurring_subtotal() { |
|
| 429 | + |
|
| 430 | + if ( wpinv_prices_include_tax() ) { |
|
| 431 | + return $this->totals['subtotal']['recurring'] - $this->totals['taxes']['recurring']; |
|
| 432 | + } |
|
| 433 | + |
|
| 434 | + return $this->totals['subtotal']['recurring']; |
|
| 435 | + } |
|
| 436 | + |
|
| 437 | + /** |
|
| 438 | + * Returns all items. |
|
| 439 | + * |
|
| 440 | + * @since 1.0.19 |
|
| 441 | + * @return GetPaid_Form_Item[] |
|
| 442 | + */ |
|
| 443 | + public function get_items() { |
|
| 444 | + return $this->items; |
|
| 445 | + } |
|
| 446 | + |
|
| 447 | + /** |
|
| 448 | + * Checks if there's a single subscription group in the submission. |
|
| 449 | + * |
|
| 450 | + * @since 2.3.0 |
|
| 451 | + * @return bool |
|
| 452 | + */ |
|
| 453 | + public function has_subscription_group() { |
|
| 454 | + return $this->has_recurring && getpaid_should_group_subscriptions( $this ) && 1 == count( getpaid_get_subscription_groups( $this ) ); |
|
| 455 | + } |
|
| 456 | + |
|
| 457 | + /** |
|
| 458 | + * Checks if there are multipe subscription groups in the submission. |
|
| 459 | + * |
|
| 460 | + * @since 2.3.0 |
|
| 461 | + * @return bool |
|
| 462 | + */ |
|
| 463 | + public function has_multiple_subscription_groups() { |
|
| 464 | + return $this->has_recurring && 1 < count( getpaid_get_subscription_groups( $this ) ); |
|
| 465 | + } |
|
| 466 | + |
|
| 467 | + /* |
|
| 468 | 468 | |-------------------------------------------------------------------------- |
| 469 | 469 | | Taxes |
| 470 | 470 | |-------------------------------------------------------------------------- |
@@ -473,128 +473,128 @@ discard block |
||
| 473 | 473 | | or only one-time. |
| 474 | 474 | */ |
| 475 | 475 | |
| 476 | - /** |
|
| 477 | - * Prepares the submission's taxes. |
|
| 478 | - * |
|
| 479 | - * @since 1.0.19 |
|
| 480 | - */ |
|
| 481 | - public function process_taxes() { |
|
| 482 | - |
|
| 483 | - // Abort if we're not using taxes. |
|
| 484 | - if ( ! $this->use_taxes() ) { |
|
| 485 | - return; |
|
| 486 | - } |
|
| 487 | - |
|
| 488 | - // If a custom country && state has been passed in, use it to calculate taxes. |
|
| 489 | - $country = $this->get_field( 'wpinv_country', 'billing' ); |
|
| 490 | - if ( ! empty( $country ) ) { |
|
| 491 | - $this->country = $country; |
|
| 492 | - } |
|
| 493 | - |
|
| 494 | - $state = $this->get_field( 'wpinv_state', 'billing' ); |
|
| 495 | - if ( ! empty( $state ) ) { |
|
| 496 | - $this->state = $state; |
|
| 497 | - } |
|
| 498 | - |
|
| 499 | - // Confirm if the provided country and the ip country are similar. |
|
| 500 | - $address_confirmed = $this->get_field( 'confirm-address' ); |
|
| 501 | - if ( isset( $_POST['billing']['country'] ) && wpinv_should_validate_vat_number() && getpaid_get_ip_country() != $this->country && empty( $address_confirmed ) ) { |
|
| 502 | - throw new Exception( __( 'The country of your current location must be the same as the country of your billing location or you must confirm the billing address is your home country.', 'invoicing' ) ); |
|
| 503 | - } |
|
| 504 | - |
|
| 505 | - // Abort if the country is not taxable. |
|
| 506 | - if ( ! wpinv_is_country_taxable( $this->country ) ) { |
|
| 507 | - return; |
|
| 508 | - } |
|
| 509 | - |
|
| 510 | - $processor = new GetPaid_Payment_Form_Submission_Taxes( $this ); |
|
| 511 | - |
|
| 512 | - foreach ( $processor->taxes as $tax ) { |
|
| 513 | - $this->add_tax( $tax ); |
|
| 514 | - } |
|
| 515 | - |
|
| 516 | - do_action_ref_array( 'getpaid_submissions_process_taxes', array( &$this ) ); |
|
| 517 | - } |
|
| 518 | - |
|
| 519 | - /** |
|
| 520 | - * Adds a tax to the submission. |
|
| 521 | - * |
|
| 522 | - * @param array $tax An array of tax details. name, initial_tax, and recurring_tax are required. |
|
| 523 | - * @since 1.0.19 |
|
| 524 | - */ |
|
| 525 | - public function add_tax( $tax ) { |
|
| 526 | - |
|
| 527 | - if ( wpinv_round_tax_per_tax_rate() ) { |
|
| 528 | - $tax['initial_tax'] = wpinv_round_amount( $tax['initial_tax'] ); |
|
| 529 | - $tax['recurring_tax'] = wpinv_round_amount( $tax['recurring_tax'] ); |
|
| 530 | - } |
|
| 531 | - |
|
| 532 | - $this->taxes[ $tax['name'] ] = $tax; |
|
| 533 | - $this->totals['taxes']['initial'] += wpinv_sanitize_amount( $tax['initial_tax'] ); |
|
| 534 | - $this->totals['taxes']['recurring'] += wpinv_sanitize_amount( $tax['recurring_tax'] ); |
|
| 535 | - |
|
| 536 | - } |
|
| 537 | - |
|
| 538 | - /** |
|
| 539 | - * Removes a specific tax. |
|
| 540 | - * |
|
| 541 | - * @since 1.0.19 |
|
| 542 | - */ |
|
| 543 | - public function remove_tax( $tax_name ) { |
|
| 544 | - |
|
| 545 | - if ( isset( $this->taxes[ $tax_name ] ) ) { |
|
| 546 | - $this->totals['taxes']['initial'] -= $this->taxes[ $tax_name ]['initial_tax']; |
|
| 547 | - $this->totals['taxes']['recurring'] -= $this->taxes[ $tax_name ]['recurring_tax']; |
|
| 548 | - unset( $this->taxes[ $tax_name ] ); |
|
| 549 | - } |
|
| 550 | - |
|
| 551 | - } |
|
| 552 | - |
|
| 553 | - /** |
|
| 554 | - * Whether or not we'll use taxes for the submission. |
|
| 555 | - * |
|
| 556 | - * @since 1.0.19 |
|
| 557 | - */ |
|
| 558 | - public function use_taxes() { |
|
| 559 | - |
|
| 560 | - $use_taxes = wpinv_use_taxes(); |
|
| 561 | - |
|
| 562 | - if ( $this->has_invoice() && ! $this->invoice->is_taxable() ) { |
|
| 563 | - $use_taxes = false; |
|
| 564 | - } |
|
| 565 | - |
|
| 566 | - return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this ); |
|
| 567 | - |
|
| 568 | - } |
|
| 569 | - |
|
| 570 | - /** |
|
| 571 | - * Returns the tax. |
|
| 572 | - * |
|
| 573 | - * @since 1.0.19 |
|
| 574 | - */ |
|
| 575 | - public function get_tax() { |
|
| 576 | - return $this->totals['taxes']['initial']; |
|
| 577 | - } |
|
| 578 | - |
|
| 579 | - /** |
|
| 580 | - * Returns the recurring tax. |
|
| 581 | - * |
|
| 582 | - * @since 1.0.19 |
|
| 583 | - */ |
|
| 584 | - public function get_recurring_tax() { |
|
| 585 | - return $this->totals['taxes']['recurring']; |
|
| 586 | - } |
|
| 587 | - |
|
| 588 | - /** |
|
| 589 | - * Returns all taxes. |
|
| 590 | - * |
|
| 591 | - * @since 1.0.19 |
|
| 592 | - */ |
|
| 593 | - public function get_taxes() { |
|
| 594 | - return $this->taxes; |
|
| 595 | - } |
|
| 596 | - |
|
| 597 | - /* |
|
| 476 | + /** |
|
| 477 | + * Prepares the submission's taxes. |
|
| 478 | + * |
|
| 479 | + * @since 1.0.19 |
|
| 480 | + */ |
|
| 481 | + public function process_taxes() { |
|
| 482 | + |
|
| 483 | + // Abort if we're not using taxes. |
|
| 484 | + if ( ! $this->use_taxes() ) { |
|
| 485 | + return; |
|
| 486 | + } |
|
| 487 | + |
|
| 488 | + // If a custom country && state has been passed in, use it to calculate taxes. |
|
| 489 | + $country = $this->get_field( 'wpinv_country', 'billing' ); |
|
| 490 | + if ( ! empty( $country ) ) { |
|
| 491 | + $this->country = $country; |
|
| 492 | + } |
|
| 493 | + |
|
| 494 | + $state = $this->get_field( 'wpinv_state', 'billing' ); |
|
| 495 | + if ( ! empty( $state ) ) { |
|
| 496 | + $this->state = $state; |
|
| 497 | + } |
|
| 498 | + |
|
| 499 | + // Confirm if the provided country and the ip country are similar. |
|
| 500 | + $address_confirmed = $this->get_field( 'confirm-address' ); |
|
| 501 | + if ( isset( $_POST['billing']['country'] ) && wpinv_should_validate_vat_number() && getpaid_get_ip_country() != $this->country && empty( $address_confirmed ) ) { |
|
| 502 | + throw new Exception( __( 'The country of your current location must be the same as the country of your billing location or you must confirm the billing address is your home country.', 'invoicing' ) ); |
|
| 503 | + } |
|
| 504 | + |
|
| 505 | + // Abort if the country is not taxable. |
|
| 506 | + if ( ! wpinv_is_country_taxable( $this->country ) ) { |
|
| 507 | + return; |
|
| 508 | + } |
|
| 509 | + |
|
| 510 | + $processor = new GetPaid_Payment_Form_Submission_Taxes( $this ); |
|
| 511 | + |
|
| 512 | + foreach ( $processor->taxes as $tax ) { |
|
| 513 | + $this->add_tax( $tax ); |
|
| 514 | + } |
|
| 515 | + |
|
| 516 | + do_action_ref_array( 'getpaid_submissions_process_taxes', array( &$this ) ); |
|
| 517 | + } |
|
| 518 | + |
|
| 519 | + /** |
|
| 520 | + * Adds a tax to the submission. |
|
| 521 | + * |
|
| 522 | + * @param array $tax An array of tax details. name, initial_tax, and recurring_tax are required. |
|
| 523 | + * @since 1.0.19 |
|
| 524 | + */ |
|
| 525 | + public function add_tax( $tax ) { |
|
| 526 | + |
|
| 527 | + if ( wpinv_round_tax_per_tax_rate() ) { |
|
| 528 | + $tax['initial_tax'] = wpinv_round_amount( $tax['initial_tax'] ); |
|
| 529 | + $tax['recurring_tax'] = wpinv_round_amount( $tax['recurring_tax'] ); |
|
| 530 | + } |
|
| 531 | + |
|
| 532 | + $this->taxes[ $tax['name'] ] = $tax; |
|
| 533 | + $this->totals['taxes']['initial'] += wpinv_sanitize_amount( $tax['initial_tax'] ); |
|
| 534 | + $this->totals['taxes']['recurring'] += wpinv_sanitize_amount( $tax['recurring_tax'] ); |
|
| 535 | + |
|
| 536 | + } |
|
| 537 | + |
|
| 538 | + /** |
|
| 539 | + * Removes a specific tax. |
|
| 540 | + * |
|
| 541 | + * @since 1.0.19 |
|
| 542 | + */ |
|
| 543 | + public function remove_tax( $tax_name ) { |
|
| 544 | + |
|
| 545 | + if ( isset( $this->taxes[ $tax_name ] ) ) { |
|
| 546 | + $this->totals['taxes']['initial'] -= $this->taxes[ $tax_name ]['initial_tax']; |
|
| 547 | + $this->totals['taxes']['recurring'] -= $this->taxes[ $tax_name ]['recurring_tax']; |
|
| 548 | + unset( $this->taxes[ $tax_name ] ); |
|
| 549 | + } |
|
| 550 | + |
|
| 551 | + } |
|
| 552 | + |
|
| 553 | + /** |
|
| 554 | + * Whether or not we'll use taxes for the submission. |
|
| 555 | + * |
|
| 556 | + * @since 1.0.19 |
|
| 557 | + */ |
|
| 558 | + public function use_taxes() { |
|
| 559 | + |
|
| 560 | + $use_taxes = wpinv_use_taxes(); |
|
| 561 | + |
|
| 562 | + if ( $this->has_invoice() && ! $this->invoice->is_taxable() ) { |
|
| 563 | + $use_taxes = false; |
|
| 564 | + } |
|
| 565 | + |
|
| 566 | + return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this ); |
|
| 567 | + |
|
| 568 | + } |
|
| 569 | + |
|
| 570 | + /** |
|
| 571 | + * Returns the tax. |
|
| 572 | + * |
|
| 573 | + * @since 1.0.19 |
|
| 574 | + */ |
|
| 575 | + public function get_tax() { |
|
| 576 | + return $this->totals['taxes']['initial']; |
|
| 577 | + } |
|
| 578 | + |
|
| 579 | + /** |
|
| 580 | + * Returns the recurring tax. |
|
| 581 | + * |
|
| 582 | + * @since 1.0.19 |
|
| 583 | + */ |
|
| 584 | + public function get_recurring_tax() { |
|
| 585 | + return $this->totals['taxes']['recurring']; |
|
| 586 | + } |
|
| 587 | + |
|
| 588 | + /** |
|
| 589 | + * Returns all taxes. |
|
| 590 | + * |
|
| 591 | + * @since 1.0.19 |
|
| 592 | + */ |
|
| 593 | + public function get_taxes() { |
|
| 594 | + return $this->taxes; |
|
| 595 | + } |
|
| 596 | + |
|
| 597 | + /* |
|
| 598 | 598 | |-------------------------------------------------------------------------- |
| 599 | 599 | | Discounts |
| 600 | 600 | |-------------------------------------------------------------------------- |
@@ -603,99 +603,99 @@ discard block |
||
| 603 | 603 | | or only one-time. They also do not have to come from a discount code. |
| 604 | 604 | */ |
| 605 | 605 | |
| 606 | - /** |
|
| 607 | - * Prepares the submission's discount. |
|
| 608 | - * |
|
| 609 | - * @since 1.0.19 |
|
| 610 | - */ |
|
| 611 | - public function process_discount() { |
|
| 612 | - |
|
| 613 | - $initial_total = $this->get_subtotal() + $this->get_fee() + $this->get_tax(); |
|
| 614 | - $recurring_total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax(); |
|
| 615 | - $processor = new GetPaid_Payment_Form_Submission_Discount( $this, $initial_total, $recurring_total ); |
|
| 616 | - |
|
| 617 | - foreach ( $processor->discounts as $discount ) { |
|
| 618 | - $this->add_discount( $discount ); |
|
| 619 | - } |
|
| 620 | - |
|
| 621 | - do_action_ref_array( 'getpaid_submissions_process_discounts', array( &$this ) ); |
|
| 622 | - } |
|
| 623 | - |
|
| 624 | - /** |
|
| 625 | - * Adds a discount to the submission. |
|
| 626 | - * |
|
| 627 | - * @param array $discount An array of discount details. name, initial_discount, and recurring_discount are required. Include discount_code if the discount is from a discount code. |
|
| 628 | - * @since 1.0.19 |
|
| 629 | - */ |
|
| 630 | - public function add_discount( $discount ) { |
|
| 631 | - $this->discounts[ $discount['name'] ] = $discount; |
|
| 632 | - $this->totals['discount']['initial'] += wpinv_sanitize_amount( $discount['initial_discount'] ); |
|
| 633 | - $this->totals['discount']['recurring'] += wpinv_sanitize_amount( $discount['recurring_discount'] ); |
|
| 634 | - } |
|
| 635 | - |
|
| 636 | - /** |
|
| 637 | - * Removes a discount from the submission. |
|
| 638 | - * |
|
| 639 | - * @since 1.0.19 |
|
| 640 | - */ |
|
| 641 | - public function remove_discount( $name ) { |
|
| 642 | - |
|
| 643 | - if ( isset( $this->discounts[ $name ] ) ) { |
|
| 644 | - $this->totals['discount']['initial'] -= $this->discounts[ $name ]['initial_discount']; |
|
| 645 | - $this->totals['discount']['recurring'] -= $this->discounts[ $name ]['recurring_discount']; |
|
| 646 | - unset( $this->discounts[ $name ] ); |
|
| 647 | - } |
|
| 648 | - |
|
| 649 | - } |
|
| 650 | - |
|
| 651 | - /** |
|
| 652 | - * Checks whether there is a discount code associated with this submission. |
|
| 653 | - * |
|
| 654 | - * @since 1.0.19 |
|
| 655 | - * @return bool |
|
| 656 | - */ |
|
| 657 | - public function has_discount_code() { |
|
| 658 | - return ! empty( $this->discounts['discount_code'] ); |
|
| 659 | - } |
|
| 660 | - |
|
| 661 | - /** |
|
| 662 | - * Returns the discount code. |
|
| 663 | - * |
|
| 664 | - * @since 1.0.19 |
|
| 665 | - * @return string |
|
| 666 | - */ |
|
| 667 | - public function get_discount_code() { |
|
| 668 | - return $this->has_discount_code() ? $this->discounts['discount_code']['discount_code'] : ''; |
|
| 669 | - } |
|
| 670 | - |
|
| 671 | - /** |
|
| 672 | - * Returns the discount. |
|
| 673 | - * |
|
| 674 | - * @since 1.0.19 |
|
| 675 | - */ |
|
| 676 | - public function get_discount() { |
|
| 677 | - return $this->totals['discount']['initial']; |
|
| 678 | - } |
|
| 679 | - |
|
| 680 | - /** |
|
| 681 | - * Returns the recurring discount. |
|
| 682 | - * |
|
| 683 | - * @since 1.0.19 |
|
| 684 | - */ |
|
| 685 | - public function get_recurring_discount() { |
|
| 686 | - return $this->totals['discount']['recurring']; |
|
| 687 | - } |
|
| 688 | - |
|
| 689 | - /** |
|
| 690 | - * Returns all discounts. |
|
| 691 | - * |
|
| 692 | - * @since 1.0.19 |
|
| 693 | - */ |
|
| 694 | - public function get_discounts() { |
|
| 695 | - return $this->discounts; |
|
| 696 | - } |
|
| 697 | - |
|
| 698 | - /* |
|
| 606 | + /** |
|
| 607 | + * Prepares the submission's discount. |
|
| 608 | + * |
|
| 609 | + * @since 1.0.19 |
|
| 610 | + */ |
|
| 611 | + public function process_discount() { |
|
| 612 | + |
|
| 613 | + $initial_total = $this->get_subtotal() + $this->get_fee() + $this->get_tax(); |
|
| 614 | + $recurring_total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax(); |
|
| 615 | + $processor = new GetPaid_Payment_Form_Submission_Discount( $this, $initial_total, $recurring_total ); |
|
| 616 | + |
|
| 617 | + foreach ( $processor->discounts as $discount ) { |
|
| 618 | + $this->add_discount( $discount ); |
|
| 619 | + } |
|
| 620 | + |
|
| 621 | + do_action_ref_array( 'getpaid_submissions_process_discounts', array( &$this ) ); |
|
| 622 | + } |
|
| 623 | + |
|
| 624 | + /** |
|
| 625 | + * Adds a discount to the submission. |
|
| 626 | + * |
|
| 627 | + * @param array $discount An array of discount details. name, initial_discount, and recurring_discount are required. Include discount_code if the discount is from a discount code. |
|
| 628 | + * @since 1.0.19 |
|
| 629 | + */ |
|
| 630 | + public function add_discount( $discount ) { |
|
| 631 | + $this->discounts[ $discount['name'] ] = $discount; |
|
| 632 | + $this->totals['discount']['initial'] += wpinv_sanitize_amount( $discount['initial_discount'] ); |
|
| 633 | + $this->totals['discount']['recurring'] += wpinv_sanitize_amount( $discount['recurring_discount'] ); |
|
| 634 | + } |
|
| 635 | + |
|
| 636 | + /** |
|
| 637 | + * Removes a discount from the submission. |
|
| 638 | + * |
|
| 639 | + * @since 1.0.19 |
|
| 640 | + */ |
|
| 641 | + public function remove_discount( $name ) { |
|
| 642 | + |
|
| 643 | + if ( isset( $this->discounts[ $name ] ) ) { |
|
| 644 | + $this->totals['discount']['initial'] -= $this->discounts[ $name ]['initial_discount']; |
|
| 645 | + $this->totals['discount']['recurring'] -= $this->discounts[ $name ]['recurring_discount']; |
|
| 646 | + unset( $this->discounts[ $name ] ); |
|
| 647 | + } |
|
| 648 | + |
|
| 649 | + } |
|
| 650 | + |
|
| 651 | + /** |
|
| 652 | + * Checks whether there is a discount code associated with this submission. |
|
| 653 | + * |
|
| 654 | + * @since 1.0.19 |
|
| 655 | + * @return bool |
|
| 656 | + */ |
|
| 657 | + public function has_discount_code() { |
|
| 658 | + return ! empty( $this->discounts['discount_code'] ); |
|
| 659 | + } |
|
| 660 | + |
|
| 661 | + /** |
|
| 662 | + * Returns the discount code. |
|
| 663 | + * |
|
| 664 | + * @since 1.0.19 |
|
| 665 | + * @return string |
|
| 666 | + */ |
|
| 667 | + public function get_discount_code() { |
|
| 668 | + return $this->has_discount_code() ? $this->discounts['discount_code']['discount_code'] : ''; |
|
| 669 | + } |
|
| 670 | + |
|
| 671 | + /** |
|
| 672 | + * Returns the discount. |
|
| 673 | + * |
|
| 674 | + * @since 1.0.19 |
|
| 675 | + */ |
|
| 676 | + public function get_discount() { |
|
| 677 | + return $this->totals['discount']['initial']; |
|
| 678 | + } |
|
| 679 | + |
|
| 680 | + /** |
|
| 681 | + * Returns the recurring discount. |
|
| 682 | + * |
|
| 683 | + * @since 1.0.19 |
|
| 684 | + */ |
|
| 685 | + public function get_recurring_discount() { |
|
| 686 | + return $this->totals['discount']['recurring']; |
|
| 687 | + } |
|
| 688 | + |
|
| 689 | + /** |
|
| 690 | + * Returns all discounts. |
|
| 691 | + * |
|
| 692 | + * @since 1.0.19 |
|
| 693 | + */ |
|
| 694 | + public function get_discounts() { |
|
| 695 | + return $this->discounts; |
|
| 696 | + } |
|
| 697 | + |
|
| 698 | + /* |
|
| 699 | 699 | |-------------------------------------------------------------------------- |
| 700 | 700 | | Fees |
| 701 | 701 | |-------------------------------------------------------------------------- |
@@ -705,100 +705,100 @@ discard block |
||
| 705 | 705 | | fees. |
| 706 | 706 | */ |
| 707 | 707 | |
| 708 | - /** |
|
| 709 | - * Prepares the submission's fees. |
|
| 710 | - * |
|
| 711 | - * @since 1.0.19 |
|
| 712 | - */ |
|
| 713 | - public function process_fees() { |
|
| 714 | - |
|
| 715 | - $fees_processor = new GetPaid_Payment_Form_Submission_Fees( $this ); |
|
| 716 | - |
|
| 717 | - foreach ( $fees_processor->fees as $fee ) { |
|
| 718 | - $this->add_fee( $fee ); |
|
| 719 | - } |
|
| 720 | - |
|
| 721 | - do_action_ref_array( 'getpaid_submissions_process_fees', array( &$this ) ); |
|
| 722 | - } |
|
| 723 | - |
|
| 724 | - /** |
|
| 725 | - * Adds a fee to the submission. |
|
| 726 | - * |
|
| 727 | - * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required. |
|
| 728 | - * @since 1.0.19 |
|
| 729 | - */ |
|
| 730 | - public function add_fee( $fee ) { |
|
| 731 | - |
|
| 732 | - if ( $fee['name'] == 'shipping' ) { |
|
| 733 | - $this->totals['shipping']['initial'] += wpinv_sanitize_amount( $fee['initial_fee'] ); |
|
| 734 | - $this->totals['shipping']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] ); |
|
| 735 | - return; |
|
| 736 | - } |
|
| 737 | - |
|
| 738 | - $this->fees[ $fee['name'] ] = $fee; |
|
| 739 | - $this->totals['fees']['initial'] += wpinv_sanitize_amount( $fee['initial_fee'] ); |
|
| 740 | - $this->totals['fees']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] ); |
|
| 741 | - |
|
| 742 | - } |
|
| 743 | - |
|
| 744 | - /** |
|
| 745 | - * Removes a fee from the submission. |
|
| 746 | - * |
|
| 747 | - * @since 1.0.19 |
|
| 748 | - */ |
|
| 749 | - public function remove_fee( $name ) { |
|
| 750 | - |
|
| 751 | - if ( isset( $this->fees[ $name ] ) ) { |
|
| 752 | - $this->totals['fees']['initial'] -= $this->fees[ $name ]['initial_fee']; |
|
| 753 | - $this->totals['fees']['recurring'] -= $this->fees[ $name ]['recurring_fee']; |
|
| 754 | - unset( $this->fees[ $name ] ); |
|
| 755 | - } |
|
| 756 | - |
|
| 757 | - if ( 'shipping' == $name ) { |
|
| 758 | - $this->totals['shipping']['initial'] = 0; |
|
| 759 | - $this->totals['shipping']['recurring'] = 0; |
|
| 760 | - } |
|
| 761 | - |
|
| 762 | - } |
|
| 763 | - |
|
| 764 | - /** |
|
| 765 | - * Returns the fees. |
|
| 766 | - * |
|
| 767 | - * @since 1.0.19 |
|
| 768 | - */ |
|
| 769 | - public function get_fee() { |
|
| 770 | - return $this->totals['fees']['initial']; |
|
| 771 | - } |
|
| 772 | - |
|
| 773 | - /** |
|
| 774 | - * Returns the recurring fees. |
|
| 775 | - * |
|
| 776 | - * @since 1.0.19 |
|
| 777 | - */ |
|
| 778 | - public function get_recurring_fee() { |
|
| 779 | - return $this->totals['fees']['recurring']; |
|
| 780 | - } |
|
| 781 | - |
|
| 782 | - /** |
|
| 783 | - * Returns all fees. |
|
| 784 | - * |
|
| 785 | - * @since 1.0.19 |
|
| 786 | - */ |
|
| 787 | - public function get_fees() { |
|
| 788 | - return $this->fees; |
|
| 789 | - } |
|
| 790 | - |
|
| 791 | - /** |
|
| 792 | - * Checks if there are any fees for the form. |
|
| 793 | - * |
|
| 794 | - * @return bool |
|
| 795 | - * @since 1.0.19 |
|
| 796 | - */ |
|
| 797 | - public function has_fees() { |
|
| 798 | - return count( $this->fees ) !== 0; |
|
| 799 | - } |
|
| 800 | - |
|
| 801 | - /* |
|
| 708 | + /** |
|
| 709 | + * Prepares the submission's fees. |
|
| 710 | + * |
|
| 711 | + * @since 1.0.19 |
|
| 712 | + */ |
|
| 713 | + public function process_fees() { |
|
| 714 | + |
|
| 715 | + $fees_processor = new GetPaid_Payment_Form_Submission_Fees( $this ); |
|
| 716 | + |
|
| 717 | + foreach ( $fees_processor->fees as $fee ) { |
|
| 718 | + $this->add_fee( $fee ); |
|
| 719 | + } |
|
| 720 | + |
|
| 721 | + do_action_ref_array( 'getpaid_submissions_process_fees', array( &$this ) ); |
|
| 722 | + } |
|
| 723 | + |
|
| 724 | + /** |
|
| 725 | + * Adds a fee to the submission. |
|
| 726 | + * |
|
| 727 | + * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required. |
|
| 728 | + * @since 1.0.19 |
|
| 729 | + */ |
|
| 730 | + public function add_fee( $fee ) { |
|
| 731 | + |
|
| 732 | + if ( $fee['name'] == 'shipping' ) { |
|
| 733 | + $this->totals['shipping']['initial'] += wpinv_sanitize_amount( $fee['initial_fee'] ); |
|
| 734 | + $this->totals['shipping']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] ); |
|
| 735 | + return; |
|
| 736 | + } |
|
| 737 | + |
|
| 738 | + $this->fees[ $fee['name'] ] = $fee; |
|
| 739 | + $this->totals['fees']['initial'] += wpinv_sanitize_amount( $fee['initial_fee'] ); |
|
| 740 | + $this->totals['fees']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] ); |
|
| 741 | + |
|
| 742 | + } |
|
| 743 | + |
|
| 744 | + /** |
|
| 745 | + * Removes a fee from the submission. |
|
| 746 | + * |
|
| 747 | + * @since 1.0.19 |
|
| 748 | + */ |
|
| 749 | + public function remove_fee( $name ) { |
|
| 750 | + |
|
| 751 | + if ( isset( $this->fees[ $name ] ) ) { |
|
| 752 | + $this->totals['fees']['initial'] -= $this->fees[ $name ]['initial_fee']; |
|
| 753 | + $this->totals['fees']['recurring'] -= $this->fees[ $name ]['recurring_fee']; |
|
| 754 | + unset( $this->fees[ $name ] ); |
|
| 755 | + } |
|
| 756 | + |
|
| 757 | + if ( 'shipping' == $name ) { |
|
| 758 | + $this->totals['shipping']['initial'] = 0; |
|
| 759 | + $this->totals['shipping']['recurring'] = 0; |
|
| 760 | + } |
|
| 761 | + |
|
| 762 | + } |
|
| 763 | + |
|
| 764 | + /** |
|
| 765 | + * Returns the fees. |
|
| 766 | + * |
|
| 767 | + * @since 1.0.19 |
|
| 768 | + */ |
|
| 769 | + public function get_fee() { |
|
| 770 | + return $this->totals['fees']['initial']; |
|
| 771 | + } |
|
| 772 | + |
|
| 773 | + /** |
|
| 774 | + * Returns the recurring fees. |
|
| 775 | + * |
|
| 776 | + * @since 1.0.19 |
|
| 777 | + */ |
|
| 778 | + public function get_recurring_fee() { |
|
| 779 | + return $this->totals['fees']['recurring']; |
|
| 780 | + } |
|
| 781 | + |
|
| 782 | + /** |
|
| 783 | + * Returns all fees. |
|
| 784 | + * |
|
| 785 | + * @since 1.0.19 |
|
| 786 | + */ |
|
| 787 | + public function get_fees() { |
|
| 788 | + return $this->fees; |
|
| 789 | + } |
|
| 790 | + |
|
| 791 | + /** |
|
| 792 | + * Checks if there are any fees for the form. |
|
| 793 | + * |
|
| 794 | + * @return bool |
|
| 795 | + * @since 1.0.19 |
|
| 796 | + */ |
|
| 797 | + public function has_fees() { |
|
| 798 | + return count( $this->fees ) !== 0; |
|
| 799 | + } |
|
| 800 | + |
|
| 801 | + /* |
|
| 802 | 802 | |-------------------------------------------------------------------------- |
| 803 | 803 | | MISC |
| 804 | 804 | |-------------------------------------------------------------------------- |
@@ -806,147 +806,147 @@ discard block |
||
| 806 | 806 | | Extra submission functions. |
| 807 | 807 | */ |
| 808 | 808 | |
| 809 | - /** |
|
| 810 | - * Returns the shipping amount. |
|
| 811 | - * |
|
| 812 | - * @since 1.0.19 |
|
| 813 | - */ |
|
| 814 | - public function get_shipping() { |
|
| 815 | - return $this->totals['shipping']['initial']; |
|
| 816 | - } |
|
| 817 | - |
|
| 818 | - /** |
|
| 819 | - * Returns the recurring shipping. |
|
| 820 | - * |
|
| 821 | - * @since 1.0.19 |
|
| 822 | - */ |
|
| 823 | - public function get_recurring_shipping() { |
|
| 824 | - return $this->totals['shipping']['recurring']; |
|
| 825 | - } |
|
| 826 | - |
|
| 827 | - /** |
|
| 828 | - * Checks if there are any shipping fees for the form. |
|
| 829 | - * |
|
| 830 | - * @return bool |
|
| 831 | - * @since 1.0.19 |
|
| 832 | - */ |
|
| 833 | - public function has_shipping() { |
|
| 834 | - return apply_filters( 'getpaid_payment_form_has_shipping', false, $this ); |
|
| 835 | - } |
|
| 836 | - |
|
| 837 | - /** |
|
| 838 | - * Checks if this is the initial fetch. |
|
| 839 | - * |
|
| 840 | - * @return bool |
|
| 841 | - * @since 1.0.19 |
|
| 842 | - */ |
|
| 843 | - public function is_initial_fetch() { |
|
| 844 | - return empty( $this->data['initial_state'] ); |
|
| 845 | - } |
|
| 846 | - |
|
| 847 | - /** |
|
| 848 | - * Returns the total amount to collect for this submission. |
|
| 849 | - * |
|
| 850 | - * @since 1.0.19 |
|
| 851 | - */ |
|
| 852 | - public function get_total() { |
|
| 853 | - $total = $this->get_subtotal() + $this->get_fee() + $this->get_tax() + $this->get_shipping() - $this->get_discount(); |
|
| 854 | - return max( $total, 0 ); |
|
| 855 | - } |
|
| 856 | - |
|
| 857 | - /** |
|
| 858 | - * Returns the recurring total amount to collect for this submission. |
|
| 859 | - * |
|
| 860 | - * @since 1.0.19 |
|
| 861 | - */ |
|
| 862 | - public function get_recurring_total() { |
|
| 863 | - $total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax() + $this->get_recurring_shipping() - $this->get_recurring_discount(); |
|
| 864 | - return max( $total, 0 ); |
|
| 865 | - } |
|
| 866 | - |
|
| 867 | - /** |
|
| 868 | - * Whether payment details should be collected for this submission. |
|
| 869 | - * |
|
| 870 | - * @since 1.0.19 |
|
| 871 | - */ |
|
| 872 | - public function should_collect_payment_details() { |
|
| 873 | - $initial = $this->get_total(); |
|
| 874 | - $recurring = $this->get_recurring_total(); |
|
| 875 | - |
|
| 876 | - if ( $this->has_recurring == 0 ) { |
|
| 877 | - $recurring = 0; |
|
| 878 | - } |
|
| 879 | - |
|
| 880 | - $collect = $initial > 0 || $recurring > 0; |
|
| 881 | - return apply_filters( 'getpaid_submission_should_collect_payment_details', $collect, $this ); |
|
| 882 | - } |
|
| 883 | - |
|
| 884 | - /** |
|
| 885 | - * Returns the billing email of the user. |
|
| 886 | - * |
|
| 887 | - * @since 1.0.19 |
|
| 888 | - */ |
|
| 889 | - public function get_billing_email() { |
|
| 890 | - return apply_filters( 'getpaid_get_submission_billing_email', $this->get_field( 'billing_email' ), $this ); |
|
| 891 | - } |
|
| 892 | - |
|
| 893 | - /** |
|
| 894 | - * Checks if the submitter has a billing email. |
|
| 895 | - * |
|
| 896 | - * @since 1.0.19 |
|
| 897 | - */ |
|
| 898 | - public function has_billing_email() { |
|
| 899 | - $billing_email = $this->get_billing_email(); |
|
| 900 | - return ! empty( $billing_email ) && is_email( $billing_email ); |
|
| 901 | - } |
|
| 902 | - |
|
| 903 | - /** |
|
| 904 | - * Returns the appropriate currency for the submission. |
|
| 905 | - * |
|
| 906 | - * @since 1.0.19 |
|
| 907 | - * @return string |
|
| 908 | - */ |
|
| 909 | - public function get_currency() { |
|
| 910 | - return $this->has_invoice() ? $this->invoice->get_currency() : wpinv_get_currency(); |
|
| 911 | - } |
|
| 912 | - |
|
| 913 | - /** |
|
| 914 | - * Returns the raw submission data. |
|
| 915 | - * |
|
| 916 | - * @since 1.0.19 |
|
| 917 | - * @return array |
|
| 918 | - */ |
|
| 919 | - public function get_data() { |
|
| 920 | - return $this->data; |
|
| 921 | - } |
|
| 922 | - |
|
| 923 | - /** |
|
| 924 | - * Returns a field from the submission data |
|
| 925 | - * |
|
| 926 | - * @param string $field |
|
| 927 | - * @since 1.0.19 |
|
| 928 | - * @return mixed|null |
|
| 929 | - */ |
|
| 930 | - public function get_field( $field, $sub_array_key = null ) { |
|
| 931 | - return getpaid_get_array_field( $this->data, $field, $sub_array_key ); |
|
| 932 | - } |
|
| 933 | - |
|
| 934 | - /** |
|
| 935 | - * Checks if a required field is set. |
|
| 936 | - * |
|
| 937 | - * @since 1.0.19 |
|
| 938 | - */ |
|
| 939 | - public function is_required_field_set( $field ) { |
|
| 940 | - return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] ); |
|
| 941 | - } |
|
| 942 | - |
|
| 943 | - /** |
|
| 944 | - * Formats an amount |
|
| 945 | - * |
|
| 946 | - * @since 1.0.19 |
|
| 947 | - */ |
|
| 948 | - public function format_amount( $amount ) { |
|
| 949 | - return wpinv_price( $amount, $this->get_currency() ); |
|
| 950 | - } |
|
| 809 | + /** |
|
| 810 | + * Returns the shipping amount. |
|
| 811 | + * |
|
| 812 | + * @since 1.0.19 |
|
| 813 | + */ |
|
| 814 | + public function get_shipping() { |
|
| 815 | + return $this->totals['shipping']['initial']; |
|
| 816 | + } |
|
| 817 | + |
|
| 818 | + /** |
|
| 819 | + * Returns the recurring shipping. |
|
| 820 | + * |
|
| 821 | + * @since 1.0.19 |
|
| 822 | + */ |
|
| 823 | + public function get_recurring_shipping() { |
|
| 824 | + return $this->totals['shipping']['recurring']; |
|
| 825 | + } |
|
| 826 | + |
|
| 827 | + /** |
|
| 828 | + * Checks if there are any shipping fees for the form. |
|
| 829 | + * |
|
| 830 | + * @return bool |
|
| 831 | + * @since 1.0.19 |
|
| 832 | + */ |
|
| 833 | + public function has_shipping() { |
|
| 834 | + return apply_filters( 'getpaid_payment_form_has_shipping', false, $this ); |
|
| 835 | + } |
|
| 836 | + |
|
| 837 | + /** |
|
| 838 | + * Checks if this is the initial fetch. |
|
| 839 | + * |
|
| 840 | + * @return bool |
|
| 841 | + * @since 1.0.19 |
|
| 842 | + */ |
|
| 843 | + public function is_initial_fetch() { |
|
| 844 | + return empty( $this->data['initial_state'] ); |
|
| 845 | + } |
|
| 846 | + |
|
| 847 | + /** |
|
| 848 | + * Returns the total amount to collect for this submission. |
|
| 849 | + * |
|
| 850 | + * @since 1.0.19 |
|
| 851 | + */ |
|
| 852 | + public function get_total() { |
|
| 853 | + $total = $this->get_subtotal() + $this->get_fee() + $this->get_tax() + $this->get_shipping() - $this->get_discount(); |
|
| 854 | + return max( $total, 0 ); |
|
| 855 | + } |
|
| 856 | + |
|
| 857 | + /** |
|
| 858 | + * Returns the recurring total amount to collect for this submission. |
|
| 859 | + * |
|
| 860 | + * @since 1.0.19 |
|
| 861 | + */ |
|
| 862 | + public function get_recurring_total() { |
|
| 863 | + $total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax() + $this->get_recurring_shipping() - $this->get_recurring_discount(); |
|
| 864 | + return max( $total, 0 ); |
|
| 865 | + } |
|
| 866 | + |
|
| 867 | + /** |
|
| 868 | + * Whether payment details should be collected for this submission. |
|
| 869 | + * |
|
| 870 | + * @since 1.0.19 |
|
| 871 | + */ |
|
| 872 | + public function should_collect_payment_details() { |
|
| 873 | + $initial = $this->get_total(); |
|
| 874 | + $recurring = $this->get_recurring_total(); |
|
| 875 | + |
|
| 876 | + if ( $this->has_recurring == 0 ) { |
|
| 877 | + $recurring = 0; |
|
| 878 | + } |
|
| 879 | + |
|
| 880 | + $collect = $initial > 0 || $recurring > 0; |
|
| 881 | + return apply_filters( 'getpaid_submission_should_collect_payment_details', $collect, $this ); |
|
| 882 | + } |
|
| 883 | + |
|
| 884 | + /** |
|
| 885 | + * Returns the billing email of the user. |
|
| 886 | + * |
|
| 887 | + * @since 1.0.19 |
|
| 888 | + */ |
|
| 889 | + public function get_billing_email() { |
|
| 890 | + return apply_filters( 'getpaid_get_submission_billing_email', $this->get_field( 'billing_email' ), $this ); |
|
| 891 | + } |
|
| 892 | + |
|
| 893 | + /** |
|
| 894 | + * Checks if the submitter has a billing email. |
|
| 895 | + * |
|
| 896 | + * @since 1.0.19 |
|
| 897 | + */ |
|
| 898 | + public function has_billing_email() { |
|
| 899 | + $billing_email = $this->get_billing_email(); |
|
| 900 | + return ! empty( $billing_email ) && is_email( $billing_email ); |
|
| 901 | + } |
|
| 902 | + |
|
| 903 | + /** |
|
| 904 | + * Returns the appropriate currency for the submission. |
|
| 905 | + * |
|
| 906 | + * @since 1.0.19 |
|
| 907 | + * @return string |
|
| 908 | + */ |
|
| 909 | + public function get_currency() { |
|
| 910 | + return $this->has_invoice() ? $this->invoice->get_currency() : wpinv_get_currency(); |
|
| 911 | + } |
|
| 912 | + |
|
| 913 | + /** |
|
| 914 | + * Returns the raw submission data. |
|
| 915 | + * |
|
| 916 | + * @since 1.0.19 |
|
| 917 | + * @return array |
|
| 918 | + */ |
|
| 919 | + public function get_data() { |
|
| 920 | + return $this->data; |
|
| 921 | + } |
|
| 922 | + |
|
| 923 | + /** |
|
| 924 | + * Returns a field from the submission data |
|
| 925 | + * |
|
| 926 | + * @param string $field |
|
| 927 | + * @since 1.0.19 |
|
| 928 | + * @return mixed|null |
|
| 929 | + */ |
|
| 930 | + public function get_field( $field, $sub_array_key = null ) { |
|
| 931 | + return getpaid_get_array_field( $this->data, $field, $sub_array_key ); |
|
| 932 | + } |
|
| 933 | + |
|
| 934 | + /** |
|
| 935 | + * Checks if a required field is set. |
|
| 936 | + * |
|
| 937 | + * @since 1.0.19 |
|
| 938 | + */ |
|
| 939 | + public function is_required_field_set( $field ) { |
|
| 940 | + return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] ); |
|
| 941 | + } |
|
| 942 | + |
|
| 943 | + /** |
|
| 944 | + * Formats an amount |
|
| 945 | + * |
|
| 946 | + * @since 1.0.19 |
|
| 947 | + */ |
|
| 948 | + public function format_amount( $amount ) { |
|
| 949 | + return wpinv_price( $amount, $this->get_currency() ); |
|
| 950 | + } |
|
| 951 | 951 | |
| 952 | 952 | } |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 2 | +if (!defined('ABSPATH')) { |
|
| 3 | 3 | exit; |
| 4 | 4 | } |
| 5 | 5 | |
@@ -146,8 +146,8 @@ discard block |
||
| 146 | 146 | $this->state = wpinv_get_default_state(); |
| 147 | 147 | |
| 148 | 148 | // Do we have an actual submission? |
| 149 | - if ( isset( $_POST['getpaid_payment_form_submission'] ) ) { |
|
| 150 | - $this->load_data( $_POST ); |
|
| 149 | + if (isset($_POST['getpaid_payment_form_submission'])) { |
|
| 150 | + $this->load_data($_POST); |
|
| 151 | 151 | } |
| 152 | 152 | |
| 153 | 153 | } |
@@ -157,19 +157,19 @@ discard block |
||
| 157 | 157 | * |
| 158 | 158 | * @param array $data |
| 159 | 159 | */ |
| 160 | - public function load_data( $data ) { |
|
| 160 | + public function load_data($data) { |
|
| 161 | 161 | |
| 162 | 162 | // Remove slashes from the submitted data... |
| 163 | - $data = wp_kses_post_deep( wp_unslash( $data ) ); |
|
| 163 | + $data = wp_kses_post_deep(wp_unslash($data)); |
|
| 164 | 164 | |
| 165 | 165 | // Allow plugins to filter the data. |
| 166 | - $data = apply_filters( 'getpaid_submission_data', $data, $this ); |
|
| 166 | + $data = apply_filters('getpaid_submission_data', $data, $this); |
|
| 167 | 167 | |
| 168 | 168 | // Cache it... |
| 169 | 169 | $this->data = $data; |
| 170 | 170 | |
| 171 | 171 | // Then generate a unique id from the data. |
| 172 | - $this->id = md5( wp_json_encode( $data ) ); |
|
| 172 | + $this->id = md5(wp_json_encode($data)); |
|
| 173 | 173 | |
| 174 | 174 | // Finally, process the submission. |
| 175 | 175 | try { |
@@ -179,30 +179,30 @@ discard block |
||
| 179 | 179 | $processors = apply_filters( |
| 180 | 180 | 'getpaid_payment_form_submission_processors', |
| 181 | 181 | array( |
| 182 | - array( $this, 'process_payment_form' ), |
|
| 183 | - array( $this, 'process_invoice' ), |
|
| 184 | - array( $this, 'process_fees' ), |
|
| 185 | - array( $this, 'process_items' ), |
|
| 186 | - array( $this, 'process_discount' ), |
|
| 187 | - array( $this, 'process_taxes' ), |
|
| 182 | + array($this, 'process_payment_form'), |
|
| 183 | + array($this, 'process_invoice'), |
|
| 184 | + array($this, 'process_fees'), |
|
| 185 | + array($this, 'process_items'), |
|
| 186 | + array($this, 'process_discount'), |
|
| 187 | + array($this, 'process_taxes'), |
|
| 188 | 188 | ), |
| 189 | 189 | $this |
| 190 | 190 | ); |
| 191 | 191 | |
| 192 | - foreach ( $processors as $processor ) { |
|
| 193 | - call_user_func_array( $processor, array( &$this ) ); |
|
| 192 | + foreach ($processors as $processor) { |
|
| 193 | + call_user_func_array($processor, array(&$this)); |
|
| 194 | 194 | } |
| 195 | 195 | |
| 196 | - } catch( GetPaid_Payment_Exception $e ) { |
|
| 196 | + } catch (GetPaid_Payment_Exception $e) { |
|
| 197 | 197 | $this->last_error = $e->getMessage(); |
| 198 | 198 | $this->last_error_code = $e->getErrorCode(); |
| 199 | - } catch ( Exception $e ) { |
|
| 199 | + } catch (Exception $e) { |
|
| 200 | 200 | $this->last_error = $e->getMessage(); |
| 201 | 201 | $this->last_error_code = $e->getCode(); |
| 202 | 202 | } |
| 203 | 203 | |
| 204 | 204 | // Fired when we are done processing a submission. |
| 205 | - do_action_ref_array( 'getpaid_process_submission', array( &$this ) ); |
|
| 205 | + do_action_ref_array('getpaid_process_submission', array(&$this)); |
|
| 206 | 206 | |
| 207 | 207 | } |
| 208 | 208 | |
@@ -223,18 +223,18 @@ discard block |
||
| 223 | 223 | public function process_payment_form() { |
| 224 | 224 | |
| 225 | 225 | // Every submission needs an active payment form. |
| 226 | - if ( empty( $this->data['form_id'] ) ) { |
|
| 227 | - throw new Exception( __( 'Missing payment form', 'invoicing' ) ); |
|
| 226 | + if (empty($this->data['form_id'])) { |
|
| 227 | + throw new Exception(__('Missing payment form', 'invoicing')); |
|
| 228 | 228 | } |
| 229 | 229 | |
| 230 | 230 | // Fetch the payment form. |
| 231 | - $this->payment_form = new GetPaid_Payment_Form( $this->data['form_id'] ); |
|
| 231 | + $this->payment_form = new GetPaid_Payment_Form($this->data['form_id']); |
|
| 232 | 232 | |
| 233 | - if ( ! $this->payment_form->is_active() ) { |
|
| 234 | - throw new Exception( __( 'Payment form not active', 'invoicing' ) ); |
|
| 233 | + if (!$this->payment_form->is_active()) { |
|
| 234 | + throw new Exception(__('Payment form not active', 'invoicing')); |
|
| 235 | 235 | } |
| 236 | 236 | |
| 237 | - do_action_ref_array( 'getpaid_submissions_process_payment_form', array( &$this ) ); |
|
| 237 | + do_action_ref_array('getpaid_submissions_process_payment_form', array(&$this)); |
|
| 238 | 238 | } |
| 239 | 239 | |
| 240 | 240 | /** |
@@ -264,53 +264,53 @@ discard block |
||
| 264 | 264 | public function process_invoice() { |
| 265 | 265 | |
| 266 | 266 | // Abort if there is no invoice. |
| 267 | - if ( empty( $this->data['invoice_id'] ) ) { |
|
| 267 | + if (empty($this->data['invoice_id'])) { |
|
| 268 | 268 | return; |
| 269 | 269 | } |
| 270 | 270 | |
| 271 | 271 | // If the submission is for an existing invoice, ensure that it exists |
| 272 | 272 | // and that it is not paid for. |
| 273 | - $invoice = wpinv_get_invoice( $this->data['invoice_id'] ); |
|
| 273 | + $invoice = wpinv_get_invoice($this->data['invoice_id']); |
|
| 274 | 274 | |
| 275 | - if ( empty( $invoice ) ) { |
|
| 276 | - throw new Exception( __( 'Invalid invoice', 'invoicing' ) ); |
|
| 275 | + if (empty($invoice)) { |
|
| 276 | + throw new Exception(__('Invalid invoice', 'invoicing')); |
|
| 277 | 277 | } |
| 278 | 278 | |
| 279 | - if ( $invoice->is_paid() ) { |
|
| 280 | - throw new Exception( __( 'This invoice is already paid for.', 'invoicing' ) ); |
|
| 279 | + if ($invoice->is_paid()) { |
|
| 280 | + throw new Exception(__('This invoice is already paid for.', 'invoicing')); |
|
| 281 | 281 | } |
| 282 | 282 | |
| 283 | 283 | $this->payment_form->invoice = $invoice; |
| 284 | - if ( ! $this->payment_form->is_default() ) { |
|
| 284 | + if (!$this->payment_form->is_default()) { |
|
| 285 | 285 | |
| 286 | 286 | $items = array(); |
| 287 | 287 | $item_ids = array(); |
| 288 | 288 | |
| 289 | - foreach ( $invoice->get_items() as $item ) { |
|
| 290 | - if ( ! in_array( $item->get_id(), $item_ids ) ) { |
|
| 289 | + foreach ($invoice->get_items() as $item) { |
|
| 290 | + if (!in_array($item->get_id(), $item_ids)) { |
|
| 291 | 291 | $item_ids[] = $item->get_id(); |
| 292 | 292 | $items[] = $item; |
| 293 | 293 | } |
| 294 | 294 | } |
| 295 | 295 | |
| 296 | - foreach ( $this->payment_form->get_items() as $item ) { |
|
| 297 | - if ( ! in_array( $item->get_id(), $item_ids ) ) { |
|
| 296 | + foreach ($this->payment_form->get_items() as $item) { |
|
| 297 | + if (!in_array($item->get_id(), $item_ids)) { |
|
| 298 | 298 | $item_ids[] = $item->get_id(); |
| 299 | 299 | $items[] = $item; |
| 300 | 300 | } |
| 301 | 301 | } |
| 302 | 302 | |
| 303 | - $this->payment_form->set_items( $items ); |
|
| 303 | + $this->payment_form->set_items($items); |
|
| 304 | 304 | |
| 305 | 305 | } else { |
| 306 | - $this->payment_form->set_items( $invoice->get_items() ); |
|
| 306 | + $this->payment_form->set_items($invoice->get_items()); |
|
| 307 | 307 | } |
| 308 | 308 | |
| 309 | 309 | $this->country = $invoice->get_country(); |
| 310 | 310 | $this->state = $invoice->get_state(); |
| 311 | 311 | $this->invoice = $invoice; |
| 312 | 312 | |
| 313 | - do_action_ref_array( 'getpaid_submissions_process_invoice', array( &$this ) ); |
|
| 313 | + do_action_ref_array('getpaid_submissions_process_invoice', array(&$this)); |
|
| 314 | 314 | } |
| 315 | 315 | |
| 316 | 316 | /** |
@@ -330,7 +330,7 @@ discard block |
||
| 330 | 330 | * @return bool |
| 331 | 331 | */ |
| 332 | 332 | public function has_invoice() { |
| 333 | - return ! empty( $this->invoice ); |
|
| 333 | + return !empty($this->invoice); |
|
| 334 | 334 | } |
| 335 | 335 | |
| 336 | 336 | /* |
@@ -349,13 +349,13 @@ discard block |
||
| 349 | 349 | */ |
| 350 | 350 | public function process_items() { |
| 351 | 351 | |
| 352 | - $processor = new GetPaid_Payment_Form_Submission_Items( $this ); |
|
| 352 | + $processor = new GetPaid_Payment_Form_Submission_Items($this); |
|
| 353 | 353 | |
| 354 | - foreach ( $processor->items as $item ) { |
|
| 355 | - $this->add_item( $item ); |
|
| 354 | + foreach ($processor->items as $item) { |
|
| 355 | + $this->add_item($item); |
|
| 356 | 356 | } |
| 357 | 357 | |
| 358 | - do_action_ref_array( 'getpaid_submissions_process_items', array( &$this ) ); |
|
| 358 | + do_action_ref_array('getpaid_submissions_process_items', array(&$this)); |
|
| 359 | 359 | } |
| 360 | 360 | |
| 361 | 361 | /** |
@@ -364,20 +364,20 @@ discard block |
||
| 364 | 364 | * @since 1.0.19 |
| 365 | 365 | * @param GetPaid_Form_Item $item |
| 366 | 366 | */ |
| 367 | - public function add_item( $item ) { |
|
| 367 | + public function add_item($item) { |
|
| 368 | 368 | |
| 369 | 369 | // Make sure that it is available for purchase. |
| 370 | - if ( ! $item->can_purchase() || isset( $this->items[ $item->get_id() ] ) ) { |
|
| 370 | + if (!$item->can_purchase() || isset($this->items[$item->get_id()])) { |
|
| 371 | 371 | return; |
| 372 | 372 | } |
| 373 | 373 | |
| 374 | 374 | // Each submission can only contain one recurring item. |
| 375 | - if ( $item->is_recurring() ) { |
|
| 375 | + if ($item->is_recurring()) { |
|
| 376 | 376 | $this->has_recurring = $item->get_id(); |
| 377 | 377 | } |
| 378 | 378 | |
| 379 | 379 | // Update the items and totals. |
| 380 | - $this->items[ $item->get_id() ] = $item; |
|
| 380 | + $this->items[$item->get_id()] = $item; |
|
| 381 | 381 | $this->totals['subtotal']['initial'] += $item->get_sub_total(); |
| 382 | 382 | $this->totals['subtotal']['recurring'] += $item->get_recurring_sub_total(); |
| 383 | 383 | |
@@ -391,17 +391,17 @@ discard block |
||
| 391 | 391 | * |
| 392 | 392 | * @since 1.0.19 |
| 393 | 393 | */ |
| 394 | - public function remove_item( $item_id ) { |
|
| 394 | + public function remove_item($item_id) { |
|
| 395 | 395 | |
| 396 | - if ( isset( $this->items[ $item_id ] ) ) { |
|
| 397 | - $this->totals['subtotal']['initial'] -= $this->items[ $item_id ]->get_sub_total(); |
|
| 398 | - $this->totals['subtotal']['recurring'] -= $this->items[ $item_id ]->get_recurring_sub_total(); |
|
| 396 | + if (isset($this->items[$item_id])) { |
|
| 397 | + $this->totals['subtotal']['initial'] -= $this->items[$item_id]->get_sub_total(); |
|
| 398 | + $this->totals['subtotal']['recurring'] -= $this->items[$item_id]->get_recurring_sub_total(); |
|
| 399 | 399 | |
| 400 | - if ( $this->items[ $item_id ]->is_recurring() ) { |
|
| 400 | + if ($this->items[$item_id]->is_recurring()) { |
|
| 401 | 401 | $this->has_recurring = 0; |
| 402 | 402 | } |
| 403 | 403 | |
| 404 | - unset( $this->items[ $item_id ] ); |
|
| 404 | + unset($this->items[$item_id]); |
|
| 405 | 405 | } |
| 406 | 406 | |
| 407 | 407 | } |
@@ -413,7 +413,7 @@ discard block |
||
| 413 | 413 | */ |
| 414 | 414 | public function get_subtotal() { |
| 415 | 415 | |
| 416 | - if ( wpinv_prices_include_tax() ) { |
|
| 416 | + if (wpinv_prices_include_tax()) { |
|
| 417 | 417 | return $this->totals['subtotal']['initial'] - $this->totals['taxes']['initial']; |
| 418 | 418 | } |
| 419 | 419 | |
@@ -427,7 +427,7 @@ discard block |
||
| 427 | 427 | */ |
| 428 | 428 | public function get_recurring_subtotal() { |
| 429 | 429 | |
| 430 | - if ( wpinv_prices_include_tax() ) { |
|
| 430 | + if (wpinv_prices_include_tax()) { |
|
| 431 | 431 | return $this->totals['subtotal']['recurring'] - $this->totals['taxes']['recurring']; |
| 432 | 432 | } |
| 433 | 433 | |
@@ -451,7 +451,7 @@ discard block |
||
| 451 | 451 | * @return bool |
| 452 | 452 | */ |
| 453 | 453 | public function has_subscription_group() { |
| 454 | - return $this->has_recurring && getpaid_should_group_subscriptions( $this ) && 1 == count( getpaid_get_subscription_groups( $this ) ); |
|
| 454 | + return $this->has_recurring && getpaid_should_group_subscriptions($this) && 1 == count(getpaid_get_subscription_groups($this)); |
|
| 455 | 455 | } |
| 456 | 456 | |
| 457 | 457 | /** |
@@ -461,7 +461,7 @@ discard block |
||
| 461 | 461 | * @return bool |
| 462 | 462 | */ |
| 463 | 463 | public function has_multiple_subscription_groups() { |
| 464 | - return $this->has_recurring && 1 < count( getpaid_get_subscription_groups( $this ) ); |
|
| 464 | + return $this->has_recurring && 1 < count(getpaid_get_subscription_groups($this)); |
|
| 465 | 465 | } |
| 466 | 466 | |
| 467 | 467 | /* |
@@ -481,39 +481,39 @@ discard block |
||
| 481 | 481 | public function process_taxes() { |
| 482 | 482 | |
| 483 | 483 | // Abort if we're not using taxes. |
| 484 | - if ( ! $this->use_taxes() ) { |
|
| 484 | + if (!$this->use_taxes()) { |
|
| 485 | 485 | return; |
| 486 | 486 | } |
| 487 | 487 | |
| 488 | 488 | // If a custom country && state has been passed in, use it to calculate taxes. |
| 489 | - $country = $this->get_field( 'wpinv_country', 'billing' ); |
|
| 490 | - if ( ! empty( $country ) ) { |
|
| 489 | + $country = $this->get_field('wpinv_country', 'billing'); |
|
| 490 | + if (!empty($country)) { |
|
| 491 | 491 | $this->country = $country; |
| 492 | 492 | } |
| 493 | 493 | |
| 494 | - $state = $this->get_field( 'wpinv_state', 'billing' ); |
|
| 495 | - if ( ! empty( $state ) ) { |
|
| 494 | + $state = $this->get_field('wpinv_state', 'billing'); |
|
| 495 | + if (!empty($state)) { |
|
| 496 | 496 | $this->state = $state; |
| 497 | 497 | } |
| 498 | 498 | |
| 499 | 499 | // Confirm if the provided country and the ip country are similar. |
| 500 | - $address_confirmed = $this->get_field( 'confirm-address' ); |
|
| 501 | - if ( isset( $_POST['billing']['country'] ) && wpinv_should_validate_vat_number() && getpaid_get_ip_country() != $this->country && empty( $address_confirmed ) ) { |
|
| 502 | - throw new Exception( __( 'The country of your current location must be the same as the country of your billing location or you must confirm the billing address is your home country.', 'invoicing' ) ); |
|
| 500 | + $address_confirmed = $this->get_field('confirm-address'); |
|
| 501 | + if (isset($_POST['billing']['country']) && wpinv_should_validate_vat_number() && getpaid_get_ip_country() != $this->country && empty($address_confirmed)) { |
|
| 502 | + throw new Exception(__('The country of your current location must be the same as the country of your billing location or you must confirm the billing address is your home country.', 'invoicing')); |
|
| 503 | 503 | } |
| 504 | 504 | |
| 505 | 505 | // Abort if the country is not taxable. |
| 506 | - if ( ! wpinv_is_country_taxable( $this->country ) ) { |
|
| 506 | + if (!wpinv_is_country_taxable($this->country)) { |
|
| 507 | 507 | return; |
| 508 | 508 | } |
| 509 | 509 | |
| 510 | - $processor = new GetPaid_Payment_Form_Submission_Taxes( $this ); |
|
| 510 | + $processor = new GetPaid_Payment_Form_Submission_Taxes($this); |
|
| 511 | 511 | |
| 512 | - foreach ( $processor->taxes as $tax ) { |
|
| 513 | - $this->add_tax( $tax ); |
|
| 512 | + foreach ($processor->taxes as $tax) { |
|
| 513 | + $this->add_tax($tax); |
|
| 514 | 514 | } |
| 515 | 515 | |
| 516 | - do_action_ref_array( 'getpaid_submissions_process_taxes', array( &$this ) ); |
|
| 516 | + do_action_ref_array('getpaid_submissions_process_taxes', array(&$this)); |
|
| 517 | 517 | } |
| 518 | 518 | |
| 519 | 519 | /** |
@@ -522,16 +522,16 @@ discard block |
||
| 522 | 522 | * @param array $tax An array of tax details. name, initial_tax, and recurring_tax are required. |
| 523 | 523 | * @since 1.0.19 |
| 524 | 524 | */ |
| 525 | - public function add_tax( $tax ) { |
|
| 525 | + public function add_tax($tax) { |
|
| 526 | 526 | |
| 527 | - if ( wpinv_round_tax_per_tax_rate() ) { |
|
| 528 | - $tax['initial_tax'] = wpinv_round_amount( $tax['initial_tax'] ); |
|
| 529 | - $tax['recurring_tax'] = wpinv_round_amount( $tax['recurring_tax'] ); |
|
| 527 | + if (wpinv_round_tax_per_tax_rate()) { |
|
| 528 | + $tax['initial_tax'] = wpinv_round_amount($tax['initial_tax']); |
|
| 529 | + $tax['recurring_tax'] = wpinv_round_amount($tax['recurring_tax']); |
|
| 530 | 530 | } |
| 531 | 531 | |
| 532 | - $this->taxes[ $tax['name'] ] = $tax; |
|
| 533 | - $this->totals['taxes']['initial'] += wpinv_sanitize_amount( $tax['initial_tax'] ); |
|
| 534 | - $this->totals['taxes']['recurring'] += wpinv_sanitize_amount( $tax['recurring_tax'] ); |
|
| 532 | + $this->taxes[$tax['name']] = $tax; |
|
| 533 | + $this->totals['taxes']['initial'] += wpinv_sanitize_amount($tax['initial_tax']); |
|
| 534 | + $this->totals['taxes']['recurring'] += wpinv_sanitize_amount($tax['recurring_tax']); |
|
| 535 | 535 | |
| 536 | 536 | } |
| 537 | 537 | |
@@ -540,12 +540,12 @@ discard block |
||
| 540 | 540 | * |
| 541 | 541 | * @since 1.0.19 |
| 542 | 542 | */ |
| 543 | - public function remove_tax( $tax_name ) { |
|
| 543 | + public function remove_tax($tax_name) { |
|
| 544 | 544 | |
| 545 | - if ( isset( $this->taxes[ $tax_name ] ) ) { |
|
| 546 | - $this->totals['taxes']['initial'] -= $this->taxes[ $tax_name ]['initial_tax']; |
|
| 547 | - $this->totals['taxes']['recurring'] -= $this->taxes[ $tax_name ]['recurring_tax']; |
|
| 548 | - unset( $this->taxes[ $tax_name ] ); |
|
| 545 | + if (isset($this->taxes[$tax_name])) { |
|
| 546 | + $this->totals['taxes']['initial'] -= $this->taxes[$tax_name]['initial_tax']; |
|
| 547 | + $this->totals['taxes']['recurring'] -= $this->taxes[$tax_name]['recurring_tax']; |
|
| 548 | + unset($this->taxes[$tax_name]); |
|
| 549 | 549 | } |
| 550 | 550 | |
| 551 | 551 | } |
@@ -559,11 +559,11 @@ discard block |
||
| 559 | 559 | |
| 560 | 560 | $use_taxes = wpinv_use_taxes(); |
| 561 | 561 | |
| 562 | - if ( $this->has_invoice() && ! $this->invoice->is_taxable() ) { |
|
| 562 | + if ($this->has_invoice() && !$this->invoice->is_taxable()) { |
|
| 563 | 563 | $use_taxes = false; |
| 564 | 564 | } |
| 565 | 565 | |
| 566 | - return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this ); |
|
| 566 | + return apply_filters('getpaid_submission_use_taxes', $use_taxes, $this); |
|
| 567 | 567 | |
| 568 | 568 | } |
| 569 | 569 | |
@@ -612,13 +612,13 @@ discard block |
||
| 612 | 612 | |
| 613 | 613 | $initial_total = $this->get_subtotal() + $this->get_fee() + $this->get_tax(); |
| 614 | 614 | $recurring_total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax(); |
| 615 | - $processor = new GetPaid_Payment_Form_Submission_Discount( $this, $initial_total, $recurring_total ); |
|
| 615 | + $processor = new GetPaid_Payment_Form_Submission_Discount($this, $initial_total, $recurring_total); |
|
| 616 | 616 | |
| 617 | - foreach ( $processor->discounts as $discount ) { |
|
| 618 | - $this->add_discount( $discount ); |
|
| 617 | + foreach ($processor->discounts as $discount) { |
|
| 618 | + $this->add_discount($discount); |
|
| 619 | 619 | } |
| 620 | 620 | |
| 621 | - do_action_ref_array( 'getpaid_submissions_process_discounts', array( &$this ) ); |
|
| 621 | + do_action_ref_array('getpaid_submissions_process_discounts', array(&$this)); |
|
| 622 | 622 | } |
| 623 | 623 | |
| 624 | 624 | /** |
@@ -627,10 +627,10 @@ discard block |
||
| 627 | 627 | * @param array $discount An array of discount details. name, initial_discount, and recurring_discount are required. Include discount_code if the discount is from a discount code. |
| 628 | 628 | * @since 1.0.19 |
| 629 | 629 | */ |
| 630 | - public function add_discount( $discount ) { |
|
| 631 | - $this->discounts[ $discount['name'] ] = $discount; |
|
| 632 | - $this->totals['discount']['initial'] += wpinv_sanitize_amount( $discount['initial_discount'] ); |
|
| 633 | - $this->totals['discount']['recurring'] += wpinv_sanitize_amount( $discount['recurring_discount'] ); |
|
| 630 | + public function add_discount($discount) { |
|
| 631 | + $this->discounts[$discount['name']] = $discount; |
|
| 632 | + $this->totals['discount']['initial'] += wpinv_sanitize_amount($discount['initial_discount']); |
|
| 633 | + $this->totals['discount']['recurring'] += wpinv_sanitize_amount($discount['recurring_discount']); |
|
| 634 | 634 | } |
| 635 | 635 | |
| 636 | 636 | /** |
@@ -638,12 +638,12 @@ discard block |
||
| 638 | 638 | * |
| 639 | 639 | * @since 1.0.19 |
| 640 | 640 | */ |
| 641 | - public function remove_discount( $name ) { |
|
| 641 | + public function remove_discount($name) { |
|
| 642 | 642 | |
| 643 | - if ( isset( $this->discounts[ $name ] ) ) { |
|
| 644 | - $this->totals['discount']['initial'] -= $this->discounts[ $name ]['initial_discount']; |
|
| 645 | - $this->totals['discount']['recurring'] -= $this->discounts[ $name ]['recurring_discount']; |
|
| 646 | - unset( $this->discounts[ $name ] ); |
|
| 643 | + if (isset($this->discounts[$name])) { |
|
| 644 | + $this->totals['discount']['initial'] -= $this->discounts[$name]['initial_discount']; |
|
| 645 | + $this->totals['discount']['recurring'] -= $this->discounts[$name]['recurring_discount']; |
|
| 646 | + unset($this->discounts[$name]); |
|
| 647 | 647 | } |
| 648 | 648 | |
| 649 | 649 | } |
@@ -655,7 +655,7 @@ discard block |
||
| 655 | 655 | * @return bool |
| 656 | 656 | */ |
| 657 | 657 | public function has_discount_code() { |
| 658 | - return ! empty( $this->discounts['discount_code'] ); |
|
| 658 | + return !empty($this->discounts['discount_code']); |
|
| 659 | 659 | } |
| 660 | 660 | |
| 661 | 661 | /** |
@@ -712,13 +712,13 @@ discard block |
||
| 712 | 712 | */ |
| 713 | 713 | public function process_fees() { |
| 714 | 714 | |
| 715 | - $fees_processor = new GetPaid_Payment_Form_Submission_Fees( $this ); |
|
| 715 | + $fees_processor = new GetPaid_Payment_Form_Submission_Fees($this); |
|
| 716 | 716 | |
| 717 | - foreach ( $fees_processor->fees as $fee ) { |
|
| 718 | - $this->add_fee( $fee ); |
|
| 717 | + foreach ($fees_processor->fees as $fee) { |
|
| 718 | + $this->add_fee($fee); |
|
| 719 | 719 | } |
| 720 | 720 | |
| 721 | - do_action_ref_array( 'getpaid_submissions_process_fees', array( &$this ) ); |
|
| 721 | + do_action_ref_array('getpaid_submissions_process_fees', array(&$this)); |
|
| 722 | 722 | } |
| 723 | 723 | |
| 724 | 724 | /** |
@@ -727,17 +727,17 @@ discard block |
||
| 727 | 727 | * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required. |
| 728 | 728 | * @since 1.0.19 |
| 729 | 729 | */ |
| 730 | - public function add_fee( $fee ) { |
|
| 730 | + public function add_fee($fee) { |
|
| 731 | 731 | |
| 732 | - if ( $fee['name'] == 'shipping' ) { |
|
| 733 | - $this->totals['shipping']['initial'] += wpinv_sanitize_amount( $fee['initial_fee'] ); |
|
| 734 | - $this->totals['shipping']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] ); |
|
| 732 | + if ($fee['name'] == 'shipping') { |
|
| 733 | + $this->totals['shipping']['initial'] += wpinv_sanitize_amount($fee['initial_fee']); |
|
| 734 | + $this->totals['shipping']['recurring'] += wpinv_sanitize_amount($fee['recurring_fee']); |
|
| 735 | 735 | return; |
| 736 | 736 | } |
| 737 | 737 | |
| 738 | - $this->fees[ $fee['name'] ] = $fee; |
|
| 739 | - $this->totals['fees']['initial'] += wpinv_sanitize_amount( $fee['initial_fee'] ); |
|
| 740 | - $this->totals['fees']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] ); |
|
| 738 | + $this->fees[$fee['name']] = $fee; |
|
| 739 | + $this->totals['fees']['initial'] += wpinv_sanitize_amount($fee['initial_fee']); |
|
| 740 | + $this->totals['fees']['recurring'] += wpinv_sanitize_amount($fee['recurring_fee']); |
|
| 741 | 741 | |
| 742 | 742 | } |
| 743 | 743 | |
@@ -746,15 +746,15 @@ discard block |
||
| 746 | 746 | * |
| 747 | 747 | * @since 1.0.19 |
| 748 | 748 | */ |
| 749 | - public function remove_fee( $name ) { |
|
| 749 | + public function remove_fee($name) { |
|
| 750 | 750 | |
| 751 | - if ( isset( $this->fees[ $name ] ) ) { |
|
| 752 | - $this->totals['fees']['initial'] -= $this->fees[ $name ]['initial_fee']; |
|
| 753 | - $this->totals['fees']['recurring'] -= $this->fees[ $name ]['recurring_fee']; |
|
| 754 | - unset( $this->fees[ $name ] ); |
|
| 751 | + if (isset($this->fees[$name])) { |
|
| 752 | + $this->totals['fees']['initial'] -= $this->fees[$name]['initial_fee']; |
|
| 753 | + $this->totals['fees']['recurring'] -= $this->fees[$name]['recurring_fee']; |
|
| 754 | + unset($this->fees[$name]); |
|
| 755 | 755 | } |
| 756 | 756 | |
| 757 | - if ( 'shipping' == $name ) { |
|
| 757 | + if ('shipping' == $name) { |
|
| 758 | 758 | $this->totals['shipping']['initial'] = 0; |
| 759 | 759 | $this->totals['shipping']['recurring'] = 0; |
| 760 | 760 | } |
@@ -795,7 +795,7 @@ discard block |
||
| 795 | 795 | * @since 1.0.19 |
| 796 | 796 | */ |
| 797 | 797 | public function has_fees() { |
| 798 | - return count( $this->fees ) !== 0; |
|
| 798 | + return count($this->fees) !== 0; |
|
| 799 | 799 | } |
| 800 | 800 | |
| 801 | 801 | /* |
@@ -831,7 +831,7 @@ discard block |
||
| 831 | 831 | * @since 1.0.19 |
| 832 | 832 | */ |
| 833 | 833 | public function has_shipping() { |
| 834 | - return apply_filters( 'getpaid_payment_form_has_shipping', false, $this ); |
|
| 834 | + return apply_filters('getpaid_payment_form_has_shipping', false, $this); |
|
| 835 | 835 | } |
| 836 | 836 | |
| 837 | 837 | /** |
@@ -841,7 +841,7 @@ discard block |
||
| 841 | 841 | * @since 1.0.19 |
| 842 | 842 | */ |
| 843 | 843 | public function is_initial_fetch() { |
| 844 | - return empty( $this->data['initial_state'] ); |
|
| 844 | + return empty($this->data['initial_state']); |
|
| 845 | 845 | } |
| 846 | 846 | |
| 847 | 847 | /** |
@@ -851,7 +851,7 @@ discard block |
||
| 851 | 851 | */ |
| 852 | 852 | public function get_total() { |
| 853 | 853 | $total = $this->get_subtotal() + $this->get_fee() + $this->get_tax() + $this->get_shipping() - $this->get_discount(); |
| 854 | - return max( $total, 0 ); |
|
| 854 | + return max($total, 0); |
|
| 855 | 855 | } |
| 856 | 856 | |
| 857 | 857 | /** |
@@ -861,7 +861,7 @@ discard block |
||
| 861 | 861 | */ |
| 862 | 862 | public function get_recurring_total() { |
| 863 | 863 | $total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax() + $this->get_recurring_shipping() - $this->get_recurring_discount(); |
| 864 | - return max( $total, 0 ); |
|
| 864 | + return max($total, 0); |
|
| 865 | 865 | } |
| 866 | 866 | |
| 867 | 867 | /** |
@@ -873,12 +873,12 @@ discard block |
||
| 873 | 873 | $initial = $this->get_total(); |
| 874 | 874 | $recurring = $this->get_recurring_total(); |
| 875 | 875 | |
| 876 | - if ( $this->has_recurring == 0 ) { |
|
| 876 | + if ($this->has_recurring == 0) { |
|
| 877 | 877 | $recurring = 0; |
| 878 | 878 | } |
| 879 | 879 | |
| 880 | 880 | $collect = $initial > 0 || $recurring > 0; |
| 881 | - return apply_filters( 'getpaid_submission_should_collect_payment_details', $collect, $this ); |
|
| 881 | + return apply_filters('getpaid_submission_should_collect_payment_details', $collect, $this); |
|
| 882 | 882 | } |
| 883 | 883 | |
| 884 | 884 | /** |
@@ -887,7 +887,7 @@ discard block |
||
| 887 | 887 | * @since 1.0.19 |
| 888 | 888 | */ |
| 889 | 889 | public function get_billing_email() { |
| 890 | - return apply_filters( 'getpaid_get_submission_billing_email', $this->get_field( 'billing_email' ), $this ); |
|
| 890 | + return apply_filters('getpaid_get_submission_billing_email', $this->get_field('billing_email'), $this); |
|
| 891 | 891 | } |
| 892 | 892 | |
| 893 | 893 | /** |
@@ -897,7 +897,7 @@ discard block |
||
| 897 | 897 | */ |
| 898 | 898 | public function has_billing_email() { |
| 899 | 899 | $billing_email = $this->get_billing_email(); |
| 900 | - return ! empty( $billing_email ) && is_email( $billing_email ); |
|
| 900 | + return !empty($billing_email) && is_email($billing_email); |
|
| 901 | 901 | } |
| 902 | 902 | |
| 903 | 903 | /** |
@@ -927,8 +927,8 @@ discard block |
||
| 927 | 927 | * @since 1.0.19 |
| 928 | 928 | * @return mixed|null |
| 929 | 929 | */ |
| 930 | - public function get_field( $field, $sub_array_key = null ) { |
|
| 931 | - return getpaid_get_array_field( $this->data, $field, $sub_array_key ); |
|
| 930 | + public function get_field($field, $sub_array_key = null) { |
|
| 931 | + return getpaid_get_array_field($this->data, $field, $sub_array_key); |
|
| 932 | 932 | } |
| 933 | 933 | |
| 934 | 934 | /** |
@@ -936,8 +936,8 @@ discard block |
||
| 936 | 936 | * |
| 937 | 937 | * @since 1.0.19 |
| 938 | 938 | */ |
| 939 | - public function is_required_field_set( $field ) { |
|
| 940 | - return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] ); |
|
| 939 | + public function is_required_field_set($field) { |
|
| 940 | + return empty($field['required']) || !empty($this->data[$field['id']]); |
|
| 941 | 941 | } |
| 942 | 942 | |
| 943 | 943 | /** |
@@ -945,8 +945,8 @@ discard block |
||
| 945 | 945 | * |
| 946 | 946 | * @since 1.0.19 |
| 947 | 947 | */ |
| 948 | - public function format_amount( $amount ) { |
|
| 949 | - return wpinv_price( $amount, $this->get_currency() ); |
|
| 948 | + public function format_amount($amount) { |
|
| 949 | + return wpinv_price($amount, $this->get_currency()); |
|
| 950 | 950 | } |
| 951 | 951 | |
| 952 | 952 | } |