@@ -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,137 +17,137 @@ 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 | - if( wpinv_use_taxes() && wpinv_get_option( 'apply_vat_rules' ) ) { |
|
90 | + if (wpinv_use_taxes() && wpinv_get_option('apply_vat_rules')) { |
|
91 | 91 | self::load_vat_scripts(); |
92 | 92 | } |
93 | 93 | } |
94 | 94 | |
95 | - public static function load_vat_scripts(){ |
|
96 | - $suffix = '';//defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
95 | + public static function load_vat_scripts() { |
|
96 | + $suffix = ''; //defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
97 | 97 | |
98 | - wp_register_script( 'wpinv-vat-validation-script', WPINV_PLUGIN_URL . 'assets/js/jsvat' . $suffix . '.js', array( 'jquery' ), WPINV_VERSION ); |
|
99 | - wp_register_script( 'wpinv-vat-script', WPINV_PLUGIN_URL . 'assets/js/euvat' . $suffix . '.js', array( 'jquery' ), WPINV_VERSION ); |
|
98 | + wp_register_script('wpinv-vat-validation-script', WPINV_PLUGIN_URL . 'assets/js/jsvat' . $suffix . '.js', array('jquery'), WPINV_VERSION); |
|
99 | + wp_register_script('wpinv-vat-script', WPINV_PLUGIN_URL . 'assets/js/euvat' . $suffix . '.js', array('jquery'), WPINV_VERSION); |
|
100 | 100 | |
101 | - $vat_name = self::get_vat_name(); |
|
101 | + $vat_name = self::get_vat_name(); |
|
102 | 102 | |
103 | 103 | $vars = array(); |
104 | 104 | $vars['UseTaxes'] = wpinv_use_taxes(); |
105 | 105 | $vars['EUStates'] = self::get_eu_states(); |
106 | - $vars['NoRateSet'] = __( 'You have not set a rate. Do you want to continue?', 'invoicing' ); |
|
107 | - $vars['EmptyCompany'] = __( 'Please enter your registered company name!', 'invoicing' ); |
|
108 | - $vars['EmptyVAT'] = wp_sprintf( __( 'Please enter your %s number!', 'invoicing' ), $vat_name ); |
|
109 | - $vars['TotalsRefreshed'] = wp_sprintf( __( 'The invoice totals will be refreshed to update the %s.', 'invoicing' ), $vat_name ); |
|
110 | - $vars['ErrValidateVAT'] = wp_sprintf( __( 'Fail to validate the %s number!', 'invoicing' ), $vat_name ); |
|
111 | - $vars['ErrResetVAT'] = wp_sprintf( __( 'Fail to reset the %s number!', 'invoicing' ), $vat_name ); |
|
112 | - $vars['ErrInvalidVat'] = wp_sprintf( __( 'The %s number supplied does not have a valid format!', 'invoicing' ), $vat_name ); |
|
113 | - $vars['ErrInvalidResponse'] = __( 'An invalid response has been received from the server!', 'invoicing' ); |
|
106 | + $vars['NoRateSet'] = __('You have not set a rate. Do you want to continue?', 'invoicing'); |
|
107 | + $vars['EmptyCompany'] = __('Please enter your registered company name!', 'invoicing'); |
|
108 | + $vars['EmptyVAT'] = wp_sprintf(__('Please enter your %s number!', 'invoicing'), $vat_name); |
|
109 | + $vars['TotalsRefreshed'] = wp_sprintf(__('The invoice totals will be refreshed to update the %s.', 'invoicing'), $vat_name); |
|
110 | + $vars['ErrValidateVAT'] = wp_sprintf(__('Fail to validate the %s number!', 'invoicing'), $vat_name); |
|
111 | + $vars['ErrResetVAT'] = wp_sprintf(__('Fail to reset the %s number!', 'invoicing'), $vat_name); |
|
112 | + $vars['ErrInvalidVat'] = wp_sprintf(__('The %s number supplied does not have a valid format!', 'invoicing'), $vat_name); |
|
113 | + $vars['ErrInvalidResponse'] = __('An invalid response has been received from the server!', 'invoicing'); |
|
114 | 114 | $vars['ApplyVATRules'] = $vars['UseTaxes'] ? self::allow_vat_rules() : false; |
115 | 115 | $vars['HideVatFields'] = $vars['ApplyVATRules'] ? self::hide_vat_fields() : true; |
116 | - $vars['ErrResponse'] = __( 'The request response is invalid!', 'invoicing' ); |
|
117 | - $vars['ErrRateResponse'] = __( 'The get rate request response is invalid', 'invoicing' ); |
|
118 | - $vars['PageRefresh'] = __( 'The page will be refreshed in 10 seconds to show the new options.', 'invoicing' ); |
|
119 | - $vars['RequestResponseNotValidJSON'] = __( 'The get rate request response is not valid JSON', 'invoicing' ); |
|
120 | - $vars['GetRateRequestFailed'] = __( 'The get rate request failed: ', 'invoicing' ); |
|
121 | - $vars['NoRateInformationInResponse'] = __( 'The get rate request response does not contain any rate information', 'invoicing' ); |
|
122 | - $vars['RatesUpdated'] = __( 'The rates have been updated. Press the save button to record these new rates.', 'invoicing' ); |
|
123 | - $vars['IPAddressInformation'] = __( 'IP Address Information', 'invoicing' ); |
|
124 | - $vars['VatValidating'] = wp_sprintf( __( 'Validating %s number...', 'invoicing' ), $vat_name ); |
|
125 | - $vars['VatReseting'] = __( 'Reseting...', 'invoicing' ); |
|
126 | - $vars['VatValidated'] = wp_sprintf( __( '%s number validated', 'invoicing' ), $vat_name ); |
|
127 | - $vars['VatNotValidated'] = wp_sprintf( __( '%s number not validated', 'invoicing' ), $vat_name ); |
|
128 | - $vars['ConfirmDeleteClass'] = __( 'Are you sure you wish to delete this rates class?', 'invoicing' ); |
|
116 | + $vars['ErrResponse'] = __('The request response is invalid!', 'invoicing'); |
|
117 | + $vars['ErrRateResponse'] = __('The get rate request response is invalid', 'invoicing'); |
|
118 | + $vars['PageRefresh'] = __('The page will be refreshed in 10 seconds to show the new options.', 'invoicing'); |
|
119 | + $vars['RequestResponseNotValidJSON'] = __('The get rate request response is not valid JSON', 'invoicing'); |
|
120 | + $vars['GetRateRequestFailed'] = __('The get rate request failed: ', 'invoicing'); |
|
121 | + $vars['NoRateInformationInResponse'] = __('The get rate request response does not contain any rate information', 'invoicing'); |
|
122 | + $vars['RatesUpdated'] = __('The rates have been updated. Press the save button to record these new rates.', 'invoicing'); |
|
123 | + $vars['IPAddressInformation'] = __('IP Address Information', 'invoicing'); |
|
124 | + $vars['VatValidating'] = wp_sprintf(__('Validating %s number...', 'invoicing'), $vat_name); |
|
125 | + $vars['VatReseting'] = __('Reseting...', 'invoicing'); |
|
126 | + $vars['VatValidated'] = wp_sprintf(__('%s number validated', 'invoicing'), $vat_name); |
|
127 | + $vars['VatNotValidated'] = wp_sprintf(__('%s number not validated', 'invoicing'), $vat_name); |
|
128 | + $vars['ConfirmDeleteClass'] = __('Are you sure you wish to delete this rates class?', 'invoicing'); |
|
129 | 129 | $vars['isFront'] = is_admin() ? false : true; |
130 | 130 | $vars['baseCountry'] = wpinv_get_default_country(); |
131 | - $vars['disableVATSameCountry'] = ( self::same_country_rule() == 'no' ? true : false ); |
|
132 | - $vars['disableVATSimpleCheck'] = wpinv_get_option( 'vat_offline_check' ) ? true : false; |
|
131 | + $vars['disableVATSameCountry'] = (self::same_country_rule() == 'no' ? true : false); |
|
132 | + $vars['disableVATSimpleCheck'] = wpinv_get_option('vat_offline_check') ? true : false; |
|
133 | 133 | |
134 | - wp_enqueue_script( 'wpinv-vat-validation-script' ); |
|
135 | - wp_enqueue_script( 'wpinv-vat-script' ); |
|
136 | - wp_localize_script( 'wpinv-vat-script', 'WPInv_VAT_Vars', $vars ); |
|
134 | + wp_enqueue_script('wpinv-vat-validation-script'); |
|
135 | + wp_enqueue_script('wpinv-vat-script'); |
|
136 | + wp_localize_script('wpinv-vat-script', 'WPInv_VAT_Vars', $vars); |
|
137 | 137 | } |
138 | 138 | |
139 | 139 | public static function enqueue_admin_scripts() { |
140 | - if( isset( $_GET['page'] ) && 'wpinv-settings' == $_GET['page'] ) { |
|
140 | + if (isset($_GET['page']) && 'wpinv-settings' == $_GET['page']) { |
|
141 | 141 | self::load_vat_scripts(); |
142 | 142 | } |
143 | 143 | } |
144 | 144 | |
145 | - public static function section_vat_settings( $sections ) { |
|
146 | - if ( !empty( $sections ) ) { |
|
147 | - $sections['vat'] = __( 'EU VAT Settings', 'invoicing' ); |
|
145 | + public static function section_vat_settings($sections) { |
|
146 | + if (!empty($sections)) { |
|
147 | + $sections['vat'] = __('EU VAT Settings', 'invoicing'); |
|
148 | 148 | |
149 | - if ( self::allow_vat_classes() ) { |
|
150 | - $sections['vat_rates'] = __( 'EU VAT Rates', 'invoicing' ); |
|
149 | + if (self::allow_vat_classes()) { |
|
150 | + $sections['vat_rates'] = __('EU VAT Rates', 'invoicing'); |
|
151 | 151 | } |
152 | 152 | } |
153 | 153 | return $sections; |
@@ -156,52 +156,52 @@ discard block |
||
156 | 156 | public static function vat_rates_settings() { |
157 | 157 | $vat_classes = self::get_rate_classes(); |
158 | 158 | $vat_rates = array(); |
159 | - $vat_class = isset( $_REQUEST['wpi_sub'] ) && $_REQUEST['wpi_sub'] !== '' && isset( $vat_classes[$_REQUEST['wpi_sub']] )? sanitize_text_field( $_REQUEST['wpi_sub'] ) : '_new'; |
|
160 | - $current_url = remove_query_arg( 'wpi_sub' ); |
|
159 | + $vat_class = isset($_REQUEST['wpi_sub']) && $_REQUEST['wpi_sub'] !== '' && isset($vat_classes[$_REQUEST['wpi_sub']]) ? sanitize_text_field($_REQUEST['wpi_sub']) : '_new'; |
|
160 | + $current_url = remove_query_arg('wpi_sub'); |
|
161 | 161 | |
162 | 162 | $vat_rates['vat_rates_header'] = array( |
163 | 163 | 'id' => 'vat_rates_header', |
164 | - 'name' => '<h3>' . __( 'Manage VAT Rates', 'invoicing' ) . '</h3>', |
|
164 | + 'name' => '<h3>' . __('Manage VAT Rates', 'invoicing') . '</h3>', |
|
165 | 165 | 'desc' => '', |
166 | 166 | 'type' => 'header', |
167 | 167 | 'size' => 'regular' |
168 | 168 | ); |
169 | 169 | $vat_rates['vat_rates_class'] = array( |
170 | 170 | 'id' => 'vat_rates_class', |
171 | - 'name' => __( 'Edit VAT Rates', 'invoicing' ), |
|
172 | - 'desc' => __( 'The standard rate will apply where no explicit rate is provided.', 'invoicing' ), |
|
171 | + 'name' => __('Edit VAT Rates', 'invoicing'), |
|
172 | + 'desc' => __('The standard rate will apply where no explicit rate is provided.', 'invoicing'), |
|
173 | 173 | 'type' => 'select', |
174 | - 'options' => array_merge( $vat_classes, array( '_new' => __( 'Add New Rate Class', 'invoicing' ) ) ), |
|
175 | - 'placeholder' => __( 'Select a VAT Rate', 'invoicing' ), |
|
174 | + 'options' => array_merge($vat_classes, array('_new' => __('Add New Rate Class', 'invoicing'))), |
|
175 | + 'placeholder' => __('Select a VAT Rate', 'invoicing'), |
|
176 | 176 | 'selected' => $vat_class, |
177 | 177 | 'class' => 'wpi_select2', |
178 | 178 | 'onchange' => 'document.location.href="' . $current_url . '&wpi_sub=" + this.value;', |
179 | 179 | ); |
180 | 180 | |
181 | - if ( $vat_class != '_standard' && $vat_class != '_new' ) { |
|
181 | + if ($vat_class != '_standard' && $vat_class != '_new') { |
|
182 | 182 | $vat_rates['vat_rate_delete'] = array( |
183 | 183 | 'id' => 'vat_rate_delete', |
184 | 184 | 'type' => 'vat_rate_delete', |
185 | 185 | ); |
186 | 186 | } |
187 | 187 | |
188 | - if ( $vat_class == '_new' ) { |
|
188 | + if ($vat_class == '_new') { |
|
189 | 189 | $vat_rates['vat_rates_settings'] = array( |
190 | 190 | 'id' => 'vat_rates_settings', |
191 | - 'name' => '<h3>' . __( 'Add New Rate Class', 'invoicing' ) . '</h3>', |
|
191 | + 'name' => '<h3>' . __('Add New Rate Class', 'invoicing') . '</h3>', |
|
192 | 192 | 'type' => 'header', |
193 | 193 | ); |
194 | 194 | $vat_rates['vat_rate_name'] = array( |
195 | 195 | 'id' => 'vat_rate_name', |
196 | - 'name' => __( 'Name', 'invoicing' ), |
|
197 | - 'desc' => __( 'A short name for the new VAT Rate class', 'invoicing' ), |
|
196 | + 'name' => __('Name', 'invoicing'), |
|
197 | + 'desc' => __('A short name for the new VAT Rate class', 'invoicing'), |
|
198 | 198 | 'type' => 'text', |
199 | 199 | 'size' => 'regular', |
200 | 200 | ); |
201 | 201 | $vat_rates['vat_rate_desc'] = array( |
202 | 202 | 'id' => 'vat_rate_desc', |
203 | - 'name' => __( 'Description', 'invoicing' ), |
|
204 | - 'desc' => __( 'Manage VAT Rate class', 'invoicing' ), |
|
203 | + 'name' => __('Description', 'invoicing'), |
|
204 | + 'desc' => __('Manage VAT Rate class', 'invoicing'), |
|
205 | 205 | 'type' => 'text', |
206 | 206 | 'size' => 'regular', |
207 | 207 | ); |
@@ -213,7 +213,7 @@ discard block |
||
213 | 213 | $vat_rates['vat_rates'] = array( |
214 | 214 | 'id' => 'vat_rates', |
215 | 215 | 'name' => '<h3>' . $vat_classes[$vat_class] . '</h3>', |
216 | - 'desc' => self::get_class_desc( $vat_class ), |
|
216 | + 'desc' => self::get_class_desc($vat_class), |
|
217 | 217 | 'type' => 'vat_rates', |
218 | 218 | ); |
219 | 219 | } |
@@ -221,12 +221,12 @@ discard block |
||
221 | 221 | return $vat_rates; |
222 | 222 | } |
223 | 223 | |
224 | - public static function vat_settings( $settings ) { |
|
225 | - if ( !empty( $settings ) ) { |
|
224 | + public static function vat_settings($settings) { |
|
225 | + if (!empty($settings)) { |
|
226 | 226 | $vat_settings = array(); |
227 | 227 | $vat_settings['vat_company_title'] = array( |
228 | 228 | 'id' => 'vat_company_title', |
229 | - 'name' => '<h3>' . __( 'Your Company Details', 'invoicing' ) . '</h3>', |
|
229 | + 'name' => '<h3>' . __('Your Company Details', 'invoicing') . '</h3>', |
|
230 | 230 | 'desc' => '', |
231 | 231 | 'type' => 'header', |
232 | 232 | 'size' => 'regular' |
@@ -234,22 +234,22 @@ discard block |
||
234 | 234 | |
235 | 235 | $vat_settings['vat_company_name'] = array( |
236 | 236 | 'id' => 'vat_company_name', |
237 | - 'name' => __( 'Your Company Name', 'invoicing' ), |
|
238 | - '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>' ), |
|
237 | + 'name' => __('Your Company Name', 'invoicing'), |
|
238 | + '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>'), |
|
239 | 239 | 'type' => 'text', |
240 | 240 | 'size' => 'regular', |
241 | 241 | ); |
242 | 242 | |
243 | 243 | $vat_settings['vat_number'] = array( |
244 | 244 | 'id' => 'vat_number', |
245 | - 'name' => __( 'Your VAT Number', 'invoicing' ), |
|
245 | + 'name' => __('Your VAT Number', 'invoicing'), |
|
246 | 246 | 'type' => 'vat_number', |
247 | 247 | 'size' => 'regular', |
248 | 248 | ); |
249 | 249 | |
250 | 250 | $vat_settings['vat_settings_title'] = array( |
251 | 251 | 'id' => 'vat_settings_title', |
252 | - 'name' => '<h3>' . __( 'Apply VAT Settings', 'invoicing' ) . '</h3>', |
|
252 | + 'name' => '<h3>' . __('Apply VAT Settings', 'invoicing') . '</h3>', |
|
253 | 253 | 'desc' => '', |
254 | 254 | 'type' => 'header', |
255 | 255 | 'size' => 'regular' |
@@ -257,8 +257,8 @@ discard block |
||
257 | 257 | |
258 | 258 | $vat_settings['apply_vat_rules'] = array( |
259 | 259 | 'id' => 'apply_vat_rules', |
260 | - 'name' => __( 'Enable VAT Rules', 'invoicing' ), |
|
261 | - '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>', |
|
260 | + 'name' => __('Enable VAT Rules', 'invoicing'), |
|
261 | + '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>', |
|
262 | 262 | 'type' => 'checkbox', |
263 | 263 | 'std' => '1' |
264 | 264 | ); |
@@ -274,8 +274,8 @@ discard block |
||
274 | 274 | |
275 | 275 | $vat_settings['vat_prevent_b2c_purchase'] = array( |
276 | 276 | 'id' => 'vat_prevent_b2c_purchase', |
277 | - 'name' => __( 'Prevent EU B2C Sales', 'invoicing' ), |
|
278 | - 'desc' => __( 'Enable this option if you are not registered for VAT in the EU.', 'invoicing' ), |
|
277 | + 'name' => __('Prevent EU B2C Sales', 'invoicing'), |
|
278 | + 'desc' => __('Enable this option if you are not registered for VAT in the EU.', 'invoicing'), |
|
279 | 279 | 'type' => 'checkbox' |
280 | 280 | ); |
281 | 281 | |
@@ -283,22 +283,22 @@ discard block |
||
283 | 283 | |
284 | 284 | $vat_settings['vat_same_country_rule'] = array( |
285 | 285 | 'id' => 'vat_same_country_rule', |
286 | - 'name' => __( 'Same Country Rule', 'invoicing' ), |
|
287 | - 'desc' => __( 'Select how you want to handle VAT charge if sales are in the same country as the base country.', 'invoicing' ), |
|
286 | + 'name' => __('Same Country Rule', 'invoicing'), |
|
287 | + 'desc' => __('Select how you want to handle VAT charge if sales are in the same country as the base country.', 'invoicing'), |
|
288 | 288 | 'type' => 'select', |
289 | 289 | 'options' => array( |
290 | - '' => __( 'Normal', 'invoicing' ), |
|
291 | - 'no' => __( 'No VAT', 'invoicing' ), |
|
292 | - 'always' => __( 'Always apply VAT', 'invoicing' ), |
|
290 | + '' => __('Normal', 'invoicing'), |
|
291 | + 'no' => __('No VAT', 'invoicing'), |
|
292 | + 'always' => __('Always apply VAT', 'invoicing'), |
|
293 | 293 | ), |
294 | - 'placeholder' => __( 'Select an option', 'invoicing' ), |
|
294 | + 'placeholder' => __('Select an option', 'invoicing'), |
|
295 | 295 | 'std' => '', |
296 | 296 | 'class' => 'wpi_select2', |
297 | 297 | ); |
298 | 298 | |
299 | 299 | $vat_settings['vat_checkout_title'] = array( |
300 | 300 | 'id' => 'vat_checkout_title', |
301 | - 'name' => '<h3>' . __( 'Checkout Fields', 'invoicing' ) . '</h3>', |
|
301 | + 'name' => '<h3>' . __('Checkout Fields', 'invoicing') . '</h3>', |
|
302 | 302 | 'desc' => '', |
303 | 303 | 'type' => 'header', |
304 | 304 | 'size' => 'regular' |
@@ -306,14 +306,14 @@ discard block |
||
306 | 306 | |
307 | 307 | $vat_settings['vat_disable_fields'] = array( |
308 | 308 | 'id' => 'vat_disable_fields', |
309 | - 'name' => __( 'Disable VAT Fields', 'invoicing' ), |
|
310 | - '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>', |
|
309 | + 'name' => __('Disable VAT Fields', 'invoicing'), |
|
310 | + '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>', |
|
311 | 311 | 'type' => 'checkbox' |
312 | 312 | ); |
313 | 313 | |
314 | 314 | $vat_settings['vat_ip_lookup'] = array( |
315 | 315 | 'id' => 'vat_ip_lookup', |
316 | - 'name' => __( 'IP Country Look-up', 'invoicing' ), |
|
316 | + 'name' => __('IP Country Look-up', 'invoicing'), |
|
317 | 317 | 'type' => 'vat_ip_lookup', |
318 | 318 | 'size' => 'regular', |
319 | 319 | 'std' => 'default', |
@@ -322,21 +322,21 @@ discard block |
||
322 | 322 | |
323 | 323 | $vat_settings['hide_ip_address'] = array( |
324 | 324 | 'id' => 'hide_ip_address', |
325 | - 'name' => __( 'Hide IP Info at Checkout', 'invoicing' ), |
|
326 | - 'desc' => __( 'Hide the user IP info at checkout.', 'invoicing' ), |
|
325 | + 'name' => __('Hide IP Info at Checkout', 'invoicing'), |
|
326 | + 'desc' => __('Hide the user IP info at checkout.', 'invoicing'), |
|
327 | 327 | 'type' => 'checkbox' |
328 | 328 | ); |
329 | 329 | |
330 | 330 | $vat_settings['vat_ip_country_default'] = array( |
331 | 331 | 'id' => 'vat_ip_country_default', |
332 | - 'name' => __( 'Enable IP Country as Default', 'invoicing' ), |
|
333 | - 'desc' => __( 'Show the country of the users IP as the default country, otherwise the site default country will be used.', 'invoicing' ), |
|
332 | + 'name' => __('Enable IP Country as Default', 'invoicing'), |
|
333 | + 'desc' => __('Show the country of the users IP as the default country, otherwise the site default country will be used.', 'invoicing'), |
|
334 | 334 | 'type' => 'checkbox' |
335 | 335 | ); |
336 | 336 | |
337 | 337 | $vat_settings['vies_validation_title'] = array( |
338 | 338 | 'id' => 'vies_validation_title', |
339 | - 'name' => '<h3>' . __( 'VIES Validation', 'invoicing' ) . '</h3>', |
|
339 | + 'name' => '<h3>' . __('VIES Validation', 'invoicing') . '</h3>', |
|
340 | 340 | 'desc' => '', |
341 | 341 | 'type' => 'header', |
342 | 342 | 'size' => 'regular' |
@@ -344,37 +344,37 @@ discard block |
||
344 | 344 | |
345 | 345 | $vat_settings['vat_vies_check'] = array( |
346 | 346 | 'id' => 'vat_vies_check', |
347 | - 'name' => __( 'Disable VIES VAT ID Check', 'invoicing' ), |
|
348 | - '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>' ), |
|
347 | + 'name' => __('Disable VIES VAT ID Check', 'invoicing'), |
|
348 | + '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>'), |
|
349 | 349 | 'type' => 'checkbox' |
350 | 350 | ); |
351 | 351 | |
352 | 352 | $vat_settings['vat_disable_company_name_check'] = array( |
353 | 353 | 'id' => 'vat_disable_company_name_check', |
354 | - 'name' => __( 'Disable VIES Name Check', 'invoicing' ), |
|
355 | - '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>' ), |
|
354 | + 'name' => __('Disable VIES Name Check', 'invoicing'), |
|
355 | + '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>'), |
|
356 | 356 | 'type' => 'checkbox' |
357 | 357 | ); |
358 | 358 | |
359 | 359 | $vat_settings['vat_offline_check'] = array( |
360 | 360 | 'id' => 'vat_offline_check', |
361 | - 'name' => __( 'Disable Basic Checks', 'invoicing' ), |
|
362 | - 'desc' => __( 'Disable basic JS checks for correct format of VAT number. (Not Recommended)', 'invoicing' ), |
|
361 | + 'name' => __('Disable Basic Checks', 'invoicing'), |
|
362 | + 'desc' => __('Disable basic JS checks for correct format of VAT number. (Not Recommended)', 'invoicing'), |
|
363 | 363 | 'type' => 'checkbox' |
364 | 364 | ); |
365 | 365 | |
366 | 366 | |
367 | 367 | $settings['vat'] = $vat_settings; |
368 | 368 | |
369 | - if ( self::allow_vat_classes() ) { |
|
369 | + if (self::allow_vat_classes()) { |
|
370 | 370 | $settings['vat_rates'] = self::vat_rates_settings(); |
371 | 371 | } |
372 | 372 | |
373 | 373 | $eu_fallback_rate = array( |
374 | 374 | 'id' => 'eu_fallback_rate', |
375 | - 'name' => '<h3>' . __( 'VAT rate for EU member states', 'invoicing' ) . '</h3>', |
|
375 | + 'name' => '<h3>' . __('VAT rate for EU member states', 'invoicing') . '</h3>', |
|
376 | 376 | 'type' => 'eu_fallback_rate', |
377 | - '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' ), |
|
377 | + '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'), |
|
378 | 378 | 'std' => '20', |
379 | 379 | 'size' => 'small' |
380 | 380 | ); |
@@ -390,11 +390,11 @@ discard block |
||
390 | 390 | $database_url = 'http' . (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] === 'on' ? 's' : '') . '://geolite.maxmind.com/download/geoip/database/'; |
391 | 391 | $destination_dir = $upload_dir['basedir'] . '/invoicing'; |
392 | 392 | |
393 | - if ( !is_dir( $destination_dir ) ) { |
|
394 | - mkdir( $destination_dir ); |
|
393 | + if (!is_dir($destination_dir)) { |
|
394 | + mkdir($destination_dir); |
|
395 | 395 | } |
396 | 396 | |
397 | - $database_files = array( |
|
397 | + $database_files = array( |
|
398 | 398 | 'country' => array( |
399 | 399 | 'source' => $database_url . 'GeoLite2-Country.mmdb.gz', |
400 | 400 | 'destination' => $destination_dir . '/GeoLite2-Country.mmdb', |
@@ -405,57 +405,57 @@ discard block |
||
405 | 405 | ) |
406 | 406 | ); |
407 | 407 | |
408 | - foreach( $database_files as $database => $files ) { |
|
409 | - $result = self::geoip2_download_file( $files['source'], $files['destination'] ); |
|
408 | + foreach ($database_files as $database => $files) { |
|
409 | + $result = self::geoip2_download_file($files['source'], $files['destination']); |
|
410 | 410 | |
411 | - if ( empty( $result['success'] ) ) { |
|
411 | + if (empty($result['success'])) { |
|
412 | 412 | echo $result['message']; |
413 | 413 | exit; |
414 | 414 | } |
415 | 415 | |
416 | - wpinv_update_option( 'wpinv_geoip2_date_updated', current_time( 'timestamp' ) ); |
|
417 | - echo sprintf(__( 'GeoIP2 %s database updated successfully.', 'invoicing' ), $database ) . ' '; |
|
416 | + wpinv_update_option('wpinv_geoip2_date_updated', current_time('timestamp')); |
|
417 | + echo sprintf(__('GeoIP2 %s database updated successfully.', 'invoicing'), $database) . ' '; |
|
418 | 418 | } |
419 | 419 | |
420 | 420 | exit; |
421 | 421 | } |
422 | 422 | |
423 | - public static function geoip2_download_file( $source_url, $destination_file ) { |
|
423 | + public static function geoip2_download_file($source_url, $destination_file) { |
|
424 | 424 | $success = false; |
425 | 425 | $message = ''; |
426 | 426 | |
427 | - if ( !function_exists( 'download_url' ) ) { |
|
428 | - require_once( ABSPATH . 'wp-admin/includes/file.php' ); |
|
427 | + if (!function_exists('download_url')) { |
|
428 | + require_once(ABSPATH . 'wp-admin/includes/file.php'); |
|
429 | 429 | } |
430 | 430 | |
431 | - $temp_file = download_url( $source_url ); |
|
431 | + $temp_file = download_url($source_url); |
|
432 | 432 | |
433 | - if ( is_wp_error( $temp_file ) ) { |
|
434 | - $message = sprintf( __( 'Error while downloading GeoIp2 database( %s ): %s', 'invoicing' ), $source_url, $temp_file->get_error_message() ); |
|
433 | + if (is_wp_error($temp_file)) { |
|
434 | + $message = sprintf(__('Error while downloading GeoIp2 database( %s ): %s', 'invoicing'), $source_url, $temp_file->get_error_message()); |
|
435 | 435 | } else { |
436 | - $handle = gzopen( $temp_file, 'rb' ); |
|
436 | + $handle = gzopen($temp_file, 'rb'); |
|
437 | 437 | |
438 | - if ( $handle ) { |
|
439 | - $fopen = fopen( $destination_file, 'wb' ); |
|
440 | - if ( $fopen ) { |
|
441 | - while ( ( $data = gzread( $handle, 4096 ) ) != false ) { |
|
442 | - fwrite( $fopen, $data ); |
|
438 | + if ($handle) { |
|
439 | + $fopen = fopen($destination_file, 'wb'); |
|
440 | + if ($fopen) { |
|
441 | + while (($data = gzread($handle, 4096)) != false) { |
|
442 | + fwrite($fopen, $data); |
|
443 | 443 | } |
444 | 444 | |
445 | - gzclose( $handle ); |
|
446 | - fclose( $fopen ); |
|
445 | + gzclose($handle); |
|
446 | + fclose($fopen); |
|
447 | 447 | |
448 | 448 | $success = true; |
449 | 449 | } else { |
450 | - gzclose( $handle ); |
|
451 | - $message = sprintf( __( 'Error could not open destination GeoIp2 database file for writing: %s', 'invoicing' ), $destination_file ); |
|
450 | + gzclose($handle); |
|
451 | + $message = sprintf(__('Error could not open destination GeoIp2 database file for writing: %s', 'invoicing'), $destination_file); |
|
452 | 452 | } |
453 | 453 | } else { |
454 | - $message = sprintf( __( 'Error could not open GeoIp2 database file for reading: %s', 'invoicing' ), $temp_file ); |
|
454 | + $message = sprintf(__('Error could not open GeoIp2 database file for reading: %s', 'invoicing'), $temp_file); |
|
455 | 455 | } |
456 | 456 | |
457 | - if ( file_exists( $temp_file ) ) { |
|
458 | - unlink( $temp_file ); |
|
457 | + if (file_exists($temp_file)) { |
|
458 | + unlink($temp_file); |
|
459 | 459 | } |
460 | 460 | } |
461 | 461 | |
@@ -467,11 +467,11 @@ discard block |
||
467 | 467 | } |
468 | 468 | |
469 | 469 | public static function load_geoip2() { |
470 | - if ( defined( 'WPINV_GEOIP2_LODDED' ) ) { |
|
470 | + if (defined('WPINV_GEOIP2_LODDED')) { |
|
471 | 471 | return; |
472 | 472 | } |
473 | 473 | |
474 | - if ( !class_exists( '\MaxMind\Db\Reader' ) ) { |
|
474 | + if (!class_exists('\MaxMind\Db\Reader')) { |
|
475 | 475 | $maxmind_db_files = array( |
476 | 476 | 'Reader/Decoder.php', |
477 | 477 | 'Reader/InvalidDatabaseException.php', |
@@ -480,12 +480,12 @@ discard block |
||
480 | 480 | 'Reader.php', |
481 | 481 | ); |
482 | 482 | |
483 | - foreach ( $maxmind_db_files as $key => $file ) { |
|
484 | - require_once( WPINV_PLUGIN_DIR . 'includes/libraries/MaxMind/Db/' . $file ); |
|
483 | + foreach ($maxmind_db_files as $key => $file) { |
|
484 | + require_once(WPINV_PLUGIN_DIR . 'includes/libraries/MaxMind/Db/' . $file); |
|
485 | 485 | } |
486 | 486 | } |
487 | 487 | |
488 | - if ( !class_exists( '\GeoIp2\Database\Reader' ) ) { |
|
488 | + if (!class_exists('\GeoIp2\Database\Reader')) { |
|
489 | 489 | $geoip2_files = array( |
490 | 490 | 'ProviderInterface.php', |
491 | 491 | 'Compat/JsonSerializable.php', |
@@ -519,23 +519,23 @@ discard block |
||
519 | 519 | 'WebService/Client.php', |
520 | 520 | ); |
521 | 521 | |
522 | - foreach ( $geoip2_files as $key => $file ) { |
|
523 | - require_once( WPINV_PLUGIN_DIR . 'includes/libraries/GeoIp2/' . $file ); |
|
522 | + foreach ($geoip2_files as $key => $file) { |
|
523 | + require_once(WPINV_PLUGIN_DIR . 'includes/libraries/GeoIp2/' . $file); |
|
524 | 524 | } |
525 | 525 | } |
526 | 526 | |
527 | - define( 'WPINV_GEOIP2_LODDED', true ); |
|
527 | + define('WPINV_GEOIP2_LODDED', true); |
|
528 | 528 | } |
529 | 529 | |
530 | 530 | public static function geoip2_country_dbfile() { |
531 | 531 | $upload_dir = wp_upload_dir(); |
532 | 532 | |
533 | - if ( !isset( $upload_dir['basedir'] ) ) { |
|
533 | + if (!isset($upload_dir['basedir'])) { |
|
534 | 534 | return false; |
535 | 535 | } |
536 | 536 | |
537 | 537 | $filename = $upload_dir['basedir'] . '/invoicing/GeoLite2-Country.mmdb'; |
538 | - if ( !file_exists( $filename ) ) { |
|
538 | + if (!file_exists($filename)) { |
|
539 | 539 | return false; |
540 | 540 | } |
541 | 541 | |
@@ -545,12 +545,12 @@ discard block |
||
545 | 545 | public static function geoip2_city_dbfile() { |
546 | 546 | $upload_dir = wp_upload_dir(); |
547 | 547 | |
548 | - if ( !isset( $upload_dir['basedir'] ) ) { |
|
548 | + if (!isset($upload_dir['basedir'])) { |
|
549 | 549 | return false; |
550 | 550 | } |
551 | 551 | |
552 | 552 | $filename = $upload_dir['basedir'] . '/invoicing/GeoLite2-City.mmdb'; |
553 | - if ( !file_exists( $filename ) ) { |
|
553 | + if (!file_exists($filename)) { |
|
554 | 554 | return false; |
555 | 555 | } |
556 | 556 | |
@@ -561,10 +561,10 @@ discard block |
||
561 | 561 | try { |
562 | 562 | self::load_geoip2(); |
563 | 563 | |
564 | - if ( $filename = self::geoip2_country_dbfile() ) { |
|
565 | - return new \GeoIp2\Database\Reader( $filename ); |
|
564 | + if ($filename = self::geoip2_country_dbfile()) { |
|
565 | + return new \GeoIp2\Database\Reader($filename); |
|
566 | 566 | } |
567 | - } catch( Exception $e ) { |
|
567 | + } catch (Exception $e) { |
|
568 | 568 | return false; |
569 | 569 | } |
570 | 570 | |
@@ -575,173 +575,173 @@ discard block |
||
575 | 575 | try { |
576 | 576 | self::load_geoip2(); |
577 | 577 | |
578 | - if ( $filename = self::geoip2_city_dbfile() ) { |
|
579 | - return new \GeoIp2\Database\Reader( $filename ); |
|
578 | + if ($filename = self::geoip2_city_dbfile()) { |
|
579 | + return new \GeoIp2\Database\Reader($filename); |
|
580 | 580 | } |
581 | - } catch( Exception $e ) { |
|
581 | + } catch (Exception $e) { |
|
582 | 582 | return false; |
583 | 583 | } |
584 | 584 | |
585 | 585 | return false; |
586 | 586 | } |
587 | 587 | |
588 | - public static function geoip2_country_record( $ip_address ) { |
|
588 | + public static function geoip2_country_record($ip_address) { |
|
589 | 589 | try { |
590 | 590 | $reader = self::geoip2_country_reader(); |
591 | 591 | |
592 | - if ( $reader ) { |
|
593 | - $record = $reader->country( $ip_address ); |
|
592 | + if ($reader) { |
|
593 | + $record = $reader->country($ip_address); |
|
594 | 594 | |
595 | - if ( !empty( $record->country->isoCode ) ) { |
|
595 | + if (!empty($record->country->isoCode)) { |
|
596 | 596 | return $record; |
597 | 597 | } |
598 | 598 | } |
599 | - } catch(\InvalidArgumentException $e) { |
|
600 | - wpinv_error_log( $e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )' ); |
|
599 | + } catch (\InvalidArgumentException $e) { |
|
600 | + wpinv_error_log($e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )'); |
|
601 | 601 | |
602 | 602 | return false; |
603 | - } catch(\GeoIp2\Exception\AddressNotFoundException $e) { |
|
604 | - wpinv_error_log( $e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )' ); |
|
603 | + } catch (\GeoIp2\Exception\AddressNotFoundException $e) { |
|
604 | + wpinv_error_log($e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )'); |
|
605 | 605 | |
606 | 606 | return false; |
607 | - } catch( Exception $e ) { |
|
607 | + } catch (Exception $e) { |
|
608 | 608 | return false; |
609 | 609 | } |
610 | 610 | |
611 | 611 | return false; |
612 | 612 | } |
613 | 613 | |
614 | - public static function geoip2_city_record( $ip_address ) { |
|
614 | + public static function geoip2_city_record($ip_address) { |
|
615 | 615 | try { |
616 | 616 | $reader = self::geoip2_city_reader(); |
617 | 617 | |
618 | - if ( $reader ) { |
|
619 | - $record = $reader->city( $ip_address ); |
|
618 | + if ($reader) { |
|
619 | + $record = $reader->city($ip_address); |
|
620 | 620 | |
621 | - if ( !empty( $record->country->isoCode ) ) { |
|
621 | + if (!empty($record->country->isoCode)) { |
|
622 | 622 | return $record; |
623 | 623 | } |
624 | 624 | } |
625 | - } catch(\InvalidArgumentException $e) { |
|
626 | - wpinv_error_log( $e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )' ); |
|
625 | + } catch (\InvalidArgumentException $e) { |
|
626 | + wpinv_error_log($e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )'); |
|
627 | 627 | |
628 | 628 | return false; |
629 | - } catch(\GeoIp2\Exception\AddressNotFoundException $e) { |
|
630 | - wpinv_error_log( $e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )' ); |
|
629 | + } catch (\GeoIp2\Exception\AddressNotFoundException $e) { |
|
630 | + wpinv_error_log($e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )'); |
|
631 | 631 | |
632 | 632 | return false; |
633 | - } catch( Exception $e ) { |
|
633 | + } catch (Exception $e) { |
|
634 | 634 | return false; |
635 | 635 | } |
636 | 636 | |
637 | 637 | return false; |
638 | 638 | } |
639 | 639 | |
640 | - public static function geoip2_country_code( $ip_address ) { |
|
641 | - $record = self::geoip2_country_record( $ip_address ); |
|
642 | - return !empty( $record->country->isoCode ) ? $record->country->isoCode : wpinv_get_default_country(); |
|
640 | + public static function geoip2_country_code($ip_address) { |
|
641 | + $record = self::geoip2_country_record($ip_address); |
|
642 | + return !empty($record->country->isoCode) ? $record->country->isoCode : wpinv_get_default_country(); |
|
643 | 643 | } |
644 | 644 | |
645 | 645 | // Find country by IP address. |
646 | - public static function get_country_by_ip( $ip = '' ) { |
|
646 | + public static function get_country_by_ip($ip = '') { |
|
647 | 647 | global $wpinv_ip_address_country; |
648 | 648 | |
649 | - if ( !empty( $wpinv_ip_address_country ) ) { |
|
649 | + if (!empty($wpinv_ip_address_country)) { |
|
650 | 650 | return $wpinv_ip_address_country; |
651 | 651 | } |
652 | 652 | |
653 | - if ( empty( $ip ) ) { |
|
653 | + if (empty($ip)) { |
|
654 | 654 | $ip = wpinv_get_ip(); |
655 | 655 | } |
656 | 656 | |
657 | - $ip_country_service = wpinv_get_option( 'vat_ip_lookup' ); |
|
658 | - $is_default = empty( $ip_country_service ) || $ip_country_service === 'default' ? true : false; |
|
657 | + $ip_country_service = wpinv_get_option('vat_ip_lookup'); |
|
658 | + $is_default = empty($ip_country_service) || $ip_country_service === 'default' ? true : false; |
|
659 | 659 | |
660 | - if ( !empty( $ip ) && $ip !== '127.0.0.1' ) { // For 127.0.0.1(localhost) use default country. |
|
661 | - if ( function_exists( 'geoip_country_code_by_name') && ( $ip_country_service === 'geoip' || $is_default ) ) { |
|
660 | + if (!empty($ip) && $ip !== '127.0.0.1') { // For 127.0.0.1(localhost) use default country. |
|
661 | + if (function_exists('geoip_country_code_by_name') && ($ip_country_service === 'geoip' || $is_default)) { |
|
662 | 662 | try { |
663 | - $wpinv_ip_address_country = geoip_country_code_by_name( $ip ); |
|
664 | - } catch( Exception $e ) { |
|
665 | - wpinv_error_log( $e->getMessage(), 'GeoIP Lookup( ' . $ip . ' )' ); |
|
663 | + $wpinv_ip_address_country = geoip_country_code_by_name($ip); |
|
664 | + } catch (Exception $e) { |
|
665 | + wpinv_error_log($e->getMessage(), 'GeoIP Lookup( ' . $ip . ' )'); |
|
666 | 666 | } |
667 | - } else if ( self::geoip2_country_dbfile() && ( $ip_country_service === 'geoip2' || $is_default ) ) { |
|
668 | - $wpinv_ip_address_country = self::geoip2_country_code( $ip ); |
|
669 | - } else if ( function_exists( 'simplexml_load_file' ) && ( $ip_country_service === 'geoplugin' || $is_default ) ) { |
|
670 | - $load_xml = simplexml_load_file( 'http://www.geoplugin.net/xml.gp?ip=' . $ip ); |
|
667 | + } else if (self::geoip2_country_dbfile() && ($ip_country_service === 'geoip2' || $is_default)) { |
|
668 | + $wpinv_ip_address_country = self::geoip2_country_code($ip); |
|
669 | + } else if (function_exists('simplexml_load_file') && ($ip_country_service === 'geoplugin' || $is_default)) { |
|
670 | + $load_xml = simplexml_load_file('http://www.geoplugin.net/xml.gp?ip=' . $ip); |
|
671 | 671 | |
672 | - if ( !empty( $load_xml ) && !empty( $load_xml->geoplugin_countryCode ) ) { |
|
672 | + if (!empty($load_xml) && !empty($load_xml->geoplugin_countryCode)) { |
|
673 | 673 | $wpinv_ip_address_country = (string)$load_xml->geoplugin_countryCode; |
674 | 674 | } |
675 | 675 | } |
676 | 676 | } |
677 | 677 | |
678 | - if ( empty( $wpinv_ip_address_country ) ) { |
|
678 | + if (empty($wpinv_ip_address_country)) { |
|
679 | 679 | $wpinv_ip_address_country = wpinv_get_default_country(); |
680 | 680 | } |
681 | 681 | |
682 | 682 | return $wpinv_ip_address_country; |
683 | 683 | } |
684 | 684 | |
685 | - public static function sanitize_vat_settings( $input ) { |
|
685 | + public static function sanitize_vat_settings($input) { |
|
686 | 686 | global $wpinv_options; |
687 | 687 | |
688 | 688 | $valid = false; |
689 | 689 | $message = ''; |
690 | 690 | |
691 | - if ( !empty( $wpinv_options['vat_vies_check'] ) ) { |
|
692 | - if ( empty( $wpinv_options['vat_offline_check'] ) ) { |
|
693 | - $valid = self::offline_check( $input['vat_number'] ); |
|
691 | + if (!empty($wpinv_options['vat_vies_check'])) { |
|
692 | + if (empty($wpinv_options['vat_offline_check'])) { |
|
693 | + $valid = self::offline_check($input['vat_number']); |
|
694 | 694 | } else { |
695 | 695 | $valid = true; |
696 | 696 | } |
697 | 697 | |
698 | - $message = $valid ? '' : __( 'VAT number not validated', 'invoicing' ); |
|
698 | + $message = $valid ? '' : __('VAT number not validated', 'invoicing'); |
|
699 | 699 | } else { |
700 | - $result = self::check_vat( $input['vat_number'] ); |
|
700 | + $result = self::check_vat($input['vat_number']); |
|
701 | 701 | |
702 | - if ( empty( $result['valid'] ) ) { |
|
702 | + if (empty($result['valid'])) { |
|
703 | 703 | $valid = false; |
704 | 704 | $message = $result['message']; |
705 | 705 | } else { |
706 | - $valid = ( isset( $result['company'] ) && ( $result['company'] == '---' || ( strcasecmp( trim( $result['company'] ), trim( $input['vat_company_name'] ) ) == 0 ) ) ) || !empty( $wpinv_options['vat_disable_company_name_check'] ); |
|
707 | - $message = $valid ? '' : __( 'The company name associated with the VAT number provided is not the same as the company name provided.', 'invoicing' ); |
|
706 | + $valid = (isset($result['company']) && ($result['company'] == '---' || (strcasecmp(trim($result['company']), trim($input['vat_company_name'])) == 0))) || !empty($wpinv_options['vat_disable_company_name_check']); |
|
707 | + $message = $valid ? '' : __('The company name associated with the VAT number provided is not the same as the company name provided.', 'invoicing'); |
|
708 | 708 | } |
709 | 709 | } |
710 | 710 | |
711 | - if ( $message && self::is_vat_validated() != $valid ) { |
|
712 | - add_settings_error( 'wpinv-notices', '', $message, ( $valid ? 'updated' : 'error' ) ); |
|
711 | + if ($message && self::is_vat_validated() != $valid) { |
|
712 | + add_settings_error('wpinv-notices', '', $message, ($valid ? 'updated' : 'error')); |
|
713 | 713 | } |
714 | 714 | |
715 | 715 | $input['vat_valid'] = $valid; |
716 | 716 | return $input; |
717 | 717 | } |
718 | 718 | |
719 | - public static function sanitize_vat_rates( $input ) { |
|
720 | - if( !current_user_can( 'manage_options' ) ) { |
|
721 | - add_settings_error( 'wpinv-notices', '', __( 'Your account does not have permission to add rate classes.', 'invoicing' ), 'error' ); |
|
719 | + public static function sanitize_vat_rates($input) { |
|
720 | + if (!current_user_can('manage_options')) { |
|
721 | + add_settings_error('wpinv-notices', '', __('Your account does not have permission to add rate classes.', 'invoicing'), 'error'); |
|
722 | 722 | return $input; |
723 | 723 | } |
724 | 724 | |
725 | 725 | $vat_classes = self::get_rate_classes(); |
726 | - $vat_class = !empty( $_REQUEST['wpi_vat_class'] ) && isset( $vat_classes[$_REQUEST['wpi_vat_class']] )? sanitize_text_field( $_REQUEST['wpi_vat_class'] ) : ''; |
|
726 | + $vat_class = !empty($_REQUEST['wpi_vat_class']) && isset($vat_classes[$_REQUEST['wpi_vat_class']]) ? sanitize_text_field($_REQUEST['wpi_vat_class']) : ''; |
|
727 | 727 | |
728 | - if ( empty( $vat_class ) ) { |
|
729 | - add_settings_error( 'wpinv-notices', '', __( 'No valid VAT rates class contained in the request to save rates.', 'invoicing' ), 'error' ); |
|
728 | + if (empty($vat_class)) { |
|
729 | + add_settings_error('wpinv-notices', '', __('No valid VAT rates class contained in the request to save rates.', 'invoicing'), 'error'); |
|
730 | 730 | |
731 | 731 | return $input; |
732 | 732 | } |
733 | 733 | |
734 | - $new_rates = ! empty( $_POST['vat_rates'] ) ? array_values( $_POST['vat_rates'] ) : array(); |
|
734 | + $new_rates = !empty($_POST['vat_rates']) ? array_values($_POST['vat_rates']) : array(); |
|
735 | 735 | |
736 | - if ( $vat_class === '_standard' ) { |
|
736 | + if ($vat_class === '_standard') { |
|
737 | 737 | // Save the active rates in the invoice settings |
738 | - update_option( 'wpinv_tax_rates', $new_rates ); |
|
738 | + update_option('wpinv_tax_rates', $new_rates); |
|
739 | 739 | } else { |
740 | 740 | // Get the existing set of rates |
741 | 741 | $rates = self::get_non_standard_rates(); |
742 | 742 | $rates[$vat_class] = $new_rates; |
743 | 743 | |
744 | - update_option( 'wpinv_vat_rates', $rates ); |
|
744 | + update_option('wpinv_vat_rates', $rates); |
|
745 | 745 | } |
746 | 746 | |
747 | 747 | return $input; |
@@ -751,71 +751,71 @@ discard block |
||
751 | 751 | $response = array(); |
752 | 752 | $response['success'] = false; |
753 | 753 | |
754 | - if ( !current_user_can( 'manage_options' ) ) { |
|
755 | - $response['error'] = __( 'Invalid access!', 'invoicing' ); |
|
756 | - wp_send_json( $response ); |
|
754 | + if (!current_user_can('manage_options')) { |
|
755 | + $response['error'] = __('Invalid access!', 'invoicing'); |
|
756 | + wp_send_json($response); |
|
757 | 757 | } |
758 | 758 | |
759 | - $vat_class_name = !empty( $_POST['name'] ) ? sanitize_text_field( $_POST['name'] ) : false; |
|
760 | - $vat_class_desc = !empty( $_POST['desc'] ) ? sanitize_text_field( $_POST['desc'] ) : false; |
|
759 | + $vat_class_name = !empty($_POST['name']) ? sanitize_text_field($_POST['name']) : false; |
|
760 | + $vat_class_desc = !empty($_POST['desc']) ? sanitize_text_field($_POST['desc']) : false; |
|
761 | 761 | |
762 | - if ( empty( $vat_class_name ) ) { |
|
763 | - $response['error'] = __( 'Select the VAT rate name', 'invoicing' ); |
|
764 | - wp_send_json( $response ); |
|
762 | + if (empty($vat_class_name)) { |
|
763 | + $response['error'] = __('Select the VAT rate name', 'invoicing'); |
|
764 | + wp_send_json($response); |
|
765 | 765 | } |
766 | 766 | |
767 | 767 | $vat_classes = (array)self::get_rate_classes(); |
768 | 768 | |
769 | - if ( !empty( $vat_classes ) && in_array( strtolower( $vat_class_name ), array_map( 'strtolower', array_values( $vat_classes ) ) ) ) { |
|
770 | - $response['error'] = wp_sprintf( __( 'A VAT Rate name "%s" already exists', 'invoicing' ), $vat_class_name ); |
|
771 | - wp_send_json( $response ); |
|
769 | + if (!empty($vat_classes) && in_array(strtolower($vat_class_name), array_map('strtolower', array_values($vat_classes)))) { |
|
770 | + $response['error'] = wp_sprintf(__('A VAT Rate name "%s" already exists', 'invoicing'), $vat_class_name); |
|
771 | + wp_send_json($response); |
|
772 | 772 | } |
773 | 773 | |
774 | - $rate_class_key = normalize_whitespace( 'wpi-' . $vat_class_name ); |
|
775 | - $rate_class_key = sanitize_key( str_replace( " ", "-", $rate_class_key ) ); |
|
774 | + $rate_class_key = normalize_whitespace('wpi-' . $vat_class_name); |
|
775 | + $rate_class_key = sanitize_key(str_replace(" ", "-", $rate_class_key)); |
|
776 | 776 | |
777 | - $vat_classes = (array)self::get_rate_classes( true ); |
|
778 | - $vat_classes[$rate_class_key] = array( 'name' => $vat_class_name, 'desc' => $vat_class_desc ); |
|
777 | + $vat_classes = (array)self::get_rate_classes(true); |
|
778 | + $vat_classes[$rate_class_key] = array('name' => $vat_class_name, 'desc' => $vat_class_desc); |
|
779 | 779 | |
780 | - update_option( '_wpinv_vat_rate_classes', $vat_classes ); |
|
780 | + update_option('_wpinv_vat_rate_classes', $vat_classes); |
|
781 | 781 | |
782 | 782 | $response['success'] = true; |
783 | - $response['redirect'] = admin_url( 'admin.php?page=wpinv-settings&tab=taxes§ion=vat_rates&wpi_sub=' . $rate_class_key ); |
|
783 | + $response['redirect'] = admin_url('admin.php?page=wpinv-settings&tab=taxes§ion=vat_rates&wpi_sub=' . $rate_class_key); |
|
784 | 784 | |
785 | - wp_send_json( $response ); |
|
785 | + wp_send_json($response); |
|
786 | 786 | } |
787 | 787 | |
788 | 788 | public static function delete_class() { |
789 | 789 | $response = array(); |
790 | 790 | $response['success'] = false; |
791 | 791 | |
792 | - if ( !current_user_can( 'manage_options' ) || !isset( $_POST['class'] ) ) { |
|
793 | - $response['error'] = __( 'Invalid access!', 'invoicing' ); |
|
794 | - wp_send_json( $response ); |
|
792 | + if (!current_user_can('manage_options') || !isset($_POST['class'])) { |
|
793 | + $response['error'] = __('Invalid access!', 'invoicing'); |
|
794 | + wp_send_json($response); |
|
795 | 795 | } |
796 | 796 | |
797 | - $vat_class = isset( $_POST['class'] ) && $_POST['class'] !== '' ? sanitize_text_field( $_POST['class'] ) : false; |
|
797 | + $vat_class = isset($_POST['class']) && $_POST['class'] !== '' ? sanitize_text_field($_POST['class']) : false; |
|
798 | 798 | $vat_classes = (array)self::get_rate_classes(); |
799 | 799 | |
800 | - if ( !isset( $vat_classes[$vat_class] ) ) { |
|
801 | - $response['error'] = __( 'Requested class does not exists', 'invoicing' ); |
|
802 | - wp_send_json( $response ); |
|
800 | + if (!isset($vat_classes[$vat_class])) { |
|
801 | + $response['error'] = __('Requested class does not exists', 'invoicing'); |
|
802 | + wp_send_json($response); |
|
803 | 803 | } |
804 | 804 | |
805 | - if ( $vat_class == '_new' || $vat_class == '_standard' ) { |
|
806 | - $response['error'] = __( 'You can not delete standard rates class', 'invoicing' ); |
|
807 | - wp_send_json( $response ); |
|
805 | + if ($vat_class == '_new' || $vat_class == '_standard') { |
|
806 | + $response['error'] = __('You can not delete standard rates class', 'invoicing'); |
|
807 | + wp_send_json($response); |
|
808 | 808 | } |
809 | 809 | |
810 | - $vat_classes = (array)self::get_rate_classes( true ); |
|
811 | - unset( $vat_classes[$vat_class] ); |
|
810 | + $vat_classes = (array)self::get_rate_classes(true); |
|
811 | + unset($vat_classes[$vat_class]); |
|
812 | 812 | |
813 | - update_option( '_wpinv_vat_rate_classes', $vat_classes ); |
|
813 | + update_option('_wpinv_vat_rate_classes', $vat_classes); |
|
814 | 814 | |
815 | 815 | $response['success'] = true; |
816 | - $response['redirect'] = admin_url( 'admin.php?page=wpinv-settings&tab=taxes§ion=vat_rates&wpi_sub=_new' ); |
|
816 | + $response['redirect'] = admin_url('admin.php?page=wpinv-settings&tab=taxes§ion=vat_rates&wpi_sub=_new'); |
|
817 | 817 | |
818 | - wp_send_json( $response ); |
|
818 | + wp_send_json($response); |
|
819 | 819 | } |
820 | 820 | |
821 | 821 | public static function update_eu_rates() { |
@@ -824,72 +824,72 @@ discard block |
||
824 | 824 | $response['error'] = null; |
825 | 825 | $response['data'] = null; |
826 | 826 | |
827 | - if ( !current_user_can( 'manage_options' ) ) { |
|
828 | - $response['error'] = __( 'Invalid access!', 'invoicing' ); |
|
829 | - wp_send_json( $response ); |
|
827 | + if (!current_user_can('manage_options')) { |
|
828 | + $response['error'] = __('Invalid access!', 'invoicing'); |
|
829 | + wp_send_json($response); |
|
830 | 830 | } |
831 | 831 | |
832 | - $group = !empty( $_POST['group'] ) ? sanitize_text_field( $_POST['group'] ) : ''; |
|
833 | - $euvatrates = self::request_euvatrates( $group ); |
|
832 | + $group = !empty($_POST['group']) ? sanitize_text_field($_POST['group']) : ''; |
|
833 | + $euvatrates = self::request_euvatrates($group); |
|
834 | 834 | |
835 | - if ( !empty( $euvatrates ) ) { |
|
836 | - if ( !empty( $euvatrates['success'] ) && !empty( $euvatrates['rates'] ) ) { |
|
835 | + if (!empty($euvatrates)) { |
|
836 | + if (!empty($euvatrates['success']) && !empty($euvatrates['rates'])) { |
|
837 | 837 | $response['success'] = true; |
838 | 838 | $response['data']['rates'] = $euvatrates['rates']; |
839 | - } else if ( !empty( $euvatrates['error'] ) ) { |
|
839 | + } else if (!empty($euvatrates['error'])) { |
|
840 | 840 | $response['error'] = $euvatrates['error']; |
841 | 841 | } |
842 | 842 | } |
843 | 843 | |
844 | - wp_send_json( $response ); |
|
844 | + wp_send_json($response); |
|
845 | 845 | } |
846 | 846 | |
847 | 847 | public static function hide_vat_fields() { |
848 | - $hide = wpinv_get_option( 'vat_disable_fields' ); |
|
848 | + $hide = wpinv_get_option('vat_disable_fields'); |
|
849 | 849 | |
850 | - return apply_filters( 'wpinv_hide_vat_fields', $hide ); |
|
850 | + return apply_filters('wpinv_hide_vat_fields', $hide); |
|
851 | 851 | } |
852 | 852 | |
853 | 853 | public static function same_country_rule() { |
854 | - $same_country_rule = wpinv_get_option( 'vat_same_country_rule' ); |
|
854 | + $same_country_rule = wpinv_get_option('vat_same_country_rule'); |
|
855 | 855 | |
856 | - return apply_filters( 'wpinv_vat_same_country_rule', $same_country_rule ); |
|
856 | + return apply_filters('wpinv_vat_same_country_rule', $same_country_rule); |
|
857 | 857 | } |
858 | 858 | |
859 | 859 | public static function get_vat_name() { |
860 | - $vat_name = wpinv_get_option( 'vat_name' ); |
|
861 | - $vat_name = !empty( $vat_name ) ? $vat_name : 'VAT'; |
|
860 | + $vat_name = wpinv_get_option('vat_name'); |
|
861 | + $vat_name = !empty($vat_name) ? $vat_name : 'VAT'; |
|
862 | 862 | |
863 | - return apply_filters( 'wpinv_get_owner_vat_name', $vat_name ); |
|
863 | + return apply_filters('wpinv_get_owner_vat_name', $vat_name); |
|
864 | 864 | } |
865 | 865 | |
866 | 866 | public static function get_company_name() { |
867 | - $company_name = wpinv_get_option( 'vat_company_name' ); |
|
867 | + $company_name = wpinv_get_option('vat_company_name'); |
|
868 | 868 | |
869 | - return apply_filters( 'wpinv_get_owner_company_name', $company_name ); |
|
869 | + return apply_filters('wpinv_get_owner_company_name', $company_name); |
|
870 | 870 | } |
871 | 871 | |
872 | 872 | public static function get_vat_number() { |
873 | - $vat_number = wpinv_get_option( 'vat_number' ); |
|
873 | + $vat_number = wpinv_get_option('vat_number'); |
|
874 | 874 | |
875 | - return apply_filters( 'wpinv_get_owner_vat_number', $vat_number ); |
|
875 | + return apply_filters('wpinv_get_owner_vat_number', $vat_number); |
|
876 | 876 | } |
877 | 877 | |
878 | 878 | public static function is_vat_validated() { |
879 | - $validated = self::get_vat_number() && wpinv_get_option( 'vat_valid' ); |
|
879 | + $validated = self::get_vat_number() && wpinv_get_option('vat_valid'); |
|
880 | 880 | |
881 | - return apply_filters( 'wpinv_is_owner_vat_validated', $validated ); |
|
881 | + return apply_filters('wpinv_is_owner_vat_validated', $validated); |
|
882 | 882 | } |
883 | 883 | |
884 | - public static function sanitize_vat( $vat_number, $country_code = '' ) { |
|
885 | - $vat_number = str_replace( array(' ', '.', '-', '_', ',' ), '', strtoupper( trim( $vat_number ) ) ); |
|
884 | + public static function sanitize_vat($vat_number, $country_code = '') { |
|
885 | + $vat_number = str_replace(array(' ', '.', '-', '_', ','), '', strtoupper(trim($vat_number))); |
|
886 | 886 | |
887 | - if ( empty( $country_code ) ) { |
|
888 | - $country_code = substr( $vat_number, 0, 2 ); |
|
887 | + if (empty($country_code)) { |
|
888 | + $country_code = substr($vat_number, 0, 2); |
|
889 | 889 | } |
890 | 890 | |
891 | - if ( strpos( $vat_number , $country_code ) === 0 ) { |
|
892 | - $vat = str_replace( $country_code, '', $vat_number ); |
|
891 | + if (strpos($vat_number, $country_code) === 0) { |
|
892 | + $vat = str_replace($country_code, '', $vat_number); |
|
893 | 893 | } else { |
894 | 894 | $vat = $country_code . $vat_number; |
895 | 895 | } |
@@ -902,140 +902,140 @@ discard block |
||
902 | 902 | return $return; |
903 | 903 | } |
904 | 904 | |
905 | - public static function offline_check( $vat_number, $country_code = '', $formatted = false ) { |
|
906 | - $vat = self::sanitize_vat( $vat_number, $country_code ); |
|
905 | + public static function offline_check($vat_number, $country_code = '', $formatted = false) { |
|
906 | + $vat = self::sanitize_vat($vat_number, $country_code); |
|
907 | 907 | $vat_number = $vat['vat_number']; |
908 | 908 | $country_code = $vat['iso']; |
909 | 909 | $regex = array(); |
910 | 910 | |
911 | - switch ( $country_code ) { |
|
911 | + switch ($country_code) { |
|
912 | 912 | case 'AT': |
913 | - $regex[] = '/^(AT)U(\d{8})$/'; // Austria |
|
913 | + $regex[] = '/^(AT)U(\d{8})$/'; // Austria |
|
914 | 914 | break; |
915 | 915 | case 'BE': |
916 | - $regex[] = '/^(BE)(0?\d{9})$/'; // Belgium |
|
916 | + $regex[] = '/^(BE)(0?\d{9})$/'; // Belgium |
|
917 | 917 | break; |
918 | 918 | case 'BG': |
919 | - $regex[] = '/^(BG)(\d{9,10})$/'; // Bulgaria |
|
919 | + $regex[] = '/^(BG)(\d{9,10})$/'; // Bulgaria |
|
920 | 920 | break; |
921 | 921 | case 'CH': |
922 | 922 | case 'CHE': |
923 | - $regex[] = '/^(CHE)(\d{9})MWST$/'; // Switzerland (Not EU) |
|
923 | + $regex[] = '/^(CHE)(\d{9})MWST$/'; // Switzerland (Not EU) |
|
924 | 924 | break; |
925 | 925 | case 'CY': |
926 | - $regex[] = '/^(CY)([0-5|9]\d{7}[A-Z])$/'; // Cyprus |
|
926 | + $regex[] = '/^(CY)([0-5|9]\d{7}[A-Z])$/'; // Cyprus |
|
927 | 927 | break; |
928 | 928 | case 'CZ': |
929 | - $regex[] = '/^(CZ)(\d{8,13})$/'; // Czech Republic |
|
929 | + $regex[] = '/^(CZ)(\d{8,13})$/'; // Czech Republic |
|
930 | 930 | break; |
931 | 931 | case 'DE': |
932 | - $regex[] = '/^(DE)([1-9]\d{8})$/'; // Germany |
|
932 | + $regex[] = '/^(DE)([1-9]\d{8})$/'; // Germany |
|
933 | 933 | break; |
934 | 934 | case 'DK': |
935 | - $regex[] = '/^(DK)(\d{8})$/'; // Denmark |
|
935 | + $regex[] = '/^(DK)(\d{8})$/'; // Denmark |
|
936 | 936 | break; |
937 | 937 | case 'EE': |
938 | - $regex[] = '/^(EE)(10\d{7})$/'; // Estonia |
|
938 | + $regex[] = '/^(EE)(10\d{7})$/'; // Estonia |
|
939 | 939 | break; |
940 | 940 | case 'EL': |
941 | - $regex[] = '/^(EL)(\d{9})$/'; // Greece |
|
941 | + $regex[] = '/^(EL)(\d{9})$/'; // Greece |
|
942 | 942 | break; |
943 | 943 | case 'ES': |
944 | - $regex[] = '/^(ES)([A-Z]\d{8})$/'; // Spain (National juridical entities) |
|
945 | - $regex[] = '/^(ES)([A-H|N-S|W]\d{7}[A-J])$/'; // Spain (Other juridical entities) |
|
946 | - $regex[] = '/^(ES)([0-9|Y|Z]\d{7}[A-Z])$/'; // Spain (Personal entities type 1) |
|
947 | - $regex[] = '/^(ES)([K|L|M|X]\d{7}[A-Z])$/'; // Spain (Personal entities type 2) |
|
944 | + $regex[] = '/^(ES)([A-Z]\d{8})$/'; // Spain (National juridical entities) |
|
945 | + $regex[] = '/^(ES)([A-H|N-S|W]\d{7}[A-J])$/'; // Spain (Other juridical entities) |
|
946 | + $regex[] = '/^(ES)([0-9|Y|Z]\d{7}[A-Z])$/'; // Spain (Personal entities type 1) |
|
947 | + $regex[] = '/^(ES)([K|L|M|X]\d{7}[A-Z])$/'; // Spain (Personal entities type 2) |
|
948 | 948 | break; |
949 | 949 | case 'EU': |
950 | - $regex[] = '/^(EU)(\d{9})$/'; // EU-type |
|
950 | + $regex[] = '/^(EU)(\d{9})$/'; // EU-type |
|
951 | 951 | break; |
952 | 952 | case 'FI': |
953 | - $regex[] = '/^(FI)(\d{8})$/'; // Finland |
|
953 | + $regex[] = '/^(FI)(\d{8})$/'; // Finland |
|
954 | 954 | break; |
955 | 955 | case 'FR': |
956 | - $regex[] = '/^(FR)(\d{11})$/'; // France (1) |
|
957 | - $regex[] = '/^(FR)[(A-H)|(J-N)|(P-Z)](\d{10})$/'; // France (2) |
|
958 | - $regex[] = '/^(FR)\d[(A-H)|(J-N)|(P-Z)](\d{9})$/'; // France (3) |
|
959 | - $regex[] = '/^(FR)[(A-H)|(J-N)|(P-Z)]{2}(\d{9})$/'; // France (4) |
|
956 | + $regex[] = '/^(FR)(\d{11})$/'; // France (1) |
|
957 | + $regex[] = '/^(FR)[(A-H)|(J-N)|(P-Z)](\d{10})$/'; // France (2) |
|
958 | + $regex[] = '/^(FR)\d[(A-H)|(J-N)|(P-Z)](\d{9})$/'; // France (3) |
|
959 | + $regex[] = '/^(FR)[(A-H)|(J-N)|(P-Z)]{2}(\d{9})$/'; // France (4) |
|
960 | 960 | break; |
961 | 961 | case 'GB': |
962 | - $regex[] = '/^(GB)?(\d{9})$/'; // UK (Standard) |
|
963 | - $regex[] = '/^(GB)?(\d{12})$/'; // UK (Branches) |
|
964 | - $regex[] = '/^(GB)?(GD\d{3})$/'; // UK (Government) |
|
965 | - $regex[] = '/^(GB)?(HA\d{3})$/'; // UK (Health authority) |
|
962 | + $regex[] = '/^(GB)?(\d{9})$/'; // UK (Standard) |
|
963 | + $regex[] = '/^(GB)?(\d{12})$/'; // UK (Branches) |
|
964 | + $regex[] = '/^(GB)?(GD\d{3})$/'; // UK (Government) |
|
965 | + $regex[] = '/^(GB)?(HA\d{3})$/'; // UK (Health authority) |
|
966 | 966 | break; |
967 | 967 | case 'GR': |
968 | - $regex[] = '/^(GR)(\d{8,9})$/'; // Greece |
|
968 | + $regex[] = '/^(GR)(\d{8,9})$/'; // Greece |
|
969 | 969 | break; |
970 | 970 | case 'HR': |
971 | - $regex[] = '/^(HR)(\d{11})$/'; // Croatia |
|
971 | + $regex[] = '/^(HR)(\d{11})$/'; // Croatia |
|
972 | 972 | break; |
973 | 973 | case 'HU': |
974 | - $regex[] = '/^(HU)(\d{8})$/'; // Hungary |
|
974 | + $regex[] = '/^(HU)(\d{8})$/'; // Hungary |
|
975 | 975 | break; |
976 | 976 | case 'IE': |
977 | - $regex[] = '/^(IE)(\d{7}[A-W])$/'; // Ireland (1) |
|
978 | - $regex[] = '/^(IE)([7-9][A-Z\*\+)]\d{5}[A-W])$/'; // Ireland (2) |
|
979 | - $regex[] = '/^(IE)(\d{7}[A-Z][AH])$/'; // Ireland (3) (new format from 1 Jan 2013) |
|
977 | + $regex[] = '/^(IE)(\d{7}[A-W])$/'; // Ireland (1) |
|
978 | + $regex[] = '/^(IE)([7-9][A-Z\*\+)]\d{5}[A-W])$/'; // Ireland (2) |
|
979 | + $regex[] = '/^(IE)(\d{7}[A-Z][AH])$/'; // Ireland (3) (new format from 1 Jan 2013) |
|
980 | 980 | break; |
981 | 981 | case 'IT': |
982 | - $regex[] = '/^(IT)(\d{11})$/'; // Italy |
|
982 | + $regex[] = '/^(IT)(\d{11})$/'; // Italy |
|
983 | 983 | break; |
984 | 984 | case 'LV': |
985 | - $regex[] = '/^(LV)(\d{11})$/'; // Latvia |
|
985 | + $regex[] = '/^(LV)(\d{11})$/'; // Latvia |
|
986 | 986 | break; |
987 | 987 | case 'LT': |
988 | - $regex[] = '/^(LT)(\d{9}|\d{12})$/'; // Lithuania |
|
988 | + $regex[] = '/^(LT)(\d{9}|\d{12})$/'; // Lithuania |
|
989 | 989 | break; |
990 | 990 | case 'LU': |
991 | - $regex[] = '/^(LU)(\d{8})$/'; // Luxembourg |
|
991 | + $regex[] = '/^(LU)(\d{8})$/'; // Luxembourg |
|
992 | 992 | break; |
993 | 993 | case 'MT': |
994 | - $regex[] = '/^(MT)([1-9]\d{7})$/'; // Malta |
|
994 | + $regex[] = '/^(MT)([1-9]\d{7})$/'; // Malta |
|
995 | 995 | break; |
996 | 996 | case 'NL': |
997 | - $regex[] = '/^(NL)(\d{9})B\d{2}$/'; // Netherlands |
|
997 | + $regex[] = '/^(NL)(\d{9})B\d{2}$/'; // Netherlands |
|
998 | 998 | break; |
999 | 999 | case 'NO': |
1000 | - $regex[] = '/^(NO)(\d{9})$/'; // Norway (Not EU) |
|
1000 | + $regex[] = '/^(NO)(\d{9})$/'; // Norway (Not EU) |
|
1001 | 1001 | break; |
1002 | 1002 | case 'PL': |
1003 | - $regex[] = '/^(PL)(\d{10})$/'; // Poland |
|
1003 | + $regex[] = '/^(PL)(\d{10})$/'; // Poland |
|
1004 | 1004 | break; |
1005 | 1005 | case 'PT': |
1006 | - $regex[] = '/^(PT)(\d{9})$/'; // Portugal |
|
1006 | + $regex[] = '/^(PT)(\d{9})$/'; // Portugal |
|
1007 | 1007 | break; |
1008 | 1008 | case 'RO': |
1009 | - $regex[] = '/^(RO)([1-9]\d{1,9})$/'; // Romania |
|
1009 | + $regex[] = '/^(RO)([1-9]\d{1,9})$/'; // Romania |
|
1010 | 1010 | break; |
1011 | 1011 | case 'RS': |
1012 | - $regex[] = '/^(RS)(\d{9})$/'; // Serbia (Not EU) |
|
1012 | + $regex[] = '/^(RS)(\d{9})$/'; // Serbia (Not EU) |
|
1013 | 1013 | break; |
1014 | 1014 | case 'SI': |
1015 | - $regex[] = '/^(SI)([1-9]\d{7})$/'; // Slovenia |
|
1015 | + $regex[] = '/^(SI)([1-9]\d{7})$/'; // Slovenia |
|
1016 | 1016 | break; |
1017 | 1017 | case 'SK': |
1018 | - $regex[] = '/^(SK)([1-9]\d[(2-4)|(6-9)]\d{7})$/'; // Slovakia Republic |
|
1018 | + $regex[] = '/^(SK)([1-9]\d[(2-4)|(6-9)]\d{7})$/'; // Slovakia Republic |
|
1019 | 1019 | break; |
1020 | 1020 | case 'SE': |
1021 | - $regex[] = '/^(SE)(\d{10}01)$/'; // Sweden |
|
1021 | + $regex[] = '/^(SE)(\d{10}01)$/'; // Sweden |
|
1022 | 1022 | break; |
1023 | 1023 | default: |
1024 | 1024 | $regex = array(); |
1025 | 1025 | break; |
1026 | 1026 | } |
1027 | 1027 | |
1028 | - if ( empty( $regex ) ) { |
|
1028 | + if (empty($regex)) { |
|
1029 | 1029 | return false; |
1030 | 1030 | } |
1031 | 1031 | |
1032 | - foreach ( $regex as $pattern ) { |
|
1032 | + foreach ($regex as $pattern) { |
|
1033 | 1033 | $matches = null; |
1034 | - preg_match_all( $pattern, $vat_number, $matches ); |
|
1034 | + preg_match_all($pattern, $vat_number, $matches); |
|
1035 | 1035 | |
1036 | - if ( !empty( $matches[1][0] ) && !empty( $matches[2][0] ) ) { |
|
1037 | - if ( $formatted ) { |
|
1038 | - return array( 'code' => $matches[1][0], 'number' => $matches[2][0] ); |
|
1036 | + if (!empty($matches[1][0]) && !empty($matches[2][0])) { |
|
1037 | + if ($formatted) { |
|
1038 | + return array('code' => $matches[1][0], 'number' => $matches[2][0]); |
|
1039 | 1039 | } else { |
1040 | 1040 | return true; |
1041 | 1041 | } |
@@ -1045,75 +1045,75 @@ discard block |
||
1045 | 1045 | return false; |
1046 | 1046 | } |
1047 | 1047 | |
1048 | - public static function vies_check( $vat_number, $country_code = '', $result = false ) { |
|
1049 | - $vat = self::sanitize_vat( $vat_number, $country_code ); |
|
1048 | + public static function vies_check($vat_number, $country_code = '', $result = false) { |
|
1049 | + $vat = self::sanitize_vat($vat_number, $country_code); |
|
1050 | 1050 | $vat_number = $vat['vat']; |
1051 | 1051 | $iso = $vat['iso']; |
1052 | 1052 | |
1053 | - $url = 'http://ec.europa.eu/taxation_customs/vies/viesquer.do?ms=' . urlencode( $iso ) . '&iso=' . urlencode( $iso ) . '&vat=' . urlencode( $vat_number ); |
|
1053 | + $url = 'http://ec.europa.eu/taxation_customs/vies/viesquer.do?ms=' . urlencode($iso) . '&iso=' . urlencode($iso) . '&vat=' . urlencode($vat_number); |
|
1054 | 1054 | |
1055 | - if ( ini_get( 'allow_url_fopen' ) ) { |
|
1056 | - $response = file_get_contents( $url ); |
|
1057 | - } else if ( function_exists( 'curl_init' ) ) { |
|
1055 | + if (ini_get('allow_url_fopen')) { |
|
1056 | + $response = file_get_contents($url); |
|
1057 | + } else if (function_exists('curl_init')) { |
|
1058 | 1058 | $ch = curl_init(); |
1059 | 1059 | |
1060 | - curl_setopt( $ch, CURLOPT_URL, $url ); |
|
1061 | - curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT, 30 ); |
|
1062 | - curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true ); |
|
1063 | - curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, 0 ); |
|
1064 | - curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, 0 ); |
|
1060 | + curl_setopt($ch, CURLOPT_URL, $url); |
|
1061 | + curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30); |
|
1062 | + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
|
1063 | + curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); |
|
1064 | + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); |
|
1065 | 1065 | |
1066 | - $response = curl_exec( $ch ); |
|
1066 | + $response = curl_exec($ch); |
|
1067 | 1067 | |
1068 | - if ( curl_errno( $ch ) ) { |
|
1069 | - wpinv_error_log( curl_error( $ch ), 'VIES CHECK ERROR' ); |
|
1068 | + if (curl_errno($ch)) { |
|
1069 | + wpinv_error_log(curl_error($ch), 'VIES CHECK ERROR'); |
|
1070 | 1070 | $response = ''; |
1071 | 1071 | } |
1072 | 1072 | |
1073 | - curl_close( $ch ); |
|
1073 | + curl_close($ch); |
|
1074 | 1074 | } else { |
1075 | - 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' ); |
|
1075 | + 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'); |
|
1076 | 1076 | } |
1077 | 1077 | |
1078 | - if ( empty( $response ) ) { |
|
1078 | + if (empty($response)) { |
|
1079 | 1079 | return $result; |
1080 | 1080 | } |
1081 | 1081 | |
1082 | - if ( preg_match( '/invalid VAT number/i', $response ) ) { |
|
1082 | + if (preg_match('/invalid VAT number/i', $response)) { |
|
1083 | 1083 | return false; |
1084 | - } else if ( preg_match( '/valid VAT number/i', $response, $matches ) ) { |
|
1085 | - $content = explode( "valid VAT number", htmlentities( $response ) ); |
|
1084 | + } else if (preg_match('/valid VAT number/i', $response, $matches)) { |
|
1085 | + $content = explode("valid VAT number", htmlentities($response)); |
|
1086 | 1086 | |
1087 | - if ( !empty( $content[1] ) ) { |
|
1088 | - preg_match_all( '/<tr>(.*?)<td.*?>(.*?)<\/td>(.*?)<\/tr>/si', html_entity_decode( $content[1] ), $matches ); |
|
1087 | + if (!empty($content[1])) { |
|
1088 | + preg_match_all('/<tr>(.*?)<td.*?>(.*?)<\/td>(.*?)<\/tr>/si', html_entity_decode($content[1]), $matches); |
|
1089 | 1089 | |
1090 | - if ( !empty( $matches[2] ) && $matches[3] ) { |
|
1090 | + if (!empty($matches[2]) && $matches[3]) { |
|
1091 | 1091 | $return = array(); |
1092 | 1092 | |
1093 | - foreach ( $matches[2] as $key => $label ) { |
|
1094 | - $label = trim( $label ); |
|
1093 | + foreach ($matches[2] as $key => $label) { |
|
1094 | + $label = trim($label); |
|
1095 | 1095 | |
1096 | - switch ( strtolower( $label ) ) { |
|
1096 | + switch (strtolower($label)) { |
|
1097 | 1097 | case 'member state': |
1098 | - $return['state'] = trim( strip_tags( $matches[3][$key] ) ); |
|
1098 | + $return['state'] = trim(strip_tags($matches[3][$key])); |
|
1099 | 1099 | break; |
1100 | 1100 | case 'vat number': |
1101 | - $return['number'] = trim( strip_tags( $matches[3][$key] ) ); |
|
1101 | + $return['number'] = trim(strip_tags($matches[3][$key])); |
|
1102 | 1102 | break; |
1103 | 1103 | case 'name': |
1104 | - $return['company'] = trim( strip_tags( $matches[3][$key] ) ); |
|
1104 | + $return['company'] = trim(strip_tags($matches[3][$key])); |
|
1105 | 1105 | break; |
1106 | 1106 | case 'address': |
1107 | - $address = str_replace( array( "<br><br>", "<br /><br />", "<br/><br/>" ), "<br>", html_entity_decode( trim( $matches[3][$key] ) ) ); |
|
1108 | - $return['address'] = trim( strip_tags( $address, '<br>' ) ); |
|
1107 | + $address = str_replace(array("<br><br>", "<br /><br />", "<br/><br/>"), "<br>", html_entity_decode(trim($matches[3][$key]))); |
|
1108 | + $return['address'] = trim(strip_tags($address, '<br>')); |
|
1109 | 1109 | break; |
1110 | 1110 | case 'consultation number': |
1111 | - $return['consultation'] = trim( strip_tags( $matches[3][$key] ) ); |
|
1111 | + $return['consultation'] = trim(strip_tags($matches[3][$key])); |
|
1112 | 1112 | break; |
1113 | 1113 | } |
1114 | 1114 | } |
1115 | 1115 | |
1116 | - if ( !empty( $return ) ) { |
|
1116 | + if (!empty($return)) { |
|
1117 | 1117 | return $return; |
1118 | 1118 | } |
1119 | 1119 | } |
@@ -1125,55 +1125,55 @@ discard block |
||
1125 | 1125 | } |
1126 | 1126 | } |
1127 | 1127 | |
1128 | - public static function check_vat( $vat_number, $country_code = '' ) { |
|
1128 | + public static function check_vat($vat_number, $country_code = '') { |
|
1129 | 1129 | $vat_name = self::get_vat_name(); |
1130 | 1130 | |
1131 | 1131 | $return = array(); |
1132 | 1132 | $return['valid'] = false; |
1133 | - $return['message'] = wp_sprintf( __( '%s number not validated', 'invoicing' ), $vat_name ); |
|
1133 | + $return['message'] = wp_sprintf(__('%s number not validated', 'invoicing'), $vat_name); |
|
1134 | 1134 | |
1135 | - if ( !wpinv_get_option( 'vat_offline_check' ) && !self::offline_check( $vat_number, $country_code ) ) { |
|
1135 | + if (!wpinv_get_option('vat_offline_check') && !self::offline_check($vat_number, $country_code)) { |
|
1136 | 1136 | return $return; |
1137 | 1137 | } |
1138 | 1138 | |
1139 | - $response = self::vies_check( $vat_number, $country_code ); |
|
1139 | + $response = self::vies_check($vat_number, $country_code); |
|
1140 | 1140 | |
1141 | - if ( $response ) { |
|
1142 | - $return['valid'] = true; |
|
1141 | + if ($response) { |
|
1142 | + $return['valid'] = true; |
|
1143 | 1143 | |
1144 | - if ( is_array( $response ) ) { |
|
1145 | - $return['company'] = isset( $response['company'] ) ? $response['company'] : ''; |
|
1146 | - $return['address'] = isset( $response['address'] ) ? $response['address'] : ''; |
|
1144 | + if (is_array($response)) { |
|
1145 | + $return['company'] = isset($response['company']) ? $response['company'] : ''; |
|
1146 | + $return['address'] = isset($response['address']) ? $response['address'] : ''; |
|
1147 | 1147 | $return['message'] = $return['company'] . '<br/>' . $return['address']; |
1148 | 1148 | } |
1149 | 1149 | } else { |
1150 | 1150 | $return['valid'] = false; |
1151 | - $return['message'] = wp_sprintf( __( 'Fail to validate the %s number: EU Commission VAT server (VIES) check fails.', 'invoicing' ), $vat_name ); |
|
1151 | + $return['message'] = wp_sprintf(__('Fail to validate the %s number: EU Commission VAT server (VIES) check fails.', 'invoicing'), $vat_name); |
|
1152 | 1152 | } |
1153 | 1153 | |
1154 | 1154 | return $return; |
1155 | 1155 | } |
1156 | 1156 | |
1157 | - public static function request_euvatrates( $group ) { |
|
1157 | + public static function request_euvatrates($group) { |
|
1158 | 1158 | $response = array(); |
1159 | 1159 | $response['success'] = false; |
1160 | 1160 | $response['error'] = null; |
1161 | 1161 | $response['eurates'] = null; |
1162 | 1162 | |
1163 | 1163 | $euvatrates_url = 'https://euvatrates.com/rates.json'; |
1164 | - $euvatrates_url = apply_filters( 'wpinv_euvatrates_url', $euvatrates_url ); |
|
1165 | - $api_response = wp_remote_get( $euvatrates_url ); |
|
1164 | + $euvatrates_url = apply_filters('wpinv_euvatrates_url', $euvatrates_url); |
|
1165 | + $api_response = wp_remote_get($euvatrates_url); |
|
1166 | 1166 | |
1167 | 1167 | try { |
1168 | - if ( is_wp_error( $api_response ) ) { |
|
1169 | - $response['error'] = __( $api_response->get_error_message(), 'invoicing' ); |
|
1168 | + if (is_wp_error($api_response)) { |
|
1169 | + $response['error'] = __($api_response->get_error_message(), 'invoicing'); |
|
1170 | 1170 | } else { |
1171 | - $body = json_decode( $api_response['body'] ); |
|
1171 | + $body = json_decode($api_response['body']); |
|
1172 | 1172 | |
1173 | - if ( isset( $body->rates ) ) { |
|
1173 | + if (isset($body->rates)) { |
|
1174 | 1174 | $rates = array(); |
1175 | 1175 | |
1176 | - foreach ( $body->rates as $country_code => $rate ) { |
|
1176 | + foreach ($body->rates as $country_code => $rate) { |
|
1177 | 1177 | $vat_rate = array(); |
1178 | 1178 | $vat_rate['country'] = $rate->country; |
1179 | 1179 | $vat_rate['standard'] = (float)$rate->standard_rate; |
@@ -1181,7 +1181,7 @@ discard block |
||
1181 | 1181 | $vat_rate['superreduced'] = (float)$rate->super_reduced_rate; |
1182 | 1182 | $vat_rate['parking'] = (float)$rate->parking_rate; |
1183 | 1183 | |
1184 | - if ( $group !== '' && in_array( $group, array( 'standard', 'reduced', 'superreduced', 'parking' ) ) ) { |
|
1184 | + if ($group !== '' && in_array($group, array('standard', 'reduced', 'superreduced', 'parking'))) { |
|
1185 | 1185 | $vat_rate_group = array(); |
1186 | 1186 | $vat_rate_group['country'] = $rate->country; |
1187 | 1187 | $vat_rate_group[$group] = $vat_rate[$group]; |
@@ -1193,79 +1193,79 @@ discard block |
||
1193 | 1193 | } |
1194 | 1194 | |
1195 | 1195 | $response['success'] = true; |
1196 | - $response['rates'] = apply_filters( 'wpinv_process_euvatrates', $rates, $api_response, $group ); |
|
1196 | + $response['rates'] = apply_filters('wpinv_process_euvatrates', $rates, $api_response, $group); |
|
1197 | 1197 | } else { |
1198 | - $response['error'] = __( 'No EU rates found!', 'invoicing' ); |
|
1198 | + $response['error'] = __('No EU rates found!', 'invoicing'); |
|
1199 | 1199 | } |
1200 | 1200 | } |
1201 | - } catch ( Exception $e ) { |
|
1202 | - $response['error'] = __( $e->getMessage(), 'invoicing' ); |
|
1201 | + } catch (Exception $e) { |
|
1202 | + $response['error'] = __($e->getMessage(), 'invoicing'); |
|
1203 | 1203 | } |
1204 | 1204 | |
1205 | - return apply_filters( 'wpinv_response_euvatrates', $response, $group ); |
|
1205 | + return apply_filters('wpinv_response_euvatrates', $response, $group); |
|
1206 | 1206 | } |
1207 | 1207 | |
1208 | - public static function requires_vat( $requires_vat = false, $user_id = 0, $is_digital = null ) { |
|
1208 | + public static function requires_vat($requires_vat = false, $user_id = 0, $is_digital = null) { |
|
1209 | 1209 | global $wpi_item_id, $wpi_country; |
1210 | 1210 | |
1211 | - if ( !empty( $_POST['wpinv_country'] ) ) { |
|
1212 | - $country_code = trim( $_POST['wpinv_country'] ); |
|
1213 | - } else if ( !empty( $_POST['country'] ) ) { |
|
1214 | - $country_code = trim( $_POST['country'] ); |
|
1215 | - } else if ( !empty( $wpi_country ) ) { |
|
1211 | + if (!empty($_POST['wpinv_country'])) { |
|
1212 | + $country_code = trim($_POST['wpinv_country']); |
|
1213 | + } else if (!empty($_POST['country'])) { |
|
1214 | + $country_code = trim($_POST['country']); |
|
1215 | + } else if (!empty($wpi_country)) { |
|
1216 | 1216 | $country_code = $wpi_country; |
1217 | 1217 | } else { |
1218 | - $country_code = self::get_user_country( '', $user_id ); |
|
1218 | + $country_code = self::get_user_country('', $user_id); |
|
1219 | 1219 | } |
1220 | 1220 | |
1221 | - if ( $is_digital === null && $wpi_item_id ) { |
|
1222 | - $is_digital = $wpi_item_id ? self::item_has_digital_rule( $wpi_item_id ) : self::allow_vat_rules(); |
|
1221 | + if ($is_digital === null && $wpi_item_id) { |
|
1222 | + $is_digital = $wpi_item_id ? self::item_has_digital_rule($wpi_item_id) : self::allow_vat_rules(); |
|
1223 | 1223 | } |
1224 | 1224 | |
1225 | - if ( !empty( $country_code ) ) { |
|
1226 | - $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 ) ); |
|
1225 | + if (!empty($country_code)) { |
|
1226 | + $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)); |
|
1227 | 1227 | } |
1228 | 1228 | |
1229 | - return apply_filters( 'wpinv_requires_vat', $requires_vat, $user_id ); |
|
1229 | + return apply_filters('wpinv_requires_vat', $requires_vat, $user_id); |
|
1230 | 1230 | } |
1231 | 1231 | |
1232 | - public static function tax_label( $label = '' ) { |
|
1232 | + public static function tax_label($label = '') { |
|
1233 | 1233 | global $wpi_requires_vat; |
1234 | 1234 | |
1235 | - if ( !( $wpi_requires_vat !== 0 && $wpi_requires_vat ) ) { |
|
1236 | - $wpi_requires_vat = self::requires_vat( 0, false ); |
|
1235 | + if (!($wpi_requires_vat !== 0 && $wpi_requires_vat)) { |
|
1236 | + $wpi_requires_vat = self::requires_vat(0, false); |
|
1237 | 1237 | } |
1238 | 1238 | |
1239 | - return $wpi_requires_vat ? __( self::get_vat_name(), 'invoicing' ) : ( $label ? $label : __( 'Tax', 'invoicing' ) ); |
|
1239 | + return $wpi_requires_vat ? __(self::get_vat_name(), 'invoicing') : ($label ? $label : __('Tax', 'invoicing')); |
|
1240 | 1240 | } |
1241 | 1241 | |
1242 | 1242 | public static function standard_rates_label() { |
1243 | - return __( 'Standard Rates', 'invoicing' ); |
|
1243 | + return __('Standard Rates', 'invoicing'); |
|
1244 | 1244 | } |
1245 | 1245 | |
1246 | - public static function get_rate_classes( $with_desc = false ) { |
|
1247 | - $rate_classes_option = get_option( '_wpinv_vat_rate_classes', true ); |
|
1248 | - $classes = maybe_unserialize( $rate_classes_option ); |
|
1246 | + public static function get_rate_classes($with_desc = false) { |
|
1247 | + $rate_classes_option = get_option('_wpinv_vat_rate_classes', true); |
|
1248 | + $classes = maybe_unserialize($rate_classes_option); |
|
1249 | 1249 | |
1250 | - if ( empty( $classes ) || !is_array( $classes ) ) { |
|
1250 | + if (empty($classes) || !is_array($classes)) { |
|
1251 | 1251 | $classes = array(); |
1252 | 1252 | } |
1253 | 1253 | |
1254 | 1254 | $rate_classes = array(); |
1255 | - if ( !array_key_exists( '_standard', $classes ) ) { |
|
1256 | - if ( $with_desc ) { |
|
1257 | - $rate_classes['_standard'] = array( 'name' => self::standard_rates_label(), 'desc' => __( 'EU member states standard VAT rates', 'invoicing' ) ); |
|
1255 | + if (!array_key_exists('_standard', $classes)) { |
|
1256 | + if ($with_desc) { |
|
1257 | + $rate_classes['_standard'] = array('name' => self::standard_rates_label(), 'desc' => __('EU member states standard VAT rates', 'invoicing')); |
|
1258 | 1258 | } else { |
1259 | 1259 | $rate_classes['_standard'] = self::standard_rates_label(); |
1260 | 1260 | } |
1261 | 1261 | } |
1262 | 1262 | |
1263 | - foreach ( $classes as $key => $class ) { |
|
1264 | - $name = !empty( $class['name'] ) ? __( $class['name'], 'invoicing' ) : $key; |
|
1265 | - $desc = !empty( $class['desc'] ) ? __( $class['desc'], 'invoicing' ) : ''; |
|
1263 | + foreach ($classes as $key => $class) { |
|
1264 | + $name = !empty($class['name']) ? __($class['name'], 'invoicing') : $key; |
|
1265 | + $desc = !empty($class['desc']) ? __($class['desc'], 'invoicing') : ''; |
|
1266 | 1266 | |
1267 | - if ( $with_desc ) { |
|
1268 | - $rate_classes[$key] = array( 'name' => $name, 'desc' => $desc ); |
|
1267 | + if ($with_desc) { |
|
1268 | + $rate_classes[$key] = array('name' => $name, 'desc' => $desc); |
|
1269 | 1269 | } else { |
1270 | 1270 | $rate_classes[$key] = $name; |
1271 | 1271 | } |
@@ -1276,15 +1276,15 @@ discard block |
||
1276 | 1276 | |
1277 | 1277 | public static function get_all_classes() { |
1278 | 1278 | $classes = self::get_rate_classes(); |
1279 | - $classes['_exempt'] = __( 'Exempt (0%)', 'invoicing' ); |
|
1279 | + $classes['_exempt'] = __('Exempt (0%)', 'invoicing'); |
|
1280 | 1280 | |
1281 | - return apply_filters( 'wpinv_vat_get_all_classes', $classes ); |
|
1281 | + return apply_filters('wpinv_vat_get_all_classes', $classes); |
|
1282 | 1282 | } |
1283 | 1283 | |
1284 | - public static function get_class_desc( $rate_class ) { |
|
1285 | - $rate_classes = self::get_rate_classes( true ); |
|
1284 | + public static function get_class_desc($rate_class) { |
|
1285 | + $rate_classes = self::get_rate_classes(true); |
|
1286 | 1286 | |
1287 | - if ( !empty( $rate_classes ) && isset( $rate_classes[$rate_class] ) && isset( $rate_classes[$rate_class]['desc'] ) ) { |
|
1287 | + if (!empty($rate_classes) && isset($rate_classes[$rate_class]) && isset($rate_classes[$rate_class]['desc'])) { |
|
1288 | 1288 | return $rate_classes[$rate_class]['desc']; |
1289 | 1289 | } |
1290 | 1290 | |
@@ -1300,106 +1300,106 @@ discard block |
||
1300 | 1300 | 'increased' => 'Increased' |
1301 | 1301 | ); |
1302 | 1302 | |
1303 | - return apply_filters( 'wpinv_get_vat_groups', $vat_groups ); |
|
1303 | + return apply_filters('wpinv_get_vat_groups', $vat_groups); |
|
1304 | 1304 | } |
1305 | 1305 | |
1306 | 1306 | public static function get_rules() { |
1307 | 1307 | $vat_rules = array( |
1308 | - 'digital' => __( 'Digital Product', 'invoicing' ), |
|
1309 | - 'physical' => __( 'Physical Product', 'invoicing' ) |
|
1308 | + 'digital' => __('Digital Product', 'invoicing'), |
|
1309 | + 'physical' => __('Physical Product', 'invoicing') |
|
1310 | 1310 | ); |
1311 | - return apply_filters( 'wpinv_get_vat_rules', $vat_rules ); |
|
1311 | + return apply_filters('wpinv_get_vat_rules', $vat_rules); |
|
1312 | 1312 | } |
1313 | 1313 | |
1314 | - public static function get_vat_rates( $class ) { |
|
1315 | - if ( $class === '_standard' ) { |
|
1314 | + public static function get_vat_rates($class) { |
|
1315 | + if ($class === '_standard') { |
|
1316 | 1316 | return wpinv_get_tax_rates(); |
1317 | 1317 | } |
1318 | 1318 | |
1319 | 1319 | $rates = self::get_non_standard_rates(); |
1320 | 1320 | |
1321 | - return array_key_exists( $class, $rates ) ? $rates[$class] : array(); |
|
1321 | + return array_key_exists($class, $rates) ? $rates[$class] : array(); |
|
1322 | 1322 | } |
1323 | 1323 | |
1324 | 1324 | public static function get_non_standard_rates() { |
1325 | - $option = get_option( 'wpinv_vat_rates', array()); |
|
1326 | - return is_array( $option ) ? $option : array(); |
|
1325 | + $option = get_option('wpinv_vat_rates', array()); |
|
1326 | + return is_array($option) ? $option : array(); |
|
1327 | 1327 | } |
1328 | 1328 | |
1329 | 1329 | public static function allow_vat_rules() { |
1330 | - return ( wpinv_use_taxes() && wpinv_get_option( 'apply_vat_rules' ) ? true : false ); |
|
1330 | + return (wpinv_use_taxes() && wpinv_get_option('apply_vat_rules') ? true : false); |
|
1331 | 1331 | } |
1332 | 1332 | |
1333 | 1333 | public static function allow_vat_classes() { |
1334 | 1334 | return false; // TODO |
1335 | - return ( wpinv_get_option( 'vat_allow_classes' ) ? true : false ); |
|
1335 | + return (wpinv_get_option('vat_allow_classes') ? true : false); |
|
1336 | 1336 | } |
1337 | 1337 | |
1338 | - public static function get_item_class( $postID ) { |
|
1339 | - $class = get_post_meta( $postID, '_wpinv_vat_class', true ); |
|
1338 | + public static function get_item_class($postID) { |
|
1339 | + $class = get_post_meta($postID, '_wpinv_vat_class', true); |
|
1340 | 1340 | |
1341 | - if ( empty( $class ) ) { |
|
1341 | + if (empty($class)) { |
|
1342 | 1342 | $class = '_standard'; |
1343 | 1343 | } |
1344 | 1344 | |
1345 | - return apply_filters( 'wpinv_get_item_vat_class', $class, $postID ); |
|
1345 | + return apply_filters('wpinv_get_item_vat_class', $class, $postID); |
|
1346 | 1346 | } |
1347 | 1347 | |
1348 | - public static function item_class_label( $postID ) { |
|
1348 | + public static function item_class_label($postID) { |
|
1349 | 1349 | $vat_classes = self::get_all_classes(); |
1350 | 1350 | |
1351 | - $class = self::get_item_class( $postID ); |
|
1352 | - $class = isset( $vat_classes[$class] ) ? $vat_classes[$class] : __( $class, 'invoicing' ); |
|
1351 | + $class = self::get_item_class($postID); |
|
1352 | + $class = isset($vat_classes[$class]) ? $vat_classes[$class] : __($class, 'invoicing'); |
|
1353 | 1353 | |
1354 | - return apply_filters( 'wpinv_item_class_label', $class, $postID ); |
|
1354 | + return apply_filters('wpinv_item_class_label', $class, $postID); |
|
1355 | 1355 | } |
1356 | 1356 | |
1357 | - public static function get_item_rule( $postID ) { |
|
1358 | - $rule_type = get_post_meta( $postID, '_wpinv_vat_rule', true ); |
|
1357 | + public static function get_item_rule($postID) { |
|
1358 | + $rule_type = get_post_meta($postID, '_wpinv_vat_rule', true); |
|
1359 | 1359 | |
1360 | - if ( empty( $rule_type ) ) { |
|
1360 | + if (empty($rule_type)) { |
|
1361 | 1361 | $rule_type = self::allow_vat_rules() ? 'digital' : 'physical'; |
1362 | 1362 | } |
1363 | 1363 | |
1364 | - return apply_filters( 'wpinv_item_get_vat_rule', $rule_type, $postID ); |
|
1364 | + return apply_filters('wpinv_item_get_vat_rule', $rule_type, $postID); |
|
1365 | 1365 | } |
1366 | 1366 | |
1367 | - public static function item_rule_label( $postID ) { |
|
1367 | + public static function item_rule_label($postID) { |
|
1368 | 1368 | $vat_rules = self::get_rules(); |
1369 | - $vat_rule = self::get_item_rule( $postID ); |
|
1370 | - $vat_rule = isset( $vat_rules[$vat_rule] ) ? $vat_rules[$vat_rule] : $vat_rule; |
|
1369 | + $vat_rule = self::get_item_rule($postID); |
|
1370 | + $vat_rule = isset($vat_rules[$vat_rule]) ? $vat_rules[$vat_rule] : $vat_rule; |
|
1371 | 1371 | |
1372 | - return apply_filters( 'wpinv_item_rule_label', $vat_rule, $postID ); |
|
1372 | + return apply_filters('wpinv_item_rule_label', $vat_rule, $postID); |
|
1373 | 1373 | } |
1374 | 1374 | |
1375 | - public static function item_has_digital_rule( $item_id = 0 ) { |
|
1376 | - return self::get_item_rule( $item_id ) == 'digital' ? true : false; |
|
1375 | + public static function item_has_digital_rule($item_id = 0) { |
|
1376 | + return self::get_item_rule($item_id) == 'digital' ? true : false; |
|
1377 | 1377 | } |
1378 | 1378 | |
1379 | - public static function invoice_has_digital_rule( $invoice = 0 ) { |
|
1380 | - if ( !self::allow_vat_rules() ) { |
|
1379 | + public static function invoice_has_digital_rule($invoice = 0) { |
|
1380 | + if (!self::allow_vat_rules()) { |
|
1381 | 1381 | return false; |
1382 | 1382 | } |
1383 | 1383 | |
1384 | - if ( empty( $invoice ) ) { |
|
1384 | + if (empty($invoice)) { |
|
1385 | 1385 | return true; |
1386 | 1386 | } |
1387 | 1387 | |
1388 | - if ( is_int( $invoice ) ) { |
|
1389 | - $invoice = new WPInv_Invoice( $invoice ); |
|
1388 | + if (is_int($invoice)) { |
|
1389 | + $invoice = new WPInv_Invoice($invoice); |
|
1390 | 1390 | } |
1391 | 1391 | |
1392 | - if ( !( is_object( $invoice ) && is_a( $invoice, 'WPInv_Invoice' ) ) ) { |
|
1392 | + if (!(is_object($invoice) && is_a($invoice, 'WPInv_Invoice'))) { |
|
1393 | 1393 | return true; |
1394 | 1394 | } |
1395 | 1395 | |
1396 | - $cart_items = $invoice->get_cart_details(); |
|
1396 | + $cart_items = $invoice->get_cart_details(); |
|
1397 | 1397 | |
1398 | - if ( !empty( $cart_items ) ) { |
|
1398 | + if (!empty($cart_items)) { |
|
1399 | 1399 | $has_digital_rule = false; |
1400 | 1400 | |
1401 | - foreach ( $cart_items as $key => $item ) { |
|
1402 | - if ( self::item_has_digital_rule( $item['id'] ) ) { |
|
1401 | + foreach ($cart_items as $key => $item) { |
|
1402 | + if (self::item_has_digital_rule($item['id'])) { |
|
1403 | 1403 | $has_digital_rule = true; |
1404 | 1404 | break; |
1405 | 1405 | } |
@@ -1411,67 +1411,67 @@ discard block |
||
1411 | 1411 | return $has_digital_rule; |
1412 | 1412 | } |
1413 | 1413 | |
1414 | - public static function item_is_taxable( $item_id = 0, $country = false, $state = false ) { |
|
1415 | - if ( !wpinv_use_taxes() ) { |
|
1414 | + public static function item_is_taxable($item_id = 0, $country = false, $state = false) { |
|
1415 | + if (!wpinv_use_taxes()) { |
|
1416 | 1416 | return false; |
1417 | 1417 | } |
1418 | 1418 | |
1419 | 1419 | $is_taxable = true; |
1420 | 1420 | |
1421 | - if ( !empty( $item_id ) && self::get_item_class( $item_id ) == '_exempt' ) { |
|
1421 | + if (!empty($item_id) && self::get_item_class($item_id) == '_exempt') { |
|
1422 | 1422 | $is_taxable = false; |
1423 | 1423 | } |
1424 | 1424 | |
1425 | - return apply_filters( 'wpinv_item_is_taxable', $is_taxable, $item_id, $country , $state ); |
|
1425 | + return apply_filters('wpinv_item_is_taxable', $is_taxable, $item_id, $country, $state); |
|
1426 | 1426 | } |
1427 | 1427 | |
1428 | - public static function find_rate( $country, $state, $rate, $class ) { |
|
1428 | + public static function find_rate($country, $state, $rate, $class) { |
|
1429 | 1429 | global $wpi_zero_tax; |
1430 | 1430 | |
1431 | - if ( $class === '_exempt' || $wpi_zero_tax ) { |
|
1431 | + if ($class === '_exempt' || $wpi_zero_tax) { |
|
1432 | 1432 | return 0; |
1433 | 1433 | } |
1434 | 1434 | |
1435 | - $tax_rates = wpinv_get_tax_rates(); |
|
1435 | + $tax_rates = wpinv_get_tax_rates(); |
|
1436 | 1436 | |
1437 | - if ( $class !== '_standard' ) { |
|
1438 | - $class_rates = self::get_vat_rates( $class ); |
|
1437 | + if ($class !== '_standard') { |
|
1438 | + $class_rates = self::get_vat_rates($class); |
|
1439 | 1439 | |
1440 | - if ( is_array( $class_rates ) ) { |
|
1440 | + if (is_array($class_rates)) { |
|
1441 | 1441 | $indexed_class_rates = array(); |
1442 | 1442 | |
1443 | - foreach ( $class_rates as $key => $cr ) { |
|
1443 | + foreach ($class_rates as $key => $cr) { |
|
1444 | 1444 | $indexed_class_rates[$cr['country']] = $cr; |
1445 | 1445 | } |
1446 | 1446 | |
1447 | - $tax_rates = array_map( function( $tr ) use( $indexed_class_rates ) { |
|
1447 | + $tax_rates = array_map(function($tr) use($indexed_class_rates) { |
|
1448 | 1448 | $tr_country = $tr['country']; |
1449 | - if ( !isset( $indexed_class_rates[$tr_country] ) ) { |
|
1449 | + if (!isset($indexed_class_rates[$tr_country])) { |
|
1450 | 1450 | return $tr; |
1451 | 1451 | } |
1452 | 1452 | $icr = $indexed_class_rates[$tr_country]; |
1453 | - return ( empty( $icr['rate'] ) && $icr['rate'] !== '0' ) ? $tr : $icr; |
|
1453 | + return (empty($icr['rate']) && $icr['rate'] !== '0') ? $tr : $icr; |
|
1454 | 1454 | |
1455 | - }, $tax_rates, $class_rates ); |
|
1455 | + }, $tax_rates, $class_rates); |
|
1456 | 1456 | } |
1457 | 1457 | } |
1458 | 1458 | |
1459 | - if ( !empty( $tax_rates ) ) { |
|
1460 | - foreach ( $tax_rates as $key => $tax_rate ) { |
|
1461 | - if ( $country != $tax_rate['country'] ) |
|
1459 | + if (!empty($tax_rates)) { |
|
1460 | + foreach ($tax_rates as $key => $tax_rate) { |
|
1461 | + if ($country != $tax_rate['country']) |
|
1462 | 1462 | continue; |
1463 | 1463 | |
1464 | - if ( !empty( $tax_rate['global'] ) ) { |
|
1465 | - if ( 0 !== $tax_rate['rate'] || !empty( $tax_rate['rate'] ) ) { |
|
1466 | - $rate = number_format( $tax_rate['rate'], 4 ); |
|
1464 | + if (!empty($tax_rate['global'])) { |
|
1465 | + if (0 !== $tax_rate['rate'] || !empty($tax_rate['rate'])) { |
|
1466 | + $rate = number_format($tax_rate['rate'], 4); |
|
1467 | 1467 | } |
1468 | 1468 | } else { |
1469 | - if ( empty( $tax_rate['state'] ) || strtolower( $state ) != strtolower( $tax_rate['state'] ) ) |
|
1469 | + if (empty($tax_rate['state']) || strtolower($state) != strtolower($tax_rate['state'])) |
|
1470 | 1470 | continue; |
1471 | 1471 | |
1472 | 1472 | $state_rate = $tax_rate['rate']; |
1473 | - if ( 0 !== $state_rate || !empty( $state_rate ) ) { |
|
1474 | - $rate = number_format( $state_rate, 4 ); |
|
1473 | + if (0 !== $state_rate || !empty($state_rate)) { |
|
1474 | + $rate = number_format($state_rate, 4); |
|
1475 | 1475 | } |
1476 | 1476 | } |
1477 | 1477 | } |
@@ -1480,84 +1480,84 @@ discard block |
||
1480 | 1480 | return $rate; |
1481 | 1481 | } |
1482 | 1482 | |
1483 | - public static function get_rate( $rate = 1, $country = '', $state = '', $item_id = 0 ) { |
|
1483 | + public static function get_rate($rate = 1, $country = '', $state = '', $item_id = 0) { |
|
1484 | 1484 | global $wpinv_options, $wpi_session, $wpi_item_id, $wpi_zero_tax; |
1485 | 1485 | |
1486 | 1486 | $item_id = $item_id > 0 ? $item_id : $wpi_item_id; |
1487 | 1487 | $allow_vat_classes = self::allow_vat_classes(); |
1488 | - $class = $item_id ? self::get_item_class( $item_id ) : '_standard'; |
|
1488 | + $class = $item_id ? self::get_item_class($item_id) : '_standard'; |
|
1489 | 1489 | |
1490 | - if ( $class === '_exempt' || $wpi_zero_tax ) { |
|
1490 | + if ($class === '_exempt' || $wpi_zero_tax) { |
|
1491 | 1491 | return 0; |
1492 | - } else if ( !$allow_vat_classes ) { |
|
1492 | + } else if (!$allow_vat_classes) { |
|
1493 | 1493 | $class = '_standard'; |
1494 | 1494 | } |
1495 | 1495 | |
1496 | - if( !empty( $_POST['wpinv_country'] ) ) { |
|
1496 | + if (!empty($_POST['wpinv_country'])) { |
|
1497 | 1497 | $post_country = $_POST['wpinv_country']; |
1498 | - } elseif( !empty( $_POST['wpinv_country'] ) ) { |
|
1498 | + } elseif (!empty($_POST['wpinv_country'])) { |
|
1499 | 1499 | $post_country = $_POST['wpinv_country']; |
1500 | - } elseif( !empty( $_POST['country'] ) ) { |
|
1500 | + } elseif (!empty($_POST['country'])) { |
|
1501 | 1501 | $post_country = $_POST['country']; |
1502 | 1502 | } else { |
1503 | 1503 | $post_country = ''; |
1504 | 1504 | } |
1505 | 1505 | |
1506 | - $country = !empty( $post_country ) ? $post_country : wpinv_default_billing_country( $country ); |
|
1507 | - $base_country = wpinv_is_base_country( $country ); |
|
1506 | + $country = !empty($post_country) ? $post_country : wpinv_default_billing_country($country); |
|
1507 | + $base_country = wpinv_is_base_country($country); |
|
1508 | 1508 | |
1509 | - $requires_vat = self::requires_vat( 0, false ); |
|
1510 | - $is_digital = self::get_item_rule( $item_id ) == 'digital' ; |
|
1511 | - $rate = $requires_vat && isset( $wpinv_options['eu_fallback_rate'] ) ? $wpinv_options['eu_fallback_rate'] : $rate; |
|
1509 | + $requires_vat = self::requires_vat(0, false); |
|
1510 | + $is_digital = self::get_item_rule($item_id) == 'digital'; |
|
1511 | + $rate = $requires_vat && isset($wpinv_options['eu_fallback_rate']) ? $wpinv_options['eu_fallback_rate'] : $rate; |
|
1512 | 1512 | |
1513 | - if ( self::same_country_rule() == 'no' && $base_country ) { // Disable VAT to same country |
|
1513 | + if (self::same_country_rule() == 'no' && $base_country) { // Disable VAT to same country |
|
1514 | 1514 | $rate = 0; |
1515 | - } else if ( $requires_vat ) { |
|
1516 | - $vat_number = self::get_user_vat_number( '', 0, true ); |
|
1515 | + } else if ($requires_vat) { |
|
1516 | + $vat_number = self::get_user_vat_number('', 0, true); |
|
1517 | 1517 | $vat_info = self::current_vat_data(); |
1518 | 1518 | |
1519 | - if ( is_array( $vat_info ) ) { |
|
1520 | - $vat_number = isset( $vat_info['number'] ) && !empty( $vat_info['valid'] ) ? $vat_info['number'] : ""; |
|
1519 | + if (is_array($vat_info)) { |
|
1520 | + $vat_number = isset($vat_info['number']) && !empty($vat_info['valid']) ? $vat_info['number'] : ""; |
|
1521 | 1521 | } |
1522 | 1522 | |
1523 | - if ( $country == 'UK' ) { |
|
1523 | + if ($country == 'UK') { |
|
1524 | 1524 | $country = 'GB'; |
1525 | 1525 | } |
1526 | 1526 | |
1527 | - if ( !empty( $vat_number ) ) { |
|
1527 | + if (!empty($vat_number)) { |
|
1528 | 1528 | $rate = 0; |
1529 | 1529 | } else { |
1530 | - $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 |
|
1530 | + $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 |
|
1531 | 1531 | } |
1532 | 1532 | |
1533 | - if ( empty( $vat_number ) && !$is_digital ) { |
|
1534 | - if ( $base_country ) { |
|
1535 | - $rate = self::find_rate( $country, null, $rate, $class ); |
|
1533 | + if (empty($vat_number) && !$is_digital) { |
|
1534 | + if ($base_country) { |
|
1535 | + $rate = self::find_rate($country, null, $rate, $class); |
|
1536 | 1536 | } else { |
1537 | - if ( empty( $country ) && isset( $wpinv_options['eu_fallback_rate'] ) ) { |
|
1537 | + if (empty($country) && isset($wpinv_options['eu_fallback_rate'])) { |
|
1538 | 1538 | $rate = $wpinv_options['eu_fallback_rate']; |
1539 | - } else if( !empty( $country ) ) { |
|
1540 | - $rate = self::find_rate( $country, $state, $rate, $class ); |
|
1539 | + } else if (!empty($country)) { |
|
1540 | + $rate = self::find_rate($country, $state, $rate, $class); |
|
1541 | 1541 | } |
1542 | 1542 | } |
1543 | - } else if ( empty( $vat_number ) || ( self::same_country_rule() == 'always' && $base_country ) ) { |
|
1544 | - if ( empty( $country ) && isset( $wpinv_options['eu_fallback_rate'] ) ) { |
|
1543 | + } else if (empty($vat_number) || (self::same_country_rule() == 'always' && $base_country)) { |
|
1544 | + if (empty($country) && isset($wpinv_options['eu_fallback_rate'])) { |
|
1545 | 1545 | $rate = $wpinv_options['eu_fallback_rate']; |
1546 | - } else if( !empty( $country ) ) { |
|
1547 | - $rate = self::find_rate( $country, $state, $rate, $class ); |
|
1546 | + } else if (!empty($country)) { |
|
1547 | + $rate = self::find_rate($country, $state, $rate, $class); |
|
1548 | 1548 | } |
1549 | 1549 | } |
1550 | 1550 | } else { |
1551 | - if ( $is_digital ) { |
|
1551 | + if ($is_digital) { |
|
1552 | 1552 | $ip_country_code = self::get_country_by_ip(); |
1553 | 1553 | |
1554 | - if ( $ip_country_code && self::is_eu_state( $ip_country_code ) ) { |
|
1555 | - $rate = self::find_rate( $ip_country_code, '', 0, $class ); |
|
1554 | + if ($ip_country_code && self::is_eu_state($ip_country_code)) { |
|
1555 | + $rate = self::find_rate($ip_country_code, '', 0, $class); |
|
1556 | 1556 | } else { |
1557 | - $rate = self::find_rate( $country, $state, $rate, $class ); |
|
1557 | + $rate = self::find_rate($country, $state, $rate, $class); |
|
1558 | 1558 | } |
1559 | 1559 | } else { |
1560 | - $rate = self::find_rate( $country, $state, $rate, $class ); |
|
1560 | + $rate = self::find_rate($country, $state, $rate, $class); |
|
1561 | 1561 | } |
1562 | 1562 | } |
1563 | 1563 | |
@@ -1567,48 +1567,48 @@ discard block |
||
1567 | 1567 | public static function current_vat_data() { |
1568 | 1568 | global $wpi_session; |
1569 | 1569 | |
1570 | - return $wpi_session->get( 'user_vat_data' ); |
|
1570 | + return $wpi_session->get('user_vat_data'); |
|
1571 | 1571 | } |
1572 | 1572 | |
1573 | - public static function get_user_country( $country = '', $user_id = 0 ) { |
|
1574 | - $user_address = wpinv_get_user_address( $user_id, false ); |
|
1573 | + public static function get_user_country($country = '', $user_id = 0) { |
|
1574 | + $user_address = wpinv_get_user_address($user_id, false); |
|
1575 | 1575 | |
1576 | - if ( wpinv_get_option( 'vat_ip_country_default' ) ) { |
|
1576 | + if (wpinv_get_option('vat_ip_country_default')) { |
|
1577 | 1577 | $country = ''; |
1578 | 1578 | } |
1579 | 1579 | |
1580 | - $country = empty( $user_address ) || !isset( $user_address['country'] ) || empty( $user_address['country'] ) ? $country : $user_address['country']; |
|
1581 | - $result = apply_filters( 'wpinv_get_user_country', $country, $user_id ); |
|
1580 | + $country = empty($user_address) || !isset($user_address['country']) || empty($user_address['country']) ? $country : $user_address['country']; |
|
1581 | + $result = apply_filters('wpinv_get_user_country', $country, $user_id); |
|
1582 | 1582 | |
1583 | - if ( empty( $result ) ) { |
|
1583 | + if (empty($result)) { |
|
1584 | 1584 | $result = self::get_country_by_ip(); |
1585 | 1585 | } |
1586 | 1586 | |
1587 | 1587 | return $result; |
1588 | 1588 | } |
1589 | 1589 | |
1590 | - public static function set_user_country( $country = '', $user_id = 0 ) { |
|
1590 | + public static function set_user_country($country = '', $user_id = 0) { |
|
1591 | 1591 | global $wpi_userID; |
1592 | 1592 | |
1593 | - if ( empty($country) && !empty($wpi_userID) && get_current_user_id() != $wpi_userID ) { |
|
1593 | + if (empty($country) && !empty($wpi_userID) && get_current_user_id() != $wpi_userID) { |
|
1594 | 1594 | $country = wpinv_get_default_country(); |
1595 | 1595 | } |
1596 | 1596 | |
1597 | 1597 | return $country; |
1598 | 1598 | } |
1599 | 1599 | |
1600 | - public static function get_user_vat_number( $vat_number = '', $user_id = 0, $is_valid = false ) { |
|
1600 | + public static function get_user_vat_number($vat_number = '', $user_id = 0, $is_valid = false) { |
|
1601 | 1601 | global $wpi_current_id, $wpi_userID; |
1602 | 1602 | |
1603 | - if ( !empty( $_POST['new_user'] ) ) { |
|
1603 | + if (!empty($_POST['new_user'])) { |
|
1604 | 1604 | return ''; |
1605 | 1605 | } |
1606 | 1606 | |
1607 | - if ( empty( $user_id ) ) { |
|
1608 | - $user_id = !empty( $wpi_userID ) ? $wpi_userID : ( $wpi_current_id ? wpinv_get_user_id( $wpi_current_id ) : get_current_user_id() ); |
|
1607 | + if (empty($user_id)) { |
|
1608 | + $user_id = !empty($wpi_userID) ? $wpi_userID : ($wpi_current_id ? wpinv_get_user_id($wpi_current_id) : get_current_user_id()); |
|
1609 | 1609 | } |
1610 | 1610 | |
1611 | - $vat_number = empty( $user_id ) ? '' : get_user_meta( $user_id, '_wpinv_vat_number', true ); |
|
1611 | + $vat_number = empty($user_id) ? '' : get_user_meta($user_id, '_wpinv_vat_number', true); |
|
1612 | 1612 | |
1613 | 1613 | /* TODO |
1614 | 1614 | if ( $is_valid && $vat_number ) { |
@@ -1619,38 +1619,38 @@ discard block |
||
1619 | 1619 | } |
1620 | 1620 | */ |
1621 | 1621 | |
1622 | - return apply_filters('wpinv_get_user_vat_number', $vat_number, $user_id, $is_valid ); |
|
1622 | + return apply_filters('wpinv_get_user_vat_number', $vat_number, $user_id, $is_valid); |
|
1623 | 1623 | } |
1624 | 1624 | |
1625 | - public static function get_user_company( $company = '', $user_id = 0 ) { |
|
1625 | + public static function get_user_company($company = '', $user_id = 0) { |
|
1626 | 1626 | global $wpi_current_id, $wpi_userID; |
1627 | 1627 | |
1628 | - if ( empty( $user_id ) ) { |
|
1629 | - $user_id = !empty( $wpi_userID ) ? $wpi_userID : ( $wpi_current_id ? wpinv_get_user_id( $wpi_current_id ) : get_current_user_id() ); |
|
1628 | + if (empty($user_id)) { |
|
1629 | + $user_id = !empty($wpi_userID) ? $wpi_userID : ($wpi_current_id ? wpinv_get_user_id($wpi_current_id) : get_current_user_id()); |
|
1630 | 1630 | } |
1631 | 1631 | |
1632 | - $company = empty( $user_id ) ? "" : get_user_meta( $user_id, '_wpinv_company', true ); |
|
1632 | + $company = empty($user_id) ? "" : get_user_meta($user_id, '_wpinv_company', true); |
|
1633 | 1633 | |
1634 | - return apply_filters( 'wpinv_user_company', $company, $user_id ); |
|
1634 | + return apply_filters('wpinv_user_company', $company, $user_id); |
|
1635 | 1635 | } |
1636 | 1636 | |
1637 | - public static function save_user_vat_details( $company = '', $vat_number = '' ) { |
|
1638 | - $save = apply_filters( 'wpinv_allow_save_user_vat_details', true ); |
|
1637 | + public static function save_user_vat_details($company = '', $vat_number = '') { |
|
1638 | + $save = apply_filters('wpinv_allow_save_user_vat_details', true); |
|
1639 | 1639 | |
1640 | - if ( is_user_logged_in() && $save ) { |
|
1640 | + if (is_user_logged_in() && $save) { |
|
1641 | 1641 | $user_id = get_current_user_id(); |
1642 | 1642 | |
1643 | - if ( !empty( $vat_number ) ) { |
|
1644 | - update_user_meta( $user_id, '_wpinv_vat_number', $vat_number ); |
|
1643 | + if (!empty($vat_number)) { |
|
1644 | + update_user_meta($user_id, '_wpinv_vat_number', $vat_number); |
|
1645 | 1645 | } else { |
1646 | - delete_user_meta( $user_id, '_wpinv_vat_number'); |
|
1646 | + delete_user_meta($user_id, '_wpinv_vat_number'); |
|
1647 | 1647 | } |
1648 | 1648 | |
1649 | - if ( !empty( $company ) ) { |
|
1650 | - update_user_meta( $user_id, '_wpinv_company', $company ); |
|
1649 | + if (!empty($company)) { |
|
1650 | + update_user_meta($user_id, '_wpinv_company', $company); |
|
1651 | 1651 | } else { |
1652 | - delete_user_meta( $user_id, '_wpinv_company'); |
|
1653 | - delete_user_meta( $user_id, '_wpinv_vat_number'); |
|
1652 | + delete_user_meta($user_id, '_wpinv_company'); |
|
1653 | + delete_user_meta($user_id, '_wpinv_vat_number'); |
|
1654 | 1654 | } |
1655 | 1655 | } |
1656 | 1656 | |
@@ -1660,113 +1660,113 @@ discard block |
||
1660 | 1660 | public static function ajax_vat_validate() { |
1661 | 1661 | global $wpinv_options, $wpi_session; |
1662 | 1662 | |
1663 | - $is_checkout = ( !empty( $_POST['source'] ) && $_POST['source'] == 'checkout' ) ? true : false; |
|
1663 | + $is_checkout = (!empty($_POST['source']) && $_POST['source'] == 'checkout') ? true : false; |
|
1664 | 1664 | $response = array(); |
1665 | 1665 | $response['success'] = false; |
1666 | 1666 | |
1667 | - if ( empty( $_REQUEST['_wpi_nonce'] ) || ( !empty( $_REQUEST['_wpi_nonce'] ) && !wp_verify_nonce( $_REQUEST['_wpi_nonce'], 'vat_validation' ) ) ) { |
|
1668 | - $response['error'] = __( 'Invalid security nonce', 'invoicing' ); |
|
1669 | - wp_send_json( $response ); |
|
1667 | + if (empty($_REQUEST['_wpi_nonce']) || (!empty($_REQUEST['_wpi_nonce']) && !wp_verify_nonce($_REQUEST['_wpi_nonce'], 'vat_validation'))) { |
|
1668 | + $response['error'] = __('Invalid security nonce', 'invoicing'); |
|
1669 | + wp_send_json($response); |
|
1670 | 1670 | } |
1671 | 1671 | |
1672 | - $vat_name = self::get_vat_name(); |
|
1672 | + $vat_name = self::get_vat_name(); |
|
1673 | 1673 | |
1674 | - if ( $is_checkout ) { |
|
1674 | + if ($is_checkout) { |
|
1675 | 1675 | $invoice = wpinv_get_invoice_cart(); |
1676 | 1676 | |
1677 | - if ( !self::requires_vat( false, 0, self::invoice_has_digital_rule( $invoice ) ) ) { |
|
1677 | + if (!self::requires_vat(false, 0, self::invoice_has_digital_rule($invoice))) { |
|
1678 | 1678 | $vat_info = array(); |
1679 | - $wpi_session->set( 'user_vat_data', $vat_info ); |
|
1679 | + $wpi_session->set('user_vat_data', $vat_info); |
|
1680 | 1680 | |
1681 | 1681 | self::save_user_vat_details(); |
1682 | 1682 | |
1683 | 1683 | $response['success'] = true; |
1684 | - $response['message'] = wp_sprintf( __( 'Ignore %s', 'invoicing' ), $vat_name ); |
|
1685 | - wp_send_json( $response ); |
|
1684 | + $response['message'] = wp_sprintf(__('Ignore %s', 'invoicing'), $vat_name); |
|
1685 | + wp_send_json($response); |
|
1686 | 1686 | } |
1687 | 1687 | } |
1688 | 1688 | |
1689 | - $company = !empty( $_POST['company'] ) ? sanitize_text_field( $_POST['company'] ) : ''; |
|
1690 | - $vat_number = !empty( $_POST['number'] ) ? sanitize_text_field( $_POST['number'] ) : ''; |
|
1689 | + $company = !empty($_POST['company']) ? sanitize_text_field($_POST['company']) : ''; |
|
1690 | + $vat_number = !empty($_POST['number']) ? sanitize_text_field($_POST['number']) : ''; |
|
1691 | 1691 | |
1692 | - $vat_info = $wpi_session->get( 'user_vat_data' ); |
|
1693 | - if ( !is_array( $vat_info ) || empty( $vat_info ) ) { |
|
1694 | - $vat_info = array( 'company'=> $company, 'number' => '', 'valid' => true ); |
|
1692 | + $vat_info = $wpi_session->get('user_vat_data'); |
|
1693 | + if (!is_array($vat_info) || empty($vat_info)) { |
|
1694 | + $vat_info = array('company'=> $company, 'number' => '', 'valid' => true); |
|
1695 | 1695 | } |
1696 | 1696 | |
1697 | - if ( empty( $vat_number ) ) { |
|
1698 | - if ( $is_checkout ) { |
|
1697 | + if (empty($vat_number)) { |
|
1698 | + if ($is_checkout) { |
|
1699 | 1699 | $response['success'] = true; |
1700 | - $response['message'] = wp_sprintf( __( 'No %s number has been applied. %s will be added to invoice totals', 'invoicing' ), $vat_name, $vat_name ); |
|
1700 | + $response['message'] = wp_sprintf(__('No %s number has been applied. %s will be added to invoice totals', 'invoicing'), $vat_name, $vat_name); |
|
1701 | 1701 | |
1702 | - $vat_info = $wpi_session->get( 'user_vat_data' ); |
|
1702 | + $vat_info = $wpi_session->get('user_vat_data'); |
|
1703 | 1703 | $vat_info['number'] = ""; |
1704 | 1704 | $vat_info['valid'] = true; |
1705 | 1705 | |
1706 | - self::save_user_vat_details( $company ); |
|
1706 | + self::save_user_vat_details($company); |
|
1707 | 1707 | } else { |
1708 | - $response['error'] = wp_sprintf( __( 'Please enter your %s number!', 'invoicing' ), $vat_name ); |
|
1708 | + $response['error'] = wp_sprintf(__('Please enter your %s number!', 'invoicing'), $vat_name); |
|
1709 | 1709 | |
1710 | 1710 | $vat_info['valid'] = false; |
1711 | 1711 | } |
1712 | 1712 | |
1713 | - $wpi_session->set( 'user_vat_data', $vat_info ); |
|
1714 | - wp_send_json( $response ); |
|
1713 | + $wpi_session->set('user_vat_data', $vat_info); |
|
1714 | + wp_send_json($response); |
|
1715 | 1715 | } |
1716 | 1716 | |
1717 | - if ( empty( $company ) ) { |
|
1717 | + if (empty($company)) { |
|
1718 | 1718 | $vat_info['valid'] = false; |
1719 | - $wpi_session->set( 'user_vat_data', $vat_info ); |
|
1719 | + $wpi_session->set('user_vat_data', $vat_info); |
|
1720 | 1720 | |
1721 | - $response['error'] = __( 'Please enter your registered company name!', 'invoicing' ); |
|
1722 | - wp_send_json( $response ); |
|
1721 | + $response['error'] = __('Please enter your registered company name!', 'invoicing'); |
|
1722 | + wp_send_json($response); |
|
1723 | 1723 | } |
1724 | 1724 | |
1725 | - if ( !empty( $wpinv_options['vat_vies_check'] ) ) { |
|
1726 | - if ( empty( $wpinv_options['vat_offline_check'] ) && !self::offline_check( $vat_number ) ) { |
|
1725 | + if (!empty($wpinv_options['vat_vies_check'])) { |
|
1726 | + if (empty($wpinv_options['vat_offline_check']) && !self::offline_check($vat_number)) { |
|
1727 | 1727 | $vat_info['valid'] = false; |
1728 | - $wpi_session->set( 'user_vat_data', $vat_info ); |
|
1728 | + $wpi_session->set('user_vat_data', $vat_info); |
|
1729 | 1729 | |
1730 | - $response['error'] = wp_sprintf( __( '%s number not validated', 'invoicing' ), $vat_name ); |
|
1731 | - wp_send_json( $response ); |
|
1730 | + $response['error'] = wp_sprintf(__('%s number not validated', 'invoicing'), $vat_name); |
|
1731 | + wp_send_json($response); |
|
1732 | 1732 | } |
1733 | 1733 | |
1734 | 1734 | $response['success'] = true; |
1735 | - $response['message'] = wp_sprintf( __( '%s number validated', 'invoicing' ), $vat_name ); |
|
1735 | + $response['message'] = wp_sprintf(__('%s number validated', 'invoicing'), $vat_name); |
|
1736 | 1736 | } else { |
1737 | - $result = self::check_vat( $vat_number ); |
|
1737 | + $result = self::check_vat($vat_number); |
|
1738 | 1738 | |
1739 | - if ( empty( $result['valid'] ) ) { |
|
1739 | + if (empty($result['valid'])) { |
|
1740 | 1740 | $response['error'] = $result['message']; |
1741 | - wp_send_json( $response ); |
|
1741 | + wp_send_json($response); |
|
1742 | 1742 | } |
1743 | 1743 | |
1744 | - $vies_company = !empty( $result['company'] ) ? $result['company'] : ''; |
|
1745 | - $vies_company = apply_filters( 'wpinv_vies_company_name', $vies_company ); |
|
1744 | + $vies_company = !empty($result['company']) ? $result['company'] : ''; |
|
1745 | + $vies_company = apply_filters('wpinv_vies_company_name', $vies_company); |
|
1746 | 1746 | |
1747 | - $valid_company = $vies_company && $company && ( $vies_company == '---' || strcasecmp( trim( $vies_company ), trim( $company ) ) == 0 ) ? true : false; |
|
1747 | + $valid_company = $vies_company && $company && ($vies_company == '---' || strcasecmp(trim($vies_company), trim($company)) == 0) ? true : false; |
|
1748 | 1748 | |
1749 | - if ( !empty( $wpinv_options['vat_disable_company_name_check'] ) || $valid_company ) { |
|
1749 | + if (!empty($wpinv_options['vat_disable_company_name_check']) || $valid_company) { |
|
1750 | 1750 | $response['success'] = true; |
1751 | - $response['message'] = wp_sprintf( __( '%s number validated', 'invoicing' ), $vat_name ); |
|
1751 | + $response['message'] = wp_sprintf(__('%s number validated', 'invoicing'), $vat_name); |
|
1752 | 1752 | } else { |
1753 | 1753 | $vat_info['valid'] = false; |
1754 | - $wpi_session->set( 'user_vat_data', $vat_info ); |
|
1754 | + $wpi_session->set('user_vat_data', $vat_info); |
|
1755 | 1755 | |
1756 | 1756 | $response['success'] = false; |
1757 | - $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 ); |
|
1758 | - wp_send_json( $response ); |
|
1757 | + $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); |
|
1758 | + wp_send_json($response); |
|
1759 | 1759 | } |
1760 | 1760 | } |
1761 | 1761 | |
1762 | - if ( $is_checkout ) { |
|
1763 | - self::save_user_vat_details( $company, $vat_number ); |
|
1762 | + if ($is_checkout) { |
|
1763 | + self::save_user_vat_details($company, $vat_number); |
|
1764 | 1764 | |
1765 | - $vat_info = array('company' => $company, 'number' => $vat_number, 'valid' => true ); |
|
1766 | - $wpi_session->set( 'user_vat_data', $vat_info ); |
|
1765 | + $vat_info = array('company' => $company, 'number' => $vat_number, 'valid' => true); |
|
1766 | + $wpi_session->set('user_vat_data', $vat_info); |
|
1767 | 1767 | } |
1768 | 1768 | |
1769 | - wp_send_json( $response ); |
|
1769 | + wp_send_json($response); |
|
1770 | 1770 | } |
1771 | 1771 | |
1772 | 1772 | public static function ajax_vat_reset() { |
@@ -1775,161 +1775,161 @@ discard block |
||
1775 | 1775 | $company = is_user_logged_in() ? self::get_user_company() : ''; |
1776 | 1776 | $vat_number = self::get_user_vat_number(); |
1777 | 1777 | |
1778 | - $vat_info = array('company' => $company, 'number' => $vat_number, 'valid' => false ); |
|
1779 | - $wpi_session->set( 'user_vat_data', $vat_info ); |
|
1778 | + $vat_info = array('company' => $company, 'number' => $vat_number, 'valid' => false); |
|
1779 | + $wpi_session->set('user_vat_data', $vat_info); |
|
1780 | 1780 | |
1781 | 1781 | $response = array(); |
1782 | 1782 | $response['success'] = true; |
1783 | 1783 | $response['data']['company'] = $company; |
1784 | 1784 | $response['data']['number'] = $vat_number; |
1785 | 1785 | |
1786 | - wp_send_json( $response ); |
|
1786 | + wp_send_json($response); |
|
1787 | 1787 | } |
1788 | 1788 | |
1789 | - public static function checkout_vat_validate( $valid_data, $post ) { |
|
1789 | + public static function checkout_vat_validate($valid_data, $post) { |
|
1790 | 1790 | global $wpinv_options, $wpi_session; |
1791 | 1791 | |
1792 | - $vat_name = __( self::get_vat_name(), 'invoicing' ); |
|
1792 | + $vat_name = __(self::get_vat_name(), 'invoicing'); |
|
1793 | 1793 | |
1794 | - if ( !isset( $_POST['_wpi_nonce'] ) || !wp_verify_nonce( $_POST['_wpi_nonce'], 'vat_validation' ) ) { |
|
1795 | - wpinv_set_error( 'vat_validation', wp_sprintf( __( "Invalid %s validation request.", 'invoicing' ), $vat_name ) ); |
|
1794 | + if (!isset($_POST['_wpi_nonce']) || !wp_verify_nonce($_POST['_wpi_nonce'], 'vat_validation')) { |
|
1795 | + wpinv_set_error('vat_validation', wp_sprintf(__("Invalid %s validation request.", 'invoicing'), $vat_name)); |
|
1796 | 1796 | return; |
1797 | 1797 | } |
1798 | 1798 | |
1799 | - $vat_saved = $wpi_session->get( 'user_vat_data' ); |
|
1800 | - $wpi_session->set( 'user_vat_data', null ); |
|
1799 | + $vat_saved = $wpi_session->get('user_vat_data'); |
|
1800 | + $wpi_session->set('user_vat_data', null); |
|
1801 | 1801 | |
1802 | 1802 | $invoice = wpinv_get_invoice_cart(); |
1803 | 1803 | $amount = $invoice->get_total(); |
1804 | - $is_digital = self::invoice_has_digital_rule( $invoice ); |
|
1805 | - $no_vat = !self::requires_vat( 0, false, $is_digital ); |
|
1804 | + $is_digital = self::invoice_has_digital_rule($invoice); |
|
1805 | + $no_vat = !self::requires_vat(0, false, $is_digital); |
|
1806 | 1806 | |
1807 | - $company = !empty( $_POST['wpinv_company'] ) ? $_POST['wpinv_company'] : null; |
|
1808 | - $vat_number = !empty( $_POST['wpinv_vat_number'] ) ? $_POST['wpinv_vat_number'] : null; |
|
1809 | - $country = !empty( $_POST['wpinv_country'] ) ? $_POST['wpinv_country'] : $invoice->country; |
|
1810 | - if ( empty( $country ) ) { |
|
1807 | + $company = !empty($_POST['wpinv_company']) ? $_POST['wpinv_company'] : null; |
|
1808 | + $vat_number = !empty($_POST['wpinv_vat_number']) ? $_POST['wpinv_vat_number'] : null; |
|
1809 | + $country = !empty($_POST['wpinv_country']) ? $_POST['wpinv_country'] : $invoice->country; |
|
1810 | + if (empty($country)) { |
|
1811 | 1811 | $country = wpinv_default_billing_country(); |
1812 | 1812 | } |
1813 | 1813 | |
1814 | - if ( !$is_digital && $no_vat ) { |
|
1814 | + if (!$is_digital && $no_vat) { |
|
1815 | 1815 | return; |
1816 | 1816 | } |
1817 | 1817 | |
1818 | - $vat_data = array( 'company' => '', 'number' => '', 'valid' => false ); |
|
1818 | + $vat_data = array('company' => '', 'number' => '', 'valid' => false); |
|
1819 | 1819 | |
1820 | 1820 | $ip_country_code = self::get_country_by_ip(); |
1821 | - $is_eu_state = self::is_eu_state( $country ); |
|
1822 | - $is_eu_state_ip = self::is_eu_state( $ip_country_code ); |
|
1821 | + $is_eu_state = self::is_eu_state($country); |
|
1822 | + $is_eu_state_ip = self::is_eu_state($ip_country_code); |
|
1823 | 1823 | $is_non_eu_user = !$is_eu_state && !$is_eu_state_ip; |
1824 | 1824 | |
1825 | - if ( $is_digital && !$is_non_eu_user && empty( $vat_number ) && apply_filters( 'wpinv_checkout_requires_country', true, $amount ) ) { |
|
1825 | + if ($is_digital && !$is_non_eu_user && empty($vat_number) && apply_filters('wpinv_checkout_requires_country', true, $amount)) { |
|
1826 | 1826 | $vat_data['adddress_confirmed'] = false; |
1827 | 1827 | |
1828 | - if ( !isset( $_POST['wpinv_adddress_confirmed'] ) ) { |
|
1829 | - if ( $ip_country_code != $country ) { |
|
1830 | - 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>' ) ); |
|
1828 | + if (!isset($_POST['wpinv_adddress_confirmed'])) { |
|
1829 | + if ($ip_country_code != $country) { |
|
1830 | + 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>')); |
|
1831 | 1831 | } |
1832 | 1832 | } else { |
1833 | 1833 | $vat_data['adddress_confirmed'] = true; |
1834 | 1834 | } |
1835 | 1835 | } |
1836 | 1836 | |
1837 | - if ( !empty( $wpinv_options['vat_prevent_b2c_purchase'] ) && !$is_non_eu_user && ( empty( $vat_number ) || $no_vat ) ) { |
|
1838 | - if ( $is_eu_state ) { |
|
1839 | - 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 ) ); |
|
1840 | - } else if ( $is_digital && $is_eu_state_ip ) { |
|
1841 | - wpinv_set_error( 'vat_validation', wp_sprintf( __( 'Sales to non-EU countries cannot be completed because %s must be applied.', 'invoicing' ), $vat_name ) ); |
|
1837 | + if (!empty($wpinv_options['vat_prevent_b2c_purchase']) && !$is_non_eu_user && (empty($vat_number) || $no_vat)) { |
|
1838 | + if ($is_eu_state) { |
|
1839 | + 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)); |
|
1840 | + } else if ($is_digital && $is_eu_state_ip) { |
|
1841 | + wpinv_set_error('vat_validation', wp_sprintf(__('Sales to non-EU countries cannot be completed because %s must be applied.', 'invoicing'), $vat_name)); |
|
1842 | 1842 | } |
1843 | 1843 | } |
1844 | 1844 | |
1845 | - if ( !$is_eu_state || $no_vat || empty( $vat_number ) ) { |
|
1845 | + if (!$is_eu_state || $no_vat || empty($vat_number)) { |
|
1846 | 1846 | return; |
1847 | 1847 | } |
1848 | 1848 | |
1849 | - if ( !empty( $vat_saved ) && isset( $vat_saved['valid'] ) ) { |
|
1850 | - $vat_data['valid'] = $vat_saved['valid']; |
|
1849 | + if (!empty($vat_saved) && isset($vat_saved['valid'])) { |
|
1850 | + $vat_data['valid'] = $vat_saved['valid']; |
|
1851 | 1851 | } |
1852 | 1852 | |
1853 | - if ( $company !== null ) { |
|
1853 | + if ($company !== null) { |
|
1854 | 1854 | $vat_data['company'] = $company; |
1855 | 1855 | } |
1856 | 1856 | |
1857 | 1857 | $message = ''; |
1858 | - if ( $vat_number !== null ) { |
|
1858 | + if ($vat_number !== null) { |
|
1859 | 1859 | $vat_data['number'] = $vat_number; |
1860 | 1860 | |
1861 | - if ( !$vat_data['valid'] || ( $vat_saved['number'] !== $vat_data['number'] ) || ( $vat_saved['company'] !== $vat_data['company'] ) ) { |
|
1862 | - if ( !empty( $wpinv_options['vat_vies_check'] ) ) { |
|
1863 | - if ( empty( $wpinv_options['vat_offline_check'] ) && !self::offline_check( $vat_number ) ) { |
|
1861 | + if (!$vat_data['valid'] || ($vat_saved['number'] !== $vat_data['number']) || ($vat_saved['company'] !== $vat_data['company'])) { |
|
1862 | + if (!empty($wpinv_options['vat_vies_check'])) { |
|
1863 | + if (empty($wpinv_options['vat_offline_check']) && !self::offline_check($vat_number)) { |
|
1864 | 1864 | $vat_data['valid'] = false; |
1865 | 1865 | } |
1866 | 1866 | } else { |
1867 | - $result = self::check_vat( $vat_number ); |
|
1867 | + $result = self::check_vat($vat_number); |
|
1868 | 1868 | |
1869 | - if ( !empty( $result['valid'] ) ) { |
|
1869 | + if (!empty($result['valid'])) { |
|
1870 | 1870 | $vat_data['valid'] = true; |
1871 | - $vies_company = !empty( $result['company'] ) ? $result['company'] : ''; |
|
1872 | - $vies_company = apply_filters( 'wpinv_vies_company_name', $vies_company ); |
|
1871 | + $vies_company = !empty($result['company']) ? $result['company'] : ''; |
|
1872 | + $vies_company = apply_filters('wpinv_vies_company_name', $vies_company); |
|
1873 | 1873 | |
1874 | - $valid_company = $vies_company && $company && ( $vies_company == '---' || strcasecmp( trim( $vies_company ), trim( $company ) ) == 0 ) ? true : false; |
|
1874 | + $valid_company = $vies_company && $company && ($vies_company == '---' || strcasecmp(trim($vies_company), trim($company)) == 0) ? true : false; |
|
1875 | 1875 | |
1876 | - if ( !( !empty( $wpinv_options['vat_disable_company_name_check'] ) || $valid_company ) ) { |
|
1876 | + if (!(!empty($wpinv_options['vat_disable_company_name_check']) || $valid_company)) { |
|
1877 | 1877 | $vat_data['valid'] = false; |
1878 | 1878 | |
1879 | - $message = wp_sprintf( __( 'The company name associated with the %s number provided is not the same as the company name provided.', 'invoicing' ), $vat_name ); |
|
1879 | + $message = wp_sprintf(__('The company name associated with the %s number provided is not the same as the company name provided.', 'invoicing'), $vat_name); |
|
1880 | 1880 | } |
1881 | 1881 | } else { |
1882 | - $message = wp_sprintf( __( 'Fail to validate the %s number: EU Commission VAT server (VIES) check fails.', 'invoicing' ), $vat_name ); |
|
1882 | + $message = wp_sprintf(__('Fail to validate the %s number: EU Commission VAT server (VIES) check fails.', 'invoicing'), $vat_name); |
|
1883 | 1883 | } |
1884 | 1884 | } |
1885 | 1885 | |
1886 | - if ( !$vat_data['valid'] ) { |
|
1887 | - $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 . ' )' : '' ); |
|
1888 | - wpinv_set_error( 'vat_validation', $error ); |
|
1886 | + if (!$vat_data['valid']) { |
|
1887 | + $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 . ' )' : ''); |
|
1888 | + wpinv_set_error('vat_validation', $error); |
|
1889 | 1889 | } |
1890 | 1890 | } |
1891 | 1891 | } |
1892 | 1892 | |
1893 | - $wpi_session->set( 'user_vat_data', $vat_data ); |
|
1893 | + $wpi_session->set('user_vat_data', $vat_data); |
|
1894 | 1894 | } |
1895 | 1895 | |
1896 | - public static function checkout_vat_fields( $billing_details ) { |
|
1896 | + public static function checkout_vat_fields($billing_details) { |
|
1897 | 1897 | global $wpi_session, $wpinv_options, $wpi_country, $wpi_requires_vat; |
1898 | 1898 | |
1899 | 1899 | $ip_address = wpinv_get_ip(); |
1900 | 1900 | $ip_country_code = self::get_country_by_ip(); |
1901 | 1901 | |
1902 | - $tax_label = __( self::get_vat_name(), 'invoicing' ); |
|
1902 | + $tax_label = __(self::get_vat_name(), 'invoicing'); |
|
1903 | 1903 | $invoice = wpinv_get_invoice_cart(); |
1904 | - $is_digital = self::invoice_has_digital_rule( $invoice ); |
|
1904 | + $is_digital = self::invoice_has_digital_rule($invoice); |
|
1905 | 1905 | $wpi_country = $invoice->country; |
1906 | 1906 | |
1907 | - $requires_vat = !self::hide_vat_fields() && !$invoice->is_free() && self::requires_vat( 0, false, $is_digital ); |
|
1907 | + $requires_vat = !self::hide_vat_fields() && !$invoice->is_free() && self::requires_vat(0, false, $is_digital); |
|
1908 | 1908 | $wpi_requires_vat = $requires_vat; |
1909 | 1909 | |
1910 | 1910 | $company = self::get_user_company(); |
1911 | 1911 | $vat_number = self::get_user_vat_number(); |
1912 | 1912 | |
1913 | - $validated = $vat_number ? self::get_user_vat_number( '', 0, true ) : 1; |
|
1914 | - $vat_info = $wpi_session->get( 'user_vat_data' ); |
|
1913 | + $validated = $vat_number ? self::get_user_vat_number('', 0, true) : 1; |
|
1914 | + $vat_info = $wpi_session->get('user_vat_data'); |
|
1915 | 1915 | |
1916 | - if ( is_array( $vat_info ) ) { |
|
1917 | - $company = isset( $vat_info['company'] ) ? $vat_info['company'] : ''; |
|
1918 | - $vat_number = isset( $vat_info['number'] ) ? $vat_info['number'] : ''; |
|
1919 | - $validated = isset( $vat_info['valid'] ) ? $vat_info['valid'] : false; |
|
1916 | + if (is_array($vat_info)) { |
|
1917 | + $company = isset($vat_info['company']) ? $vat_info['company'] : ''; |
|
1918 | + $vat_number = isset($vat_info['number']) ? $vat_info['number'] : ''; |
|
1919 | + $validated = isset($vat_info['valid']) ? $vat_info['valid'] : false; |
|
1920 | 1920 | } |
1921 | 1921 | |
1922 | 1922 | $selected_country = $invoice->country ? $invoice->country : wpinv_default_billing_country(); |
1923 | 1923 | |
1924 | - if ( $ip_country_code == 'UK' ) { |
|
1924 | + if ($ip_country_code == 'UK') { |
|
1925 | 1925 | $ip_country_code = 'GB'; |
1926 | 1926 | } |
1927 | 1927 | |
1928 | - if ( $selected_country == 'UK' ) { |
|
1928 | + if ($selected_country == 'UK') { |
|
1929 | 1929 | $selected_country = 'GB'; |
1930 | 1930 | } |
1931 | 1931 | |
1932 | - if ( $requires_vat && ( self::same_country_rule() == 'no' && wpinv_is_base_country( $selected_country ) || !self::allow_vat_rules() ) ) { |
|
1932 | + if ($requires_vat && (self::same_country_rule() == 'no' && wpinv_is_base_country($selected_country) || !self::allow_vat_rules())) { |
|
1933 | 1933 | $requires_vat = false; |
1934 | 1934 | } |
1935 | 1935 | |
@@ -1937,52 +1937,52 @@ discard block |
||
1937 | 1937 | $display_validate_btn = 'none'; |
1938 | 1938 | $display_reset_btn = 'none'; |
1939 | 1939 | |
1940 | - if ( !empty( $vat_number ) && $validated ) { |
|
1941 | - $vat_vailidated_text = wp_sprintf( __( '%s number validated', 'invoicing' ), $tax_label ); |
|
1940 | + if (!empty($vat_number) && $validated) { |
|
1941 | + $vat_vailidated_text = wp_sprintf(__('%s number validated', 'invoicing'), $tax_label); |
|
1942 | 1942 | $vat_vailidated_class = 'wpinv-vat-stat-1'; |
1943 | 1943 | $display_reset_btn = 'block'; |
1944 | 1944 | } else { |
1945 | - $vat_vailidated_text = empty( $vat_number ) ? '' : wp_sprintf( __( '%s number not validated', 'invoicing' ), $tax_label ); |
|
1946 | - $vat_vailidated_class = empty( $vat_number ) ? '' : 'wpinv-vat-stat-0'; |
|
1945 | + $vat_vailidated_text = empty($vat_number) ? '' : wp_sprintf(__('%s number not validated', 'invoicing'), $tax_label); |
|
1946 | + $vat_vailidated_class = empty($vat_number) ? '' : 'wpinv-vat-stat-0'; |
|
1947 | 1947 | $display_validate_btn = 'block'; |
1948 | 1948 | } |
1949 | 1949 | |
1950 | - $show_ip_country = $is_digital && ( empty( $vat_number ) || !$requires_vat ) && $ip_country_code != $selected_country ? 'block' : 'none'; |
|
1950 | + $show_ip_country = $is_digital && (empty($vat_number) || !$requires_vat) && $ip_country_code != $selected_country ? 'block' : 'none'; |
|
1951 | 1951 | ?> |
1952 | 1952 | <div id="wpi-vat-details" class="wpi-vat-details clearfix" style="display:<?php echo $display_vat_details; ?>"> |
1953 | 1953 | <div id="wpi_vat_info" class="clearfix panel panel-default"> |
1954 | - <div class="panel-heading"><h3 class="panel-title"><?php echo wp_sprintf( __( '%s Details', 'invoicing' ), $tax_label );?></h3></div> |
|
1954 | + <div class="panel-heading"><h3 class="panel-title"><?php echo wp_sprintf(__('%s Details', 'invoicing'), $tax_label); ?></h3></div> |
|
1955 | 1955 | <div id="wpinv-fields-box" class="panel-body"> |
1956 | 1956 | <p id="wpi_show_vat_note"> |
1957 | - <?php echo wp_sprintf( __( 'Validate your registered %s number to exclude tax.', 'invoicing' ), $tax_label ); ?> |
|
1957 | + <?php echo wp_sprintf(__('Validate your registered %s number to exclude tax.', 'invoicing'), $tax_label); ?> |
|
1958 | 1958 | </p> |
1959 | 1959 | <div id="wpi_vat_fields" class="wpi_vat_info"> |
1960 | 1960 | <p class="wpi-cart-field wpi-col2 wpi-colf"> |
1961 | - <label for="wpinv_company" class="wpi-label"><?php _e( 'Company Name', 'invoicing' );?></label> |
|
1961 | + <label for="wpinv_company" class="wpi-label"><?php _e('Company Name', 'invoicing'); ?></label> |
|
1962 | 1962 | <?php |
1963 | - echo wpinv_html_text( array( |
|
1963 | + echo wpinv_html_text(array( |
|
1964 | 1964 | 'id' => 'wpinv_company', |
1965 | 1965 | 'name' => 'wpinv_company', |
1966 | 1966 | 'value' => $company, |
1967 | 1967 | 'class' => 'wpi-input form-control', |
1968 | - 'placeholder' => __( 'Company name', 'invoicing' ), |
|
1969 | - ) ); |
|
1968 | + 'placeholder' => __('Company name', 'invoicing'), |
|
1969 | + )); |
|
1970 | 1970 | ?> |
1971 | 1971 | </p> |
1972 | 1972 | <p class="wpi-cart-field wpi-col2 wpi-coll wpi-cart-field-vat"> |
1973 | - <label for="wpinv_vat_number" class="wpi-label"><?php echo wp_sprintf( __( '%s Number', 'invoicing' ), $tax_label );?></label> |
|
1973 | + <label for="wpinv_vat_number" class="wpi-label"><?php echo wp_sprintf(__('%s Number', 'invoicing'), $tax_label); ?></label> |
|
1974 | 1974 | <span id="wpinv_vat_number-wrap"> |
1975 | 1975 | <label for="wpinv_vat_number" class="wpinv-label"></label> |
1976 | - <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"> |
|
1977 | - <span class="wpinv-vat-stat <?php echo $vat_vailidated_class;?>"><i class="fa"></i> <font><?php echo $vat_vailidated_text;?></font></span> |
|
1976 | + <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"> |
|
1977 | + <span class="wpinv-vat-stat <?php echo $vat_vailidated_class; ?>"><i class="fa"></i> <font><?php echo $vat_vailidated_text; ?></font></span> |
|
1978 | 1978 | </span> |
1979 | 1979 | </p> |
1980 | 1980 | <p class="wpi-cart-field wpi-col wpi-colf wpi-cart-field-actions"> |
1981 | - <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> |
|
1982 | - <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> |
|
1981 | + <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> |
|
1982 | + <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> |
|
1983 | 1983 | <span class="wpi-vat-box wpi-vat-box-info"><span id="text"></span></span> |
1984 | 1984 | <span class="wpi-vat-box wpi-vat-box-error"><span id="text"></span></span> |
1985 | - <input type="hidden" name="_wpi_nonce" value="<?php echo wp_create_nonce( 'vat_validation' ) ?>" /> |
|
1985 | + <input type="hidden" name="_wpi_nonce" value="<?php echo wp_create_nonce('vat_validation') ?>" /> |
|
1986 | 1986 | </p> |
1987 | 1987 | </div> |
1988 | 1988 | </div> |
@@ -1996,32 +1996,32 @@ discard block |
||
1996 | 1996 | </span> |
1997 | 1997 | </div> |
1998 | 1998 | </div> |
1999 | - <?php if ( empty( $wpinv_options['hide_ip_address'] ) ) { |
|
2000 | - $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>'; |
|
1999 | + <?php if (empty($wpinv_options['hide_ip_address'])) { |
|
2000 | + $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>'; |
|
2001 | 2001 | ?> |
2002 | 2002 | <div class="wpi-ip-info clearfix panel panel-info"> |
2003 | 2003 | <div id="wpinv-fields-box" class="panel-body"> |
2004 | - <span><?php echo wp_sprintf( __( "Your IP address is: %s", 'invoicing' ), $ip_link ); ?></span> |
|
2004 | + <span><?php echo wp_sprintf(__("Your IP address is: %s", 'invoicing'), $ip_link); ?></span> |
|
2005 | 2005 | </div> |
2006 | 2006 | </div> |
2007 | 2007 | <?php } |
2008 | 2008 | } |
2009 | 2009 | |
2010 | - public static function show_vat_notice( $invoice ) { |
|
2011 | - if ( empty( $invoice ) ) { |
|
2010 | + public static function show_vat_notice($invoice) { |
|
2011 | + if (empty($invoice)) { |
|
2012 | 2012 | return NULL; |
2013 | 2013 | } |
2014 | 2014 | |
2015 | - $label = wpinv_get_option( 'vat_invoice_notice_label' ); |
|
2016 | - $notice = wpinv_get_option( 'vat_invoice_notice' ); |
|
2017 | - if ( $label || $notice ) { |
|
2015 | + $label = wpinv_get_option('vat_invoice_notice_label'); |
|
2016 | + $notice = wpinv_get_option('vat_invoice_notice'); |
|
2017 | + if ($label || $notice) { |
|
2018 | 2018 | ?> |
2019 | 2019 | <div class="row wpinv-vat-notice"> |
2020 | 2020 | <div class="col-sm-12"> |
2021 | - <?php if ( $label ) { ?> |
|
2022 | - <strong><?php _e( $label, 'invoicing' ); ?></strong> |
|
2023 | - <?php } if ( $notice ) { ?> |
|
2024 | - <?php echo wpautop( wptexturize( __( $notice, 'invoicing' ) ) ) ?> |
|
2021 | + <?php if ($label) { ?> |
|
2022 | + <strong><?php _e($label, 'invoicing'); ?></strong> |
|
2023 | + <?php } if ($notice) { ?> |
|
2024 | + <?php echo wpautop(wptexturize(__($notice, 'invoicing'))) ?> |
|
2025 | 2025 | <?php } ?> |
2026 | 2026 | </div> |
2027 | 2027 | </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 amount should be %s', 'invoicing' ), wpinv_price( wpinv_format_amount( $min ) ) ) ); |
|
535 | + wpinv_set_error('wpinv-discount-error', sprintf(__('Minimum invoice amount should be %s', '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 amount should be %s', 'invoicing' ), wpinv_price( wpinv_format_amount( $max ) ) ) ); |
|
554 | + wpinv_set_error('wpinv-discount-error', sprintf(__('Maximum invoice amount should be %s', '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( __( 'Discount: %s', 'invoicing' ), $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(__('Discount: %s', 'invoicing'), $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 |
@@ -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; |
@@ -1,67 +1,67 @@ |
||
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_before_billing_details', $invoice ); ?> |
|
6 | +do_action('wpinv_email_before_billing_details', $invoice); ?> |
|
7 | 7 | <div id="wpinv-email-billing"> |
8 | - <h3 class="wpinv-address-t"><?php echo apply_filters( 'wpinv_email_billing_title', __( 'Billing Details', 'invoicing' ) ); ?></h3> |
|
8 | + <h3 class="wpinv-address-t"><?php echo apply_filters('wpinv_email_billing_title', __('Billing Details', 'invoicing')); ?></h3> |
|
9 | 9 | <?php |
10 | 10 | $address_row = ''; |
11 | - if ( $address = $invoice->get_address() ) { |
|
12 | - $address_row .= wpautop( wp_kses_post( $address ) ); |
|
11 | + if ($address = $invoice->get_address()) { |
|
12 | + $address_row .= wpautop(wp_kses_post($address)); |
|
13 | 13 | } |
14 | 14 | |
15 | 15 | $address_fields = array(); |
16 | - if ( !empty( $invoice->city ) ) { |
|
16 | + if (!empty($invoice->city)) { |
|
17 | 17 | $address_fields[] = $invoice->city; |
18 | 18 | } |
19 | 19 | |
20 | - $country_code = !empty( $invoice->country ) ? $invoice->country : ''; |
|
21 | - if ( !empty( $invoice->state ) ) { |
|
22 | - $address_fields[] = wpinv_state_name( $invoice->state, $country_code ); |
|
20 | + $country_code = !empty($invoice->country) ? $invoice->country : ''; |
|
21 | + if (!empty($invoice->state)) { |
|
22 | + $address_fields[] = wpinv_state_name($invoice->state, $country_code); |
|
23 | 23 | } |
24 | 24 | |
25 | - if ( !empty( $address_fields ) ) { |
|
26 | - $address_fields = implode( ", ", $address_fields ); |
|
27 | - $address_row .= wpautop( wp_kses_post( $address_fields ) ); |
|
25 | + if (!empty($address_fields)) { |
|
26 | + $address_fields = implode(", ", $address_fields); |
|
27 | + $address_row .= wpautop(wp_kses_post($address_fields)); |
|
28 | 28 | } |
29 | 29 | |
30 | - if ( !empty( $country_code ) ) { |
|
31 | - $country = wpinv_country_name( $country_code ); |
|
32 | - $address_row .= wpautop( wp_kses_post( trim( $country . '(' . $country_code . ')' . ' ' . $invoice->zip ) ) ); |
|
30 | + if (!empty($country_code)) { |
|
31 | + $country = wpinv_country_name($country_code); |
|
32 | + $address_row .= wpautop(wp_kses_post(trim($country . '(' . $country_code . ')' . ' ' . $invoice->zip))); |
|
33 | 33 | } |
34 | 34 | |
35 | 35 | ?> |
36 | 36 | <table class="table table-bordered table-sm wpi-billing-details"> |
37 | 37 | <tbody> |
38 | - <?php do_action( 'wpinv_email_billing_fields_first', $invoice ); ?> |
|
38 | + <?php do_action('wpinv_email_billing_fields_first', $invoice); ?> |
|
39 | 39 | <tr class="wpi-receipt-name"> |
40 | - <th class="text-left"><?php _e( 'Name', 'invoicing' ); ?></th> |
|
41 | - <td><?php if ( $sent_to_admin && $invoice->user_id ) { ?><a href="<?php echo esc_url( add_query_arg( 'user_id', $invoice->get_user_id(), self_admin_url( 'user-edit.php' ) ) ) ;?>"><?php echo esc_html( $invoice->get_user_full_name() ); ?></a><?php } else { echo esc_html( $invoice->get_user_full_name() ); } ?></td> |
|
40 | + <th class="text-left"><?php _e('Name', 'invoicing'); ?></th> |
|
41 | + <td><?php if ($sent_to_admin && $invoice->user_id) { ?><a href="<?php echo esc_url(add_query_arg('user_id', $invoice->get_user_id(), self_admin_url('user-edit.php'))); ?>"><?php echo esc_html($invoice->get_user_full_name()); ?></a><?php } else { echo esc_html($invoice->get_user_full_name()); } ?></td> |
|
42 | 42 | </tr> |
43 | 43 | <tr class="wpi-receipt-email"> |
44 | - <th class="text-left"><?php _e( 'Email', 'invoicing' ); ?></th> |
|
45 | - <td><?php echo $invoice->get_email() ;?></td> |
|
44 | + <th class="text-left"><?php _e('Email', 'invoicing'); ?></th> |
|
45 | + <td><?php echo $invoice->get_email(); ?></td> |
|
46 | 46 | </tr> |
47 | - <?php if ( $invoice->company ) { ?> |
|
47 | + <?php if ($invoice->company) { ?> |
|
48 | 48 | <tr class="wpi-receipt-company"> |
49 | - <th class="text-left"><?php _e( 'Company', 'invoicing' ); ?></th> |
|
50 | - <td><?php echo esc_html( $invoice->company ) ;?></td> |
|
49 | + <th class="text-left"><?php _e('Company', 'invoicing'); ?></th> |
|
50 | + <td><?php echo esc_html($invoice->company); ?></td> |
|
51 | 51 | </tr> |
52 | 52 | <?php } ?> |
53 | 53 | <tr class="wpi-receipt-address"> |
54 | - <th class="text-left"><?php _e( 'Address', 'invoicing' ); ?></th> |
|
55 | - <td><?php echo $address_row ;?></td> |
|
54 | + <th class="text-left"><?php _e('Address', 'invoicing'); ?></th> |
|
55 | + <td><?php echo $address_row; ?></td> |
|
56 | 56 | </tr> |
57 | - <?php if ( $invoice->phone ) { ?> |
|
57 | + <?php if ($invoice->phone) { ?> |
|
58 | 58 | <tr class="wpi-receipt-phone"> |
59 | - <th class="text-left"><?php _e( 'Phone', 'invoicing' ); ?></th> |
|
60 | - <td><?php echo esc_html( $invoice->phone ) ;?></td> |
|
59 | + <th class="text-left"><?php _e('Phone', 'invoicing'); ?></th> |
|
60 | + <td><?php echo esc_html($invoice->phone); ?></td> |
|
61 | 61 | </tr> |
62 | 62 | <?php } ?> |
63 | - <?php do_action( 'wpinv_email_billing_fields_last', $invoice ); ?> |
|
63 | + <?php do_action('wpinv_email_billing_fields_last', $invoice); ?> |
|
64 | 64 | </tbody> |
65 | 65 | </table> |
66 | 66 | </div> |
67 | -<?php do_action( 'wpinv_email_after_billing_details', $invoice ); ?> |
|
68 | 67 | \ No newline at end of file |
68 | +<?php do_action('wpinv_email_after_billing_details', $invoice); ?> |
|
69 | 69 | \ 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 | do_action( 'wpinv_email_before_billing_details', $invoice ); ?> |
7 | 8 | <div id="wpinv-email-billing"> |