@@ -48,7 +48,6 @@ |
||
48 | 48 | /** |
49 | 49 | * Retrieve the current session instance. |
50 | 50 | * |
51 | - * @param bool $session_id Session ID from which to populate data. |
|
52 | 51 | * |
53 | 52 | * @return bool|WP_Session |
54 | 53 | */ |
@@ -17,215 +17,215 @@ |
||
17 | 17 | * @since 3.7.0 |
18 | 18 | */ |
19 | 19 | final class WP_Session extends Recursive_ArrayAccess { |
20 | - /** |
|
21 | - * ID of the current session. |
|
22 | - * |
|
23 | - * @var string |
|
24 | - */ |
|
25 | - public $session_id; |
|
26 | - |
|
27 | - /** |
|
28 | - * Unix timestamp when session expires. |
|
29 | - * |
|
30 | - * @var int |
|
31 | - */ |
|
32 | - protected $expires; |
|
33 | - |
|
34 | - /** |
|
35 | - * Unix timestamp indicating when the expiration time needs to be reset. |
|
36 | - * |
|
37 | - * @var int |
|
38 | - */ |
|
39 | - protected $exp_variant; |
|
40 | - |
|
41 | - /** |
|
42 | - * Singleton instance. |
|
43 | - * |
|
44 | - * @var bool|WP_Session |
|
45 | - */ |
|
46 | - private static $instance = false; |
|
47 | - |
|
48 | - /** |
|
49 | - * Retrieve the current session instance. |
|
50 | - * |
|
51 | - * @param bool $session_id Session ID from which to populate data. |
|
52 | - * |
|
53 | - * @return bool|WP_Session |
|
54 | - */ |
|
55 | - public static function get_instance() { |
|
56 | - if ( ! self::$instance ) { |
|
57 | - self::$instance = new self(); |
|
58 | - } |
|
59 | - |
|
60 | - return self::$instance; |
|
61 | - } |
|
62 | - |
|
63 | - /** |
|
64 | - * Default constructor. |
|
65 | - * Will rebuild the session collection from the given session ID if it exists. Otherwise, will |
|
66 | - * create a new session with that ID. |
|
67 | - * |
|
68 | - * @param $session_id |
|
69 | - * @uses apply_filters Calls `wp_session_expiration` to determine how long until sessions expire. |
|
70 | - */ |
|
71 | - protected function __construct() { |
|
72 | - if ( isset( $_COOKIE[WP_SESSION_COOKIE] ) ) { |
|
73 | - $cookie = stripslashes( $_COOKIE[WP_SESSION_COOKIE] ); |
|
74 | - $cookie_crumbs = explode( '||', $cookie ); |
|
20 | + /** |
|
21 | + * ID of the current session. |
|
22 | + * |
|
23 | + * @var string |
|
24 | + */ |
|
25 | + public $session_id; |
|
26 | + |
|
27 | + /** |
|
28 | + * Unix timestamp when session expires. |
|
29 | + * |
|
30 | + * @var int |
|
31 | + */ |
|
32 | + protected $expires; |
|
33 | + |
|
34 | + /** |
|
35 | + * Unix timestamp indicating when the expiration time needs to be reset. |
|
36 | + * |
|
37 | + * @var int |
|
38 | + */ |
|
39 | + protected $exp_variant; |
|
40 | + |
|
41 | + /** |
|
42 | + * Singleton instance. |
|
43 | + * |
|
44 | + * @var bool|WP_Session |
|
45 | + */ |
|
46 | + private static $instance = false; |
|
47 | + |
|
48 | + /** |
|
49 | + * Retrieve the current session instance. |
|
50 | + * |
|
51 | + * @param bool $session_id Session ID from which to populate data. |
|
52 | + * |
|
53 | + * @return bool|WP_Session |
|
54 | + */ |
|
55 | + public static function get_instance() { |
|
56 | + if ( ! self::$instance ) { |
|
57 | + self::$instance = new self(); |
|
58 | + } |
|
59 | + |
|
60 | + return self::$instance; |
|
61 | + } |
|
62 | + |
|
63 | + /** |
|
64 | + * Default constructor. |
|
65 | + * Will rebuild the session collection from the given session ID if it exists. Otherwise, will |
|
66 | + * create a new session with that ID. |
|
67 | + * |
|
68 | + * @param $session_id |
|
69 | + * @uses apply_filters Calls `wp_session_expiration` to determine how long until sessions expire. |
|
70 | + */ |
|
71 | + protected function __construct() { |
|
72 | + if ( isset( $_COOKIE[WP_SESSION_COOKIE] ) ) { |
|
73 | + $cookie = stripslashes( $_COOKIE[WP_SESSION_COOKIE] ); |
|
74 | + $cookie_crumbs = explode( '||', $cookie ); |
|
75 | 75 | |
76 | 76 | $this->session_id = preg_replace("/[^A-Za-z0-9_]/", '', $cookie_crumbs[0] ); |
77 | 77 | $this->expires = absint( $cookie_crumbs[1] ); |
78 | 78 | $this->exp_variant = absint( $cookie_crumbs[2] ); |
79 | 79 | |
80 | - // Update the session expiration if we're past the variant time |
|
81 | - if ( time() > $this->exp_variant ) { |
|
82 | - $this->set_expiration(); |
|
83 | - delete_option( "_wp_session_expires_{$this->session_id}" ); |
|
84 | - add_option( "_wp_session_expires_{$this->session_id}", $this->expires, '', 'no' ); |
|
85 | - } |
|
86 | - } else { |
|
87 | - $this->session_id = WP_Session_Utils::generate_id(); |
|
88 | - $this->set_expiration(); |
|
89 | - } |
|
90 | - |
|
91 | - $this->read_data(); |
|
92 | - |
|
93 | - $this->set_cookie(); |
|
94 | - |
|
95 | - } |
|
96 | - |
|
97 | - /** |
|
98 | - * Set both the expiration time and the expiration variant. |
|
99 | - * |
|
100 | - * If the current time is below the variant, we don't update the session's expiration time. If it's |
|
101 | - * greater than the variant, then we update the expiration time in the database. This prevents |
|
102 | - * writing to the database on every page load for active sessions and only updates the expiration |
|
103 | - * time if we're nearing when the session actually expires. |
|
104 | - * |
|
105 | - * By default, the expiration time is set to 30 minutes. |
|
106 | - * By default, the expiration variant is set to 24 minutes. |
|
107 | - * |
|
108 | - * As a result, the session expiration time - at a maximum - will only be written to the database once |
|
109 | - * every 24 minutes. After 30 minutes, the session will have been expired. No cookie will be sent by |
|
110 | - * the browser, and the old session will be queued for deletion by the garbage collector. |
|
111 | - * |
|
112 | - * @uses apply_filters Calls `wp_session_expiration_variant` to get the max update window for session data. |
|
113 | - * @uses apply_filters Calls `wp_session_expiration` to get the standard expiration time for sessions. |
|
114 | - */ |
|
115 | - protected function set_expiration() { |
|
116 | - $this->exp_variant = time() + (int) apply_filters( 'wp_session_expiration_variant', 24 * 60 ); |
|
117 | - $this->expires = time() + (int) apply_filters( 'wp_session_expiration', 30 * 60 ); |
|
118 | - } |
|
119 | - |
|
120 | - /** |
|
121 | - * Set the session cookie |
|
122 | - * @uses apply_filters Calls `wp_session_cookie_secure` to set the $secure parameter of setcookie() |
|
123 | - * @uses apply_filters Calls `wp_session_cookie_httponly` to set the $httponly parameter of setcookie() |
|
124 | - */ |
|
125 | - protected function set_cookie() { |
|
126 | - if ( !defined( 'WPI_TESTING_MODE' ) ) { |
|
127 | - try { |
|
128 | - $secure = apply_filters('wp_session_cookie_secure', false); |
|
129 | - $httponly = apply_filters('wp_session_cookie_httponly', false); |
|
130 | - setcookie( WP_SESSION_COOKIE, $this->session_id . '||' . $this->expires . '||' . $this->exp_variant , $this->expires, COOKIEPATH, COOKIE_DOMAIN, $secure, $httponly ); |
|
131 | - } catch(Exception $e) { |
|
132 | - error_log( 'Set Cookie Error: ' . $e->getMessage() ); |
|
133 | - } |
|
134 | - } |
|
135 | - } |
|
136 | - |
|
137 | - /** |
|
138 | - * Read data from a transient for the current session. |
|
139 | - * |
|
140 | - * Automatically resets the expiration time for the session transient to some time in the future. |
|
141 | - * |
|
142 | - * @return array |
|
143 | - */ |
|
144 | - protected function read_data() { |
|
145 | - $this->container = get_option( "_wp_session_{$this->session_id}", array() ); |
|
146 | - |
|
147 | - return $this->container; |
|
148 | - } |
|
149 | - |
|
150 | - /** |
|
151 | - * Write the data from the current session to the data storage system. |
|
152 | - */ |
|
153 | - public function write_data() { |
|
154 | - $option_key = "_wp_session_{$this->session_id}"; |
|
80 | + // Update the session expiration if we're past the variant time |
|
81 | + if ( time() > $this->exp_variant ) { |
|
82 | + $this->set_expiration(); |
|
83 | + delete_option( "_wp_session_expires_{$this->session_id}" ); |
|
84 | + add_option( "_wp_session_expires_{$this->session_id}", $this->expires, '', 'no' ); |
|
85 | + } |
|
86 | + } else { |
|
87 | + $this->session_id = WP_Session_Utils::generate_id(); |
|
88 | + $this->set_expiration(); |
|
89 | + } |
|
90 | + |
|
91 | + $this->read_data(); |
|
92 | + |
|
93 | + $this->set_cookie(); |
|
94 | + |
|
95 | + } |
|
96 | + |
|
97 | + /** |
|
98 | + * Set both the expiration time and the expiration variant. |
|
99 | + * |
|
100 | + * If the current time is below the variant, we don't update the session's expiration time. If it's |
|
101 | + * greater than the variant, then we update the expiration time in the database. This prevents |
|
102 | + * writing to the database on every page load for active sessions and only updates the expiration |
|
103 | + * time if we're nearing when the session actually expires. |
|
104 | + * |
|
105 | + * By default, the expiration time is set to 30 minutes. |
|
106 | + * By default, the expiration variant is set to 24 minutes. |
|
107 | + * |
|
108 | + * As a result, the session expiration time - at a maximum - will only be written to the database once |
|
109 | + * every 24 minutes. After 30 minutes, the session will have been expired. No cookie will be sent by |
|
110 | + * the browser, and the old session will be queued for deletion by the garbage collector. |
|
111 | + * |
|
112 | + * @uses apply_filters Calls `wp_session_expiration_variant` to get the max update window for session data. |
|
113 | + * @uses apply_filters Calls `wp_session_expiration` to get the standard expiration time for sessions. |
|
114 | + */ |
|
115 | + protected function set_expiration() { |
|
116 | + $this->exp_variant = time() + (int) apply_filters( 'wp_session_expiration_variant', 24 * 60 ); |
|
117 | + $this->expires = time() + (int) apply_filters( 'wp_session_expiration', 30 * 60 ); |
|
118 | + } |
|
119 | + |
|
120 | + /** |
|
121 | + * Set the session cookie |
|
122 | + * @uses apply_filters Calls `wp_session_cookie_secure` to set the $secure parameter of setcookie() |
|
123 | + * @uses apply_filters Calls `wp_session_cookie_httponly` to set the $httponly parameter of setcookie() |
|
124 | + */ |
|
125 | + protected function set_cookie() { |
|
126 | + if ( !defined( 'WPI_TESTING_MODE' ) ) { |
|
127 | + try { |
|
128 | + $secure = apply_filters('wp_session_cookie_secure', false); |
|
129 | + $httponly = apply_filters('wp_session_cookie_httponly', false); |
|
130 | + setcookie( WP_SESSION_COOKIE, $this->session_id . '||' . $this->expires . '||' . $this->exp_variant , $this->expires, COOKIEPATH, COOKIE_DOMAIN, $secure, $httponly ); |
|
131 | + } catch(Exception $e) { |
|
132 | + error_log( 'Set Cookie Error: ' . $e->getMessage() ); |
|
133 | + } |
|
134 | + } |
|
135 | + } |
|
136 | + |
|
137 | + /** |
|
138 | + * Read data from a transient for the current session. |
|
139 | + * |
|
140 | + * Automatically resets the expiration time for the session transient to some time in the future. |
|
141 | + * |
|
142 | + * @return array |
|
143 | + */ |
|
144 | + protected function read_data() { |
|
145 | + $this->container = get_option( "_wp_session_{$this->session_id}", array() ); |
|
146 | + |
|
147 | + return $this->container; |
|
148 | + } |
|
149 | + |
|
150 | + /** |
|
151 | + * Write the data from the current session to the data storage system. |
|
152 | + */ |
|
153 | + public function write_data() { |
|
154 | + $option_key = "_wp_session_{$this->session_id}"; |
|
155 | 155 | |
156 | - if ( false === get_option( $option_key ) ) { |
|
157 | - add_option( "_wp_session_{$this->session_id}", $this->container, '', 'no' ); |
|
158 | - add_option( "_wp_session_expires_{$this->session_id}", $this->expires, '', 'no' ); |
|
159 | - } else { |
|
160 | - delete_option( "_wp_session_{$this->session_id}" ); |
|
161 | - add_option( "_wp_session_{$this->session_id}", $this->container, '', 'no' ); |
|
162 | - } |
|
163 | - } |
|
164 | - |
|
165 | - /** |
|
166 | - * Output the current container contents as a JSON-encoded string. |
|
167 | - * |
|
168 | - * @return string |
|
169 | - */ |
|
170 | - public function json_out() { |
|
171 | - return json_encode( $this->container ); |
|
172 | - } |
|
173 | - |
|
174 | - /** |
|
175 | - * Decodes a JSON string and, if the object is an array, overwrites the session container with its contents. |
|
176 | - * |
|
177 | - * @param string $data |
|
178 | - * |
|
179 | - * @return bool |
|
180 | - */ |
|
181 | - public function json_in( $data ) { |
|
182 | - $array = json_decode( $data ); |
|
183 | - |
|
184 | - if ( is_array( $array ) ) { |
|
185 | - $this->container = $array; |
|
186 | - return true; |
|
187 | - } |
|
188 | - |
|
189 | - return false; |
|
190 | - } |
|
191 | - |
|
192 | - /** |
|
193 | - * Regenerate the current session's ID. |
|
194 | - * |
|
195 | - * @param bool $delete_old Flag whether or not to delete the old session data from the server. |
|
196 | - */ |
|
197 | - public function regenerate_id( $delete_old = false ) { |
|
198 | - if ( $delete_old ) { |
|
199 | - delete_option( "_wp_session_{$this->session_id}" ); |
|
200 | - } |
|
201 | - |
|
202 | - $this->session_id = WP_Session_Utils::generate_id(); |
|
203 | - |
|
204 | - $this->set_cookie(); |
|
205 | - } |
|
206 | - |
|
207 | - /** |
|
208 | - * Check if a session has been initialized. |
|
209 | - * |
|
210 | - * @return bool |
|
211 | - */ |
|
212 | - public function session_started() { |
|
213 | - return !!self::$instance; |
|
214 | - } |
|
215 | - |
|
216 | - /** |
|
217 | - * Return the read-only cache expiration value. |
|
218 | - * |
|
219 | - * @return int |
|
220 | - */ |
|
221 | - public function cache_expiration() { |
|
222 | - return $this->expires; |
|
223 | - } |
|
224 | - |
|
225 | - /** |
|
226 | - * Flushes all session variables. |
|
227 | - */ |
|
228 | - public function reset() { |
|
229 | - $this->container = array(); |
|
230 | - } |
|
156 | + if ( false === get_option( $option_key ) ) { |
|
157 | + add_option( "_wp_session_{$this->session_id}", $this->container, '', 'no' ); |
|
158 | + add_option( "_wp_session_expires_{$this->session_id}", $this->expires, '', 'no' ); |
|
159 | + } else { |
|
160 | + delete_option( "_wp_session_{$this->session_id}" ); |
|
161 | + add_option( "_wp_session_{$this->session_id}", $this->container, '', 'no' ); |
|
162 | + } |
|
163 | + } |
|
164 | + |
|
165 | + /** |
|
166 | + * Output the current container contents as a JSON-encoded string. |
|
167 | + * |
|
168 | + * @return string |
|
169 | + */ |
|
170 | + public function json_out() { |
|
171 | + return json_encode( $this->container ); |
|
172 | + } |
|
173 | + |
|
174 | + /** |
|
175 | + * Decodes a JSON string and, if the object is an array, overwrites the session container with its contents. |
|
176 | + * |
|
177 | + * @param string $data |
|
178 | + * |
|
179 | + * @return bool |
|
180 | + */ |
|
181 | + public function json_in( $data ) { |
|
182 | + $array = json_decode( $data ); |
|
183 | + |
|
184 | + if ( is_array( $array ) ) { |
|
185 | + $this->container = $array; |
|
186 | + return true; |
|
187 | + } |
|
188 | + |
|
189 | + return false; |
|
190 | + } |
|
191 | + |
|
192 | + /** |
|
193 | + * Regenerate the current session's ID. |
|
194 | + * |
|
195 | + * @param bool $delete_old Flag whether or not to delete the old session data from the server. |
|
196 | + */ |
|
197 | + public function regenerate_id( $delete_old = false ) { |
|
198 | + if ( $delete_old ) { |
|
199 | + delete_option( "_wp_session_{$this->session_id}" ); |
|
200 | + } |
|
201 | + |
|
202 | + $this->session_id = WP_Session_Utils::generate_id(); |
|
203 | + |
|
204 | + $this->set_cookie(); |
|
205 | + } |
|
206 | + |
|
207 | + /** |
|
208 | + * Check if a session has been initialized. |
|
209 | + * |
|
210 | + * @return bool |
|
211 | + */ |
|
212 | + public function session_started() { |
|
213 | + return !!self::$instance; |
|
214 | + } |
|
215 | + |
|
216 | + /** |
|
217 | + * Return the read-only cache expiration value. |
|
218 | + * |
|
219 | + * @return int |
|
220 | + */ |
|
221 | + public function cache_expiration() { |
|
222 | + return $this->expires; |
|
223 | + } |
|
224 | + |
|
225 | + /** |
|
226 | + * Flushes all session variables. |
|
227 | + */ |
|
228 | + public function reset() { |
|
229 | + $this->container = array(); |
|
230 | + } |
|
231 | 231 | } |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | * @return bool|WP_Session |
54 | 54 | */ |
55 | 55 | public static function get_instance() { |
56 | - if ( ! self::$instance ) { |
|
56 | + if (!self::$instance) { |
|
57 | 57 | self::$instance = new self(); |
58 | 58 | } |
59 | 59 | |
@@ -69,19 +69,19 @@ discard block |
||
69 | 69 | * @uses apply_filters Calls `wp_session_expiration` to determine how long until sessions expire. |
70 | 70 | */ |
71 | 71 | protected function __construct() { |
72 | - if ( isset( $_COOKIE[WP_SESSION_COOKIE] ) ) { |
|
73 | - $cookie = stripslashes( $_COOKIE[WP_SESSION_COOKIE] ); |
|
74 | - $cookie_crumbs = explode( '||', $cookie ); |
|
72 | + if (isset($_COOKIE[WP_SESSION_COOKIE])) { |
|
73 | + $cookie = stripslashes($_COOKIE[WP_SESSION_COOKIE]); |
|
74 | + $cookie_crumbs = explode('||', $cookie); |
|
75 | 75 | |
76 | - $this->session_id = preg_replace("/[^A-Za-z0-9_]/", '', $cookie_crumbs[0] ); |
|
77 | - $this->expires = absint( $cookie_crumbs[1] ); |
|
78 | - $this->exp_variant = absint( $cookie_crumbs[2] ); |
|
76 | + $this->session_id = preg_replace("/[^A-Za-z0-9_]/", '', $cookie_crumbs[0]); |
|
77 | + $this->expires = absint($cookie_crumbs[1]); |
|
78 | + $this->exp_variant = absint($cookie_crumbs[2]); |
|
79 | 79 | |
80 | 80 | // Update the session expiration if we're past the variant time |
81 | - if ( time() > $this->exp_variant ) { |
|
81 | + if (time() > $this->exp_variant) { |
|
82 | 82 | $this->set_expiration(); |
83 | - delete_option( "_wp_session_expires_{$this->session_id}" ); |
|
84 | - add_option( "_wp_session_expires_{$this->session_id}", $this->expires, '', 'no' ); |
|
83 | + delete_option("_wp_session_expires_{$this->session_id}"); |
|
84 | + add_option("_wp_session_expires_{$this->session_id}", $this->expires, '', 'no'); |
|
85 | 85 | } |
86 | 86 | } else { |
87 | 87 | $this->session_id = WP_Session_Utils::generate_id(); |
@@ -113,8 +113,8 @@ discard block |
||
113 | 113 | * @uses apply_filters Calls `wp_session_expiration` to get the standard expiration time for sessions. |
114 | 114 | */ |
115 | 115 | protected function set_expiration() { |
116 | - $this->exp_variant = time() + (int) apply_filters( 'wp_session_expiration_variant', 24 * 60 ); |
|
117 | - $this->expires = time() + (int) apply_filters( 'wp_session_expiration', 30 * 60 ); |
|
116 | + $this->exp_variant = time() + (int)apply_filters('wp_session_expiration_variant', 24 * 60); |
|
117 | + $this->expires = time() + (int)apply_filters('wp_session_expiration', 30 * 60); |
|
118 | 118 | } |
119 | 119 | |
120 | 120 | /** |
@@ -123,13 +123,13 @@ discard block |
||
123 | 123 | * @uses apply_filters Calls `wp_session_cookie_httponly` to set the $httponly parameter of setcookie() |
124 | 124 | */ |
125 | 125 | protected function set_cookie() { |
126 | - if ( !defined( 'WPI_TESTING_MODE' ) ) { |
|
126 | + if (!defined('WPI_TESTING_MODE')) { |
|
127 | 127 | try { |
128 | 128 | $secure = apply_filters('wp_session_cookie_secure', false); |
129 | 129 | $httponly = apply_filters('wp_session_cookie_httponly', false); |
130 | - setcookie( WP_SESSION_COOKIE, $this->session_id . '||' . $this->expires . '||' . $this->exp_variant , $this->expires, COOKIEPATH, COOKIE_DOMAIN, $secure, $httponly ); |
|
131 | - } catch(Exception $e) { |
|
132 | - error_log( 'Set Cookie Error: ' . $e->getMessage() ); |
|
130 | + setcookie(WP_SESSION_COOKIE, $this->session_id . '||' . $this->expires . '||' . $this->exp_variant, $this->expires, COOKIEPATH, COOKIE_DOMAIN, $secure, $httponly); |
|
131 | + } catch (Exception $e) { |
|
132 | + error_log('Set Cookie Error: ' . $e->getMessage()); |
|
133 | 133 | } |
134 | 134 | } |
135 | 135 | } |
@@ -142,7 +142,7 @@ discard block |
||
142 | 142 | * @return array |
143 | 143 | */ |
144 | 144 | protected function read_data() { |
145 | - $this->container = get_option( "_wp_session_{$this->session_id}", array() ); |
|
145 | + $this->container = get_option("_wp_session_{$this->session_id}", array()); |
|
146 | 146 | |
147 | 147 | return $this->container; |
148 | 148 | } |
@@ -153,12 +153,12 @@ discard block |
||
153 | 153 | public function write_data() { |
154 | 154 | $option_key = "_wp_session_{$this->session_id}"; |
155 | 155 | |
156 | - if ( false === get_option( $option_key ) ) { |
|
157 | - add_option( "_wp_session_{$this->session_id}", $this->container, '', 'no' ); |
|
158 | - add_option( "_wp_session_expires_{$this->session_id}", $this->expires, '', 'no' ); |
|
156 | + if (false === get_option($option_key)) { |
|
157 | + add_option("_wp_session_{$this->session_id}", $this->container, '', 'no'); |
|
158 | + add_option("_wp_session_expires_{$this->session_id}", $this->expires, '', 'no'); |
|
159 | 159 | } else { |
160 | - delete_option( "_wp_session_{$this->session_id}" ); |
|
161 | - add_option( "_wp_session_{$this->session_id}", $this->container, '', 'no' ); |
|
160 | + delete_option("_wp_session_{$this->session_id}"); |
|
161 | + add_option("_wp_session_{$this->session_id}", $this->container, '', 'no'); |
|
162 | 162 | } |
163 | 163 | } |
164 | 164 | |
@@ -168,7 +168,7 @@ discard block |
||
168 | 168 | * @return string |
169 | 169 | */ |
170 | 170 | public function json_out() { |
171 | - return json_encode( $this->container ); |
|
171 | + return json_encode($this->container); |
|
172 | 172 | } |
173 | 173 | |
174 | 174 | /** |
@@ -178,10 +178,10 @@ discard block |
||
178 | 178 | * |
179 | 179 | * @return bool |
180 | 180 | */ |
181 | - public function json_in( $data ) { |
|
182 | - $array = json_decode( $data ); |
|
181 | + public function json_in($data) { |
|
182 | + $array = json_decode($data); |
|
183 | 183 | |
184 | - if ( is_array( $array ) ) { |
|
184 | + if (is_array($array)) { |
|
185 | 185 | $this->container = $array; |
186 | 186 | return true; |
187 | 187 | } |
@@ -194,9 +194,9 @@ discard block |
||
194 | 194 | * |
195 | 195 | * @param bool $delete_old Flag whether or not to delete the old session data from the server. |
196 | 196 | */ |
197 | - public function regenerate_id( $delete_old = false ) { |
|
198 | - if ( $delete_old ) { |
|
199 | - delete_option( "_wp_session_{$this->session_id}" ); |
|
197 | + public function regenerate_id($delete_old = false) { |
|
198 | + if ($delete_old) { |
|
199 | + delete_option("_wp_session_{$this->session_id}"); |
|
200 | 200 | } |
201 | 201 | |
202 | 202 | $this->session_id = WP_Session_Utils::generate_id(); |
@@ -407,6 +407,10 @@ discard block |
||
407 | 407 | exit; |
408 | 408 | } |
409 | 409 | |
410 | + /** |
|
411 | + * @param string $source_url |
|
412 | + * @param string $destination_file |
|
413 | + */ |
|
410 | 414 | public static function geoip2_download_file( $source_url, $destination_file ) { |
411 | 415 | $success = false; |
412 | 416 | $message = ''; |
@@ -1192,6 +1196,9 @@ discard block |
||
1192 | 1196 | return apply_filters( 'wpinv_response_euvatrates', $response, $group ); |
1193 | 1197 | } |
1194 | 1198 | |
1199 | + /** |
|
1200 | + * @param boolean $is_digital |
|
1201 | + */ |
|
1195 | 1202 | public static function requires_vat( $requires_vat = false, $user_id = 0, $is_digital = null ) { |
1196 | 1203 | global $wpi_item_id, $wpi_country; |
1197 | 1204 | |
@@ -1412,6 +1419,9 @@ discard block |
||
1412 | 1419 | return apply_filters( 'wpinv_item_is_taxable', $is_taxable, $item_id, $country , $state ); |
1413 | 1420 | } |
1414 | 1421 | |
1422 | + /** |
|
1423 | + * @param string|null $state |
|
1424 | + */ |
|
1415 | 1425 | public static function find_rate( $country, $state, $rate, $class ) { |
1416 | 1426 | global $wpi_zero_tax; |
1417 | 1427 |
@@ -1,6 +1,8 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | // Exit if accessed directly. |
3 | -if (!defined( 'ABSPATH' ) ) exit; |
|
3 | +if (!defined( 'ABSPATH' ) ) { |
|
4 | + exit; |
|
5 | +} |
|
4 | 6 | |
5 | 7 | class WPInv_EUVat { |
6 | 8 | private static $is_ajax = false; |
@@ -1445,16 +1447,18 @@ discard block |
||
1445 | 1447 | |
1446 | 1448 | if ( !empty( $tax_rates ) ) { |
1447 | 1449 | foreach ( $tax_rates as $key => $tax_rate ) { |
1448 | - if ( $country != $tax_rate['country'] ) |
|
1449 | - continue; |
|
1450 | + if ( $country != $tax_rate['country'] ) { |
|
1451 | + continue; |
|
1452 | + } |
|
1450 | 1453 | |
1451 | 1454 | if ( !empty( $tax_rate['global'] ) ) { |
1452 | 1455 | if ( 0 !== $tax_rate['rate'] || !empty( $tax_rate['rate'] ) ) { |
1453 | 1456 | $rate = number_format( $tax_rate['rate'], 4 ); |
1454 | 1457 | } |
1455 | 1458 | } else { |
1456 | - if ( empty( $tax_rate['state'] ) || strtolower( $state ) != strtolower( $tax_rate['state'] ) ) |
|
1457 | - continue; |
|
1459 | + if ( empty( $tax_rate['state'] ) || strtolower( $state ) != strtolower( $tax_rate['state'] ) ) { |
|
1460 | + continue; |
|
1461 | + } |
|
1458 | 1462 | |
1459 | 1463 | $state_rate = $tax_rate['rate']; |
1460 | 1464 | if ( 0 !== $state_rate || !empty( $state_rate ) ) { |
@@ -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,51 +151,51 @@ 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' ) ) ), |
|
170 | - 'placeholder' => __( 'Select a VAT Rate', 'invoicing' ), |
|
169 | + 'options' => array_merge($vat_classes, array('_new' => __('Add New Rate Class', 'invoicing'))), |
|
170 | + 'placeholder' => __('Select a VAT Rate', 'invoicing'), |
|
171 | 171 | 'selected' => $vat_class, |
172 | 172 | 'onchange' => 'document.location.href="' . $current_url . '&wpi_sub=" + this.value;', |
173 | 173 | ); |
174 | 174 | |
175 | - if ( $vat_class != '_standard' && $vat_class != '_new' ) { |
|
175 | + if ($vat_class != '_standard' && $vat_class != '_new') { |
|
176 | 176 | $vat_rates['vat_rate_delete'] = array( |
177 | 177 | 'id' => 'vat_rate_delete', |
178 | 178 | 'type' => 'vat_rate_delete', |
179 | 179 | ); |
180 | 180 | } |
181 | 181 | |
182 | - if ( $vat_class == '_new' ) { |
|
182 | + if ($vat_class == '_new') { |
|
183 | 183 | $vat_rates['vat_rates_settings'] = array( |
184 | 184 | 'id' => 'vat_rates_settings', |
185 | - 'name' => '<h3>' . __( 'Add New Rate Class', 'invoicing' ) . '</h3>', |
|
185 | + 'name' => '<h3>' . __('Add New Rate Class', 'invoicing') . '</h3>', |
|
186 | 186 | 'type' => 'header', |
187 | 187 | ); |
188 | 188 | $vat_rates['vat_rate_name'] = array( |
189 | 189 | 'id' => 'vat_rate_name', |
190 | - 'name' => __( 'Name', 'invoicing' ), |
|
191 | - 'desc' => __( 'A short name for the new VAT Rate class', 'invoicing' ), |
|
190 | + 'name' => __('Name', 'invoicing'), |
|
191 | + 'desc' => __('A short name for the new VAT Rate class', 'invoicing'), |
|
192 | 192 | 'type' => 'text', |
193 | 193 | 'size' => 'regular', |
194 | 194 | ); |
195 | 195 | $vat_rates['vat_rate_desc'] = array( |
196 | 196 | 'id' => 'vat_rate_desc', |
197 | - 'name' => __( 'Description', 'invoicing' ), |
|
198 | - 'desc' => __( 'Manage VAT Rate class', 'invoicing' ), |
|
197 | + 'name' => __('Description', 'invoicing'), |
|
198 | + 'desc' => __('Manage VAT Rate class', 'invoicing'), |
|
199 | 199 | 'type' => 'text', |
200 | 200 | 'size' => 'regular', |
201 | 201 | ); |
@@ -207,7 +207,7 @@ discard block |
||
207 | 207 | $vat_rates['vat_rates'] = array( |
208 | 208 | 'id' => 'vat_rates', |
209 | 209 | 'name' => '<h3>' . $vat_classes[$vat_class] . '</h3>', |
210 | - 'desc' => self::get_class_desc( $vat_class ), |
|
210 | + 'desc' => self::get_class_desc($vat_class), |
|
211 | 211 | 'type' => 'vat_rates', |
212 | 212 | ); |
213 | 213 | } |
@@ -215,12 +215,12 @@ discard block |
||
215 | 215 | return $vat_rates; |
216 | 216 | } |
217 | 217 | |
218 | - public static function vat_settings( $settings ) { |
|
219 | - if ( !empty( $settings ) ) { |
|
218 | + public static function vat_settings($settings) { |
|
219 | + if (!empty($settings)) { |
|
220 | 220 | $vat_settings = array(); |
221 | 221 | $vat_settings['vat_company_title'] = array( |
222 | 222 | 'id' => 'vat_company_title', |
223 | - 'name' => '<h3>' . __( 'Your Company Details', 'invoicing' ) . '</h3>', |
|
223 | + 'name' => '<h3>' . __('Your Company Details', 'invoicing') . '</h3>', |
|
224 | 224 | 'desc' => '', |
225 | 225 | 'type' => 'header', |
226 | 226 | 'size' => 'regular' |
@@ -228,22 +228,22 @@ discard block |
||
228 | 228 | |
229 | 229 | $vat_settings['vat_company_name'] = array( |
230 | 230 | 'id' => 'vat_company_name', |
231 | - 'name' => __( 'Your Company Name', 'invoicing' ), |
|
232 | - '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>' ), |
|
231 | + 'name' => __('Your Company Name', 'invoicing'), |
|
232 | + '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>'), |
|
233 | 233 | 'type' => 'text', |
234 | 234 | 'size' => 'regular', |
235 | 235 | ); |
236 | 236 | |
237 | 237 | $vat_settings['vat_number'] = array( |
238 | 238 | 'id' => 'vat_number', |
239 | - 'name' => __( 'Your VAT Number', 'invoicing' ), |
|
239 | + 'name' => __('Your VAT Number', 'invoicing'), |
|
240 | 240 | 'type' => 'vat_number', |
241 | 241 | 'size' => 'regular', |
242 | 242 | ); |
243 | 243 | |
244 | 244 | $vat_settings['vat_settings_title'] = array( |
245 | 245 | 'id' => 'vat_settings_title', |
246 | - 'name' => '<h3>' . __( 'Apply VAT Settings', 'invoicing' ) . '</h3>', |
|
246 | + 'name' => '<h3>' . __('Apply VAT Settings', 'invoicing') . '</h3>', |
|
247 | 247 | 'desc' => '', |
248 | 248 | 'type' => 'header', |
249 | 249 | 'size' => 'regular' |
@@ -251,8 +251,8 @@ discard block |
||
251 | 251 | |
252 | 252 | $vat_settings['apply_vat_rules'] = array( |
253 | 253 | 'id' => 'apply_vat_rules', |
254 | - 'name' => __( 'Enable VAT Rules', 'invoicing' ), |
|
255 | - '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>', |
|
254 | + 'name' => __('Enable VAT Rules', 'invoicing'), |
|
255 | + '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>', |
|
256 | 256 | 'type' => 'checkbox', |
257 | 257 | 'std' => '1' |
258 | 258 | ); |
@@ -268,8 +268,8 @@ discard block |
||
268 | 268 | |
269 | 269 | $vat_settings['vat_prevent_b2c_purchase'] = array( |
270 | 270 | 'id' => 'vat_prevent_b2c_purchase', |
271 | - 'name' => __( 'Prevent EU B2C Sales', 'invoicing' ), |
|
272 | - 'desc' => __( 'Enable this option if you are not registered for VAT in the EU.', 'invoicing' ), |
|
271 | + 'name' => __('Prevent EU B2C Sales', 'invoicing'), |
|
272 | + 'desc' => __('Enable this option if you are not registered for VAT in the EU.', 'invoicing'), |
|
273 | 273 | 'type' => 'checkbox' |
274 | 274 | ); |
275 | 275 | |
@@ -277,21 +277,21 @@ discard block |
||
277 | 277 | |
278 | 278 | $vat_settings['vat_same_country_rule'] = array( |
279 | 279 | 'id' => 'vat_same_country_rule', |
280 | - 'name' => __( 'Same Country Rule', 'invoicing' ), |
|
281 | - 'desc' => __( 'Select how you want to handle VAT charge if sales are in the same country as the base country.', 'invoicing' ), |
|
280 | + 'name' => __('Same Country Rule', 'invoicing'), |
|
281 | + 'desc' => __('Select how you want to handle VAT charge if sales are in the same country as the base country.', 'invoicing'), |
|
282 | 282 | 'type' => 'select', |
283 | 283 | 'options' => array( |
284 | - '' => __( 'Normal', 'invoicing' ), |
|
285 | - 'no' => __( 'No VAT', 'invoicing' ), |
|
286 | - 'always' => __( 'Always apply VAT', 'invoicing' ), |
|
284 | + '' => __('Normal', 'invoicing'), |
|
285 | + 'no' => __('No VAT', 'invoicing'), |
|
286 | + 'always' => __('Always apply VAT', 'invoicing'), |
|
287 | 287 | ), |
288 | - 'placeholder' => __( 'Select an option', 'invoicing' ), |
|
288 | + 'placeholder' => __('Select an option', 'invoicing'), |
|
289 | 289 | 'std' => '' |
290 | 290 | ); |
291 | 291 | |
292 | 292 | $vat_settings['vat_checkout_title'] = array( |
293 | 293 | 'id' => 'vat_checkout_title', |
294 | - 'name' => '<h3>' . __( 'Checkout Fields', 'invoicing' ) . '</h3>', |
|
294 | + 'name' => '<h3>' . __('Checkout Fields', 'invoicing') . '</h3>', |
|
295 | 295 | 'desc' => '', |
296 | 296 | 'type' => 'header', |
297 | 297 | 'size' => 'regular' |
@@ -299,14 +299,14 @@ discard block |
||
299 | 299 | |
300 | 300 | $vat_settings['vat_disable_fields'] = array( |
301 | 301 | 'id' => 'vat_disable_fields', |
302 | - 'name' => __( 'Disable VAT Fields', 'invoicing' ), |
|
303 | - '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>', |
|
302 | + 'name' => __('Disable VAT Fields', 'invoicing'), |
|
303 | + '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>', |
|
304 | 304 | 'type' => 'checkbox' |
305 | 305 | ); |
306 | 306 | |
307 | 307 | $vat_settings['vat_ip_lookup'] = array( |
308 | 308 | 'id' => 'vat_ip_lookup', |
309 | - 'name' => __( 'IP Country Look-up', 'invoicing' ), |
|
309 | + 'name' => __('IP Country Look-up', 'invoicing'), |
|
310 | 310 | 'type' => 'vat_ip_lookup', |
311 | 311 | 'size' => 'regular', |
312 | 312 | 'std' => 'default' |
@@ -314,21 +314,21 @@ discard block |
||
314 | 314 | |
315 | 315 | $vat_settings['hide_ip_address'] = array( |
316 | 316 | 'id' => 'hide_ip_address', |
317 | - 'name' => __( 'Hide IP Info at Checkout', 'invoicing' ), |
|
318 | - 'desc' => __( 'Hide the user IP info at checkout.', 'invoicing' ), |
|
317 | + 'name' => __('Hide IP Info at Checkout', 'invoicing'), |
|
318 | + 'desc' => __('Hide the user IP info at checkout.', 'invoicing'), |
|
319 | 319 | 'type' => 'checkbox' |
320 | 320 | ); |
321 | 321 | |
322 | 322 | $vat_settings['vat_ip_country_default'] = array( |
323 | 323 | 'id' => 'vat_ip_country_default', |
324 | - 'name' => __( 'Enable IP Country as Default', 'invoicing' ), |
|
325 | - 'desc' => __( 'Show the country of the users IP as the default country, otherwise the site default country will be used.', 'invoicing' ), |
|
324 | + 'name' => __('Enable IP Country as Default', 'invoicing'), |
|
325 | + 'desc' => __('Show the country of the users IP as the default country, otherwise the site default country will be used.', 'invoicing'), |
|
326 | 326 | 'type' => 'checkbox' |
327 | 327 | ); |
328 | 328 | |
329 | 329 | $vat_settings['vies_validation_title'] = array( |
330 | 330 | 'id' => 'vies_validation_title', |
331 | - 'name' => '<h3>' . __( 'VIES Validation', 'invoicing' ) . '</h3>', |
|
331 | + 'name' => '<h3>' . __('VIES Validation', 'invoicing') . '</h3>', |
|
332 | 332 | 'desc' => '', |
333 | 333 | 'type' => 'header', |
334 | 334 | 'size' => 'regular' |
@@ -336,37 +336,37 @@ discard block |
||
336 | 336 | |
337 | 337 | $vat_settings['vat_vies_check'] = array( |
338 | 338 | 'id' => 'vat_vies_check', |
339 | - 'name' => __( 'Disable VIES VAT ID Check', 'invoicing' ), |
|
340 | - '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>' ), |
|
339 | + 'name' => __('Disable VIES VAT ID Check', 'invoicing'), |
|
340 | + '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>'), |
|
341 | 341 | 'type' => 'checkbox' |
342 | 342 | ); |
343 | 343 | |
344 | 344 | $vat_settings['vat_disable_company_name_check'] = array( |
345 | 345 | 'id' => 'vat_disable_company_name_check', |
346 | - 'name' => __( 'Disable VIES Name Check', 'invoicing' ), |
|
347 | - '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>' ), |
|
346 | + 'name' => __('Disable VIES Name Check', 'invoicing'), |
|
347 | + '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>'), |
|
348 | 348 | 'type' => 'checkbox' |
349 | 349 | ); |
350 | 350 | |
351 | 351 | $vat_settings['vat_offline_check'] = array( |
352 | 352 | 'id' => 'vat_offline_check', |
353 | - 'name' => __( 'Disable Basic Checks', 'invoicing' ), |
|
354 | - 'desc' => __( 'Disable basic JS checks for correct format of VAT number. (Not Recommended)', 'invoicing' ), |
|
353 | + 'name' => __('Disable Basic Checks', 'invoicing'), |
|
354 | + 'desc' => __('Disable basic JS checks for correct format of VAT number. (Not Recommended)', 'invoicing'), |
|
355 | 355 | 'type' => 'checkbox' |
356 | 356 | ); |
357 | 357 | |
358 | 358 | |
359 | 359 | $settings['vat'] = $vat_settings; |
360 | 360 | |
361 | - if ( self::allow_vat_classes() ) { |
|
361 | + if (self::allow_vat_classes()) { |
|
362 | 362 | $settings['vat_rates'] = self::vat_rates_settings(); |
363 | 363 | } |
364 | 364 | |
365 | 365 | $eu_fallback_rate = array( |
366 | 366 | 'id' => 'eu_fallback_rate', |
367 | - 'name' => '<h3>' . __( 'VAT rate for EU member states', 'invoicing' ) . '</h3>', |
|
367 | + 'name' => '<h3>' . __('VAT rate for EU member states', 'invoicing') . '</h3>', |
|
368 | 368 | 'type' => 'eu_fallback_rate', |
369 | - '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' ), |
|
369 | + '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 | 370 | 'std' => '20', |
371 | 371 | 'size' => 'small' |
372 | 372 | ); |
@@ -382,11 +382,11 @@ discard block |
||
382 | 382 | $database_url = 'http' . (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] === 'on' ? 's' : '') . '://geolite.maxmind.com/download/geoip/database/'; |
383 | 383 | $destination_dir = $upload_dir['basedir'] . '/invoicing'; |
384 | 384 | |
385 | - if ( !is_dir( $destination_dir ) ) { |
|
386 | - mkdir( $destination_dir ); |
|
385 | + if (!is_dir($destination_dir)) { |
|
386 | + mkdir($destination_dir); |
|
387 | 387 | } |
388 | 388 | |
389 | - $database_files = array( |
|
389 | + $database_files = array( |
|
390 | 390 | 'country' => array( |
391 | 391 | 'source' => $database_url . 'GeoLite2-Country.mmdb.gz', |
392 | 392 | 'destination' => $destination_dir . '/GeoLite2-Country.mmdb', |
@@ -397,57 +397,57 @@ discard block |
||
397 | 397 | ) |
398 | 398 | ); |
399 | 399 | |
400 | - foreach( $database_files as $database => $files ) { |
|
401 | - $result = self::geoip2_download_file( $files['source'], $files['destination'] ); |
|
400 | + foreach ($database_files as $database => $files) { |
|
401 | + $result = self::geoip2_download_file($files['source'], $files['destination']); |
|
402 | 402 | |
403 | - if ( empty( $result['success'] ) ) { |
|
403 | + if (empty($result['success'])) { |
|
404 | 404 | echo $result['message']; |
405 | 405 | exit; |
406 | 406 | } |
407 | 407 | |
408 | - wpinv_update_option( 'wpinv_geoip2_date_updated', current_time( 'timestamp' ) ); |
|
409 | - echo sprintf(__( 'GeoIP2 %s database updated successfully.', 'invoicing' ), $database ) . ' '; |
|
408 | + wpinv_update_option('wpinv_geoip2_date_updated', current_time('timestamp')); |
|
409 | + echo sprintf(__('GeoIP2 %s database updated successfully.', 'invoicing'), $database) . ' '; |
|
410 | 410 | } |
411 | 411 | |
412 | 412 | exit; |
413 | 413 | } |
414 | 414 | |
415 | - public static function geoip2_download_file( $source_url, $destination_file ) { |
|
415 | + public static function geoip2_download_file($source_url, $destination_file) { |
|
416 | 416 | $success = false; |
417 | 417 | $message = ''; |
418 | 418 | |
419 | - if ( !function_exists( 'download_url' ) ) { |
|
420 | - require_once( ABSPATH . 'wp-admin/includes/file.php' ); |
|
419 | + if (!function_exists('download_url')) { |
|
420 | + require_once(ABSPATH . 'wp-admin/includes/file.php'); |
|
421 | 421 | } |
422 | 422 | |
423 | - $temp_file = download_url( $source_url ); |
|
423 | + $temp_file = download_url($source_url); |
|
424 | 424 | |
425 | - if ( is_wp_error( $temp_file ) ) { |
|
426 | - $message = sprintf( __( 'Error while downloading GeoIp2 database( %s ): %s', 'invoicing' ), $source_url, $temp_file->get_error_message() ); |
|
425 | + if (is_wp_error($temp_file)) { |
|
426 | + $message = sprintf(__('Error while downloading GeoIp2 database( %s ): %s', 'invoicing'), $source_url, $temp_file->get_error_message()); |
|
427 | 427 | } else { |
428 | - $handle = gzopen( $temp_file, 'rb' ); |
|
428 | + $handle = gzopen($temp_file, 'rb'); |
|
429 | 429 | |
430 | - if ( $handle ) { |
|
431 | - $fopen = fopen( $destination_file, 'wb' ); |
|
432 | - if ( $fopen ) { |
|
433 | - while ( ( $data = gzread( $handle, 4096 ) ) != false ) { |
|
434 | - fwrite( $fopen, $data ); |
|
430 | + if ($handle) { |
|
431 | + $fopen = fopen($destination_file, 'wb'); |
|
432 | + if ($fopen) { |
|
433 | + while (($data = gzread($handle, 4096)) != false) { |
|
434 | + fwrite($fopen, $data); |
|
435 | 435 | } |
436 | 436 | |
437 | - gzclose( $handle ); |
|
438 | - fclose( $fopen ); |
|
437 | + gzclose($handle); |
|
438 | + fclose($fopen); |
|
439 | 439 | |
440 | 440 | $success = true; |
441 | 441 | } else { |
442 | - gzclose( $handle ); |
|
443 | - $message = sprintf( __( 'Error could not open destination GeoIp2 database file for writing: %s', 'invoicing' ), $destination_file ); |
|
442 | + gzclose($handle); |
|
443 | + $message = sprintf(__('Error could not open destination GeoIp2 database file for writing: %s', 'invoicing'), $destination_file); |
|
444 | 444 | } |
445 | 445 | } else { |
446 | - $message = sprintf( __( 'Error could not open GeoIp2 database file for reading: %s', 'invoicing' ), $temp_file ); |
|
446 | + $message = sprintf(__('Error could not open GeoIp2 database file for reading: %s', 'invoicing'), $temp_file); |
|
447 | 447 | } |
448 | 448 | |
449 | - if ( file_exists( $temp_file ) ) { |
|
450 | - unlink( $temp_file ); |
|
449 | + if (file_exists($temp_file)) { |
|
450 | + unlink($temp_file); |
|
451 | 451 | } |
452 | 452 | } |
453 | 453 | |
@@ -459,11 +459,11 @@ discard block |
||
459 | 459 | } |
460 | 460 | |
461 | 461 | public static function load_geoip2() { |
462 | - if ( defined( 'WPINV_GEOIP2_LODDED' ) ) { |
|
462 | + if (defined('WPINV_GEOIP2_LODDED')) { |
|
463 | 463 | return; |
464 | 464 | } |
465 | 465 | |
466 | - if ( !class_exists( '\MaxMind\Db\Reader' ) ) { |
|
466 | + if (!class_exists('\MaxMind\Db\Reader')) { |
|
467 | 467 | $maxmind_db_files = array( |
468 | 468 | 'Reader/Decoder.php', |
469 | 469 | 'Reader/InvalidDatabaseException.php', |
@@ -472,12 +472,12 @@ discard block |
||
472 | 472 | 'Reader.php', |
473 | 473 | ); |
474 | 474 | |
475 | - foreach ( $maxmind_db_files as $key => $file ) { |
|
476 | - require_once( WPINV_PLUGIN_DIR . 'includes/libraries/MaxMind/Db/' . $file ); |
|
475 | + foreach ($maxmind_db_files as $key => $file) { |
|
476 | + require_once(WPINV_PLUGIN_DIR . 'includes/libraries/MaxMind/Db/' . $file); |
|
477 | 477 | } |
478 | 478 | } |
479 | 479 | |
480 | - if ( !class_exists( '\GeoIp2\Database\Reader' ) ) { |
|
480 | + if (!class_exists('\GeoIp2\Database\Reader')) { |
|
481 | 481 | $geoip2_files = array( |
482 | 482 | 'ProviderInterface.php', |
483 | 483 | 'Compat/JsonSerializable.php', |
@@ -511,23 +511,23 @@ discard block |
||
511 | 511 | 'WebService/Client.php', |
512 | 512 | ); |
513 | 513 | |
514 | - foreach ( $geoip2_files as $key => $file ) { |
|
515 | - require_once( WPINV_PLUGIN_DIR . 'includes/libraries/GeoIp2/' . $file ); |
|
514 | + foreach ($geoip2_files as $key => $file) { |
|
515 | + require_once(WPINV_PLUGIN_DIR . 'includes/libraries/GeoIp2/' . $file); |
|
516 | 516 | } |
517 | 517 | } |
518 | 518 | |
519 | - define( 'WPINV_GEOIP2_LODDED', true ); |
|
519 | + define('WPINV_GEOIP2_LODDED', true); |
|
520 | 520 | } |
521 | 521 | |
522 | 522 | public static function geoip2_country_dbfile() { |
523 | 523 | $upload_dir = wp_upload_dir(); |
524 | 524 | |
525 | - if ( !isset( $upload_dir['basedir'] ) ) { |
|
525 | + if (!isset($upload_dir['basedir'])) { |
|
526 | 526 | return false; |
527 | 527 | } |
528 | 528 | |
529 | 529 | $filename = $upload_dir['basedir'] . '/invoicing/GeoLite2-Country.mmdb'; |
530 | - if ( !file_exists( $filename ) ) { |
|
530 | + if (!file_exists($filename)) { |
|
531 | 531 | return false; |
532 | 532 | } |
533 | 533 | |
@@ -537,12 +537,12 @@ discard block |
||
537 | 537 | public static function geoip2_city_dbfile() { |
538 | 538 | $upload_dir = wp_upload_dir(); |
539 | 539 | |
540 | - if ( !isset( $upload_dir['basedir'] ) ) { |
|
540 | + if (!isset($upload_dir['basedir'])) { |
|
541 | 541 | return false; |
542 | 542 | } |
543 | 543 | |
544 | 544 | $filename = $upload_dir['basedir'] . '/invoicing/GeoLite2-City.mmdb'; |
545 | - if ( !file_exists( $filename ) ) { |
|
545 | + if (!file_exists($filename)) { |
|
546 | 546 | return false; |
547 | 547 | } |
548 | 548 | |
@@ -553,10 +553,10 @@ discard block |
||
553 | 553 | try { |
554 | 554 | self::load_geoip2(); |
555 | 555 | |
556 | - if ( $filename = self::geoip2_country_dbfile() ) { |
|
557 | - return new \GeoIp2\Database\Reader( $filename ); |
|
556 | + if ($filename = self::geoip2_country_dbfile()) { |
|
557 | + return new \GeoIp2\Database\Reader($filename); |
|
558 | 558 | } |
559 | - } catch( Exception $e ) { |
|
559 | + } catch (Exception $e) { |
|
560 | 560 | return false; |
561 | 561 | } |
562 | 562 | |
@@ -567,173 +567,173 @@ discard block |
||
567 | 567 | try { |
568 | 568 | self::load_geoip2(); |
569 | 569 | |
570 | - if ( $filename = self::geoip2_city_dbfile() ) { |
|
571 | - return new \GeoIp2\Database\Reader( $filename ); |
|
570 | + if ($filename = self::geoip2_city_dbfile()) { |
|
571 | + return new \GeoIp2\Database\Reader($filename); |
|
572 | 572 | } |
573 | - } catch( Exception $e ) { |
|
573 | + } catch (Exception $e) { |
|
574 | 574 | return false; |
575 | 575 | } |
576 | 576 | |
577 | 577 | return false; |
578 | 578 | } |
579 | 579 | |
580 | - public static function geoip2_country_record( $ip_address ) { |
|
580 | + public static function geoip2_country_record($ip_address) { |
|
581 | 581 | try { |
582 | 582 | $reader = self::geoip2_country_reader(); |
583 | 583 | |
584 | - if ( $reader ) { |
|
585 | - $record = $reader->country( $ip_address ); |
|
584 | + if ($reader) { |
|
585 | + $record = $reader->country($ip_address); |
|
586 | 586 | |
587 | - if ( !empty( $record->country->isoCode ) ) { |
|
587 | + if (!empty($record->country->isoCode)) { |
|
588 | 588 | return $record; |
589 | 589 | } |
590 | 590 | } |
591 | - } catch(\InvalidArgumentException $e) { |
|
592 | - wpinv_error_log( $e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )' ); |
|
591 | + } catch (\InvalidArgumentException $e) { |
|
592 | + wpinv_error_log($e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )'); |
|
593 | 593 | |
594 | 594 | return false; |
595 | - } catch(\GeoIp2\Exception\AddressNotFoundException $e) { |
|
596 | - wpinv_error_log( $e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )' ); |
|
595 | + } catch (\GeoIp2\Exception\AddressNotFoundException $e) { |
|
596 | + wpinv_error_log($e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )'); |
|
597 | 597 | |
598 | 598 | return false; |
599 | - } catch( Exception $e ) { |
|
599 | + } catch (Exception $e) { |
|
600 | 600 | return false; |
601 | 601 | } |
602 | 602 | |
603 | 603 | return false; |
604 | 604 | } |
605 | 605 | |
606 | - public static function geoip2_city_record( $ip_address ) { |
|
606 | + public static function geoip2_city_record($ip_address) { |
|
607 | 607 | try { |
608 | 608 | $reader = self::geoip2_city_reader(); |
609 | 609 | |
610 | - if ( $reader ) { |
|
611 | - $record = $reader->city( $ip_address ); |
|
610 | + if ($reader) { |
|
611 | + $record = $reader->city($ip_address); |
|
612 | 612 | |
613 | - if ( !empty( $record->country->isoCode ) ) { |
|
613 | + if (!empty($record->country->isoCode)) { |
|
614 | 614 | return $record; |
615 | 615 | } |
616 | 616 | } |
617 | - } catch(\InvalidArgumentException $e) { |
|
618 | - wpinv_error_log( $e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )' ); |
|
617 | + } catch (\InvalidArgumentException $e) { |
|
618 | + wpinv_error_log($e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )'); |
|
619 | 619 | |
620 | 620 | return false; |
621 | - } catch(\GeoIp2\Exception\AddressNotFoundException $e) { |
|
622 | - wpinv_error_log( $e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )' ); |
|
621 | + } catch (\GeoIp2\Exception\AddressNotFoundException $e) { |
|
622 | + wpinv_error_log($e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )'); |
|
623 | 623 | |
624 | 624 | return false; |
625 | - } catch( Exception $e ) { |
|
625 | + } catch (Exception $e) { |
|
626 | 626 | return false; |
627 | 627 | } |
628 | 628 | |
629 | 629 | return false; |
630 | 630 | } |
631 | 631 | |
632 | - public static function geoip2_country_code( $ip_address ) { |
|
633 | - $record = self::geoip2_country_record( $ip_address ); |
|
634 | - return !empty( $record->country->isoCode ) ? $record->country->isoCode : wpinv_get_default_country(); |
|
632 | + public static function geoip2_country_code($ip_address) { |
|
633 | + $record = self::geoip2_country_record($ip_address); |
|
634 | + return !empty($record->country->isoCode) ? $record->country->isoCode : wpinv_get_default_country(); |
|
635 | 635 | } |
636 | 636 | |
637 | 637 | // Find country by IP address. |
638 | - public static function get_country_by_ip( $ip = '' ) { |
|
638 | + public static function get_country_by_ip($ip = '') { |
|
639 | 639 | global $wpinv_ip_address_country; |
640 | 640 | |
641 | - if ( !empty( $wpinv_ip_address_country ) ) { |
|
641 | + if (!empty($wpinv_ip_address_country)) { |
|
642 | 642 | return $wpinv_ip_address_country; |
643 | 643 | } |
644 | 644 | |
645 | - if ( empty( $ip ) ) { |
|
645 | + if (empty($ip)) { |
|
646 | 646 | $ip = wpinv_get_ip(); |
647 | 647 | } |
648 | 648 | |
649 | - $ip_country_service = wpinv_get_option( 'vat_ip_lookup' ); |
|
650 | - $is_default = empty( $ip_country_service ) || $ip_country_service === 'default' ? true : false; |
|
649 | + $ip_country_service = wpinv_get_option('vat_ip_lookup'); |
|
650 | + $is_default = empty($ip_country_service) || $ip_country_service === 'default' ? true : false; |
|
651 | 651 | |
652 | - if ( !empty( $ip ) && $ip !== '127.0.0.1' ) { // For 127.0.0.1(localhost) use default country. |
|
653 | - if ( function_exists( 'geoip_country_code_by_name') && ( $ip_country_service === 'geoip' || $is_default ) ) { |
|
652 | + if (!empty($ip) && $ip !== '127.0.0.1') { // For 127.0.0.1(localhost) use default country. |
|
653 | + if (function_exists('geoip_country_code_by_name') && ($ip_country_service === 'geoip' || $is_default)) { |
|
654 | 654 | try { |
655 | - $wpinv_ip_address_country = geoip_country_code_by_name( $ip ); |
|
656 | - } catch( Exception $e ) { |
|
657 | - wpinv_error_log( $e->getMessage(), 'GeoIP Lookup( ' . $ip . ' )' ); |
|
655 | + $wpinv_ip_address_country = geoip_country_code_by_name($ip); |
|
656 | + } catch (Exception $e) { |
|
657 | + wpinv_error_log($e->getMessage(), 'GeoIP Lookup( ' . $ip . ' )'); |
|
658 | 658 | } |
659 | - } else if ( self::geoip2_country_dbfile() && ( $ip_country_service === 'geoip2' || $is_default ) ) { |
|
660 | - $wpinv_ip_address_country = self::geoip2_country_code( $ip ); |
|
661 | - } else if ( function_exists( 'simplexml_load_file' ) && ( $ip_country_service === 'geoplugin' || $is_default ) ) { |
|
662 | - $load_xml = simplexml_load_file( 'http://www.geoplugin.net/xml.gp?ip=' . $ip ); |
|
659 | + } else if (self::geoip2_country_dbfile() && ($ip_country_service === 'geoip2' || $is_default)) { |
|
660 | + $wpinv_ip_address_country = self::geoip2_country_code($ip); |
|
661 | + } else if (function_exists('simplexml_load_file') && ($ip_country_service === 'geoplugin' || $is_default)) { |
|
662 | + $load_xml = simplexml_load_file('http://www.geoplugin.net/xml.gp?ip=' . $ip); |
|
663 | 663 | |
664 | - if ( !empty( $load_xml ) && !empty( $load_xml->geoplugin_countryCode ) ) { |
|
664 | + if (!empty($load_xml) && !empty($load_xml->geoplugin_countryCode)) { |
|
665 | 665 | $wpinv_ip_address_country = (string)$load_xml->geoplugin_countryCode; |
666 | 666 | } |
667 | 667 | } |
668 | 668 | } |
669 | 669 | |
670 | - if ( empty( $wpinv_ip_address_country ) ) { |
|
670 | + if (empty($wpinv_ip_address_country)) { |
|
671 | 671 | $wpinv_ip_address_country = wpinv_get_default_country(); |
672 | 672 | } |
673 | 673 | |
674 | 674 | return $wpinv_ip_address_country; |
675 | 675 | } |
676 | 676 | |
677 | - public static function sanitize_vat_settings( $input ) { |
|
677 | + public static function sanitize_vat_settings($input) { |
|
678 | 678 | global $wpinv_options; |
679 | 679 | |
680 | 680 | $valid = false; |
681 | 681 | $message = ''; |
682 | 682 | |
683 | - if ( !empty( $wpinv_options['vat_vies_check'] ) ) { |
|
684 | - if ( empty( $wpinv_options['vat_offline_check'] ) ) { |
|
685 | - $valid = self::offline_check( $input['vat_number'] ); |
|
683 | + if (!empty($wpinv_options['vat_vies_check'])) { |
|
684 | + if (empty($wpinv_options['vat_offline_check'])) { |
|
685 | + $valid = self::offline_check($input['vat_number']); |
|
686 | 686 | } else { |
687 | 687 | $valid = true; |
688 | 688 | } |
689 | 689 | |
690 | - $message = $valid ? '' : __( 'VAT number not validated', 'invoicing' ); |
|
690 | + $message = $valid ? '' : __('VAT number not validated', 'invoicing'); |
|
691 | 691 | } else { |
692 | - $result = self::check_vat( $input['vat_number'] ); |
|
692 | + $result = self::check_vat($input['vat_number']); |
|
693 | 693 | |
694 | - if ( empty( $result['valid'] ) ) { |
|
694 | + if (empty($result['valid'])) { |
|
695 | 695 | $valid = false; |
696 | 696 | $message = $result['message']; |
697 | 697 | } else { |
698 | - $valid = ( isset( $result['company'] ) && ( $result['company'] == '---' || ( strcasecmp( trim( $result['company'] ), trim( $input['vat_company_name'] ) ) == 0 ) ) ) || !empty( $wpinv_options['vat_disable_company_name_check'] ); |
|
699 | - $message = $valid ? '' : __( 'The company name associated with the VAT number provided is not the same as the company name provided.', 'invoicing' ); |
|
698 | + $valid = (isset($result['company']) && ($result['company'] == '---' || (strcasecmp(trim($result['company']), trim($input['vat_company_name'])) == 0))) || !empty($wpinv_options['vat_disable_company_name_check']); |
|
699 | + $message = $valid ? '' : __('The company name associated with the VAT number provided is not the same as the company name provided.', 'invoicing'); |
|
700 | 700 | } |
701 | 701 | } |
702 | 702 | |
703 | - if ( $message && self::is_vat_validated() != $valid ) { |
|
704 | - add_settings_error( 'wpinv-notices', '', $message, ( $valid ? 'updated' : 'error' ) ); |
|
703 | + if ($message && self::is_vat_validated() != $valid) { |
|
704 | + add_settings_error('wpinv-notices', '', $message, ($valid ? 'updated' : 'error')); |
|
705 | 705 | } |
706 | 706 | |
707 | 707 | $input['vat_valid'] = $valid; |
708 | 708 | return $input; |
709 | 709 | } |
710 | 710 | |
711 | - public static function sanitize_vat_rates( $input ) { |
|
712 | - if( !current_user_can( 'manage_options' ) ) { |
|
713 | - add_settings_error( 'wpinv-notices', '', __( 'Your account does not have permission to add rate classes.', 'invoicing' ), 'error' ); |
|
711 | + public static function sanitize_vat_rates($input) { |
|
712 | + if (!current_user_can('manage_options')) { |
|
713 | + add_settings_error('wpinv-notices', '', __('Your account does not have permission to add rate classes.', 'invoicing'), 'error'); |
|
714 | 714 | return $input; |
715 | 715 | } |
716 | 716 | |
717 | 717 | $vat_classes = self::get_rate_classes(); |
718 | - $vat_class = !empty( $_REQUEST['wpi_vat_class'] ) && isset( $vat_classes[$_REQUEST['wpi_vat_class']] )? sanitize_text_field( $_REQUEST['wpi_vat_class'] ) : ''; |
|
718 | + $vat_class = !empty($_REQUEST['wpi_vat_class']) && isset($vat_classes[$_REQUEST['wpi_vat_class']]) ? sanitize_text_field($_REQUEST['wpi_vat_class']) : ''; |
|
719 | 719 | |
720 | - if ( empty( $vat_class ) ) { |
|
721 | - add_settings_error( 'wpinv-notices', '', __( 'No valid VAT rates class contained in the request to save rates.', 'invoicing' ), 'error' ); |
|
720 | + if (empty($vat_class)) { |
|
721 | + add_settings_error('wpinv-notices', '', __('No valid VAT rates class contained in the request to save rates.', 'invoicing'), 'error'); |
|
722 | 722 | |
723 | 723 | return $input; |
724 | 724 | } |
725 | 725 | |
726 | - $new_rates = ! empty( $_POST['vat_rates'] ) ? array_values( $_POST['vat_rates'] ) : array(); |
|
726 | + $new_rates = !empty($_POST['vat_rates']) ? array_values($_POST['vat_rates']) : array(); |
|
727 | 727 | |
728 | - if ( $vat_class === '_standard' ) { |
|
728 | + if ($vat_class === '_standard') { |
|
729 | 729 | // Save the active rates in the invoice settings |
730 | - update_option( 'wpinv_tax_rates', $new_rates ); |
|
730 | + update_option('wpinv_tax_rates', $new_rates); |
|
731 | 731 | } else { |
732 | 732 | // Get the existing set of rates |
733 | 733 | $rates = self::get_non_standard_rates(); |
734 | 734 | $rates[$vat_class] = $new_rates; |
735 | 735 | |
736 | - update_option( 'wpinv_vat_rates', $rates ); |
|
736 | + update_option('wpinv_vat_rates', $rates); |
|
737 | 737 | } |
738 | 738 | |
739 | 739 | return $input; |
@@ -743,71 +743,71 @@ discard block |
||
743 | 743 | $response = array(); |
744 | 744 | $response['success'] = false; |
745 | 745 | |
746 | - if ( !current_user_can( 'manage_options' ) ) { |
|
747 | - $response['error'] = __( 'Invalid access!', 'invoicing' ); |
|
748 | - wp_send_json( $response ); |
|
746 | + if (!current_user_can('manage_options')) { |
|
747 | + $response['error'] = __('Invalid access!', 'invoicing'); |
|
748 | + wp_send_json($response); |
|
749 | 749 | } |
750 | 750 | |
751 | - $vat_class_name = !empty( $_POST['name'] ) ? sanitize_text_field( $_POST['name'] ) : false; |
|
752 | - $vat_class_desc = !empty( $_POST['desc'] ) ? sanitize_text_field( $_POST['desc'] ) : false; |
|
751 | + $vat_class_name = !empty($_POST['name']) ? sanitize_text_field($_POST['name']) : false; |
|
752 | + $vat_class_desc = !empty($_POST['desc']) ? sanitize_text_field($_POST['desc']) : false; |
|
753 | 753 | |
754 | - if ( empty( $vat_class_name ) ) { |
|
755 | - $response['error'] = __( 'Select the VAT rate name', 'invoicing' ); |
|
756 | - wp_send_json( $response ); |
|
754 | + if (empty($vat_class_name)) { |
|
755 | + $response['error'] = __('Select the VAT rate name', 'invoicing'); |
|
756 | + wp_send_json($response); |
|
757 | 757 | } |
758 | 758 | |
759 | 759 | $vat_classes = (array)self::get_rate_classes(); |
760 | 760 | |
761 | - if ( !empty( $vat_classes ) && in_array( strtolower( $vat_class_name ), array_map( 'strtolower', array_values( $vat_classes ) ) ) ) { |
|
762 | - $response['error'] = wp_sprintf( __( 'A VAT Rate name "%s" already exists', 'invoicing' ), $vat_class_name ); |
|
763 | - wp_send_json( $response ); |
|
761 | + if (!empty($vat_classes) && in_array(strtolower($vat_class_name), array_map('strtolower', array_values($vat_classes)))) { |
|
762 | + $response['error'] = wp_sprintf(__('A VAT Rate name "%s" already exists', 'invoicing'), $vat_class_name); |
|
763 | + wp_send_json($response); |
|
764 | 764 | } |
765 | 765 | |
766 | - $rate_class_key = normalize_whitespace( 'wpi-' . $vat_class_name ); |
|
767 | - $rate_class_key = sanitize_key( str_replace( " ", "-", $rate_class_key ) ); |
|
766 | + $rate_class_key = normalize_whitespace('wpi-' . $vat_class_name); |
|
767 | + $rate_class_key = sanitize_key(str_replace(" ", "-", $rate_class_key)); |
|
768 | 768 | |
769 | - $vat_classes = (array)self::get_rate_classes( true ); |
|
770 | - $vat_classes[$rate_class_key] = array( 'name' => $vat_class_name, 'desc' => $vat_class_desc ); |
|
769 | + $vat_classes = (array)self::get_rate_classes(true); |
|
770 | + $vat_classes[$rate_class_key] = array('name' => $vat_class_name, 'desc' => $vat_class_desc); |
|
771 | 771 | |
772 | - update_option( '_wpinv_vat_rate_classes', $vat_classes ); |
|
772 | + update_option('_wpinv_vat_rate_classes', $vat_classes); |
|
773 | 773 | |
774 | 774 | $response['success'] = true; |
775 | - $response['redirect'] = admin_url( 'admin.php?page=wpinv-settings&tab=taxes§ion=vat_rates&wpi_sub=' . $rate_class_key ); |
|
775 | + $response['redirect'] = admin_url('admin.php?page=wpinv-settings&tab=taxes§ion=vat_rates&wpi_sub=' . $rate_class_key); |
|
776 | 776 | |
777 | - wp_send_json( $response ); |
|
777 | + wp_send_json($response); |
|
778 | 778 | } |
779 | 779 | |
780 | 780 | public static function delete_class() { |
781 | 781 | $response = array(); |
782 | 782 | $response['success'] = false; |
783 | 783 | |
784 | - if ( !current_user_can( 'manage_options' ) || !isset( $_POST['class'] ) ) { |
|
785 | - $response['error'] = __( 'Invalid access!', 'invoicing' ); |
|
786 | - wp_send_json( $response ); |
|
784 | + if (!current_user_can('manage_options') || !isset($_POST['class'])) { |
|
785 | + $response['error'] = __('Invalid access!', 'invoicing'); |
|
786 | + wp_send_json($response); |
|
787 | 787 | } |
788 | 788 | |
789 | - $vat_class = isset( $_POST['class'] ) && $_POST['class'] !== '' ? sanitize_text_field( $_POST['class'] ) : false; |
|
789 | + $vat_class = isset($_POST['class']) && $_POST['class'] !== '' ? sanitize_text_field($_POST['class']) : false; |
|
790 | 790 | $vat_classes = (array)self::get_rate_classes(); |
791 | 791 | |
792 | - if ( !isset( $vat_classes[$vat_class] ) ) { |
|
793 | - $response['error'] = __( 'Requested class does not exists', 'invoicing' ); |
|
794 | - wp_send_json( $response ); |
|
792 | + if (!isset($vat_classes[$vat_class])) { |
|
793 | + $response['error'] = __('Requested class does not exists', 'invoicing'); |
|
794 | + wp_send_json($response); |
|
795 | 795 | } |
796 | 796 | |
797 | - if ( $vat_class == '_new' || $vat_class == '_standard' ) { |
|
798 | - $response['error'] = __( 'You can not delete standard rates class', 'invoicing' ); |
|
799 | - wp_send_json( $response ); |
|
797 | + if ($vat_class == '_new' || $vat_class == '_standard') { |
|
798 | + $response['error'] = __('You can not delete standard rates class', 'invoicing'); |
|
799 | + wp_send_json($response); |
|
800 | 800 | } |
801 | 801 | |
802 | - $vat_classes = (array)self::get_rate_classes( true ); |
|
803 | - unset( $vat_classes[$vat_class] ); |
|
802 | + $vat_classes = (array)self::get_rate_classes(true); |
|
803 | + unset($vat_classes[$vat_class]); |
|
804 | 804 | |
805 | - update_option( '_wpinv_vat_rate_classes', $vat_classes ); |
|
805 | + update_option('_wpinv_vat_rate_classes', $vat_classes); |
|
806 | 806 | |
807 | 807 | $response['success'] = true; |
808 | - $response['redirect'] = admin_url( 'admin.php?page=wpinv-settings&tab=taxes§ion=vat_rates&wpi_sub=_new' ); |
|
808 | + $response['redirect'] = admin_url('admin.php?page=wpinv-settings&tab=taxes§ion=vat_rates&wpi_sub=_new'); |
|
809 | 809 | |
810 | - wp_send_json( $response ); |
|
810 | + wp_send_json($response); |
|
811 | 811 | } |
812 | 812 | |
813 | 813 | public static function update_eu_rates() { |
@@ -816,72 +816,72 @@ discard block |
||
816 | 816 | $response['error'] = null; |
817 | 817 | $response['data'] = null; |
818 | 818 | |
819 | - if ( !current_user_can( 'manage_options' ) ) { |
|
820 | - $response['error'] = __( 'Invalid access!', 'invoicing' ); |
|
821 | - wp_send_json( $response ); |
|
819 | + if (!current_user_can('manage_options')) { |
|
820 | + $response['error'] = __('Invalid access!', 'invoicing'); |
|
821 | + wp_send_json($response); |
|
822 | 822 | } |
823 | 823 | |
824 | - $group = !empty( $_POST['group'] ) ? sanitize_text_field( $_POST['group'] ) : ''; |
|
825 | - $euvatrates = self::request_euvatrates( $group ); |
|
824 | + $group = !empty($_POST['group']) ? sanitize_text_field($_POST['group']) : ''; |
|
825 | + $euvatrates = self::request_euvatrates($group); |
|
826 | 826 | |
827 | - if ( !empty( $euvatrates ) ) { |
|
828 | - if ( !empty( $euvatrates['success'] ) && !empty( $euvatrates['rates'] ) ) { |
|
827 | + if (!empty($euvatrates)) { |
|
828 | + if (!empty($euvatrates['success']) && !empty($euvatrates['rates'])) { |
|
829 | 829 | $response['success'] = true; |
830 | 830 | $response['data']['rates'] = $euvatrates['rates']; |
831 | - } else if ( !empty( $euvatrates['error'] ) ) { |
|
831 | + } else if (!empty($euvatrates['error'])) { |
|
832 | 832 | $response['error'] = $euvatrates['error']; |
833 | 833 | } |
834 | 834 | } |
835 | 835 | |
836 | - wp_send_json( $response ); |
|
836 | + wp_send_json($response); |
|
837 | 837 | } |
838 | 838 | |
839 | 839 | public static function hide_vat_fields() { |
840 | - $hide = wpinv_get_option( 'vat_disable_fields' ); |
|
840 | + $hide = wpinv_get_option('vat_disable_fields'); |
|
841 | 841 | |
842 | - return apply_filters( 'wpinv_hide_vat_fields', $hide ); |
|
842 | + return apply_filters('wpinv_hide_vat_fields', $hide); |
|
843 | 843 | } |
844 | 844 | |
845 | 845 | public static function same_country_rule() { |
846 | - $same_country_rule = wpinv_get_option( 'vat_same_country_rule' ); |
|
846 | + $same_country_rule = wpinv_get_option('vat_same_country_rule'); |
|
847 | 847 | |
848 | - return apply_filters( 'wpinv_vat_same_country_rule', $same_country_rule ); |
|
848 | + return apply_filters('wpinv_vat_same_country_rule', $same_country_rule); |
|
849 | 849 | } |
850 | 850 | |
851 | 851 | public static function get_vat_name() { |
852 | - $vat_name = wpinv_get_option( 'vat_name' ); |
|
853 | - $vat_name = !empty( $vat_name ) ? $vat_name : 'VAT'; |
|
852 | + $vat_name = wpinv_get_option('vat_name'); |
|
853 | + $vat_name = !empty($vat_name) ? $vat_name : 'VAT'; |
|
854 | 854 | |
855 | - return apply_filters( 'wpinv_get_owner_vat_name', $vat_name ); |
|
855 | + return apply_filters('wpinv_get_owner_vat_name', $vat_name); |
|
856 | 856 | } |
857 | 857 | |
858 | 858 | public static function get_company_name() { |
859 | - $company_name = wpinv_get_option( 'vat_company_name' ); |
|
859 | + $company_name = wpinv_get_option('vat_company_name'); |
|
860 | 860 | |
861 | - return apply_filters( 'wpinv_get_owner_company_name', $company_name ); |
|
861 | + return apply_filters('wpinv_get_owner_company_name', $company_name); |
|
862 | 862 | } |
863 | 863 | |
864 | 864 | public static function get_vat_number() { |
865 | - $vat_number = wpinv_get_option( 'vat_number' ); |
|
865 | + $vat_number = wpinv_get_option('vat_number'); |
|
866 | 866 | |
867 | - return apply_filters( 'wpinv_get_owner_vat_number', $vat_number ); |
|
867 | + return apply_filters('wpinv_get_owner_vat_number', $vat_number); |
|
868 | 868 | } |
869 | 869 | |
870 | 870 | public static function is_vat_validated() { |
871 | - $validated = self::get_vat_number() && wpinv_get_option( 'vat_valid' ); |
|
871 | + $validated = self::get_vat_number() && wpinv_get_option('vat_valid'); |
|
872 | 872 | |
873 | - return apply_filters( 'wpinv_is_owner_vat_validated', $validated ); |
|
873 | + return apply_filters('wpinv_is_owner_vat_validated', $validated); |
|
874 | 874 | } |
875 | 875 | |
876 | - public static function sanitize_vat( $vat_number, $country_code = '' ) { |
|
877 | - $vat_number = str_replace( array(' ', '.', '-', '_', ',' ), '', strtoupper( trim( $vat_number ) ) ); |
|
876 | + public static function sanitize_vat($vat_number, $country_code = '') { |
|
877 | + $vat_number = str_replace(array(' ', '.', '-', '_', ','), '', strtoupper(trim($vat_number))); |
|
878 | 878 | |
879 | - if ( empty( $country_code ) ) { |
|
880 | - $country_code = substr( $vat_number, 0, 2 ); |
|
879 | + if (empty($country_code)) { |
|
880 | + $country_code = substr($vat_number, 0, 2); |
|
881 | 881 | } |
882 | 882 | |
883 | - if ( strpos( $vat_number , $country_code ) === 0 ) { |
|
884 | - $vat = str_replace( $country_code, '', $vat_number ); |
|
883 | + if (strpos($vat_number, $country_code) === 0) { |
|
884 | + $vat = str_replace($country_code, '', $vat_number); |
|
885 | 885 | } else { |
886 | 886 | $vat = $country_code . $vat_number; |
887 | 887 | } |
@@ -894,140 +894,140 @@ discard block |
||
894 | 894 | return $return; |
895 | 895 | } |
896 | 896 | |
897 | - public static function offline_check( $vat_number, $country_code = '', $formatted = false ) { |
|
898 | - $vat = self::sanitize_vat( $vat_number, $country_code ); |
|
897 | + public static function offline_check($vat_number, $country_code = '', $formatted = false) { |
|
898 | + $vat = self::sanitize_vat($vat_number, $country_code); |
|
899 | 899 | $vat_number = $vat['vat_number']; |
900 | 900 | $country_code = $vat['iso']; |
901 | 901 | $regex = array(); |
902 | 902 | |
903 | - switch ( $country_code ) { |
|
903 | + switch ($country_code) { |
|
904 | 904 | case 'AT': |
905 | - $regex[] = '/^(AT)U(\d{8})$/'; // Austria |
|
905 | + $regex[] = '/^(AT)U(\d{8})$/'; // Austria |
|
906 | 906 | break; |
907 | 907 | case 'BE': |
908 | - $regex[] = '/^(BE)(0?\d{9})$/'; // Belgium |
|
908 | + $regex[] = '/^(BE)(0?\d{9})$/'; // Belgium |
|
909 | 909 | break; |
910 | 910 | case 'BG': |
911 | - $regex[] = '/^(BG)(\d{9,10})$/'; // Bulgaria |
|
911 | + $regex[] = '/^(BG)(\d{9,10})$/'; // Bulgaria |
|
912 | 912 | break; |
913 | 913 | case 'CH': |
914 | 914 | case 'CHE': |
915 | - $regex[] = '/^(CHE)(\d{9})MWST$/'; // Switzerland (Not EU) |
|
915 | + $regex[] = '/^(CHE)(\d{9})MWST$/'; // Switzerland (Not EU) |
|
916 | 916 | break; |
917 | 917 | case 'CY': |
918 | - $regex[] = '/^(CY)([0-5|9]\d{7}[A-Z])$/'; // Cyprus |
|
918 | + $regex[] = '/^(CY)([0-5|9]\d{7}[A-Z])$/'; // Cyprus |
|
919 | 919 | break; |
920 | 920 | case 'CZ': |
921 | - $regex[] = '/^(CZ)(\d{8,13})$/'; // Czech Republic |
|
921 | + $regex[] = '/^(CZ)(\d{8,13})$/'; // Czech Republic |
|
922 | 922 | break; |
923 | 923 | case 'DE': |
924 | - $regex[] = '/^(DE)([1-9]\d{8})$/'; // Germany |
|
924 | + $regex[] = '/^(DE)([1-9]\d{8})$/'; // Germany |
|
925 | 925 | break; |
926 | 926 | case 'DK': |
927 | - $regex[] = '/^(DK)(\d{8})$/'; // Denmark |
|
927 | + $regex[] = '/^(DK)(\d{8})$/'; // Denmark |
|
928 | 928 | break; |
929 | 929 | case 'EE': |
930 | - $regex[] = '/^(EE)(10\d{7})$/'; // Estonia |
|
930 | + $regex[] = '/^(EE)(10\d{7})$/'; // Estonia |
|
931 | 931 | break; |
932 | 932 | case 'EL': |
933 | - $regex[] = '/^(EL)(\d{9})$/'; // Greece |
|
933 | + $regex[] = '/^(EL)(\d{9})$/'; // Greece |
|
934 | 934 | break; |
935 | 935 | case 'ES': |
936 | - $regex[] = '/^(ES)([A-Z]\d{8})$/'; // Spain (National juridical entities) |
|
937 | - $regex[] = '/^(ES)([A-H|N-S|W]\d{7}[A-J])$/'; // Spain (Other juridical entities) |
|
938 | - $regex[] = '/^(ES)([0-9|Y|Z]\d{7}[A-Z])$/'; // Spain (Personal entities type 1) |
|
939 | - $regex[] = '/^(ES)([K|L|M|X]\d{7}[A-Z])$/'; // Spain (Personal entities type 2) |
|
936 | + $regex[] = '/^(ES)([A-Z]\d{8})$/'; // Spain (National juridical entities) |
|
937 | + $regex[] = '/^(ES)([A-H|N-S|W]\d{7}[A-J])$/'; // Spain (Other juridical entities) |
|
938 | + $regex[] = '/^(ES)([0-9|Y|Z]\d{7}[A-Z])$/'; // Spain (Personal entities type 1) |
|
939 | + $regex[] = '/^(ES)([K|L|M|X]\d{7}[A-Z])$/'; // Spain (Personal entities type 2) |
|
940 | 940 | break; |
941 | 941 | case 'EU': |
942 | - $regex[] = '/^(EU)(\d{9})$/'; // EU-type |
|
942 | + $regex[] = '/^(EU)(\d{9})$/'; // EU-type |
|
943 | 943 | break; |
944 | 944 | case 'FI': |
945 | - $regex[] = '/^(FI)(\d{8})$/'; // Finland |
|
945 | + $regex[] = '/^(FI)(\d{8})$/'; // Finland |
|
946 | 946 | break; |
947 | 947 | case 'FR': |
948 | - $regex[] = '/^(FR)(\d{11})$/'; // France (1) |
|
949 | - $regex[] = '/^(FR)[(A-H)|(J-N)|(P-Z)](\d{10})$/'; // France (2) |
|
950 | - $regex[] = '/^(FR)\d[(A-H)|(J-N)|(P-Z)](\d{9})$/'; // France (3) |
|
951 | - $regex[] = '/^(FR)[(A-H)|(J-N)|(P-Z)]{2}(\d{9})$/'; // France (4) |
|
948 | + $regex[] = '/^(FR)(\d{11})$/'; // France (1) |
|
949 | + $regex[] = '/^(FR)[(A-H)|(J-N)|(P-Z)](\d{10})$/'; // France (2) |
|
950 | + $regex[] = '/^(FR)\d[(A-H)|(J-N)|(P-Z)](\d{9})$/'; // France (3) |
|
951 | + $regex[] = '/^(FR)[(A-H)|(J-N)|(P-Z)]{2}(\d{9})$/'; // France (4) |
|
952 | 952 | break; |
953 | 953 | case 'GB': |
954 | - $regex[] = '/^(GB)?(\d{9})$/'; // UK (Standard) |
|
955 | - $regex[] = '/^(GB)?(\d{12})$/'; // UK (Branches) |
|
956 | - $regex[] = '/^(GB)?(GD\d{3})$/'; // UK (Government) |
|
957 | - $regex[] = '/^(GB)?(HA\d{3})$/'; // UK (Health authority) |
|
954 | + $regex[] = '/^(GB)?(\d{9})$/'; // UK (Standard) |
|
955 | + $regex[] = '/^(GB)?(\d{12})$/'; // UK (Branches) |
|
956 | + $regex[] = '/^(GB)?(GD\d{3})$/'; // UK (Government) |
|
957 | + $regex[] = '/^(GB)?(HA\d{3})$/'; // UK (Health authority) |
|
958 | 958 | break; |
959 | 959 | case 'GR': |
960 | - $regex[] = '/^(GR)(\d{8,9})$/'; // Greece |
|
960 | + $regex[] = '/^(GR)(\d{8,9})$/'; // Greece |
|
961 | 961 | break; |
962 | 962 | case 'HR': |
963 | - $regex[] = '/^(HR)(\d{11})$/'; // Croatia |
|
963 | + $regex[] = '/^(HR)(\d{11})$/'; // Croatia |
|
964 | 964 | break; |
965 | 965 | case 'HU': |
966 | - $regex[] = '/^(HU)(\d{8})$/'; // Hungary |
|
966 | + $regex[] = '/^(HU)(\d{8})$/'; // Hungary |
|
967 | 967 | break; |
968 | 968 | case 'IE': |
969 | - $regex[] = '/^(IE)(\d{7}[A-W])$/'; // Ireland (1) |
|
970 | - $regex[] = '/^(IE)([7-9][A-Z\*\+)]\d{5}[A-W])$/'; // Ireland (2) |
|
971 | - $regex[] = '/^(IE)(\d{7}[A-Z][AH])$/'; // Ireland (3) (new format from 1 Jan 2013) |
|
969 | + $regex[] = '/^(IE)(\d{7}[A-W])$/'; // Ireland (1) |
|
970 | + $regex[] = '/^(IE)([7-9][A-Z\*\+)]\d{5}[A-W])$/'; // Ireland (2) |
|
971 | + $regex[] = '/^(IE)(\d{7}[A-Z][AH])$/'; // Ireland (3) (new format from 1 Jan 2013) |
|
972 | 972 | break; |
973 | 973 | case 'IT': |
974 | - $regex[] = '/^(IT)(\d{11})$/'; // Italy |
|
974 | + $regex[] = '/^(IT)(\d{11})$/'; // Italy |
|
975 | 975 | break; |
976 | 976 | case 'LV': |
977 | - $regex[] = '/^(LV)(\d{11})$/'; // Latvia |
|
977 | + $regex[] = '/^(LV)(\d{11})$/'; // Latvia |
|
978 | 978 | break; |
979 | 979 | case 'LT': |
980 | - $regex[] = '/^(LT)(\d{9}|\d{12})$/'; // Lithuania |
|
980 | + $regex[] = '/^(LT)(\d{9}|\d{12})$/'; // Lithuania |
|
981 | 981 | break; |
982 | 982 | case 'LU': |
983 | - $regex[] = '/^(LU)(\d{8})$/'; // Luxembourg |
|
983 | + $regex[] = '/^(LU)(\d{8})$/'; // Luxembourg |
|
984 | 984 | break; |
985 | 985 | case 'MT': |
986 | - $regex[] = '/^(MT)([1-9]\d{7})$/'; // Malta |
|
986 | + $regex[] = '/^(MT)([1-9]\d{7})$/'; // Malta |
|
987 | 987 | break; |
988 | 988 | case 'NL': |
989 | - $regex[] = '/^(NL)(\d{9})B\d{2}$/'; // Netherlands |
|
989 | + $regex[] = '/^(NL)(\d{9})B\d{2}$/'; // Netherlands |
|
990 | 990 | break; |
991 | 991 | case 'NO': |
992 | - $regex[] = '/^(NO)(\d{9})$/'; // Norway (Not EU) |
|
992 | + $regex[] = '/^(NO)(\d{9})$/'; // Norway (Not EU) |
|
993 | 993 | break; |
994 | 994 | case 'PL': |
995 | - $regex[] = '/^(PL)(\d{10})$/'; // Poland |
|
995 | + $regex[] = '/^(PL)(\d{10})$/'; // Poland |
|
996 | 996 | break; |
997 | 997 | case 'PT': |
998 | - $regex[] = '/^(PT)(\d{9})$/'; // Portugal |
|
998 | + $regex[] = '/^(PT)(\d{9})$/'; // Portugal |
|
999 | 999 | break; |
1000 | 1000 | case 'RO': |
1001 | - $regex[] = '/^(RO)([1-9]\d{1,9})$/'; // Romania |
|
1001 | + $regex[] = '/^(RO)([1-9]\d{1,9})$/'; // Romania |
|
1002 | 1002 | break; |
1003 | 1003 | case 'RS': |
1004 | - $regex[] = '/^(RS)(\d{9})$/'; // Serbia (Not EU) |
|
1004 | + $regex[] = '/^(RS)(\d{9})$/'; // Serbia (Not EU) |
|
1005 | 1005 | break; |
1006 | 1006 | case 'SI': |
1007 | - $regex[] = '/^(SI)([1-9]\d{7})$/'; // Slovenia |
|
1007 | + $regex[] = '/^(SI)([1-9]\d{7})$/'; // Slovenia |
|
1008 | 1008 | break; |
1009 | 1009 | case 'SK': |
1010 | - $regex[] = '/^(SK)([1-9]\d[(2-4)|(6-9)]\d{7})$/'; // Slovakia Republic |
|
1010 | + $regex[] = '/^(SK)([1-9]\d[(2-4)|(6-9)]\d{7})$/'; // Slovakia Republic |
|
1011 | 1011 | break; |
1012 | 1012 | case 'SE': |
1013 | - $regex[] = '/^(SE)(\d{10}01)$/'; // Sweden |
|
1013 | + $regex[] = '/^(SE)(\d{10}01)$/'; // Sweden |
|
1014 | 1014 | break; |
1015 | 1015 | default: |
1016 | 1016 | $regex = array(); |
1017 | 1017 | break; |
1018 | 1018 | } |
1019 | 1019 | |
1020 | - if ( empty( $regex ) ) { |
|
1020 | + if (empty($regex)) { |
|
1021 | 1021 | return false; |
1022 | 1022 | } |
1023 | 1023 | |
1024 | - foreach ( $regex as $pattern ) { |
|
1024 | + foreach ($regex as $pattern) { |
|
1025 | 1025 | $matches = null; |
1026 | - preg_match_all( $pattern, $vat_number, $matches ); |
|
1026 | + preg_match_all($pattern, $vat_number, $matches); |
|
1027 | 1027 | |
1028 | - if ( !empty( $matches[1][0] ) && !empty( $matches[2][0] ) ) { |
|
1029 | - if ( $formatted ) { |
|
1030 | - return array( 'code' => $matches[1][0], 'number' => $matches[2][0] ); |
|
1028 | + if (!empty($matches[1][0]) && !empty($matches[2][0])) { |
|
1029 | + if ($formatted) { |
|
1030 | + return array('code' => $matches[1][0], 'number' => $matches[2][0]); |
|
1031 | 1031 | } else { |
1032 | 1032 | return true; |
1033 | 1033 | } |
@@ -1037,75 +1037,75 @@ discard block |
||
1037 | 1037 | return false; |
1038 | 1038 | } |
1039 | 1039 | |
1040 | - public static function vies_check( $vat_number, $country_code = '', $result = false ) { |
|
1041 | - $vat = self::sanitize_vat( $vat_number, $country_code ); |
|
1040 | + public static function vies_check($vat_number, $country_code = '', $result = false) { |
|
1041 | + $vat = self::sanitize_vat($vat_number, $country_code); |
|
1042 | 1042 | $vat_number = $vat['vat']; |
1043 | 1043 | $iso = $vat['iso']; |
1044 | 1044 | |
1045 | - $url = 'http://ec.europa.eu/taxation_customs/vies/viesquer.do?ms=' . urlencode( $iso ) . '&iso=' . urlencode( $iso ) . '&vat=' . urlencode( $vat_number ); |
|
1045 | + $url = 'http://ec.europa.eu/taxation_customs/vies/viesquer.do?ms=' . urlencode($iso) . '&iso=' . urlencode($iso) . '&vat=' . urlencode($vat_number); |
|
1046 | 1046 | |
1047 | - if ( ini_get( 'allow_url_fopen' ) ) { |
|
1048 | - $response = file_get_contents( $url ); |
|
1049 | - } else if ( function_exists( 'curl_init' ) ) { |
|
1047 | + if (ini_get('allow_url_fopen')) { |
|
1048 | + $response = file_get_contents($url); |
|
1049 | + } else if (function_exists('curl_init')) { |
|
1050 | 1050 | $ch = curl_init(); |
1051 | 1051 | |
1052 | - curl_setopt( $ch, CURLOPT_URL, $url ); |
|
1053 | - curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT, 30 ); |
|
1054 | - curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true ); |
|
1055 | - curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, 0 ); |
|
1056 | - curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, 0 ); |
|
1052 | + curl_setopt($ch, CURLOPT_URL, $url); |
|
1053 | + curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30); |
|
1054 | + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
|
1055 | + curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); |
|
1056 | + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); |
|
1057 | 1057 | |
1058 | - $response = curl_exec( $ch ); |
|
1058 | + $response = curl_exec($ch); |
|
1059 | 1059 | |
1060 | - if ( curl_errno( $ch ) ) { |
|
1061 | - wpinv_error_log( curl_error( $ch ), 'VIES CHECK ERROR' ); |
|
1060 | + if (curl_errno($ch)) { |
|
1061 | + wpinv_error_log(curl_error($ch), 'VIES CHECK ERROR'); |
|
1062 | 1062 | $response = ''; |
1063 | 1063 | } |
1064 | 1064 | |
1065 | - curl_close( $ch ); |
|
1065 | + curl_close($ch); |
|
1066 | 1066 | } else { |
1067 | - 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' ); |
|
1067 | + 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 | 1068 | } |
1069 | 1069 | |
1070 | - if ( empty( $response ) ) { |
|
1070 | + if (empty($response)) { |
|
1071 | 1071 | return $result; |
1072 | 1072 | } |
1073 | 1073 | |
1074 | - if ( preg_match( '/invalid VAT number/i', $response ) ) { |
|
1074 | + if (preg_match('/invalid VAT number/i', $response)) { |
|
1075 | 1075 | return false; |
1076 | - } else if ( preg_match( '/valid VAT number/i', $response, $matches ) ) { |
|
1077 | - $content = explode( "valid VAT number", htmlentities( $response ) ); |
|
1076 | + } else if (preg_match('/valid VAT number/i', $response, $matches)) { |
|
1077 | + $content = explode("valid VAT number", htmlentities($response)); |
|
1078 | 1078 | |
1079 | - if ( !empty( $content[1] ) ) { |
|
1080 | - preg_match_all( '/<tr>(.*?)<td.*?>(.*?)<\/td>(.*?)<\/tr>/si', html_entity_decode( $content[1] ), $matches ); |
|
1079 | + if (!empty($content[1])) { |
|
1080 | + preg_match_all('/<tr>(.*?)<td.*?>(.*?)<\/td>(.*?)<\/tr>/si', html_entity_decode($content[1]), $matches); |
|
1081 | 1081 | |
1082 | - if ( !empty( $matches[2] ) && $matches[3] ) { |
|
1082 | + if (!empty($matches[2]) && $matches[3]) { |
|
1083 | 1083 | $return = array(); |
1084 | 1084 | |
1085 | - foreach ( $matches[2] as $key => $label ) { |
|
1086 | - $label = trim( $label ); |
|
1085 | + foreach ($matches[2] as $key => $label) { |
|
1086 | + $label = trim($label); |
|
1087 | 1087 | |
1088 | - switch ( strtolower( $label ) ) { |
|
1088 | + switch (strtolower($label)) { |
|
1089 | 1089 | case 'member state': |
1090 | - $return['state'] = trim( strip_tags( $matches[3][$key] ) ); |
|
1090 | + $return['state'] = trim(strip_tags($matches[3][$key])); |
|
1091 | 1091 | break; |
1092 | 1092 | case 'vat number': |
1093 | - $return['number'] = trim( strip_tags( $matches[3][$key] ) ); |
|
1093 | + $return['number'] = trim(strip_tags($matches[3][$key])); |
|
1094 | 1094 | break; |
1095 | 1095 | case 'name': |
1096 | - $return['company'] = trim( strip_tags( $matches[3][$key] ) ); |
|
1096 | + $return['company'] = trim(strip_tags($matches[3][$key])); |
|
1097 | 1097 | break; |
1098 | 1098 | case 'address': |
1099 | - $address = str_replace( array( "<br><br>", "<br /><br />", "<br/><br/>" ), "<br>", html_entity_decode( trim( $matches[3][$key] ) ) ); |
|
1100 | - $return['address'] = trim( strip_tags( $address, '<br>' ) ); |
|
1099 | + $address = str_replace(array("<br><br>", "<br /><br />", "<br/><br/>"), "<br>", html_entity_decode(trim($matches[3][$key]))); |
|
1100 | + $return['address'] = trim(strip_tags($address, '<br>')); |
|
1101 | 1101 | break; |
1102 | 1102 | case 'consultation number': |
1103 | - $return['consultation'] = trim( strip_tags( $matches[3][$key] ) ); |
|
1103 | + $return['consultation'] = trim(strip_tags($matches[3][$key])); |
|
1104 | 1104 | break; |
1105 | 1105 | } |
1106 | 1106 | } |
1107 | 1107 | |
1108 | - if ( !empty( $return ) ) { |
|
1108 | + if (!empty($return)) { |
|
1109 | 1109 | return $return; |
1110 | 1110 | } |
1111 | 1111 | } |
@@ -1117,55 +1117,55 @@ discard block |
||
1117 | 1117 | } |
1118 | 1118 | } |
1119 | 1119 | |
1120 | - public static function check_vat( $vat_number, $country_code = '' ) { |
|
1120 | + public static function check_vat($vat_number, $country_code = '') { |
|
1121 | 1121 | $vat_name = self::get_vat_name(); |
1122 | 1122 | |
1123 | 1123 | $return = array(); |
1124 | 1124 | $return['valid'] = false; |
1125 | - $return['message'] = wp_sprintf( __( '%s number not validated', 'invoicing' ), $vat_name ); |
|
1125 | + $return['message'] = wp_sprintf(__('%s number not validated', 'invoicing'), $vat_name); |
|
1126 | 1126 | |
1127 | - if ( !wpinv_get_option( 'vat_offline_check' ) && !self::offline_check( $vat_number, $country_code ) ) { |
|
1127 | + if (!wpinv_get_option('vat_offline_check') && !self::offline_check($vat_number, $country_code)) { |
|
1128 | 1128 | return $return; |
1129 | 1129 | } |
1130 | 1130 | |
1131 | - $response = self::vies_check( $vat_number, $country_code ); |
|
1131 | + $response = self::vies_check($vat_number, $country_code); |
|
1132 | 1132 | |
1133 | - if ( $response ) { |
|
1134 | - $return['valid'] = true; |
|
1133 | + if ($response) { |
|
1134 | + $return['valid'] = true; |
|
1135 | 1135 | |
1136 | - if ( is_array( $response ) ) { |
|
1137 | - $return['company'] = isset( $response['company'] ) ? $response['company'] : ''; |
|
1138 | - $return['address'] = isset( $response['address'] ) ? $response['address'] : ''; |
|
1136 | + if (is_array($response)) { |
|
1137 | + $return['company'] = isset($response['company']) ? $response['company'] : ''; |
|
1138 | + $return['address'] = isset($response['address']) ? $response['address'] : ''; |
|
1139 | 1139 | $return['message'] = $return['company'] . '<br/>' . $return['address']; |
1140 | 1140 | } |
1141 | 1141 | } else { |
1142 | 1142 | $return['valid'] = false; |
1143 | - $return['message'] = wp_sprintf( __( 'Fail to validate the %s number: EU Commission VAT server (VIES) check fails.', 'invoicing' ), $vat_name ); |
|
1143 | + $return['message'] = wp_sprintf(__('Fail to validate the %s number: EU Commission VAT server (VIES) check fails.', 'invoicing'), $vat_name); |
|
1144 | 1144 | } |
1145 | 1145 | |
1146 | 1146 | return $return; |
1147 | 1147 | } |
1148 | 1148 | |
1149 | - public static function request_euvatrates( $group ) { |
|
1149 | + public static function request_euvatrates($group) { |
|
1150 | 1150 | $response = array(); |
1151 | 1151 | $response['success'] = false; |
1152 | 1152 | $response['error'] = null; |
1153 | 1153 | $response['eurates'] = null; |
1154 | 1154 | |
1155 | 1155 | $euvatrates_url = 'https://euvatrates.com/rates.json'; |
1156 | - $euvatrates_url = apply_filters( 'wpinv_euvatrates_url', $euvatrates_url ); |
|
1157 | - $api_response = wp_remote_get( $euvatrates_url ); |
|
1156 | + $euvatrates_url = apply_filters('wpinv_euvatrates_url', $euvatrates_url); |
|
1157 | + $api_response = wp_remote_get($euvatrates_url); |
|
1158 | 1158 | |
1159 | 1159 | try { |
1160 | - if ( is_wp_error( $api_response ) ) { |
|
1161 | - $response['error'] = __( $api_response->get_error_message(), 'invoicing' ); |
|
1160 | + if (is_wp_error($api_response)) { |
|
1161 | + $response['error'] = __($api_response->get_error_message(), 'invoicing'); |
|
1162 | 1162 | } else { |
1163 | - $body = json_decode( $api_response['body'] ); |
|
1163 | + $body = json_decode($api_response['body']); |
|
1164 | 1164 | |
1165 | - if ( isset( $body->rates ) ) { |
|
1165 | + if (isset($body->rates)) { |
|
1166 | 1166 | $rates = array(); |
1167 | 1167 | |
1168 | - foreach ( $body->rates as $country_code => $rate ) { |
|
1168 | + foreach ($body->rates as $country_code => $rate) { |
|
1169 | 1169 | $vat_rate = array(); |
1170 | 1170 | $vat_rate['country'] = $rate->country; |
1171 | 1171 | $vat_rate['standard'] = (float)$rate->standard_rate; |
@@ -1173,7 +1173,7 @@ discard block |
||
1173 | 1173 | $vat_rate['superreduced'] = (float)$rate->super_reduced_rate; |
1174 | 1174 | $vat_rate['parking'] = (float)$rate->parking_rate; |
1175 | 1175 | |
1176 | - if ( $group !== '' && in_array( $group, array( 'standard', 'reduced', 'superreduced', 'parking' ) ) ) { |
|
1176 | + if ($group !== '' && in_array($group, array('standard', 'reduced', 'superreduced', 'parking'))) { |
|
1177 | 1177 | $vat_rate_group = array(); |
1178 | 1178 | $vat_rate_group['country'] = $rate->country; |
1179 | 1179 | $vat_rate_group[$group] = $vat_rate[$group]; |
@@ -1185,79 +1185,79 @@ discard block |
||
1185 | 1185 | } |
1186 | 1186 | |
1187 | 1187 | $response['success'] = true; |
1188 | - $response['rates'] = apply_filters( 'wpinv_process_euvatrates', $rates, $api_response, $group ); |
|
1188 | + $response['rates'] = apply_filters('wpinv_process_euvatrates', $rates, $api_response, $group); |
|
1189 | 1189 | } else { |
1190 | - $response['error'] = __( 'No EU rates found!', 'invoicing' ); |
|
1190 | + $response['error'] = __('No EU rates found!', 'invoicing'); |
|
1191 | 1191 | } |
1192 | 1192 | } |
1193 | - } catch ( Exception $e ) { |
|
1194 | - $response['error'] = __( $e->getMessage(), 'invoicing' ); |
|
1193 | + } catch (Exception $e) { |
|
1194 | + $response['error'] = __($e->getMessage(), 'invoicing'); |
|
1195 | 1195 | } |
1196 | 1196 | |
1197 | - return apply_filters( 'wpinv_response_euvatrates', $response, $group ); |
|
1197 | + return apply_filters('wpinv_response_euvatrates', $response, $group); |
|
1198 | 1198 | } |
1199 | 1199 | |
1200 | - public static function requires_vat( $requires_vat = false, $user_id = 0, $is_digital = null ) { |
|
1200 | + public static function requires_vat($requires_vat = false, $user_id = 0, $is_digital = null) { |
|
1201 | 1201 | global $wpi_item_id, $wpi_country; |
1202 | 1202 | |
1203 | - if ( !empty( $_POST['wpinv_country'] ) ) { |
|
1204 | - $country_code = trim( $_POST['wpinv_country'] ); |
|
1205 | - } else if ( !empty( $_POST['country'] ) ) { |
|
1206 | - $country_code = trim( $_POST['country'] ); |
|
1207 | - } else if ( !empty( $wpi_country ) ) { |
|
1203 | + if (!empty($_POST['wpinv_country'])) { |
|
1204 | + $country_code = trim($_POST['wpinv_country']); |
|
1205 | + } else if (!empty($_POST['country'])) { |
|
1206 | + $country_code = trim($_POST['country']); |
|
1207 | + } else if (!empty($wpi_country)) { |
|
1208 | 1208 | $country_code = $wpi_country; |
1209 | 1209 | } else { |
1210 | - $country_code = self::get_user_country( '', $user_id ); |
|
1210 | + $country_code = self::get_user_country('', $user_id); |
|
1211 | 1211 | } |
1212 | 1212 | |
1213 | - if ( $is_digital === null && $wpi_item_id ) { |
|
1214 | - $is_digital = $wpi_item_id ? self::item_has_digital_rule( $wpi_item_id ) : self::allow_vat_rules(); |
|
1213 | + if ($is_digital === null && $wpi_item_id) { |
|
1214 | + $is_digital = $wpi_item_id ? self::item_has_digital_rule($wpi_item_id) : self::allow_vat_rules(); |
|
1215 | 1215 | } |
1216 | 1216 | |
1217 | - if ( !empty( $country_code ) ) { |
|
1218 | - $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 ) ); |
|
1217 | + if (!empty($country_code)) { |
|
1218 | + $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)); |
|
1219 | 1219 | } |
1220 | 1220 | |
1221 | - return apply_filters( 'wpinv_requires_vat', $requires_vat, $user_id ); |
|
1221 | + return apply_filters('wpinv_requires_vat', $requires_vat, $user_id); |
|
1222 | 1222 | } |
1223 | 1223 | |
1224 | - public static function tax_label( $label = '' ) { |
|
1224 | + public static function tax_label($label = '') { |
|
1225 | 1225 | global $wpi_requires_vat; |
1226 | 1226 | |
1227 | - if ( !( $wpi_requires_vat !== 0 && $wpi_requires_vat ) ) { |
|
1228 | - $wpi_requires_vat = self::requires_vat( 0, false ); |
|
1227 | + if (!($wpi_requires_vat !== 0 && $wpi_requires_vat)) { |
|
1228 | + $wpi_requires_vat = self::requires_vat(0, false); |
|
1229 | 1229 | } |
1230 | 1230 | |
1231 | - return $wpi_requires_vat ? __( self::get_vat_name(), 'invoicing' ) : ( $label ? $label : __( 'Tax', 'invoicing' ) ); |
|
1231 | + return $wpi_requires_vat ? __(self::get_vat_name(), 'invoicing') : ($label ? $label : __('Tax', 'invoicing')); |
|
1232 | 1232 | } |
1233 | 1233 | |
1234 | 1234 | public static function standard_rates_label() { |
1235 | - return __( 'Standard Rates', 'invoicing' ); |
|
1235 | + return __('Standard Rates', 'invoicing'); |
|
1236 | 1236 | } |
1237 | 1237 | |
1238 | - public static function get_rate_classes( $with_desc = false ) { |
|
1239 | - $rate_classes_option = get_option( '_wpinv_vat_rate_classes', true ); |
|
1240 | - $classes = maybe_unserialize( $rate_classes_option ); |
|
1238 | + public static function get_rate_classes($with_desc = false) { |
|
1239 | + $rate_classes_option = get_option('_wpinv_vat_rate_classes', true); |
|
1240 | + $classes = maybe_unserialize($rate_classes_option); |
|
1241 | 1241 | |
1242 | - if ( empty( $classes ) || !is_array( $classes ) ) { |
|
1242 | + if (empty($classes) || !is_array($classes)) { |
|
1243 | 1243 | $classes = array(); |
1244 | 1244 | } |
1245 | 1245 | |
1246 | 1246 | $rate_classes = array(); |
1247 | - if ( !array_key_exists( '_standard', $classes ) ) { |
|
1248 | - if ( $with_desc ) { |
|
1249 | - $rate_classes['_standard'] = array( 'name' => self::standard_rates_label(), 'desc' => __( 'EU member states standard VAT rates', 'invoicing' ) ); |
|
1247 | + if (!array_key_exists('_standard', $classes)) { |
|
1248 | + if ($with_desc) { |
|
1249 | + $rate_classes['_standard'] = array('name' => self::standard_rates_label(), 'desc' => __('EU member states standard VAT rates', 'invoicing')); |
|
1250 | 1250 | } else { |
1251 | 1251 | $rate_classes['_standard'] = self::standard_rates_label(); |
1252 | 1252 | } |
1253 | 1253 | } |
1254 | 1254 | |
1255 | - foreach ( $classes as $key => $class ) { |
|
1256 | - $name = !empty( $class['name'] ) ? __( $class['name'], 'invoicing' ) : $key; |
|
1257 | - $desc = !empty( $class['desc'] ) ? __( $class['desc'], 'invoicing' ) : ''; |
|
1255 | + foreach ($classes as $key => $class) { |
|
1256 | + $name = !empty($class['name']) ? __($class['name'], 'invoicing') : $key; |
|
1257 | + $desc = !empty($class['desc']) ? __($class['desc'], 'invoicing') : ''; |
|
1258 | 1258 | |
1259 | - if ( $with_desc ) { |
|
1260 | - $rate_classes[$key] = array( 'name' => $name, 'desc' => $desc ); |
|
1259 | + if ($with_desc) { |
|
1260 | + $rate_classes[$key] = array('name' => $name, 'desc' => $desc); |
|
1261 | 1261 | } else { |
1262 | 1262 | $rate_classes[$key] = $name; |
1263 | 1263 | } |
@@ -1268,15 +1268,15 @@ discard block |
||
1268 | 1268 | |
1269 | 1269 | public static function get_all_classes() { |
1270 | 1270 | $classes = self::get_rate_classes(); |
1271 | - $classes['_exempt'] = __( 'Exempt (0%)', 'invoicing' ); |
|
1271 | + $classes['_exempt'] = __('Exempt (0%)', 'invoicing'); |
|
1272 | 1272 | |
1273 | - return apply_filters( 'wpinv_vat_get_all_classes', $classes ); |
|
1273 | + return apply_filters('wpinv_vat_get_all_classes', $classes); |
|
1274 | 1274 | } |
1275 | 1275 | |
1276 | - public static function get_class_desc( $rate_class ) { |
|
1277 | - $rate_classes = self::get_rate_classes( true ); |
|
1276 | + public static function get_class_desc($rate_class) { |
|
1277 | + $rate_classes = self::get_rate_classes(true); |
|
1278 | 1278 | |
1279 | - if ( !empty( $rate_classes ) && isset( $rate_classes[$rate_class] ) && isset( $rate_classes[$rate_class]['desc'] ) ) { |
|
1279 | + if (!empty($rate_classes) && isset($rate_classes[$rate_class]) && isset($rate_classes[$rate_class]['desc'])) { |
|
1280 | 1280 | return $rate_classes[$rate_class]['desc']; |
1281 | 1281 | } |
1282 | 1282 | |
@@ -1292,106 +1292,106 @@ discard block |
||
1292 | 1292 | 'increased' => 'Increased' |
1293 | 1293 | ); |
1294 | 1294 | |
1295 | - return apply_filters( 'wpinv_get_vat_groups', $vat_groups ); |
|
1295 | + return apply_filters('wpinv_get_vat_groups', $vat_groups); |
|
1296 | 1296 | } |
1297 | 1297 | |
1298 | 1298 | public static function get_rules() { |
1299 | 1299 | $vat_rules = array( |
1300 | - 'digital' => __( 'Digital Product', 'invoicing' ), |
|
1301 | - 'physical' => __( 'Physical Product', 'invoicing' ) |
|
1300 | + 'digital' => __('Digital Product', 'invoicing'), |
|
1301 | + 'physical' => __('Physical Product', 'invoicing') |
|
1302 | 1302 | ); |
1303 | - return apply_filters( 'wpinv_get_vat_rules', $vat_rules ); |
|
1303 | + return apply_filters('wpinv_get_vat_rules', $vat_rules); |
|
1304 | 1304 | } |
1305 | 1305 | |
1306 | - public static function get_vat_rates( $class ) { |
|
1307 | - if ( $class === '_standard' ) { |
|
1306 | + public static function get_vat_rates($class) { |
|
1307 | + if ($class === '_standard') { |
|
1308 | 1308 | return wpinv_get_tax_rates(); |
1309 | 1309 | } |
1310 | 1310 | |
1311 | 1311 | $rates = self::get_non_standard_rates(); |
1312 | 1312 | |
1313 | - return array_key_exists( $class, $rates ) ? $rates[$class] : array(); |
|
1313 | + return array_key_exists($class, $rates) ? $rates[$class] : array(); |
|
1314 | 1314 | } |
1315 | 1315 | |
1316 | 1316 | public static function get_non_standard_rates() { |
1317 | - $option = get_option( 'wpinv_vat_rates', array()); |
|
1318 | - return is_array( $option ) ? $option : array(); |
|
1317 | + $option = get_option('wpinv_vat_rates', array()); |
|
1318 | + return is_array($option) ? $option : array(); |
|
1319 | 1319 | } |
1320 | 1320 | |
1321 | 1321 | public static function allow_vat_rules() { |
1322 | - return ( wpinv_use_taxes() && wpinv_get_option( 'apply_vat_rules' ) ? true : false ); |
|
1322 | + return (wpinv_use_taxes() && wpinv_get_option('apply_vat_rules') ? true : false); |
|
1323 | 1323 | } |
1324 | 1324 | |
1325 | 1325 | public static function allow_vat_classes() { |
1326 | 1326 | return false; // TODO |
1327 | - return ( wpinv_get_option( 'vat_allow_classes' ) ? true : false ); |
|
1327 | + return (wpinv_get_option('vat_allow_classes') ? true : false); |
|
1328 | 1328 | } |
1329 | 1329 | |
1330 | - public static function get_item_class( $postID ) { |
|
1331 | - $class = get_post_meta( $postID, '_wpinv_vat_class', true ); |
|
1330 | + public static function get_item_class($postID) { |
|
1331 | + $class = get_post_meta($postID, '_wpinv_vat_class', true); |
|
1332 | 1332 | |
1333 | - if ( empty( $class ) ) { |
|
1333 | + if (empty($class)) { |
|
1334 | 1334 | $class = '_standard'; |
1335 | 1335 | } |
1336 | 1336 | |
1337 | - return apply_filters( 'wpinv_get_item_vat_class', $class, $postID ); |
|
1337 | + return apply_filters('wpinv_get_item_vat_class', $class, $postID); |
|
1338 | 1338 | } |
1339 | 1339 | |
1340 | - public static function item_class_label( $postID ) { |
|
1340 | + public static function item_class_label($postID) { |
|
1341 | 1341 | $vat_classes = self::get_all_classes(); |
1342 | 1342 | |
1343 | - $class = self::get_item_class( $postID ); |
|
1344 | - $class = isset( $vat_classes[$class] ) ? $vat_classes[$class] : __( $class, 'invoicing' ); |
|
1343 | + $class = self::get_item_class($postID); |
|
1344 | + $class = isset($vat_classes[$class]) ? $vat_classes[$class] : __($class, 'invoicing'); |
|
1345 | 1345 | |
1346 | - return apply_filters( 'wpinv_item_class_label', $class, $postID ); |
|
1346 | + return apply_filters('wpinv_item_class_label', $class, $postID); |
|
1347 | 1347 | } |
1348 | 1348 | |
1349 | - public static function get_item_rule( $postID ) { |
|
1350 | - $rule_type = get_post_meta( $postID, '_wpinv_vat_rule', true ); |
|
1349 | + public static function get_item_rule($postID) { |
|
1350 | + $rule_type = get_post_meta($postID, '_wpinv_vat_rule', true); |
|
1351 | 1351 | |
1352 | - if ( empty( $rule_type ) ) { |
|
1352 | + if (empty($rule_type)) { |
|
1353 | 1353 | $rule_type = self::allow_vat_rules() ? 'digital' : 'physical'; |
1354 | 1354 | } |
1355 | 1355 | |
1356 | - return apply_filters( 'wpinv_item_get_vat_rule', $rule_type, $postID ); |
|
1356 | + return apply_filters('wpinv_item_get_vat_rule', $rule_type, $postID); |
|
1357 | 1357 | } |
1358 | 1358 | |
1359 | - public static function item_rule_label( $postID ) { |
|
1359 | + public static function item_rule_label($postID) { |
|
1360 | 1360 | $vat_rules = self::get_rules(); |
1361 | - $vat_rule = self::get_item_rule( $postID ); |
|
1362 | - $vat_rule = isset( $vat_rules[$vat_rule] ) ? $vat_rules[$vat_rule] : $vat_rule; |
|
1361 | + $vat_rule = self::get_item_rule($postID); |
|
1362 | + $vat_rule = isset($vat_rules[$vat_rule]) ? $vat_rules[$vat_rule] : $vat_rule; |
|
1363 | 1363 | |
1364 | - return apply_filters( 'wpinv_item_rule_label', $vat_rule, $postID ); |
|
1364 | + return apply_filters('wpinv_item_rule_label', $vat_rule, $postID); |
|
1365 | 1365 | } |
1366 | 1366 | |
1367 | - public static function item_has_digital_rule( $item_id = 0 ) { |
|
1368 | - return self::get_item_rule( $item_id ) == 'digital' ? true : false; |
|
1367 | + public static function item_has_digital_rule($item_id = 0) { |
|
1368 | + return self::get_item_rule($item_id) == 'digital' ? true : false; |
|
1369 | 1369 | } |
1370 | 1370 | |
1371 | - public static function invoice_has_digital_rule( $invoice = 0 ) { |
|
1372 | - if ( !self::allow_vat_rules() ) { |
|
1371 | + public static function invoice_has_digital_rule($invoice = 0) { |
|
1372 | + if (!self::allow_vat_rules()) { |
|
1373 | 1373 | return false; |
1374 | 1374 | } |
1375 | 1375 | |
1376 | - if ( empty( $invoice ) ) { |
|
1376 | + if (empty($invoice)) { |
|
1377 | 1377 | return true; |
1378 | 1378 | } |
1379 | 1379 | |
1380 | - if ( is_int( $invoice ) ) { |
|
1381 | - $invoice = new WPInv_Invoice( $invoice ); |
|
1380 | + if (is_int($invoice)) { |
|
1381 | + $invoice = new WPInv_Invoice($invoice); |
|
1382 | 1382 | } |
1383 | 1383 | |
1384 | - if ( !( is_object( $invoice ) && is_a( $invoice, 'WPInv_Invoice' ) ) ) { |
|
1384 | + if (!(is_object($invoice) && is_a($invoice, 'WPInv_Invoice'))) { |
|
1385 | 1385 | return true; |
1386 | 1386 | } |
1387 | 1387 | |
1388 | - $cart_items = $invoice->get_cart_details(); |
|
1388 | + $cart_items = $invoice->get_cart_details(); |
|
1389 | 1389 | |
1390 | - if ( !empty( $cart_items ) ) { |
|
1390 | + if (!empty($cart_items)) { |
|
1391 | 1391 | $has_digital_rule = false; |
1392 | 1392 | |
1393 | - foreach ( $cart_items as $key => $item ) { |
|
1394 | - if ( self::item_has_digital_rule( $item['id'] ) ) { |
|
1393 | + foreach ($cart_items as $key => $item) { |
|
1394 | + if (self::item_has_digital_rule($item['id'])) { |
|
1395 | 1395 | $has_digital_rule = true; |
1396 | 1396 | break; |
1397 | 1397 | } |
@@ -1403,67 +1403,67 @@ discard block |
||
1403 | 1403 | return $has_digital_rule; |
1404 | 1404 | } |
1405 | 1405 | |
1406 | - public static function item_is_taxable( $item_id = 0, $country = false, $state = false ) { |
|
1407 | - if ( !wpinv_use_taxes() ) { |
|
1406 | + public static function item_is_taxable($item_id = 0, $country = false, $state = false) { |
|
1407 | + if (!wpinv_use_taxes()) { |
|
1408 | 1408 | return false; |
1409 | 1409 | } |
1410 | 1410 | |
1411 | 1411 | $is_taxable = true; |
1412 | 1412 | |
1413 | - if ( !empty( $item_id ) && self::get_item_class( $item_id ) == '_exempt' ) { |
|
1413 | + if (!empty($item_id) && self::get_item_class($item_id) == '_exempt') { |
|
1414 | 1414 | $is_taxable = false; |
1415 | 1415 | } |
1416 | 1416 | |
1417 | - return apply_filters( 'wpinv_item_is_taxable', $is_taxable, $item_id, $country , $state ); |
|
1417 | + return apply_filters('wpinv_item_is_taxable', $is_taxable, $item_id, $country, $state); |
|
1418 | 1418 | } |
1419 | 1419 | |
1420 | - public static function find_rate( $country, $state, $rate, $class ) { |
|
1420 | + public static function find_rate($country, $state, $rate, $class) { |
|
1421 | 1421 | global $wpi_zero_tax; |
1422 | 1422 | |
1423 | - if ( $class === '_exempt' || $wpi_zero_tax ) { |
|
1423 | + if ($class === '_exempt' || $wpi_zero_tax) { |
|
1424 | 1424 | return 0; |
1425 | 1425 | } |
1426 | 1426 | |
1427 | - $tax_rates = wpinv_get_tax_rates(); |
|
1427 | + $tax_rates = wpinv_get_tax_rates(); |
|
1428 | 1428 | |
1429 | - if ( $class !== '_standard' ) { |
|
1430 | - $class_rates = self::get_vat_rates( $class ); |
|
1429 | + if ($class !== '_standard') { |
|
1430 | + $class_rates = self::get_vat_rates($class); |
|
1431 | 1431 | |
1432 | - if ( is_array( $class_rates ) ) { |
|
1432 | + if (is_array($class_rates)) { |
|
1433 | 1433 | $indexed_class_rates = array(); |
1434 | 1434 | |
1435 | - foreach ( $class_rates as $key => $cr ) { |
|
1435 | + foreach ($class_rates as $key => $cr) { |
|
1436 | 1436 | $indexed_class_rates[$cr['country']] = $cr; |
1437 | 1437 | } |
1438 | 1438 | |
1439 | - $tax_rates = array_map( function( $tr ) use( $indexed_class_rates ) { |
|
1439 | + $tax_rates = array_map(function($tr) use($indexed_class_rates) { |
|
1440 | 1440 | $tr_country = $tr['country']; |
1441 | - if ( !isset( $indexed_class_rates[$tr_country] ) ) { |
|
1441 | + if (!isset($indexed_class_rates[$tr_country])) { |
|
1442 | 1442 | return $tr; |
1443 | 1443 | } |
1444 | 1444 | $icr = $indexed_class_rates[$tr_country]; |
1445 | - return ( empty( $icr['rate'] ) && $icr['rate'] !== '0' ) ? $tr : $icr; |
|
1445 | + return (empty($icr['rate']) && $icr['rate'] !== '0') ? $tr : $icr; |
|
1446 | 1446 | |
1447 | - }, $tax_rates, $class_rates ); |
|
1447 | + }, $tax_rates, $class_rates); |
|
1448 | 1448 | } |
1449 | 1449 | } |
1450 | 1450 | |
1451 | - if ( !empty( $tax_rates ) ) { |
|
1452 | - foreach ( $tax_rates as $key => $tax_rate ) { |
|
1453 | - if ( $country != $tax_rate['country'] ) |
|
1451 | + if (!empty($tax_rates)) { |
|
1452 | + foreach ($tax_rates as $key => $tax_rate) { |
|
1453 | + if ($country != $tax_rate['country']) |
|
1454 | 1454 | continue; |
1455 | 1455 | |
1456 | - if ( !empty( $tax_rate['global'] ) ) { |
|
1457 | - if ( 0 !== $tax_rate['rate'] || !empty( $tax_rate['rate'] ) ) { |
|
1458 | - $rate = number_format( $tax_rate['rate'], 4 ); |
|
1456 | + if (!empty($tax_rate['global'])) { |
|
1457 | + if (0 !== $tax_rate['rate'] || !empty($tax_rate['rate'])) { |
|
1458 | + $rate = number_format($tax_rate['rate'], 4); |
|
1459 | 1459 | } |
1460 | 1460 | } else { |
1461 | - if ( empty( $tax_rate['state'] ) || strtolower( $state ) != strtolower( $tax_rate['state'] ) ) |
|
1461 | + if (empty($tax_rate['state']) || strtolower($state) != strtolower($tax_rate['state'])) |
|
1462 | 1462 | continue; |
1463 | 1463 | |
1464 | 1464 | $state_rate = $tax_rate['rate']; |
1465 | - if ( 0 !== $state_rate || !empty( $state_rate ) ) { |
|
1466 | - $rate = number_format( $state_rate, 4 ); |
|
1465 | + if (0 !== $state_rate || !empty($state_rate)) { |
|
1466 | + $rate = number_format($state_rate, 4); |
|
1467 | 1467 | } |
1468 | 1468 | } |
1469 | 1469 | } |
@@ -1472,84 +1472,84 @@ discard block |
||
1472 | 1472 | return $rate; |
1473 | 1473 | } |
1474 | 1474 | |
1475 | - public static function get_rate( $rate = 1, $country = '', $state = '', $item_id = 0 ) { |
|
1475 | + public static function get_rate($rate = 1, $country = '', $state = '', $item_id = 0) { |
|
1476 | 1476 | global $wpinv_options, $wpi_session, $wpi_item_id, $wpi_zero_tax; |
1477 | 1477 | |
1478 | 1478 | $item_id = $item_id > 0 ? $item_id : $wpi_item_id; |
1479 | 1479 | $allow_vat_classes = self::allow_vat_classes(); |
1480 | - $class = $item_id ? self::get_item_class( $item_id ) : '_standard'; |
|
1480 | + $class = $item_id ? self::get_item_class($item_id) : '_standard'; |
|
1481 | 1481 | |
1482 | - if ( $class === '_exempt' || $wpi_zero_tax ) { |
|
1482 | + if ($class === '_exempt' || $wpi_zero_tax) { |
|
1483 | 1483 | return 0; |
1484 | - } else if ( !$allow_vat_classes ) { |
|
1484 | + } else if (!$allow_vat_classes) { |
|
1485 | 1485 | $class = '_standard'; |
1486 | 1486 | } |
1487 | 1487 | |
1488 | - if( !empty( $_POST['wpinv_country'] ) ) { |
|
1488 | + if (!empty($_POST['wpinv_country'])) { |
|
1489 | 1489 | $post_country = $_POST['wpinv_country']; |
1490 | - } elseif( !empty( $_POST['wpinv_country'] ) ) { |
|
1490 | + } elseif (!empty($_POST['wpinv_country'])) { |
|
1491 | 1491 | $post_country = $_POST['wpinv_country']; |
1492 | - } elseif( !empty( $_POST['country'] ) ) { |
|
1492 | + } elseif (!empty($_POST['country'])) { |
|
1493 | 1493 | $post_country = $_POST['country']; |
1494 | 1494 | } else { |
1495 | 1495 | $post_country = ''; |
1496 | 1496 | } |
1497 | 1497 | |
1498 | - $country = !empty( $post_country ) ? $post_country : wpinv_default_billing_country( $country ); |
|
1499 | - $base_country = wpinv_is_base_country( $country ); |
|
1498 | + $country = !empty($post_country) ? $post_country : wpinv_default_billing_country($country); |
|
1499 | + $base_country = wpinv_is_base_country($country); |
|
1500 | 1500 | |
1501 | - $requires_vat = self::requires_vat( 0, false ); |
|
1502 | - $is_digital = self::get_item_rule( $item_id ) == 'digital' ; |
|
1503 | - $rate = $requires_vat && isset( $wpinv_options['eu_fallback_rate'] ) ? $wpinv_options['eu_fallback_rate'] : $rate; |
|
1501 | + $requires_vat = self::requires_vat(0, false); |
|
1502 | + $is_digital = self::get_item_rule($item_id) == 'digital'; |
|
1503 | + $rate = $requires_vat && isset($wpinv_options['eu_fallback_rate']) ? $wpinv_options['eu_fallback_rate'] : $rate; |
|
1504 | 1504 | |
1505 | - if ( self::same_country_rule() == 'no' && $base_country ) { // Disable VAT to same country |
|
1505 | + if (self::same_country_rule() == 'no' && $base_country) { // Disable VAT to same country |
|
1506 | 1506 | $rate = 0; |
1507 | - } else if ( $requires_vat ) { |
|
1508 | - $vat_number = self::get_user_vat_number( '', 0, true ); |
|
1507 | + } else if ($requires_vat) { |
|
1508 | + $vat_number = self::get_user_vat_number('', 0, true); |
|
1509 | 1509 | $vat_info = self::current_vat_data(); |
1510 | 1510 | |
1511 | - if ( is_array( $vat_info ) ) { |
|
1512 | - $vat_number = isset( $vat_info['number'] ) && !empty( $vat_info['valid'] ) ? $vat_info['number'] : ""; |
|
1511 | + if (is_array($vat_info)) { |
|
1512 | + $vat_number = isset($vat_info['number']) && !empty($vat_info['valid']) ? $vat_info['number'] : ""; |
|
1513 | 1513 | } |
1514 | 1514 | |
1515 | - if ( $country == 'UK' ) { |
|
1515 | + if ($country == 'UK') { |
|
1516 | 1516 | $country = 'GB'; |
1517 | 1517 | } |
1518 | 1518 | |
1519 | - if ( !empty( $vat_number ) ) { |
|
1519 | + if (!empty($vat_number)) { |
|
1520 | 1520 | $rate = 0; |
1521 | 1521 | } else { |
1522 | - $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 |
|
1522 | + $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 | 1523 | } |
1524 | 1524 | |
1525 | - if ( empty( $vat_number ) && !$is_digital ) { |
|
1526 | - if ( $base_country ) { |
|
1527 | - $rate = self::find_rate( $country, null, $rate, $class ); |
|
1525 | + if (empty($vat_number) && !$is_digital) { |
|
1526 | + if ($base_country) { |
|
1527 | + $rate = self::find_rate($country, null, $rate, $class); |
|
1528 | 1528 | } else { |
1529 | - if ( empty( $country ) && isset( $wpinv_options['eu_fallback_rate'] ) ) { |
|
1529 | + if (empty($country) && isset($wpinv_options['eu_fallback_rate'])) { |
|
1530 | 1530 | $rate = $wpinv_options['eu_fallback_rate']; |
1531 | - } else if( !empty( $country ) ) { |
|
1532 | - $rate = self::find_rate( $country, $state, $rate, $class ); |
|
1531 | + } else if (!empty($country)) { |
|
1532 | + $rate = self::find_rate($country, $state, $rate, $class); |
|
1533 | 1533 | } |
1534 | 1534 | } |
1535 | - } else if ( empty( $vat_number ) || ( self::same_country_rule() == 'always' && $base_country ) ) { |
|
1536 | - if ( empty( $country ) && isset( $wpinv_options['eu_fallback_rate'] ) ) { |
|
1535 | + } else if (empty($vat_number) || (self::same_country_rule() == 'always' && $base_country)) { |
|
1536 | + if (empty($country) && isset($wpinv_options['eu_fallback_rate'])) { |
|
1537 | 1537 | $rate = $wpinv_options['eu_fallback_rate']; |
1538 | - } else if( !empty( $country ) ) { |
|
1539 | - $rate = self::find_rate( $country, $state, $rate, $class ); |
|
1538 | + } else if (!empty($country)) { |
|
1539 | + $rate = self::find_rate($country, $state, $rate, $class); |
|
1540 | 1540 | } |
1541 | 1541 | } |
1542 | 1542 | } else { |
1543 | - if ( $is_digital ) { |
|
1543 | + if ($is_digital) { |
|
1544 | 1544 | $ip_country_code = self::get_country_by_ip(); |
1545 | 1545 | |
1546 | - if ( $ip_country_code && self::is_eu_state( $ip_country_code ) ) { |
|
1547 | - $rate = self::find_rate( $ip_country_code, '', 0, $class ); |
|
1546 | + if ($ip_country_code && self::is_eu_state($ip_country_code)) { |
|
1547 | + $rate = self::find_rate($ip_country_code, '', 0, $class); |
|
1548 | 1548 | } else { |
1549 | - $rate = self::find_rate( $country, $state, $rate, $class ); |
|
1549 | + $rate = self::find_rate($country, $state, $rate, $class); |
|
1550 | 1550 | } |
1551 | 1551 | } else { |
1552 | - $rate = self::find_rate( $country, $state, $rate, $class ); |
|
1552 | + $rate = self::find_rate($country, $state, $rate, $class); |
|
1553 | 1553 | } |
1554 | 1554 | } |
1555 | 1555 | |
@@ -1559,48 +1559,48 @@ discard block |
||
1559 | 1559 | public static function current_vat_data() { |
1560 | 1560 | global $wpi_session; |
1561 | 1561 | |
1562 | - return $wpi_session->get( 'user_vat_data' ); |
|
1562 | + return $wpi_session->get('user_vat_data'); |
|
1563 | 1563 | } |
1564 | 1564 | |
1565 | - public static function get_user_country( $country = '', $user_id = 0 ) { |
|
1566 | - $user_address = wpinv_get_user_address( $user_id, false ); |
|
1565 | + public static function get_user_country($country = '', $user_id = 0) { |
|
1566 | + $user_address = wpinv_get_user_address($user_id, false); |
|
1567 | 1567 | |
1568 | - if ( wpinv_get_option( 'vat_ip_country_default' ) ) { |
|
1568 | + if (wpinv_get_option('vat_ip_country_default')) { |
|
1569 | 1569 | $country = ''; |
1570 | 1570 | } |
1571 | 1571 | |
1572 | - $country = empty( $user_address ) || !isset( $user_address['country'] ) || empty( $user_address['country'] ) ? $country : $user_address['country']; |
|
1573 | - $result = apply_filters( 'wpinv_get_user_country', $country, $user_id ); |
|
1572 | + $country = empty($user_address) || !isset($user_address['country']) || empty($user_address['country']) ? $country : $user_address['country']; |
|
1573 | + $result = apply_filters('wpinv_get_user_country', $country, $user_id); |
|
1574 | 1574 | |
1575 | - if ( empty( $result ) ) { |
|
1575 | + if (empty($result)) { |
|
1576 | 1576 | $result = self::get_country_by_ip(); |
1577 | 1577 | } |
1578 | 1578 | |
1579 | 1579 | return $result; |
1580 | 1580 | } |
1581 | 1581 | |
1582 | - public static function set_user_country( $country = '', $user_id = 0 ) { |
|
1582 | + public static function set_user_country($country = '', $user_id = 0) { |
|
1583 | 1583 | global $wpi_userID; |
1584 | 1584 | |
1585 | - if ( empty($country) && !empty($wpi_userID) && get_current_user_id() != $wpi_userID ) { |
|
1585 | + if (empty($country) && !empty($wpi_userID) && get_current_user_id() != $wpi_userID) { |
|
1586 | 1586 | $country = wpinv_get_default_country(); |
1587 | 1587 | } |
1588 | 1588 | |
1589 | 1589 | return $country; |
1590 | 1590 | } |
1591 | 1591 | |
1592 | - public static function get_user_vat_number( $vat_number = '', $user_id = 0, $is_valid = false ) { |
|
1592 | + public static function get_user_vat_number($vat_number = '', $user_id = 0, $is_valid = false) { |
|
1593 | 1593 | global $wpi_current_id, $wpi_userID; |
1594 | 1594 | |
1595 | - if ( !empty( $_POST['new_user'] ) ) { |
|
1595 | + if (!empty($_POST['new_user'])) { |
|
1596 | 1596 | return ''; |
1597 | 1597 | } |
1598 | 1598 | |
1599 | - if ( empty( $user_id ) ) { |
|
1600 | - $user_id = !empty( $wpi_userID ) ? $wpi_userID : ( $wpi_current_id ? wpinv_get_user_id( $wpi_current_id ) : get_current_user_id() ); |
|
1599 | + if (empty($user_id)) { |
|
1600 | + $user_id = !empty($wpi_userID) ? $wpi_userID : ($wpi_current_id ? wpinv_get_user_id($wpi_current_id) : get_current_user_id()); |
|
1601 | 1601 | } |
1602 | 1602 | |
1603 | - $vat_number = empty( $user_id ) ? '' : get_user_meta( $user_id, '_wpinv_vat_number', true ); |
|
1603 | + $vat_number = empty($user_id) ? '' : get_user_meta($user_id, '_wpinv_vat_number', true); |
|
1604 | 1604 | |
1605 | 1605 | /* TODO |
1606 | 1606 | if ( $is_valid && $vat_number ) { |
@@ -1611,38 +1611,38 @@ discard block |
||
1611 | 1611 | } |
1612 | 1612 | */ |
1613 | 1613 | |
1614 | - return apply_filters('wpinv_get_user_vat_number', $vat_number, $user_id, $is_valid ); |
|
1614 | + return apply_filters('wpinv_get_user_vat_number', $vat_number, $user_id, $is_valid); |
|
1615 | 1615 | } |
1616 | 1616 | |
1617 | - public static function get_user_company( $company = '', $user_id = 0 ) { |
|
1617 | + public static function get_user_company($company = '', $user_id = 0) { |
|
1618 | 1618 | global $wpi_current_id, $wpi_userID; |
1619 | 1619 | |
1620 | - if ( empty( $user_id ) ) { |
|
1621 | - $user_id = !empty( $wpi_userID ) ? $wpi_userID : ( $wpi_current_id ? wpinv_get_user_id( $wpi_current_id ) : get_current_user_id() ); |
|
1620 | + if (empty($user_id)) { |
|
1621 | + $user_id = !empty($wpi_userID) ? $wpi_userID : ($wpi_current_id ? wpinv_get_user_id($wpi_current_id) : get_current_user_id()); |
|
1622 | 1622 | } |
1623 | 1623 | |
1624 | - $company = empty( $user_id ) ? "" : get_user_meta( $user_id, '_wpinv_company', true ); |
|
1624 | + $company = empty($user_id) ? "" : get_user_meta($user_id, '_wpinv_company', true); |
|
1625 | 1625 | |
1626 | - return apply_filters( 'wpinv_user_company', $company, $user_id ); |
|
1626 | + return apply_filters('wpinv_user_company', $company, $user_id); |
|
1627 | 1627 | } |
1628 | 1628 | |
1629 | - public static function save_user_vat_details( $company = '', $vat_number = '' ) { |
|
1630 | - $save = apply_filters( 'wpinv_allow_save_user_vat_details', true ); |
|
1629 | + public static function save_user_vat_details($company = '', $vat_number = '') { |
|
1630 | + $save = apply_filters('wpinv_allow_save_user_vat_details', true); |
|
1631 | 1631 | |
1632 | - if ( is_user_logged_in() && $save ) { |
|
1632 | + if (is_user_logged_in() && $save) { |
|
1633 | 1633 | $user_id = get_current_user_id(); |
1634 | 1634 | |
1635 | - if ( !empty( $vat_number ) ) { |
|
1636 | - update_user_meta( $user_id, '_wpinv_vat_number', $vat_number ); |
|
1635 | + if (!empty($vat_number)) { |
|
1636 | + update_user_meta($user_id, '_wpinv_vat_number', $vat_number); |
|
1637 | 1637 | } else { |
1638 | - delete_user_meta( $user_id, '_wpinv_vat_number'); |
|
1638 | + delete_user_meta($user_id, '_wpinv_vat_number'); |
|
1639 | 1639 | } |
1640 | 1640 | |
1641 | - if ( !empty( $company ) ) { |
|
1642 | - update_user_meta( $user_id, '_wpinv_company', $company ); |
|
1641 | + if (!empty($company)) { |
|
1642 | + update_user_meta($user_id, '_wpinv_company', $company); |
|
1643 | 1643 | } else { |
1644 | - delete_user_meta( $user_id, '_wpinv_company'); |
|
1645 | - delete_user_meta( $user_id, '_wpinv_vat_number'); |
|
1644 | + delete_user_meta($user_id, '_wpinv_company'); |
|
1645 | + delete_user_meta($user_id, '_wpinv_vat_number'); |
|
1646 | 1646 | } |
1647 | 1647 | } |
1648 | 1648 | |
@@ -1652,113 +1652,113 @@ discard block |
||
1652 | 1652 | public static function ajax_vat_validate() { |
1653 | 1653 | global $wpinv_options, $wpi_session; |
1654 | 1654 | |
1655 | - $is_checkout = ( !empty( $_POST['source'] ) && $_POST['source'] == 'checkout' ) ? true : false; |
|
1655 | + $is_checkout = (!empty($_POST['source']) && $_POST['source'] == 'checkout') ? true : false; |
|
1656 | 1656 | $response = array(); |
1657 | 1657 | $response['success'] = false; |
1658 | 1658 | |
1659 | - if ( empty( $_REQUEST['_wpi_nonce'] ) || ( !empty( $_REQUEST['_wpi_nonce'] ) && !wp_verify_nonce( $_REQUEST['_wpi_nonce'], 'vat_validation' ) ) ) { |
|
1660 | - $response['error'] = __( 'Invalid security nonce', 'invoicing' ); |
|
1661 | - wp_send_json( $response ); |
|
1659 | + if (empty($_REQUEST['_wpi_nonce']) || (!empty($_REQUEST['_wpi_nonce']) && !wp_verify_nonce($_REQUEST['_wpi_nonce'], 'vat_validation'))) { |
|
1660 | + $response['error'] = __('Invalid security nonce', 'invoicing'); |
|
1661 | + wp_send_json($response); |
|
1662 | 1662 | } |
1663 | 1663 | |
1664 | - $vat_name = self::get_vat_name(); |
|
1664 | + $vat_name = self::get_vat_name(); |
|
1665 | 1665 | |
1666 | - if ( $is_checkout ) { |
|
1666 | + if ($is_checkout) { |
|
1667 | 1667 | $invoice = wpinv_get_invoice_cart(); |
1668 | 1668 | |
1669 | - if ( !self::requires_vat( false, 0, self::invoice_has_digital_rule( $invoice ) ) ) { |
|
1669 | + if (!self::requires_vat(false, 0, self::invoice_has_digital_rule($invoice))) { |
|
1670 | 1670 | $vat_info = array(); |
1671 | - $wpi_session->set( 'user_vat_data', $vat_info ); |
|
1671 | + $wpi_session->set('user_vat_data', $vat_info); |
|
1672 | 1672 | |
1673 | 1673 | self::save_user_vat_details(); |
1674 | 1674 | |
1675 | 1675 | $response['success'] = true; |
1676 | - $response['message'] = wp_sprintf( __( 'Ignore %s', 'invoicing' ), $vat_name ); |
|
1677 | - wp_send_json( $response ); |
|
1676 | + $response['message'] = wp_sprintf(__('Ignore %s', 'invoicing'), $vat_name); |
|
1677 | + wp_send_json($response); |
|
1678 | 1678 | } |
1679 | 1679 | } |
1680 | 1680 | |
1681 | - $company = !empty( $_POST['company'] ) ? sanitize_text_field( $_POST['company'] ) : ''; |
|
1682 | - $vat_number = !empty( $_POST['number'] ) ? sanitize_text_field( $_POST['number'] ) : ''; |
|
1681 | + $company = !empty($_POST['company']) ? sanitize_text_field($_POST['company']) : ''; |
|
1682 | + $vat_number = !empty($_POST['number']) ? sanitize_text_field($_POST['number']) : ''; |
|
1683 | 1683 | |
1684 | - $vat_info = $wpi_session->get( 'user_vat_data' ); |
|
1685 | - if ( !is_array( $vat_info ) || empty( $vat_info ) ) { |
|
1686 | - $vat_info = array( 'company'=> $company, 'number' => '', 'valid' => true ); |
|
1684 | + $vat_info = $wpi_session->get('user_vat_data'); |
|
1685 | + if (!is_array($vat_info) || empty($vat_info)) { |
|
1686 | + $vat_info = array('company'=> $company, 'number' => '', 'valid' => true); |
|
1687 | 1687 | } |
1688 | 1688 | |
1689 | - if ( empty( $vat_number ) ) { |
|
1690 | - if ( $is_checkout ) { |
|
1689 | + if (empty($vat_number)) { |
|
1690 | + if ($is_checkout) { |
|
1691 | 1691 | $response['success'] = true; |
1692 | - $response['message'] = wp_sprintf( __( 'No %s number has been applied. %s will be added to invoice totals', 'invoicing' ), $vat_name, $vat_name ); |
|
1692 | + $response['message'] = wp_sprintf(__('No %s number has been applied. %s will be added to invoice totals', 'invoicing'), $vat_name, $vat_name); |
|
1693 | 1693 | |
1694 | - $vat_info = $wpi_session->get( 'user_vat_data' ); |
|
1694 | + $vat_info = $wpi_session->get('user_vat_data'); |
|
1695 | 1695 | $vat_info['number'] = ""; |
1696 | 1696 | $vat_info['valid'] = true; |
1697 | 1697 | |
1698 | - self::save_user_vat_details( $company ); |
|
1698 | + self::save_user_vat_details($company); |
|
1699 | 1699 | } else { |
1700 | - $response['error'] = wp_sprintf( __( 'Please enter your %s number!', 'invoicing' ), $vat_name ); |
|
1700 | + $response['error'] = wp_sprintf(__('Please enter your %s number!', 'invoicing'), $vat_name); |
|
1701 | 1701 | |
1702 | 1702 | $vat_info['valid'] = false; |
1703 | 1703 | } |
1704 | 1704 | |
1705 | - $wpi_session->set( 'user_vat_data', $vat_info ); |
|
1706 | - wp_send_json( $response ); |
|
1705 | + $wpi_session->set('user_vat_data', $vat_info); |
|
1706 | + wp_send_json($response); |
|
1707 | 1707 | } |
1708 | 1708 | |
1709 | - if ( empty( $company ) ) { |
|
1709 | + if (empty($company)) { |
|
1710 | 1710 | $vat_info['valid'] = false; |
1711 | - $wpi_session->set( 'user_vat_data', $vat_info ); |
|
1711 | + $wpi_session->set('user_vat_data', $vat_info); |
|
1712 | 1712 | |
1713 | - $response['error'] = __( 'Please enter your registered company name!', 'invoicing' ); |
|
1714 | - wp_send_json( $response ); |
|
1713 | + $response['error'] = __('Please enter your registered company name!', 'invoicing'); |
|
1714 | + wp_send_json($response); |
|
1715 | 1715 | } |
1716 | 1716 | |
1717 | - if ( !empty( $wpinv_options['vat_vies_check'] ) ) { |
|
1718 | - if ( empty( $wpinv_options['vat_offline_check'] ) && !self::offline_check( $vat_number ) ) { |
|
1717 | + if (!empty($wpinv_options['vat_vies_check'])) { |
|
1718 | + if (empty($wpinv_options['vat_offline_check']) && !self::offline_check($vat_number)) { |
|
1719 | 1719 | $vat_info['valid'] = false; |
1720 | - $wpi_session->set( 'user_vat_data', $vat_info ); |
|
1720 | + $wpi_session->set('user_vat_data', $vat_info); |
|
1721 | 1721 | |
1722 | - $response['error'] = wp_sprintf( __( '%s number not validated', 'invoicing' ), $vat_name ); |
|
1723 | - wp_send_json( $response ); |
|
1722 | + $response['error'] = wp_sprintf(__('%s number not validated', 'invoicing'), $vat_name); |
|
1723 | + wp_send_json($response); |
|
1724 | 1724 | } |
1725 | 1725 | |
1726 | 1726 | $response['success'] = true; |
1727 | - $response['message'] = wp_sprintf( __( '%s number validated', 'invoicing' ), $vat_name ); |
|
1727 | + $response['message'] = wp_sprintf(__('%s number validated', 'invoicing'), $vat_name); |
|
1728 | 1728 | } else { |
1729 | - $result = self::check_vat( $vat_number ); |
|
1729 | + $result = self::check_vat($vat_number); |
|
1730 | 1730 | |
1731 | - if ( empty( $result['valid'] ) ) { |
|
1731 | + if (empty($result['valid'])) { |
|
1732 | 1732 | $response['error'] = $result['message']; |
1733 | - wp_send_json( $response ); |
|
1733 | + wp_send_json($response); |
|
1734 | 1734 | } |
1735 | 1735 | |
1736 | - $vies_company = !empty( $result['company'] ) ? $result['company'] : ''; |
|
1737 | - $vies_company = apply_filters( 'wpinv_vies_company_name', $vies_company ); |
|
1736 | + $vies_company = !empty($result['company']) ? $result['company'] : ''; |
|
1737 | + $vies_company = apply_filters('wpinv_vies_company_name', $vies_company); |
|
1738 | 1738 | |
1739 | - $valid_company = $vies_company && $company && ( $vies_company == '---' || strcasecmp( trim( $vies_company ), trim( $company ) ) == 0 ) ? true : false; |
|
1739 | + $valid_company = $vies_company && $company && ($vies_company == '---' || strcasecmp(trim($vies_company), trim($company)) == 0) ? true : false; |
|
1740 | 1740 | |
1741 | - if ( !empty( $wpinv_options['vat_disable_company_name_check'] ) || $valid_company ) { |
|
1741 | + if (!empty($wpinv_options['vat_disable_company_name_check']) || $valid_company) { |
|
1742 | 1742 | $response['success'] = true; |
1743 | - $response['message'] = wp_sprintf( __( '%s number validated', 'invoicing' ), $vat_name ); |
|
1743 | + $response['message'] = wp_sprintf(__('%s number validated', 'invoicing'), $vat_name); |
|
1744 | 1744 | } else { |
1745 | 1745 | $vat_info['valid'] = false; |
1746 | - $wpi_session->set( 'user_vat_data', $vat_info ); |
|
1746 | + $wpi_session->set('user_vat_data', $vat_info); |
|
1747 | 1747 | |
1748 | 1748 | $response['success'] = false; |
1749 | - $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 ); |
|
1750 | - wp_send_json( $response ); |
|
1749 | + $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); |
|
1750 | + wp_send_json($response); |
|
1751 | 1751 | } |
1752 | 1752 | } |
1753 | 1753 | |
1754 | - if ( $is_checkout ) { |
|
1755 | - self::save_user_vat_details( $company, $vat_number ); |
|
1754 | + if ($is_checkout) { |
|
1755 | + self::save_user_vat_details($company, $vat_number); |
|
1756 | 1756 | |
1757 | - $vat_info = array('company' => $company, 'number' => $vat_number, 'valid' => true ); |
|
1758 | - $wpi_session->set( 'user_vat_data', $vat_info ); |
|
1757 | + $vat_info = array('company' => $company, 'number' => $vat_number, 'valid' => true); |
|
1758 | + $wpi_session->set('user_vat_data', $vat_info); |
|
1759 | 1759 | } |
1760 | 1760 | |
1761 | - wp_send_json( $response ); |
|
1761 | + wp_send_json($response); |
|
1762 | 1762 | } |
1763 | 1763 | |
1764 | 1764 | public static function ajax_vat_reset() { |
@@ -1767,161 +1767,161 @@ discard block |
||
1767 | 1767 | $company = is_user_logged_in() ? self::get_user_company() : ''; |
1768 | 1768 | $vat_number = self::get_user_vat_number(); |
1769 | 1769 | |
1770 | - $vat_info = array('company' => $company, 'number' => $vat_number, 'valid' => false ); |
|
1771 | - $wpi_session->set( 'user_vat_data', $vat_info ); |
|
1770 | + $vat_info = array('company' => $company, 'number' => $vat_number, 'valid' => false); |
|
1771 | + $wpi_session->set('user_vat_data', $vat_info); |
|
1772 | 1772 | |
1773 | 1773 | $response = array(); |
1774 | 1774 | $response['success'] = true; |
1775 | 1775 | $response['data']['company'] = $company; |
1776 | 1776 | $response['data']['number'] = $vat_number; |
1777 | 1777 | |
1778 | - wp_send_json( $response ); |
|
1778 | + wp_send_json($response); |
|
1779 | 1779 | } |
1780 | 1780 | |
1781 | - public static function checkout_vat_validate( $valid_data, $post ) { |
|
1781 | + public static function checkout_vat_validate($valid_data, $post) { |
|
1782 | 1782 | global $wpinv_options, $wpi_session; |
1783 | 1783 | |
1784 | - $vat_name = __( self::get_vat_name(), 'invoicing' ); |
|
1784 | + $vat_name = __(self::get_vat_name(), 'invoicing'); |
|
1785 | 1785 | |
1786 | - if ( !isset( $_POST['_wpi_nonce'] ) || !wp_verify_nonce( $_POST['_wpi_nonce'], 'vat_validation' ) ) { |
|
1787 | - wpinv_set_error( 'vat_validation', wp_sprintf( __( "Invalid %s validation request.", 'invoicing' ), $vat_name ) ); |
|
1786 | + if (!isset($_POST['_wpi_nonce']) || !wp_verify_nonce($_POST['_wpi_nonce'], 'vat_validation')) { |
|
1787 | + wpinv_set_error('vat_validation', wp_sprintf(__("Invalid %s validation request.", 'invoicing'), $vat_name)); |
|
1788 | 1788 | return; |
1789 | 1789 | } |
1790 | 1790 | |
1791 | - $vat_saved = $wpi_session->get( 'user_vat_data' ); |
|
1792 | - $wpi_session->set( 'user_vat_data', null ); |
|
1791 | + $vat_saved = $wpi_session->get('user_vat_data'); |
|
1792 | + $wpi_session->set('user_vat_data', null); |
|
1793 | 1793 | |
1794 | 1794 | $invoice = wpinv_get_invoice_cart(); |
1795 | 1795 | $amount = $invoice->get_total(); |
1796 | - $is_digital = self::invoice_has_digital_rule( $invoice ); |
|
1797 | - $no_vat = !self::requires_vat( 0, false, $is_digital ); |
|
1796 | + $is_digital = self::invoice_has_digital_rule($invoice); |
|
1797 | + $no_vat = !self::requires_vat(0, false, $is_digital); |
|
1798 | 1798 | |
1799 | - $company = !empty( $_POST['wpinv_company'] ) ? $_POST['wpinv_company'] : null; |
|
1800 | - $vat_number = !empty( $_POST['wpinv_vat_number'] ) ? $_POST['wpinv_vat_number'] : null; |
|
1801 | - $country = !empty( $_POST['wpinv_country'] ) ? $_POST['wpinv_country'] : $invoice->country; |
|
1802 | - if ( empty( $country ) ) { |
|
1799 | + $company = !empty($_POST['wpinv_company']) ? $_POST['wpinv_company'] : null; |
|
1800 | + $vat_number = !empty($_POST['wpinv_vat_number']) ? $_POST['wpinv_vat_number'] : null; |
|
1801 | + $country = !empty($_POST['wpinv_country']) ? $_POST['wpinv_country'] : $invoice->country; |
|
1802 | + if (empty($country)) { |
|
1803 | 1803 | $country = wpinv_default_billing_country(); |
1804 | 1804 | } |
1805 | 1805 | |
1806 | - if ( !$is_digital && $no_vat ) { |
|
1806 | + if (!$is_digital && $no_vat) { |
|
1807 | 1807 | return; |
1808 | 1808 | } |
1809 | 1809 | |
1810 | - $vat_data = array( 'company' => '', 'number' => '', 'valid' => false ); |
|
1810 | + $vat_data = array('company' => '', 'number' => '', 'valid' => false); |
|
1811 | 1811 | |
1812 | 1812 | $ip_country_code = self::get_country_by_ip(); |
1813 | - $is_eu_state = self::is_eu_state( $country ); |
|
1814 | - $is_eu_state_ip = self::is_eu_state( $ip_country_code ); |
|
1813 | + $is_eu_state = self::is_eu_state($country); |
|
1814 | + $is_eu_state_ip = self::is_eu_state($ip_country_code); |
|
1815 | 1815 | $is_non_eu_user = !$is_eu_state && !$is_eu_state_ip; |
1816 | 1816 | |
1817 | - if ( $is_digital && !$is_non_eu_user && empty( $vat_number ) && apply_filters( 'wpinv_checkout_requires_country', true, $amount ) ) { |
|
1817 | + if ($is_digital && !$is_non_eu_user && empty($vat_number) && apply_filters('wpinv_checkout_requires_country', true, $amount)) { |
|
1818 | 1818 | $vat_data['adddress_confirmed'] = false; |
1819 | 1819 | |
1820 | - if ( !isset( $_POST['wpinv_adddress_confirmed'] ) ) { |
|
1821 | - if ( $ip_country_code != $country ) { |
|
1822 | - 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>' ) ); |
|
1820 | + if (!isset($_POST['wpinv_adddress_confirmed'])) { |
|
1821 | + if ($ip_country_code != $country) { |
|
1822 | + 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>')); |
|
1823 | 1823 | } |
1824 | 1824 | } else { |
1825 | 1825 | $vat_data['adddress_confirmed'] = true; |
1826 | 1826 | } |
1827 | 1827 | } |
1828 | 1828 | |
1829 | - if ( !empty( $wpinv_options['vat_prevent_b2c_purchase'] ) && !$is_non_eu_user && ( empty( $vat_number ) || $no_vat ) ) { |
|
1830 | - if ( $is_eu_state ) { |
|
1831 | - 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 ) ); |
|
1832 | - } else if ( $is_digital && $is_eu_state_ip ) { |
|
1833 | - wpinv_set_error( 'vat_validation', wp_sprintf( __( 'Sales to non-EU countries cannot be completed because %s must be applied.', 'invoicing' ), $vat_name ) ); |
|
1829 | + if (!empty($wpinv_options['vat_prevent_b2c_purchase']) && !$is_non_eu_user && (empty($vat_number) || $no_vat)) { |
|
1830 | + if ($is_eu_state) { |
|
1831 | + 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)); |
|
1832 | + } else if ($is_digital && $is_eu_state_ip) { |
|
1833 | + wpinv_set_error('vat_validation', wp_sprintf(__('Sales to non-EU countries cannot be completed because %s must be applied.', 'invoicing'), $vat_name)); |
|
1834 | 1834 | } |
1835 | 1835 | } |
1836 | 1836 | |
1837 | - if ( !$is_eu_state || $no_vat || empty( $vat_number ) ) { |
|
1837 | + if (!$is_eu_state || $no_vat || empty($vat_number)) { |
|
1838 | 1838 | return; |
1839 | 1839 | } |
1840 | 1840 | |
1841 | - if ( !empty( $vat_saved ) && isset( $vat_saved['valid'] ) ) { |
|
1842 | - $vat_data['valid'] = $vat_saved['valid']; |
|
1841 | + if (!empty($vat_saved) && isset($vat_saved['valid'])) { |
|
1842 | + $vat_data['valid'] = $vat_saved['valid']; |
|
1843 | 1843 | } |
1844 | 1844 | |
1845 | - if ( $company !== null ) { |
|
1845 | + if ($company !== null) { |
|
1846 | 1846 | $vat_data['company'] = $company; |
1847 | 1847 | } |
1848 | 1848 | |
1849 | 1849 | $message = ''; |
1850 | - if ( $vat_number !== null ) { |
|
1850 | + if ($vat_number !== null) { |
|
1851 | 1851 | $vat_data['number'] = $vat_number; |
1852 | 1852 | |
1853 | - if ( !$vat_data['valid'] || ( $vat_saved['number'] !== $vat_data['number'] ) || ( $vat_saved['company'] !== $vat_data['company'] ) ) { |
|
1854 | - if ( !empty( $wpinv_options['vat_vies_check'] ) ) { |
|
1855 | - if ( empty( $wpinv_options['vat_offline_check'] ) && !self::offline_check( $vat_number ) ) { |
|
1853 | + if (!$vat_data['valid'] || ($vat_saved['number'] !== $vat_data['number']) || ($vat_saved['company'] !== $vat_data['company'])) { |
|
1854 | + if (!empty($wpinv_options['vat_vies_check'])) { |
|
1855 | + if (empty($wpinv_options['vat_offline_check']) && !self::offline_check($vat_number)) { |
|
1856 | 1856 | $vat_data['valid'] = false; |
1857 | 1857 | } |
1858 | 1858 | } else { |
1859 | - $result = self::check_vat( $vat_number ); |
|
1859 | + $result = self::check_vat($vat_number); |
|
1860 | 1860 | |
1861 | - if ( !empty( $result['valid'] ) ) { |
|
1861 | + if (!empty($result['valid'])) { |
|
1862 | 1862 | $vat_data['valid'] = true; |
1863 | - $vies_company = !empty( $result['company'] ) ? $result['company'] : ''; |
|
1864 | - $vies_company = apply_filters( 'wpinv_vies_company_name', $vies_company ); |
|
1863 | + $vies_company = !empty($result['company']) ? $result['company'] : ''; |
|
1864 | + $vies_company = apply_filters('wpinv_vies_company_name', $vies_company); |
|
1865 | 1865 | |
1866 | - $valid_company = $vies_company && $company && ( $vies_company == '---' || strcasecmp( trim( $vies_company ), trim( $company ) ) == 0 ) ? true : false; |
|
1866 | + $valid_company = $vies_company && $company && ($vies_company == '---' || strcasecmp(trim($vies_company), trim($company)) == 0) ? true : false; |
|
1867 | 1867 | |
1868 | - if ( !( !empty( $wpinv_options['vat_disable_company_name_check'] ) || $valid_company ) ) { |
|
1868 | + if (!(!empty($wpinv_options['vat_disable_company_name_check']) || $valid_company)) { |
|
1869 | 1869 | $vat_data['valid'] = false; |
1870 | 1870 | |
1871 | - $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 | + $message = wp_sprintf(__('The company name associated with the %s number provided is not the same as the company name provided.', 'invoicing'), $vat_name); |
|
1872 | 1872 | } |
1873 | 1873 | } else { |
1874 | - $message = wp_sprintf( __( 'Fail to validate the %s number: EU Commission VAT server (VIES) check fails.', 'invoicing' ), $vat_name ); |
|
1874 | + $message = wp_sprintf(__('Fail to validate the %s number: EU Commission VAT server (VIES) check fails.', 'invoicing'), $vat_name); |
|
1875 | 1875 | } |
1876 | 1876 | } |
1877 | 1877 | |
1878 | - if ( !$vat_data['valid'] ) { |
|
1879 | - $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 . ' )' : '' ); |
|
1880 | - wpinv_set_error( 'vat_validation', $error ); |
|
1878 | + if (!$vat_data['valid']) { |
|
1879 | + $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 . ' )' : ''); |
|
1880 | + wpinv_set_error('vat_validation', $error); |
|
1881 | 1881 | } |
1882 | 1882 | } |
1883 | 1883 | } |
1884 | 1884 | |
1885 | - $wpi_session->set( 'user_vat_data', $vat_data ); |
|
1885 | + $wpi_session->set('user_vat_data', $vat_data); |
|
1886 | 1886 | } |
1887 | 1887 | |
1888 | - public static function checkout_vat_fields( $billing_details ) { |
|
1888 | + public static function checkout_vat_fields($billing_details) { |
|
1889 | 1889 | global $wpi_session, $wpinv_options, $wpi_country, $wpi_requires_vat; |
1890 | 1890 | |
1891 | 1891 | $ip_address = wpinv_get_ip(); |
1892 | 1892 | $ip_country_code = self::get_country_by_ip(); |
1893 | 1893 | |
1894 | - $tax_label = __( self::get_vat_name(), 'invoicing' ); |
|
1894 | + $tax_label = __(self::get_vat_name(), 'invoicing'); |
|
1895 | 1895 | $invoice = wpinv_get_invoice_cart(); |
1896 | - $is_digital = self::invoice_has_digital_rule( $invoice ); |
|
1896 | + $is_digital = self::invoice_has_digital_rule($invoice); |
|
1897 | 1897 | $wpi_country = $invoice->country; |
1898 | 1898 | |
1899 | - $requires_vat = !self::hide_vat_fields() && !$invoice->is_free() && self::requires_vat( 0, false, $is_digital ); |
|
1899 | + $requires_vat = !self::hide_vat_fields() && !$invoice->is_free() && self::requires_vat(0, false, $is_digital); |
|
1900 | 1900 | $wpi_requires_vat = $requires_vat; |
1901 | 1901 | |
1902 | 1902 | $company = self::get_user_company(); |
1903 | 1903 | $vat_number = self::get_user_vat_number(); |
1904 | 1904 | |
1905 | - $validated = $vat_number ? self::get_user_vat_number( '', 0, true ) : 1; |
|
1906 | - $vat_info = $wpi_session->get( 'user_vat_data' ); |
|
1905 | + $validated = $vat_number ? self::get_user_vat_number('', 0, true) : 1; |
|
1906 | + $vat_info = $wpi_session->get('user_vat_data'); |
|
1907 | 1907 | |
1908 | - if ( is_array( $vat_info ) ) { |
|
1909 | - $company = isset( $vat_info['company'] ) ? $vat_info['company'] : ''; |
|
1910 | - $vat_number = isset( $vat_info['number'] ) ? $vat_info['number'] : ''; |
|
1911 | - $validated = isset( $vat_info['valid'] ) ? $vat_info['valid'] : false; |
|
1908 | + if (is_array($vat_info)) { |
|
1909 | + $company = isset($vat_info['company']) ? $vat_info['company'] : ''; |
|
1910 | + $vat_number = isset($vat_info['number']) ? $vat_info['number'] : ''; |
|
1911 | + $validated = isset($vat_info['valid']) ? $vat_info['valid'] : false; |
|
1912 | 1912 | } |
1913 | 1913 | |
1914 | 1914 | $selected_country = $invoice->country ? $invoice->country : wpinv_default_billing_country(); |
1915 | 1915 | |
1916 | - if ( $ip_country_code == 'UK' ) { |
|
1916 | + if ($ip_country_code == 'UK') { |
|
1917 | 1917 | $ip_country_code = 'GB'; |
1918 | 1918 | } |
1919 | 1919 | |
1920 | - if ( $selected_country == 'UK' ) { |
|
1920 | + if ($selected_country == 'UK') { |
|
1921 | 1921 | $selected_country = 'GB'; |
1922 | 1922 | } |
1923 | 1923 | |
1924 | - if ( $requires_vat && ( self::same_country_rule() == 'no' && wpinv_is_base_country( $selected_country ) || !self::allow_vat_rules() ) ) { |
|
1924 | + if ($requires_vat && (self::same_country_rule() == 'no' && wpinv_is_base_country($selected_country) || !self::allow_vat_rules())) { |
|
1925 | 1925 | $requires_vat = false; |
1926 | 1926 | } |
1927 | 1927 | |
@@ -1929,52 +1929,52 @@ discard block |
||
1929 | 1929 | $display_validate_btn = 'none'; |
1930 | 1930 | $display_reset_btn = 'none'; |
1931 | 1931 | |
1932 | - if ( !empty( $vat_number ) && $validated ) { |
|
1933 | - $vat_vailidated_text = wp_sprintf( __( '%s number validated', 'invoicing' ), $tax_label ); |
|
1932 | + if (!empty($vat_number) && $validated) { |
|
1933 | + $vat_vailidated_text = wp_sprintf(__('%s number validated', 'invoicing'), $tax_label); |
|
1934 | 1934 | $vat_vailidated_class = 'wpinv-vat-stat-1'; |
1935 | 1935 | $display_reset_btn = 'block'; |
1936 | 1936 | } else { |
1937 | - $vat_vailidated_text = empty( $vat_number ) ? '' : wp_sprintf( __( '%s number not validated', 'invoicing' ), $tax_label ); |
|
1938 | - $vat_vailidated_class = empty( $vat_number ) ? '' : 'wpinv-vat-stat-0'; |
|
1937 | + $vat_vailidated_text = empty($vat_number) ? '' : wp_sprintf(__('%s number not validated', 'invoicing'), $tax_label); |
|
1938 | + $vat_vailidated_class = empty($vat_number) ? '' : 'wpinv-vat-stat-0'; |
|
1939 | 1939 | $display_validate_btn = 'block'; |
1940 | 1940 | } |
1941 | 1941 | |
1942 | - $show_ip_country = $is_digital && ( empty( $vat_number ) || !$requires_vat ) && $ip_country_code != $selected_country ? 'block' : 'none'; |
|
1942 | + $show_ip_country = $is_digital && (empty($vat_number) || !$requires_vat) && $ip_country_code != $selected_country ? 'block' : 'none'; |
|
1943 | 1943 | ?> |
1944 | 1944 | <div id="wpi-vat-details" class="wpi-vat-details clearfix" style="display:<?php echo $display_vat_details; ?>"> |
1945 | 1945 | <div id="wpi_vat_info" class="clearfix panel panel-default"> |
1946 | - <div class="panel-heading"><h3 class="panel-title"><?php echo wp_sprintf( __( '%s Details', 'invoicing' ), $tax_label );?></h3></div> |
|
1946 | + <div class="panel-heading"><h3 class="panel-title"><?php echo wp_sprintf(__('%s Details', 'invoicing'), $tax_label); ?></h3></div> |
|
1947 | 1947 | <div id="wpinv-fields-box" class="panel-body"> |
1948 | 1948 | <p id="wpi_show_vat_note"> |
1949 | - <?php echo wp_sprintf( __( 'Validate your registered %s number to exclude tax.', 'invoicing' ), $tax_label ); ?> |
|
1949 | + <?php echo wp_sprintf(__('Validate your registered %s number to exclude tax.', 'invoicing'), $tax_label); ?> |
|
1950 | 1950 | </p> |
1951 | 1951 | <div id="wpi_vat_fields" class="wpi_vat_info"> |
1952 | 1952 | <p class="wpi-cart-field wpi-col2 wpi-colf"> |
1953 | - <label for="wpinv_company" class="wpi-label"><?php _e( 'Company Name', 'invoicing' );?></label> |
|
1953 | + <label for="wpinv_company" class="wpi-label"><?php _e('Company Name', 'invoicing'); ?></label> |
|
1954 | 1954 | <?php |
1955 | - echo wpinv_html_text( array( |
|
1955 | + echo wpinv_html_text(array( |
|
1956 | 1956 | 'id' => 'wpinv_company', |
1957 | 1957 | 'name' => 'wpinv_company', |
1958 | 1958 | 'value' => $company, |
1959 | 1959 | 'class' => 'wpi-input form-control', |
1960 | - 'placeholder' => __( 'Company name', 'invoicing' ), |
|
1961 | - ) ); |
|
1960 | + 'placeholder' => __('Company name', 'invoicing'), |
|
1961 | + )); |
|
1962 | 1962 | ?> |
1963 | 1963 | </p> |
1964 | 1964 | <p class="wpi-cart-field wpi-col2 wpi-coll wpi-cart-field-vat"> |
1965 | - <label for="wpinv_vat_number" class="wpi-label"><?php echo wp_sprintf( __( '%s Number', 'invoicing' ), $tax_label );?></label> |
|
1965 | + <label for="wpinv_vat_number" class="wpi-label"><?php echo wp_sprintf(__('%s Number', 'invoicing'), $tax_label); ?></label> |
|
1966 | 1966 | <span id="wpinv_vat_number-wrap"> |
1967 | 1967 | <label for="wpinv_vat_number" class="wpinv-label"></label> |
1968 | - <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"> |
|
1969 | - <span class="wpinv-vat-stat <?php echo $vat_vailidated_class;?>"><i class="fa"></i> <font><?php echo $vat_vailidated_text;?></font></span> |
|
1968 | + <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"> |
|
1969 | + <span class="wpinv-vat-stat <?php echo $vat_vailidated_class; ?>"><i class="fa"></i> <font><?php echo $vat_vailidated_text; ?></font></span> |
|
1970 | 1970 | </span> |
1971 | 1971 | </p> |
1972 | 1972 | <p class="wpi-cart-field wpi-col wpi-colf wpi-cart-field-actions"> |
1973 | - <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> |
|
1974 | - <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> |
|
1973 | + <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> |
|
1974 | + <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> |
|
1975 | 1975 | <span class="wpi-vat-box wpi-vat-box-info"><span id="text"></span></span> |
1976 | 1976 | <span class="wpi-vat-box wpi-vat-box-error"><span id="text"></span></span> |
1977 | - <input type="hidden" name="_wpi_nonce" value="<?php echo wp_create_nonce( 'vat_validation' ) ?>" /> |
|
1977 | + <input type="hidden" name="_wpi_nonce" value="<?php echo wp_create_nonce('vat_validation') ?>" /> |
|
1978 | 1978 | </p> |
1979 | 1979 | </div> |
1980 | 1980 | </div> |
@@ -1988,32 +1988,32 @@ discard block |
||
1988 | 1988 | </span> |
1989 | 1989 | </div> |
1990 | 1990 | </div> |
1991 | - <?php if ( empty( $wpinv_options['hide_ip_address'] ) ) { |
|
1992 | - $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>'; |
|
1991 | + <?php if (empty($wpinv_options['hide_ip_address'])) { |
|
1992 | + $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>'; |
|
1993 | 1993 | ?> |
1994 | 1994 | <div class="wpi-ip-info clearfix panel panel-info"> |
1995 | 1995 | <div id="wpinv-fields-box" class="panel-body"> |
1996 | - <span><?php echo wp_sprintf( __( "Your IP address is: %s", 'invoicing' ), $ip_link ); ?></span> |
|
1996 | + <span><?php echo wp_sprintf(__("Your IP address is: %s", 'invoicing'), $ip_link); ?></span> |
|
1997 | 1997 | </div> |
1998 | 1998 | </div> |
1999 | 1999 | <?php } |
2000 | 2000 | } |
2001 | 2001 | |
2002 | - public static function show_vat_notice( $invoice ) { |
|
2003 | - if ( empty( $invoice ) ) { |
|
2002 | + public static function show_vat_notice($invoice) { |
|
2003 | + if (empty($invoice)) { |
|
2004 | 2004 | return NULL; |
2005 | 2005 | } |
2006 | 2006 | |
2007 | - $label = wpinv_get_option( 'vat_invoice_notice_label' ); |
|
2008 | - $notice = wpinv_get_option( 'vat_invoice_notice' ); |
|
2009 | - if ( $label || $notice ) { |
|
2007 | + $label = wpinv_get_option('vat_invoice_notice_label'); |
|
2008 | + $notice = wpinv_get_option('vat_invoice_notice'); |
|
2009 | + if ($label || $notice) { |
|
2010 | 2010 | ?> |
2011 | 2011 | <div class="row wpinv-vat-notice"> |
2012 | 2012 | <div class="col-sm-12"> |
2013 | - <?php if ( $label ) { ?> |
|
2014 | - <strong><?php _e( $label, 'invoicing' ); ?></strong> |
|
2015 | - <?php } if ( $notice ) { ?> |
|
2016 | - <?php echo wpautop( wptexturize( __( $notice, 'invoicing' ) ) ) ?> |
|
2013 | + <?php if ($label) { ?> |
|
2014 | + <strong><?php _e($label, 'invoicing'); ?></strong> |
|
2015 | + <?php } if ($notice) { ?> |
|
2016 | + <?php echo wpautop(wptexturize(__($notice, 'invoicing'))) ?> |
|
2017 | 2017 | <?php } ?> |
2018 | 2018 | </div> |
2019 | 2019 | </div> |
@@ -324,12 +324,18 @@ discard block |
||
324 | 324 | return apply_filters( 'wpinv_get_discount_code', $code, $code_id ); |
325 | 325 | } |
326 | 326 | |
327 | +/** |
|
328 | + * @return string |
|
329 | + */ |
|
327 | 330 | function wpinv_get_discount_start_date( $code_id = null ) { |
328 | 331 | $start_date = get_post_meta( $code_id, '_wpi_discount_start', true ); |
329 | 332 | |
330 | 333 | return apply_filters( 'wpinv_get_discount_start_date', $start_date, $code_id ); |
331 | 334 | } |
332 | 335 | |
336 | +/** |
|
337 | + * @return string |
|
338 | + */ |
|
333 | 339 | function wpinv_get_discount_expiration( $code_id = null ) { |
334 | 340 | $expiration = get_post_meta( $code_id, '_wpi_discount_expiration', true ); |
335 | 341 | |
@@ -652,6 +658,9 @@ discard block |
||
652 | 658 | return (bool) apply_filters( 'wpinv_is_discount_item_req_met', $ret, $code_id, $condition ); |
653 | 659 | } |
654 | 660 | |
661 | +/** |
|
662 | + * @param string $code |
|
663 | + */ |
|
655 | 664 | function wpinv_is_discount_used( $code = null, $user = '', $code_id = 0 ) { |
656 | 665 | global $wpi_checkout_id; |
657 | 666 | |
@@ -817,6 +826,9 @@ discard block |
||
817 | 826 | |
818 | 827 | } |
819 | 828 | |
829 | +/** |
|
830 | + * @param double $amount |
|
831 | + */ |
|
820 | 832 | function wpinv_format_discount_rate( $type, $amount ) { |
821 | 833 | if ( $type == 'flat' ) { |
822 | 834 | return wpinv_price( wpinv_format_amount( $amount ) ); |
@@ -861,6 +873,9 @@ discard block |
||
861 | 873 | return $discounts; |
862 | 874 | } |
863 | 875 | |
876 | +/** |
|
877 | + * @return boolean |
|
878 | + */ |
|
864 | 879 | function wpinv_unset_cart_discount( $code = '' ) { |
865 | 880 | $discounts = wpinv_get_cart_discounts(); |
866 | 881 | |
@@ -1175,6 +1190,9 @@ discard block |
||
1175 | 1190 | } |
1176 | 1191 | //add_action( 'init', 'wpinv_apply_preset_discount', 999 ); |
1177 | 1192 | |
1193 | +/** |
|
1194 | + * @param integer $code |
|
1195 | + */ |
|
1178 | 1196 | function wpinv_get_discount_label( $code, $echo = true ) { |
1179 | 1197 | $label = wp_sprintf( __( 'Discount%1$s', 'invoicing' ), ( $code != '' && $code != 'none' ? ' (<code>' . $code . '</code>)': '' ) ); |
1180 | 1198 | $label = apply_filters( 'wpinv_get_discount_label', $label, $code ); |
@@ -887,8 +887,8 @@ |
||
887 | 887 | if ( !empty( $data ) && isset( $data['cart_discounts'] ) ) { |
888 | 888 | unset( $data['cart_discounts'] ); |
889 | 889 | |
890 | - wpinv_set_checkout_session( $data ); |
|
891 | - return true; |
|
890 | + wpinv_set_checkout_session( $data ); |
|
891 | + return true; |
|
892 | 892 | } |
893 | 893 | |
894 | 894 | return false; |
@@ -7,90 +7,90 @@ discard block |
||
7 | 7 | */ |
8 | 8 | |
9 | 9 | // MUST have WordPress. |
10 | -if ( !defined( 'WPINC' ) ) { |
|
11 | - exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) ); |
|
10 | +if (!defined('WPINC')) { |
|
11 | + exit('Do NOT access this file directly: ' . basename(__FILE__)); |
|
12 | 12 | } |
13 | 13 | |
14 | 14 | function wpinv_get_discount_types() { |
15 | 15 | $discount_types = array( |
16 | - 'percent' => __( 'Percentage', 'invoicing' ), |
|
17 | - 'flat' => __( 'Flat Amount', 'invoicing' ), |
|
16 | + 'percent' => __('Percentage', 'invoicing'), |
|
17 | + 'flat' => __('Flat Amount', 'invoicing'), |
|
18 | 18 | ); |
19 | - return (array)apply_filters( 'wpinv_discount_types', $discount_types ); |
|
19 | + return (array)apply_filters('wpinv_discount_types', $discount_types); |
|
20 | 20 | } |
21 | 21 | |
22 | -function wpinv_get_discount_type_name( $type = '' ) { |
|
22 | +function wpinv_get_discount_type_name($type = '') { |
|
23 | 23 | $types = wpinv_get_discount_types(); |
24 | - return isset( $types[ $type ] ) ? $types[ $type ] : ''; |
|
24 | + return isset($types[$type]) ? $types[$type] : ''; |
|
25 | 25 | } |
26 | 26 | |
27 | -function wpinv_delete_discount( $data ) { |
|
28 | - if ( ! isset( $data['_wpnonce'] ) || ! wp_verify_nonce( $data['_wpnonce'], 'wpinv_discount_nonce' ) ) { |
|
29 | - wp_die( __( 'Trying to cheat or something?', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
27 | +function wpinv_delete_discount($data) { |
|
28 | + if (!isset($data['_wpnonce']) || !wp_verify_nonce($data['_wpnonce'], 'wpinv_discount_nonce')) { |
|
29 | + wp_die(__('Trying to cheat or something?', 'invoicing'), __('Error', 'invoicing'), array('response' => 403)); |
|
30 | 30 | } |
31 | 31 | |
32 | - if( ! current_user_can( 'manage_options' ) ) { |
|
33 | - wp_die( __( 'You do not have permission to delete discount codes', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
32 | + if (!current_user_can('manage_options')) { |
|
33 | + wp_die(__('You do not have permission to delete discount codes', 'invoicing'), __('Error', 'invoicing'), array('response' => 403)); |
|
34 | 34 | } |
35 | 35 | |
36 | 36 | $discount_id = $data['discount']; |
37 | - wpinv_remove_discount( $discount_id ); |
|
37 | + wpinv_remove_discount($discount_id); |
|
38 | 38 | } |
39 | -add_action( 'wpinv_delete_discount', 'wpinv_delete_discount' ); |
|
39 | +add_action('wpinv_delete_discount', 'wpinv_delete_discount'); |
|
40 | 40 | |
41 | -function wpinv_activate_discount( $data ) { |
|
42 | - if ( ! isset( $data['_wpnonce'] ) || ! wp_verify_nonce( $data['_wpnonce'], 'wpinv_discount_nonce' ) ) { |
|
43 | - wp_die( __( 'Trying to cheat or something?', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
41 | +function wpinv_activate_discount($data) { |
|
42 | + if (!isset($data['_wpnonce']) || !wp_verify_nonce($data['_wpnonce'], 'wpinv_discount_nonce')) { |
|
43 | + wp_die(__('Trying to cheat or something?', 'invoicing'), __('Error', 'invoicing'), array('response' => 403)); |
|
44 | 44 | } |
45 | 45 | |
46 | - if( ! current_user_can( 'manage_options' ) ) { |
|
47 | - wp_die( __( 'You do not have permission to edit discount codes', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
46 | + if (!current_user_can('manage_options')) { |
|
47 | + wp_die(__('You do not have permission to edit discount codes', 'invoicing'), __('Error', 'invoicing'), array('response' => 403)); |
|
48 | 48 | } |
49 | 49 | |
50 | - $id = absint( $data['discount'] ); |
|
51 | - wpinv_update_discount_status( $id, 'publish' ); |
|
50 | + $id = absint($data['discount']); |
|
51 | + wpinv_update_discount_status($id, 'publish'); |
|
52 | 52 | } |
53 | -add_action( 'wpinv_activate_discount', 'wpinv_activate_discount' ); |
|
53 | +add_action('wpinv_activate_discount', 'wpinv_activate_discount'); |
|
54 | 54 | |
55 | -function wpinv_deactivate_discount( $data ) { |
|
56 | - if ( ! isset( $data['_wpnonce'] ) || ! wp_verify_nonce( $data['_wpnonce'], 'wpinv_discount_nonce' ) ) { |
|
57 | - wp_die( __( 'Trying to cheat or something?', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
55 | +function wpinv_deactivate_discount($data) { |
|
56 | + if (!isset($data['_wpnonce']) || !wp_verify_nonce($data['_wpnonce'], 'wpinv_discount_nonce')) { |
|
57 | + wp_die(__('Trying to cheat or something?', 'invoicing'), __('Error', 'invoicing'), array('response' => 403)); |
|
58 | 58 | } |
59 | 59 | |
60 | - if( ! current_user_can( 'manage_options' ) ) { |
|
61 | - wp_die( __( 'You do not have permission to create discount codes', 'invoicing' ), array( 'response' => 403 ) ); |
|
60 | + if (!current_user_can('manage_options')) { |
|
61 | + wp_die(__('You do not have permission to create discount codes', 'invoicing'), array('response' => 403)); |
|
62 | 62 | } |
63 | 63 | |
64 | - $id = absint( $data['discount'] ); |
|
65 | - wpinv_update_discount_status( $id, 'pending' ); |
|
64 | + $id = absint($data['discount']); |
|
65 | + wpinv_update_discount_status($id, 'pending'); |
|
66 | 66 | } |
67 | -add_action( 'wpinv_deactivate_discount', 'wpinv_deactivate_discount' ); |
|
67 | +add_action('wpinv_deactivate_discount', 'wpinv_deactivate_discount'); |
|
68 | 68 | |
69 | -function wpinv_get_discounts( $args = array() ) { |
|
69 | +function wpinv_get_discounts($args = array()) { |
|
70 | 70 | $defaults = array( |
71 | 71 | 'post_type' => 'wpi_discount', |
72 | 72 | 'posts_per_page' => 20, |
73 | 73 | 'paged' => null, |
74 | - 'post_status' => array( 'publish', 'pending', 'draft', 'expired' ) |
|
74 | + 'post_status' => array('publish', 'pending', 'draft', 'expired') |
|
75 | 75 | ); |
76 | 76 | |
77 | - $args = wp_parse_args( $args, $defaults ); |
|
77 | + $args = wp_parse_args($args, $defaults); |
|
78 | 78 | |
79 | - $discounts = get_posts( $args ); |
|
79 | + $discounts = get_posts($args); |
|
80 | 80 | |
81 | - if ( $discounts ) { |
|
81 | + if ($discounts) { |
|
82 | 82 | return $discounts; |
83 | 83 | } |
84 | 84 | |
85 | - if( ! $discounts && ! empty( $args['s'] ) ) { |
|
85 | + if (!$discounts && !empty($args['s'])) { |
|
86 | 86 | $args['meta_key'] = '_wpi_discount_code'; |
87 | 87 | $args['meta_value'] = $args['s']; |
88 | 88 | $args['meta_compare'] = 'LIKE'; |
89 | - unset( $args['s'] ); |
|
90 | - $discounts = get_posts( $args ); |
|
89 | + unset($args['s']); |
|
90 | + $discounts = get_posts($args); |
|
91 | 91 | } |
92 | 92 | |
93 | - if( $discounts ) { |
|
93 | + if ($discounts) { |
|
94 | 94 | return $discounts; |
95 | 95 | } |
96 | 96 | |
@@ -102,9 +102,9 @@ discard block |
||
102 | 102 | |
103 | 103 | $discounts = wpinv_get_discounts(); |
104 | 104 | |
105 | - if ( $discounts) { |
|
106 | - foreach ( $discounts as $discount ) { |
|
107 | - if ( wpinv_is_discount_active( $discount->ID ) ) { |
|
105 | + if ($discounts) { |
|
106 | + foreach ($discounts as $discount) { |
|
107 | + if (wpinv_is_discount_active($discount->ID)) { |
|
108 | 108 | $has_active = true; |
109 | 109 | break; |
110 | 110 | } |
@@ -113,38 +113,38 @@ discard block |
||
113 | 113 | return $has_active; |
114 | 114 | } |
115 | 115 | |
116 | -function wpinv_get_discount( $discount_id = 0 ) { |
|
117 | - if( empty( $discount_id ) ) { |
|
116 | +function wpinv_get_discount($discount_id = 0) { |
|
117 | + if (empty($discount_id)) { |
|
118 | 118 | return false; |
119 | 119 | } |
120 | 120 | |
121 | - if ( get_post_type( $discount_id ) != 'wpi_discount' ) { |
|
121 | + if (get_post_type($discount_id) != 'wpi_discount') { |
|
122 | 122 | return false; |
123 | 123 | } |
124 | 124 | |
125 | - $discount = get_post( $discount_id ); |
|
125 | + $discount = get_post($discount_id); |
|
126 | 126 | |
127 | 127 | return $discount; |
128 | 128 | } |
129 | 129 | |
130 | -function wpinv_get_discount_by_code( $code = '' ) { |
|
131 | - if( empty( $code ) || ! is_string( $code ) ) { |
|
130 | +function wpinv_get_discount_by_code($code = '') { |
|
131 | + if (empty($code) || !is_string($code)) { |
|
132 | 132 | return false; |
133 | 133 | } |
134 | 134 | |
135 | - return wpinv_get_discount_by( 'code', $code ); |
|
135 | + return wpinv_get_discount_by('code', $code); |
|
136 | 136 | } |
137 | 137 | |
138 | -function wpinv_get_discount_by( $field = '', $value = '' ) { |
|
139 | - if( empty( $field ) || empty( $value ) ) { |
|
138 | +function wpinv_get_discount_by($field = '', $value = '') { |
|
139 | + if (empty($field) || empty($value)) { |
|
140 | 140 | return false; |
141 | 141 | } |
142 | 142 | |
143 | - if( ! is_string( $field ) ) { |
|
143 | + if (!is_string($field)) { |
|
144 | 144 | return false; |
145 | 145 | } |
146 | 146 | |
147 | - switch( strtolower( $field ) ) { |
|
147 | + switch (strtolower($field)) { |
|
148 | 148 | |
149 | 149 | case 'code': |
150 | 150 | $meta_query = array(); |
@@ -154,32 +154,32 @@ discard block |
||
154 | 154 | 'compare' => '=' |
155 | 155 | ); |
156 | 156 | |
157 | - $discount = wpinv_get_discounts( array( |
|
157 | + $discount = wpinv_get_discounts(array( |
|
158 | 158 | 'posts_per_page' => 1, |
159 | 159 | 'post_status' => 'any', |
160 | 160 | 'meta_query' => $meta_query, |
161 | - ) ); |
|
161 | + )); |
|
162 | 162 | |
163 | - if( $discount ) { |
|
163 | + if ($discount) { |
|
164 | 164 | $discount = $discount[0]; |
165 | 165 | } |
166 | 166 | |
167 | 167 | break; |
168 | 168 | |
169 | 169 | case 'id': |
170 | - $discount = wpinv_get_discount( $value ); |
|
170 | + $discount = wpinv_get_discount($value); |
|
171 | 171 | |
172 | 172 | break; |
173 | 173 | |
174 | 174 | case 'name': |
175 | - $discount = get_posts( array( |
|
175 | + $discount = get_posts(array( |
|
176 | 176 | 'post_type' => 'wpi_discount', |
177 | 177 | 'name' => $value, |
178 | 178 | 'posts_per_page' => 1, |
179 | 179 | 'post_status' => 'any' |
180 | - ) ); |
|
180 | + )); |
|
181 | 181 | |
182 | - if( $discount ) { |
|
182 | + if ($discount) { |
|
183 | 183 | $discount = $discount[0]; |
184 | 184 | } |
185 | 185 | |
@@ -189,96 +189,96 @@ discard block |
||
189 | 189 | return false; |
190 | 190 | } |
191 | 191 | |
192 | - if( ! empty( $discount ) ) { |
|
192 | + if (!empty($discount)) { |
|
193 | 193 | return $discount; |
194 | 194 | } |
195 | 195 | |
196 | 196 | return false; |
197 | 197 | } |
198 | 198 | |
199 | -function wpinv_store_discount( $post_id, $data, $post, $update = false ) { |
|
199 | +function wpinv_store_discount($post_id, $data, $post, $update = false) { |
|
200 | 200 | $meta = array( |
201 | - 'code' => isset( $data['code'] ) ? sanitize_text_field( $data['code'] ) : '', |
|
202 | - 'type' => isset( $data['type'] ) ? sanitize_text_field( $data['type'] ) : 'percent', |
|
203 | - 'amount' => isset( $data['amount'] ) ? wpinv_sanitize_amount( $data['amount'] ) : '', |
|
204 | - 'start' => isset( $data['start'] ) ? sanitize_text_field( $data['start'] ) : '', |
|
205 | - 'expiration' => isset( $data['expiration'] ) ? sanitize_text_field( $data['expiration'] ) : '', |
|
206 | - 'min_total' => isset( $data['min_total'] ) ? wpinv_sanitize_amount( $data['min_total'] ) : '', |
|
207 | - 'max_total' => isset( $data['max_total'] ) ? wpinv_sanitize_amount( $data['max_total'] ) : '', |
|
208 | - 'max_uses' => isset( $data['max_uses'] ) ? absint( $data['max_uses'] ) : '', |
|
209 | - 'items' => isset( $data['items'] ) ? $data['items'] : array(), |
|
210 | - 'excluded_items' => isset( $data['excluded_items'] ) ? $data['excluded_items'] : array(), |
|
211 | - 'is_recurring' => isset( $data['recurring'] ) ? (bool)$data['recurring'] : false, |
|
212 | - 'is_single_use' => isset( $data['single_use'] ) ? (bool)$data['single_use'] : false, |
|
213 | - 'uses' => isset( $data['uses'] ) ? (int)$data['uses'] : false, |
|
201 | + 'code' => isset($data['code']) ? sanitize_text_field($data['code']) : '', |
|
202 | + 'type' => isset($data['type']) ? sanitize_text_field($data['type']) : 'percent', |
|
203 | + 'amount' => isset($data['amount']) ? wpinv_sanitize_amount($data['amount']) : '', |
|
204 | + 'start' => isset($data['start']) ? sanitize_text_field($data['start']) : '', |
|
205 | + 'expiration' => isset($data['expiration']) ? sanitize_text_field($data['expiration']) : '', |
|
206 | + 'min_total' => isset($data['min_total']) ? wpinv_sanitize_amount($data['min_total']) : '', |
|
207 | + 'max_total' => isset($data['max_total']) ? wpinv_sanitize_amount($data['max_total']) : '', |
|
208 | + 'max_uses' => isset($data['max_uses']) ? absint($data['max_uses']) : '', |
|
209 | + 'items' => isset($data['items']) ? $data['items'] : array(), |
|
210 | + 'excluded_items' => isset($data['excluded_items']) ? $data['excluded_items'] : array(), |
|
211 | + 'is_recurring' => isset($data['recurring']) ? (bool)$data['recurring'] : false, |
|
212 | + 'is_single_use' => isset($data['single_use']) ? (bool)$data['single_use'] : false, |
|
213 | + 'uses' => isset($data['uses']) ? (int)$data['uses'] : false, |
|
214 | 214 | ); |
215 | 215 | |
216 | - if ( $meta['type'] == 'percent' && (float)$meta['amount'] > 100 ) { |
|
216 | + if ($meta['type'] == 'percent' && (float)$meta['amount'] > 100) { |
|
217 | 217 | $meta['amount'] = 100; |
218 | 218 | } |
219 | 219 | |
220 | - if ( !empty( $meta['start'] ) ) { |
|
221 | - $meta['start'] = date_i18n( 'Y-m-d H:i:s', strtotime( $meta['start'] ) ); |
|
220 | + if (!empty($meta['start'])) { |
|
221 | + $meta['start'] = date_i18n('Y-m-d H:i:s', strtotime($meta['start'])); |
|
222 | 222 | } |
223 | 223 | |
224 | - if ( !empty( $meta['expiration'] ) ) { |
|
225 | - $meta['expiration'] = date_i18n( 'Y-m-d H:i:s', strtotime( $meta['expiration'] ) ); |
|
224 | + if (!empty($meta['expiration'])) { |
|
225 | + $meta['expiration'] = date_i18n('Y-m-d H:i:s', strtotime($meta['expiration'])); |
|
226 | 226 | |
227 | - if ( !empty( $meta['start'] ) && strtotime( $meta['start'] ) > strtotime( $meta['expiration'] ) ) { |
|
227 | + if (!empty($meta['start']) && strtotime($meta['start']) > strtotime($meta['expiration'])) { |
|
228 | 228 | $meta['expiration'] = $meta['start']; |
229 | 229 | } |
230 | 230 | } |
231 | 231 | |
232 | - if ( $meta['uses'] === false ) { |
|
233 | - unset( $meta['uses'] ); |
|
232 | + if ($meta['uses'] === false) { |
|
233 | + unset($meta['uses']); |
|
234 | 234 | } |
235 | 235 | |
236 | - if ( ! empty( $meta['items'] ) ) { |
|
237 | - foreach ( $meta['items'] as $key => $item ) { |
|
238 | - if ( 0 === intval( $item ) ) { |
|
239 | - unset( $meta['items'][ $key ] ); |
|
236 | + if (!empty($meta['items'])) { |
|
237 | + foreach ($meta['items'] as $key => $item) { |
|
238 | + if (0 === intval($item)) { |
|
239 | + unset($meta['items'][$key]); |
|
240 | 240 | } |
241 | 241 | } |
242 | 242 | } |
243 | 243 | |
244 | - if ( ! empty( $meta['excluded_items'] ) ) { |
|
245 | - foreach ( $meta['excluded_items'] as $key => $item ) { |
|
246 | - if ( 0 === intval( $item ) ) { |
|
247 | - unset( $meta['excluded_items'][ $key ] ); |
|
244 | + if (!empty($meta['excluded_items'])) { |
|
245 | + foreach ($meta['excluded_items'] as $key => $item) { |
|
246 | + if (0 === intval($item)) { |
|
247 | + unset($meta['excluded_items'][$key]); |
|
248 | 248 | } |
249 | 249 | } |
250 | 250 | } |
251 | 251 | |
252 | - $meta = apply_filters( 'wpinv_update_discount', $meta, $post_id, $post ); |
|
252 | + $meta = apply_filters('wpinv_update_discount', $meta, $post_id, $post); |
|
253 | 253 | |
254 | - do_action( 'wpinv_pre_update_discount', $meta, $post_id, $post ); |
|
254 | + do_action('wpinv_pre_update_discount', $meta, $post_id, $post); |
|
255 | 255 | |
256 | - foreach( $meta as $key => $value ) { |
|
257 | - update_post_meta( $post_id, '_wpi_discount_' . $key, $value ); |
|
256 | + foreach ($meta as $key => $value) { |
|
257 | + update_post_meta($post_id, '_wpi_discount_' . $key, $value); |
|
258 | 258 | } |
259 | 259 | |
260 | - do_action( 'wpinv_post_update_discount', $meta, $post_id, $post ); |
|
260 | + do_action('wpinv_post_update_discount', $meta, $post_id, $post); |
|
261 | 261 | |
262 | 262 | return $post_id; |
263 | 263 | } |
264 | 264 | |
265 | -function wpinv_remove_discount( $discount_id = 0 ) { |
|
266 | - do_action( 'wpinv_pre_delete_discount', $discount_id ); |
|
265 | +function wpinv_remove_discount($discount_id = 0) { |
|
266 | + do_action('wpinv_pre_delete_discount', $discount_id); |
|
267 | 267 | |
268 | - wp_delete_post( $discount_id, true ); |
|
268 | + wp_delete_post($discount_id, true); |
|
269 | 269 | |
270 | - do_action( 'wpinv_post_delete_discount', $discount_id ); |
|
270 | + do_action('wpinv_post_delete_discount', $discount_id); |
|
271 | 271 | } |
272 | 272 | |
273 | -function wpinv_update_discount_status( $code_id = 0, $new_status = 'publish' ) { |
|
274 | - $discount = wpinv_get_discount( $code_id ); |
|
273 | +function wpinv_update_discount_status($code_id = 0, $new_status = 'publish') { |
|
274 | + $discount = wpinv_get_discount($code_id); |
|
275 | 275 | |
276 | - if ( $discount ) { |
|
277 | - do_action( 'wpinv_pre_update_discount_status', $code_id, $new_status, $discount->post_status ); |
|
276 | + if ($discount) { |
|
277 | + do_action('wpinv_pre_update_discount_status', $code_id, $new_status, $discount->post_status); |
|
278 | 278 | |
279 | - wp_update_post( array( 'ID' => $code_id, 'post_status' => $new_status ) ); |
|
279 | + wp_update_post(array('ID' => $code_id, 'post_status' => $new_status)); |
|
280 | 280 | |
281 | - do_action( 'wpinv_post_update_discount_status', $code_id, $new_status, $discount->post_status ); |
|
281 | + do_action('wpinv_post_update_discount_status', $code_id, $new_status, $discount->post_status); |
|
282 | 282 | |
283 | 283 | return true; |
284 | 284 | } |
@@ -286,173 +286,173 @@ discard block |
||
286 | 286 | return false; |
287 | 287 | } |
288 | 288 | |
289 | -function wpinv_discount_exists( $code_id ) { |
|
290 | - if ( wpinv_get_discount( $code_id ) ) { |
|
289 | +function wpinv_discount_exists($code_id) { |
|
290 | + if (wpinv_get_discount($code_id)) { |
|
291 | 291 | return true; |
292 | 292 | } |
293 | 293 | |
294 | 294 | return false; |
295 | 295 | } |
296 | 296 | |
297 | -function wpinv_is_discount_active( $code_id = null ) { |
|
298 | - $discount = wpinv_get_discount( $code_id ); |
|
297 | +function wpinv_is_discount_active($code_id = null) { |
|
298 | + $discount = wpinv_get_discount($code_id); |
|
299 | 299 | $return = false; |
300 | 300 | |
301 | - if ( $discount ) { |
|
302 | - if ( wpinv_is_discount_expired( $code_id ) ) { |
|
303 | - if( defined( 'DOING_AJAX' ) ) { |
|
304 | - wpinv_set_error( 'wpinv-discount-error', __( 'This discount is expired.', 'invoicing' ) ); |
|
301 | + if ($discount) { |
|
302 | + if (wpinv_is_discount_expired($code_id)) { |
|
303 | + if (defined('DOING_AJAX')) { |
|
304 | + wpinv_set_error('wpinv-discount-error', __('This discount is expired.', 'invoicing')); |
|
305 | 305 | } |
306 | - } elseif ( $discount->post_status == 'publish' ) { |
|
306 | + } elseif ($discount->post_status == 'publish') { |
|
307 | 307 | $return = true; |
308 | 308 | } else { |
309 | - if( defined( 'DOING_AJAX' ) ) { |
|
310 | - wpinv_set_error( 'wpinv-discount-error', __( 'This discount is not active.', 'invoicing' ) ); |
|
309 | + if (defined('DOING_AJAX')) { |
|
310 | + wpinv_set_error('wpinv-discount-error', __('This discount is not active.', 'invoicing')); |
|
311 | 311 | } |
312 | 312 | } |
313 | 313 | } |
314 | 314 | |
315 | - return apply_filters( 'wpinv_is_discount_active', $return, $code_id ); |
|
315 | + return apply_filters('wpinv_is_discount_active', $return, $code_id); |
|
316 | 316 | } |
317 | 317 | |
318 | -function wpinv_get_discount_code( $code_id = null ) { |
|
319 | - $code = get_post_meta( $code_id, '_wpi_discount_code', true ); |
|
318 | +function wpinv_get_discount_code($code_id = null) { |
|
319 | + $code = get_post_meta($code_id, '_wpi_discount_code', true); |
|
320 | 320 | |
321 | - return apply_filters( 'wpinv_get_discount_code', $code, $code_id ); |
|
321 | + return apply_filters('wpinv_get_discount_code', $code, $code_id); |
|
322 | 322 | } |
323 | 323 | |
324 | -function wpinv_get_discount_start_date( $code_id = null ) { |
|
325 | - $start_date = get_post_meta( $code_id, '_wpi_discount_start', true ); |
|
324 | +function wpinv_get_discount_start_date($code_id = null) { |
|
325 | + $start_date = get_post_meta($code_id, '_wpi_discount_start', true); |
|
326 | 326 | |
327 | - return apply_filters( 'wpinv_get_discount_start_date', $start_date, $code_id ); |
|
327 | + return apply_filters('wpinv_get_discount_start_date', $start_date, $code_id); |
|
328 | 328 | } |
329 | 329 | |
330 | -function wpinv_get_discount_expiration( $code_id = null ) { |
|
331 | - $expiration = get_post_meta( $code_id, '_wpi_discount_expiration', true ); |
|
330 | +function wpinv_get_discount_expiration($code_id = null) { |
|
331 | + $expiration = get_post_meta($code_id, '_wpi_discount_expiration', true); |
|
332 | 332 | |
333 | - return apply_filters( 'wpinv_get_discount_expiration', $expiration, $code_id ); |
|
333 | + return apply_filters('wpinv_get_discount_expiration', $expiration, $code_id); |
|
334 | 334 | } |
335 | 335 | |
336 | -function wpinv_get_discount_max_uses( $code_id = null ) { |
|
337 | - $max_uses = get_post_meta( $code_id, '_wpi_discount_max_uses', true ); |
|
336 | +function wpinv_get_discount_max_uses($code_id = null) { |
|
337 | + $max_uses = get_post_meta($code_id, '_wpi_discount_max_uses', true); |
|
338 | 338 | |
339 | - return (int) apply_filters( 'wpinv_get_discount_max_uses', $max_uses, $code_id ); |
|
339 | + return (int)apply_filters('wpinv_get_discount_max_uses', $max_uses, $code_id); |
|
340 | 340 | } |
341 | 341 | |
342 | -function wpinv_get_discount_uses( $code_id = null ) { |
|
343 | - $uses = get_post_meta( $code_id, '_wpi_discount_uses', true ); |
|
342 | +function wpinv_get_discount_uses($code_id = null) { |
|
343 | + $uses = get_post_meta($code_id, '_wpi_discount_uses', true); |
|
344 | 344 | |
345 | - return (int) apply_filters( 'wpinv_get_discount_uses', $uses, $code_id ); |
|
345 | + return (int)apply_filters('wpinv_get_discount_uses', $uses, $code_id); |
|
346 | 346 | } |
347 | 347 | |
348 | -function wpinv_get_discount_min_total( $code_id = null ) { |
|
349 | - $min_total = get_post_meta( $code_id, '_wpi_discount_min_total', true ); |
|
348 | +function wpinv_get_discount_min_total($code_id = null) { |
|
349 | + $min_total = get_post_meta($code_id, '_wpi_discount_min_total', true); |
|
350 | 350 | |
351 | - return (float) apply_filters( 'wpinv_get_discount_min_total', $min_total, $code_id ); |
|
351 | + return (float)apply_filters('wpinv_get_discount_min_total', $min_total, $code_id); |
|
352 | 352 | } |
353 | 353 | |
354 | -function wpinv_get_discount_max_total( $code_id = null ) { |
|
355 | - $max_total = get_post_meta( $code_id, '_wpi_discount_max_total', true ); |
|
354 | +function wpinv_get_discount_max_total($code_id = null) { |
|
355 | + $max_total = get_post_meta($code_id, '_wpi_discount_max_total', true); |
|
356 | 356 | |
357 | - return (float) apply_filters( 'wpinv_get_discount_max_total', $max_total, $code_id ); |
|
357 | + return (float)apply_filters('wpinv_get_discount_max_total', $max_total, $code_id); |
|
358 | 358 | } |
359 | 359 | |
360 | -function wpinv_get_discount_amount( $code_id = null ) { |
|
361 | - $amount = get_post_meta( $code_id, '_wpi_discount_amount', true ); |
|
360 | +function wpinv_get_discount_amount($code_id = null) { |
|
361 | + $amount = get_post_meta($code_id, '_wpi_discount_amount', true); |
|
362 | 362 | |
363 | - return (float) apply_filters( 'wpinv_get_discount_amount', $amount, $code_id ); |
|
363 | + return (float)apply_filters('wpinv_get_discount_amount', $amount, $code_id); |
|
364 | 364 | } |
365 | 365 | |
366 | -function wpinv_get_discount_type( $code_id = null, $name = false ) { |
|
367 | - $type = strtolower( get_post_meta( $code_id, '_wpi_discount_type', true ) ); |
|
366 | +function wpinv_get_discount_type($code_id = null, $name = false) { |
|
367 | + $type = strtolower(get_post_meta($code_id, '_wpi_discount_type', true)); |
|
368 | 368 | |
369 | - if ( $name ) { |
|
370 | - $name = wpinv_get_discount_type_name( $type ); |
|
369 | + if ($name) { |
|
370 | + $name = wpinv_get_discount_type_name($type); |
|
371 | 371 | |
372 | - return apply_filters( 'wpinv_get_discount_type_name', $name, $code_id ); |
|
372 | + return apply_filters('wpinv_get_discount_type_name', $name, $code_id); |
|
373 | 373 | } |
374 | 374 | |
375 | - return apply_filters( 'wpinv_get_discount_type', $type, $code_id ); |
|
375 | + return apply_filters('wpinv_get_discount_type', $type, $code_id); |
|
376 | 376 | } |
377 | 377 | |
378 | -function wpinv_discount_status( $status ) { |
|
379 | - switch( $status ){ |
|
378 | +function wpinv_discount_status($status) { |
|
379 | + switch ($status) { |
|
380 | 380 | case 'expired' : |
381 | - $name = __( 'Expired', 'invoicing' ); |
|
381 | + $name = __('Expired', 'invoicing'); |
|
382 | 382 | break; |
383 | 383 | case 'publish' : |
384 | 384 | case 'active' : |
385 | - $name = __( 'Active', 'invoicing' ); |
|
385 | + $name = __('Active', 'invoicing'); |
|
386 | 386 | break; |
387 | 387 | default : |
388 | - $name = __( 'Inactive', 'invoicing' ); |
|
388 | + $name = __('Inactive', 'invoicing'); |
|
389 | 389 | break; |
390 | 390 | } |
391 | 391 | return $name; |
392 | 392 | } |
393 | 393 | |
394 | -function wpinv_get_discount_excluded_items( $code_id = null ) { |
|
395 | - $excluded_items = get_post_meta( $code_id, '_wpi_discount_excluded_items', true ); |
|
394 | +function wpinv_get_discount_excluded_items($code_id = null) { |
|
395 | + $excluded_items = get_post_meta($code_id, '_wpi_discount_excluded_items', true); |
|
396 | 396 | |
397 | - if ( empty( $excluded_items ) || ! is_array( $excluded_items ) ) { |
|
397 | + if (empty($excluded_items) || !is_array($excluded_items)) { |
|
398 | 398 | $excluded_items = array(); |
399 | 399 | } |
400 | 400 | |
401 | - return (array) apply_filters( 'wpinv_get_discount_excluded_items', $excluded_items, $code_id ); |
|
401 | + return (array)apply_filters('wpinv_get_discount_excluded_items', $excluded_items, $code_id); |
|
402 | 402 | } |
403 | 403 | |
404 | -function wpinv_get_discount_item_reqs( $code_id = null ) { |
|
405 | - $item_reqs = get_post_meta( $code_id, '_wpi_discount_items', true ); |
|
404 | +function wpinv_get_discount_item_reqs($code_id = null) { |
|
405 | + $item_reqs = get_post_meta($code_id, '_wpi_discount_items', true); |
|
406 | 406 | |
407 | - if ( empty( $item_reqs ) || ! is_array( $item_reqs ) ) { |
|
407 | + if (empty($item_reqs) || !is_array($item_reqs)) { |
|
408 | 408 | $item_reqs = array(); |
409 | 409 | } |
410 | 410 | |
411 | - return (array) apply_filters( 'wpinv_get_discount_item_reqs', $item_reqs, $code_id ); |
|
411 | + return (array)apply_filters('wpinv_get_discount_item_reqs', $item_reqs, $code_id); |
|
412 | 412 | } |
413 | 413 | |
414 | -function wpinv_get_discount_item_condition( $code_id = 0 ) { |
|
415 | - return get_post_meta( $code_id, '_wpi_discount_item_condition', true ); |
|
414 | +function wpinv_get_discount_item_condition($code_id = 0) { |
|
415 | + return get_post_meta($code_id, '_wpi_discount_item_condition', true); |
|
416 | 416 | } |
417 | 417 | |
418 | -function wpinv_is_discount_not_global( $code_id = 0 ) { |
|
419 | - return (bool) get_post_meta( $code_id, '_wpi_discount_is_not_global', true ); |
|
418 | +function wpinv_is_discount_not_global($code_id = 0) { |
|
419 | + return (bool)get_post_meta($code_id, '_wpi_discount_is_not_global', true); |
|
420 | 420 | } |
421 | 421 | |
422 | -function wpinv_is_discount_expired( $code_id = null ) { |
|
423 | - $discount = wpinv_get_discount( $code_id ); |
|
422 | +function wpinv_is_discount_expired($code_id = null) { |
|
423 | + $discount = wpinv_get_discount($code_id); |
|
424 | 424 | $return = false; |
425 | 425 | |
426 | - if ( $discount ) { |
|
427 | - $expiration = wpinv_get_discount_expiration( $code_id ); |
|
428 | - if ( $expiration ) { |
|
429 | - $expiration = strtotime( $expiration ); |
|
430 | - if ( $expiration < current_time( 'timestamp' ) ) { |
|
426 | + if ($discount) { |
|
427 | + $expiration = wpinv_get_discount_expiration($code_id); |
|
428 | + if ($expiration) { |
|
429 | + $expiration = strtotime($expiration); |
|
430 | + if ($expiration < current_time('timestamp')) { |
|
431 | 431 | // Discount is expired |
432 | - wpinv_update_discount_status( $code_id, 'pending' ); |
|
432 | + wpinv_update_discount_status($code_id, 'pending'); |
|
433 | 433 | $return = true; |
434 | 434 | } |
435 | 435 | } |
436 | 436 | } |
437 | 437 | |
438 | - return apply_filters( 'wpinv_is_discount_expired', $return, $code_id ); |
|
438 | + return apply_filters('wpinv_is_discount_expired', $return, $code_id); |
|
439 | 439 | } |
440 | 440 | |
441 | -function wpinv_is_discount_started( $code_id = null ) { |
|
442 | - $discount = wpinv_get_discount( $code_id ); |
|
441 | +function wpinv_is_discount_started($code_id = null) { |
|
442 | + $discount = wpinv_get_discount($code_id); |
|
443 | 443 | $return = false; |
444 | 444 | |
445 | - if ( $discount ) { |
|
446 | - $start_date = wpinv_get_discount_start_date( $code_id ); |
|
445 | + if ($discount) { |
|
446 | + $start_date = wpinv_get_discount_start_date($code_id); |
|
447 | 447 | |
448 | - if ( $start_date ) { |
|
449 | - $start_date = strtotime( $start_date ); |
|
448 | + if ($start_date) { |
|
449 | + $start_date = strtotime($start_date); |
|
450 | 450 | |
451 | - if ( $start_date < current_time( 'timestamp' ) ) { |
|
451 | + if ($start_date < current_time('timestamp')) { |
|
452 | 452 | // Discount has past the start date |
453 | 453 | $return = true; |
454 | 454 | } else { |
455 | - wpinv_set_error( 'wpinv-discount-error', __( 'This discount is not active yet.', 'invoicing' ) ); |
|
455 | + wpinv_set_error('wpinv-discount-error', __('This discount is not active yet.', 'invoicing')); |
|
456 | 456 | } |
457 | 457 | } else { |
458 | 458 | // No start date for this discount, so has to be true |
@@ -460,159 +460,159 @@ discard block |
||
460 | 460 | } |
461 | 461 | } |
462 | 462 | |
463 | - return apply_filters( 'wpinv_is_discount_started', $return, $code_id ); |
|
463 | + return apply_filters('wpinv_is_discount_started', $return, $code_id); |
|
464 | 464 | } |
465 | 465 | |
466 | -function wpinv_check_discount_dates( $code_id = null ) { |
|
467 | - $discount = wpinv_get_discount( $code_id ); |
|
466 | +function wpinv_check_discount_dates($code_id = null) { |
|
467 | + $discount = wpinv_get_discount($code_id); |
|
468 | 468 | $return = false; |
469 | 469 | |
470 | - if ( $discount ) { |
|
471 | - $start_date = wpinv_get_discount_start_date( $code_id ); |
|
470 | + if ($discount) { |
|
471 | + $start_date = wpinv_get_discount_start_date($code_id); |
|
472 | 472 | |
473 | - if ( $start_date ) { |
|
474 | - $start_date = strtotime( $start_date ); |
|
473 | + if ($start_date) { |
|
474 | + $start_date = strtotime($start_date); |
|
475 | 475 | |
476 | - if ( $start_date < current_time( 'timestamp' ) ) { |
|
476 | + if ($start_date < current_time('timestamp')) { |
|
477 | 477 | // Discount has past the start date |
478 | 478 | $return = true; |
479 | 479 | } else { |
480 | - wpinv_set_error( 'wpinv-discount-error', __( 'This discount is not active yet.', 'invoicing' ) ); |
|
480 | + wpinv_set_error('wpinv-discount-error', __('This discount is not active yet.', 'invoicing')); |
|
481 | 481 | } |
482 | 482 | } else { |
483 | 483 | // No start date for this discount, so has to be true |
484 | 484 | $return = true; |
485 | 485 | } |
486 | 486 | |
487 | - if ( $return ) { |
|
488 | - $expiration = wpinv_get_discount_expiration( $code_id ); |
|
487 | + if ($return) { |
|
488 | + $expiration = wpinv_get_discount_expiration($code_id); |
|
489 | 489 | |
490 | - if ( $expiration ) { |
|
491 | - $expiration = strtotime( $expiration ); |
|
492 | - if ( $expiration < current_time( 'timestamp' ) ) { |
|
490 | + if ($expiration) { |
|
491 | + $expiration = strtotime($expiration); |
|
492 | + if ($expiration < current_time('timestamp')) { |
|
493 | 493 | // Discount is expired |
494 | - wpinv_update_discount_status( $code_id, 'pending' ); |
|
494 | + wpinv_update_discount_status($code_id, 'pending'); |
|
495 | 495 | $return = true; |
496 | 496 | } |
497 | 497 | } |
498 | 498 | } |
499 | 499 | } |
500 | 500 | |
501 | - return apply_filters( 'wpinv_check_discount_dates', $return, $code_id ); |
|
501 | + return apply_filters('wpinv_check_discount_dates', $return, $code_id); |
|
502 | 502 | } |
503 | 503 | |
504 | -function wpinv_is_discount_maxed_out( $code_id = null ) { |
|
505 | - $discount = wpinv_get_discount( $code_id ); |
|
504 | +function wpinv_is_discount_maxed_out($code_id = null) { |
|
505 | + $discount = wpinv_get_discount($code_id); |
|
506 | 506 | $return = false; |
507 | 507 | |
508 | - if ( $discount ) { |
|
509 | - $uses = wpinv_get_discount_uses( $code_id ); |
|
508 | + if ($discount) { |
|
509 | + $uses = wpinv_get_discount_uses($code_id); |
|
510 | 510 | // Large number that will never be reached |
511 | - $max_uses = wpinv_get_discount_max_uses( $code_id ); |
|
511 | + $max_uses = wpinv_get_discount_max_uses($code_id); |
|
512 | 512 | // Should never be greater than, but just in case |
513 | - if ( $uses >= $max_uses && ! empty( $max_uses ) ) { |
|
513 | + if ($uses >= $max_uses && !empty($max_uses)) { |
|
514 | 514 | // Discount is maxed out |
515 | - wpinv_set_error( 'wpinv-discount-error', __( 'This discount has reached its maximum usage.', 'invoicing' ) ); |
|
515 | + wpinv_set_error('wpinv-discount-error', __('This discount has reached its maximum usage.', 'invoicing')); |
|
516 | 516 | $return = true; |
517 | 517 | } |
518 | 518 | } |
519 | 519 | |
520 | - return apply_filters( 'wpinv_is_discount_maxed_out', $return, $code_id ); |
|
520 | + return apply_filters('wpinv_is_discount_maxed_out', $return, $code_id); |
|
521 | 521 | } |
522 | 522 | |
523 | -function wpinv_discount_is_min_met( $code_id = null ) { |
|
524 | - $discount = wpinv_get_discount( $code_id ); |
|
523 | +function wpinv_discount_is_min_met($code_id = null) { |
|
524 | + $discount = wpinv_get_discount($code_id); |
|
525 | 525 | $return = false; |
526 | 526 | |
527 | - if ( $discount ) { |
|
528 | - $min = (float)wpinv_get_discount_min_total( $code_id ); |
|
529 | - $cart_amount = (float)wpinv_get_cart_discountable_subtotal( $code_id ); |
|
527 | + if ($discount) { |
|
528 | + $min = (float)wpinv_get_discount_min_total($code_id); |
|
529 | + $cart_amount = (float)wpinv_get_cart_discountable_subtotal($code_id); |
|
530 | 530 | |
531 | - if ( !$min > 0 || $cart_amount >= $min ) { |
|
531 | + if (!$min > 0 || $cart_amount >= $min) { |
|
532 | 532 | // Minimum has been met |
533 | 533 | $return = true; |
534 | 534 | } else { |
535 | - wpinv_set_error( 'wpinv-discount-error', sprintf( __( 'Minimum invoice of %s not met.', 'invoicing' ), wpinv_price( wpinv_format_amount( $min ) ) ) ); |
|
535 | + wpinv_set_error('wpinv-discount-error', sprintf(__('Minimum invoice of %s not met.', 'invoicing'), wpinv_price(wpinv_format_amount($min)))); |
|
536 | 536 | } |
537 | 537 | } |
538 | 538 | |
539 | - return apply_filters( 'wpinv_is_discount_min_met', $return, $code_id ); |
|
539 | + return apply_filters('wpinv_is_discount_min_met', $return, $code_id); |
|
540 | 540 | } |
541 | 541 | |
542 | -function wpinv_discount_is_max_met( $code_id = null ) { |
|
543 | - $discount = wpinv_get_discount( $code_id ); |
|
542 | +function wpinv_discount_is_max_met($code_id = null) { |
|
543 | + $discount = wpinv_get_discount($code_id); |
|
544 | 544 | $return = false; |
545 | 545 | |
546 | - if ( $discount ) { |
|
547 | - $max = (float)wpinv_get_discount_max_total( $code_id ); |
|
548 | - $cart_amount = (float)wpinv_get_cart_discountable_subtotal( $code_id ); |
|
546 | + if ($discount) { |
|
547 | + $max = (float)wpinv_get_discount_max_total($code_id); |
|
548 | + $cart_amount = (float)wpinv_get_cart_discountable_subtotal($code_id); |
|
549 | 549 | |
550 | - if ( !$max > 0 || $cart_amount <= $max ) { |
|
550 | + if (!$max > 0 || $cart_amount <= $max) { |
|
551 | 551 | // Minimum has been met |
552 | 552 | $return = true; |
553 | 553 | } else { |
554 | - wpinv_set_error( 'wpinv-discount-error', sprintf( __( 'Maximum invoice of %s not met.', 'invoicing' ), wpinv_price( wpinv_format_amount( $max ) ) ) ); |
|
554 | + wpinv_set_error('wpinv-discount-error', sprintf(__('Maximum invoice of %s not met.', 'invoicing'), wpinv_price(wpinv_format_amount($max)))); |
|
555 | 555 | } |
556 | 556 | } |
557 | 557 | |
558 | - return apply_filters( 'wpinv_is_discount_max_met', $return, $code_id ); |
|
558 | + return apply_filters('wpinv_is_discount_max_met', $return, $code_id); |
|
559 | 559 | } |
560 | 560 | |
561 | -function wpinv_discount_is_single_use( $code_id = 0 ) { |
|
562 | - $single_use = get_post_meta( $code_id, '_wpi_discount_is_single_use', true ); |
|
563 | - return (bool) apply_filters( 'wpinv_is_discount_single_use', $single_use, $code_id ); |
|
561 | +function wpinv_discount_is_single_use($code_id = 0) { |
|
562 | + $single_use = get_post_meta($code_id, '_wpi_discount_is_single_use', true); |
|
563 | + return (bool)apply_filters('wpinv_is_discount_single_use', $single_use, $code_id); |
|
564 | 564 | } |
565 | 565 | |
566 | -function wpinv_discount_is_recurring( $code_id = 0, $code = false ) { |
|
567 | - if ( $code ) { |
|
568 | - $discount = wpinv_get_discount_by_code( $code_id ); |
|
566 | +function wpinv_discount_is_recurring($code_id = 0, $code = false) { |
|
567 | + if ($code) { |
|
568 | + $discount = wpinv_get_discount_by_code($code_id); |
|
569 | 569 | |
570 | - if ( !empty( $discount ) ) { |
|
570 | + if (!empty($discount)) { |
|
571 | 571 | $code_id = $discount->ID; |
572 | 572 | } |
573 | 573 | } |
574 | 574 | |
575 | - $recurring = get_post_meta( $code_id, '_wpi_discount_is_recurring', true ); |
|
575 | + $recurring = get_post_meta($code_id, '_wpi_discount_is_recurring', true); |
|
576 | 576 | |
577 | - return (bool) apply_filters( 'wpinv_is_discount_recurring', $recurring, $code_id, $code ); |
|
577 | + return (bool)apply_filters('wpinv_is_discount_recurring', $recurring, $code_id, $code); |
|
578 | 578 | } |
579 | 579 | |
580 | -function wpinv_discount_item_reqs_met( $code_id = null ) { |
|
581 | - $item_reqs = wpinv_get_discount_item_reqs( $code_id ); |
|
582 | - $condition = wpinv_get_discount_item_condition( $code_id ); |
|
583 | - $excluded_ps = wpinv_get_discount_excluded_items( $code_id ); |
|
580 | +function wpinv_discount_item_reqs_met($code_id = null) { |
|
581 | + $item_reqs = wpinv_get_discount_item_reqs($code_id); |
|
582 | + $condition = wpinv_get_discount_item_condition($code_id); |
|
583 | + $excluded_ps = wpinv_get_discount_excluded_items($code_id); |
|
584 | 584 | $cart_items = wpinv_get_cart_contents(); |
585 | - $cart_ids = $cart_items ? wp_list_pluck( $cart_items, 'id' ) : null; |
|
585 | + $cart_ids = $cart_items ? wp_list_pluck($cart_items, 'id') : null; |
|
586 | 586 | $ret = false; |
587 | 587 | |
588 | - if ( empty( $item_reqs ) && empty( $excluded_ps ) ) { |
|
588 | + if (empty($item_reqs) && empty($excluded_ps)) { |
|
589 | 589 | $ret = true; |
590 | 590 | } |
591 | 591 | |
592 | 592 | // Normalize our data for item requirements, exclusions and cart data |
593 | 593 | // First absint the items, then sort, and reset the array keys |
594 | - $item_reqs = array_map( 'absint', $item_reqs ); |
|
595 | - asort( $item_reqs ); |
|
596 | - $item_reqs = array_values( $item_reqs ); |
|
594 | + $item_reqs = array_map('absint', $item_reqs); |
|
595 | + asort($item_reqs); |
|
596 | + $item_reqs = array_values($item_reqs); |
|
597 | 597 | |
598 | - $excluded_ps = array_map( 'absint', $excluded_ps ); |
|
599 | - asort( $excluded_ps ); |
|
600 | - $excluded_ps = array_values( $excluded_ps ); |
|
598 | + $excluded_ps = array_map('absint', $excluded_ps); |
|
599 | + asort($excluded_ps); |
|
600 | + $excluded_ps = array_values($excluded_ps); |
|
601 | 601 | |
602 | - $cart_ids = array_map( 'absint', $cart_ids ); |
|
603 | - asort( $cart_ids ); |
|
604 | - $cart_ids = array_values( $cart_ids ); |
|
602 | + $cart_ids = array_map('absint', $cart_ids); |
|
603 | + asort($cart_ids); |
|
604 | + $cart_ids = array_values($cart_ids); |
|
605 | 605 | |
606 | 606 | // Ensure we have requirements before proceeding |
607 | - if ( !$ret && ! empty( $item_reqs ) ) { |
|
608 | - switch( $condition ) { |
|
607 | + if (!$ret && !empty($item_reqs)) { |
|
608 | + switch ($condition) { |
|
609 | 609 | case 'all' : |
610 | 610 | // Default back to true |
611 | 611 | $ret = true; |
612 | 612 | |
613 | - foreach ( $item_reqs as $item_id ) { |
|
614 | - if ( !wpinv_item_in_cart( $item_id ) ) { |
|
615 | - wpinv_set_error( 'wpinv-discount-error', __( 'The item requirements for this discount are not met.', 'invoicing' ) ); |
|
613 | + foreach ($item_reqs as $item_id) { |
|
614 | + if (!wpinv_item_in_cart($item_id)) { |
|
615 | + wpinv_set_error('wpinv-discount-error', __('The item requirements for this discount are not met.', 'invoicing')); |
|
616 | 616 | $ret = false; |
617 | 617 | break; |
618 | 618 | } |
@@ -621,15 +621,15 @@ discard block |
||
621 | 621 | break; |
622 | 622 | |
623 | 623 | default : // Any |
624 | - foreach ( $item_reqs as $item_id ) { |
|
625 | - if ( wpinv_item_in_cart( $item_id ) ) { |
|
624 | + foreach ($item_reqs as $item_id) { |
|
625 | + if (wpinv_item_in_cart($item_id)) { |
|
626 | 626 | $ret = true; |
627 | 627 | break; |
628 | 628 | } |
629 | 629 | } |
630 | 630 | |
631 | - if( ! $ret ) { |
|
632 | - wpinv_set_error( 'wpinv-discount-error', __( 'The item requirements for this discount are not met.', 'invoicing' ) ); |
|
631 | + if (!$ret) { |
|
632 | + wpinv_set_error('wpinv-discount-error', __('The item requirements for this discount are not met.', 'invoicing')); |
|
633 | 633 | } |
634 | 634 | |
635 | 635 | break; |
@@ -638,70 +638,70 @@ discard block |
||
638 | 638 | $ret = true; |
639 | 639 | } |
640 | 640 | |
641 | - if( ! empty( $excluded_ps ) ) { |
|
641 | + if (!empty($excluded_ps)) { |
|
642 | 642 | // Check that there are items other than excluded ones in the cart |
643 | - if( $cart_ids == $excluded_ps ) { |
|
644 | - wpinv_set_error( 'wpinv-discount-error', __( 'This discount is not valid for the cart contents.', 'invoicing' ) ); |
|
643 | + if ($cart_ids == $excluded_ps) { |
|
644 | + wpinv_set_error('wpinv-discount-error', __('This discount is not valid for the cart contents.', 'invoicing')); |
|
645 | 645 | $ret = false; |
646 | 646 | } |
647 | 647 | } |
648 | 648 | |
649 | - return (bool) apply_filters( 'wpinv_is_discount_item_req_met', $ret, $code_id, $condition ); |
|
649 | + return (bool)apply_filters('wpinv_is_discount_item_req_met', $ret, $code_id, $condition); |
|
650 | 650 | } |
651 | 651 | |
652 | -function wpinv_is_discount_used( $code = null, $user = '', $code_id = 0 ) { |
|
652 | +function wpinv_is_discount_used($code = null, $user = '', $code_id = 0) { |
|
653 | 653 | global $wpi_checkout_id; |
654 | 654 | |
655 | 655 | $return = false; |
656 | 656 | |
657 | - if ( empty( $code_id ) ) { |
|
658 | - $code_id = wpinv_get_discount_id_by_code( $code ); |
|
657 | + if (empty($code_id)) { |
|
658 | + $code_id = wpinv_get_discount_id_by_code($code); |
|
659 | 659 | |
660 | - if( empty( $code_id ) ) { |
|
660 | + if (empty($code_id)) { |
|
661 | 661 | return false; // No discount was found |
662 | 662 | } |
663 | 663 | } |
664 | 664 | |
665 | - if ( wpinv_discount_is_single_use( $code_id ) ) { |
|
665 | + if (wpinv_discount_is_single_use($code_id)) { |
|
666 | 666 | $payments = array(); |
667 | 667 | |
668 | 668 | $user_id = 0; |
669 | - if ( is_int( $user ) ) { |
|
670 | - $user_id = absint( $user ); |
|
671 | - } else if ( is_email( $user ) && $user_data = get_user_by( 'email', $user ) ) { |
|
669 | + if (is_int($user)) { |
|
670 | + $user_id = absint($user); |
|
671 | + } else if (is_email($user) && $user_data = get_user_by('email', $user)) { |
|
672 | 672 | $user_id = $user_data->ID; |
673 | - } else if ( $user_data = get_user_by( 'login', $user ) ) { |
|
673 | + } else if ($user_data = get_user_by('login', $user)) { |
|
674 | 674 | $user_id = $user_data->ID; |
675 | - } else if ( absint( $user ) > 0 ) { |
|
676 | - $user_id = absint( $user ); |
|
675 | + } else if (absint($user) > 0) { |
|
676 | + $user_id = absint($user); |
|
677 | 677 | } |
678 | 678 | |
679 | - if ( !empty( $user_id ) ) { |
|
680 | - $query = array( 'user' => $user_id, 'limit' => false ); |
|
681 | - $payments = wpinv_get_invoices( $query ); // Get all payments with matching user id |
|
679 | + if (!empty($user_id)) { |
|
680 | + $query = array('user' => $user_id, 'limit' => false); |
|
681 | + $payments = wpinv_get_invoices($query); // Get all payments with matching user id |
|
682 | 682 | } |
683 | 683 | |
684 | - if ( $payments ) { |
|
685 | - foreach ( $payments as $payment ) { |
|
684 | + if ($payments) { |
|
685 | + foreach ($payments as $payment) { |
|
686 | 686 | // Don't count discount used for current invoice chekcout. |
687 | - if ( !empty( $wpi_checkout_id ) && $wpi_checkout_id == $payment->ID ) { |
|
687 | + if (!empty($wpi_checkout_id) && $wpi_checkout_id == $payment->ID) { |
|
688 | 688 | continue; |
689 | 689 | } |
690 | 690 | |
691 | - if ( $payment->has_status( array( 'wpi-cancelled', 'wpi-failed' ) ) ) { |
|
691 | + if ($payment->has_status(array('wpi-cancelled', 'wpi-failed'))) { |
|
692 | 692 | continue; |
693 | 693 | } |
694 | 694 | |
695 | - $discounts = $payment->get_discounts( true ); |
|
696 | - if ( empty( $discounts ) ) { |
|
695 | + $discounts = $payment->get_discounts(true); |
|
696 | + if (empty($discounts)) { |
|
697 | 697 | continue; |
698 | 698 | } |
699 | 699 | |
700 | - $discounts = $discounts && !is_array( $discounts ) ? explode( ',', $discounts ) : $discounts; |
|
700 | + $discounts = $discounts && !is_array($discounts) ? explode(',', $discounts) : $discounts; |
|
701 | 701 | |
702 | - if ( !empty( $discounts ) && is_array( $discounts ) ) { |
|
703 | - if ( in_array( strtolower( $code ), array_map( 'strtolower', $discounts ) ) ) { |
|
704 | - wpinv_set_error( 'wpinv-discount-error', __( 'This discount has already been redeemed.', 'invoicing' ) ); |
|
702 | + if (!empty($discounts) && is_array($discounts)) { |
|
703 | + if (in_array(strtolower($code), array_map('strtolower', $discounts))) { |
|
704 | + wpinv_set_error('wpinv-discount-error', __('This discount has already been redeemed.', 'invoicing')); |
|
705 | 705 | $return = true; |
706 | 706 | break; |
707 | 707 | } |
@@ -710,61 +710,61 @@ discard block |
||
710 | 710 | } |
711 | 711 | } |
712 | 712 | |
713 | - return apply_filters( 'wpinv_is_discount_used', $return, $code, $user ); |
|
713 | + return apply_filters('wpinv_is_discount_used', $return, $code, $user); |
|
714 | 714 | } |
715 | 715 | |
716 | -function wpinv_is_discount_valid( $code = '', $user = '', $set_error = true ) { |
|
716 | +function wpinv_is_discount_valid($code = '', $user = '', $set_error = true) { |
|
717 | 717 | $return = false; |
718 | - $discount_id = wpinv_get_discount_id_by_code( $code ); |
|
719 | - $user = trim( $user ); |
|
718 | + $discount_id = wpinv_get_discount_id_by_code($code); |
|
719 | + $user = trim($user); |
|
720 | 720 | |
721 | - if ( wpinv_get_cart_contents() ) { |
|
722 | - if ( $discount_id ) { |
|
721 | + if (wpinv_get_cart_contents()) { |
|
722 | + if ($discount_id) { |
|
723 | 723 | if ( |
724 | - wpinv_is_discount_active( $discount_id ) && |
|
725 | - wpinv_check_discount_dates( $discount_id ) && |
|
726 | - !wpinv_is_discount_maxed_out( $discount_id ) && |
|
727 | - !wpinv_is_discount_used( $code, $user, $discount_id ) && |
|
728 | - wpinv_discount_is_min_met( $discount_id ) && |
|
729 | - wpinv_discount_is_max_met( $discount_id ) && |
|
730 | - wpinv_discount_item_reqs_met( $discount_id ) |
|
724 | + wpinv_is_discount_active($discount_id) && |
|
725 | + wpinv_check_discount_dates($discount_id) && |
|
726 | + !wpinv_is_discount_maxed_out($discount_id) && |
|
727 | + !wpinv_is_discount_used($code, $user, $discount_id) && |
|
728 | + wpinv_discount_is_min_met($discount_id) && |
|
729 | + wpinv_discount_is_max_met($discount_id) && |
|
730 | + wpinv_discount_item_reqs_met($discount_id) |
|
731 | 731 | ) { |
732 | 732 | $return = true; |
733 | 733 | } |
734 | - } elseif( $set_error ) { |
|
735 | - wpinv_set_error( 'wpinv-discount-error', __( 'This discount is invalid.', 'invoicing' ) ); |
|
734 | + } elseif ($set_error) { |
|
735 | + wpinv_set_error('wpinv-discount-error', __('This discount is invalid.', 'invoicing')); |
|
736 | 736 | } |
737 | 737 | } |
738 | 738 | |
739 | - return apply_filters( 'wpinv_is_discount_valid', $return, $discount_id, $code, $user ); |
|
739 | + return apply_filters('wpinv_is_discount_valid', $return, $discount_id, $code, $user); |
|
740 | 740 | } |
741 | 741 | |
742 | -function wpinv_get_discount_id_by_code( $code ) { |
|
743 | - $discount = wpinv_get_discount_by_code( $code ); |
|
744 | - if( $discount ) { |
|
742 | +function wpinv_get_discount_id_by_code($code) { |
|
743 | + $discount = wpinv_get_discount_by_code($code); |
|
744 | + if ($discount) { |
|
745 | 745 | return $discount->ID; |
746 | 746 | } |
747 | 747 | return false; |
748 | 748 | } |
749 | 749 | |
750 | -function wpinv_get_discounted_amount( $code, $base_price ) { |
|
750 | +function wpinv_get_discounted_amount($code, $base_price) { |
|
751 | 751 | $amount = $base_price; |
752 | - $discount_id = wpinv_get_discount_id_by_code( $code ); |
|
752 | + $discount_id = wpinv_get_discount_id_by_code($code); |
|
753 | 753 | |
754 | - if( $discount_id ) { |
|
755 | - $type = wpinv_get_discount_type( $discount_id ); |
|
756 | - $rate = wpinv_get_discount_amount( $discount_id ); |
|
754 | + if ($discount_id) { |
|
755 | + $type = wpinv_get_discount_type($discount_id); |
|
756 | + $rate = wpinv_get_discount_amount($discount_id); |
|
757 | 757 | |
758 | - if ( $type == 'flat' ) { |
|
758 | + if ($type == 'flat') { |
|
759 | 759 | // Set amount |
760 | 760 | $amount = $base_price - $rate; |
761 | - if ( $amount < 0 ) { |
|
761 | + if ($amount < 0) { |
|
762 | 762 | $amount = 0; |
763 | 763 | } |
764 | 764 | |
765 | 765 | } else { |
766 | 766 | // Percentage discount |
767 | - $amount = $base_price - ( $base_price * ( $rate / 100 ) ); |
|
767 | + $amount = $base_price - ($base_price * ($rate / 100)); |
|
768 | 768 | } |
769 | 769 | |
770 | 770 | } else { |
@@ -773,108 +773,108 @@ discard block |
||
773 | 773 | |
774 | 774 | } |
775 | 775 | |
776 | - return apply_filters( 'wpinv_discounted_amount', $amount ); |
|
776 | + return apply_filters('wpinv_discounted_amount', $amount); |
|
777 | 777 | } |
778 | 778 | |
779 | -function wpinv_increase_discount_usage( $code ) { |
|
779 | +function wpinv_increase_discount_usage($code) { |
|
780 | 780 | |
781 | - $id = wpinv_get_discount_id_by_code( $code ); |
|
782 | - $uses = wpinv_get_discount_uses( $id ); |
|
781 | + $id = wpinv_get_discount_id_by_code($code); |
|
782 | + $uses = wpinv_get_discount_uses($id); |
|
783 | 783 | |
784 | - if ( $uses ) { |
|
784 | + if ($uses) { |
|
785 | 785 | $uses++; |
786 | 786 | } else { |
787 | 787 | $uses = 1; |
788 | 788 | } |
789 | 789 | |
790 | - update_post_meta( $id, '_wpi_discount_uses', $uses ); |
|
790 | + update_post_meta($id, '_wpi_discount_uses', $uses); |
|
791 | 791 | |
792 | - do_action( 'wpinv_discount_increase_use_count', $uses, $id, $code ); |
|
792 | + do_action('wpinv_discount_increase_use_count', $uses, $id, $code); |
|
793 | 793 | |
794 | 794 | return $uses; |
795 | 795 | |
796 | 796 | } |
797 | 797 | |
798 | -function wpinv_decrease_discount_usage( $code ) { |
|
798 | +function wpinv_decrease_discount_usage($code) { |
|
799 | 799 | |
800 | - $id = wpinv_get_discount_id_by_code( $code ); |
|
801 | - $uses = wpinv_get_discount_uses( $id ); |
|
800 | + $id = wpinv_get_discount_id_by_code($code); |
|
801 | + $uses = wpinv_get_discount_uses($id); |
|
802 | 802 | |
803 | - if ( $uses ) { |
|
803 | + if ($uses) { |
|
804 | 804 | $uses--; |
805 | 805 | } |
806 | 806 | |
807 | - if ( $uses < 0 ) { |
|
807 | + if ($uses < 0) { |
|
808 | 808 | $uses = 0; |
809 | 809 | } |
810 | 810 | |
811 | - update_post_meta( $id, '_wpi_discount_uses', $uses ); |
|
811 | + update_post_meta($id, '_wpi_discount_uses', $uses); |
|
812 | 812 | |
813 | - do_action( 'wpinv_discount_decrease_use_count', $uses, $id, $code ); |
|
813 | + do_action('wpinv_discount_decrease_use_count', $uses, $id, $code); |
|
814 | 814 | |
815 | 815 | return $uses; |
816 | 816 | |
817 | 817 | } |
818 | 818 | |
819 | -function wpinv_format_discount_rate( $type, $amount ) { |
|
820 | - if ( $type == 'flat' ) { |
|
821 | - return wpinv_price( wpinv_format_amount( $amount ) ); |
|
819 | +function wpinv_format_discount_rate($type, $amount) { |
|
820 | + if ($type == 'flat') { |
|
821 | + return wpinv_price(wpinv_format_amount($amount)); |
|
822 | 822 | } else { |
823 | 823 | return $amount . '%'; |
824 | 824 | } |
825 | 825 | } |
826 | 826 | |
827 | -function wpinv_set_cart_discount( $code = '' ) { |
|
828 | - if ( wpinv_multiple_discounts_allowed() ) { |
|
827 | +function wpinv_set_cart_discount($code = '') { |
|
828 | + if (wpinv_multiple_discounts_allowed()) { |
|
829 | 829 | // Get all active cart discounts |
830 | 830 | $discounts = wpinv_get_cart_discounts(); |
831 | 831 | } else { |
832 | 832 | $discounts = false; // Only one discount allowed per purchase, so override any existing |
833 | 833 | } |
834 | 834 | |
835 | - if ( $discounts ) { |
|
836 | - $key = array_search( strtolower( $code ), array_map( 'strtolower', $discounts ) ); |
|
837 | - if( false !== $key ) { |
|
838 | - unset( $discounts[ $key ] ); // Can't set the same discount more than once |
|
835 | + if ($discounts) { |
|
836 | + $key = array_search(strtolower($code), array_map('strtolower', $discounts)); |
|
837 | + if (false !== $key) { |
|
838 | + unset($discounts[$key]); // Can't set the same discount more than once |
|
839 | 839 | } |
840 | 840 | $discounts[] = $code; |
841 | 841 | } else { |
842 | 842 | $discounts = array(); |
843 | 843 | $discounts[] = $code; |
844 | 844 | } |
845 | - $discounts = array_values( $discounts ); |
|
845 | + $discounts = array_values($discounts); |
|
846 | 846 | |
847 | 847 | $data = wpinv_get_checkout_session(); |
848 | - if ( empty( $data ) ) { |
|
848 | + if (empty($data)) { |
|
849 | 849 | $data = array(); |
850 | 850 | } else { |
851 | - if ( !empty( $data['invoice_id'] ) && $payment_meta = wpinv_get_invoice_meta( $data['invoice_id'] ) ) { |
|
852 | - $payment_meta['user_info']['discount'] = implode( ',', $discounts ); |
|
853 | - update_post_meta( $data['invoice_id'], '_wpinv_payment_meta', $payment_meta ); |
|
851 | + if (!empty($data['invoice_id']) && $payment_meta = wpinv_get_invoice_meta($data['invoice_id'])) { |
|
852 | + $payment_meta['user_info']['discount'] = implode(',', $discounts); |
|
853 | + update_post_meta($data['invoice_id'], '_wpinv_payment_meta', $payment_meta); |
|
854 | 854 | } |
855 | 855 | } |
856 | 856 | $data['cart_discounts'] = $discounts; |
857 | 857 | |
858 | - wpinv_set_checkout_session( $data ); |
|
858 | + wpinv_set_checkout_session($data); |
|
859 | 859 | |
860 | 860 | return $discounts; |
861 | 861 | } |
862 | 862 | |
863 | -function wpinv_unset_cart_discount( $code = '' ) { |
|
863 | +function wpinv_unset_cart_discount($code = '') { |
|
864 | 864 | $discounts = wpinv_get_cart_discounts(); |
865 | 865 | |
866 | - if ( $code && !empty( $discounts ) && in_array( $code, $discounts ) ) { |
|
867 | - $key = array_search( $code, $discounts ); |
|
868 | - unset( $discounts[ $key ] ); |
|
866 | + if ($code && !empty($discounts) && in_array($code, $discounts)) { |
|
867 | + $key = array_search($code, $discounts); |
|
868 | + unset($discounts[$key]); |
|
869 | 869 | |
870 | 870 | $data = wpinv_get_checkout_session(); |
871 | 871 | $data['cart_discounts'] = $discounts; |
872 | - if ( !empty( $data['invoice_id'] ) && $payment_meta = wpinv_get_invoice_meta( $data['invoice_id'] ) ) { |
|
873 | - $payment_meta['user_info']['discount'] = !empty( $discounts ) ? implode( ',', $discounts ) : ''; |
|
874 | - update_post_meta( $data['invoice_id'], '_wpinv_payment_meta', $payment_meta ); |
|
872 | + if (!empty($data['invoice_id']) && $payment_meta = wpinv_get_invoice_meta($data['invoice_id'])) { |
|
873 | + $payment_meta['user_info']['discount'] = !empty($discounts) ? implode(',', $discounts) : ''; |
|
874 | + update_post_meta($data['invoice_id'], '_wpinv_payment_meta', $payment_meta); |
|
875 | 875 | } |
876 | 876 | |
877 | - wpinv_set_checkout_session( $data ); |
|
877 | + wpinv_set_checkout_session($data); |
|
878 | 878 | } |
879 | 879 | |
880 | 880 | return $discounts; |
@@ -883,27 +883,27 @@ discard block |
||
883 | 883 | function wpinv_unset_all_cart_discounts() { |
884 | 884 | $data = wpinv_get_checkout_session(); |
885 | 885 | |
886 | - if ( !empty( $data ) && isset( $data['cart_discounts'] ) ) { |
|
887 | - unset( $data['cart_discounts'] ); |
|
886 | + if (!empty($data) && isset($data['cart_discounts'])) { |
|
887 | + unset($data['cart_discounts']); |
|
888 | 888 | |
889 | - wpinv_set_checkout_session( $data ); |
|
889 | + wpinv_set_checkout_session($data); |
|
890 | 890 | return true; |
891 | 891 | } |
892 | 892 | |
893 | 893 | return false; |
894 | 894 | } |
895 | 895 | |
896 | -function wpinv_get_cart_discounts( $items = array() ) { |
|
896 | +function wpinv_get_cart_discounts($items = array()) { |
|
897 | 897 | $session = wpinv_get_checkout_session(); |
898 | 898 | |
899 | - $discounts = !empty( $session['cart_discounts'] ) ? $session['cart_discounts'] : false; |
|
899 | + $discounts = !empty($session['cart_discounts']) ? $session['cart_discounts'] : false; |
|
900 | 900 | return $discounts; |
901 | 901 | } |
902 | 902 | |
903 | -function wpinv_cart_has_discounts( $items = array() ) { |
|
903 | +function wpinv_cart_has_discounts($items = array()) { |
|
904 | 904 | $ret = false; |
905 | 905 | |
906 | - if ( wpinv_get_cart_discounts( $items ) ) { |
|
906 | + if (wpinv_get_cart_discounts($items)) { |
|
907 | 907 | $ret = true; |
908 | 908 | } |
909 | 909 | |
@@ -914,131 +914,131 @@ discard block |
||
914 | 914 | } |
915 | 915 | */ |
916 | 916 | |
917 | - return apply_filters( 'wpinv_cart_has_discounts', $ret ); |
|
917 | + return apply_filters('wpinv_cart_has_discounts', $ret); |
|
918 | 918 | } |
919 | 919 | |
920 | -function wpinv_get_cart_discounted_amount( $items = array(), $discounts = false ) { |
|
920 | +function wpinv_get_cart_discounted_amount($items = array(), $discounts = false) { |
|
921 | 921 | $amount = 0.00; |
922 | - $items = !empty( $items ) ? $items : wpinv_get_cart_content_details(); |
|
922 | + $items = !empty($items) ? $items : wpinv_get_cart_content_details(); |
|
923 | 923 | |
924 | - if ( $items ) { |
|
925 | - $discounts = wp_list_pluck( $items, 'discount' ); |
|
924 | + if ($items) { |
|
925 | + $discounts = wp_list_pluck($items, 'discount'); |
|
926 | 926 | |
927 | - if ( is_array( $discounts ) ) { |
|
928 | - $discounts = array_map( 'floatval', $discounts ); |
|
929 | - $amount = array_sum( $discounts ); |
|
927 | + if (is_array($discounts)) { |
|
928 | + $discounts = array_map('floatval', $discounts); |
|
929 | + $amount = array_sum($discounts); |
|
930 | 930 | } |
931 | 931 | } |
932 | 932 | |
933 | - return apply_filters( 'wpinv_get_cart_discounted_amount', $amount ); |
|
933 | + return apply_filters('wpinv_get_cart_discounted_amount', $amount); |
|
934 | 934 | } |
935 | 935 | |
936 | -function wpinv_get_cart_items_discount_amount( $items = array(), $discount = false ) { |
|
937 | - $items = !empty( $items ) ? $items : wpinv_get_cart_content_details(); |
|
936 | +function wpinv_get_cart_items_discount_amount($items = array(), $discount = false) { |
|
937 | + $items = !empty($items) ? $items : wpinv_get_cart_content_details(); |
|
938 | 938 | |
939 | - if ( empty( $discount ) || empty( $items ) ) { |
|
939 | + if (empty($discount) || empty($items)) { |
|
940 | 940 | return 0; |
941 | 941 | } |
942 | 942 | |
943 | 943 | $amount = 0; |
944 | 944 | |
945 | - foreach ( $items as $item ) { |
|
946 | - $amount += wpinv_get_cart_item_discount_amount( $item, $discount ); |
|
945 | + foreach ($items as $item) { |
|
946 | + $amount += wpinv_get_cart_item_discount_amount($item, $discount); |
|
947 | 947 | } |
948 | 948 | |
949 | - $amount = wpinv_round_amount( $amount ); |
|
949 | + $amount = wpinv_round_amount($amount); |
|
950 | 950 | |
951 | 951 | return $amount; |
952 | 952 | } |
953 | 953 | |
954 | -function wpinv_get_cart_item_discount_amount( $item = array(), $discount = false ) { |
|
954 | +function wpinv_get_cart_item_discount_amount($item = array(), $discount = false) { |
|
955 | 955 | global $wpinv_is_last_cart_item, $wpinv_flat_discount_total; |
956 | 956 | |
957 | 957 | $amount = 0; |
958 | 958 | |
959 | - if ( empty( $item ) || empty( $item['id'] ) ) { |
|
959 | + if (empty($item) || empty($item['id'])) { |
|
960 | 960 | return $amount; |
961 | 961 | } |
962 | 962 | |
963 | - if ( empty( $item['quantity'] ) ) { |
|
963 | + if (empty($item['quantity'])) { |
|
964 | 964 | return $amount; |
965 | 965 | } |
966 | 966 | |
967 | - if ( empty( $item['options'] ) ) { |
|
967 | + if (empty($item['options'])) { |
|
968 | 968 | $item['options'] = array(); |
969 | 969 | } |
970 | 970 | |
971 | - $price = wpinv_get_cart_item_price( $item['id'], $item, $item['options'] ); |
|
971 | + $price = wpinv_get_cart_item_price($item['id'], $item, $item['options']); |
|
972 | 972 | $discounted_price = $price; |
973 | 973 | |
974 | 974 | $discounts = false === $discount ? wpinv_get_cart_discounts() : $discount; |
975 | - if ( empty( $discounts ) ) { |
|
975 | + if (empty($discounts)) { |
|
976 | 976 | return $amount; |
977 | 977 | } |
978 | 978 | |
979 | - if ( $discounts ) { |
|
980 | - if ( is_array( $discounts ) ) { |
|
981 | - $discounts = array_values( $discounts ); |
|
979 | + if ($discounts) { |
|
980 | + if (is_array($discounts)) { |
|
981 | + $discounts = array_values($discounts); |
|
982 | 982 | } else { |
983 | - $discounts = explode( ',', $discounts ); |
|
983 | + $discounts = explode(',', $discounts); |
|
984 | 984 | } |
985 | 985 | } |
986 | 986 | |
987 | - if( $discounts ) { |
|
988 | - foreach ( $discounts as $discount ) { |
|
989 | - $code_id = wpinv_get_discount_id_by_code( $discount ); |
|
987 | + if ($discounts) { |
|
988 | + foreach ($discounts as $discount) { |
|
989 | + $code_id = wpinv_get_discount_id_by_code($discount); |
|
990 | 990 | |
991 | 991 | // Check discount exists |
992 | - if( ! $code_id ) { |
|
992 | + if (!$code_id) { |
|
993 | 993 | continue; |
994 | 994 | } |
995 | 995 | |
996 | - $reqs = wpinv_get_discount_item_reqs( $code_id ); |
|
997 | - $excluded_items = wpinv_get_discount_excluded_items( $code_id ); |
|
996 | + $reqs = wpinv_get_discount_item_reqs($code_id); |
|
997 | + $excluded_items = wpinv_get_discount_excluded_items($code_id); |
|
998 | 998 | |
999 | 999 | // Make sure requirements are set and that this discount shouldn't apply to the whole cart |
1000 | - if ( !empty( $reqs ) && wpinv_is_discount_not_global( $code_id ) ) { |
|
1001 | - foreach ( $reqs as $item_id ) { |
|
1002 | - if ( $item_id == $item['id'] && ! in_array( $item['id'], $excluded_items ) ) { |
|
1003 | - $discounted_price -= $price - wpinv_get_discounted_amount( $discount, $price ); |
|
1000 | + if (!empty($reqs) && wpinv_is_discount_not_global($code_id)) { |
|
1001 | + foreach ($reqs as $item_id) { |
|
1002 | + if ($item_id == $item['id'] && !in_array($item['id'], $excluded_items)) { |
|
1003 | + $discounted_price -= $price - wpinv_get_discounted_amount($discount, $price); |
|
1004 | 1004 | } |
1005 | 1005 | } |
1006 | 1006 | } else { |
1007 | 1007 | // This is a global cart discount |
1008 | - if ( !in_array( $item['id'], $excluded_items ) ) { |
|
1009 | - if ( 'flat' === wpinv_get_discount_type( $code_id ) ) { |
|
1008 | + if (!in_array($item['id'], $excluded_items)) { |
|
1009 | + if ('flat' === wpinv_get_discount_type($code_id)) { |
|
1010 | 1010 | $items_subtotal = 0.00; |
1011 | 1011 | $cart_items = wpinv_get_cart_contents(); |
1012 | 1012 | |
1013 | - foreach ( $cart_items as $cart_item ) { |
|
1014 | - if ( ! in_array( $cart_item['id'], $excluded_items ) ) { |
|
1015 | - $options = !empty( $cart_item['options'] ) ? $cart_item['options'] : array(); |
|
1016 | - $item_price = wpinv_get_cart_item_price( $cart_item['id'], $cart_item, $options ); |
|
1013 | + foreach ($cart_items as $cart_item) { |
|
1014 | + if (!in_array($cart_item['id'], $excluded_items)) { |
|
1015 | + $options = !empty($cart_item['options']) ? $cart_item['options'] : array(); |
|
1016 | + $item_price = wpinv_get_cart_item_price($cart_item['id'], $cart_item, $options); |
|
1017 | 1017 | $items_subtotal += $item_price * $cart_item['quantity']; |
1018 | 1018 | } |
1019 | 1019 | } |
1020 | 1020 | |
1021 | - $subtotal_percent = ( ( $price * $item['quantity'] ) / $items_subtotal ); |
|
1022 | - $code_amount = wpinv_get_discount_amount( $code_id ); |
|
1021 | + $subtotal_percent = (($price * $item['quantity']) / $items_subtotal); |
|
1022 | + $code_amount = wpinv_get_discount_amount($code_id); |
|
1023 | 1023 | $discounted_amount = $code_amount * $subtotal_percent; |
1024 | 1024 | $discounted_price -= $discounted_amount; |
1025 | 1025 | |
1026 | - $wpinv_flat_discount_total += round( $discounted_amount, wpinv_currency_decimal_filter() ); |
|
1026 | + $wpinv_flat_discount_total += round($discounted_amount, wpinv_currency_decimal_filter()); |
|
1027 | 1027 | |
1028 | - if ( $wpinv_is_last_cart_item && $wpinv_flat_discount_total < $code_amount ) { |
|
1028 | + if ($wpinv_is_last_cart_item && $wpinv_flat_discount_total < $code_amount) { |
|
1029 | 1029 | $adjustment = $code_amount - $wpinv_flat_discount_total; |
1030 | 1030 | $discounted_price -= $adjustment; |
1031 | 1031 | } |
1032 | 1032 | } else { |
1033 | - $discounted_price -= $price - wpinv_get_discounted_amount( $discount, $price ); |
|
1033 | + $discounted_price -= $price - wpinv_get_discounted_amount($discount, $price); |
|
1034 | 1034 | } |
1035 | 1035 | } |
1036 | 1036 | } |
1037 | 1037 | } |
1038 | 1038 | |
1039 | - $amount = ( $price - apply_filters( 'wpinv_get_cart_item_discounted_amount', $discounted_price, $discounts, $item, $price ) ); |
|
1039 | + $amount = ($price - apply_filters('wpinv_get_cart_item_discounted_amount', $discounted_price, $discounts, $item, $price)); |
|
1040 | 1040 | |
1041 | - if ( 'flat' !== wpinv_get_discount_type( $code_id ) ) { |
|
1041 | + if ('flat' !== wpinv_get_discount_type($code_id)) { |
|
1042 | 1042 | $amount = $amount * $item['quantity']; |
1043 | 1043 | } |
1044 | 1044 | } |
@@ -1046,59 +1046,59 @@ discard block |
||
1046 | 1046 | return $amount; |
1047 | 1047 | } |
1048 | 1048 | |
1049 | -function wpinv_cart_discounts_html( $items = array() ) { |
|
1050 | - echo wpinv_get_cart_discounts_html( $items ); |
|
1049 | +function wpinv_cart_discounts_html($items = array()) { |
|
1050 | + echo wpinv_get_cart_discounts_html($items); |
|
1051 | 1051 | } |
1052 | 1052 | |
1053 | -function wpinv_get_cart_discounts_html( $items = array(), $discounts = false ) { |
|
1053 | +function wpinv_get_cart_discounts_html($items = array(), $discounts = false) { |
|
1054 | 1054 | global $wpi_cart_columns; |
1055 | 1055 | |
1056 | - $items = !empty( $items ) ? $items : wpinv_get_cart_content_details(); |
|
1056 | + $items = !empty($items) ? $items : wpinv_get_cart_content_details(); |
|
1057 | 1057 | |
1058 | - if ( !$discounts ) { |
|
1059 | - $discounts = wpinv_get_cart_discounts( $items ); |
|
1058 | + if (!$discounts) { |
|
1059 | + $discounts = wpinv_get_cart_discounts($items); |
|
1060 | 1060 | } |
1061 | 1061 | |
1062 | - if ( !$discounts ) { |
|
1062 | + if (!$discounts) { |
|
1063 | 1063 | return; |
1064 | 1064 | } |
1065 | 1065 | |
1066 | - $discounts = is_array( $discounts ) ? $discounts : array( $discounts ); |
|
1066 | + $discounts = is_array($discounts) ? $discounts : array($discounts); |
|
1067 | 1067 | |
1068 | 1068 | $html = ''; |
1069 | 1069 | |
1070 | - foreach ( $discounts as $discount ) { |
|
1071 | - $discount_id = wpinv_get_discount_id_by_code( $discount ); |
|
1072 | - $discount_value = wpinv_get_discount_amount( $discount_id ); |
|
1073 | - $rate = wpinv_format_discount_rate( wpinv_get_discount_type( $discount_id ), $discount_value ); |
|
1074 | - $amount = wpinv_get_cart_items_discount_amount( $items, $discount ); |
|
1075 | - $remove_btn = '<a title="' . esc_attr__( 'Remove discount', 'invoicing' ) . '" data-code="' . $discount . '" data-value="' . $discount_value . '" class="wpi-discount-remove" href="javascript:void(0);">[<i class="fa fa-times" aria-hidden="true"></i>]</a> '; |
|
1070 | + foreach ($discounts as $discount) { |
|
1071 | + $discount_id = wpinv_get_discount_id_by_code($discount); |
|
1072 | + $discount_value = wpinv_get_discount_amount($discount_id); |
|
1073 | + $rate = wpinv_format_discount_rate(wpinv_get_discount_type($discount_id), $discount_value); |
|
1074 | + $amount = wpinv_get_cart_items_discount_amount($items, $discount); |
|
1075 | + $remove_btn = '<a title="' . esc_attr__('Remove discount', 'invoicing') . '" data-code="' . $discount . '" data-value="' . $discount_value . '" class="wpi-discount-remove" href="javascript:void(0);">[<i class="fa fa-times" aria-hidden="true"></i>]</a> '; |
|
1076 | 1076 | |
1077 | 1077 | $html .= '<tr class="wpinv_cart_footer_row wpinv_cart_discount_row">'; |
1078 | 1078 | ob_start(); |
1079 | - do_action( 'wpinv_checkout_table_discount_first', $items ); |
|
1079 | + do_action('wpinv_checkout_table_discount_first', $items); |
|
1080 | 1080 | $html .= ob_get_clean(); |
1081 | - $html .= '<td class="wpinv_cart_discount_label text-right" colspan="' . $wpi_cart_columns . '">' . $remove_btn . '<strong>' . wpinv_cart_discount_label( $discount, $rate, false ) . '</strong></td><td class="wpinv_cart_discount text-right"><span data-discount="' . $amount . '" class="wpinv_cart_discount_amount">–' . wpinv_price( wpinv_format_amount( $amount ) ) . '</span></td>'; |
|
1081 | + $html .= '<td class="wpinv_cart_discount_label text-right" colspan="' . $wpi_cart_columns . '">' . $remove_btn . '<strong>' . wpinv_cart_discount_label($discount, $rate, false) . '</strong></td><td class="wpinv_cart_discount text-right"><span data-discount="' . $amount . '" class="wpinv_cart_discount_amount">–' . wpinv_price(wpinv_format_amount($amount)) . '</span></td>'; |
|
1082 | 1082 | ob_start(); |
1083 | - do_action( 'wpinv_checkout_table_discount_last', $items ); |
|
1083 | + do_action('wpinv_checkout_table_discount_last', $items); |
|
1084 | 1084 | $html .= ob_get_clean(); |
1085 | 1085 | $html .= '</tr>'; |
1086 | 1086 | } |
1087 | 1087 | |
1088 | - return apply_filters( 'wpinv_get_cart_discounts_html', $html, $discounts, $rate ); |
|
1088 | + return apply_filters('wpinv_get_cart_discounts_html', $html, $discounts, $rate); |
|
1089 | 1089 | } |
1090 | 1090 | |
1091 | -function wpinv_display_cart_discount( $formatted = false, $echo = false ) { |
|
1091 | +function wpinv_display_cart_discount($formatted = false, $echo = false) { |
|
1092 | 1092 | $discounts = wpinv_get_cart_discounts(); |
1093 | 1093 | |
1094 | - if ( empty( $discounts ) ) { |
|
1094 | + if (empty($discounts)) { |
|
1095 | 1095 | return false; |
1096 | 1096 | } |
1097 | 1097 | |
1098 | - $discount_id = wpinv_get_discount_id_by_code( $discounts[0] ); |
|
1099 | - $amount = wpinv_format_discount_rate( wpinv_get_discount_type( $discount_id ), wpinv_get_discount_amount( $discount_id ) ); |
|
1098 | + $discount_id = wpinv_get_discount_id_by_code($discounts[0]); |
|
1099 | + $amount = wpinv_format_discount_rate(wpinv_get_discount_type($discount_id), wpinv_get_discount_amount($discount_id)); |
|
1100 | 1100 | |
1101 | - if ( $echo ) { |
|
1101 | + if ($echo) { |
|
1102 | 1102 | echo $amount; |
1103 | 1103 | } |
1104 | 1104 | |
@@ -1106,135 +1106,135 @@ discard block |
||
1106 | 1106 | } |
1107 | 1107 | |
1108 | 1108 | function wpinv_remove_cart_discount() { |
1109 | - if ( !isset( $_GET['discount_id'] ) || ! isset( $_GET['discount_code'] ) ) { |
|
1109 | + if (!isset($_GET['discount_id']) || !isset($_GET['discount_code'])) { |
|
1110 | 1110 | return; |
1111 | 1111 | } |
1112 | 1112 | |
1113 | - do_action( 'wpinv_pre_remove_cart_discount', absint( $_GET['discount_id'] ) ); |
|
1113 | + do_action('wpinv_pre_remove_cart_discount', absint($_GET['discount_id'])); |
|
1114 | 1114 | |
1115 | - wpinv_unset_cart_discount( urldecode( $_GET['discount_code'] ) ); |
|
1115 | + wpinv_unset_cart_discount(urldecode($_GET['discount_code'])); |
|
1116 | 1116 | |
1117 | - do_action( 'wpinv_post_remove_cart_discount', absint( $_GET['discount_id'] ) ); |
|
1117 | + do_action('wpinv_post_remove_cart_discount', absint($_GET['discount_id'])); |
|
1118 | 1118 | |
1119 | - wp_redirect( wpinv_get_checkout_uri() ); wpinv_die(); |
|
1119 | + wp_redirect(wpinv_get_checkout_uri()); wpinv_die(); |
|
1120 | 1120 | } |
1121 | -add_action( 'wpinv_remove_cart_discount', 'wpinv_remove_cart_discount' ); |
|
1121 | +add_action('wpinv_remove_cart_discount', 'wpinv_remove_cart_discount'); |
|
1122 | 1122 | |
1123 | -function wpinv_maybe_remove_cart_discount( $cart_key = 0 ) { |
|
1123 | +function wpinv_maybe_remove_cart_discount($cart_key = 0) { |
|
1124 | 1124 | $discounts = wpinv_get_cart_discounts(); |
1125 | 1125 | |
1126 | - if ( !$discounts ) { |
|
1126 | + if (!$discounts) { |
|
1127 | 1127 | return; |
1128 | 1128 | } |
1129 | 1129 | |
1130 | - foreach ( $discounts as $discount ) { |
|
1131 | - if ( !wpinv_is_discount_valid( $discount ) ) { |
|
1132 | - wpinv_unset_cart_discount( $discount ); |
|
1130 | + foreach ($discounts as $discount) { |
|
1131 | + if (!wpinv_is_discount_valid($discount)) { |
|
1132 | + wpinv_unset_cart_discount($discount); |
|
1133 | 1133 | } |
1134 | 1134 | } |
1135 | 1135 | } |
1136 | -add_action( 'wpinv_post_remove_from_cart', 'wpinv_maybe_remove_cart_discount' ); |
|
1136 | +add_action('wpinv_post_remove_from_cart', 'wpinv_maybe_remove_cart_discount'); |
|
1137 | 1137 | |
1138 | 1138 | function wpinv_multiple_discounts_allowed() { |
1139 | - $ret = wpinv_get_option( 'allow_multiple_discounts', false ); |
|
1140 | - return (bool) apply_filters( 'wpinv_multiple_discounts_allowed', $ret ); |
|
1139 | + $ret = wpinv_get_option('allow_multiple_discounts', false); |
|
1140 | + return (bool)apply_filters('wpinv_multiple_discounts_allowed', $ret); |
|
1141 | 1141 | } |
1142 | 1142 | |
1143 | 1143 | function wpinv_listen_for_cart_discount() { |
1144 | 1144 | global $wpi_session; |
1145 | 1145 | |
1146 | - if ( empty( $_REQUEST['discount'] ) || is_array( $_REQUEST['discount'] ) ) { |
|
1146 | + if (empty($_REQUEST['discount']) || is_array($_REQUEST['discount'])) { |
|
1147 | 1147 | return; |
1148 | 1148 | } |
1149 | 1149 | |
1150 | - $code = preg_replace('/[^a-zA-Z0-9-_]+/', '', $_REQUEST['discount'] ); |
|
1150 | + $code = preg_replace('/[^a-zA-Z0-9-_]+/', '', $_REQUEST['discount']); |
|
1151 | 1151 | |
1152 | - $wpi_session->set( 'preset_discount', $code ); |
|
1152 | + $wpi_session->set('preset_discount', $code); |
|
1153 | 1153 | } |
1154 | 1154 | //add_action( 'init', 'wpinv_listen_for_cart_discount', 0 ); |
1155 | 1155 | |
1156 | 1156 | function wpinv_apply_preset_discount() { |
1157 | 1157 | global $wpi_session; |
1158 | 1158 | |
1159 | - $code = $wpi_session->get( 'preset_discount' ); |
|
1159 | + $code = $wpi_session->get('preset_discount'); |
|
1160 | 1160 | |
1161 | - if ( !$code ) { |
|
1161 | + if (!$code) { |
|
1162 | 1162 | return; |
1163 | 1163 | } |
1164 | 1164 | |
1165 | - if ( !wpinv_is_discount_valid( $code, '', false ) ) { |
|
1165 | + if (!wpinv_is_discount_valid($code, '', false)) { |
|
1166 | 1166 | return; |
1167 | 1167 | } |
1168 | 1168 | |
1169 | - $code = apply_filters( 'wpinv_apply_preset_discount', $code ); |
|
1169 | + $code = apply_filters('wpinv_apply_preset_discount', $code); |
|
1170 | 1170 | |
1171 | - wpinv_set_cart_discount( $code ); |
|
1171 | + wpinv_set_cart_discount($code); |
|
1172 | 1172 | |
1173 | - $wpi_session->set( 'preset_discount', null ); |
|
1173 | + $wpi_session->set('preset_discount', null); |
|
1174 | 1174 | } |
1175 | 1175 | //add_action( 'init', 'wpinv_apply_preset_discount', 999 ); |
1176 | 1176 | |
1177 | -function wpinv_get_discount_label( $code, $echo = true ) { |
|
1178 | - $label = wp_sprintf( __( 'Discount%1$s', 'invoicing' ), ( $code != '' && $code != 'none' ? ' (<code>' . $code . '</code>)': '' ) ); |
|
1179 | - $label = apply_filters( 'wpinv_get_discount_label', $label, $code ); |
|
1177 | +function wpinv_get_discount_label($code, $echo = true) { |
|
1178 | + $label = wp_sprintf(__('Discount%1$s', 'invoicing'), ($code != '' && $code != 'none' ? ' (<code>' . $code . '</code>)' : '')); |
|
1179 | + $label = apply_filters('wpinv_get_discount_label', $label, $code); |
|
1180 | 1180 | |
1181 | - if ( $echo ) { |
|
1181 | + if ($echo) { |
|
1182 | 1182 | echo $label; |
1183 | 1183 | } else { |
1184 | 1184 | return $label; |
1185 | 1185 | } |
1186 | 1186 | } |
1187 | 1187 | |
1188 | -function wpinv_cart_discount_label( $code, $rate, $echo = true ) { |
|
1189 | - $label = wp_sprintf( __( '%1$s Discount: %2$s', 'invoicing' ), $rate, $code ); |
|
1190 | - $label = apply_filters( 'wpinv_cart_discount_label', $label, $code, $rate ); |
|
1188 | +function wpinv_cart_discount_label($code, $rate, $echo = true) { |
|
1189 | + $label = wp_sprintf(__('%1$s Discount: %2$s', 'invoicing'), $rate, $code); |
|
1190 | + $label = apply_filters('wpinv_cart_discount_label', $label, $code, $rate); |
|
1191 | 1191 | |
1192 | - if ( $echo ) { |
|
1192 | + if ($echo) { |
|
1193 | 1193 | echo $label; |
1194 | 1194 | } else { |
1195 | 1195 | return $label; |
1196 | 1196 | } |
1197 | 1197 | } |
1198 | 1198 | |
1199 | -function wpinv_check_delete_discount( $check, $post, $force_delete ) { |
|
1200 | - if ( $post->post_type == 'wpi_discount' && wpinv_get_discount_uses( $post->ID ) > 0 ) { |
|
1199 | +function wpinv_check_delete_discount($check, $post, $force_delete) { |
|
1200 | + if ($post->post_type == 'wpi_discount' && wpinv_get_discount_uses($post->ID) > 0) { |
|
1201 | 1201 | return true; |
1202 | 1202 | } |
1203 | 1203 | |
1204 | 1204 | return $check; |
1205 | 1205 | } |
1206 | -add_filter( 'pre_delete_post', 'wpinv_check_delete_discount', 10, 3 ); |
|
1206 | +add_filter('pre_delete_post', 'wpinv_check_delete_discount', 10, 3); |
|
1207 | 1207 | |
1208 | 1208 | function wpinv_checkout_form_validate_discounts() { |
1209 | 1209 | global $wpi_checkout_id; |
1210 | 1210 | |
1211 | 1211 | $discounts = wpinv_get_cart_discounts(); |
1212 | 1212 | |
1213 | - if ( !empty( $discounts ) ) { |
|
1213 | + if (!empty($discounts)) { |
|
1214 | 1214 | $invalid = false; |
1215 | 1215 | |
1216 | - foreach ( $discounts as $key => $code ) { |
|
1217 | - if ( !wpinv_is_discount_valid( $code, (int)wpinv_get_user_id( $wpi_checkout_id ) ) ) { |
|
1216 | + foreach ($discounts as $key => $code) { |
|
1217 | + if (!wpinv_is_discount_valid($code, (int)wpinv_get_user_id($wpi_checkout_id))) { |
|
1218 | 1218 | $invalid = true; |
1219 | 1219 | |
1220 | - wpinv_unset_cart_discount( $code ); |
|
1220 | + wpinv_unset_cart_discount($code); |
|
1221 | 1221 | } |
1222 | 1222 | } |
1223 | 1223 | |
1224 | - if ( $invalid ) { |
|
1224 | + if ($invalid) { |
|
1225 | 1225 | $errors = wpinv_get_errors(); |
1226 | - $error = !empty( $errors['wpinv-discount-error'] ) ? $errors['wpinv-discount-error'] . ' ' : ''; |
|
1227 | - $error .= __( 'The discount has been removed from cart.', 'invoicing' ); |
|
1228 | - wpinv_set_error( 'wpinv-discount-error', $error ); |
|
1226 | + $error = !empty($errors['wpinv-discount-error']) ? $errors['wpinv-discount-error'] . ' ' : ''; |
|
1227 | + $error .= __('The discount has been removed from cart.', 'invoicing'); |
|
1228 | + wpinv_set_error('wpinv-discount-error', $error); |
|
1229 | 1229 | |
1230 | - wpinv_recalculate_tax( true ); |
|
1230 | + wpinv_recalculate_tax(true); |
|
1231 | 1231 | } |
1232 | 1232 | } |
1233 | 1233 | } |
1234 | -add_action( 'wpinv_before_checkout_form', 'wpinv_checkout_form_validate_discounts', -10 ); |
|
1234 | +add_action('wpinv_before_checkout_form', 'wpinv_checkout_form_validate_discounts', -10); |
|
1235 | 1235 | |
1236 | 1236 | function wpinv_discount_amount() { |
1237 | 1237 | $output = 0.00; |
1238 | 1238 | |
1239 | - return apply_filters( 'wpinv_discount_amount', $output ); |
|
1239 | + return apply_filters('wpinv_discount_amount', $output); |
|
1240 | 1240 | } |
1241 | 1241 | \ No newline at end of file |
@@ -194,6 +194,9 @@ |
||
194 | 194 | return apply_filters( 'wpinv_is_tax_exclusive', $ret, $item_id ); |
195 | 195 | } |
196 | 196 | |
197 | +/** |
|
198 | + * @return integer |
|
199 | + */ |
|
197 | 200 | function wpinv_currency_decimal_filter( $decimals = 2 ) { |
198 | 201 | $currency = wpinv_get_currency(); |
199 | 202 |
@@ -70,8 +70,9 @@ discard block |
||
70 | 70 | if( !empty( $tax_rates ) ) { |
71 | 71 | // Locate the tax rate for this country / state, if it exists |
72 | 72 | foreach( $tax_rates as $key => $tax_rate ) { |
73 | - if( $country != $tax_rate['country'] ) |
|
74 | - continue; |
|
73 | + if( $country != $tax_rate['country'] ) { |
|
74 | + continue; |
|
75 | + } |
|
75 | 76 | |
76 | 77 | if( !empty( $tax_rate['global'] ) ) { |
77 | 78 | if( !empty( $tax_rate['rate'] ) ) { |
@@ -79,8 +80,9 @@ discard block |
||
79 | 80 | } |
80 | 81 | } else { |
81 | 82 | |
82 | - if( empty( $tax_rate['state'] ) || strtolower( $state ) != strtolower( $tax_rate['state'] ) ) |
|
83 | - continue; |
|
83 | + if( empty( $tax_rate['state'] ) || strtolower( $state ) != strtolower( $tax_rate['state'] ) ) { |
|
84 | + continue; |
|
85 | + } |
|
84 | 86 | |
85 | 87 | $state_rate = $tax_rate['rate']; |
86 | 88 | if( 0 !== $state_rate || !empty( $state_rate ) ) { |
@@ -183,8 +185,9 @@ discard block |
||
183 | 185 | } |
184 | 186 | |
185 | 187 | function wpinv_cart_needs_tax_address_fields() { |
186 | - if( !wpinv_is_cart_taxed() ) |
|
187 | - return false; |
|
188 | + if( !wpinv_is_cart_taxed() ) { |
|
189 | + return false; |
|
190 | + } |
|
188 | 191 | |
189 | 192 | return ! did_action( 'wpinv_after_cc_fields', 'wpinv_default_cc_address_fields' ); |
190 | 193 | } |
@@ -1,121 +1,121 @@ 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 | function wpinv_use_taxes() { |
8 | - $ret = wpinv_get_option( 'enable_taxes', false ); |
|
8 | + $ret = wpinv_get_option('enable_taxes', false); |
|
9 | 9 | |
10 | - return (bool) apply_filters( 'wpinv_use_taxes', $ret ); |
|
10 | + return (bool)apply_filters('wpinv_use_taxes', $ret); |
|
11 | 11 | } |
12 | 12 | |
13 | 13 | function wpinv_get_tax_rates() { |
14 | - $rates = get_option( 'wpinv_tax_rates', array() ); |
|
14 | + $rates = get_option('wpinv_tax_rates', array()); |
|
15 | 15 | |
16 | - return apply_filters( 'wpinv_get_tax_rates', $rates ); |
|
16 | + return apply_filters('wpinv_get_tax_rates', $rates); |
|
17 | 17 | } |
18 | 18 | |
19 | -function wpinv_get_tax_rate( $country = false, $state = false, $item_id = 0 ) { |
|
19 | +function wpinv_get_tax_rate($country = false, $state = false, $item_id = 0) { |
|
20 | 20 | global $wpinv_euvat, $wpi_tax_rates, $wpi_userID; |
21 | - $wpi_tax_rates = !empty( $wpi_tax_rates ) ? $wpi_tax_rates : array(); |
|
21 | + $wpi_tax_rates = !empty($wpi_tax_rates) ? $wpi_tax_rates : array(); |
|
22 | 22 | |
23 | - if ( !empty( $wpi_tax_rates ) && !empty( $item_id ) && isset( $wpi_tax_rates[$item_id] ) ) { |
|
23 | + if (!empty($wpi_tax_rates) && !empty($item_id) && isset($wpi_tax_rates[$item_id])) { |
|
24 | 24 | return $wpi_tax_rates[$item_id]; |
25 | 25 | } |
26 | 26 | |
27 | - if ( !$wpinv_euvat->item_is_taxable( $item_id, $country, $state ) ) { |
|
27 | + if (!$wpinv_euvat->item_is_taxable($item_id, $country, $state)) { |
|
28 | 28 | $wpi_tax_rates[$item_id] = 0; |
29 | 29 | return 0; |
30 | 30 | } |
31 | 31 | |
32 | 32 | $is_global = false; |
33 | - if ( $item_id == 'global' ) { |
|
33 | + if ($item_id == 'global') { |
|
34 | 34 | $is_global = true; |
35 | 35 | $item_id = 0; |
36 | 36 | } |
37 | 37 | |
38 | - $rate = (float)wpinv_get_option( 'tax_rate', 0 ); |
|
39 | - $user_address = wpinv_get_user_address( $wpi_userID ); |
|
38 | + $rate = (float)wpinv_get_option('tax_rate', 0); |
|
39 | + $user_address = wpinv_get_user_address($wpi_userID); |
|
40 | 40 | |
41 | - if( empty( $country ) ) { |
|
42 | - if( !empty( $_POST['wpinv_country'] ) ) { |
|
41 | + if (empty($country)) { |
|
42 | + if (!empty($_POST['wpinv_country'])) { |
|
43 | 43 | $country = $_POST['wpinv_country']; |
44 | - } elseif( !empty( $_POST['wpinv_country'] ) ) { |
|
44 | + } elseif (!empty($_POST['wpinv_country'])) { |
|
45 | 45 | $country = $_POST['wpinv_country']; |
46 | - } elseif( !empty( $_POST['country'] ) ) { |
|
46 | + } elseif (!empty($_POST['country'])) { |
|
47 | 47 | $country = $_POST['country']; |
48 | - } elseif( is_user_logged_in() && !empty( $user_address ) ) { |
|
48 | + } elseif (is_user_logged_in() && !empty($user_address)) { |
|
49 | 49 | $country = $user_address['country']; |
50 | 50 | } |
51 | - $country = !empty( $country ) ? $country : wpinv_get_default_country(); |
|
51 | + $country = !empty($country) ? $country : wpinv_get_default_country(); |
|
52 | 52 | } |
53 | 53 | |
54 | - if( empty( $state ) ) { |
|
55 | - if( !empty( $_POST['wpinv_state'] ) ) { |
|
54 | + if (empty($state)) { |
|
55 | + if (!empty($_POST['wpinv_state'])) { |
|
56 | 56 | $state = $_POST['wpinv_state']; |
57 | - } elseif( !empty( $_POST['wpinv_state'] ) ) { |
|
57 | + } elseif (!empty($_POST['wpinv_state'])) { |
|
58 | 58 | $state = $_POST['wpinv_state']; |
59 | - } elseif( !empty( $_POST['state'] ) ) { |
|
59 | + } elseif (!empty($_POST['state'])) { |
|
60 | 60 | $state = $_POST['state']; |
61 | - } elseif( is_user_logged_in() && !empty( $user_address ) ) { |
|
61 | + } elseif (is_user_logged_in() && !empty($user_address)) { |
|
62 | 62 | $state = $user_address['state']; |
63 | 63 | } |
64 | - $state = !empty( $state ) ? $state : wpinv_get_default_state(); |
|
64 | + $state = !empty($state) ? $state : wpinv_get_default_state(); |
|
65 | 65 | } |
66 | 66 | |
67 | - if( !empty( $country ) ) { |
|
68 | - $tax_rates = wpinv_get_tax_rates(); |
|
67 | + if (!empty($country)) { |
|
68 | + $tax_rates = wpinv_get_tax_rates(); |
|
69 | 69 | |
70 | - if( !empty( $tax_rates ) ) { |
|
70 | + if (!empty($tax_rates)) { |
|
71 | 71 | // Locate the tax rate for this country / state, if it exists |
72 | - foreach( $tax_rates as $key => $tax_rate ) { |
|
73 | - if( $country != $tax_rate['country'] ) |
|
72 | + foreach ($tax_rates as $key => $tax_rate) { |
|
73 | + if ($country != $tax_rate['country']) |
|
74 | 74 | continue; |
75 | 75 | |
76 | - if( !empty( $tax_rate['global'] ) ) { |
|
77 | - if( !empty( $tax_rate['rate'] ) ) { |
|
78 | - $rate = number_format( $tax_rate['rate'], 4 ); |
|
76 | + if (!empty($tax_rate['global'])) { |
|
77 | + if (!empty($tax_rate['rate'])) { |
|
78 | + $rate = number_format($tax_rate['rate'], 4); |
|
79 | 79 | } |
80 | 80 | } else { |
81 | 81 | |
82 | - if( empty( $tax_rate['state'] ) || strtolower( $state ) != strtolower( $tax_rate['state'] ) ) |
|
82 | + if (empty($tax_rate['state']) || strtolower($state) != strtolower($tax_rate['state'])) |
|
83 | 83 | continue; |
84 | 84 | |
85 | 85 | $state_rate = $tax_rate['rate']; |
86 | - if( 0 !== $state_rate || !empty( $state_rate ) ) { |
|
87 | - $rate = number_format( $state_rate, 4 ); |
|
86 | + if (0 !== $state_rate || !empty($state_rate)) { |
|
87 | + $rate = number_format($state_rate, 4); |
|
88 | 88 | } |
89 | 89 | } |
90 | 90 | } |
91 | 91 | } |
92 | 92 | } |
93 | 93 | |
94 | - $rate = apply_filters( 'wpinv_tax_rate', $rate, $country, $state, $item_id ); |
|
94 | + $rate = apply_filters('wpinv_tax_rate', $rate, $country, $state, $item_id); |
|
95 | 95 | |
96 | - if ( !empty( $item_id ) ) { |
|
96 | + if (!empty($item_id)) { |
|
97 | 97 | $wpi_tax_rates[$item_id] = $rate; |
98 | - } else if ( $is_global ) { |
|
98 | + } else if ($is_global) { |
|
99 | 99 | $wpi_tax_rates['global'] = $rate; |
100 | 100 | } |
101 | 101 | |
102 | 102 | return $rate; |
103 | 103 | } |
104 | 104 | |
105 | -function wpinv_get_formatted_tax_rate( $country = false, $state = false, $item_id ) { |
|
106 | - $rate = wpinv_get_tax_rate( $country, $state, $item_id ); |
|
107 | - $rate = round( $rate, 4 ); |
|
105 | +function wpinv_get_formatted_tax_rate($country = false, $state = false, $item_id) { |
|
106 | + $rate = wpinv_get_tax_rate($country, $state, $item_id); |
|
107 | + $rate = round($rate, 4); |
|
108 | 108 | $formatted = $rate .= '%'; |
109 | - return apply_filters( 'wpinv_formatted_tax_rate', $formatted, $rate, $country, $state, $item_id ); |
|
109 | + return apply_filters('wpinv_formatted_tax_rate', $formatted, $rate, $country, $state, $item_id); |
|
110 | 110 | } |
111 | 111 | |
112 | -function wpinv_calculate_tax( $amount = 0, $country = false, $state = false, $item_id = 0 ) { |
|
113 | - $rate = wpinv_get_tax_rate( $country, $state, $item_id ); |
|
112 | +function wpinv_calculate_tax($amount = 0, $country = false, $state = false, $item_id = 0) { |
|
113 | + $rate = wpinv_get_tax_rate($country, $state, $item_id); |
|
114 | 114 | $tax = 0.00; |
115 | 115 | |
116 | - if ( wpinv_use_taxes() ) { |
|
117 | - if ( wpinv_prices_include_tax() ) { |
|
118 | - $pre_tax = ( $amount / ( ( 1 + $rate ) * 0.01 ) ); |
|
116 | + if (wpinv_use_taxes()) { |
|
117 | + if (wpinv_prices_include_tax()) { |
|
118 | + $pre_tax = ($amount / ((1 + $rate) * 0.01)); |
|
119 | 119 | $tax = $amount - $pre_tax; |
120 | 120 | } else { |
121 | 121 | $tax = $amount * $rate * 0.01; |
@@ -123,46 +123,46 @@ discard block |
||
123 | 123 | |
124 | 124 | } |
125 | 125 | |
126 | - return apply_filters( 'wpinv_taxed_amount', $tax, $rate, $country, $state, $item_id ); |
|
126 | + return apply_filters('wpinv_taxed_amount', $tax, $rate, $country, $state, $item_id); |
|
127 | 127 | } |
128 | 128 | |
129 | 129 | function wpinv_prices_include_tax() { |
130 | 130 | return false; // TODO |
131 | - $ret = ( wpinv_get_option( 'prices_include_tax', false ) == 'yes' && wpinv_use_taxes() ); |
|
131 | + $ret = (wpinv_get_option('prices_include_tax', false) == 'yes' && wpinv_use_taxes()); |
|
132 | 132 | |
133 | - return apply_filters( 'wpinv_prices_include_tax', $ret ); |
|
133 | + return apply_filters('wpinv_prices_include_tax', $ret); |
|
134 | 134 | } |
135 | 135 | |
136 | -function wpinv_sales_tax_for_year( $year = null ) { |
|
137 | - return wpinv_price( wpinv_format_amount( wpinv_get_sales_tax_for_year( $year ) ) ); |
|
136 | +function wpinv_sales_tax_for_year($year = null) { |
|
137 | + return wpinv_price(wpinv_format_amount(wpinv_get_sales_tax_for_year($year))); |
|
138 | 138 | } |
139 | 139 | |
140 | -function wpinv_get_sales_tax_for_year( $year = null ) { |
|
140 | +function wpinv_get_sales_tax_for_year($year = null) { |
|
141 | 141 | global $wpdb; |
142 | 142 | |
143 | 143 | // Start at zero |
144 | 144 | $tax = 0; |
145 | 145 | |
146 | - if ( ! empty( $year ) ) { |
|
146 | + if (!empty($year)) { |
|
147 | 147 | $args = array( |
148 | 148 | 'post_type' => 'wpi_invoice', |
149 | - 'post_status' => array( 'publish' ), |
|
149 | + 'post_status' => array('publish'), |
|
150 | 150 | 'posts_per_page' => -1, |
151 | 151 | 'year' => $year, |
152 | 152 | 'fields' => 'ids' |
153 | 153 | ); |
154 | 154 | |
155 | - $payments = get_posts( $args ); |
|
156 | - $payment_ids = implode( ',', $payments ); |
|
155 | + $payments = get_posts($args); |
|
156 | + $payment_ids = implode(',', $payments); |
|
157 | 157 | |
158 | - if ( count( $payments ) > 0 ) { |
|
158 | + if (count($payments) > 0) { |
|
159 | 159 | $sql = "SELECT SUM( meta_value ) FROM $wpdb->postmeta WHERE meta_key = '_wpinv_tax' AND post_id IN( $payment_ids )"; |
160 | - $tax = $wpdb->get_var( $sql ); |
|
160 | + $tax = $wpdb->get_var($sql); |
|
161 | 161 | } |
162 | 162 | |
163 | 163 | } |
164 | 164 | |
165 | - return apply_filters( 'wpinv_get_sales_tax_for_year', $tax, $year ); |
|
165 | + return apply_filters('wpinv_get_sales_tax_for_year', $tax, $year); |
|
166 | 166 | } |
167 | 167 | |
168 | 168 | function wpinv_is_cart_taxed() { |
@@ -171,33 +171,33 @@ discard block |
||
171 | 171 | |
172 | 172 | function wpinv_prices_show_tax_on_checkout() { |
173 | 173 | return false; // TODO |
174 | - $ret = ( wpinv_get_option( 'checkout_include_tax', false ) == 'yes' && wpinv_use_taxes() ); |
|
174 | + $ret = (wpinv_get_option('checkout_include_tax', false) == 'yes' && wpinv_use_taxes()); |
|
175 | 175 | |
176 | - return apply_filters( 'wpinv_taxes_on_prices_on_checkout', $ret ); |
|
176 | + return apply_filters('wpinv_taxes_on_prices_on_checkout', $ret); |
|
177 | 177 | } |
178 | 178 | |
179 | 179 | function wpinv_display_tax_rate() { |
180 | - $ret = wpinv_use_taxes() && wpinv_get_option( 'display_tax_rate', false ); |
|
180 | + $ret = wpinv_use_taxes() && wpinv_get_option('display_tax_rate', false); |
|
181 | 181 | |
182 | - return apply_filters( 'wpinv_display_tax_rate', $ret ); |
|
182 | + return apply_filters('wpinv_display_tax_rate', $ret); |
|
183 | 183 | } |
184 | 184 | |
185 | 185 | function wpinv_cart_needs_tax_address_fields() { |
186 | - if( !wpinv_is_cart_taxed() ) |
|
186 | + if (!wpinv_is_cart_taxed()) |
|
187 | 187 | return false; |
188 | 188 | |
189 | - return ! did_action( 'wpinv_after_cc_fields', 'wpinv_default_cc_address_fields' ); |
|
189 | + return !did_action('wpinv_after_cc_fields', 'wpinv_default_cc_address_fields'); |
|
190 | 190 | } |
191 | 191 | |
192 | -function wpinv_item_is_tax_exclusive( $item_id = 0 ) { |
|
193 | - $ret = (bool)get_post_meta( $item_id, '_wpinv_tax_exclusive', false ); |
|
194 | - return apply_filters( 'wpinv_is_tax_exclusive', $ret, $item_id ); |
|
192 | +function wpinv_item_is_tax_exclusive($item_id = 0) { |
|
193 | + $ret = (bool)get_post_meta($item_id, '_wpinv_tax_exclusive', false); |
|
194 | + return apply_filters('wpinv_is_tax_exclusive', $ret, $item_id); |
|
195 | 195 | } |
196 | 196 | |
197 | -function wpinv_currency_decimal_filter( $decimals = 2 ) { |
|
197 | +function wpinv_currency_decimal_filter($decimals = 2) { |
|
198 | 198 | $currency = wpinv_get_currency(); |
199 | 199 | |
200 | - switch ( $currency ) { |
|
200 | + switch ($currency) { |
|
201 | 201 | case 'RIAL' : |
202 | 202 | case 'JPY' : |
203 | 203 | case 'TWD' : |
@@ -206,48 +206,48 @@ discard block |
||
206 | 206 | break; |
207 | 207 | } |
208 | 208 | |
209 | - return apply_filters( 'wpinv_currency_decimal_count', $decimals, $currency ); |
|
209 | + return apply_filters('wpinv_currency_decimal_count', $decimals, $currency); |
|
210 | 210 | } |
211 | 211 | |
212 | 212 | function wpinv_tax_amount() { |
213 | 213 | $output = 0.00; |
214 | 214 | |
215 | - return apply_filters( 'wpinv_tax_amount', $output ); |
|
215 | + return apply_filters('wpinv_tax_amount', $output); |
|
216 | 216 | } |
217 | 217 | |
218 | 218 | function wpinv_recalculated_tax() { |
219 | - define( 'WPINV_RECALCTAX', true ); |
|
219 | + define('WPINV_RECALCTAX', true); |
|
220 | 220 | } |
221 | -add_action( 'wp_ajax_wpinv_recalculate_tax', 'wpinv_recalculated_tax', 1 ); |
|
221 | +add_action('wp_ajax_wpinv_recalculate_tax', 'wpinv_recalculated_tax', 1); |
|
222 | 222 | |
223 | -function wpinv_recalculate_tax( $return = false ) { |
|
223 | +function wpinv_recalculate_tax($return = false) { |
|
224 | 224 | $invoice_id = (int)wpinv_get_invoice_cart_id(); |
225 | - if ( empty( $invoice_id ) ) { |
|
225 | + if (empty($invoice_id)) { |
|
226 | 226 | return false; |
227 | 227 | } |
228 | 228 | |
229 | - $invoice = wpinv_get_invoice_cart( $invoice_id ); |
|
229 | + $invoice = wpinv_get_invoice_cart($invoice_id); |
|
230 | 230 | |
231 | - if ( empty( $invoice ) ) { |
|
231 | + if (empty($invoice)) { |
|
232 | 232 | return false; |
233 | 233 | } |
234 | 234 | |
235 | - if ( empty( $_POST['country'] ) ) { |
|
235 | + if (empty($_POST['country'])) { |
|
236 | 236 | $_POST['country'] = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country(); |
237 | 237 | } |
238 | 238 | |
239 | 239 | $invoice->country = sanitize_text_field($_POST['country']); |
240 | - $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) ); |
|
240 | + $invoice->set('country', sanitize_text_field($_POST['country'])); |
|
241 | 241 | if (isset($_POST['state'])) { |
242 | 242 | $invoice->state = sanitize_text_field($_POST['state']); |
243 | - $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) ); |
|
243 | + $invoice->set('state', sanitize_text_field($_POST['state'])); |
|
244 | 244 | } |
245 | 245 | |
246 | 246 | $invoice->cart_details = wpinv_get_cart_content_details(); |
247 | 247 | |
248 | - $subtotal = wpinv_get_cart_subtotal( $invoice->cart_details ); |
|
249 | - $tax = wpinv_get_cart_tax( $invoice->cart_details ); |
|
250 | - $total = wpinv_get_cart_total( $invoice->cart_details ); |
|
248 | + $subtotal = wpinv_get_cart_subtotal($invoice->cart_details); |
|
249 | + $tax = wpinv_get_cart_tax($invoice->cart_details); |
|
250 | + $total = wpinv_get_cart_total($invoice->cart_details); |
|
251 | 251 | |
252 | 252 | $invoice->tax = $tax; |
253 | 253 | $invoice->subtotal = $subtotal; |
@@ -255,61 +255,61 @@ discard block |
||
255 | 255 | |
256 | 256 | $invoice->save(); |
257 | 257 | |
258 | - if ( $invoice->is_free_trial() ) { |
|
258 | + if ($invoice->is_free_trial()) { |
|
259 | 259 | $total = 0; |
260 | 260 | } |
261 | 261 | |
262 | 262 | $response = array( |
263 | - 'total' => html_entity_decode( wpinv_price( wpinv_format_amount( $total ) ), ENT_COMPAT, 'UTF-8' ), |
|
263 | + 'total' => html_entity_decode(wpinv_price(wpinv_format_amount($total)), ENT_COMPAT, 'UTF-8'), |
|
264 | 264 | 'total_raw' => $total, |
265 | - 'free' => !( (float)$total > 0 ) && $invoice->is_free() ? true : false, |
|
266 | - 'html' => wpinv_checkout_cart( $invoice->cart_details, false ), |
|
265 | + 'free' => !((float)$total > 0) && $invoice->is_free() ? true : false, |
|
266 | + 'html' => wpinv_checkout_cart($invoice->cart_details, false), |
|
267 | 267 | ); |
268 | 268 | |
269 | - if ( $return ) { |
|
269 | + if ($return) { |
|
270 | 270 | return $response; |
271 | 271 | } |
272 | 272 | |
273 | - wp_send_json( $response ); |
|
273 | + wp_send_json($response); |
|
274 | 274 | } |
275 | -add_action( 'wp_ajax_wpinv_recalculate_tax', 'wpinv_recalculate_tax' ); |
|
276 | -add_action( 'wp_ajax_nopriv_wpinv_recalculate_tax', 'wpinv_recalculate_tax' ); |
|
275 | +add_action('wp_ajax_wpinv_recalculate_tax', 'wpinv_recalculate_tax'); |
|
276 | +add_action('wp_ajax_nopriv_wpinv_recalculate_tax', 'wpinv_recalculate_tax'); |
|
277 | 277 | |
278 | 278 | // VAT Settings |
279 | -function wpinv_vat_rate_add_callback( $args ) { |
|
279 | +function wpinv_vat_rate_add_callback($args) { |
|
280 | 280 | ?> |
281 | - <p class="wpi-vat-rate-actions"><input id="wpi_vat_rate_add" type="button" value="<?php esc_attr_e( 'Add', 'invoicing' );?>" class="button button-primary" /> <i style="display:none;" class="fa fa-refresh fa-spin"></i></p> |
|
281 | + <p class="wpi-vat-rate-actions"><input id="wpi_vat_rate_add" type="button" value="<?php esc_attr_e('Add', 'invoicing'); ?>" class="button button-primary" /> <i style="display:none;" class="fa fa-refresh fa-spin"></i></p> |
|
282 | 282 | <?php |
283 | 283 | } |
284 | 284 | |
285 | -function wpinv_vat_rate_delete_callback( $args ) { |
|
285 | +function wpinv_vat_rate_delete_callback($args) { |
|
286 | 286 | global $wpinv_euvat; |
287 | 287 | |
288 | 288 | $vat_classes = $wpinv_euvat->get_rate_classes(); |
289 | - $vat_class = isset( $_REQUEST['wpi_sub'] ) && $_REQUEST['wpi_sub'] !== '' && isset( $vat_classes[$_REQUEST['wpi_sub']] )? sanitize_text_field( $_REQUEST['wpi_sub'] ) : ''; |
|
290 | - if ( isset( $vat_classes[$vat_class] ) ) { |
|
289 | + $vat_class = isset($_REQUEST['wpi_sub']) && $_REQUEST['wpi_sub'] !== '' && isset($vat_classes[$_REQUEST['wpi_sub']]) ? sanitize_text_field($_REQUEST['wpi_sub']) : ''; |
|
290 | + if (isset($vat_classes[$vat_class])) { |
|
291 | 291 | ?> |
292 | - <p class="wpi-vat-rate-actions"><input id="wpi_vat_rate_delete" type="button" value="<?php echo wp_sprintf( esc_attr__( 'Delete class "%s"', 'invoicing' ), $vat_classes[$vat_class] );?>" class="button button-primary" /> <i style="display:none;" class="fa fa-refresh fa-spin"></i></p> |
|
292 | + <p class="wpi-vat-rate-actions"><input id="wpi_vat_rate_delete" type="button" value="<?php echo wp_sprintf(esc_attr__('Delete class "%s"', 'invoicing'), $vat_classes[$vat_class]); ?>" class="button button-primary" /> <i style="display:none;" class="fa fa-refresh fa-spin"></i></p> |
|
293 | 293 | <?php |
294 | 294 | } |
295 | 295 | } |
296 | 296 | |
297 | -function wpinv_vat_rates_callback( $args ) { |
|
297 | +function wpinv_vat_rates_callback($args) { |
|
298 | 298 | global $wpinv_euvat; |
299 | 299 | |
300 | 300 | $vat_classes = $wpinv_euvat->get_rate_classes(); |
301 | - $vat_class = isset( $_REQUEST['wpi_sub'] ) && $_REQUEST['wpi_sub'] !== '' && isset( $vat_classes[$_REQUEST['wpi_sub']] )? sanitize_text_field( $_REQUEST['wpi_sub'] ) : '_standard'; |
|
301 | + $vat_class = isset($_REQUEST['wpi_sub']) && $_REQUEST['wpi_sub'] !== '' && isset($vat_classes[$_REQUEST['wpi_sub']]) ? sanitize_text_field($_REQUEST['wpi_sub']) : '_standard'; |
|
302 | 302 | |
303 | 303 | $eu_states = $wpinv_euvat->get_eu_states(); |
304 | 304 | $countries = wpinv_get_country_list(); |
305 | 305 | $vat_groups = $wpinv_euvat->get_vat_groups(); |
306 | - $rates = $wpinv_euvat->get_vat_rates( $vat_class ); |
|
306 | + $rates = $wpinv_euvat->get_vat_rates($vat_class); |
|
307 | 307 | ob_start(); |
308 | 308 | ?> |
309 | 309 | </td><tr> |
310 | 310 | <td colspan="2" class="wpinv_vat_tdbox"> |
311 | - <input type="hidden" name="wpi_vat_class" value="<?php echo $vat_class;?>" /> |
|
312 | - <p><?php echo ( isset( $args['desc'] ) ? $args['desc'] : '' ); ?></p> |
|
311 | + <input type="hidden" name="wpi_vat_class" value="<?php echo $vat_class; ?>" /> |
|
312 | + <p><?php echo (isset($args['desc']) ? $args['desc'] : ''); ?></p> |
|
313 | 313 | <table id="wpinv_vat_rates" class="wp-list-table widefat fixed posts"> |
314 | 314 | <colgroup> |
315 | 315 | <col width="50px" /> |
@@ -321,43 +321,43 @@ discard block |
||
321 | 321 | </colgroup> |
322 | 322 | <thead> |
323 | 323 | <tr> |
324 | - <th scope="col" colspan="2" class="wpinv_vat_country_name"><?php _e( 'Country', 'invoicing' ); ?></th> |
|
325 | - <th scope="col" class="wpinv_vat_global" title="<?php esc_attr_e( 'Apply rate to whole country', 'invoicing' ); ?>"><?php _e( 'Country Wide', 'invoicing' ); ?></th> |
|
326 | - <th scope="col" class="wpinv_vat_rate"><?php _e( 'Rate %', 'invoicing' ); ?></th> |
|
327 | - <th scope="col" class="wpinv_vat_name"><?php _e( 'VAT Name', 'invoicing' ); ?></th> |
|
328 | - <th scope="col" class="wpinv_vat_group"><?php _e( 'Tax Group', 'invoicing' ); ?></th> |
|
324 | + <th scope="col" colspan="2" class="wpinv_vat_country_name"><?php _e('Country', 'invoicing'); ?></th> |
|
325 | + <th scope="col" class="wpinv_vat_global" title="<?php esc_attr_e('Apply rate to whole country', 'invoicing'); ?>"><?php _e('Country Wide', 'invoicing'); ?></th> |
|
326 | + <th scope="col" class="wpinv_vat_rate"><?php _e('Rate %', 'invoicing'); ?></th> |
|
327 | + <th scope="col" class="wpinv_vat_name"><?php _e('VAT Name', 'invoicing'); ?></th> |
|
328 | + <th scope="col" class="wpinv_vat_group"><?php _e('Tax Group', 'invoicing'); ?></th> |
|
329 | 329 | </tr> |
330 | 330 | </thead> |
331 | 331 | <tbody> |
332 | - <?php if( !empty( $eu_states ) ) { ?> |
|
332 | + <?php if (!empty($eu_states)) { ?> |
|
333 | 333 | <?php |
334 | - foreach ( $eu_states as $state ) { |
|
335 | - $country_name = isset( $countries[$state] ) ? $countries[$state] : ''; |
|
334 | + foreach ($eu_states as $state) { |
|
335 | + $country_name = isset($countries[$state]) ? $countries[$state] : ''; |
|
336 | 336 | |
337 | 337 | // Filter the rate for each country |
338 | - $country_rate = array_filter( $rates, function( $rate ) use( $state ) { return $rate['country'] === $state; } ); |
|
338 | + $country_rate = array_filter($rates, function($rate) use($state) { return $rate['country'] === $state; } ); |
|
339 | 339 | |
340 | 340 | // If one does not exist create a default |
341 | - $country_rate = is_array( $country_rate ) && count( $country_rate ) > 0 ? reset( $country_rate ) : array(); |
|
341 | + $country_rate = is_array($country_rate) && count($country_rate) > 0 ? reset($country_rate) : array(); |
|
342 | 342 | |
343 | - $vat_global = isset( $country_rate['global'] ) ? !empty( $country_rate['global'] ) : true; |
|
344 | - $vat_rate = isset( $country_rate['rate'] ) ? $country_rate['rate'] : ''; |
|
345 | - $vat_name = !empty( $country_rate['name'] ) ? esc_attr( stripslashes( $country_rate['name'] ) ) : ''; |
|
346 | - $vat_group = !empty( $country_rate['group'] ) ? $country_rate['group'] : ( $vat_class === '_standard' ? 'standard' : 'reduced' ); |
|
343 | + $vat_global = isset($country_rate['global']) ? !empty($country_rate['global']) : true; |
|
344 | + $vat_rate = isset($country_rate['rate']) ? $country_rate['rate'] : ''; |
|
345 | + $vat_name = !empty($country_rate['name']) ? esc_attr(stripslashes($country_rate['name'])) : ''; |
|
346 | + $vat_group = !empty($country_rate['group']) ? $country_rate['group'] : ($vat_class === '_standard' ? 'standard' : 'reduced'); |
|
347 | 347 | ?> |
348 | 348 | <tr> |
349 | 349 | <td class="wpinv_vat_country"><?php echo $state; ?><input type="hidden" name="vat_rates[<?php echo $state; ?>][country]" value="<?php echo $state; ?>" /><input type="hidden" name="vat_rates[<?php echo $state; ?>][state]" value="" /></td> |
350 | 350 | <td class="wpinv_vat_country_name"><?php echo $country_name; ?></td> |
351 | 351 | <td class="wpinv_vat_global"> |
352 | - <input type="checkbox" name="vat_rates[<?php echo $state;?>][global]" id="vat_rates[<?php echo $state;?>][global]" value="1" <?php checked( true, $vat_global );?> disabled="disabled" /> |
|
353 | - <label for="tax_rates[<?php echo $state;?>][global]"><?php _e( 'Apply to whole country', 'invoicing' ); ?></label> |
|
354 | - <input type="hidden" name="vat_rates[<?php echo $state;?>][global]" value="1" checked="checked" /> |
|
352 | + <input type="checkbox" name="vat_rates[<?php echo $state; ?>][global]" id="vat_rates[<?php echo $state; ?>][global]" value="1" <?php checked(true, $vat_global); ?> disabled="disabled" /> |
|
353 | + <label for="tax_rates[<?php echo $state; ?>][global]"><?php _e('Apply to whole country', 'invoicing'); ?></label> |
|
354 | + <input type="hidden" name="vat_rates[<?php echo $state; ?>][global]" value="1" checked="checked" /> |
|
355 | 355 | </td> |
356 | - <td class="wpinv_vat_rate"><input type="number" class="small-text" step="any" min="0" max="99" name="vat_rates[<?php echo $state;?>][rate]" value="<?php echo $vat_rate; ?>" /></td> |
|
357 | - <td class="wpinv_vat_name"><input type="text" class="regular-text" name="vat_rates[<?php echo $state;?>][name]" value="<?php echo $vat_name; ?>" /></td> |
|
356 | + <td class="wpinv_vat_rate"><input type="number" class="small-text" step="any" min="0" max="99" name="vat_rates[<?php echo $state; ?>][rate]" value="<?php echo $vat_rate; ?>" /></td> |
|
357 | + <td class="wpinv_vat_name"><input type="text" class="regular-text" name="vat_rates[<?php echo $state; ?>][name]" value="<?php echo $vat_name; ?>" /></td> |
|
358 | 358 | <td class="wpinv_vat_group"> |
359 | 359 | <?php |
360 | - echo wpinv_html_select( array( |
|
360 | + echo wpinv_html_select(array( |
|
361 | 361 | 'name' => 'vat_rates[' . $state . '][group]', |
362 | 362 | 'selected' => $vat_group, |
363 | 363 | 'id' => 'vat_rates[' . $state . '][group]', |
@@ -366,14 +366,14 @@ discard block |
||
366 | 366 | 'multiple' => false, |
367 | 367 | 'show_option_all' => false, |
368 | 368 | 'show_option_none' => false |
369 | - ) ); |
|
369 | + )); |
|
370 | 370 | ?> |
371 | 371 | </td> |
372 | 372 | </tr> |
373 | 373 | <?php } ?> |
374 | 374 | <tr> |
375 | 375 | <td colspan="6" style="background-color:#fafafa;"> |
376 | - <span><input id="wpi_vat_get_rates_group" type="button" class="button-secondary" value="<?php esc_attr_e( 'Update EU VAT Rates', 'invoicing' ); ?>" /> <i style="display:none" class="fa fa-refresh fa-spin"></i></span><span id="wpinv-rates-error-wrap" class="wpinv_errors" style="display:none;"></span> |
|
376 | + <span><input id="wpi_vat_get_rates_group" type="button" class="button-secondary" value="<?php esc_attr_e('Update EU VAT Rates', 'invoicing'); ?>" /> <i style="display:none" class="fa fa-refresh fa-spin"></i></span><span id="wpinv-rates-error-wrap" class="wpinv_errors" style="display:none;"></span> |
|
377 | 377 | </td> |
378 | 378 | </tr> |
379 | 379 | <?php } ?> |
@@ -385,35 +385,35 @@ discard block |
||
385 | 385 | echo $content; |
386 | 386 | } |
387 | 387 | |
388 | -function wpinv_vat_number_callback( $args ) { |
|
388 | +function wpinv_vat_number_callback($args) { |
|
389 | 389 | global $wpinv_euvat; |
390 | 390 | |
391 | 391 | $vat_number = $wpinv_euvat->get_vat_number(); |
392 | 392 | $vat_valid = $wpinv_euvat->is_vat_validated(); |
393 | 393 | |
394 | - $size = ( isset( $args['size'] ) && !is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
395 | - $validated_text = $vat_valid ? __( 'VAT number validated', 'invoicing' ) : __( 'VAT number not validated', 'invoicing' ); |
|
394 | + $size = (isset($args['size']) && !is_null($args['size'])) ? $args['size'] : 'regular'; |
|
395 | + $validated_text = $vat_valid ? __('VAT number validated', 'invoicing') : __('VAT number not validated', 'invoicing'); |
|
396 | 396 | $disabled = $vat_valid ? 'disabled="disabled"' : " "; |
397 | 397 | |
398 | - $html = '<input type="text" class="' . $size . '-text" id="wpinv_settings[' . $args['id'] . ']" name="wpinv_settings[' . $args['id'] . ']" placeholder="GB123456789" value="' . esc_attr( stripslashes( $vat_number ) ) . '"/>'; |
|
399 | - $html .= '<span> <input type="button" id="wpinv_vat_validate" class="wpinv_validate_vat_button button-secondary" ' . $disabled . ' value="' . esc_attr__( 'Validate VAT Number', 'invoicing' ) . '" /></span>'; |
|
398 | + $html = '<input type="text" class="' . $size . '-text" id="wpinv_settings[' . $args['id'] . ']" name="wpinv_settings[' . $args['id'] . ']" placeholder="GB123456789" value="' . esc_attr(stripslashes($vat_number)) . '"/>'; |
|
399 | + $html .= '<span> <input type="button" id="wpinv_vat_validate" class="wpinv_validate_vat_button button-secondary" ' . $disabled . ' value="' . esc_attr__('Validate VAT Number', 'invoicing') . '" /></span>'; |
|
400 | 400 | $html .= '<span class="wpinv-vat-stat wpinv-vat-stat-' . (int)$vat_valid . '"><i class="fa"></i> <font>' . $validated_text . '</font></span>'; |
401 | - $html .= '<label for="wpinv_settings[' . $args['id'] . ']">' . '<p>' . __( 'Enter your VAT number including country identifier, eg: GB123456789 (Settings must be saved after validation)', 'invoicing' ).'</p>' . '</label>'; |
|
402 | - $html .= '<input type="hidden" name="_wpi_nonce" value="' . wp_create_nonce( 'vat_validation' ) . '">'; |
|
401 | + $html .= '<label for="wpinv_settings[' . $args['id'] . ']">' . '<p>' . __('Enter your VAT number including country identifier, eg: GB123456789 (Settings must be saved after validation)', 'invoicing') . '</p>' . '</label>'; |
|
402 | + $html .= '<input type="hidden" name="_wpi_nonce" value="' . wp_create_nonce('vat_validation') . '">'; |
|
403 | 403 | |
404 | 404 | echo $html; |
405 | 405 | } |
406 | 406 | |
407 | -function wpinv_eu_fallback_rate_callback( $args ) { |
|
407 | +function wpinv_eu_fallback_rate_callback($args) { |
|
408 | 408 | global $wpinv_options; |
409 | 409 | |
410 | - $value = isset( $wpinv_options[$args['id']] ) ? $wpinv_options[ $args['id'] ] : ( isset( $args['std'] ) ? $args['std'] : '' ); |
|
411 | - $size = ( isset( $args['size'] ) && !is_null( $args['size'] ) ) ? $args['size'] : 'small'; |
|
410 | + $value = isset($wpinv_options[$args['id']]) ? $wpinv_options[$args['id']] : (isset($args['std']) ? $args['std'] : ''); |
|
411 | + $size = (isset($args['size']) && !is_null($args['size'])) ? $args['size'] : 'small'; |
|
412 | 412 | |
413 | - $html = '<input type="number" min="0" max="99" step="any" class="' . $size . '-text" id="wpinv_settings_' . $args['section'] . '_' . $args['id'] . '" name="wpinv_settings[' . $args['id'] . ']" value="' . esc_attr( stripslashes( $value ) ) . '" />'; |
|
414 | - $html .= '<span> <input id="wpi_add_eu_states" type="button" class="button-secondary" value="' . esc_attr__( 'Add EU Member States', 'invoicing' ) . '" /></span>'; |
|
415 | - $html .= '<span> <input id="wpi_remove_eu_states" type="button" class="button-secondary" value="' . esc_attr__( 'Remove EU Member States', 'invoicing' ) . '" /></span>'; |
|
416 | - $html .= '<span> <input id="wpi_vat_get_rates" type="button" class="button-secondary" value="' . esc_attr__( 'Update EU VAT Rates', 'invoicing' ) . '" /> <i style="display:none" class="fa fa-refresh fa-spin"></i></span>'; |
|
413 | + $html = '<input type="number" min="0" max="99" step="any" class="' . $size . '-text" id="wpinv_settings_' . $args['section'] . '_' . $args['id'] . '" name="wpinv_settings[' . $args['id'] . ']" value="' . esc_attr(stripslashes($value)) . '" />'; |
|
414 | + $html .= '<span> <input id="wpi_add_eu_states" type="button" class="button-secondary" value="' . esc_attr__('Add EU Member States', 'invoicing') . '" /></span>'; |
|
415 | + $html .= '<span> <input id="wpi_remove_eu_states" type="button" class="button-secondary" value="' . esc_attr__('Remove EU Member States', 'invoicing') . '" /></span>'; |
|
416 | + $html .= '<span> <input id="wpi_vat_get_rates" type="button" class="button-secondary" value="' . esc_attr__('Update EU VAT Rates', 'invoicing') . '" /> <i style="display:none" class="fa fa-refresh fa-spin"></i></span>'; |
|
417 | 417 | $html .= '<p><label for="wpinv_settings_' . $args['section'] . '_' . $args['id'] . '">' . $args['desc'] . '</label></p>'; |
418 | 418 | echo $html; |
419 | 419 | ?> |
@@ -421,36 +421,36 @@ discard block |
||
421 | 421 | <?php |
422 | 422 | } |
423 | 423 | |
424 | -function wpinv_vat_ip_lookup_callback( $args ) { |
|
424 | +function wpinv_vat_ip_lookup_callback($args) { |
|
425 | 425 | global $wpinv_options, $wpinv_euvat; |
426 | 426 | |
427 | - $value = isset( $wpinv_options[ $args['id'] ] ) ? $wpinv_options[ $args['id'] ] : ( isset( $args['std'] ) ? $args['std'] : 'default' ); |
|
427 | + $value = isset($wpinv_options[$args['id']]) ? $wpinv_options[$args['id']] : (isset($args['std']) ? $args['std'] : 'default'); |
|
428 | 428 | |
429 | 429 | $options = array(); |
430 | - if ( function_exists( 'geoip_country_code_by_name' ) ) { |
|
431 | - $options['geoip'] = __( 'PHP GeoIP extension', 'invoicing' ); |
|
430 | + if (function_exists('geoip_country_code_by_name')) { |
|
431 | + $options['geoip'] = __('PHP GeoIP extension', 'invoicing'); |
|
432 | 432 | } |
433 | 433 | |
434 | 434 | $geoip2_database = $wpinv_euvat->geoip2_country_dbfile(); |
435 | 435 | |
436 | - if ( !function_exists( 'bcadd' ) ) { |
|
437 | - $geoip2_message = __( 'GeoIP2 service requires the BC Math PHP extension, it is not loaded in your version of PHP!', 'invoicing' ); |
|
436 | + if (!function_exists('bcadd')) { |
|
437 | + $geoip2_message = __('GeoIP2 service requires the BC Math PHP extension, it is not loaded in your version of PHP!', 'invoicing'); |
|
438 | 438 | } else { |
439 | - $geoip2_message = ini_get('safe_mode') ? __( 'GeoIP2 is not supported with PHP safe mode enabled!', 'invoicing' ) : ''; |
|
439 | + $geoip2_message = ini_get('safe_mode') ? __('GeoIP2 is not supported with PHP safe mode enabled!', 'invoicing') : ''; |
|
440 | 440 | } |
441 | 441 | |
442 | - if ( $geoip2_database !== false && empty( $geoip2_message ) ) { |
|
443 | - $options['geoip2'] = __( 'GeoIP2 Database', 'invoicing' ); |
|
442 | + if ($geoip2_database !== false && empty($geoip2_message)) { |
|
443 | + $options['geoip2'] = __('GeoIP2 Database', 'invoicing'); |
|
444 | 444 | } |
445 | 445 | |
446 | - if ( function_exists( 'simplexml_load_file' ) ) { |
|
447 | - $options['geoplugin'] = __( 'geoPlugin Web Service', 'invoicing' ); |
|
446 | + if (function_exists('simplexml_load_file')) { |
|
447 | + $options['geoplugin'] = __('geoPlugin Web Service', 'invoicing'); |
|
448 | 448 | } |
449 | 449 | |
450 | - $options['site'] = __( 'Use default country', 'invoicing' ); |
|
451 | - $options['default'] = __( 'Auto', 'invoicing' ); |
|
450 | + $options['site'] = __('Use default country', 'invoicing'); |
|
451 | + $options['default'] = __('Auto', 'invoicing'); |
|
452 | 452 | |
453 | - $html = wpinv_html_select( array( |
|
453 | + $html = wpinv_html_select(array( |
|
454 | 454 | 'name' => "wpinv_settings[{$args['id']}]", |
455 | 455 | 'selected' => $value, |
456 | 456 | 'id' => "wpinv_settings[{$args['id']}]", |
@@ -462,23 +462,23 @@ discard block |
||
462 | 462 | )); |
463 | 463 | |
464 | 464 | $desc = '<label for="wpinv_settings[' . $args['id'] . ']">'; |
465 | - $desc .= __( 'Select the option Invoicing should use to determine the country from the IP address of the user.', 'invoicing' ); |
|
465 | + $desc .= __('Select the option Invoicing should use to determine the country from the IP address of the user.', 'invoicing'); |
|
466 | 466 | $desc .= '<p>'; |
467 | - if ( empty( $geoip2_message ) ) { |
|
468 | - if ( $geoip2_database ) { |
|
467 | + if (empty($geoip2_message)) { |
|
468 | + if ($geoip2_database) { |
|
469 | 469 | $last_updated = ''; |
470 | - if ( $time_updated = wpinv_get_option( 'wpinv_geoip2_date_updated' ) ) { |
|
471 | - $date_updated = date_i18n( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), $time_updated ); |
|
472 | - $last_updated = '<br>' . sprintf( __( 'The GeoIP2 database was last updated on: <b>%s</b>', 'invoicing' ), $date_updated ); |
|
470 | + if ($time_updated = wpinv_get_option('wpinv_geoip2_date_updated')) { |
|
471 | + $date_updated = date_i18n(get_option('date_format') . ' ' . get_option('time_format'), $time_updated); |
|
472 | + $last_updated = '<br>' . sprintf(__('The GeoIP2 database was last updated on: <b>%s</b>', 'invoicing'), $date_updated); |
|
473 | 473 | } |
474 | - $desc .= __( 'GeoIP2 database exists:', 'invoicing' ) . $last_updated . ' <input type="button" id="wpi_geoip2" action="update" class="wpinv-refresh-geoip2-btn button-secondary" value="' . __( 'Update GeoIP2 database now (~55MB)', 'invoicing' ) . '"></input>'; |
|
474 | + $desc .= __('GeoIP2 database exists:', 'invoicing') . $last_updated . ' <input type="button" id="wpi_geoip2" action="update" class="wpinv-refresh-geoip2-btn button-secondary" value="' . __('Update GeoIP2 database now (~55MB)', 'invoicing') . '"></input>'; |
|
475 | 475 | } else { |
476 | - $desc .= __( 'GeoIP2 database does not exist:', 'invoicing' ) . ' <input type="button" id="wpi_geoip2" action="download" class="wpinv-download-geoip2-btn button-secondary" value="' . __( 'Download GeoIP2 database now', 'invoicing' ) . ' (~53MB)"></input><br>' . __( 'After downloading the GeoIP2 database the GeoIP2 lookup option will show.', 'invoicing' ); |
|
476 | + $desc .= __('GeoIP2 database does not exist:', 'invoicing') . ' <input type="button" id="wpi_geoip2" action="download" class="wpinv-download-geoip2-btn button-secondary" value="' . __('Download GeoIP2 database now', 'invoicing') . ' (~53MB)"></input><br>' . __('After downloading the GeoIP2 database the GeoIP2 lookup option will show.', 'invoicing'); |
|
477 | 477 | } |
478 | 478 | } else { |
479 | 479 | $desc .= $geoip2_message; |
480 | 480 | } |
481 | - $desc .= '</p><p>'. __( 'geoPlugin is a great free service please consider supporting them: ', 'invoicing' ) . ' <a href="http://www.geoplugin.com/" target="_blank">GeoPlugin.com</a></p>'; |
|
481 | + $desc .= '</p><p>' . __('geoPlugin is a great free service please consider supporting them: ', 'invoicing') . ' <a href="http://www.geoplugin.com/" target="_blank">GeoPlugin.com</a></p>'; |
|
482 | 482 | $desc .= '</label>'; |
483 | 483 | |
484 | 484 | $html .= $desc; |
@@ -103,7 +103,10 @@ discard block |
||
103 | 103 | <?php } ?> |
104 | 104 | |
105 | 105 | <?php if ( $use_taxes && !wpinv_prices_include_tax() ) { ?> |
106 | - <tr class="wpinv_cart_footer_row wpinv_cart_subtotal_row"<?php if ( !wpinv_is_cart_taxed() ) echo ' style="display:none;"'; ?>> |
|
106 | + <tr class="wpinv_cart_footer_row wpinv_cart_subtotal_row"<?php if ( !wpinv_is_cart_taxed() ) { |
|
107 | + echo ' style="display:none;"'; |
|
108 | +} |
|
109 | +?>> |
|
107 | 110 | <?php do_action( 'wpinv_checkout_table_subtotal_first', $cart_items ); ?> |
108 | 111 | <td colspan="<?php echo ( $cart_columns - 1 ); ?>" class="wpinv_cart_subtotal_label text-right"> |
109 | 112 | <strong><?php _e( 'Sub-Total', 'invoicing' ); ?>:</strong> |
@@ -118,7 +121,10 @@ discard block |
||
118 | 121 | <?php $wpi_cart_columns = $cart_columns - 1; wpinv_cart_discounts_html( $cart_items ); ?> |
119 | 122 | |
120 | 123 | <?php if ( $use_taxes ) { ?> |
121 | - <tr class="wpinv_cart_footer_row wpinv_cart_tax_row"<?php if( !wpinv_is_cart_taxed() ) echo ' style="display:none;"'; ?>> |
|
124 | + <tr class="wpinv_cart_footer_row wpinv_cart_tax_row"<?php if( !wpinv_is_cart_taxed() ) { |
|
125 | + echo ' style="display:none;"'; |
|
126 | +} |
|
127 | +?>> |
|
122 | 128 | <?php do_action( 'wpinv_checkout_table_tax_first' ); ?> |
123 | 129 | <td colspan="<?php echo ( $cart_columns - 1 ); ?>" class="wpinv_cart_tax_label text-right"> |
124 | 130 | <strong><?php echo $tax_label; ?>:</strong> |
@@ -5,138 +5,138 @@ |
||
5 | 5 | |
6 | 6 | global $wpinv_euvat, $post, $ajax_cart_details, $wpi_cart_columns, $wpi_session; |
7 | 7 | $invoice = wpinv_get_invoice_cart(); |
8 | -$cart_items = !empty( $ajax_cart_details ) ? $ajax_cart_details : wpinv_get_cart_content_details(); |
|
8 | +$cart_items = !empty($ajax_cart_details) ? $ajax_cart_details : wpinv_get_cart_content_details(); |
|
9 | 9 | $quantities_enabled = wpinv_item_quantities_enabled(); |
10 | 10 | $use_taxes = wpinv_use_taxes(); |
11 | 11 | $tax_label = $wpinv_euvat->tax_label(); |
12 | -$tax_title = $use_taxes ? ( wpinv_prices_include_tax() ? wp_sprintf( __( '(%s Incl.)', 'invoicing' ), $tax_label ) : wp_sprintf( __( '(%s Excl.)', 'invoicing' ), $tax_label ) ) : ''; |
|
12 | +$tax_title = $use_taxes ? (wpinv_prices_include_tax() ? wp_sprintf(__('(%s Incl.)', 'invoicing'), $tax_label) : wp_sprintf(__('(%s Excl.)', 'invoicing'), $tax_label)) : ''; |
|
13 | 13 | ?> |
14 | 14 | <table id="wpinv_checkout_cart" class="table table-bordered table-hover"> |
15 | 15 | <thead> |
16 | 16 | <tr class="wpinv_cart_header_row"> |
17 | - <?php do_action( 'wpinv_checkout_table_header_first' ); ?> |
|
18 | - <th class="wpinv_cart_item_name text-left"><?php _e( 'Item Name', 'invoicing' ); ?></th> |
|
19 | - <th class="wpinv_cart_item_price text-right"><?php _e( 'Item Price', 'invoicing' ); ?></th> |
|
20 | - <?php if ( $quantities_enabled ) { ?> |
|
21 | - <th class="wpinv_cart_item_qty text-right"><?php _e( 'Qty', 'invoicing' ); ?></th> |
|
17 | + <?php do_action('wpinv_checkout_table_header_first'); ?> |
|
18 | + <th class="wpinv_cart_item_name text-left"><?php _e('Item Name', 'invoicing'); ?></th> |
|
19 | + <th class="wpinv_cart_item_price text-right"><?php _e('Item Price', 'invoicing'); ?></th> |
|
20 | + <?php if ($quantities_enabled) { ?> |
|
21 | + <th class="wpinv_cart_item_qty text-right"><?php _e('Qty', 'invoicing'); ?></th> |
|
22 | 22 | <?php } ?> |
23 | - <?php if ( $use_taxes ) { ?> |
|
23 | + <?php if ($use_taxes) { ?> |
|
24 | 24 | <th class="wpinv_cart_item_tax text-right"><?php echo $tax_label . ' <span class="normal small">(%)</span>'; ?></th> |
25 | 25 | <?php } ?> |
26 | - <th class="wpinv_cart_item_subtotal text-right"><?php echo __( 'Item Total', 'invoicing' ) . ' <span class="normal small">' . $tax_title . '<span>'; ?></th> |
|
27 | - <?php do_action( 'wpinv_checkout_table_header_last' ); ?> |
|
26 | + <th class="wpinv_cart_item_subtotal text-right"><?php echo __('Item Total', 'invoicing') . ' <span class="normal small">' . $tax_title . '<span>'; ?></th> |
|
27 | + <?php do_action('wpinv_checkout_table_header_last'); ?> |
|
28 | 28 | </tr> |
29 | 29 | </thead> |
30 | 30 | <tbody> |
31 | 31 | <?php |
32 | - do_action( 'wpinv_cart_items_before' ); |
|
32 | + do_action('wpinv_cart_items_before'); |
|
33 | 33 | |
34 | - if ( $cart_items ) { |
|
35 | - foreach ( $cart_items as $key => $item ) { |
|
36 | - $wpi_item = !empty( $item['id'] ) ? new WPInv_Item( $item['id'] ) : NULL; |
|
34 | + if ($cart_items) { |
|
35 | + foreach ($cart_items as $key => $item) { |
|
36 | + $wpi_item = !empty($item['id']) ? new WPInv_Item($item['id']) : NULL; |
|
37 | 37 | ?> |
38 | - <tr class="wpinv_cart_item" id="wpinv_cart_item_<?php echo esc_attr( $key ) . '_' . esc_attr( $item['id'] ); ?>" data-item-id="<?php echo esc_attr( $item['id'] ); ?>"> |
|
39 | - <?php do_action( 'wpinv_checkout_table_body_first', $item ); ?> |
|
38 | + <tr class="wpinv_cart_item" id="wpinv_cart_item_<?php echo esc_attr($key) . '_' . esc_attr($item['id']); ?>" data-item-id="<?php echo esc_attr($item['id']); ?>"> |
|
39 | + <?php do_action('wpinv_checkout_table_body_first', $item); ?> |
|
40 | 40 | <td class="wpinv_cart_item_name text-left"> |
41 | 41 | <?php |
42 | - if ( current_theme_supports( 'post-thumbnails' ) && has_post_thumbnail( $item['id'] ) ) { |
|
42 | + if (current_theme_supports('post-thumbnails') && has_post_thumbnail($item['id'])) { |
|
43 | 43 | echo '<div class="wpinv_cart_item_image">'; |
44 | - echo get_the_post_thumbnail( $item['id'], apply_filters( 'wpinv_checkout_image_size', array( 25,25 ) ) ); |
|
44 | + echo get_the_post_thumbnail($item['id'], apply_filters('wpinv_checkout_image_size', array(25, 25))); |
|
45 | 45 | echo '</div>'; |
46 | 46 | } |
47 | - $item_title = esc_html( wpinv_get_cart_item_name( $item ) ) . wpinv_get_item_suffix( $wpi_item ); |
|
47 | + $item_title = esc_html(wpinv_get_cart_item_name($item)) . wpinv_get_item_suffix($wpi_item); |
|
48 | 48 | echo '<span class="wpinv_checkout_cart_item_title">' . $item_title . '</span>'; |
49 | - $summary = apply_filters( 'wpinv_checkout_cart_line_item_summary', '', $item, $wpi_item, $invoice ); |
|
50 | - if ( !empty( $summary ) ) { |
|
49 | + $summary = apply_filters('wpinv_checkout_cart_line_item_summary', '', $item, $wpi_item, $invoice); |
|
50 | + if (!empty($summary)) { |
|
51 | 51 | echo $summary; |
52 | 52 | } |
53 | 53 | ?> |
54 | 54 | </td> |
55 | 55 | <td class="wpinv_cart_item_price text-right"> |
56 | 56 | <?php |
57 | - echo wpinv_cart_item_price( $item ); |
|
58 | - do_action( 'wpinv_checkout_cart_item_price_after', $item, $key ); |
|
57 | + echo wpinv_cart_item_price($item); |
|
58 | + do_action('wpinv_checkout_cart_item_price_after', $item, $key); |
|
59 | 59 | ?> |
60 | 60 | </td> |
61 | - <?php if ( $quantities_enabled ) { ?> |
|
61 | + <?php if ($quantities_enabled) { ?> |
|
62 | 62 | <td class="wpinv_cart_item_qty text-right"> |
63 | 63 | <?php |
64 | - echo wpinv_get_cart_item_quantity( $item ); |
|
65 | - do_action( 'wpinv_cart_item_quantitiy', $item, $key ); |
|
64 | + echo wpinv_get_cart_item_quantity($item); |
|
65 | + do_action('wpinv_cart_item_quantitiy', $item, $key); |
|
66 | 66 | ?> |
67 | 67 | </td> |
68 | 68 | <?php } ?> |
69 | - <?php if ( $use_taxes ) { ?> |
|
69 | + <?php if ($use_taxes) { ?> |
|
70 | 70 | <td class="wpinv_cart_item_tax text-right"> |
71 | 71 | <?php |
72 | - echo wpinv_cart_item_tax( $item ); |
|
72 | + echo wpinv_cart_item_tax($item); |
|
73 | 73 | //echo wpinv_get_cart_item_tax( $wpi_item->ID, $subtotal = '', $options = array() ); |
74 | - do_action( 'wpinv_cart_item_tax', $item, $key ); |
|
74 | + do_action('wpinv_cart_item_tax', $item, $key); |
|
75 | 75 | ?> |
76 | 76 | </td> |
77 | 77 | <?php } ?> |
78 | 78 | <td class="wpinv_cart_item_subtotal text-right"> |
79 | 79 | <?php |
80 | - echo wpinv_cart_item_subtotal( $item ); |
|
81 | - do_action( 'wpinv_cart_item_subtotal', $item, $key ); |
|
80 | + echo wpinv_cart_item_subtotal($item); |
|
81 | + do_action('wpinv_cart_item_subtotal', $item, $key); |
|
82 | 82 | ?> |
83 | 83 | </td> |
84 | - <?php do_action( 'wpinv_checkout_table_body_last', $item, $key ); ?> |
|
84 | + <?php do_action('wpinv_checkout_table_body_last', $item, $key); ?> |
|
85 | 85 | </tr> |
86 | 86 | <?php } ?> |
87 | 87 | <?php } ?> |
88 | - <?php do_action( 'wpinv_cart_items_middle' ); ?> |
|
89 | - <?php do_action( 'wpinv_cart_items_after' ); ?> |
|
88 | + <?php do_action('wpinv_cart_items_middle'); ?> |
|
89 | + <?php do_action('wpinv_cart_items_after'); ?> |
|
90 | 90 | </tbody> |
91 | 91 | <tfoot> |
92 | 92 | <?php $cart_columns = wpinv_checkout_cart_columns(); ?> |
93 | - <?php if ( has_action( 'wpinv_cart_footer_buttons' ) ) { ?> |
|
93 | + <?php if (has_action('wpinv_cart_footer_buttons')) { ?> |
|
94 | 94 | <tr class="wpinv_cart_footer_row"> |
95 | - <?php do_action( 'wpinv_checkout_table_buttons_first', $cart_items ); ?> |
|
96 | - <td colspan="<?php echo ( $cart_columns ); ?>"> |
|
97 | - <?php do_action( 'wpinv_cart_footer_buttons' ); ?> |
|
95 | + <?php do_action('wpinv_checkout_table_buttons_first', $cart_items); ?> |
|
96 | + <td colspan="<?php echo ($cart_columns); ?>"> |
|
97 | + <?php do_action('wpinv_cart_footer_buttons'); ?> |
|
98 | 98 | </td> |
99 | - <?php do_action( 'wpinv_checkout_table_buttons_first', $cart_items ); ?> |
|
99 | + <?php do_action('wpinv_checkout_table_buttons_first', $cart_items); ?> |
|
100 | 100 | </tr> |
101 | 101 | <?php } ?> |
102 | 102 | |
103 | - <?php if ( $use_taxes && !wpinv_prices_include_tax() ) { ?> |
|
104 | - <tr class="wpinv_cart_footer_row wpinv_cart_subtotal_row"<?php if ( !wpinv_is_cart_taxed() ) echo ' style="display:none;"'; ?>> |
|
105 | - <?php do_action( 'wpinv_checkout_table_subtotal_first', $cart_items ); ?> |
|
106 | - <td colspan="<?php echo ( $cart_columns - 1 ); ?>" class="wpinv_cart_subtotal_label text-right"> |
|
107 | - <strong><?php _e( 'Sub-Total', 'invoicing' ); ?>:</strong> |
|
103 | + <?php if ($use_taxes && !wpinv_prices_include_tax()) { ?> |
|
104 | + <tr class="wpinv_cart_footer_row wpinv_cart_subtotal_row"<?php if (!wpinv_is_cart_taxed()) echo ' style="display:none;"'; ?>> |
|
105 | + <?php do_action('wpinv_checkout_table_subtotal_first', $cart_items); ?> |
|
106 | + <td colspan="<?php echo ($cart_columns - 1); ?>" class="wpinv_cart_subtotal_label text-right"> |
|
107 | + <strong><?php _e('Sub-Total', 'invoicing'); ?>:</strong> |
|
108 | 108 | </td> |
109 | 109 | <td class="wpinv_cart_subtotal text-right"> |
110 | - <span class="wpinv_cart_subtotal_amount bold"><?php echo wpinv_cart_subtotal( $cart_items ); ?></span> |
|
110 | + <span class="wpinv_cart_subtotal_amount bold"><?php echo wpinv_cart_subtotal($cart_items); ?></span> |
|
111 | 111 | </td> |
112 | - <?php do_action( 'wpinv_checkout_table_subtotal_last', $cart_items ); ?> |
|
112 | + <?php do_action('wpinv_checkout_table_subtotal_last', $cart_items); ?> |
|
113 | 113 | </tr> |
114 | 114 | <?php } ?> |
115 | 115 | |
116 | - <?php $wpi_cart_columns = $cart_columns - 1; wpinv_cart_discounts_html( $cart_items ); ?> |
|
116 | + <?php $wpi_cart_columns = $cart_columns - 1; wpinv_cart_discounts_html($cart_items); ?> |
|
117 | 117 | |
118 | - <?php if ( $use_taxes ) { ?> |
|
119 | - <tr class="wpinv_cart_footer_row wpinv_cart_tax_row"<?php if( !wpinv_is_cart_taxed() ) echo ' style="display:none;"'; ?>> |
|
120 | - <?php do_action( 'wpinv_checkout_table_tax_first' ); ?> |
|
121 | - <td colspan="<?php echo ( $cart_columns - 1 ); ?>" class="wpinv_cart_tax_label text-right"> |
|
118 | + <?php if ($use_taxes) { ?> |
|
119 | + <tr class="wpinv_cart_footer_row wpinv_cart_tax_row"<?php if (!wpinv_is_cart_taxed()) echo ' style="display:none;"'; ?>> |
|
120 | + <?php do_action('wpinv_checkout_table_tax_first'); ?> |
|
121 | + <td colspan="<?php echo ($cart_columns - 1); ?>" class="wpinv_cart_tax_label text-right"> |
|
122 | 122 | <strong><?php echo $tax_label; ?>:</strong> |
123 | 123 | </td> |
124 | 124 | <td class="wpinv_cart_tax text-right"> |
125 | - <span class="wpinv_cart_tax_amount" data-tax="<?php echo wpinv_get_cart_tax( $cart_items ); ?>"><?php echo esc_html( wpinv_cart_tax( $cart_items ) ); ?></span> |
|
125 | + <span class="wpinv_cart_tax_amount" data-tax="<?php echo wpinv_get_cart_tax($cart_items); ?>"><?php echo esc_html(wpinv_cart_tax($cart_items)); ?></span> |
|
126 | 126 | </td> |
127 | - <?php do_action( 'wpinv_checkout_table_tax_last' ); ?> |
|
127 | + <?php do_action('wpinv_checkout_table_tax_last'); ?> |
|
128 | 128 | </tr> |
129 | 129 | <?php } ?> |
130 | 130 | |
131 | 131 | <tr class="wpinv_cart_footer_row wpinv_cart_total_row"> |
132 | - <?php do_action( 'wpinv_checkout_table_footer_first' ); ?> |
|
133 | - <td colspan="<?php echo ( $cart_columns - 1 ); ?>" class="wpinv_cart_total_label text-right"> |
|
134 | - <?php echo apply_filters( 'wpinv_cart_total_label', '<strong>' . __( 'Total', 'invoicing' ) . ':</strong>', $invoice ); ?> |
|
132 | + <?php do_action('wpinv_checkout_table_footer_first'); ?> |
|
133 | + <td colspan="<?php echo ($cart_columns - 1); ?>" class="wpinv_cart_total_label text-right"> |
|
134 | + <?php echo apply_filters('wpinv_cart_total_label', '<strong>' . __('Total', 'invoicing') . ':</strong>', $invoice); ?> |
|
135 | 135 | </td> |
136 | 136 | <td class="wpinv_cart_total text-right"> |
137 | - <span class="wpinv_cart_amount bold" data-subtotal="<?php echo wpinv_get_cart_total( $cart_items ); ?>" data-total="<?php echo wpinv_get_cart_total( NULL, NULL, $invoice ); ?>"><?php wpinv_cart_total( $cart_items, true, $invoice ); ?></span> |
|
137 | + <span class="wpinv_cart_amount bold" data-subtotal="<?php echo wpinv_get_cart_total($cart_items); ?>" data-total="<?php echo wpinv_get_cart_total(NULL, NULL, $invoice); ?>"><?php wpinv_cart_total($cart_items, true, $invoice); ?></span> |
|
138 | 138 | </td> |
139 | - <?php do_action( 'wpinv_checkout_table_footer_last' ); ?> |
|
139 | + <?php do_action('wpinv_checkout_table_footer_last'); ?> |
|
140 | 140 | </tr> |
141 | 141 | </tfoot> |
142 | 142 | </table> |
@@ -1,10 +1,10 @@ |
||
1 | 1 | <?php |
2 | 2 | // don't load directly |
3 | -if ( !defined('ABSPATH') ) |
|
3 | +if (!defined('ABSPATH')) |
|
4 | 4 | die('-1'); |
5 | 5 | |
6 | -$email_footer = apply_filters( 'wpinv_email_footer_text', wpinv_get_option( 'email_footer_text' ) ); |
|
7 | -$email_footer = $email_footer ? wpautop( wp_kses_post( wptexturize( $email_footer ) ) ) : ''; |
|
6 | +$email_footer = apply_filters('wpinv_email_footer_text', wpinv_get_option('email_footer_text')); |
|
7 | +$email_footer = $email_footer ? wpautop(wp_kses_post(wptexturize($email_footer))) : ''; |
|
8 | 8 | ?> |
9 | 9 | </div> |
10 | 10 | </td> |
@@ -1,7 +1,8 @@ |
||
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 | 7 | $email_footer = apply_filters( 'wpinv_email_footer_text', wpinv_get_option( 'email_footer_text' ) ); |
7 | 8 | $email_footer = $email_footer ? wpautop( wp_kses_post( wptexturize( $email_footer ) ) ) : ''; |
@@ -1,16 +1,16 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | // don't load directly |
3 | -if ( !defined('ABSPATH') ) |
|
3 | +if (!defined('ABSPATH')) |
|
4 | 4 | die('-1'); |
5 | 5 | |
6 | -if ( !isset( $email_heading ) ) { |
|
6 | +if (!isset($email_heading)) { |
|
7 | 7 | global $email_heading; |
8 | 8 | } |
9 | 9 | ?> |
10 | 10 | <!DOCTYPE html> |
11 | 11 | <html dir="<?php echo is_rtl() ? 'rtl' : 'ltr'?>"> |
12 | 12 | <head> |
13 | - <meta http-equiv="Content-Type" content="text/html; charset=<?php bloginfo( 'charset' ); ?>" /> |
|
13 | + <meta http-equiv="Content-Type" content="text/html; charset=<?php bloginfo('charset'); ?>" /> |
|
14 | 14 | <meta name="viewport" content="width=device-width, initial-scale=1"> |
15 | 15 | <meta name="robots" content="noindex,nofollow"> |
16 | 16 | <title><?php echo wpinv_get_blogname(); ?></title> |
@@ -22,13 +22,13 @@ discard block |
||
22 | 22 | <td align="center" valign="top"> |
23 | 23 | <div id="template_header_image"> |
24 | 24 | <?php |
25 | - if ( $img = wpinv_get_option( 'email_header_image' ) ) { |
|
26 | - echo '<p style="margin-top:0;"><img style="max-width:100%" src="' . esc_url( $img ) . '" alt="' . esc_attr( wpinv_get_blogname() ) . '" /></p>'; |
|
25 | + if ($img = wpinv_get_option('email_header_image')) { |
|
26 | + echo '<p style="margin-top:0;"><img style="max-width:100%" src="' . esc_url($img) . '" alt="' . esc_attr(wpinv_get_blogname()) . '" /></p>'; |
|
27 | 27 | } |
28 | 28 | ?> |
29 | 29 | </div> |
30 | 30 | <table border="0" cellpadding="0" cellspacing="0" width="100%" id="template_container"> |
31 | - <?php if ( !empty( $email_heading ) ) { ?> |
|
31 | + <?php if (!empty($email_heading)) { ?> |
|
32 | 32 | <tr> |
33 | 33 | <td align="center" valign="top"> |
34 | 34 | <!-- Header --> |
@@ -1,7 +1,8 @@ |
||
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 | 7 | if ( !isset( $email_heading ) ) { |
7 | 8 | global $email_heading; |
@@ -1,7 +1,8 @@ |
||
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 | 7 | do_action( 'wpinv_email_header', $email_heading, $invoice, $email_type, $sent_to_admin ); |
7 | 8 |
@@ -1,18 +1,18 @@ |
||
1 | 1 | <?php |
2 | 2 | // don't load directly |
3 | -if ( !defined('ABSPATH') ) |
|
3 | +if (!defined('ABSPATH')) |
|
4 | 4 | die('-1'); |
5 | 5 | |
6 | -do_action( 'wpinv_email_header', $email_heading, $invoice, $email_type, $sent_to_admin ); |
|
6 | +do_action('wpinv_email_header', $email_heading, $invoice, $email_type, $sent_to_admin); |
|
7 | 7 | |
8 | -if ( ! empty( $message_body ) ) { |
|
9 | - echo wpautop( wptexturize( $message_body ) ); |
|
8 | +if (!empty($message_body)) { |
|
9 | + echo wpautop(wptexturize($message_body)); |
|
10 | 10 | } |
11 | 11 | |
12 | -do_action( 'wpinv_email_invoice_details', $invoice, $email_type, $sent_to_admin ); |
|
12 | +do_action('wpinv_email_invoice_details', $invoice, $email_type, $sent_to_admin); |
|
13 | 13 | |
14 | -do_action( 'wpinv_email_invoice_items', $invoice, $email_type, $sent_to_admin ); |
|
14 | +do_action('wpinv_email_invoice_items', $invoice, $email_type, $sent_to_admin); |
|
15 | 15 | |
16 | -do_action( 'wpinv_email_billing_details', $invoice, $email_type, $sent_to_admin ); |
|
16 | +do_action('wpinv_email_billing_details', $invoice, $email_type, $sent_to_admin); |
|
17 | 17 | |
18 | -do_action( 'wpinv_email_footer', $invoice, $email_type, $sent_to_admin ); |
|
19 | 18 | \ No newline at end of file |
19 | +do_action('wpinv_email_footer', $invoice, $email_type, $sent_to_admin); |
|
20 | 20 | \ No newline at end of file |
@@ -1,7 +1,8 @@ |
||
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 | 7 | // Load colours |
7 | 8 | $bg = wpinv_get_option( 'email_background_color', '#f5f5f5' ); |
@@ -1,25 +1,25 @@ discard block |
||
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 | // Load colours |
7 | -$bg = wpinv_get_option( 'email_background_color', '#f5f5f5' ); |
|
8 | -$body = wpinv_get_option( 'email_body_background_color', '#fdfdfd' ); |
|
9 | -$base = wpinv_get_option( 'email_base_color', '#557da2' ); |
|
10 | -$base_text = wpinv_light_or_dark( $base, '#202020', '#ffffff' ); |
|
11 | -$text = wpinv_get_option( 'email_text_color', '#505050' ); |
|
7 | +$bg = wpinv_get_option('email_background_color', '#f5f5f5'); |
|
8 | +$body = wpinv_get_option('email_body_background_color', '#fdfdfd'); |
|
9 | +$base = wpinv_get_option('email_base_color', '#557da2'); |
|
10 | +$base_text = wpinv_light_or_dark($base, '#202020', '#ffffff'); |
|
11 | +$text = wpinv_get_option('email_text_color', '#505050'); |
|
12 | 12 | |
13 | -$bg_darker_10 = wpinv_hex_darker( $bg, 10 ); |
|
14 | -$body_darker_10 = wpinv_hex_darker( $body, 10 ); |
|
15 | -$base_lighter_20 = wpinv_hex_lighter( $base, 20 ); |
|
16 | -$base_lighter_40 = wpinv_hex_lighter( $base, 40 ); |
|
17 | -$text_lighter_20 = wpinv_hex_lighter( $text, 20 ); |
|
13 | +$bg_darker_10 = wpinv_hex_darker($bg, 10); |
|
14 | +$body_darker_10 = wpinv_hex_darker($body, 10); |
|
15 | +$base_lighter_20 = wpinv_hex_lighter($base, 20); |
|
16 | +$base_lighter_40 = wpinv_hex_lighter($base, 40); |
|
17 | +$text_lighter_20 = wpinv_hex_lighter($text, 20); |
|
18 | 18 | |
19 | 19 | // !important; is a gmail hack to prevent styles being stripped if it doesn't like something. |
20 | 20 | ?> |
21 | 21 | #wrapper { |
22 | - background-color: <?php echo esc_attr( $bg ); ?>; |
|
22 | + background-color: <?php echo esc_attr($bg); ?>; |
|
23 | 23 | margin: 0; |
24 | 24 | -webkit-text-size-adjust: none !important; |
25 | 25 | padding: 3%; |
@@ -40,15 +40,15 @@ discard block |
||
40 | 40 | |
41 | 41 | #template_container { |
42 | 42 | box-shadow: 0 1px 4px rgba(0,0,0,0.1) !important; |
43 | - background-color: <?php echo esc_attr( $body ); ?>; |
|
44 | - border: 1px solid <?php echo esc_attr( $bg_darker_10 ); ?>; |
|
43 | + background-color: <?php echo esc_attr($body); ?>; |
|
44 | + border: 1px solid <?php echo esc_attr($bg_darker_10); ?>; |
|
45 | 45 | border-radius: 3px !important; |
46 | 46 | } |
47 | 47 | |
48 | 48 | #template_header { |
49 | - background-color: <?php echo esc_attr( $base ); ?>; |
|
49 | + background-color: <?php echo esc_attr($base); ?>; |
|
50 | 50 | border-radius: 3px 3px 0 0 !important; |
51 | - color: <?php echo esc_attr( $base_text ); ?>; |
|
51 | + color: <?php echo esc_attr($base_text); ?>; |
|
52 | 52 | border-bottom: 0; |
53 | 53 | font-weight: bold; |
54 | 54 | line-height: 100%; |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | } |
62 | 62 | |
63 | 63 | #template_header h1 { |
64 | - color: <?php echo esc_attr( $base_text ); ?>; |
|
64 | + color: <?php echo esc_attr($base_text); ?>; |
|
65 | 65 | } |
66 | 66 | |
67 | 67 | #template_footer td { |
@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | |
73 | 73 | #template_footer #credit { |
74 | 74 | border:0; |
75 | - color: <?php echo esc_attr( $base_lighter_40 ); ?>; |
|
75 | + color: <?php echo esc_attr($base_lighter_40); ?>; |
|
76 | 76 | font-family: Arial; |
77 | 77 | font-size:12px; |
78 | 78 | line-height:125%; |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | } |
82 | 82 | |
83 | 83 | #body_content { |
84 | - background-color: <?php echo esc_attr( $body ); ?>; |
|
84 | + background-color: <?php echo esc_attr($body); ?>; |
|
85 | 85 | } |
86 | 86 | |
87 | 87 | #body_content table td { |
@@ -101,7 +101,7 @@ discard block |
||
101 | 101 | } |
102 | 102 | |
103 | 103 | #body_content_inner { |
104 | - color: <?php echo esc_attr( $text_lighter_20 ); ?>; |
|
104 | + color: <?php echo esc_attr($text_lighter_20); ?>; |
|
105 | 105 | font-family: Arial,Helvetica,sans-serif; |
106 | 106 | font-size: 14px; |
107 | 107 | line-height: 150%; |
@@ -109,17 +109,17 @@ discard block |
||
109 | 109 | } |
110 | 110 | |
111 | 111 | .td { |
112 | - color: <?php echo esc_attr( $text_lighter_20 ); ?>; |
|
113 | - border: 1px solid <?php echo esc_attr( $body_darker_10 ); ?>; |
|
112 | + color: <?php echo esc_attr($text_lighter_20); ?>; |
|
113 | + border: 1px solid <?php echo esc_attr($body_darker_10); ?>; |
|
114 | 114 | } |
115 | 115 | |
116 | 116 | .text { |
117 | - color: <?php echo esc_attr( $text ); ?>; |
|
117 | + color: <?php echo esc_attr($text); ?>; |
|
118 | 118 | font-family: Arial,Helvetica,sans-serif; |
119 | 119 | } |
120 | 120 | |
121 | 121 | .link { |
122 | - color: <?php echo esc_attr( $base ); ?>; |
|
122 | + color: <?php echo esc_attr($base); ?>; |
|
123 | 123 | } |
124 | 124 | |
125 | 125 | #header_wrapper { |
@@ -128,19 +128,19 @@ discard block |
||
128 | 128 | } |
129 | 129 | |
130 | 130 | h1 { |
131 | - color: <?php echo esc_attr( $base ); ?>; |
|
131 | + color: <?php echo esc_attr($base); ?>; |
|
132 | 132 | font-family: Arial,Helvetica,sans-serif; |
133 | 133 | font-size: 30px; |
134 | 134 | font-weight: 300; |
135 | 135 | line-height: 150%; |
136 | 136 | margin: 0; |
137 | 137 | text-align: <?php echo is_rtl() ? 'right' : 'left'; ?>; |
138 | - text-shadow: 0 1px 0 <?php echo esc_attr( $base_lighter_20 ); ?>; |
|
138 | + text-shadow: 0 1px 0 <?php echo esc_attr($base_lighter_20); ?>; |
|
139 | 139 | -webkit-font-smoothing: antialiased; |
140 | 140 | } |
141 | 141 | |
142 | 142 | h2 { |
143 | - color: <?php echo esc_attr( $base ); ?>; |
|
143 | + color: <?php echo esc_attr($base); ?>; |
|
144 | 144 | display: block; |
145 | 145 | font-family: Arial,Helvetica,sans-serif; |
146 | 146 | font-size: 18px; |
@@ -151,7 +151,7 @@ discard block |
||
151 | 151 | } |
152 | 152 | |
153 | 153 | h3 { |
154 | - color: <?php echo esc_attr( $base ); ?>; |
|
154 | + color: <?php echo esc_attr($base); ?>; |
|
155 | 155 | display: block; |
156 | 156 | font-family: Arial,Helvetica,sans-serif; |
157 | 157 | font-size: 16px; |
@@ -162,7 +162,7 @@ discard block |
||
162 | 162 | } |
163 | 163 | |
164 | 164 | a { |
165 | - color: <?php echo esc_attr( $base ); ?>; |
|
165 | + color: <?php echo esc_attr($base); ?>; |
|
166 | 166 | font-weight: normal; |
167 | 167 | text-decoration: underline; |
168 | 168 | } |
@@ -180,7 +180,7 @@ discard block |
||
180 | 180 | } |
181 | 181 | |
182 | 182 | .table-bordered { |
183 | - border: 1px solid <?php echo esc_attr( $body_darker_10 ); ?>; |
|
183 | + border: 1px solid <?php echo esc_attr($body_darker_10); ?>; |
|
184 | 184 | border-collapse: collapse; |
185 | 185 | border-spacing: 0; |
186 | 186 | width: 100%; |
@@ -188,8 +188,8 @@ discard block |
||
188 | 188 | |
189 | 189 | .table-bordered th, |
190 | 190 | .table-bordered td { |
191 | - border: 1px solid <?php echo esc_attr( $body_darker_10 ); ?>; |
|
192 | - color: <?php echo esc_attr( $text_lighter_20 ); ?>; |
|
191 | + border: 1px solid <?php echo esc_attr($body_darker_10); ?>; |
|
192 | + color: <?php echo esc_attr($text_lighter_20); ?>; |
|
193 | 193 | font-size: 14px; |
194 | 194 | } |
195 | 195 | .small { |
@@ -288,9 +288,9 @@ discard block |
||
288 | 288 | text-decoration: none; |
289 | 289 | } |
290 | 290 | .btn-default { |
291 | - color: <?php echo esc_attr( $base_text ); ?>; |
|
292 | - background-color: <?php echo esc_attr( $base ); ?>; |
|
293 | - border-color: <?php echo esc_attr( $base ); ?>; |
|
291 | + color: <?php echo esc_attr($base_text); ?>; |
|
292 | + background-color: <?php echo esc_attr($base); ?>; |
|
293 | + border-color: <?php echo esc_attr($base); ?>; |
|
294 | 294 | } |
295 | 295 | .btn-primary { |
296 | 296 | color: #fff; |