@@ -1,47 +1,47 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | // MUST have WordPress. |
| 3 | -if ( !defined( 'WPINC' ) ) { |
|
| 4 | - exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) ); |
|
| 3 | +if (!defined('WPINC')) { |
|
| 4 | + exit('Do NOT access this file directly: ' . basename(__FILE__)); |
|
| 5 | 5 | } |
| 6 | 6 | |
| 7 | 7 | class WPInv_Meta_Box_Items { |
| 8 | - public static function output( $post ) { |
|
| 8 | + public static function output($post) { |
|
| 9 | 9 | global $wpinv_euvat, $ajax_cart_details; |
| 10 | 10 | |
| 11 | - $post_id = !empty( $post->ID ) ? $post->ID : 0; |
|
| 12 | - $invoice = new WPInv_Invoice( $post_id ); |
|
| 11 | + $post_id = !empty($post->ID) ? $post->ID : 0; |
|
| 12 | + $invoice = new WPInv_Invoice($post_id); |
|
| 13 | 13 | $ajax_cart_details = $invoice->get_cart_details(); |
| 14 | - $subtotal = $invoice->get_subtotal( true ); |
|
| 14 | + $subtotal = $invoice->get_subtotal(true); |
|
| 15 | 15 | $discount_raw = $invoice->get_discount(); |
| 16 | - $discount = wpinv_price( $discount_raw, $invoice->get_currency() ); |
|
| 16 | + $discount = wpinv_price($discount_raw, $invoice->get_currency()); |
|
| 17 | 17 | $discounts = $discount_raw > 0 ? $invoice->get_discounts() : ''; |
| 18 | - $tax = $invoice->get_tax( true ); |
|
| 19 | - $total = $invoice->get_total( true ); |
|
| 18 | + $tax = $invoice->get_tax(true); |
|
| 19 | + $total = $invoice->get_total(true); |
|
| 20 | 20 | $item_quantities = wpinv_item_quantities_enabled(); |
| 21 | 21 | $use_taxes = wpinv_use_taxes(); |
| 22 | - if ( !$use_taxes && (float)$invoice->get_tax() > 0 ) { |
|
| 22 | + if (!$use_taxes && (float) $invoice->get_tax() > 0) { |
|
| 23 | 23 | $use_taxes = true; |
| 24 | 24 | } |
| 25 | - $item_types = apply_filters( 'wpinv_item_types_for_quick_add_item', wpinv_get_item_types(), $post ); |
|
| 25 | + $item_types = apply_filters('wpinv_item_types_for_quick_add_item', wpinv_get_item_types(), $post); |
|
| 26 | 26 | $is_recurring = $invoice->is_recurring(); |
| 27 | 27 | $post_type_object = get_post_type_object($invoice->post_type); |
| 28 | 28 | $type_title = $post_type_object->labels->singular_name; |
| 29 | 29 | |
| 30 | 30 | $cols = 5; |
| 31 | - if ( $item_quantities ) { |
|
| 31 | + if ($item_quantities) { |
|
| 32 | 32 | $cols++; |
| 33 | 33 | } |
| 34 | - if ( $use_taxes ) { |
|
| 34 | + if ($use_taxes) { |
|
| 35 | 35 | $cols++; |
| 36 | 36 | } |
| 37 | 37 | $class = ''; |
| 38 | - if ( $invoice->is_paid() ) { |
|
| 38 | + if ($invoice->is_paid()) { |
|
| 39 | 39 | $class .= ' wpinv-paid'; |
| 40 | 40 | } |
| 41 | - if ( $invoice->is_refunded() ) { |
|
| 41 | + if ($invoice->is_refunded()) { |
|
| 42 | 42 | $class .= ' wpinv-refunded'; |
| 43 | 43 | } |
| 44 | - if ( $is_recurring ) { |
|
| 44 | + if ($is_recurring) { |
|
| 45 | 45 | $class .= ' wpi-recurring'; |
| 46 | 46 | } |
| 47 | 47 | ?> |
@@ -49,21 +49,21 @@ discard block |
||
| 49 | 49 | <table id="wpinv_items" class="wpinv-items" cellspacing="0" cellpadding="0"> |
| 50 | 50 | <thead> |
| 51 | 51 | <tr> |
| 52 | - <th class="id"><?php _e( 'ID', 'invoicing' );?></th> |
|
| 53 | - <th class="title"><?php _e( 'Item', 'invoicing' );?></th> |
|
| 54 | - <th class="price"><?php _e( 'Price', 'invoicing' );?></th> |
|
| 55 | - <?php if ( $item_quantities ) { ?> |
|
| 56 | - <th class="qty"><?php _e( 'Qty', 'invoicing' );?></th> |
|
| 52 | + <th class="id"><?php _e('ID', 'invoicing'); ?></th> |
|
| 53 | + <th class="title"><?php _e('Item', 'invoicing'); ?></th> |
|
| 54 | + <th class="price"><?php _e('Price', 'invoicing'); ?></th> |
|
| 55 | + <?php if ($item_quantities) { ?> |
|
| 56 | + <th class="qty"><?php _e('Qty', 'invoicing'); ?></th> |
|
| 57 | 57 | <?php } ?> |
| 58 | - <th class="total"><?php _e( 'Total', 'invoicing' );?></th> |
|
| 59 | - <?php if ( $use_taxes ) { ?> |
|
| 60 | - <th class="tax"><?php _e( 'Tax (%)', 'invoicing' );?></th> |
|
| 58 | + <th class="total"><?php _e('Total', 'invoicing'); ?></th> |
|
| 59 | + <?php if ($use_taxes) { ?> |
|
| 60 | + <th class="tax"><?php _e('Tax (%)', 'invoicing'); ?></th> |
|
| 61 | 61 | <?php } ?> |
| 62 | 62 | <th class="action"></th> |
| 63 | 63 | </tr> |
| 64 | 64 | </thead> |
| 65 | 65 | <tbody class="wpinv-line-items"> |
| 66 | - <?php echo wpinv_admin_get_line_items( $invoice ); ?> |
|
| 66 | + <?php echo wpinv_admin_get_line_items($invoice); ?> |
|
| 67 | 67 | </tbody> |
| 68 | 68 | <tfoot class="wpinv-totals"> |
| 69 | 69 | <tr> |
@@ -74,45 +74,45 @@ discard block |
||
| 74 | 74 | <td class="id"> |
| 75 | 75 | </td> |
| 76 | 76 | <td class="title"> |
| 77 | - <input type="text" class="regular-text" placeholder="<?php _e( 'Item Name', 'invoicing' ); ?>" value="" name="_wpinv_quick[name]"> |
|
| 78 | - <?php if ( $wpinv_euvat->allow_vat_rules() ) { ?> |
|
| 77 | + <input type="text" class="regular-text" placeholder="<?php _e('Item Name', 'invoicing'); ?>" value="" name="_wpinv_quick[name]"> |
|
| 78 | + <?php if ($wpinv_euvat->allow_vat_rules()) { ?> |
|
| 79 | 79 | <div class="wp-clearfix"> |
| 80 | 80 | <label class="wpi-vat-rule"> |
| 81 | - <span class="title"><?php _e( 'VAT rule type', 'invoicing' );?></span> |
|
| 81 | + <span class="title"><?php _e('VAT rule type', 'invoicing'); ?></span> |
|
| 82 | 82 | <span class="input-text-wrap"> |
| 83 | - <?php echo wpinv_html_select( array( |
|
| 83 | + <?php echo wpinv_html_select(array( |
|
| 84 | 84 | 'options' => $wpinv_euvat->get_rules(), |
| 85 | 85 | 'name' => '_wpinv_quick[vat_rule]', |
| 86 | 86 | 'id' => '_wpinv_quick_vat_rule', |
| 87 | 87 | 'show_option_all' => false, |
| 88 | 88 | 'show_option_none' => false, |
| 89 | 89 | 'class' => 'gdmbx2-text-medium wpinv-quick-vat-rule wpi_select2', |
| 90 | - ) ); ?> |
|
| 90 | + )); ?> |
|
| 91 | 91 | </span> |
| 92 | 92 | </label> |
| 93 | 93 | </div> |
| 94 | - <?php } if ( $wpinv_euvat->allow_vat_classes() ) { ?> |
|
| 94 | + <?php } if ($wpinv_euvat->allow_vat_classes()) { ?> |
|
| 95 | 95 | <div class="wp-clearfix"> |
| 96 | 96 | <label class="wpi-vat-class"> |
| 97 | - <span class="title"><?php _e( 'VAT class', 'invoicing' );?></span> |
|
| 97 | + <span class="title"><?php _e('VAT class', 'invoicing'); ?></span> |
|
| 98 | 98 | <span class="input-text-wrap"> |
| 99 | - <?php echo wpinv_html_select( array( |
|
| 99 | + <?php echo wpinv_html_select(array( |
|
| 100 | 100 | 'options' => $wpinv_euvat->get_all_classes(), |
| 101 | 101 | 'name' => '_wpinv_quick[vat_class]', |
| 102 | 102 | 'id' => '_wpinv_quick_vat_class', |
| 103 | 103 | 'show_option_all' => false, |
| 104 | 104 | 'show_option_none' => false, |
| 105 | 105 | 'class' => 'gdmbx2-text-medium wpinv-quick-vat-class wpi_select2', |
| 106 | - ) ); ?> |
|
| 106 | + )); ?> |
|
| 107 | 107 | </span> |
| 108 | 108 | </label> |
| 109 | 109 | </div> |
| 110 | 110 | <?php } ?> |
| 111 | 111 | <div class="wp-clearfix"> |
| 112 | 112 | <label class="wpi-item-type"> |
| 113 | - <span class="title"><?php _e( 'Item type', 'invoicing' );?></span> |
|
| 113 | + <span class="title"><?php _e('Item type', 'invoicing'); ?></span> |
|
| 114 | 114 | <span class="input-text-wrap"> |
| 115 | - <?php echo wpinv_html_select( array( |
|
| 115 | + <?php echo wpinv_html_select(array( |
|
| 116 | 116 | 'options' => $item_types, |
| 117 | 117 | 'name' => '_wpinv_quick[type]', |
| 118 | 118 | 'id' => '_wpinv_quick_type', |
@@ -120,37 +120,37 @@ discard block |
||
| 120 | 120 | 'show_option_all' => false, |
| 121 | 121 | 'show_option_none' => false, |
| 122 | 122 | 'class' => 'gdmbx2-text-medium wpinv-quick-type wpi_select2', |
| 123 | - ) ); ?> |
|
| 123 | + )); ?> |
|
| 124 | 124 | </span> |
| 125 | 125 | </label> |
| 126 | 126 | </div> |
| 127 | 127 | |
| 128 | 128 | <div class="wp-clearfix"> |
| 129 | 129 | <?php |
| 130 | - echo wpinv_html_textarea( array( |
|
| 130 | + echo wpinv_html_textarea(array( |
|
| 131 | 131 | 'name' => '_wpinv_quick[excerpt]', |
| 132 | 132 | 'id' => '_wpinv_quick_excerpt', |
| 133 | 133 | 'value' => '', |
| 134 | 134 | 'class' => 'large-text', |
| 135 | - 'label' => __( 'Item description', 'invoicing' ), |
|
| 136 | - ) ); |
|
| 135 | + 'label' => __('Item description', 'invoicing'), |
|
| 136 | + )); |
|
| 137 | 137 | ?> |
| 138 | 138 | </div> |
| 139 | 139 | |
| 140 | 140 | <div class="wp-clearfix"> |
| 141 | 141 | <label class="wpi-item-actions"> |
| 142 | 142 | <span class="input-text-wrap"> |
| 143 | - <input type="button" value="<?php esc_attr_e( 'Add', 'invoicing' ); ?>" class="button button-primary" id="wpinv-save-item"><input type="button" value="Cancel" class="button button-secondary" id="wpinv-cancel-item"> |
|
| 143 | + <input type="button" value="<?php esc_attr_e('Add', 'invoicing'); ?>" class="button button-primary" id="wpinv-save-item"><input type="button" value="Cancel" class="button button-secondary" id="wpinv-cancel-item"> |
|
| 144 | 144 | </span> |
| 145 | 145 | </label> |
| 146 | 146 | </div> |
| 147 | 147 | </td> |
| 148 | 148 | <td class="price"><input type="text" placeholder="0.00" class="wpi-field-price wpi-price" name="_wpinv_quick[price]" /></td> |
| 149 | - <?php if ( $item_quantities ) { ?> |
|
| 149 | + <?php if ($item_quantities) { ?> |
|
| 150 | 150 | <td class="qty"><input type="number" class="small-text" step="1" min="1" value="1" name="_wpinv_quick[qty]" /></td> |
| 151 | 151 | <?php } ?> |
| 152 | 152 | <td class="total"></td> |
| 153 | - <?php if ( $use_taxes ) { ?> |
|
| 153 | + <?php if ($use_taxes) { ?> |
|
| 154 | 154 | <td class="tax"></td> |
| 155 | 155 | <?php } ?> |
| 156 | 156 | <td class="action"></td> |
@@ -163,29 +163,29 @@ discard block |
||
| 163 | 163 | <td colspan="<?php echo $cols; ?>"></td> |
| 164 | 164 | </tr> |
| 165 | 165 | <tr class="totals"> |
| 166 | - <td colspan="<?php echo ( $cols - 4 ); ?>"></td> |
|
| 166 | + <td colspan="<?php echo ($cols - 4); ?>"></td> |
|
| 167 | 167 | <td colspan="4"> |
| 168 | 168 | <table cellspacing="0" cellpadding="0"> |
| 169 | 169 | <tr class="subtotal"> |
| 170 | - <td class="name"><?php _e( 'Sub Total:', 'invoicing' );?></td> |
|
| 171 | - <td class="total"><?php echo $subtotal;?></td> |
|
| 170 | + <td class="name"><?php _e('Sub Total:', 'invoicing'); ?></td> |
|
| 171 | + <td class="total"><?php echo $subtotal; ?></td> |
|
| 172 | 172 | <td class="action"></td> |
| 173 | 173 | </tr> |
| 174 | 174 | <tr class="discount"> |
| 175 | - <td class="name"><?php wpinv_get_discount_label( wpinv_discount_code( $invoice->ID ) ); ?>:</td> |
|
| 176 | - <td class="total"><?php echo wpinv_discount( $invoice->ID, true, true ); ?></td> |
|
| 175 | + <td class="name"><?php wpinv_get_discount_label(wpinv_discount_code($invoice->ID)); ?>:</td> |
|
| 176 | + <td class="total"><?php echo wpinv_discount($invoice->ID, true, true); ?></td> |
|
| 177 | 177 | <td class="action"></td> |
| 178 | 178 | </tr> |
| 179 | - <?php if ( $use_taxes ) { ?> |
|
| 179 | + <?php if ($use_taxes) { ?> |
|
| 180 | 180 | <tr class="tax"> |
| 181 | - <td class="name"><?php _e( 'Tax:', 'invoicing' );?></td> |
|
| 182 | - <td class="total"><?php echo $tax;?></td> |
|
| 181 | + <td class="name"><?php _e('Tax:', 'invoicing'); ?></td> |
|
| 182 | + <td class="total"><?php echo $tax; ?></td> |
|
| 183 | 183 | <td class="action"></td> |
| 184 | 184 | </tr> |
| 185 | 185 | <?php } ?> |
| 186 | 186 | <tr class="total"> |
| 187 | - <td class="name"><?php echo apply_filters( 'wpinv_invoice_items_total_label', __( 'Invoice Total:', 'invoicing' ), $invoice );?></td> |
|
| 188 | - <td class="total"><?php echo $total;?></td> |
|
| 187 | + <td class="name"><?php echo apply_filters('wpinv_invoice_items_total_label', __('Invoice Total:', 'invoicing'), $invoice); ?></td> |
|
| 188 | + <td class="total"><?php echo $total; ?></td> |
|
| 189 | 189 | <td class="action"></td> |
| 190 | 190 | </tr> |
| 191 | 191 | </table> |
@@ -196,90 +196,90 @@ discard block |
||
| 196 | 196 | <div class="wpinv-actions"> |
| 197 | 197 | <?php ob_start(); ?> |
| 198 | 198 | <?php |
| 199 | - if ( !$invoice->is_paid() && !$invoice->is_refunded() ) { |
|
| 200 | - if ( !$invoice->is_recurring() ) { |
|
| 201 | - echo wpinv_item_dropdown( array( |
|
| 199 | + if (!$invoice->is_paid() && !$invoice->is_refunded()) { |
|
| 200 | + if (!$invoice->is_recurring()) { |
|
| 201 | + echo wpinv_item_dropdown(array( |
|
| 202 | 202 | 'name' => 'wpinv_invoice_item', |
| 203 | 203 | 'id' => 'wpinv_invoice_item', |
| 204 | 204 | 'show_recurring' => true, |
| 205 | 205 | 'class' => 'wpi_select2', |
| 206 | - ) ); |
|
| 206 | + )); |
|
| 207 | 207 | ?> |
| 208 | - <input type="button" value="<?php echo sprintf(esc_attr__( 'Add item to %s', 'invoicing'), $type_title); ?>" class="button button-primary" id="wpinv-add-item"><input type="button" value="<?php esc_attr_e( 'Create new item', 'invoicing' );?>" class="button button-primary" id="wpinv-new-item"><?php } ?><input type="button" value="<?php esc_attr_e( 'Recalculate Totals', 'invoicing' );?>" class="button button-primary wpinv-flr" id="wpinv-recalc-totals"> |
|
| 208 | + <input type="button" value="<?php echo sprintf(esc_attr__('Add item to %s', 'invoicing'), $type_title); ?>" class="button button-primary" id="wpinv-add-item"><input type="button" value="<?php esc_attr_e('Create new item', 'invoicing'); ?>" class="button button-primary" id="wpinv-new-item"><?php } ?><input type="button" value="<?php esc_attr_e('Recalculate Totals', 'invoicing'); ?>" class="button button-primary wpinv-flr" id="wpinv-recalc-totals"> |
|
| 209 | 209 | <?php } ?> |
| 210 | - <?php do_action( 'wpinv_invoice_items_actions', $invoice ); ?> |
|
| 211 | - <?php $item_actions = ob_get_clean(); echo apply_filters( 'wpinv_invoice_items_actions_content', $item_actions, $invoice, $post ); ?> |
|
| 210 | + <?php do_action('wpinv_invoice_items_actions', $invoice); ?> |
|
| 211 | + <?php $item_actions = ob_get_clean(); echo apply_filters('wpinv_invoice_items_actions_content', $item_actions, $invoice, $post); ?> |
|
| 212 | 212 | </div> |
| 213 | 213 | </div> |
| 214 | 214 | <?php |
| 215 | 215 | } |
| 216 | 216 | |
| 217 | - public static function prices( $post ) { |
|
| 217 | + public static function prices($post) { |
|
| 218 | 218 | $symbol = wpinv_currency_symbol(); |
| 219 | 219 | $position = wpinv_currency_position(); |
| 220 | - $item = new WPInv_Item( $post->ID ); |
|
| 220 | + $item = new WPInv_Item($post->ID); |
|
| 221 | 221 | |
| 222 | 222 | $price = $item->get_price(); |
| 223 | 223 | $is_dynamic_pricing = $item->get_is_dynamic_pricing(); |
| 224 | 224 | $minimum_price = $item->get_minimum_price(); |
| 225 | 225 | $is_recurring = $item->is_recurring(); |
| 226 | 226 | $period = $item->get_recurring_period(); |
| 227 | - $interval = absint( $item->get_recurring_interval() ); |
|
| 228 | - $times = absint( $item->get_recurring_limit() ); |
|
| 227 | + $interval = absint($item->get_recurring_interval()); |
|
| 228 | + $times = absint($item->get_recurring_limit()); |
|
| 229 | 229 | $free_trial = $item->has_free_trial(); |
| 230 | 230 | $trial_interval = $item->get_trial_interval(); |
| 231 | 231 | $trial_period = $item->get_trial_period(); |
| 232 | 232 | |
| 233 | 233 | $intervals = array(); |
| 234 | - for ( $i = 1; $i <= 90; $i++ ) { |
|
| 234 | + for ($i = 1; $i <= 90; $i++) { |
|
| 235 | 235 | $intervals[$i] = $i; |
| 236 | 236 | } |
| 237 | 237 | |
| 238 | - $interval = $interval > 0 ? $interval : 1; |
|
| 238 | + $interval = $interval > 0 ? $interval : 1; |
|
| 239 | 239 | |
| 240 | 240 | $class = $is_recurring ? 'wpinv-recurring-y' : 'wpinv-recurring-n'; |
| 241 | 241 | |
| 242 | 242 | $minimum_price_style = 'margin-left: 24px;'; |
| 243 | - if(! $is_dynamic_pricing ) { |
|
| 243 | + if (!$is_dynamic_pricing) { |
|
| 244 | 244 | $minimum_price_style .= 'display: none;'; |
| 245 | 245 | } |
| 246 | 246 | |
| 247 | 247 | ?> |
| 248 | - <p class="wpinv-row-prices"><?php echo ( $position != 'right' ? $symbol . ' ' : '' );?><input type="text" maxlength="12" placeholder="<?php echo wpinv_sanitize_amount( 0 ); ?>" value="<?php echo $price;?>" id="wpinv_item_price" name="wpinv_item_price" class="medium-text wpi-field-price wpi-price" <?php disabled( $item->is_editable(), false ); ?> /><?php echo ( $position == 'right' ? ' ' . $symbol : '' );?><input type="hidden" name="wpinv_vat_meta_box_nonce" value="<?php echo wp_create_nonce( 'wpinv_item_meta_box_save' ) ;?>" /> |
|
| 249 | - <?php do_action( 'wpinv_prices_metabox_price', $item ); ?> |
|
| 248 | + <p class="wpinv-row-prices"><?php echo ($position != 'right' ? $symbol . ' ' : ''); ?><input type="text" maxlength="12" placeholder="<?php echo wpinv_sanitize_amount(0); ?>" value="<?php echo $price; ?>" id="wpinv_item_price" name="wpinv_item_price" class="medium-text wpi-field-price wpi-price" <?php disabled($item->is_editable(), false); ?> /><?php echo ($position == 'right' ? ' ' . $symbol : ''); ?><input type="hidden" name="wpinv_vat_meta_box_nonce" value="<?php echo wp_create_nonce('wpinv_item_meta_box_save'); ?>" /> |
|
| 249 | + <?php do_action('wpinv_prices_metabox_price', $item); ?> |
|
| 250 | 250 | </p> |
| 251 | 251 | |
| 252 | - <?php if( $item->supports_dynamic_pricing() ) { ?> |
|
| 252 | + <?php if ($item->supports_dynamic_pricing()) { ?> |
|
| 253 | 253 | |
| 254 | 254 | <p class="wpinv-row-name-your-price"> |
| 255 | 255 | <label> |
| 256 | - <input type="checkbox" name="wpinv_name_your_price" id="wpinv_name_your_price" value="1" <?php checked( 1, $is_dynamic_pricing ); ?> /> |
|
| 257 | - <?php echo apply_filters( 'wpinv_name_your_price_toggle_text', __( 'User can set a custom price', 'invoicing' ) ); ?> |
|
| 256 | + <input type="checkbox" name="wpinv_name_your_price" id="wpinv_name_your_price" value="1" <?php checked(1, $is_dynamic_pricing); ?> /> |
|
| 257 | + <?php echo apply_filters('wpinv_name_your_price_toggle_text', __('User can set a custom price', 'invoicing')); ?> |
|
| 258 | 258 | </label> |
| 259 | - <?php do_action( 'wpinv_prices_metabox_name_your_price_field', $item ); ?> |
|
| 259 | + <?php do_action('wpinv_prices_metabox_name_your_price_field', $item); ?> |
|
| 260 | 260 | </p> |
| 261 | 261 | |
| 262 | 262 | <p class="wpinv-row-minimum-price" style="<?php echo $minimum_price_style; ?>"> |
| 263 | 263 | <label> |
| 264 | - <?php _e( 'Minimum Price', 'invoicing' ); ?> |
|
| 265 | - <?php echo ( $position != 'right' ? $symbol . ' ' : '' );?><input type="text" maxlength="12" placeholder="<?php echo wpinv_sanitize_amount( 0 ); ?>" value="<?php echo $minimum_price;?>" id="wpinv_minimum_price" name="wpinv_minimum_price" class="medium-text wpi-field-price" <?php disabled( $item->is_editable(), false ); ?> /><?php echo ( $position == 'right' ? ' ' . $symbol : '' );?> |
|
| 264 | + <?php _e('Minimum Price', 'invoicing'); ?> |
|
| 265 | + <?php echo ($position != 'right' ? $symbol . ' ' : ''); ?><input type="text" maxlength="12" placeholder="<?php echo wpinv_sanitize_amount(0); ?>" value="<?php echo $minimum_price; ?>" id="wpinv_minimum_price" name="wpinv_minimum_price" class="medium-text wpi-field-price" <?php disabled($item->is_editable(), false); ?> /><?php echo ($position == 'right' ? ' ' . $symbol : ''); ?> |
|
| 266 | 266 | </label> |
| 267 | 267 | |
| 268 | - <?php do_action( 'wpinv_prices_metabox_minimum_price_field', $item ); ?> |
|
| 268 | + <?php do_action('wpinv_prices_metabox_minimum_price_field', $item); ?> |
|
| 269 | 269 | </p> |
| 270 | 270 | |
| 271 | 271 | <?php } ?> |
| 272 | 272 | |
| 273 | 273 | <p class="wpinv-row-is-recurring"> |
| 274 | 274 | <label for="wpinv_is_recurring"> |
| 275 | - <input type="checkbox" name="wpinv_is_recurring" id="wpinv_is_recurring" value="1" <?php checked( 1, $is_recurring ); ?> /> |
|
| 276 | - <?php echo apply_filters( 'wpinv_is_recurring_toggle_text', __( 'Is Recurring Item?', 'invoicing' ) ); ?> |
|
| 275 | + <input type="checkbox" name="wpinv_is_recurring" id="wpinv_is_recurring" value="1" <?php checked(1, $is_recurring); ?> /> |
|
| 276 | + <?php echo apply_filters('wpinv_is_recurring_toggle_text', __('Is Recurring Item?', 'invoicing')); ?> |
|
| 277 | 277 | </label> |
| 278 | - <?php do_action( 'wpinv_prices_metabox_is_recurring_field', $item ); ?> |
|
| 278 | + <?php do_action('wpinv_prices_metabox_is_recurring_field', $item); ?> |
|
| 279 | 279 | </p> |
| 280 | - <p class="wpinv-row-recurring-fields <?php echo $class;?>"> |
|
| 281 | - <label class="wpinv-period" for="wpinv_recurring_period"><?php _e( 'Recurring', 'invoicing' );?> <select class="wpinv-select wpi_select2" id="wpinv_recurring_period" name="wpinv_recurring_period"><option value="D" data-text="<?php esc_attr_e( 'day(s)', 'invoicing' ); ?>" <?php selected( 'D', $period );?>><?php _e( 'Daily', 'invoicing' ); ?></option><option value="W" data-text="<?php esc_attr_e( 'week(s)', 'invoicing' ); ?>" <?php selected( 'W', $period );?>><?php _e( 'Weekly', 'invoicing' ); ?></option><option value="M" data-text="<?php esc_attr_e( 'month(s)', 'invoicing' ); ?>" <?php selected( 'M', $period );?>><?php _e( 'Monthly', 'invoicing' ); ?></option><option value="Y" data-text="<?php esc_attr_e( 'year(s)', 'invoicing' ); ?>" <?php selected( 'Y', $period );?>><?php _e( 'Yearly', 'invoicing' ); ?></option></select></label> |
|
| 282 | - <label class="wpinv-interval" for="wpinv_recurring_interval"> <?php _e( 'at every', 'invoicing' );?> <?php echo wpinv_html_select( array( |
|
| 280 | + <p class="wpinv-row-recurring-fields <?php echo $class; ?>"> |
|
| 281 | + <label class="wpinv-period" for="wpinv_recurring_period"><?php _e('Recurring', 'invoicing'); ?> <select class="wpinv-select wpi_select2" id="wpinv_recurring_period" name="wpinv_recurring_period"><option value="D" data-text="<?php esc_attr_e('day(s)', 'invoicing'); ?>" <?php selected('D', $period); ?>><?php _e('Daily', 'invoicing'); ?></option><option value="W" data-text="<?php esc_attr_e('week(s)', 'invoicing'); ?>" <?php selected('W', $period); ?>><?php _e('Weekly', 'invoicing'); ?></option><option value="M" data-text="<?php esc_attr_e('month(s)', 'invoicing'); ?>" <?php selected('M', $period); ?>><?php _e('Monthly', 'invoicing'); ?></option><option value="Y" data-text="<?php esc_attr_e('year(s)', 'invoicing'); ?>" <?php selected('Y', $period); ?>><?php _e('Yearly', 'invoicing'); ?></option></select></label> |
|
| 282 | + <label class="wpinv-interval" for="wpinv_recurring_interval"> <?php _e('at every', 'invoicing'); ?> <?php echo wpinv_html_select(array( |
|
| 283 | 283 | 'options' => $intervals, |
| 284 | 284 | 'name' => 'wpinv_recurring_interval', |
| 285 | 285 | 'id' => 'wpinv_recurring_interval', |
@@ -287,30 +287,30 @@ discard block |
||
| 287 | 287 | 'show_option_all' => false, |
| 288 | 288 | 'show_option_none' => false, |
| 289 | 289 | 'class' => 'wpi_select2', |
| 290 | - ) ); ?> <span id="wpinv_interval_text"><?php _e( 'day(s)', 'invoicing' );?></span></label> |
|
| 291 | - <label class="wpinv-times" for="wpinv_recurring_limit"> <?php _e( 'for', 'invoicing' );?> <input class="small-text" type="number" value="<?php echo $times;?>" size="4" id="wpinv_recurring_limit" name="wpinv_recurring_limit" step="1" min="0"> <?php _e( 'time(s) <i>(select 0 for recurring forever until cancelled</i>)', 'invoicing' );?></label> |
|
| 290 | + )); ?> <span id="wpinv_interval_text"><?php _e('day(s)', 'invoicing'); ?></span></label> |
|
| 291 | + <label class="wpinv-times" for="wpinv_recurring_limit"> <?php _e('for', 'invoicing'); ?> <input class="small-text" type="number" value="<?php echo $times; ?>" size="4" id="wpinv_recurring_limit" name="wpinv_recurring_limit" step="1" min="0"> <?php _e('time(s) <i>(select 0 for recurring forever until cancelled</i>)', 'invoicing'); ?></label> |
|
| 292 | 292 | <span class="clear wpi-trial-clr"></span> |
| 293 | 293 | <label class="wpinv-free-trial" for="wpinv_free_trial"> |
| 294 | - <input type="checkbox" name="wpinv_free_trial" id="wpinv_free_trial" value="1" <?php checked( true, (bool)$free_trial ); ?> /> |
|
| 295 | - <?php echo __( 'Offer free trial for', 'invoicing' ); ?> |
|
| 294 | + <input type="checkbox" name="wpinv_free_trial" id="wpinv_free_trial" value="1" <?php checked(true, (bool) $free_trial); ?> /> |
|
| 295 | + <?php echo __('Offer free trial for', 'invoicing'); ?> |
|
| 296 | 296 | </label> |
| 297 | 297 | <label class="wpinv-trial-interval" for="wpinv_trial_interval"> |
| 298 | - <input class="small-text" type="number" value="<?php echo $trial_interval;?>" size="4" id="wpinv_trial_interval" name="wpinv_trial_interval" step="1" min="1"> <select class="wpinv-select wpi_select2" id="wpinv_trial_period" name="wpinv_trial_period"><option value="D" <?php selected( 'D', $trial_period );?>><?php _e( 'day(s)', 'invoicing' ); ?></option><option value="W" <?php selected( 'W', $trial_period );?>><?php _e( 'week(s)', 'invoicing' ); ?></option><option value="M" <?php selected( 'M', $trial_period );?>><?php _e( 'month(s)', 'invoicing' ); ?></option><option value="Y" <?php selected( 'Y', $trial_period );?>><?php _e( 'year(s)', 'invoicing' ); ?></option></select> |
|
| 298 | + <input class="small-text" type="number" value="<?php echo $trial_interval; ?>" size="4" id="wpinv_trial_interval" name="wpinv_trial_interval" step="1" min="1"> <select class="wpinv-select wpi_select2" id="wpinv_trial_period" name="wpinv_trial_period"><option value="D" <?php selected('D', $trial_period); ?>><?php _e('day(s)', 'invoicing'); ?></option><option value="W" <?php selected('W', $trial_period); ?>><?php _e('week(s)', 'invoicing'); ?></option><option value="M" <?php selected('M', $trial_period); ?>><?php _e('month(s)', 'invoicing'); ?></option><option value="Y" <?php selected('Y', $trial_period); ?>><?php _e('year(s)', 'invoicing'); ?></option></select> |
|
| 299 | 299 | </label> |
| 300 | - <?php do_action( 'wpinv_prices_metabox_recurring_fields', $item ); ?> |
|
| 300 | + <?php do_action('wpinv_prices_metabox_recurring_fields', $item); ?> |
|
| 301 | 301 | </p> |
| 302 | - <input type="hidden" id="_wpi_current_type" value="<?php echo wpinv_get_item_type( $post->ID ); ?>" /> |
|
| 303 | - <?php do_action( 'wpinv_item_price_field', $post->ID ); ?> |
|
| 302 | + <input type="hidden" id="_wpi_current_type" value="<?php echo wpinv_get_item_type($post->ID); ?>" /> |
|
| 303 | + <?php do_action('wpinv_item_price_field', $post->ID); ?> |
|
| 304 | 304 | <?php |
| 305 | 305 | } |
| 306 | 306 | |
| 307 | - public static function vat_rules( $post ) { |
|
| 307 | + public static function vat_rules($post) { |
|
| 308 | 308 | global $wpinv_euvat; |
| 309 | 309 | |
| 310 | - $rule_type = $wpinv_euvat->get_item_rule( $post->ID ); |
|
| 310 | + $rule_type = $wpinv_euvat->get_item_rule($post->ID); |
|
| 311 | 311 | ?> |
| 312 | - <p><label for="wpinv_vat_rules"><strong><?php _e( 'Select how VAT rules will be applied:', 'invoicing' );?></strong></label> |
|
| 313 | - <?php echo wpinv_html_select( array( |
|
| 312 | + <p><label for="wpinv_vat_rules"><strong><?php _e('Select how VAT rules will be applied:', 'invoicing'); ?></strong></label> |
|
| 313 | + <?php echo wpinv_html_select(array( |
|
| 314 | 314 | 'options' => $wpinv_euvat->get_rules(), |
| 315 | 315 | 'name' => 'wpinv_vat_rules', |
| 316 | 316 | 'id' => 'wpinv_vat_rules', |
@@ -318,19 +318,19 @@ discard block |
||
| 318 | 318 | 'show_option_all' => false, |
| 319 | 319 | 'show_option_none' => false, |
| 320 | 320 | 'class' => 'gdmbx2-text-medium wpinv-vat-rules wpi_select2', |
| 321 | - ) ); ?> |
|
| 321 | + )); ?> |
|
| 322 | 322 | </p> |
| 323 | - <p class="wpi-m0"><?php _e( 'When you select physical product rules, only consumers and businesses in your country will be charged VAT. The VAT rate used will be the rate in your country.', 'invoicing' ); ?></p> |
|
| 324 | - <p class="wpi-m0"><?php _e( 'If you select Digital product rules, VAT will be charged at the rate that applies in the country of the consumer. Only businesses in your country will be charged VAT.', 'invoicing' ); ?></p> |
|
| 323 | + <p class="wpi-m0"><?php _e('When you select physical product rules, only consumers and businesses in your country will be charged VAT. The VAT rate used will be the rate in your country.', 'invoicing'); ?></p> |
|
| 324 | + <p class="wpi-m0"><?php _e('If you select Digital product rules, VAT will be charged at the rate that applies in the country of the consumer. Only businesses in your country will be charged VAT.', 'invoicing'); ?></p> |
|
| 325 | 325 | <?php |
| 326 | 326 | } |
| 327 | 327 | |
| 328 | - public static function vat_classes( $post ) { |
|
| 328 | + public static function vat_classes($post) { |
|
| 329 | 329 | global $wpinv_euvat; |
| 330 | 330 | |
| 331 | - $vat_class = $wpinv_euvat->get_item_class( $post->ID ); |
|
| 331 | + $vat_class = $wpinv_euvat->get_item_class($post->ID); |
|
| 332 | 332 | ?> |
| 333 | - <p><?php echo wpinv_html_select( array( |
|
| 333 | + <p><?php echo wpinv_html_select(array( |
|
| 334 | 334 | 'options' => $wpinv_euvat->get_all_classes(), |
| 335 | 335 | 'name' => 'wpinv_vat_class', |
| 336 | 336 | 'id' => 'wpinv_vat_class', |
@@ -338,18 +338,18 @@ discard block |
||
| 338 | 338 | 'show_option_all' => false, |
| 339 | 339 | 'show_option_none' => false, |
| 340 | 340 | 'class' => 'gdmbx2-text-medium wpinv-vat-class wpi_select2', |
| 341 | - ) ); ?> |
|
| 341 | + )); ?> |
|
| 342 | 342 | </p> |
| 343 | - <p class="wpi-m0"><?php _e( 'Select the VAT rate class to use for this invoice item.', 'invoicing' ); ?></p> |
|
| 343 | + <p class="wpi-m0"><?php _e('Select the VAT rate class to use for this invoice item.', 'invoicing'); ?></p> |
|
| 344 | 344 | <?php |
| 345 | 345 | } |
| 346 | 346 | |
| 347 | - public static function item_info( $post ) { |
|
| 348 | - $item_type = wpinv_get_item_type( $post->ID ); |
|
| 349 | - do_action( 'wpinv_item_info_metabox_before', $post ); |
|
| 347 | + public static function item_info($post) { |
|
| 348 | + $item_type = wpinv_get_item_type($post->ID); |
|
| 349 | + do_action('wpinv_item_info_metabox_before', $post); |
|
| 350 | 350 | ?> |
| 351 | - <p><label for="wpinv_item_type"><strong><?php _e( 'Type:', 'invoicing' );?></strong></label> |
|
| 352 | - <?php echo wpinv_html_select( array( |
|
| 351 | + <p><label for="wpinv_item_type"><strong><?php _e('Type:', 'invoicing'); ?></strong></label> |
|
| 352 | + <?php echo wpinv_html_select(array( |
|
| 353 | 353 | 'options' => wpinv_get_item_types(), |
| 354 | 354 | 'name' => 'wpinv_item_type', |
| 355 | 355 | 'id' => 'wpinv_item_type', |
@@ -357,127 +357,127 @@ discard block |
||
| 357 | 357 | 'show_option_all' => false, |
| 358 | 358 | 'show_option_none' => false, |
| 359 | 359 | 'class' => 'gdmbx2-text-medium wpinv-item-type', |
| 360 | - ) ); ?> |
|
| 360 | + )); ?> |
|
| 361 | 361 | </p> |
| 362 | - <p class="wpi-m0"><?php _e( 'Select item type.', 'invoicing' );?><br><?php _e( '<b>Standard:</b> Standard item type', 'invoicing' );?><br><?php _e( '<b>Fee:</b> Like Registration Fee, Sign up Fee etc.', 'invoicing' );?></p> |
|
| 362 | + <p class="wpi-m0"><?php _e('Select item type.', 'invoicing'); ?><br><?php _e('<b>Standard:</b> Standard item type', 'invoicing'); ?><br><?php _e('<b>Fee:</b> Like Registration Fee, Sign up Fee etc.', 'invoicing'); ?></p> |
|
| 363 | 363 | <?php |
| 364 | - do_action( 'wpinv_item_info_metabox_after', $post ); |
|
| 364 | + do_action('wpinv_item_info_metabox_after', $post); |
|
| 365 | 365 | } |
| 366 | 366 | |
| 367 | - public static function meta_values( $post ) { |
|
| 368 | - $meta_keys = apply_filters( 'wpinv_show_meta_values_for_keys', array( |
|
| 367 | + public static function meta_values($post) { |
|
| 368 | + $meta_keys = apply_filters('wpinv_show_meta_values_for_keys', array( |
|
| 369 | 369 | 'type', |
| 370 | 370 | 'custom_id' |
| 371 | - ) ); |
|
| 371 | + )); |
|
| 372 | 372 | |
| 373 | - if ( empty( $meta_keys ) ) { |
|
| 373 | + if (empty($meta_keys)) { |
|
| 374 | 374 | return; |
| 375 | 375 | } |
| 376 | 376 | |
| 377 | - do_action( 'wpinv_meta_values_metabox_before', $post ); |
|
| 377 | + do_action('wpinv_meta_values_metabox_before', $post); |
|
| 378 | 378 | |
| 379 | - foreach ( $meta_keys as $meta_key ) { |
|
| 379 | + foreach ($meta_keys as $meta_key) { |
|
| 380 | 380 | ?> |
| 381 | - <p class="wpi-mtb05"><label><strong><?php echo $meta_key; ?></strong>: <?php echo get_post_meta( $post->ID, '_wpinv_' . $meta_key, true ); ?></label></p> |
|
| 381 | + <p class="wpi-mtb05"><label><strong><?php echo $meta_key; ?></strong>: <?php echo get_post_meta($post->ID, '_wpinv_' . $meta_key, true); ?></label></p> |
|
| 382 | 382 | <?php |
| 383 | 383 | } |
| 384 | 384 | |
| 385 | - do_action( 'wpinv_meta_values_metabox_after', $post ); |
|
| 385 | + do_action('wpinv_meta_values_metabox_after', $post); |
|
| 386 | 386 | } |
| 387 | 387 | |
| 388 | - public static function save( $post_id, $data, $post ) { |
|
| 389 | - $invoice = new WPInv_Invoice( $post_id ); |
|
| 388 | + public static function save($post_id, $data, $post) { |
|
| 389 | + $invoice = new WPInv_Invoice($post_id); |
|
| 390 | 390 | |
| 391 | 391 | // Billing |
| 392 | - $first_name = sanitize_text_field( $data['wpinv_first_name'] ); |
|
| 393 | - $last_name = sanitize_text_field( $data['wpinv_last_name'] ); |
|
| 394 | - $company = sanitize_text_field( $data['wpinv_company'] ); |
|
| 395 | - $vat_number = sanitize_text_field( $data['wpinv_vat_number'] ); |
|
| 396 | - $phone = sanitize_text_field( $data['wpinv_phone'] ); |
|
| 397 | - $address = sanitize_text_field( $data['wpinv_address'] ); |
|
| 398 | - $city = sanitize_text_field( $data['wpinv_city'] ); |
|
| 399 | - $zip = sanitize_text_field( $data['wpinv_zip'] ); |
|
| 400 | - $country = sanitize_text_field( $data['wpinv_country'] ); |
|
| 401 | - $state = sanitize_text_field( $data['wpinv_state'] ); |
|
| 392 | + $first_name = sanitize_text_field($data['wpinv_first_name']); |
|
| 393 | + $last_name = sanitize_text_field($data['wpinv_last_name']); |
|
| 394 | + $company = sanitize_text_field($data['wpinv_company']); |
|
| 395 | + $vat_number = sanitize_text_field($data['wpinv_vat_number']); |
|
| 396 | + $phone = sanitize_text_field($data['wpinv_phone']); |
|
| 397 | + $address = sanitize_text_field($data['wpinv_address']); |
|
| 398 | + $city = sanitize_text_field($data['wpinv_city']); |
|
| 399 | + $zip = sanitize_text_field($data['wpinv_zip']); |
|
| 400 | + $country = sanitize_text_field($data['wpinv_country']); |
|
| 401 | + $state = sanitize_text_field($data['wpinv_state']); |
|
| 402 | 402 | |
| 403 | 403 | // Details |
| 404 | - $status = sanitize_text_field( $data['wpinv_status'] ); |
|
| 405 | - $old_status = !empty( $data['original_post_status'] ) ? sanitize_text_field( $data['original_post_status'] ) : $status; |
|
| 406 | - $number = sanitize_text_field( $data['wpinv_number'] ); |
|
| 407 | - $due_date = isset( $data['wpinv_due_date'] ) ? sanitize_text_field( $data['wpinv_due_date'] ) : ''; |
|
| 404 | + $status = sanitize_text_field($data['wpinv_status']); |
|
| 405 | + $old_status = !empty($data['original_post_status']) ? sanitize_text_field($data['original_post_status']) : $status; |
|
| 406 | + $number = sanitize_text_field($data['wpinv_number']); |
|
| 407 | + $due_date = isset($data['wpinv_due_date']) ? sanitize_text_field($data['wpinv_due_date']) : ''; |
|
| 408 | 408 | //$discounts = sanitize_text_field( $data['wpinv_discounts'] ); |
| 409 | 409 | //$discount = sanitize_text_field( $data['wpinv_discount'] ); |
| 410 | 410 | |
| 411 | - $ip = $invoice->get_ip() ? $invoice->get_ip() : wpinv_get_ip(); |
|
| 412 | - |
|
| 413 | - $invoice->set( 'due_date', $due_date ); |
|
| 414 | - $invoice->set( 'first_name', $first_name ); |
|
| 415 | - $invoice->set( 'last_name', $last_name ); |
|
| 416 | - $invoice->set( 'company', $company ); |
|
| 417 | - $invoice->set( 'vat_number', $vat_number ); |
|
| 418 | - $invoice->set( 'phone', $phone ); |
|
| 419 | - $invoice->set( 'address', $address ); |
|
| 420 | - $invoice->set( 'city', $city ); |
|
| 421 | - $invoice->set( 'zip', $zip ); |
|
| 422 | - $invoice->set( 'country', $country ); |
|
| 423 | - $invoice->set( 'state', $state ); |
|
| 424 | - $invoice->set( 'status', $status ); |
|
| 411 | + $ip = $invoice->get_ip() ? $invoice->get_ip() : wpinv_get_ip(); |
|
| 412 | + |
|
| 413 | + $invoice->set('due_date', $due_date); |
|
| 414 | + $invoice->set('first_name', $first_name); |
|
| 415 | + $invoice->set('last_name', $last_name); |
|
| 416 | + $invoice->set('company', $company); |
|
| 417 | + $invoice->set('vat_number', $vat_number); |
|
| 418 | + $invoice->set('phone', $phone); |
|
| 419 | + $invoice->set('address', $address); |
|
| 420 | + $invoice->set('city', $city); |
|
| 421 | + $invoice->set('zip', $zip); |
|
| 422 | + $invoice->set('country', $country); |
|
| 423 | + $invoice->set('state', $state); |
|
| 424 | + $invoice->set('status', $status); |
|
| 425 | 425 | //$invoice->set( 'number', $number ); |
| 426 | 426 | //$invoice->set( 'discounts', $discounts ); |
| 427 | 427 | //$invoice->set( 'discount', $discount ); |
| 428 | - $invoice->set( 'ip', $ip ); |
|
| 428 | + $invoice->set('ip', $ip); |
|
| 429 | 429 | $invoice->old_status = $_POST['original_post_status']; |
| 430 | 430 | |
| 431 | 431 | $currency = $invoice->get_currency(); |
| 432 | - if ( ! empty( sanitize_text_field( $data['wpinv_currency'] ) ) ) { |
|
| 433 | - $currency = sanitize_text_field( $data['wpinv_currency'] ); |
|
| 432 | + if (!empty(sanitize_text_field($data['wpinv_currency']))) { |
|
| 433 | + $currency = sanitize_text_field($data['wpinv_currency']); |
|
| 434 | 434 | } |
| 435 | 435 | |
| 436 | - if ( empty( $currency ) ) { |
|
| 436 | + if (empty($currency)) { |
|
| 437 | 437 | $currency = wpinv_get_currency(); |
| 438 | 438 | } |
| 439 | 439 | |
| 440 | - if ( ! $invoice->is_paid() ) { |
|
| 440 | + if (!$invoice->is_paid()) { |
|
| 441 | 441 | $invoice->currency = $currency; |
| 442 | 442 | } |
| 443 | 443 | |
| 444 | - if ( !empty( $data['wpinv_gateway'] ) ) { |
|
| 445 | - $invoice->set( 'gateway', sanitize_text_field( $data['wpinv_gateway'] ) ); |
|
| 444 | + if (!empty($data['wpinv_gateway'])) { |
|
| 445 | + $invoice->set('gateway', sanitize_text_field($data['wpinv_gateway'])); |
|
| 446 | 446 | } |
| 447 | 447 | $saved = $invoice->save(); |
| 448 | 448 | |
| 449 | 449 | // Check for payment notes |
| 450 | - if ( !empty( $data['invoice_note'] ) ) { |
|
| 451 | - $note = wp_kses( $data['invoice_note'], array() ); |
|
| 452 | - $note_type = sanitize_text_field( $data['invoice_note_type'] ); |
|
| 450 | + if (!empty($data['invoice_note'])) { |
|
| 451 | + $note = wp_kses($data['invoice_note'], array()); |
|
| 452 | + $note_type = sanitize_text_field($data['invoice_note_type']); |
|
| 453 | 453 | $is_customer_note = $note_type == 'customer' ? 1 : 0; |
| 454 | 454 | |
| 455 | - wpinv_insert_payment_note( $invoice->ID, $note, $is_customer_note ); |
|
| 455 | + wpinv_insert_payment_note($invoice->ID, $note, $is_customer_note); |
|
| 456 | 456 | } |
| 457 | 457 | |
| 458 | 458 | // Update user address if empty. |
| 459 | - if ( $saved && !empty( $invoice ) ) { |
|
| 460 | - if ( $user_id = $invoice->get_user_id() ) { |
|
| 461 | - $user_address = wpinv_get_user_address( $user_id, false ); |
|
| 459 | + if ($saved && !empty($invoice)) { |
|
| 460 | + if ($user_id = $invoice->get_user_id()) { |
|
| 461 | + $user_address = wpinv_get_user_address($user_id, false); |
|
| 462 | 462 | |
| 463 | 463 | if (empty($user_address['first_name'])) { |
| 464 | - update_user_meta( $user_id, '_wpinv_first_name', $first_name ); |
|
| 465 | - update_user_meta( $user_id, '_wpinv_last_name', $last_name ); |
|
| 464 | + update_user_meta($user_id, '_wpinv_first_name', $first_name); |
|
| 465 | + update_user_meta($user_id, '_wpinv_last_name', $last_name); |
|
| 466 | 466 | } else if (empty($user_address['last_name']) && $user_address['first_name'] == $first_name) { |
| 467 | - update_user_meta( $user_id, '_wpinv_last_name', $last_name ); |
|
| 467 | + update_user_meta($user_id, '_wpinv_last_name', $last_name); |
|
| 468 | 468 | } |
| 469 | 469 | |
| 470 | 470 | if (empty($user_address['address']) || empty($user_address['city']) || empty($user_address['state']) || empty($user_address['country'])) { |
| 471 | - update_user_meta( $user_id, '_wpinv_address', $address ); |
|
| 472 | - update_user_meta( $user_id, '_wpinv_city', $city ); |
|
| 473 | - update_user_meta( $user_id, '_wpinv_state', $state ); |
|
| 474 | - update_user_meta( $user_id, '_wpinv_country', $country ); |
|
| 475 | - update_user_meta( $user_id, '_wpinv_zip', $zip ); |
|
| 476 | - update_user_meta( $user_id, '_wpinv_phone', $phone ); |
|
| 471 | + update_user_meta($user_id, '_wpinv_address', $address); |
|
| 472 | + update_user_meta($user_id, '_wpinv_city', $city); |
|
| 473 | + update_user_meta($user_id, '_wpinv_state', $state); |
|
| 474 | + update_user_meta($user_id, '_wpinv_country', $country); |
|
| 475 | + update_user_meta($user_id, '_wpinv_zip', $zip); |
|
| 476 | + update_user_meta($user_id, '_wpinv_phone', $phone); |
|
| 477 | 477 | } |
| 478 | 478 | } |
| 479 | 479 | |
| 480 | - do_action( 'wpinv_invoice_metabox_saved', $invoice ); |
|
| 480 | + do_action('wpinv_invoice_metabox_saved', $invoice); |
|
| 481 | 481 | } |
| 482 | 482 | |
| 483 | 483 | return $saved; |
@@ -7,28 +7,28 @@ discard block |
||
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | 9 | // MUST have WordPress. |
| 10 | -if ( !defined( 'WPINC' ) ) { |
|
| 11 | - exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) ); |
|
| 10 | +if (!defined('WPINC')) { |
|
| 11 | + exit('Do NOT access this file directly: ' . basename(__FILE__)); |
|
| 12 | 12 | } |
| 13 | 13 | |
| 14 | 14 | class WPInv_Ajax { |
| 15 | 15 | public static function init() { |
| 16 | - add_action( 'init', array( __CLASS__, 'define_ajax' ), 0 ); |
|
| 17 | - add_action( 'template_redirect', array( __CLASS__, 'do_wpinv_ajax' ), 0 ); |
|
| 16 | + add_action('init', array(__CLASS__, 'define_ajax'), 0); |
|
| 17 | + add_action('template_redirect', array(__CLASS__, 'do_wpinv_ajax'), 0); |
|
| 18 | 18 | self::add_ajax_events(); |
| 19 | 19 | } |
| 20 | 20 | |
| 21 | 21 | public static function define_ajax() { |
| 22 | - if ( !empty( $_GET['wpinv-ajax'] ) ) { |
|
| 23 | - if ( ! defined( 'DOING_AJAX' ) ) { |
|
| 24 | - define( 'DOING_AJAX', true ); |
|
| 22 | + if (!empty($_GET['wpinv-ajax'])) { |
|
| 23 | + if (!defined('DOING_AJAX')) { |
|
| 24 | + define('DOING_AJAX', true); |
|
| 25 | 25 | } |
| 26 | - if ( ! defined( 'WC_DOING_AJAX' ) ) { |
|
| 27 | - define( 'WC_DOING_AJAX', true ); |
|
| 26 | + if (!defined('WC_DOING_AJAX')) { |
|
| 27 | + define('WC_DOING_AJAX', true); |
|
| 28 | 28 | } |
| 29 | 29 | // Turn off display_errors during AJAX events to prevent malformed JSON |
| 30 | - if ( ! WP_DEBUG || ( WP_DEBUG && ! WP_DEBUG_DISPLAY ) ) { |
|
| 31 | - /** @scrutinizer ignore-unhandled */ @ini_set( 'display_errors', 0 ); |
|
| 30 | + if (!WP_DEBUG || (WP_DEBUG && !WP_DEBUG_DISPLAY)) { |
|
| 31 | + /** @scrutinizer ignore-unhandled */ @ini_set('display_errors', 0); |
|
| 32 | 32 | } |
| 33 | 33 | $GLOBALS['wpdb']->hide_errors(); |
| 34 | 34 | } |
@@ -37,24 +37,24 @@ discard block |
||
| 37 | 37 | public static function do_wpinv_ajax() { |
| 38 | 38 | global $wp_query; |
| 39 | 39 | |
| 40 | - if ( !empty( $_GET['wpinv-ajax'] ) ) { |
|
| 41 | - $wp_query->set( 'wpinv-ajax', sanitize_text_field( $_GET['wpinv-ajax'] ) ); |
|
| 40 | + if (!empty($_GET['wpinv-ajax'])) { |
|
| 41 | + $wp_query->set('wpinv-ajax', sanitize_text_field($_GET['wpinv-ajax'])); |
|
| 42 | 42 | } |
| 43 | 43 | |
| 44 | - if ( $action = $wp_query->get( 'wpinv-ajax' ) ) { |
|
| 44 | + if ($action = $wp_query->get('wpinv-ajax')) { |
|
| 45 | 45 | self::wpinv_ajax_headers(); |
| 46 | - do_action( 'wpinv_ajax_' . sanitize_text_field( $action ) ); |
|
| 46 | + do_action('wpinv_ajax_' . sanitize_text_field($action)); |
|
| 47 | 47 | die(); |
| 48 | 48 | } |
| 49 | 49 | } |
| 50 | 50 | |
| 51 | 51 | private static function wpinv_ajax_headers() { |
| 52 | 52 | send_origin_headers(); |
| 53 | - /** @scrutinizer ignore-unhandled */ @header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) ); |
|
| 54 | - /** @scrutinizer ignore-unhandled */ @header( 'X-Robots-Tag: noindex' ); |
|
| 53 | + /** @scrutinizer ignore-unhandled */ @header('Content-Type: text/html; charset=' . get_option('blog_charset')); |
|
| 54 | + /** @scrutinizer ignore-unhandled */ @header('X-Robots-Tag: noindex'); |
|
| 55 | 55 | send_nosniff_header(); |
| 56 | 56 | nocache_headers(); |
| 57 | - status_header( 200 ); |
|
| 57 | + status_header(200); |
|
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | public static function add_ajax_events() { |
@@ -77,39 +77,39 @@ discard block |
||
| 77 | 77 | 'buy_items' => true, |
| 78 | 78 | ); |
| 79 | 79 | |
| 80 | - foreach ( $ajax_events as $ajax_event => $nopriv ) { |
|
| 81 | - add_action( 'wp_ajax_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
| 80 | + foreach ($ajax_events as $ajax_event => $nopriv) { |
|
| 81 | + add_action('wp_ajax_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
| 82 | 82 | |
| 83 | - if ( !defined( 'WPI_AJAX_' . strtoupper( $nopriv ) ) ) { |
|
| 84 | - define( 'WPI_AJAX_' . strtoupper( $nopriv ), 1 ); |
|
| 83 | + if (!defined('WPI_AJAX_' . strtoupper($nopriv))) { |
|
| 84 | + define('WPI_AJAX_' . strtoupper($nopriv), 1); |
|
| 85 | 85 | } |
| 86 | 86 | |
| 87 | - if ( $nopriv ) { |
|
| 88 | - add_action( 'wp_ajax_nopriv_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
| 87 | + if ($nopriv) { |
|
| 88 | + add_action('wp_ajax_nopriv_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
| 89 | 89 | |
| 90 | - add_action( 'wpinv_ajax_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
| 90 | + add_action('wpinv_ajax_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
| 91 | 91 | } |
| 92 | 92 | } |
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | public static function add_note() { |
| 96 | - check_ajax_referer( 'add-invoice-note', '_nonce' ); |
|
| 96 | + check_ajax_referer('add-invoice-note', '_nonce'); |
|
| 97 | 97 | |
| 98 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
| 98 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
| 99 | 99 | die(-1); |
| 100 | 100 | } |
| 101 | 101 | |
| 102 | - $post_id = absint( $_POST['post_id'] ); |
|
| 103 | - $note = wp_kses_post( trim( stripslashes( $_POST['note'] ) ) ); |
|
| 104 | - $note_type = sanitize_text_field( $_POST['note_type'] ); |
|
| 102 | + $post_id = absint($_POST['post_id']); |
|
| 103 | + $note = wp_kses_post(trim(stripslashes($_POST['note']))); |
|
| 104 | + $note_type = sanitize_text_field($_POST['note_type']); |
|
| 105 | 105 | |
| 106 | 106 | $is_customer_note = $note_type == 'customer' ? 1 : 0; |
| 107 | 107 | |
| 108 | - if ( $post_id > 0 ) { |
|
| 109 | - $note_id = wpinv_insert_payment_note( $post_id, $note, $is_customer_note ); |
|
| 108 | + if ($post_id > 0) { |
|
| 109 | + $note_id = wpinv_insert_payment_note($post_id, $note, $is_customer_note); |
|
| 110 | 110 | |
| 111 | - if ( $note_id > 0 && !is_wp_error( $note_id ) ) { |
|
| 112 | - wpinv_get_invoice_note_line_item( $note_id ); |
|
| 111 | + if ($note_id > 0 && !is_wp_error($note_id)) { |
|
| 112 | + wpinv_get_invoice_note_line_item($note_id); |
|
| 113 | 113 | } |
| 114 | 114 | } |
| 115 | 115 | |
@@ -117,16 +117,16 @@ discard block |
||
| 117 | 117 | } |
| 118 | 118 | |
| 119 | 119 | public static function delete_note() { |
| 120 | - check_ajax_referer( 'delete-invoice-note', '_nonce' ); |
|
| 120 | + check_ajax_referer('delete-invoice-note', '_nonce'); |
|
| 121 | 121 | |
| 122 | - if ( !wpinv_current_user_can_manage_invoicing() ) { |
|
| 122 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
| 123 | 123 | die(-1); |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | - $note_id = (int)$_POST['note_id']; |
|
| 126 | + $note_id = (int) $_POST['note_id']; |
|
| 127 | 127 | |
| 128 | - if ( $note_id > 0 ) { |
|
| 129 | - wp_delete_comment( $note_id, true ); |
|
| 128 | + if ($note_id > 0) { |
|
| 129 | + wp_delete_comment($note_id, true); |
|
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | die(); |
@@ -139,8 +139,8 @@ discard block |
||
| 139 | 139 | } |
| 140 | 140 | |
| 141 | 141 | public static function checkout() { |
| 142 | - if ( ! defined( 'WPINV_CHECKOUT' ) ) { |
|
| 143 | - define( 'WPINV_CHECKOUT', true ); |
|
| 142 | + if (!defined('WPINV_CHECKOUT')) { |
|
| 143 | + define('WPINV_CHECKOUT', true); |
|
| 144 | 144 | } |
| 145 | 145 | |
| 146 | 146 | wpinv_process_checkout(); |
@@ -149,53 +149,53 @@ discard block |
||
| 149 | 149 | |
| 150 | 150 | public static function add_invoice_item() { |
| 151 | 151 | global $wpi_userID, $wpinv_ip_address_country; |
| 152 | - check_ajax_referer( 'invoice-item', '_nonce' ); |
|
| 153 | - if ( !wpinv_current_user_can_manage_invoicing() ) { |
|
| 152 | + check_ajax_referer('invoice-item', '_nonce'); |
|
| 153 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
| 154 | 154 | die(-1); |
| 155 | 155 | } |
| 156 | 156 | |
| 157 | - $item_id = sanitize_text_field( $_POST['item_id'] ); |
|
| 158 | - $invoice_id = absint( $_POST['invoice_id'] ); |
|
| 157 | + $item_id = sanitize_text_field($_POST['item_id']); |
|
| 158 | + $invoice_id = absint($_POST['invoice_id']); |
|
| 159 | 159 | |
| 160 | - if ( !is_numeric( $invoice_id ) || !is_numeric( $item_id ) ) { |
|
| 160 | + if (!is_numeric($invoice_id) || !is_numeric($item_id)) { |
|
| 161 | 161 | die(); |
| 162 | 162 | } |
| 163 | 163 | |
| 164 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
| 165 | - if ( empty( $invoice ) ) { |
|
| 164 | + $invoice = wpinv_get_invoice($invoice_id); |
|
| 165 | + if (empty($invoice)) { |
|
| 166 | 166 | die(); |
| 167 | 167 | } |
| 168 | 168 | |
| 169 | - if ( $invoice->is_paid() || $invoice->is_refunded() ) { |
|
| 169 | + if ($invoice->is_paid() || $invoice->is_refunded()) { |
|
| 170 | 170 | die(); // Don't allow modify items for paid invoice. |
| 171 | 171 | } |
| 172 | 172 | |
| 173 | - if ( !empty( $_POST['user_id'] ) ) { |
|
| 174 | - $wpi_userID = absint( $_POST['user_id'] ); |
|
| 173 | + if (!empty($_POST['user_id'])) { |
|
| 174 | + $wpi_userID = absint($_POST['user_id']); |
|
| 175 | 175 | } |
| 176 | 176 | |
| 177 | - $item = new WPInv_Item( $item_id ); |
|
| 178 | - if ( !( !empty( $item ) && $item->post_type == 'wpi_item' ) ) { |
|
| 177 | + $item = new WPInv_Item($item_id); |
|
| 178 | + if (!(!empty($item) && $item->post_type == 'wpi_item')) { |
|
| 179 | 179 | die(); |
| 180 | 180 | } |
| 181 | 181 | |
| 182 | 182 | // Validate item before adding to invoice because recurring item must be paid individually. |
| 183 | - if ( !empty( $invoice->cart_details ) ) { |
|
| 183 | + if (!empty($invoice->cart_details)) { |
|
| 184 | 184 | $valid = true; |
| 185 | 185 | |
| 186 | - if ( $recurring_item = $invoice->get_recurring() ) { |
|
| 187 | - if ( $recurring_item != $item_id ) { |
|
| 186 | + if ($recurring_item = $invoice->get_recurring()) { |
|
| 187 | + if ($recurring_item != $item_id) { |
|
| 188 | 188 | $valid = false; |
| 189 | 189 | } |
| 190 | - } else if ( wpinv_is_recurring_item( $item_id ) ) { |
|
| 190 | + } else if (wpinv_is_recurring_item($item_id)) { |
|
| 191 | 191 | $valid = false; |
| 192 | 192 | } |
| 193 | 193 | |
| 194 | - if ( !$valid ) { |
|
| 194 | + if (!$valid) { |
|
| 195 | 195 | $response = array(); |
| 196 | 196 | $response['success'] = false; |
| 197 | - $response['msg'] = __( 'You can not add item because recurring item must be paid individually!', 'invoicing' ); |
|
| 198 | - wp_send_json( $response ); |
|
| 197 | + $response['msg'] = __('You can not add item because recurring item must be paid individually!', 'invoicing'); |
|
| 198 | + wp_send_json($response); |
|
| 199 | 199 | } |
| 200 | 200 | } |
| 201 | 201 | |
@@ -203,11 +203,11 @@ discard block |
||
| 203 | 203 | |
| 204 | 204 | $data = array(); |
| 205 | 205 | $data['invoice_id'] = $invoice_id; |
| 206 | - $data['cart_discounts'] = $invoice->get_discounts( true ); |
|
| 206 | + $data['cart_discounts'] = $invoice->get_discounts(true); |
|
| 207 | 207 | |
| 208 | - wpinv_set_checkout_session( $data ); |
|
| 208 | + wpinv_set_checkout_session($data); |
|
| 209 | 209 | |
| 210 | - $quantity = wpinv_item_quantities_enabled() && !empty($_POST['qty']) && (int)$_POST['qty'] > 0 ? (int)$_POST['qty'] : 1; |
|
| 210 | + $quantity = wpinv_item_quantities_enabled() && !empty($_POST['qty']) && (int) $_POST['qty'] > 0 ? (int) $_POST['qty'] : 1; |
|
| 211 | 211 | |
| 212 | 212 | $args = array( |
| 213 | 213 | 'id' => $item_id, |
@@ -220,21 +220,21 @@ discard block |
||
| 220 | 220 | 'fees' => array() |
| 221 | 221 | ); |
| 222 | 222 | |
| 223 | - $invoice->add_item( $item_id, $args ); |
|
| 223 | + $invoice->add_item($item_id, $args); |
|
| 224 | 224 | $invoice->save(); |
| 225 | 225 | |
| 226 | - if ( empty( $_POST['country'] ) ) { |
|
| 226 | + if (empty($_POST['country'])) { |
|
| 227 | 227 | $_POST['country'] = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country(); |
| 228 | 228 | } |
| 229 | - if ( empty( $_POST['state'] ) ) { |
|
| 229 | + if (empty($_POST['state'])) { |
|
| 230 | 230 | $_POST['state'] = $invoice->state; |
| 231 | 231 | } |
| 232 | 232 | |
| 233 | - $invoice->country = sanitize_text_field( $_POST['country'] ); |
|
| 234 | - $invoice->state = sanitize_text_field( $_POST['state'] ); |
|
| 233 | + $invoice->country = sanitize_text_field($_POST['country']); |
|
| 234 | + $invoice->state = sanitize_text_field($_POST['state']); |
|
| 235 | 235 | |
| 236 | - $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) ); |
|
| 237 | - $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) ); |
|
| 236 | + $invoice->set('country', sanitize_text_field($_POST['country'])); |
|
| 237 | + $invoice->set('state', sanitize_text_field($_POST['state'])); |
|
| 238 | 238 | |
| 239 | 239 | $wpinv_ip_address_country = $invoice->country; |
| 240 | 240 | |
@@ -242,7 +242,7 @@ discard block |
||
| 242 | 242 | |
| 243 | 243 | $response = array(); |
| 244 | 244 | $response['success'] = true; |
| 245 | - $response['data']['items'] = wpinv_admin_get_line_items( $invoice ); |
|
| 245 | + $response['data']['items'] = wpinv_admin_get_line_items($invoice); |
|
| 246 | 246 | $response['data']['subtotal'] = $invoice->get_subtotal(); |
| 247 | 247 | $response['data']['subtotalf'] = $invoice->get_subtotal(true); |
| 248 | 248 | $response['data']['tax'] = $invoice->get_tax(); |
@@ -254,40 +254,40 @@ discard block |
||
| 254 | 254 | |
| 255 | 255 | wpinv_set_checkout_session($checkout_session); |
| 256 | 256 | |
| 257 | - wp_send_json( $response ); |
|
| 257 | + wp_send_json($response); |
|
| 258 | 258 | } |
| 259 | 259 | |
| 260 | 260 | public static function remove_invoice_item() { |
| 261 | 261 | global $wpi_userID, $wpinv_ip_address_country; |
| 262 | 262 | |
| 263 | - check_ajax_referer( 'invoice-item', '_nonce' ); |
|
| 264 | - if ( !wpinv_current_user_can_manage_invoicing() ) { |
|
| 263 | + check_ajax_referer('invoice-item', '_nonce'); |
|
| 264 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
| 265 | 265 | die(-1); |
| 266 | 266 | } |
| 267 | 267 | |
| 268 | - $item_id = sanitize_text_field( $_POST['item_id'] ); |
|
| 269 | - $invoice_id = absint( $_POST['invoice_id'] ); |
|
| 270 | - $cart_index = isset( $_POST['index'] ) && $_POST['index'] >= 0 ? $_POST['index'] : false; |
|
| 268 | + $item_id = sanitize_text_field($_POST['item_id']); |
|
| 269 | + $invoice_id = absint($_POST['invoice_id']); |
|
| 270 | + $cart_index = isset($_POST['index']) && $_POST['index'] >= 0 ? $_POST['index'] : false; |
|
| 271 | 271 | |
| 272 | - if ( !is_numeric( $invoice_id ) || !is_numeric( $item_id ) ) { |
|
| 272 | + if (!is_numeric($invoice_id) || !is_numeric($item_id)) { |
|
| 273 | 273 | die(); |
| 274 | 274 | } |
| 275 | 275 | |
| 276 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
| 277 | - if ( empty( $invoice ) ) { |
|
| 276 | + $invoice = wpinv_get_invoice($invoice_id); |
|
| 277 | + if (empty($invoice)) { |
|
| 278 | 278 | die(); |
| 279 | 279 | } |
| 280 | 280 | |
| 281 | - if ( $invoice->is_paid() || $invoice->is_refunded() ) { |
|
| 281 | + if ($invoice->is_paid() || $invoice->is_refunded()) { |
|
| 282 | 282 | die(); // Don't allow modify items for paid invoice. |
| 283 | 283 | } |
| 284 | 284 | |
| 285 | - if ( !empty( $_POST['user_id'] ) ) { |
|
| 286 | - $wpi_userID = absint( $_POST['user_id'] ); |
|
| 285 | + if (!empty($_POST['user_id'])) { |
|
| 286 | + $wpi_userID = absint($_POST['user_id']); |
|
| 287 | 287 | } |
| 288 | 288 | |
| 289 | - $item = new WPInv_Item( $item_id ); |
|
| 290 | - if ( !( !empty( $item ) && $item->post_type == 'wpi_item' ) ) { |
|
| 289 | + $item = new WPInv_Item($item_id); |
|
| 290 | + if (!(!empty($item) && $item->post_type == 'wpi_item')) { |
|
| 291 | 291 | die(); |
| 292 | 292 | } |
| 293 | 293 | |
@@ -295,9 +295,9 @@ discard block |
||
| 295 | 295 | |
| 296 | 296 | $data = array(); |
| 297 | 297 | $data['invoice_id'] = $invoice_id; |
| 298 | - $data['cart_discounts'] = $invoice->get_discounts( true ); |
|
| 298 | + $data['cart_discounts'] = $invoice->get_discounts(true); |
|
| 299 | 299 | |
| 300 | - wpinv_set_checkout_session( $data ); |
|
| 300 | + wpinv_set_checkout_session($data); |
|
| 301 | 301 | |
| 302 | 302 | $args = array( |
| 303 | 303 | 'id' => $item_id, |
@@ -305,21 +305,21 @@ discard block |
||
| 305 | 305 | 'cart_index' => $cart_index |
| 306 | 306 | ); |
| 307 | 307 | |
| 308 | - $invoice->remove_item( $item_id, $args ); |
|
| 308 | + $invoice->remove_item($item_id, $args); |
|
| 309 | 309 | $invoice->save(); |
| 310 | 310 | |
| 311 | - if ( empty( $_POST['country'] ) ) { |
|
| 311 | + if (empty($_POST['country'])) { |
|
| 312 | 312 | $_POST['country'] = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country(); |
| 313 | 313 | } |
| 314 | - if ( empty( $_POST['state'] ) ) { |
|
| 314 | + if (empty($_POST['state'])) { |
|
| 315 | 315 | $_POST['state'] = $invoice->state; |
| 316 | 316 | } |
| 317 | 317 | |
| 318 | - $invoice->country = sanitize_text_field( $_POST['country'] ); |
|
| 319 | - $invoice->state = sanitize_text_field( $_POST['state'] ); |
|
| 318 | + $invoice->country = sanitize_text_field($_POST['country']); |
|
| 319 | + $invoice->state = sanitize_text_field($_POST['state']); |
|
| 320 | 320 | |
| 321 | - $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) ); |
|
| 322 | - $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) ); |
|
| 321 | + $invoice->set('country', sanitize_text_field($_POST['country'])); |
|
| 322 | + $invoice->set('state', sanitize_text_field($_POST['state'])); |
|
| 323 | 323 | |
| 324 | 324 | $wpinv_ip_address_country = $invoice->country; |
| 325 | 325 | |
@@ -327,7 +327,7 @@ discard block |
||
| 327 | 327 | |
| 328 | 328 | $response = array(); |
| 329 | 329 | $response['success'] = true; |
| 330 | - $response['data']['items'] = wpinv_admin_get_line_items( $invoice ); |
|
| 330 | + $response['data']['items'] = wpinv_admin_get_line_items($invoice); |
|
| 331 | 331 | $response['data']['subtotal'] = $invoice->get_subtotal(); |
| 332 | 332 | $response['data']['subtotalf'] = $invoice->get_subtotal(true); |
| 333 | 333 | $response['data']['tax'] = $invoice->get_tax(); |
@@ -339,55 +339,55 @@ discard block |
||
| 339 | 339 | |
| 340 | 340 | wpinv_set_checkout_session($checkout_session); |
| 341 | 341 | |
| 342 | - wp_send_json( $response ); |
|
| 342 | + wp_send_json($response); |
|
| 343 | 343 | } |
| 344 | 344 | |
| 345 | 345 | public static function create_invoice_item() { |
| 346 | - check_ajax_referer( 'invoice-item', '_nonce' ); |
|
| 347 | - if ( !wpinv_current_user_can_manage_invoicing() ) { |
|
| 346 | + check_ajax_referer('invoice-item', '_nonce'); |
|
| 347 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
| 348 | 348 | die(-1); |
| 349 | 349 | } |
| 350 | 350 | |
| 351 | - $invoice_id = absint( $_POST['invoice_id'] ); |
|
| 351 | + $invoice_id = absint($_POST['invoice_id']); |
|
| 352 | 352 | |
| 353 | 353 | // Find the item |
| 354 | - if ( !is_numeric( $invoice_id ) ) { |
|
| 354 | + if (!is_numeric($invoice_id)) { |
|
| 355 | 355 | die(); |
| 356 | 356 | } |
| 357 | 357 | |
| 358 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
| 359 | - if ( empty( $invoice ) ) { |
|
| 358 | + $invoice = wpinv_get_invoice($invoice_id); |
|
| 359 | + if (empty($invoice)) { |
|
| 360 | 360 | die(); |
| 361 | 361 | } |
| 362 | 362 | |
| 363 | 363 | // Validate item before adding to invoice because recurring item must be paid individually. |
| 364 | - if ( !empty( $invoice->cart_details ) && $invoice->get_recurring() ) { |
|
| 364 | + if (!empty($invoice->cart_details) && $invoice->get_recurring()) { |
|
| 365 | 365 | $response = array(); |
| 366 | 366 | $response['success'] = false; |
| 367 | - $response['msg'] = __( 'You can not add item because recurring item must be paid individually!', 'invoicing' ); |
|
| 368 | - wp_send_json( $response ); |
|
| 367 | + $response['msg'] = __('You can not add item because recurring item must be paid individually!', 'invoicing'); |
|
| 368 | + wp_send_json($response); |
|
| 369 | 369 | } |
| 370 | 370 | |
| 371 | - $save_item = wp_unslash( $_POST['_wpinv_quick'] ); |
|
| 371 | + $save_item = wp_unslash($_POST['_wpinv_quick']); |
|
| 372 | 372 | |
| 373 | 373 | $meta = array(); |
| 374 | 374 | $meta['type'] = !empty($save_item['type']) ? sanitize_text_field($save_item['type']) : 'custom'; |
| 375 | - $meta['price'] = !empty($save_item['price']) ? wpinv_sanitize_amount( $save_item['price'] ) : 0; |
|
| 375 | + $meta['price'] = !empty($save_item['price']) ? wpinv_sanitize_amount($save_item['price']) : 0; |
|
| 376 | 376 | $meta['vat_rule'] = !empty($save_item['vat_rule']) ? sanitize_text_field($save_item['vat_rule']) : 'digital'; |
| 377 | 377 | $meta['vat_class'] = !empty($save_item['vat_class']) ? sanitize_text_field($save_item['vat_class']) : '_standard'; |
| 378 | 378 | |
| 379 | 379 | $data = array(); |
| 380 | 380 | $data['post_title'] = sanitize_text_field($save_item['name']); |
| 381 | 381 | $data['post_status'] = 'publish'; |
| 382 | - $data['post_excerpt'] = ! empty( $save_item['excerpt'] ) ? wp_kses_post( $save_item['excerpt'] ) : ''; |
|
| 382 | + $data['post_excerpt'] = !empty($save_item['excerpt']) ? wp_kses_post($save_item['excerpt']) : ''; |
|
| 383 | 383 | $data['meta'] = $meta; |
| 384 | 384 | |
| 385 | 385 | $item = new WPInv_Item(); |
| 386 | - $item->create( $data ); |
|
| 386 | + $item->create($data); |
|
| 387 | 387 | |
| 388 | - if ( !empty( $item ) ) { |
|
| 388 | + if (!empty($item)) { |
|
| 389 | 389 | $_POST['item_id'] = $item->ID; |
| 390 | - $_POST['qty'] = !empty($save_item['qty']) && $save_item['qty'] > 0 ? (int)$save_item['qty'] : 1; |
|
| 390 | + $_POST['qty'] = !empty($save_item['qty']) && $save_item['qty'] > 0 ? (int) $save_item['qty'] : 1; |
|
| 391 | 391 | |
| 392 | 392 | self::add_invoice_item(); |
| 393 | 393 | } |
@@ -395,15 +395,15 @@ discard block |
||
| 395 | 395 | } |
| 396 | 396 | |
| 397 | 397 | public static function get_billing_details() { |
| 398 | - check_ajax_referer( 'get-billing-details', '_nonce' ); |
|
| 398 | + check_ajax_referer('get-billing-details', '_nonce'); |
|
| 399 | 399 | |
| 400 | - if ( !wpinv_current_user_can_manage_invoicing() ) { |
|
| 400 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
| 401 | 401 | die(-1); |
| 402 | 402 | } |
| 403 | 403 | |
| 404 | - $user_id = (int)$_POST['user_id']; |
|
| 404 | + $user_id = (int) $_POST['user_id']; |
|
| 405 | 405 | $billing_details = wpinv_get_user_address($user_id); |
| 406 | - $billing_details = apply_filters( 'wpinv_fill_billing_details', $billing_details, $user_id ); |
|
| 406 | + $billing_details = apply_filters('wpinv_fill_billing_details', $billing_details, $user_id); |
|
| 407 | 407 | |
| 408 | 408 | if (isset($billing_details['user_id'])) { |
| 409 | 409 | unset($billing_details['user_id']); |
@@ -417,20 +417,20 @@ discard block |
||
| 417 | 417 | $response['success'] = true; |
| 418 | 418 | $response['data']['billing_details'] = $billing_details; |
| 419 | 419 | |
| 420 | - wp_send_json( $response ); |
|
| 420 | + wp_send_json($response); |
|
| 421 | 421 | } |
| 422 | 422 | |
| 423 | 423 | public static function admin_recalculate_totals() { |
| 424 | 424 | global $wpi_userID, $wpinv_ip_address_country; |
| 425 | 425 | |
| 426 | - check_ajax_referer( 'wpinv-nonce', '_nonce' ); |
|
| 427 | - if ( !wpinv_current_user_can_manage_invoicing() ) { |
|
| 426 | + check_ajax_referer('wpinv-nonce', '_nonce'); |
|
| 427 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
| 428 | 428 | die(-1); |
| 429 | 429 | } |
| 430 | 430 | |
| 431 | - $invoice_id = absint( $_POST['invoice_id'] ); |
|
| 432 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
| 433 | - if ( empty( $invoice ) ) { |
|
| 431 | + $invoice_id = absint($_POST['invoice_id']); |
|
| 432 | + $invoice = wpinv_get_invoice($invoice_id); |
|
| 433 | + if (empty($invoice)) { |
|
| 434 | 434 | die(); |
| 435 | 435 | } |
| 436 | 436 | |
@@ -438,23 +438,23 @@ discard block |
||
| 438 | 438 | |
| 439 | 439 | $data = array(); |
| 440 | 440 | $data['invoice_id'] = $invoice_id; |
| 441 | - $data['cart_discounts'] = $invoice->get_discounts( true ); |
|
| 441 | + $data['cart_discounts'] = $invoice->get_discounts(true); |
|
| 442 | 442 | |
| 443 | - wpinv_set_checkout_session( $data ); |
|
| 443 | + wpinv_set_checkout_session($data); |
|
| 444 | 444 | |
| 445 | - if ( !empty( $_POST['user_id'] ) ) { |
|
| 446 | - $wpi_userID = absint( $_POST['user_id'] ); |
|
| 445 | + if (!empty($_POST['user_id'])) { |
|
| 446 | + $wpi_userID = absint($_POST['user_id']); |
|
| 447 | 447 | } |
| 448 | 448 | |
| 449 | - if ( empty( $_POST['country'] ) ) { |
|
| 449 | + if (empty($_POST['country'])) { |
|
| 450 | 450 | $_POST['country'] = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country(); |
| 451 | 451 | } |
| 452 | 452 | |
| 453 | - $invoice->country = sanitize_text_field( $_POST['country'] ); |
|
| 454 | - $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) ); |
|
| 455 | - if ( isset( $_POST['state'] ) ) { |
|
| 456 | - $invoice->state = sanitize_text_field( $_POST['state'] ); |
|
| 457 | - $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) ); |
|
| 453 | + $invoice->country = sanitize_text_field($_POST['country']); |
|
| 454 | + $invoice->set('country', sanitize_text_field($_POST['country'])); |
|
| 455 | + if (isset($_POST['state'])) { |
|
| 456 | + $invoice->state = sanitize_text_field($_POST['state']); |
|
| 457 | + $invoice->set('state', sanitize_text_field($_POST['state'])); |
|
| 458 | 458 | } |
| 459 | 459 | |
| 460 | 460 | $wpinv_ip_address_country = $invoice->country; |
@@ -463,7 +463,7 @@ discard block |
||
| 463 | 463 | |
| 464 | 464 | $response = array(); |
| 465 | 465 | $response['success'] = true; |
| 466 | - $response['data']['items'] = wpinv_admin_get_line_items( $invoice ); |
|
| 466 | + $response['data']['items'] = wpinv_admin_get_line_items($invoice); |
|
| 467 | 467 | $response['data']['subtotal'] = $invoice->get_subtotal(); |
| 468 | 468 | $response['data']['subtotalf'] = $invoice->get_subtotal(true); |
| 469 | 469 | $response['data']['tax'] = $invoice->get_tax(); |
@@ -475,25 +475,25 @@ discard block |
||
| 475 | 475 | |
| 476 | 476 | wpinv_set_checkout_session($checkout_session); |
| 477 | 477 | |
| 478 | - wp_send_json( $response ); |
|
| 478 | + wp_send_json($response); |
|
| 479 | 479 | } |
| 480 | 480 | |
| 481 | 481 | public static function admin_apply_discount() { |
| 482 | 482 | global $wpi_userID; |
| 483 | 483 | |
| 484 | - check_ajax_referer( 'wpinv-nonce', '_nonce' ); |
|
| 485 | - if ( !wpinv_current_user_can_manage_invoicing() ) { |
|
| 484 | + check_ajax_referer('wpinv-nonce', '_nonce'); |
|
| 485 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
| 486 | 486 | die(-1); |
| 487 | 487 | } |
| 488 | 488 | |
| 489 | - $invoice_id = absint( $_POST['invoice_id'] ); |
|
| 490 | - $discount_code = sanitize_text_field( $_POST['code'] ); |
|
| 491 | - if ( empty( $invoice_id ) || empty( $discount_code ) ) { |
|
| 489 | + $invoice_id = absint($_POST['invoice_id']); |
|
| 490 | + $discount_code = sanitize_text_field($_POST['code']); |
|
| 491 | + if (empty($invoice_id) || empty($discount_code)) { |
|
| 492 | 492 | die(); |
| 493 | 493 | } |
| 494 | 494 | |
| 495 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
| 496 | - if ( empty( $invoice ) || ( !empty( $invoice ) && ( $invoice->is_paid() || $invoice->is_refunded() ) ) ) { |
|
| 495 | + $invoice = wpinv_get_invoice($invoice_id); |
|
| 496 | + if (empty($invoice) || (!empty($invoice) && ($invoice->is_paid() || $invoice->is_refunded()))) { |
|
| 497 | 497 | die(); |
| 498 | 498 | } |
| 499 | 499 | |
@@ -501,49 +501,49 @@ discard block |
||
| 501 | 501 | |
| 502 | 502 | $data = array(); |
| 503 | 503 | $data['invoice_id'] = $invoice_id; |
| 504 | - $data['cart_discounts'] = $invoice->get_discounts( true ); |
|
| 504 | + $data['cart_discounts'] = $invoice->get_discounts(true); |
|
| 505 | 505 | |
| 506 | - wpinv_set_checkout_session( $data ); |
|
| 506 | + wpinv_set_checkout_session($data); |
|
| 507 | 507 | |
| 508 | 508 | $response = array(); |
| 509 | 509 | $response['success'] = false; |
| 510 | - $response['msg'] = __( 'This discount is invalid.', 'invoicing' ); |
|
| 510 | + $response['msg'] = __('This discount is invalid.', 'invoicing'); |
|
| 511 | 511 | $response['data']['code'] = $discount_code; |
| 512 | 512 | |
| 513 | - if ( wpinv_is_discount_valid( $discount_code, $invoice->get_user_id() ) ) { |
|
| 514 | - $discounts = wpinv_set_cart_discount( $discount_code ); |
|
| 513 | + if (wpinv_is_discount_valid($discount_code, $invoice->get_user_id())) { |
|
| 514 | + $discounts = wpinv_set_cart_discount($discount_code); |
|
| 515 | 515 | |
| 516 | 516 | $response['success'] = true; |
| 517 | - $response['msg'] = __( 'Discount has been applied successfully.', 'invoicing' ); |
|
| 518 | - } else { |
|
| 517 | + $response['msg'] = __('Discount has been applied successfully.', 'invoicing'); |
|
| 518 | + } else { |
|
| 519 | 519 | $errors = wpinv_get_errors(); |
| 520 | - if ( !empty( $errors['wpinv-discount-error'] ) ) { |
|
| 520 | + if (!empty($errors['wpinv-discount-error'])) { |
|
| 521 | 521 | $response['msg'] = $errors['wpinv-discount-error']; |
| 522 | 522 | } |
| 523 | - wpinv_unset_error( 'wpinv-discount-error' ); |
|
| 523 | + wpinv_unset_error('wpinv-discount-error'); |
|
| 524 | 524 | } |
| 525 | 525 | |
| 526 | 526 | wpinv_set_checkout_session($checkout_session); |
| 527 | 527 | |
| 528 | - wp_send_json( $response ); |
|
| 528 | + wp_send_json($response); |
|
| 529 | 529 | } |
| 530 | 530 | |
| 531 | 531 | public static function admin_remove_discount() { |
| 532 | 532 | global $wpi_userID; |
| 533 | 533 | |
| 534 | - check_ajax_referer( 'wpinv-nonce', '_nonce' ); |
|
| 535 | - if ( !wpinv_current_user_can_manage_invoicing() ) { |
|
| 534 | + check_ajax_referer('wpinv-nonce', '_nonce'); |
|
| 535 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
| 536 | 536 | die(-1); |
| 537 | 537 | } |
| 538 | 538 | |
| 539 | - $invoice_id = absint( $_POST['invoice_id'] ); |
|
| 540 | - $discount_code = sanitize_text_field( $_POST['code'] ); |
|
| 541 | - if ( empty( $invoice_id ) || empty( $discount_code ) ) { |
|
| 539 | + $invoice_id = absint($_POST['invoice_id']); |
|
| 540 | + $discount_code = sanitize_text_field($_POST['code']); |
|
| 541 | + if (empty($invoice_id) || empty($discount_code)) { |
|
| 542 | 542 | die(); |
| 543 | 543 | } |
| 544 | 544 | |
| 545 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
| 546 | - if ( empty( $invoice ) || ( !empty( $invoice ) && ( $invoice->is_paid() || $invoice->is_refunded() ) ) ) { |
|
| 545 | + $invoice = wpinv_get_invoice($invoice_id); |
|
| 546 | + if (empty($invoice) || (!empty($invoice) && ($invoice->is_paid() || $invoice->is_refunded()))) { |
|
| 547 | 547 | die(); |
| 548 | 548 | } |
| 549 | 549 | |
@@ -551,38 +551,38 @@ discard block |
||
| 551 | 551 | |
| 552 | 552 | $data = array(); |
| 553 | 553 | $data['invoice_id'] = $invoice_id; |
| 554 | - $data['cart_discounts'] = $invoice->get_discounts( true ); |
|
| 554 | + $data['cart_discounts'] = $invoice->get_discounts(true); |
|
| 555 | 555 | |
| 556 | - wpinv_set_checkout_session( $data ); |
|
| 556 | + wpinv_set_checkout_session($data); |
|
| 557 | 557 | |
| 558 | 558 | $response = array(); |
| 559 | 559 | $response['success'] = false; |
| 560 | 560 | $response['msg'] = NULL; |
| 561 | 561 | |
| 562 | - $discounts = wpinv_unset_cart_discount( $discount_code ); |
|
| 562 | + $discounts = wpinv_unset_cart_discount($discount_code); |
|
| 563 | 563 | $response['success'] = true; |
| 564 | - $response['msg'] = __( 'Discount has been removed successfully.', 'invoicing' ); |
|
| 564 | + $response['msg'] = __('Discount has been removed successfully.', 'invoicing'); |
|
| 565 | 565 | |
| 566 | 566 | wpinv_set_checkout_session($checkout_session); |
| 567 | 567 | |
| 568 | - wp_send_json( $response ); |
|
| 568 | + wp_send_json($response); |
|
| 569 | 569 | } |
| 570 | 570 | |
| 571 | 571 | public static function check_email() { |
| 572 | - check_ajax_referer( 'wpinv-nonce', '_nonce' ); |
|
| 573 | - if ( !wpinv_current_user_can_manage_invoicing() ) { |
|
| 572 | + check_ajax_referer('wpinv-nonce', '_nonce'); |
|
| 573 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
| 574 | 574 | die(-1); |
| 575 | 575 | } |
| 576 | 576 | |
| 577 | - $email = sanitize_text_field( $_POST['email'] ); |
|
| 577 | + $email = sanitize_text_field($_POST['email']); |
|
| 578 | 578 | |
| 579 | 579 | $response = array(); |
| 580 | - if ( is_email( $email ) && email_exists( $email ) && $user_data = get_user_by( 'email', $email ) ) { |
|
| 580 | + if (is_email($email) && email_exists($email) && $user_data = get_user_by('email', $email)) { |
|
| 581 | 581 | $user_id = $user_data->ID; |
| 582 | 582 | $user_login = $user_data->user_login; |
| 583 | 583 | $display_name = $user_data->display_name ? $user_data->display_name : $user_login; |
| 584 | 584 | $billing_details = wpinv_get_user_address($user_id); |
| 585 | - $billing_details = apply_filters( 'wpinv_fill_billing_details', $billing_details, $user_id ); |
|
| 585 | + $billing_details = apply_filters('wpinv_fill_billing_details', $billing_details, $user_id); |
|
| 586 | 586 | |
| 587 | 587 | if (isset($billing_details['user_id'])) { |
| 588 | 588 | unset($billing_details['user_id']); |
@@ -598,54 +598,54 @@ discard block |
||
| 598 | 598 | $response['data']['billing_details'] = $billing_details; |
| 599 | 599 | } |
| 600 | 600 | |
| 601 | - wp_send_json( $response ); |
|
| 601 | + wp_send_json($response); |
|
| 602 | 602 | } |
| 603 | 603 | |
| 604 | 604 | public static function run_tool() { |
| 605 | - check_ajax_referer( 'wpinv-nonce', '_nonce' ); |
|
| 606 | - if ( !wpinv_current_user_can_manage_invoicing() ) { |
|
| 605 | + check_ajax_referer('wpinv-nonce', '_nonce'); |
|
| 606 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
| 607 | 607 | die(-1); |
| 608 | 608 | } |
| 609 | 609 | |
| 610 | - $tool = sanitize_text_field( $_POST['tool'] ); |
|
| 610 | + $tool = sanitize_text_field($_POST['tool']); |
|
| 611 | 611 | |
| 612 | - do_action( 'wpinv_run_tool' ); |
|
| 612 | + do_action('wpinv_run_tool'); |
|
| 613 | 613 | |
| 614 | - if ( !empty( $tool ) ) { |
|
| 615 | - do_action( 'wpinv_tool_' . $tool ); |
|
| 614 | + if (!empty($tool)) { |
|
| 615 | + do_action('wpinv_tool_' . $tool); |
|
| 616 | 616 | } |
| 617 | 617 | } |
| 618 | 618 | |
| 619 | 619 | public static function apply_discount() { |
| 620 | 620 | global $wpi_userID; |
| 621 | 621 | |
| 622 | - check_ajax_referer( 'wpinv-nonce', '_nonce' ); |
|
| 622 | + check_ajax_referer('wpinv-nonce', '_nonce'); |
|
| 623 | 623 | |
| 624 | 624 | $response = array(); |
| 625 | 625 | |
| 626 | - if ( isset( $_POST['code'] ) ) { |
|
| 627 | - $discount_code = sanitize_text_field( $_POST['code'] ); |
|
| 626 | + if (isset($_POST['code'])) { |
|
| 627 | + $discount_code = sanitize_text_field($_POST['code']); |
|
| 628 | 628 | |
| 629 | 629 | $response['success'] = false; |
| 630 | 630 | $response['msg'] = ''; |
| 631 | 631 | $response['data']['code'] = $discount_code; |
| 632 | 632 | |
| 633 | 633 | $invoice = wpinv_get_invoice_cart(); |
| 634 | - if ( empty( $invoice->ID ) ) { |
|
| 635 | - $response['msg'] = __( 'Invalid checkout request.', 'invoicing' ); |
|
| 636 | - wp_send_json( $response ); |
|
| 634 | + if (empty($invoice->ID)) { |
|
| 635 | + $response['msg'] = __('Invalid checkout request.', 'invoicing'); |
|
| 636 | + wp_send_json($response); |
|
| 637 | 637 | } |
| 638 | 638 | |
| 639 | 639 | $wpi_userID = $invoice->get_user_id(); |
| 640 | 640 | |
| 641 | - if ( wpinv_is_discount_valid( $discount_code, $wpi_userID ) ) { |
|
| 642 | - $discount = wpinv_get_discount_by_code( $discount_code ); |
|
| 643 | - $discounts = wpinv_set_cart_discount( $discount_code ); |
|
| 644 | - $amount = wpinv_format_discount_rate( wpinv_get_discount_type( $discount->ID ), wpinv_get_discount_amount( $discount->ID ) ); |
|
| 645 | - $total = wpinv_get_cart_total( null, $discounts ); |
|
| 646 | - $cart_totals = wpinv_recalculate_tax( true ); |
|
| 641 | + if (wpinv_is_discount_valid($discount_code, $wpi_userID)) { |
|
| 642 | + $discount = wpinv_get_discount_by_code($discount_code); |
|
| 643 | + $discounts = wpinv_set_cart_discount($discount_code); |
|
| 644 | + $amount = wpinv_format_discount_rate(wpinv_get_discount_type($discount->ID), wpinv_get_discount_amount($discount->ID)); |
|
| 645 | + $total = wpinv_get_cart_total(null, $discounts); |
|
| 646 | + $cart_totals = wpinv_recalculate_tax(true); |
|
| 647 | 647 | |
| 648 | - if ( !empty( $cart_totals ) ) { |
|
| 648 | + if (!empty($cart_totals)) { |
|
| 649 | 649 | $response['success'] = true; |
| 650 | 650 | $response['data'] = $cart_totals; |
| 651 | 651 | $response['data']['code'] = $discount_code; |
@@ -654,29 +654,29 @@ discard block |
||
| 654 | 654 | } |
| 655 | 655 | } else { |
| 656 | 656 | $errors = wpinv_get_errors(); |
| 657 | - $response['msg'] = $errors['wpinv-discount-error']; |
|
| 658 | - wpinv_unset_error( 'wpinv-discount-error' ); |
|
| 657 | + $response['msg'] = $errors['wpinv-discount-error']; |
|
| 658 | + wpinv_unset_error('wpinv-discount-error'); |
|
| 659 | 659 | } |
| 660 | 660 | |
| 661 | 661 | // Allow for custom discount code handling |
| 662 | - $response = apply_filters( 'wpinv_ajax_discount_response', $response ); |
|
| 662 | + $response = apply_filters('wpinv_ajax_discount_response', $response); |
|
| 663 | 663 | } |
| 664 | 664 | |
| 665 | - wp_send_json( $response ); |
|
| 665 | + wp_send_json($response); |
|
| 666 | 666 | } |
| 667 | 667 | |
| 668 | 668 | public static function remove_discount() { |
| 669 | - check_ajax_referer( 'wpinv-nonce', '_nonce' ); |
|
| 669 | + check_ajax_referer('wpinv-nonce', '_nonce'); |
|
| 670 | 670 | |
| 671 | 671 | $response = array(); |
| 672 | 672 | |
| 673 | - if ( isset( $_POST['code'] ) ) { |
|
| 674 | - $discount_code = sanitize_text_field( $_POST['code'] ); |
|
| 675 | - $discounts = wpinv_unset_cart_discount( $discount_code ); |
|
| 676 | - $total = wpinv_get_cart_total( null, $discounts ); |
|
| 677 | - $cart_totals = wpinv_recalculate_tax( true ); |
|
| 673 | + if (isset($_POST['code'])) { |
|
| 674 | + $discount_code = sanitize_text_field($_POST['code']); |
|
| 675 | + $discounts = wpinv_unset_cart_discount($discount_code); |
|
| 676 | + $total = wpinv_get_cart_total(null, $discounts); |
|
| 677 | + $cart_totals = wpinv_recalculate_tax(true); |
|
| 678 | 678 | |
| 679 | - if ( !empty( $cart_totals ) ) { |
|
| 679 | + if (!empty($cart_totals)) { |
|
| 680 | 680 | $response['success'] = true; |
| 681 | 681 | $response['data'] = $cart_totals; |
| 682 | 682 | $response['data']['code'] = $discount_code; |
@@ -685,10 +685,10 @@ discard block |
||
| 685 | 685 | } |
| 686 | 686 | |
| 687 | 687 | // Allow for custom discount code handling |
| 688 | - $response = apply_filters( 'wpinv_ajax_discount_response', $response ); |
|
| 688 | + $response = apply_filters('wpinv_ajax_discount_response', $response); |
|
| 689 | 689 | } |
| 690 | 690 | |
| 691 | - wp_send_json( $response ); |
|
| 691 | + wp_send_json($response); |
|
| 692 | 692 | } |
| 693 | 693 | |
| 694 | 694 | |
@@ -700,53 +700,53 @@ discard block |
||
| 700 | 700 | public static function buy_items() { |
| 701 | 701 | $user_id = get_current_user_id(); |
| 702 | 702 | |
| 703 | - if ( empty( $user_id ) ) { // If not logged in then lets redirect to the login page |
|
| 704 | - wp_send_json( array( |
|
| 705 | - 'success' => wp_login_url( wp_get_referer() ) |
|
| 706 | - ) ); |
|
| 703 | + if (empty($user_id)) { // If not logged in then lets redirect to the login page |
|
| 704 | + wp_send_json(array( |
|
| 705 | + 'success' => wp_login_url(wp_get_referer()) |
|
| 706 | + )); |
|
| 707 | 707 | } else { |
| 708 | 708 | // Only check nonce if logged in as it could be cached when logged out. |
| 709 | - if ( ! isset( $_POST['wpinv_buy_nonce'] ) || ! wp_verify_nonce( $_POST['wpinv_buy_nonce'], 'wpinv_buy_items' ) ) { |
|
| 710 | - wp_send_json( array( |
|
| 711 | - 'error' => __( 'Security checks failed.', 'invoicing' ) |
|
| 712 | - ) ); |
|
| 709 | + if (!isset($_POST['wpinv_buy_nonce']) || !wp_verify_nonce($_POST['wpinv_buy_nonce'], 'wpinv_buy_items')) { |
|
| 710 | + wp_send_json(array( |
|
| 711 | + 'error' => __('Security checks failed.', 'invoicing') |
|
| 712 | + )); |
|
| 713 | 713 | wp_die(); |
| 714 | 714 | } |
| 715 | 715 | |
| 716 | 716 | // allow to set a custom price through post_id |
| 717 | 717 | $items = $_POST['items']; |
| 718 | - $related_post_id = isset( $_POST['post_id'] ) ? (int)$_POST['post_id'] : 0; |
|
| 719 | - $custom_item_price = $related_post_id ? abs( get_post_meta( $related_post_id, '_wpi_custom_price', true ) ) : 0; |
|
| 718 | + $related_post_id = isset($_POST['post_id']) ? (int) $_POST['post_id'] : 0; |
|
| 719 | + $custom_item_price = $related_post_id ? abs(get_post_meta($related_post_id, '_wpi_custom_price', true)) : 0; |
|
| 720 | 720 | |
| 721 | 721 | $cart_items = array(); |
| 722 | - if ( $items ) { |
|
| 723 | - $items = explode( ',', $items ); |
|
| 722 | + if ($items) { |
|
| 723 | + $items = explode(',', $items); |
|
| 724 | 724 | |
| 725 | - foreach( $items as $item ) { |
|
| 725 | + foreach ($items as $item) { |
|
| 726 | 726 | $item_id = $item; |
| 727 | 727 | $quantity = 1; |
| 728 | 728 | |
| 729 | - if ( strpos( $item, '|' ) !== false ) { |
|
| 730 | - $item_parts = explode( '|', $item ); |
|
| 729 | + if (strpos($item, '|') !== false) { |
|
| 730 | + $item_parts = explode('|', $item); |
|
| 731 | 731 | $item_id = $item_parts[0]; |
| 732 | 732 | $quantity = $item_parts[1]; |
| 733 | 733 | } |
| 734 | 734 | |
| 735 | - if ( $item_id && $quantity ) { |
|
| 735 | + if ($item_id && $quantity) { |
|
| 736 | 736 | $cart_items_arr = array( |
| 737 | - 'id' => (int)$item_id, |
|
| 738 | - 'quantity' => (int)$quantity |
|
| 737 | + 'id' => (int) $item_id, |
|
| 738 | + 'quantity' => (int) $quantity |
|
| 739 | 739 | ); |
| 740 | 740 | |
| 741 | 741 | // If there is a related post id then add it to meta |
| 742 | - if ( $related_post_id ) { |
|
| 742 | + if ($related_post_id) { |
|
| 743 | 743 | $cart_items_arr['meta'] = array( |
| 744 | 744 | 'post_id' => $related_post_id |
| 745 | 745 | ); |
| 746 | 746 | } |
| 747 | 747 | |
| 748 | 748 | // If there is a custom price then set it. |
| 749 | - if ( $custom_item_price ) { |
|
| 749 | + if ($custom_item_price) { |
|
| 750 | 750 | $cart_items_arr['custom_price'] = $custom_item_price; |
| 751 | 751 | } |
| 752 | 752 | |
@@ -762,37 +762,37 @@ discard block |
||
| 762 | 762 | * @param int $related_post_id The related post id if any. |
| 763 | 763 | * @since 1.0.0 |
| 764 | 764 | */ |
| 765 | - $cart_items = apply_filters( 'wpinv_buy_cart_items', $cart_items, $related_post_id ); |
|
| 765 | + $cart_items = apply_filters('wpinv_buy_cart_items', $cart_items, $related_post_id); |
|
| 766 | 766 | |
| 767 | 767 | // Make sure its not in the cart already, if it is then redirect to checkout. |
| 768 | 768 | $cart_invoice = wpinv_get_invoice_cart(); |
| 769 | 769 | |
| 770 | - if ( isset( $cart_invoice->items ) && !empty( $cart_invoice->items ) && !empty( $cart_items ) && serialize( $cart_invoice->items ) == serialize( $cart_items ) ) { |
|
| 771 | - wp_send_json( array( |
|
| 770 | + if (isset($cart_invoice->items) && !empty($cart_invoice->items) && !empty($cart_items) && serialize($cart_invoice->items) == serialize($cart_items)) { |
|
| 771 | + wp_send_json(array( |
|
| 772 | 772 | 'success' => $cart_invoice->get_checkout_payment_url() |
| 773 | - ) ); |
|
| 773 | + )); |
|
| 774 | 774 | wp_die(); |
| 775 | 775 | } |
| 776 | 776 | |
| 777 | 777 | // Check if user has invoice with same items waiting to be paid. |
| 778 | - $user_invoices = wpinv_get_users_invoices( $user_id , 10 , false , 'wpi-pending' ); |
|
| 779 | - if ( !empty( $user_invoices ) ) { |
|
| 780 | - foreach( $user_invoices as $user_invoice ) { |
|
| 778 | + $user_invoices = wpinv_get_users_invoices($user_id, 10, false, 'wpi-pending'); |
|
| 779 | + if (!empty($user_invoices)) { |
|
| 780 | + foreach ($user_invoices as $user_invoice) { |
|
| 781 | 781 | $user_cart_details = array(); |
| 782 | - $invoice = wpinv_get_invoice( $user_invoice->ID ); |
|
| 782 | + $invoice = wpinv_get_invoice($user_invoice->ID); |
|
| 783 | 783 | $cart_details = $invoice->get_cart_details(); |
| 784 | 784 | |
| 785 | - if ( !empty( $cart_details ) ) { |
|
| 786 | - foreach ( $cart_details as $invoice_item ) { |
|
| 785 | + if (!empty($cart_details)) { |
|
| 786 | + foreach ($cart_details as $invoice_item) { |
|
| 787 | 787 | $ii_arr = array(); |
| 788 | - $ii_arr['id'] = (int)$invoice_item['id']; |
|
| 789 | - $ii_arr['quantity'] = (int)$invoice_item['quantity']; |
|
| 788 | + $ii_arr['id'] = (int) $invoice_item['id']; |
|
| 789 | + $ii_arr['quantity'] = (int) $invoice_item['quantity']; |
|
| 790 | 790 | |
| 791 | - if (isset( $invoice_item['meta'] ) && !empty( $invoice_item['meta'] ) ) { |
|
| 791 | + if (isset($invoice_item['meta']) && !empty($invoice_item['meta'])) { |
|
| 792 | 792 | $ii_arr['meta'] = $invoice_item['meta']; |
| 793 | 793 | } |
| 794 | 794 | |
| 795 | - if ( isset( $invoice_item['custom_price'] ) && !empty( $invoice_item['custom_price'] ) ) { |
|
| 795 | + if (isset($invoice_item['custom_price']) && !empty($invoice_item['custom_price'])) { |
|
| 796 | 796 | $ii_arr['custom_price'] = $invoice_item['custom_price']; |
| 797 | 797 | } |
| 798 | 798 | |
@@ -800,17 +800,17 @@ discard block |
||
| 800 | 800 | } |
| 801 | 801 | } |
| 802 | 802 | |
| 803 | - if ( !empty( $user_cart_details ) && serialize( $cart_items ) == serialize( $user_cart_details ) ) { |
|
| 804 | - wp_send_json( array( |
|
| 803 | + if (!empty($user_cart_details) && serialize($cart_items) == serialize($user_cart_details)) { |
|
| 804 | + wp_send_json(array( |
|
| 805 | 805 | 'success' => $invoice->get_checkout_payment_url() |
| 806 | - ) ); |
|
| 806 | + )); |
|
| 807 | 807 | wp_die(); |
| 808 | 808 | } |
| 809 | 809 | } |
| 810 | 810 | } |
| 811 | 811 | |
| 812 | 812 | // Create invoice and send user to checkout |
| 813 | - if ( !empty( $cart_items ) ) { |
|
| 813 | + if (!empty($cart_items)) { |
|
| 814 | 814 | $invoice_data = array( |
| 815 | 815 | 'status' => 'wpi-pending', |
| 816 | 816 | 'created_via' => 'wpi', |
@@ -818,21 +818,21 @@ discard block |
||
| 818 | 818 | 'cart_details' => $cart_items, |
| 819 | 819 | ); |
| 820 | 820 | |
| 821 | - $invoice = wpinv_insert_invoice( $invoice_data, true ); |
|
| 821 | + $invoice = wpinv_insert_invoice($invoice_data, true); |
|
| 822 | 822 | |
| 823 | - if ( !empty( $invoice ) && isset( $invoice->ID ) ) { |
|
| 824 | - wp_send_json( array( |
|
| 823 | + if (!empty($invoice) && isset($invoice->ID)) { |
|
| 824 | + wp_send_json(array( |
|
| 825 | 825 | 'success' => $invoice->get_checkout_payment_url() |
| 826 | - ) ); |
|
| 826 | + )); |
|
| 827 | 827 | } else { |
| 828 | - wp_send_json( array( |
|
| 829 | - 'error' => __( 'Invoice failed to create', 'invoicing' ) |
|
| 830 | - ) ); |
|
| 828 | + wp_send_json(array( |
|
| 829 | + 'error' => __('Invoice failed to create', 'invoicing') |
|
| 830 | + )); |
|
| 831 | 831 | } |
| 832 | 832 | } else { |
| 833 | - wp_send_json( array( |
|
| 834 | - 'error' => __( 'Items not valid.', 'invoicing' ) |
|
| 835 | - ) ); |
|
| 833 | + wp_send_json(array( |
|
| 834 | + 'error' => __('Items not valid.', 'invoicing') |
|
| 835 | + )); |
|
| 836 | 836 | } |
| 837 | 837 | } |
| 838 | 838 | |