@@ -1,72 +1,72 @@ |
||
1 | 1 | <?php |
2 | 2 | // don't load directly |
3 | -if ( !defined('ABSPATH') ) |
|
3 | +if (!defined('ABSPATH')) |
|
4 | 4 | die('-1'); |
5 | 5 | |
6 | 6 | global $wpinv_euvat; |
7 | 7 | |
8 | -$sent_to_admin = !empty( $sent_to_admin ) ? true : false; |
|
9 | -if ( $sent_to_admin ) { |
|
10 | - $invoice_url = get_edit_post_link( $invoice->ID ); |
|
8 | +$sent_to_admin = !empty($sent_to_admin) ? true : false; |
|
9 | +if ($sent_to_admin) { |
|
10 | + $invoice_url = get_edit_post_link($invoice->ID); |
|
11 | 11 | } else { |
12 | - $secret = !empty( $email_type ) && $email_type == 'user_invoice' ? true : false; |
|
13 | - $invoice_url = $invoice->get_view_url( $secret ); |
|
12 | + $secret = !empty($email_type) && $email_type == 'user_invoice' ? true : false; |
|
13 | + $invoice_url = $invoice->get_view_url($secret); |
|
14 | 14 | } |
15 | 15 | $use_taxes = wpinv_use_taxes(); |
16 | 16 | $vat_name = $wpinv_euvat->get_vat_name(); |
17 | 17 | |
18 | -do_action( 'wpinv_email_before_invoice_details', $invoice, $sent_to_admin ); ?> |
|
18 | +do_action('wpinv_email_before_invoice_details', $invoice, $sent_to_admin); ?> |
|
19 | 19 | <div id="wpinv-email-details"> |
20 | - <h3 class="wpinv-details-t"><?php echo apply_filters( 'wpinv_email_details_title', __( 'Invoice Details', 'invoicing' ) ); ?></h3> |
|
20 | + <h3 class="wpinv-details-t"><?php echo apply_filters('wpinv_email_details_title', __('Invoice Details', 'invoicing')); ?></h3> |
|
21 | 21 | <table class="table table-bordered table-sm"> |
22 | - <?php if ( $invoice_number = $invoice->get_number() ) { ?> |
|
22 | + <?php if ($invoice_number = $invoice->get_number()) { ?> |
|
23 | 23 | <tr> |
24 | - <td><?php _e( 'Invoice Number', 'invoicing' ); ?></td> |
|
25 | - <td><a href="<?php echo esc_url( $invoice_url ) ;?>"><?php echo $invoice_number; ?></a></td> |
|
24 | + <td><?php _e('Invoice Number', 'invoicing'); ?></td> |
|
25 | + <td><a href="<?php echo esc_url($invoice_url); ?>"><?php echo $invoice_number; ?></a></td> |
|
26 | 26 | </tr> |
27 | 27 | <?php } ?> |
28 | 28 | <tr> |
29 | - <td><?php _e( 'Invoice Status', 'invoicing' ); ?></td> |
|
30 | - <td><?php echo $invoice->get_status( true ); ?></td> |
|
29 | + <td><?php _e('Invoice Status', 'invoicing'); ?></td> |
|
30 | + <td><?php echo $invoice->get_status(true); ?></td> |
|
31 | 31 | </tr> |
32 | - <?php if ( $invoice->is_renewal() ) { ?> |
|
32 | + <?php if ($invoice->is_renewal()) { ?> |
|
33 | 33 | <tr> |
34 | - <td><?php _e( 'Parent Invoice', 'invoicing' ); ?></td> |
|
35 | - <td><?php echo wpinv_invoice_link( $invoice->parent_invoice ); ?></td> |
|
34 | + <td><?php _e('Parent Invoice', 'invoicing'); ?></td> |
|
35 | + <td><?php echo wpinv_invoice_link($invoice->parent_invoice); ?></td> |
|
36 | 36 | </tr> |
37 | 37 | <?php } ?> |
38 | 38 | <tr> |
39 | - <td><?php _e( 'Payment Method', 'invoicing' ); ?></td> |
|
39 | + <td><?php _e('Payment Method', 'invoicing'); ?></td> |
|
40 | 40 | <td><?php echo $invoice->get_gateway_title(); ?></td> |
41 | 41 | </tr> |
42 | - <?php if ( $invoice_date = $invoice->get_invoice_date( false ) ) { ?> |
|
42 | + <?php if ($invoice_date = $invoice->get_invoice_date(false)) { ?> |
|
43 | 43 | <tr> |
44 | - <td><?php _e( 'Invoice Date', 'invoicing' ); ?></td> |
|
45 | - <td><?php echo wp_sprintf( '<time datetime="%s">%s</time>', date_i18n( 'c', strtotime( $invoice_date ) ), $invoice->get_invoice_date() ); ?></td> |
|
44 | + <td><?php _e('Invoice Date', 'invoicing'); ?></td> |
|
45 | + <td><?php echo wp_sprintf('<time datetime="%s">%s</time>', date_i18n('c', strtotime($invoice_date)), $invoice->get_invoice_date()); ?></td> |
|
46 | 46 | </tr> |
47 | 47 | <?php } ?> |
48 | - <?php if ( wpinv_get_option( 'overdue_active' ) && $invoice->needs_payment() && ( $due_date = $invoice->get_due_date() ) ) { ?> |
|
48 | + <?php if (wpinv_get_option('overdue_active') && $invoice->needs_payment() && ($due_date = $invoice->get_due_date())) { ?> |
|
49 | 49 | <tr> |
50 | - <td><?php _e( 'Due Date', 'invoicing' ); ?></td> |
|
51 | - <td><?php echo wp_sprintf( '<time datetime="%s">%s</time>', date_i18n( 'c', strtotime( $due_date ) ), $invoice->get_due_date( true ) ); ?></td> |
|
50 | + <td><?php _e('Due Date', 'invoicing'); ?></td> |
|
51 | + <td><?php echo wp_sprintf('<time datetime="%s">%s</time>', date_i18n('c', strtotime($due_date)), $invoice->get_due_date(true)); ?></td> |
|
52 | 52 | </tr> |
53 | 53 | <?php } ?> |
54 | - <?php if ( empty( $sent_to_admin ) && $owner_vat_number = $wpinv_euvat->get_vat_number() ) { ?> |
|
54 | + <?php if (empty($sent_to_admin) && $owner_vat_number = $wpinv_euvat->get_vat_number()) { ?> |
|
55 | 55 | <tr> |
56 | - <td><?php echo wp_sprintf( __( 'Owner %s Number', 'invoicing' ), $vat_name ); ?></td> |
|
56 | + <td><?php echo wp_sprintf(__('Owner %s Number', 'invoicing'), $vat_name); ?></td> |
|
57 | 57 | <td><?php echo $owner_vat_number; ?></td> |
58 | 58 | </tr> |
59 | 59 | <?php } ?> |
60 | - <?php if ( $use_taxes && $user_vat_number = $invoice->vat_number ) { ?> |
|
60 | + <?php if ($use_taxes && $user_vat_number = $invoice->vat_number) { ?> |
|
61 | 61 | <tr> |
62 | - <td><?php echo wp_sprintf( __( 'Invoice %s Number', 'invoicing' ), $vat_name ); ?></td> |
|
62 | + <td><?php echo wp_sprintf(__('Invoice %s Number', 'invoicing'), $vat_name); ?></td> |
|
63 | 63 | <td><?php echo $user_vat_number; ?></td> |
64 | 64 | </tr> |
65 | 65 | <?php } ?> |
66 | 66 | <tr class="table-active"> |
67 | - <td><strong><?php _e( 'Total Amount', 'invoicing' ) ?></strong></td> |
|
68 | - <td><strong><?php echo $invoice->get_total( true ); ?></strong></td> |
|
67 | + <td><strong><?php _e('Total Amount', 'invoicing') ?></strong></td> |
|
68 | + <td><strong><?php echo $invoice->get_total(true); ?></strong></td> |
|
69 | 69 | </tr> |
70 | 70 | </table> |
71 | 71 | </div> |
72 | -<?php do_action( 'wpinv_email_after_invoice_details', $invoice, $sent_to_admin ); ?> |
|
73 | 72 | \ No newline at end of file |
73 | +<?php do_action('wpinv_email_after_invoice_details', $invoice, $sent_to_admin); ?> |
|
74 | 74 | \ No newline at end of file |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | // Exit if accessed directly. |
3 | -if (!defined( 'ABSPATH' ) ) exit; |
|
3 | +if (!defined('ABSPATH')) exit; |
|
4 | 4 | |
5 | 5 | class WPInv_EUVat { |
6 | 6 | private static $is_ajax = false; |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | private static $instance = false; |
9 | 9 | |
10 | 10 | public static function get_instance() { |
11 | - if ( !self::$instance ) { |
|
11 | + if (!self::$instance) { |
|
12 | 12 | self::$instance = new self(); |
13 | 13 | self::$instance->actions(); |
14 | 14 | } |
@@ -17,132 +17,132 @@ discard block |
||
17 | 17 | } |
18 | 18 | |
19 | 19 | public function __construct() { |
20 | - self::$is_ajax = defined( 'DOING_AJAX' ) && DOING_AJAX; |
|
20 | + self::$is_ajax = defined('DOING_AJAX') && DOING_AJAX; |
|
21 | 21 | self::$default_country = wpinv_get_default_country(); |
22 | 22 | } |
23 | 23 | |
24 | 24 | public static function actions() { |
25 | - if ( is_admin() ) { |
|
26 | - add_action( 'admin_enqueue_scripts', array( self::$instance, 'enqueue_admin_scripts' ) ); |
|
27 | - add_action( 'wpinv_settings_sections_taxes', array( self::$instance, 'section_vat_settings' ) ); |
|
28 | - add_action( 'wpinv_settings_taxes', array( self::$instance, 'vat_settings' ) ); |
|
29 | - add_filter( 'wpinv_settings_taxes-vat_sanitize', array( self::$instance, 'sanitize_vat_settings' ) ); |
|
30 | - add_filter( 'wpinv_settings_taxes-vat_rates_sanitize', array( self::$instance, 'sanitize_vat_rates' ) ); |
|
31 | - add_action( 'wp_ajax_wpinv_add_vat_class', array( self::$instance, 'add_class' ) ); |
|
32 | - add_action( 'wp_ajax_nopriv_wpinv_add_vat_class', array( self::$instance, 'add_class' ) ); |
|
33 | - add_action( 'wp_ajax_wpinv_delete_vat_class', array( self::$instance, 'delete_class' ) ); |
|
34 | - add_action( 'wp_ajax_nopriv_wpinv_delete_vat_class', array( self::$instance, 'delete_class' ) ); |
|
35 | - add_action( 'wp_ajax_wpinv_update_vat_rates', array( self::$instance, 'update_eu_rates' ) ); |
|
36 | - add_action( 'wp_ajax_nopriv_wpinv_update_vat_rates', array( self::$instance, 'update_eu_rates' ) ); |
|
37 | - add_action( 'wp_ajax_wpinv_geoip2', array( self::$instance, 'geoip2_download_database' ) ); |
|
38 | - add_action( 'wp_ajax_nopriv_wpinv_geoip2', array( self::$instance, 'geoip2_download_database' ) ); |
|
39 | - } |
|
40 | - |
|
41 | - add_action( 'wp_enqueue_scripts', array( self::$instance, 'enqueue_vat_scripts' ) ); |
|
42 | - add_filter( 'wpinv_default_billing_country', array( self::$instance, 'get_user_country' ), 10 ); |
|
43 | - add_filter( 'wpinv_get_user_country', array( self::$instance, 'set_user_country' ), 10 ); |
|
44 | - add_action( 'wp_ajax_wpinv_vat_validate', array( self::$instance, 'ajax_vat_validate' ) ); |
|
45 | - add_action( 'wp_ajax_nopriv_wpinv_vat_validate', array( self::$instance, 'ajax_vat_validate' ) ); |
|
46 | - add_action( 'wp_ajax_wpinv_vat_reset', array( self::$instance, 'ajax_vat_reset' ) ); |
|
47 | - add_action( 'wp_ajax_nopriv_wpinv_vat_reset', array( self::$instance, 'ajax_vat_reset' ) ); |
|
48 | - add_action( 'wpinv_invoice_print_after_line_items', array( self::$instance, 'show_vat_notice' ), 999, 1 ); |
|
49 | - if ( wpinv_use_taxes() ) { |
|
50 | - add_action( 'wpinv_after_billing_fields', array( self::$instance, 'checkout_vat_fields' ) ); |
|
51 | - if ( self::allow_vat_rules() ) { |
|
52 | - add_action( 'wpinv_checkout_error_checks', array( self::$instance, 'checkout_vat_validate' ), 10, 2 ); |
|
53 | - add_filter( 'wpinv_tax_rate', array( self::$instance, 'get_rate' ), 10, 4 ); |
|
25 | + if (is_admin()) { |
|
26 | + add_action('admin_enqueue_scripts', array(self::$instance, 'enqueue_admin_scripts')); |
|
27 | + add_action('wpinv_settings_sections_taxes', array(self::$instance, 'section_vat_settings')); |
|
28 | + add_action('wpinv_settings_taxes', array(self::$instance, 'vat_settings')); |
|
29 | + add_filter('wpinv_settings_taxes-vat_sanitize', array(self::$instance, 'sanitize_vat_settings')); |
|
30 | + add_filter('wpinv_settings_taxes-vat_rates_sanitize', array(self::$instance, 'sanitize_vat_rates')); |
|
31 | + add_action('wp_ajax_wpinv_add_vat_class', array(self::$instance, 'add_class')); |
|
32 | + add_action('wp_ajax_nopriv_wpinv_add_vat_class', array(self::$instance, 'add_class')); |
|
33 | + add_action('wp_ajax_wpinv_delete_vat_class', array(self::$instance, 'delete_class')); |
|
34 | + add_action('wp_ajax_nopriv_wpinv_delete_vat_class', array(self::$instance, 'delete_class')); |
|
35 | + add_action('wp_ajax_wpinv_update_vat_rates', array(self::$instance, 'update_eu_rates')); |
|
36 | + add_action('wp_ajax_nopriv_wpinv_update_vat_rates', array(self::$instance, 'update_eu_rates')); |
|
37 | + add_action('wp_ajax_wpinv_geoip2', array(self::$instance, 'geoip2_download_database')); |
|
38 | + add_action('wp_ajax_nopriv_wpinv_geoip2', array(self::$instance, 'geoip2_download_database')); |
|
39 | + } |
|
40 | + |
|
41 | + add_action('wp_enqueue_scripts', array(self::$instance, 'enqueue_vat_scripts')); |
|
42 | + add_filter('wpinv_default_billing_country', array(self::$instance, 'get_user_country'), 10); |
|
43 | + add_filter('wpinv_get_user_country', array(self::$instance, 'set_user_country'), 10); |
|
44 | + add_action('wp_ajax_wpinv_vat_validate', array(self::$instance, 'ajax_vat_validate')); |
|
45 | + add_action('wp_ajax_nopriv_wpinv_vat_validate', array(self::$instance, 'ajax_vat_validate')); |
|
46 | + add_action('wp_ajax_wpinv_vat_reset', array(self::$instance, 'ajax_vat_reset')); |
|
47 | + add_action('wp_ajax_nopriv_wpinv_vat_reset', array(self::$instance, 'ajax_vat_reset')); |
|
48 | + add_action('wpinv_invoice_print_after_line_items', array(self::$instance, 'show_vat_notice'), 999, 1); |
|
49 | + if (wpinv_use_taxes()) { |
|
50 | + add_action('wpinv_after_billing_fields', array(self::$instance, 'checkout_vat_fields')); |
|
51 | + if (self::allow_vat_rules()) { |
|
52 | + add_action('wpinv_checkout_error_checks', array(self::$instance, 'checkout_vat_validate'), 10, 2); |
|
53 | + add_filter('wpinv_tax_rate', array(self::$instance, 'get_rate'), 10, 4); |
|
54 | 54 | } |
55 | 55 | } |
56 | 56 | } |
57 | 57 | |
58 | - public static function get_eu_states( $sort = true ) { |
|
59 | - $eu_states = array( 'AT', 'BE', 'BG', 'HR', 'CY', 'CZ', 'DK', 'EE', 'FI', 'FR', 'DE', 'GB', 'GR', 'HU', 'IE', 'IT', 'LV', 'LT', 'LU', 'MT', 'NL', 'PL', 'PT', 'RO', 'SK', 'SI', 'ES', 'SE' ); |
|
60 | - if ( $sort ) { |
|
61 | - $sort = sort( $eu_states ); |
|
58 | + public static function get_eu_states($sort = true) { |
|
59 | + $eu_states = array('AT', 'BE', 'BG', 'HR', 'CY', 'CZ', 'DK', 'EE', 'FI', 'FR', 'DE', 'GB', 'GR', 'HU', 'IE', 'IT', 'LV', 'LT', 'LU', 'MT', 'NL', 'PL', 'PT', 'RO', 'SK', 'SI', 'ES', 'SE'); |
|
60 | + if ($sort) { |
|
61 | + $sort = sort($eu_states); |
|
62 | 62 | } |
63 | 63 | |
64 | - return apply_filters( 'wpinv_get_eu_states', $eu_states, $sort ); |
|
64 | + return apply_filters('wpinv_get_eu_states', $eu_states, $sort); |
|
65 | 65 | } |
66 | 66 | |
67 | - public static function get_gst_countries( $sort = true ) { |
|
68 | - $gst_countries = array( 'AU', 'NZ', 'CA', 'CN' ); |
|
67 | + public static function get_gst_countries($sort = true) { |
|
68 | + $gst_countries = array('AU', 'NZ', 'CA', 'CN'); |
|
69 | 69 | |
70 | - if ( $sort ) { |
|
71 | - $sort = sort( $gst_countries ); |
|
70 | + if ($sort) { |
|
71 | + $sort = sort($gst_countries); |
|
72 | 72 | } |
73 | 73 | |
74 | - return apply_filters( 'wpinv_get_gst_countries', $gst_countries, $sort ); |
|
74 | + return apply_filters('wpinv_get_gst_countries', $gst_countries, $sort); |
|
75 | 75 | } |
76 | 76 | |
77 | - public static function is_eu_state( $country_code ) { |
|
78 | - $return = !empty( $country_code ) && in_array( strtoupper( $country_code ), self::get_eu_states() ) ? true : false; |
|
77 | + public static function is_eu_state($country_code) { |
|
78 | + $return = !empty($country_code) && in_array(strtoupper($country_code), self::get_eu_states()) ? true : false; |
|
79 | 79 | |
80 | - return apply_filters( 'wpinv_is_eu_state', $return, $country_code ); |
|
80 | + return apply_filters('wpinv_is_eu_state', $return, $country_code); |
|
81 | 81 | } |
82 | 82 | |
83 | - public static function is_gst_country( $country_code ) { |
|
84 | - $return = !empty( $country_code ) && in_array( strtoupper( $country_code ), self::get_gst_countries() ) ? true : false; |
|
83 | + public static function is_gst_country($country_code) { |
|
84 | + $return = !empty($country_code) && in_array(strtoupper($country_code), self::get_gst_countries()) ? true : false; |
|
85 | 85 | |
86 | - return apply_filters( 'wpinv_is_gst_country', $return, $country_code ); |
|
86 | + return apply_filters('wpinv_is_gst_country', $return, $country_code); |
|
87 | 87 | } |
88 | 88 | |
89 | 89 | public static function enqueue_vat_scripts() { |
90 | - $suffix = '';//defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
90 | + $suffix = ''; //defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
91 | 91 | |
92 | - wp_register_script( 'wpinv-vat-validation-script', WPINV_PLUGIN_URL . 'assets/js/jsvat' . $suffix . '.js', array( 'jquery' ), WPINV_VERSION ); |
|
93 | - wp_register_script( 'wpinv-vat-script', WPINV_PLUGIN_URL . 'assets/js/euvat' . $suffix . '.js', array( 'jquery' ), WPINV_VERSION ); |
|
92 | + wp_register_script('wpinv-vat-validation-script', WPINV_PLUGIN_URL . 'assets/js/jsvat' . $suffix . '.js', array('jquery'), WPINV_VERSION); |
|
93 | + wp_register_script('wpinv-vat-script', WPINV_PLUGIN_URL . 'assets/js/euvat' . $suffix . '.js', array('jquery'), WPINV_VERSION); |
|
94 | 94 | |
95 | - $vat_name = self::get_vat_name(); |
|
95 | + $vat_name = self::get_vat_name(); |
|
96 | 96 | |
97 | 97 | $vars = array(); |
98 | 98 | $vars['UseTaxes'] = wpinv_use_taxes(); |
99 | 99 | $vars['EUStates'] = self::get_eu_states(); |
100 | - $vars['NoRateSet'] = __( 'You have not set a rate. Do you want to continue?', 'invoicing' ); |
|
101 | - $vars['EmptyCompany'] = __( 'Please enter your registered company name!', 'invoicing' ); |
|
102 | - $vars['EmptyVAT'] = wp_sprintf( __( 'Please enter your %s number!', 'invoicing' ), $vat_name ); |
|
103 | - $vars['TotalsRefreshed'] = wp_sprintf( __( 'The invoice totals will be refreshed to update the %s.', 'invoicing' ), $vat_name ); |
|
104 | - $vars['ErrValidateVAT'] = wp_sprintf( __( 'Fail to validate the %s number!', 'invoicing' ), $vat_name ); |
|
105 | - $vars['ErrResetVAT'] = wp_sprintf( __( 'Fail to reset the %s number!', 'invoicing' ), $vat_name ); |
|
106 | - $vars['ErrInvalidVat'] = wp_sprintf( __( 'The %s number supplied does not have a valid format!', 'invoicing' ), $vat_name ); |
|
107 | - $vars['ErrInvalidResponse'] = __( 'An invalid response has been received from the server!', 'invoicing' ); |
|
100 | + $vars['NoRateSet'] = __('You have not set a rate. Do you want to continue?', 'invoicing'); |
|
101 | + $vars['EmptyCompany'] = __('Please enter your registered company name!', 'invoicing'); |
|
102 | + $vars['EmptyVAT'] = wp_sprintf(__('Please enter your %s number!', 'invoicing'), $vat_name); |
|
103 | + $vars['TotalsRefreshed'] = wp_sprintf(__('The invoice totals will be refreshed to update the %s.', 'invoicing'), $vat_name); |
|
104 | + $vars['ErrValidateVAT'] = wp_sprintf(__('Fail to validate the %s number!', 'invoicing'), $vat_name); |
|
105 | + $vars['ErrResetVAT'] = wp_sprintf(__('Fail to reset the %s number!', 'invoicing'), $vat_name); |
|
106 | + $vars['ErrInvalidVat'] = wp_sprintf(__('The %s number supplied does not have a valid format!', 'invoicing'), $vat_name); |
|
107 | + $vars['ErrInvalidResponse'] = __('An invalid response has been received from the server!', 'invoicing'); |
|
108 | 108 | $vars['ApplyVATRules'] = $vars['UseTaxes'] ? self::allow_vat_rules() : false; |
109 | 109 | $vars['HideVatFields'] = $vars['ApplyVATRules'] ? self::hide_vat_fields() : true; |
110 | - $vars['ErrResponse'] = __( 'The request response is invalid!', 'invoicing' ); |
|
111 | - $vars['ErrRateResponse'] = __( 'The get rate request response is invalid', 'invoicing' ); |
|
112 | - $vars['PageRefresh'] = __( 'The page will be refreshed in 10 seconds to show the new options.', 'invoicing' ); |
|
113 | - $vars['RequestResponseNotValidJSON'] = __( 'The get rate request response is not valid JSON', 'invoicing' ); |
|
114 | - $vars['GetRateRequestFailed'] = __( 'The get rate request failed: ', 'invoicing' ); |
|
115 | - $vars['NoRateInformationInResponse'] = __( 'The get rate request response does not contain any rate information', 'invoicing' ); |
|
116 | - $vars['RatesUpdated'] = __( 'The rates have been updated. Press the save button to record these new rates.', 'invoicing' ); |
|
117 | - $vars['IPAddressInformation'] = __( 'IP Address Information', 'invoicing' ); |
|
118 | - $vars['VatValidating'] = wp_sprintf( __( 'Validating %s number...', 'invoicing' ), $vat_name ); |
|
119 | - $vars['VatReseting'] = __( 'Reseting...', 'invoicing' ); |
|
120 | - $vars['VatValidated'] = wp_sprintf( __( '%s number validated', 'invoicing' ), $vat_name ); |
|
121 | - $vars['VatNotValidated'] = wp_sprintf( __( '%s number not validated', 'invoicing' ), $vat_name ); |
|
122 | - $vars['ConfirmDeleteClass'] = __( 'Are you sure you wish to delete this rates class?', 'invoicing' ); |
|
110 | + $vars['ErrResponse'] = __('The request response is invalid!', 'invoicing'); |
|
111 | + $vars['ErrRateResponse'] = __('The get rate request response is invalid', 'invoicing'); |
|
112 | + $vars['PageRefresh'] = __('The page will be refreshed in 10 seconds to show the new options.', 'invoicing'); |
|
113 | + $vars['RequestResponseNotValidJSON'] = __('The get rate request response is not valid JSON', 'invoicing'); |
|
114 | + $vars['GetRateRequestFailed'] = __('The get rate request failed: ', 'invoicing'); |
|
115 | + $vars['NoRateInformationInResponse'] = __('The get rate request response does not contain any rate information', 'invoicing'); |
|
116 | + $vars['RatesUpdated'] = __('The rates have been updated. Press the save button to record these new rates.', 'invoicing'); |
|
117 | + $vars['IPAddressInformation'] = __('IP Address Information', 'invoicing'); |
|
118 | + $vars['VatValidating'] = wp_sprintf(__('Validating %s number...', 'invoicing'), $vat_name); |
|
119 | + $vars['VatReseting'] = __('Reseting...', 'invoicing'); |
|
120 | + $vars['VatValidated'] = wp_sprintf(__('%s number validated', 'invoicing'), $vat_name); |
|
121 | + $vars['VatNotValidated'] = wp_sprintf(__('%s number not validated', 'invoicing'), $vat_name); |
|
122 | + $vars['ConfirmDeleteClass'] = __('Are you sure you wish to delete this rates class?', 'invoicing'); |
|
123 | 123 | $vars['isFront'] = is_admin() ? false : true; |
124 | - $vars['checkoutNonce'] = wp_create_nonce( 'wpinv_checkout_nonce' ); |
|
124 | + $vars['checkoutNonce'] = wp_create_nonce('wpinv_checkout_nonce'); |
|
125 | 125 | $vars['baseCountry'] = wpinv_get_default_country(); |
126 | - $vars['disableVATSameCountry'] = ( self::same_country_rule() == 'no' ? true : false ); |
|
127 | - $vars['disableVATSimpleCheck'] = wpinv_get_option( 'vat_offline_check' ) ? true : false; |
|
126 | + $vars['disableVATSameCountry'] = (self::same_country_rule() == 'no' ? true : false); |
|
127 | + $vars['disableVATSimpleCheck'] = wpinv_get_option('vat_offline_check') ? true : false; |
|
128 | 128 | |
129 | - wp_enqueue_script( 'wpinv-vat-validation-script' ); |
|
130 | - wp_enqueue_script( 'wpinv-vat-script' ); |
|
131 | - wp_localize_script( 'wpinv-vat-script', 'WPInv_VAT_Vars', $vars ); |
|
129 | + wp_enqueue_script('wpinv-vat-validation-script'); |
|
130 | + wp_enqueue_script('wpinv-vat-script'); |
|
131 | + wp_localize_script('wpinv-vat-script', 'WPInv_VAT_Vars', $vars); |
|
132 | 132 | } |
133 | 133 | |
134 | 134 | public static function enqueue_admin_scripts() { |
135 | - if( isset( $_GET['page'] ) && 'wpinv-settings' == $_GET['page'] ) { |
|
135 | + if (isset($_GET['page']) && 'wpinv-settings' == $_GET['page']) { |
|
136 | 136 | self::enqueue_vat_scripts(); |
137 | 137 | } |
138 | 138 | } |
139 | 139 | |
140 | - public static function section_vat_settings( $sections ) { |
|
141 | - if ( !empty( $sections ) ) { |
|
142 | - $sections['vat'] = __( 'EU VAT Settings', 'invoicing' ); |
|
140 | + public static function section_vat_settings($sections) { |
|
141 | + if (!empty($sections)) { |
|
142 | + $sections['vat'] = __('EU VAT Settings', 'invoicing'); |
|
143 | 143 | |
144 | - if ( self::allow_vat_classes() ) { |
|
145 | - $sections['vat_rates'] = __( 'EU VAT Rates', 'invoicing' ); |
|
144 | + if (self::allow_vat_classes()) { |
|
145 | + $sections['vat_rates'] = __('EU VAT Rates', 'invoicing'); |
|
146 | 146 | } |
147 | 147 | } |
148 | 148 | return $sections; |
@@ -151,52 +151,52 @@ discard block |
||
151 | 151 | public static function vat_rates_settings() { |
152 | 152 | $vat_classes = self::get_rate_classes(); |
153 | 153 | $vat_rates = array(); |
154 | - $vat_class = isset( $_REQUEST['wpi_sub'] ) && $_REQUEST['wpi_sub'] !== '' && isset( $vat_classes[$_REQUEST['wpi_sub']] )? sanitize_text_field( $_REQUEST['wpi_sub'] ) : '_new'; |
|
155 | - $current_url = remove_query_arg( 'wpi_sub' ); |
|
154 | + $vat_class = isset($_REQUEST['wpi_sub']) && $_REQUEST['wpi_sub'] !== '' && isset($vat_classes[$_REQUEST['wpi_sub']]) ? sanitize_text_field($_REQUEST['wpi_sub']) : '_new'; |
|
155 | + $current_url = remove_query_arg('wpi_sub'); |
|
156 | 156 | |
157 | 157 | $vat_rates['vat_rates_header'] = array( |
158 | 158 | 'id' => 'vat_rates_header', |
159 | - 'name' => '<h3>' . __( 'Manage VAT Rates', 'invoicing' ) . '</h3>', |
|
159 | + 'name' => '<h3>' . __('Manage VAT Rates', 'invoicing') . '</h3>', |
|
160 | 160 | 'desc' => '', |
161 | 161 | 'type' => 'header', |
162 | 162 | 'size' => 'regular' |
163 | 163 | ); |
164 | 164 | $vat_rates['vat_rates_class'] = array( |
165 | 165 | 'id' => 'vat_rates_class', |
166 | - 'name' => __( 'Edit VAT Rates', 'invoicing' ), |
|
167 | - 'desc' => __( 'The standard rate will apply where no explicit rate is provided.', 'invoicing' ), |
|
166 | + 'name' => __('Edit VAT Rates', 'invoicing'), |
|
167 | + 'desc' => __('The standard rate will apply where no explicit rate is provided.', 'invoicing'), |
|
168 | 168 | 'type' => 'select', |
169 | - 'options' => array_merge( $vat_classes, array( '_new' => __( 'Add New Rate Class', 'invoicing' ) ) ), |
|
169 | + 'options' => array_merge($vat_classes, array('_new' => __('Add New Rate Class', 'invoicing'))), |
|
170 | 170 | 'chosen' => true, |
171 | - 'placeholder' => __( 'Select a VAT Rate', 'invoicing' ), |
|
171 | + 'placeholder' => __('Select a VAT Rate', 'invoicing'), |
|
172 | 172 | 'selected' => $vat_class, |
173 | 173 | 'onchange' => 'document.location.href="' . $current_url . '&wpi_sub=" + this.value;', |
174 | 174 | ); |
175 | 175 | |
176 | - if ( $vat_class != '_standard' && $vat_class != '_new' ) { |
|
176 | + if ($vat_class != '_standard' && $vat_class != '_new') { |
|
177 | 177 | $vat_rates['vat_rate_delete'] = array( |
178 | 178 | 'id' => 'vat_rate_delete', |
179 | 179 | 'type' => 'vat_rate_delete', |
180 | 180 | ); |
181 | 181 | } |
182 | 182 | |
183 | - if ( $vat_class == '_new' ) { |
|
183 | + if ($vat_class == '_new') { |
|
184 | 184 | $vat_rates['vat_rates_settings'] = array( |
185 | 185 | 'id' => 'vat_rates_settings', |
186 | - 'name' => '<h3>' . __( 'Add New Rate Class', 'invoicing' ) . '</h3>', |
|
186 | + 'name' => '<h3>' . __('Add New Rate Class', 'invoicing') . '</h3>', |
|
187 | 187 | 'type' => 'header', |
188 | 188 | ); |
189 | 189 | $vat_rates['vat_rate_name'] = array( |
190 | 190 | 'id' => 'vat_rate_name', |
191 | - 'name' => __( 'Name', 'invoicing' ), |
|
192 | - 'desc' => __( 'A short name for the new VAT Rate class', 'invoicing' ), |
|
191 | + 'name' => __('Name', 'invoicing'), |
|
192 | + 'desc' => __('A short name for the new VAT Rate class', 'invoicing'), |
|
193 | 193 | 'type' => 'text', |
194 | 194 | 'size' => 'regular', |
195 | 195 | ); |
196 | 196 | $vat_rates['vat_rate_desc'] = array( |
197 | 197 | 'id' => 'vat_rate_desc', |
198 | - 'name' => __( 'Description', 'invoicing' ), |
|
199 | - 'desc' => __( 'Manage VAT Rate class', 'invoicing' ), |
|
198 | + 'name' => __('Description', 'invoicing'), |
|
199 | + 'desc' => __('Manage VAT Rate class', 'invoicing'), |
|
200 | 200 | 'type' => 'text', |
201 | 201 | 'size' => 'regular', |
202 | 202 | ); |
@@ -208,7 +208,7 @@ discard block |
||
208 | 208 | $vat_rates['vat_rates'] = array( |
209 | 209 | 'id' => 'vat_rates', |
210 | 210 | 'name' => '<h3>' . $vat_classes[$vat_class] . '</h3>', |
211 | - 'desc' => self::get_class_desc( $vat_class ), |
|
211 | + 'desc' => self::get_class_desc($vat_class), |
|
212 | 212 | 'type' => 'vat_rates', |
213 | 213 | ); |
214 | 214 | } |
@@ -216,12 +216,12 @@ discard block |
||
216 | 216 | return $vat_rates; |
217 | 217 | } |
218 | 218 | |
219 | - public static function vat_settings( $settings ) { |
|
220 | - if ( !empty( $settings ) ) { |
|
219 | + public static function vat_settings($settings) { |
|
220 | + if (!empty($settings)) { |
|
221 | 221 | $vat_settings = array(); |
222 | 222 | $vat_settings['vat_company_title'] = array( |
223 | 223 | 'id' => 'vat_company_title', |
224 | - 'name' => '<h3>' . __( 'Your Company Details', 'invoicing' ) . '</h3>', |
|
224 | + 'name' => '<h3>' . __('Your Company Details', 'invoicing') . '</h3>', |
|
225 | 225 | 'desc' => '', |
226 | 226 | 'type' => 'header', |
227 | 227 | 'size' => 'regular' |
@@ -229,22 +229,22 @@ discard block |
||
229 | 229 | |
230 | 230 | $vat_settings['vat_company_name'] = array( |
231 | 231 | 'id' => 'vat_company_name', |
232 | - 'name' => __( 'Your Company Name', 'invoicing' ), |
|
233 | - 'desc' => wp_sprintf(__( 'Your company name as it appears on your VAT return, you can verify it via your VAT ID on the %sEU VIES System.%s', 'invoicing' ), '<a href="http://ec.europa.eu/taxation_customs/vies/" target="_blank">', '</a>' ), |
|
232 | + 'name' => __('Your Company Name', 'invoicing'), |
|
233 | + 'desc' => wp_sprintf(__('Your company name as it appears on your VAT return, you can verify it via your VAT ID on the %sEU VIES System.%s', 'invoicing'), '<a href="http://ec.europa.eu/taxation_customs/vies/" target="_blank">', '</a>'), |
|
234 | 234 | 'type' => 'text', |
235 | 235 | 'size' => 'regular', |
236 | 236 | ); |
237 | 237 | |
238 | 238 | $vat_settings['vat_number'] = array( |
239 | 239 | 'id' => 'vat_number', |
240 | - 'name' => __( 'Your VAT Number', 'invoicing' ), |
|
240 | + 'name' => __('Your VAT Number', 'invoicing'), |
|
241 | 241 | 'type' => 'vat_number', |
242 | 242 | 'size' => 'regular', |
243 | 243 | ); |
244 | 244 | |
245 | 245 | $vat_settings['vat_settings_title'] = array( |
246 | 246 | 'id' => 'vat_settings_title', |
247 | - 'name' => '<h3>' . __( 'Apply VAT Settings', 'invoicing' ) . '</h3>', |
|
247 | + 'name' => '<h3>' . __('Apply VAT Settings', 'invoicing') . '</h3>', |
|
248 | 248 | 'desc' => '', |
249 | 249 | 'type' => 'header', |
250 | 250 | 'size' => 'regular' |
@@ -252,8 +252,8 @@ discard block |
||
252 | 252 | |
253 | 253 | $vat_settings['apply_vat_rules'] = array( |
254 | 254 | 'id' => 'apply_vat_rules', |
255 | - 'name' => __( 'Enable VAT rules', 'invoicing' ), |
|
256 | - 'desc' => __( 'Apply VAT to consumer sales from IP addresses within the EU, even if the billing address is outside the EU.', 'invoicing' ) . '<br><font style="color:red">' . __( 'Do not disable unless you know what you are doing.', 'invoicing' ) . '</font>', |
|
255 | + 'name' => __('Enable VAT rules', 'invoicing'), |
|
256 | + 'desc' => __('Apply VAT to consumer sales from IP addresses within the EU, even if the billing address is outside the EU.', 'invoicing') . '<br><font style="color:red">' . __('Do not disable unless you know what you are doing.', 'invoicing') . '</font>', |
|
257 | 257 | 'type' => 'checkbox', |
258 | 258 | 'std' => '1' |
259 | 259 | ); |
@@ -269,8 +269,8 @@ discard block |
||
269 | 269 | |
270 | 270 | $vat_settings['vat_prevent_b2c_purchase'] = array( |
271 | 271 | 'id' => 'vat_prevent_b2c_purchase', |
272 | - 'name' => __( 'Prevent EU B2C sales', 'invoicing' ), |
|
273 | - 'desc' => __( 'Enable this option if you are not registered for VAT in the EU.', 'invoicing' ), |
|
272 | + 'name' => __('Prevent EU B2C sales', 'invoicing'), |
|
273 | + 'desc' => __('Enable this option if you are not registered for VAT in the EU.', 'invoicing'), |
|
274 | 274 | 'type' => 'checkbox' |
275 | 275 | ); |
276 | 276 | |
@@ -278,21 +278,21 @@ discard block |
||
278 | 278 | |
279 | 279 | $vat_settings['vat_same_country_rule'] = array( |
280 | 280 | 'id' => 'vat_same_country_rule', |
281 | - 'name' => __( 'Same country rule', 'invoicing' ), |
|
282 | - 'desc' => __( 'Select how you want handle VAT charge if sales are in the same country as the base country.', 'invoicing' ), |
|
281 | + 'name' => __('Same country rule', 'invoicing'), |
|
282 | + 'desc' => __('Select how you want handle VAT charge if sales are in the same country as the base country.', 'invoicing'), |
|
283 | 283 | 'type' => 'select', |
284 | 284 | 'options' => array( |
285 | - '' => __( 'Normal', 'invoicing' ), |
|
286 | - 'no' => __( 'No VAT', 'invoicing' ), |
|
287 | - 'always' => __( 'Always apply VAT', 'invoicing' ), |
|
285 | + '' => __('Normal', 'invoicing'), |
|
286 | + 'no' => __('No VAT', 'invoicing'), |
|
287 | + 'always' => __('Always apply VAT', 'invoicing'), |
|
288 | 288 | ), |
289 | - 'placeholder' => __( 'Select a option', 'invoicing' ), |
|
289 | + 'placeholder' => __('Select a option', 'invoicing'), |
|
290 | 290 | 'std' => '' |
291 | 291 | ); |
292 | 292 | |
293 | 293 | $vat_settings['vat_checkout_title'] = array( |
294 | 294 | 'id' => 'vat_checkout_title', |
295 | - 'name' => '<h3>' . __( 'Checkout Fields', 'invoicing' ) . '</h3>', |
|
295 | + 'name' => '<h3>' . __('Checkout Fields', 'invoicing') . '</h3>', |
|
296 | 296 | 'desc' => '', |
297 | 297 | 'type' => 'header', |
298 | 298 | 'size' => 'regular' |
@@ -300,14 +300,14 @@ discard block |
||
300 | 300 | |
301 | 301 | $vat_settings['vat_disable_fields'] = array( |
302 | 302 | 'id' => 'vat_disable_fields', |
303 | - 'name' => __( 'Disable VAT fields', 'invoicing' ), |
|
304 | - 'desc' => __( 'Disable VAT fields if Invoicing is being used for GST.', 'invoicing' ) . '<br><font style="color:red">' . __( 'Do not disable if you have enabled Prevent EU B2C sales, otherwise Prevent EU B2C sales setting will not work.', 'invoicing' ) . '</font>', |
|
303 | + 'name' => __('Disable VAT fields', 'invoicing'), |
|
304 | + 'desc' => __('Disable VAT fields if Invoicing is being used for GST.', 'invoicing') . '<br><font style="color:red">' . __('Do not disable if you have enabled Prevent EU B2C sales, otherwise Prevent EU B2C sales setting will not work.', 'invoicing') . '</font>', |
|
305 | 305 | 'type' => 'checkbox' |
306 | 306 | ); |
307 | 307 | |
308 | 308 | $vat_settings['vat_ip_lookup'] = array( |
309 | 309 | 'id' => 'vat_ip_lookup', |
310 | - 'name' => __( 'IP Country lookup', 'invoicing' ), |
|
310 | + 'name' => __('IP Country lookup', 'invoicing'), |
|
311 | 311 | 'type' => 'vat_ip_lookup', |
312 | 312 | 'size' => 'regular', |
313 | 313 | 'std' => 'default' |
@@ -315,21 +315,21 @@ discard block |
||
315 | 315 | |
316 | 316 | $vat_settings['hide_ip_address'] = array( |
317 | 317 | 'id' => 'hide_ip_address', |
318 | - 'name' => __( 'Hide IP info at checkout', 'invoicing' ), |
|
319 | - 'desc' => __( 'Hide the user IP info at checkout.', 'invoicing' ), |
|
318 | + 'name' => __('Hide IP info at checkout', 'invoicing'), |
|
319 | + 'desc' => __('Hide the user IP info at checkout.', 'invoicing'), |
|
320 | 320 | 'type' => 'checkbox' |
321 | 321 | ); |
322 | 322 | |
323 | 323 | $vat_settings['vat_ip_country_default'] = array( |
324 | 324 | 'id' => 'vat_ip_country_default', |
325 | - 'name' => __( 'Enable IP Country as Default', 'invoicing' ), |
|
326 | - 'desc' => __( 'Show the country of the users IP as the default country, otherwise the site default country will be used.', 'invoicing' ), |
|
325 | + 'name' => __('Enable IP Country as Default', 'invoicing'), |
|
326 | + 'desc' => __('Show the country of the users IP as the default country, otherwise the site default country will be used.', 'invoicing'), |
|
327 | 327 | 'type' => 'checkbox' |
328 | 328 | ); |
329 | 329 | |
330 | 330 | $vat_settings['vies_validation_title'] = array( |
331 | 331 | 'id' => 'vies_validation_title', |
332 | - 'name' => '<h3>' . __( 'VIES Validation', 'invoicing' ) . '</h3>', |
|
332 | + 'name' => '<h3>' . __('VIES Validation', 'invoicing') . '</h3>', |
|
333 | 333 | 'desc' => '', |
334 | 334 | 'type' => 'header', |
335 | 335 | 'size' => 'regular' |
@@ -337,37 +337,37 @@ discard block |
||
337 | 337 | |
338 | 338 | $vat_settings['vat_vies_check'] = array( |
339 | 339 | 'id' => 'vat_vies_check', |
340 | - 'name' => __( 'Disable VIES VAT ID check', 'invoicing' ), |
|
341 | - 'desc' => wp_sprintf( __( 'Prevent VAT numbers from being validated by the %sEU VIES System.%s', 'invoicing' ), '<a href="http://ec.europa.eu/taxation_customs/vies/" target="_blank">', '</a>' ), |
|
340 | + 'name' => __('Disable VIES VAT ID check', 'invoicing'), |
|
341 | + 'desc' => wp_sprintf(__('Prevent VAT numbers from being validated by the %sEU VIES System.%s', 'invoicing'), '<a href="http://ec.europa.eu/taxation_customs/vies/" target="_blank">', '</a>'), |
|
342 | 342 | 'type' => 'checkbox' |
343 | 343 | ); |
344 | 344 | |
345 | 345 | $vat_settings['vat_disable_company_name_check'] = array( |
346 | 346 | 'id' => 'vat_disable_company_name_check', |
347 | - 'name' => __( 'Disable VIES name check', 'invoicing' ), |
|
348 | - 'desc' => wp_sprintf( __( 'Prevent company name from being validated by the %sEU VIES System.%s', 'invoicing' ), '<a href="http://ec.europa.eu/taxation_customs/vies/" target="_blank">', '</a>' ), |
|
347 | + 'name' => __('Disable VIES name check', 'invoicing'), |
|
348 | + 'desc' => wp_sprintf(__('Prevent company name from being validated by the %sEU VIES System.%s', 'invoicing'), '<a href="http://ec.europa.eu/taxation_customs/vies/" target="_blank">', '</a>'), |
|
349 | 349 | 'type' => 'checkbox' |
350 | 350 | ); |
351 | 351 | |
352 | 352 | $vat_settings['vat_offline_check'] = array( |
353 | 353 | 'id' => 'vat_offline_check', |
354 | - 'name' => __( 'Disable basic checks', 'invoicing' ), |
|
355 | - 'desc' => __( 'This will disable basic JS correct format validation attempts, it is very rare this should need to be disabled.', 'invoicing' ), |
|
354 | + 'name' => __('Disable basic checks', 'invoicing'), |
|
355 | + 'desc' => __('This will disable basic JS correct format validation attempts, it is very rare this should need to be disabled.', 'invoicing'), |
|
356 | 356 | 'type' => 'checkbox' |
357 | 357 | ); |
358 | 358 | |
359 | 359 | |
360 | 360 | $settings['vat'] = $vat_settings; |
361 | 361 | |
362 | - if ( self::allow_vat_classes() ) { |
|
362 | + if (self::allow_vat_classes()) { |
|
363 | 363 | $settings['vat_rates'] = self::vat_rates_settings(); |
364 | 364 | } |
365 | 365 | |
366 | 366 | $eu_fallback_rate = array( |
367 | 367 | 'id' => 'eu_fallback_rate', |
368 | - 'name' => '<h3>' . __( 'VAT rate for EU member states', 'invoicing' ) . '</h3>', |
|
368 | + 'name' => '<h3>' . __('VAT rate for EU member states', 'invoicing') . '</h3>', |
|
369 | 369 | 'type' => 'eu_fallback_rate', |
370 | - 'desc' => __( 'Enter the VAT rate to be charged for EU member states. You can edit the rates for each member state when a country rate has been set up by pressing this button.', 'invoicing' ), |
|
370 | + 'desc' => __('Enter the VAT rate to be charged for EU member states. You can edit the rates for each member state when a country rate has been set up by pressing this button.', 'invoicing'), |
|
371 | 371 | 'std' => '20', |
372 | 372 | 'size' => 'small' |
373 | 373 | ); |
@@ -383,11 +383,11 @@ discard block |
||
383 | 383 | $database_url = 'http' . (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] === 'on' ? 's' : '') . '://geolite.maxmind.com/download/geoip/database/'; |
384 | 384 | $destination_dir = $upload_dir['basedir'] . '/invoicing'; |
385 | 385 | |
386 | - if ( !is_dir( $destination_dir ) ) { |
|
387 | - mkdir( $destination_dir ); |
|
386 | + if (!is_dir($destination_dir)) { |
|
387 | + mkdir($destination_dir); |
|
388 | 388 | } |
389 | 389 | |
390 | - $database_files = array( |
|
390 | + $database_files = array( |
|
391 | 391 | 'country' => array( |
392 | 392 | 'source' => $database_url . 'GeoLite2-Country.mmdb.gz', |
393 | 393 | 'destination' => $destination_dir . '/GeoLite2-Country.mmdb', |
@@ -398,57 +398,57 @@ discard block |
||
398 | 398 | ) |
399 | 399 | ); |
400 | 400 | |
401 | - foreach( $database_files as $database => $files ) { |
|
402 | - $result = self::geoip2_download_file( $files['source'], $files['destination'] ); |
|
401 | + foreach ($database_files as $database => $files) { |
|
402 | + $result = self::geoip2_download_file($files['source'], $files['destination']); |
|
403 | 403 | |
404 | - if ( empty( $result['success'] ) ) { |
|
404 | + if (empty($result['success'])) { |
|
405 | 405 | echo $result['message']; |
406 | 406 | exit; |
407 | 407 | } |
408 | 408 | |
409 | - wpinv_update_option( 'wpinv_geoip2_date_updated', current_time( 'timestamp' ) ); |
|
410 | - echo sprintf(__( 'GeoIp2 %s database updated successfully.', 'invoicing' ), $database ) . ' '; |
|
409 | + wpinv_update_option('wpinv_geoip2_date_updated', current_time('timestamp')); |
|
410 | + echo sprintf(__('GeoIp2 %s database updated successfully.', 'invoicing'), $database) . ' '; |
|
411 | 411 | } |
412 | 412 | |
413 | 413 | exit; |
414 | 414 | } |
415 | 415 | |
416 | - public static function geoip2_download_file( $source_url, $destination_file ) { |
|
416 | + public static function geoip2_download_file($source_url, $destination_file) { |
|
417 | 417 | $success = false; |
418 | 418 | $message = ''; |
419 | 419 | |
420 | - if ( !function_exists( 'download_url' ) ) { |
|
421 | - require_once( ABSPATH . 'wp-admin/includes/file.php' ); |
|
420 | + if (!function_exists('download_url')) { |
|
421 | + require_once(ABSPATH . 'wp-admin/includes/file.php'); |
|
422 | 422 | } |
423 | 423 | |
424 | - $temp_file = download_url( $source_url ); |
|
424 | + $temp_file = download_url($source_url); |
|
425 | 425 | |
426 | - if ( is_wp_error( $temp_file ) ) { |
|
427 | - $message = sprintf( __( 'Error while downloading GeoIp2 database( %s ): %s', 'invoicing' ), $source_url, $temp_file->get_error_message() ); |
|
426 | + if (is_wp_error($temp_file)) { |
|
427 | + $message = sprintf(__('Error while downloading GeoIp2 database( %s ): %s', 'invoicing'), $source_url, $temp_file->get_error_message()); |
|
428 | 428 | } else { |
429 | - $handle = gzopen( $temp_file, 'rb' ); |
|
429 | + $handle = gzopen($temp_file, 'rb'); |
|
430 | 430 | |
431 | - if ( $handle ) { |
|
432 | - $fopen = fopen( $destination_file, 'wb' ); |
|
433 | - if ( $fopen ) { |
|
434 | - while ( ( $data = gzread( $handle, 4096 ) ) != false ) { |
|
435 | - fwrite( $fopen, $data ); |
|
431 | + if ($handle) { |
|
432 | + $fopen = fopen($destination_file, 'wb'); |
|
433 | + if ($fopen) { |
|
434 | + while (($data = gzread($handle, 4096)) != false) { |
|
435 | + fwrite($fopen, $data); |
|
436 | 436 | } |
437 | 437 | |
438 | - gzclose( $handle ); |
|
439 | - fclose( $fopen ); |
|
438 | + gzclose($handle); |
|
439 | + fclose($fopen); |
|
440 | 440 | |
441 | 441 | $success = true; |
442 | 442 | } else { |
443 | - gzclose( $handle ); |
|
444 | - $message = sprintf( __( 'Error could not open destination GeoIp2 database file for writing: %s', 'invoicing' ), $destination_file ); |
|
443 | + gzclose($handle); |
|
444 | + $message = sprintf(__('Error could not open destination GeoIp2 database file for writing: %s', 'invoicing'), $destination_file); |
|
445 | 445 | } |
446 | 446 | } else { |
447 | - $message = sprintf( __( 'Error could not open GeoIp2 database file for reading: %s', 'invoicing' ), $temp_file ); |
|
447 | + $message = sprintf(__('Error could not open GeoIp2 database file for reading: %s', 'invoicing'), $temp_file); |
|
448 | 448 | } |
449 | 449 | |
450 | - if ( file_exists( $temp_file ) ) { |
|
451 | - unlink( $temp_file ); |
|
450 | + if (file_exists($temp_file)) { |
|
451 | + unlink($temp_file); |
|
452 | 452 | } |
453 | 453 | } |
454 | 454 | |
@@ -460,11 +460,11 @@ discard block |
||
460 | 460 | } |
461 | 461 | |
462 | 462 | public static function load_geoip2() { |
463 | - if ( defined( 'WPINV_GEOIP2_LODDED' ) ) { |
|
463 | + if (defined('WPINV_GEOIP2_LODDED')) { |
|
464 | 464 | return; |
465 | 465 | } |
466 | 466 | |
467 | - if ( !class_exists( '\MaxMind\Db\Reader' ) ) { |
|
467 | + if (!class_exists('\MaxMind\Db\Reader')) { |
|
468 | 468 | $maxmind_db_files = array( |
469 | 469 | 'Reader/Decoder.php', |
470 | 470 | 'Reader/InvalidDatabaseException.php', |
@@ -473,12 +473,12 @@ discard block |
||
473 | 473 | 'Reader.php', |
474 | 474 | ); |
475 | 475 | |
476 | - foreach ( $maxmind_db_files as $key => $file ) { |
|
477 | - require_once( WPINV_PLUGIN_DIR . 'includes/libraries/MaxMind/Db/' . $file ); |
|
476 | + foreach ($maxmind_db_files as $key => $file) { |
|
477 | + require_once(WPINV_PLUGIN_DIR . 'includes/libraries/MaxMind/Db/' . $file); |
|
478 | 478 | } |
479 | 479 | } |
480 | 480 | |
481 | - if ( !class_exists( '\GeoIp2\Database\Reader' ) ) { |
|
481 | + if (!class_exists('\GeoIp2\Database\Reader')) { |
|
482 | 482 | $geoip2_files = array( |
483 | 483 | 'ProviderInterface.php', |
484 | 484 | 'Compat/JsonSerializable.php', |
@@ -512,23 +512,23 @@ discard block |
||
512 | 512 | 'WebService/Client.php', |
513 | 513 | ); |
514 | 514 | |
515 | - foreach ( $geoip2_files as $key => $file ) { |
|
516 | - require_once( WPINV_PLUGIN_DIR . 'includes/libraries/GeoIp2/' . $file ); |
|
515 | + foreach ($geoip2_files as $key => $file) { |
|
516 | + require_once(WPINV_PLUGIN_DIR . 'includes/libraries/GeoIp2/' . $file); |
|
517 | 517 | } |
518 | 518 | } |
519 | 519 | |
520 | - define( 'WPINV_GEOIP2_LODDED', true ); |
|
520 | + define('WPINV_GEOIP2_LODDED', true); |
|
521 | 521 | } |
522 | 522 | |
523 | 523 | public static function geoip2_country_dbfile() { |
524 | 524 | $upload_dir = wp_upload_dir(); |
525 | 525 | |
526 | - if ( !isset( $upload_dir['basedir'] ) ) { |
|
526 | + if (!isset($upload_dir['basedir'])) { |
|
527 | 527 | return false; |
528 | 528 | } |
529 | 529 | |
530 | 530 | $filename = $upload_dir['basedir'] . '/invoicing/GeoLite2-Country.mmdb'; |
531 | - if ( !file_exists( $filename ) ) { |
|
531 | + if (!file_exists($filename)) { |
|
532 | 532 | return false; |
533 | 533 | } |
534 | 534 | |
@@ -538,12 +538,12 @@ discard block |
||
538 | 538 | public static function geoip2_city_dbfile() { |
539 | 539 | $upload_dir = wp_upload_dir(); |
540 | 540 | |
541 | - if ( !isset( $upload_dir['basedir'] ) ) { |
|
541 | + if (!isset($upload_dir['basedir'])) { |
|
542 | 542 | return false; |
543 | 543 | } |
544 | 544 | |
545 | 545 | $filename = $upload_dir['basedir'] . '/invoicing/GeoLite2-City.mmdb'; |
546 | - if ( !file_exists( $filename ) ) { |
|
546 | + if (!file_exists($filename)) { |
|
547 | 547 | return false; |
548 | 548 | } |
549 | 549 | |
@@ -554,10 +554,10 @@ discard block |
||
554 | 554 | try { |
555 | 555 | self::load_geoip2(); |
556 | 556 | |
557 | - if ( $filename = self::geoip2_country_dbfile() ) { |
|
558 | - return new \GeoIp2\Database\Reader( $filename ); |
|
557 | + if ($filename = self::geoip2_country_dbfile()) { |
|
558 | + return new \GeoIp2\Database\Reader($filename); |
|
559 | 559 | } |
560 | - } catch( Exception $e ) { |
|
560 | + } catch (Exception $e) { |
|
561 | 561 | return false; |
562 | 562 | } |
563 | 563 | |
@@ -568,173 +568,173 @@ discard block |
||
568 | 568 | try { |
569 | 569 | self::load_geoip2(); |
570 | 570 | |
571 | - if ( $filename = self::geoip2_city_dbfile() ) { |
|
572 | - return new \GeoIp2\Database\Reader( $filename ); |
|
571 | + if ($filename = self::geoip2_city_dbfile()) { |
|
572 | + return new \GeoIp2\Database\Reader($filename); |
|
573 | 573 | } |
574 | - } catch( Exception $e ) { |
|
574 | + } catch (Exception $e) { |
|
575 | 575 | return false; |
576 | 576 | } |
577 | 577 | |
578 | 578 | return false; |
579 | 579 | } |
580 | 580 | |
581 | - public static function geoip2_country_record( $ip_address ) { |
|
581 | + public static function geoip2_country_record($ip_address) { |
|
582 | 582 | try { |
583 | 583 | $reader = self::geoip2_country_reader(); |
584 | 584 | |
585 | - if ( $reader ) { |
|
586 | - $record = $reader->country( $ip_address ); |
|
585 | + if ($reader) { |
|
586 | + $record = $reader->country($ip_address); |
|
587 | 587 | |
588 | - if ( !empty( $record->country->isoCode ) ) { |
|
588 | + if (!empty($record->country->isoCode)) { |
|
589 | 589 | return $record; |
590 | 590 | } |
591 | 591 | } |
592 | - } catch(\InvalidArgumentException $e) { |
|
593 | - wpinv_error_log( $e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )' ); |
|
592 | + } catch (\InvalidArgumentException $e) { |
|
593 | + wpinv_error_log($e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )'); |
|
594 | 594 | |
595 | 595 | return false; |
596 | - } catch(\GeoIp2\Exception\AddressNotFoundException $e) { |
|
597 | - wpinv_error_log( $e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )' ); |
|
596 | + } catch (\GeoIp2\Exception\AddressNotFoundException $e) { |
|
597 | + wpinv_error_log($e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )'); |
|
598 | 598 | |
599 | 599 | return false; |
600 | - } catch( Exception $e ) { |
|
600 | + } catch (Exception $e) { |
|
601 | 601 | return false; |
602 | 602 | } |
603 | 603 | |
604 | 604 | return false; |
605 | 605 | } |
606 | 606 | |
607 | - public static function geoip2_city_record( $ip_address ) { |
|
607 | + public static function geoip2_city_record($ip_address) { |
|
608 | 608 | try { |
609 | 609 | $reader = self::geoip2_city_reader(); |
610 | 610 | |
611 | - if ( $reader ) { |
|
612 | - $record = $reader->city( $ip_address ); |
|
611 | + if ($reader) { |
|
612 | + $record = $reader->city($ip_address); |
|
613 | 613 | |
614 | - if ( !empty( $record->country->isoCode ) ) { |
|
614 | + if (!empty($record->country->isoCode)) { |
|
615 | 615 | return $record; |
616 | 616 | } |
617 | 617 | } |
618 | - } catch(\InvalidArgumentException $e) { |
|
619 | - wpinv_error_log( $e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )' ); |
|
618 | + } catch (\InvalidArgumentException $e) { |
|
619 | + wpinv_error_log($e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )'); |
|
620 | 620 | |
621 | 621 | return false; |
622 | - } catch(\GeoIp2\Exception\AddressNotFoundException $e) { |
|
623 | - wpinv_error_log( $e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )' ); |
|
622 | + } catch (\GeoIp2\Exception\AddressNotFoundException $e) { |
|
623 | + wpinv_error_log($e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )'); |
|
624 | 624 | |
625 | 625 | return false; |
626 | - } catch( Exception $e ) { |
|
626 | + } catch (Exception $e) { |
|
627 | 627 | return false; |
628 | 628 | } |
629 | 629 | |
630 | 630 | return false; |
631 | 631 | } |
632 | 632 | |
633 | - public static function geoip2_country_code( $ip_address ) { |
|
634 | - $record = self::geoip2_country_record( $ip_address ); |
|
635 | - return !empty( $record->country->isoCode ) ? $record->country->isoCode : wpinv_get_default_country(); |
|
633 | + public static function geoip2_country_code($ip_address) { |
|
634 | + $record = self::geoip2_country_record($ip_address); |
|
635 | + return !empty($record->country->isoCode) ? $record->country->isoCode : wpinv_get_default_country(); |
|
636 | 636 | } |
637 | 637 | |
638 | 638 | // Find country by IP address. |
639 | - public static function get_country_by_ip( $ip = '' ) { |
|
639 | + public static function get_country_by_ip($ip = '') { |
|
640 | 640 | global $wpinv_ip_address_country; |
641 | 641 | |
642 | - if ( !empty( $wpinv_ip_address_country ) ) { |
|
642 | + if (!empty($wpinv_ip_address_country)) { |
|
643 | 643 | return $wpinv_ip_address_country; |
644 | 644 | } |
645 | 645 | |
646 | - if ( empty( $ip ) ) { |
|
646 | + if (empty($ip)) { |
|
647 | 647 | $ip = wpinv_get_ip(); |
648 | 648 | } |
649 | 649 | |
650 | - $ip_country_service = wpinv_get_option( 'vat_ip_lookup' ); |
|
651 | - $is_default = empty( $ip_country_service ) || $ip_country_service === 'default' ? true : false; |
|
650 | + $ip_country_service = wpinv_get_option('vat_ip_lookup'); |
|
651 | + $is_default = empty($ip_country_service) || $ip_country_service === 'default' ? true : false; |
|
652 | 652 | |
653 | - if ( !empty( $ip ) && $ip !== '127.0.0.1' ) { // For 127.0.0.1(localhost) use default country. |
|
654 | - if ( function_exists( 'geoip_country_code_by_name') && ( $ip_country_service === 'geoip' || $is_default ) ) { |
|
653 | + if (!empty($ip) && $ip !== '127.0.0.1') { // For 127.0.0.1(localhost) use default country. |
|
654 | + if (function_exists('geoip_country_code_by_name') && ($ip_country_service === 'geoip' || $is_default)) { |
|
655 | 655 | try { |
656 | - $wpinv_ip_address_country = geoip_country_code_by_name( $ip ); |
|
657 | - } catch( Exception $e ) { |
|
658 | - wpinv_error_log( $e->getMessage(), 'GeoIP Lookup( ' . $ip . ' )' ); |
|
656 | + $wpinv_ip_address_country = geoip_country_code_by_name($ip); |
|
657 | + } catch (Exception $e) { |
|
658 | + wpinv_error_log($e->getMessage(), 'GeoIP Lookup( ' . $ip . ' )'); |
|
659 | 659 | } |
660 | - } else if ( self::geoip2_country_dbfile() && ( $ip_country_service === 'geoip2' || $is_default ) ) { |
|
661 | - $wpinv_ip_address_country = self::geoip2_country_code( $ip ); |
|
662 | - } else if ( function_exists( 'simplexml_load_file' ) && ( $ip_country_service === 'geoplugin' || $is_default ) ) { |
|
663 | - $load_xml = simplexml_load_file( 'http://www.geoplugin.net/xml.gp?ip=' . $ip ); |
|
660 | + } else if (self::geoip2_country_dbfile() && ($ip_country_service === 'geoip2' || $is_default)) { |
|
661 | + $wpinv_ip_address_country = self::geoip2_country_code($ip); |
|
662 | + } else if (function_exists('simplexml_load_file') && ($ip_country_service === 'geoplugin' || $is_default)) { |
|
663 | + $load_xml = simplexml_load_file('http://www.geoplugin.net/xml.gp?ip=' . $ip); |
|
664 | 664 | |
665 | - if ( !empty( $load_xml ) && !empty( $load_xml->geoplugin_countryCode ) ) { |
|
665 | + if (!empty($load_xml) && !empty($load_xml->geoplugin_countryCode)) { |
|
666 | 666 | $wpinv_ip_address_country = (string)$load_xml->geoplugin_countryCode; |
667 | 667 | } |
668 | 668 | } |
669 | 669 | } |
670 | 670 | |
671 | - if ( empty( $wpinv_ip_address_country ) ) { |
|
671 | + if (empty($wpinv_ip_address_country)) { |
|
672 | 672 | $wpinv_ip_address_country = wpinv_get_default_country(); |
673 | 673 | } |
674 | 674 | |
675 | 675 | return $wpinv_ip_address_country; |
676 | 676 | } |
677 | 677 | |
678 | - public static function sanitize_vat_settings( $input ) { |
|
678 | + public static function sanitize_vat_settings($input) { |
|
679 | 679 | global $wpinv_options; |
680 | 680 | |
681 | 681 | $valid = false; |
682 | 682 | $message = ''; |
683 | 683 | |
684 | - if ( !empty( $wpinv_options['vat_vies_check'] ) ) { |
|
685 | - if ( empty( $wpinv_options['vat_offline_check'] ) ) { |
|
686 | - $valid = self::offline_check( $input['vat_number'] ); |
|
684 | + if (!empty($wpinv_options['vat_vies_check'])) { |
|
685 | + if (empty($wpinv_options['vat_offline_check'])) { |
|
686 | + $valid = self::offline_check($input['vat_number']); |
|
687 | 687 | } else { |
688 | 688 | $valid = true; |
689 | 689 | } |
690 | 690 | |
691 | - $message = $valid ? '' : __( 'VAT number not validated', 'invoicing' ); |
|
691 | + $message = $valid ? '' : __('VAT number not validated', 'invoicing'); |
|
692 | 692 | } else { |
693 | - $result = self::check_vat( $input['vat_number'] ); |
|
693 | + $result = self::check_vat($input['vat_number']); |
|
694 | 694 | |
695 | - if ( empty( $result['valid'] ) ) { |
|
695 | + if (empty($result['valid'])) { |
|
696 | 696 | $valid = false; |
697 | 697 | $message = $result['message']; |
698 | 698 | } else { |
699 | - $valid = ( isset( $result['company'] ) && ( $result['company'] == '---' || ( strcasecmp( trim( $result['company'] ), trim( $input['vat_company_name'] ) ) == 0 ) ) ) || !empty( $wpinv_options['vat_disable_company_name_check'] ); |
|
700 | - $message = $valid ? '' : __( 'The company name associated with the VAT number provided is not the same as the company name provided.', 'invoicing' ); |
|
699 | + $valid = (isset($result['company']) && ($result['company'] == '---' || (strcasecmp(trim($result['company']), trim($input['vat_company_name'])) == 0))) || !empty($wpinv_options['vat_disable_company_name_check']); |
|
700 | + $message = $valid ? '' : __('The company name associated with the VAT number provided is not the same as the company name provided.', 'invoicing'); |
|
701 | 701 | } |
702 | 702 | } |
703 | 703 | |
704 | - if ( $message && self::is_vat_validated() != $valid ) { |
|
705 | - add_settings_error( 'wpinv-notices', '', $message, ( $valid ? 'updated' : 'error' ) ); |
|
704 | + if ($message && self::is_vat_validated() != $valid) { |
|
705 | + add_settings_error('wpinv-notices', '', $message, ($valid ? 'updated' : 'error')); |
|
706 | 706 | } |
707 | 707 | |
708 | 708 | $input['vat_valid'] = $valid; |
709 | 709 | return $input; |
710 | 710 | } |
711 | 711 | |
712 | - public static function sanitize_vat_rates( $input ) { |
|
713 | - if( !current_user_can( 'manage_options' ) ) { |
|
714 | - add_settings_error( 'wpinv-notices', '', __( 'Your account does not have permission to add rate classes.', 'invoicing' ), 'error' ); |
|
712 | + public static function sanitize_vat_rates($input) { |
|
713 | + if (!current_user_can('manage_options')) { |
|
714 | + add_settings_error('wpinv-notices', '', __('Your account does not have permission to add rate classes.', 'invoicing'), 'error'); |
|
715 | 715 | return $input; |
716 | 716 | } |
717 | 717 | |
718 | 718 | $vat_classes = self::get_rate_classes(); |
719 | - $vat_class = !empty( $_REQUEST['wpi_vat_class'] ) && isset( $vat_classes[$_REQUEST['wpi_vat_class']] )? sanitize_text_field( $_REQUEST['wpi_vat_class'] ) : ''; |
|
719 | + $vat_class = !empty($_REQUEST['wpi_vat_class']) && isset($vat_classes[$_REQUEST['wpi_vat_class']]) ? sanitize_text_field($_REQUEST['wpi_vat_class']) : ''; |
|
720 | 720 | |
721 | - if ( empty( $vat_class ) ) { |
|
722 | - add_settings_error( 'wpinv-notices', '', __( 'No valid VAT rates class contained in the request to save rates.', 'invoicing' ), 'error' ); |
|
721 | + if (empty($vat_class)) { |
|
722 | + add_settings_error('wpinv-notices', '', __('No valid VAT rates class contained in the request to save rates.', 'invoicing'), 'error'); |
|
723 | 723 | |
724 | 724 | return $input; |
725 | 725 | } |
726 | 726 | |
727 | - $new_rates = ! empty( $_POST['vat_rates'] ) ? array_values( $_POST['vat_rates'] ) : array(); |
|
727 | + $new_rates = !empty($_POST['vat_rates']) ? array_values($_POST['vat_rates']) : array(); |
|
728 | 728 | |
729 | - if ( $vat_class === '_standard' ) { |
|
729 | + if ($vat_class === '_standard') { |
|
730 | 730 | // Save the active rates in the invoice settings |
731 | - update_option( 'wpinv_tax_rates', $new_rates ); |
|
731 | + update_option('wpinv_tax_rates', $new_rates); |
|
732 | 732 | } else { |
733 | 733 | // Get the existing set of rates |
734 | 734 | $rates = self::get_non_standard_rates(); |
735 | 735 | $rates[$vat_class] = $new_rates; |
736 | 736 | |
737 | - update_option( 'wpinv_vat_rates', $rates ); |
|
737 | + update_option('wpinv_vat_rates', $rates); |
|
738 | 738 | } |
739 | 739 | |
740 | 740 | return $input; |
@@ -744,71 +744,71 @@ discard block |
||
744 | 744 | $response = array(); |
745 | 745 | $response['success'] = false; |
746 | 746 | |
747 | - if ( !current_user_can( 'manage_options' ) ) { |
|
748 | - $response['error'] = __( 'Invalid access!', 'invoicing' ); |
|
749 | - wp_send_json( $response ); |
|
747 | + if (!current_user_can('manage_options')) { |
|
748 | + $response['error'] = __('Invalid access!', 'invoicing'); |
|
749 | + wp_send_json($response); |
|
750 | 750 | } |
751 | 751 | |
752 | - $vat_class_name = !empty( $_POST['name'] ) ? sanitize_text_field( $_POST['name'] ) : false; |
|
753 | - $vat_class_desc = !empty( $_POST['desc'] ) ? sanitize_text_field( $_POST['desc'] ) : false; |
|
752 | + $vat_class_name = !empty($_POST['name']) ? sanitize_text_field($_POST['name']) : false; |
|
753 | + $vat_class_desc = !empty($_POST['desc']) ? sanitize_text_field($_POST['desc']) : false; |
|
754 | 754 | |
755 | - if ( empty( $vat_class_name ) ) { |
|
756 | - $response['error'] = __( 'Select the VAT rate name', 'invoicing' ); |
|
757 | - wp_send_json( $response ); |
|
755 | + if (empty($vat_class_name)) { |
|
756 | + $response['error'] = __('Select the VAT rate name', 'invoicing'); |
|
757 | + wp_send_json($response); |
|
758 | 758 | } |
759 | 759 | |
760 | 760 | $vat_classes = (array)self::get_rate_classes(); |
761 | 761 | |
762 | - if ( !empty( $vat_classes ) && in_array( strtolower( $vat_class_name ), array_map( 'strtolower', array_values( $vat_classes ) ) ) ) { |
|
763 | - $response['error'] = wp_sprintf( __( 'A VAT Rate name "%s" already exists', 'invoicing' ), $vat_class_name ); |
|
764 | - wp_send_json( $response ); |
|
762 | + if (!empty($vat_classes) && in_array(strtolower($vat_class_name), array_map('strtolower', array_values($vat_classes)))) { |
|
763 | + $response['error'] = wp_sprintf(__('A VAT Rate name "%s" already exists', 'invoicing'), $vat_class_name); |
|
764 | + wp_send_json($response); |
|
765 | 765 | } |
766 | 766 | |
767 | - $rate_class_key = normalize_whitespace( 'wpi-' . $vat_class_name ); |
|
768 | - $rate_class_key = sanitize_key( str_replace( " ", "-", $rate_class_key ) ); |
|
767 | + $rate_class_key = normalize_whitespace('wpi-' . $vat_class_name); |
|
768 | + $rate_class_key = sanitize_key(str_replace(" ", "-", $rate_class_key)); |
|
769 | 769 | |
770 | - $vat_classes = (array)self::get_rate_classes( true ); |
|
771 | - $vat_classes[$rate_class_key] = array( 'name' => $vat_class_name, 'desc' => $vat_class_desc ); |
|
770 | + $vat_classes = (array)self::get_rate_classes(true); |
|
771 | + $vat_classes[$rate_class_key] = array('name' => $vat_class_name, 'desc' => $vat_class_desc); |
|
772 | 772 | |
773 | - update_option( '_wpinv_vat_rate_classes', $vat_classes ); |
|
773 | + update_option('_wpinv_vat_rate_classes', $vat_classes); |
|
774 | 774 | |
775 | 775 | $response['success'] = true; |
776 | - $response['redirect'] = admin_url( 'admin.php?page=wpinv-settings&tab=taxes§ion=vat_rates&wpi_sub=' . $rate_class_key ); |
|
776 | + $response['redirect'] = admin_url('admin.php?page=wpinv-settings&tab=taxes§ion=vat_rates&wpi_sub=' . $rate_class_key); |
|
777 | 777 | |
778 | - wp_send_json( $response ); |
|
778 | + wp_send_json($response); |
|
779 | 779 | } |
780 | 780 | |
781 | 781 | public static function delete_class() { |
782 | 782 | $response = array(); |
783 | 783 | $response['success'] = false; |
784 | 784 | |
785 | - if ( !current_user_can( 'manage_options' ) || !isset( $_POST['class'] ) ) { |
|
786 | - $response['error'] = __( 'Invalid access!', 'invoicing' ); |
|
787 | - wp_send_json( $response ); |
|
785 | + if (!current_user_can('manage_options') || !isset($_POST['class'])) { |
|
786 | + $response['error'] = __('Invalid access!', 'invoicing'); |
|
787 | + wp_send_json($response); |
|
788 | 788 | } |
789 | 789 | |
790 | - $vat_class = isset( $_POST['class'] ) && $_POST['class'] !== '' ? sanitize_text_field( $_POST['class'] ) : false; |
|
790 | + $vat_class = isset($_POST['class']) && $_POST['class'] !== '' ? sanitize_text_field($_POST['class']) : false; |
|
791 | 791 | $vat_classes = (array)self::get_rate_classes(); |
792 | 792 | |
793 | - if ( !isset( $vat_classes[$vat_class] ) ) { |
|
794 | - $response['error'] = __( 'Requested class does not exists', 'invoicing' ); |
|
795 | - wp_send_json( $response ); |
|
793 | + if (!isset($vat_classes[$vat_class])) { |
|
794 | + $response['error'] = __('Requested class does not exists', 'invoicing'); |
|
795 | + wp_send_json($response); |
|
796 | 796 | } |
797 | 797 | |
798 | - if ( $vat_class == '_new' || $vat_class == '_standard' ) { |
|
799 | - $response['error'] = __( 'You can not delete standard rates class', 'invoicing' ); |
|
800 | - wp_send_json( $response ); |
|
798 | + if ($vat_class == '_new' || $vat_class == '_standard') { |
|
799 | + $response['error'] = __('You can not delete standard rates class', 'invoicing'); |
|
800 | + wp_send_json($response); |
|
801 | 801 | } |
802 | 802 | |
803 | - $vat_classes = (array)self::get_rate_classes( true ); |
|
804 | - unset( $vat_classes[$vat_class] ); |
|
803 | + $vat_classes = (array)self::get_rate_classes(true); |
|
804 | + unset($vat_classes[$vat_class]); |
|
805 | 805 | |
806 | - update_option( '_wpinv_vat_rate_classes', $vat_classes ); |
|
806 | + update_option('_wpinv_vat_rate_classes', $vat_classes); |
|
807 | 807 | |
808 | 808 | $response['success'] = true; |
809 | - $response['redirect'] = admin_url( 'admin.php?page=wpinv-settings&tab=taxes§ion=vat_rates&wpi_sub=_new' ); |
|
809 | + $response['redirect'] = admin_url('admin.php?page=wpinv-settings&tab=taxes§ion=vat_rates&wpi_sub=_new'); |
|
810 | 810 | |
811 | - wp_send_json( $response ); |
|
811 | + wp_send_json($response); |
|
812 | 812 | } |
813 | 813 | |
814 | 814 | public static function update_eu_rates() { |
@@ -817,72 +817,72 @@ discard block |
||
817 | 817 | $response['error'] = null; |
818 | 818 | $response['data'] = null; |
819 | 819 | |
820 | - if ( !current_user_can( 'manage_options' ) ) { |
|
821 | - $response['error'] = __( 'Invalid access!', 'invoicing' ); |
|
822 | - wp_send_json( $response ); |
|
820 | + if (!current_user_can('manage_options')) { |
|
821 | + $response['error'] = __('Invalid access!', 'invoicing'); |
|
822 | + wp_send_json($response); |
|
823 | 823 | } |
824 | 824 | |
825 | - $group = !empty( $_POST['group'] ) ? sanitize_text_field( $_POST['group'] ) : ''; |
|
826 | - $euvatrates = self::request_euvatrates( $group ); |
|
825 | + $group = !empty($_POST['group']) ? sanitize_text_field($_POST['group']) : ''; |
|
826 | + $euvatrates = self::request_euvatrates($group); |
|
827 | 827 | |
828 | - if ( !empty( $euvatrates ) ) { |
|
829 | - if ( !empty( $euvatrates['success'] ) && !empty( $euvatrates['rates'] ) ) { |
|
828 | + if (!empty($euvatrates)) { |
|
829 | + if (!empty($euvatrates['success']) && !empty($euvatrates['rates'])) { |
|
830 | 830 | $response['success'] = true; |
831 | 831 | $response['data']['rates'] = $euvatrates['rates']; |
832 | - } else if ( !empty( $euvatrates['error'] ) ) { |
|
832 | + } else if (!empty($euvatrates['error'])) { |
|
833 | 833 | $response['error'] = $euvatrates['error']; |
834 | 834 | } |
835 | 835 | } |
836 | 836 | |
837 | - wp_send_json( $response ); |
|
837 | + wp_send_json($response); |
|
838 | 838 | } |
839 | 839 | |
840 | 840 | public static function hide_vat_fields() { |
841 | - $hide = wpinv_get_option( 'vat_disable_fields' ); |
|
841 | + $hide = wpinv_get_option('vat_disable_fields'); |
|
842 | 842 | |
843 | - return apply_filters( 'wpinv_hide_vat_fields', $hide ); |
|
843 | + return apply_filters('wpinv_hide_vat_fields', $hide); |
|
844 | 844 | } |
845 | 845 | |
846 | 846 | public static function same_country_rule() { |
847 | - $same_country_rule = wpinv_get_option( 'vat_same_country_rule' ); |
|
847 | + $same_country_rule = wpinv_get_option('vat_same_country_rule'); |
|
848 | 848 | |
849 | - return apply_filters( 'wpinv_vat_same_country_rule', $same_country_rule ); |
|
849 | + return apply_filters('wpinv_vat_same_country_rule', $same_country_rule); |
|
850 | 850 | } |
851 | 851 | |
852 | 852 | public static function get_vat_name() { |
853 | - $vat_name = wpinv_get_option( 'vat_name' ); |
|
854 | - $vat_name = !empty( $vat_name ) ? $vat_name : 'VAT'; |
|
853 | + $vat_name = wpinv_get_option('vat_name'); |
|
854 | + $vat_name = !empty($vat_name) ? $vat_name : 'VAT'; |
|
855 | 855 | |
856 | - return apply_filters( 'wpinv_get_owner_vat_name', $vat_name ); |
|
856 | + return apply_filters('wpinv_get_owner_vat_name', $vat_name); |
|
857 | 857 | } |
858 | 858 | |
859 | 859 | public static function get_company_name() { |
860 | - $company_name = wpinv_get_option( 'vat_company_name' ); |
|
860 | + $company_name = wpinv_get_option('vat_company_name'); |
|
861 | 861 | |
862 | - return apply_filters( 'wpinv_get_owner_company_name', $company_name ); |
|
862 | + return apply_filters('wpinv_get_owner_company_name', $company_name); |
|
863 | 863 | } |
864 | 864 | |
865 | 865 | public static function get_vat_number() { |
866 | - $vat_number = wpinv_get_option( 'vat_number' ); |
|
866 | + $vat_number = wpinv_get_option('vat_number'); |
|
867 | 867 | |
868 | - return apply_filters( 'wpinv_get_owner_vat_number', $vat_number ); |
|
868 | + return apply_filters('wpinv_get_owner_vat_number', $vat_number); |
|
869 | 869 | } |
870 | 870 | |
871 | 871 | public static function is_vat_validated() { |
872 | - $validated = self::get_vat_number() && wpinv_get_option( 'vat_valid' ); |
|
872 | + $validated = self::get_vat_number() && wpinv_get_option('vat_valid'); |
|
873 | 873 | |
874 | - return apply_filters( 'wpinv_is_owner_vat_validated', $validated ); |
|
874 | + return apply_filters('wpinv_is_owner_vat_validated', $validated); |
|
875 | 875 | } |
876 | 876 | |
877 | - public static function sanitize_vat( $vat_number, $country_code = '' ) { |
|
878 | - $vat_number = str_replace( array(' ', '.', '-', '_', ',' ), '', strtoupper( trim( $vat_number ) ) ); |
|
877 | + public static function sanitize_vat($vat_number, $country_code = '') { |
|
878 | + $vat_number = str_replace(array(' ', '.', '-', '_', ','), '', strtoupper(trim($vat_number))); |
|
879 | 879 | |
880 | - if ( empty( $country_code ) ) { |
|
881 | - $country_code = substr( $vat_number, 0, 2 ); |
|
880 | + if (empty($country_code)) { |
|
881 | + $country_code = substr($vat_number, 0, 2); |
|
882 | 882 | } |
883 | 883 | |
884 | - if ( strpos( $vat_number , $country_code ) === 0 ) { |
|
885 | - $vat = str_replace( $country_code, '', $vat_number ); |
|
884 | + if (strpos($vat_number, $country_code) === 0) { |
|
885 | + $vat = str_replace($country_code, '', $vat_number); |
|
886 | 886 | } else { |
887 | 887 | $vat = $country_code . $vat_number; |
888 | 888 | } |
@@ -895,140 +895,140 @@ discard block |
||
895 | 895 | return $return; |
896 | 896 | } |
897 | 897 | |
898 | - public static function offline_check( $vat_number, $country_code = '', $formatted = false ) { |
|
899 | - $vat = self::sanitize_vat( $vat_number, $country_code ); |
|
898 | + public static function offline_check($vat_number, $country_code = '', $formatted = false) { |
|
899 | + $vat = self::sanitize_vat($vat_number, $country_code); |
|
900 | 900 | $vat_number = $vat['vat_number']; |
901 | 901 | $country_code = $vat['iso']; |
902 | 902 | $regex = array(); |
903 | 903 | |
904 | - switch ( $country_code ) { |
|
904 | + switch ($country_code) { |
|
905 | 905 | case 'AT': |
906 | - $regex[] = '/^(AT)U(\d{8})$/'; // Austria |
|
906 | + $regex[] = '/^(AT)U(\d{8})$/'; // Austria |
|
907 | 907 | break; |
908 | 908 | case 'BE': |
909 | - $regex[] = '/^(BE)(0?\d{9})$/'; // Belgium |
|
909 | + $regex[] = '/^(BE)(0?\d{9})$/'; // Belgium |
|
910 | 910 | break; |
911 | 911 | case 'BG': |
912 | - $regex[] = '/^(BG)(\d{9,10})$/'; // Bulgaria |
|
912 | + $regex[] = '/^(BG)(\d{9,10})$/'; // Bulgaria |
|
913 | 913 | break; |
914 | 914 | case 'CH': |
915 | 915 | case 'CHE': |
916 | - $regex[] = '/^(CHE)(\d{9})MWST$/'; // Switzerland (Not EU) |
|
916 | + $regex[] = '/^(CHE)(\d{9})MWST$/'; // Switzerland (Not EU) |
|
917 | 917 | break; |
918 | 918 | case 'CY': |
919 | - $regex[] = '/^(CY)([0-5|9]\d{7}[A-Z])$/'; // Cyprus |
|
919 | + $regex[] = '/^(CY)([0-5|9]\d{7}[A-Z])$/'; // Cyprus |
|
920 | 920 | break; |
921 | 921 | case 'CZ': |
922 | - $regex[] = '/^(CZ)(\d{8,13})$/'; // Czech Republic |
|
922 | + $regex[] = '/^(CZ)(\d{8,13})$/'; // Czech Republic |
|
923 | 923 | break; |
924 | 924 | case 'DE': |
925 | - $regex[] = '/^(DE)([1-9]\d{8})$/'; // Germany |
|
925 | + $regex[] = '/^(DE)([1-9]\d{8})$/'; // Germany |
|
926 | 926 | break; |
927 | 927 | case 'DK': |
928 | - $regex[] = '/^(DK)(\d{8})$/'; // Denmark |
|
928 | + $regex[] = '/^(DK)(\d{8})$/'; // Denmark |
|
929 | 929 | break; |
930 | 930 | case 'EE': |
931 | - $regex[] = '/^(EE)(10\d{7})$/'; // Estonia |
|
931 | + $regex[] = '/^(EE)(10\d{7})$/'; // Estonia |
|
932 | 932 | break; |
933 | 933 | case 'EL': |
934 | - $regex[] = '/^(EL)(\d{9})$/'; // Greece |
|
934 | + $regex[] = '/^(EL)(\d{9})$/'; // Greece |
|
935 | 935 | break; |
936 | 936 | case 'ES': |
937 | - $regex[] = '/^(ES)([A-Z]\d{8})$/'; // Spain (National juridical entities) |
|
938 | - $regex[] = '/^(ES)([A-H|N-S|W]\d{7}[A-J])$/'; // Spain (Other juridical entities) |
|
939 | - $regex[] = '/^(ES)([0-9|Y|Z]\d{7}[A-Z])$/'; // Spain (Personal entities type 1) |
|
940 | - $regex[] = '/^(ES)([K|L|M|X]\d{7}[A-Z])$/'; // Spain (Personal entities type 2) |
|
937 | + $regex[] = '/^(ES)([A-Z]\d{8})$/'; // Spain (National juridical entities) |
|
938 | + $regex[] = '/^(ES)([A-H|N-S|W]\d{7}[A-J])$/'; // Spain (Other juridical entities) |
|
939 | + $regex[] = '/^(ES)([0-9|Y|Z]\d{7}[A-Z])$/'; // Spain (Personal entities type 1) |
|
940 | + $regex[] = '/^(ES)([K|L|M|X]\d{7}[A-Z])$/'; // Spain (Personal entities type 2) |
|
941 | 941 | break; |
942 | 942 | case 'EU': |
943 | - $regex[] = '/^(EU)(\d{9})$/'; // EU-type |
|
943 | + $regex[] = '/^(EU)(\d{9})$/'; // EU-type |
|
944 | 944 | break; |
945 | 945 | case 'FI': |
946 | - $regex[] = '/^(FI)(\d{8})$/'; // Finland |
|
946 | + $regex[] = '/^(FI)(\d{8})$/'; // Finland |
|
947 | 947 | break; |
948 | 948 | case 'FR': |
949 | - $regex[] = '/^(FR)(\d{11})$/'; // France (1) |
|
950 | - $regex[] = '/^(FR)[(A-H)|(J-N)|(P-Z)](\d{10})$/'; // France (2) |
|
951 | - $regex[] = '/^(FR)\d[(A-H)|(J-N)|(P-Z)](\d{9})$/'; // France (3) |
|
952 | - $regex[] = '/^(FR)[(A-H)|(J-N)|(P-Z)]{2}(\d{9})$/'; // France (4) |
|
949 | + $regex[] = '/^(FR)(\d{11})$/'; // France (1) |
|
950 | + $regex[] = '/^(FR)[(A-H)|(J-N)|(P-Z)](\d{10})$/'; // France (2) |
|
951 | + $regex[] = '/^(FR)\d[(A-H)|(J-N)|(P-Z)](\d{9})$/'; // France (3) |
|
952 | + $regex[] = '/^(FR)[(A-H)|(J-N)|(P-Z)]{2}(\d{9})$/'; // France (4) |
|
953 | 953 | break; |
954 | 954 | case 'GB': |
955 | - $regex[] = '/^(GB)?(\d{9})$/'; // UK (Standard) |
|
956 | - $regex[] = '/^(GB)?(\d{12})$/'; // UK (Branches) |
|
957 | - $regex[] = '/^(GB)?(GD\d{3})$/'; // UK (Government) |
|
958 | - $regex[] = '/^(GB)?(HA\d{3})$/'; // UK (Health authority) |
|
955 | + $regex[] = '/^(GB)?(\d{9})$/'; // UK (Standard) |
|
956 | + $regex[] = '/^(GB)?(\d{12})$/'; // UK (Branches) |
|
957 | + $regex[] = '/^(GB)?(GD\d{3})$/'; // UK (Government) |
|
958 | + $regex[] = '/^(GB)?(HA\d{3})$/'; // UK (Health authority) |
|
959 | 959 | break; |
960 | 960 | case 'GR': |
961 | - $regex[] = '/^(GR)(\d{8,9})$/'; // Greece |
|
961 | + $regex[] = '/^(GR)(\d{8,9})$/'; // Greece |
|
962 | 962 | break; |
963 | 963 | case 'HR': |
964 | - $regex[] = '/^(HR)(\d{11})$/'; // Croatia |
|
964 | + $regex[] = '/^(HR)(\d{11})$/'; // Croatia |
|
965 | 965 | break; |
966 | 966 | case 'HU': |
967 | - $regex[] = '/^(HU)(\d{8})$/'; // Hungary |
|
967 | + $regex[] = '/^(HU)(\d{8})$/'; // Hungary |
|
968 | 968 | break; |
969 | 969 | case 'IE': |
970 | - $regex[] = '/^(IE)(\d{7}[A-W])$/'; // Ireland (1) |
|
971 | - $regex[] = '/^(IE)([7-9][A-Z\*\+)]\d{5}[A-W])$/'; // Ireland (2) |
|
972 | - $regex[] = '/^(IE)(\d{7}[A-Z][AH])$/'; // Ireland (3) (new format from 1 Jan 2013) |
|
970 | + $regex[] = '/^(IE)(\d{7}[A-W])$/'; // Ireland (1) |
|
971 | + $regex[] = '/^(IE)([7-9][A-Z\*\+)]\d{5}[A-W])$/'; // Ireland (2) |
|
972 | + $regex[] = '/^(IE)(\d{7}[A-Z][AH])$/'; // Ireland (3) (new format from 1 Jan 2013) |
|
973 | 973 | break; |
974 | 974 | case 'IT': |
975 | - $regex[] = '/^(IT)(\d{11})$/'; // Italy |
|
975 | + $regex[] = '/^(IT)(\d{11})$/'; // Italy |
|
976 | 976 | break; |
977 | 977 | case 'LV': |
978 | - $regex[] = '/^(LV)(\d{11})$/'; // Latvia |
|
978 | + $regex[] = '/^(LV)(\d{11})$/'; // Latvia |
|
979 | 979 | break; |
980 | 980 | case 'LT': |
981 | - $regex[] = '/^(LT)(\d{9}|\d{12})$/'; // Lithuania |
|
981 | + $regex[] = '/^(LT)(\d{9}|\d{12})$/'; // Lithuania |
|
982 | 982 | break; |
983 | 983 | case 'LU': |
984 | - $regex[] = '/^(LU)(\d{8})$/'; // Luxembourg |
|
984 | + $regex[] = '/^(LU)(\d{8})$/'; // Luxembourg |
|
985 | 985 | break; |
986 | 986 | case 'MT': |
987 | - $regex[] = '/^(MT)([1-9]\d{7})$/'; // Malta |
|
987 | + $regex[] = '/^(MT)([1-9]\d{7})$/'; // Malta |
|
988 | 988 | break; |
989 | 989 | case 'NL': |
990 | - $regex[] = '/^(NL)(\d{9})B\d{2}$/'; // Netherlands |
|
990 | + $regex[] = '/^(NL)(\d{9})B\d{2}$/'; // Netherlands |
|
991 | 991 | break; |
992 | 992 | case 'NO': |
993 | - $regex[] = '/^(NO)(\d{9})$/'; // Norway (Not EU) |
|
993 | + $regex[] = '/^(NO)(\d{9})$/'; // Norway (Not EU) |
|
994 | 994 | break; |
995 | 995 | case 'PL': |
996 | - $regex[] = '/^(PL)(\d{10})$/'; // Poland |
|
996 | + $regex[] = '/^(PL)(\d{10})$/'; // Poland |
|
997 | 997 | break; |
998 | 998 | case 'PT': |
999 | - $regex[] = '/^(PT)(\d{9})$/'; // Portugal |
|
999 | + $regex[] = '/^(PT)(\d{9})$/'; // Portugal |
|
1000 | 1000 | break; |
1001 | 1001 | case 'RO': |
1002 | - $regex[] = '/^(RO)([1-9]\d{1,9})$/'; // Romania |
|
1002 | + $regex[] = '/^(RO)([1-9]\d{1,9})$/'; // Romania |
|
1003 | 1003 | break; |
1004 | 1004 | case 'RS': |
1005 | - $regex[] = '/^(RS)(\d{9})$/'; // Serbia (Not EU) |
|
1005 | + $regex[] = '/^(RS)(\d{9})$/'; // Serbia (Not EU) |
|
1006 | 1006 | break; |
1007 | 1007 | case 'SI': |
1008 | - $regex[] = '/^(SI)([1-9]\d{7})$/'; // Slovenia |
|
1008 | + $regex[] = '/^(SI)([1-9]\d{7})$/'; // Slovenia |
|
1009 | 1009 | break; |
1010 | 1010 | case 'SK': |
1011 | - $regex[] = '/^(SK)([1-9]\d[(2-4)|(6-9)]\d{7})$/'; // Slovakia Republic |
|
1011 | + $regex[] = '/^(SK)([1-9]\d[(2-4)|(6-9)]\d{7})$/'; // Slovakia Republic |
|
1012 | 1012 | break; |
1013 | 1013 | case 'SE': |
1014 | - $regex[] = '/^(SE)(\d{10}01)$/'; // Sweden |
|
1014 | + $regex[] = '/^(SE)(\d{10}01)$/'; // Sweden |
|
1015 | 1015 | break; |
1016 | 1016 | default: |
1017 | 1017 | $regex = array(); |
1018 | 1018 | break; |
1019 | 1019 | } |
1020 | 1020 | |
1021 | - if ( empty( $regex ) ) { |
|
1021 | + if (empty($regex)) { |
|
1022 | 1022 | return false; |
1023 | 1023 | } |
1024 | 1024 | |
1025 | - foreach ( $regex as $pattern ) { |
|
1025 | + foreach ($regex as $pattern) { |
|
1026 | 1026 | $matches = null; |
1027 | - preg_match_all( $pattern, $vat_number, $matches ); |
|
1027 | + preg_match_all($pattern, $vat_number, $matches); |
|
1028 | 1028 | |
1029 | - if ( !empty( $matches[1][0] ) && !empty( $matches[2][0] ) ) { |
|
1030 | - if ( $formatted ) { |
|
1031 | - return array( 'code' => $matches[1][0], 'number' => $matches[2][0] ); |
|
1029 | + if (!empty($matches[1][0]) && !empty($matches[2][0])) { |
|
1030 | + if ($formatted) { |
|
1031 | + return array('code' => $matches[1][0], 'number' => $matches[2][0]); |
|
1032 | 1032 | } else { |
1033 | 1033 | return true; |
1034 | 1034 | } |
@@ -1038,75 +1038,75 @@ discard block |
||
1038 | 1038 | return false; |
1039 | 1039 | } |
1040 | 1040 | |
1041 | - public static function vies_check( $vat_number, $country_code = '', $result = false ) { |
|
1042 | - $vat = self::sanitize_vat( $vat_number, $country_code ); |
|
1041 | + public static function vies_check($vat_number, $country_code = '', $result = false) { |
|
1042 | + $vat = self::sanitize_vat($vat_number, $country_code); |
|
1043 | 1043 | $vat_number = $vat['vat']; |
1044 | 1044 | $iso = $vat['iso']; |
1045 | 1045 | |
1046 | - $url = 'http://ec.europa.eu/taxation_customs/vies/viesquer.do?ms=' . urlencode( $iso ) . '&iso=' . urlencode( $iso ) . '&vat=' . urlencode( $vat_number ); |
|
1046 | + $url = 'http://ec.europa.eu/taxation_customs/vies/viesquer.do?ms=' . urlencode($iso) . '&iso=' . urlencode($iso) . '&vat=' . urlencode($vat_number); |
|
1047 | 1047 | |
1048 | - if ( ini_get( 'allow_url_fopen' ) ) { |
|
1049 | - $response = file_get_contents( $url ); |
|
1050 | - } else if ( function_exists( 'curl_init' ) ) { |
|
1048 | + if (ini_get('allow_url_fopen')) { |
|
1049 | + $response = file_get_contents($url); |
|
1050 | + } else if (function_exists('curl_init')) { |
|
1051 | 1051 | $ch = curl_init(); |
1052 | 1052 | |
1053 | - curl_setopt( $ch, CURLOPT_URL, $url ); |
|
1054 | - curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT, 30 ); |
|
1055 | - curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true ); |
|
1056 | - curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, 0 ); |
|
1057 | - curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, 0 ); |
|
1053 | + curl_setopt($ch, CURLOPT_URL, $url); |
|
1054 | + curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30); |
|
1055 | + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
|
1056 | + curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); |
|
1057 | + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); |
|
1058 | 1058 | |
1059 | - $response = curl_exec( $ch ); |
|
1059 | + $response = curl_exec($ch); |
|
1060 | 1060 | |
1061 | - if ( curl_errno( $ch ) ) { |
|
1062 | - wpinv_error_log( curl_error( $ch ), 'VIES CHECK ERROR' ); |
|
1061 | + if (curl_errno($ch)) { |
|
1062 | + wpinv_error_log(curl_error($ch), 'VIES CHECK ERROR'); |
|
1063 | 1063 | $response = ''; |
1064 | 1064 | } |
1065 | 1065 | |
1066 | - curl_close( $ch ); |
|
1066 | + curl_close($ch); |
|
1067 | 1067 | } else { |
1068 | - wpinv_error_log( 'To use VIES CHECK you must have allow_url_fopen is ON or cURL installed & active on your server.', 'VIES CHECK ERROR' ); |
|
1068 | + wpinv_error_log('To use VIES CHECK you must have allow_url_fopen is ON or cURL installed & active on your server.', 'VIES CHECK ERROR'); |
|
1069 | 1069 | } |
1070 | 1070 | |
1071 | - if ( empty( $response ) ) { |
|
1071 | + if (empty($response)) { |
|
1072 | 1072 | return $result; |
1073 | 1073 | } |
1074 | 1074 | |
1075 | - if ( preg_match( '/invalid VAT number/i', $response ) ) { |
|
1075 | + if (preg_match('/invalid VAT number/i', $response)) { |
|
1076 | 1076 | return false; |
1077 | - } else if ( preg_match( '/valid VAT number/i', $response, $matches ) ) { |
|
1078 | - $content = explode( "valid VAT number", htmlentities( $response ) ); |
|
1077 | + } else if (preg_match('/valid VAT number/i', $response, $matches)) { |
|
1078 | + $content = explode("valid VAT number", htmlentities($response)); |
|
1079 | 1079 | |
1080 | - if ( !empty( $content[1] ) ) { |
|
1081 | - preg_match_all( '/<tr>(.*?)<td.*?>(.*?)<\/td>(.*?)<\/tr>/si', html_entity_decode( $content[1] ), $matches ); |
|
1080 | + if (!empty($content[1])) { |
|
1081 | + preg_match_all('/<tr>(.*?)<td.*?>(.*?)<\/td>(.*?)<\/tr>/si', html_entity_decode($content[1]), $matches); |
|
1082 | 1082 | |
1083 | - if ( !empty( $matches[2] ) && $matches[3] ) { |
|
1083 | + if (!empty($matches[2]) && $matches[3]) { |
|
1084 | 1084 | $return = array(); |
1085 | 1085 | |
1086 | - foreach ( $matches[2] as $key => $label ) { |
|
1087 | - $label = trim( $label ); |
|
1086 | + foreach ($matches[2] as $key => $label) { |
|
1087 | + $label = trim($label); |
|
1088 | 1088 | |
1089 | - switch ( strtolower( $label ) ) { |
|
1089 | + switch (strtolower($label)) { |
|
1090 | 1090 | case 'member state': |
1091 | - $return['state'] = trim( strip_tags( $matches[3][$key] ) ); |
|
1091 | + $return['state'] = trim(strip_tags($matches[3][$key])); |
|
1092 | 1092 | break; |
1093 | 1093 | case 'vat number': |
1094 | - $return['number'] = trim( strip_tags( $matches[3][$key] ) ); |
|
1094 | + $return['number'] = trim(strip_tags($matches[3][$key])); |
|
1095 | 1095 | break; |
1096 | 1096 | case 'name': |
1097 | - $return['company'] = trim( strip_tags( $matches[3][$key] ) ); |
|
1097 | + $return['company'] = trim(strip_tags($matches[3][$key])); |
|
1098 | 1098 | break; |
1099 | 1099 | case 'address': |
1100 | - $address = str_replace( array( "<br><br>", "<br /><br />", "<br/><br/>" ), "<br>", html_entity_decode( trim( $matches[3][$key] ) ) ); |
|
1101 | - $return['address'] = trim( strip_tags( $address, '<br>' ) ); |
|
1100 | + $address = str_replace(array("<br><br>", "<br /><br />", "<br/><br/>"), "<br>", html_entity_decode(trim($matches[3][$key]))); |
|
1101 | + $return['address'] = trim(strip_tags($address, '<br>')); |
|
1102 | 1102 | break; |
1103 | 1103 | case 'consultation number': |
1104 | - $return['consultation'] = trim( strip_tags( $matches[3][$key] ) ); |
|
1104 | + $return['consultation'] = trim(strip_tags($matches[3][$key])); |
|
1105 | 1105 | break; |
1106 | 1106 | } |
1107 | 1107 | } |
1108 | 1108 | |
1109 | - if ( !empty( $return ) ) { |
|
1109 | + if (!empty($return)) { |
|
1110 | 1110 | return $return; |
1111 | 1111 | } |
1112 | 1112 | } |
@@ -1118,55 +1118,55 @@ discard block |
||
1118 | 1118 | } |
1119 | 1119 | } |
1120 | 1120 | |
1121 | - public static function check_vat( $vat_number, $country_code = '' ) { |
|
1121 | + public static function check_vat($vat_number, $country_code = '') { |
|
1122 | 1122 | $vat_name = self::get_vat_name(); |
1123 | 1123 | |
1124 | 1124 | $return = array(); |
1125 | 1125 | $return['valid'] = false; |
1126 | - $return['message'] = wp_sprintf( __( '%s number not validated', 'invoicing' ), $vat_name ); |
|
1126 | + $return['message'] = wp_sprintf(__('%s number not validated', 'invoicing'), $vat_name); |
|
1127 | 1127 | |
1128 | - if ( !wpinv_get_option( 'vat_offline_check' ) && !self::offline_check( $vat_number, $country_code ) ) { |
|
1128 | + if (!wpinv_get_option('vat_offline_check') && !self::offline_check($vat_number, $country_code)) { |
|
1129 | 1129 | return $return; |
1130 | 1130 | } |
1131 | 1131 | |
1132 | - $response = self::vies_check( $vat_number, $country_code ); |
|
1132 | + $response = self::vies_check($vat_number, $country_code); |
|
1133 | 1133 | |
1134 | - if ( $response ) { |
|
1135 | - $return['valid'] = true; |
|
1134 | + if ($response) { |
|
1135 | + $return['valid'] = true; |
|
1136 | 1136 | |
1137 | - if ( is_array( $response ) ) { |
|
1138 | - $return['company'] = isset( $response['company'] ) ? $response['company'] : ''; |
|
1139 | - $return['address'] = isset( $response['address'] ) ? $response['address'] : ''; |
|
1137 | + if (is_array($response)) { |
|
1138 | + $return['company'] = isset($response['company']) ? $response['company'] : ''; |
|
1139 | + $return['address'] = isset($response['address']) ? $response['address'] : ''; |
|
1140 | 1140 | $return['message'] = $return['company'] . '<br/>' . $return['address']; |
1141 | 1141 | } |
1142 | 1142 | } else { |
1143 | 1143 | $return['valid'] = false; |
1144 | - $return['message'] = wp_sprintf( __( 'Fail to validate the %s number: EU Commission VAT server (VIES) check fails.', 'invoicing' ), $vat_name ); |
|
1144 | + $return['message'] = wp_sprintf(__('Fail to validate the %s number: EU Commission VAT server (VIES) check fails.', 'invoicing'), $vat_name); |
|
1145 | 1145 | } |
1146 | 1146 | |
1147 | 1147 | return $return; |
1148 | 1148 | } |
1149 | 1149 | |
1150 | - public static function request_euvatrates( $group ) { |
|
1150 | + public static function request_euvatrates($group) { |
|
1151 | 1151 | $response = array(); |
1152 | 1152 | $response['success'] = false; |
1153 | 1153 | $response['error'] = null; |
1154 | 1154 | $response['eurates'] = null; |
1155 | 1155 | |
1156 | 1156 | $euvatrates_url = 'https://euvatrates.com/rates.json'; |
1157 | - $euvatrates_url = apply_filters( 'wpinv_euvatrates_url', $euvatrates_url ); |
|
1158 | - $api_response = wp_remote_get( $euvatrates_url ); |
|
1157 | + $euvatrates_url = apply_filters('wpinv_euvatrates_url', $euvatrates_url); |
|
1158 | + $api_response = wp_remote_get($euvatrates_url); |
|
1159 | 1159 | |
1160 | 1160 | try { |
1161 | - if ( is_wp_error( $api_response ) ) { |
|
1162 | - $response['error'] = __( $api_response->get_error_message(), 'invoicing' ); |
|
1161 | + if (is_wp_error($api_response)) { |
|
1162 | + $response['error'] = __($api_response->get_error_message(), 'invoicing'); |
|
1163 | 1163 | } else { |
1164 | - $body = json_decode( $api_response['body'] ); |
|
1164 | + $body = json_decode($api_response['body']); |
|
1165 | 1165 | |
1166 | - if ( isset( $body->rates ) ) { |
|
1166 | + if (isset($body->rates)) { |
|
1167 | 1167 | $rates = array(); |
1168 | 1168 | |
1169 | - foreach ( $body->rates as $country_code => $rate ) { |
|
1169 | + foreach ($body->rates as $country_code => $rate) { |
|
1170 | 1170 | $vat_rate = array(); |
1171 | 1171 | $vat_rate['country'] = $rate->country; |
1172 | 1172 | $vat_rate['standard'] = (float)$rate->standard_rate; |
@@ -1174,7 +1174,7 @@ discard block |
||
1174 | 1174 | $vat_rate['superreduced'] = (float)$rate->super_reduced_rate; |
1175 | 1175 | $vat_rate['parking'] = (float)$rate->parking_rate; |
1176 | 1176 | |
1177 | - if ( $group !== '' && in_array( $group, array( 'standard', 'reduced', 'superreduced', 'parking' ) ) ) { |
|
1177 | + if ($group !== '' && in_array($group, array('standard', 'reduced', 'superreduced', 'parking'))) { |
|
1178 | 1178 | $vat_rate_group = array(); |
1179 | 1179 | $vat_rate_group['country'] = $rate->country; |
1180 | 1180 | $vat_rate_group[$group] = $vat_rate[$group]; |
@@ -1186,79 +1186,79 @@ discard block |
||
1186 | 1186 | } |
1187 | 1187 | |
1188 | 1188 | $response['success'] = true; |
1189 | - $response['rates'] = apply_filters( 'wpinv_process_euvatrates', $rates, $api_response, $group ); |
|
1189 | + $response['rates'] = apply_filters('wpinv_process_euvatrates', $rates, $api_response, $group); |
|
1190 | 1190 | } else { |
1191 | - $response['error'] = __( 'No EU rates found!', 'invoicing' ); |
|
1191 | + $response['error'] = __('No EU rates found!', 'invoicing'); |
|
1192 | 1192 | } |
1193 | 1193 | } |
1194 | - } catch ( Exception $e ) { |
|
1195 | - $response['error'] = __( $e->getMessage(), 'invoicing' ); |
|
1194 | + } catch (Exception $e) { |
|
1195 | + $response['error'] = __($e->getMessage(), 'invoicing'); |
|
1196 | 1196 | } |
1197 | 1197 | |
1198 | - return apply_filters( 'wpinv_response_euvatrates', $response, $group ); |
|
1198 | + return apply_filters('wpinv_response_euvatrates', $response, $group); |
|
1199 | 1199 | } |
1200 | 1200 | |
1201 | - public static function requires_vat( $requires_vat = false, $user_id = 0, $is_digital = null ) { |
|
1201 | + public static function requires_vat($requires_vat = false, $user_id = 0, $is_digital = null) { |
|
1202 | 1202 | global $wpi_item_id, $wpi_country; |
1203 | 1203 | |
1204 | - if ( !empty( $_POST['wpinv_country'] ) ) { |
|
1205 | - $country_code = trim( $_POST['wpinv_country'] ); |
|
1206 | - } else if ( !empty( $_POST['country'] ) ) { |
|
1207 | - $country_code = trim( $_POST['country'] ); |
|
1208 | - } else if ( !empty( $wpi_country ) ) { |
|
1204 | + if (!empty($_POST['wpinv_country'])) { |
|
1205 | + $country_code = trim($_POST['wpinv_country']); |
|
1206 | + } else if (!empty($_POST['country'])) { |
|
1207 | + $country_code = trim($_POST['country']); |
|
1208 | + } else if (!empty($wpi_country)) { |
|
1209 | 1209 | $country_code = $wpi_country; |
1210 | 1210 | } else { |
1211 | - $country_code = self::get_user_country( '', $user_id ); |
|
1211 | + $country_code = self::get_user_country('', $user_id); |
|
1212 | 1212 | } |
1213 | 1213 | |
1214 | - if ( $is_digital === null && $wpi_item_id ) { |
|
1215 | - $is_digital = $wpi_item_id ? self::item_has_digital_rule( $wpi_item_id ) : self::allow_vat_rules(); |
|
1214 | + if ($is_digital === null && $wpi_item_id) { |
|
1215 | + $is_digital = $wpi_item_id ? self::item_has_digital_rule($wpi_item_id) : self::allow_vat_rules(); |
|
1216 | 1216 | } |
1217 | 1217 | |
1218 | - if ( !empty( $country_code ) ) { |
|
1219 | - $requires_vat = ( self::is_eu_state( $country_code ) && ( self::is_eu_state( self::$default_country ) || $is_digital ) ) || ( self::is_gst_country( $country_code ) && self::is_gst_country( self::$default_country ) ); |
|
1218 | + if (!empty($country_code)) { |
|
1219 | + $requires_vat = (self::is_eu_state($country_code) && (self::is_eu_state(self::$default_country) || $is_digital)) || (self::is_gst_country($country_code) && self::is_gst_country(self::$default_country)); |
|
1220 | 1220 | } |
1221 | 1221 | |
1222 | - return apply_filters( 'wpinv_requires_vat', $requires_vat, $user_id ); |
|
1222 | + return apply_filters('wpinv_requires_vat', $requires_vat, $user_id); |
|
1223 | 1223 | } |
1224 | 1224 | |
1225 | - public static function tax_label( $label = '' ) { |
|
1225 | + public static function tax_label($label = '') { |
|
1226 | 1226 | global $wpi_requires_vat; |
1227 | 1227 | |
1228 | - if ( !( $wpi_requires_vat !== 0 && $wpi_requires_vat ) ) { |
|
1229 | - $wpi_requires_vat = self::requires_vat( 0, false ); |
|
1228 | + if (!($wpi_requires_vat !== 0 && $wpi_requires_vat)) { |
|
1229 | + $wpi_requires_vat = self::requires_vat(0, false); |
|
1230 | 1230 | } |
1231 | 1231 | |
1232 | - return $wpi_requires_vat ? __( self::get_vat_name(), 'invoicing' ) : ( $label ? $label : __( 'Tax', 'invoicing' ) ); |
|
1232 | + return $wpi_requires_vat ? __(self::get_vat_name(), 'invoicing') : ($label ? $label : __('Tax', 'invoicing')); |
|
1233 | 1233 | } |
1234 | 1234 | |
1235 | 1235 | public static function standard_rates_label() { |
1236 | - return __( 'Standard Rates', 'invoicing' ); |
|
1236 | + return __('Standard Rates', 'invoicing'); |
|
1237 | 1237 | } |
1238 | 1238 | |
1239 | - public static function get_rate_classes( $with_desc = false ) { |
|
1240 | - $rate_classes_option = get_option( '_wpinv_vat_rate_classes', true ); |
|
1241 | - $classes = maybe_unserialize( $rate_classes_option ); |
|
1239 | + public static function get_rate_classes($with_desc = false) { |
|
1240 | + $rate_classes_option = get_option('_wpinv_vat_rate_classes', true); |
|
1241 | + $classes = maybe_unserialize($rate_classes_option); |
|
1242 | 1242 | |
1243 | - if ( empty( $classes ) || !is_array( $classes ) ) { |
|
1243 | + if (empty($classes) || !is_array($classes)) { |
|
1244 | 1244 | $classes = array(); |
1245 | 1245 | } |
1246 | 1246 | |
1247 | 1247 | $rate_classes = array(); |
1248 | - if ( !array_key_exists( '_standard', $classes ) ) { |
|
1249 | - if ( $with_desc ) { |
|
1250 | - $rate_classes['_standard'] = array( 'name' => self::standard_rates_label(), 'desc' => __( 'EU member states standard VAT rates', 'invoicing' ) ); |
|
1248 | + if (!array_key_exists('_standard', $classes)) { |
|
1249 | + if ($with_desc) { |
|
1250 | + $rate_classes['_standard'] = array('name' => self::standard_rates_label(), 'desc' => __('EU member states standard VAT rates', 'invoicing')); |
|
1251 | 1251 | } else { |
1252 | 1252 | $rate_classes['_standard'] = self::standard_rates_label(); |
1253 | 1253 | } |
1254 | 1254 | } |
1255 | 1255 | |
1256 | - foreach ( $classes as $key => $class ) { |
|
1257 | - $name = !empty( $class['name'] ) ? __( $class['name'], 'invoicing' ) : $key; |
|
1258 | - $desc = !empty( $class['desc'] ) ? __( $class['desc'], 'invoicing' ) : ''; |
|
1256 | + foreach ($classes as $key => $class) { |
|
1257 | + $name = !empty($class['name']) ? __($class['name'], 'invoicing') : $key; |
|
1258 | + $desc = !empty($class['desc']) ? __($class['desc'], 'invoicing') : ''; |
|
1259 | 1259 | |
1260 | - if ( $with_desc ) { |
|
1261 | - $rate_classes[$key] = array( 'name' => $name, 'desc' => $desc ); |
|
1260 | + if ($with_desc) { |
|
1261 | + $rate_classes[$key] = array('name' => $name, 'desc' => $desc); |
|
1262 | 1262 | } else { |
1263 | 1263 | $rate_classes[$key] = $name; |
1264 | 1264 | } |
@@ -1269,15 +1269,15 @@ discard block |
||
1269 | 1269 | |
1270 | 1270 | public static function get_all_classes() { |
1271 | 1271 | $classes = self::get_rate_classes(); |
1272 | - $classes['_exempt'] = __( 'Exempt (0%)', 'invoicing' ); |
|
1272 | + $classes['_exempt'] = __('Exempt (0%)', 'invoicing'); |
|
1273 | 1273 | |
1274 | - return apply_filters( 'wpinv_vat_get_all_classes', $classes ); |
|
1274 | + return apply_filters('wpinv_vat_get_all_classes', $classes); |
|
1275 | 1275 | } |
1276 | 1276 | |
1277 | - public static function get_class_desc( $rate_class ) { |
|
1278 | - $rate_classes = self::get_rate_classes( true ); |
|
1277 | + public static function get_class_desc($rate_class) { |
|
1278 | + $rate_classes = self::get_rate_classes(true); |
|
1279 | 1279 | |
1280 | - if ( !empty( $rate_classes ) && isset( $rate_classes[$rate_class] ) && isset( $rate_classes[$rate_class]['desc'] ) ) { |
|
1280 | + if (!empty($rate_classes) && isset($rate_classes[$rate_class]) && isset($rate_classes[$rate_class]['desc'])) { |
|
1281 | 1281 | return $rate_classes[$rate_class]['desc']; |
1282 | 1282 | } |
1283 | 1283 | |
@@ -1293,106 +1293,106 @@ discard block |
||
1293 | 1293 | 'increased' => 'Increased' |
1294 | 1294 | ); |
1295 | 1295 | |
1296 | - return apply_filters( 'wpinv_get_vat_groups', $vat_groups ); |
|
1296 | + return apply_filters('wpinv_get_vat_groups', $vat_groups); |
|
1297 | 1297 | } |
1298 | 1298 | |
1299 | 1299 | public static function get_rules() { |
1300 | 1300 | $vat_rules = array( |
1301 | - 'digital' => __( 'Digital Product', 'invoicing' ), |
|
1302 | - 'physical' => __( 'Physical Product', 'invoicing' ) |
|
1301 | + 'digital' => __('Digital Product', 'invoicing'), |
|
1302 | + 'physical' => __('Physical Product', 'invoicing') |
|
1303 | 1303 | ); |
1304 | - return apply_filters( 'wpinv_get_vat_rules', $vat_rules ); |
|
1304 | + return apply_filters('wpinv_get_vat_rules', $vat_rules); |
|
1305 | 1305 | } |
1306 | 1306 | |
1307 | - public static function get_vat_rates( $class ) { |
|
1308 | - if ( $class === '_standard' ) { |
|
1307 | + public static function get_vat_rates($class) { |
|
1308 | + if ($class === '_standard') { |
|
1309 | 1309 | return wpinv_get_tax_rates(); |
1310 | 1310 | } |
1311 | 1311 | |
1312 | 1312 | $rates = self::get_non_standard_rates(); |
1313 | 1313 | |
1314 | - return array_key_exists( $class, $rates ) ? $rates[$class] : array(); |
|
1314 | + return array_key_exists($class, $rates) ? $rates[$class] : array(); |
|
1315 | 1315 | } |
1316 | 1316 | |
1317 | 1317 | public static function get_non_standard_rates() { |
1318 | - $option = get_option( 'wpinv_vat_rates', array()); |
|
1319 | - return is_array( $option ) ? $option : array(); |
|
1318 | + $option = get_option('wpinv_vat_rates', array()); |
|
1319 | + return is_array($option) ? $option : array(); |
|
1320 | 1320 | } |
1321 | 1321 | |
1322 | 1322 | public static function allow_vat_rules() { |
1323 | - return ( wpinv_use_taxes() && wpinv_get_option( 'apply_vat_rules' ) ? true : false ); |
|
1323 | + return (wpinv_use_taxes() && wpinv_get_option('apply_vat_rules') ? true : false); |
|
1324 | 1324 | } |
1325 | 1325 | |
1326 | 1326 | public static function allow_vat_classes() { |
1327 | 1327 | return false; // TODO |
1328 | - return ( wpinv_get_option( 'vat_allow_classes' ) ? true : false ); |
|
1328 | + return (wpinv_get_option('vat_allow_classes') ? true : false); |
|
1329 | 1329 | } |
1330 | 1330 | |
1331 | - public static function get_item_class( $postID ) { |
|
1332 | - $class = get_post_meta( $postID, '_wpinv_vat_class', true ); |
|
1331 | + public static function get_item_class($postID) { |
|
1332 | + $class = get_post_meta($postID, '_wpinv_vat_class', true); |
|
1333 | 1333 | |
1334 | - if ( empty( $class ) ) { |
|
1334 | + if (empty($class)) { |
|
1335 | 1335 | $class = '_standard'; |
1336 | 1336 | } |
1337 | 1337 | |
1338 | - return apply_filters( 'wpinv_get_item_vat_class', $class, $postID ); |
|
1338 | + return apply_filters('wpinv_get_item_vat_class', $class, $postID); |
|
1339 | 1339 | } |
1340 | 1340 | |
1341 | - public static function item_class_label( $postID ) { |
|
1341 | + public static function item_class_label($postID) { |
|
1342 | 1342 | $vat_classes = self::get_all_classes(); |
1343 | 1343 | |
1344 | - $class = self::get_item_class( $postID ); |
|
1345 | - $class = isset( $vat_classes[$class] ) ? $vat_classes[$class] : __( $class, 'invoicing' ); |
|
1344 | + $class = self::get_item_class($postID); |
|
1345 | + $class = isset($vat_classes[$class]) ? $vat_classes[$class] : __($class, 'invoicing'); |
|
1346 | 1346 | |
1347 | - return apply_filters( 'wpinv_item_class_label', $class, $postID ); |
|
1347 | + return apply_filters('wpinv_item_class_label', $class, $postID); |
|
1348 | 1348 | } |
1349 | 1349 | |
1350 | - public static function get_item_rule( $postID ) { |
|
1351 | - $rule_type = get_post_meta( $postID, '_wpinv_vat_rule', true ); |
|
1350 | + public static function get_item_rule($postID) { |
|
1351 | + $rule_type = get_post_meta($postID, '_wpinv_vat_rule', true); |
|
1352 | 1352 | |
1353 | - if ( empty( $rule_type ) ) { |
|
1353 | + if (empty($rule_type)) { |
|
1354 | 1354 | $rule_type = self::allow_vat_rules() ? 'digital' : 'physical'; |
1355 | 1355 | } |
1356 | 1356 | |
1357 | - return apply_filters( 'wpinv_item_get_vat_rule', $rule_type, $postID ); |
|
1357 | + return apply_filters('wpinv_item_get_vat_rule', $rule_type, $postID); |
|
1358 | 1358 | } |
1359 | 1359 | |
1360 | - public static function item_rule_label( $postID ) { |
|
1360 | + public static function item_rule_label($postID) { |
|
1361 | 1361 | $vat_rules = self::get_rules(); |
1362 | - $vat_rule = self::get_item_rule( $postID ); |
|
1363 | - $vat_rule = isset( $vat_rules[$vat_rule] ) ? $vat_rules[$vat_rule] : $vat_rule; |
|
1362 | + $vat_rule = self::get_item_rule($postID); |
|
1363 | + $vat_rule = isset($vat_rules[$vat_rule]) ? $vat_rules[$vat_rule] : $vat_rule; |
|
1364 | 1364 | |
1365 | - return apply_filters( 'wpinv_item_rule_label', $vat_rule, $postID ); |
|
1365 | + return apply_filters('wpinv_item_rule_label', $vat_rule, $postID); |
|
1366 | 1366 | } |
1367 | 1367 | |
1368 | - public static function item_has_digital_rule( $item_id = 0 ) { |
|
1369 | - return self::get_item_rule( $item_id ) == 'digital' ? true : false; |
|
1368 | + public static function item_has_digital_rule($item_id = 0) { |
|
1369 | + return self::get_item_rule($item_id) == 'digital' ? true : false; |
|
1370 | 1370 | } |
1371 | 1371 | |
1372 | - public static function invoice_has_digital_rule( $invoice = 0 ) { |
|
1373 | - if ( !self::allow_vat_rules() ) { |
|
1372 | + public static function invoice_has_digital_rule($invoice = 0) { |
|
1373 | + if (!self::allow_vat_rules()) { |
|
1374 | 1374 | return false; |
1375 | 1375 | } |
1376 | 1376 | |
1377 | - if ( empty( $invoice ) ) { |
|
1377 | + if (empty($invoice)) { |
|
1378 | 1378 | return true; |
1379 | 1379 | } |
1380 | 1380 | |
1381 | - if ( is_int( $invoice ) ) { |
|
1382 | - $invoice = new WPInv_Invoice( $invoice ); |
|
1381 | + if (is_int($invoice)) { |
|
1382 | + $invoice = new WPInv_Invoice($invoice); |
|
1383 | 1383 | } |
1384 | 1384 | |
1385 | - if ( !( is_object( $invoice ) && is_a( $invoice, 'WPInv_Invoice' ) ) ) { |
|
1385 | + if (!(is_object($invoice) && is_a($invoice, 'WPInv_Invoice'))) { |
|
1386 | 1386 | return true; |
1387 | 1387 | } |
1388 | 1388 | |
1389 | - $cart_items = $invoice->get_cart_details(); |
|
1389 | + $cart_items = $invoice->get_cart_details(); |
|
1390 | 1390 | |
1391 | - if ( !empty( $cart_items ) ) { |
|
1391 | + if (!empty($cart_items)) { |
|
1392 | 1392 | $has_digital_rule = false; |
1393 | 1393 | |
1394 | - foreach ( $cart_items as $key => $item ) { |
|
1395 | - if ( self::item_has_digital_rule( $item['id'] ) ) { |
|
1394 | + foreach ($cart_items as $key => $item) { |
|
1395 | + if (self::item_has_digital_rule($item['id'])) { |
|
1396 | 1396 | $has_digital_rule = true; |
1397 | 1397 | break; |
1398 | 1398 | } |
@@ -1404,67 +1404,67 @@ discard block |
||
1404 | 1404 | return $has_digital_rule; |
1405 | 1405 | } |
1406 | 1406 | |
1407 | - public static function item_is_taxable( $item_id = 0, $country = false, $state = false ) { |
|
1408 | - if ( !wpinv_use_taxes() ) { |
|
1407 | + public static function item_is_taxable($item_id = 0, $country = false, $state = false) { |
|
1408 | + if (!wpinv_use_taxes()) { |
|
1409 | 1409 | return false; |
1410 | 1410 | } |
1411 | 1411 | |
1412 | 1412 | $is_taxable = true; |
1413 | 1413 | |
1414 | - if ( !empty( $item_id ) && self::get_item_class( $item_id ) == '_exempt' ) { |
|
1414 | + if (!empty($item_id) && self::get_item_class($item_id) == '_exempt') { |
|
1415 | 1415 | $is_taxable = false; |
1416 | 1416 | } |
1417 | 1417 | |
1418 | - return apply_filters( 'wpinv_item_is_taxable', $is_taxable, $item_id, $country , $state ); |
|
1418 | + return apply_filters('wpinv_item_is_taxable', $is_taxable, $item_id, $country, $state); |
|
1419 | 1419 | } |
1420 | 1420 | |
1421 | - public static function find_rate( $country, $state, $rate, $class ) { |
|
1421 | + public static function find_rate($country, $state, $rate, $class) { |
|
1422 | 1422 | global $wpi_zero_tax; |
1423 | 1423 | |
1424 | - if ( $class === '_exempt' || $wpi_zero_tax ) { |
|
1424 | + if ($class === '_exempt' || $wpi_zero_tax) { |
|
1425 | 1425 | return 0; |
1426 | 1426 | } |
1427 | 1427 | |
1428 | - $tax_rates = wpinv_get_tax_rates(); |
|
1428 | + $tax_rates = wpinv_get_tax_rates(); |
|
1429 | 1429 | |
1430 | - if ( $class !== '_standard' ) { |
|
1431 | - $class_rates = self::get_vat_rates( $class ); |
|
1430 | + if ($class !== '_standard') { |
|
1431 | + $class_rates = self::get_vat_rates($class); |
|
1432 | 1432 | |
1433 | - if ( is_array( $class_rates ) ) { |
|
1433 | + if (is_array($class_rates)) { |
|
1434 | 1434 | $indexed_class_rates = array(); |
1435 | 1435 | |
1436 | - foreach ( $class_rates as $key => $cr ) { |
|
1436 | + foreach ($class_rates as $key => $cr) { |
|
1437 | 1437 | $indexed_class_rates[$cr['country']] = $cr; |
1438 | 1438 | } |
1439 | 1439 | |
1440 | - $tax_rates = array_map( function( $tr ) use( $indexed_class_rates ) { |
|
1440 | + $tax_rates = array_map(function($tr) use($indexed_class_rates) { |
|
1441 | 1441 | $tr_country = $tr['country']; |
1442 | - if ( !isset( $indexed_class_rates[$tr_country] ) ) { |
|
1442 | + if (!isset($indexed_class_rates[$tr_country])) { |
|
1443 | 1443 | return $tr; |
1444 | 1444 | } |
1445 | 1445 | $icr = $indexed_class_rates[$tr_country]; |
1446 | - return ( empty( $icr['rate'] ) && $icr['rate'] !== '0' ) ? $tr : $icr; |
|
1446 | + return (empty($icr['rate']) && $icr['rate'] !== '0') ? $tr : $icr; |
|
1447 | 1447 | |
1448 | - }, $tax_rates, $class_rates ); |
|
1448 | + }, $tax_rates, $class_rates); |
|
1449 | 1449 | } |
1450 | 1450 | } |
1451 | 1451 | |
1452 | - if ( !empty( $tax_rates ) ) { |
|
1453 | - foreach ( $tax_rates as $key => $tax_rate ) { |
|
1454 | - if ( $country != $tax_rate['country'] ) |
|
1452 | + if (!empty($tax_rates)) { |
|
1453 | + foreach ($tax_rates as $key => $tax_rate) { |
|
1454 | + if ($country != $tax_rate['country']) |
|
1455 | 1455 | continue; |
1456 | 1456 | |
1457 | - if ( !empty( $tax_rate['global'] ) ) { |
|
1458 | - if ( 0 !== $tax_rate['rate'] || !empty( $tax_rate['rate'] ) ) { |
|
1459 | - $rate = number_format( $tax_rate['rate'], 4 ); |
|
1457 | + if (!empty($tax_rate['global'])) { |
|
1458 | + if (0 !== $tax_rate['rate'] || !empty($tax_rate['rate'])) { |
|
1459 | + $rate = number_format($tax_rate['rate'], 4); |
|
1460 | 1460 | } |
1461 | 1461 | } else { |
1462 | - if ( empty( $tax_rate['state'] ) || strtolower( $state ) != strtolower( $tax_rate['state'] ) ) |
|
1462 | + if (empty($tax_rate['state']) || strtolower($state) != strtolower($tax_rate['state'])) |
|
1463 | 1463 | continue; |
1464 | 1464 | |
1465 | 1465 | $state_rate = $tax_rate['rate']; |
1466 | - if ( 0 !== $state_rate || !empty( $state_rate ) ) { |
|
1467 | - $rate = number_format( $state_rate, 4 ); |
|
1466 | + if (0 !== $state_rate || !empty($state_rate)) { |
|
1467 | + $rate = number_format($state_rate, 4); |
|
1468 | 1468 | } |
1469 | 1469 | } |
1470 | 1470 | } |
@@ -1473,84 +1473,84 @@ discard block |
||
1473 | 1473 | return $rate; |
1474 | 1474 | } |
1475 | 1475 | |
1476 | - public static function get_rate( $rate = 1, $country = '', $state = '', $item_id = 0 ) { |
|
1476 | + public static function get_rate($rate = 1, $country = '', $state = '', $item_id = 0) { |
|
1477 | 1477 | global $wpinv_options, $wpi_session, $wpi_item_id, $wpi_zero_tax; |
1478 | 1478 | |
1479 | 1479 | $item_id = $item_id > 0 ? $item_id : $wpi_item_id; |
1480 | 1480 | $allow_vat_classes = self::allow_vat_classes(); |
1481 | - $class = $item_id ? self::get_item_class( $item_id ) : '_standard'; |
|
1481 | + $class = $item_id ? self::get_item_class($item_id) : '_standard'; |
|
1482 | 1482 | |
1483 | - if ( $class === '_exempt' || $wpi_zero_tax ) { |
|
1483 | + if ($class === '_exempt' || $wpi_zero_tax) { |
|
1484 | 1484 | return 0; |
1485 | - } else if ( !$allow_vat_classes ) { |
|
1485 | + } else if (!$allow_vat_classes) { |
|
1486 | 1486 | $class = '_standard'; |
1487 | 1487 | } |
1488 | 1488 | |
1489 | - if( !empty( $_POST['wpinv_country'] ) ) { |
|
1489 | + if (!empty($_POST['wpinv_country'])) { |
|
1490 | 1490 | $post_country = $_POST['wpinv_country']; |
1491 | - } elseif( !empty( $_POST['wpinv_country'] ) ) { |
|
1491 | + } elseif (!empty($_POST['wpinv_country'])) { |
|
1492 | 1492 | $post_country = $_POST['wpinv_country']; |
1493 | - } elseif( !empty( $_POST['country'] ) ) { |
|
1493 | + } elseif (!empty($_POST['country'])) { |
|
1494 | 1494 | $post_country = $_POST['country']; |
1495 | 1495 | } else { |
1496 | 1496 | $post_country = ''; |
1497 | 1497 | } |
1498 | 1498 | |
1499 | - $country = !empty( $post_country ) ? $post_country : wpinv_default_billing_country( $country ); |
|
1500 | - $base_country = wpinv_is_base_country( $country ); |
|
1499 | + $country = !empty($post_country) ? $post_country : wpinv_default_billing_country($country); |
|
1500 | + $base_country = wpinv_is_base_country($country); |
|
1501 | 1501 | |
1502 | - $requires_vat = self::requires_vat( 0, false ); |
|
1503 | - $is_digital = self::get_item_rule( $item_id ) == 'digital' ; |
|
1504 | - $rate = $requires_vat && isset( $wpinv_options['eu_fallback_rate'] ) ? $wpinv_options['eu_fallback_rate'] : $rate; |
|
1502 | + $requires_vat = self::requires_vat(0, false); |
|
1503 | + $is_digital = self::get_item_rule($item_id) == 'digital'; |
|
1504 | + $rate = $requires_vat && isset($wpinv_options['eu_fallback_rate']) ? $wpinv_options['eu_fallback_rate'] : $rate; |
|
1505 | 1505 | |
1506 | - if ( self::same_country_rule() == 'no' && $base_country ) { // Disable VAT to same country |
|
1506 | + if (self::same_country_rule() == 'no' && $base_country) { // Disable VAT to same country |
|
1507 | 1507 | $rate = 0; |
1508 | - } else if ( $requires_vat ) { |
|
1509 | - $vat_number = self::get_user_vat_number( '', 0, true ); |
|
1508 | + } else if ($requires_vat) { |
|
1509 | + $vat_number = self::get_user_vat_number('', 0, true); |
|
1510 | 1510 | $vat_info = self::current_vat_data(); |
1511 | 1511 | |
1512 | - if ( is_array( $vat_info ) ) { |
|
1513 | - $vat_number = isset( $vat_info['number'] ) && !empty( $vat_info['valid'] ) ? $vat_info['number'] : ""; |
|
1512 | + if (is_array($vat_info)) { |
|
1513 | + $vat_number = isset($vat_info['number']) && !empty($vat_info['valid']) ? $vat_info['number'] : ""; |
|
1514 | 1514 | } |
1515 | 1515 | |
1516 | - if ( $country == 'UK' ) { |
|
1516 | + if ($country == 'UK') { |
|
1517 | 1517 | $country = 'GB'; |
1518 | 1518 | } |
1519 | 1519 | |
1520 | - if ( !empty( $vat_number ) ) { |
|
1520 | + if (!empty($vat_number)) { |
|
1521 | 1521 | $rate = 0; |
1522 | 1522 | } else { |
1523 | - $rate = self::find_rate( $country, $state, $rate, $class ); // Fix if there are no tax rated and you try to pay an invoice it does not add the fallback tax rate |
|
1523 | + $rate = self::find_rate($country, $state, $rate, $class); // Fix if there are no tax rated and you try to pay an invoice it does not add the fallback tax rate |
|
1524 | 1524 | } |
1525 | 1525 | |
1526 | - if ( empty( $vat_number ) && !$is_digital ) { |
|
1527 | - if ( $base_country ) { |
|
1528 | - $rate = self::find_rate( $country, null, $rate, $class ); |
|
1526 | + if (empty($vat_number) && !$is_digital) { |
|
1527 | + if ($base_country) { |
|
1528 | + $rate = self::find_rate($country, null, $rate, $class); |
|
1529 | 1529 | } else { |
1530 | - if ( empty( $country ) && isset( $wpinv_options['eu_fallback_rate'] ) ) { |
|
1530 | + if (empty($country) && isset($wpinv_options['eu_fallback_rate'])) { |
|
1531 | 1531 | $rate = $wpinv_options['eu_fallback_rate']; |
1532 | - } else if( !empty( $country ) ) { |
|
1533 | - $rate = self::find_rate( $country, $state, $rate, $class ); |
|
1532 | + } else if (!empty($country)) { |
|
1533 | + $rate = self::find_rate($country, $state, $rate, $class); |
|
1534 | 1534 | } |
1535 | 1535 | } |
1536 | - } else if ( empty( $vat_number ) || ( self::same_country_rule() == 'always' && $base_country ) ) { |
|
1537 | - if ( empty( $country ) && isset( $wpinv_options['eu_fallback_rate'] ) ) { |
|
1536 | + } else if (empty($vat_number) || (self::same_country_rule() == 'always' && $base_country)) { |
|
1537 | + if (empty($country) && isset($wpinv_options['eu_fallback_rate'])) { |
|
1538 | 1538 | $rate = $wpinv_options['eu_fallback_rate']; |
1539 | - } else if( !empty( $country ) ) { |
|
1540 | - $rate = self::find_rate( $country, $state, $rate, $class ); |
|
1539 | + } else if (!empty($country)) { |
|
1540 | + $rate = self::find_rate($country, $state, $rate, $class); |
|
1541 | 1541 | } |
1542 | 1542 | } |
1543 | 1543 | } else { |
1544 | - if ( $is_digital ) { |
|
1544 | + if ($is_digital) { |
|
1545 | 1545 | $ip_country_code = self::get_country_by_ip(); |
1546 | 1546 | |
1547 | - if ( $ip_country_code && self::is_eu_state( $ip_country_code ) ) { |
|
1548 | - $rate = self::find_rate( $ip_country_code, '', 0, $class ); |
|
1547 | + if ($ip_country_code && self::is_eu_state($ip_country_code)) { |
|
1548 | + $rate = self::find_rate($ip_country_code, '', 0, $class); |
|
1549 | 1549 | } else { |
1550 | - $rate = self::find_rate( $country, $state, $rate, $class ); |
|
1550 | + $rate = self::find_rate($country, $state, $rate, $class); |
|
1551 | 1551 | } |
1552 | 1552 | } else { |
1553 | - $rate = self::find_rate( $country, $state, $rate, $class ); |
|
1553 | + $rate = self::find_rate($country, $state, $rate, $class); |
|
1554 | 1554 | } |
1555 | 1555 | } |
1556 | 1556 | |
@@ -1560,48 +1560,48 @@ discard block |
||
1560 | 1560 | public static function current_vat_data() { |
1561 | 1561 | global $wpi_session; |
1562 | 1562 | |
1563 | - return $wpi_session->get( 'user_vat_data' ); |
|
1563 | + return $wpi_session->get('user_vat_data'); |
|
1564 | 1564 | } |
1565 | 1565 | |
1566 | - public static function get_user_country( $country = '', $user_id = 0 ) { |
|
1567 | - $user_address = wpinv_get_user_address( $user_id, false ); |
|
1566 | + public static function get_user_country($country = '', $user_id = 0) { |
|
1567 | + $user_address = wpinv_get_user_address($user_id, false); |
|
1568 | 1568 | |
1569 | - if ( wpinv_get_option( 'vat_ip_country_default' ) ) { |
|
1569 | + if (wpinv_get_option('vat_ip_country_default')) { |
|
1570 | 1570 | $country = ''; |
1571 | 1571 | } |
1572 | 1572 | |
1573 | - $country = empty( $user_address ) || !isset( $user_address['country'] ) || empty( $user_address['country'] ) ? $country : $user_address['country']; |
|
1574 | - $result = apply_filters( 'wpinv_get_user_country', $country, $user_id ); |
|
1573 | + $country = empty($user_address) || !isset($user_address['country']) || empty($user_address['country']) ? $country : $user_address['country']; |
|
1574 | + $result = apply_filters('wpinv_get_user_country', $country, $user_id); |
|
1575 | 1575 | |
1576 | - if ( empty( $result ) ) { |
|
1576 | + if (empty($result)) { |
|
1577 | 1577 | $result = self::get_country_by_ip(); |
1578 | 1578 | } |
1579 | 1579 | |
1580 | 1580 | return $result; |
1581 | 1581 | } |
1582 | 1582 | |
1583 | - public static function set_user_country( $country = '', $user_id = 0 ) { |
|
1583 | + public static function set_user_country($country = '', $user_id = 0) { |
|
1584 | 1584 | global $wpi_userID; |
1585 | 1585 | |
1586 | - if ( empty($country) && !empty($wpi_userID) && get_current_user_id() != $wpi_userID ) { |
|
1586 | + if (empty($country) && !empty($wpi_userID) && get_current_user_id() != $wpi_userID) { |
|
1587 | 1587 | $country = wpinv_get_default_country(); |
1588 | 1588 | } |
1589 | 1589 | |
1590 | 1590 | return $country; |
1591 | 1591 | } |
1592 | 1592 | |
1593 | - public static function get_user_vat_number( $vat_number = '', $user_id = 0, $is_valid = false ) { |
|
1593 | + public static function get_user_vat_number($vat_number = '', $user_id = 0, $is_valid = false) { |
|
1594 | 1594 | global $wpi_current_id, $wpi_userID; |
1595 | 1595 | |
1596 | - if ( !empty( $_POST['new_user'] ) ) { |
|
1596 | + if (!empty($_POST['new_user'])) { |
|
1597 | 1597 | return ''; |
1598 | 1598 | } |
1599 | 1599 | |
1600 | - if ( empty( $user_id ) ) { |
|
1601 | - $user_id = !empty( $wpi_userID ) ? $wpi_userID : ( $wpi_current_id ? wpinv_get_user_id( $wpi_current_id ) : get_current_user_id() ); |
|
1600 | + if (empty($user_id)) { |
|
1601 | + $user_id = !empty($wpi_userID) ? $wpi_userID : ($wpi_current_id ? wpinv_get_user_id($wpi_current_id) : get_current_user_id()); |
|
1602 | 1602 | } |
1603 | 1603 | |
1604 | - $vat_number = empty( $user_id ) ? '' : get_user_meta( $user_id, '_wpinv_vat_number', true ); |
|
1604 | + $vat_number = empty($user_id) ? '' : get_user_meta($user_id, '_wpinv_vat_number', true); |
|
1605 | 1605 | |
1606 | 1606 | /* TODO |
1607 | 1607 | if ( $is_valid && $vat_number ) { |
@@ -1612,36 +1612,36 @@ discard block |
||
1612 | 1612 | } |
1613 | 1613 | */ |
1614 | 1614 | |
1615 | - return apply_filters('wpinv_get_user_vat_number', $vat_number, $user_id, $is_valid ); |
|
1615 | + return apply_filters('wpinv_get_user_vat_number', $vat_number, $user_id, $is_valid); |
|
1616 | 1616 | } |
1617 | 1617 | |
1618 | - public static function get_user_company( $company = '', $user_id = 0 ) { |
|
1619 | - if ( empty( $user_id ) ) { |
|
1618 | + public static function get_user_company($company = '', $user_id = 0) { |
|
1619 | + if (empty($user_id)) { |
|
1620 | 1620 | $user_id = get_current_user_id(); |
1621 | 1621 | } |
1622 | 1622 | |
1623 | - $company = empty( $user_id ) ? "" : get_user_meta( $user_id, '_wpinv_company', true ); |
|
1623 | + $company = empty($user_id) ? "" : get_user_meta($user_id, '_wpinv_company', true); |
|
1624 | 1624 | |
1625 | - return apply_filters( 'wpinv_user_company', $company, $user_id ); |
|
1625 | + return apply_filters('wpinv_user_company', $company, $user_id); |
|
1626 | 1626 | } |
1627 | 1627 | |
1628 | - public static function save_user_vat_details( $company = '', $vat_number = '' ) { |
|
1629 | - $save = apply_filters( 'wpinv_allow_save_user_vat_details', true ); |
|
1628 | + public static function save_user_vat_details($company = '', $vat_number = '') { |
|
1629 | + $save = apply_filters('wpinv_allow_save_user_vat_details', true); |
|
1630 | 1630 | |
1631 | - if ( is_user_logged_in() && $save ) { |
|
1631 | + if (is_user_logged_in() && $save) { |
|
1632 | 1632 | $user_id = get_current_user_id(); |
1633 | 1633 | |
1634 | - if ( !empty( $vat_number ) ) { |
|
1635 | - update_user_meta( $user_id, '_wpinv_vat_number', $vat_number ); |
|
1634 | + if (!empty($vat_number)) { |
|
1635 | + update_user_meta($user_id, '_wpinv_vat_number', $vat_number); |
|
1636 | 1636 | } else { |
1637 | - delete_user_meta( $user_id, '_wpinv_vat_number'); |
|
1637 | + delete_user_meta($user_id, '_wpinv_vat_number'); |
|
1638 | 1638 | } |
1639 | 1639 | |
1640 | - if ( !empty( $company ) ) { |
|
1641 | - update_user_meta( $user_id, '_wpinv_company', $company ); |
|
1640 | + if (!empty($company)) { |
|
1641 | + update_user_meta($user_id, '_wpinv_company', $company); |
|
1642 | 1642 | } else { |
1643 | - delete_user_meta( $user_id, '_wpinv_company'); |
|
1644 | - delete_user_meta( $user_id, '_wpinv_vat_number'); |
|
1643 | + delete_user_meta($user_id, '_wpinv_company'); |
|
1644 | + delete_user_meta($user_id, '_wpinv_vat_number'); |
|
1645 | 1645 | } |
1646 | 1646 | } |
1647 | 1647 | |
@@ -1651,113 +1651,113 @@ discard block |
||
1651 | 1651 | public static function ajax_vat_validate() { |
1652 | 1652 | global $wpinv_options, $wpi_session; |
1653 | 1653 | |
1654 | - $is_checkout = ( !empty( $_POST['source'] ) && $_POST['source'] == 'checkout' ) ? true : false; |
|
1654 | + $is_checkout = (!empty($_POST['source']) && $_POST['source'] == 'checkout') ? true : false; |
|
1655 | 1655 | $response = array(); |
1656 | 1656 | $response['success'] = false; |
1657 | 1657 | |
1658 | - if ( empty( $_REQUEST['_wpi_nonce'] ) || ( !empty( $_REQUEST['_wpi_nonce'] ) && !wp_verify_nonce( $_REQUEST['_wpi_nonce'], 'vat_validation' ) ) ) { |
|
1659 | - $response['error'] = __( 'Invalid security nonce', 'invoicing' ); |
|
1660 | - wp_send_json( $response ); |
|
1658 | + if (empty($_REQUEST['_wpi_nonce']) || (!empty($_REQUEST['_wpi_nonce']) && !wp_verify_nonce($_REQUEST['_wpi_nonce'], 'vat_validation'))) { |
|
1659 | + $response['error'] = __('Invalid security nonce', 'invoicing'); |
|
1660 | + wp_send_json($response); |
|
1661 | 1661 | } |
1662 | 1662 | |
1663 | - $vat_name = self::get_vat_name(); |
|
1663 | + $vat_name = self::get_vat_name(); |
|
1664 | 1664 | |
1665 | - if ( $is_checkout ) { |
|
1665 | + if ($is_checkout) { |
|
1666 | 1666 | $invoice = wpinv_get_invoice_cart(); |
1667 | 1667 | |
1668 | - if ( !self::requires_vat( false, 0, self::invoice_has_digital_rule( $invoice ) ) ) { |
|
1668 | + if (!self::requires_vat(false, 0, self::invoice_has_digital_rule($invoice))) { |
|
1669 | 1669 | $vat_info = array(); |
1670 | - $wpi_session->set( 'user_vat_data', $vat_info ); |
|
1670 | + $wpi_session->set('user_vat_data', $vat_info); |
|
1671 | 1671 | |
1672 | 1672 | self::save_user_vat_details(); |
1673 | 1673 | |
1674 | 1674 | $response['success'] = true; |
1675 | - $response['message'] = wp_sprintf( __( 'Ignore %s', 'invoicing' ), $vat_name ); |
|
1676 | - wp_send_json( $response ); |
|
1675 | + $response['message'] = wp_sprintf(__('Ignore %s', 'invoicing'), $vat_name); |
|
1676 | + wp_send_json($response); |
|
1677 | 1677 | } |
1678 | 1678 | } |
1679 | 1679 | |
1680 | - $company = !empty( $_POST['company'] ) ? sanitize_text_field( $_POST['company'] ) : ''; |
|
1681 | - $vat_number = !empty( $_POST['number'] ) ? sanitize_text_field( $_POST['number'] ) : ''; |
|
1680 | + $company = !empty($_POST['company']) ? sanitize_text_field($_POST['company']) : ''; |
|
1681 | + $vat_number = !empty($_POST['number']) ? sanitize_text_field($_POST['number']) : ''; |
|
1682 | 1682 | |
1683 | - $vat_info = $wpi_session->get( 'user_vat_data' ); |
|
1684 | - if ( !is_array( $vat_info ) || empty( $vat_info ) ) { |
|
1685 | - $vat_info = array( 'company'=> $company, 'number' => '', 'valid' => true ); |
|
1683 | + $vat_info = $wpi_session->get('user_vat_data'); |
|
1684 | + if (!is_array($vat_info) || empty($vat_info)) { |
|
1685 | + $vat_info = array('company'=> $company, 'number' => '', 'valid' => true); |
|
1686 | 1686 | } |
1687 | 1687 | |
1688 | - if ( empty( $vat_number ) ) { |
|
1689 | - if ( $is_checkout ) { |
|
1688 | + if (empty($vat_number)) { |
|
1689 | + if ($is_checkout) { |
|
1690 | 1690 | $response['success'] = true; |
1691 | - $response['message'] = wp_sprintf( __( 'No %s number has been applied. %s will be added to invoice totals', 'invoicing' ), $vat_name, $vat_name ); |
|
1691 | + $response['message'] = wp_sprintf(__('No %s number has been applied. %s will be added to invoice totals', 'invoicing'), $vat_name, $vat_name); |
|
1692 | 1692 | |
1693 | - $vat_info = $wpi_session->get( 'user_vat_data' ); |
|
1693 | + $vat_info = $wpi_session->get('user_vat_data'); |
|
1694 | 1694 | $vat_info['number'] = ""; |
1695 | 1695 | $vat_info['valid'] = true; |
1696 | 1696 | |
1697 | - self::save_user_vat_details( $company ); |
|
1697 | + self::save_user_vat_details($company); |
|
1698 | 1698 | } else { |
1699 | - $response['error'] = wp_sprintf( __( 'Please enter your %s number!', 'invoicing' ), $vat_name ); |
|
1699 | + $response['error'] = wp_sprintf(__('Please enter your %s number!', 'invoicing'), $vat_name); |
|
1700 | 1700 | |
1701 | 1701 | $vat_info['valid'] = false; |
1702 | 1702 | } |
1703 | 1703 | |
1704 | - $wpi_session->set( 'user_vat_data', $vat_info ); |
|
1705 | - wp_send_json( $response ); |
|
1704 | + $wpi_session->set('user_vat_data', $vat_info); |
|
1705 | + wp_send_json($response); |
|
1706 | 1706 | } |
1707 | 1707 | |
1708 | - if ( empty( $company ) ) { |
|
1708 | + if (empty($company)) { |
|
1709 | 1709 | $vat_info['valid'] = false; |
1710 | - $wpi_session->set( 'user_vat_data', $vat_info ); |
|
1710 | + $wpi_session->set('user_vat_data', $vat_info); |
|
1711 | 1711 | |
1712 | - $response['error'] = __( 'Please enter your registered company name!', 'invoicing' ); |
|
1713 | - wp_send_json( $response ); |
|
1712 | + $response['error'] = __('Please enter your registered company name!', 'invoicing'); |
|
1713 | + wp_send_json($response); |
|
1714 | 1714 | } |
1715 | 1715 | |
1716 | - if ( !empty( $wpinv_options['vat_vies_check'] ) ) { |
|
1717 | - if ( empty( $wpinv_options['vat_offline_check'] ) && !self::offline_check( $vat_number ) ) { |
|
1716 | + if (!empty($wpinv_options['vat_vies_check'])) { |
|
1717 | + if (empty($wpinv_options['vat_offline_check']) && !self::offline_check($vat_number)) { |
|
1718 | 1718 | $vat_info['valid'] = false; |
1719 | - $wpi_session->set( 'user_vat_data', $vat_info ); |
|
1719 | + $wpi_session->set('user_vat_data', $vat_info); |
|
1720 | 1720 | |
1721 | - $response['error'] = wp_sprintf( __( '%s number not validated', 'invoicing' ), $vat_name ); |
|
1722 | - wp_send_json( $response ); |
|
1721 | + $response['error'] = wp_sprintf(__('%s number not validated', 'invoicing'), $vat_name); |
|
1722 | + wp_send_json($response); |
|
1723 | 1723 | } |
1724 | 1724 | |
1725 | 1725 | $response['success'] = true; |
1726 | - $response['message'] = wp_sprintf( __( '%s number validated', 'invoicing' ), $vat_name ); |
|
1726 | + $response['message'] = wp_sprintf(__('%s number validated', 'invoicing'), $vat_name); |
|
1727 | 1727 | } else { |
1728 | - $result = self::check_vat( $vat_number ); |
|
1728 | + $result = self::check_vat($vat_number); |
|
1729 | 1729 | |
1730 | - if ( empty( $result['valid'] ) ) { |
|
1730 | + if (empty($result['valid'])) { |
|
1731 | 1731 | $response['error'] = $result['message']; |
1732 | - wp_send_json( $response ); |
|
1732 | + wp_send_json($response); |
|
1733 | 1733 | } |
1734 | 1734 | |
1735 | - $vies_company = !empty( $result['company'] ) ? $result['company'] : ''; |
|
1736 | - $vies_company = apply_filters( 'wpinv_vies_company_name', $vies_company ); |
|
1735 | + $vies_company = !empty($result['company']) ? $result['company'] : ''; |
|
1736 | + $vies_company = apply_filters('wpinv_vies_company_name', $vies_company); |
|
1737 | 1737 | |
1738 | - $valid_company = $vies_company && $company && ( $vies_company == '---' || strcasecmp( trim( $vies_company ), trim( $company ) ) == 0 ) ? true : false; |
|
1738 | + $valid_company = $vies_company && $company && ($vies_company == '---' || strcasecmp(trim($vies_company), trim($company)) == 0) ? true : false; |
|
1739 | 1739 | |
1740 | - if ( !empty( $wpinv_options['vat_disable_company_name_check'] ) || $valid_company ) { |
|
1740 | + if (!empty($wpinv_options['vat_disable_company_name_check']) || $valid_company) { |
|
1741 | 1741 | $response['success'] = true; |
1742 | - $response['message'] = wp_sprintf( __( '%s number validated', 'invoicing' ), $vat_name ); |
|
1742 | + $response['message'] = wp_sprintf(__('%s number validated', 'invoicing'), $vat_name); |
|
1743 | 1743 | } else { |
1744 | 1744 | $vat_info['valid'] = false; |
1745 | - $wpi_session->set( 'user_vat_data', $vat_info ); |
|
1745 | + $wpi_session->set('user_vat_data', $vat_info); |
|
1746 | 1746 | |
1747 | 1747 | $response['success'] = false; |
1748 | - $response['message'] = wp_sprintf( __( 'The company name associated with the %s number provided is not the same as the company name provided.', 'invoicing' ), $vat_name ); |
|
1749 | - wp_send_json( $response ); |
|
1748 | + $response['message'] = wp_sprintf(__('The company name associated with the %s number provided is not the same as the company name provided.', 'invoicing'), $vat_name); |
|
1749 | + wp_send_json($response); |
|
1750 | 1750 | } |
1751 | 1751 | } |
1752 | 1752 | |
1753 | - if ( $is_checkout ) { |
|
1754 | - self::save_user_vat_details( $company, $vat_number ); |
|
1753 | + if ($is_checkout) { |
|
1754 | + self::save_user_vat_details($company, $vat_number); |
|
1755 | 1755 | |
1756 | - $vat_info = array('company' => $company, 'number' => $vat_number, 'valid' => true ); |
|
1757 | - $wpi_session->set( 'user_vat_data', $vat_info ); |
|
1756 | + $vat_info = array('company' => $company, 'number' => $vat_number, 'valid' => true); |
|
1757 | + $wpi_session->set('user_vat_data', $vat_info); |
|
1758 | 1758 | } |
1759 | 1759 | |
1760 | - wp_send_json( $response ); |
|
1760 | + wp_send_json($response); |
|
1761 | 1761 | } |
1762 | 1762 | |
1763 | 1763 | public static function ajax_vat_reset() { |
@@ -1766,161 +1766,161 @@ discard block |
||
1766 | 1766 | $company = is_user_logged_in() ? self::get_user_company() : ''; |
1767 | 1767 | $vat_number = self::get_user_vat_number(); |
1768 | 1768 | |
1769 | - $vat_info = array('company' => $company, 'number' => $vat_number, 'valid' => false ); |
|
1770 | - $wpi_session->set( 'user_vat_data', $vat_info ); |
|
1769 | + $vat_info = array('company' => $company, 'number' => $vat_number, 'valid' => false); |
|
1770 | + $wpi_session->set('user_vat_data', $vat_info); |
|
1771 | 1771 | |
1772 | 1772 | $response = array(); |
1773 | 1773 | $response['success'] = true; |
1774 | 1774 | $response['data']['company'] = $company; |
1775 | 1775 | $response['data']['number'] = $vat_number; |
1776 | 1776 | |
1777 | - wp_send_json( $response ); |
|
1777 | + wp_send_json($response); |
|
1778 | 1778 | } |
1779 | 1779 | |
1780 | - public static function checkout_vat_validate( $valid_data, $post ) { |
|
1780 | + public static function checkout_vat_validate($valid_data, $post) { |
|
1781 | 1781 | global $wpinv_options, $wpi_session; |
1782 | 1782 | |
1783 | - $vat_name = __( self::get_vat_name(), 'invoicing' ); |
|
1783 | + $vat_name = __(self::get_vat_name(), 'invoicing'); |
|
1784 | 1784 | |
1785 | - if ( !isset( $_POST['_wpi_nonce'] ) || !wp_verify_nonce( $_POST['_wpi_nonce'], 'vat_validation' ) ) { |
|
1786 | - wpinv_set_error( 'vat_validation', wp_sprintf( __( "Invalid %s validation request.", 'invoicing' ), $vat_name ) ); |
|
1785 | + if (!isset($_POST['_wpi_nonce']) || !wp_verify_nonce($_POST['_wpi_nonce'], 'vat_validation')) { |
|
1786 | + wpinv_set_error('vat_validation', wp_sprintf(__("Invalid %s validation request.", 'invoicing'), $vat_name)); |
|
1787 | 1787 | return; |
1788 | 1788 | } |
1789 | 1789 | |
1790 | - $vat_saved = $wpi_session->get( 'user_vat_data' ); |
|
1791 | - $wpi_session->set( 'user_vat_data', null ); |
|
1790 | + $vat_saved = $wpi_session->get('user_vat_data'); |
|
1791 | + $wpi_session->set('user_vat_data', null); |
|
1792 | 1792 | |
1793 | 1793 | $invoice = wpinv_get_invoice_cart(); |
1794 | 1794 | $amount = $invoice->get_total(); |
1795 | - $is_digital = self::invoice_has_digital_rule( $invoice ); |
|
1796 | - $no_vat = !self::requires_vat( 0, false, $is_digital ); |
|
1795 | + $is_digital = self::invoice_has_digital_rule($invoice); |
|
1796 | + $no_vat = !self::requires_vat(0, false, $is_digital); |
|
1797 | 1797 | |
1798 | - $company = !empty( $_POST['wpinv_company'] ) ? $_POST['wpinv_company'] : null; |
|
1799 | - $vat_number = !empty( $_POST['wpinv_vat_number'] ) ? $_POST['wpinv_vat_number'] : null; |
|
1800 | - $country = !empty( $_POST['wpinv_country'] ) ? $_POST['wpinv_country'] : $invoice->country; |
|
1801 | - if ( empty( $country ) ) { |
|
1798 | + $company = !empty($_POST['wpinv_company']) ? $_POST['wpinv_company'] : null; |
|
1799 | + $vat_number = !empty($_POST['wpinv_vat_number']) ? $_POST['wpinv_vat_number'] : null; |
|
1800 | + $country = !empty($_POST['wpinv_country']) ? $_POST['wpinv_country'] : $invoice->country; |
|
1801 | + if (empty($country)) { |
|
1802 | 1802 | $country = wpinv_default_billing_country(); |
1803 | 1803 | } |
1804 | 1804 | |
1805 | - if ( !$is_digital && $no_vat ) { |
|
1805 | + if (!$is_digital && $no_vat) { |
|
1806 | 1806 | return; |
1807 | 1807 | } |
1808 | 1808 | |
1809 | - $vat_data = array( 'company' => '', 'number' => '', 'valid' => false ); |
|
1809 | + $vat_data = array('company' => '', 'number' => '', 'valid' => false); |
|
1810 | 1810 | |
1811 | 1811 | $ip_country_code = self::get_country_by_ip(); |
1812 | - $is_eu_state = self::is_eu_state( $country ); |
|
1813 | - $is_eu_state_ip = self::is_eu_state( $ip_country_code ); |
|
1812 | + $is_eu_state = self::is_eu_state($country); |
|
1813 | + $is_eu_state_ip = self::is_eu_state($ip_country_code); |
|
1814 | 1814 | $is_non_eu_user = !$is_eu_state && !$is_eu_state_ip; |
1815 | 1815 | |
1816 | - if ( $is_digital && !$is_non_eu_user && empty( $vat_number ) && apply_filters( 'wpinv_checkout_requires_country', true, $amount ) ) { |
|
1816 | + if ($is_digital && !$is_non_eu_user && empty($vat_number) && apply_filters('wpinv_checkout_requires_country', true, $amount)) { |
|
1817 | 1817 | $vat_data['adddress_confirmed'] = false; |
1818 | 1818 | |
1819 | - if ( !isset( $_POST['wpinv_adddress_confirmed'] ) ) { |
|
1820 | - if ( $ip_country_code != $country ) { |
|
1821 | - wpinv_set_error( 'vat_validation', sprintf( __( 'The country of your current location must be the same as the country of your billing location or you must %s confirm %s the billing address is your home country.', 'invoicing' ), '<a href="#wpinv_adddress_confirm">', '</a>' ) ); |
|
1819 | + if (!isset($_POST['wpinv_adddress_confirmed'])) { |
|
1820 | + if ($ip_country_code != $country) { |
|
1821 | + wpinv_set_error('vat_validation', sprintf(__('The country of your current location must be the same as the country of your billing location or you must %s confirm %s the billing address is your home country.', 'invoicing'), '<a href="#wpinv_adddress_confirm">', '</a>')); |
|
1822 | 1822 | } |
1823 | 1823 | } else { |
1824 | 1824 | $vat_data['adddress_confirmed'] = true; |
1825 | 1825 | } |
1826 | 1826 | } |
1827 | 1827 | |
1828 | - if ( !empty( $wpinv_options['vat_prevent_b2c_purchase'] ) && !$is_non_eu_user && ( empty( $vat_number ) || $no_vat ) ) { |
|
1829 | - if ( $is_eu_state ) { |
|
1830 | - wpinv_set_error( 'vat_validation', wp_sprintf( __( 'Please enter and validate your %s number to verify your purchase is by an EU business.', 'invoicing' ), $vat_name ) ); |
|
1831 | - } else if ( $is_digital && $is_eu_state_ip ) { |
|
1832 | - wpinv_set_error( 'vat_validation', wp_sprintf( __( 'Sales to non-EU countries cannot be completed because %s must be applied.', 'invoicing' ), $vat_name ) ); |
|
1828 | + if (!empty($wpinv_options['vat_prevent_b2c_purchase']) && !$is_non_eu_user && (empty($vat_number) || $no_vat)) { |
|
1829 | + if ($is_eu_state) { |
|
1830 | + wpinv_set_error('vat_validation', wp_sprintf(__('Please enter and validate your %s number to verify your purchase is by an EU business.', 'invoicing'), $vat_name)); |
|
1831 | + } else if ($is_digital && $is_eu_state_ip) { |
|
1832 | + wpinv_set_error('vat_validation', wp_sprintf(__('Sales to non-EU countries cannot be completed because %s must be applied.', 'invoicing'), $vat_name)); |
|
1833 | 1833 | } |
1834 | 1834 | } |
1835 | 1835 | |
1836 | - if ( !$is_eu_state || $no_vat || empty( $vat_number ) ) { |
|
1836 | + if (!$is_eu_state || $no_vat || empty($vat_number)) { |
|
1837 | 1837 | return; |
1838 | 1838 | } |
1839 | 1839 | |
1840 | - if ( !empty( $vat_saved ) && isset( $vat_saved['valid'] ) ) { |
|
1841 | - $vat_data['valid'] = $vat_saved['valid']; |
|
1840 | + if (!empty($vat_saved) && isset($vat_saved['valid'])) { |
|
1841 | + $vat_data['valid'] = $vat_saved['valid']; |
|
1842 | 1842 | } |
1843 | 1843 | |
1844 | - if ( $company !== null ) { |
|
1844 | + if ($company !== null) { |
|
1845 | 1845 | $vat_data['company'] = $company; |
1846 | 1846 | } |
1847 | 1847 | |
1848 | 1848 | $message = ''; |
1849 | - if ( $vat_number !== null ) { |
|
1849 | + if ($vat_number !== null) { |
|
1850 | 1850 | $vat_data['number'] = $vat_number; |
1851 | 1851 | |
1852 | - if ( !$vat_data['valid'] || ( $vat_saved['number'] !== $vat_data['number'] ) || ( $vat_saved['company'] !== $vat_data['company'] ) ) { |
|
1853 | - if ( !empty( $wpinv_options['vat_vies_check'] ) ) { |
|
1854 | - if ( empty( $wpinv_options['vat_offline_check'] ) && !self::offline_check( $vat_number ) ) { |
|
1852 | + if (!$vat_data['valid'] || ($vat_saved['number'] !== $vat_data['number']) || ($vat_saved['company'] !== $vat_data['company'])) { |
|
1853 | + if (!empty($wpinv_options['vat_vies_check'])) { |
|
1854 | + if (empty($wpinv_options['vat_offline_check']) && !self::offline_check($vat_number)) { |
|
1855 | 1855 | $vat_data['valid'] = false; |
1856 | 1856 | } |
1857 | 1857 | } else { |
1858 | - $result = self::check_vat( $vat_number ); |
|
1858 | + $result = self::check_vat($vat_number); |
|
1859 | 1859 | |
1860 | - if ( !empty( $result['valid'] ) ) { |
|
1860 | + if (!empty($result['valid'])) { |
|
1861 | 1861 | $vat_data['valid'] = true; |
1862 | - $vies_company = !empty( $result['company'] ) ? $result['company'] : ''; |
|
1863 | - $vies_company = apply_filters( 'wpinv_vies_company_name', $vies_company ); |
|
1862 | + $vies_company = !empty($result['company']) ? $result['company'] : ''; |
|
1863 | + $vies_company = apply_filters('wpinv_vies_company_name', $vies_company); |
|
1864 | 1864 | |
1865 | - $valid_company = $vies_company && $company && ( $vies_company == '---' || strcasecmp( trim( $vies_company ), trim( $company ) ) == 0 ) ? true : false; |
|
1865 | + $valid_company = $vies_company && $company && ($vies_company == '---' || strcasecmp(trim($vies_company), trim($company)) == 0) ? true : false; |
|
1866 | 1866 | |
1867 | - if ( !( !empty( $wpinv_options['vat_disable_company_name_check'] ) || $valid_company ) ) { |
|
1867 | + if (!(!empty($wpinv_options['vat_disable_company_name_check']) || $valid_company)) { |
|
1868 | 1868 | $vat_data['valid'] = false; |
1869 | 1869 | |
1870 | - $message = wp_sprintf( __( 'The company name associated with the %s number provided is not the same as the company name provided.', 'invoicing' ), $vat_name ); |
|
1870 | + $message = wp_sprintf(__('The company name associated with the %s number provided is not the same as the company name provided.', 'invoicing'), $vat_name); |
|
1871 | 1871 | } |
1872 | 1872 | } else { |
1873 | - $message = wp_sprintf( __( 'Fail to validate the %s number: EU Commission VAT server (VIES) check fails.', 'invoicing' ), $vat_name ); |
|
1873 | + $message = wp_sprintf(__('Fail to validate the %s number: EU Commission VAT server (VIES) check fails.', 'invoicing'), $vat_name); |
|
1874 | 1874 | } |
1875 | 1875 | } |
1876 | 1876 | |
1877 | - if ( !$vat_data['valid'] ) { |
|
1878 | - $error = wp_sprintf( __( 'The %s %s number %s you have entered has not been validated', 'invoicing' ), '<a href="#wpi-vat-details">', $vat_name, '</a>' ) . ( $message ? ' ( ' . $message . ' )' : '' ); |
|
1879 | - wpinv_set_error( 'vat_validation', $error ); |
|
1877 | + if (!$vat_data['valid']) { |
|
1878 | + $error = wp_sprintf(__('The %s %s number %s you have entered has not been validated', 'invoicing'), '<a href="#wpi-vat-details">', $vat_name, '</a>') . ($message ? ' ( ' . $message . ' )' : ''); |
|
1879 | + wpinv_set_error('vat_validation', $error); |
|
1880 | 1880 | } |
1881 | 1881 | } |
1882 | 1882 | } |
1883 | 1883 | |
1884 | - $wpi_session->set( 'user_vat_data', $vat_data ); |
|
1884 | + $wpi_session->set('user_vat_data', $vat_data); |
|
1885 | 1885 | } |
1886 | 1886 | |
1887 | - public static function checkout_vat_fields( $billing_details ) { |
|
1887 | + public static function checkout_vat_fields($billing_details) { |
|
1888 | 1888 | global $wpi_session, $wpinv_options, $wpi_country, $wpi_requires_vat; |
1889 | 1889 | |
1890 | 1890 | $ip_address = wpinv_get_ip(); |
1891 | 1891 | $ip_country_code = self::get_country_by_ip(); |
1892 | 1892 | |
1893 | - $tax_label = __( self::get_vat_name(), 'invoicing' ); |
|
1893 | + $tax_label = __(self::get_vat_name(), 'invoicing'); |
|
1894 | 1894 | $invoice = wpinv_get_invoice_cart(); |
1895 | - $is_digital = self::invoice_has_digital_rule( $invoice ); |
|
1895 | + $is_digital = self::invoice_has_digital_rule($invoice); |
|
1896 | 1896 | $wpi_country = $invoice->country; |
1897 | 1897 | |
1898 | - $requires_vat = !self::hide_vat_fields() && $invoice->get_total() > 0 && self::requires_vat( 0, false, $is_digital ); |
|
1898 | + $requires_vat = !self::hide_vat_fields() && $invoice->get_total() > 0 && self::requires_vat(0, false, $is_digital); |
|
1899 | 1899 | $wpi_requires_vat = $requires_vat; |
1900 | 1900 | |
1901 | 1901 | $company = is_user_logged_in() ? self::get_user_company() : ''; |
1902 | 1902 | $vat_number = self::get_user_vat_number(); |
1903 | 1903 | |
1904 | - $validated = $vat_number ? self::get_user_vat_number( '', 0, true ) : 1; |
|
1905 | - $vat_info = $wpi_session->get( 'user_vat_data' ); |
|
1904 | + $validated = $vat_number ? self::get_user_vat_number('', 0, true) : 1; |
|
1905 | + $vat_info = $wpi_session->get('user_vat_data'); |
|
1906 | 1906 | |
1907 | - if ( is_array( $vat_info ) ) { |
|
1908 | - $company = isset( $vat_info['company'] ) ? $vat_info['company'] : ''; |
|
1909 | - $vat_number = isset( $vat_info['number'] ) ? $vat_info['number'] : ''; |
|
1910 | - $validated = isset( $vat_info['valid'] ) ? $vat_info['valid'] : false; |
|
1907 | + if (is_array($vat_info)) { |
|
1908 | + $company = isset($vat_info['company']) ? $vat_info['company'] : ''; |
|
1909 | + $vat_number = isset($vat_info['number']) ? $vat_info['number'] : ''; |
|
1910 | + $validated = isset($vat_info['valid']) ? $vat_info['valid'] : false; |
|
1911 | 1911 | } |
1912 | 1912 | |
1913 | 1913 | $selected_country = $invoice->country ? $invoice->country : wpinv_default_billing_country(); |
1914 | 1914 | |
1915 | - if ( $ip_country_code == 'UK' ) { |
|
1915 | + if ($ip_country_code == 'UK') { |
|
1916 | 1916 | $ip_country_code = 'GB'; |
1917 | 1917 | } |
1918 | 1918 | |
1919 | - if ( $selected_country == 'UK' ) { |
|
1919 | + if ($selected_country == 'UK') { |
|
1920 | 1920 | $selected_country = 'GB'; |
1921 | 1921 | } |
1922 | 1922 | |
1923 | - if ( $requires_vat && ( self::same_country_rule() == 'no' && wpinv_is_base_country( $selected_country ) || !self::allow_vat_rules() ) ) { |
|
1923 | + if ($requires_vat && (self::same_country_rule() == 'no' && wpinv_is_base_country($selected_country) || !self::allow_vat_rules())) { |
|
1924 | 1924 | $requires_vat = false; |
1925 | 1925 | } |
1926 | 1926 | |
@@ -1928,52 +1928,52 @@ discard block |
||
1928 | 1928 | $display_validate_btn = 'none'; |
1929 | 1929 | $display_reset_btn = 'none'; |
1930 | 1930 | |
1931 | - if ( !empty( $vat_number ) && $validated ) { |
|
1932 | - $vat_vailidated_text = wp_sprintf( __( '%s number validated', 'invoicing' ), $tax_label ); |
|
1931 | + if (!empty($vat_number) && $validated) { |
|
1932 | + $vat_vailidated_text = wp_sprintf(__('%s number validated', 'invoicing'), $tax_label); |
|
1933 | 1933 | $vat_vailidated_class = 'wpinv-vat-stat-1'; |
1934 | 1934 | $display_reset_btn = 'block'; |
1935 | 1935 | } else { |
1936 | - $vat_vailidated_text = empty( $vat_number ) ? '' : wp_sprintf( __( '%s number not validated', 'invoicing' ), $tax_label ); |
|
1937 | - $vat_vailidated_class = empty( $vat_number ) ? '' : 'wpinv-vat-stat-0'; |
|
1936 | + $vat_vailidated_text = empty($vat_number) ? '' : wp_sprintf(__('%s number not validated', 'invoicing'), $tax_label); |
|
1937 | + $vat_vailidated_class = empty($vat_number) ? '' : 'wpinv-vat-stat-0'; |
|
1938 | 1938 | $display_validate_btn = 'block'; |
1939 | 1939 | } |
1940 | 1940 | |
1941 | - $show_ip_country = $is_digital && ( empty( $vat_number ) || !$requires_vat ) && $ip_country_code != $selected_country ? 'block' : 'none'; |
|
1941 | + $show_ip_country = $is_digital && (empty($vat_number) || !$requires_vat) && $ip_country_code != $selected_country ? 'block' : 'none'; |
|
1942 | 1942 | ?> |
1943 | 1943 | <div id="wpi-vat-details" class="wpi-vat-details clearfix" style="display:<?php echo $display_vat_details; ?>"> |
1944 | 1944 | <div id="wpi_vat_info" class="clearfix panel panel-default"> |
1945 | - <div class="panel-heading"><h3 class="panel-title"><?php echo wp_sprintf( __( '%s Details', 'invoicing' ), $tax_label );?></h3></div> |
|
1945 | + <div class="panel-heading"><h3 class="panel-title"><?php echo wp_sprintf(__('%s Details', 'invoicing'), $tax_label); ?></h3></div> |
|
1946 | 1946 | <div id="wpinv-fields-box" class="panel-body"> |
1947 | 1947 | <p id="wpi_show_vat_note"> |
1948 | - <?php echo wp_sprintf( __( 'Validate your registered %s number to exclude tax.', 'invoicing' ), $tax_label ); ?> |
|
1948 | + <?php echo wp_sprintf(__('Validate your registered %s number to exclude tax.', 'invoicing'), $tax_label); ?> |
|
1949 | 1949 | </p> |
1950 | 1950 | <div id="wpi_vat_fields" class="wpi_vat_info"> |
1951 | 1951 | <p class="wpi-cart-field wpi-col2 wpi-colf"> |
1952 | - <label for="wpinv_company" class="wpi-label"><?php _e( 'Company Name', 'invoicing' );?></label> |
|
1952 | + <label for="wpinv_company" class="wpi-label"><?php _e('Company Name', 'invoicing'); ?></label> |
|
1953 | 1953 | <?php |
1954 | - echo wpinv_html_text( array( |
|
1954 | + echo wpinv_html_text(array( |
|
1955 | 1955 | 'id' => 'wpinv_company', |
1956 | 1956 | 'name' => 'wpinv_company', |
1957 | 1957 | 'value' => $company, |
1958 | 1958 | 'class' => 'wpi-input form-control', |
1959 | - 'placeholder' => __( 'Company name', 'invoicing' ), |
|
1960 | - ) ); |
|
1959 | + 'placeholder' => __('Company name', 'invoicing'), |
|
1960 | + )); |
|
1961 | 1961 | ?> |
1962 | 1962 | </p> |
1963 | 1963 | <p class="wpi-cart-field wpi-col2 wpi-coll wpi-cart-field-vat"> |
1964 | - <label for="wpinv_vat_number" class="wpi-label"><?php echo wp_sprintf( __( '%s Number', 'invoicing' ), $tax_label );?></label> |
|
1964 | + <label for="wpinv_vat_number" class="wpi-label"><?php echo wp_sprintf(__('%s Number', 'invoicing'), $tax_label); ?></label> |
|
1965 | 1965 | <span id="wpinv_vat_number-wrap"> |
1966 | 1966 | <label for="wpinv_vat_number" class="wpinv-label"></label> |
1967 | - <input type="text" class="wpi-input form-control" placeholder="<?php echo esc_attr( wp_sprintf( __( '%s number', 'invoicing' ), $tax_label ) );?>" value="<?php esc_attr_e( $vat_number );?>" id="wpinv_vat_number" name="wpinv_vat_number"> |
|
1968 | - <span class="wpinv-vat-stat <?php echo $vat_vailidated_class;?>"><i class="fa"></i> <font><?php echo $vat_vailidated_text;?></font></span> |
|
1967 | + <input type="text" class="wpi-input form-control" placeholder="<?php echo esc_attr(wp_sprintf(__('%s number', 'invoicing'), $tax_label)); ?>" value="<?php esc_attr_e($vat_number); ?>" id="wpinv_vat_number" name="wpinv_vat_number"> |
|
1968 | + <span class="wpinv-vat-stat <?php echo $vat_vailidated_class; ?>"><i class="fa"></i> <font><?php echo $vat_vailidated_text; ?></font></span> |
|
1969 | 1969 | </span> |
1970 | 1970 | </p> |
1971 | 1971 | <p class="wpi-cart-field wpi-col wpi-colf wpi-cart-field-actions"> |
1972 | - <button class="btn btn-success btn-sm wpinv-vat-validate" type="button" id="wpinv_vat_validate" style="display:<?php echo $display_validate_btn; ?>"><?php echo wp_sprintf( __("Validate %s Number", 'invoicing'), $tax_label ); ?></button> |
|
1973 | - <button class="btn btn-danger btn-sm wpinv-vat-reset" type="button" id="wpinv_vat_reset" style="display:<?php echo $display_reset_btn; ?>"><?php echo wp_sprintf( __("Reset %s", 'invoicing'), $tax_label ); ?></button> |
|
1972 | + <button class="btn btn-success btn-sm wpinv-vat-validate" type="button" id="wpinv_vat_validate" style="display:<?php echo $display_validate_btn; ?>"><?php echo wp_sprintf(__("Validate %s Number", 'invoicing'), $tax_label); ?></button> |
|
1973 | + <button class="btn btn-danger btn-sm wpinv-vat-reset" type="button" id="wpinv_vat_reset" style="display:<?php echo $display_reset_btn; ?>"><?php echo wp_sprintf(__("Reset %s", 'invoicing'), $tax_label); ?></button> |
|
1974 | 1974 | <span class="wpi-vat-box wpi-vat-box-info"><span id="text"></span></span> |
1975 | 1975 | <span class="wpi-vat-box wpi-vat-box-error"><span id="text"></span></span> |
1976 | - <input type="hidden" name="_wpi_nonce" value="<?php echo wp_create_nonce( 'vat_validation' ) ?>" /> |
|
1976 | + <input type="hidden" name="_wpi_nonce" value="<?php echo wp_create_nonce('vat_validation') ?>" /> |
|
1977 | 1977 | </p> |
1978 | 1978 | </div> |
1979 | 1979 | </div> |
@@ -1987,32 +1987,32 @@ discard block |
||
1987 | 1987 | </span> |
1988 | 1988 | </div> |
1989 | 1989 | </div> |
1990 | - <?php if ( empty( $wpinv_options['hide_ip_address'] ) ) { |
|
1991 | - $ip_link = '<a title="' . esc_attr( __( 'View more details on map', 'invoicing' ) ) . '" target="_blank" href="' . esc_url( admin_url( 'admin-ajax.php?action=wpinv_ip_geolocation&ip=' . $ip_address ) ) . '" class="wpi-ip-address-link">' . $ip_address . ' <i class="fa fa-external-link-square" aria-hidden="true"></i></a>'; |
|
1990 | + <?php if (empty($wpinv_options['hide_ip_address'])) { |
|
1991 | + $ip_link = '<a title="' . esc_attr(__('View more details on map', 'invoicing')) . '" target="_blank" href="' . esc_url(admin_url('admin-ajax.php?action=wpinv_ip_geolocation&ip=' . $ip_address)) . '" class="wpi-ip-address-link">' . $ip_address . ' <i class="fa fa-external-link-square" aria-hidden="true"></i></a>'; |
|
1992 | 1992 | ?> |
1993 | 1993 | <div class="wpi-ip-info clearfix panel panel-info"> |
1994 | 1994 | <div id="wpinv-fields-box" class="panel-body"> |
1995 | - <span><?php echo wp_sprintf( __( "Your IP address is: %s", 'invoicing' ), $ip_link ); ?></span> |
|
1995 | + <span><?php echo wp_sprintf(__("Your IP address is: %s", 'invoicing'), $ip_link); ?></span> |
|
1996 | 1996 | </div> |
1997 | 1997 | </div> |
1998 | 1998 | <?php } |
1999 | 1999 | } |
2000 | 2000 | |
2001 | - public static function show_vat_notice( $invoice ) { |
|
2002 | - if ( empty( $invoice ) ) { |
|
2001 | + public static function show_vat_notice($invoice) { |
|
2002 | + if (empty($invoice)) { |
|
2003 | 2003 | return NULL; |
2004 | 2004 | } |
2005 | 2005 | |
2006 | - $label = wpinv_get_option( 'vat_invoice_notice_label' ); |
|
2007 | - $notice = wpinv_get_option( 'vat_invoice_notice' ); |
|
2008 | - if ( $label || $notice ) { |
|
2006 | + $label = wpinv_get_option('vat_invoice_notice_label'); |
|
2007 | + $notice = wpinv_get_option('vat_invoice_notice'); |
|
2008 | + if ($label || $notice) { |
|
2009 | 2009 | ?> |
2010 | 2010 | <div class="row wpinv-vat-notice"> |
2011 | 2011 | <div class="col-sm-12"> |
2012 | - <?php if ( $label ) { ?> |
|
2013 | - <strong><?php _e( $label, 'invoicing' ); ?></strong> |
|
2014 | - <?php } if ( $notice ) { ?> |
|
2015 | - <?php echo wpautop( wptexturize( __( $notice, 'invoicing' ) ) ) ?> |
|
2012 | + <?php if ($label) { ?> |
|
2013 | + <strong><?php _e($label, 'invoicing'); ?></strong> |
|
2014 | + <?php } if ($notice) { ?> |
|
2015 | + <?php echo wpautop(wptexturize(__($notice, 'invoicing'))) ?> |
|
2016 | 2016 | <?php } ?> |
2017 | 2017 | </div> |
2018 | 2018 | </div> |
@@ -7,105 +7,105 @@ 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 | -if ( !is_admin() ) { |
|
15 | - add_filter( 'template_include', 'wpinv_template', 10, 1 ); |
|
16 | - add_action( 'wpinv_invoice_print_body_start', 'wpinv_display_invoice_top_bar' ); |
|
17 | - add_action( 'wpinv_invoice_top_bar_left', 'wpinv_invoice_display_left_actions' ); |
|
18 | - add_action( 'wpinv_invoice_top_bar_right', 'wpinv_invoice_display_right_actions' ); |
|
14 | +if (!is_admin()) { |
|
15 | + add_filter('template_include', 'wpinv_template', 10, 1); |
|
16 | + add_action('wpinv_invoice_print_body_start', 'wpinv_display_invoice_top_bar'); |
|
17 | + add_action('wpinv_invoice_top_bar_left', 'wpinv_invoice_display_left_actions'); |
|
18 | + add_action('wpinv_invoice_top_bar_right', 'wpinv_invoice_display_right_actions'); |
|
19 | 19 | } |
20 | 20 | |
21 | 21 | function wpinv_template_path() { |
22 | - return apply_filters( 'wpinv_template_path', 'invoicing/' ); |
|
22 | + return apply_filters('wpinv_template_path', 'invoicing/'); |
|
23 | 23 | } |
24 | 24 | |
25 | -function wpinv_post_class( $classes, $class, $post_id ) { |
|
25 | +function wpinv_post_class($classes, $class, $post_id) { |
|
26 | 26 | global $pagenow, $typenow; |
27 | 27 | |
28 | - if ( $pagenow == 'edit.php' && $typenow == 'wpi_item' && get_post_type( $post_id ) == $typenow && get_post_meta( $post_id, '_wpinv_type', true ) == 'package' ) { |
|
28 | + if ($pagenow == 'edit.php' && $typenow == 'wpi_item' && get_post_type($post_id) == $typenow && get_post_meta($post_id, '_wpinv_type', true) == 'package') { |
|
29 | 29 | $classes[] = 'wpi-gd-package'; |
30 | 30 | } |
31 | 31 | return $classes; |
32 | 32 | } |
33 | -add_filter( 'post_class', 'wpinv_post_class', 10, 3 ); |
|
33 | +add_filter('post_class', 'wpinv_post_class', 10, 3); |
|
34 | 34 | |
35 | -function wpinv_display_invoice_top_bar( $invoice ) { |
|
36 | - if ( empty( $invoice ) ) { |
|
35 | +function wpinv_display_invoice_top_bar($invoice) { |
|
36 | + if (empty($invoice)) { |
|
37 | 37 | return; |
38 | 38 | } |
39 | 39 | ?> |
40 | 40 | <div class="row wpinv-top-bar no-print"> |
41 | 41 | <div class="container"> |
42 | 42 | <div class="col-xs-6"> |
43 | - <?php do_action( 'wpinv_invoice_top_bar_left', $invoice );?> |
|
43 | + <?php do_action('wpinv_invoice_top_bar_left', $invoice); ?> |
|
44 | 44 | </div> |
45 | 45 | <div class="col-xs-6 text-right"> |
46 | - <?php do_action( 'wpinv_invoice_top_bar_right', $invoice );?> |
|
46 | + <?php do_action('wpinv_invoice_top_bar_right', $invoice); ?> |
|
47 | 47 | </div> |
48 | 48 | </div> |
49 | 49 | </div> |
50 | 50 | <?php |
51 | 51 | } |
52 | 52 | |
53 | -function wpinv_invoice_display_left_actions( $invoice ) { |
|
54 | - if ( empty( $invoice ) ) { |
|
53 | +function wpinv_invoice_display_left_actions($invoice) { |
|
54 | + if (empty($invoice)) { |
|
55 | 55 | return; |
56 | 56 | } |
57 | 57 | |
58 | 58 | $user_id = (int)$invoice->get_user_id(); |
59 | 59 | $current_user_id = (int)get_current_user_id(); |
60 | 60 | |
61 | - if ( $user_id > 0 && $user_id == $current_user_id && $invoice->needs_payment() ) { |
|
61 | + if ($user_id > 0 && $user_id == $current_user_id && $invoice->needs_payment()) { |
|
62 | 62 | ?> |
63 | - <a class="btn btn-success btn-sm" title="<?php esc_attr_e( 'Pay This Invoice', 'invoicing' ); ?>" href="<?php echo esc_url( $invoice->get_checkout_payment_url() ); ?>"><?php _e( 'Pay For Invoice', 'invoicing' ); ?></a> |
|
63 | + <a class="btn btn-success btn-sm" title="<?php esc_attr_e('Pay This Invoice', 'invoicing'); ?>" href="<?php echo esc_url($invoice->get_checkout_payment_url()); ?>"><?php _e('Pay For Invoice', 'invoicing'); ?></a> |
|
64 | 64 | <?php |
65 | 65 | } |
66 | 66 | } |
67 | 67 | |
68 | -function wpinv_invoice_display_right_actions( $invoice ) { |
|
69 | - if ( empty( $invoice ) ) { |
|
68 | +function wpinv_invoice_display_right_actions($invoice) { |
|
69 | + if (empty($invoice)) { |
|
70 | 70 | return; |
71 | 71 | } |
72 | 72 | |
73 | 73 | $user_id = (int)$invoice->get_user_id(); |
74 | 74 | $current_user_id = (int)get_current_user_id(); |
75 | 75 | |
76 | - if ( $user_id > 0 && $user_id == $current_user_id ) { |
|
76 | + if ($user_id > 0 && $user_id == $current_user_id) { |
|
77 | 77 | ?> |
78 | - <a class="btn btn-primary btn-sm" onclick="window.print();" href="javascript:void(0)"><?php _e( 'Print Invoice', 'invoicing' ); ?></a> |
|
79 | - <a class="btn btn-warning btn-sm" href="<?php echo esc_url( wpinv_get_history_page_uri() ); ?>"><?php _e( 'Invoice History', 'invoicing' ); ?></a> |
|
78 | + <a class="btn btn-primary btn-sm" onclick="window.print();" href="javascript:void(0)"><?php _e('Print Invoice', 'invoicing'); ?></a> |
|
79 | + <a class="btn btn-warning btn-sm" href="<?php echo esc_url(wpinv_get_history_page_uri()); ?>"><?php _e('Invoice History', 'invoicing'); ?></a> |
|
80 | 80 | <?php } ?> |
81 | 81 | <?php |
82 | 82 | } |
83 | 83 | |
84 | -function wpinv_before_invoice_content( $content ) { |
|
84 | +function wpinv_before_invoice_content($content) { |
|
85 | 85 | global $post; |
86 | 86 | |
87 | - if ( $post && $post->post_type == 'wpi_invoice' && is_singular( 'wpi_invoice' ) && is_main_query() ) { |
|
87 | + if ($post && $post->post_type == 'wpi_invoice' && is_singular('wpi_invoice') && is_main_query()) { |
|
88 | 88 | ob_start(); |
89 | - do_action( 'wpinv_before_invoice_content', $post->ID ); |
|
89 | + do_action('wpinv_before_invoice_content', $post->ID); |
|
90 | 90 | $content = ob_get_clean() . $content; |
91 | 91 | } |
92 | 92 | |
93 | 93 | return $content; |
94 | 94 | } |
95 | -add_filter( 'the_content', 'wpinv_before_invoice_content' ); |
|
95 | +add_filter('the_content', 'wpinv_before_invoice_content'); |
|
96 | 96 | |
97 | -function wpinv_after_invoice_content( $content ) { |
|
97 | +function wpinv_after_invoice_content($content) { |
|
98 | 98 | global $post; |
99 | 99 | |
100 | - if ( $post && $post->post_type == 'wpi_invoice' && is_singular( 'wpi_invoice' ) && is_main_query() ) { |
|
100 | + if ($post && $post->post_type == 'wpi_invoice' && is_singular('wpi_invoice') && is_main_query()) { |
|
101 | 101 | ob_start(); |
102 | - do_action( 'wpinv_after_invoice_content', $post->ID ); |
|
102 | + do_action('wpinv_after_invoice_content', $post->ID); |
|
103 | 103 | $content .= ob_get_clean(); |
104 | 104 | } |
105 | 105 | |
106 | 106 | return $content; |
107 | 107 | } |
108 | -add_filter( 'the_content', 'wpinv_after_invoice_content' ); |
|
108 | +add_filter('the_content', 'wpinv_after_invoice_content'); |
|
109 | 109 | |
110 | 110 | function wpinv_get_templates_dir() { |
111 | 111 | return WPINV_PLUGIN_DIR . 'templates'; |
@@ -115,105 +115,105 @@ discard block |
||
115 | 115 | return WPINV_PLUGIN_URL . 'templates'; |
116 | 116 | } |
117 | 117 | |
118 | -function wpinv_get_template( $template_name, $args = array(), $template_path = '', $default_path = '' ) { |
|
119 | - if ( ! empty( $args ) && is_array( $args ) ) { |
|
120 | - extract( $args ); |
|
118 | +function wpinv_get_template($template_name, $args = array(), $template_path = '', $default_path = '') { |
|
119 | + if (!empty($args) && is_array($args)) { |
|
120 | + extract($args); |
|
121 | 121 | } |
122 | 122 | |
123 | - $located = wpinv_locate_template( $template_name, $template_path, $default_path ); |
|
124 | - if ( ! file_exists( $located ) ) { |
|
125 | - _doing_it_wrong( __FUNCTION__, sprintf( '<code>%s</code> does not exist.', $located ), '2.1' ); |
|
123 | + $located = wpinv_locate_template($template_name, $template_path, $default_path); |
|
124 | + if (!file_exists($located)) { |
|
125 | + _doing_it_wrong(__FUNCTION__, sprintf('<code>%s</code> does not exist.', $located), '2.1'); |
|
126 | 126 | return; |
127 | 127 | } |
128 | 128 | |
129 | 129 | // Allow 3rd party plugin filter template file from their plugin. |
130 | - $located = apply_filters( 'wpinv_get_template', $located, $template_name, $args, $template_path, $default_path ); |
|
130 | + $located = apply_filters('wpinv_get_template', $located, $template_name, $args, $template_path, $default_path); |
|
131 | 131 | |
132 | - do_action( 'wpinv_before_template_part', $template_name, $template_path, $located, $args ); |
|
132 | + do_action('wpinv_before_template_part', $template_name, $template_path, $located, $args); |
|
133 | 133 | |
134 | - include( $located ); |
|
134 | + include($located); |
|
135 | 135 | |
136 | - do_action( 'wpinv_after_template_part', $template_name, $template_path, $located, $args ); |
|
136 | + do_action('wpinv_after_template_part', $template_name, $template_path, $located, $args); |
|
137 | 137 | } |
138 | 138 | |
139 | -function wpinv_get_template_html( $template_name, $args = array(), $template_path = '', $default_path = '' ) { |
|
139 | +function wpinv_get_template_html($template_name, $args = array(), $template_path = '', $default_path = '') { |
|
140 | 140 | ob_start(); |
141 | - wpinv_get_template( $template_name, $args, $template_path, $default_path ); |
|
141 | + wpinv_get_template($template_name, $args, $template_path, $default_path); |
|
142 | 142 | return ob_get_clean(); |
143 | 143 | } |
144 | 144 | |
145 | -function wpinv_locate_template( $template_name, $template_path = '', $default_path = '' ) { |
|
146 | - if ( ! $template_path ) { |
|
145 | +function wpinv_locate_template($template_name, $template_path = '', $default_path = '') { |
|
146 | + if (!$template_path) { |
|
147 | 147 | $template_path = wpinv_template_path(); |
148 | 148 | } |
149 | 149 | |
150 | - if ( ! $default_path ) { |
|
150 | + if (!$default_path) { |
|
151 | 151 | $default_path = WPINV_PLUGIN_DIR . 'templates/'; |
152 | 152 | } |
153 | 153 | |
154 | 154 | // Look within passed path within the theme - this is priority. |
155 | 155 | $template = locate_template( |
156 | 156 | array( |
157 | - trailingslashit( $template_path ) . $template_name, |
|
157 | + trailingslashit($template_path) . $template_name, |
|
158 | 158 | $template_name |
159 | 159 | ) |
160 | 160 | ); |
161 | 161 | |
162 | 162 | // Get default templates/ |
163 | - if ( !$template && $default_path ) { |
|
164 | - $template = trailingslashit( $default_path ) . $template_name; |
|
163 | + if (!$template && $default_path) { |
|
164 | + $template = trailingslashit($default_path) . $template_name; |
|
165 | 165 | } |
166 | 166 | |
167 | 167 | // Return what we found. |
168 | - return apply_filters( 'wpinv_locate_template', $template, $template_name, $template_path ); |
|
168 | + return apply_filters('wpinv_locate_template', $template, $template_name, $template_path); |
|
169 | 169 | } |
170 | 170 | |
171 | -function wpinv_get_template_part( $slug, $name = null, $load = true ) { |
|
172 | - do_action( 'get_template_part_' . $slug, $slug, $name ); |
|
171 | +function wpinv_get_template_part($slug, $name = null, $load = true) { |
|
172 | + do_action('get_template_part_' . $slug, $slug, $name); |
|
173 | 173 | |
174 | 174 | // Setup possible parts |
175 | 175 | $templates = array(); |
176 | - if ( isset( $name ) ) |
|
176 | + if (isset($name)) |
|
177 | 177 | $templates[] = $slug . '-' . $name . '.php'; |
178 | 178 | $templates[] = $slug . '.php'; |
179 | 179 | |
180 | 180 | // Allow template parts to be filtered |
181 | - $templates = apply_filters( 'wpinv_get_template_part', $templates, $slug, $name ); |
|
181 | + $templates = apply_filters('wpinv_get_template_part', $templates, $slug, $name); |
|
182 | 182 | |
183 | 183 | // Return the part that is found |
184 | - return wpinv_locate_tmpl( $templates, $load, false ); |
|
184 | + return wpinv_locate_tmpl($templates, $load, false); |
|
185 | 185 | } |
186 | 186 | |
187 | -function wpinv_locate_tmpl( $template_names, $load = false, $require_once = true ) { |
|
187 | +function wpinv_locate_tmpl($template_names, $load = false, $require_once = true) { |
|
188 | 188 | // No file found yet |
189 | 189 | $located = false; |
190 | 190 | |
191 | 191 | // Try to find a template file |
192 | - foreach ( (array)$template_names as $template_name ) { |
|
192 | + foreach ((array)$template_names as $template_name) { |
|
193 | 193 | |
194 | 194 | // Continue if template is empty |
195 | - if ( empty( $template_name ) ) |
|
195 | + if (empty($template_name)) |
|
196 | 196 | continue; |
197 | 197 | |
198 | 198 | // Trim off any slashes from the template name |
199 | - $template_name = ltrim( $template_name, '/' ); |
|
199 | + $template_name = ltrim($template_name, '/'); |
|
200 | 200 | |
201 | 201 | // try locating this template file by looping through the template paths |
202 | - foreach( wpinv_get_theme_template_paths() as $template_path ) { |
|
202 | + foreach (wpinv_get_theme_template_paths() as $template_path) { |
|
203 | 203 | |
204 | - if( file_exists( $template_path . $template_name ) ) { |
|
204 | + if (file_exists($template_path . $template_name)) { |
|
205 | 205 | $located = $template_path . $template_name; |
206 | 206 | break; |
207 | 207 | } |
208 | 208 | } |
209 | 209 | |
210 | - if( !empty( $located ) ) { |
|
210 | + if (!empty($located)) { |
|
211 | 211 | break; |
212 | 212 | } |
213 | 213 | } |
214 | 214 | |
215 | - if ( ( true == $load ) && ! empty( $located ) ) |
|
216 | - load_template( $located, $require_once ); |
|
215 | + if ((true == $load) && !empty($located)) |
|
216 | + load_template($located, $require_once); |
|
217 | 217 | |
218 | 218 | return $located; |
219 | 219 | } |
@@ -222,143 +222,143 @@ discard block |
||
222 | 222 | $template_dir = wpinv_get_theme_template_dir_name(); |
223 | 223 | |
224 | 224 | $file_paths = array( |
225 | - 1 => trailingslashit( get_stylesheet_directory() ) . $template_dir, |
|
226 | - 10 => trailingslashit( get_template_directory() ) . $template_dir, |
|
225 | + 1 => trailingslashit(get_stylesheet_directory()) . $template_dir, |
|
226 | + 10 => trailingslashit(get_template_directory()) . $template_dir, |
|
227 | 227 | 100 => wpinv_get_templates_dir() |
228 | 228 | ); |
229 | 229 | |
230 | - $file_paths = apply_filters( 'wpinv_template_paths', $file_paths ); |
|
230 | + $file_paths = apply_filters('wpinv_template_paths', $file_paths); |
|
231 | 231 | |
232 | 232 | // sort the file paths based on priority |
233 | - ksort( $file_paths, SORT_NUMERIC ); |
|
233 | + ksort($file_paths, SORT_NUMERIC); |
|
234 | 234 | |
235 | - return array_map( 'trailingslashit', $file_paths ); |
|
235 | + return array_map('trailingslashit', $file_paths); |
|
236 | 236 | } |
237 | 237 | |
238 | 238 | function wpinv_get_theme_template_dir_name() { |
239 | - return trailingslashit( apply_filters( 'wpinv_templates_dir', 'wpinv_templates' ) ); |
|
239 | + return trailingslashit(apply_filters('wpinv_templates_dir', 'wpinv_templates')); |
|
240 | 240 | } |
241 | 241 | |
242 | 242 | function wpinv_checkout_meta_tags() { |
243 | 243 | |
244 | 244 | $pages = array(); |
245 | - $pages[] = wpinv_get_option( 'success_page' ); |
|
246 | - $pages[] = wpinv_get_option( 'failure_page' ); |
|
247 | - $pages[] = wpinv_get_option( 'invoice_history_page' ); |
|
245 | + $pages[] = wpinv_get_option('success_page'); |
|
246 | + $pages[] = wpinv_get_option('failure_page'); |
|
247 | + $pages[] = wpinv_get_option('invoice_history_page'); |
|
248 | 248 | |
249 | - if( !wpinv_is_checkout() && !is_page( $pages ) ) { |
|
249 | + if (!wpinv_is_checkout() && !is_page($pages)) { |
|
250 | 250 | return; |
251 | 251 | } |
252 | 252 | |
253 | 253 | echo '<meta name="robots" content="noindex,nofollow" />' . "\n"; |
254 | 254 | } |
255 | -add_action( 'wp_head', 'wpinv_checkout_meta_tags' ); |
|
255 | +add_action('wp_head', 'wpinv_checkout_meta_tags'); |
|
256 | 256 | |
257 | -function wpinv_add_body_classes( $class ) { |
|
257 | +function wpinv_add_body_classes($class) { |
|
258 | 258 | $classes = (array)$class; |
259 | 259 | |
260 | - if( wpinv_is_checkout() ) { |
|
260 | + if (wpinv_is_checkout()) { |
|
261 | 261 | $classes[] = 'wpinv-checkout'; |
262 | 262 | $classes[] = 'wpinv-page'; |
263 | 263 | } |
264 | 264 | |
265 | - if( wpinv_is_success_page() ) { |
|
265 | + if (wpinv_is_success_page()) { |
|
266 | 266 | $classes[] = 'wpinv-success'; |
267 | 267 | $classes[] = 'wpinv-page'; |
268 | 268 | } |
269 | 269 | |
270 | - if( wpinv_is_failed_transaction_page() ) { |
|
270 | + if (wpinv_is_failed_transaction_page()) { |
|
271 | 271 | $classes[] = 'wpinv-failed-transaction'; |
272 | 272 | $classes[] = 'wpinv-page'; |
273 | 273 | } |
274 | 274 | |
275 | - if( wpinv_is_invoice_history_page() ) { |
|
275 | + if (wpinv_is_invoice_history_page()) { |
|
276 | 276 | $classes[] = 'wpinv-history'; |
277 | 277 | $classes[] = 'wpinv-page'; |
278 | 278 | } |
279 | 279 | |
280 | - if( wpinv_is_test_mode() ) { |
|
280 | + if (wpinv_is_test_mode()) { |
|
281 | 281 | $classes[] = 'wpinv-test-mode'; |
282 | 282 | $classes[] = 'wpinv-page'; |
283 | 283 | } |
284 | 284 | |
285 | - return array_unique( $classes ); |
|
285 | + return array_unique($classes); |
|
286 | 286 | } |
287 | -add_filter( 'body_class', 'wpinv_add_body_classes' ); |
|
287 | +add_filter('body_class', 'wpinv_add_body_classes'); |
|
288 | 288 | |
289 | -function wpinv_html_dropdown( $name = 'wpinv_discounts', $selected = 0, $status = '' ) { |
|
290 | - $args = array( 'nopaging' => true ); |
|
289 | +function wpinv_html_dropdown($name = 'wpinv_discounts', $selected = 0, $status = '') { |
|
290 | + $args = array('nopaging' => true); |
|
291 | 291 | |
292 | - if ( ! empty( $status ) ) |
|
292 | + if (!empty($status)) |
|
293 | 293 | $args['post_status'] = $status; |
294 | 294 | |
295 | - $discounts = wpinv_get_discounts( $args ); |
|
295 | + $discounts = wpinv_get_discounts($args); |
|
296 | 296 | $options = array(); |
297 | 297 | |
298 | - if ( $discounts ) { |
|
299 | - foreach ( $discounts as $discount ) { |
|
300 | - $options[ absint( $discount->ID ) ] = esc_html( get_the_title( $discount->ID ) ); |
|
298 | + if ($discounts) { |
|
299 | + foreach ($discounts as $discount) { |
|
300 | + $options[absint($discount->ID)] = esc_html(get_the_title($discount->ID)); |
|
301 | 301 | } |
302 | 302 | } else { |
303 | - $options[0] = __( 'No discounts found', 'invoicing' ); |
|
303 | + $options[0] = __('No discounts found', 'invoicing'); |
|
304 | 304 | } |
305 | 305 | |
306 | - $output = wpinv_html_select( array( |
|
306 | + $output = wpinv_html_select(array( |
|
307 | 307 | 'name' => $name, |
308 | 308 | 'selected' => $selected, |
309 | 309 | 'options' => $options, |
310 | 310 | 'show_option_all' => false, |
311 | 311 | 'show_option_none' => false, |
312 | - ) ); |
|
312 | + )); |
|
313 | 313 | |
314 | 314 | return $output; |
315 | 315 | } |
316 | 316 | |
317 | -function wpinv_html_year_dropdown( $name = 'year', $selected = 0, $years_before = 5, $years_after = 0 ) { |
|
318 | - $current = date( 'Y' ); |
|
319 | - $start_year = $current - absint( $years_before ); |
|
320 | - $end_year = $current + absint( $years_after ); |
|
321 | - $selected = empty( $selected ) ? date( 'Y' ) : $selected; |
|
317 | +function wpinv_html_year_dropdown($name = 'year', $selected = 0, $years_before = 5, $years_after = 0) { |
|
318 | + $current = date('Y'); |
|
319 | + $start_year = $current - absint($years_before); |
|
320 | + $end_year = $current + absint($years_after); |
|
321 | + $selected = empty($selected) ? date('Y') : $selected; |
|
322 | 322 | $options = array(); |
323 | 323 | |
324 | - while ( $start_year <= $end_year ) { |
|
325 | - $options[ absint( $start_year ) ] = $start_year; |
|
324 | + while ($start_year <= $end_year) { |
|
325 | + $options[absint($start_year)] = $start_year; |
|
326 | 326 | $start_year++; |
327 | 327 | } |
328 | 328 | |
329 | - $output = wpinv_html_select( array( |
|
329 | + $output = wpinv_html_select(array( |
|
330 | 330 | 'name' => $name, |
331 | 331 | 'selected' => $selected, |
332 | 332 | 'options' => $options, |
333 | 333 | 'show_option_all' => false, |
334 | 334 | 'show_option_none' => false |
335 | - ) ); |
|
335 | + )); |
|
336 | 336 | |
337 | 337 | return $output; |
338 | 338 | } |
339 | 339 | |
340 | -function wpinv_html_month_dropdown( $name = 'month', $selected = 0 ) { |
|
340 | +function wpinv_html_month_dropdown($name = 'month', $selected = 0) { |
|
341 | 341 | $month = 1; |
342 | 342 | $options = array(); |
343 | - $selected = empty( $selected ) ? date( 'n' ) : $selected; |
|
343 | + $selected = empty($selected) ? date('n') : $selected; |
|
344 | 344 | |
345 | - while ( $month <= 12 ) { |
|
346 | - $options[ absint( $month ) ] = wpinv_month_num_to_name( $month ); |
|
345 | + while ($month <= 12) { |
|
346 | + $options[absint($month)] = wpinv_month_num_to_name($month); |
|
347 | 347 | $month++; |
348 | 348 | } |
349 | 349 | |
350 | - $output = wpinv_html_select( array( |
|
350 | + $output = wpinv_html_select(array( |
|
351 | 351 | 'name' => $name, |
352 | 352 | 'selected' => $selected, |
353 | 353 | 'options' => $options, |
354 | 354 | 'show_option_all' => false, |
355 | 355 | 'show_option_none' => false |
356 | - ) ); |
|
356 | + )); |
|
357 | 357 | |
358 | 358 | return $output; |
359 | 359 | } |
360 | 360 | |
361 | -function wpinv_html_select( $args = array() ) { |
|
361 | +function wpinv_html_select($args = array()) { |
|
362 | 362 | $defaults = array( |
363 | 363 | 'options' => array(), |
364 | 364 | 'name' => null, |
@@ -368,8 +368,8 @@ discard block |
||
368 | 368 | 'chosen' => false, |
369 | 369 | 'placeholder' => null, |
370 | 370 | 'multiple' => false, |
371 | - 'show_option_all' => _x( 'All', 'all dropdown items', 'invoicing' ), |
|
372 | - 'show_option_none' => _x( 'None', 'no dropdown items', 'invoicing' ), |
|
371 | + 'show_option_all' => _x('All', 'all dropdown items', 'invoicing'), |
|
372 | + 'show_option_none' => _x('None', 'no dropdown items', 'invoicing'), |
|
373 | 373 | 'data' => array(), |
374 | 374 | 'onchange' => null, |
375 | 375 | 'required' => false, |
@@ -377,78 +377,78 @@ discard block |
||
377 | 377 | 'readonly' => false, |
378 | 378 | ); |
379 | 379 | |
380 | - $args = wp_parse_args( $args, $defaults ); |
|
380 | + $args = wp_parse_args($args, $defaults); |
|
381 | 381 | |
382 | 382 | $data_elements = ''; |
383 | - foreach ( $args['data'] as $key => $value ) { |
|
384 | - $data_elements .= ' data-' . esc_attr( $key ) . '="' . esc_attr( $value ) . '"'; |
|
383 | + foreach ($args['data'] as $key => $value) { |
|
384 | + $data_elements .= ' data-' . esc_attr($key) . '="' . esc_attr($value) . '"'; |
|
385 | 385 | } |
386 | 386 | |
387 | - if( $args['multiple'] ) { |
|
387 | + if ($args['multiple']) { |
|
388 | 388 | $multiple = ' MULTIPLE'; |
389 | 389 | } else { |
390 | 390 | $multiple = ''; |
391 | 391 | } |
392 | 392 | |
393 | - if( $args['chosen'] ) { |
|
393 | + if ($args['chosen']) { |
|
394 | 394 | $args['class'] .= ' wpinv-select-chosen'; |
395 | 395 | } |
396 | 396 | |
397 | - if( $args['placeholder'] ) { |
|
397 | + if ($args['placeholder']) { |
|
398 | 398 | $placeholder = $args['placeholder']; |
399 | 399 | } else { |
400 | 400 | $placeholder = ''; |
401 | 401 | } |
402 | 402 | |
403 | 403 | $options = ''; |
404 | - if( !empty( $args['onchange'] ) ) { |
|
405 | - $options .= ' onchange="' . esc_attr( $args['onchange'] ) . '"'; |
|
404 | + if (!empty($args['onchange'])) { |
|
405 | + $options .= ' onchange="' . esc_attr($args['onchange']) . '"'; |
|
406 | 406 | } |
407 | 407 | |
408 | - if( !empty( $args['required'] ) ) { |
|
408 | + if (!empty($args['required'])) { |
|
409 | 409 | $options .= ' required="required"'; |
410 | 410 | } |
411 | 411 | |
412 | - if( !empty( $args['disabled'] ) ) { |
|
412 | + if (!empty($args['disabled'])) { |
|
413 | 413 | $options .= ' disabled'; |
414 | 414 | } |
415 | 415 | |
416 | - if( !empty( $args['readonly'] ) ) { |
|
416 | + if (!empty($args['readonly'])) { |
|
417 | 417 | $options .= ' readonly'; |
418 | 418 | } |
419 | 419 | |
420 | - $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) ); |
|
421 | - $output = '<select name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['id'] ) . '" class="wpinv-select ' . $class . '"' . $multiple . ' data-placeholder="' . $placeholder . '" ' . trim( $options ) . $data_elements . '>'; |
|
420 | + $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class']))); |
|
421 | + $output = '<select name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['id']) . '" class="wpinv-select ' . $class . '"' . $multiple . ' data-placeholder="' . $placeholder . '" ' . trim($options) . $data_elements . '>'; |
|
422 | 422 | |
423 | - if ( $args['show_option_all'] ) { |
|
424 | - if( $args['multiple'] ) { |
|
425 | - $selected = selected( true, in_array( 0, $args['selected'] ), false ); |
|
423 | + if ($args['show_option_all']) { |
|
424 | + if ($args['multiple']) { |
|
425 | + $selected = selected(true, in_array(0, $args['selected']), false); |
|
426 | 426 | } else { |
427 | - $selected = selected( $args['selected'], 0, false ); |
|
427 | + $selected = selected($args['selected'], 0, false); |
|
428 | 428 | } |
429 | - $output .= '<option value="all"' . $selected . '>' . esc_html( $args['show_option_all'] ) . '</option>'; |
|
429 | + $output .= '<option value="all"' . $selected . '>' . esc_html($args['show_option_all']) . '</option>'; |
|
430 | 430 | } |
431 | 431 | |
432 | - if ( !empty( $args['options'] ) ) { |
|
432 | + if (!empty($args['options'])) { |
|
433 | 433 | |
434 | - if ( $args['show_option_none'] ) { |
|
435 | - if( $args['multiple'] ) { |
|
436 | - $selected = selected( true, in_array( "", $args['selected'] ), false ); |
|
434 | + if ($args['show_option_none']) { |
|
435 | + if ($args['multiple']) { |
|
436 | + $selected = selected(true, in_array("", $args['selected']), false); |
|
437 | 437 | } else { |
438 | - $selected = selected( $args['selected'] === "", true, false ); |
|
438 | + $selected = selected($args['selected'] === "", true, false); |
|
439 | 439 | } |
440 | - $output .= '<option value=""' . $selected . '>' . esc_html( $args['show_option_none'] ) . '</option>'; |
|
440 | + $output .= '<option value=""' . $selected . '>' . esc_html($args['show_option_none']) . '</option>'; |
|
441 | 441 | } |
442 | 442 | |
443 | - foreach( $args['options'] as $key => $option ) { |
|
443 | + foreach ($args['options'] as $key => $option) { |
|
444 | 444 | |
445 | - if( $args['multiple'] && is_array( $args['selected'] ) ) { |
|
446 | - $selected = selected( true, (bool)in_array( $key, $args['selected'] ), false ); |
|
445 | + if ($args['multiple'] && is_array($args['selected'])) { |
|
446 | + $selected = selected(true, (bool)in_array($key, $args['selected']), false); |
|
447 | 447 | } else { |
448 | - $selected = selected( $args['selected'], $key, false ); |
|
448 | + $selected = selected($args['selected'], $key, false); |
|
449 | 449 | } |
450 | 450 | |
451 | - $output .= '<option value="' . esc_attr( $key ) . '"' . $selected . '>' . esc_html( $option ) . '</option>'; |
|
451 | + $output .= '<option value="' . esc_attr($key) . '"' . $selected . '>' . esc_html($option) . '</option>'; |
|
452 | 452 | } |
453 | 453 | } |
454 | 454 | |
@@ -457,7 +457,7 @@ discard block |
||
457 | 457 | return $output; |
458 | 458 | } |
459 | 459 | |
460 | -function wpinv_item_dropdown( $args = array() ) { |
|
460 | +function wpinv_item_dropdown($args = array()) { |
|
461 | 461 | $defaults = array( |
462 | 462 | 'name' => 'wpi_item', |
463 | 463 | 'id' => 'wpi_item', |
@@ -466,15 +466,15 @@ discard block |
||
466 | 466 | 'selected' => 0, |
467 | 467 | 'chosen' => false, |
468 | 468 | 'number' => 100, |
469 | - 'placeholder' => __( 'Choose a item', 'invoicing' ), |
|
470 | - 'data' => array( 'search-type' => 'item' ), |
|
469 | + 'placeholder' => __('Choose a item', 'invoicing'), |
|
470 | + 'data' => array('search-type' => 'item'), |
|
471 | 471 | 'show_option_all' => false, |
472 | 472 | 'show_option_none' => false, |
473 | 473 | 'with_packages' => true, |
474 | 474 | 'show_recurring' => false, |
475 | 475 | ); |
476 | 476 | |
477 | - $args = wp_parse_args( $args, $defaults ); |
|
477 | + $args = wp_parse_args($args, $defaults); |
|
478 | 478 | |
479 | 479 | $item_args = array( |
480 | 480 | 'post_type' => 'wpi_item', |
@@ -483,7 +483,7 @@ discard block |
||
483 | 483 | 'posts_per_page' => $args['number'] |
484 | 484 | ); |
485 | 485 | |
486 | - if ( !$args['with_packages'] ) { |
|
486 | + if (!$args['with_packages']) { |
|
487 | 487 | $item_args['meta_query'] = array( |
488 | 488 | array( |
489 | 489 | 'key' => '_wpinv_type', |
@@ -493,42 +493,42 @@ discard block |
||
493 | 493 | ); |
494 | 494 | } |
495 | 495 | |
496 | - $items = get_posts( $item_args ); |
|
496 | + $items = get_posts($item_args); |
|
497 | 497 | $options = array(); |
498 | - if ( $items ) { |
|
499 | - foreach ( $items as $item ) { |
|
500 | - $title = esc_html( $item->post_title ); |
|
498 | + if ($items) { |
|
499 | + foreach ($items as $item) { |
|
500 | + $title = esc_html($item->post_title); |
|
501 | 501 | |
502 | - if ( !empty( $args['show_recurring'] ) ) { |
|
503 | - $title .= wpinv_get_item_suffix( $item->ID, false ); |
|
502 | + if (!empty($args['show_recurring'])) { |
|
503 | + $title .= wpinv_get_item_suffix($item->ID, false); |
|
504 | 504 | } |
505 | 505 | |
506 | - $options[ absint( $item->ID ) ] = $title; |
|
506 | + $options[absint($item->ID)] = $title; |
|
507 | 507 | } |
508 | 508 | } |
509 | 509 | |
510 | 510 | // This ensures that any selected items are included in the drop down |
511 | - if( is_array( $args['selected'] ) ) { |
|
512 | - foreach( $args['selected'] as $item ) { |
|
513 | - if( ! in_array( $item, $options ) ) { |
|
514 | - $title = get_the_title( $item ); |
|
515 | - if ( !empty( $args['show_recurring'] ) ) { |
|
516 | - $title .= wpinv_get_item_suffix( $item, false ); |
|
511 | + if (is_array($args['selected'])) { |
|
512 | + foreach ($args['selected'] as $item) { |
|
513 | + if (!in_array($item, $options)) { |
|
514 | + $title = get_the_title($item); |
|
515 | + if (!empty($args['show_recurring'])) { |
|
516 | + $title .= wpinv_get_item_suffix($item, false); |
|
517 | 517 | } |
518 | 518 | $options[$item] = $title; |
519 | 519 | } |
520 | 520 | } |
521 | - } elseif ( is_numeric( $args['selected'] ) && $args['selected'] !== 0 ) { |
|
522 | - if ( ! in_array( $args['selected'], $options ) ) { |
|
523 | - $title = get_the_title( $args['selected'] ); |
|
524 | - if ( !empty( $args['show_recurring'] ) ) { |
|
525 | - $title .= wpinv_get_item_suffix( $args['selected'], false ); |
|
521 | + } elseif (is_numeric($args['selected']) && $args['selected'] !== 0) { |
|
522 | + if (!in_array($args['selected'], $options)) { |
|
523 | + $title = get_the_title($args['selected']); |
|
524 | + if (!empty($args['show_recurring'])) { |
|
525 | + $title .= wpinv_get_item_suffix($args['selected'], false); |
|
526 | 526 | } |
527 | - $options[$args['selected']] = get_the_title( $args['selected'] ); |
|
527 | + $options[$args['selected']] = get_the_title($args['selected']); |
|
528 | 528 | } |
529 | 529 | } |
530 | 530 | |
531 | - $output = wpinv_html_select( array( |
|
531 | + $output = wpinv_html_select(array( |
|
532 | 532 | 'name' => $args['name'], |
533 | 533 | 'selected' => $args['selected'], |
534 | 534 | 'id' => $args['id'], |
@@ -540,12 +540,12 @@ discard block |
||
540 | 540 | 'show_option_all' => $args['show_option_all'], |
541 | 541 | 'show_option_none' => $args['show_option_none'], |
542 | 542 | 'data' => $args['data'], |
543 | - ) ); |
|
543 | + )); |
|
544 | 544 | |
545 | 545 | return $output; |
546 | 546 | } |
547 | 547 | |
548 | -function wpinv_html_checkbox( $args = array() ) { |
|
548 | +function wpinv_html_checkbox($args = array()) { |
|
549 | 549 | $defaults = array( |
550 | 550 | 'name' => null, |
551 | 551 | 'current' => null, |
@@ -556,38 +556,38 @@ discard block |
||
556 | 556 | ) |
557 | 557 | ); |
558 | 558 | |
559 | - $args = wp_parse_args( $args, $defaults ); |
|
559 | + $args = wp_parse_args($args, $defaults); |
|
560 | 560 | |
561 | - $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) ); |
|
561 | + $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class']))); |
|
562 | 562 | $options = ''; |
563 | - if ( ! empty( $args['options']['disabled'] ) ) { |
|
563 | + if (!empty($args['options']['disabled'])) { |
|
564 | 564 | $options .= ' disabled="disabled"'; |
565 | - } elseif ( ! empty( $args['options']['readonly'] ) ) { |
|
565 | + } elseif (!empty($args['options']['readonly'])) { |
|
566 | 566 | $options .= ' readonly'; |
567 | 567 | } |
568 | 568 | |
569 | - $output = '<input type="checkbox"' . $options . ' name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['name'] ) . '" class="' . $class . ' ' . esc_attr( $args['name'] ) . '" ' . checked( 1, $args['current'], false ) . ' />'; |
|
569 | + $output = '<input type="checkbox"' . $options . ' name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['name']) . '" class="' . $class . ' ' . esc_attr($args['name']) . '" ' . checked(1, $args['current'], false) . ' />'; |
|
570 | 570 | |
571 | 571 | return $output; |
572 | 572 | } |
573 | 573 | |
574 | -function wpinv_html_text( $args = array() ) { |
|
574 | +function wpinv_html_text($args = array()) { |
|
575 | 575 | // Backwards compatibility |
576 | - if ( func_num_args() > 1 ) { |
|
576 | + if (func_num_args() > 1) { |
|
577 | 577 | $args = func_get_args(); |
578 | 578 | |
579 | 579 | $name = $args[0]; |
580 | - $value = isset( $args[1] ) ? $args[1] : ''; |
|
581 | - $label = isset( $args[2] ) ? $args[2] : ''; |
|
582 | - $desc = isset( $args[3] ) ? $args[3] : ''; |
|
580 | + $value = isset($args[1]) ? $args[1] : ''; |
|
581 | + $label = isset($args[2]) ? $args[2] : ''; |
|
582 | + $desc = isset($args[3]) ? $args[3] : ''; |
|
583 | 583 | } |
584 | 584 | |
585 | 585 | $defaults = array( |
586 | 586 | 'id' => '', |
587 | - 'name' => isset( $name ) ? $name : 'text', |
|
588 | - 'value' => isset( $value ) ? $value : null, |
|
589 | - 'label' => isset( $label ) ? $label : null, |
|
590 | - 'desc' => isset( $desc ) ? $desc : null, |
|
587 | + 'name' => isset($name) ? $name : 'text', |
|
588 | + 'value' => isset($value) ? $value : null, |
|
589 | + 'label' => isset($label) ? $label : null, |
|
590 | + 'desc' => isset($desc) ? $desc : null, |
|
591 | 591 | 'placeholder' => '', |
592 | 592 | 'class' => 'regular-text', |
593 | 593 | 'disabled' => false, |
@@ -597,51 +597,51 @@ discard block |
||
597 | 597 | 'data' => false |
598 | 598 | ); |
599 | 599 | |
600 | - $args = wp_parse_args( $args, $defaults ); |
|
600 | + $args = wp_parse_args($args, $defaults); |
|
601 | 601 | |
602 | - $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) ); |
|
602 | + $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class']))); |
|
603 | 603 | $options = ''; |
604 | - if( $args['required'] ) { |
|
604 | + if ($args['required']) { |
|
605 | 605 | $options .= ' required="required"'; |
606 | 606 | } |
607 | - if( $args['readonly'] ) { |
|
607 | + if ($args['readonly']) { |
|
608 | 608 | $options .= ' readonly'; |
609 | 609 | } |
610 | - if( $args['readonly'] ) { |
|
610 | + if ($args['readonly']) { |
|
611 | 611 | $options .= ' readonly'; |
612 | 612 | } |
613 | 613 | |
614 | 614 | $data = ''; |
615 | - if ( !empty( $args['data'] ) ) { |
|
616 | - foreach ( $args['data'] as $key => $value ) { |
|
617 | - $data .= 'data-' . wpinv_sanitize_key( $key ) . '="' . esc_attr( $value ) . '" '; |
|
615 | + if (!empty($args['data'])) { |
|
616 | + foreach ($args['data'] as $key => $value) { |
|
617 | + $data .= 'data-' . wpinv_sanitize_key($key) . '="' . esc_attr($value) . '" '; |
|
618 | 618 | } |
619 | 619 | } |
620 | 620 | |
621 | - $output = '<span id="wpinv-' . wpinv_sanitize_key( $args['name'] ) . '-wrap">'; |
|
622 | - $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key( $args['id'] ) . '">' . esc_html( $args['label'] ) . '</label>'; |
|
623 | - if ( ! empty( $args['desc'] ) ) { |
|
624 | - $output .= '<span class="wpinv-description">' . esc_html( $args['desc'] ) . '</span>'; |
|
621 | + $output = '<span id="wpinv-' . wpinv_sanitize_key($args['name']) . '-wrap">'; |
|
622 | + $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key($args['id']) . '">' . esc_html($args['label']) . '</label>'; |
|
623 | + if (!empty($args['desc'])) { |
|
624 | + $output .= '<span class="wpinv-description">' . esc_html($args['desc']) . '</span>'; |
|
625 | 625 | } |
626 | 626 | |
627 | - $output .= '<input type="text" name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['id'] ) . '" autocomplete="' . esc_attr( $args['autocomplete'] ) . '" value="' . esc_attr( $args['value'] ) . '" placeholder="' . esc_attr( $args['placeholder'] ) . '" class="' . $class . '" ' . $data . ' ' . trim( $options ) . '/>'; |
|
627 | + $output .= '<input type="text" name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['id']) . '" autocomplete="' . esc_attr($args['autocomplete']) . '" value="' . esc_attr($args['value']) . '" placeholder="' . esc_attr($args['placeholder']) . '" class="' . $class . '" ' . $data . ' ' . trim($options) . '/>'; |
|
628 | 628 | |
629 | 629 | $output .= '</span>'; |
630 | 630 | |
631 | 631 | return $output; |
632 | 632 | } |
633 | 633 | |
634 | -function wpinv_html_date_field( $args = array() ) { |
|
635 | - if( empty( $args['class'] ) ) { |
|
634 | +function wpinv_html_date_field($args = array()) { |
|
635 | + if (empty($args['class'])) { |
|
636 | 636 | $args['class'] = 'wpiDatepicker'; |
637 | - } elseif( ! strpos( $args['class'], 'wpiDatepicker' ) ) { |
|
637 | + } elseif (!strpos($args['class'], 'wpiDatepicker')) { |
|
638 | 638 | $args['class'] .= ' wpiDatepicker'; |
639 | 639 | } |
640 | 640 | |
641 | - return wpinv_html_text( $args ); |
|
641 | + return wpinv_html_text($args); |
|
642 | 642 | } |
643 | 643 | |
644 | -function wpinv_html_textarea( $args = array() ) { |
|
644 | +function wpinv_html_textarea($args = array()) { |
|
645 | 645 | $defaults = array( |
646 | 646 | 'name' => 'textarea', |
647 | 647 | 'value' => null, |
@@ -651,31 +651,31 @@ discard block |
||
651 | 651 | 'disabled' => false |
652 | 652 | ); |
653 | 653 | |
654 | - $args = wp_parse_args( $args, $defaults ); |
|
654 | + $args = wp_parse_args($args, $defaults); |
|
655 | 655 | |
656 | - $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) ); |
|
656 | + $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class']))); |
|
657 | 657 | $disabled = ''; |
658 | - if( $args['disabled'] ) { |
|
658 | + if ($args['disabled']) { |
|
659 | 659 | $disabled = ' disabled="disabled"'; |
660 | 660 | } |
661 | 661 | |
662 | - $output = '<span id="wpinv-' . wpinv_sanitize_key( $args['name'] ) . '-wrap">'; |
|
663 | - $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key( $args['name'] ) . '">' . esc_html( $args['label'] ) . '</label>'; |
|
664 | - $output .= '<textarea name="' . esc_attr( $args['name'] ) . '" id="' . wpinv_sanitize_key( $args['name'] ) . '" class="' . $class . '"' . $disabled . '>' . esc_attr( $args['value'] ) . '</textarea>'; |
|
662 | + $output = '<span id="wpinv-' . wpinv_sanitize_key($args['name']) . '-wrap">'; |
|
663 | + $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key($args['name']) . '">' . esc_html($args['label']) . '</label>'; |
|
664 | + $output .= '<textarea name="' . esc_attr($args['name']) . '" id="' . wpinv_sanitize_key($args['name']) . '" class="' . $class . '"' . $disabled . '>' . esc_attr($args['value']) . '</textarea>'; |
|
665 | 665 | |
666 | - if ( ! empty( $args['desc'] ) ) { |
|
667 | - $output .= '<span class="wpinv-description">' . esc_html( $args['desc'] ) . '</span>'; |
|
666 | + if (!empty($args['desc'])) { |
|
667 | + $output .= '<span class="wpinv-description">' . esc_html($args['desc']) . '</span>'; |
|
668 | 668 | } |
669 | 669 | $output .= '</span>'; |
670 | 670 | |
671 | 671 | return $output; |
672 | 672 | } |
673 | 673 | |
674 | -function wpinv_html_ajax_user_search( $args = array() ) { |
|
674 | +function wpinv_html_ajax_user_search($args = array()) { |
|
675 | 675 | $defaults = array( |
676 | 676 | 'name' => 'user_id', |
677 | 677 | 'value' => null, |
678 | - 'placeholder' => __( 'Enter username', 'invoicing' ), |
|
678 | + 'placeholder' => __('Enter username', 'invoicing'), |
|
679 | 679 | 'label' => null, |
680 | 680 | 'desc' => null, |
681 | 681 | 'class' => '', |
@@ -684,13 +684,13 @@ discard block |
||
684 | 684 | 'data' => false |
685 | 685 | ); |
686 | 686 | |
687 | - $args = wp_parse_args( $args, $defaults ); |
|
687 | + $args = wp_parse_args($args, $defaults); |
|
688 | 688 | |
689 | 689 | $args['class'] = 'wpinv-ajax-user-search ' . $args['class']; |
690 | 690 | |
691 | 691 | $output = '<span class="wpinv_user_search_wrap">'; |
692 | - $output .= wpinv_html_text( $args ); |
|
693 | - $output .= '<span class="wpinv_user_search_results hidden"><a class="wpinv-ajax-user-cancel" title="' . __( 'Cancel', 'invoicing' ) . '" aria-label="' . __( 'Cancel', 'invoicing' ) . '" href="#">x</a><span></span></span>'; |
|
692 | + $output .= wpinv_html_text($args); |
|
693 | + $output .= '<span class="wpinv_user_search_results hidden"><a class="wpinv-ajax-user-cancel" title="' . __('Cancel', 'invoicing') . '" aria-label="' . __('Cancel', 'invoicing') . '" href="#">x</a><span></span></span>'; |
|
694 | 694 | $output .= '</span>'; |
695 | 695 | |
696 | 696 | return $output; |
@@ -699,7 +699,7 @@ discard block |
||
699 | 699 | function wpinv_ip_geolocation() { |
700 | 700 | global $wpinv_euvat; |
701 | 701 | |
702 | - $ip = !empty( $_GET['ip'] ) ? sanitize_text_field( $_GET['ip'] ) : ''; |
|
702 | + $ip = !empty($_GET['ip']) ? sanitize_text_field($_GET['ip']) : ''; |
|
703 | 703 | $content = ''; |
704 | 704 | $iso = ''; |
705 | 705 | $country = ''; |
@@ -710,69 +710,69 @@ discard block |
||
710 | 710 | $credit = ''; |
711 | 711 | $address = ''; |
712 | 712 | |
713 | - if ( wpinv_get_option( 'vat_ip_lookup' ) == 'geoip2' && $geoip2_city = $wpinv_euvat->geoip2_city_record( $ip ) ) { |
|
713 | + if (wpinv_get_option('vat_ip_lookup') == 'geoip2' && $geoip2_city = $wpinv_euvat->geoip2_city_record($ip)) { |
|
714 | 714 | try { |
715 | 715 | $iso = $geoip2_city->country->isoCode; |
716 | 716 | $country = $geoip2_city->country->name; |
717 | - $region = !empty( $geoip2_city->subdivisions ) && !empty( $geoip2_city->subdivisions[0]->name ) ? $geoip2_city->subdivisions[0]->name : ''; |
|
717 | + $region = !empty($geoip2_city->subdivisions) && !empty($geoip2_city->subdivisions[0]->name) ? $geoip2_city->subdivisions[0]->name : ''; |
|
718 | 718 | $city = $geoip2_city->city->name; |
719 | 719 | $longitude = $geoip2_city->location->longitude; |
720 | 720 | $latitude = $geoip2_city->location->latitude; |
721 | - $credit = __( 'Geolocated using the information by MaxMind, available from <a href="http://www.maxmind.com" target="_blank">www.maxmind.com</a>', 'invoicing' ); |
|
722 | - } catch( Exception $e ) { } |
|
721 | + $credit = __('Geolocated using the information by MaxMind, available from <a href="http://www.maxmind.com" target="_blank">www.maxmind.com</a>', 'invoicing'); |
|
722 | + } catch (Exception $e) { } |
|
723 | 723 | } |
724 | 724 | |
725 | - if ( !( $iso && $longitude && $latitude ) && function_exists( 'simplexml_load_file' ) ) { |
|
725 | + if (!($iso && $longitude && $latitude) && function_exists('simplexml_load_file')) { |
|
726 | 726 | try { |
727 | - $load_xml = simplexml_load_file( 'http://www.geoplugin.net/xml.gp?ip=' . $ip ); |
|
727 | + $load_xml = simplexml_load_file('http://www.geoplugin.net/xml.gp?ip=' . $ip); |
|
728 | 728 | |
729 | - if ( !empty( $load_xml ) && isset( $load_xml->geoplugin_countryCode ) && !empty( $load_xml->geoplugin_latitude ) && !empty( $load_xml->geoplugin_longitude ) ) { |
|
729 | + if (!empty($load_xml) && isset($load_xml->geoplugin_countryCode) && !empty($load_xml->geoplugin_latitude) && !empty($load_xml->geoplugin_longitude)) { |
|
730 | 730 | $iso = $load_xml->geoplugin_countryCode; |
731 | 731 | $country = $load_xml->geoplugin_countryName; |
732 | - $region = !empty( $load_xml->geoplugin_regionName ) ? $load_xml->geoplugin_regionName : ''; |
|
733 | - $city = !empty( $load_xml->geoplugin_city ) ? $load_xml->geoplugin_city : ''; |
|
732 | + $region = !empty($load_xml->geoplugin_regionName) ? $load_xml->geoplugin_regionName : ''; |
|
733 | + $city = !empty($load_xml->geoplugin_city) ? $load_xml->geoplugin_city : ''; |
|
734 | 734 | $longitude = $load_xml->geoplugin_longitude; |
735 | 735 | $latitude = $load_xml->geoplugin_latitude; |
736 | 736 | $credit = $load_xml->geoplugin_credit; |
737 | - $credit = __( 'Geolocated using the information by geoPlugin, available from <a href="http://www.geoplugin.com" target="_blank">www.geoplugin.com</a>', 'invoicing' ) . '<br>' . $load_xml->geoplugin_credit; |
|
737 | + $credit = __('Geolocated using the information by geoPlugin, available from <a href="http://www.geoplugin.com" target="_blank">www.geoplugin.com</a>', 'invoicing') . '<br>' . $load_xml->geoplugin_credit; |
|
738 | 738 | } |
739 | - } catch( Exception $e ) { } |
|
739 | + } catch (Exception $e) { } |
|
740 | 740 | } |
741 | 741 | |
742 | - if ( $iso && $longitude && $latitude ) { |
|
743 | - if ( $city ) { |
|
742 | + if ($iso && $longitude && $latitude) { |
|
743 | + if ($city) { |
|
744 | 744 | $address .= $city . ', '; |
745 | 745 | } |
746 | 746 | |
747 | - if ( $region ) { |
|
747 | + if ($region) { |
|
748 | 748 | $address .= $region . ', '; |
749 | 749 | } |
750 | 750 | |
751 | 751 | $address .= $country . ' (' . $iso . ')'; |
752 | - $content = '<p>'. sprintf( __( '<b>Address:</b> %s', 'invoicing' ), $address ) . '</p>'; |
|
753 | - $content .= '<p>'. $credit . '</p>'; |
|
752 | + $content = '<p>' . sprintf(__('<b>Address:</b> %s', 'invoicing'), $address) . '</p>'; |
|
753 | + $content .= '<p>' . $credit . '</p>'; |
|
754 | 754 | } else { |
755 | - $content = '<p>'. sprintf( __( 'Unable to find geolocation for the IP address: %s', 'invoicing' ), $ip ) . '</p>'; |
|
755 | + $content = '<p>' . sprintf(__('Unable to find geolocation for the IP address: %s', 'invoicing'), $ip) . '</p>'; |
|
756 | 756 | } |
757 | 757 | ?> |
758 | 758 | <!DOCTYPE html> |
759 | -<html><head><title><?php echo sprintf( __( 'IP: %s', 'invoicing' ), $ip );?></title><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"><link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/leaflet/1.0.0-rc.1/leaflet.css" /><style>html,body{height:100%;margin:0;padding:0;width:100%}body{text-align:center;background:#fff;color:#222;font-size:small;}body,p{font-family: arial,sans-serif}#map{margin:auto;width:100%;height:calc(100% - 120px);min-height:240px}</style></head> |
|
759 | +<html><head><title><?php echo sprintf(__('IP: %s', 'invoicing'), $ip); ?></title><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"><link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/leaflet/1.0.0-rc.1/leaflet.css" /><style>html,body{height:100%;margin:0;padding:0;width:100%}body{text-align:center;background:#fff;color:#222;font-size:small;}body,p{font-family: arial,sans-serif}#map{margin:auto;width:100%;height:calc(100% - 120px);min-height:240px}</style></head> |
|
760 | 760 | <body> |
761 | - <?php if ( $latitude && $latitude ) { ?> |
|
761 | + <?php if ($latitude && $latitude) { ?> |
|
762 | 762 | <div id="map"></div> |
763 | 763 | <script src="//cdnjs.cloudflare.com/ajax/libs/leaflet/1.0.0-rc.1/leaflet.js"></script> |
764 | 764 | <script type="text/javascript"> |
765 | 765 | var osmUrl = 'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', |
766 | 766 | osmAttrib = '© <a href="http://openstreetmap.org/copyright">OpenStreetMap</a> contributors', |
767 | 767 | osm = L.tileLayer(osmUrl, {maxZoom: 18, attribution: osmAttrib}), |
768 | - latlng = new L.LatLng(<?php echo $latitude;?>, <?php echo $longitude;?>); |
|
768 | + latlng = new L.LatLng(<?php echo $latitude; ?>, <?php echo $longitude; ?>); |
|
769 | 769 | |
770 | 770 | var map = new L.Map('map', {center: latlng, zoom: 12, layers: [osm]}); |
771 | 771 | |
772 | 772 | var marker = new L.Marker(latlng); |
773 | 773 | map.addLayer(marker); |
774 | 774 | |
775 | - marker.bindPopup("<p><?php esc_attr_e( $address );?></p>"); |
|
775 | + marker.bindPopup("<p><?php esc_attr_e($address); ?></p>"); |
|
776 | 776 | </script> |
777 | 777 | <?php } ?> |
778 | 778 | <div style="height:100px"><?php echo $content; ?></div> |
@@ -780,31 +780,31 @@ discard block |
||
780 | 780 | <?php |
781 | 781 | exit; |
782 | 782 | } |
783 | -add_action( 'wp_ajax_wpinv_ip_geolocation', 'wpinv_ip_geolocation' ); |
|
784 | -add_action( 'wp_ajax_nopriv_wpinv_ip_geolocation', 'wpinv_ip_geolocation' ); |
|
783 | +add_action('wp_ajax_wpinv_ip_geolocation', 'wpinv_ip_geolocation'); |
|
784 | +add_action('wp_ajax_nopriv_wpinv_ip_geolocation', 'wpinv_ip_geolocation'); |
|
785 | 785 | |
786 | 786 | // Set up the template for the invoice. |
787 | -function wpinv_template( $template ) { |
|
787 | +function wpinv_template($template) { |
|
788 | 788 | global $post, $wp_query; |
789 | 789 | |
790 | - if ( ( is_single() || is_404() ) && !empty( $post->ID ) && get_post_type( $post->ID ) == 'wpi_invoice' ) { |
|
791 | - if ( wpinv_user_can_print_invoice( $post->ID ) ) { |
|
792 | - $template = wpinv_get_template_part( 'wpinv-invoice-print', false, false ); |
|
790 | + if ((is_single() || is_404()) && !empty($post->ID) && get_post_type($post->ID) == 'wpi_invoice') { |
|
791 | + if (wpinv_user_can_print_invoice($post->ID)) { |
|
792 | + $template = wpinv_get_template_part('wpinv-invoice-print', false, false); |
|
793 | 793 | } else { |
794 | - if ( !is_user_logged_in() && !empty( $_REQUEST['_wpipay'] ) && $invoice = wpinv_get_invoice( $post->ID ) ) { |
|
794 | + if (!is_user_logged_in() && !empty($_REQUEST['_wpipay']) && $invoice = wpinv_get_invoice($post->ID)) { |
|
795 | 795 | $user_id = $invoice->get_user_id(); |
796 | - $secret = sanitize_text_field( $_GET['_wpipay'] ); |
|
796 | + $secret = sanitize_text_field($_GET['_wpipay']); |
|
797 | 797 | |
798 | - if ( $secret === md5( $user_id . '::' . $invoice->get_email() . '::' . $invoice->get_key() ) ) { // valid invoice link |
|
799 | - $redirect_to = remove_query_arg( '_wpipay', get_permalink() ); |
|
798 | + if ($secret === md5($user_id . '::' . $invoice->get_email() . '::' . $invoice->get_key())) { // valid invoice link |
|
799 | + $redirect_to = remove_query_arg('_wpipay', get_permalink()); |
|
800 | 800 | |
801 | - wpinv_guest_redirect( $redirect_to, $user_id ); |
|
801 | + wpinv_guest_redirect($redirect_to, $user_id); |
|
802 | 802 | wpinv_die(); |
803 | 803 | } |
804 | 804 | } |
805 | - $redirect_to = is_user_logged_in() ? wpinv_get_history_page_uri() : wp_login_url( get_permalink() ); |
|
805 | + $redirect_to = is_user_logged_in() ? wpinv_get_history_page_uri() : wp_login_url(get_permalink()); |
|
806 | 806 | |
807 | - wp_redirect( $redirect_to ); |
|
807 | + wp_redirect($redirect_to); |
|
808 | 808 | wpinv_die(); |
809 | 809 | } |
810 | 810 | } |
@@ -814,7 +814,7 @@ discard block |
||
814 | 814 | |
815 | 815 | function wpinv_get_business_address() { |
816 | 816 | $business_address = wpinv_store_address(); |
817 | - $business_address = !empty( $business_address ) ? wpautop( wp_kses_post( $business_address ) ) : ''; |
|
817 | + $business_address = !empty($business_address) ? wpautop(wp_kses_post($business_address)) : ''; |
|
818 | 818 | |
819 | 819 | /* |
820 | 820 | $default_country = wpinv_get_default_country(); |
@@ -838,7 +838,7 @@ discard block |
||
838 | 838 | |
839 | 839 | $business_address = $business_address ? '<div class="address">' . $business_address . '</div>' : ''; |
840 | 840 | |
841 | - return apply_filters( 'wpinv_get_business_address', $business_address ); |
|
841 | + return apply_filters('wpinv_get_business_address', $business_address); |
|
842 | 842 | } |
843 | 843 | |
844 | 844 | function wpinv_display_from_address() { |
@@ -848,182 +848,182 @@ discard block |
||
848 | 848 | if (empty($from_name)) { |
849 | 849 | $from_name = wpinv_get_business_name(); |
850 | 850 | } |
851 | - ?><div class="from col-xs-2"><strong><?php _e( 'From:', 'invoicing' ) ?></strong></div> |
|
851 | + ?><div class="from col-xs-2"><strong><?php _e('From:', 'invoicing') ?></strong></div> |
|
852 | 852 | <div class="wrapper col-xs-10"> |
853 | - <div class="name"><?php echo esc_html( $from_name ); ?></div> |
|
854 | - <?php if ( $address = wpinv_get_business_address() ) { ?> |
|
855 | - <div class="address"><?php echo wpautop( wp_kses_post( $address ) );?></div> |
|
853 | + <div class="name"><?php echo esc_html($from_name); ?></div> |
|
854 | + <?php if ($address = wpinv_get_business_address()) { ?> |
|
855 | + <div class="address"><?php echo wpautop(wp_kses_post($address)); ?></div> |
|
856 | 856 | <?php } ?> |
857 | - <?php if ( $email_from = wpinv_mail_get_from_address() ) { ?> |
|
858 | - <div class="email_from"><?php echo wp_sprintf( __( 'Email: %s' ), $email_from );?></div> |
|
857 | + <?php if ($email_from = wpinv_mail_get_from_address()) { ?> |
|
858 | + <div class="email_from"><?php echo wp_sprintf(__('Email: %s'), $email_from); ?></div> |
|
859 | 859 | <?php } ?> |
860 | 860 | </div> |
861 | 861 | <?php |
862 | 862 | } |
863 | 863 | |
864 | -function wpinv_watermark( $id = 0 ) { |
|
865 | - $output = wpinv_get_watermark( $id ); |
|
864 | +function wpinv_watermark($id = 0) { |
|
865 | + $output = wpinv_get_watermark($id); |
|
866 | 866 | |
867 | - return apply_filters( 'wpinv_get_watermark', $output, $id ); |
|
867 | + return apply_filters('wpinv_get_watermark', $output, $id); |
|
868 | 868 | } |
869 | 869 | |
870 | -function wpinv_get_watermark( $id ) { |
|
871 | - if ( !$id > 0 ) { |
|
870 | +function wpinv_get_watermark($id) { |
|
871 | + if (!$id > 0) { |
|
872 | 872 | return NULL; |
873 | 873 | } |
874 | - $invoice = wpinv_get_invoice( $id ); |
|
874 | + $invoice = wpinv_get_invoice($id); |
|
875 | 875 | |
876 | - if ( !empty( $invoice ) ) { |
|
877 | - if ( $invoice->is_paid() ) { |
|
878 | - return __( 'Paid', 'invoicing' ); |
|
876 | + if (!empty($invoice)) { |
|
877 | + if ($invoice->is_paid()) { |
|
878 | + return __('Paid', 'invoicing'); |
|
879 | 879 | } |
880 | - if ( $invoice->has_status( array( 'cancelled' ) ) ) { |
|
881 | - return __( 'Cancelled', 'invoicing' ); |
|
880 | + if ($invoice->has_status(array('cancelled'))) { |
|
881 | + return __('Cancelled', 'invoicing'); |
|
882 | 882 | } |
883 | 883 | } |
884 | 884 | |
885 | 885 | return NULL; |
886 | 886 | } |
887 | 887 | |
888 | -function wpinv_display_invoice_details( $invoice ) { |
|
888 | +function wpinv_display_invoice_details($invoice) { |
|
889 | 889 | global $wpinv_euvat; |
890 | 890 | |
891 | 891 | $invoice_id = $invoice->ID; |
892 | 892 | $vat_name = $wpinv_euvat->get_vat_name(); |
893 | 893 | $use_taxes = wpinv_use_taxes(); |
894 | 894 | |
895 | - $invoice_status = wpinv_get_invoice_status( $invoice_id ); |
|
895 | + $invoice_status = wpinv_get_invoice_status($invoice_id); |
|
896 | 896 | ?> |
897 | 897 | <table class="table table-bordered table-sm"> |
898 | - <?php if ( $invoice_number = wpinv_get_invoice_number( $invoice_id ) ) { ?> |
|
898 | + <?php if ($invoice_number = wpinv_get_invoice_number($invoice_id)) { ?> |
|
899 | 899 | <tr class="wpi-row-number"> |
900 | - <th><?php _e( 'Invoice Number', 'invoicing' ); ?></th> |
|
901 | - <td><?php echo esc_html( $invoice_number ); ?></td> |
|
900 | + <th><?php _e('Invoice Number', 'invoicing'); ?></th> |
|
901 | + <td><?php echo esc_html($invoice_number); ?></td> |
|
902 | 902 | </tr> |
903 | 903 | <?php } ?> |
904 | 904 | <tr class="wpi-row-status"> |
905 | - <th><?php _e( 'Invoice Status', 'invoicing' ); ?></th> |
|
906 | - <td><?php echo wpinv_invoice_status_label( $invoice_status, wpinv_get_invoice_status( $invoice_id, true ) ); ?></td> |
|
905 | + <th><?php _e('Invoice Status', 'invoicing'); ?></th> |
|
906 | + <td><?php echo wpinv_invoice_status_label($invoice_status, wpinv_get_invoice_status($invoice_id, true)); ?></td> |
|
907 | 907 | </tr> |
908 | - <?php if ( $invoice->is_renewal() ) { ?> |
|
908 | + <?php if ($invoice->is_renewal()) { ?> |
|
909 | 909 | <tr class="wpi-row-parent"> |
910 | - <th><?php _e( 'Parent Invoice', 'invoicing' ); ?></th> |
|
911 | - <td><?php echo wpinv_invoice_link( $invoice->parent_invoice ); ?></td> |
|
910 | + <th><?php _e('Parent Invoice', 'invoicing'); ?></th> |
|
911 | + <td><?php echo wpinv_invoice_link($invoice->parent_invoice); ?></td> |
|
912 | 912 | </tr> |
913 | 913 | <?php } ?> |
914 | 914 | <tr class="wpi-row-gateway"> |
915 | - <th><?php _e( 'Payment Method', 'invoicing' ); ?></th> |
|
916 | - <td><?php echo wpinv_get_payment_gateway_name( $invoice_id ); ?></td> |
|
915 | + <th><?php _e('Payment Method', 'invoicing'); ?></th> |
|
916 | + <td><?php echo wpinv_get_payment_gateway_name($invoice_id); ?></td> |
|
917 | 917 | </tr> |
918 | - <?php if ( $invoice_date = wpinv_get_invoice_date( $invoice_id ) ) { ?> |
|
918 | + <?php if ($invoice_date = wpinv_get_invoice_date($invoice_id)) { ?> |
|
919 | 919 | <tr class="wpi-row-date"> |
920 | - <th><?php _e( 'Invoice Date', 'invoicing' ); ?></th> |
|
920 | + <th><?php _e('Invoice Date', 'invoicing'); ?></th> |
|
921 | 921 | <td><?php echo $invoice_date; ?></td> |
922 | 922 | </tr> |
923 | 923 | <?php } ?> |
924 | - <?php if ( wpinv_get_option( 'overdue_active' ) && $invoice->needs_payment() && ( $due_date = $invoice->get_due_date( true ) ) ) { ?> |
|
924 | + <?php if (wpinv_get_option('overdue_active') && $invoice->needs_payment() && ($due_date = $invoice->get_due_date(true))) { ?> |
|
925 | 925 | <tr class="wpi-row-date"> |
926 | - <th><?php _e( 'Due Date', 'invoicing' ); ?></th> |
|
926 | + <th><?php _e('Due Date', 'invoicing'); ?></th> |
|
927 | 927 | <td><?php echo $due_date; ?></td> |
928 | 928 | </tr> |
929 | 929 | <?php } ?> |
930 | - <?php if ( $owner_vat_number = $wpinv_euvat->get_vat_number() ) { ?> |
|
930 | + <?php if ($owner_vat_number = $wpinv_euvat->get_vat_number()) { ?> |
|
931 | 931 | <tr class="wpi-row-ovatno"> |
932 | - <th><?php echo wp_sprintf( __( 'Owner %s Number', 'invoicing' ), $vat_name ); ?></th> |
|
932 | + <th><?php echo wp_sprintf(__('Owner %s Number', 'invoicing'), $vat_name); ?></th> |
|
933 | 933 | <td><?php echo $owner_vat_number; ?></td> |
934 | 934 | </tr> |
935 | 935 | <?php } ?> |
936 | - <?php if ( $use_taxes && $user_vat_number = wpinv_get_invoice_vat_number( $invoice_id ) ) { ?> |
|
936 | + <?php if ($use_taxes && $user_vat_number = wpinv_get_invoice_vat_number($invoice_id)) { ?> |
|
937 | 937 | <tr class="wpi-row-uvatno"> |
938 | - <th><?php echo wp_sprintf( __( 'Your %s Number', 'invoicing' ), $vat_name ); ?></th> |
|
938 | + <th><?php echo wp_sprintf(__('Your %s Number', 'invoicing'), $vat_name); ?></th> |
|
939 | 939 | <td><?php echo $user_vat_number; ?></td> |
940 | 940 | </tr> |
941 | 941 | <?php } ?> |
942 | 942 | <tr class="table-active tr-total wpi-row-total"> |
943 | - <th><strong><?php _e( 'Total Amount', 'invoicing' ) ?></strong></th> |
|
944 | - <td><strong><?php echo wpinv_payment_total( $invoice_id, true ); ?></strong></td> |
|
943 | + <th><strong><?php _e('Total Amount', 'invoicing') ?></strong></th> |
|
944 | + <td><strong><?php echo wpinv_payment_total($invoice_id, true); ?></strong></td> |
|
945 | 945 | </tr> |
946 | 946 | </table> |
947 | 947 | <?php |
948 | 948 | } |
949 | 949 | |
950 | -function wpinv_display_to_address( $invoice_id = 0 ) { |
|
951 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
950 | +function wpinv_display_to_address($invoice_id = 0) { |
|
951 | + $invoice = wpinv_get_invoice($invoice_id); |
|
952 | 952 | |
953 | - if ( empty( $invoice ) ) { |
|
953 | + if (empty($invoice)) { |
|
954 | 954 | return NULL; |
955 | 955 | } |
956 | 956 | |
957 | 957 | $billing_details = $invoice->get_user_info(); |
958 | - $output = '<div class="to col-xs-2"><strong>' . __( 'To:', 'invoicing' ) . '</strong></div>'; |
|
958 | + $output = '<div class="to col-xs-2"><strong>' . __('To:', 'invoicing') . '</strong></div>'; |
|
959 | 959 | $output .= '<div class="wrapper col-xs-10">'; |
960 | 960 | |
961 | 961 | ob_start(); |
962 | - do_action( 'wpinv_display_to_address_top', $invoice ); |
|
962 | + do_action('wpinv_display_to_address_top', $invoice); |
|
963 | 963 | $output .= ob_get_clean(); |
964 | 964 | |
965 | - $output .= '<div class="name">' . esc_html( trim( $billing_details['first_name'] . ' ' . $billing_details['last_name'] ) ) . '</div>'; |
|
966 | - if ( $company = $billing_details['company'] ) { |
|
967 | - $output .= '<div class="company">' . wpautop( wp_kses_post( $company ) ) . '</div>'; |
|
965 | + $output .= '<div class="name">' . esc_html(trim($billing_details['first_name'] . ' ' . $billing_details['last_name'])) . '</div>'; |
|
966 | + if ($company = $billing_details['company']) { |
|
967 | + $output .= '<div class="company">' . wpautop(wp_kses_post($company)) . '</div>'; |
|
968 | 968 | } |
969 | 969 | $address_row = ''; |
970 | - if ( $address = $billing_details['address'] ) { |
|
971 | - $address_row .= wpautop( wp_kses_post( $address ) ); |
|
970 | + if ($address = $billing_details['address']) { |
|
971 | + $address_row .= wpautop(wp_kses_post($address)); |
|
972 | 972 | } |
973 | 973 | |
974 | 974 | $address_fields = array(); |
975 | - if ( !empty( $billing_details['city'] ) ) { |
|
975 | + if (!empty($billing_details['city'])) { |
|
976 | 976 | $address_fields[] = $billing_details['city']; |
977 | 977 | } |
978 | 978 | |
979 | - $billing_country = !empty( $billing_details['country'] ) ? $billing_details['country'] : ''; |
|
980 | - if ( !empty( $billing_details['state'] ) ) { |
|
981 | - $address_fields[] = wpinv_state_name( $billing_details['state'], $billing_country ); |
|
979 | + $billing_country = !empty($billing_details['country']) ? $billing_details['country'] : ''; |
|
980 | + if (!empty($billing_details['state'])) { |
|
981 | + $address_fields[] = wpinv_state_name($billing_details['state'], $billing_country); |
|
982 | 982 | } |
983 | 983 | |
984 | - if ( !empty( $billing_country ) ) { |
|
985 | - $address_fields[] = wpinv_country_name( $billing_country ); |
|
984 | + if (!empty($billing_country)) { |
|
985 | + $address_fields[] = wpinv_country_name($billing_country); |
|
986 | 986 | } |
987 | 987 | |
988 | - if ( !empty( $address_fields ) ) { |
|
989 | - $address_fields = implode( ", ", $address_fields ); |
|
988 | + if (!empty($address_fields)) { |
|
989 | + $address_fields = implode(", ", $address_fields); |
|
990 | 990 | |
991 | - if ( !empty( $billing_details['zip'] ) ) { |
|
991 | + if (!empty($billing_details['zip'])) { |
|
992 | 992 | $address_fields .= ' ' . $billing_details['zip']; |
993 | 993 | } |
994 | 994 | |
995 | - $address_row .= wpautop( wp_kses_post( $address_fields ) ); |
|
995 | + $address_row .= wpautop(wp_kses_post($address_fields)); |
|
996 | 996 | } |
997 | 997 | |
998 | - if ( $address_row ) { |
|
998 | + if ($address_row) { |
|
999 | 999 | $output .= '<div class="address">' . $address_row . '</div>'; |
1000 | 1000 | } |
1001 | 1001 | |
1002 | - if ( $phone = $invoice->get_phone() ) { |
|
1003 | - $output .= '<div class="phone">' . wp_sprintf( __( 'Phone: %s' ), esc_html( $phone ) ) . '</div>'; |
|
1002 | + if ($phone = $invoice->get_phone()) { |
|
1003 | + $output .= '<div class="phone">' . wp_sprintf(__('Phone: %s'), esc_html($phone)) . '</div>'; |
|
1004 | 1004 | } |
1005 | - if ( $email = $invoice->get_email() ) { |
|
1006 | - $output .= '<div class="email">' . wp_sprintf( __( 'Email: %s' ), esc_html( $email ) ) . '</div>'; |
|
1005 | + if ($email = $invoice->get_email()) { |
|
1006 | + $output .= '<div class="email">' . wp_sprintf(__('Email: %s'), esc_html($email)) . '</div>'; |
|
1007 | 1007 | } |
1008 | 1008 | |
1009 | 1009 | ob_start(); |
1010 | - do_action( 'wpinv_display_to_address_bottom', $invoice ); |
|
1010 | + do_action('wpinv_display_to_address_bottom', $invoice); |
|
1011 | 1011 | $output .= ob_get_clean(); |
1012 | 1012 | |
1013 | 1013 | $output .= '</div>'; |
1014 | - $output = apply_filters( 'wpinv_display_to_address', $output, $invoice ); |
|
1014 | + $output = apply_filters('wpinv_display_to_address', $output, $invoice); |
|
1015 | 1015 | |
1016 | 1016 | echo $output; |
1017 | 1017 | } |
1018 | 1018 | |
1019 | -function wpinv_display_line_items( $invoice_id = 0 ) { |
|
1019 | +function wpinv_display_line_items($invoice_id = 0) { |
|
1020 | 1020 | global $wpinv_euvat, $ajax_cart_details; |
1021 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
1021 | + $invoice = wpinv_get_invoice($invoice_id); |
|
1022 | 1022 | $quantities_enabled = wpinv_item_quantities_enabled(); |
1023 | 1023 | $use_taxes = wpinv_use_taxes(); |
1024 | 1024 | $zero_tax = !(float)$invoice->get_tax() > 0 ? true : false; |
1025 | - $tax_label = $use_taxes && $invoice->has_vat() ? $wpinv_euvat->get_vat_name() : __( 'Tax', 'invoicing' ); |
|
1026 | - $tax_title = !$zero_tax && $use_taxes ? ( wpinv_prices_include_tax() ? wp_sprintf( __( '(%s Incl.)', 'invoicing' ), $tax_label ) : wp_sprintf( __( '(%s Excl.)', 'invoicing' ), $tax_label ) ) : ''; |
|
1025 | + $tax_label = $use_taxes && $invoice->has_vat() ? $wpinv_euvat->get_vat_name() : __('Tax', 'invoicing'); |
|
1026 | + $tax_title = !$zero_tax && $use_taxes ? (wpinv_prices_include_tax() ? wp_sprintf(__('(%s Incl.)', 'invoicing'), $tax_label) : wp_sprintf(__('(%s Excl.)', 'invoicing'), $tax_label)) : ''; |
|
1027 | 1027 | |
1028 | 1028 | $cart_details = $invoice->get_cart_details(); |
1029 | 1029 | $ajax_cart_details = $cart_details; |
@@ -1032,68 +1032,68 @@ discard block |
||
1032 | 1032 | <table class="table table-sm table-bordered table-responsive"> |
1033 | 1033 | <thead> |
1034 | 1034 | <tr> |
1035 | - <th class="name"><strong><?php _e( "Item Name", "invoicing" );?></strong></th> |
|
1036 | - <th class="rate"><strong><?php _e( "Price", "invoicing" );?></strong></th> |
|
1035 | + <th class="name"><strong><?php _e("Item Name", "invoicing"); ?></strong></th> |
|
1036 | + <th class="rate"><strong><?php _e("Price", "invoicing"); ?></strong></th> |
|
1037 | 1037 | <?php if ($quantities_enabled) { ?> |
1038 | - <th class="qty"><strong><?php _e( "Qty", "invoicing" );?></strong></th> |
|
1038 | + <th class="qty"><strong><?php _e("Qty", "invoicing"); ?></strong></th> |
|
1039 | 1039 | <?php } ?> |
1040 | 1040 | <?php if ($use_taxes && !$zero_tax) { ?> |
1041 | 1041 | <th class="tax"><strong><?php echo $tax_label . ' <span class="normal small">(%)</span>'; ?></strong></th> |
1042 | 1042 | <?php } ?> |
1043 | - <th class="total"><strong><?php echo __( "Item Total", "invoicing" ) . ' <span class="normal small">' . $tax_title . '<span>';?></strong></th> |
|
1043 | + <th class="total"><strong><?php echo __("Item Total", "invoicing") . ' <span class="normal small">' . $tax_title . '<span>'; ?></strong></th> |
|
1044 | 1044 | </tr> |
1045 | 1045 | </thead> |
1046 | 1046 | <tbody> |
1047 | 1047 | <?php |
1048 | - if ( !empty( $cart_details ) ) { |
|
1049 | - do_action( 'wpinv_display_line_items_start', $invoice ); |
|
1048 | + if (!empty($cart_details)) { |
|
1049 | + do_action('wpinv_display_line_items_start', $invoice); |
|
1050 | 1050 | |
1051 | 1051 | $count = 0; |
1052 | 1052 | $cols = 3; |
1053 | - foreach ( $cart_details as $key => $cart_item ) { |
|
1054 | - $item_id = !empty($cart_item['id']) ? absint( $cart_item['id'] ) : ''; |
|
1055 | - $item_price = isset($cart_item["item_price"]) ? wpinv_format_amount( $cart_item["item_price"] ) : 0; |
|
1056 | - $line_total = isset($cart_item["subtotal"]) ? wpinv_format_amount( $cart_item["subtotal"] ) : 0; |
|
1057 | - $quantity = !empty($cart_item['quantity']) && (int)$cart_item['quantity'] > 0 ? absint( $cart_item['quantity'] ) : 1; |
|
1053 | + foreach ($cart_details as $key => $cart_item) { |
|
1054 | + $item_id = !empty($cart_item['id']) ? absint($cart_item['id']) : ''; |
|
1055 | + $item_price = isset($cart_item["item_price"]) ? wpinv_format_amount($cart_item["item_price"]) : 0; |
|
1056 | + $line_total = isset($cart_item["subtotal"]) ? wpinv_format_amount($cart_item["subtotal"]) : 0; |
|
1057 | + $quantity = !empty($cart_item['quantity']) && (int)$cart_item['quantity'] > 0 ? absint($cart_item['quantity']) : 1; |
|
1058 | 1058 | |
1059 | - $item = $item_id ? new WPInv_Item( $item_id ) : NULL; |
|
1059 | + $item = $item_id ? new WPInv_Item($item_id) : NULL; |
|
1060 | 1060 | $summary = ''; |
1061 | 1061 | $cols = 3; |
1062 | - if ( !empty($item) ) { |
|
1062 | + if (!empty($item)) { |
|
1063 | 1063 | $item_name = $item->get_name(); |
1064 | 1064 | $summary = $item->get_summary(); |
1065 | 1065 | } |
1066 | - $item_name = !empty($cart_item['name']) ? $cart_item['name'] : $item_name; |
|
1066 | + $item_name = !empty($cart_item['name']) ? $cart_item['name'] : $item_name; |
|
1067 | 1067 | |
1068 | 1068 | if (!empty($item) && $item->is_package() && !empty($cart_item['meta']['post_id'])) { |
1069 | - $post_link = '<a href="' . get_edit_post_link( $cart_item['meta']['post_id'] ) .'" target="_blank">' . (!empty($cart_item['meta']['invoice_title']) ? $cart_item['meta']['invoice_title'] : get_the_title( $cart_item['meta']['post_id']) ) . '</a>'; |
|
1070 | - $summary = wp_sprintf( __( '%s: %s', 'invoicing' ), $item->get_cpt_singular_name(), $post_link ); |
|
1069 | + $post_link = '<a href="' . get_edit_post_link($cart_item['meta']['post_id']) . '" target="_blank">' . (!empty($cart_item['meta']['invoice_title']) ? $cart_item['meta']['invoice_title'] : get_the_title($cart_item['meta']['post_id'])) . '</a>'; |
|
1070 | + $summary = wp_sprintf(__('%s: %s', 'invoicing'), $item->get_cpt_singular_name(), $post_link); |
|
1071 | 1071 | } |
1072 | - $summary = apply_filters( 'wpinv_print_invoice_line_item_summary', $summary, $cart_item, $item, $invoice ); |
|
1072 | + $summary = apply_filters('wpinv_print_invoice_line_item_summary', $summary, $cart_item, $item, $invoice); |
|
1073 | 1073 | |
1074 | 1074 | $item_tax = ''; |
1075 | 1075 | $tax_rate = ''; |
1076 | - if ( $use_taxes && $cart_item['tax'] > 0 && $cart_item['subtotal'] > 0 ) { |
|
1077 | - $item_tax = wpinv_price( wpinv_format_amount( $cart_item['tax'] ) ); |
|
1078 | - $tax_rate = !empty( $cart_item['vat_rate'] ) ? $cart_item['vat_rate'] : ( $cart_item['tax'] / $cart_item['subtotal'] ) * 100; |
|
1079 | - $tax_rate = $tax_rate > 0 ? (float)wpinv_format_amount( $tax_rate, 2 ) : ''; |
|
1076 | + if ($use_taxes && $cart_item['tax'] > 0 && $cart_item['subtotal'] > 0) { |
|
1077 | + $item_tax = wpinv_price(wpinv_format_amount($cart_item['tax'])); |
|
1078 | + $tax_rate = !empty($cart_item['vat_rate']) ? $cart_item['vat_rate'] : ($cart_item['tax'] / $cart_item['subtotal']) * 100; |
|
1079 | + $tax_rate = $tax_rate > 0 ? (float)wpinv_format_amount($tax_rate, 2) : ''; |
|
1080 | 1080 | $tax_rate = $tax_rate != '' ? ' <small class="tax-rate">(' . $tax_rate . '%)</small>' : ''; |
1081 | 1081 | } |
1082 | 1082 | |
1083 | 1083 | $line_item_tax = $item_tax . $tax_rate; |
1084 | 1084 | |
1085 | - if ( $line_item_tax === '' ) { |
|
1085 | + if ($line_item_tax === '') { |
|
1086 | 1086 | $line_item_tax = 0; // Zero tax |
1087 | 1087 | } |
1088 | 1088 | |
1089 | - $line_item = '<tr class="row-' . ( ($count % 2 == 0) ? 'even' : 'odd' ) . ' wpinv-item">'; |
|
1090 | - $line_item .= '<td class="name">' . esc_html__( $item_name, 'invoicing' ) . wpinv_get_item_suffix( $item ); |
|
1091 | - if ( $summary !== '' ) { |
|
1092 | - $line_item .= '<br/><small class="meta">' . wpautop( wp_kses_post( $summary ) ) . '</small>'; |
|
1089 | + $line_item = '<tr class="row-' . (($count % 2 == 0) ? 'even' : 'odd') . ' wpinv-item">'; |
|
1090 | + $line_item .= '<td class="name">' . esc_html__($item_name, 'invoicing') . wpinv_get_item_suffix($item); |
|
1091 | + if ($summary !== '') { |
|
1092 | + $line_item .= '<br/><small class="meta">' . wpautop(wp_kses_post($summary)) . '</small>'; |
|
1093 | 1093 | } |
1094 | 1094 | $line_item .= '</td>'; |
1095 | 1095 | |
1096 | - $line_item .= '<td class="rate">' . esc_html__( wpinv_price( $item_price, $invoice->get_currency() ) ) . '</td>'; |
|
1096 | + $line_item .= '<td class="rate">' . esc_html__(wpinv_price($item_price, $invoice->get_currency())) . '</td>'; |
|
1097 | 1097 | if ($quantities_enabled) { |
1098 | 1098 | $cols++; |
1099 | 1099 | $line_item .= '<td class="qty">' . $quantity . '</td>'; |
@@ -1102,55 +1102,55 @@ discard block |
||
1102 | 1102 | $cols++; |
1103 | 1103 | $line_item .= '<td class="tax">' . $line_item_tax . '</td>'; |
1104 | 1104 | } |
1105 | - $line_item .= '<td class="total">' . esc_html__( wpinv_price( $line_total, $invoice->get_currency() ) ) . '</td>'; |
|
1105 | + $line_item .= '<td class="total">' . esc_html__(wpinv_price($line_total, $invoice->get_currency())) . '</td>'; |
|
1106 | 1106 | $line_item .= '</tr>'; |
1107 | 1107 | |
1108 | - echo apply_filters( 'wpinv_display_line_item', $line_item, $cart_item, $invoice, $cols ); |
|
1108 | + echo apply_filters('wpinv_display_line_item', $line_item, $cart_item, $invoice, $cols); |
|
1109 | 1109 | |
1110 | 1110 | $count++; |
1111 | 1111 | } |
1112 | 1112 | |
1113 | - do_action( 'wpinv_display_before_subtotal', $invoice, $cols ); |
|
1113 | + do_action('wpinv_display_before_subtotal', $invoice, $cols); |
|
1114 | 1114 | ?> |
1115 | 1115 | <tr class="row-sub-total row_odd"> |
1116 | - <td class="rate" colspan="<?php echo ( $cols - 1 ); ?>"><?php echo apply_filters( 'wpinv_print_cart_subtotal_label', '<strong>' . __( 'Sub Total', 'invoicing' ) . ':</strong>', $invoice ); ?></td> |
|
1117 | - <td class="total"><strong><?php _e( wpinv_subtotal( $invoice_id, true ) ) ?></strong></td> |
|
1116 | + <td class="rate" colspan="<?php echo ($cols - 1); ?>"><?php echo apply_filters('wpinv_print_cart_subtotal_label', '<strong>' . __('Sub Total', 'invoicing') . ':</strong>', $invoice); ?></td> |
|
1117 | + <td class="total"><strong><?php _e(wpinv_subtotal($invoice_id, true)) ?></strong></td> |
|
1118 | 1118 | </tr> |
1119 | 1119 | <?php |
1120 | - do_action( 'wpinv_display_after_subtotal', $invoice, $cols ); |
|
1120 | + do_action('wpinv_display_after_subtotal', $invoice, $cols); |
|
1121 | 1121 | |
1122 | - if ( wpinv_discount( $invoice_id, false ) > 0 ) { |
|
1123 | - do_action( 'wpinv_display_before_discount', $invoice, $cols ); |
|
1122 | + if (wpinv_discount($invoice_id, false) > 0) { |
|
1123 | + do_action('wpinv_display_before_discount', $invoice, $cols); |
|
1124 | 1124 | ?> |
1125 | 1125 | <tr class="row-discount"> |
1126 | - <td class="rate" colspan="<?php echo ( $cols - 1 ); ?>"><?php wpinv_get_discount_label( wpinv_discount_code( $invoice_id ) ); ?>:</td> |
|
1127 | - <td class="total"><?php echo wpinv_discount( $invoice_id, true, true ); ?></td> |
|
1126 | + <td class="rate" colspan="<?php echo ($cols - 1); ?>"><?php wpinv_get_discount_label(wpinv_discount_code($invoice_id)); ?>:</td> |
|
1127 | + <td class="total"><?php echo wpinv_discount($invoice_id, true, true); ?></td> |
|
1128 | 1128 | </tr> |
1129 | 1129 | <?php |
1130 | - do_action( 'wpinv_display_after_discount', $invoice, $cols ); |
|
1130 | + do_action('wpinv_display_after_discount', $invoice, $cols); |
|
1131 | 1131 | } |
1132 | 1132 | |
1133 | - if ( $use_taxes ) { |
|
1134 | - do_action( 'wpinv_display_before_tax', $invoice, $cols ); |
|
1133 | + if ($use_taxes) { |
|
1134 | + do_action('wpinv_display_before_tax', $invoice, $cols); |
|
1135 | 1135 | ?> |
1136 | 1136 | <tr class="row-tax"> |
1137 | - <td class="rate" colspan="<?php echo ( $cols - 1 ); ?>"><?php echo apply_filters( 'wpinv_print_cart_tax_label', '<strong>' . $tax_label . ':</strong>', $invoice ); ?></td> |
|
1138 | - <td class="total"><?php _e( wpinv_tax( $invoice_id, true ) ) ?></td> |
|
1137 | + <td class="rate" colspan="<?php echo ($cols - 1); ?>"><?php echo apply_filters('wpinv_print_cart_tax_label', '<strong>' . $tax_label . ':</strong>', $invoice); ?></td> |
|
1138 | + <td class="total"><?php _e(wpinv_tax($invoice_id, true)) ?></td> |
|
1139 | 1139 | </tr> |
1140 | 1140 | <?php |
1141 | - do_action( 'wpinv_display_after_tax', $invoice, $cols ); |
|
1141 | + do_action('wpinv_display_after_tax', $invoice, $cols); |
|
1142 | 1142 | } |
1143 | 1143 | |
1144 | - do_action( 'wpinv_display_before_total', $invoice, $cols ); |
|
1144 | + do_action('wpinv_display_before_total', $invoice, $cols); |
|
1145 | 1145 | ?> |
1146 | 1146 | <tr class="table-active row-total"> |
1147 | - <td class="rate" colspan="<?php echo ( $cols - 1 ); ?>"><?php echo apply_filters( 'wpinv_print_cart_total_label', '<strong>' . __( 'Total', 'invoicing' ) . ':</strong>', $invoice ); ?></td> |
|
1148 | - <td class="total"><strong><?php _e( wpinv_payment_total( $invoice_id, true ) ) ?></strong></td> |
|
1147 | + <td class="rate" colspan="<?php echo ($cols - 1); ?>"><?php echo apply_filters('wpinv_print_cart_total_label', '<strong>' . __('Total', 'invoicing') . ':</strong>', $invoice); ?></td> |
|
1148 | + <td class="total"><strong><?php _e(wpinv_payment_total($invoice_id, true)) ?></strong></td> |
|
1149 | 1149 | </tr> |
1150 | 1150 | <?php |
1151 | - do_action( 'wpinv_display_after_total', $invoice, $cols ); |
|
1151 | + do_action('wpinv_display_after_total', $invoice, $cols); |
|
1152 | 1152 | |
1153 | - do_action( 'wpinv_display_line_end', $invoice, $cols ); |
|
1153 | + do_action('wpinv_display_line_end', $invoice, $cols); |
|
1154 | 1154 | } |
1155 | 1155 | ?> |
1156 | 1156 | </tbody> |
@@ -1159,35 +1159,35 @@ discard block |
||
1159 | 1159 | echo ob_get_clean(); |
1160 | 1160 | } |
1161 | 1161 | |
1162 | -function wpinv_display_invoice_totals( $invoice_id = 0 ) { |
|
1162 | +function wpinv_display_invoice_totals($invoice_id = 0) { |
|
1163 | 1163 | $use_taxes = wpinv_use_taxes(); |
1164 | 1164 | |
1165 | - do_action( 'wpinv_before_display_totals_table', $invoice_id ); |
|
1165 | + do_action('wpinv_before_display_totals_table', $invoice_id); |
|
1166 | 1166 | ?> |
1167 | 1167 | <table class="table table-sm table-bordered table-responsive"> |
1168 | 1168 | <tbody> |
1169 | - <?php do_action( 'wpinv_before_display_totals' ); ?> |
|
1169 | + <?php do_action('wpinv_before_display_totals'); ?> |
|
1170 | 1170 | <tr class="row-sub-total"> |
1171 | - <td class="rate"><strong><?php _e( 'Sub Total', 'invoicing' ); ?></strong></td> |
|
1172 | - <td class="total"><strong><?php _e( wpinv_subtotal( $invoice_id, true ) ) ?></strong></td> |
|
1171 | + <td class="rate"><strong><?php _e('Sub Total', 'invoicing'); ?></strong></td> |
|
1172 | + <td class="total"><strong><?php _e(wpinv_subtotal($invoice_id, true)) ?></strong></td> |
|
1173 | 1173 | </tr> |
1174 | - <?php do_action( 'wpinv_after_display_totals' ); ?> |
|
1175 | - <?php if ( wpinv_discount( $invoice_id, false ) > 0 ) { ?> |
|
1174 | + <?php do_action('wpinv_after_display_totals'); ?> |
|
1175 | + <?php if (wpinv_discount($invoice_id, false) > 0) { ?> |
|
1176 | 1176 | <tr class="row-discount"> |
1177 | - <td class="rate"><?php wpinv_get_discount_label( wpinv_discount_code( $invoice_id ) ); ?></td> |
|
1178 | - <td class="total"><?php echo wpinv_discount( $invoice_id, true, true ); ?></td> |
|
1177 | + <td class="rate"><?php wpinv_get_discount_label(wpinv_discount_code($invoice_id)); ?></td> |
|
1178 | + <td class="total"><?php echo wpinv_discount($invoice_id, true, true); ?></td> |
|
1179 | 1179 | </tr> |
1180 | - <?php do_action( 'wpinv_after_display_discount' ); ?> |
|
1180 | + <?php do_action('wpinv_after_display_discount'); ?> |
|
1181 | 1181 | <?php } ?> |
1182 | - <?php if ( $use_taxes ) { ?> |
|
1182 | + <?php if ($use_taxes) { ?> |
|
1183 | 1183 | <tr class="row-tax"> |
1184 | - <td class="rate"><?php _e( 'Tax', 'invoicing' ); ?></td> |
|
1185 | - <td class="total"><?php _e( wpinv_tax( $invoice_id, true ) ) ?></td> |
|
1184 | + <td class="rate"><?php _e('Tax', 'invoicing'); ?></td> |
|
1185 | + <td class="total"><?php _e(wpinv_tax($invoice_id, true)) ?></td> |
|
1186 | 1186 | </tr> |
1187 | - <?php do_action( 'wpinv_after_display_tax' ); ?> |
|
1187 | + <?php do_action('wpinv_after_display_tax'); ?> |
|
1188 | 1188 | <?php } ?> |
1189 | - <?php if ( $fees = wpinv_get_fees( $invoice_id ) ) { ?> |
|
1190 | - <?php foreach ( $fees as $fee ) { ?> |
|
1189 | + <?php if ($fees = wpinv_get_fees($invoice_id)) { ?> |
|
1190 | + <?php foreach ($fees as $fee) { ?> |
|
1191 | 1191 | <tr class="row-fee"> |
1192 | 1192 | <td class="rate"><?php echo $fee['label']; ?></td> |
1193 | 1193 | <td class="total"><?php echo $fee['amount_display']; ?></td> |
@@ -1195,72 +1195,72 @@ discard block |
||
1195 | 1195 | <?php } ?> |
1196 | 1196 | <?php } ?> |
1197 | 1197 | <tr class="table-active row-total"> |
1198 | - <td class="rate"><strong><?php _e( 'Total', 'invoicing' ) ?></strong></td> |
|
1199 | - <td class="total"><strong><?php _e( wpinv_payment_total( $invoice_id, true ) ) ?></strong></td> |
|
1198 | + <td class="rate"><strong><?php _e('Total', 'invoicing') ?></strong></td> |
|
1199 | + <td class="total"><strong><?php _e(wpinv_payment_total($invoice_id, true)) ?></strong></td> |
|
1200 | 1200 | </tr> |
1201 | - <?php do_action( 'wpinv_after_totals' ); ?> |
|
1201 | + <?php do_action('wpinv_after_totals'); ?> |
|
1202 | 1202 | </tbody> |
1203 | 1203 | |
1204 | 1204 | </table> |
1205 | 1205 | |
1206 | - <?php do_action( 'wpinv_after_totals_table' ); |
|
1206 | + <?php do_action('wpinv_after_totals_table'); |
|
1207 | 1207 | } |
1208 | 1208 | |
1209 | -function wpinv_display_payments_info( $invoice_id = 0, $echo = true ) { |
|
1210 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
1209 | +function wpinv_display_payments_info($invoice_id = 0, $echo = true) { |
|
1210 | + $invoice = wpinv_get_invoice($invoice_id); |
|
1211 | 1211 | |
1212 | 1212 | ob_start(); |
1213 | - do_action( 'wpinv_before_display_payments_info', $invoice_id ); |
|
1214 | - if ( ( $gateway_title = $invoice->get_gateway_title() ) || $invoice->is_paid() ) { |
|
1213 | + do_action('wpinv_before_display_payments_info', $invoice_id); |
|
1214 | + if (($gateway_title = $invoice->get_gateway_title()) || $invoice->is_paid()) { |
|
1215 | 1215 | ?> |
1216 | 1216 | <div class="wpi-payment-info"> |
1217 | - <p class="wpi-payment-gateway"><?php echo wp_sprintf( __( 'Payment via %s', 'invoicing' ), $gateway_title ? $gateway_title : __( 'Manually', 'invoicing' ) ); ?></p> |
|
1218 | - <?php if ( $gateway_title ) { ?> |
|
1219 | - <p class="wpi-payment-transid"><?php echo wp_sprintf( __( 'Transaction ID: %s', 'invoicing' ), $invoice->get_transaction_id() ); ?></p> |
|
1217 | + <p class="wpi-payment-gateway"><?php echo wp_sprintf(__('Payment via %s', 'invoicing'), $gateway_title ? $gateway_title : __('Manually', 'invoicing')); ?></p> |
|
1218 | + <?php if ($gateway_title) { ?> |
|
1219 | + <p class="wpi-payment-transid"><?php echo wp_sprintf(__('Transaction ID: %s', 'invoicing'), $invoice->get_transaction_id()); ?></p> |
|
1220 | 1220 | <?php } ?> |
1221 | 1221 | </div> |
1222 | 1222 | <?php |
1223 | 1223 | } |
1224 | - do_action( 'wpinv_after_display_payments_info', $invoice_id ); |
|
1224 | + do_action('wpinv_after_display_payments_info', $invoice_id); |
|
1225 | 1225 | $outout = ob_get_clean(); |
1226 | 1226 | |
1227 | - if ( $echo ) { |
|
1227 | + if ($echo) { |
|
1228 | 1228 | echo $outout; |
1229 | 1229 | } else { |
1230 | 1230 | return $outout; |
1231 | 1231 | } |
1232 | 1232 | } |
1233 | 1233 | |
1234 | -function wpinv_display_style( $invoice ) { |
|
1235 | - wp_register_style( 'wpinv-single-style', WPINV_PLUGIN_URL . 'assets/css/invoice.css', array(), WPINV_VERSION ); |
|
1234 | +function wpinv_display_style($invoice) { |
|
1235 | + wp_register_style('wpinv-single-style', WPINV_PLUGIN_URL . 'assets/css/invoice.css', array(), WPINV_VERSION); |
|
1236 | 1236 | |
1237 | - wp_print_styles( 'open-sans' ); |
|
1238 | - wp_print_styles( 'wpinv-single-style' ); |
|
1237 | + wp_print_styles('open-sans'); |
|
1238 | + wp_print_styles('wpinv-single-style'); |
|
1239 | 1239 | } |
1240 | -add_action( 'wpinv_invoice_print_head', 'wpinv_display_style' ); |
|
1240 | +add_action('wpinv_invoice_print_head', 'wpinv_display_style'); |
|
1241 | 1241 | |
1242 | 1242 | function wpinv_checkout_billing_details() { |
1243 | 1243 | $invoice_id = (int)wpinv_get_invoice_cart_id(); |
1244 | 1244 | if (empty($invoice_id)) { |
1245 | - wpinv_error_log( 'Invoice id not found', 'ERROR', __FILE__, __LINE__ ); |
|
1245 | + wpinv_error_log('Invoice id not found', 'ERROR', __FILE__, __LINE__); |
|
1246 | 1246 | return null; |
1247 | 1247 | } |
1248 | 1248 | |
1249 | - $invoice = wpinv_get_invoice_cart( $invoice_id ); |
|
1249 | + $invoice = wpinv_get_invoice_cart($invoice_id); |
|
1250 | 1250 | if (empty($invoice)) { |
1251 | - wpinv_error_log( 'Invoice not found', 'ERROR', __FILE__, __LINE__ ); |
|
1251 | + wpinv_error_log('Invoice not found', 'ERROR', __FILE__, __LINE__); |
|
1252 | 1252 | return null; |
1253 | 1253 | } |
1254 | 1254 | $user_id = $invoice->get_user_id(); |
1255 | 1255 | $user_info = $invoice->get_user_info(); |
1256 | - $address_info = wpinv_get_user_address( $user_id ); |
|
1256 | + $address_info = wpinv_get_user_address($user_id); |
|
1257 | 1257 | |
1258 | - if ( empty( $user_info['first_name'] ) && !empty( $user_info['first_name'] ) ) { |
|
1258 | + if (empty($user_info['first_name']) && !empty($user_info['first_name'])) { |
|
1259 | 1259 | $user_info['first_name'] = $user_info['first_name']; |
1260 | 1260 | $user_info['last_name'] = $user_info['last_name']; |
1261 | 1261 | } |
1262 | 1262 | |
1263 | - if ( ( ( empty( $user_info['country'] ) && !empty( $address_info['country'] ) ) || ( empty( $user_info['state'] ) && !empty( $address_info['state'] ) && $user_info['country'] == $address_info['country'] ) ) ) { |
|
1263 | + if (((empty($user_info['country']) && !empty($address_info['country'])) || (empty($user_info['state']) && !empty($address_info['state']) && $user_info['country'] == $address_info['country']))) { |
|
1264 | 1264 | $user_info['country'] = $address_info['country']; |
1265 | 1265 | $user_info['state'] = $address_info['state']; |
1266 | 1266 | $user_info['city'] = $address_info['city']; |
@@ -1276,103 +1276,103 @@ discard block |
||
1276 | 1276 | 'address' |
1277 | 1277 | ); |
1278 | 1278 | |
1279 | - foreach ( $address_fields as $field ) { |
|
1280 | - if ( empty( $user_info[$field] ) ) { |
|
1279 | + foreach ($address_fields as $field) { |
|
1280 | + if (empty($user_info[$field])) { |
|
1281 | 1281 | $user_info[$field] = $address_info[$field]; |
1282 | 1282 | } |
1283 | 1283 | } |
1284 | 1284 | |
1285 | - return apply_filters( 'wpinv_checkout_billing_details', $user_info, $invoice ); |
|
1285 | + return apply_filters('wpinv_checkout_billing_details', $user_info, $invoice); |
|
1286 | 1286 | } |
1287 | 1287 | |
1288 | 1288 | function wpinv_admin_get_line_items($invoice = array()) { |
1289 | 1289 | $item_quantities = wpinv_item_quantities_enabled(); |
1290 | 1290 | $use_taxes = wpinv_use_taxes(); |
1291 | 1291 | |
1292 | - if ( empty( $invoice ) ) { |
|
1292 | + if (empty($invoice)) { |
|
1293 | 1293 | return NULL; |
1294 | 1294 | } |
1295 | 1295 | |
1296 | 1296 | $cart_items = $invoice->get_cart_details(); |
1297 | - if ( empty( $cart_items ) ) { |
|
1297 | + if (empty($cart_items)) { |
|
1298 | 1298 | return NULL; |
1299 | 1299 | } |
1300 | 1300 | ob_start(); |
1301 | 1301 | |
1302 | - do_action( 'wpinv_admin_before_line_items', $cart_items, $invoice ); |
|
1302 | + do_action('wpinv_admin_before_line_items', $cart_items, $invoice); |
|
1303 | 1303 | |
1304 | 1304 | $count = 0; |
1305 | - foreach ( $cart_items as $key => $cart_item ) { |
|
1305 | + foreach ($cart_items as $key => $cart_item) { |
|
1306 | 1306 | $item_id = $cart_item['id']; |
1307 | - $wpi_item = $item_id > 0 ? new WPInv_Item( $item_id ) : NULL; |
|
1307 | + $wpi_item = $item_id > 0 ? new WPInv_Item($item_id) : NULL; |
|
1308 | 1308 | |
1309 | 1309 | if (empty($wpi_item)) { |
1310 | 1310 | continue; |
1311 | 1311 | } |
1312 | 1312 | |
1313 | - $item_price = wpinv_price( wpinv_format_amount( $cart_item['item_price'] ) ); |
|
1314 | - $quantity = !empty( $cart_item['quantity'] ) && $cart_item['quantity'] > 0 ? $cart_item['quantity'] : 1; |
|
1315 | - $item_subtotal = wpinv_price( wpinv_format_amount( $cart_item['subtotal'] ) ); |
|
1313 | + $item_price = wpinv_price(wpinv_format_amount($cart_item['item_price'])); |
|
1314 | + $quantity = !empty($cart_item['quantity']) && $cart_item['quantity'] > 0 ? $cart_item['quantity'] : 1; |
|
1315 | + $item_subtotal = wpinv_price(wpinv_format_amount($cart_item['subtotal'])); |
|
1316 | 1316 | $can_remove = true; |
1317 | 1317 | |
1318 | 1318 | $summary = ''; |
1319 | 1319 | if ($wpi_item->is_package() && !empty($cart_item['meta']['post_id'])) { |
1320 | - $post_link = '<a href="' . get_edit_post_link( $cart_item['meta']['post_id'] ) .'" target="_blank">' . (!empty($cart_item['meta']['invoice_title']) ? $cart_item['meta']['invoice_title'] : get_the_title( $cart_item['meta']['post_id']) ) . '</a>'; |
|
1321 | - $summary = wp_sprintf( __( '%s: %s', 'invoicing' ), $wpi_item->get_cpt_singular_name(), $post_link ); |
|
1320 | + $post_link = '<a href="' . get_edit_post_link($cart_item['meta']['post_id']) . '" target="_blank">' . (!empty($cart_item['meta']['invoice_title']) ? $cart_item['meta']['invoice_title'] : get_the_title($cart_item['meta']['post_id'])) . '</a>'; |
|
1321 | + $summary = wp_sprintf(__('%s: %s', 'invoicing'), $wpi_item->get_cpt_singular_name(), $post_link); |
|
1322 | 1322 | } |
1323 | - $summary = apply_filters( 'wpinv_admin_invoice_line_item_summary', $summary, $cart_item, $wpi_item, $invoice ); |
|
1323 | + $summary = apply_filters('wpinv_admin_invoice_line_item_summary', $summary, $cart_item, $wpi_item, $invoice); |
|
1324 | 1324 | |
1325 | 1325 | $item_tax = ''; |
1326 | 1326 | $tax_rate = ''; |
1327 | - if ( $cart_item['tax'] > 0 && $cart_item['subtotal'] > 0 ) { |
|
1328 | - $item_tax = wpinv_price( wpinv_format_amount( $cart_item['tax'] ) ); |
|
1329 | - $tax_rate = !empty( $cart_item['vat_rate'] ) ? $cart_item['vat_rate'] : ( $cart_item['tax'] / $cart_item['subtotal'] ) * 100; |
|
1330 | - $tax_rate = $tax_rate > 0 ? (float)wpinv_format_amount( $tax_rate, 2 ) : ''; |
|
1327 | + if ($cart_item['tax'] > 0 && $cart_item['subtotal'] > 0) { |
|
1328 | + $item_tax = wpinv_price(wpinv_format_amount($cart_item['tax'])); |
|
1329 | + $tax_rate = !empty($cart_item['vat_rate']) ? $cart_item['vat_rate'] : ($cart_item['tax'] / $cart_item['subtotal']) * 100; |
|
1330 | + $tax_rate = $tax_rate > 0 ? (float)wpinv_format_amount($tax_rate, 2) : ''; |
|
1331 | 1331 | $tax_rate = $tax_rate != '' ? ' <span class="tax-rate">(' . $tax_rate . '%)</span>' : ''; |
1332 | 1332 | } |
1333 | 1333 | $line_item_tax = $item_tax . $tax_rate; |
1334 | 1334 | |
1335 | - if ( $line_item_tax === '' ) { |
|
1335 | + if ($line_item_tax === '') { |
|
1336 | 1336 | $line_item_tax = 0; // Zero tax |
1337 | 1337 | } |
1338 | 1338 | |
1339 | - $line_item = '<tr class="item item-' . ( ($count % 2 == 0) ? 'even' : 'odd' ) . '" data-item-id="' . $item_id . '">'; |
|
1339 | + $line_item = '<tr class="item item-' . (($count % 2 == 0) ? 'even' : 'odd') . '" data-item-id="' . $item_id . '">'; |
|
1340 | 1340 | $line_item .= '<td class="id">' . $item_id . '</td>'; |
1341 | - $line_item .= '<td class="title"><a href="' . get_edit_post_link( $item_id ) . '" target="_blank">' . $cart_item['name'] . '</a>' . wpinv_get_item_suffix( $wpi_item ); |
|
1342 | - if ( $summary !== '' ) { |
|
1343 | - $line_item .= '<span class="meta">' . wpautop( wp_kses_post( $summary ) ) . '</span>'; |
|
1341 | + $line_item .= '<td class="title"><a href="' . get_edit_post_link($item_id) . '" target="_blank">' . $cart_item['name'] . '</a>' . wpinv_get_item_suffix($wpi_item); |
|
1342 | + if ($summary !== '') { |
|
1343 | + $line_item .= '<span class="meta">' . wpautop(wp_kses_post($summary)) . '</span>'; |
|
1344 | 1344 | } |
1345 | 1345 | $line_item .= '</td>'; |
1346 | 1346 | $line_item .= '<td class="price">' . $item_price . '</td>'; |
1347 | 1347 | |
1348 | - if ( $item_quantities ) { |
|
1349 | - if ( count( $cart_items ) == 1 && $quantity <= 1 ) { |
|
1348 | + if ($item_quantities) { |
|
1349 | + if (count($cart_items) == 1 && $quantity <= 1) { |
|
1350 | 1350 | $can_remove = false; |
1351 | 1351 | } |
1352 | 1352 | $line_item .= '<td class="qty" data-quantity="' . $quantity . '"> × ' . $quantity . '</td>'; |
1353 | 1353 | } else { |
1354 | - if ( count( $cart_items ) == 1 ) { |
|
1354 | + if (count($cart_items) == 1) { |
|
1355 | 1355 | $can_remove = false; |
1356 | 1356 | } |
1357 | 1357 | } |
1358 | 1358 | $line_item .= '<td class="total">' . $item_subtotal . '</td>'; |
1359 | 1359 | |
1360 | - if ( $use_taxes ) { |
|
1360 | + if ($use_taxes) { |
|
1361 | 1361 | $line_item .= '<td class="tax">' . $line_item_tax . '</td>'; |
1362 | 1362 | } |
1363 | 1363 | $line_item .= '<td class="action">'; |
1364 | - if ( !$invoice->is_paid() && $can_remove ) { |
|
1364 | + if (!$invoice->is_paid() && $can_remove) { |
|
1365 | 1365 | $line_item .= '<i class="fa fa-remove wpinv-item-remove"></i>'; |
1366 | 1366 | } |
1367 | 1367 | $line_item .= '</td>'; |
1368 | 1368 | $line_item .= '</tr>'; |
1369 | 1369 | |
1370 | - echo apply_filters( 'wpinv_admin_line_item', $line_item, $cart_item, $invoice ); |
|
1370 | + echo apply_filters('wpinv_admin_line_item', $line_item, $cart_item, $invoice); |
|
1371 | 1371 | |
1372 | 1372 | $count++; |
1373 | 1373 | } |
1374 | 1374 | |
1375 | - do_action( 'wpinv_admin_after_line_items', $cart_items, $invoice ); |
|
1375 | + do_action('wpinv_admin_after_line_items', $cart_items, $invoice); |
|
1376 | 1376 | |
1377 | 1377 | return ob_get_clean(); |
1378 | 1378 | } |
@@ -1383,35 +1383,35 @@ discard block |
||
1383 | 1383 | // Set current invoice id. |
1384 | 1384 | $wpi_checkout_id = wpinv_get_invoice_cart_id(); |
1385 | 1385 | |
1386 | - $form_action = esc_url( wpinv_get_checkout_uri() ); |
|
1386 | + $form_action = esc_url(wpinv_get_checkout_uri()); |
|
1387 | 1387 | |
1388 | 1388 | ob_start(); |
1389 | 1389 | echo '<div id="wpinv_checkout_wrap">'; |
1390 | 1390 | |
1391 | - if ( wpinv_get_cart_contents() || wpinv_cart_has_fees() ) { |
|
1391 | + if (wpinv_get_cart_contents() || wpinv_cart_has_fees()) { |
|
1392 | 1392 | ?> |
1393 | 1393 | <div id="wpinv_checkout_form_wrap" class="wpinv_clearfix table-responsive"> |
1394 | - <?php do_action( 'wpinv_before_checkout_form' ); ?> |
|
1394 | + <?php do_action('wpinv_before_checkout_form'); ?> |
|
1395 | 1395 | <form id="wpinv_checkout_form" class="wpi-form" action="<?php echo $form_action; ?>" method="POST"> |
1396 | 1396 | <?php |
1397 | - do_action( 'wpinv_checkout_form_top' ); |
|
1398 | - do_action( 'wpinv_checkout_billing_info' ); |
|
1399 | - do_action( 'wpinv_checkout_cart' ); |
|
1400 | - do_action( 'wpinv_payment_mode_select' ); |
|
1401 | - do_action( 'wpinv_checkout_form_bottom' ) |
|
1397 | + do_action('wpinv_checkout_form_top'); |
|
1398 | + do_action('wpinv_checkout_billing_info'); |
|
1399 | + do_action('wpinv_checkout_cart'); |
|
1400 | + do_action('wpinv_payment_mode_select'); |
|
1401 | + do_action('wpinv_checkout_form_bottom') |
|
1402 | 1402 | ?> |
1403 | 1403 | </form> |
1404 | - <?php do_action( 'wpinv_after_purchase_form' ); ?> |
|
1404 | + <?php do_action('wpinv_after_purchase_form'); ?> |
|
1405 | 1405 | </div><!--end #wpinv_checkout_form_wrap--> |
1406 | 1406 | <?php |
1407 | 1407 | } else { |
1408 | - do_action( 'wpinv_cart_empty' ); |
|
1408 | + do_action('wpinv_cart_empty'); |
|
1409 | 1409 | } |
1410 | 1410 | echo '</div><!--end #wpinv_checkout_wrap-->'; |
1411 | 1411 | return ob_get_clean(); |
1412 | 1412 | } |
1413 | 1413 | |
1414 | -function wpinv_checkout_cart( $cart_details = array(), $echo = true ) { |
|
1414 | +function wpinv_checkout_cart($cart_details = array(), $echo = true) { |
|
1415 | 1415 | global $ajax_cart_details; |
1416 | 1416 | $ajax_cart_details = $cart_details; |
1417 | 1417 | /* |
@@ -1426,25 +1426,25 @@ discard block |
||
1426 | 1426 | } |
1427 | 1427 | */ |
1428 | 1428 | ob_start(); |
1429 | - do_action( 'wpinv_before_checkout_cart' ); |
|
1429 | + do_action('wpinv_before_checkout_cart'); |
|
1430 | 1430 | echo '<div id="wpinv_checkout_cart_form" method="post">'; |
1431 | 1431 | echo '<div id="wpinv_checkout_cart_wrap">'; |
1432 | - wpinv_get_template_part( 'wpinv-checkout-cart' ); |
|
1432 | + wpinv_get_template_part('wpinv-checkout-cart'); |
|
1433 | 1433 | echo '</div>'; |
1434 | 1434 | echo '</div>'; |
1435 | - do_action( 'wpinv_after_checkout_cart' ); |
|
1435 | + do_action('wpinv_after_checkout_cart'); |
|
1436 | 1436 | $content = ob_get_clean(); |
1437 | 1437 | |
1438 | - if ( $echo ) { |
|
1438 | + if ($echo) { |
|
1439 | 1439 | echo $content; |
1440 | 1440 | } else { |
1441 | 1441 | return $content; |
1442 | 1442 | } |
1443 | 1443 | } |
1444 | -add_action( 'wpinv_checkout_cart', 'wpinv_checkout_cart', 10 ); |
|
1444 | +add_action('wpinv_checkout_cart', 'wpinv_checkout_cart', 10); |
|
1445 | 1445 | |
1446 | 1446 | function wpinv_empty_cart_message() { |
1447 | - return apply_filters( 'wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __( 'Your cart is empty.', 'invoicing' ) . '</span>' ); |
|
1447 | + return apply_filters('wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __('Your cart is empty.', 'invoicing') . '</span>'); |
|
1448 | 1448 | } |
1449 | 1449 | |
1450 | 1450 | /** |
@@ -1456,91 +1456,91 @@ discard block |
||
1456 | 1456 | function wpinv_empty_checkout_cart() { |
1457 | 1457 | echo wpinv_empty_cart_message(); |
1458 | 1458 | } |
1459 | -add_action( 'wpinv_cart_empty', 'wpinv_empty_checkout_cart' ); |
|
1459 | +add_action('wpinv_cart_empty', 'wpinv_empty_checkout_cart'); |
|
1460 | 1460 | |
1461 | 1461 | function wpinv_save_cart_button() { |
1462 | - if ( wpinv_is_cart_saving_disabled() ) |
|
1462 | + if (wpinv_is_cart_saving_disabled()) |
|
1463 | 1463 | return; |
1464 | 1464 | ?> |
1465 | - <a class="wpinv-cart-saving-button wpinv-submit button" id="wpinv-save-cart-button" href="<?php echo esc_url( add_query_arg( 'wpi_action', 'save_cart' ) ); ?>"><?php _e( 'Save Cart', 'invoicing' ); ?></a> |
|
1465 | + <a class="wpinv-cart-saving-button wpinv-submit button" id="wpinv-save-cart-button" href="<?php echo esc_url(add_query_arg('wpi_action', 'save_cart')); ?>"><?php _e('Save Cart', 'invoicing'); ?></a> |
|
1466 | 1466 | <?php |
1467 | 1467 | } |
1468 | 1468 | |
1469 | 1469 | function wpinv_update_cart_button() { |
1470 | - if ( !wpinv_item_quantities_enabled() ) |
|
1470 | + if (!wpinv_item_quantities_enabled()) |
|
1471 | 1471 | return; |
1472 | 1472 | ?> |
1473 | - <input type="submit" name="wpinv_update_cart_submit" class="wpinv-submit wpinv-no-js button" value="<?php _e( 'Update Cart', 'invoicing' ); ?>"/> |
|
1473 | + <input type="submit" name="wpinv_update_cart_submit" class="wpinv-submit wpinv-no-js button" value="<?php _e('Update Cart', 'invoicing'); ?>"/> |
|
1474 | 1474 | <input type="hidden" name="wpi_action" value="update_cart"/> |
1475 | 1475 | <?php |
1476 | 1476 | } |
1477 | 1477 | |
1478 | 1478 | function wpinv_checkout_cart_columns() { |
1479 | 1479 | $default = 3; |
1480 | - if ( wpinv_item_quantities_enabled() ) { |
|
1480 | + if (wpinv_item_quantities_enabled()) { |
|
1481 | 1481 | $default++; |
1482 | 1482 | } |
1483 | 1483 | |
1484 | - if ( wpinv_use_taxes() ) { |
|
1484 | + if (wpinv_use_taxes()) { |
|
1485 | 1485 | $default++; |
1486 | 1486 | } |
1487 | 1487 | |
1488 | - return apply_filters( 'wpinv_checkout_cart_columns', $default ); |
|
1488 | + return apply_filters('wpinv_checkout_cart_columns', $default); |
|
1489 | 1489 | } |
1490 | 1490 | |
1491 | 1491 | function wpinv_display_cart_messages() { |
1492 | 1492 | global $wpi_session; |
1493 | 1493 | |
1494 | - $messages = $wpi_session->get( 'wpinv_cart_messages' ); |
|
1494 | + $messages = $wpi_session->get('wpinv_cart_messages'); |
|
1495 | 1495 | |
1496 | - if ( $messages ) { |
|
1497 | - foreach ( $messages as $message_id => $message ) { |
|
1496 | + if ($messages) { |
|
1497 | + foreach ($messages as $message_id => $message) { |
|
1498 | 1498 | // Try and detect what type of message this is |
1499 | - if ( strpos( strtolower( $message ), 'error' ) ) { |
|
1499 | + if (strpos(strtolower($message), 'error')) { |
|
1500 | 1500 | $type = 'error'; |
1501 | - } elseif ( strpos( strtolower( $message ), 'success' ) ) { |
|
1501 | + } elseif (strpos(strtolower($message), 'success')) { |
|
1502 | 1502 | $type = 'success'; |
1503 | 1503 | } else { |
1504 | 1504 | $type = 'info'; |
1505 | 1505 | } |
1506 | 1506 | |
1507 | - $classes = apply_filters( 'wpinv_' . $type . '_class', array( 'wpinv_errors', 'wpinv-alert', 'wpinv-alert-' . $type ) ); |
|
1507 | + $classes = apply_filters('wpinv_' . $type . '_class', array('wpinv_errors', 'wpinv-alert', 'wpinv-alert-' . $type)); |
|
1508 | 1508 | |
1509 | - echo '<div class="' . implode( ' ', $classes ) . '">'; |
|
1509 | + echo '<div class="' . implode(' ', $classes) . '">'; |
|
1510 | 1510 | // Loop message codes and display messages |
1511 | 1511 | echo '<p class="wpinv_error" id="wpinv_msg_' . $message_id . '">' . $message . '</p>'; |
1512 | 1512 | echo '</div>'; |
1513 | 1513 | } |
1514 | 1514 | |
1515 | 1515 | // Remove all of the cart saving messages |
1516 | - $wpi_session->set( 'wpinv_cart_messages', null ); |
|
1516 | + $wpi_session->set('wpinv_cart_messages', null); |
|
1517 | 1517 | } |
1518 | 1518 | } |
1519 | -add_action( 'wpinv_before_checkout_cart', 'wpinv_display_cart_messages' ); |
|
1519 | +add_action('wpinv_before_checkout_cart', 'wpinv_display_cart_messages'); |
|
1520 | 1520 | |
1521 | 1521 | function wpinv_discount_field() { |
1522 | - if ( isset( $_GET['wpi-gateway'] ) && wpinv_is_ajax_disabled() ) { |
|
1522 | + if (isset($_GET['wpi-gateway']) && wpinv_is_ajax_disabled()) { |
|
1523 | 1523 | return; // Only show before a payment method has been selected if ajax is disabled |
1524 | 1524 | } |
1525 | 1525 | |
1526 | - if ( !wpinv_is_checkout() ) { |
|
1526 | + if (!wpinv_is_checkout()) { |
|
1527 | 1527 | return; |
1528 | 1528 | } |
1529 | 1529 | |
1530 | - if ( wpinv_has_active_discounts() && wpinv_get_cart_total() ) { |
|
1530 | + if (wpinv_has_active_discounts() && wpinv_get_cart_total()) { |
|
1531 | 1531 | ?> |
1532 | 1532 | <div id="wpinv-discount-field" class="panel panel-default"> |
1533 | 1533 | <div class="panel-body"> |
1534 | 1534 | <p> |
1535 | - <label class="wpinv-label" for="wpinv_discount_code"><strong><?php _e( 'Discount', 'invoicing' ); ?></strong></label> |
|
1536 | - <span class="wpinv-description"><?php _e( 'Enter a discount code if you have one.', 'invoicing' ); ?></span> |
|
1535 | + <label class="wpinv-label" for="wpinv_discount_code"><strong><?php _e('Discount', 'invoicing'); ?></strong></label> |
|
1536 | + <span class="wpinv-description"><?php _e('Enter a discount code if you have one.', 'invoicing'); ?></span> |
|
1537 | 1537 | </p> |
1538 | 1538 | <div class="form-group row"> |
1539 | 1539 | <div class="col-sm-4"> |
1540 | - <input class="wpinv-input form-control" type="text" id="wpinv_discount_code" name="wpinv_discount_code" placeholder="<?php _e( 'Enter discount code', 'invoicing' ); ?>"/> |
|
1540 | + <input class="wpinv-input form-control" type="text" id="wpinv_discount_code" name="wpinv_discount_code" placeholder="<?php _e('Enter discount code', 'invoicing'); ?>"/> |
|
1541 | 1541 | </div> |
1542 | 1542 | <div class="col-sm-3"> |
1543 | - <button id="wpi-apply-discount" type="button" class="btn btn-success btn-sm"><?php _e( 'Apply Discount', 'invoicing' ); ?></button> |
|
1543 | + <button id="wpi-apply-discount" type="button" class="btn btn-success btn-sm"><?php _e('Apply Discount', 'invoicing'); ?></button> |
|
1544 | 1544 | </div> |
1545 | 1545 | <div class="col-sm-12 wpinv-discount-msg"> |
1546 | 1546 | <div class="alert alert-success"><i class="fa fa-check-circle"></i><span class="wpi-msg"></span></div> |
@@ -1552,10 +1552,10 @@ discard block |
||
1552 | 1552 | <?php |
1553 | 1553 | } |
1554 | 1554 | } |
1555 | -add_action( 'wpinv_after_checkout_cart', 'wpinv_discount_field', -10 ); |
|
1555 | +add_action('wpinv_after_checkout_cart', 'wpinv_discount_field', -10); |
|
1556 | 1556 | |
1557 | 1557 | function wpinv_agree_to_terms_js() { |
1558 | - if ( wpinv_get_option( 'show_agree_to_terms', false ) ) { |
|
1558 | + if (wpinv_get_option('show_agree_to_terms', false)) { |
|
1559 | 1559 | ?> |
1560 | 1560 | <script type="text/javascript"> |
1561 | 1561 | jQuery(document).ready(function($){ |
@@ -1570,124 +1570,124 @@ discard block |
||
1570 | 1570 | <?php |
1571 | 1571 | } |
1572 | 1572 | } |
1573 | -add_action( 'wpinv_checkout_form_top', 'wpinv_agree_to_terms_js' ); |
|
1573 | +add_action('wpinv_checkout_form_top', 'wpinv_agree_to_terms_js'); |
|
1574 | 1574 | |
1575 | 1575 | function wpinv_payment_mode_select() { |
1576 | - $gateways = wpinv_get_enabled_payment_gateways( true ); |
|
1577 | - $gateways = apply_filters( 'wpinv_payment_gateways_on_cart', $gateways ); |
|
1576 | + $gateways = wpinv_get_enabled_payment_gateways(true); |
|
1577 | + $gateways = apply_filters('wpinv_payment_gateways_on_cart', $gateways); |
|
1578 | 1578 | $page_URL = wpinv_get_current_page_url(); |
1579 | 1579 | |
1580 | 1580 | do_action('wpinv_payment_mode_top'); |
1581 | 1581 | $invoice_id = (int)wpinv_get_invoice_cart_id(); |
1582 | 1582 | ?> |
1583 | 1583 | <div id="wpinv_payment_mode_select"> |
1584 | - <?php do_action( 'wpinv_payment_mode_before_gateways_wrap' ); ?> |
|
1584 | + <?php do_action('wpinv_payment_mode_before_gateways_wrap'); ?> |
|
1585 | 1585 | <div id="wpinv-payment-mode-wrap" class="panel panel-default"> |
1586 | - <div class="panel-heading"><h3 class="panel-title"><?php _e( 'Select Payment Method', 'invoicing' ); ?></h3></div> |
|
1586 | + <div class="panel-heading"><h3 class="panel-title"><?php _e('Select Payment Method', 'invoicing'); ?></h3></div> |
|
1587 | 1587 | <div class="panel-body list-group wpi-payment_methods"> |
1588 | 1588 | <?php |
1589 | - do_action( 'wpinv_payment_mode_before_gateways' ); |
|
1590 | - $chosen_gateway = wpinv_get_chosen_gateway( $invoice_id ); |
|
1589 | + do_action('wpinv_payment_mode_before_gateways'); |
|
1590 | + $chosen_gateway = wpinv_get_chosen_gateway($invoice_id); |
|
1591 | 1591 | |
1592 | - if(!empty($gateways)){ |
|
1593 | - foreach ( $gateways as $gateway_id => $gateway ) { |
|
1594 | - $checked = checked( $gateway_id, $chosen_gateway, false ); |
|
1595 | - $button_label = wpinv_get_gateway_button_label( $gateway_id ); |
|
1596 | - $description = wpinv_get_gateway_description( $gateway_id ); |
|
1592 | + if (!empty($gateways)) { |
|
1593 | + foreach ($gateways as $gateway_id => $gateway) { |
|
1594 | + $checked = checked($gateway_id, $chosen_gateway, false); |
|
1595 | + $button_label = wpinv_get_gateway_button_label($gateway_id); |
|
1596 | + $description = wpinv_get_gateway_description($gateway_id); |
|
1597 | 1597 | ?> |
1598 | 1598 | <div class="list-group-item"> |
1599 | 1599 | <div class="radio"> |
1600 | - <label><input type="radio" data-button-text="<?php echo esc_attr( $button_label );?>" value="<?php echo esc_attr( $gateway_id ) ;?>" <?php echo $checked ;?> id="wpi_gateway_<?php echo esc_attr( $gateway_id );?>" name="wpi-gateway" class="wpi-pmethod"><?php echo esc_html( $gateway['checkout_label'] ); ?></label> |
|
1600 | + <label><input type="radio" data-button-text="<?php echo esc_attr($button_label); ?>" value="<?php echo esc_attr($gateway_id); ?>" <?php echo $checked; ?> id="wpi_gateway_<?php echo esc_attr($gateway_id); ?>" name="wpi-gateway" class="wpi-pmethod"><?php echo esc_html($gateway['checkout_label']); ?></label> |
|
1601 | 1601 | </div> |
1602 | - <div style="display:none;" class="payment_box wpi_gateway_<?php echo esc_attr( $gateway_id );?>" role="alert"> |
|
1603 | - <?php if ( !empty( $description ) ) { ?> |
|
1604 | - <div class="wpi-gateway-desc alert alert-info"><?php echo $description;?></div> |
|
1602 | + <div style="display:none;" class="payment_box wpi_gateway_<?php echo esc_attr($gateway_id); ?>" role="alert"> |
|
1603 | + <?php if (!empty($description)) { ?> |
|
1604 | + <div class="wpi-gateway-desc alert alert-info"><?php echo $description; ?></div> |
|
1605 | 1605 | <?php } ?> |
1606 | - <?php do_action( 'wpinv_' . $gateway_id . '_cc_form', $invoice_id ) ;?> |
|
1606 | + <?php do_action('wpinv_' . $gateway_id . '_cc_form', $invoice_id); ?> |
|
1607 | 1607 | </div> |
1608 | 1608 | </div> |
1609 | 1609 | <?php |
1610 | 1610 | } |
1611 | - }else{ |
|
1612 | - echo '<div class="alert alert-warning">'. __('No payment gateway active','invoicing') .'</div>'; |
|
1611 | + } else { |
|
1612 | + echo '<div class="alert alert-warning">' . __('No payment gateway active', 'invoicing') . '</div>'; |
|
1613 | 1613 | } |
1614 | 1614 | |
1615 | - do_action( 'wpinv_payment_mode_after_gateways' ); |
|
1615 | + do_action('wpinv_payment_mode_after_gateways'); |
|
1616 | 1616 | ?> |
1617 | 1617 | </div> |
1618 | 1618 | </div> |
1619 | - <?php do_action( 'wpinv_payment_mode_after_gateways_wrap' ); ?> |
|
1619 | + <?php do_action('wpinv_payment_mode_after_gateways_wrap'); ?> |
|
1620 | 1620 | </div> |
1621 | 1621 | <?php |
1622 | 1622 | do_action('wpinv_payment_mode_bottom'); |
1623 | 1623 | } |
1624 | -add_action( 'wpinv_payment_mode_select', 'wpinv_payment_mode_select' ); |
|
1624 | +add_action('wpinv_payment_mode_select', 'wpinv_payment_mode_select'); |
|
1625 | 1625 | |
1626 | 1626 | function wpinv_checkout_billing_info() { |
1627 | - if ( wpinv_is_checkout() ) { |
|
1627 | + if (wpinv_is_checkout()) { |
|
1628 | 1628 | $logged_in = is_user_logged_in(); |
1629 | 1629 | $billing_details = wpinv_checkout_billing_details(); |
1630 | - $selected_country = !empty( $billing_details['country'] ) ? $billing_details['country'] : wpinv_default_billing_country(); |
|
1630 | + $selected_country = !empty($billing_details['country']) ? $billing_details['country'] : wpinv_default_billing_country(); |
|
1631 | 1631 | ?> |
1632 | 1632 | <div id="wpinv-fields" class="clearfix"> |
1633 | 1633 | <div id="wpi-billing" class="wpi-billing clearfix panel panel-default"> |
1634 | - <div class="panel-heading"><h3 class="panel-title"><?php _e( 'Billing Details', 'invoicing' );?></h3></div> |
|
1634 | + <div class="panel-heading"><h3 class="panel-title"><?php _e('Billing Details', 'invoicing'); ?></h3></div> |
|
1635 | 1635 | <div id="wpinv-fields-box" class="panel-body"> |
1636 | - <?php do_action( 'wpinv_checkout_billing_fields_first', $billing_details ); ?> |
|
1636 | + <?php do_action('wpinv_checkout_billing_fields_first', $billing_details); ?> |
|
1637 | 1637 | <p class="wpi-cart-field wpi-col2 wpi-colf"> |
1638 | - <label for="wpinv_first_name" class="wpi-label"><?php _e( 'First Name', 'invoicing' );?><span class="wpi-required">*</span></label> |
|
1638 | + <label for="wpinv_first_name" class="wpi-label"><?php _e('First Name', 'invoicing'); ?><span class="wpi-required">*</span></label> |
|
1639 | 1639 | <?php |
1640 | - echo wpinv_html_text( array( |
|
1640 | + echo wpinv_html_text(array( |
|
1641 | 1641 | 'id' => 'wpinv_first_name', |
1642 | 1642 | 'name' => 'wpinv_first_name', |
1643 | 1643 | 'value' => $billing_details['first_name'], |
1644 | 1644 | 'class' => 'wpi-input form-control required', |
1645 | - 'placeholder' => __( 'First name', 'invoicing' ), |
|
1645 | + 'placeholder' => __('First name', 'invoicing'), |
|
1646 | 1646 | 'required' => true, |
1647 | - ) ); |
|
1647 | + )); |
|
1648 | 1648 | ?> |
1649 | 1649 | </p> |
1650 | 1650 | <p class="wpi-cart-field wpi-col2 wpi-coll"> |
1651 | - <label for="wpinv_last_name" class="wpi-label"><?php _e( 'Last Name', 'invoicing' );?></label> |
|
1651 | + <label for="wpinv_last_name" class="wpi-label"><?php _e('Last Name', 'invoicing'); ?></label> |
|
1652 | 1652 | <?php |
1653 | - echo wpinv_html_text( array( |
|
1653 | + echo wpinv_html_text(array( |
|
1654 | 1654 | 'id' => 'wpinv_last_name', |
1655 | 1655 | 'name' => 'wpinv_last_name', |
1656 | 1656 | 'value' => $billing_details['last_name'], |
1657 | 1657 | 'class' => 'wpi-input form-control', |
1658 | - 'placeholder' => __( 'Last name', 'invoicing' ), |
|
1659 | - ) ); |
|
1658 | + 'placeholder' => __('Last name', 'invoicing'), |
|
1659 | + )); |
|
1660 | 1660 | ?> |
1661 | 1661 | </p> |
1662 | 1662 | <p class="wpi-cart-field wpi-col2 wpi-colf"> |
1663 | - <label for="wpinv_address" class="wpi-label"><?php _e( 'Address', 'invoicing' );?><span class="wpi-required">*</span></label> |
|
1663 | + <label for="wpinv_address" class="wpi-label"><?php _e('Address', 'invoicing'); ?><span class="wpi-required">*</span></label> |
|
1664 | 1664 | <?php |
1665 | - echo wpinv_html_text( array( |
|
1665 | + echo wpinv_html_text(array( |
|
1666 | 1666 | 'id' => 'wpinv_address', |
1667 | 1667 | 'name' => 'wpinv_address', |
1668 | 1668 | 'value' => $billing_details['address'], |
1669 | 1669 | 'class' => 'wpi-input form-control required', |
1670 | - 'placeholder' => __( 'Address', 'invoicing' ), |
|
1670 | + 'placeholder' => __('Address', 'invoicing'), |
|
1671 | 1671 | 'required' => true, |
1672 | - ) ); |
|
1672 | + )); |
|
1673 | 1673 | ?> |
1674 | 1674 | </p> |
1675 | 1675 | <p class="wpi-cart-field wpi-col2 wpi-coll"> |
1676 | - <label for="wpinv_city" class="wpi-label"><?php _e( 'City', 'invoicing' );?><span class="wpi-required">*</span></label> |
|
1676 | + <label for="wpinv_city" class="wpi-label"><?php _e('City', 'invoicing'); ?><span class="wpi-required">*</span></label> |
|
1677 | 1677 | <?php |
1678 | - echo wpinv_html_text( array( |
|
1678 | + echo wpinv_html_text(array( |
|
1679 | 1679 | 'id' => 'wpinv_city', |
1680 | 1680 | 'name' => 'wpinv_city', |
1681 | 1681 | 'value' => $billing_details['city'], |
1682 | 1682 | 'class' => 'wpi-input form-control required', |
1683 | - 'placeholder' => __( 'City', 'invoicing' ), |
|
1683 | + 'placeholder' => __('City', 'invoicing'), |
|
1684 | 1684 | 'required' => true, |
1685 | - ) ); |
|
1685 | + )); |
|
1686 | 1686 | ?> |
1687 | 1687 | </p> |
1688 | 1688 | <p id="wpinv_country_box" class="wpi-cart-field wpi-col2 wpi-colf"> |
1689 | - <label for="wpinv_country" class="wpi-label"><?php _e( 'Country', 'invoicing' );?><span class="wpi-required">*</span></label> |
|
1690 | - <?php echo wpinv_html_select( array( |
|
1689 | + <label for="wpinv_country" class="wpi-label"><?php _e('Country', 'invoicing'); ?><span class="wpi-required">*</span></label> |
|
1690 | + <?php echo wpinv_html_select(array( |
|
1691 | 1691 | 'options' => wpinv_get_country_list(), |
1692 | 1692 | 'name' => 'wpinv_country', |
1693 | 1693 | 'id' => 'wpinv_country', |
@@ -1695,16 +1695,16 @@ discard block |
||
1695 | 1695 | 'show_option_all' => false, |
1696 | 1696 | 'show_option_none' => false, |
1697 | 1697 | 'class' => 'wpi-input form-control required', |
1698 | - 'placeholder' => __( 'Choose a country', 'invoicing' ), |
|
1698 | + 'placeholder' => __('Choose a country', 'invoicing'), |
|
1699 | 1699 | 'required' => true, |
1700 | - ) ); ?> |
|
1700 | + )); ?> |
|
1701 | 1701 | </p> |
1702 | 1702 | <p id="wpinv_state_box" class="wpi-cart-field wpi-col2 wpi-coll"> |
1703 | - <label for="wpinv_state" class="wpi-label"><?php _e( 'State / Province', 'invoicing' );?><span class="wpi-required">*</span></label> |
|
1703 | + <label for="wpinv_state" class="wpi-label"><?php _e('State / Province', 'invoicing'); ?><span class="wpi-required">*</span></label> |
|
1704 | 1704 | <?php |
1705 | - $states = wpinv_get_country_states( $selected_country ); |
|
1706 | - if( !empty( $states ) ) { |
|
1707 | - echo wpinv_html_select( array( |
|
1705 | + $states = wpinv_get_country_states($selected_country); |
|
1706 | + if (!empty($states)) { |
|
1707 | + echo wpinv_html_select(array( |
|
1708 | 1708 | 'options' => $states, |
1709 | 1709 | 'name' => 'wpinv_state', |
1710 | 1710 | 'id' => 'wpinv_state', |
@@ -1712,60 +1712,60 @@ discard block |
||
1712 | 1712 | 'show_option_all' => false, |
1713 | 1713 | 'show_option_none' => false, |
1714 | 1714 | 'class' => 'wpi-input form-control required', |
1715 | - 'placeholder' => __( 'Choose a state', 'invoicing' ), |
|
1715 | + 'placeholder' => __('Choose a state', 'invoicing'), |
|
1716 | 1716 | 'required' => true, |
1717 | - ) ); |
|
1717 | + )); |
|
1718 | 1718 | } else { |
1719 | - echo wpinv_html_text( array( |
|
1719 | + echo wpinv_html_text(array( |
|
1720 | 1720 | 'name' => 'wpinv_state', |
1721 | 1721 | 'value' => $billing_details['state'], |
1722 | 1722 | 'id' => 'wpinv_state', |
1723 | 1723 | 'class' => 'wpi-input form-control required', |
1724 | - 'placeholder' => __( 'State / Province', 'invoicing' ), |
|
1724 | + 'placeholder' => __('State / Province', 'invoicing'), |
|
1725 | 1725 | 'required' => true, |
1726 | - ) ); |
|
1726 | + )); |
|
1727 | 1727 | } |
1728 | 1728 | ?> |
1729 | 1729 | </p> |
1730 | 1730 | <p class="wpi-cart-field wpi-col2 wpi-colf"> |
1731 | - <label for="wpinv_zip" class="wpi-label"><?php _e( 'ZIP / Postcode', 'invoicing' );?></label> |
|
1731 | + <label for="wpinv_zip" class="wpi-label"><?php _e('ZIP / Postcode', 'invoicing'); ?></label> |
|
1732 | 1732 | <?php |
1733 | - echo wpinv_html_text( array( |
|
1733 | + echo wpinv_html_text(array( |
|
1734 | 1734 | 'name' => 'wpinv_zip', |
1735 | 1735 | 'value' => $billing_details['zip'], |
1736 | 1736 | 'id' => 'wpinv_zip', |
1737 | 1737 | 'class' => 'wpi-input form-control', |
1738 | - 'placeholder' => __( 'ZIP / Postcode', 'invoicing' ), |
|
1739 | - ) ); |
|
1738 | + 'placeholder' => __('ZIP / Postcode', 'invoicing'), |
|
1739 | + )); |
|
1740 | 1740 | ?> |
1741 | 1741 | </p> |
1742 | 1742 | <p class="wpi-cart-field wpi-col2 wpi-coll"> |
1743 | - <label for="wpinv_phone" class="wpi-label"><?php _e( 'Phone', 'invoicing' );?><?php if ( wpinv_get_option( 'phone_mandatory' ) ) { echo '<span class="wpi-required">*</span>'; } ?></label> |
|
1743 | + <label for="wpinv_phone" class="wpi-label"><?php _e('Phone', 'invoicing'); ?><?php if (wpinv_get_option('phone_mandatory')) { echo '<span class="wpi-required">*</span>'; } ?></label> |
|
1744 | 1744 | <?php |
1745 | - echo wpinv_html_text( array( |
|
1745 | + echo wpinv_html_text(array( |
|
1746 | 1746 | 'id' => 'wpinv_phone', |
1747 | 1747 | 'name' => 'wpinv_phone', |
1748 | 1748 | 'value' => $billing_details['phone'], |
1749 | 1749 | 'class' => 'wpi-input form-control', |
1750 | - 'placeholder' => __( 'Phone', 'invoicing' ), |
|
1751 | - 'required' => (bool)wpinv_get_option( 'phone_mandatory' ), |
|
1752 | - ) ); |
|
1750 | + 'placeholder' => __('Phone', 'invoicing'), |
|
1751 | + 'required' => (bool)wpinv_get_option('phone_mandatory'), |
|
1752 | + )); |
|
1753 | 1753 | ?> |
1754 | 1754 | </p> |
1755 | - <?php do_action( 'wpinv_checkout_billing_fields_last', $billing_details ); ?> |
|
1755 | + <?php do_action('wpinv_checkout_billing_fields_last', $billing_details); ?> |
|
1756 | 1756 | <div class="clearfix"></div> |
1757 | 1757 | </div> |
1758 | 1758 | </div> |
1759 | - <?php do_action( 'wpinv_after_billing_fields', $billing_details ); ?> |
|
1759 | + <?php do_action('wpinv_after_billing_fields', $billing_details); ?> |
|
1760 | 1760 | </div> |
1761 | 1761 | <?php |
1762 | 1762 | } |
1763 | 1763 | } |
1764 | -add_action( 'wpinv_checkout_billing_info', 'wpinv_checkout_billing_info' ); |
|
1764 | +add_action('wpinv_checkout_billing_info', 'wpinv_checkout_billing_info'); |
|
1765 | 1765 | |
1766 | 1766 | function wpinv_checkout_hidden_fields() { |
1767 | 1767 | ?> |
1768 | - <?php if ( is_user_logged_in() ) { ?> |
|
1768 | + <?php if (is_user_logged_in()) { ?> |
|
1769 | 1769 | <input type="hidden" name="wpinv_user_id" value="<?php echo get_current_user_id(); ?>"/> |
1770 | 1770 | <?php } ?> |
1771 | 1771 | <input type="hidden" name="wpi_action" value="payment" /> |
@@ -1775,9 +1775,9 @@ discard block |
||
1775 | 1775 | function wpinv_checkout_button_purchase() { |
1776 | 1776 | ob_start(); |
1777 | 1777 | ?> |
1778 | - <input type="submit" class="btn btn-success wpinv-submit" id="wpinv-payment-button" data-value="<?php esc_attr_e( 'Proceed to Pay', 'invoicing' ) ?>" name="wpinv_payment" value="<?php esc_attr_e( 'Proceed to Pay', 'invoicing' ) ?>"/> |
|
1778 | + <input type="submit" class="btn btn-success wpinv-submit" id="wpinv-payment-button" data-value="<?php esc_attr_e('Proceed to Pay', 'invoicing') ?>" name="wpinv_payment" value="<?php esc_attr_e('Proceed to Pay', 'invoicing') ?>"/> |
|
1779 | 1779 | <?php |
1780 | - return apply_filters( 'wpinv_checkout_button_purchase', ob_get_clean() ); |
|
1780 | + return apply_filters('wpinv_checkout_button_purchase', ob_get_clean()); |
|
1781 | 1781 | } |
1782 | 1782 | |
1783 | 1783 | function wpinv_checkout_total() { |
@@ -1786,96 +1786,96 @@ discard block |
||
1786 | 1786 | <div id="wpinv_checkout_total" class="panel panel-info"> |
1787 | 1787 | <div class="panel-body"> |
1788 | 1788 | <?php |
1789 | - do_action( 'wpinv_purchase_form_before_checkout_total' ); |
|
1789 | + do_action('wpinv_purchase_form_before_checkout_total'); |
|
1790 | 1790 | ?> |
1791 | - <strong><?php _e( 'Invoice Total:', 'invoicing' ) ?></strong> <span class="wpinv-chdeckout-total"><?php echo $cart_total;?></span> |
|
1791 | + <strong><?php _e('Invoice Total:', 'invoicing') ?></strong> <span class="wpinv-chdeckout-total"><?php echo $cart_total; ?></span> |
|
1792 | 1792 | <?php |
1793 | - do_action( 'wpinv_purchase_form_after_checkout_total' ); |
|
1793 | + do_action('wpinv_purchase_form_after_checkout_total'); |
|
1794 | 1794 | ?> |
1795 | 1795 | </div> |
1796 | 1796 | </div> |
1797 | 1797 | <?php |
1798 | 1798 | } |
1799 | -add_action( 'wpinv_checkout_form_bottom', 'wpinv_checkout_total', 9998 ); |
|
1799 | +add_action('wpinv_checkout_form_bottom', 'wpinv_checkout_total', 9998); |
|
1800 | 1800 | |
1801 | 1801 | function wpinv_checkout_submit() { |
1802 | 1802 | ?> |
1803 | 1803 | <div id="wpinv_purchase_submit" class="panel panel-success"> |
1804 | 1804 | <div class="panel-body text-center"> |
1805 | 1805 | <?php |
1806 | - do_action( 'wpinv_purchase_form_before_submit' ); |
|
1806 | + do_action('wpinv_purchase_form_before_submit'); |
|
1807 | 1807 | wpinv_checkout_hidden_fields(); |
1808 | 1808 | echo wpinv_checkout_button_purchase(); |
1809 | - do_action( 'wpinv_purchase_form_after_submit' ); |
|
1809 | + do_action('wpinv_purchase_form_after_submit'); |
|
1810 | 1810 | ?> |
1811 | 1811 | </div> |
1812 | 1812 | </div> |
1813 | 1813 | <?php |
1814 | 1814 | } |
1815 | -add_action( 'wpinv_checkout_form_bottom', 'wpinv_checkout_submit', 9999 ); |
|
1815 | +add_action('wpinv_checkout_form_bottom', 'wpinv_checkout_submit', 9999); |
|
1816 | 1816 | |
1817 | -function wpinv_receipt_billing_address( $invoice_id = 0 ) { |
|
1818 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
1817 | +function wpinv_receipt_billing_address($invoice_id = 0) { |
|
1818 | + $invoice = wpinv_get_invoice($invoice_id); |
|
1819 | 1819 | |
1820 | - if ( empty( $invoice ) ) { |
|
1820 | + if (empty($invoice)) { |
|
1821 | 1821 | return NULL; |
1822 | 1822 | } |
1823 | 1823 | |
1824 | 1824 | $billing_details = $invoice->get_user_info(); |
1825 | 1825 | $address_row = ''; |
1826 | - if ( $address = $billing_details['address'] ) { |
|
1827 | - $address_row .= wpautop( wp_kses_post( $address ) ); |
|
1826 | + if ($address = $billing_details['address']) { |
|
1827 | + $address_row .= wpautop(wp_kses_post($address)); |
|
1828 | 1828 | } |
1829 | 1829 | |
1830 | 1830 | $address_fields = array(); |
1831 | - if ( !empty( $billing_details['city'] ) ) { |
|
1831 | + if (!empty($billing_details['city'])) { |
|
1832 | 1832 | $address_fields[] = $billing_details['city']; |
1833 | 1833 | } |
1834 | 1834 | |
1835 | - $billing_country = !empty( $billing_details['country'] ) ? $billing_details['country'] : ''; |
|
1836 | - if ( !empty( $billing_details['state'] ) ) { |
|
1837 | - $address_fields[] = wpinv_state_name( $billing_details['state'], $billing_country ); |
|
1835 | + $billing_country = !empty($billing_details['country']) ? $billing_details['country'] : ''; |
|
1836 | + if (!empty($billing_details['state'])) { |
|
1837 | + $address_fields[] = wpinv_state_name($billing_details['state'], $billing_country); |
|
1838 | 1838 | } |
1839 | 1839 | |
1840 | - if ( !empty( $billing_country ) ) { |
|
1841 | - $address_fields[] = wpinv_country_name( $billing_country ); |
|
1840 | + if (!empty($billing_country)) { |
|
1841 | + $address_fields[] = wpinv_country_name($billing_country); |
|
1842 | 1842 | } |
1843 | 1843 | |
1844 | - if ( !empty( $address_fields ) ) { |
|
1845 | - $address_fields = implode( ", ", $address_fields ); |
|
1844 | + if (!empty($address_fields)) { |
|
1845 | + $address_fields = implode(", ", $address_fields); |
|
1846 | 1846 | |
1847 | - if ( !empty( $billing_details['zip'] ) ) { |
|
1847 | + if (!empty($billing_details['zip'])) { |
|
1848 | 1848 | $address_fields .= ' ' . $billing_details['zip']; |
1849 | 1849 | } |
1850 | 1850 | |
1851 | - $address_row .= wpautop( wp_kses_post( $address_fields ) ); |
|
1851 | + $address_row .= wpautop(wp_kses_post($address_fields)); |
|
1852 | 1852 | } |
1853 | 1853 | ob_start(); |
1854 | 1854 | ?> |
1855 | 1855 | <table class="table table-bordered table-sm wpi-billing-details"> |
1856 | 1856 | <tbody> |
1857 | 1857 | <tr class="wpi-receipt-name"> |
1858 | - <th class="text-left"><?php _e( 'Name', 'invoicing' ); ?></th> |
|
1859 | - <td><?php echo esc_html( trim( $billing_details['first_name'] . ' ' . $billing_details['last_name'] ) ) ;?></td> |
|
1858 | + <th class="text-left"><?php _e('Name', 'invoicing'); ?></th> |
|
1859 | + <td><?php echo esc_html(trim($billing_details['first_name'] . ' ' . $billing_details['last_name'])); ?></td> |
|
1860 | 1860 | </tr> |
1861 | 1861 | <tr class="wpi-receipt-email"> |
1862 | - <th class="text-left"><?php _e( 'Email', 'invoicing' ); ?></th> |
|
1863 | - <td><?php echo $billing_details['email'] ;?></td> |
|
1862 | + <th class="text-left"><?php _e('Email', 'invoicing'); ?></th> |
|
1863 | + <td><?php echo $billing_details['email']; ?></td> |
|
1864 | 1864 | </tr> |
1865 | - <?php if ( $billing_details['company'] ) { ?> |
|
1865 | + <?php if ($billing_details['company']) { ?> |
|
1866 | 1866 | <tr class="wpi-receipt-company"> |
1867 | - <th class="text-left"><?php _e( 'Company', 'invoicing' ); ?></th> |
|
1868 | - <td><?php echo esc_html( $billing_details['company'] ) ;?></td> |
|
1867 | + <th class="text-left"><?php _e('Company', 'invoicing'); ?></th> |
|
1868 | + <td><?php echo esc_html($billing_details['company']); ?></td> |
|
1869 | 1869 | </tr> |
1870 | 1870 | <?php } ?> |
1871 | 1871 | <tr class="wpi-receipt-address"> |
1872 | - <th class="text-left"><?php _e( 'Address', 'invoicing' ); ?></th> |
|
1873 | - <td><?php echo $address_row ;?></td> |
|
1872 | + <th class="text-left"><?php _e('Address', 'invoicing'); ?></th> |
|
1873 | + <td><?php echo $address_row; ?></td> |
|
1874 | 1874 | </tr> |
1875 | - <?php if ( $billing_details['phone'] ) { ?> |
|
1875 | + <?php if ($billing_details['phone']) { ?> |
|
1876 | 1876 | <tr class="wpi-receipt-phone"> |
1877 | - <th class="text-left"><?php _e( 'Phone', 'invoicing' ); ?></th> |
|
1878 | - <td><?php echo esc_html( $billing_details['phone'] ) ;?></td> |
|
1877 | + <th class="text-left"><?php _e('Phone', 'invoicing'); ?></th> |
|
1878 | + <td><?php echo esc_html($billing_details['phone']); ?></td> |
|
1879 | 1879 | </tr> |
1880 | 1880 | <?php } ?> |
1881 | 1881 | </tbody> |
@@ -1883,98 +1883,98 @@ discard block |
||
1883 | 1883 | <?php |
1884 | 1884 | $output = ob_get_clean(); |
1885 | 1885 | |
1886 | - $output = apply_filters( 'wpinv_receipt_billing_address', $output, $invoice_id ); |
|
1886 | + $output = apply_filters('wpinv_receipt_billing_address', $output, $invoice_id); |
|
1887 | 1887 | |
1888 | 1888 | echo $output; |
1889 | 1889 | } |
1890 | 1890 | |
1891 | -function wpinv_filter_success_page_content( $content ) { |
|
1892 | - if ( isset( $_GET['payment-confirm'] ) && wpinv_is_success_page() ) { |
|
1893 | - if ( has_filter( 'wpinv_payment_confirm_' . sanitize_text_field( $_GET['payment-confirm'] ) ) ) { |
|
1894 | - $content = apply_filters( 'wpinv_payment_confirm_' . sanitize_text_field( $_GET['payment-confirm'] ), $content ); |
|
1891 | +function wpinv_filter_success_page_content($content) { |
|
1892 | + if (isset($_GET['payment-confirm']) && wpinv_is_success_page()) { |
|
1893 | + if (has_filter('wpinv_payment_confirm_' . sanitize_text_field($_GET['payment-confirm']))) { |
|
1894 | + $content = apply_filters('wpinv_payment_confirm_' . sanitize_text_field($_GET['payment-confirm']), $content); |
|
1895 | 1895 | } |
1896 | 1896 | } |
1897 | 1897 | |
1898 | 1898 | return $content; |
1899 | 1899 | } |
1900 | -add_filter( 'the_content', 'wpinv_filter_success_page_content', 99999 ); |
|
1900 | +add_filter('the_content', 'wpinv_filter_success_page_content', 99999); |
|
1901 | 1901 | |
1902 | -function wpinv_receipt_actions( $invoice ) { |
|
1903 | - if ( !empty( $invoice ) ) { |
|
1902 | +function wpinv_receipt_actions($invoice) { |
|
1903 | + if (!empty($invoice)) { |
|
1904 | 1904 | $actions = array( |
1905 | 1905 | 'print' => array( |
1906 | 1906 | 'url' => $invoice->get_view_url(), |
1907 | - 'name' => __( 'Print Invoice', 'invoicing' ), |
|
1907 | + 'name' => __('Print Invoice', 'invoicing'), |
|
1908 | 1908 | 'class' => 'btn-primary', |
1909 | 1909 | ), |
1910 | 1910 | 'history' => array( |
1911 | 1911 | 'url' => wpinv_get_history_page_uri(), |
1912 | - 'name' => __( 'Invoice History', 'invoicing' ), |
|
1912 | + 'name' => __('Invoice History', 'invoicing'), |
|
1913 | 1913 | 'class' => 'btn-warning', |
1914 | 1914 | ) |
1915 | 1915 | ); |
1916 | 1916 | |
1917 | - $actions = apply_filters( 'wpinv_invoice_receipt_actions', $actions, $invoice ); |
|
1917 | + $actions = apply_filters('wpinv_invoice_receipt_actions', $actions, $invoice); |
|
1918 | 1918 | |
1919 | - if ( !empty( $actions ) ) { |
|
1919 | + if (!empty($actions)) { |
|
1920 | 1920 | ?> |
1921 | 1921 | <div class="wpinv-receipt-actions text-right"> |
1922 | - <?php foreach ( $actions as $key => $action ) { $class = !empty($action['class']) ? sanitize_html_class( $action['class'] ) : ''; ?> |
|
1923 | - <a href="<?php echo esc_url( $action['url'] );?>" class="btn btn-sm <?php echo $class . ' ' . sanitize_html_class( $key );?>" <?php echo ( !empty($action['attrs']) ? $action['attrs'] : '' ) ;?>><?php echo esc_html( $action['name'] );?></a> |
|
1922 | + <?php foreach ($actions as $key => $action) { $class = !empty($action['class']) ? sanitize_html_class($action['class']) : ''; ?> |
|
1923 | + <a href="<?php echo esc_url($action['url']); ?>" class="btn btn-sm <?php echo $class . ' ' . sanitize_html_class($key); ?>" <?php echo (!empty($action['attrs']) ? $action['attrs'] : ''); ?>><?php echo esc_html($action['name']); ?></a> |
|
1924 | 1924 | <?php } ?> |
1925 | 1925 | </div> |
1926 | 1926 | <?php |
1927 | 1927 | } |
1928 | 1928 | } |
1929 | 1929 | } |
1930 | -add_action( 'wpinv_receipt_start', 'wpinv_receipt_actions', -10, 1 ); |
|
1930 | +add_action('wpinv_receipt_start', 'wpinv_receipt_actions', -10, 1); |
|
1931 | 1931 | |
1932 | -function wpinv_invoice_link( $invoice_id ) { |
|
1933 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
1932 | +function wpinv_invoice_link($invoice_id) { |
|
1933 | + $invoice = wpinv_get_invoice($invoice_id); |
|
1934 | 1934 | |
1935 | - if ( empty( $invoice ) ) { |
|
1935 | + if (empty($invoice)) { |
|
1936 | 1936 | return NULL; |
1937 | 1937 | } |
1938 | 1938 | |
1939 | - $invoice_link = '<a href="' . esc_url( $invoice->get_view_url() ) . '">' . $invoice->get_number() . '</a>'; |
|
1939 | + $invoice_link = '<a href="' . esc_url($invoice->get_view_url()) . '">' . $invoice->get_number() . '</a>'; |
|
1940 | 1940 | |
1941 | - return apply_filters( 'wpinv_get_invoice_link', $invoice_link, $invoice ); |
|
1941 | + return apply_filters('wpinv_get_invoice_link', $invoice_link, $invoice); |
|
1942 | 1942 | } |
1943 | 1943 | |
1944 | -function wpinv_invoice_subscription_details( $invoice ) { |
|
1945 | - if ( !empty( $invoice ) && $invoice->is_recurring() && !wpinv_is_subscription_payment( $invoice ) ) { |
|
1944 | +function wpinv_invoice_subscription_details($invoice) { |
|
1945 | + if (!empty($invoice) && $invoice->is_recurring() && !wpinv_is_subscription_payment($invoice)) { |
|
1946 | 1946 | $total_payments = (int)$invoice->get_total_payments(); |
1947 | 1947 | $payments = $invoice->get_child_payments(); |
1948 | 1948 | |
1949 | 1949 | $subscription = $invoice->get_subscription_data(); |
1950 | 1950 | |
1951 | - if ( !( !empty( $subscription ) && !empty( $subscription['item_id'] ) ) ) { |
|
1951 | + if (!(!empty($subscription) && !empty($subscription['item_id']))) { |
|
1952 | 1952 | return; |
1953 | 1953 | } |
1954 | 1954 | |
1955 | - $billing_cycle = wpinv_get_billing_cycle( $subscription['initial_amount'], $subscription['recurring_amount'], $subscription['period'], $subscription['interval'], $subscription['bill_times'], $subscription['trial_period'], $subscription['trial_interval'], $invoice->get_currency() ); |
|
1956 | - $times_billed = $total_payments . ' / ' . ( ( (int)$subscription['bill_times'] == 0 ) ? __( 'Until cancelled', 'invoicing' ) : $subscription['bill_times'] ); |
|
1955 | + $billing_cycle = wpinv_get_billing_cycle($subscription['initial_amount'], $subscription['recurring_amount'], $subscription['period'], $subscription['interval'], $subscription['bill_times'], $subscription['trial_period'], $subscription['trial_interval'], $invoice->get_currency()); |
|
1956 | + $times_billed = $total_payments . ' / ' . (((int)$subscription['bill_times'] == 0) ? __('Until cancelled', 'invoicing') : $subscription['bill_times']); |
|
1957 | 1957 | |
1958 | 1958 | $subscription_status = $invoice->get_subscription_status(); |
1959 | 1959 | |
1960 | 1960 | $status_desc = ''; |
1961 | - if ( $subscription_status == 'trialing' && $trial_end_date = $invoice->get_trial_end_date() ) { |
|
1962 | - $status_desc = wp_sprintf( __( 'Until: %s', 'invoicing' ), $trial_end_date ); |
|
1963 | - } else if ( $subscription_status == 'cancelled' && $cancelled_date = $invoice->get_cancelled_date() ) { |
|
1964 | - $status_desc = wp_sprintf( __( 'On: %s', 'invoicing' ), $cancelled_date ); |
|
1961 | + if ($subscription_status == 'trialing' && $trial_end_date = $invoice->get_trial_end_date()) { |
|
1962 | + $status_desc = wp_sprintf(__('Until: %s', 'invoicing'), $trial_end_date); |
|
1963 | + } else if ($subscription_status == 'cancelled' && $cancelled_date = $invoice->get_cancelled_date()) { |
|
1964 | + $status_desc = wp_sprintf(__('On: %s', 'invoicing'), $cancelled_date); |
|
1965 | 1965 | } |
1966 | 1966 | $status_desc = $status_desc != '' ? '<span class="meta">' . $status_desc . '</span>' : ''; |
1967 | 1967 | ?> |
1968 | 1968 | <div class="wpinv-subscriptions-details"> |
1969 | - <h3 class="wpinv-subscriptions-t"><?php echo apply_filters( 'wpinv_subscription_details_title', __( 'Subscription Details', 'invoicing' ) ); ?></h3> |
|
1969 | + <h3 class="wpinv-subscriptions-t"><?php echo apply_filters('wpinv_subscription_details_title', __('Subscription Details', 'invoicing')); ?></h3> |
|
1970 | 1970 | <table class="table"> |
1971 | 1971 | <thead> |
1972 | 1972 | <tr> |
1973 | - <th><?php _e( 'Billing Cycle', 'invoicing' ) ;?></th> |
|
1974 | - <th><?php _e( 'Start Date', 'invoicing' ) ;?></th> |
|
1975 | - <th><?php _e( 'Expiration Date', 'invoicing' ) ;?></th> |
|
1976 | - <th class="text-center"><?php _e( 'Times Billed', 'invoicing' ) ;?></th> |
|
1977 | - <th class="text-center"><?php _e( 'Status', 'invoicing' ) ;?></th> |
|
1973 | + <th><?php _e('Billing Cycle', 'invoicing'); ?></th> |
|
1974 | + <th><?php _e('Start Date', 'invoicing'); ?></th> |
|
1975 | + <th><?php _e('Expiration Date', 'invoicing'); ?></th> |
|
1976 | + <th class="text-center"><?php _e('Times Billed', 'invoicing'); ?></th> |
|
1977 | + <th class="text-center"><?php _e('Status', 'invoicing'); ?></th> |
|
1978 | 1978 | </tr> |
1979 | 1979 | </thead> |
1980 | 1980 | <tbody> |
@@ -1983,32 +1983,32 @@ discard block |
||
1983 | 1983 | <td><?php echo $invoice->get_subscription_start(); ?></td> |
1984 | 1984 | <td><?php echo $invoice->get_subscription_end(); ?></td> |
1985 | 1985 | <td class="text-center"><?php echo $times_billed; ?></td> |
1986 | - <td class="text-center wpi-sub-status"><?php echo $invoice->get_subscription_status_label() ;?> |
|
1986 | + <td class="text-center wpi-sub-status"><?php echo $invoice->get_subscription_status_label(); ?> |
|
1987 | 1987 | <?php echo $status_desc; ?> |
1988 | 1988 | </td> |
1989 | 1989 | </tr> |
1990 | 1990 | </tbody> |
1991 | 1991 | </table> |
1992 | 1992 | </div> |
1993 | - <?php if ( !empty( $payments ) ) { ?> |
|
1993 | + <?php if (!empty($payments)) { ?> |
|
1994 | 1994 | <div class="wpinv-renewal-payments"> |
1995 | - <h3 class="wpinv-renewals-t"><?php echo apply_filters( 'wpinv_renewal_payments_title', __( 'Renewal Payments', 'invoicing' ) ); ?></h3> |
|
1995 | + <h3 class="wpinv-renewals-t"><?php echo apply_filters('wpinv_renewal_payments_title', __('Renewal Payments', 'invoicing')); ?></h3> |
|
1996 | 1996 | <table class="table"> |
1997 | 1997 | <thead> |
1998 | 1998 | <tr> |
1999 | 1999 | <th>#</th> |
2000 | - <th><?php _e( 'Invoice', 'invoicing' ) ;?></th> |
|
2001 | - <th><?php _e( 'Date', 'invoicing' ) ;?></th> |
|
2002 | - <th class="text-right"><?php _e( 'Amount', 'invoicing' ) ;?></th> |
|
2000 | + <th><?php _e('Invoice', 'invoicing'); ?></th> |
|
2001 | + <th><?php _e('Date', 'invoicing'); ?></th> |
|
2002 | + <th class="text-right"><?php _e('Amount', 'invoicing'); ?></th> |
|
2003 | 2003 | </tr> |
2004 | 2004 | </thead> |
2005 | 2005 | <tbody> |
2006 | - <?php foreach ( $payments as $key => $invoice_id ) { ?> |
|
2006 | + <?php foreach ($payments as $key => $invoice_id) { ?> |
|
2007 | 2007 | <tr> |
2008 | - <th scope="row"><?php echo ( $key + 1 );?></th> |
|
2009 | - <td><?php echo wpinv_invoice_link( $invoice_id ) ;?></td> |
|
2010 | - <td><?php echo wpinv_get_invoice_date( $invoice_id ); ?></td> |
|
2011 | - <td class="text-right"><?php echo wpinv_payment_total( $invoice_id, true ); ?></td> |
|
2008 | + <th scope="row"><?php echo ($key + 1); ?></th> |
|
2009 | + <td><?php echo wpinv_invoice_link($invoice_id); ?></td> |
|
2010 | + <td><?php echo wpinv_get_invoice_date($invoice_id); ?></td> |
|
2011 | + <td class="text-right"><?php echo wpinv_payment_total($invoice_id, true); ?></td> |
|
2012 | 2012 | </tr> |
2013 | 2013 | <?php } ?> |
2014 | 2014 | <tr><td colspan="4" style="padding:0"></td></tr> |
@@ -2020,52 +2020,52 @@ discard block |
||
2020 | 2020 | } |
2021 | 2021 | } |
2022 | 2022 | |
2023 | -function wpinv_cart_total_label( $label, $invoice ) { |
|
2024 | - if ( empty( $invoice ) ) { |
|
2023 | +function wpinv_cart_total_label($label, $invoice) { |
|
2024 | + if (empty($invoice)) { |
|
2025 | 2025 | return $label; |
2026 | 2026 | } |
2027 | 2027 | |
2028 | 2028 | $prefix_label = ''; |
2029 | - if ( $invoice->is_parent() && $item_id = $invoice->get_recurring() ) { |
|
2030 | - $prefix_label = '<span class="label label-primary label-recurring">' . __( 'Recurring Payment', 'invoicing' ) . '</span> ' . wpinv_subscription_payment_desc( $invoice ); |
|
2031 | - } else if ( $invoice->is_renewal() ) { |
|
2032 | - $prefix_label = '<span class="label label-primary label-renewal">' . __( 'Renewal Payment', 'invoicing' ) . '</span> '; |
|
2029 | + if ($invoice->is_parent() && $item_id = $invoice->get_recurring()) { |
|
2030 | + $prefix_label = '<span class="label label-primary label-recurring">' . __('Recurring Payment', 'invoicing') . '</span> ' . wpinv_subscription_payment_desc($invoice); |
|
2031 | + } else if ($invoice->is_renewal()) { |
|
2032 | + $prefix_label = '<span class="label label-primary label-renewal">' . __('Renewal Payment', 'invoicing') . '</span> '; |
|
2033 | 2033 | } |
2034 | 2034 | |
2035 | - if ( $prefix_label != '' ) { |
|
2036 | - $label = '<span class="wpinv-cart-sub-desc">' . $prefix_label . '</span> ' . $label; |
|
2035 | + if ($prefix_label != '') { |
|
2036 | + $label = '<span class="wpinv-cart-sub-desc">' . $prefix_label . '</span> ' . $label; |
|
2037 | 2037 | } |
2038 | 2038 | |
2039 | 2039 | return $label; |
2040 | 2040 | } |
2041 | -add_filter( 'wpinv_cart_total_label', 'wpinv_cart_total_label', 10, 2 ); |
|
2042 | -add_filter( 'wpinv_email_cart_total_label', 'wpinv_cart_total_label', 10, 2 ); |
|
2043 | -add_filter( 'wpinv_print_cart_total_label', 'wpinv_cart_total_label', 10, 2 ); |
|
2041 | +add_filter('wpinv_cart_total_label', 'wpinv_cart_total_label', 10, 2); |
|
2042 | +add_filter('wpinv_email_cart_total_label', 'wpinv_cart_total_label', 10, 2); |
|
2043 | +add_filter('wpinv_print_cart_total_label', 'wpinv_cart_total_label', 10, 2); |
|
2044 | 2044 | |
2045 | -add_action( 'wpinv_invoice_print_middle', 'wpinv_invoice_subscription_details', 10, 1 ); |
|
2045 | +add_action('wpinv_invoice_print_middle', 'wpinv_invoice_subscription_details', 10, 1); |
|
2046 | 2046 | |
2047 | -function wpinv_invoice_print_description( $invoice ) { |
|
2048 | - if ( empty( $invoice ) ) { |
|
2047 | +function wpinv_invoice_print_description($invoice) { |
|
2048 | + if (empty($invoice)) { |
|
2049 | 2049 | return NULL; |
2050 | 2050 | } |
2051 | - if ( $description = wpinv_get_invoice_description( $invoice->ID ) ) { |
|
2051 | + if ($description = wpinv_get_invoice_description($invoice->ID)) { |
|
2052 | 2052 | ?> |
2053 | 2053 | <div class="row wpinv-lower"> |
2054 | 2054 | <div class="col-sm-12 wpinv-description"> |
2055 | - <?php echo wpautop( $description ); ?> |
|
2055 | + <?php echo wpautop($description); ?> |
|
2056 | 2056 | </div> |
2057 | 2057 | </div> |
2058 | 2058 | <?php |
2059 | 2059 | } |
2060 | 2060 | } |
2061 | -add_action( 'wpinv_invoice_print_middle', 'wpinv_invoice_print_description', 10.1, 1 ); |
|
2061 | +add_action('wpinv_invoice_print_middle', 'wpinv_invoice_print_description', 10.1, 1); |
|
2062 | 2062 | |
2063 | -function wpinv_invoice_print_payment_info( $invoice ) { |
|
2064 | - if ( empty( $invoice ) ) { |
|
2063 | +function wpinv_invoice_print_payment_info($invoice) { |
|
2064 | + if (empty($invoice)) { |
|
2065 | 2065 | return NULL; |
2066 | 2066 | } |
2067 | 2067 | |
2068 | - if ( $payments_info = wpinv_display_payments_info( $invoice->ID, false ) ) { |
|
2068 | + if ($payments_info = wpinv_display_payments_info($invoice->ID, false)) { |
|
2069 | 2069 | ?> |
2070 | 2070 | <div class="row wpinv-payments"> |
2071 | 2071 | <div class="col-sm-12"> |
@@ -2077,40 +2077,40 @@ discard block |
||
2077 | 2077 | } |
2078 | 2078 | // add_action( 'wpinv_invoice_print_after_line_items', 'wpinv_invoice_print_payment_info', 10, 1 ); |
2079 | 2079 | |
2080 | -function wpinv_get_invoice_note_line_item( $note, $echo = true ) { |
|
2081 | - if ( empty( $note ) ) { |
|
2080 | +function wpinv_get_invoice_note_line_item($note, $echo = true) { |
|
2081 | + if (empty($note)) { |
|
2082 | 2082 | return NULL; |
2083 | 2083 | } |
2084 | 2084 | |
2085 | - if ( is_int( $note ) ) { |
|
2086 | - $note = get_comment( $note ); |
|
2085 | + if (is_int($note)) { |
|
2086 | + $note = get_comment($note); |
|
2087 | 2087 | } |
2088 | 2088 | |
2089 | - if ( !( is_object( $note ) && is_a( $note, 'WP_Comment' ) ) ) { |
|
2089 | + if (!(is_object($note) && is_a($note, 'WP_Comment'))) { |
|
2090 | 2090 | return NULL; |
2091 | 2091 | } |
2092 | 2092 | |
2093 | - $note_classes = array( 'note' ); |
|
2094 | - $note_classes[] = get_comment_meta( $note->comment_ID, '_wpi_customer_note', true ) ? 'customer-note' : ''; |
|
2095 | - $note_classes[] = $note->comment_author === __( 'GeoDirectory', 'invoicing' ) ? 'system-note' : ''; |
|
2096 | - $note_classes = apply_filters( 'wpinv_invoice_note_class', array_filter( $note_classes ), $note ); |
|
2097 | - $note_classes = !empty( $note_classes ) ? implode( ' ', $note_classes ) : ''; |
|
2093 | + $note_classes = array('note'); |
|
2094 | + $note_classes[] = get_comment_meta($note->comment_ID, '_wpi_customer_note', true) ? 'customer-note' : ''; |
|
2095 | + $note_classes[] = $note->comment_author === __('GeoDirectory', 'invoicing') ? 'system-note' : ''; |
|
2096 | + $note_classes = apply_filters('wpinv_invoice_note_class', array_filter($note_classes), $note); |
|
2097 | + $note_classes = !empty($note_classes) ? implode(' ', $note_classes) : ''; |
|
2098 | 2098 | |
2099 | 2099 | ob_start(); |
2100 | 2100 | ?> |
2101 | - <li rel="<?php echo absint( $note->comment_ID ) ; ?>" class="<?php echo esc_attr( $note_classes ); ?>"> |
|
2101 | + <li rel="<?php echo absint($note->comment_ID); ?>" class="<?php echo esc_attr($note_classes); ?>"> |
|
2102 | 2102 | <div class="note_content"> |
2103 | - <?php echo wpautop( wptexturize( wp_kses_post( $note->comment_content ) ) ); ?> |
|
2103 | + <?php echo wpautop(wptexturize(wp_kses_post($note->comment_content))); ?> |
|
2104 | 2104 | </div> |
2105 | 2105 | <p class="meta"> |
2106 | - <abbr class="exact-date" title="<?php echo $note->comment_date; ?>"><?php printf( __( '%1$s - %2$s at %3$s', 'invoicing' ), $note->comment_author, date_i18n( get_option( 'date_format' ), strtotime( $note->comment_date ) ), date_i18n( get_option( 'time_format' ), strtotime( $note->comment_date ) ) ); ?></abbr> <a href="#" class="delete_note"><?php _e( 'Delete note', 'invoicing' ); ?></a> |
|
2106 | + <abbr class="exact-date" title="<?php echo $note->comment_date; ?>"><?php printf(__('%1$s - %2$s at %3$s', 'invoicing'), $note->comment_author, date_i18n(get_option('date_format'), strtotime($note->comment_date)), date_i18n(get_option('time_format'), strtotime($note->comment_date))); ?></abbr> <a href="#" class="delete_note"><?php _e('Delete note', 'invoicing'); ?></a> |
|
2107 | 2107 | </p> |
2108 | 2108 | </li> |
2109 | 2109 | <?php |
2110 | 2110 | $note_content = ob_get_clean(); |
2111 | - $note_content = apply_filters( 'wpinv_get_invoice_note_line_item', $note_content, $note, $echo ); |
|
2111 | + $note_content = apply_filters('wpinv_get_invoice_note_line_item', $note_content, $note, $echo); |
|
2112 | 2112 | |
2113 | - if ( $echo ) { |
|
2113 | + if ($echo) { |
|
2114 | 2114 | echo $note_content; |
2115 | 2115 | } else { |
2116 | 2116 | return $note_content; |
@@ -1,22 +1,22 @@ 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 | 22 | $item_types = wpinv_get_item_types(); |
@@ -27,17 +27,17 @@ discard block |
||
27 | 27 | } |
28 | 28 | |
29 | 29 | $cols = 5; |
30 | - if ( $item_quantities ) { |
|
30 | + if ($item_quantities) { |
|
31 | 31 | $cols++; |
32 | 32 | } |
33 | - if ( $use_taxes ) { |
|
33 | + if ($use_taxes) { |
|
34 | 34 | $cols++; |
35 | 35 | } |
36 | 36 | $class = ''; |
37 | - if ( $invoice->is_paid() ) { |
|
37 | + if ($invoice->is_paid()) { |
|
38 | 38 | $class .= ' wpinv-paid'; |
39 | 39 | } |
40 | - if ( $is_recurring ) { |
|
40 | + if ($is_recurring) { |
|
41 | 41 | $class .= ' wpi-recurring'; |
42 | 42 | } |
43 | 43 | ?> |
@@ -45,21 +45,21 @@ discard block |
||
45 | 45 | <table id="wpinv_items" class="wpinv-items" cellspacing="0" cellpadding="0"> |
46 | 46 | <thead> |
47 | 47 | <tr> |
48 | - <th class="id"><?php _e( 'ID', 'invoicing' );?></th> |
|
49 | - <th class="title"><?php _e( 'Item', 'invoicing' );?></th> |
|
50 | - <th class="price"><?php _e( 'Price', 'invoicing' );?></th> |
|
51 | - <?php if ( $item_quantities ) { ?> |
|
52 | - <th class="qty"><?php _e( 'Qty', 'invoicing' );?></th> |
|
48 | + <th class="id"><?php _e('ID', 'invoicing'); ?></th> |
|
49 | + <th class="title"><?php _e('Item', 'invoicing'); ?></th> |
|
50 | + <th class="price"><?php _e('Price', 'invoicing'); ?></th> |
|
51 | + <?php if ($item_quantities) { ?> |
|
52 | + <th class="qty"><?php _e('Qty', 'invoicing'); ?></th> |
|
53 | 53 | <?php } ?> |
54 | - <th class="total"><?php _e( 'Total', 'invoicing' );?></th> |
|
55 | - <?php if ( $use_taxes ) { ?> |
|
56 | - <th class="tax"><?php _e( 'Tax (%)', 'invoicing' );?></th> |
|
54 | + <th class="total"><?php _e('Total', 'invoicing'); ?></th> |
|
55 | + <?php if ($use_taxes) { ?> |
|
56 | + <th class="tax"><?php _e('Tax (%)', 'invoicing'); ?></th> |
|
57 | 57 | <?php } ?> |
58 | 58 | <th class="action"></th> |
59 | 59 | </tr> |
60 | 60 | </thead> |
61 | 61 | <tbody class="wpinv-line-items"> |
62 | - <?php echo wpinv_admin_get_line_items( $invoice ); ?> |
|
62 | + <?php echo wpinv_admin_get_line_items($invoice); ?> |
|
63 | 63 | </tbody> |
64 | 64 | <tfoot class="wpinv-totals"> |
65 | 65 | <tr> |
@@ -71,44 +71,44 @@ discard block |
||
71 | 71 | </td> |
72 | 72 | <td class="title"> |
73 | 73 | <input type="text" class="regular-text" placeholder="Item name" value="" name="_wpinv_quick[name]"> |
74 | - <?php if ( $wpinv_euvat->allow_vat_rules() ) { ?> |
|
74 | + <?php if ($wpinv_euvat->allow_vat_rules()) { ?> |
|
75 | 75 | <div class="wp-clearfix"> |
76 | 76 | <label class="wpi-vat-rule"> |
77 | - <span class="title"><?php _e( 'VAT rule type', 'invoicing' );?></span> |
|
77 | + <span class="title"><?php _e('VAT rule type', 'invoicing'); ?></span> |
|
78 | 78 | <span class="input-text-wrap"> |
79 | - <?php echo wpinv_html_select( array( |
|
79 | + <?php echo wpinv_html_select(array( |
|
80 | 80 | 'options' => $wpinv_euvat->get_rules(), |
81 | 81 | 'name' => '_wpinv_quick[vat_rule]', |
82 | 82 | 'id' => '_wpinv_quick_vat_rule', |
83 | 83 | 'show_option_all' => false, |
84 | 84 | 'show_option_none' => false, |
85 | 85 | 'class' => 'gdmbx2-text-medium wpinv-quick-vat-rule', |
86 | - ) ); ?> |
|
86 | + )); ?> |
|
87 | 87 | </span> |
88 | 88 | </label> |
89 | 89 | </div> |
90 | - <?php } if ( $wpinv_euvat->allow_vat_classes() ) { ?> |
|
90 | + <?php } if ($wpinv_euvat->allow_vat_classes()) { ?> |
|
91 | 91 | <div class="wp-clearfix"> |
92 | 92 | <label class="wpi-vat-class"> |
93 | - <span class="title"><?php _e( 'VAT class', 'invoicing' );?></span> |
|
93 | + <span class="title"><?php _e('VAT class', 'invoicing'); ?></span> |
|
94 | 94 | <span class="input-text-wrap"> |
95 | - <?php echo wpinv_html_select( array( |
|
95 | + <?php echo wpinv_html_select(array( |
|
96 | 96 | 'options' => $wpinv_euvat->get_all_classes(), |
97 | 97 | 'name' => '_wpinv_quick[vat_class]', |
98 | 98 | 'id' => '_wpinv_quick_vat_class', |
99 | 99 | 'show_option_all' => false, |
100 | 100 | 'show_option_none' => false, |
101 | 101 | 'class' => 'gdmbx2-text-medium wpinv-quick-vat-class', |
102 | - ) ); ?> |
|
102 | + )); ?> |
|
103 | 103 | </span> |
104 | 104 | </label> |
105 | 105 | </div> |
106 | 106 | <?php } ?> |
107 | 107 | <div class="wp-clearfix"> |
108 | 108 | <label class="wpi-item-type"> |
109 | - <span class="title"><?php _e( 'Item type', 'invoicing' );?></span> |
|
109 | + <span class="title"><?php _e('Item type', 'invoicing'); ?></span> |
|
110 | 110 | <span class="input-text-wrap"> |
111 | - <?php echo wpinv_html_select( array( |
|
111 | + <?php echo wpinv_html_select(array( |
|
112 | 112 | 'options' => $item_types, |
113 | 113 | 'name' => '_wpinv_quick[type]', |
114 | 114 | 'id' => '_wpinv_quick_type', |
@@ -116,7 +116,7 @@ discard block |
||
116 | 116 | 'show_option_all' => false, |
117 | 117 | 'show_option_none' => false, |
118 | 118 | 'class' => 'gdmbx2-text-medium wpinv-quick-type', |
119 | - ) ); ?> |
|
119 | + )); ?> |
|
120 | 120 | </span> |
121 | 121 | </label> |
122 | 122 | </div> |
@@ -129,11 +129,11 @@ discard block |
||
129 | 129 | </div> |
130 | 130 | </td> |
131 | 131 | <td class="price"><input type="text" placeholder="0.00" class="wpi-field-price wpi-price" name="_wpinv_quick[price]" /></td> |
132 | - <?php if ( $item_quantities ) { ?> |
|
132 | + <?php if ($item_quantities) { ?> |
|
133 | 133 | <td class="qty"><input type="number" class="small-text" step="1" min="1" value="1" name="_wpinv_quick[qty]" /></td> |
134 | 134 | <?php } ?> |
135 | 135 | <td class="total"></td> |
136 | - <?php if ( $use_taxes ) { ?> |
|
136 | + <?php if ($use_taxes) { ?> |
|
137 | 137 | <td class="tax"></td> |
138 | 138 | <?php } ?> |
139 | 139 | <td class="action"></td> |
@@ -146,29 +146,29 @@ discard block |
||
146 | 146 | <td colspan="<?php echo $cols; ?>"></td> |
147 | 147 | </tr> |
148 | 148 | <tr class="totals"> |
149 | - <td colspan="<?php echo ( $cols - 4 ); ?>"></td> |
|
149 | + <td colspan="<?php echo ($cols - 4); ?>"></td> |
|
150 | 150 | <td colspan="4"> |
151 | 151 | <table cellspacing="0" cellpadding="0"> |
152 | 152 | <tr class="subtotal"> |
153 | - <td class="name"><?php _e( 'Sub Total:', 'invoicing' );?></td> |
|
154 | - <td class="total"><?php echo $subtotal;?></td> |
|
153 | + <td class="name"><?php _e('Sub Total:', 'invoicing'); ?></td> |
|
154 | + <td class="total"><?php echo $subtotal; ?></td> |
|
155 | 155 | <td class="action"></td> |
156 | 156 | </tr> |
157 | 157 | <tr class="discount"> |
158 | - <td class="name"><?php wpinv_get_discount_label( wpinv_discount_code( $invoice->ID ) ); ?>:</td> |
|
159 | - <td class="total"><?php echo wpinv_discount( $invoice->ID, true, true ); ?></td> |
|
158 | + <td class="name"><?php wpinv_get_discount_label(wpinv_discount_code($invoice->ID)); ?>:</td> |
|
159 | + <td class="total"><?php echo wpinv_discount($invoice->ID, true, true); ?></td> |
|
160 | 160 | <td class="action"></td> |
161 | 161 | </tr> |
162 | - <?php if ( $use_taxes ) { ?> |
|
162 | + <?php if ($use_taxes) { ?> |
|
163 | 163 | <tr class="tax"> |
164 | - <td class="name"><?php _e( 'Tax:', 'invoicing' );?></td> |
|
165 | - <td class="total"><?php echo $tax;?></td> |
|
164 | + <td class="name"><?php _e('Tax:', 'invoicing'); ?></td> |
|
165 | + <td class="total"><?php echo $tax; ?></td> |
|
166 | 166 | <td class="action"></td> |
167 | 167 | </tr> |
168 | 168 | <?php } ?> |
169 | 169 | <tr class="total"> |
170 | - <td class="name"><?php _e( 'Invoice Total:', 'invoicing' );?></td> |
|
171 | - <td class="total"><?php echo $total;?></td> |
|
170 | + <td class="name"><?php _e('Invoice Total:', 'invoicing'); ?></td> |
|
171 | + <td class="total"><?php echo $total; ?></td> |
|
172 | 172 | <td class="action"></td> |
173 | 173 | </tr> |
174 | 174 | </table> |
@@ -178,89 +178,89 @@ discard block |
||
178 | 178 | </table> |
179 | 179 | <div class="wpinv-actions"> |
180 | 180 | <?php |
181 | - if ( !$invoice->is_paid() ) { |
|
182 | - if ( !$invoice->is_recurring() ) { |
|
183 | - echo wpinv_item_dropdown( array( |
|
181 | + if (!$invoice->is_paid()) { |
|
182 | + if (!$invoice->is_recurring()) { |
|
183 | + echo wpinv_item_dropdown(array( |
|
184 | 184 | 'name' => 'wpinv_invoice_item', |
185 | 185 | 'id' => 'wpinv_invoice_item', |
186 | 186 | 'with_packages' => false, |
187 | 187 | 'show_recurring' => true, |
188 | - ) ); |
|
188 | + )); |
|
189 | 189 | ?> |
190 | - <input type="button" value="<?php esc_attr_e( 'Add item to Invoice', 'invoicing' );?>" 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"> |
|
190 | + <input type="button" value="<?php esc_attr_e('Add item to Invoice', 'invoicing'); ?>" 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"> |
|
191 | 191 | <?php } ?> |
192 | - <?php do_action( 'wpinv_invoice_items_actions', $invoice ); ?> |
|
192 | + <?php do_action('wpinv_invoice_items_actions', $invoice); ?> |
|
193 | 193 | </div> |
194 | 194 | </div> |
195 | 195 | <?php |
196 | 196 | } |
197 | 197 | |
198 | - public static function prices( $post ) { |
|
198 | + public static function prices($post) { |
|
199 | 199 | $symbol = wpinv_currency_symbol(); |
200 | 200 | $position = wpinv_currency_position(); |
201 | - $item = new WPInv_Item( $post->ID ); |
|
201 | + $item = new WPInv_Item($post->ID); |
|
202 | 202 | |
203 | 203 | $price = $item->get_price(); |
204 | 204 | $is_recurring = $item->is_recurring(); |
205 | 205 | $period = $item->get_recurring_period(); |
206 | - $interval = absint( $item->get_recurring_interval() ); |
|
207 | - $times = absint( $item->get_recurring_limit() ); |
|
206 | + $interval = absint($item->get_recurring_interval()); |
|
207 | + $times = absint($item->get_recurring_limit()); |
|
208 | 208 | $free_trial = $item->has_free_trial(); |
209 | 209 | $trial_interval = $item->get_trial_interval(); |
210 | 210 | $trial_period = $item->get_trial_period(); |
211 | 211 | |
212 | 212 | $intervals = array(); |
213 | - for ( $i = 1; $i <= 90; $i++ ) { |
|
213 | + for ($i = 1; $i <= 90; $i++) { |
|
214 | 214 | $intervals[$i] = $i; |
215 | 215 | } |
216 | 216 | |
217 | - $interval = $interval > 0 ? $interval : 1; |
|
217 | + $interval = $interval > 0 ? $interval : 1; |
|
218 | 218 | |
219 | 219 | $class = $is_recurring ? 'wpinv-recurring-y' : 'wpinv-recurring-n'; |
220 | 220 | ?> |
221 | - <p class="wpinv-row-prices"><?php echo ( $position != 'right' ? $symbol . ' ' : '' );?><input type="text" maxlength="12" placeholder="<?php echo wpinv_format_amount( 0 ); ?>" value="<?php echo wpinv_format_amount( $price );?>" id="wpinv_item_price" name="wpinv_item_price" class="medium-text wpi-field-price wpi-price" <?php disabled( $item->is_package(), true ); ?> /><?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' ) ;?>" /> |
|
222 | - <?php if ( $item->is_package() ) { ?> |
|
223 | - <span class="description"><?php _e( 'GD package item price can be edited only from GD payment manager.', 'invoicing' ); ?></span> |
|
221 | + <p class="wpinv-row-prices"><?php echo ($position != 'right' ? $symbol . ' ' : ''); ?><input type="text" maxlength="12" placeholder="<?php echo wpinv_format_amount(0); ?>" value="<?php echo wpinv_format_amount($price); ?>" id="wpinv_item_price" name="wpinv_item_price" class="medium-text wpi-field-price wpi-price" <?php disabled($item->is_package(), true); ?> /><?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'); ?>" /> |
|
222 | + <?php if ($item->is_package()) { ?> |
|
223 | + <span class="description"><?php _e('GD package item price can be edited only from GD payment manager.', 'invoicing'); ?></span> |
|
224 | 224 | <?php } ?> |
225 | 225 | </p> |
226 | 226 | <p class="wpinv-row-is-recurring"> |
227 | 227 | <label for="wpinv_is_recurring"> |
228 | - <input type="checkbox" name="wpinv_is_recurring" id="wpinv_is_recurring" value="1" <?php checked( 1, $is_recurring ); ?> /> |
|
229 | - <?php echo apply_filters( 'wpinv_is_recurring_toggle_text', __( 'Is Recurring Item?', 'invoicing' ) ); ?> |
|
228 | + <input type="checkbox" name="wpinv_is_recurring" id="wpinv_is_recurring" value="1" <?php checked(1, $is_recurring); ?> /> |
|
229 | + <?php echo apply_filters('wpinv_is_recurring_toggle_text', __('Is Recurring Item?', 'invoicing')); ?> |
|
230 | 230 | </label> |
231 | 231 | </p> |
232 | - <p class="wpinv-row-recurring-fields <?php echo $class;?>"> |
|
233 | - <label class="wpinv-period" for="wpinv_recurring_period"><?php _e( 'Recurring', 'invoicing' );?> <select class="wpinv-select " 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> |
|
234 | - <label class="wpinv-interval" for="wpinv_recurring_interval"> <?php _e( 'at every', 'invoicing' );?> <?php echo wpinv_html_select( array( |
|
232 | + <p class="wpinv-row-recurring-fields <?php echo $class; ?>"> |
|
233 | + <label class="wpinv-period" for="wpinv_recurring_period"><?php _e('Recurring', 'invoicing'); ?> <select class="wpinv-select " 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> |
|
234 | + <label class="wpinv-interval" for="wpinv_recurring_interval"> <?php _e('at every', 'invoicing'); ?> <?php echo wpinv_html_select(array( |
|
235 | 235 | 'options' => $intervals, |
236 | 236 | 'name' => 'wpinv_recurring_interval', |
237 | 237 | 'id' => 'wpinv_recurring_interval', |
238 | 238 | 'selected' => $interval, |
239 | 239 | 'show_option_all' => false, |
240 | 240 | 'show_option_none' => false |
241 | - ) ); ?> <span id="wpinv_interval_text"><?php _e( 'day(s)', 'invoicing' );?></span></label> |
|
242 | - <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> |
|
241 | + )); ?> <span id="wpinv_interval_text"><?php _e('day(s)', 'invoicing'); ?></span></label> |
|
242 | + <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> |
|
243 | 243 | <span class="clear wpi-trial-clr"></span> |
244 | 244 | <label class="wpinv-free-trial" for="wpinv_free_trial"> |
245 | - <input type="checkbox" name="wpinv_free_trial" id="wpinv_free_trial" value="1" <?php checked( true, (bool)$free_trial ); ?> /> |
|
246 | - <?php echo __( 'Offer free trial for', 'invoicing' ); ?> |
|
245 | + <input type="checkbox" name="wpinv_free_trial" id="wpinv_free_trial" value="1" <?php checked(true, (bool)$free_trial); ?> /> |
|
246 | + <?php echo __('Offer free trial for', 'invoicing'); ?> |
|
247 | 247 | </label> |
248 | 248 | <label class="wpinv-trial-interval" for="wpinv_trial_interval"> |
249 | - <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" 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> |
|
249 | + <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" 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> |
|
250 | 250 | </label> |
251 | 251 | </p> |
252 | - <input type="hidden" id="_wpi_current_type" value="<?php echo wpinv_get_item_type( $post->ID ); ?>" /> |
|
253 | - <?php do_action( 'wpinv_item_price_field', $post->ID ); ?> |
|
252 | + <input type="hidden" id="_wpi_current_type" value="<?php echo wpinv_get_item_type($post->ID); ?>" /> |
|
253 | + <?php do_action('wpinv_item_price_field', $post->ID); ?> |
|
254 | 254 | <?php |
255 | 255 | } |
256 | 256 | |
257 | - public static function vat_rules( $post ) { |
|
257 | + public static function vat_rules($post) { |
|
258 | 258 | global $wpinv_euvat; |
259 | 259 | |
260 | - $rule_type = $wpinv_euvat->get_item_rule( $post->ID ); |
|
260 | + $rule_type = $wpinv_euvat->get_item_rule($post->ID); |
|
261 | 261 | ?> |
262 | - <p><label for="wpinv_vat_rules"><strong><?php _e( 'Select how VAT rules will be applied:', 'invoicing' );?></strong></label> |
|
263 | - <?php echo wpinv_html_select( array( |
|
262 | + <p><label for="wpinv_vat_rules"><strong><?php _e('Select how VAT rules will be applied:', 'invoicing'); ?></strong></label> |
|
263 | + <?php echo wpinv_html_select(array( |
|
264 | 264 | 'options' => $wpinv_euvat->get_rules(), |
265 | 265 | 'name' => 'wpinv_vat_rules', |
266 | 266 | 'id' => 'wpinv_vat_rules', |
@@ -268,19 +268,19 @@ discard block |
||
268 | 268 | 'show_option_all' => false, |
269 | 269 | 'show_option_none' => false, |
270 | 270 | 'class' => 'gdmbx2-text-medium wpinv-vat-rules', |
271 | - ) ); ?> |
|
271 | + )); ?> |
|
272 | 272 | </p> |
273 | - <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> |
|
274 | - <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> |
|
273 | + <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> |
|
274 | + <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> |
|
275 | 275 | <?php |
276 | 276 | } |
277 | 277 | |
278 | - public static function vat_classes( $post ) { |
|
278 | + public static function vat_classes($post) { |
|
279 | 279 | global $wpinv_euvat; |
280 | 280 | |
281 | - $vat_class = $wpinv_euvat->get_item_class( $post->ID ); |
|
281 | + $vat_class = $wpinv_euvat->get_item_class($post->ID); |
|
282 | 282 | ?> |
283 | - <p><?php echo wpinv_html_select( array( |
|
283 | + <p><?php echo wpinv_html_select(array( |
|
284 | 284 | 'options' => $wpinv_euvat->get_all_classes(), |
285 | 285 | 'name' => 'wpinv_vat_class', |
286 | 286 | 'id' => 'wpinv_vat_class', |
@@ -288,18 +288,18 @@ discard block |
||
288 | 288 | 'show_option_all' => false, |
289 | 289 | 'show_option_none' => false, |
290 | 290 | 'class' => 'gdmbx2-text-medium wpinv-vat-class', |
291 | - ) ); ?> |
|
291 | + )); ?> |
|
292 | 292 | </p> |
293 | - <p class="wpi-m0"><?php _e( 'Select the VAT rate class to use for this invoice item.', 'invoicing' ); ?></p> |
|
293 | + <p class="wpi-m0"><?php _e('Select the VAT rate class to use for this invoice item.', 'invoicing'); ?></p> |
|
294 | 294 | <?php |
295 | 295 | } |
296 | 296 | |
297 | - public static function item_info( $post ) { |
|
298 | - $item_type = wpinv_get_item_type( $post->ID ); |
|
299 | - do_action( 'wpinv_item_info_metabox_before', $post ); |
|
297 | + public static function item_info($post) { |
|
298 | + $item_type = wpinv_get_item_type($post->ID); |
|
299 | + do_action('wpinv_item_info_metabox_before', $post); |
|
300 | 300 | ?> |
301 | - <p><label for="wpinv_item_type"><strong><?php _e( 'Type:', 'invoicing' );?></strong></label> |
|
302 | - <?php echo wpinv_html_select( array( |
|
301 | + <p><label for="wpinv_item_type"><strong><?php _e('Type:', 'invoicing'); ?></strong></label> |
|
302 | + <?php echo wpinv_html_select(array( |
|
303 | 303 | 'options' => wpinv_get_item_types(), |
304 | 304 | 'name' => 'wpinv_item_type', |
305 | 305 | 'id' => 'wpinv_item_type', |
@@ -308,93 +308,93 @@ discard block |
||
308 | 308 | 'show_option_none' => false, |
309 | 309 | 'class' => 'gdmbx2-text-medium wpinv-item-type', |
310 | 310 | //'disabled' => $item_type == 'package' ? true : false, |
311 | - ) ); ?> |
|
311 | + )); ?> |
|
312 | 312 | </p> |
313 | - <p class="wpi-m0"><?php _e( 'Select item type.', 'invoicing' );?><br><?php _e( 'Standard: standard item type', 'invoicing' );?><br><?php _e( 'Fee: like Registration Fee, Signup Fee etc.', 'invoicing' );?></p> |
|
313 | + <p class="wpi-m0"><?php _e('Select item type.', 'invoicing'); ?><br><?php _e('Standard: standard item type', 'invoicing'); ?><br><?php _e('Fee: like Registration Fee, Signup Fee etc.', 'invoicing'); ?></p> |
|
314 | 314 | <?php |
315 | - do_action( 'wpinv_item_info_metabox_after', $post ); |
|
315 | + do_action('wpinv_item_info_metabox_after', $post); |
|
316 | 316 | } |
317 | 317 | |
318 | - public static function save( $post_id, $data, $post ) { |
|
319 | - $invoice = new WPInv_Invoice( $post_id ); |
|
318 | + public static function save($post_id, $data, $post) { |
|
319 | + $invoice = new WPInv_Invoice($post_id); |
|
320 | 320 | |
321 | 321 | // Billing |
322 | - $first_name = sanitize_text_field( $data['wpinv_first_name'] ); |
|
323 | - $last_name = sanitize_text_field( $data['wpinv_last_name'] ); |
|
324 | - $company = sanitize_text_field( $data['wpinv_company'] ); |
|
325 | - $vat_number = sanitize_text_field( $data['wpinv_vat_number'] ); |
|
326 | - $phone = sanitize_text_field( $data['wpinv_phone'] ); |
|
327 | - $address = sanitize_text_field( $data['wpinv_address'] ); |
|
328 | - $city = sanitize_text_field( $data['wpinv_city'] ); |
|
329 | - $zip = sanitize_text_field( $data['wpinv_zip'] ); |
|
330 | - $country = sanitize_text_field( $data['wpinv_country'] ); |
|
331 | - $state = sanitize_text_field( $data['wpinv_state'] ); |
|
322 | + $first_name = sanitize_text_field($data['wpinv_first_name']); |
|
323 | + $last_name = sanitize_text_field($data['wpinv_last_name']); |
|
324 | + $company = sanitize_text_field($data['wpinv_company']); |
|
325 | + $vat_number = sanitize_text_field($data['wpinv_vat_number']); |
|
326 | + $phone = sanitize_text_field($data['wpinv_phone']); |
|
327 | + $address = sanitize_text_field($data['wpinv_address']); |
|
328 | + $city = sanitize_text_field($data['wpinv_city']); |
|
329 | + $zip = sanitize_text_field($data['wpinv_zip']); |
|
330 | + $country = sanitize_text_field($data['wpinv_country']); |
|
331 | + $state = sanitize_text_field($data['wpinv_state']); |
|
332 | 332 | |
333 | 333 | // Details |
334 | - $status = sanitize_text_field( $data['wpinv_status'] ); |
|
335 | - $old_status = !empty( $data['original_post_status'] ) ? sanitize_text_field( $data['original_post_status'] ) : $status; |
|
336 | - $number = sanitize_text_field( $data['wpinv_number'] ); |
|
337 | - $due_date = isset( $data['wpinv_due_date'] ) ? sanitize_text_field( $data['wpinv_due_date'] ) : ''; |
|
334 | + $status = sanitize_text_field($data['wpinv_status']); |
|
335 | + $old_status = !empty($data['original_post_status']) ? sanitize_text_field($data['original_post_status']) : $status; |
|
336 | + $number = sanitize_text_field($data['wpinv_number']); |
|
337 | + $due_date = isset($data['wpinv_due_date']) ? sanitize_text_field($data['wpinv_due_date']) : ''; |
|
338 | 338 | //$discounts = sanitize_text_field( $data['wpinv_discounts'] ); |
339 | 339 | //$discount = sanitize_text_field( $data['wpinv_discount'] ); |
340 | 340 | |
341 | - $ip = $invoice->get_ip() ? $invoice->get_ip() : wpinv_get_ip(); |
|
341 | + $ip = $invoice->get_ip() ? $invoice->get_ip() : wpinv_get_ip(); |
|
342 | 342 | |
343 | - $invoice->set( 'due_date', $due_date ); |
|
344 | - $invoice->set( 'first_name', $first_name ); |
|
345 | - $invoice->set( 'last_name', $last_name ); |
|
346 | - $invoice->set( 'company', $company ); |
|
347 | - $invoice->set( 'vat_number', $vat_number ); |
|
348 | - $invoice->set( 'phone', $phone ); |
|
349 | - $invoice->set( 'address', $address ); |
|
350 | - $invoice->set( 'city', $city ); |
|
351 | - $invoice->set( 'zip', $zip ); |
|
352 | - $invoice->set( 'country', $country ); |
|
353 | - $invoice->set( 'state', $state ); |
|
354 | - $invoice->set( 'status', $status ); |
|
355 | - $invoice->set( 'number', $number ); |
|
343 | + $invoice->set('due_date', $due_date); |
|
344 | + $invoice->set('first_name', $first_name); |
|
345 | + $invoice->set('last_name', $last_name); |
|
346 | + $invoice->set('company', $company); |
|
347 | + $invoice->set('vat_number', $vat_number); |
|
348 | + $invoice->set('phone', $phone); |
|
349 | + $invoice->set('address', $address); |
|
350 | + $invoice->set('city', $city); |
|
351 | + $invoice->set('zip', $zip); |
|
352 | + $invoice->set('country', $country); |
|
353 | + $invoice->set('state', $state); |
|
354 | + $invoice->set('status', $status); |
|
355 | + $invoice->set('number', $number); |
|
356 | 356 | //$invoice->set( 'discounts', $discounts ); |
357 | 357 | //$invoice->set( 'discount', $discount ); |
358 | - $invoice->set( 'ip', $ip ); |
|
358 | + $invoice->set('ip', $ip); |
|
359 | 359 | $invoice->old_status = $_POST['original_post_status']; |
360 | 360 | $invoice->currency = wpinv_get_currency(); |
361 | - if ( !empty( $data['wpinv_gateway'] ) ) { |
|
362 | - $invoice->set( 'gateway', sanitize_text_field( $data['wpinv_gateway'] ) ); |
|
361 | + if (!empty($data['wpinv_gateway'])) { |
|
362 | + $invoice->set('gateway', sanitize_text_field($data['wpinv_gateway'])); |
|
363 | 363 | } |
364 | 364 | $saved = $invoice->save(); |
365 | 365 | |
366 | 366 | // Check for payment notes |
367 | - if ( !empty( $data['invoice_note'] ) ) { |
|
368 | - $note = wp_kses( $data['invoice_note'], array() ); |
|
369 | - $note_type = sanitize_text_field( $data['invoice_note_type'] ); |
|
367 | + if (!empty($data['invoice_note'])) { |
|
368 | + $note = wp_kses($data['invoice_note'], array()); |
|
369 | + $note_type = sanitize_text_field($data['invoice_note_type']); |
|
370 | 370 | $is_customer_note = $note_type == 'customer' ? 1 : 0; |
371 | 371 | |
372 | - wpinv_insert_payment_note( $invoice->ID, $note, $is_customer_note ); |
|
372 | + wpinv_insert_payment_note($invoice->ID, $note, $is_customer_note); |
|
373 | 373 | } |
374 | 374 | |
375 | 375 | // Update user address if empty. |
376 | - if ( $saved && !empty( $invoice ) ) { |
|
377 | - if ( $user_id = $invoice->get_user_id() ) { |
|
378 | - $user_address = wpinv_get_user_address( $user_id, false ); |
|
376 | + if ($saved && !empty($invoice)) { |
|
377 | + if ($user_id = $invoice->get_user_id()) { |
|
378 | + $user_address = wpinv_get_user_address($user_id, false); |
|
379 | 379 | |
380 | 380 | if (empty($user_address['first_name'])) { |
381 | - update_user_meta( $user_id, '_wpinv_first_name', $first_name ); |
|
382 | - update_user_meta( $user_id, '_wpinv_last_name', $last_name ); |
|
381 | + update_user_meta($user_id, '_wpinv_first_name', $first_name); |
|
382 | + update_user_meta($user_id, '_wpinv_last_name', $last_name); |
|
383 | 383 | } else if (empty($user_address['last_name']) && $user_address['first_name'] == $first_name) { |
384 | - update_user_meta( $user_id, '_wpinv_last_name', $last_name ); |
|
384 | + update_user_meta($user_id, '_wpinv_last_name', $last_name); |
|
385 | 385 | } |
386 | 386 | |
387 | 387 | if (empty($user_address['address']) || empty($user_address['city']) || empty($user_address['state']) || empty($user_address['country'])) { |
388 | - update_user_meta( $user_id, '_wpinv_address', $address ); |
|
389 | - update_user_meta( $user_id, '_wpinv_city', $city ); |
|
390 | - update_user_meta( $user_id, '_wpinv_state', $state ); |
|
391 | - update_user_meta( $user_id, '_wpinv_country', $country ); |
|
392 | - update_user_meta( $user_id, '_wpinv_zip', $zip ); |
|
393 | - update_user_meta( $user_id, '_wpinv_phone', $phone ); |
|
388 | + update_user_meta($user_id, '_wpinv_address', $address); |
|
389 | + update_user_meta($user_id, '_wpinv_city', $city); |
|
390 | + update_user_meta($user_id, '_wpinv_state', $state); |
|
391 | + update_user_meta($user_id, '_wpinv_country', $country); |
|
392 | + update_user_meta($user_id, '_wpinv_zip', $zip); |
|
393 | + update_user_meta($user_id, '_wpinv_phone', $phone); |
|
394 | 394 | } |
395 | 395 | } |
396 | 396 | |
397 | - do_action( 'wpinv_invoice_metabox_saveed', $invoice ); |
|
397 | + do_action('wpinv_invoice_metabox_saveed', $invoice); |
|
398 | 398 | } |
399 | 399 | |
400 | 400 | return $saved; |
@@ -1,19 +1,19 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | // Exit if accessed directly |
3 | -if ( ! defined( 'ABSPATH' ) ) exit; |
|
3 | +if (!defined('ABSPATH')) exit; |
|
4 | 4 | |
5 | -function wpinv_get_item_by( $field = '', $value = '', $type = '' ) { |
|
6 | - if( empty( $field ) || empty( $value ) ) { |
|
5 | +function wpinv_get_item_by($field = '', $value = '', $type = '') { |
|
6 | + if (empty($field) || empty($value)) { |
|
7 | 7 | return false; |
8 | 8 | } |
9 | 9 | |
10 | 10 | $posts = array(); |
11 | 11 | |
12 | - switch( strtolower( $field ) ) { |
|
12 | + switch (strtolower($field)) { |
|
13 | 13 | case 'id': |
14 | - $item = get_post( $value ); |
|
14 | + $item = get_post($value); |
|
15 | 15 | |
16 | - if( get_post_type( $item ) != 'wpi_item' ) { |
|
16 | + if (get_post_type($item) != 'wpi_item') { |
|
17 | 17 | return false; |
18 | 18 | } |
19 | 19 | |
@@ -21,16 +21,16 @@ discard block |
||
21 | 21 | |
22 | 22 | case 'slug': |
23 | 23 | case 'name': |
24 | - $posts = get_posts( array( |
|
24 | + $posts = get_posts(array( |
|
25 | 25 | 'post_type' => 'wpi_item', |
26 | 26 | 'name' => $value, |
27 | 27 | 'posts_per_page' => 1, |
28 | 28 | 'post_status' => 'any' |
29 | - ) ); |
|
29 | + )); |
|
30 | 30 | |
31 | 31 | break; |
32 | 32 | case 'package_id': |
33 | - $posts = get_posts( array( |
|
33 | + $posts = get_posts(array( |
|
34 | 34 | 'post_type' => 'wpi_item', |
35 | 35 | 'posts_per_page' => 1, |
36 | 36 | 'post_status' => 'any', |
@@ -46,11 +46,11 @@ discard block |
||
46 | 46 | 'value' => 'package', |
47 | 47 | ) |
48 | 48 | ) |
49 | - ) ); |
|
49 | + )); |
|
50 | 50 | |
51 | 51 | break; |
52 | 52 | case 'item_id': |
53 | - if ( empty( $value ) ) { |
|
53 | + if (empty($value)) { |
|
54 | 54 | return false; |
55 | 55 | } |
56 | 56 | |
@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | 'key' => '_wpinv_post_id', |
60 | 60 | 'value' => $value, |
61 | 61 | ); |
62 | - if ( !empty( $type ) ) { |
|
62 | + if (!empty($type)) { |
|
63 | 63 | $meta_query[] = array( |
64 | 64 | 'key' => '_wpinv_type', |
65 | 65 | 'value' => $type, |
@@ -72,14 +72,14 @@ discard block |
||
72 | 72 | 'post_status' => 'any', |
73 | 73 | 'orderby' => 'ID', |
74 | 74 | 'order' => 'ASC', |
75 | - 'meta_query' => array( $meta_query ) |
|
75 | + 'meta_query' => array($meta_query) |
|
76 | 76 | ); |
77 | 77 | |
78 | - $posts = get_posts( $args ); |
|
78 | + $posts = get_posts($args); |
|
79 | 79 | |
80 | 80 | break; |
81 | 81 | case 'custom': |
82 | - if ( empty( $value ) || empty( $type ) ) { |
|
82 | + if (empty($value) || empty($type)) { |
|
83 | 83 | return false; |
84 | 84 | } |
85 | 85 | |
@@ -99,10 +99,10 @@ discard block |
||
99 | 99 | 'post_status' => 'any', |
100 | 100 | 'orderby' => 'ID', |
101 | 101 | 'order' => 'ASC', |
102 | - 'meta_query' => array( $meta_query ) |
|
102 | + 'meta_query' => array($meta_query) |
|
103 | 103 | ); |
104 | 104 | |
105 | - $posts = get_posts( $args ); |
|
105 | + $posts = get_posts($args); |
|
106 | 106 | |
107 | 107 | break; |
108 | 108 | |
@@ -110,17 +110,17 @@ discard block |
||
110 | 110 | return false; |
111 | 111 | } |
112 | 112 | |
113 | - if ( !empty( $posts[0] ) ) { |
|
114 | - return new WPInv_Item( $posts[0]->ID ); |
|
113 | + if (!empty($posts[0])) { |
|
114 | + return new WPInv_Item($posts[0]->ID); |
|
115 | 115 | } |
116 | 116 | |
117 | 117 | return false; |
118 | 118 | } |
119 | 119 | |
120 | -function wpinv_get_item( $item = 0 ) { |
|
121 | - if ( is_numeric( $item ) ) { |
|
122 | - $item = get_post( $item ); |
|
123 | - if ( ! $item || 'wpi_item' !== $item->post_type ) |
|
120 | +function wpinv_get_item($item = 0) { |
|
121 | + if (is_numeric($item)) { |
|
122 | + $item = get_post($item); |
|
123 | + if (!$item || 'wpi_item' !== $item->post_type) |
|
124 | 124 | return null; |
125 | 125 | return $item; |
126 | 126 | } |
@@ -133,136 +133,136 @@ discard block |
||
133 | 133 | |
134 | 134 | $item = get_posts($args); |
135 | 135 | |
136 | - if ( $item ) { |
|
136 | + if ($item) { |
|
137 | 137 | return $item[0]; |
138 | 138 | } |
139 | 139 | |
140 | 140 | return null; |
141 | 141 | } |
142 | 142 | |
143 | -function wpinv_is_free_item( $item_id = 0 ) { |
|
144 | - if( empty( $item_id ) ) { |
|
143 | +function wpinv_is_free_item($item_id = 0) { |
|
144 | + if (empty($item_id)) { |
|
145 | 145 | return false; |
146 | 146 | } |
147 | 147 | |
148 | - $item = new WPInv_Item( $item_id ); |
|
148 | + $item = new WPInv_Item($item_id); |
|
149 | 149 | |
150 | 150 | return $item->is_free(); |
151 | 151 | } |
152 | 152 | |
153 | -function wpinv_get_item_price( $item_id = 0 ) { |
|
154 | - if( empty( $item_id ) ) { |
|
153 | +function wpinv_get_item_price($item_id = 0) { |
|
154 | + if (empty($item_id)) { |
|
155 | 155 | return false; |
156 | 156 | } |
157 | 157 | |
158 | - $item = new WPInv_Item( $item_id ); |
|
158 | + $item = new WPInv_Item($item_id); |
|
159 | 159 | |
160 | 160 | return $item->get_price(); |
161 | 161 | } |
162 | 162 | |
163 | -function wpinv_is_recurring_item( $item_id = 0 ) { |
|
164 | - if( empty( $item_id ) ) { |
|
163 | +function wpinv_is_recurring_item($item_id = 0) { |
|
164 | + if (empty($item_id)) { |
|
165 | 165 | return false; |
166 | 166 | } |
167 | 167 | |
168 | - $item = new WPInv_Item( $item_id ); |
|
168 | + $item = new WPInv_Item($item_id); |
|
169 | 169 | |
170 | 170 | return $item->is_recurring(); |
171 | 171 | } |
172 | 172 | |
173 | -function wpinv_item_price( $item_id = 0 ) { |
|
174 | - if( empty( $item_id ) ) { |
|
173 | +function wpinv_item_price($item_id = 0) { |
|
174 | + if (empty($item_id)) { |
|
175 | 175 | return false; |
176 | 176 | } |
177 | 177 | |
178 | - $price = wpinv_get_item_price( $item_id ); |
|
179 | - $price = wpinv_price( wpinv_format_amount( $price ) ); |
|
178 | + $price = wpinv_get_item_price($item_id); |
|
179 | + $price = wpinv_price(wpinv_format_amount($price)); |
|
180 | 180 | |
181 | - return apply_filters( 'wpinv_item_price', $price, $item_id ); |
|
181 | + return apply_filters('wpinv_item_price', $price, $item_id); |
|
182 | 182 | } |
183 | 183 | |
184 | -function wpinv_item_show_price( $item_id = 0, $echo = true ) { |
|
185 | - if ( empty( $item_id ) ) { |
|
184 | +function wpinv_item_show_price($item_id = 0, $echo = true) { |
|
185 | + if (empty($item_id)) { |
|
186 | 186 | $item_id = get_the_ID(); |
187 | 187 | } |
188 | 188 | |
189 | - $price = wpinv_item_price( $item_id ); |
|
189 | + $price = wpinv_item_price($item_id); |
|
190 | 190 | |
191 | - $price = apply_filters( 'wpinv_item_price', wpinv_sanitize_amount( $price ), $item_id ); |
|
191 | + $price = apply_filters('wpinv_item_price', wpinv_sanitize_amount($price), $item_id); |
|
192 | 192 | $formatted_price = '<span class="wpinv_price" id="wpinv_item_' . $item_id . '">' . $price . '</span>'; |
193 | - $formatted_price = apply_filters( 'wpinv_item_price_after_html', $formatted_price, $item_id, $price ); |
|
193 | + $formatted_price = apply_filters('wpinv_item_price_after_html', $formatted_price, $item_id, $price); |
|
194 | 194 | |
195 | - if ( $echo ) { |
|
195 | + if ($echo) { |
|
196 | 196 | echo $formatted_price; |
197 | 197 | } else { |
198 | 198 | return $formatted_price; |
199 | 199 | } |
200 | 200 | } |
201 | 201 | |
202 | -function wpinv_get_item_final_price( $item_id = 0, $amount_override = null ) { |
|
203 | - if ( is_null( $amount_override ) ) { |
|
204 | - $original_price = get_post_meta( $item_id, '_wpinv_price', true ); |
|
202 | +function wpinv_get_item_final_price($item_id = 0, $amount_override = null) { |
|
203 | + if (is_null($amount_override)) { |
|
204 | + $original_price = get_post_meta($item_id, '_wpinv_price', true); |
|
205 | 205 | } else { |
206 | 206 | $original_price = $amount_override; |
207 | 207 | } |
208 | 208 | |
209 | 209 | $price = $original_price; |
210 | 210 | |
211 | - return apply_filters( 'wpinv_get_item_final_price', $price, $item_id ); |
|
211 | + return apply_filters('wpinv_get_item_final_price', $price, $item_id); |
|
212 | 212 | } |
213 | 213 | |
214 | -function wpinv_item_cpt_singular_name( $item_id ) { |
|
215 | - if( empty( $item_id ) ) { |
|
214 | +function wpinv_item_cpt_singular_name($item_id) { |
|
215 | + if (empty($item_id)) { |
|
216 | 216 | return false; |
217 | 217 | } |
218 | 218 | |
219 | - $item = new WPInv_Item( $item_id ); |
|
219 | + $item = new WPInv_Item($item_id); |
|
220 | 220 | |
221 | 221 | return $item->get_cpt_singular_name(); |
222 | 222 | } |
223 | 223 | |
224 | 224 | function wpinv_get_item_types() { |
225 | 225 | $item_types = array( |
226 | - 'custom' => __( 'Standard', 'invoicing' ), |
|
227 | - 'fee' => __( 'Fee', 'invoicing' ), |
|
226 | + 'custom' => __('Standard', 'invoicing'), |
|
227 | + 'fee' => __('Fee', 'invoicing'), |
|
228 | 228 | ); |
229 | - return apply_filters( 'wpinv_get_item_types', $item_types ); |
|
229 | + return apply_filters('wpinv_get_item_types', $item_types); |
|
230 | 230 | } |
231 | 231 | |
232 | 232 | function wpinv_item_types() { |
233 | 233 | $item_types = wpinv_get_item_types(); |
234 | 234 | |
235 | - return ( !empty( $item_types ) ? array_keys( $item_types ) : array() ); |
|
235 | + return (!empty($item_types) ? array_keys($item_types) : array()); |
|
236 | 236 | } |
237 | 237 | |
238 | -function wpinv_get_item_type( $item_id ) { |
|
239 | - if( empty( $item_id ) ) { |
|
238 | +function wpinv_get_item_type($item_id) { |
|
239 | + if (empty($item_id)) { |
|
240 | 240 | return false; |
241 | 241 | } |
242 | 242 | |
243 | - $item = new WPInv_Item( $item_id ); |
|
243 | + $item = new WPInv_Item($item_id); |
|
244 | 244 | |
245 | 245 | return $item->get_type(); |
246 | 246 | } |
247 | 247 | |
248 | -function wpinv_item_type( $item_id ) { |
|
248 | +function wpinv_item_type($item_id) { |
|
249 | 249 | $item_types = wpinv_get_item_types(); |
250 | 250 | |
251 | - $item_type = wpinv_get_item_type( $item_id ); |
|
251 | + $item_type = wpinv_get_item_type($item_id); |
|
252 | 252 | |
253 | - if ( empty( $item_type ) ) { |
|
253 | + if (empty($item_type)) { |
|
254 | 254 | $item_type = '-'; |
255 | 255 | } |
256 | 256 | |
257 | - $item_type = isset( $item_types[$item_type] ) ? $item_types[$item_type] : __( $item_type, 'invoicing' ); |
|
257 | + $item_type = isset($item_types[$item_type]) ? $item_types[$item_type] : __($item_type, 'invoicing'); |
|
258 | 258 | |
259 | - return apply_filters( 'wpinv_item_type', $item_type, $item_id ); |
|
259 | + return apply_filters('wpinv_item_type', $item_type, $item_id); |
|
260 | 260 | } |
261 | 261 | |
262 | -function wpinv_record_item_in_log( $item_id = 0, $file_id, $user_info, $ip, $invoice_id ) { |
|
262 | +function wpinv_record_item_in_log($item_id = 0, $file_id, $user_info, $ip, $invoice_id) { |
|
263 | 263 | global $wpinv_logs; |
264 | 264 | |
265 | - if ( empty( $wpinv_logs ) ) { |
|
265 | + if (empty($wpinv_logs)) { |
|
266 | 266 | return false; |
267 | 267 | } |
268 | 268 | |
@@ -271,7 +271,7 @@ discard block |
||
271 | 271 | 'log_type' => 'wpi_item' |
272 | 272 | ); |
273 | 273 | |
274 | - $user_id = isset( $user_info['user_id'] ) ? $user_info['user_id'] : (int) -1; |
|
274 | + $user_id = isset($user_info['user_id']) ? $user_info['user_id'] : (int) -1; |
|
275 | 275 | |
276 | 276 | $log_meta = array( |
277 | 277 | 'user_info' => $user_info, |
@@ -281,247 +281,247 @@ discard block |
||
281 | 281 | 'invoice_id'=> $invoice_id, |
282 | 282 | ); |
283 | 283 | |
284 | - $wpinv_logs->insert_log( $log_data, $log_meta ); |
|
284 | + $wpinv_logs->insert_log($log_data, $log_meta); |
|
285 | 285 | } |
286 | 286 | |
287 | -function wpinv_remove_item_logs_on_delete( $item_id = 0 ) { |
|
288 | - if ( 'wpi_item' !== get_post_type( $item_id ) ) |
|
287 | +function wpinv_remove_item_logs_on_delete($item_id = 0) { |
|
288 | + if ('wpi_item' !== get_post_type($item_id)) |
|
289 | 289 | return; |
290 | 290 | |
291 | 291 | global $wpinv_logs; |
292 | 292 | |
293 | - if ( empty( $wpinv_logs ) ) { |
|
293 | + if (empty($wpinv_logs)) { |
|
294 | 294 | return false; |
295 | 295 | } |
296 | 296 | |
297 | 297 | // Remove all log entries related to this item |
298 | - $wpinv_logs->delete_logs( $item_id ); |
|
298 | + $wpinv_logs->delete_logs($item_id); |
|
299 | 299 | } |
300 | -add_action( 'delete_post', 'wpinv_remove_item_logs_on_delete' ); |
|
300 | +add_action('delete_post', 'wpinv_remove_item_logs_on_delete'); |
|
301 | 301 | |
302 | -function wpinv_get_random_item( $post_ids = true ) { |
|
303 | - wpinv_get_random_items( 1, $post_ids ); |
|
302 | +function wpinv_get_random_item($post_ids = true) { |
|
303 | + wpinv_get_random_items(1, $post_ids); |
|
304 | 304 | } |
305 | 305 | |
306 | -function wpinv_get_random_items( $num = 3, $post_ids = true ) { |
|
307 | - if ( $post_ids ) { |
|
308 | - $args = array( 'post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num, 'fields' => 'ids' ); |
|
306 | +function wpinv_get_random_items($num = 3, $post_ids = true) { |
|
307 | + if ($post_ids) { |
|
308 | + $args = array('post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num, 'fields' => 'ids'); |
|
309 | 309 | } else { |
310 | - $args = array( 'post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num ); |
|
310 | + $args = array('post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num); |
|
311 | 311 | } |
312 | 312 | |
313 | - $args = apply_filters( 'wpinv_get_random_items', $args ); |
|
313 | + $args = apply_filters('wpinv_get_random_items', $args); |
|
314 | 314 | |
315 | - return get_posts( $args ); |
|
315 | + return get_posts($args); |
|
316 | 316 | } |
317 | 317 | |
318 | -function wpinv_get_item_token( $url = '' ) { |
|
318 | +function wpinv_get_item_token($url = '') { |
|
319 | 319 | $args = array(); |
320 | - $hash = apply_filters( 'wpinv_get_url_token_algorithm', 'sha256' ); |
|
321 | - $secret = apply_filters( 'wpinv_get_url_token_secret', hash( $hash, wp_salt() ) ); |
|
320 | + $hash = apply_filters('wpinv_get_url_token_algorithm', 'sha256'); |
|
321 | + $secret = apply_filters('wpinv_get_url_token_secret', hash($hash, wp_salt())); |
|
322 | 322 | |
323 | - $parts = parse_url( $url ); |
|
323 | + $parts = parse_url($url); |
|
324 | 324 | $options = array(); |
325 | 325 | |
326 | - if ( isset( $parts['query'] ) ) { |
|
327 | - wp_parse_str( $parts['query'], $query_args ); |
|
326 | + if (isset($parts['query'])) { |
|
327 | + wp_parse_str($parts['query'], $query_args); |
|
328 | 328 | |
329 | - if ( ! empty( $query_args['o'] ) ) { |
|
330 | - $options = explode( ':', rawurldecode( $query_args['o'] ) ); |
|
329 | + if (!empty($query_args['o'])) { |
|
330 | + $options = explode(':', rawurldecode($query_args['o'])); |
|
331 | 331 | |
332 | - if ( in_array( 'ip', $options ) ) { |
|
332 | + if (in_array('ip', $options)) { |
|
333 | 333 | $args['ip'] = wpinv_get_ip(); |
334 | 334 | } |
335 | 335 | |
336 | - if ( in_array( 'ua', $options ) ) { |
|
336 | + if (in_array('ua', $options)) { |
|
337 | 337 | $ua = wpinv_get_user_agent(); |
338 | - $args['user_agent'] = rawurlencode( $ua ); |
|
338 | + $args['user_agent'] = rawurlencode($ua); |
|
339 | 339 | } |
340 | 340 | } |
341 | 341 | } |
342 | 342 | |
343 | - $args = apply_filters( 'wpinv_get_url_token_args', $args, $url, $options ); |
|
343 | + $args = apply_filters('wpinv_get_url_token_args', $args, $url, $options); |
|
344 | 344 | |
345 | 345 | $args['secret'] = $secret; |
346 | 346 | $args['token'] = false; |
347 | 347 | |
348 | - $url = add_query_arg( $args, $url ); |
|
349 | - $parts = parse_url( $url ); |
|
348 | + $url = add_query_arg($args, $url); |
|
349 | + $parts = parse_url($url); |
|
350 | 350 | |
351 | - if ( ! isset( $parts['path'] ) ) { |
|
351 | + if (!isset($parts['path'])) { |
|
352 | 352 | $parts['path'] = ''; |
353 | 353 | } |
354 | 354 | |
355 | - $token = md5( $parts['path'] . '?' . $parts['query'] ); |
|
355 | + $token = md5($parts['path'] . '?' . $parts['query']); |
|
356 | 356 | |
357 | 357 | return $token; |
358 | 358 | } |
359 | 359 | |
360 | -function wpinv_validate_url_token( $url = '' ) { |
|
360 | +function wpinv_validate_url_token($url = '') { |
|
361 | 361 | $ret = false; |
362 | - $parts = parse_url( $url ); |
|
362 | + $parts = parse_url($url); |
|
363 | 363 | |
364 | - if ( isset( $parts['query'] ) ) { |
|
365 | - wp_parse_str( $parts['query'], $query_args ); |
|
364 | + if (isset($parts['query'])) { |
|
365 | + wp_parse_str($parts['query'], $query_args); |
|
366 | 366 | |
367 | - $allowed = apply_filters( 'wpinv_url_token_allowed_params', array( |
|
367 | + $allowed = apply_filters('wpinv_url_token_allowed_params', array( |
|
368 | 368 | 'item', |
369 | 369 | 'ttl', |
370 | 370 | 'token' |
371 | - ) ); |
|
371 | + )); |
|
372 | 372 | |
373 | 373 | $remove = array(); |
374 | 374 | |
375 | - foreach( $query_args as $key => $value ) { |
|
376 | - if( false === in_array( $key, $allowed ) ) { |
|
375 | + foreach ($query_args as $key => $value) { |
|
376 | + if (false === in_array($key, $allowed)) { |
|
377 | 377 | $remove[] = $key; |
378 | 378 | } |
379 | 379 | } |
380 | 380 | |
381 | - if( ! empty( $remove ) ) { |
|
382 | - $url = remove_query_arg( $remove, $url ); |
|
381 | + if (!empty($remove)) { |
|
382 | + $url = remove_query_arg($remove, $url); |
|
383 | 383 | } |
384 | 384 | |
385 | - if ( isset( $query_args['ttl'] ) && current_time( 'timestamp' ) > $query_args['ttl'] ) { |
|
386 | - wp_die( apply_filters( 'wpinv_item_link_expired_text', __( 'Sorry but your item link has expired.', 'invoicing' ) ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
385 | + if (isset($query_args['ttl']) && current_time('timestamp') > $query_args['ttl']) { |
|
386 | + wp_die(apply_filters('wpinv_item_link_expired_text', __('Sorry but your item link has expired.', 'invoicing')), __('Error', 'invoicing'), array('response' => 403)); |
|
387 | 387 | } |
388 | 388 | |
389 | - if ( isset( $query_args['token'] ) && $query_args['token'] == wpinv_get_item_token( $url ) ) { |
|
389 | + if (isset($query_args['token']) && $query_args['token'] == wpinv_get_item_token($url)) { |
|
390 | 390 | $ret = true; |
391 | 391 | } |
392 | 392 | |
393 | 393 | } |
394 | 394 | |
395 | - return apply_filters( 'wpinv_validate_url_token', $ret, $url, $query_args ); |
|
395 | + return apply_filters('wpinv_validate_url_token', $ret, $url, $query_args); |
|
396 | 396 | } |
397 | 397 | |
398 | -function wpinv_item_in_cart( $item_id = 0, $options = array() ) { |
|
398 | +function wpinv_item_in_cart($item_id = 0, $options = array()) { |
|
399 | 399 | $cart_items = wpinv_get_cart_contents(); |
400 | 400 | |
401 | 401 | $ret = false; |
402 | 402 | |
403 | - if ( is_array( $cart_items ) ) { |
|
404 | - foreach ( $cart_items as $item ) { |
|
405 | - if ( $item['id'] == $item_id ) { |
|
403 | + if (is_array($cart_items)) { |
|
404 | + foreach ($cart_items as $item) { |
|
405 | + if ($item['id'] == $item_id) { |
|
406 | 406 | $ret = true; |
407 | 407 | break; |
408 | 408 | } |
409 | 409 | } |
410 | 410 | } |
411 | 411 | |
412 | - return (bool) apply_filters( 'wpinv_item_in_cart', $ret, $item_id, $options ); |
|
412 | + return (bool)apply_filters('wpinv_item_in_cart', $ret, $item_id, $options); |
|
413 | 413 | } |
414 | 414 | |
415 | -function wpinv_get_cart_item_tax( $item_id = 0, $subtotal = '', $options = array() ) { |
|
415 | +function wpinv_get_cart_item_tax($item_id = 0, $subtotal = '', $options = array()) { |
|
416 | 416 | $tax = 0; |
417 | - if ( ! wpinv_item_is_tax_exclusive( $item_id ) ) { |
|
418 | - $country = !empty( $_POST['country'] ) ? $_POST['country'] : false; |
|
419 | - $state = isset( $_POST['state'] ) ? $_POST['state'] : ''; |
|
417 | + if (!wpinv_item_is_tax_exclusive($item_id)) { |
|
418 | + $country = !empty($_POST['country']) ? $_POST['country'] : false; |
|
419 | + $state = isset($_POST['state']) ? $_POST['state'] : ''; |
|
420 | 420 | |
421 | - $tax = wpinv_calculate_tax( $subtotal, $country, $state, $item_id ); |
|
421 | + $tax = wpinv_calculate_tax($subtotal, $country, $state, $item_id); |
|
422 | 422 | } |
423 | 423 | |
424 | - return apply_filters( 'wpinv_get_cart_item_tax', $tax, $item_id, $subtotal, $options ); |
|
424 | + return apply_filters('wpinv_get_cart_item_tax', $tax, $item_id, $subtotal, $options); |
|
425 | 425 | } |
426 | 426 | |
427 | -function wpinv_cart_item_price( $item ) { |
|
427 | +function wpinv_cart_item_price($item) { |
|
428 | 428 | $use_taxes = wpinv_use_taxes(); |
429 | - $item_id = isset( $item['id'] ) ? $item['id'] : 0; |
|
430 | - $price = isset( $item['item_price'] ) ? wpinv_format_amount( $item['item_price'] ) : 0; |
|
431 | - $options = isset( $item['options'] ) ? $item['options'] : array(); |
|
432 | - $price_id = isset( $options['price_id'] ) ? $options['price_id'] : false; |
|
433 | - $tax = wpinv_price( wpinv_format_amount( $item['tax'] ) ); |
|
434 | - |
|
435 | - if ( !wpinv_is_free_item( $item_id, $price_id ) && !wpinv_item_is_tax_exclusive( $item_id ) ) { |
|
436 | - if ( wpinv_prices_show_tax_on_checkout() && !wpinv_prices_include_tax() ) { |
|
429 | + $item_id = isset($item['id']) ? $item['id'] : 0; |
|
430 | + $price = isset($item['item_price']) ? wpinv_format_amount($item['item_price']) : 0; |
|
431 | + $options = isset($item['options']) ? $item['options'] : array(); |
|
432 | + $price_id = isset($options['price_id']) ? $options['price_id'] : false; |
|
433 | + $tax = wpinv_price(wpinv_format_amount($item['tax'])); |
|
434 | + |
|
435 | + if (!wpinv_is_free_item($item_id, $price_id) && !wpinv_item_is_tax_exclusive($item_id)) { |
|
436 | + if (wpinv_prices_show_tax_on_checkout() && !wpinv_prices_include_tax()) { |
|
437 | 437 | $price += $tax; |
438 | 438 | } |
439 | 439 | |
440 | - if( !wpinv_prices_show_tax_on_checkout() && wpinv_prices_include_tax() ) { |
|
440 | + if (!wpinv_prices_show_tax_on_checkout() && wpinv_prices_include_tax()) { |
|
441 | 441 | $price -= $tax; |
442 | 442 | } |
443 | 443 | } |
444 | 444 | |
445 | - $price = wpinv_price( wpinv_format_amount( $price ) ); |
|
445 | + $price = wpinv_price(wpinv_format_amount($price)); |
|
446 | 446 | |
447 | - return apply_filters( 'wpinv_cart_item_price_label', $price, $item ); |
|
447 | + return apply_filters('wpinv_cart_item_price_label', $price, $item); |
|
448 | 448 | } |
449 | 449 | |
450 | -function wpinv_cart_item_subtotal( $item ) { |
|
451 | - $subtotal = isset( $item['subtotal'] ) ? $item['subtotal'] : 0; |
|
452 | - $subtotal = wpinv_price( wpinv_format_amount( $subtotal ) ); |
|
450 | +function wpinv_cart_item_subtotal($item) { |
|
451 | + $subtotal = isset($item['subtotal']) ? $item['subtotal'] : 0; |
|
452 | + $subtotal = wpinv_price(wpinv_format_amount($subtotal)); |
|
453 | 453 | |
454 | - return apply_filters( 'wpinv_cart_item_subtotal_label', $subtotal, $item ); |
|
454 | + return apply_filters('wpinv_cart_item_subtotal_label', $subtotal, $item); |
|
455 | 455 | } |
456 | 456 | |
457 | -function wpinv_cart_item_tax( $item ) { |
|
457 | +function wpinv_cart_item_tax($item) { |
|
458 | 458 | $tax = ''; |
459 | 459 | $tax_rate = ''; |
460 | 460 | |
461 | - if ( isset( $item['tax'] ) && $item['tax'] > 0 && $item['subtotal'] > 0 ) { |
|
462 | - $tax = wpinv_price( wpinv_format_amount( $item['tax'] ) ); |
|
463 | - $tax_rate = !empty( $item['vat_rate'] ) ? $item['vat_rate'] : ( $item['tax'] / $item['subtotal'] ) * 100; |
|
464 | - $tax_rate = $tax_rate > 0 ? (float)wpinv_format_amount( $tax_rate, 2 ) : ''; |
|
461 | + if (isset($item['tax']) && $item['tax'] > 0 && $item['subtotal'] > 0) { |
|
462 | + $tax = wpinv_price(wpinv_format_amount($item['tax'])); |
|
463 | + $tax_rate = !empty($item['vat_rate']) ? $item['vat_rate'] : ($item['tax'] / $item['subtotal']) * 100; |
|
464 | + $tax_rate = $tax_rate > 0 ? (float)wpinv_format_amount($tax_rate, 2) : ''; |
|
465 | 465 | $tax_rate = $tax_rate != '' ? ' <small class="tax-rate normal small">(' . $tax_rate . '%)</small>' : ''; |
466 | 466 | } |
467 | 467 | |
468 | - $tax = $tax . $tax_rate; |
|
468 | + $tax = $tax . $tax_rate; |
|
469 | 469 | |
470 | - if ( $tax === '' ) { |
|
470 | + if ($tax === '') { |
|
471 | 471 | $tax = 0; // Zero tax |
472 | 472 | } |
473 | 473 | |
474 | - return apply_filters( 'wpinv_cart_item_tax_label', $tax, $item ); |
|
474 | + return apply_filters('wpinv_cart_item_tax_label', $tax, $item); |
|
475 | 475 | } |
476 | 476 | |
477 | -function wpinv_get_cart_item_price( $item_id = 0, $options = array(), $remove_tax_from_inclusive = false ) { |
|
477 | +function wpinv_get_cart_item_price($item_id = 0, $options = array(), $remove_tax_from_inclusive = false) { |
|
478 | 478 | $price = 0; |
479 | - $variable_prices = wpinv_has_variable_prices( $item_id ); |
|
479 | + $variable_prices = wpinv_has_variable_prices($item_id); |
|
480 | 480 | |
481 | - if ( $variable_prices ) { |
|
482 | - $prices = wpinv_get_variable_prices( $item_id ); |
|
481 | + if ($variable_prices) { |
|
482 | + $prices = wpinv_get_variable_prices($item_id); |
|
483 | 483 | |
484 | - if ( $prices ) { |
|
485 | - if( ! empty( $options ) ) { |
|
486 | - $price = isset( $prices[ $options['price_id'] ] ) ? $prices[ $options['price_id'] ]['amount'] : false; |
|
484 | + if ($prices) { |
|
485 | + if (!empty($options)) { |
|
486 | + $price = isset($prices[$options['price_id']]) ? $prices[$options['price_id']]['amount'] : false; |
|
487 | 487 | } else { |
488 | 488 | $price = false; |
489 | 489 | } |
490 | 490 | } |
491 | 491 | } |
492 | 492 | |
493 | - if( ! $variable_prices || false === $price ) { |
|
493 | + if (!$variable_prices || false === $price) { |
|
494 | 494 | // Get the standard Item price if not using variable prices |
495 | - $price = wpinv_get_item_price( $item_id ); |
|
495 | + $price = wpinv_get_item_price($item_id); |
|
496 | 496 | } |
497 | 497 | |
498 | - if ( $remove_tax_from_inclusive && wpinv_prices_include_tax() ) { |
|
499 | - $price -= wpinv_get_cart_item_tax( $item_id, $price, $options ); |
|
498 | + if ($remove_tax_from_inclusive && wpinv_prices_include_tax()) { |
|
499 | + $price -= wpinv_get_cart_item_tax($item_id, $price, $options); |
|
500 | 500 | } |
501 | 501 | |
502 | - return apply_filters( 'wpinv_cart_item_price', $price, $item_id, $options ); |
|
502 | + return apply_filters('wpinv_cart_item_price', $price, $item_id, $options); |
|
503 | 503 | } |
504 | 504 | |
505 | -function wpinv_get_cart_item_price_id( $item = array() ) { |
|
506 | - if( isset( $item['item_number'] ) ) { |
|
507 | - $price_id = isset( $item['item_number']['options']['price_id'] ) ? $item['item_number']['options']['price_id'] : null; |
|
505 | +function wpinv_get_cart_item_price_id($item = array()) { |
|
506 | + if (isset($item['item_number'])) { |
|
507 | + $price_id = isset($item['item_number']['options']['price_id']) ? $item['item_number']['options']['price_id'] : null; |
|
508 | 508 | } else { |
509 | - $price_id = isset( $item['options']['price_id'] ) ? $item['options']['price_id'] : null; |
|
509 | + $price_id = isset($item['options']['price_id']) ? $item['options']['price_id'] : null; |
|
510 | 510 | } |
511 | 511 | return $price_id; |
512 | 512 | } |
513 | 513 | |
514 | -function wpinv_get_cart_item_price_name( $item = array() ) { |
|
515 | - $price_id = (int)wpinv_get_cart_item_price_id( $item ); |
|
516 | - $prices = wpinv_get_variable_prices( $item['id'] ); |
|
517 | - $name = ! empty( $prices[ $price_id ] ) ? $prices[ $price_id ]['name'] : ''; |
|
518 | - return apply_filters( 'wpinv_get_cart_item_price_name', $name, $item['id'], $price_id, $item ); |
|
514 | +function wpinv_get_cart_item_price_name($item = array()) { |
|
515 | + $price_id = (int)wpinv_get_cart_item_price_id($item); |
|
516 | + $prices = wpinv_get_variable_prices($item['id']); |
|
517 | + $name = !empty($prices[$price_id]) ? $prices[$price_id]['name'] : ''; |
|
518 | + return apply_filters('wpinv_get_cart_item_price_name', $name, $item['id'], $price_id, $item); |
|
519 | 519 | } |
520 | 520 | |
521 | -function wpinv_get_cart_item_name( $item = array() ) { |
|
522 | - $item_title = !empty( $item['name'] ) ? $item['name'] : get_the_title( $item['id'] ); |
|
521 | +function wpinv_get_cart_item_name($item = array()) { |
|
522 | + $item_title = !empty($item['name']) ? $item['name'] : get_the_title($item['id']); |
|
523 | 523 | |
524 | - if ( empty( $item_title ) ) { |
|
524 | + if (empty($item_title)) { |
|
525 | 525 | $item_title = $item['id']; |
526 | 526 | } |
527 | 527 | |
@@ -531,23 +531,23 @@ discard block |
||
531 | 531 | } |
532 | 532 | */ |
533 | 533 | |
534 | - return apply_filters( 'wpinv_get_cart_item_name', $item_title, $item['id'], $item ); |
|
534 | + return apply_filters('wpinv_get_cart_item_name', $item_title, $item['id'], $item); |
|
535 | 535 | } |
536 | 536 | |
537 | -function wpinv_has_variable_prices( $item_id = 0 ) { |
|
537 | +function wpinv_has_variable_prices($item_id = 0) { |
|
538 | 538 | return false; |
539 | 539 | } |
540 | 540 | |
541 | -function wpinv_get_item_position_in_cart( $item_id = 0, $options = array() ) { |
|
541 | +function wpinv_get_item_position_in_cart($item_id = 0, $options = array()) { |
|
542 | 542 | $cart_items = wpinv_get_cart_contents(); |
543 | 543 | |
544 | - if ( !is_array( $cart_items ) ) { |
|
544 | + if (!is_array($cart_items)) { |
|
545 | 545 | return false; // Empty cart |
546 | 546 | } else { |
547 | - foreach ( $cart_items as $position => $item ) { |
|
548 | - if ( $item['id'] == $item_id ) { |
|
549 | - if ( isset( $options['price_id'] ) && isset( $item['options']['price_id'] ) ) { |
|
550 | - if ( (int) $options['price_id'] == (int) $item['options']['price_id'] ) { |
|
547 | + foreach ($cart_items as $position => $item) { |
|
548 | + if ($item['id'] == $item_id) { |
|
549 | + if (isset($options['price_id']) && isset($item['options']['price_id'])) { |
|
550 | + if ((int)$options['price_id'] == (int)$item['options']['price_id']) { |
|
551 | 551 | return $position; |
552 | 552 | } |
553 | 553 | } else { |
@@ -560,80 +560,80 @@ discard block |
||
560 | 560 | return false; // Not found |
561 | 561 | } |
562 | 562 | |
563 | -function wpinv_get_cart_item_quantity( $item ) { |
|
564 | - if ( wpinv_item_quantities_enabled() ) { |
|
565 | - $quantity = !empty( $item['quantity'] ) && (int)$item['quantity'] > 0 ? absint( $item['quantity'] ) : 1; |
|
563 | +function wpinv_get_cart_item_quantity($item) { |
|
564 | + if (wpinv_item_quantities_enabled()) { |
|
565 | + $quantity = !empty($item['quantity']) && (int)$item['quantity'] > 0 ? absint($item['quantity']) : 1; |
|
566 | 566 | } else { |
567 | 567 | $quantity = 1; |
568 | 568 | } |
569 | 569 | |
570 | - if ( $quantity < 1 ) { |
|
570 | + if ($quantity < 1) { |
|
571 | 571 | $quantity = 1; |
572 | 572 | } |
573 | 573 | |
574 | - return apply_filters( 'wpinv_get_cart_item_quantity', $quantity, $item ); |
|
574 | + return apply_filters('wpinv_get_cart_item_quantity', $quantity, $item); |
|
575 | 575 | } |
576 | 576 | |
577 | -function wpinv_get_item_suffix( $item, $html = true ) { |
|
578 | - if ( empty( $item ) ) { |
|
577 | +function wpinv_get_item_suffix($item, $html = true) { |
|
578 | + if (empty($item)) { |
|
579 | 579 | return NULL; |
580 | 580 | } |
581 | 581 | |
582 | - if ( is_int( $item ) ) { |
|
583 | - $item = new WPInv_Item( $item ); |
|
582 | + if (is_int($item)) { |
|
583 | + $item = new WPInv_Item($item); |
|
584 | 584 | } |
585 | 585 | |
586 | - if ( !( is_object( $item ) && is_a( $item, 'WPInv_Item' ) ) ) { |
|
586 | + if (!(is_object($item) && is_a($item, 'WPInv_Item'))) { |
|
587 | 587 | return NULL; |
588 | 588 | } |
589 | 589 | |
590 | - $suffix = $item->is_recurring() ? ' <span class="wpi-suffix">' . __( '(r)', 'invoicing' ) . '</span>' : ''; |
|
590 | + $suffix = $item->is_recurring() ? ' <span class="wpi-suffix">' . __('(r)', 'invoicing') . '</span>' : ''; |
|
591 | 591 | |
592 | - if ( !$html && $suffix ) { |
|
593 | - $suffix = strip_tags( $suffix ); |
|
592 | + if (!$html && $suffix) { |
|
593 | + $suffix = strip_tags($suffix); |
|
594 | 594 | } |
595 | 595 | |
596 | - return apply_filters( 'wpinv_get_item_suffix', $suffix, $item, $html ); |
|
596 | + return apply_filters('wpinv_get_item_suffix', $suffix, $item, $html); |
|
597 | 597 | } |
598 | 598 | |
599 | -function wpinv_remove_item( $item = 0, $force_delete = false ) { |
|
600 | - if ( empty( $item ) ) { |
|
599 | +function wpinv_remove_item($item = 0, $force_delete = false) { |
|
600 | + if (empty($item)) { |
|
601 | 601 | return NULL; |
602 | 602 | } |
603 | 603 | |
604 | - if ( is_int( $item ) ) { |
|
605 | - $item = new WPInv_Item( $item ); |
|
604 | + if (is_int($item)) { |
|
605 | + $item = new WPInv_Item($item); |
|
606 | 606 | } |
607 | 607 | |
608 | - if ( !( is_object( $item ) && is_a( $item, 'WPInv_Item' ) ) ) { |
|
608 | + if (!(is_object($item) && is_a($item, 'WPInv_Item'))) { |
|
609 | 609 | return NULL; |
610 | 610 | } |
611 | 611 | |
612 | - do_action( 'wpinv_pre_delete_item', $item ); |
|
612 | + do_action('wpinv_pre_delete_item', $item); |
|
613 | 613 | |
614 | - wp_delete_post( $item->ID, $force_delete ); |
|
614 | + wp_delete_post($item->ID, $force_delete); |
|
615 | 615 | |
616 | - do_action( 'wpinv_post_delete_item', $item ); |
|
616 | + do_action('wpinv_post_delete_item', $item); |
|
617 | 617 | } |
618 | 618 | |
619 | -function wpinv_can_delete_item( $post_id ) { |
|
620 | - $return = current_user_can( 'manage_options' ) ? true : false; |
|
619 | +function wpinv_can_delete_item($post_id) { |
|
620 | + $return = current_user_can('manage_options') ? true : false; |
|
621 | 621 | |
622 | - if ( $return && wpinv_item_in_use( $post_id ) ) { |
|
622 | + if ($return && wpinv_item_in_use($post_id)) { |
|
623 | 623 | $return = false; // Don't delete item already use in invoices. |
624 | 624 | } |
625 | 625 | |
626 | - return apply_filters( 'wpinv_can_delete_item', $return, $post_id ); |
|
626 | + return apply_filters('wpinv_can_delete_item', $return, $post_id); |
|
627 | 627 | } |
628 | 628 | |
629 | 629 | function wpinv_admin_action_delete() { |
630 | 630 | $screen = get_current_screen(); |
631 | 631 | |
632 | - if ( !empty( $screen->post_type ) && $screen->post_type == 'wpi_item' && !empty( $_REQUEST['post'] ) && is_array( $_REQUEST['post'] ) ) { |
|
632 | + if (!empty($screen->post_type) && $screen->post_type == 'wpi_item' && !empty($_REQUEST['post']) && is_array($_REQUEST['post'])) { |
|
633 | 633 | $post_ids = array(); |
634 | 634 | |
635 | - foreach ( $_REQUEST['post'] as $post_id ) { |
|
636 | - if ( !wpinv_can_delete_item( $post_id ) ) { |
|
635 | + foreach ($_REQUEST['post'] as $post_id) { |
|
636 | + if (!wpinv_can_delete_item($post_id)) { |
|
637 | 637 | continue; |
638 | 638 | } |
639 | 639 | |
@@ -643,83 +643,83 @@ discard block |
||
643 | 643 | $_REQUEST['post'] = $post_ids; |
644 | 644 | } |
645 | 645 | } |
646 | -add_action( 'admin_action_trash', 'wpinv_admin_action_delete', -10 ); |
|
647 | -add_action( 'admin_action_delete', 'wpinv_admin_action_delete', -10 ); |
|
646 | +add_action('admin_action_trash', 'wpinv_admin_action_delete', -10); |
|
647 | +add_action('admin_action_delete', 'wpinv_admin_action_delete', -10); |
|
648 | 648 | |
649 | -function wpinv_check_delete_item( $check, $post, $force_delete ) { |
|
650 | - if ( $post->post_type == 'wpi_item' ) { |
|
651 | - if ( $force_delete && !wpinv_can_delete_item( $post->ID ) ) { |
|
649 | +function wpinv_check_delete_item($check, $post, $force_delete) { |
|
650 | + if ($post->post_type == 'wpi_item') { |
|
651 | + if ($force_delete && !wpinv_can_delete_item($post->ID)) { |
|
652 | 652 | return true; |
653 | 653 | } |
654 | 654 | } |
655 | 655 | |
656 | 656 | return $check; |
657 | 657 | } |
658 | -add_filter( 'pre_delete_post', 'wpinv_check_delete_item', 10, 3 ); |
|
658 | +add_filter('pre_delete_post', 'wpinv_check_delete_item', 10, 3); |
|
659 | 659 | |
660 | -function wpinv_item_in_use( $item_id ) { |
|
660 | +function wpinv_item_in_use($item_id) { |
|
661 | 661 | global $wpdb, $wpi_items_in_use; |
662 | 662 | |
663 | - if ( !$item_id > 0 ) { |
|
663 | + if (!$item_id > 0) { |
|
664 | 664 | return false; |
665 | 665 | } |
666 | 666 | |
667 | - if ( !empty( $wpi_items_in_use ) ) { |
|
668 | - if ( isset( $wpi_items_in_use[$item_id] ) ) { |
|
667 | + if (!empty($wpi_items_in_use)) { |
|
668 | + if (isset($wpi_items_in_use[$item_id])) { |
|
669 | 669 | return $wpi_items_in_use[$item_id]; |
670 | 670 | } |
671 | 671 | } else { |
672 | 672 | $wpi_items_in_use = array(); |
673 | 673 | } |
674 | 674 | |
675 | - $statuses = array_keys( wpinv_get_invoice_statuses( true ) ); |
|
675 | + $statuses = array_keys(wpinv_get_invoice_statuses(true)); |
|
676 | 676 | |
677 | - $query = "SELECT p.ID FROM " . $wpdb->posts . " AS p INNER JOIN " . $wpdb->postmeta . " AS pm ON p.ID = pm.post_id WHERE p.post_type = 'wpi_invoice' AND p.post_status IN( '" . implode( "','", $statuses ) . "' ) AND pm.meta_key = '_wpinv_item_ids' AND FIND_IN_SET( '" . (int)$item_id . "', pm.meta_value )"; |
|
678 | - $in_use = $wpdb->get_var( $query ) > 0 ? true : false; |
|
677 | + $query = "SELECT p.ID FROM " . $wpdb->posts . " AS p INNER JOIN " . $wpdb->postmeta . " AS pm ON p.ID = pm.post_id WHERE p.post_type = 'wpi_invoice' AND p.post_status IN( '" . implode("','", $statuses) . "' ) AND pm.meta_key = '_wpinv_item_ids' AND FIND_IN_SET( '" . (int)$item_id . "', pm.meta_value )"; |
|
678 | + $in_use = $wpdb->get_var($query) > 0 ? true : false; |
|
679 | 679 | |
680 | 680 | $wpi_items_in_use[$item_id] = $in_use; |
681 | 681 | |
682 | 682 | return $in_use; |
683 | 683 | } |
684 | 684 | |
685 | -function wpinv_create_item( $args = array(), $wp_error = false, $force_update = false ) { |
|
685 | +function wpinv_create_item($args = array(), $wp_error = false, $force_update = false) { |
|
686 | 686 | // Set some defaults |
687 | 687 | $defaults = array( |
688 | - 'type' => 'custom', // Optional. Item type. Default 'custom'. |
|
689 | - 'item_id' => 0, // Required. Any integer number. Must be unique within item type. |
|
690 | - 'title' => '', // Required. Item title. |
|
691 | - 'price' => '0.00', // Optional. Item price. Default '0.00'. |
|
692 | - 'status' => 'pending', // Optional. pending, publish |
|
693 | - 'vat_rule' => 'digital', // Optional. digital => Digital item, physical => Physical item |
|
694 | - 'cpt_singular_name' => '', // Optional. Sub title for item. Should be singular. |
|
695 | - 'cpt_name' => '', // Optional. Sub title for item. Should be plural. |
|
696 | - 'is_recurring' => 0, // Optional. 1 => Allow recurring or 0 => Don't allow recurring |
|
697 | - 'recurring_period' => 'M', // Optional. D => Daily, W => Weekly, M => Monthly, Y => Yearly |
|
698 | - 'recurring_interval' => 0, // Optional. Integer value between 1 - 90. |
|
699 | - 'recurring_limit' => 0, // Optional. Any integer number. 0 for recurring forever until cancelled. |
|
700 | - 'free_trial' => 0, // Optional. 1 => Allow free trial or 0 => Don't free trial |
|
701 | - 'trial_period' => 'M', // Optional. D => Daily, W => Weekly, M => Monthly, Y => Yearly |
|
702 | - 'trial_interval' => 0, // Optional. Any integer number. |
|
703 | - 'excerpt' => '', // Optional. Item short description |
|
688 | + 'type' => 'custom', // Optional. Item type. Default 'custom'. |
|
689 | + 'item_id' => 0, // Required. Any integer number. Must be unique within item type. |
|
690 | + 'title' => '', // Required. Item title. |
|
691 | + 'price' => '0.00', // Optional. Item price. Default '0.00'. |
|
692 | + 'status' => 'pending', // Optional. pending, publish |
|
693 | + 'vat_rule' => 'digital', // Optional. digital => Digital item, physical => Physical item |
|
694 | + 'cpt_singular_name' => '', // Optional. Sub title for item. Should be singular. |
|
695 | + 'cpt_name' => '', // Optional. Sub title for item. Should be plural. |
|
696 | + 'is_recurring' => 0, // Optional. 1 => Allow recurring or 0 => Don't allow recurring |
|
697 | + 'recurring_period' => 'M', // Optional. D => Daily, W => Weekly, M => Monthly, Y => Yearly |
|
698 | + 'recurring_interval' => 0, // Optional. Integer value between 1 - 90. |
|
699 | + 'recurring_limit' => 0, // Optional. Any integer number. 0 for recurring forever until cancelled. |
|
700 | + 'free_trial' => 0, // Optional. 1 => Allow free trial or 0 => Don't free trial |
|
701 | + 'trial_period' => 'M', // Optional. D => Daily, W => Weekly, M => Monthly, Y => Yearly |
|
702 | + 'trial_interval' => 0, // Optional. Any integer number. |
|
703 | + 'excerpt' => '', // Optional. Item short description |
|
704 | 704 | ); |
705 | 705 | |
706 | - $data = wp_parse_args( $args, $defaults ); |
|
706 | + $data = wp_parse_args($args, $defaults); |
|
707 | 707 | |
708 | - if ( empty( $data['item_id'] ) ) { |
|
709 | - if ( $wp_error ) { |
|
710 | - return new WP_Error( 'invalid_item_id', __( 'Invalid item ID.' ) ); |
|
708 | + if (empty($data['item_id'])) { |
|
709 | + if ($wp_error) { |
|
710 | + return new WP_Error('invalid_item_id', __('Invalid item ID.')); |
|
711 | 711 | } else { |
712 | 712 | return false; |
713 | 713 | } |
714 | 714 | } |
715 | 715 | |
716 | - if ( empty( $data['type'] ) ) { |
|
716 | + if (empty($data['type'])) { |
|
717 | 717 | $data['type'] = 'custom'; |
718 | 718 | } |
719 | 719 | |
720 | - $item = wpinv_get_item_by( 'item_id', $data['item_id'], $data['type'] ); |
|
720 | + $item = wpinv_get_item_by('item_id', $data['item_id'], $data['type']); |
|
721 | 721 | |
722 | - if ( !$force_update && !empty( $item ) ) { |
|
722 | + if (!$force_update && !empty($item)) { |
|
723 | 723 | return $item; |
724 | 724 | } |
725 | 725 | |
@@ -728,18 +728,18 @@ discard block |
||
728 | 728 | $meta['post_id'] = $data['item_id']; |
729 | 729 | $meta['cpt_singular_name'] = $data['cpt_singular_name']; |
730 | 730 | $meta['cpt_name'] = $data['cpt_name']; |
731 | - $meta['price'] = wpinv_format_amount( $data['price'], NULL, true ); |
|
731 | + $meta['price'] = wpinv_format_amount($data['price'], NULL, true); |
|
732 | 732 | $meta['vat_rule'] = $data['vat_rule']; |
733 | 733 | $meta['vat_class'] = '_standard'; |
734 | 734 | |
735 | - if ( !empty( $data['is_recurring'] ) ) { |
|
735 | + if (!empty($data['is_recurring'])) { |
|
736 | 736 | $meta['is_recurring'] = $data['is_recurring']; |
737 | 737 | $meta['recurring_period'] = $data['recurring_period']; |
738 | - $meta['recurring_interval'] = absint( $data['recurring_interval'] ); |
|
739 | - $meta['recurring_limit'] = absint( $data['recurring_limit'] ); |
|
738 | + $meta['recurring_interval'] = absint($data['recurring_interval']); |
|
739 | + $meta['recurring_limit'] = absint($data['recurring_limit']); |
|
740 | 740 | $meta['free_trial'] = $data['free_trial']; |
741 | 741 | $meta['trial_period'] = $data['trial_period']; |
742 | - $meta['trial_interval'] = absint( $data['trial_interval'] ); |
|
742 | + $meta['trial_interval'] = absint($data['trial_interval']); |
|
743 | 743 | } else { |
744 | 744 | $meta['is_recurring'] = 0; |
745 | 745 | $meta['recurring_period'] = ''; |
@@ -750,18 +750,18 @@ discard block |
||
750 | 750 | $meta['trial_interval'] = ''; |
751 | 751 | } |
752 | 752 | |
753 | - $post_data = array( |
|
753 | + $post_data = array( |
|
754 | 754 | 'post_title' => $data['title'], |
755 | 755 | 'post_excerpt' => $data['excerpt'], |
756 | 756 | 'post_status' => $data['status'], |
757 | 757 | 'meta' => $meta |
758 | 758 | ); |
759 | 759 | |
760 | - if ( !empty( $item ) ) { |
|
761 | - $item->update( $post_data, $wp_error ); |
|
760 | + if (!empty($item)) { |
|
761 | + $item->update($post_data, $wp_error); |
|
762 | 762 | } else { |
763 | 763 | $item = new WPInv_Item(); |
764 | - $item->create( $post_data, $wp_error ); |
|
764 | + $item->create($post_data, $wp_error); |
|
765 | 765 | } |
766 | 766 | |
767 | 767 | return $item; |