@@ -48,7 +48,6 @@ |
||
| 48 | 48 | /** |
| 49 | 49 | * Retrieve the current session instance. |
| 50 | 50 | * |
| 51 | - * @param bool $session_id Session ID from which to populate data. |
|
| 52 | 51 | * |
| 53 | 52 | * @return bool|WP_Session |
| 54 | 53 | */ |
@@ -17,215 +17,215 @@ |
||
| 17 | 17 | * @since 3.7.0 |
| 18 | 18 | */ |
| 19 | 19 | final class WP_Session extends Recursive_ArrayAccess { |
| 20 | - /** |
|
| 21 | - * ID of the current session. |
|
| 22 | - * |
|
| 23 | - * @var string |
|
| 24 | - */ |
|
| 25 | - public $session_id; |
|
| 26 | - |
|
| 27 | - /** |
|
| 28 | - * Unix timestamp when session expires. |
|
| 29 | - * |
|
| 30 | - * @var int |
|
| 31 | - */ |
|
| 32 | - protected $expires; |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * Unix timestamp indicating when the expiration time needs to be reset. |
|
| 36 | - * |
|
| 37 | - * @var int |
|
| 38 | - */ |
|
| 39 | - protected $exp_variant; |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * Singleton instance. |
|
| 43 | - * |
|
| 44 | - * @var bool|WP_Session |
|
| 45 | - */ |
|
| 46 | - private static $instance = false; |
|
| 47 | - |
|
| 48 | - /** |
|
| 49 | - * Retrieve the current session instance. |
|
| 50 | - * |
|
| 51 | - * @param bool $session_id Session ID from which to populate data. |
|
| 52 | - * |
|
| 53 | - * @return bool|WP_Session |
|
| 54 | - */ |
|
| 55 | - public static function get_instance() { |
|
| 56 | - if ( ! self::$instance ) { |
|
| 57 | - self::$instance = new self(); |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - return self::$instance; |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * Default constructor. |
|
| 65 | - * Will rebuild the session collection from the given session ID if it exists. Otherwise, will |
|
| 66 | - * create a new session with that ID. |
|
| 67 | - * |
|
| 68 | - * @param $session_id |
|
| 69 | - * @uses apply_filters Calls `wp_session_expiration` to determine how long until sessions expire. |
|
| 70 | - */ |
|
| 71 | - protected function __construct() { |
|
| 72 | - if ( isset( $_COOKIE[WP_SESSION_COOKIE] ) ) { |
|
| 73 | - $cookie = stripslashes( $_COOKIE[WP_SESSION_COOKIE] ); |
|
| 74 | - $cookie_crumbs = explode( '||', $cookie ); |
|
| 20 | + /** |
|
| 21 | + * ID of the current session. |
|
| 22 | + * |
|
| 23 | + * @var string |
|
| 24 | + */ |
|
| 25 | + public $session_id; |
|
| 26 | + |
|
| 27 | + /** |
|
| 28 | + * Unix timestamp when session expires. |
|
| 29 | + * |
|
| 30 | + * @var int |
|
| 31 | + */ |
|
| 32 | + protected $expires; |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * Unix timestamp indicating when the expiration time needs to be reset. |
|
| 36 | + * |
|
| 37 | + * @var int |
|
| 38 | + */ |
|
| 39 | + protected $exp_variant; |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * Singleton instance. |
|
| 43 | + * |
|
| 44 | + * @var bool|WP_Session |
|
| 45 | + */ |
|
| 46 | + private static $instance = false; |
|
| 47 | + |
|
| 48 | + /** |
|
| 49 | + * Retrieve the current session instance. |
|
| 50 | + * |
|
| 51 | + * @param bool $session_id Session ID from which to populate data. |
|
| 52 | + * |
|
| 53 | + * @return bool|WP_Session |
|
| 54 | + */ |
|
| 55 | + public static function get_instance() { |
|
| 56 | + if ( ! self::$instance ) { |
|
| 57 | + self::$instance = new self(); |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + return self::$instance; |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * Default constructor. |
|
| 65 | + * Will rebuild the session collection from the given session ID if it exists. Otherwise, will |
|
| 66 | + * create a new session with that ID. |
|
| 67 | + * |
|
| 68 | + * @param $session_id |
|
| 69 | + * @uses apply_filters Calls `wp_session_expiration` to determine how long until sessions expire. |
|
| 70 | + */ |
|
| 71 | + protected function __construct() { |
|
| 72 | + if ( isset( $_COOKIE[WP_SESSION_COOKIE] ) ) { |
|
| 73 | + $cookie = stripslashes( $_COOKIE[WP_SESSION_COOKIE] ); |
|
| 74 | + $cookie_crumbs = explode( '||', $cookie ); |
|
| 75 | 75 | |
| 76 | 76 | $this->session_id = preg_replace("/[^A-Za-z0-9_]/", '', $cookie_crumbs[0] ); |
| 77 | 77 | $this->expires = absint( $cookie_crumbs[1] ); |
| 78 | 78 | $this->exp_variant = absint( $cookie_crumbs[2] ); |
| 79 | 79 | |
| 80 | - // Update the session expiration if we're past the variant time |
|
| 81 | - if ( time() > $this->exp_variant ) { |
|
| 82 | - $this->set_expiration(); |
|
| 83 | - delete_option( "_wp_session_expires_{$this->session_id}" ); |
|
| 84 | - add_option( "_wp_session_expires_{$this->session_id}", $this->expires, '', 'no' ); |
|
| 85 | - } |
|
| 86 | - } else { |
|
| 87 | - $this->session_id = WP_Session_Utils::generate_id(); |
|
| 88 | - $this->set_expiration(); |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - $this->read_data(); |
|
| 92 | - |
|
| 93 | - $this->set_cookie(); |
|
| 94 | - |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - /** |
|
| 98 | - * Set both the expiration time and the expiration variant. |
|
| 99 | - * |
|
| 100 | - * If the current time is below the variant, we don't update the session's expiration time. If it's |
|
| 101 | - * greater than the variant, then we update the expiration time in the database. This prevents |
|
| 102 | - * writing to the database on every page load for active sessions and only updates the expiration |
|
| 103 | - * time if we're nearing when the session actually expires. |
|
| 104 | - * |
|
| 105 | - * By default, the expiration time is set to 30 minutes. |
|
| 106 | - * By default, the expiration variant is set to 24 minutes. |
|
| 107 | - * |
|
| 108 | - * As a result, the session expiration time - at a maximum - will only be written to the database once |
|
| 109 | - * every 24 minutes. After 30 minutes, the session will have been expired. No cookie will be sent by |
|
| 110 | - * the browser, and the old session will be queued for deletion by the garbage collector. |
|
| 111 | - * |
|
| 112 | - * @uses apply_filters Calls `wp_session_expiration_variant` to get the max update window for session data. |
|
| 113 | - * @uses apply_filters Calls `wp_session_expiration` to get the standard expiration time for sessions. |
|
| 114 | - */ |
|
| 115 | - protected function set_expiration() { |
|
| 116 | - $this->exp_variant = time() + (int) apply_filters( 'wp_session_expiration_variant', 24 * 60 ); |
|
| 117 | - $this->expires = time() + (int) apply_filters( 'wp_session_expiration', 30 * 60 ); |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - /** |
|
| 121 | - * Set the session cookie |
|
| 122 | - * @uses apply_filters Calls `wp_session_cookie_secure` to set the $secure parameter of setcookie() |
|
| 123 | - * @uses apply_filters Calls `wp_session_cookie_httponly` to set the $httponly parameter of setcookie() |
|
| 124 | - */ |
|
| 125 | - protected function set_cookie() { |
|
| 126 | - if ( !defined( 'WPI_TESTING_MODE' ) ) { |
|
| 127 | - try { |
|
| 128 | - $secure = apply_filters('wp_session_cookie_secure', false); |
|
| 129 | - $httponly = apply_filters('wp_session_cookie_httponly', false); |
|
| 130 | - setcookie( WP_SESSION_COOKIE, $this->session_id . '||' . $this->expires . '||' . $this->exp_variant , $this->expires, COOKIEPATH, COOKIE_DOMAIN, $secure, $httponly ); |
|
| 131 | - } catch(Exception $e) { |
|
| 132 | - error_log( 'Set Cookie Error: ' . $e->getMessage() ); |
|
| 133 | - } |
|
| 134 | - } |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - /** |
|
| 138 | - * Read data from a transient for the current session. |
|
| 139 | - * |
|
| 140 | - * Automatically resets the expiration time for the session transient to some time in the future. |
|
| 141 | - * |
|
| 142 | - * @return array |
|
| 143 | - */ |
|
| 144 | - protected function read_data() { |
|
| 145 | - $this->container = get_option( "_wp_session_{$this->session_id}", array() ); |
|
| 146 | - |
|
| 147 | - return $this->container; |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - /** |
|
| 151 | - * Write the data from the current session to the data storage system. |
|
| 152 | - */ |
|
| 153 | - public function write_data() { |
|
| 154 | - $option_key = "_wp_session_{$this->session_id}"; |
|
| 80 | + // Update the session expiration if we're past the variant time |
|
| 81 | + if ( time() > $this->exp_variant ) { |
|
| 82 | + $this->set_expiration(); |
|
| 83 | + delete_option( "_wp_session_expires_{$this->session_id}" ); |
|
| 84 | + add_option( "_wp_session_expires_{$this->session_id}", $this->expires, '', 'no' ); |
|
| 85 | + } |
|
| 86 | + } else { |
|
| 87 | + $this->session_id = WP_Session_Utils::generate_id(); |
|
| 88 | + $this->set_expiration(); |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + $this->read_data(); |
|
| 92 | + |
|
| 93 | + $this->set_cookie(); |
|
| 94 | + |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + /** |
|
| 98 | + * Set both the expiration time and the expiration variant. |
|
| 99 | + * |
|
| 100 | + * If the current time is below the variant, we don't update the session's expiration time. If it's |
|
| 101 | + * greater than the variant, then we update the expiration time in the database. This prevents |
|
| 102 | + * writing to the database on every page load for active sessions and only updates the expiration |
|
| 103 | + * time if we're nearing when the session actually expires. |
|
| 104 | + * |
|
| 105 | + * By default, the expiration time is set to 30 minutes. |
|
| 106 | + * By default, the expiration variant is set to 24 minutes. |
|
| 107 | + * |
|
| 108 | + * As a result, the session expiration time - at a maximum - will only be written to the database once |
|
| 109 | + * every 24 minutes. After 30 minutes, the session will have been expired. No cookie will be sent by |
|
| 110 | + * the browser, and the old session will be queued for deletion by the garbage collector. |
|
| 111 | + * |
|
| 112 | + * @uses apply_filters Calls `wp_session_expiration_variant` to get the max update window for session data. |
|
| 113 | + * @uses apply_filters Calls `wp_session_expiration` to get the standard expiration time for sessions. |
|
| 114 | + */ |
|
| 115 | + protected function set_expiration() { |
|
| 116 | + $this->exp_variant = time() + (int) apply_filters( 'wp_session_expiration_variant', 24 * 60 ); |
|
| 117 | + $this->expires = time() + (int) apply_filters( 'wp_session_expiration', 30 * 60 ); |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + /** |
|
| 121 | + * Set the session cookie |
|
| 122 | + * @uses apply_filters Calls `wp_session_cookie_secure` to set the $secure parameter of setcookie() |
|
| 123 | + * @uses apply_filters Calls `wp_session_cookie_httponly` to set the $httponly parameter of setcookie() |
|
| 124 | + */ |
|
| 125 | + protected function set_cookie() { |
|
| 126 | + if ( !defined( 'WPI_TESTING_MODE' ) ) { |
|
| 127 | + try { |
|
| 128 | + $secure = apply_filters('wp_session_cookie_secure', false); |
|
| 129 | + $httponly = apply_filters('wp_session_cookie_httponly', false); |
|
| 130 | + setcookie( WP_SESSION_COOKIE, $this->session_id . '||' . $this->expires . '||' . $this->exp_variant , $this->expires, COOKIEPATH, COOKIE_DOMAIN, $secure, $httponly ); |
|
| 131 | + } catch(Exception $e) { |
|
| 132 | + error_log( 'Set Cookie Error: ' . $e->getMessage() ); |
|
| 133 | + } |
|
| 134 | + } |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + /** |
|
| 138 | + * Read data from a transient for the current session. |
|
| 139 | + * |
|
| 140 | + * Automatically resets the expiration time for the session transient to some time in the future. |
|
| 141 | + * |
|
| 142 | + * @return array |
|
| 143 | + */ |
|
| 144 | + protected function read_data() { |
|
| 145 | + $this->container = get_option( "_wp_session_{$this->session_id}", array() ); |
|
| 146 | + |
|
| 147 | + return $this->container; |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + /** |
|
| 151 | + * Write the data from the current session to the data storage system. |
|
| 152 | + */ |
|
| 153 | + public function write_data() { |
|
| 154 | + $option_key = "_wp_session_{$this->session_id}"; |
|
| 155 | 155 | |
| 156 | - if ( false === get_option( $option_key ) ) { |
|
| 157 | - add_option( "_wp_session_{$this->session_id}", $this->container, '', 'no' ); |
|
| 158 | - add_option( "_wp_session_expires_{$this->session_id}", $this->expires, '', 'no' ); |
|
| 159 | - } else { |
|
| 160 | - delete_option( "_wp_session_{$this->session_id}" ); |
|
| 161 | - add_option( "_wp_session_{$this->session_id}", $this->container, '', 'no' ); |
|
| 162 | - } |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - /** |
|
| 166 | - * Output the current container contents as a JSON-encoded string. |
|
| 167 | - * |
|
| 168 | - * @return string |
|
| 169 | - */ |
|
| 170 | - public function json_out() { |
|
| 171 | - return json_encode( $this->container ); |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - /** |
|
| 175 | - * Decodes a JSON string and, if the object is an array, overwrites the session container with its contents. |
|
| 176 | - * |
|
| 177 | - * @param string $data |
|
| 178 | - * |
|
| 179 | - * @return bool |
|
| 180 | - */ |
|
| 181 | - public function json_in( $data ) { |
|
| 182 | - $array = json_decode( $data ); |
|
| 183 | - |
|
| 184 | - if ( is_array( $array ) ) { |
|
| 185 | - $this->container = $array; |
|
| 186 | - return true; |
|
| 187 | - } |
|
| 188 | - |
|
| 189 | - return false; |
|
| 190 | - } |
|
| 191 | - |
|
| 192 | - /** |
|
| 193 | - * Regenerate the current session's ID. |
|
| 194 | - * |
|
| 195 | - * @param bool $delete_old Flag whether or not to delete the old session data from the server. |
|
| 196 | - */ |
|
| 197 | - public function regenerate_id( $delete_old = false ) { |
|
| 198 | - if ( $delete_old ) { |
|
| 199 | - delete_option( "_wp_session_{$this->session_id}" ); |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - $this->session_id = WP_Session_Utils::generate_id(); |
|
| 203 | - |
|
| 204 | - $this->set_cookie(); |
|
| 205 | - } |
|
| 206 | - |
|
| 207 | - /** |
|
| 208 | - * Check if a session has been initialized. |
|
| 209 | - * |
|
| 210 | - * @return bool |
|
| 211 | - */ |
|
| 212 | - public function session_started() { |
|
| 213 | - return !!self::$instance; |
|
| 214 | - } |
|
| 215 | - |
|
| 216 | - /** |
|
| 217 | - * Return the read-only cache expiration value. |
|
| 218 | - * |
|
| 219 | - * @return int |
|
| 220 | - */ |
|
| 221 | - public function cache_expiration() { |
|
| 222 | - return $this->expires; |
|
| 223 | - } |
|
| 224 | - |
|
| 225 | - /** |
|
| 226 | - * Flushes all session variables. |
|
| 227 | - */ |
|
| 228 | - public function reset() { |
|
| 229 | - $this->container = array(); |
|
| 230 | - } |
|
| 156 | + if ( false === get_option( $option_key ) ) { |
|
| 157 | + add_option( "_wp_session_{$this->session_id}", $this->container, '', 'no' ); |
|
| 158 | + add_option( "_wp_session_expires_{$this->session_id}", $this->expires, '', 'no' ); |
|
| 159 | + } else { |
|
| 160 | + delete_option( "_wp_session_{$this->session_id}" ); |
|
| 161 | + add_option( "_wp_session_{$this->session_id}", $this->container, '', 'no' ); |
|
| 162 | + } |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + /** |
|
| 166 | + * Output the current container contents as a JSON-encoded string. |
|
| 167 | + * |
|
| 168 | + * @return string |
|
| 169 | + */ |
|
| 170 | + public function json_out() { |
|
| 171 | + return json_encode( $this->container ); |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + /** |
|
| 175 | + * Decodes a JSON string and, if the object is an array, overwrites the session container with its contents. |
|
| 176 | + * |
|
| 177 | + * @param string $data |
|
| 178 | + * |
|
| 179 | + * @return bool |
|
| 180 | + */ |
|
| 181 | + public function json_in( $data ) { |
|
| 182 | + $array = json_decode( $data ); |
|
| 183 | + |
|
| 184 | + if ( is_array( $array ) ) { |
|
| 185 | + $this->container = $array; |
|
| 186 | + return true; |
|
| 187 | + } |
|
| 188 | + |
|
| 189 | + return false; |
|
| 190 | + } |
|
| 191 | + |
|
| 192 | + /** |
|
| 193 | + * Regenerate the current session's ID. |
|
| 194 | + * |
|
| 195 | + * @param bool $delete_old Flag whether or not to delete the old session data from the server. |
|
| 196 | + */ |
|
| 197 | + public function regenerate_id( $delete_old = false ) { |
|
| 198 | + if ( $delete_old ) { |
|
| 199 | + delete_option( "_wp_session_{$this->session_id}" ); |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + $this->session_id = WP_Session_Utils::generate_id(); |
|
| 203 | + |
|
| 204 | + $this->set_cookie(); |
|
| 205 | + } |
|
| 206 | + |
|
| 207 | + /** |
|
| 208 | + * Check if a session has been initialized. |
|
| 209 | + * |
|
| 210 | + * @return bool |
|
| 211 | + */ |
|
| 212 | + public function session_started() { |
|
| 213 | + return !!self::$instance; |
|
| 214 | + } |
|
| 215 | + |
|
| 216 | + /** |
|
| 217 | + * Return the read-only cache expiration value. |
|
| 218 | + * |
|
| 219 | + * @return int |
|
| 220 | + */ |
|
| 221 | + public function cache_expiration() { |
|
| 222 | + return $this->expires; |
|
| 223 | + } |
|
| 224 | + |
|
| 225 | + /** |
|
| 226 | + * Flushes all session variables. |
|
| 227 | + */ |
|
| 228 | + public function reset() { |
|
| 229 | + $this->container = array(); |
|
| 230 | + } |
|
| 231 | 231 | } |
@@ -53,7 +53,7 @@ discard block |
||
| 53 | 53 | * @return bool|WP_Session |
| 54 | 54 | */ |
| 55 | 55 | public static function get_instance() { |
| 56 | - if ( ! self::$instance ) { |
|
| 56 | + if (!self::$instance) { |
|
| 57 | 57 | self::$instance = new self(); |
| 58 | 58 | } |
| 59 | 59 | |
@@ -69,19 +69,19 @@ discard block |
||
| 69 | 69 | * @uses apply_filters Calls `wp_session_expiration` to determine how long until sessions expire. |
| 70 | 70 | */ |
| 71 | 71 | protected function __construct() { |
| 72 | - if ( isset( $_COOKIE[WP_SESSION_COOKIE] ) ) { |
|
| 73 | - $cookie = stripslashes( $_COOKIE[WP_SESSION_COOKIE] ); |
|
| 74 | - $cookie_crumbs = explode( '||', $cookie ); |
|
| 72 | + if (isset($_COOKIE[WP_SESSION_COOKIE])) { |
|
| 73 | + $cookie = stripslashes($_COOKIE[WP_SESSION_COOKIE]); |
|
| 74 | + $cookie_crumbs = explode('||', $cookie); |
|
| 75 | 75 | |
| 76 | - $this->session_id = preg_replace("/[^A-Za-z0-9_]/", '', $cookie_crumbs[0] ); |
|
| 77 | - $this->expires = absint( $cookie_crumbs[1] ); |
|
| 78 | - $this->exp_variant = absint( $cookie_crumbs[2] ); |
|
| 76 | + $this->session_id = preg_replace("/[^A-Za-z0-9_]/", '', $cookie_crumbs[0]); |
|
| 77 | + $this->expires = absint($cookie_crumbs[1]); |
|
| 78 | + $this->exp_variant = absint($cookie_crumbs[2]); |
|
| 79 | 79 | |
| 80 | 80 | // Update the session expiration if we're past the variant time |
| 81 | - if ( time() > $this->exp_variant ) { |
|
| 81 | + if (time() > $this->exp_variant) { |
|
| 82 | 82 | $this->set_expiration(); |
| 83 | - delete_option( "_wp_session_expires_{$this->session_id}" ); |
|
| 84 | - add_option( "_wp_session_expires_{$this->session_id}", $this->expires, '', 'no' ); |
|
| 83 | + delete_option("_wp_session_expires_{$this->session_id}"); |
|
| 84 | + add_option("_wp_session_expires_{$this->session_id}", $this->expires, '', 'no'); |
|
| 85 | 85 | } |
| 86 | 86 | } else { |
| 87 | 87 | $this->session_id = WP_Session_Utils::generate_id(); |
@@ -113,8 +113,8 @@ discard block |
||
| 113 | 113 | * @uses apply_filters Calls `wp_session_expiration` to get the standard expiration time for sessions. |
| 114 | 114 | */ |
| 115 | 115 | protected function set_expiration() { |
| 116 | - $this->exp_variant = time() + (int) apply_filters( 'wp_session_expiration_variant', 24 * 60 ); |
|
| 117 | - $this->expires = time() + (int) apply_filters( 'wp_session_expiration', 30 * 60 ); |
|
| 116 | + $this->exp_variant = time() + (int)apply_filters('wp_session_expiration_variant', 24 * 60); |
|
| 117 | + $this->expires = time() + (int)apply_filters('wp_session_expiration', 30 * 60); |
|
| 118 | 118 | } |
| 119 | 119 | |
| 120 | 120 | /** |
@@ -123,13 +123,13 @@ discard block |
||
| 123 | 123 | * @uses apply_filters Calls `wp_session_cookie_httponly` to set the $httponly parameter of setcookie() |
| 124 | 124 | */ |
| 125 | 125 | protected function set_cookie() { |
| 126 | - if ( !defined( 'WPI_TESTING_MODE' ) ) { |
|
| 126 | + if (!defined('WPI_TESTING_MODE')) { |
|
| 127 | 127 | try { |
| 128 | 128 | $secure = apply_filters('wp_session_cookie_secure', false); |
| 129 | 129 | $httponly = apply_filters('wp_session_cookie_httponly', false); |
| 130 | - setcookie( WP_SESSION_COOKIE, $this->session_id . '||' . $this->expires . '||' . $this->exp_variant , $this->expires, COOKIEPATH, COOKIE_DOMAIN, $secure, $httponly ); |
|
| 131 | - } catch(Exception $e) { |
|
| 132 | - error_log( 'Set Cookie Error: ' . $e->getMessage() ); |
|
| 130 | + setcookie(WP_SESSION_COOKIE, $this->session_id . '||' . $this->expires . '||' . $this->exp_variant, $this->expires, COOKIEPATH, COOKIE_DOMAIN, $secure, $httponly); |
|
| 131 | + } catch (Exception $e) { |
|
| 132 | + error_log('Set Cookie Error: ' . $e->getMessage()); |
|
| 133 | 133 | } |
| 134 | 134 | } |
| 135 | 135 | } |
@@ -142,7 +142,7 @@ discard block |
||
| 142 | 142 | * @return array |
| 143 | 143 | */ |
| 144 | 144 | protected function read_data() { |
| 145 | - $this->container = get_option( "_wp_session_{$this->session_id}", array() ); |
|
| 145 | + $this->container = get_option("_wp_session_{$this->session_id}", array()); |
|
| 146 | 146 | |
| 147 | 147 | return $this->container; |
| 148 | 148 | } |
@@ -153,12 +153,12 @@ discard block |
||
| 153 | 153 | public function write_data() { |
| 154 | 154 | $option_key = "_wp_session_{$this->session_id}"; |
| 155 | 155 | |
| 156 | - if ( false === get_option( $option_key ) ) { |
|
| 157 | - add_option( "_wp_session_{$this->session_id}", $this->container, '', 'no' ); |
|
| 158 | - add_option( "_wp_session_expires_{$this->session_id}", $this->expires, '', 'no' ); |
|
| 156 | + if (false === get_option($option_key)) { |
|
| 157 | + add_option("_wp_session_{$this->session_id}", $this->container, '', 'no'); |
|
| 158 | + add_option("_wp_session_expires_{$this->session_id}", $this->expires, '', 'no'); |
|
| 159 | 159 | } else { |
| 160 | - delete_option( "_wp_session_{$this->session_id}" ); |
|
| 161 | - add_option( "_wp_session_{$this->session_id}", $this->container, '', 'no' ); |
|
| 160 | + delete_option("_wp_session_{$this->session_id}"); |
|
| 161 | + add_option("_wp_session_{$this->session_id}", $this->container, '', 'no'); |
|
| 162 | 162 | } |
| 163 | 163 | } |
| 164 | 164 | |
@@ -168,7 +168,7 @@ discard block |
||
| 168 | 168 | * @return string |
| 169 | 169 | */ |
| 170 | 170 | public function json_out() { |
| 171 | - return json_encode( $this->container ); |
|
| 171 | + return json_encode($this->container); |
|
| 172 | 172 | } |
| 173 | 173 | |
| 174 | 174 | /** |
@@ -178,10 +178,10 @@ discard block |
||
| 178 | 178 | * |
| 179 | 179 | * @return bool |
| 180 | 180 | */ |
| 181 | - public function json_in( $data ) { |
|
| 182 | - $array = json_decode( $data ); |
|
| 181 | + public function json_in($data) { |
|
| 182 | + $array = json_decode($data); |
|
| 183 | 183 | |
| 184 | - if ( is_array( $array ) ) { |
|
| 184 | + if (is_array($array)) { |
|
| 185 | 185 | $this->container = $array; |
| 186 | 186 | return true; |
| 187 | 187 | } |
@@ -194,9 +194,9 @@ discard block |
||
| 194 | 194 | * |
| 195 | 195 | * @param bool $delete_old Flag whether or not to delete the old session data from the server. |
| 196 | 196 | */ |
| 197 | - public function regenerate_id( $delete_old = false ) { |
|
| 198 | - if ( $delete_old ) { |
|
| 199 | - delete_option( "_wp_session_{$this->session_id}" ); |
|
| 197 | + public function regenerate_id($delete_old = false) { |
|
| 198 | + if ($delete_old) { |
|
| 199 | + delete_option("_wp_session_{$this->session_id}"); |
|
| 200 | 200 | } |
| 201 | 201 | |
| 202 | 202 | $this->session_id = WP_Session_Utils::generate_id(); |
@@ -407,6 +407,10 @@ discard block |
||
| 407 | 407 | exit; |
| 408 | 408 | } |
| 409 | 409 | |
| 410 | + /** |
|
| 411 | + * @param string $source_url |
|
| 412 | + * @param string $destination_file |
|
| 413 | + */ |
|
| 410 | 414 | public static function geoip2_download_file( $source_url, $destination_file ) { |
| 411 | 415 | $success = false; |
| 412 | 416 | $message = ''; |
@@ -1192,6 +1196,9 @@ discard block |
||
| 1192 | 1196 | return apply_filters( 'wpinv_response_euvatrates', $response, $group ); |
| 1193 | 1197 | } |
| 1194 | 1198 | |
| 1199 | + /** |
|
| 1200 | + * @param boolean $is_digital |
|
| 1201 | + */ |
|
| 1195 | 1202 | public static function requires_vat( $requires_vat = false, $user_id = 0, $is_digital = null ) { |
| 1196 | 1203 | global $wpi_item_id, $wpi_country; |
| 1197 | 1204 | |
@@ -1412,6 +1419,9 @@ discard block |
||
| 1412 | 1419 | return apply_filters( 'wpinv_item_is_taxable', $is_taxable, $item_id, $country , $state ); |
| 1413 | 1420 | } |
| 1414 | 1421 | |
| 1422 | + /** |
|
| 1423 | + * @param string|null $state |
|
| 1424 | + */ |
|
| 1415 | 1425 | public static function find_rate( $country, $state, $rate, $class ) { |
| 1416 | 1426 | global $wpi_zero_tax; |
| 1417 | 1427 | |
@@ -1,6 +1,8 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | // Exit if accessed directly. |
| 3 | -if (!defined( 'ABSPATH' ) ) exit; |
|
| 3 | +if (!defined( 'ABSPATH' ) ) { |
|
| 4 | + exit; |
|
| 5 | +} |
|
| 4 | 6 | |
| 5 | 7 | class WPInv_EUVat { |
| 6 | 8 | private static $is_ajax = false; |
@@ -1445,16 +1447,18 @@ discard block |
||
| 1445 | 1447 | |
| 1446 | 1448 | if ( !empty( $tax_rates ) ) { |
| 1447 | 1449 | foreach ( $tax_rates as $key => $tax_rate ) { |
| 1448 | - if ( $country != $tax_rate['country'] ) |
|
| 1449 | - continue; |
|
| 1450 | + if ( $country != $tax_rate['country'] ) { |
|
| 1451 | + continue; |
|
| 1452 | + } |
|
| 1450 | 1453 | |
| 1451 | 1454 | if ( !empty( $tax_rate['global'] ) ) { |
| 1452 | 1455 | if ( 0 !== $tax_rate['rate'] || !empty( $tax_rate['rate'] ) ) { |
| 1453 | 1456 | $rate = number_format( $tax_rate['rate'], 4 ); |
| 1454 | 1457 | } |
| 1455 | 1458 | } else { |
| 1456 | - if ( empty( $tax_rate['state'] ) || strtolower( $state ) != strtolower( $tax_rate['state'] ) ) |
|
| 1457 | - continue; |
|
| 1459 | + if ( empty( $tax_rate['state'] ) || strtolower( $state ) != strtolower( $tax_rate['state'] ) ) { |
|
| 1460 | + continue; |
|
| 1461 | + } |
|
| 1458 | 1462 | |
| 1459 | 1463 | $state_rate = $tax_rate['rate']; |
| 1460 | 1464 | if ( 0 !== $state_rate || !empty( $state_rate ) ) { |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | // Exit if accessed directly. |
| 3 | -if (!defined( 'ABSPATH' ) ) exit; |
|
| 3 | +if (!defined('ABSPATH')) exit; |
|
| 4 | 4 | |
| 5 | 5 | class WPInv_EUVat { |
| 6 | 6 | private static $is_ajax = false; |
@@ -8,7 +8,7 @@ discard block |
||
| 8 | 8 | private static $instance = false; |
| 9 | 9 | |
| 10 | 10 | public static function get_instance() { |
| 11 | - if ( !self::$instance ) { |
|
| 11 | + if (!self::$instance) { |
|
| 12 | 12 | self::$instance = new self(); |
| 13 | 13 | self::$instance->actions(); |
| 14 | 14 | } |
@@ -17,132 +17,132 @@ discard block |
||
| 17 | 17 | } |
| 18 | 18 | |
| 19 | 19 | public function __construct() { |
| 20 | - self::$is_ajax = defined( 'DOING_AJAX' ) && DOING_AJAX; |
|
| 20 | + self::$is_ajax = defined('DOING_AJAX') && DOING_AJAX; |
|
| 21 | 21 | self::$default_country = wpinv_get_default_country(); |
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | public static function actions() { |
| 25 | - if ( is_admin() ) { |
|
| 26 | - add_action( 'admin_enqueue_scripts', array( self::$instance, 'enqueue_admin_scripts' ) ); |
|
| 27 | - add_action( 'wpinv_settings_sections_taxes', array( self::$instance, 'section_vat_settings' ) ); |
|
| 28 | - add_action( 'wpinv_settings_taxes', array( self::$instance, 'vat_settings' ) ); |
|
| 29 | - add_filter( 'wpinv_settings_taxes-vat_sanitize', array( self::$instance, 'sanitize_vat_settings' ) ); |
|
| 30 | - add_filter( 'wpinv_settings_taxes-vat_rates_sanitize', array( self::$instance, 'sanitize_vat_rates' ) ); |
|
| 31 | - add_action( 'wp_ajax_wpinv_add_vat_class', array( self::$instance, 'add_class' ) ); |
|
| 32 | - add_action( 'wp_ajax_nopriv_wpinv_add_vat_class', array( self::$instance, 'add_class' ) ); |
|
| 33 | - add_action( 'wp_ajax_wpinv_delete_vat_class', array( self::$instance, 'delete_class' ) ); |
|
| 34 | - add_action( 'wp_ajax_nopriv_wpinv_delete_vat_class', array( self::$instance, 'delete_class' ) ); |
|
| 35 | - add_action( 'wp_ajax_wpinv_update_vat_rates', array( self::$instance, 'update_eu_rates' ) ); |
|
| 36 | - add_action( 'wp_ajax_nopriv_wpinv_update_vat_rates', array( self::$instance, 'update_eu_rates' ) ); |
|
| 37 | - add_action( 'wp_ajax_wpinv_geoip2', array( self::$instance, 'geoip2_download_database' ) ); |
|
| 38 | - add_action( 'wp_ajax_nopriv_wpinv_geoip2', array( self::$instance, 'geoip2_download_database' ) ); |
|
| 39 | - } |
|
| 40 | - |
|
| 41 | - add_action( 'wp_enqueue_scripts', array( self::$instance, 'enqueue_vat_scripts' ) ); |
|
| 42 | - add_filter( 'wpinv_default_billing_country', array( self::$instance, 'get_user_country' ), 10 ); |
|
| 43 | - add_filter( 'wpinv_get_user_country', array( self::$instance, 'set_user_country' ), 10 ); |
|
| 44 | - add_action( 'wp_ajax_wpinv_vat_validate', array( self::$instance, 'ajax_vat_validate' ) ); |
|
| 45 | - add_action( 'wp_ajax_nopriv_wpinv_vat_validate', array( self::$instance, 'ajax_vat_validate' ) ); |
|
| 46 | - add_action( 'wp_ajax_wpinv_vat_reset', array( self::$instance, 'ajax_vat_reset' ) ); |
|
| 47 | - add_action( 'wp_ajax_nopriv_wpinv_vat_reset', array( self::$instance, 'ajax_vat_reset' ) ); |
|
| 48 | - add_action( 'wpinv_invoice_print_after_line_items', array( self::$instance, 'show_vat_notice' ), 999, 1 ); |
|
| 49 | - if ( wpinv_use_taxes() ) { |
|
| 50 | - add_action( 'wpinv_after_billing_fields', array( self::$instance, 'checkout_vat_fields' ) ); |
|
| 51 | - if ( self::allow_vat_rules() ) { |
|
| 52 | - add_action( 'wpinv_checkout_error_checks', array( self::$instance, 'checkout_vat_validate' ), 10, 2 ); |
|
| 53 | - add_filter( 'wpinv_tax_rate', array( self::$instance, 'get_rate' ), 10, 4 ); |
|
| 25 | + if (is_admin()) { |
|
| 26 | + add_action('admin_enqueue_scripts', array(self::$instance, 'enqueue_admin_scripts')); |
|
| 27 | + add_action('wpinv_settings_sections_taxes', array(self::$instance, 'section_vat_settings')); |
|
| 28 | + add_action('wpinv_settings_taxes', array(self::$instance, 'vat_settings')); |
|
| 29 | + add_filter('wpinv_settings_taxes-vat_sanitize', array(self::$instance, 'sanitize_vat_settings')); |
|
| 30 | + add_filter('wpinv_settings_taxes-vat_rates_sanitize', array(self::$instance, 'sanitize_vat_rates')); |
|
| 31 | + add_action('wp_ajax_wpinv_add_vat_class', array(self::$instance, 'add_class')); |
|
| 32 | + add_action('wp_ajax_nopriv_wpinv_add_vat_class', array(self::$instance, 'add_class')); |
|
| 33 | + add_action('wp_ajax_wpinv_delete_vat_class', array(self::$instance, 'delete_class')); |
|
| 34 | + add_action('wp_ajax_nopriv_wpinv_delete_vat_class', array(self::$instance, 'delete_class')); |
|
| 35 | + add_action('wp_ajax_wpinv_update_vat_rates', array(self::$instance, 'update_eu_rates')); |
|
| 36 | + add_action('wp_ajax_nopriv_wpinv_update_vat_rates', array(self::$instance, 'update_eu_rates')); |
|
| 37 | + add_action('wp_ajax_wpinv_geoip2', array(self::$instance, 'geoip2_download_database')); |
|
| 38 | + add_action('wp_ajax_nopriv_wpinv_geoip2', array(self::$instance, 'geoip2_download_database')); |
|
| 39 | + } |
|
| 40 | + |
|
| 41 | + add_action('wp_enqueue_scripts', array(self::$instance, 'enqueue_vat_scripts')); |
|
| 42 | + add_filter('wpinv_default_billing_country', array(self::$instance, 'get_user_country'), 10); |
|
| 43 | + add_filter('wpinv_get_user_country', array(self::$instance, 'set_user_country'), 10); |
|
| 44 | + add_action('wp_ajax_wpinv_vat_validate', array(self::$instance, 'ajax_vat_validate')); |
|
| 45 | + add_action('wp_ajax_nopriv_wpinv_vat_validate', array(self::$instance, 'ajax_vat_validate')); |
|
| 46 | + add_action('wp_ajax_wpinv_vat_reset', array(self::$instance, 'ajax_vat_reset')); |
|
| 47 | + add_action('wp_ajax_nopriv_wpinv_vat_reset', array(self::$instance, 'ajax_vat_reset')); |
|
| 48 | + add_action('wpinv_invoice_print_after_line_items', array(self::$instance, 'show_vat_notice'), 999, 1); |
|
| 49 | + if (wpinv_use_taxes()) { |
|
| 50 | + add_action('wpinv_after_billing_fields', array(self::$instance, 'checkout_vat_fields')); |
|
| 51 | + if (self::allow_vat_rules()) { |
|
| 52 | + add_action('wpinv_checkout_error_checks', array(self::$instance, 'checkout_vat_validate'), 10, 2); |
|
| 53 | + add_filter('wpinv_tax_rate', array(self::$instance, 'get_rate'), 10, 4); |
|
| 54 | 54 | } |
| 55 | 55 | } |
| 56 | 56 | } |
| 57 | 57 | |
| 58 | - public static function get_eu_states( $sort = true ) { |
|
| 59 | - $eu_states = array( 'AT', 'BE', 'BG', 'HR', 'CY', 'CZ', 'DK', 'EE', 'FI', 'FR', 'DE', 'GB', 'GR', 'HU', 'IE', 'IT', 'LV', 'LT', 'LU', 'MT', 'NL', 'PL', 'PT', 'RO', 'SK', 'SI', 'ES', 'SE' ); |
|
| 60 | - if ( $sort ) { |
|
| 61 | - $sort = sort( $eu_states ); |
|
| 58 | + public static function get_eu_states($sort = true) { |
|
| 59 | + $eu_states = array('AT', 'BE', 'BG', 'HR', 'CY', 'CZ', 'DK', 'EE', 'FI', 'FR', 'DE', 'GB', 'GR', 'HU', 'IE', 'IT', 'LV', 'LT', 'LU', 'MT', 'NL', 'PL', 'PT', 'RO', 'SK', 'SI', 'ES', 'SE'); |
|
| 60 | + if ($sort) { |
|
| 61 | + $sort = sort($eu_states); |
|
| 62 | 62 | } |
| 63 | 63 | |
| 64 | - return apply_filters( 'wpinv_get_eu_states', $eu_states, $sort ); |
|
| 64 | + return apply_filters('wpinv_get_eu_states', $eu_states, $sort); |
|
| 65 | 65 | } |
| 66 | 66 | |
| 67 | - public static function get_gst_countries( $sort = true ) { |
|
| 68 | - $gst_countries = array( 'AU', 'NZ', 'CA', 'CN' ); |
|
| 67 | + public static function get_gst_countries($sort = true) { |
|
| 68 | + $gst_countries = array('AU', 'NZ', 'CA', 'CN'); |
|
| 69 | 69 | |
| 70 | - if ( $sort ) { |
|
| 71 | - $sort = sort( $gst_countries ); |
|
| 70 | + if ($sort) { |
|
| 71 | + $sort = sort($gst_countries); |
|
| 72 | 72 | } |
| 73 | 73 | |
| 74 | - return apply_filters( 'wpinv_get_gst_countries', $gst_countries, $sort ); |
|
| 74 | + return apply_filters('wpinv_get_gst_countries', $gst_countries, $sort); |
|
| 75 | 75 | } |
| 76 | 76 | |
| 77 | - public static function is_eu_state( $country_code ) { |
|
| 78 | - $return = !empty( $country_code ) && in_array( strtoupper( $country_code ), self::get_eu_states() ) ? true : false; |
|
| 77 | + public static function is_eu_state($country_code) { |
|
| 78 | + $return = !empty($country_code) && in_array(strtoupper($country_code), self::get_eu_states()) ? true : false; |
|
| 79 | 79 | |
| 80 | - return apply_filters( 'wpinv_is_eu_state', $return, $country_code ); |
|
| 80 | + return apply_filters('wpinv_is_eu_state', $return, $country_code); |
|
| 81 | 81 | } |
| 82 | 82 | |
| 83 | - public static function is_gst_country( $country_code ) { |
|
| 84 | - $return = !empty( $country_code ) && in_array( strtoupper( $country_code ), self::get_gst_countries() ) ? true : false; |
|
| 83 | + public static function is_gst_country($country_code) { |
|
| 84 | + $return = !empty($country_code) && in_array(strtoupper($country_code), self::get_gst_countries()) ? true : false; |
|
| 85 | 85 | |
| 86 | - return apply_filters( 'wpinv_is_gst_country', $return, $country_code ); |
|
| 86 | + return apply_filters('wpinv_is_gst_country', $return, $country_code); |
|
| 87 | 87 | } |
| 88 | 88 | |
| 89 | 89 | public static function enqueue_vat_scripts() { |
| 90 | - $suffix = '';//defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
| 90 | + $suffix = ''; //defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
| 91 | 91 | |
| 92 | - wp_register_script( 'wpinv-vat-validation-script', WPINV_PLUGIN_URL . 'assets/js/jsvat' . $suffix . '.js', array( 'jquery' ), WPINV_VERSION ); |
|
| 93 | - wp_register_script( 'wpinv-vat-script', WPINV_PLUGIN_URL . 'assets/js/euvat' . $suffix . '.js', array( 'jquery' ), WPINV_VERSION ); |
|
| 92 | + wp_register_script('wpinv-vat-validation-script', WPINV_PLUGIN_URL . 'assets/js/jsvat' . $suffix . '.js', array('jquery'), WPINV_VERSION); |
|
| 93 | + wp_register_script('wpinv-vat-script', WPINV_PLUGIN_URL . 'assets/js/euvat' . $suffix . '.js', array('jquery'), WPINV_VERSION); |
|
| 94 | 94 | |
| 95 | - $vat_name = self::get_vat_name(); |
|
| 95 | + $vat_name = self::get_vat_name(); |
|
| 96 | 96 | |
| 97 | 97 | $vars = array(); |
| 98 | 98 | $vars['UseTaxes'] = wpinv_use_taxes(); |
| 99 | 99 | $vars['EUStates'] = self::get_eu_states(); |
| 100 | - $vars['NoRateSet'] = __( 'You have not set a rate. Do you want to continue?', 'invoicing' ); |
|
| 101 | - $vars['EmptyCompany'] = __( 'Please enter your registered company name!', 'invoicing' ); |
|
| 102 | - $vars['EmptyVAT'] = wp_sprintf( __( 'Please enter your %s number!', 'invoicing' ), $vat_name ); |
|
| 103 | - $vars['TotalsRefreshed'] = wp_sprintf( __( 'The invoice totals will be refreshed to update the %s.', 'invoicing' ), $vat_name ); |
|
| 104 | - $vars['ErrValidateVAT'] = wp_sprintf( __( 'Fail to validate the %s number!', 'invoicing' ), $vat_name ); |
|
| 105 | - $vars['ErrResetVAT'] = wp_sprintf( __( 'Fail to reset the %s number!', 'invoicing' ), $vat_name ); |
|
| 106 | - $vars['ErrInvalidVat'] = wp_sprintf( __( 'The %s number supplied does not have a valid format!', 'invoicing' ), $vat_name ); |
|
| 107 | - $vars['ErrInvalidResponse'] = __( 'An invalid response has been received from the server!', 'invoicing' ); |
|
| 100 | + $vars['NoRateSet'] = __('You have not set a rate. Do you want to continue?', 'invoicing'); |
|
| 101 | + $vars['EmptyCompany'] = __('Please enter your registered company name!', 'invoicing'); |
|
| 102 | + $vars['EmptyVAT'] = wp_sprintf(__('Please enter your %s number!', 'invoicing'), $vat_name); |
|
| 103 | + $vars['TotalsRefreshed'] = wp_sprintf(__('The invoice totals will be refreshed to update the %s.', 'invoicing'), $vat_name); |
|
| 104 | + $vars['ErrValidateVAT'] = wp_sprintf(__('Fail to validate the %s number!', 'invoicing'), $vat_name); |
|
| 105 | + $vars['ErrResetVAT'] = wp_sprintf(__('Fail to reset the %s number!', 'invoicing'), $vat_name); |
|
| 106 | + $vars['ErrInvalidVat'] = wp_sprintf(__('The %s number supplied does not have a valid format!', 'invoicing'), $vat_name); |
|
| 107 | + $vars['ErrInvalidResponse'] = __('An invalid response has been received from the server!', 'invoicing'); |
|
| 108 | 108 | $vars['ApplyVATRules'] = $vars['UseTaxes'] ? self::allow_vat_rules() : false; |
| 109 | 109 | $vars['HideVatFields'] = $vars['ApplyVATRules'] ? self::hide_vat_fields() : true; |
| 110 | - $vars['ErrResponse'] = __( 'The request response is invalid!', 'invoicing' ); |
|
| 111 | - $vars['ErrRateResponse'] = __( 'The get rate request response is invalid', 'invoicing' ); |
|
| 112 | - $vars['PageRefresh'] = __( 'The page will be refreshed in 10 seconds to show the new options.', 'invoicing' ); |
|
| 113 | - $vars['RequestResponseNotValidJSON'] = __( 'The get rate request response is not valid JSON', 'invoicing' ); |
|
| 114 | - $vars['GetRateRequestFailed'] = __( 'The get rate request failed: ', 'invoicing' ); |
|
| 115 | - $vars['NoRateInformationInResponse'] = __( 'The get rate request response does not contain any rate information', 'invoicing' ); |
|
| 116 | - $vars['RatesUpdated'] = __( 'The rates have been updated. Press the save button to record these new rates.', 'invoicing' ); |
|
| 117 | - $vars['IPAddressInformation'] = __( 'IP Address Information', 'invoicing' ); |
|
| 118 | - $vars['VatValidating'] = wp_sprintf( __( 'Validating %s number...', 'invoicing' ), $vat_name ); |
|
| 119 | - $vars['VatReseting'] = __( 'Reseting...', 'invoicing' ); |
|
| 120 | - $vars['VatValidated'] = wp_sprintf( __( '%s number validated', 'invoicing' ), $vat_name ); |
|
| 121 | - $vars['VatNotValidated'] = wp_sprintf( __( '%s number not validated', 'invoicing' ), $vat_name ); |
|
| 122 | - $vars['ConfirmDeleteClass'] = __( 'Are you sure you wish to delete this rates class?', 'invoicing' ); |
|
| 110 | + $vars['ErrResponse'] = __('The request response is invalid!', 'invoicing'); |
|
| 111 | + $vars['ErrRateResponse'] = __('The get rate request response is invalid', 'invoicing'); |
|
| 112 | + $vars['PageRefresh'] = __('The page will be refreshed in 10 seconds to show the new options.', 'invoicing'); |
|
| 113 | + $vars['RequestResponseNotValidJSON'] = __('The get rate request response is not valid JSON', 'invoicing'); |
|
| 114 | + $vars['GetRateRequestFailed'] = __('The get rate request failed: ', 'invoicing'); |
|
| 115 | + $vars['NoRateInformationInResponse'] = __('The get rate request response does not contain any rate information', 'invoicing'); |
|
| 116 | + $vars['RatesUpdated'] = __('The rates have been updated. Press the save button to record these new rates.', 'invoicing'); |
|
| 117 | + $vars['IPAddressInformation'] = __('IP Address Information', 'invoicing'); |
|
| 118 | + $vars['VatValidating'] = wp_sprintf(__('Validating %s number...', 'invoicing'), $vat_name); |
|
| 119 | + $vars['VatReseting'] = __('Reseting...', 'invoicing'); |
|
| 120 | + $vars['VatValidated'] = wp_sprintf(__('%s number validated', 'invoicing'), $vat_name); |
|
| 121 | + $vars['VatNotValidated'] = wp_sprintf(__('%s number not validated', 'invoicing'), $vat_name); |
|
| 122 | + $vars['ConfirmDeleteClass'] = __('Are you sure you wish to delete this rates class?', 'invoicing'); |
|
| 123 | 123 | $vars['isFront'] = is_admin() ? false : true; |
| 124 | - $vars['checkoutNonce'] = wp_create_nonce( 'wpinv_checkout_nonce' ); |
|
| 124 | + $vars['checkoutNonce'] = wp_create_nonce('wpinv_checkout_nonce'); |
|
| 125 | 125 | $vars['baseCountry'] = wpinv_get_default_country(); |
| 126 | - $vars['disableVATSameCountry'] = ( self::same_country_rule() == 'no' ? true : false ); |
|
| 127 | - $vars['disableVATSimpleCheck'] = wpinv_get_option( 'vat_offline_check' ) ? true : false; |
|
| 126 | + $vars['disableVATSameCountry'] = (self::same_country_rule() == 'no' ? true : false); |
|
| 127 | + $vars['disableVATSimpleCheck'] = wpinv_get_option('vat_offline_check') ? true : false; |
|
| 128 | 128 | |
| 129 | - wp_enqueue_script( 'wpinv-vat-validation-script' ); |
|
| 130 | - wp_enqueue_script( 'wpinv-vat-script' ); |
|
| 131 | - wp_localize_script( 'wpinv-vat-script', 'WPInv_VAT_Vars', $vars ); |
|
| 129 | + wp_enqueue_script('wpinv-vat-validation-script'); |
|
| 130 | + wp_enqueue_script('wpinv-vat-script'); |
|
| 131 | + wp_localize_script('wpinv-vat-script', 'WPInv_VAT_Vars', $vars); |
|
| 132 | 132 | } |
| 133 | 133 | |
| 134 | 134 | public static function enqueue_admin_scripts() { |
| 135 | - if( isset( $_GET['page'] ) && 'wpinv-settings' == $_GET['page'] ) { |
|
| 135 | + if (isset($_GET['page']) && 'wpinv-settings' == $_GET['page']) { |
|
| 136 | 136 | self::enqueue_vat_scripts(); |
| 137 | 137 | } |
| 138 | 138 | } |
| 139 | 139 | |
| 140 | - public static function section_vat_settings( $sections ) { |
|
| 141 | - if ( !empty( $sections ) ) { |
|
| 142 | - $sections['vat'] = __( 'EU VAT Settings', 'invoicing' ); |
|
| 140 | + public static function section_vat_settings($sections) { |
|
| 141 | + if (!empty($sections)) { |
|
| 142 | + $sections['vat'] = __('EU VAT Settings', 'invoicing'); |
|
| 143 | 143 | |
| 144 | - if ( self::allow_vat_classes() ) { |
|
| 145 | - $sections['vat_rates'] = __( 'EU VAT Rates', 'invoicing' ); |
|
| 144 | + if (self::allow_vat_classes()) { |
|
| 145 | + $sections['vat_rates'] = __('EU VAT Rates', 'invoicing'); |
|
| 146 | 146 | } |
| 147 | 147 | } |
| 148 | 148 | return $sections; |
@@ -151,52 +151,52 @@ discard block |
||
| 151 | 151 | public static function vat_rates_settings() { |
| 152 | 152 | $vat_classes = self::get_rate_classes(); |
| 153 | 153 | $vat_rates = array(); |
| 154 | - $vat_class = isset( $_REQUEST['wpi_sub'] ) && $_REQUEST['wpi_sub'] !== '' && isset( $vat_classes[$_REQUEST['wpi_sub']] )? sanitize_text_field( $_REQUEST['wpi_sub'] ) : '_new'; |
|
| 155 | - $current_url = remove_query_arg( 'wpi_sub' ); |
|
| 154 | + $vat_class = isset($_REQUEST['wpi_sub']) && $_REQUEST['wpi_sub'] !== '' && isset($vat_classes[$_REQUEST['wpi_sub']]) ? sanitize_text_field($_REQUEST['wpi_sub']) : '_new'; |
|
| 155 | + $current_url = remove_query_arg('wpi_sub'); |
|
| 156 | 156 | |
| 157 | 157 | $vat_rates['vat_rates_header'] = array( |
| 158 | 158 | 'id' => 'vat_rates_header', |
| 159 | - 'name' => '<h3>' . __( 'Manage VAT Rates', 'invoicing' ) . '</h3>', |
|
| 159 | + 'name' => '<h3>' . __('Manage VAT Rates', 'invoicing') . '</h3>', |
|
| 160 | 160 | 'desc' => '', |
| 161 | 161 | 'type' => 'header', |
| 162 | 162 | 'size' => 'regular' |
| 163 | 163 | ); |
| 164 | 164 | $vat_rates['vat_rates_class'] = array( |
| 165 | 165 | 'id' => 'vat_rates_class', |
| 166 | - 'name' => __( 'Edit VAT Rates', 'invoicing' ), |
|
| 167 | - 'desc' => __( 'The standard rate will apply where no explicit rate is provided.', 'invoicing' ), |
|
| 166 | + 'name' => __('Edit VAT Rates', 'invoicing'), |
|
| 167 | + 'desc' => __('The standard rate will apply where no explicit rate is provided.', 'invoicing'), |
|
| 168 | 168 | 'type' => 'select', |
| 169 | - 'options' => array_merge( $vat_classes, array( '_new' => __( 'Add New Rate Class', 'invoicing' ) ) ), |
|
| 169 | + 'options' => array_merge($vat_classes, array('_new' => __('Add New Rate Class', 'invoicing'))), |
|
| 170 | 170 | 'chosen' => true, |
| 171 | - 'placeholder' => __( 'Select a VAT Rate', 'invoicing' ), |
|
| 171 | + 'placeholder' => __('Select a VAT Rate', 'invoicing'), |
|
| 172 | 172 | 'selected' => $vat_class, |
| 173 | 173 | 'onchange' => 'document.location.href="' . $current_url . '&wpi_sub=" + this.value;', |
| 174 | 174 | ); |
| 175 | 175 | |
| 176 | - if ( $vat_class != '_standard' && $vat_class != '_new' ) { |
|
| 176 | + if ($vat_class != '_standard' && $vat_class != '_new') { |
|
| 177 | 177 | $vat_rates['vat_rate_delete'] = array( |
| 178 | 178 | 'id' => 'vat_rate_delete', |
| 179 | 179 | 'type' => 'vat_rate_delete', |
| 180 | 180 | ); |
| 181 | 181 | } |
| 182 | 182 | |
| 183 | - if ( $vat_class == '_new' ) { |
|
| 183 | + if ($vat_class == '_new') { |
|
| 184 | 184 | $vat_rates['vat_rates_settings'] = array( |
| 185 | 185 | 'id' => 'vat_rates_settings', |
| 186 | - 'name' => '<h3>' . __( 'Add New Rate Class', 'invoicing' ) . '</h3>', |
|
| 186 | + 'name' => '<h3>' . __('Add New Rate Class', 'invoicing') . '</h3>', |
|
| 187 | 187 | 'type' => 'header', |
| 188 | 188 | ); |
| 189 | 189 | $vat_rates['vat_rate_name'] = array( |
| 190 | 190 | 'id' => 'vat_rate_name', |
| 191 | - 'name' => __( 'Name', 'invoicing' ), |
|
| 192 | - 'desc' => __( 'A short name for the new VAT Rate class', 'invoicing' ), |
|
| 191 | + 'name' => __('Name', 'invoicing'), |
|
| 192 | + 'desc' => __('A short name for the new VAT Rate class', 'invoicing'), |
|
| 193 | 193 | 'type' => 'text', |
| 194 | 194 | 'size' => 'regular', |
| 195 | 195 | ); |
| 196 | 196 | $vat_rates['vat_rate_desc'] = array( |
| 197 | 197 | 'id' => 'vat_rate_desc', |
| 198 | - 'name' => __( 'Description', 'invoicing' ), |
|
| 199 | - 'desc' => __( 'Manage VAT Rate class', 'invoicing' ), |
|
| 198 | + 'name' => __('Description', 'invoicing'), |
|
| 199 | + 'desc' => __('Manage VAT Rate class', 'invoicing'), |
|
| 200 | 200 | 'type' => 'text', |
| 201 | 201 | 'size' => 'regular', |
| 202 | 202 | ); |
@@ -208,7 +208,7 @@ discard block |
||
| 208 | 208 | $vat_rates['vat_rates'] = array( |
| 209 | 209 | 'id' => 'vat_rates', |
| 210 | 210 | 'name' => '<h3>' . $vat_classes[$vat_class] . '</h3>', |
| 211 | - 'desc' => self::get_class_desc( $vat_class ), |
|
| 211 | + 'desc' => self::get_class_desc($vat_class), |
|
| 212 | 212 | 'type' => 'vat_rates', |
| 213 | 213 | ); |
| 214 | 214 | } |
@@ -216,12 +216,12 @@ discard block |
||
| 216 | 216 | return $vat_rates; |
| 217 | 217 | } |
| 218 | 218 | |
| 219 | - public static function vat_settings( $settings ) { |
|
| 220 | - if ( !empty( $settings ) ) { |
|
| 219 | + public static function vat_settings($settings) { |
|
| 220 | + if (!empty($settings)) { |
|
| 221 | 221 | $vat_settings = array(); |
| 222 | 222 | $vat_settings['vat_company_title'] = array( |
| 223 | 223 | 'id' => 'vat_company_title', |
| 224 | - 'name' => '<h3>' . __( 'Your Company Details', 'invoicing' ) . '</h3>', |
|
| 224 | + 'name' => '<h3>' . __('Your Company Details', 'invoicing') . '</h3>', |
|
| 225 | 225 | 'desc' => '', |
| 226 | 226 | 'type' => 'header', |
| 227 | 227 | 'size' => 'regular' |
@@ -229,22 +229,22 @@ discard block |
||
| 229 | 229 | |
| 230 | 230 | $vat_settings['vat_company_name'] = array( |
| 231 | 231 | 'id' => 'vat_company_name', |
| 232 | - 'name' => __( 'Your Company Name', 'invoicing' ), |
|
| 233 | - 'desc' => wp_sprintf(__( 'Your company name as it appears on your VAT return, you can verify it via your VAT ID on the %sEU VIES System.%s', 'invoicing' ), '<a href="http://ec.europa.eu/taxation_customs/vies/" target="_blank">', '</a>' ), |
|
| 232 | + 'name' => __('Your Company Name', 'invoicing'), |
|
| 233 | + 'desc' => wp_sprintf(__('Your company name as it appears on your VAT return, you can verify it via your VAT ID on the %sEU VIES System.%s', 'invoicing'), '<a href="http://ec.europa.eu/taxation_customs/vies/" target="_blank">', '</a>'), |
|
| 234 | 234 | 'type' => 'text', |
| 235 | 235 | 'size' => 'regular', |
| 236 | 236 | ); |
| 237 | 237 | |
| 238 | 238 | $vat_settings['vat_number'] = array( |
| 239 | 239 | 'id' => 'vat_number', |
| 240 | - 'name' => __( 'Your VAT Number', 'invoicing' ), |
|
| 240 | + 'name' => __('Your VAT Number', 'invoicing'), |
|
| 241 | 241 | 'type' => 'vat_number', |
| 242 | 242 | 'size' => 'regular', |
| 243 | 243 | ); |
| 244 | 244 | |
| 245 | 245 | $vat_settings['vat_settings_title'] = array( |
| 246 | 246 | 'id' => 'vat_settings_title', |
| 247 | - 'name' => '<h3>' . __( 'Apply VAT Settings', 'invoicing' ) . '</h3>', |
|
| 247 | + 'name' => '<h3>' . __('Apply VAT Settings', 'invoicing') . '</h3>', |
|
| 248 | 248 | 'desc' => '', |
| 249 | 249 | 'type' => 'header', |
| 250 | 250 | 'size' => 'regular' |
@@ -252,8 +252,8 @@ discard block |
||
| 252 | 252 | |
| 253 | 253 | $vat_settings['apply_vat_rules'] = array( |
| 254 | 254 | 'id' => 'apply_vat_rules', |
| 255 | - 'name' => __( 'Enable VAT Rules', 'invoicing' ), |
|
| 256 | - 'desc' => __( 'Apply VAT to consumer sales from IP addresses within the EU, even if the billing address is outside the EU.', 'invoicing' ) . '<br><font style="color:red">' . __( 'Do not disable unless you know what you are doing.', 'invoicing' ) . '</font>', |
|
| 255 | + 'name' => __('Enable VAT Rules', 'invoicing'), |
|
| 256 | + 'desc' => __('Apply VAT to consumer sales from IP addresses within the EU, even if the billing address is outside the EU.', 'invoicing') . '<br><font style="color:red">' . __('Do not disable unless you know what you are doing.', 'invoicing') . '</font>', |
|
| 257 | 257 | 'type' => 'checkbox', |
| 258 | 258 | 'std' => '1' |
| 259 | 259 | ); |
@@ -269,8 +269,8 @@ discard block |
||
| 269 | 269 | |
| 270 | 270 | $vat_settings['vat_prevent_b2c_purchase'] = array( |
| 271 | 271 | 'id' => 'vat_prevent_b2c_purchase', |
| 272 | - 'name' => __( 'Prevent EU B2C Sales', 'invoicing' ), |
|
| 273 | - 'desc' => __( 'Enable this option if you are not registered for VAT in the EU.', 'invoicing' ), |
|
| 272 | + 'name' => __('Prevent EU B2C Sales', 'invoicing'), |
|
| 273 | + 'desc' => __('Enable this option if you are not registered for VAT in the EU.', 'invoicing'), |
|
| 274 | 274 | 'type' => 'checkbox' |
| 275 | 275 | ); |
| 276 | 276 | |
@@ -278,21 +278,21 @@ discard block |
||
| 278 | 278 | |
| 279 | 279 | $vat_settings['vat_same_country_rule'] = array( |
| 280 | 280 | 'id' => 'vat_same_country_rule', |
| 281 | - 'name' => __( 'Same Country Rule', 'invoicing' ), |
|
| 282 | - 'desc' => __( 'Select how you want to handle VAT charge if sales are in the same country as the base country.', 'invoicing' ), |
|
| 281 | + 'name' => __('Same Country Rule', 'invoicing'), |
|
| 282 | + 'desc' => __('Select how you want to handle VAT charge if sales are in the same country as the base country.', 'invoicing'), |
|
| 283 | 283 | 'type' => 'select', |
| 284 | 284 | 'options' => array( |
| 285 | - '' => __( 'Normal', 'invoicing' ), |
|
| 286 | - 'no' => __( 'No VAT', 'invoicing' ), |
|
| 287 | - 'always' => __( 'Always apply VAT', 'invoicing' ), |
|
| 285 | + '' => __('Normal', 'invoicing'), |
|
| 286 | + 'no' => __('No VAT', 'invoicing'), |
|
| 287 | + 'always' => __('Always apply VAT', 'invoicing'), |
|
| 288 | 288 | ), |
| 289 | - 'placeholder' => __( 'Select an option', 'invoicing' ), |
|
| 289 | + 'placeholder' => __('Select an option', 'invoicing'), |
|
| 290 | 290 | 'std' => '' |
| 291 | 291 | ); |
| 292 | 292 | |
| 293 | 293 | $vat_settings['vat_checkout_title'] = array( |
| 294 | 294 | 'id' => 'vat_checkout_title', |
| 295 | - 'name' => '<h3>' . __( 'Checkout Fields', 'invoicing' ) . '</h3>', |
|
| 295 | + 'name' => '<h3>' . __('Checkout Fields', 'invoicing') . '</h3>', |
|
| 296 | 296 | 'desc' => '', |
| 297 | 297 | 'type' => 'header', |
| 298 | 298 | 'size' => 'regular' |
@@ -300,14 +300,14 @@ discard block |
||
| 300 | 300 | |
| 301 | 301 | $vat_settings['vat_disable_fields'] = array( |
| 302 | 302 | 'id' => 'vat_disable_fields', |
| 303 | - 'name' => __( 'Disable VAT Fields', 'invoicing' ), |
|
| 304 | - 'desc' => __( 'Disable VAT fields if Invoicing is being used for GST.', 'invoicing' ) . '<br><font style="color:red">' . __( 'Do not disable if you have enabled Prevent EU B2C sales, otherwise Prevent EU B2C sales setting will not work.', 'invoicing' ) . '</font>', |
|
| 303 | + 'name' => __('Disable VAT Fields', 'invoicing'), |
|
| 304 | + 'desc' => __('Disable VAT fields if Invoicing is being used for GST.', 'invoicing') . '<br><font style="color:red">' . __('Do not disable if you have enabled Prevent EU B2C sales, otherwise Prevent EU B2C sales setting will not work.', 'invoicing') . '</font>', |
|
| 305 | 305 | 'type' => 'checkbox' |
| 306 | 306 | ); |
| 307 | 307 | |
| 308 | 308 | $vat_settings['vat_ip_lookup'] = array( |
| 309 | 309 | 'id' => 'vat_ip_lookup', |
| 310 | - 'name' => __( 'IP Country Look-up', 'invoicing' ), |
|
| 310 | + 'name' => __('IP Country Look-up', 'invoicing'), |
|
| 311 | 311 | 'type' => 'vat_ip_lookup', |
| 312 | 312 | 'size' => 'regular', |
| 313 | 313 | 'std' => 'default' |
@@ -315,21 +315,21 @@ discard block |
||
| 315 | 315 | |
| 316 | 316 | $vat_settings['hide_ip_address'] = array( |
| 317 | 317 | 'id' => 'hide_ip_address', |
| 318 | - 'name' => __( 'Hide IP Info at Checkout', 'invoicing' ), |
|
| 319 | - 'desc' => __( 'Hide the user IP info at checkout.', 'invoicing' ), |
|
| 318 | + 'name' => __('Hide IP Info at Checkout', 'invoicing'), |
|
| 319 | + 'desc' => __('Hide the user IP info at checkout.', 'invoicing'), |
|
| 320 | 320 | 'type' => 'checkbox' |
| 321 | 321 | ); |
| 322 | 322 | |
| 323 | 323 | $vat_settings['vat_ip_country_default'] = array( |
| 324 | 324 | 'id' => 'vat_ip_country_default', |
| 325 | - 'name' => __( 'Enable IP Country as Default', 'invoicing' ), |
|
| 326 | - 'desc' => __( 'Show the country of the users IP as the default country, otherwise the site default country will be used.', 'invoicing' ), |
|
| 325 | + 'name' => __('Enable IP Country as Default', 'invoicing'), |
|
| 326 | + 'desc' => __('Show the country of the users IP as the default country, otherwise the site default country will be used.', 'invoicing'), |
|
| 327 | 327 | 'type' => 'checkbox' |
| 328 | 328 | ); |
| 329 | 329 | |
| 330 | 330 | $vat_settings['vies_validation_title'] = array( |
| 331 | 331 | 'id' => 'vies_validation_title', |
| 332 | - 'name' => '<h3>' . __( 'VIES Validation', 'invoicing' ) . '</h3>', |
|
| 332 | + 'name' => '<h3>' . __('VIES Validation', 'invoicing') . '</h3>', |
|
| 333 | 333 | 'desc' => '', |
| 334 | 334 | 'type' => 'header', |
| 335 | 335 | 'size' => 'regular' |
@@ -337,37 +337,37 @@ discard block |
||
| 337 | 337 | |
| 338 | 338 | $vat_settings['vat_vies_check'] = array( |
| 339 | 339 | 'id' => 'vat_vies_check', |
| 340 | - 'name' => __( 'Disable VIES VAT ID Check', 'invoicing' ), |
|
| 341 | - 'desc' => wp_sprintf( __( 'Prevent VAT numbers from being validated by the %sEU VIES System.%s', 'invoicing' ), '<a href="http://ec.europa.eu/taxation_customs/vies/" target="_blank">', '</a>' ), |
|
| 340 | + 'name' => __('Disable VIES VAT ID Check', 'invoicing'), |
|
| 341 | + 'desc' => wp_sprintf(__('Prevent VAT numbers from being validated by the %sEU VIES System.%s', 'invoicing'), '<a href="http://ec.europa.eu/taxation_customs/vies/" target="_blank">', '</a>'), |
|
| 342 | 342 | 'type' => 'checkbox' |
| 343 | 343 | ); |
| 344 | 344 | |
| 345 | 345 | $vat_settings['vat_disable_company_name_check'] = array( |
| 346 | 346 | 'id' => 'vat_disable_company_name_check', |
| 347 | - 'name' => __( 'Disable VIES Name Check', 'invoicing' ), |
|
| 348 | - 'desc' => wp_sprintf( __( 'Prevent company name from being validated by the %sEU VIES System.%s', 'invoicing' ), '<a href="http://ec.europa.eu/taxation_customs/vies/" target="_blank">', '</a>' ), |
|
| 347 | + 'name' => __('Disable VIES Name Check', 'invoicing'), |
|
| 348 | + 'desc' => wp_sprintf(__('Prevent company name from being validated by the %sEU VIES System.%s', 'invoicing'), '<a href="http://ec.europa.eu/taxation_customs/vies/" target="_blank">', '</a>'), |
|
| 349 | 349 | 'type' => 'checkbox' |
| 350 | 350 | ); |
| 351 | 351 | |
| 352 | 352 | $vat_settings['vat_offline_check'] = array( |
| 353 | 353 | 'id' => 'vat_offline_check', |
| 354 | - 'name' => __( 'Disable Basic Checks', 'invoicing' ), |
|
| 355 | - 'desc' => __( 'This will disable basic JS correct format validation attempts, it is very rare this should need to be disabled.', 'invoicing' ), |
|
| 354 | + 'name' => __('Disable Basic Checks', 'invoicing'), |
|
| 355 | + 'desc' => __('This will disable basic JS correct format validation attempts, it is very rare this should need to be disabled.', 'invoicing'), |
|
| 356 | 356 | 'type' => 'checkbox' |
| 357 | 357 | ); |
| 358 | 358 | |
| 359 | 359 | |
| 360 | 360 | $settings['vat'] = $vat_settings; |
| 361 | 361 | |
| 362 | - if ( self::allow_vat_classes() ) { |
|
| 362 | + if (self::allow_vat_classes()) { |
|
| 363 | 363 | $settings['vat_rates'] = self::vat_rates_settings(); |
| 364 | 364 | } |
| 365 | 365 | |
| 366 | 366 | $eu_fallback_rate = array( |
| 367 | 367 | 'id' => 'eu_fallback_rate', |
| 368 | - 'name' => '<h3>' . __( 'VAT rate for EU member states', 'invoicing' ) . '</h3>', |
|
| 368 | + 'name' => '<h3>' . __('VAT rate for EU member states', 'invoicing') . '</h3>', |
|
| 369 | 369 | 'type' => 'eu_fallback_rate', |
| 370 | - 'desc' => __( 'Enter the VAT rate to be charged for EU member states. You can edit the rates for each member state when a country rate has been set up by pressing this button.', 'invoicing' ), |
|
| 370 | + 'desc' => __('Enter the VAT rate to be charged for EU member states. You can edit the rates for each member state when a country rate has been set up by pressing this button.', 'invoicing'), |
|
| 371 | 371 | 'std' => '20', |
| 372 | 372 | 'size' => 'small' |
| 373 | 373 | ); |
@@ -383,11 +383,11 @@ discard block |
||
| 383 | 383 | $database_url = 'http' . (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] === 'on' ? 's' : '') . '://geolite.maxmind.com/download/geoip/database/'; |
| 384 | 384 | $destination_dir = $upload_dir['basedir'] . '/invoicing'; |
| 385 | 385 | |
| 386 | - if ( !is_dir( $destination_dir ) ) { |
|
| 387 | - mkdir( $destination_dir ); |
|
| 386 | + if (!is_dir($destination_dir)) { |
|
| 387 | + mkdir($destination_dir); |
|
| 388 | 388 | } |
| 389 | 389 | |
| 390 | - $database_files = array( |
|
| 390 | + $database_files = array( |
|
| 391 | 391 | 'country' => array( |
| 392 | 392 | 'source' => $database_url . 'GeoLite2-Country.mmdb.gz', |
| 393 | 393 | 'destination' => $destination_dir . '/GeoLite2-Country.mmdb', |
@@ -398,57 +398,57 @@ discard block |
||
| 398 | 398 | ) |
| 399 | 399 | ); |
| 400 | 400 | |
| 401 | - foreach( $database_files as $database => $files ) { |
|
| 402 | - $result = self::geoip2_download_file( $files['source'], $files['destination'] ); |
|
| 401 | + foreach ($database_files as $database => $files) { |
|
| 402 | + $result = self::geoip2_download_file($files['source'], $files['destination']); |
|
| 403 | 403 | |
| 404 | - if ( empty( $result['success'] ) ) { |
|
| 404 | + if (empty($result['success'])) { |
|
| 405 | 405 | echo $result['message']; |
| 406 | 406 | exit; |
| 407 | 407 | } |
| 408 | 408 | |
| 409 | - wpinv_update_option( 'wpinv_geoip2_date_updated', current_time( 'timestamp' ) ); |
|
| 410 | - echo sprintf(__( 'GeoIp2 %s database updated successfully.', 'invoicing' ), $database ) . ' '; |
|
| 409 | + wpinv_update_option('wpinv_geoip2_date_updated', current_time('timestamp')); |
|
| 410 | + echo sprintf(__('GeoIp2 %s database updated successfully.', 'invoicing'), $database) . ' '; |
|
| 411 | 411 | } |
| 412 | 412 | |
| 413 | 413 | exit; |
| 414 | 414 | } |
| 415 | 415 | |
| 416 | - public static function geoip2_download_file( $source_url, $destination_file ) { |
|
| 416 | + public static function geoip2_download_file($source_url, $destination_file) { |
|
| 417 | 417 | $success = false; |
| 418 | 418 | $message = ''; |
| 419 | 419 | |
| 420 | - if ( !function_exists( 'download_url' ) ) { |
|
| 421 | - require_once( ABSPATH . 'wp-admin/includes/file.php' ); |
|
| 420 | + if (!function_exists('download_url')) { |
|
| 421 | + require_once(ABSPATH . 'wp-admin/includes/file.php'); |
|
| 422 | 422 | } |
| 423 | 423 | |
| 424 | - $temp_file = download_url( $source_url ); |
|
| 424 | + $temp_file = download_url($source_url); |
|
| 425 | 425 | |
| 426 | - if ( is_wp_error( $temp_file ) ) { |
|
| 427 | - $message = sprintf( __( 'Error while downloading GeoIp2 database( %s ): %s', 'invoicing' ), $source_url, $temp_file->get_error_message() ); |
|
| 426 | + if (is_wp_error($temp_file)) { |
|
| 427 | + $message = sprintf(__('Error while downloading GeoIp2 database( %s ): %s', 'invoicing'), $source_url, $temp_file->get_error_message()); |
|
| 428 | 428 | } else { |
| 429 | - $handle = gzopen( $temp_file, 'rb' ); |
|
| 429 | + $handle = gzopen($temp_file, 'rb'); |
|
| 430 | 430 | |
| 431 | - if ( $handle ) { |
|
| 432 | - $fopen = fopen( $destination_file, 'wb' ); |
|
| 433 | - if ( $fopen ) { |
|
| 434 | - while ( ( $data = gzread( $handle, 4096 ) ) != false ) { |
|
| 435 | - fwrite( $fopen, $data ); |
|
| 431 | + if ($handle) { |
|
| 432 | + $fopen = fopen($destination_file, 'wb'); |
|
| 433 | + if ($fopen) { |
|
| 434 | + while (($data = gzread($handle, 4096)) != false) { |
|
| 435 | + fwrite($fopen, $data); |
|
| 436 | 436 | } |
| 437 | 437 | |
| 438 | - gzclose( $handle ); |
|
| 439 | - fclose( $fopen ); |
|
| 438 | + gzclose($handle); |
|
| 439 | + fclose($fopen); |
|
| 440 | 440 | |
| 441 | 441 | $success = true; |
| 442 | 442 | } else { |
| 443 | - gzclose( $handle ); |
|
| 444 | - $message = sprintf( __( 'Error could not open destination GeoIp2 database file for writing: %s', 'invoicing' ), $destination_file ); |
|
| 443 | + gzclose($handle); |
|
| 444 | + $message = sprintf(__('Error could not open destination GeoIp2 database file for writing: %s', 'invoicing'), $destination_file); |
|
| 445 | 445 | } |
| 446 | 446 | } else { |
| 447 | - $message = sprintf( __( 'Error could not open GeoIp2 database file for reading: %s', 'invoicing' ), $temp_file ); |
|
| 447 | + $message = sprintf(__('Error could not open GeoIp2 database file for reading: %s', 'invoicing'), $temp_file); |
|
| 448 | 448 | } |
| 449 | 449 | |
| 450 | - if ( file_exists( $temp_file ) ) { |
|
| 451 | - unlink( $temp_file ); |
|
| 450 | + if (file_exists($temp_file)) { |
|
| 451 | + unlink($temp_file); |
|
| 452 | 452 | } |
| 453 | 453 | } |
| 454 | 454 | |
@@ -460,11 +460,11 @@ discard block |
||
| 460 | 460 | } |
| 461 | 461 | |
| 462 | 462 | public static function load_geoip2() { |
| 463 | - if ( defined( 'WPINV_GEOIP2_LODDED' ) ) { |
|
| 463 | + if (defined('WPINV_GEOIP2_LODDED')) { |
|
| 464 | 464 | return; |
| 465 | 465 | } |
| 466 | 466 | |
| 467 | - if ( !class_exists( '\MaxMind\Db\Reader' ) ) { |
|
| 467 | + if (!class_exists('\MaxMind\Db\Reader')) { |
|
| 468 | 468 | $maxmind_db_files = array( |
| 469 | 469 | 'Reader/Decoder.php', |
| 470 | 470 | 'Reader/InvalidDatabaseException.php', |
@@ -473,12 +473,12 @@ discard block |
||
| 473 | 473 | 'Reader.php', |
| 474 | 474 | ); |
| 475 | 475 | |
| 476 | - foreach ( $maxmind_db_files as $key => $file ) { |
|
| 477 | - require_once( WPINV_PLUGIN_DIR . 'includes/libraries/MaxMind/Db/' . $file ); |
|
| 476 | + foreach ($maxmind_db_files as $key => $file) { |
|
| 477 | + require_once(WPINV_PLUGIN_DIR . 'includes/libraries/MaxMind/Db/' . $file); |
|
| 478 | 478 | } |
| 479 | 479 | } |
| 480 | 480 | |
| 481 | - if ( !class_exists( '\GeoIp2\Database\Reader' ) ) { |
|
| 481 | + if (!class_exists('\GeoIp2\Database\Reader')) { |
|
| 482 | 482 | $geoip2_files = array( |
| 483 | 483 | 'ProviderInterface.php', |
| 484 | 484 | 'Compat/JsonSerializable.php', |
@@ -512,23 +512,23 @@ discard block |
||
| 512 | 512 | 'WebService/Client.php', |
| 513 | 513 | ); |
| 514 | 514 | |
| 515 | - foreach ( $geoip2_files as $key => $file ) { |
|
| 516 | - require_once( WPINV_PLUGIN_DIR . 'includes/libraries/GeoIp2/' . $file ); |
|
| 515 | + foreach ($geoip2_files as $key => $file) { |
|
| 516 | + require_once(WPINV_PLUGIN_DIR . 'includes/libraries/GeoIp2/' . $file); |
|
| 517 | 517 | } |
| 518 | 518 | } |
| 519 | 519 | |
| 520 | - define( 'WPINV_GEOIP2_LODDED', true ); |
|
| 520 | + define('WPINV_GEOIP2_LODDED', true); |
|
| 521 | 521 | } |
| 522 | 522 | |
| 523 | 523 | public static function geoip2_country_dbfile() { |
| 524 | 524 | $upload_dir = wp_upload_dir(); |
| 525 | 525 | |
| 526 | - if ( !isset( $upload_dir['basedir'] ) ) { |
|
| 526 | + if (!isset($upload_dir['basedir'])) { |
|
| 527 | 527 | return false; |
| 528 | 528 | } |
| 529 | 529 | |
| 530 | 530 | $filename = $upload_dir['basedir'] . '/invoicing/GeoLite2-Country.mmdb'; |
| 531 | - if ( !file_exists( $filename ) ) { |
|
| 531 | + if (!file_exists($filename)) { |
|
| 532 | 532 | return false; |
| 533 | 533 | } |
| 534 | 534 | |
@@ -538,12 +538,12 @@ discard block |
||
| 538 | 538 | public static function geoip2_city_dbfile() { |
| 539 | 539 | $upload_dir = wp_upload_dir(); |
| 540 | 540 | |
| 541 | - if ( !isset( $upload_dir['basedir'] ) ) { |
|
| 541 | + if (!isset($upload_dir['basedir'])) { |
|
| 542 | 542 | return false; |
| 543 | 543 | } |
| 544 | 544 | |
| 545 | 545 | $filename = $upload_dir['basedir'] . '/invoicing/GeoLite2-City.mmdb'; |
| 546 | - if ( !file_exists( $filename ) ) { |
|
| 546 | + if (!file_exists($filename)) { |
|
| 547 | 547 | return false; |
| 548 | 548 | } |
| 549 | 549 | |
@@ -554,10 +554,10 @@ discard block |
||
| 554 | 554 | try { |
| 555 | 555 | self::load_geoip2(); |
| 556 | 556 | |
| 557 | - if ( $filename = self::geoip2_country_dbfile() ) { |
|
| 558 | - return new \GeoIp2\Database\Reader( $filename ); |
|
| 557 | + if ($filename = self::geoip2_country_dbfile()) { |
|
| 558 | + return new \GeoIp2\Database\Reader($filename); |
|
| 559 | 559 | } |
| 560 | - } catch( Exception $e ) { |
|
| 560 | + } catch (Exception $e) { |
|
| 561 | 561 | return false; |
| 562 | 562 | } |
| 563 | 563 | |
@@ -568,173 +568,173 @@ discard block |
||
| 568 | 568 | try { |
| 569 | 569 | self::load_geoip2(); |
| 570 | 570 | |
| 571 | - if ( $filename = self::geoip2_city_dbfile() ) { |
|
| 572 | - return new \GeoIp2\Database\Reader( $filename ); |
|
| 571 | + if ($filename = self::geoip2_city_dbfile()) { |
|
| 572 | + return new \GeoIp2\Database\Reader($filename); |
|
| 573 | 573 | } |
| 574 | - } catch( Exception $e ) { |
|
| 574 | + } catch (Exception $e) { |
|
| 575 | 575 | return false; |
| 576 | 576 | } |
| 577 | 577 | |
| 578 | 578 | return false; |
| 579 | 579 | } |
| 580 | 580 | |
| 581 | - public static function geoip2_country_record( $ip_address ) { |
|
| 581 | + public static function geoip2_country_record($ip_address) { |
|
| 582 | 582 | try { |
| 583 | 583 | $reader = self::geoip2_country_reader(); |
| 584 | 584 | |
| 585 | - if ( $reader ) { |
|
| 586 | - $record = $reader->country( $ip_address ); |
|
| 585 | + if ($reader) { |
|
| 586 | + $record = $reader->country($ip_address); |
|
| 587 | 587 | |
| 588 | - if ( !empty( $record->country->isoCode ) ) { |
|
| 588 | + if (!empty($record->country->isoCode)) { |
|
| 589 | 589 | return $record; |
| 590 | 590 | } |
| 591 | 591 | } |
| 592 | - } catch(\InvalidArgumentException $e) { |
|
| 593 | - wpinv_error_log( $e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )' ); |
|
| 592 | + } catch (\InvalidArgumentException $e) { |
|
| 593 | + wpinv_error_log($e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )'); |
|
| 594 | 594 | |
| 595 | 595 | return false; |
| 596 | - } catch(\GeoIp2\Exception\AddressNotFoundException $e) { |
|
| 597 | - wpinv_error_log( $e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )' ); |
|
| 596 | + } catch (\GeoIp2\Exception\AddressNotFoundException $e) { |
|
| 597 | + wpinv_error_log($e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )'); |
|
| 598 | 598 | |
| 599 | 599 | return false; |
| 600 | - } catch( Exception $e ) { |
|
| 600 | + } catch (Exception $e) { |
|
| 601 | 601 | return false; |
| 602 | 602 | } |
| 603 | 603 | |
| 604 | 604 | return false; |
| 605 | 605 | } |
| 606 | 606 | |
| 607 | - public static function geoip2_city_record( $ip_address ) { |
|
| 607 | + public static function geoip2_city_record($ip_address) { |
|
| 608 | 608 | try { |
| 609 | 609 | $reader = self::geoip2_city_reader(); |
| 610 | 610 | |
| 611 | - if ( $reader ) { |
|
| 612 | - $record = $reader->city( $ip_address ); |
|
| 611 | + if ($reader) { |
|
| 612 | + $record = $reader->city($ip_address); |
|
| 613 | 613 | |
| 614 | - if ( !empty( $record->country->isoCode ) ) { |
|
| 614 | + if (!empty($record->country->isoCode)) { |
|
| 615 | 615 | return $record; |
| 616 | 616 | } |
| 617 | 617 | } |
| 618 | - } catch(\InvalidArgumentException $e) { |
|
| 619 | - wpinv_error_log( $e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )' ); |
|
| 618 | + } catch (\InvalidArgumentException $e) { |
|
| 619 | + wpinv_error_log($e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )'); |
|
| 620 | 620 | |
| 621 | 621 | return false; |
| 622 | - } catch(\GeoIp2\Exception\AddressNotFoundException $e) { |
|
| 623 | - wpinv_error_log( $e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )' ); |
|
| 622 | + } catch (\GeoIp2\Exception\AddressNotFoundException $e) { |
|
| 623 | + wpinv_error_log($e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )'); |
|
| 624 | 624 | |
| 625 | 625 | return false; |
| 626 | - } catch( Exception $e ) { |
|
| 626 | + } catch (Exception $e) { |
|
| 627 | 627 | return false; |
| 628 | 628 | } |
| 629 | 629 | |
| 630 | 630 | return false; |
| 631 | 631 | } |
| 632 | 632 | |
| 633 | - public static function geoip2_country_code( $ip_address ) { |
|
| 634 | - $record = self::geoip2_country_record( $ip_address ); |
|
| 635 | - return !empty( $record->country->isoCode ) ? $record->country->isoCode : wpinv_get_default_country(); |
|
| 633 | + public static function geoip2_country_code($ip_address) { |
|
| 634 | + $record = self::geoip2_country_record($ip_address); |
|
| 635 | + return !empty($record->country->isoCode) ? $record->country->isoCode : wpinv_get_default_country(); |
|
| 636 | 636 | } |
| 637 | 637 | |
| 638 | 638 | // Find country by IP address. |
| 639 | - public static function get_country_by_ip( $ip = '' ) { |
|
| 639 | + public static function get_country_by_ip($ip = '') { |
|
| 640 | 640 | global $wpinv_ip_address_country; |
| 641 | 641 | |
| 642 | - if ( !empty( $wpinv_ip_address_country ) ) { |
|
| 642 | + if (!empty($wpinv_ip_address_country)) { |
|
| 643 | 643 | return $wpinv_ip_address_country; |
| 644 | 644 | } |
| 645 | 645 | |
| 646 | - if ( empty( $ip ) ) { |
|
| 646 | + if (empty($ip)) { |
|
| 647 | 647 | $ip = wpinv_get_ip(); |
| 648 | 648 | } |
| 649 | 649 | |
| 650 | - $ip_country_service = wpinv_get_option( 'vat_ip_lookup' ); |
|
| 651 | - $is_default = empty( $ip_country_service ) || $ip_country_service === 'default' ? true : false; |
|
| 650 | + $ip_country_service = wpinv_get_option('vat_ip_lookup'); |
|
| 651 | + $is_default = empty($ip_country_service) || $ip_country_service === 'default' ? true : false; |
|
| 652 | 652 | |
| 653 | - if ( !empty( $ip ) && $ip !== '127.0.0.1' ) { // For 127.0.0.1(localhost) use default country. |
|
| 654 | - if ( function_exists( 'geoip_country_code_by_name') && ( $ip_country_service === 'geoip' || $is_default ) ) { |
|
| 653 | + if (!empty($ip) && $ip !== '127.0.0.1') { // For 127.0.0.1(localhost) use default country. |
|
| 654 | + if (function_exists('geoip_country_code_by_name') && ($ip_country_service === 'geoip' || $is_default)) { |
|
| 655 | 655 | try { |
| 656 | - $wpinv_ip_address_country = geoip_country_code_by_name( $ip ); |
|
| 657 | - } catch( Exception $e ) { |
|
| 658 | - wpinv_error_log( $e->getMessage(), 'GeoIP Lookup( ' . $ip . ' )' ); |
|
| 656 | + $wpinv_ip_address_country = geoip_country_code_by_name($ip); |
|
| 657 | + } catch (Exception $e) { |
|
| 658 | + wpinv_error_log($e->getMessage(), 'GeoIP Lookup( ' . $ip . ' )'); |
|
| 659 | 659 | } |
| 660 | - } else if ( self::geoip2_country_dbfile() && ( $ip_country_service === 'geoip2' || $is_default ) ) { |
|
| 661 | - $wpinv_ip_address_country = self::geoip2_country_code( $ip ); |
|
| 662 | - } else if ( function_exists( 'simplexml_load_file' ) && ( $ip_country_service === 'geoplugin' || $is_default ) ) { |
|
| 663 | - $load_xml = simplexml_load_file( 'http://www.geoplugin.net/xml.gp?ip=' . $ip ); |
|
| 660 | + } else if (self::geoip2_country_dbfile() && ($ip_country_service === 'geoip2' || $is_default)) { |
|
| 661 | + $wpinv_ip_address_country = self::geoip2_country_code($ip); |
|
| 662 | + } else if (function_exists('simplexml_load_file') && ($ip_country_service === 'geoplugin' || $is_default)) { |
|
| 663 | + $load_xml = simplexml_load_file('http://www.geoplugin.net/xml.gp?ip=' . $ip); |
|
| 664 | 664 | |
| 665 | - if ( !empty( $load_xml ) && !empty( $load_xml->geoplugin_countryCode ) ) { |
|
| 665 | + if (!empty($load_xml) && !empty($load_xml->geoplugin_countryCode)) { |
|
| 666 | 666 | $wpinv_ip_address_country = (string)$load_xml->geoplugin_countryCode; |
| 667 | 667 | } |
| 668 | 668 | } |
| 669 | 669 | } |
| 670 | 670 | |
| 671 | - if ( empty( $wpinv_ip_address_country ) ) { |
|
| 671 | + if (empty($wpinv_ip_address_country)) { |
|
| 672 | 672 | $wpinv_ip_address_country = wpinv_get_default_country(); |
| 673 | 673 | } |
| 674 | 674 | |
| 675 | 675 | return $wpinv_ip_address_country; |
| 676 | 676 | } |
| 677 | 677 | |
| 678 | - public static function sanitize_vat_settings( $input ) { |
|
| 678 | + public static function sanitize_vat_settings($input) { |
|
| 679 | 679 | global $wpinv_options; |
| 680 | 680 | |
| 681 | 681 | $valid = false; |
| 682 | 682 | $message = ''; |
| 683 | 683 | |
| 684 | - if ( !empty( $wpinv_options['vat_vies_check'] ) ) { |
|
| 685 | - if ( empty( $wpinv_options['vat_offline_check'] ) ) { |
|
| 686 | - $valid = self::offline_check( $input['vat_number'] ); |
|
| 684 | + if (!empty($wpinv_options['vat_vies_check'])) { |
|
| 685 | + if (empty($wpinv_options['vat_offline_check'])) { |
|
| 686 | + $valid = self::offline_check($input['vat_number']); |
|
| 687 | 687 | } else { |
| 688 | 688 | $valid = true; |
| 689 | 689 | } |
| 690 | 690 | |
| 691 | - $message = $valid ? '' : __( 'VAT number not validated', 'invoicing' ); |
|
| 691 | + $message = $valid ? '' : __('VAT number not validated', 'invoicing'); |
|
| 692 | 692 | } else { |
| 693 | - $result = self::check_vat( $input['vat_number'] ); |
|
| 693 | + $result = self::check_vat($input['vat_number']); |
|
| 694 | 694 | |
| 695 | - if ( empty( $result['valid'] ) ) { |
|
| 695 | + if (empty($result['valid'])) { |
|
| 696 | 696 | $valid = false; |
| 697 | 697 | $message = $result['message']; |
| 698 | 698 | } else { |
| 699 | - $valid = ( isset( $result['company'] ) && ( $result['company'] == '---' || ( strcasecmp( trim( $result['company'] ), trim( $input['vat_company_name'] ) ) == 0 ) ) ) || !empty( $wpinv_options['vat_disable_company_name_check'] ); |
|
| 700 | - $message = $valid ? '' : __( 'The company name associated with the VAT number provided is not the same as the company name provided.', 'invoicing' ); |
|
| 699 | + $valid = (isset($result['company']) && ($result['company'] == '---' || (strcasecmp(trim($result['company']), trim($input['vat_company_name'])) == 0))) || !empty($wpinv_options['vat_disable_company_name_check']); |
|
| 700 | + $message = $valid ? '' : __('The company name associated with the VAT number provided is not the same as the company name provided.', 'invoicing'); |
|
| 701 | 701 | } |
| 702 | 702 | } |
| 703 | 703 | |
| 704 | - if ( $message && self::is_vat_validated() != $valid ) { |
|
| 705 | - add_settings_error( 'wpinv-notices', '', $message, ( $valid ? 'updated' : 'error' ) ); |
|
| 704 | + if ($message && self::is_vat_validated() != $valid) { |
|
| 705 | + add_settings_error('wpinv-notices', '', $message, ($valid ? 'updated' : 'error')); |
|
| 706 | 706 | } |
| 707 | 707 | |
| 708 | 708 | $input['vat_valid'] = $valid; |
| 709 | 709 | return $input; |
| 710 | 710 | } |
| 711 | 711 | |
| 712 | - public static function sanitize_vat_rates( $input ) { |
|
| 713 | - if( !current_user_can( 'manage_options' ) ) { |
|
| 714 | - add_settings_error( 'wpinv-notices', '', __( 'Your account does not have permission to add rate classes.', 'invoicing' ), 'error' ); |
|
| 712 | + public static function sanitize_vat_rates($input) { |
|
| 713 | + if (!current_user_can('manage_options')) { |
|
| 714 | + add_settings_error('wpinv-notices', '', __('Your account does not have permission to add rate classes.', 'invoicing'), 'error'); |
|
| 715 | 715 | return $input; |
| 716 | 716 | } |
| 717 | 717 | |
| 718 | 718 | $vat_classes = self::get_rate_classes(); |
| 719 | - $vat_class = !empty( $_REQUEST['wpi_vat_class'] ) && isset( $vat_classes[$_REQUEST['wpi_vat_class']] )? sanitize_text_field( $_REQUEST['wpi_vat_class'] ) : ''; |
|
| 719 | + $vat_class = !empty($_REQUEST['wpi_vat_class']) && isset($vat_classes[$_REQUEST['wpi_vat_class']]) ? sanitize_text_field($_REQUEST['wpi_vat_class']) : ''; |
|
| 720 | 720 | |
| 721 | - if ( empty( $vat_class ) ) { |
|
| 722 | - add_settings_error( 'wpinv-notices', '', __( 'No valid VAT rates class contained in the request to save rates.', 'invoicing' ), 'error' ); |
|
| 721 | + if (empty($vat_class)) { |
|
| 722 | + add_settings_error('wpinv-notices', '', __('No valid VAT rates class contained in the request to save rates.', 'invoicing'), 'error'); |
|
| 723 | 723 | |
| 724 | 724 | return $input; |
| 725 | 725 | } |
| 726 | 726 | |
| 727 | - $new_rates = ! empty( $_POST['vat_rates'] ) ? array_values( $_POST['vat_rates'] ) : array(); |
|
| 727 | + $new_rates = !empty($_POST['vat_rates']) ? array_values($_POST['vat_rates']) : array(); |
|
| 728 | 728 | |
| 729 | - if ( $vat_class === '_standard' ) { |
|
| 729 | + if ($vat_class === '_standard') { |
|
| 730 | 730 | // Save the active rates in the invoice settings |
| 731 | - update_option( 'wpinv_tax_rates', $new_rates ); |
|
| 731 | + update_option('wpinv_tax_rates', $new_rates); |
|
| 732 | 732 | } else { |
| 733 | 733 | // Get the existing set of rates |
| 734 | 734 | $rates = self::get_non_standard_rates(); |
| 735 | 735 | $rates[$vat_class] = $new_rates; |
| 736 | 736 | |
| 737 | - update_option( 'wpinv_vat_rates', $rates ); |
|
| 737 | + update_option('wpinv_vat_rates', $rates); |
|
| 738 | 738 | } |
| 739 | 739 | |
| 740 | 740 | return $input; |
@@ -744,71 +744,71 @@ discard block |
||
| 744 | 744 | $response = array(); |
| 745 | 745 | $response['success'] = false; |
| 746 | 746 | |
| 747 | - if ( !current_user_can( 'manage_options' ) ) { |
|
| 748 | - $response['error'] = __( 'Invalid access!', 'invoicing' ); |
|
| 749 | - wp_send_json( $response ); |
|
| 747 | + if (!current_user_can('manage_options')) { |
|
| 748 | + $response['error'] = __('Invalid access!', 'invoicing'); |
|
| 749 | + wp_send_json($response); |
|
| 750 | 750 | } |
| 751 | 751 | |
| 752 | - $vat_class_name = !empty( $_POST['name'] ) ? sanitize_text_field( $_POST['name'] ) : false; |
|
| 753 | - $vat_class_desc = !empty( $_POST['desc'] ) ? sanitize_text_field( $_POST['desc'] ) : false; |
|
| 752 | + $vat_class_name = !empty($_POST['name']) ? sanitize_text_field($_POST['name']) : false; |
|
| 753 | + $vat_class_desc = !empty($_POST['desc']) ? sanitize_text_field($_POST['desc']) : false; |
|
| 754 | 754 | |
| 755 | - if ( empty( $vat_class_name ) ) { |
|
| 756 | - $response['error'] = __( 'Select the VAT rate name', 'invoicing' ); |
|
| 757 | - wp_send_json( $response ); |
|
| 755 | + if (empty($vat_class_name)) { |
|
| 756 | + $response['error'] = __('Select the VAT rate name', 'invoicing'); |
|
| 757 | + wp_send_json($response); |
|
| 758 | 758 | } |
| 759 | 759 | |
| 760 | 760 | $vat_classes = (array)self::get_rate_classes(); |
| 761 | 761 | |
| 762 | - if ( !empty( $vat_classes ) && in_array( strtolower( $vat_class_name ), array_map( 'strtolower', array_values( $vat_classes ) ) ) ) { |
|
| 763 | - $response['error'] = wp_sprintf( __( 'A VAT Rate name "%s" already exists', 'invoicing' ), $vat_class_name ); |
|
| 764 | - wp_send_json( $response ); |
|
| 762 | + if (!empty($vat_classes) && in_array(strtolower($vat_class_name), array_map('strtolower', array_values($vat_classes)))) { |
|
| 763 | + $response['error'] = wp_sprintf(__('A VAT Rate name "%s" already exists', 'invoicing'), $vat_class_name); |
|
| 764 | + wp_send_json($response); |
|
| 765 | 765 | } |
| 766 | 766 | |
| 767 | - $rate_class_key = normalize_whitespace( 'wpi-' . $vat_class_name ); |
|
| 768 | - $rate_class_key = sanitize_key( str_replace( " ", "-", $rate_class_key ) ); |
|
| 767 | + $rate_class_key = normalize_whitespace('wpi-' . $vat_class_name); |
|
| 768 | + $rate_class_key = sanitize_key(str_replace(" ", "-", $rate_class_key)); |
|
| 769 | 769 | |
| 770 | - $vat_classes = (array)self::get_rate_classes( true ); |
|
| 771 | - $vat_classes[$rate_class_key] = array( 'name' => $vat_class_name, 'desc' => $vat_class_desc ); |
|
| 770 | + $vat_classes = (array)self::get_rate_classes(true); |
|
| 771 | + $vat_classes[$rate_class_key] = array('name' => $vat_class_name, 'desc' => $vat_class_desc); |
|
| 772 | 772 | |
| 773 | - update_option( '_wpinv_vat_rate_classes', $vat_classes ); |
|
| 773 | + update_option('_wpinv_vat_rate_classes', $vat_classes); |
|
| 774 | 774 | |
| 775 | 775 | $response['success'] = true; |
| 776 | - $response['redirect'] = admin_url( 'admin.php?page=wpinv-settings&tab=taxes§ion=vat_rates&wpi_sub=' . $rate_class_key ); |
|
| 776 | + $response['redirect'] = admin_url('admin.php?page=wpinv-settings&tab=taxes§ion=vat_rates&wpi_sub=' . $rate_class_key); |
|
| 777 | 777 | |
| 778 | - wp_send_json( $response ); |
|
| 778 | + wp_send_json($response); |
|
| 779 | 779 | } |
| 780 | 780 | |
| 781 | 781 | public static function delete_class() { |
| 782 | 782 | $response = array(); |
| 783 | 783 | $response['success'] = false; |
| 784 | 784 | |
| 785 | - if ( !current_user_can( 'manage_options' ) || !isset( $_POST['class'] ) ) { |
|
| 786 | - $response['error'] = __( 'Invalid access!', 'invoicing' ); |
|
| 787 | - wp_send_json( $response ); |
|
| 785 | + if (!current_user_can('manage_options') || !isset($_POST['class'])) { |
|
| 786 | + $response['error'] = __('Invalid access!', 'invoicing'); |
|
| 787 | + wp_send_json($response); |
|
| 788 | 788 | } |
| 789 | 789 | |
| 790 | - $vat_class = isset( $_POST['class'] ) && $_POST['class'] !== '' ? sanitize_text_field( $_POST['class'] ) : false; |
|
| 790 | + $vat_class = isset($_POST['class']) && $_POST['class'] !== '' ? sanitize_text_field($_POST['class']) : false; |
|
| 791 | 791 | $vat_classes = (array)self::get_rate_classes(); |
| 792 | 792 | |
| 793 | - if ( !isset( $vat_classes[$vat_class] ) ) { |
|
| 794 | - $response['error'] = __( 'Requested class does not exists', 'invoicing' ); |
|
| 795 | - wp_send_json( $response ); |
|
| 793 | + if (!isset($vat_classes[$vat_class])) { |
|
| 794 | + $response['error'] = __('Requested class does not exists', 'invoicing'); |
|
| 795 | + wp_send_json($response); |
|
| 796 | 796 | } |
| 797 | 797 | |
| 798 | - if ( $vat_class == '_new' || $vat_class == '_standard' ) { |
|
| 799 | - $response['error'] = __( 'You can not delete standard rates class', 'invoicing' ); |
|
| 800 | - wp_send_json( $response ); |
|
| 798 | + if ($vat_class == '_new' || $vat_class == '_standard') { |
|
| 799 | + $response['error'] = __('You can not delete standard rates class', 'invoicing'); |
|
| 800 | + wp_send_json($response); |
|
| 801 | 801 | } |
| 802 | 802 | |
| 803 | - $vat_classes = (array)self::get_rate_classes( true ); |
|
| 804 | - unset( $vat_classes[$vat_class] ); |
|
| 803 | + $vat_classes = (array)self::get_rate_classes(true); |
|
| 804 | + unset($vat_classes[$vat_class]); |
|
| 805 | 805 | |
| 806 | - update_option( '_wpinv_vat_rate_classes', $vat_classes ); |
|
| 806 | + update_option('_wpinv_vat_rate_classes', $vat_classes); |
|
| 807 | 807 | |
| 808 | 808 | $response['success'] = true; |
| 809 | - $response['redirect'] = admin_url( 'admin.php?page=wpinv-settings&tab=taxes§ion=vat_rates&wpi_sub=_new' ); |
|
| 809 | + $response['redirect'] = admin_url('admin.php?page=wpinv-settings&tab=taxes§ion=vat_rates&wpi_sub=_new'); |
|
| 810 | 810 | |
| 811 | - wp_send_json( $response ); |
|
| 811 | + wp_send_json($response); |
|
| 812 | 812 | } |
| 813 | 813 | |
| 814 | 814 | public static function update_eu_rates() { |
@@ -817,72 +817,72 @@ discard block |
||
| 817 | 817 | $response['error'] = null; |
| 818 | 818 | $response['data'] = null; |
| 819 | 819 | |
| 820 | - if ( !current_user_can( 'manage_options' ) ) { |
|
| 821 | - $response['error'] = __( 'Invalid access!', 'invoicing' ); |
|
| 822 | - wp_send_json( $response ); |
|
| 820 | + if (!current_user_can('manage_options')) { |
|
| 821 | + $response['error'] = __('Invalid access!', 'invoicing'); |
|
| 822 | + wp_send_json($response); |
|
| 823 | 823 | } |
| 824 | 824 | |
| 825 | - $group = !empty( $_POST['group'] ) ? sanitize_text_field( $_POST['group'] ) : ''; |
|
| 826 | - $euvatrates = self::request_euvatrates( $group ); |
|
| 825 | + $group = !empty($_POST['group']) ? sanitize_text_field($_POST['group']) : ''; |
|
| 826 | + $euvatrates = self::request_euvatrates($group); |
|
| 827 | 827 | |
| 828 | - if ( !empty( $euvatrates ) ) { |
|
| 829 | - if ( !empty( $euvatrates['success'] ) && !empty( $euvatrates['rates'] ) ) { |
|
| 828 | + if (!empty($euvatrates)) { |
|
| 829 | + if (!empty($euvatrates['success']) && !empty($euvatrates['rates'])) { |
|
| 830 | 830 | $response['success'] = true; |
| 831 | 831 | $response['data']['rates'] = $euvatrates['rates']; |
| 832 | - } else if ( !empty( $euvatrates['error'] ) ) { |
|
| 832 | + } else if (!empty($euvatrates['error'])) { |
|
| 833 | 833 | $response['error'] = $euvatrates['error']; |
| 834 | 834 | } |
| 835 | 835 | } |
| 836 | 836 | |
| 837 | - wp_send_json( $response ); |
|
| 837 | + wp_send_json($response); |
|
| 838 | 838 | } |
| 839 | 839 | |
| 840 | 840 | public static function hide_vat_fields() { |
| 841 | - $hide = wpinv_get_option( 'vat_disable_fields' ); |
|
| 841 | + $hide = wpinv_get_option('vat_disable_fields'); |
|
| 842 | 842 | |
| 843 | - return apply_filters( 'wpinv_hide_vat_fields', $hide ); |
|
| 843 | + return apply_filters('wpinv_hide_vat_fields', $hide); |
|
| 844 | 844 | } |
| 845 | 845 | |
| 846 | 846 | public static function same_country_rule() { |
| 847 | - $same_country_rule = wpinv_get_option( 'vat_same_country_rule' ); |
|
| 847 | + $same_country_rule = wpinv_get_option('vat_same_country_rule'); |
|
| 848 | 848 | |
| 849 | - return apply_filters( 'wpinv_vat_same_country_rule', $same_country_rule ); |
|
| 849 | + return apply_filters('wpinv_vat_same_country_rule', $same_country_rule); |
|
| 850 | 850 | } |
| 851 | 851 | |
| 852 | 852 | public static function get_vat_name() { |
| 853 | - $vat_name = wpinv_get_option( 'vat_name' ); |
|
| 854 | - $vat_name = !empty( $vat_name ) ? $vat_name : 'VAT'; |
|
| 853 | + $vat_name = wpinv_get_option('vat_name'); |
|
| 854 | + $vat_name = !empty($vat_name) ? $vat_name : 'VAT'; |
|
| 855 | 855 | |
| 856 | - return apply_filters( 'wpinv_get_owner_vat_name', $vat_name ); |
|
| 856 | + return apply_filters('wpinv_get_owner_vat_name', $vat_name); |
|
| 857 | 857 | } |
| 858 | 858 | |
| 859 | 859 | public static function get_company_name() { |
| 860 | - $company_name = wpinv_get_option( 'vat_company_name' ); |
|
| 860 | + $company_name = wpinv_get_option('vat_company_name'); |
|
| 861 | 861 | |
| 862 | - return apply_filters( 'wpinv_get_owner_company_name', $company_name ); |
|
| 862 | + return apply_filters('wpinv_get_owner_company_name', $company_name); |
|
| 863 | 863 | } |
| 864 | 864 | |
| 865 | 865 | public static function get_vat_number() { |
| 866 | - $vat_number = wpinv_get_option( 'vat_number' ); |
|
| 866 | + $vat_number = wpinv_get_option('vat_number'); |
|
| 867 | 867 | |
| 868 | - return apply_filters( 'wpinv_get_owner_vat_number', $vat_number ); |
|
| 868 | + return apply_filters('wpinv_get_owner_vat_number', $vat_number); |
|
| 869 | 869 | } |
| 870 | 870 | |
| 871 | 871 | public static function is_vat_validated() { |
| 872 | - $validated = self::get_vat_number() && wpinv_get_option( 'vat_valid' ); |
|
| 872 | + $validated = self::get_vat_number() && wpinv_get_option('vat_valid'); |
|
| 873 | 873 | |
| 874 | - return apply_filters( 'wpinv_is_owner_vat_validated', $validated ); |
|
| 874 | + return apply_filters('wpinv_is_owner_vat_validated', $validated); |
|
| 875 | 875 | } |
| 876 | 876 | |
| 877 | - public static function sanitize_vat( $vat_number, $country_code = '' ) { |
|
| 878 | - $vat_number = str_replace( array(' ', '.', '-', '_', ',' ), '', strtoupper( trim( $vat_number ) ) ); |
|
| 877 | + public static function sanitize_vat($vat_number, $country_code = '') { |
|
| 878 | + $vat_number = str_replace(array(' ', '.', '-', '_', ','), '', strtoupper(trim($vat_number))); |
|
| 879 | 879 | |
| 880 | - if ( empty( $country_code ) ) { |
|
| 881 | - $country_code = substr( $vat_number, 0, 2 ); |
|
| 880 | + if (empty($country_code)) { |
|
| 881 | + $country_code = substr($vat_number, 0, 2); |
|
| 882 | 882 | } |
| 883 | 883 | |
| 884 | - if ( strpos( $vat_number , $country_code ) === 0 ) { |
|
| 885 | - $vat = str_replace( $country_code, '', $vat_number ); |
|
| 884 | + if (strpos($vat_number, $country_code) === 0) { |
|
| 885 | + $vat = str_replace($country_code, '', $vat_number); |
|
| 886 | 886 | } else { |
| 887 | 887 | $vat = $country_code . $vat_number; |
| 888 | 888 | } |
@@ -895,140 +895,140 @@ discard block |
||
| 895 | 895 | return $return; |
| 896 | 896 | } |
| 897 | 897 | |
| 898 | - public static function offline_check( $vat_number, $country_code = '', $formatted = false ) { |
|
| 899 | - $vat = self::sanitize_vat( $vat_number, $country_code ); |
|
| 898 | + public static function offline_check($vat_number, $country_code = '', $formatted = false) { |
|
| 899 | + $vat = self::sanitize_vat($vat_number, $country_code); |
|
| 900 | 900 | $vat_number = $vat['vat_number']; |
| 901 | 901 | $country_code = $vat['iso']; |
| 902 | 902 | $regex = array(); |
| 903 | 903 | |
| 904 | - switch ( $country_code ) { |
|
| 904 | + switch ($country_code) { |
|
| 905 | 905 | case 'AT': |
| 906 | - $regex[] = '/^(AT)U(\d{8})$/'; // Austria |
|
| 906 | + $regex[] = '/^(AT)U(\d{8})$/'; // Austria |
|
| 907 | 907 | break; |
| 908 | 908 | case 'BE': |
| 909 | - $regex[] = '/^(BE)(0?\d{9})$/'; // Belgium |
|
| 909 | + $regex[] = '/^(BE)(0?\d{9})$/'; // Belgium |
|
| 910 | 910 | break; |
| 911 | 911 | case 'BG': |
| 912 | - $regex[] = '/^(BG)(\d{9,10})$/'; // Bulgaria |
|
| 912 | + $regex[] = '/^(BG)(\d{9,10})$/'; // Bulgaria |
|
| 913 | 913 | break; |
| 914 | 914 | case 'CH': |
| 915 | 915 | case 'CHE': |
| 916 | - $regex[] = '/^(CHE)(\d{9})MWST$/'; // Switzerland (Not EU) |
|
| 916 | + $regex[] = '/^(CHE)(\d{9})MWST$/'; // Switzerland (Not EU) |
|
| 917 | 917 | break; |
| 918 | 918 | case 'CY': |
| 919 | - $regex[] = '/^(CY)([0-5|9]\d{7}[A-Z])$/'; // Cyprus |
|
| 919 | + $regex[] = '/^(CY)([0-5|9]\d{7}[A-Z])$/'; // Cyprus |
|
| 920 | 920 | break; |
| 921 | 921 | case 'CZ': |
| 922 | - $regex[] = '/^(CZ)(\d{8,13})$/'; // Czech Republic |
|
| 922 | + $regex[] = '/^(CZ)(\d{8,13})$/'; // Czech Republic |
|
| 923 | 923 | break; |
| 924 | 924 | case 'DE': |
| 925 | - $regex[] = '/^(DE)([1-9]\d{8})$/'; // Germany |
|
| 925 | + $regex[] = '/^(DE)([1-9]\d{8})$/'; // Germany |
|
| 926 | 926 | break; |
| 927 | 927 | case 'DK': |
| 928 | - $regex[] = '/^(DK)(\d{8})$/'; // Denmark |
|
| 928 | + $regex[] = '/^(DK)(\d{8})$/'; // Denmark |
|
| 929 | 929 | break; |
| 930 | 930 | case 'EE': |
| 931 | - $regex[] = '/^(EE)(10\d{7})$/'; // Estonia |
|
| 931 | + $regex[] = '/^(EE)(10\d{7})$/'; // Estonia |
|
| 932 | 932 | break; |
| 933 | 933 | case 'EL': |
| 934 | - $regex[] = '/^(EL)(\d{9})$/'; // Greece |
|
| 934 | + $regex[] = '/^(EL)(\d{9})$/'; // Greece |
|
| 935 | 935 | break; |
| 936 | 936 | case 'ES': |
| 937 | - $regex[] = '/^(ES)([A-Z]\d{8})$/'; // Spain (National juridical entities) |
|
| 938 | - $regex[] = '/^(ES)([A-H|N-S|W]\d{7}[A-J])$/'; // Spain (Other juridical entities) |
|
| 939 | - $regex[] = '/^(ES)([0-9|Y|Z]\d{7}[A-Z])$/'; // Spain (Personal entities type 1) |
|
| 940 | - $regex[] = '/^(ES)([K|L|M|X]\d{7}[A-Z])$/'; // Spain (Personal entities type 2) |
|
| 937 | + $regex[] = '/^(ES)([A-Z]\d{8})$/'; // Spain (National juridical entities) |
|
| 938 | + $regex[] = '/^(ES)([A-H|N-S|W]\d{7}[A-J])$/'; // Spain (Other juridical entities) |
|
| 939 | + $regex[] = '/^(ES)([0-9|Y|Z]\d{7}[A-Z])$/'; // Spain (Personal entities type 1) |
|
| 940 | + $regex[] = '/^(ES)([K|L|M|X]\d{7}[A-Z])$/'; // Spain (Personal entities type 2) |
|
| 941 | 941 | break; |
| 942 | 942 | case 'EU': |
| 943 | - $regex[] = '/^(EU)(\d{9})$/'; // EU-type |
|
| 943 | + $regex[] = '/^(EU)(\d{9})$/'; // EU-type |
|
| 944 | 944 | break; |
| 945 | 945 | case 'FI': |
| 946 | - $regex[] = '/^(FI)(\d{8})$/'; // Finland |
|
| 946 | + $regex[] = '/^(FI)(\d{8})$/'; // Finland |
|
| 947 | 947 | break; |
| 948 | 948 | case 'FR': |
| 949 | - $regex[] = '/^(FR)(\d{11})$/'; // France (1) |
|
| 950 | - $regex[] = '/^(FR)[(A-H)|(J-N)|(P-Z)](\d{10})$/'; // France (2) |
|
| 951 | - $regex[] = '/^(FR)\d[(A-H)|(J-N)|(P-Z)](\d{9})$/'; // France (3) |
|
| 952 | - $regex[] = '/^(FR)[(A-H)|(J-N)|(P-Z)]{2}(\d{9})$/'; // France (4) |
|
| 949 | + $regex[] = '/^(FR)(\d{11})$/'; // France (1) |
|
| 950 | + $regex[] = '/^(FR)[(A-H)|(J-N)|(P-Z)](\d{10})$/'; // France (2) |
|
| 951 | + $regex[] = '/^(FR)\d[(A-H)|(J-N)|(P-Z)](\d{9})$/'; // France (3) |
|
| 952 | + $regex[] = '/^(FR)[(A-H)|(J-N)|(P-Z)]{2}(\d{9})$/'; // France (4) |
|
| 953 | 953 | break; |
| 954 | 954 | case 'GB': |
| 955 | - $regex[] = '/^(GB)?(\d{9})$/'; // UK (Standard) |
|
| 956 | - $regex[] = '/^(GB)?(\d{12})$/'; // UK (Branches) |
|
| 957 | - $regex[] = '/^(GB)?(GD\d{3})$/'; // UK (Government) |
|
| 958 | - $regex[] = '/^(GB)?(HA\d{3})$/'; // UK (Health authority) |
|
| 955 | + $regex[] = '/^(GB)?(\d{9})$/'; // UK (Standard) |
|
| 956 | + $regex[] = '/^(GB)?(\d{12})$/'; // UK (Branches) |
|
| 957 | + $regex[] = '/^(GB)?(GD\d{3})$/'; // UK (Government) |
|
| 958 | + $regex[] = '/^(GB)?(HA\d{3})$/'; // UK (Health authority) |
|
| 959 | 959 | break; |
| 960 | 960 | case 'GR': |
| 961 | - $regex[] = '/^(GR)(\d{8,9})$/'; // Greece |
|
| 961 | + $regex[] = '/^(GR)(\d{8,9})$/'; // Greece |
|
| 962 | 962 | break; |
| 963 | 963 | case 'HR': |
| 964 | - $regex[] = '/^(HR)(\d{11})$/'; // Croatia |
|
| 964 | + $regex[] = '/^(HR)(\d{11})$/'; // Croatia |
|
| 965 | 965 | break; |
| 966 | 966 | case 'HU': |
| 967 | - $regex[] = '/^(HU)(\d{8})$/'; // Hungary |
|
| 967 | + $regex[] = '/^(HU)(\d{8})$/'; // Hungary |
|
| 968 | 968 | break; |
| 969 | 969 | case 'IE': |
| 970 | - $regex[] = '/^(IE)(\d{7}[A-W])$/'; // Ireland (1) |
|
| 971 | - $regex[] = '/^(IE)([7-9][A-Z\*\+)]\d{5}[A-W])$/'; // Ireland (2) |
|
| 972 | - $regex[] = '/^(IE)(\d{7}[A-Z][AH])$/'; // Ireland (3) (new format from 1 Jan 2013) |
|
| 970 | + $regex[] = '/^(IE)(\d{7}[A-W])$/'; // Ireland (1) |
|
| 971 | + $regex[] = '/^(IE)([7-9][A-Z\*\+)]\d{5}[A-W])$/'; // Ireland (2) |
|
| 972 | + $regex[] = '/^(IE)(\d{7}[A-Z][AH])$/'; // Ireland (3) (new format from 1 Jan 2013) |
|
| 973 | 973 | break; |
| 974 | 974 | case 'IT': |
| 975 | - $regex[] = '/^(IT)(\d{11})$/'; // Italy |
|
| 975 | + $regex[] = '/^(IT)(\d{11})$/'; // Italy |
|
| 976 | 976 | break; |
| 977 | 977 | case 'LV': |
| 978 | - $regex[] = '/^(LV)(\d{11})$/'; // Latvia |
|
| 978 | + $regex[] = '/^(LV)(\d{11})$/'; // Latvia |
|
| 979 | 979 | break; |
| 980 | 980 | case 'LT': |
| 981 | - $regex[] = '/^(LT)(\d{9}|\d{12})$/'; // Lithuania |
|
| 981 | + $regex[] = '/^(LT)(\d{9}|\d{12})$/'; // Lithuania |
|
| 982 | 982 | break; |
| 983 | 983 | case 'LU': |
| 984 | - $regex[] = '/^(LU)(\d{8})$/'; // Luxembourg |
|
| 984 | + $regex[] = '/^(LU)(\d{8})$/'; // Luxembourg |
|
| 985 | 985 | break; |
| 986 | 986 | case 'MT': |
| 987 | - $regex[] = '/^(MT)([1-9]\d{7})$/'; // Malta |
|
| 987 | + $regex[] = '/^(MT)([1-9]\d{7})$/'; // Malta |
|
| 988 | 988 | break; |
| 989 | 989 | case 'NL': |
| 990 | - $regex[] = '/^(NL)(\d{9})B\d{2}$/'; // Netherlands |
|
| 990 | + $regex[] = '/^(NL)(\d{9})B\d{2}$/'; // Netherlands |
|
| 991 | 991 | break; |
| 992 | 992 | case 'NO': |
| 993 | - $regex[] = '/^(NO)(\d{9})$/'; // Norway (Not EU) |
|
| 993 | + $regex[] = '/^(NO)(\d{9})$/'; // Norway (Not EU) |
|
| 994 | 994 | break; |
| 995 | 995 | case 'PL': |
| 996 | - $regex[] = '/^(PL)(\d{10})$/'; // Poland |
|
| 996 | + $regex[] = '/^(PL)(\d{10})$/'; // Poland |
|
| 997 | 997 | break; |
| 998 | 998 | case 'PT': |
| 999 | - $regex[] = '/^(PT)(\d{9})$/'; // Portugal |
|
| 999 | + $regex[] = '/^(PT)(\d{9})$/'; // Portugal |
|
| 1000 | 1000 | break; |
| 1001 | 1001 | case 'RO': |
| 1002 | - $regex[] = '/^(RO)([1-9]\d{1,9})$/'; // Romania |
|
| 1002 | + $regex[] = '/^(RO)([1-9]\d{1,9})$/'; // Romania |
|
| 1003 | 1003 | break; |
| 1004 | 1004 | case 'RS': |
| 1005 | - $regex[] = '/^(RS)(\d{9})$/'; // Serbia (Not EU) |
|
| 1005 | + $regex[] = '/^(RS)(\d{9})$/'; // Serbia (Not EU) |
|
| 1006 | 1006 | break; |
| 1007 | 1007 | case 'SI': |
| 1008 | - $regex[] = '/^(SI)([1-9]\d{7})$/'; // Slovenia |
|
| 1008 | + $regex[] = '/^(SI)([1-9]\d{7})$/'; // Slovenia |
|
| 1009 | 1009 | break; |
| 1010 | 1010 | case 'SK': |
| 1011 | - $regex[] = '/^(SK)([1-9]\d[(2-4)|(6-9)]\d{7})$/'; // Slovakia Republic |
|
| 1011 | + $regex[] = '/^(SK)([1-9]\d[(2-4)|(6-9)]\d{7})$/'; // Slovakia Republic |
|
| 1012 | 1012 | break; |
| 1013 | 1013 | case 'SE': |
| 1014 | - $regex[] = '/^(SE)(\d{10}01)$/'; // Sweden |
|
| 1014 | + $regex[] = '/^(SE)(\d{10}01)$/'; // Sweden |
|
| 1015 | 1015 | break; |
| 1016 | 1016 | default: |
| 1017 | 1017 | $regex = array(); |
| 1018 | 1018 | break; |
| 1019 | 1019 | } |
| 1020 | 1020 | |
| 1021 | - if ( empty( $regex ) ) { |
|
| 1021 | + if (empty($regex)) { |
|
| 1022 | 1022 | return false; |
| 1023 | 1023 | } |
| 1024 | 1024 | |
| 1025 | - foreach ( $regex as $pattern ) { |
|
| 1025 | + foreach ($regex as $pattern) { |
|
| 1026 | 1026 | $matches = null; |
| 1027 | - preg_match_all( $pattern, $vat_number, $matches ); |
|
| 1027 | + preg_match_all($pattern, $vat_number, $matches); |
|
| 1028 | 1028 | |
| 1029 | - if ( !empty( $matches[1][0] ) && !empty( $matches[2][0] ) ) { |
|
| 1030 | - if ( $formatted ) { |
|
| 1031 | - return array( 'code' => $matches[1][0], 'number' => $matches[2][0] ); |
|
| 1029 | + if (!empty($matches[1][0]) && !empty($matches[2][0])) { |
|
| 1030 | + if ($formatted) { |
|
| 1031 | + return array('code' => $matches[1][0], 'number' => $matches[2][0]); |
|
| 1032 | 1032 | } else { |
| 1033 | 1033 | return true; |
| 1034 | 1034 | } |
@@ -1038,75 +1038,75 @@ discard block |
||
| 1038 | 1038 | return false; |
| 1039 | 1039 | } |
| 1040 | 1040 | |
| 1041 | - public static function vies_check( $vat_number, $country_code = '', $result = false ) { |
|
| 1042 | - $vat = self::sanitize_vat( $vat_number, $country_code ); |
|
| 1041 | + public static function vies_check($vat_number, $country_code = '', $result = false) { |
|
| 1042 | + $vat = self::sanitize_vat($vat_number, $country_code); |
|
| 1043 | 1043 | $vat_number = $vat['vat']; |
| 1044 | 1044 | $iso = $vat['iso']; |
| 1045 | 1045 | |
| 1046 | - $url = 'http://ec.europa.eu/taxation_customs/vies/viesquer.do?ms=' . urlencode( $iso ) . '&iso=' . urlencode( $iso ) . '&vat=' . urlencode( $vat_number ); |
|
| 1046 | + $url = 'http://ec.europa.eu/taxation_customs/vies/viesquer.do?ms=' . urlencode($iso) . '&iso=' . urlencode($iso) . '&vat=' . urlencode($vat_number); |
|
| 1047 | 1047 | |
| 1048 | - if ( ini_get( 'allow_url_fopen' ) ) { |
|
| 1049 | - $response = file_get_contents( $url ); |
|
| 1050 | - } else if ( function_exists( 'curl_init' ) ) { |
|
| 1048 | + if (ini_get('allow_url_fopen')) { |
|
| 1049 | + $response = file_get_contents($url); |
|
| 1050 | + } else if (function_exists('curl_init')) { |
|
| 1051 | 1051 | $ch = curl_init(); |
| 1052 | 1052 | |
| 1053 | - curl_setopt( $ch, CURLOPT_URL, $url ); |
|
| 1054 | - curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT, 30 ); |
|
| 1055 | - curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true ); |
|
| 1056 | - curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, 0 ); |
|
| 1057 | - curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, 0 ); |
|
| 1053 | + curl_setopt($ch, CURLOPT_URL, $url); |
|
| 1054 | + curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30); |
|
| 1055 | + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
|
| 1056 | + curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); |
|
| 1057 | + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); |
|
| 1058 | 1058 | |
| 1059 | - $response = curl_exec( $ch ); |
|
| 1059 | + $response = curl_exec($ch); |
|
| 1060 | 1060 | |
| 1061 | - if ( curl_errno( $ch ) ) { |
|
| 1062 | - wpinv_error_log( curl_error( $ch ), 'VIES CHECK ERROR' ); |
|
| 1061 | + if (curl_errno($ch)) { |
|
| 1062 | + wpinv_error_log(curl_error($ch), 'VIES CHECK ERROR'); |
|
| 1063 | 1063 | $response = ''; |
| 1064 | 1064 | } |
| 1065 | 1065 | |
| 1066 | - curl_close( $ch ); |
|
| 1066 | + curl_close($ch); |
|
| 1067 | 1067 | } else { |
| 1068 | - wpinv_error_log( 'To use VIES CHECK you must have allow_url_fopen is ON or cURL installed & active on your server.', 'VIES CHECK ERROR' ); |
|
| 1068 | + wpinv_error_log('To use VIES CHECK you must have allow_url_fopen is ON or cURL installed & active on your server.', 'VIES CHECK ERROR'); |
|
| 1069 | 1069 | } |
| 1070 | 1070 | |
| 1071 | - if ( empty( $response ) ) { |
|
| 1071 | + if (empty($response)) { |
|
| 1072 | 1072 | return $result; |
| 1073 | 1073 | } |
| 1074 | 1074 | |
| 1075 | - if ( preg_match( '/invalid VAT number/i', $response ) ) { |
|
| 1075 | + if (preg_match('/invalid VAT number/i', $response)) { |
|
| 1076 | 1076 | return false; |
| 1077 | - } else if ( preg_match( '/valid VAT number/i', $response, $matches ) ) { |
|
| 1078 | - $content = explode( "valid VAT number", htmlentities( $response ) ); |
|
| 1077 | + } else if (preg_match('/valid VAT number/i', $response, $matches)) { |
|
| 1078 | + $content = explode("valid VAT number", htmlentities($response)); |
|
| 1079 | 1079 | |
| 1080 | - if ( !empty( $content[1] ) ) { |
|
| 1081 | - preg_match_all( '/<tr>(.*?)<td.*?>(.*?)<\/td>(.*?)<\/tr>/si', html_entity_decode( $content[1] ), $matches ); |
|
| 1080 | + if (!empty($content[1])) { |
|
| 1081 | + preg_match_all('/<tr>(.*?)<td.*?>(.*?)<\/td>(.*?)<\/tr>/si', html_entity_decode($content[1]), $matches); |
|
| 1082 | 1082 | |
| 1083 | - if ( !empty( $matches[2] ) && $matches[3] ) { |
|
| 1083 | + if (!empty($matches[2]) && $matches[3]) { |
|
| 1084 | 1084 | $return = array(); |
| 1085 | 1085 | |
| 1086 | - foreach ( $matches[2] as $key => $label ) { |
|
| 1087 | - $label = trim( $label ); |
|
| 1086 | + foreach ($matches[2] as $key => $label) { |
|
| 1087 | + $label = trim($label); |
|
| 1088 | 1088 | |
| 1089 | - switch ( strtolower( $label ) ) { |
|
| 1089 | + switch (strtolower($label)) { |
|
| 1090 | 1090 | case 'member state': |
| 1091 | - $return['state'] = trim( strip_tags( $matches[3][$key] ) ); |
|
| 1091 | + $return['state'] = trim(strip_tags($matches[3][$key])); |
|
| 1092 | 1092 | break; |
| 1093 | 1093 | case 'vat number': |
| 1094 | - $return['number'] = trim( strip_tags( $matches[3][$key] ) ); |
|
| 1094 | + $return['number'] = trim(strip_tags($matches[3][$key])); |
|
| 1095 | 1095 | break; |
| 1096 | 1096 | case 'name': |
| 1097 | - $return['company'] = trim( strip_tags( $matches[3][$key] ) ); |
|
| 1097 | + $return['company'] = trim(strip_tags($matches[3][$key])); |
|
| 1098 | 1098 | break; |
| 1099 | 1099 | case 'address': |
| 1100 | - $address = str_replace( array( "<br><br>", "<br /><br />", "<br/><br/>" ), "<br>", html_entity_decode( trim( $matches[3][$key] ) ) ); |
|
| 1101 | - $return['address'] = trim( strip_tags( $address, '<br>' ) ); |
|
| 1100 | + $address = str_replace(array("<br><br>", "<br /><br />", "<br/><br/>"), "<br>", html_entity_decode(trim($matches[3][$key]))); |
|
| 1101 | + $return['address'] = trim(strip_tags($address, '<br>')); |
|
| 1102 | 1102 | break; |
| 1103 | 1103 | case 'consultation number': |
| 1104 | - $return['consultation'] = trim( strip_tags( $matches[3][$key] ) ); |
|
| 1104 | + $return['consultation'] = trim(strip_tags($matches[3][$key])); |
|
| 1105 | 1105 | break; |
| 1106 | 1106 | } |
| 1107 | 1107 | } |
| 1108 | 1108 | |
| 1109 | - if ( !empty( $return ) ) { |
|
| 1109 | + if (!empty($return)) { |
|
| 1110 | 1110 | return $return; |
| 1111 | 1111 | } |
| 1112 | 1112 | } |
@@ -1118,55 +1118,55 @@ discard block |
||
| 1118 | 1118 | } |
| 1119 | 1119 | } |
| 1120 | 1120 | |
| 1121 | - public static function check_vat( $vat_number, $country_code = '' ) { |
|
| 1121 | + public static function check_vat($vat_number, $country_code = '') { |
|
| 1122 | 1122 | $vat_name = self::get_vat_name(); |
| 1123 | 1123 | |
| 1124 | 1124 | $return = array(); |
| 1125 | 1125 | $return['valid'] = false; |
| 1126 | - $return['message'] = wp_sprintf( __( '%s number not validated', 'invoicing' ), $vat_name ); |
|
| 1126 | + $return['message'] = wp_sprintf(__('%s number not validated', 'invoicing'), $vat_name); |
|
| 1127 | 1127 | |
| 1128 | - if ( !wpinv_get_option( 'vat_offline_check' ) && !self::offline_check( $vat_number, $country_code ) ) { |
|
| 1128 | + if (!wpinv_get_option('vat_offline_check') && !self::offline_check($vat_number, $country_code)) { |
|
| 1129 | 1129 | return $return; |
| 1130 | 1130 | } |
| 1131 | 1131 | |
| 1132 | - $response = self::vies_check( $vat_number, $country_code ); |
|
| 1132 | + $response = self::vies_check($vat_number, $country_code); |
|
| 1133 | 1133 | |
| 1134 | - if ( $response ) { |
|
| 1135 | - $return['valid'] = true; |
|
| 1134 | + if ($response) { |
|
| 1135 | + $return['valid'] = true; |
|
| 1136 | 1136 | |
| 1137 | - if ( is_array( $response ) ) { |
|
| 1138 | - $return['company'] = isset( $response['company'] ) ? $response['company'] : ''; |
|
| 1139 | - $return['address'] = isset( $response['address'] ) ? $response['address'] : ''; |
|
| 1137 | + if (is_array($response)) { |
|
| 1138 | + $return['company'] = isset($response['company']) ? $response['company'] : ''; |
|
| 1139 | + $return['address'] = isset($response['address']) ? $response['address'] : ''; |
|
| 1140 | 1140 | $return['message'] = $return['company'] . '<br/>' . $return['address']; |
| 1141 | 1141 | } |
| 1142 | 1142 | } else { |
| 1143 | 1143 | $return['valid'] = false; |
| 1144 | - $return['message'] = wp_sprintf( __( 'Fail to validate the %s number: EU Commission VAT server (VIES) check fails.', 'invoicing' ), $vat_name ); |
|
| 1144 | + $return['message'] = wp_sprintf(__('Fail to validate the %s number: EU Commission VAT server (VIES) check fails.', 'invoicing'), $vat_name); |
|
| 1145 | 1145 | } |
| 1146 | 1146 | |
| 1147 | 1147 | return $return; |
| 1148 | 1148 | } |
| 1149 | 1149 | |
| 1150 | - public static function request_euvatrates( $group ) { |
|
| 1150 | + public static function request_euvatrates($group) { |
|
| 1151 | 1151 | $response = array(); |
| 1152 | 1152 | $response['success'] = false; |
| 1153 | 1153 | $response['error'] = null; |
| 1154 | 1154 | $response['eurates'] = null; |
| 1155 | 1155 | |
| 1156 | 1156 | $euvatrates_url = 'https://euvatrates.com/rates.json'; |
| 1157 | - $euvatrates_url = apply_filters( 'wpinv_euvatrates_url', $euvatrates_url ); |
|
| 1158 | - $api_response = wp_remote_get( $euvatrates_url ); |
|
| 1157 | + $euvatrates_url = apply_filters('wpinv_euvatrates_url', $euvatrates_url); |
|
| 1158 | + $api_response = wp_remote_get($euvatrates_url); |
|
| 1159 | 1159 | |
| 1160 | 1160 | try { |
| 1161 | - if ( is_wp_error( $api_response ) ) { |
|
| 1162 | - $response['error'] = __( $api_response->get_error_message(), 'invoicing' ); |
|
| 1161 | + if (is_wp_error($api_response)) { |
|
| 1162 | + $response['error'] = __($api_response->get_error_message(), 'invoicing'); |
|
| 1163 | 1163 | } else { |
| 1164 | - $body = json_decode( $api_response['body'] ); |
|
| 1164 | + $body = json_decode($api_response['body']); |
|
| 1165 | 1165 | |
| 1166 | - if ( isset( $body->rates ) ) { |
|
| 1166 | + if (isset($body->rates)) { |
|
| 1167 | 1167 | $rates = array(); |
| 1168 | 1168 | |
| 1169 | - foreach ( $body->rates as $country_code => $rate ) { |
|
| 1169 | + foreach ($body->rates as $country_code => $rate) { |
|
| 1170 | 1170 | $vat_rate = array(); |
| 1171 | 1171 | $vat_rate['country'] = $rate->country; |
| 1172 | 1172 | $vat_rate['standard'] = (float)$rate->standard_rate; |
@@ -1174,7 +1174,7 @@ discard block |
||
| 1174 | 1174 | $vat_rate['superreduced'] = (float)$rate->super_reduced_rate; |
| 1175 | 1175 | $vat_rate['parking'] = (float)$rate->parking_rate; |
| 1176 | 1176 | |
| 1177 | - if ( $group !== '' && in_array( $group, array( 'standard', 'reduced', 'superreduced', 'parking' ) ) ) { |
|
| 1177 | + if ($group !== '' && in_array($group, array('standard', 'reduced', 'superreduced', 'parking'))) { |
|
| 1178 | 1178 | $vat_rate_group = array(); |
| 1179 | 1179 | $vat_rate_group['country'] = $rate->country; |
| 1180 | 1180 | $vat_rate_group[$group] = $vat_rate[$group]; |
@@ -1186,79 +1186,79 @@ discard block |
||
| 1186 | 1186 | } |
| 1187 | 1187 | |
| 1188 | 1188 | $response['success'] = true; |
| 1189 | - $response['rates'] = apply_filters( 'wpinv_process_euvatrates', $rates, $api_response, $group ); |
|
| 1189 | + $response['rates'] = apply_filters('wpinv_process_euvatrates', $rates, $api_response, $group); |
|
| 1190 | 1190 | } else { |
| 1191 | - $response['error'] = __( 'No EU rates found!', 'invoicing' ); |
|
| 1191 | + $response['error'] = __('No EU rates found!', 'invoicing'); |
|
| 1192 | 1192 | } |
| 1193 | 1193 | } |
| 1194 | - } catch ( Exception $e ) { |
|
| 1195 | - $response['error'] = __( $e->getMessage(), 'invoicing' ); |
|
| 1194 | + } catch (Exception $e) { |
|
| 1195 | + $response['error'] = __($e->getMessage(), 'invoicing'); |
|
| 1196 | 1196 | } |
| 1197 | 1197 | |
| 1198 | - return apply_filters( 'wpinv_response_euvatrates', $response, $group ); |
|
| 1198 | + return apply_filters('wpinv_response_euvatrates', $response, $group); |
|
| 1199 | 1199 | } |
| 1200 | 1200 | |
| 1201 | - public static function requires_vat( $requires_vat = false, $user_id = 0, $is_digital = null ) { |
|
| 1201 | + public static function requires_vat($requires_vat = false, $user_id = 0, $is_digital = null) { |
|
| 1202 | 1202 | global $wpi_item_id, $wpi_country; |
| 1203 | 1203 | |
| 1204 | - if ( !empty( $_POST['wpinv_country'] ) ) { |
|
| 1205 | - $country_code = trim( $_POST['wpinv_country'] ); |
|
| 1206 | - } else if ( !empty( $_POST['country'] ) ) { |
|
| 1207 | - $country_code = trim( $_POST['country'] ); |
|
| 1208 | - } else if ( !empty( $wpi_country ) ) { |
|
| 1204 | + if (!empty($_POST['wpinv_country'])) { |
|
| 1205 | + $country_code = trim($_POST['wpinv_country']); |
|
| 1206 | + } else if (!empty($_POST['country'])) { |
|
| 1207 | + $country_code = trim($_POST['country']); |
|
| 1208 | + } else if (!empty($wpi_country)) { |
|
| 1209 | 1209 | $country_code = $wpi_country; |
| 1210 | 1210 | } else { |
| 1211 | - $country_code = self::get_user_country( '', $user_id ); |
|
| 1211 | + $country_code = self::get_user_country('', $user_id); |
|
| 1212 | 1212 | } |
| 1213 | 1213 | |
| 1214 | - if ( $is_digital === null && $wpi_item_id ) { |
|
| 1215 | - $is_digital = $wpi_item_id ? self::item_has_digital_rule( $wpi_item_id ) : self::allow_vat_rules(); |
|
| 1214 | + if ($is_digital === null && $wpi_item_id) { |
|
| 1215 | + $is_digital = $wpi_item_id ? self::item_has_digital_rule($wpi_item_id) : self::allow_vat_rules(); |
|
| 1216 | 1216 | } |
| 1217 | 1217 | |
| 1218 | - if ( !empty( $country_code ) ) { |
|
| 1219 | - $requires_vat = ( self::is_eu_state( $country_code ) && ( self::is_eu_state( self::$default_country ) || $is_digital ) ) || ( self::is_gst_country( $country_code ) && self::is_gst_country( self::$default_country ) ); |
|
| 1218 | + if (!empty($country_code)) { |
|
| 1219 | + $requires_vat = (self::is_eu_state($country_code) && (self::is_eu_state(self::$default_country) || $is_digital)) || (self::is_gst_country($country_code) && self::is_gst_country(self::$default_country)); |
|
| 1220 | 1220 | } |
| 1221 | 1221 | |
| 1222 | - return apply_filters( 'wpinv_requires_vat', $requires_vat, $user_id ); |
|
| 1222 | + return apply_filters('wpinv_requires_vat', $requires_vat, $user_id); |
|
| 1223 | 1223 | } |
| 1224 | 1224 | |
| 1225 | - public static function tax_label( $label = '' ) { |
|
| 1225 | + public static function tax_label($label = '') { |
|
| 1226 | 1226 | global $wpi_requires_vat; |
| 1227 | 1227 | |
| 1228 | - if ( !( $wpi_requires_vat !== 0 && $wpi_requires_vat ) ) { |
|
| 1229 | - $wpi_requires_vat = self::requires_vat( 0, false ); |
|
| 1228 | + if (!($wpi_requires_vat !== 0 && $wpi_requires_vat)) { |
|
| 1229 | + $wpi_requires_vat = self::requires_vat(0, false); |
|
| 1230 | 1230 | } |
| 1231 | 1231 | |
| 1232 | - return $wpi_requires_vat ? __( self::get_vat_name(), 'invoicing' ) : ( $label ? $label : __( 'Tax', 'invoicing' ) ); |
|
| 1232 | + return $wpi_requires_vat ? __(self::get_vat_name(), 'invoicing') : ($label ? $label : __('Tax', 'invoicing')); |
|
| 1233 | 1233 | } |
| 1234 | 1234 | |
| 1235 | 1235 | public static function standard_rates_label() { |
| 1236 | - return __( 'Standard Rates', 'invoicing' ); |
|
| 1236 | + return __('Standard Rates', 'invoicing'); |
|
| 1237 | 1237 | } |
| 1238 | 1238 | |
| 1239 | - public static function get_rate_classes( $with_desc = false ) { |
|
| 1240 | - $rate_classes_option = get_option( '_wpinv_vat_rate_classes', true ); |
|
| 1241 | - $classes = maybe_unserialize( $rate_classes_option ); |
|
| 1239 | + public static function get_rate_classes($with_desc = false) { |
|
| 1240 | + $rate_classes_option = get_option('_wpinv_vat_rate_classes', true); |
|
| 1241 | + $classes = maybe_unserialize($rate_classes_option); |
|
| 1242 | 1242 | |
| 1243 | - if ( empty( $classes ) || !is_array( $classes ) ) { |
|
| 1243 | + if (empty($classes) || !is_array($classes)) { |
|
| 1244 | 1244 | $classes = array(); |
| 1245 | 1245 | } |
| 1246 | 1246 | |
| 1247 | 1247 | $rate_classes = array(); |
| 1248 | - if ( !array_key_exists( '_standard', $classes ) ) { |
|
| 1249 | - if ( $with_desc ) { |
|
| 1250 | - $rate_classes['_standard'] = array( 'name' => self::standard_rates_label(), 'desc' => __( 'EU member states standard VAT rates', 'invoicing' ) ); |
|
| 1248 | + if (!array_key_exists('_standard', $classes)) { |
|
| 1249 | + if ($with_desc) { |
|
| 1250 | + $rate_classes['_standard'] = array('name' => self::standard_rates_label(), 'desc' => __('EU member states standard VAT rates', 'invoicing')); |
|
| 1251 | 1251 | } else { |
| 1252 | 1252 | $rate_classes['_standard'] = self::standard_rates_label(); |
| 1253 | 1253 | } |
| 1254 | 1254 | } |
| 1255 | 1255 | |
| 1256 | - foreach ( $classes as $key => $class ) { |
|
| 1257 | - $name = !empty( $class['name'] ) ? __( $class['name'], 'invoicing' ) : $key; |
|
| 1258 | - $desc = !empty( $class['desc'] ) ? __( $class['desc'], 'invoicing' ) : ''; |
|
| 1256 | + foreach ($classes as $key => $class) { |
|
| 1257 | + $name = !empty($class['name']) ? __($class['name'], 'invoicing') : $key; |
|
| 1258 | + $desc = !empty($class['desc']) ? __($class['desc'], 'invoicing') : ''; |
|
| 1259 | 1259 | |
| 1260 | - if ( $with_desc ) { |
|
| 1261 | - $rate_classes[$key] = array( 'name' => $name, 'desc' => $desc ); |
|
| 1260 | + if ($with_desc) { |
|
| 1261 | + $rate_classes[$key] = array('name' => $name, 'desc' => $desc); |
|
| 1262 | 1262 | } else { |
| 1263 | 1263 | $rate_classes[$key] = $name; |
| 1264 | 1264 | } |
@@ -1269,15 +1269,15 @@ discard block |
||
| 1269 | 1269 | |
| 1270 | 1270 | public static function get_all_classes() { |
| 1271 | 1271 | $classes = self::get_rate_classes(); |
| 1272 | - $classes['_exempt'] = __( 'Exempt (0%)', 'invoicing' ); |
|
| 1272 | + $classes['_exempt'] = __('Exempt (0%)', 'invoicing'); |
|
| 1273 | 1273 | |
| 1274 | - return apply_filters( 'wpinv_vat_get_all_classes', $classes ); |
|
| 1274 | + return apply_filters('wpinv_vat_get_all_classes', $classes); |
|
| 1275 | 1275 | } |
| 1276 | 1276 | |
| 1277 | - public static function get_class_desc( $rate_class ) { |
|
| 1278 | - $rate_classes = self::get_rate_classes( true ); |
|
| 1277 | + public static function get_class_desc($rate_class) { |
|
| 1278 | + $rate_classes = self::get_rate_classes(true); |
|
| 1279 | 1279 | |
| 1280 | - if ( !empty( $rate_classes ) && isset( $rate_classes[$rate_class] ) && isset( $rate_classes[$rate_class]['desc'] ) ) { |
|
| 1280 | + if (!empty($rate_classes) && isset($rate_classes[$rate_class]) && isset($rate_classes[$rate_class]['desc'])) { |
|
| 1281 | 1281 | return $rate_classes[$rate_class]['desc']; |
| 1282 | 1282 | } |
| 1283 | 1283 | |
@@ -1293,106 +1293,106 @@ discard block |
||
| 1293 | 1293 | 'increased' => 'Increased' |
| 1294 | 1294 | ); |
| 1295 | 1295 | |
| 1296 | - return apply_filters( 'wpinv_get_vat_groups', $vat_groups ); |
|
| 1296 | + return apply_filters('wpinv_get_vat_groups', $vat_groups); |
|
| 1297 | 1297 | } |
| 1298 | 1298 | |
| 1299 | 1299 | public static function get_rules() { |
| 1300 | 1300 | $vat_rules = array( |
| 1301 | - 'digital' => __( 'Digital Product', 'invoicing' ), |
|
| 1302 | - 'physical' => __( 'Physical Product', 'invoicing' ) |
|
| 1301 | + 'digital' => __('Digital Product', 'invoicing'), |
|
| 1302 | + 'physical' => __('Physical Product', 'invoicing') |
|
| 1303 | 1303 | ); |
| 1304 | - return apply_filters( 'wpinv_get_vat_rules', $vat_rules ); |
|
| 1304 | + return apply_filters('wpinv_get_vat_rules', $vat_rules); |
|
| 1305 | 1305 | } |
| 1306 | 1306 | |
| 1307 | - public static function get_vat_rates( $class ) { |
|
| 1308 | - if ( $class === '_standard' ) { |
|
| 1307 | + public static function get_vat_rates($class) { |
|
| 1308 | + if ($class === '_standard') { |
|
| 1309 | 1309 | return wpinv_get_tax_rates(); |
| 1310 | 1310 | } |
| 1311 | 1311 | |
| 1312 | 1312 | $rates = self::get_non_standard_rates(); |
| 1313 | 1313 | |
| 1314 | - return array_key_exists( $class, $rates ) ? $rates[$class] : array(); |
|
| 1314 | + return array_key_exists($class, $rates) ? $rates[$class] : array(); |
|
| 1315 | 1315 | } |
| 1316 | 1316 | |
| 1317 | 1317 | public static function get_non_standard_rates() { |
| 1318 | - $option = get_option( 'wpinv_vat_rates', array()); |
|
| 1319 | - return is_array( $option ) ? $option : array(); |
|
| 1318 | + $option = get_option('wpinv_vat_rates', array()); |
|
| 1319 | + return is_array($option) ? $option : array(); |
|
| 1320 | 1320 | } |
| 1321 | 1321 | |
| 1322 | 1322 | public static function allow_vat_rules() { |
| 1323 | - return ( wpinv_use_taxes() && wpinv_get_option( 'apply_vat_rules' ) ? true : false ); |
|
| 1323 | + return (wpinv_use_taxes() && wpinv_get_option('apply_vat_rules') ? true : false); |
|
| 1324 | 1324 | } |
| 1325 | 1325 | |
| 1326 | 1326 | public static function allow_vat_classes() { |
| 1327 | 1327 | return false; // TODO |
| 1328 | - return ( wpinv_get_option( 'vat_allow_classes' ) ? true : false ); |
|
| 1328 | + return (wpinv_get_option('vat_allow_classes') ? true : false); |
|
| 1329 | 1329 | } |
| 1330 | 1330 | |
| 1331 | - public static function get_item_class( $postID ) { |
|
| 1332 | - $class = get_post_meta( $postID, '_wpinv_vat_class', true ); |
|
| 1331 | + public static function get_item_class($postID) { |
|
| 1332 | + $class = get_post_meta($postID, '_wpinv_vat_class', true); |
|
| 1333 | 1333 | |
| 1334 | - if ( empty( $class ) ) { |
|
| 1334 | + if (empty($class)) { |
|
| 1335 | 1335 | $class = '_standard'; |
| 1336 | 1336 | } |
| 1337 | 1337 | |
| 1338 | - return apply_filters( 'wpinv_get_item_vat_class', $class, $postID ); |
|
| 1338 | + return apply_filters('wpinv_get_item_vat_class', $class, $postID); |
|
| 1339 | 1339 | } |
| 1340 | 1340 | |
| 1341 | - public static function item_class_label( $postID ) { |
|
| 1341 | + public static function item_class_label($postID) { |
|
| 1342 | 1342 | $vat_classes = self::get_all_classes(); |
| 1343 | 1343 | |
| 1344 | - $class = self::get_item_class( $postID ); |
|
| 1345 | - $class = isset( $vat_classes[$class] ) ? $vat_classes[$class] : __( $class, 'invoicing' ); |
|
| 1344 | + $class = self::get_item_class($postID); |
|
| 1345 | + $class = isset($vat_classes[$class]) ? $vat_classes[$class] : __($class, 'invoicing'); |
|
| 1346 | 1346 | |
| 1347 | - return apply_filters( 'wpinv_item_class_label', $class, $postID ); |
|
| 1347 | + return apply_filters('wpinv_item_class_label', $class, $postID); |
|
| 1348 | 1348 | } |
| 1349 | 1349 | |
| 1350 | - public static function get_item_rule( $postID ) { |
|
| 1351 | - $rule_type = get_post_meta( $postID, '_wpinv_vat_rule', true ); |
|
| 1350 | + public static function get_item_rule($postID) { |
|
| 1351 | + $rule_type = get_post_meta($postID, '_wpinv_vat_rule', true); |
|
| 1352 | 1352 | |
| 1353 | - if ( empty( $rule_type ) ) { |
|
| 1353 | + if (empty($rule_type)) { |
|
| 1354 | 1354 | $rule_type = self::allow_vat_rules() ? 'digital' : 'physical'; |
| 1355 | 1355 | } |
| 1356 | 1356 | |
| 1357 | - return apply_filters( 'wpinv_item_get_vat_rule', $rule_type, $postID ); |
|
| 1357 | + return apply_filters('wpinv_item_get_vat_rule', $rule_type, $postID); |
|
| 1358 | 1358 | } |
| 1359 | 1359 | |
| 1360 | - public static function item_rule_label( $postID ) { |
|
| 1360 | + public static function item_rule_label($postID) { |
|
| 1361 | 1361 | $vat_rules = self::get_rules(); |
| 1362 | - $vat_rule = self::get_item_rule( $postID ); |
|
| 1363 | - $vat_rule = isset( $vat_rules[$vat_rule] ) ? $vat_rules[$vat_rule] : $vat_rule; |
|
| 1362 | + $vat_rule = self::get_item_rule($postID); |
|
| 1363 | + $vat_rule = isset($vat_rules[$vat_rule]) ? $vat_rules[$vat_rule] : $vat_rule; |
|
| 1364 | 1364 | |
| 1365 | - return apply_filters( 'wpinv_item_rule_label', $vat_rule, $postID ); |
|
| 1365 | + return apply_filters('wpinv_item_rule_label', $vat_rule, $postID); |
|
| 1366 | 1366 | } |
| 1367 | 1367 | |
| 1368 | - public static function item_has_digital_rule( $item_id = 0 ) { |
|
| 1369 | - return self::get_item_rule( $item_id ) == 'digital' ? true : false; |
|
| 1368 | + public static function item_has_digital_rule($item_id = 0) { |
|
| 1369 | + return self::get_item_rule($item_id) == 'digital' ? true : false; |
|
| 1370 | 1370 | } |
| 1371 | 1371 | |
| 1372 | - public static function invoice_has_digital_rule( $invoice = 0 ) { |
|
| 1373 | - if ( !self::allow_vat_rules() ) { |
|
| 1372 | + public static function invoice_has_digital_rule($invoice = 0) { |
|
| 1373 | + if (!self::allow_vat_rules()) { |
|
| 1374 | 1374 | return false; |
| 1375 | 1375 | } |
| 1376 | 1376 | |
| 1377 | - if ( empty( $invoice ) ) { |
|
| 1377 | + if (empty($invoice)) { |
|
| 1378 | 1378 | return true; |
| 1379 | 1379 | } |
| 1380 | 1380 | |
| 1381 | - if ( is_int( $invoice ) ) { |
|
| 1382 | - $invoice = new WPInv_Invoice( $invoice ); |
|
| 1381 | + if (is_int($invoice)) { |
|
| 1382 | + $invoice = new WPInv_Invoice($invoice); |
|
| 1383 | 1383 | } |
| 1384 | 1384 | |
| 1385 | - if ( !( is_object( $invoice ) && is_a( $invoice, 'WPInv_Invoice' ) ) ) { |
|
| 1385 | + if (!(is_object($invoice) && is_a($invoice, 'WPInv_Invoice'))) { |
|
| 1386 | 1386 | return true; |
| 1387 | 1387 | } |
| 1388 | 1388 | |
| 1389 | - $cart_items = $invoice->get_cart_details(); |
|
| 1389 | + $cart_items = $invoice->get_cart_details(); |
|
| 1390 | 1390 | |
| 1391 | - if ( !empty( $cart_items ) ) { |
|
| 1391 | + if (!empty($cart_items)) { |
|
| 1392 | 1392 | $has_digital_rule = false; |
| 1393 | 1393 | |
| 1394 | - foreach ( $cart_items as $key => $item ) { |
|
| 1395 | - if ( self::item_has_digital_rule( $item['id'] ) ) { |
|
| 1394 | + foreach ($cart_items as $key => $item) { |
|
| 1395 | + if (self::item_has_digital_rule($item['id'])) { |
|
| 1396 | 1396 | $has_digital_rule = true; |
| 1397 | 1397 | break; |
| 1398 | 1398 | } |
@@ -1404,67 +1404,67 @@ discard block |
||
| 1404 | 1404 | return $has_digital_rule; |
| 1405 | 1405 | } |
| 1406 | 1406 | |
| 1407 | - public static function item_is_taxable( $item_id = 0, $country = false, $state = false ) { |
|
| 1408 | - if ( !wpinv_use_taxes() ) { |
|
| 1407 | + public static function item_is_taxable($item_id = 0, $country = false, $state = false) { |
|
| 1408 | + if (!wpinv_use_taxes()) { |
|
| 1409 | 1409 | return false; |
| 1410 | 1410 | } |
| 1411 | 1411 | |
| 1412 | 1412 | $is_taxable = true; |
| 1413 | 1413 | |
| 1414 | - if ( !empty( $item_id ) && self::get_item_class( $item_id ) == '_exempt' ) { |
|
| 1414 | + if (!empty($item_id) && self::get_item_class($item_id) == '_exempt') { |
|
| 1415 | 1415 | $is_taxable = false; |
| 1416 | 1416 | } |
| 1417 | 1417 | |
| 1418 | - return apply_filters( 'wpinv_item_is_taxable', $is_taxable, $item_id, $country , $state ); |
|
| 1418 | + return apply_filters('wpinv_item_is_taxable', $is_taxable, $item_id, $country, $state); |
|
| 1419 | 1419 | } |
| 1420 | 1420 | |
| 1421 | - public static function find_rate( $country, $state, $rate, $class ) { |
|
| 1421 | + public static function find_rate($country, $state, $rate, $class) { |
|
| 1422 | 1422 | global $wpi_zero_tax; |
| 1423 | 1423 | |
| 1424 | - if ( $class === '_exempt' || $wpi_zero_tax ) { |
|
| 1424 | + if ($class === '_exempt' || $wpi_zero_tax) { |
|
| 1425 | 1425 | return 0; |
| 1426 | 1426 | } |
| 1427 | 1427 | |
| 1428 | - $tax_rates = wpinv_get_tax_rates(); |
|
| 1428 | + $tax_rates = wpinv_get_tax_rates(); |
|
| 1429 | 1429 | |
| 1430 | - if ( $class !== '_standard' ) { |
|
| 1431 | - $class_rates = self::get_vat_rates( $class ); |
|
| 1430 | + if ($class !== '_standard') { |
|
| 1431 | + $class_rates = self::get_vat_rates($class); |
|
| 1432 | 1432 | |
| 1433 | - if ( is_array( $class_rates ) ) { |
|
| 1433 | + if (is_array($class_rates)) { |
|
| 1434 | 1434 | $indexed_class_rates = array(); |
| 1435 | 1435 | |
| 1436 | - foreach ( $class_rates as $key => $cr ) { |
|
| 1436 | + foreach ($class_rates as $key => $cr) { |
|
| 1437 | 1437 | $indexed_class_rates[$cr['country']] = $cr; |
| 1438 | 1438 | } |
| 1439 | 1439 | |
| 1440 | - $tax_rates = array_map( function( $tr ) use( $indexed_class_rates ) { |
|
| 1440 | + $tax_rates = array_map(function($tr) use($indexed_class_rates) { |
|
| 1441 | 1441 | $tr_country = $tr['country']; |
| 1442 | - if ( !isset( $indexed_class_rates[$tr_country] ) ) { |
|
| 1442 | + if (!isset($indexed_class_rates[$tr_country])) { |
|
| 1443 | 1443 | return $tr; |
| 1444 | 1444 | } |
| 1445 | 1445 | $icr = $indexed_class_rates[$tr_country]; |
| 1446 | - return ( empty( $icr['rate'] ) && $icr['rate'] !== '0' ) ? $tr : $icr; |
|
| 1446 | + return (empty($icr['rate']) && $icr['rate'] !== '0') ? $tr : $icr; |
|
| 1447 | 1447 | |
| 1448 | - }, $tax_rates, $class_rates ); |
|
| 1448 | + }, $tax_rates, $class_rates); |
|
| 1449 | 1449 | } |
| 1450 | 1450 | } |
| 1451 | 1451 | |
| 1452 | - if ( !empty( $tax_rates ) ) { |
|
| 1453 | - foreach ( $tax_rates as $key => $tax_rate ) { |
|
| 1454 | - if ( $country != $tax_rate['country'] ) |
|
| 1452 | + if (!empty($tax_rates)) { |
|
| 1453 | + foreach ($tax_rates as $key => $tax_rate) { |
|
| 1454 | + if ($country != $tax_rate['country']) |
|
| 1455 | 1455 | continue; |
| 1456 | 1456 | |
| 1457 | - if ( !empty( $tax_rate['global'] ) ) { |
|
| 1458 | - if ( 0 !== $tax_rate['rate'] || !empty( $tax_rate['rate'] ) ) { |
|
| 1459 | - $rate = number_format( $tax_rate['rate'], 4 ); |
|
| 1457 | + if (!empty($tax_rate['global'])) { |
|
| 1458 | + if (0 !== $tax_rate['rate'] || !empty($tax_rate['rate'])) { |
|
| 1459 | + $rate = number_format($tax_rate['rate'], 4); |
|
| 1460 | 1460 | } |
| 1461 | 1461 | } else { |
| 1462 | - if ( empty( $tax_rate['state'] ) || strtolower( $state ) != strtolower( $tax_rate['state'] ) ) |
|
| 1462 | + if (empty($tax_rate['state']) || strtolower($state) != strtolower($tax_rate['state'])) |
|
| 1463 | 1463 | continue; |
| 1464 | 1464 | |
| 1465 | 1465 | $state_rate = $tax_rate['rate']; |
| 1466 | - if ( 0 !== $state_rate || !empty( $state_rate ) ) { |
|
| 1467 | - $rate = number_format( $state_rate, 4 ); |
|
| 1466 | + if (0 !== $state_rate || !empty($state_rate)) { |
|
| 1467 | + $rate = number_format($state_rate, 4); |
|
| 1468 | 1468 | } |
| 1469 | 1469 | } |
| 1470 | 1470 | } |
@@ -1473,84 +1473,84 @@ discard block |
||
| 1473 | 1473 | return $rate; |
| 1474 | 1474 | } |
| 1475 | 1475 | |
| 1476 | - public static function get_rate( $rate = 1, $country = '', $state = '', $item_id = 0 ) { |
|
| 1476 | + public static function get_rate($rate = 1, $country = '', $state = '', $item_id = 0) { |
|
| 1477 | 1477 | global $wpinv_options, $wpi_session, $wpi_item_id, $wpi_zero_tax; |
| 1478 | 1478 | |
| 1479 | 1479 | $item_id = $item_id > 0 ? $item_id : $wpi_item_id; |
| 1480 | 1480 | $allow_vat_classes = self::allow_vat_classes(); |
| 1481 | - $class = $item_id ? self::get_item_class( $item_id ) : '_standard'; |
|
| 1481 | + $class = $item_id ? self::get_item_class($item_id) : '_standard'; |
|
| 1482 | 1482 | |
| 1483 | - if ( $class === '_exempt' || $wpi_zero_tax ) { |
|
| 1483 | + if ($class === '_exempt' || $wpi_zero_tax) { |
|
| 1484 | 1484 | return 0; |
| 1485 | - } else if ( !$allow_vat_classes ) { |
|
| 1485 | + } else if (!$allow_vat_classes) { |
|
| 1486 | 1486 | $class = '_standard'; |
| 1487 | 1487 | } |
| 1488 | 1488 | |
| 1489 | - if( !empty( $_POST['wpinv_country'] ) ) { |
|
| 1489 | + if (!empty($_POST['wpinv_country'])) { |
|
| 1490 | 1490 | $post_country = $_POST['wpinv_country']; |
| 1491 | - } elseif( !empty( $_POST['wpinv_country'] ) ) { |
|
| 1491 | + } elseif (!empty($_POST['wpinv_country'])) { |
|
| 1492 | 1492 | $post_country = $_POST['wpinv_country']; |
| 1493 | - } elseif( !empty( $_POST['country'] ) ) { |
|
| 1493 | + } elseif (!empty($_POST['country'])) { |
|
| 1494 | 1494 | $post_country = $_POST['country']; |
| 1495 | 1495 | } else { |
| 1496 | 1496 | $post_country = ''; |
| 1497 | 1497 | } |
| 1498 | 1498 | |
| 1499 | - $country = !empty( $post_country ) ? $post_country : wpinv_default_billing_country( $country ); |
|
| 1500 | - $base_country = wpinv_is_base_country( $country ); |
|
| 1499 | + $country = !empty($post_country) ? $post_country : wpinv_default_billing_country($country); |
|
| 1500 | + $base_country = wpinv_is_base_country($country); |
|
| 1501 | 1501 | |
| 1502 | - $requires_vat = self::requires_vat( 0, false ); |
|
| 1503 | - $is_digital = self::get_item_rule( $item_id ) == 'digital' ; |
|
| 1504 | - $rate = $requires_vat && isset( $wpinv_options['eu_fallback_rate'] ) ? $wpinv_options['eu_fallback_rate'] : $rate; |
|
| 1502 | + $requires_vat = self::requires_vat(0, false); |
|
| 1503 | + $is_digital = self::get_item_rule($item_id) == 'digital'; |
|
| 1504 | + $rate = $requires_vat && isset($wpinv_options['eu_fallback_rate']) ? $wpinv_options['eu_fallback_rate'] : $rate; |
|
| 1505 | 1505 | |
| 1506 | - if ( self::same_country_rule() == 'no' && $base_country ) { // Disable VAT to same country |
|
| 1506 | + if (self::same_country_rule() == 'no' && $base_country) { // Disable VAT to same country |
|
| 1507 | 1507 | $rate = 0; |
| 1508 | - } else if ( $requires_vat ) { |
|
| 1509 | - $vat_number = self::get_user_vat_number( '', 0, true ); |
|
| 1508 | + } else if ($requires_vat) { |
|
| 1509 | + $vat_number = self::get_user_vat_number('', 0, true); |
|
| 1510 | 1510 | $vat_info = self::current_vat_data(); |
| 1511 | 1511 | |
| 1512 | - if ( is_array( $vat_info ) ) { |
|
| 1513 | - $vat_number = isset( $vat_info['number'] ) && !empty( $vat_info['valid'] ) ? $vat_info['number'] : ""; |
|
| 1512 | + if (is_array($vat_info)) { |
|
| 1513 | + $vat_number = isset($vat_info['number']) && !empty($vat_info['valid']) ? $vat_info['number'] : ""; |
|
| 1514 | 1514 | } |
| 1515 | 1515 | |
| 1516 | - if ( $country == 'UK' ) { |
|
| 1516 | + if ($country == 'UK') { |
|
| 1517 | 1517 | $country = 'GB'; |
| 1518 | 1518 | } |
| 1519 | 1519 | |
| 1520 | - if ( !empty( $vat_number ) ) { |
|
| 1520 | + if (!empty($vat_number)) { |
|
| 1521 | 1521 | $rate = 0; |
| 1522 | 1522 | } else { |
| 1523 | - $rate = self::find_rate( $country, $state, $rate, $class ); // Fix if there are no tax rated and you try to pay an invoice it does not add the fallback tax rate |
|
| 1523 | + $rate = self::find_rate($country, $state, $rate, $class); // Fix if there are no tax rated and you try to pay an invoice it does not add the fallback tax rate |
|
| 1524 | 1524 | } |
| 1525 | 1525 | |
| 1526 | - if ( empty( $vat_number ) && !$is_digital ) { |
|
| 1527 | - if ( $base_country ) { |
|
| 1528 | - $rate = self::find_rate( $country, null, $rate, $class ); |
|
| 1526 | + if (empty($vat_number) && !$is_digital) { |
|
| 1527 | + if ($base_country) { |
|
| 1528 | + $rate = self::find_rate($country, null, $rate, $class); |
|
| 1529 | 1529 | } else { |
| 1530 | - if ( empty( $country ) && isset( $wpinv_options['eu_fallback_rate'] ) ) { |
|
| 1530 | + if (empty($country) && isset($wpinv_options['eu_fallback_rate'])) { |
|
| 1531 | 1531 | $rate = $wpinv_options['eu_fallback_rate']; |
| 1532 | - } else if( !empty( $country ) ) { |
|
| 1533 | - $rate = self::find_rate( $country, $state, $rate, $class ); |
|
| 1532 | + } else if (!empty($country)) { |
|
| 1533 | + $rate = self::find_rate($country, $state, $rate, $class); |
|
| 1534 | 1534 | } |
| 1535 | 1535 | } |
| 1536 | - } else if ( empty( $vat_number ) || ( self::same_country_rule() == 'always' && $base_country ) ) { |
|
| 1537 | - if ( empty( $country ) && isset( $wpinv_options['eu_fallback_rate'] ) ) { |
|
| 1536 | + } else if (empty($vat_number) || (self::same_country_rule() == 'always' && $base_country)) { |
|
| 1537 | + if (empty($country) && isset($wpinv_options['eu_fallback_rate'])) { |
|
| 1538 | 1538 | $rate = $wpinv_options['eu_fallback_rate']; |
| 1539 | - } else if( !empty( $country ) ) { |
|
| 1540 | - $rate = self::find_rate( $country, $state, $rate, $class ); |
|
| 1539 | + } else if (!empty($country)) { |
|
| 1540 | + $rate = self::find_rate($country, $state, $rate, $class); |
|
| 1541 | 1541 | } |
| 1542 | 1542 | } |
| 1543 | 1543 | } else { |
| 1544 | - if ( $is_digital ) { |
|
| 1544 | + if ($is_digital) { |
|
| 1545 | 1545 | $ip_country_code = self::get_country_by_ip(); |
| 1546 | 1546 | |
| 1547 | - if ( $ip_country_code && self::is_eu_state( $ip_country_code ) ) { |
|
| 1548 | - $rate = self::find_rate( $ip_country_code, '', 0, $class ); |
|
| 1547 | + if ($ip_country_code && self::is_eu_state($ip_country_code)) { |
|
| 1548 | + $rate = self::find_rate($ip_country_code, '', 0, $class); |
|
| 1549 | 1549 | } else { |
| 1550 | - $rate = self::find_rate( $country, $state, $rate, $class ); |
|
| 1550 | + $rate = self::find_rate($country, $state, $rate, $class); |
|
| 1551 | 1551 | } |
| 1552 | 1552 | } else { |
| 1553 | - $rate = self::find_rate( $country, $state, $rate, $class ); |
|
| 1553 | + $rate = self::find_rate($country, $state, $rate, $class); |
|
| 1554 | 1554 | } |
| 1555 | 1555 | } |
| 1556 | 1556 | |
@@ -1560,48 +1560,48 @@ discard block |
||
| 1560 | 1560 | public static function current_vat_data() { |
| 1561 | 1561 | global $wpi_session; |
| 1562 | 1562 | |
| 1563 | - return $wpi_session->get( 'user_vat_data' ); |
|
| 1563 | + return $wpi_session->get('user_vat_data'); |
|
| 1564 | 1564 | } |
| 1565 | 1565 | |
| 1566 | - public static function get_user_country( $country = '', $user_id = 0 ) { |
|
| 1567 | - $user_address = wpinv_get_user_address( $user_id, false ); |
|
| 1566 | + public static function get_user_country($country = '', $user_id = 0) { |
|
| 1567 | + $user_address = wpinv_get_user_address($user_id, false); |
|
| 1568 | 1568 | |
| 1569 | - if ( wpinv_get_option( 'vat_ip_country_default' ) ) { |
|
| 1569 | + if (wpinv_get_option('vat_ip_country_default')) { |
|
| 1570 | 1570 | $country = ''; |
| 1571 | 1571 | } |
| 1572 | 1572 | |
| 1573 | - $country = empty( $user_address ) || !isset( $user_address['country'] ) || empty( $user_address['country'] ) ? $country : $user_address['country']; |
|
| 1574 | - $result = apply_filters( 'wpinv_get_user_country', $country, $user_id ); |
|
| 1573 | + $country = empty($user_address) || !isset($user_address['country']) || empty($user_address['country']) ? $country : $user_address['country']; |
|
| 1574 | + $result = apply_filters('wpinv_get_user_country', $country, $user_id); |
|
| 1575 | 1575 | |
| 1576 | - if ( empty( $result ) ) { |
|
| 1576 | + if (empty($result)) { |
|
| 1577 | 1577 | $result = self::get_country_by_ip(); |
| 1578 | 1578 | } |
| 1579 | 1579 | |
| 1580 | 1580 | return $result; |
| 1581 | 1581 | } |
| 1582 | 1582 | |
| 1583 | - public static function set_user_country( $country = '', $user_id = 0 ) { |
|
| 1583 | + public static function set_user_country($country = '', $user_id = 0) { |
|
| 1584 | 1584 | global $wpi_userID; |
| 1585 | 1585 | |
| 1586 | - if ( empty($country) && !empty($wpi_userID) && get_current_user_id() != $wpi_userID ) { |
|
| 1586 | + if (empty($country) && !empty($wpi_userID) && get_current_user_id() != $wpi_userID) { |
|
| 1587 | 1587 | $country = wpinv_get_default_country(); |
| 1588 | 1588 | } |
| 1589 | 1589 | |
| 1590 | 1590 | return $country; |
| 1591 | 1591 | } |
| 1592 | 1592 | |
| 1593 | - public static function get_user_vat_number( $vat_number = '', $user_id = 0, $is_valid = false ) { |
|
| 1593 | + public static function get_user_vat_number($vat_number = '', $user_id = 0, $is_valid = false) { |
|
| 1594 | 1594 | global $wpi_current_id, $wpi_userID; |
| 1595 | 1595 | |
| 1596 | - if ( !empty( $_POST['new_user'] ) ) { |
|
| 1596 | + if (!empty($_POST['new_user'])) { |
|
| 1597 | 1597 | return ''; |
| 1598 | 1598 | } |
| 1599 | 1599 | |
| 1600 | - if ( empty( $user_id ) ) { |
|
| 1601 | - $user_id = !empty( $wpi_userID ) ? $wpi_userID : ( $wpi_current_id ? wpinv_get_user_id( $wpi_current_id ) : get_current_user_id() ); |
|
| 1600 | + if (empty($user_id)) { |
|
| 1601 | + $user_id = !empty($wpi_userID) ? $wpi_userID : ($wpi_current_id ? wpinv_get_user_id($wpi_current_id) : get_current_user_id()); |
|
| 1602 | 1602 | } |
| 1603 | 1603 | |
| 1604 | - $vat_number = empty( $user_id ) ? '' : get_user_meta( $user_id, '_wpinv_vat_number', true ); |
|
| 1604 | + $vat_number = empty($user_id) ? '' : get_user_meta($user_id, '_wpinv_vat_number', true); |
|
| 1605 | 1605 | |
| 1606 | 1606 | /* TODO |
| 1607 | 1607 | if ( $is_valid && $vat_number ) { |
@@ -1612,36 +1612,36 @@ discard block |
||
| 1612 | 1612 | } |
| 1613 | 1613 | */ |
| 1614 | 1614 | |
| 1615 | - return apply_filters('wpinv_get_user_vat_number', $vat_number, $user_id, $is_valid ); |
|
| 1615 | + return apply_filters('wpinv_get_user_vat_number', $vat_number, $user_id, $is_valid); |
|
| 1616 | 1616 | } |
| 1617 | 1617 | |
| 1618 | - public static function get_user_company( $company = '', $user_id = 0 ) { |
|
| 1619 | - if ( empty( $user_id ) ) { |
|
| 1618 | + public static function get_user_company($company = '', $user_id = 0) { |
|
| 1619 | + if (empty($user_id)) { |
|
| 1620 | 1620 | $user_id = get_current_user_id(); |
| 1621 | 1621 | } |
| 1622 | 1622 | |
| 1623 | - $company = empty( $user_id ) ? "" : get_user_meta( $user_id, '_wpinv_company', true ); |
|
| 1623 | + $company = empty($user_id) ? "" : get_user_meta($user_id, '_wpinv_company', true); |
|
| 1624 | 1624 | |
| 1625 | - return apply_filters( 'wpinv_user_company', $company, $user_id ); |
|
| 1625 | + return apply_filters('wpinv_user_company', $company, $user_id); |
|
| 1626 | 1626 | } |
| 1627 | 1627 | |
| 1628 | - public static function save_user_vat_details( $company = '', $vat_number = '' ) { |
|
| 1629 | - $save = apply_filters( 'wpinv_allow_save_user_vat_details', true ); |
|
| 1628 | + public static function save_user_vat_details($company = '', $vat_number = '') { |
|
| 1629 | + $save = apply_filters('wpinv_allow_save_user_vat_details', true); |
|
| 1630 | 1630 | |
| 1631 | - if ( is_user_logged_in() && $save ) { |
|
| 1631 | + if (is_user_logged_in() && $save) { |
|
| 1632 | 1632 | $user_id = get_current_user_id(); |
| 1633 | 1633 | |
| 1634 | - if ( !empty( $vat_number ) ) { |
|
| 1635 | - update_user_meta( $user_id, '_wpinv_vat_number', $vat_number ); |
|
| 1634 | + if (!empty($vat_number)) { |
|
| 1635 | + update_user_meta($user_id, '_wpinv_vat_number', $vat_number); |
|
| 1636 | 1636 | } else { |
| 1637 | - delete_user_meta( $user_id, '_wpinv_vat_number'); |
|
| 1637 | + delete_user_meta($user_id, '_wpinv_vat_number'); |
|
| 1638 | 1638 | } |
| 1639 | 1639 | |
| 1640 | - if ( !empty( $company ) ) { |
|
| 1641 | - update_user_meta( $user_id, '_wpinv_company', $company ); |
|
| 1640 | + if (!empty($company)) { |
|
| 1641 | + update_user_meta($user_id, '_wpinv_company', $company); |
|
| 1642 | 1642 | } else { |
| 1643 | - delete_user_meta( $user_id, '_wpinv_company'); |
|
| 1644 | - delete_user_meta( $user_id, '_wpinv_vat_number'); |
|
| 1643 | + delete_user_meta($user_id, '_wpinv_company'); |
|
| 1644 | + delete_user_meta($user_id, '_wpinv_vat_number'); |
|
| 1645 | 1645 | } |
| 1646 | 1646 | } |
| 1647 | 1647 | |
@@ -1651,113 +1651,113 @@ discard block |
||
| 1651 | 1651 | public static function ajax_vat_validate() { |
| 1652 | 1652 | global $wpinv_options, $wpi_session; |
| 1653 | 1653 | |
| 1654 | - $is_checkout = ( !empty( $_POST['source'] ) && $_POST['source'] == 'checkout' ) ? true : false; |
|
| 1654 | + $is_checkout = (!empty($_POST['source']) && $_POST['source'] == 'checkout') ? true : false; |
|
| 1655 | 1655 | $response = array(); |
| 1656 | 1656 | $response['success'] = false; |
| 1657 | 1657 | |
| 1658 | - if ( empty( $_REQUEST['_wpi_nonce'] ) || ( !empty( $_REQUEST['_wpi_nonce'] ) && !wp_verify_nonce( $_REQUEST['_wpi_nonce'], 'vat_validation' ) ) ) { |
|
| 1659 | - $response['error'] = __( 'Invalid security nonce', 'invoicing' ); |
|
| 1660 | - wp_send_json( $response ); |
|
| 1658 | + if (empty($_REQUEST['_wpi_nonce']) || (!empty($_REQUEST['_wpi_nonce']) && !wp_verify_nonce($_REQUEST['_wpi_nonce'], 'vat_validation'))) { |
|
| 1659 | + $response['error'] = __('Invalid security nonce', 'invoicing'); |
|
| 1660 | + wp_send_json($response); |
|
| 1661 | 1661 | } |
| 1662 | 1662 | |
| 1663 | - $vat_name = self::get_vat_name(); |
|
| 1663 | + $vat_name = self::get_vat_name(); |
|
| 1664 | 1664 | |
| 1665 | - if ( $is_checkout ) { |
|
| 1665 | + if ($is_checkout) { |
|
| 1666 | 1666 | $invoice = wpinv_get_invoice_cart(); |
| 1667 | 1667 | |
| 1668 | - if ( !self::requires_vat( false, 0, self::invoice_has_digital_rule( $invoice ) ) ) { |
|
| 1668 | + if (!self::requires_vat(false, 0, self::invoice_has_digital_rule($invoice))) { |
|
| 1669 | 1669 | $vat_info = array(); |
| 1670 | - $wpi_session->set( 'user_vat_data', $vat_info ); |
|
| 1670 | + $wpi_session->set('user_vat_data', $vat_info); |
|
| 1671 | 1671 | |
| 1672 | 1672 | self::save_user_vat_details(); |
| 1673 | 1673 | |
| 1674 | 1674 | $response['success'] = true; |
| 1675 | - $response['message'] = wp_sprintf( __( 'Ignore %s', 'invoicing' ), $vat_name ); |
|
| 1676 | - wp_send_json( $response ); |
|
| 1675 | + $response['message'] = wp_sprintf(__('Ignore %s', 'invoicing'), $vat_name); |
|
| 1676 | + wp_send_json($response); |
|
| 1677 | 1677 | } |
| 1678 | 1678 | } |
| 1679 | 1679 | |
| 1680 | - $company = !empty( $_POST['company'] ) ? sanitize_text_field( $_POST['company'] ) : ''; |
|
| 1681 | - $vat_number = !empty( $_POST['number'] ) ? sanitize_text_field( $_POST['number'] ) : ''; |
|
| 1680 | + $company = !empty($_POST['company']) ? sanitize_text_field($_POST['company']) : ''; |
|
| 1681 | + $vat_number = !empty($_POST['number']) ? sanitize_text_field($_POST['number']) : ''; |
|
| 1682 | 1682 | |
| 1683 | - $vat_info = $wpi_session->get( 'user_vat_data' ); |
|
| 1684 | - if ( !is_array( $vat_info ) || empty( $vat_info ) ) { |
|
| 1685 | - $vat_info = array( 'company'=> $company, 'number' => '', 'valid' => true ); |
|
| 1683 | + $vat_info = $wpi_session->get('user_vat_data'); |
|
| 1684 | + if (!is_array($vat_info) || empty($vat_info)) { |
|
| 1685 | + $vat_info = array('company'=> $company, 'number' => '', 'valid' => true); |
|
| 1686 | 1686 | } |
| 1687 | 1687 | |
| 1688 | - if ( empty( $vat_number ) ) { |
|
| 1689 | - if ( $is_checkout ) { |
|
| 1688 | + if (empty($vat_number)) { |
|
| 1689 | + if ($is_checkout) { |
|
| 1690 | 1690 | $response['success'] = true; |
| 1691 | - $response['message'] = wp_sprintf( __( 'No %s number has been applied. %s will be added to invoice totals', 'invoicing' ), $vat_name, $vat_name ); |
|
| 1691 | + $response['message'] = wp_sprintf(__('No %s number has been applied. %s will be added to invoice totals', 'invoicing'), $vat_name, $vat_name); |
|
| 1692 | 1692 | |
| 1693 | - $vat_info = $wpi_session->get( 'user_vat_data' ); |
|
| 1693 | + $vat_info = $wpi_session->get('user_vat_data'); |
|
| 1694 | 1694 | $vat_info['number'] = ""; |
| 1695 | 1695 | $vat_info['valid'] = true; |
| 1696 | 1696 | |
| 1697 | - self::save_user_vat_details( $company ); |
|
| 1697 | + self::save_user_vat_details($company); |
|
| 1698 | 1698 | } else { |
| 1699 | - $response['error'] = wp_sprintf( __( 'Please enter your %s number!', 'invoicing' ), $vat_name ); |
|
| 1699 | + $response['error'] = wp_sprintf(__('Please enter your %s number!', 'invoicing'), $vat_name); |
|
| 1700 | 1700 | |
| 1701 | 1701 | $vat_info['valid'] = false; |
| 1702 | 1702 | } |
| 1703 | 1703 | |
| 1704 | - $wpi_session->set( 'user_vat_data', $vat_info ); |
|
| 1705 | - wp_send_json( $response ); |
|
| 1704 | + $wpi_session->set('user_vat_data', $vat_info); |
|
| 1705 | + wp_send_json($response); |
|
| 1706 | 1706 | } |
| 1707 | 1707 | |
| 1708 | - if ( empty( $company ) ) { |
|
| 1708 | + if (empty($company)) { |
|
| 1709 | 1709 | $vat_info['valid'] = false; |
| 1710 | - $wpi_session->set( 'user_vat_data', $vat_info ); |
|
| 1710 | + $wpi_session->set('user_vat_data', $vat_info); |
|
| 1711 | 1711 | |
| 1712 | - $response['error'] = __( 'Please enter your registered company name!', 'invoicing' ); |
|
| 1713 | - wp_send_json( $response ); |
|
| 1712 | + $response['error'] = __('Please enter your registered company name!', 'invoicing'); |
|
| 1713 | + wp_send_json($response); |
|
| 1714 | 1714 | } |
| 1715 | 1715 | |
| 1716 | - if ( !empty( $wpinv_options['vat_vies_check'] ) ) { |
|
| 1717 | - if ( empty( $wpinv_options['vat_offline_check'] ) && !self::offline_check( $vat_number ) ) { |
|
| 1716 | + if (!empty($wpinv_options['vat_vies_check'])) { |
|
| 1717 | + if (empty($wpinv_options['vat_offline_check']) && !self::offline_check($vat_number)) { |
|
| 1718 | 1718 | $vat_info['valid'] = false; |
| 1719 | - $wpi_session->set( 'user_vat_data', $vat_info ); |
|
| 1719 | + $wpi_session->set('user_vat_data', $vat_info); |
|
| 1720 | 1720 | |
| 1721 | - $response['error'] = wp_sprintf( __( '%s number not validated', 'invoicing' ), $vat_name ); |
|
| 1722 | - wp_send_json( $response ); |
|
| 1721 | + $response['error'] = wp_sprintf(__('%s number not validated', 'invoicing'), $vat_name); |
|
| 1722 | + wp_send_json($response); |
|
| 1723 | 1723 | } |
| 1724 | 1724 | |
| 1725 | 1725 | $response['success'] = true; |
| 1726 | - $response['message'] = wp_sprintf( __( '%s number validated', 'invoicing' ), $vat_name ); |
|
| 1726 | + $response['message'] = wp_sprintf(__('%s number validated', 'invoicing'), $vat_name); |
|
| 1727 | 1727 | } else { |
| 1728 | - $result = self::check_vat( $vat_number ); |
|
| 1728 | + $result = self::check_vat($vat_number); |
|
| 1729 | 1729 | |
| 1730 | - if ( empty( $result['valid'] ) ) { |
|
| 1730 | + if (empty($result['valid'])) { |
|
| 1731 | 1731 | $response['error'] = $result['message']; |
| 1732 | - wp_send_json( $response ); |
|
| 1732 | + wp_send_json($response); |
|
| 1733 | 1733 | } |
| 1734 | 1734 | |
| 1735 | - $vies_company = !empty( $result['company'] ) ? $result['company'] : ''; |
|
| 1736 | - $vies_company = apply_filters( 'wpinv_vies_company_name', $vies_company ); |
|
| 1735 | + $vies_company = !empty($result['company']) ? $result['company'] : ''; |
|
| 1736 | + $vies_company = apply_filters('wpinv_vies_company_name', $vies_company); |
|
| 1737 | 1737 | |
| 1738 | - $valid_company = $vies_company && $company && ( $vies_company == '---' || strcasecmp( trim( $vies_company ), trim( $company ) ) == 0 ) ? true : false; |
|
| 1738 | + $valid_company = $vies_company && $company && ($vies_company == '---' || strcasecmp(trim($vies_company), trim($company)) == 0) ? true : false; |
|
| 1739 | 1739 | |
| 1740 | - if ( !empty( $wpinv_options['vat_disable_company_name_check'] ) || $valid_company ) { |
|
| 1740 | + if (!empty($wpinv_options['vat_disable_company_name_check']) || $valid_company) { |
|
| 1741 | 1741 | $response['success'] = true; |
| 1742 | - $response['message'] = wp_sprintf( __( '%s number validated', 'invoicing' ), $vat_name ); |
|
| 1742 | + $response['message'] = wp_sprintf(__('%s number validated', 'invoicing'), $vat_name); |
|
| 1743 | 1743 | } else { |
| 1744 | 1744 | $vat_info['valid'] = false; |
| 1745 | - $wpi_session->set( 'user_vat_data', $vat_info ); |
|
| 1745 | + $wpi_session->set('user_vat_data', $vat_info); |
|
| 1746 | 1746 | |
| 1747 | 1747 | $response['success'] = false; |
| 1748 | - $response['message'] = wp_sprintf( __( 'The company name associated with the %s number provided is not the same as the company name provided.', 'invoicing' ), $vat_name ); |
|
| 1749 | - wp_send_json( $response ); |
|
| 1748 | + $response['message'] = wp_sprintf(__('The company name associated with the %s number provided is not the same as the company name provided.', 'invoicing'), $vat_name); |
|
| 1749 | + wp_send_json($response); |
|
| 1750 | 1750 | } |
| 1751 | 1751 | } |
| 1752 | 1752 | |
| 1753 | - if ( $is_checkout ) { |
|
| 1754 | - self::save_user_vat_details( $company, $vat_number ); |
|
| 1753 | + if ($is_checkout) { |
|
| 1754 | + self::save_user_vat_details($company, $vat_number); |
|
| 1755 | 1755 | |
| 1756 | - $vat_info = array('company' => $company, 'number' => $vat_number, 'valid' => true ); |
|
| 1757 | - $wpi_session->set( 'user_vat_data', $vat_info ); |
|
| 1756 | + $vat_info = array('company' => $company, 'number' => $vat_number, 'valid' => true); |
|
| 1757 | + $wpi_session->set('user_vat_data', $vat_info); |
|
| 1758 | 1758 | } |
| 1759 | 1759 | |
| 1760 | - wp_send_json( $response ); |
|
| 1760 | + wp_send_json($response); |
|
| 1761 | 1761 | } |
| 1762 | 1762 | |
| 1763 | 1763 | public static function ajax_vat_reset() { |
@@ -1766,161 +1766,161 @@ discard block |
||
| 1766 | 1766 | $company = is_user_logged_in() ? self::get_user_company() : ''; |
| 1767 | 1767 | $vat_number = self::get_user_vat_number(); |
| 1768 | 1768 | |
| 1769 | - $vat_info = array('company' => $company, 'number' => $vat_number, 'valid' => false ); |
|
| 1770 | - $wpi_session->set( 'user_vat_data', $vat_info ); |
|
| 1769 | + $vat_info = array('company' => $company, 'number' => $vat_number, 'valid' => false); |
|
| 1770 | + $wpi_session->set('user_vat_data', $vat_info); |
|
| 1771 | 1771 | |
| 1772 | 1772 | $response = array(); |
| 1773 | 1773 | $response['success'] = true; |
| 1774 | 1774 | $response['data']['company'] = $company; |
| 1775 | 1775 | $response['data']['number'] = $vat_number; |
| 1776 | 1776 | |
| 1777 | - wp_send_json( $response ); |
|
| 1777 | + wp_send_json($response); |
|
| 1778 | 1778 | } |
| 1779 | 1779 | |
| 1780 | - public static function checkout_vat_validate( $valid_data, $post ) { |
|
| 1780 | + public static function checkout_vat_validate($valid_data, $post) { |
|
| 1781 | 1781 | global $wpinv_options, $wpi_session; |
| 1782 | 1782 | |
| 1783 | - $vat_name = __( self::get_vat_name(), 'invoicing' ); |
|
| 1783 | + $vat_name = __(self::get_vat_name(), 'invoicing'); |
|
| 1784 | 1784 | |
| 1785 | - if ( !isset( $_POST['_wpi_nonce'] ) || !wp_verify_nonce( $_POST['_wpi_nonce'], 'vat_validation' ) ) { |
|
| 1786 | - wpinv_set_error( 'vat_validation', wp_sprintf( __( "Invalid %s validation request.", 'invoicing' ), $vat_name ) ); |
|
| 1785 | + if (!isset($_POST['_wpi_nonce']) || !wp_verify_nonce($_POST['_wpi_nonce'], 'vat_validation')) { |
|
| 1786 | + wpinv_set_error('vat_validation', wp_sprintf(__("Invalid %s validation request.", 'invoicing'), $vat_name)); |
|
| 1787 | 1787 | return; |
| 1788 | 1788 | } |
| 1789 | 1789 | |
| 1790 | - $vat_saved = $wpi_session->get( 'user_vat_data' ); |
|
| 1791 | - $wpi_session->set( 'user_vat_data', null ); |
|
| 1790 | + $vat_saved = $wpi_session->get('user_vat_data'); |
|
| 1791 | + $wpi_session->set('user_vat_data', null); |
|
| 1792 | 1792 | |
| 1793 | 1793 | $invoice = wpinv_get_invoice_cart(); |
| 1794 | 1794 | $amount = $invoice->get_total(); |
| 1795 | - $is_digital = self::invoice_has_digital_rule( $invoice ); |
|
| 1796 | - $no_vat = !self::requires_vat( 0, false, $is_digital ); |
|
| 1795 | + $is_digital = self::invoice_has_digital_rule($invoice); |
|
| 1796 | + $no_vat = !self::requires_vat(0, false, $is_digital); |
|
| 1797 | 1797 | |
| 1798 | - $company = !empty( $_POST['wpinv_company'] ) ? $_POST['wpinv_company'] : null; |
|
| 1799 | - $vat_number = !empty( $_POST['wpinv_vat_number'] ) ? $_POST['wpinv_vat_number'] : null; |
|
| 1800 | - $country = !empty( $_POST['wpinv_country'] ) ? $_POST['wpinv_country'] : $invoice->country; |
|
| 1801 | - if ( empty( $country ) ) { |
|
| 1798 | + $company = !empty($_POST['wpinv_company']) ? $_POST['wpinv_company'] : null; |
|
| 1799 | + $vat_number = !empty($_POST['wpinv_vat_number']) ? $_POST['wpinv_vat_number'] : null; |
|
| 1800 | + $country = !empty($_POST['wpinv_country']) ? $_POST['wpinv_country'] : $invoice->country; |
|
| 1801 | + if (empty($country)) { |
|
| 1802 | 1802 | $country = wpinv_default_billing_country(); |
| 1803 | 1803 | } |
| 1804 | 1804 | |
| 1805 | - if ( !$is_digital && $no_vat ) { |
|
| 1805 | + if (!$is_digital && $no_vat) { |
|
| 1806 | 1806 | return; |
| 1807 | 1807 | } |
| 1808 | 1808 | |
| 1809 | - $vat_data = array( 'company' => '', 'number' => '', 'valid' => false ); |
|
| 1809 | + $vat_data = array('company' => '', 'number' => '', 'valid' => false); |
|
| 1810 | 1810 | |
| 1811 | 1811 | $ip_country_code = self::get_country_by_ip(); |
| 1812 | - $is_eu_state = self::is_eu_state( $country ); |
|
| 1813 | - $is_eu_state_ip = self::is_eu_state( $ip_country_code ); |
|
| 1812 | + $is_eu_state = self::is_eu_state($country); |
|
| 1813 | + $is_eu_state_ip = self::is_eu_state($ip_country_code); |
|
| 1814 | 1814 | $is_non_eu_user = !$is_eu_state && !$is_eu_state_ip; |
| 1815 | 1815 | |
| 1816 | - if ( $is_digital && !$is_non_eu_user && empty( $vat_number ) && apply_filters( 'wpinv_checkout_requires_country', true, $amount ) ) { |
|
| 1816 | + if ($is_digital && !$is_non_eu_user && empty($vat_number) && apply_filters('wpinv_checkout_requires_country', true, $amount)) { |
|
| 1817 | 1817 | $vat_data['adddress_confirmed'] = false; |
| 1818 | 1818 | |
| 1819 | - if ( !isset( $_POST['wpinv_adddress_confirmed'] ) ) { |
|
| 1820 | - if ( $ip_country_code != $country ) { |
|
| 1821 | - wpinv_set_error( 'vat_validation', sprintf( __( 'The country of your current location must be the same as the country of your billing location or you must %s confirm %s the billing address is your home country.', 'invoicing' ), '<a href="#wpinv_adddress_confirm">', '</a>' ) ); |
|
| 1819 | + if (!isset($_POST['wpinv_adddress_confirmed'])) { |
|
| 1820 | + if ($ip_country_code != $country) { |
|
| 1821 | + wpinv_set_error('vat_validation', sprintf(__('The country of your current location must be the same as the country of your billing location or you must %s confirm %s the billing address is your home country.', 'invoicing'), '<a href="#wpinv_adddress_confirm">', '</a>')); |
|
| 1822 | 1822 | } |
| 1823 | 1823 | } else { |
| 1824 | 1824 | $vat_data['adddress_confirmed'] = true; |
| 1825 | 1825 | } |
| 1826 | 1826 | } |
| 1827 | 1827 | |
| 1828 | - if ( !empty( $wpinv_options['vat_prevent_b2c_purchase'] ) && !$is_non_eu_user && ( empty( $vat_number ) || $no_vat ) ) { |
|
| 1829 | - if ( $is_eu_state ) { |
|
| 1830 | - wpinv_set_error( 'vat_validation', wp_sprintf( __( 'Please enter and validate your %s number to verify your purchase is by an EU business.', 'invoicing' ), $vat_name ) ); |
|
| 1831 | - } else if ( $is_digital && $is_eu_state_ip ) { |
|
| 1832 | - wpinv_set_error( 'vat_validation', wp_sprintf( __( 'Sales to non-EU countries cannot be completed because %s must be applied.', 'invoicing' ), $vat_name ) ); |
|
| 1828 | + if (!empty($wpinv_options['vat_prevent_b2c_purchase']) && !$is_non_eu_user && (empty($vat_number) || $no_vat)) { |
|
| 1829 | + if ($is_eu_state) { |
|
| 1830 | + wpinv_set_error('vat_validation', wp_sprintf(__('Please enter and validate your %s number to verify your purchase is by an EU business.', 'invoicing'), $vat_name)); |
|
| 1831 | + } else if ($is_digital && $is_eu_state_ip) { |
|
| 1832 | + wpinv_set_error('vat_validation', wp_sprintf(__('Sales to non-EU countries cannot be completed because %s must be applied.', 'invoicing'), $vat_name)); |
|
| 1833 | 1833 | } |
| 1834 | 1834 | } |
| 1835 | 1835 | |
| 1836 | - if ( !$is_eu_state || $no_vat || empty( $vat_number ) ) { |
|
| 1836 | + if (!$is_eu_state || $no_vat || empty($vat_number)) { |
|
| 1837 | 1837 | return; |
| 1838 | 1838 | } |
| 1839 | 1839 | |
| 1840 | - if ( !empty( $vat_saved ) && isset( $vat_saved['valid'] ) ) { |
|
| 1841 | - $vat_data['valid'] = $vat_saved['valid']; |
|
| 1840 | + if (!empty($vat_saved) && isset($vat_saved['valid'])) { |
|
| 1841 | + $vat_data['valid'] = $vat_saved['valid']; |
|
| 1842 | 1842 | } |
| 1843 | 1843 | |
| 1844 | - if ( $company !== null ) { |
|
| 1844 | + if ($company !== null) { |
|
| 1845 | 1845 | $vat_data['company'] = $company; |
| 1846 | 1846 | } |
| 1847 | 1847 | |
| 1848 | 1848 | $message = ''; |
| 1849 | - if ( $vat_number !== null ) { |
|
| 1849 | + if ($vat_number !== null) { |
|
| 1850 | 1850 | $vat_data['number'] = $vat_number; |
| 1851 | 1851 | |
| 1852 | - if ( !$vat_data['valid'] || ( $vat_saved['number'] !== $vat_data['number'] ) || ( $vat_saved['company'] !== $vat_data['company'] ) ) { |
|
| 1853 | - if ( !empty( $wpinv_options['vat_vies_check'] ) ) { |
|
| 1854 | - if ( empty( $wpinv_options['vat_offline_check'] ) && !self::offline_check( $vat_number ) ) { |
|
| 1852 | + if (!$vat_data['valid'] || ($vat_saved['number'] !== $vat_data['number']) || ($vat_saved['company'] !== $vat_data['company'])) { |
|
| 1853 | + if (!empty($wpinv_options['vat_vies_check'])) { |
|
| 1854 | + if (empty($wpinv_options['vat_offline_check']) && !self::offline_check($vat_number)) { |
|
| 1855 | 1855 | $vat_data['valid'] = false; |
| 1856 | 1856 | } |
| 1857 | 1857 | } else { |
| 1858 | - $result = self::check_vat( $vat_number ); |
|
| 1858 | + $result = self::check_vat($vat_number); |
|
| 1859 | 1859 | |
| 1860 | - if ( !empty( $result['valid'] ) ) { |
|
| 1860 | + if (!empty($result['valid'])) { |
|
| 1861 | 1861 | $vat_data['valid'] = true; |
| 1862 | - $vies_company = !empty( $result['company'] ) ? $result['company'] : ''; |
|
| 1863 | - $vies_company = apply_filters( 'wpinv_vies_company_name', $vies_company ); |
|
| 1862 | + $vies_company = !empty($result['company']) ? $result['company'] : ''; |
|
| 1863 | + $vies_company = apply_filters('wpinv_vies_company_name', $vies_company); |
|
| 1864 | 1864 | |
| 1865 | - $valid_company = $vies_company && $company && ( $vies_company == '---' || strcasecmp( trim( $vies_company ), trim( $company ) ) == 0 ) ? true : false; |
|
| 1865 | + $valid_company = $vies_company && $company && ($vies_company == '---' || strcasecmp(trim($vies_company), trim($company)) == 0) ? true : false; |
|
| 1866 | 1866 | |
| 1867 | - if ( !( !empty( $wpinv_options['vat_disable_company_name_check'] ) || $valid_company ) ) { |
|
| 1867 | + if (!(!empty($wpinv_options['vat_disable_company_name_check']) || $valid_company)) { |
|
| 1868 | 1868 | $vat_data['valid'] = false; |
| 1869 | 1869 | |
| 1870 | - $message = wp_sprintf( __( 'The company name associated with the %s number provided is not the same as the company name provided.', 'invoicing' ), $vat_name ); |
|
| 1870 | + $message = wp_sprintf(__('The company name associated with the %s number provided is not the same as the company name provided.', 'invoicing'), $vat_name); |
|
| 1871 | 1871 | } |
| 1872 | 1872 | } else { |
| 1873 | - $message = wp_sprintf( __( 'Fail to validate the %s number: EU Commission VAT server (VIES) check fails.', 'invoicing' ), $vat_name ); |
|
| 1873 | + $message = wp_sprintf(__('Fail to validate the %s number: EU Commission VAT server (VIES) check fails.', 'invoicing'), $vat_name); |
|
| 1874 | 1874 | } |
| 1875 | 1875 | } |
| 1876 | 1876 | |
| 1877 | - if ( !$vat_data['valid'] ) { |
|
| 1878 | - $error = wp_sprintf( __( 'The %s %s number %s you have entered has not been validated', 'invoicing' ), '<a href="#wpi-vat-details">', $vat_name, '</a>' ) . ( $message ? ' ( ' . $message . ' )' : '' ); |
|
| 1879 | - wpinv_set_error( 'vat_validation', $error ); |
|
| 1877 | + if (!$vat_data['valid']) { |
|
| 1878 | + $error = wp_sprintf(__('The %s %s number %s you have entered has not been validated', 'invoicing'), '<a href="#wpi-vat-details">', $vat_name, '</a>') . ($message ? ' ( ' . $message . ' )' : ''); |
|
| 1879 | + wpinv_set_error('vat_validation', $error); |
|
| 1880 | 1880 | } |
| 1881 | 1881 | } |
| 1882 | 1882 | } |
| 1883 | 1883 | |
| 1884 | - $wpi_session->set( 'user_vat_data', $vat_data ); |
|
| 1884 | + $wpi_session->set('user_vat_data', $vat_data); |
|
| 1885 | 1885 | } |
| 1886 | 1886 | |
| 1887 | - public static function checkout_vat_fields( $billing_details ) { |
|
| 1887 | + public static function checkout_vat_fields($billing_details) { |
|
| 1888 | 1888 | global $wpi_session, $wpinv_options, $wpi_country, $wpi_requires_vat; |
| 1889 | 1889 | |
| 1890 | 1890 | $ip_address = wpinv_get_ip(); |
| 1891 | 1891 | $ip_country_code = self::get_country_by_ip(); |
| 1892 | 1892 | |
| 1893 | - $tax_label = __( self::get_vat_name(), 'invoicing' ); |
|
| 1893 | + $tax_label = __(self::get_vat_name(), 'invoicing'); |
|
| 1894 | 1894 | $invoice = wpinv_get_invoice_cart(); |
| 1895 | - $is_digital = self::invoice_has_digital_rule( $invoice ); |
|
| 1895 | + $is_digital = self::invoice_has_digital_rule($invoice); |
|
| 1896 | 1896 | $wpi_country = $invoice->country; |
| 1897 | 1897 | |
| 1898 | - $requires_vat = !self::hide_vat_fields() && $invoice->get_total() > 0 && self::requires_vat( 0, false, $is_digital ); |
|
| 1898 | + $requires_vat = !self::hide_vat_fields() && $invoice->get_total() > 0 && self::requires_vat(0, false, $is_digital); |
|
| 1899 | 1899 | $wpi_requires_vat = $requires_vat; |
| 1900 | 1900 | |
| 1901 | 1901 | $company = is_user_logged_in() ? self::get_user_company() : ''; |
| 1902 | 1902 | $vat_number = self::get_user_vat_number(); |
| 1903 | 1903 | |
| 1904 | - $validated = $vat_number ? self::get_user_vat_number( '', 0, true ) : 1; |
|
| 1905 | - $vat_info = $wpi_session->get( 'user_vat_data' ); |
|
| 1904 | + $validated = $vat_number ? self::get_user_vat_number('', 0, true) : 1; |
|
| 1905 | + $vat_info = $wpi_session->get('user_vat_data'); |
|
| 1906 | 1906 | |
| 1907 | - if ( is_array( $vat_info ) ) { |
|
| 1908 | - $company = isset( $vat_info['company'] ) ? $vat_info['company'] : ''; |
|
| 1909 | - $vat_number = isset( $vat_info['number'] ) ? $vat_info['number'] : ''; |
|
| 1910 | - $validated = isset( $vat_info['valid'] ) ? $vat_info['valid'] : false; |
|
| 1907 | + if (is_array($vat_info)) { |
|
| 1908 | + $company = isset($vat_info['company']) ? $vat_info['company'] : ''; |
|
| 1909 | + $vat_number = isset($vat_info['number']) ? $vat_info['number'] : ''; |
|
| 1910 | + $validated = isset($vat_info['valid']) ? $vat_info['valid'] : false; |
|
| 1911 | 1911 | } |
| 1912 | 1912 | |
| 1913 | 1913 | $selected_country = $invoice->country ? $invoice->country : wpinv_default_billing_country(); |
| 1914 | 1914 | |
| 1915 | - if ( $ip_country_code == 'UK' ) { |
|
| 1915 | + if ($ip_country_code == 'UK') { |
|
| 1916 | 1916 | $ip_country_code = 'GB'; |
| 1917 | 1917 | } |
| 1918 | 1918 | |
| 1919 | - if ( $selected_country == 'UK' ) { |
|
| 1919 | + if ($selected_country == 'UK') { |
|
| 1920 | 1920 | $selected_country = 'GB'; |
| 1921 | 1921 | } |
| 1922 | 1922 | |
| 1923 | - if ( $requires_vat && ( self::same_country_rule() == 'no' && wpinv_is_base_country( $selected_country ) || !self::allow_vat_rules() ) ) { |
|
| 1923 | + if ($requires_vat && (self::same_country_rule() == 'no' && wpinv_is_base_country($selected_country) || !self::allow_vat_rules())) { |
|
| 1924 | 1924 | $requires_vat = false; |
| 1925 | 1925 | } |
| 1926 | 1926 | |
@@ -1928,52 +1928,52 @@ discard block |
||
| 1928 | 1928 | $display_validate_btn = 'none'; |
| 1929 | 1929 | $display_reset_btn = 'none'; |
| 1930 | 1930 | |
| 1931 | - if ( !empty( $vat_number ) && $validated ) { |
|
| 1932 | - $vat_vailidated_text = wp_sprintf( __( '%s number validated', 'invoicing' ), $tax_label ); |
|
| 1931 | + if (!empty($vat_number) && $validated) { |
|
| 1932 | + $vat_vailidated_text = wp_sprintf(__('%s number validated', 'invoicing'), $tax_label); |
|
| 1933 | 1933 | $vat_vailidated_class = 'wpinv-vat-stat-1'; |
| 1934 | 1934 | $display_reset_btn = 'block'; |
| 1935 | 1935 | } else { |
| 1936 | - $vat_vailidated_text = empty( $vat_number ) ? '' : wp_sprintf( __( '%s number not validated', 'invoicing' ), $tax_label ); |
|
| 1937 | - $vat_vailidated_class = empty( $vat_number ) ? '' : 'wpinv-vat-stat-0'; |
|
| 1936 | + $vat_vailidated_text = empty($vat_number) ? '' : wp_sprintf(__('%s number not validated', 'invoicing'), $tax_label); |
|
| 1937 | + $vat_vailidated_class = empty($vat_number) ? '' : 'wpinv-vat-stat-0'; |
|
| 1938 | 1938 | $display_validate_btn = 'block'; |
| 1939 | 1939 | } |
| 1940 | 1940 | |
| 1941 | - $show_ip_country = $is_digital && ( empty( $vat_number ) || !$requires_vat ) && $ip_country_code != $selected_country ? 'block' : 'none'; |
|
| 1941 | + $show_ip_country = $is_digital && (empty($vat_number) || !$requires_vat) && $ip_country_code != $selected_country ? 'block' : 'none'; |
|
| 1942 | 1942 | ?> |
| 1943 | 1943 | <div id="wpi-vat-details" class="wpi-vat-details clearfix" style="display:<?php echo $display_vat_details; ?>"> |
| 1944 | 1944 | <div id="wpi_vat_info" class="clearfix panel panel-default"> |
| 1945 | - <div class="panel-heading"><h3 class="panel-title"><?php echo wp_sprintf( __( '%s Details', 'invoicing' ), $tax_label );?></h3></div> |
|
| 1945 | + <div class="panel-heading"><h3 class="panel-title"><?php echo wp_sprintf(__('%s Details', 'invoicing'), $tax_label); ?></h3></div> |
|
| 1946 | 1946 | <div id="wpinv-fields-box" class="panel-body"> |
| 1947 | 1947 | <p id="wpi_show_vat_note"> |
| 1948 | - <?php echo wp_sprintf( __( 'Validate your registered %s number to exclude tax.', 'invoicing' ), $tax_label ); ?> |
|
| 1948 | + <?php echo wp_sprintf(__('Validate your registered %s number to exclude tax.', 'invoicing'), $tax_label); ?> |
|
| 1949 | 1949 | </p> |
| 1950 | 1950 | <div id="wpi_vat_fields" class="wpi_vat_info"> |
| 1951 | 1951 | <p class="wpi-cart-field wpi-col2 wpi-colf"> |
| 1952 | - <label for="wpinv_company" class="wpi-label"><?php _e( 'Company Name', 'invoicing' );?></label> |
|
| 1952 | + <label for="wpinv_company" class="wpi-label"><?php _e('Company Name', 'invoicing'); ?></label> |
|
| 1953 | 1953 | <?php |
| 1954 | - echo wpinv_html_text( array( |
|
| 1954 | + echo wpinv_html_text(array( |
|
| 1955 | 1955 | 'id' => 'wpinv_company', |
| 1956 | 1956 | 'name' => 'wpinv_company', |
| 1957 | 1957 | 'value' => $company, |
| 1958 | 1958 | 'class' => 'wpi-input form-control', |
| 1959 | - 'placeholder' => __( 'Company name', 'invoicing' ), |
|
| 1960 | - ) ); |
|
| 1959 | + 'placeholder' => __('Company name', 'invoicing'), |
|
| 1960 | + )); |
|
| 1961 | 1961 | ?> |
| 1962 | 1962 | </p> |
| 1963 | 1963 | <p class="wpi-cart-field wpi-col2 wpi-coll wpi-cart-field-vat"> |
| 1964 | - <label for="wpinv_vat_number" class="wpi-label"><?php echo wp_sprintf( __( '%s Number', 'invoicing' ), $tax_label );?></label> |
|
| 1964 | + <label for="wpinv_vat_number" class="wpi-label"><?php echo wp_sprintf(__('%s Number', 'invoicing'), $tax_label); ?></label> |
|
| 1965 | 1965 | <span id="wpinv_vat_number-wrap"> |
| 1966 | 1966 | <label for="wpinv_vat_number" class="wpinv-label"></label> |
| 1967 | - <input type="text" class="wpi-input form-control" placeholder="<?php echo esc_attr( wp_sprintf( __( '%s number', 'invoicing' ), $tax_label ) );?>" value="<?php esc_attr_e( $vat_number );?>" id="wpinv_vat_number" name="wpinv_vat_number"> |
|
| 1968 | - <span class="wpinv-vat-stat <?php echo $vat_vailidated_class;?>"><i class="fa"></i> <font><?php echo $vat_vailidated_text;?></font></span> |
|
| 1967 | + <input type="text" class="wpi-input form-control" placeholder="<?php echo esc_attr(wp_sprintf(__('%s number', 'invoicing'), $tax_label)); ?>" value="<?php esc_attr_e($vat_number); ?>" id="wpinv_vat_number" name="wpinv_vat_number"> |
|
| 1968 | + <span class="wpinv-vat-stat <?php echo $vat_vailidated_class; ?>"><i class="fa"></i> <font><?php echo $vat_vailidated_text; ?></font></span> |
|
| 1969 | 1969 | </span> |
| 1970 | 1970 | </p> |
| 1971 | 1971 | <p class="wpi-cart-field wpi-col wpi-colf wpi-cart-field-actions"> |
| 1972 | - <button class="btn btn-success btn-sm wpinv-vat-validate" type="button" id="wpinv_vat_validate" style="display:<?php echo $display_validate_btn; ?>"><?php echo wp_sprintf( __("Validate %s Number", 'invoicing'), $tax_label ); ?></button> |
|
| 1973 | - <button class="btn btn-danger btn-sm wpinv-vat-reset" type="button" id="wpinv_vat_reset" style="display:<?php echo $display_reset_btn; ?>"><?php echo wp_sprintf( __("Reset %s", 'invoicing'), $tax_label ); ?></button> |
|
| 1972 | + <button class="btn btn-success btn-sm wpinv-vat-validate" type="button" id="wpinv_vat_validate" style="display:<?php echo $display_validate_btn; ?>"><?php echo wp_sprintf(__("Validate %s Number", 'invoicing'), $tax_label); ?></button> |
|
| 1973 | + <button class="btn btn-danger btn-sm wpinv-vat-reset" type="button" id="wpinv_vat_reset" style="display:<?php echo $display_reset_btn; ?>"><?php echo wp_sprintf(__("Reset %s", 'invoicing'), $tax_label); ?></button> |
|
| 1974 | 1974 | <span class="wpi-vat-box wpi-vat-box-info"><span id="text"></span></span> |
| 1975 | 1975 | <span class="wpi-vat-box wpi-vat-box-error"><span id="text"></span></span> |
| 1976 | - <input type="hidden" name="_wpi_nonce" value="<?php echo wp_create_nonce( 'vat_validation' ) ?>" /> |
|
| 1976 | + <input type="hidden" name="_wpi_nonce" value="<?php echo wp_create_nonce('vat_validation') ?>" /> |
|
| 1977 | 1977 | </p> |
| 1978 | 1978 | </div> |
| 1979 | 1979 | </div> |
@@ -1987,32 +1987,32 @@ discard block |
||
| 1987 | 1987 | </span> |
| 1988 | 1988 | </div> |
| 1989 | 1989 | </div> |
| 1990 | - <?php if ( empty( $wpinv_options['hide_ip_address'] ) ) { |
|
| 1991 | - $ip_link = '<a title="' . esc_attr( __( 'View more details on map', 'invoicing' ) ) . '" target="_blank" href="' . esc_url( admin_url( 'admin-ajax.php?action=wpinv_ip_geolocation&ip=' . $ip_address ) ) . '" class="wpi-ip-address-link">' . $ip_address . ' <i class="fa fa-external-link-square" aria-hidden="true"></i></a>'; |
|
| 1990 | + <?php if (empty($wpinv_options['hide_ip_address'])) { |
|
| 1991 | + $ip_link = '<a title="' . esc_attr(__('View more details on map', 'invoicing')) . '" target="_blank" href="' . esc_url(admin_url('admin-ajax.php?action=wpinv_ip_geolocation&ip=' . $ip_address)) . '" class="wpi-ip-address-link">' . $ip_address . ' <i class="fa fa-external-link-square" aria-hidden="true"></i></a>'; |
|
| 1992 | 1992 | ?> |
| 1993 | 1993 | <div class="wpi-ip-info clearfix panel panel-info"> |
| 1994 | 1994 | <div id="wpinv-fields-box" class="panel-body"> |
| 1995 | - <span><?php echo wp_sprintf( __( "Your IP address is: %s", 'invoicing' ), $ip_link ); ?></span> |
|
| 1995 | + <span><?php echo wp_sprintf(__("Your IP address is: %s", 'invoicing'), $ip_link); ?></span> |
|
| 1996 | 1996 | </div> |
| 1997 | 1997 | </div> |
| 1998 | 1998 | <?php } |
| 1999 | 1999 | } |
| 2000 | 2000 | |
| 2001 | - public static function show_vat_notice( $invoice ) { |
|
| 2002 | - if ( empty( $invoice ) ) { |
|
| 2001 | + public static function show_vat_notice($invoice) { |
|
| 2002 | + if (empty($invoice)) { |
|
| 2003 | 2003 | return NULL; |
| 2004 | 2004 | } |
| 2005 | 2005 | |
| 2006 | - $label = wpinv_get_option( 'vat_invoice_notice_label' ); |
|
| 2007 | - $notice = wpinv_get_option( 'vat_invoice_notice' ); |
|
| 2008 | - if ( $label || $notice ) { |
|
| 2006 | + $label = wpinv_get_option('vat_invoice_notice_label'); |
|
| 2007 | + $notice = wpinv_get_option('vat_invoice_notice'); |
|
| 2008 | + if ($label || $notice) { |
|
| 2009 | 2009 | ?> |
| 2010 | 2010 | <div class="row wpinv-vat-notice"> |
| 2011 | 2011 | <div class="col-sm-12"> |
| 2012 | - <?php if ( $label ) { ?> |
|
| 2013 | - <strong><?php _e( $label, 'invoicing' ); ?></strong> |
|
| 2014 | - <?php } if ( $notice ) { ?> |
|
| 2015 | - <?php echo wpautop( wptexturize( __( $notice, 'invoicing' ) ) ) ?> |
|
| 2012 | + <?php if ($label) { ?> |
|
| 2013 | + <strong><?php _e($label, 'invoicing'); ?></strong> |
|
| 2014 | + <?php } if ($notice) { ?> |
|
| 2015 | + <?php echo wpautop(wptexturize(__($notice, 'invoicing'))) ?> |
|
| 2016 | 2016 | <?php } ?> |
| 2017 | 2017 | </div> |
| 2018 | 2018 | </div> |
@@ -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'] = 'gd_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,99 +189,99 @@ 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 | - $start_timestamp = strtotime( $meta['start'] ); |
|
| 216 | + $start_timestamp = strtotime($meta['start']); |
|
| 217 | 217 | |
| 218 | - if ( !empty( $meta['start'] ) ) { |
|
| 219 | - $meta['start'] = date( 'Y-m-d H:i:s', $start_timestamp ); |
|
| 218 | + if (!empty($meta['start'])) { |
|
| 219 | + $meta['start'] = date('Y-m-d H:i:s', $start_timestamp); |
|
| 220 | 220 | } |
| 221 | 221 | |
| 222 | - if ( $meta['type'] == 'percent' && (float)$meta['amount'] > 100 ) { |
|
| 222 | + if ($meta['type'] == 'percent' && (float)$meta['amount'] > 100) { |
|
| 223 | 223 | $meta['amount'] = 100; |
| 224 | 224 | } |
| 225 | 225 | |
| 226 | - if ( !empty( $meta['expiration'] ) ) { |
|
| 227 | - $meta['expiration'] = date( 'Y-m-d H:i:s', strtotime( date( 'Y-m-d', strtotime( $meta['expiration'] ) ) . ' 23:59:59' ) ); |
|
| 228 | - $end_timestamp = strtotime( $meta['expiration'] ); |
|
| 226 | + if (!empty($meta['expiration'])) { |
|
| 227 | + $meta['expiration'] = date('Y-m-d H:i:s', strtotime(date('Y-m-d', strtotime($meta['expiration'])) . ' 23:59:59')); |
|
| 228 | + $end_timestamp = strtotime($meta['expiration']); |
|
| 229 | 229 | |
| 230 | - if ( !empty( $meta['start'] ) && $start_timestamp > $end_timestamp ) { |
|
| 230 | + if (!empty($meta['start']) && $start_timestamp > $end_timestamp) { |
|
| 231 | 231 | $meta['expiration'] = $meta['start']; // Set the expiration date to the start date if start is later than expiration date. |
| 232 | 232 | } |
| 233 | 233 | } |
| 234 | 234 | |
| 235 | - if ( $meta['uses'] === false ) { |
|
| 236 | - unset( $meta['uses'] ); |
|
| 235 | + if ($meta['uses'] === false) { |
|
| 236 | + unset($meta['uses']); |
|
| 237 | 237 | } |
| 238 | 238 | |
| 239 | - if ( ! empty( $meta['items'] ) ) { |
|
| 240 | - foreach ( $meta['items'] as $key => $item ) { |
|
| 241 | - if ( 0 === intval( $item ) ) { |
|
| 242 | - unset( $meta['items'][ $key ] ); |
|
| 239 | + if (!empty($meta['items'])) { |
|
| 240 | + foreach ($meta['items'] as $key => $item) { |
|
| 241 | + if (0 === intval($item)) { |
|
| 242 | + unset($meta['items'][$key]); |
|
| 243 | 243 | } |
| 244 | 244 | } |
| 245 | 245 | } |
| 246 | 246 | |
| 247 | - if ( ! empty( $meta['excluded_items'] ) ) { |
|
| 248 | - foreach ( $meta['excluded_items'] as $key => $item ) { |
|
| 249 | - if ( 0 === intval( $item ) ) { |
|
| 250 | - unset( $meta['excluded_items'][ $key ] ); |
|
| 247 | + if (!empty($meta['excluded_items'])) { |
|
| 248 | + foreach ($meta['excluded_items'] as $key => $item) { |
|
| 249 | + if (0 === intval($item)) { |
|
| 250 | + unset($meta['excluded_items'][$key]); |
|
| 251 | 251 | } |
| 252 | 252 | } |
| 253 | 253 | } |
| 254 | 254 | |
| 255 | - $meta = apply_filters( 'wpinv_update_discount', $meta, $post_id, $post ); |
|
| 255 | + $meta = apply_filters('wpinv_update_discount', $meta, $post_id, $post); |
|
| 256 | 256 | |
| 257 | - do_action( 'wpinv_pre_update_discount', $meta, $post_id, $post ); |
|
| 257 | + do_action('wpinv_pre_update_discount', $meta, $post_id, $post); |
|
| 258 | 258 | |
| 259 | - foreach( $meta as $key => $value ) { |
|
| 260 | - update_post_meta( $post_id, '_wpi_discount_' . $key, $value ); |
|
| 259 | + foreach ($meta as $key => $value) { |
|
| 260 | + update_post_meta($post_id, '_wpi_discount_' . $key, $value); |
|
| 261 | 261 | } |
| 262 | 262 | |
| 263 | - do_action( 'wpinv_post_update_discount', $meta, $post_id, $post ); |
|
| 263 | + do_action('wpinv_post_update_discount', $meta, $post_id, $post); |
|
| 264 | 264 | |
| 265 | 265 | return $post_id; |
| 266 | 266 | } |
| 267 | 267 | |
| 268 | -function wpinv_remove_discount( $discount_id = 0 ) { |
|
| 269 | - do_action( 'wpinv_pre_delete_discount', $discount_id ); |
|
| 268 | +function wpinv_remove_discount($discount_id = 0) { |
|
| 269 | + do_action('wpinv_pre_delete_discount', $discount_id); |
|
| 270 | 270 | |
| 271 | - wp_delete_post( $discount_id, true ); |
|
| 271 | + wp_delete_post($discount_id, true); |
|
| 272 | 272 | |
| 273 | - do_action( 'wpinv_post_delete_discount', $discount_id ); |
|
| 273 | + do_action('wpinv_post_delete_discount', $discount_id); |
|
| 274 | 274 | } |
| 275 | 275 | |
| 276 | -function wpinv_update_discount_status( $code_id = 0, $new_status = 'publish' ) { |
|
| 277 | - $discount = wpinv_get_discount( $code_id ); |
|
| 276 | +function wpinv_update_discount_status($code_id = 0, $new_status = 'publish') { |
|
| 277 | + $discount = wpinv_get_discount($code_id); |
|
| 278 | 278 | |
| 279 | - if ( $discount ) { |
|
| 280 | - do_action( 'wpinv_pre_update_discount_status', $code_id, $new_status, $discount->post_status ); |
|
| 279 | + if ($discount) { |
|
| 280 | + do_action('wpinv_pre_update_discount_status', $code_id, $new_status, $discount->post_status); |
|
| 281 | 281 | |
| 282 | - wp_update_post( array( 'ID' => $code_id, 'post_status' => $new_status ) ); |
|
| 282 | + wp_update_post(array('ID' => $code_id, 'post_status' => $new_status)); |
|
| 283 | 283 | |
| 284 | - do_action( 'wpinv_post_update_discount_status', $code_id, $new_status, $discount->post_status ); |
|
| 284 | + do_action('wpinv_post_update_discount_status', $code_id, $new_status, $discount->post_status); |
|
| 285 | 285 | |
| 286 | 286 | return true; |
| 287 | 287 | } |
@@ -289,173 +289,173 @@ discard block |
||
| 289 | 289 | return false; |
| 290 | 290 | } |
| 291 | 291 | |
| 292 | -function wpinv_discount_exists( $code_id ) { |
|
| 293 | - if ( wpinv_get_discount( $code_id ) ) { |
|
| 292 | +function wpinv_discount_exists($code_id) { |
|
| 293 | + if (wpinv_get_discount($code_id)) { |
|
| 294 | 294 | return true; |
| 295 | 295 | } |
| 296 | 296 | |
| 297 | 297 | return false; |
| 298 | 298 | } |
| 299 | 299 | |
| 300 | -function wpinv_is_discount_active( $code_id = null ) { |
|
| 301 | - $discount = wpinv_get_discount( $code_id ); |
|
| 300 | +function wpinv_is_discount_active($code_id = null) { |
|
| 301 | + $discount = wpinv_get_discount($code_id); |
|
| 302 | 302 | $return = false; |
| 303 | 303 | |
| 304 | - if ( $discount ) { |
|
| 305 | - if ( wpinv_is_discount_expired( $code_id ) ) { |
|
| 306 | - if( defined( 'DOING_AJAX' ) ) { |
|
| 307 | - wpinv_set_error( 'wpinv-discount-error', __( 'This discount is expired.', 'invoicing' ) ); |
|
| 304 | + if ($discount) { |
|
| 305 | + if (wpinv_is_discount_expired($code_id)) { |
|
| 306 | + if (defined('DOING_AJAX')) { |
|
| 307 | + wpinv_set_error('wpinv-discount-error', __('This discount is expired.', 'invoicing')); |
|
| 308 | 308 | } |
| 309 | - } elseif ( $discount->post_status == 'publish' ) { |
|
| 309 | + } elseif ($discount->post_status == 'publish') { |
|
| 310 | 310 | $return = true; |
| 311 | 311 | } else { |
| 312 | - if( defined( 'DOING_AJAX' ) ) { |
|
| 313 | - wpinv_set_error( 'wpinv-discount-error', __( 'This discount is not active.', 'invoicing' ) ); |
|
| 312 | + if (defined('DOING_AJAX')) { |
|
| 313 | + wpinv_set_error('wpinv-discount-error', __('This discount is not active.', 'invoicing')); |
|
| 314 | 314 | } |
| 315 | 315 | } |
| 316 | 316 | } |
| 317 | 317 | |
| 318 | - return apply_filters( 'wpinv_is_discount_active', $return, $code_id ); |
|
| 318 | + return apply_filters('wpinv_is_discount_active', $return, $code_id); |
|
| 319 | 319 | } |
| 320 | 320 | |
| 321 | -function wpinv_get_discount_code( $code_id = null ) { |
|
| 322 | - $code = get_post_meta( $code_id, '_wpi_discount_code', true ); |
|
| 321 | +function wpinv_get_discount_code($code_id = null) { |
|
| 322 | + $code = get_post_meta($code_id, '_wpi_discount_code', true); |
|
| 323 | 323 | |
| 324 | - return apply_filters( 'wpinv_get_discount_code', $code, $code_id ); |
|
| 324 | + return apply_filters('wpinv_get_discount_code', $code, $code_id); |
|
| 325 | 325 | } |
| 326 | 326 | |
| 327 | -function wpinv_get_discount_start_date( $code_id = null ) { |
|
| 328 | - $start_date = get_post_meta( $code_id, '_wpi_discount_start', true ); |
|
| 327 | +function wpinv_get_discount_start_date($code_id = null) { |
|
| 328 | + $start_date = get_post_meta($code_id, '_wpi_discount_start', true); |
|
| 329 | 329 | |
| 330 | - return apply_filters( 'wpinv_get_discount_start_date', $start_date, $code_id ); |
|
| 330 | + return apply_filters('wpinv_get_discount_start_date', $start_date, $code_id); |
|
| 331 | 331 | } |
| 332 | 332 | |
| 333 | -function wpinv_get_discount_expiration( $code_id = null ) { |
|
| 334 | - $expiration = get_post_meta( $code_id, '_wpi_discount_expiration', true ); |
|
| 333 | +function wpinv_get_discount_expiration($code_id = null) { |
|
| 334 | + $expiration = get_post_meta($code_id, '_wpi_discount_expiration', true); |
|
| 335 | 335 | |
| 336 | - return apply_filters( 'wpinv_get_discount_expiration', $expiration, $code_id ); |
|
| 336 | + return apply_filters('wpinv_get_discount_expiration', $expiration, $code_id); |
|
| 337 | 337 | } |
| 338 | 338 | |
| 339 | -function wpinv_get_discount_max_uses( $code_id = null ) { |
|
| 340 | - $max_uses = get_post_meta( $code_id, '_wpi_discount_max_uses', true ); |
|
| 339 | +function wpinv_get_discount_max_uses($code_id = null) { |
|
| 340 | + $max_uses = get_post_meta($code_id, '_wpi_discount_max_uses', true); |
|
| 341 | 341 | |
| 342 | - return (int) apply_filters( 'wpinv_get_discount_max_uses', $max_uses, $code_id ); |
|
| 342 | + return (int)apply_filters('wpinv_get_discount_max_uses', $max_uses, $code_id); |
|
| 343 | 343 | } |
| 344 | 344 | |
| 345 | -function wpinv_get_discount_uses( $code_id = null ) { |
|
| 346 | - $uses = get_post_meta( $code_id, '_wpi_discount_uses', true ); |
|
| 345 | +function wpinv_get_discount_uses($code_id = null) { |
|
| 346 | + $uses = get_post_meta($code_id, '_wpi_discount_uses', true); |
|
| 347 | 347 | |
| 348 | - return (int) apply_filters( 'wpinv_get_discount_uses', $uses, $code_id ); |
|
| 348 | + return (int)apply_filters('wpinv_get_discount_uses', $uses, $code_id); |
|
| 349 | 349 | } |
| 350 | 350 | |
| 351 | -function wpinv_get_discount_min_total( $code_id = null ) { |
|
| 352 | - $min_total = get_post_meta( $code_id, '_wpi_discount_min_total', true ); |
|
| 351 | +function wpinv_get_discount_min_total($code_id = null) { |
|
| 352 | + $min_total = get_post_meta($code_id, '_wpi_discount_min_total', true); |
|
| 353 | 353 | |
| 354 | - return (float) apply_filters( 'wpinv_get_discount_min_total', $min_total, $code_id ); |
|
| 354 | + return (float)apply_filters('wpinv_get_discount_min_total', $min_total, $code_id); |
|
| 355 | 355 | } |
| 356 | 356 | |
| 357 | -function wpinv_get_discount_max_total( $code_id = null ) { |
|
| 358 | - $max_total = get_post_meta( $code_id, '_wpi_discount_max_total', true ); |
|
| 357 | +function wpinv_get_discount_max_total($code_id = null) { |
|
| 358 | + $max_total = get_post_meta($code_id, '_wpi_discount_max_total', true); |
|
| 359 | 359 | |
| 360 | - return (float) apply_filters( 'wpinv_get_discount_max_total', $max_total, $code_id ); |
|
| 360 | + return (float)apply_filters('wpinv_get_discount_max_total', $max_total, $code_id); |
|
| 361 | 361 | } |
| 362 | 362 | |
| 363 | -function wpinv_get_discount_amount( $code_id = null ) { |
|
| 364 | - $amount = get_post_meta( $code_id, '_wpi_discount_amount', true ); |
|
| 363 | +function wpinv_get_discount_amount($code_id = null) { |
|
| 364 | + $amount = get_post_meta($code_id, '_wpi_discount_amount', true); |
|
| 365 | 365 | |
| 366 | - return (float) apply_filters( 'wpinv_get_discount_amount', $amount, $code_id ); |
|
| 366 | + return (float)apply_filters('wpinv_get_discount_amount', $amount, $code_id); |
|
| 367 | 367 | } |
| 368 | 368 | |
| 369 | -function wpinv_get_discount_type( $code_id = null, $name = false ) { |
|
| 370 | - $type = strtolower( get_post_meta( $code_id, '_wpi_discount_type', true ) ); |
|
| 369 | +function wpinv_get_discount_type($code_id = null, $name = false) { |
|
| 370 | + $type = strtolower(get_post_meta($code_id, '_wpi_discount_type', true)); |
|
| 371 | 371 | |
| 372 | - if ( $name ) { |
|
| 373 | - $name = wpinv_get_discount_type_name( $type ); |
|
| 372 | + if ($name) { |
|
| 373 | + $name = wpinv_get_discount_type_name($type); |
|
| 374 | 374 | |
| 375 | - return apply_filters( 'wpinv_get_discount_type_name', $name, $code_id ); |
|
| 375 | + return apply_filters('wpinv_get_discount_type_name', $name, $code_id); |
|
| 376 | 376 | } |
| 377 | 377 | |
| 378 | - return apply_filters( 'wpinv_get_discount_type', $type, $code_id ); |
|
| 378 | + return apply_filters('wpinv_get_discount_type', $type, $code_id); |
|
| 379 | 379 | } |
| 380 | 380 | |
| 381 | -function wpinv_discount_status( $status ) { |
|
| 382 | - switch( $status ){ |
|
| 381 | +function wpinv_discount_status($status) { |
|
| 382 | + switch ($status) { |
|
| 383 | 383 | case 'expired' : |
| 384 | - $name = __( 'Expired', 'invoicing' ); |
|
| 384 | + $name = __('Expired', 'invoicing'); |
|
| 385 | 385 | break; |
| 386 | 386 | case 'publish' : |
| 387 | 387 | case 'active' : |
| 388 | - $name = __( 'Active', 'invoicing' ); |
|
| 388 | + $name = __('Active', 'invoicing'); |
|
| 389 | 389 | break; |
| 390 | 390 | default : |
| 391 | - $name = __( 'Inactive', 'invoicing' ); |
|
| 391 | + $name = __('Inactive', 'invoicing'); |
|
| 392 | 392 | break; |
| 393 | 393 | } |
| 394 | 394 | return $name; |
| 395 | 395 | } |
| 396 | 396 | |
| 397 | -function wpinv_get_discount_excluded_items( $code_id = null ) { |
|
| 398 | - $excluded_items = get_post_meta( $code_id, '_wpi_discount_excluded_items', true ); |
|
| 397 | +function wpinv_get_discount_excluded_items($code_id = null) { |
|
| 398 | + $excluded_items = get_post_meta($code_id, '_wpi_discount_excluded_items', true); |
|
| 399 | 399 | |
| 400 | - if ( empty( $excluded_items ) || ! is_array( $excluded_items ) ) { |
|
| 400 | + if (empty($excluded_items) || !is_array($excluded_items)) { |
|
| 401 | 401 | $excluded_items = array(); |
| 402 | 402 | } |
| 403 | 403 | |
| 404 | - return (array) apply_filters( 'wpinv_get_discount_excluded_items', $excluded_items, $code_id ); |
|
| 404 | + return (array)apply_filters('wpinv_get_discount_excluded_items', $excluded_items, $code_id); |
|
| 405 | 405 | } |
| 406 | 406 | |
| 407 | -function wpinv_get_discount_item_reqs( $code_id = null ) { |
|
| 408 | - $item_reqs = get_post_meta( $code_id, '_wpi_discount_items', true ); |
|
| 407 | +function wpinv_get_discount_item_reqs($code_id = null) { |
|
| 408 | + $item_reqs = get_post_meta($code_id, '_wpi_discount_items', true); |
|
| 409 | 409 | |
| 410 | - if ( empty( $item_reqs ) || ! is_array( $item_reqs ) ) { |
|
| 410 | + if (empty($item_reqs) || !is_array($item_reqs)) { |
|
| 411 | 411 | $item_reqs = array(); |
| 412 | 412 | } |
| 413 | 413 | |
| 414 | - return (array) apply_filters( 'wpinv_get_discount_item_reqs', $item_reqs, $code_id ); |
|
| 414 | + return (array)apply_filters('wpinv_get_discount_item_reqs', $item_reqs, $code_id); |
|
| 415 | 415 | } |
| 416 | 416 | |
| 417 | -function wpinv_get_discount_item_condition( $code_id = 0 ) { |
|
| 418 | - return get_post_meta( $code_id, '_wpi_discount_item_condition', true ); |
|
| 417 | +function wpinv_get_discount_item_condition($code_id = 0) { |
|
| 418 | + return get_post_meta($code_id, '_wpi_discount_item_condition', true); |
|
| 419 | 419 | } |
| 420 | 420 | |
| 421 | -function wpinv_is_discount_not_global( $code_id = 0 ) { |
|
| 422 | - return (bool) get_post_meta( $code_id, '_wpi_discount_is_not_global', true ); |
|
| 421 | +function wpinv_is_discount_not_global($code_id = 0) { |
|
| 422 | + return (bool)get_post_meta($code_id, '_wpi_discount_is_not_global', true); |
|
| 423 | 423 | } |
| 424 | 424 | |
| 425 | -function wpinv_is_discount_expired( $code_id = null ) { |
|
| 426 | - $discount = wpinv_get_discount( $code_id ); |
|
| 425 | +function wpinv_is_discount_expired($code_id = null) { |
|
| 426 | + $discount = wpinv_get_discount($code_id); |
|
| 427 | 427 | $return = false; |
| 428 | 428 | |
| 429 | - if ( $discount ) { |
|
| 430 | - $expiration = wpinv_get_discount_expiration( $code_id ); |
|
| 431 | - if ( $expiration ) { |
|
| 432 | - $expiration = strtotime( $expiration ); |
|
| 433 | - if ( $expiration < current_time( 'timestamp' ) ) { |
|
| 429 | + if ($discount) { |
|
| 430 | + $expiration = wpinv_get_discount_expiration($code_id); |
|
| 431 | + if ($expiration) { |
|
| 432 | + $expiration = strtotime($expiration); |
|
| 433 | + if ($expiration < current_time('timestamp')) { |
|
| 434 | 434 | // Discount is expired |
| 435 | - wpinv_update_discount_status( $code_id, 'pending' ); |
|
| 435 | + wpinv_update_discount_status($code_id, 'pending'); |
|
| 436 | 436 | $return = true; |
| 437 | 437 | } |
| 438 | 438 | } |
| 439 | 439 | } |
| 440 | 440 | |
| 441 | - return apply_filters( 'wpinv_is_discount_expired', $return, $code_id ); |
|
| 441 | + return apply_filters('wpinv_is_discount_expired', $return, $code_id); |
|
| 442 | 442 | } |
| 443 | 443 | |
| 444 | -function wpinv_is_discount_started( $code_id = null ) { |
|
| 445 | - $discount = wpinv_get_discount( $code_id ); |
|
| 444 | +function wpinv_is_discount_started($code_id = null) { |
|
| 445 | + $discount = wpinv_get_discount($code_id); |
|
| 446 | 446 | $return = false; |
| 447 | 447 | |
| 448 | - if ( $discount ) { |
|
| 449 | - $start_date = wpinv_get_discount_start_date( $code_id ); |
|
| 448 | + if ($discount) { |
|
| 449 | + $start_date = wpinv_get_discount_start_date($code_id); |
|
| 450 | 450 | |
| 451 | - if ( $start_date ) { |
|
| 452 | - $start_date = strtotime( $start_date ); |
|
| 451 | + if ($start_date) { |
|
| 452 | + $start_date = strtotime($start_date); |
|
| 453 | 453 | |
| 454 | - if ( $start_date < current_time( 'timestamp' ) ) { |
|
| 454 | + if ($start_date < current_time('timestamp')) { |
|
| 455 | 455 | // Discount has past the start date |
| 456 | 456 | $return = true; |
| 457 | 457 | } else { |
| 458 | - wpinv_set_error( 'wpinv-discount-error', __( 'This discount is not active yet.', 'invoicing' ) ); |
|
| 458 | + wpinv_set_error('wpinv-discount-error', __('This discount is not active yet.', 'invoicing')); |
|
| 459 | 459 | } |
| 460 | 460 | } else { |
| 461 | 461 | // No start date for this discount, so has to be true |
@@ -463,159 +463,159 @@ discard block |
||
| 463 | 463 | } |
| 464 | 464 | } |
| 465 | 465 | |
| 466 | - return apply_filters( 'wpinv_is_discount_started', $return, $code_id ); |
|
| 466 | + return apply_filters('wpinv_is_discount_started', $return, $code_id); |
|
| 467 | 467 | } |
| 468 | 468 | |
| 469 | -function wpinv_check_discount_dates( $code_id = null ) { |
|
| 470 | - $discount = wpinv_get_discount( $code_id ); |
|
| 469 | +function wpinv_check_discount_dates($code_id = null) { |
|
| 470 | + $discount = wpinv_get_discount($code_id); |
|
| 471 | 471 | $return = false; |
| 472 | 472 | |
| 473 | - if ( $discount ) { |
|
| 474 | - $start_date = wpinv_get_discount_start_date( $code_id ); |
|
| 473 | + if ($discount) { |
|
| 474 | + $start_date = wpinv_get_discount_start_date($code_id); |
|
| 475 | 475 | |
| 476 | - if ( $start_date ) { |
|
| 477 | - $start_date = strtotime( $start_date ); |
|
| 476 | + if ($start_date) { |
|
| 477 | + $start_date = strtotime($start_date); |
|
| 478 | 478 | |
| 479 | - if ( $start_date < current_time( 'timestamp' ) ) { |
|
| 479 | + if ($start_date < current_time('timestamp')) { |
|
| 480 | 480 | // Discount has past the start date |
| 481 | 481 | $return = true; |
| 482 | 482 | } else { |
| 483 | - wpinv_set_error( 'wpinv-discount-error', __( 'This discount is not active yet.', 'invoicing' ) ); |
|
| 483 | + wpinv_set_error('wpinv-discount-error', __('This discount is not active yet.', 'invoicing')); |
|
| 484 | 484 | } |
| 485 | 485 | } else { |
| 486 | 486 | // No start date for this discount, so has to be true |
| 487 | 487 | $return = true; |
| 488 | 488 | } |
| 489 | 489 | |
| 490 | - if ( $return ) { |
|
| 491 | - $expiration = wpinv_get_discount_expiration( $code_id ); |
|
| 490 | + if ($return) { |
|
| 491 | + $expiration = wpinv_get_discount_expiration($code_id); |
|
| 492 | 492 | |
| 493 | - if ( $expiration ) { |
|
| 494 | - $expiration = strtotime( $expiration ); |
|
| 495 | - if ( $expiration < current_time( 'timestamp' ) ) { |
|
| 493 | + if ($expiration) { |
|
| 494 | + $expiration = strtotime($expiration); |
|
| 495 | + if ($expiration < current_time('timestamp')) { |
|
| 496 | 496 | // Discount is expired |
| 497 | - wpinv_update_discount_status( $code_id, 'pending' ); |
|
| 497 | + wpinv_update_discount_status($code_id, 'pending'); |
|
| 498 | 498 | $return = true; |
| 499 | 499 | } |
| 500 | 500 | } |
| 501 | 501 | } |
| 502 | 502 | } |
| 503 | 503 | |
| 504 | - return apply_filters( 'wpinv_check_discount_dates', $return, $code_id ); |
|
| 504 | + return apply_filters('wpinv_check_discount_dates', $return, $code_id); |
|
| 505 | 505 | } |
| 506 | 506 | |
| 507 | -function wpinv_is_discount_maxed_out( $code_id = null ) { |
|
| 508 | - $discount = wpinv_get_discount( $code_id ); |
|
| 507 | +function wpinv_is_discount_maxed_out($code_id = null) { |
|
| 508 | + $discount = wpinv_get_discount($code_id); |
|
| 509 | 509 | $return = false; |
| 510 | 510 | |
| 511 | - if ( $discount ) { |
|
| 512 | - $uses = wpinv_get_discount_uses( $code_id ); |
|
| 511 | + if ($discount) { |
|
| 512 | + $uses = wpinv_get_discount_uses($code_id); |
|
| 513 | 513 | // Large number that will never be reached |
| 514 | - $max_uses = wpinv_get_discount_max_uses( $code_id ); |
|
| 514 | + $max_uses = wpinv_get_discount_max_uses($code_id); |
|
| 515 | 515 | // Should never be greater than, but just in case |
| 516 | - if ( $uses >= $max_uses && ! empty( $max_uses ) ) { |
|
| 516 | + if ($uses >= $max_uses && !empty($max_uses)) { |
|
| 517 | 517 | // Discount is maxed out |
| 518 | - wpinv_set_error( 'wpinv-discount-error', __( 'This discount has reached its maximum usage.', 'invoicing' ) ); |
|
| 518 | + wpinv_set_error('wpinv-discount-error', __('This discount has reached its maximum usage.', 'invoicing')); |
|
| 519 | 519 | $return = true; |
| 520 | 520 | } |
| 521 | 521 | } |
| 522 | 522 | |
| 523 | - return apply_filters( 'wpinv_is_discount_maxed_out', $return, $code_id ); |
|
| 523 | + return apply_filters('wpinv_is_discount_maxed_out', $return, $code_id); |
|
| 524 | 524 | } |
| 525 | 525 | |
| 526 | -function wpinv_discount_is_min_met( $code_id = null ) { |
|
| 527 | - $discount = wpinv_get_discount( $code_id ); |
|
| 526 | +function wpinv_discount_is_min_met($code_id = null) { |
|
| 527 | + $discount = wpinv_get_discount($code_id); |
|
| 528 | 528 | $return = false; |
| 529 | 529 | |
| 530 | - if ( $discount ) { |
|
| 531 | - $min = (float)wpinv_get_discount_min_total( $code_id ); |
|
| 532 | - $cart_amount = (float)wpinv_get_cart_discountable_subtotal( $code_id ); |
|
| 530 | + if ($discount) { |
|
| 531 | + $min = (float)wpinv_get_discount_min_total($code_id); |
|
| 532 | + $cart_amount = (float)wpinv_get_cart_discountable_subtotal($code_id); |
|
| 533 | 533 | |
| 534 | - if ( !$min > 0 || $cart_amount >= $min ) { |
|
| 534 | + if (!$min > 0 || $cart_amount >= $min) { |
|
| 535 | 535 | // Minimum has been met |
| 536 | 536 | $return = true; |
| 537 | 537 | } else { |
| 538 | - wpinv_set_error( 'wpinv-discount-error', sprintf( __( 'Minimum invoice of %s not met.', 'invoicing' ), wpinv_price( wpinv_format_amount( $min ) ) ) ); |
|
| 538 | + wpinv_set_error('wpinv-discount-error', sprintf(__('Minimum invoice of %s not met.', 'invoicing'), wpinv_price(wpinv_format_amount($min)))); |
|
| 539 | 539 | } |
| 540 | 540 | } |
| 541 | 541 | |
| 542 | - return apply_filters( 'wpinv_is_discount_min_met', $return, $code_id ); |
|
| 542 | + return apply_filters('wpinv_is_discount_min_met', $return, $code_id); |
|
| 543 | 543 | } |
| 544 | 544 | |
| 545 | -function wpinv_discount_is_max_met( $code_id = null ) { |
|
| 546 | - $discount = wpinv_get_discount( $code_id ); |
|
| 545 | +function wpinv_discount_is_max_met($code_id = null) { |
|
| 546 | + $discount = wpinv_get_discount($code_id); |
|
| 547 | 547 | $return = false; |
| 548 | 548 | |
| 549 | - if ( $discount ) { |
|
| 550 | - $max = (float)wpinv_get_discount_max_total( $code_id ); |
|
| 551 | - $cart_amount = (float)wpinv_get_cart_discountable_subtotal( $code_id ); |
|
| 549 | + if ($discount) { |
|
| 550 | + $max = (float)wpinv_get_discount_max_total($code_id); |
|
| 551 | + $cart_amount = (float)wpinv_get_cart_discountable_subtotal($code_id); |
|
| 552 | 552 | |
| 553 | - if ( !$max > 0 || $cart_amount <= $max ) { |
|
| 553 | + if (!$max > 0 || $cart_amount <= $max) { |
|
| 554 | 554 | // Minimum has been met |
| 555 | 555 | $return = true; |
| 556 | 556 | } else { |
| 557 | - wpinv_set_error( 'wpinv-discount-error', sprintf( __( 'Maximum invoice of %s not met.', 'invoicing' ), wpinv_price( wpinv_format_amount( $max ) ) ) ); |
|
| 557 | + wpinv_set_error('wpinv-discount-error', sprintf(__('Maximum invoice of %s not met.', 'invoicing'), wpinv_price(wpinv_format_amount($max)))); |
|
| 558 | 558 | } |
| 559 | 559 | } |
| 560 | 560 | |
| 561 | - return apply_filters( 'wpinv_is_discount_max_met', $return, $code_id ); |
|
| 561 | + return apply_filters('wpinv_is_discount_max_met', $return, $code_id); |
|
| 562 | 562 | } |
| 563 | 563 | |
| 564 | -function wpinv_discount_is_single_use( $code_id = 0 ) { |
|
| 565 | - $single_use = get_post_meta( $code_id, '_wpi_discount_is_single_use', true ); |
|
| 566 | - return (bool) apply_filters( 'wpinv_is_discount_single_use', $single_use, $code_id ); |
|
| 564 | +function wpinv_discount_is_single_use($code_id = 0) { |
|
| 565 | + $single_use = get_post_meta($code_id, '_wpi_discount_is_single_use', true); |
|
| 566 | + return (bool)apply_filters('wpinv_is_discount_single_use', $single_use, $code_id); |
|
| 567 | 567 | } |
| 568 | 568 | |
| 569 | -function wpinv_discount_is_recurring( $code_id = 0, $code = false ) { |
|
| 570 | - if ( $code ) { |
|
| 571 | - $discount = wpinv_get_discount_by_code( $code_id ); |
|
| 569 | +function wpinv_discount_is_recurring($code_id = 0, $code = false) { |
|
| 570 | + if ($code) { |
|
| 571 | + $discount = wpinv_get_discount_by_code($code_id); |
|
| 572 | 572 | |
| 573 | - if ( !empty( $discount ) ) { |
|
| 573 | + if (!empty($discount)) { |
|
| 574 | 574 | $code_id = $discount->ID; |
| 575 | 575 | } |
| 576 | 576 | } |
| 577 | 577 | |
| 578 | - $recurring = get_post_meta( $code_id, '_wpi_discount_is_recurring', true ); |
|
| 578 | + $recurring = get_post_meta($code_id, '_wpi_discount_is_recurring', true); |
|
| 579 | 579 | |
| 580 | - return (bool) apply_filters( 'wpinv_is_discount_recurring', $recurring, $code_id, $code ); |
|
| 580 | + return (bool)apply_filters('wpinv_is_discount_recurring', $recurring, $code_id, $code); |
|
| 581 | 581 | } |
| 582 | 582 | |
| 583 | -function wpinv_discount_item_reqs_met( $code_id = null ) { |
|
| 584 | - $item_reqs = wpinv_get_discount_item_reqs( $code_id ); |
|
| 585 | - $condition = wpinv_get_discount_item_condition( $code_id ); |
|
| 586 | - $excluded_ps = wpinv_get_discount_excluded_items( $code_id ); |
|
| 583 | +function wpinv_discount_item_reqs_met($code_id = null) { |
|
| 584 | + $item_reqs = wpinv_get_discount_item_reqs($code_id); |
|
| 585 | + $condition = wpinv_get_discount_item_condition($code_id); |
|
| 586 | + $excluded_ps = wpinv_get_discount_excluded_items($code_id); |
|
| 587 | 587 | $cart_items = wpinv_get_cart_contents(); |
| 588 | - $cart_ids = $cart_items ? wp_list_pluck( $cart_items, 'id' ) : null; |
|
| 588 | + $cart_ids = $cart_items ? wp_list_pluck($cart_items, 'id') : null; |
|
| 589 | 589 | $ret = false; |
| 590 | 590 | |
| 591 | - if ( empty( $item_reqs ) && empty( $excluded_ps ) ) { |
|
| 591 | + if (empty($item_reqs) && empty($excluded_ps)) { |
|
| 592 | 592 | $ret = true; |
| 593 | 593 | } |
| 594 | 594 | |
| 595 | 595 | // Normalize our data for item requirements, exclusions and cart data |
| 596 | 596 | // First absint the items, then sort, and reset the array keys |
| 597 | - $item_reqs = array_map( 'absint', $item_reqs ); |
|
| 598 | - asort( $item_reqs ); |
|
| 599 | - $item_reqs = array_values( $item_reqs ); |
|
| 597 | + $item_reqs = array_map('absint', $item_reqs); |
|
| 598 | + asort($item_reqs); |
|
| 599 | + $item_reqs = array_values($item_reqs); |
|
| 600 | 600 | |
| 601 | - $excluded_ps = array_map( 'absint', $excluded_ps ); |
|
| 602 | - asort( $excluded_ps ); |
|
| 603 | - $excluded_ps = array_values( $excluded_ps ); |
|
| 601 | + $excluded_ps = array_map('absint', $excluded_ps); |
|
| 602 | + asort($excluded_ps); |
|
| 603 | + $excluded_ps = array_values($excluded_ps); |
|
| 604 | 604 | |
| 605 | - $cart_ids = array_map( 'absint', $cart_ids ); |
|
| 606 | - asort( $cart_ids ); |
|
| 607 | - $cart_ids = array_values( $cart_ids ); |
|
| 605 | + $cart_ids = array_map('absint', $cart_ids); |
|
| 606 | + asort($cart_ids); |
|
| 607 | + $cart_ids = array_values($cart_ids); |
|
| 608 | 608 | |
| 609 | 609 | // Ensure we have requirements before proceeding |
| 610 | - if ( !$ret && ! empty( $item_reqs ) ) { |
|
| 611 | - switch( $condition ) { |
|
| 610 | + if (!$ret && !empty($item_reqs)) { |
|
| 611 | + switch ($condition) { |
|
| 612 | 612 | case 'all' : |
| 613 | 613 | // Default back to true |
| 614 | 614 | $ret = true; |
| 615 | 615 | |
| 616 | - foreach ( $item_reqs as $item_id ) { |
|
| 617 | - if ( !wpinv_item_in_cart( $item_id ) ) { |
|
| 618 | - wpinv_set_error( 'wpinv-discount-error', __( 'The item requirements for this discount are not met.', 'invoicing' ) ); |
|
| 616 | + foreach ($item_reqs as $item_id) { |
|
| 617 | + if (!wpinv_item_in_cart($item_id)) { |
|
| 618 | + wpinv_set_error('wpinv-discount-error', __('The item requirements for this discount are not met.', 'invoicing')); |
|
| 619 | 619 | $ret = false; |
| 620 | 620 | break; |
| 621 | 621 | } |
@@ -624,15 +624,15 @@ discard block |
||
| 624 | 624 | break; |
| 625 | 625 | |
| 626 | 626 | default : // Any |
| 627 | - foreach ( $item_reqs as $item_id ) { |
|
| 628 | - if ( wpinv_item_in_cart( $item_id ) ) { |
|
| 627 | + foreach ($item_reqs as $item_id) { |
|
| 628 | + if (wpinv_item_in_cart($item_id)) { |
|
| 629 | 629 | $ret = true; |
| 630 | 630 | break; |
| 631 | 631 | } |
| 632 | 632 | } |
| 633 | 633 | |
| 634 | - if( ! $ret ) { |
|
| 635 | - wpinv_set_error( 'wpinv-discount-error', __( 'The item requirements for this discount are not met.', 'invoicing' ) ); |
|
| 634 | + if (!$ret) { |
|
| 635 | + wpinv_set_error('wpinv-discount-error', __('The item requirements for this discount are not met.', 'invoicing')); |
|
| 636 | 636 | } |
| 637 | 637 | |
| 638 | 638 | break; |
@@ -641,68 +641,68 @@ discard block |
||
| 641 | 641 | $ret = true; |
| 642 | 642 | } |
| 643 | 643 | |
| 644 | - if( ! empty( $excluded_ps ) ) { |
|
| 644 | + if (!empty($excluded_ps)) { |
|
| 645 | 645 | // Check that there are items other than excluded ones in the cart |
| 646 | - if( $cart_ids == $excluded_ps ) { |
|
| 647 | - wpinv_set_error( 'wpinv-discount-error', __( 'This discount is not valid for the cart contents.', 'invoicing' ) ); |
|
| 646 | + if ($cart_ids == $excluded_ps) { |
|
| 647 | + wpinv_set_error('wpinv-discount-error', __('This discount is not valid for the cart contents.', 'invoicing')); |
|
| 648 | 648 | $ret = false; |
| 649 | 649 | } |
| 650 | 650 | } |
| 651 | 651 | |
| 652 | - return (bool) apply_filters( 'wpinv_is_discount_item_req_met', $ret, $code_id, $condition ); |
|
| 652 | + return (bool)apply_filters('wpinv_is_discount_item_req_met', $ret, $code_id, $condition); |
|
| 653 | 653 | } |
| 654 | 654 | |
| 655 | -function wpinv_is_discount_used( $code = null, $user = '', $code_id = 0 ) { |
|
| 655 | +function wpinv_is_discount_used($code = null, $user = '', $code_id = 0) { |
|
| 656 | 656 | global $wpi_checkout_id; |
| 657 | 657 | |
| 658 | 658 | $return = false; |
| 659 | 659 | |
| 660 | - if ( empty( $code_id ) ) { |
|
| 661 | - $code_id = wpinv_get_discount_id_by_code( $code ); |
|
| 660 | + if (empty($code_id)) { |
|
| 661 | + $code_id = wpinv_get_discount_id_by_code($code); |
|
| 662 | 662 | |
| 663 | - if( empty( $code_id ) ) { |
|
| 663 | + if (empty($code_id)) { |
|
| 664 | 664 | return false; // No discount was found |
| 665 | 665 | } |
| 666 | 666 | } |
| 667 | 667 | |
| 668 | - if ( wpinv_discount_is_single_use( $code_id ) ) { |
|
| 668 | + if (wpinv_discount_is_single_use($code_id)) { |
|
| 669 | 669 | $payments = array(); |
| 670 | 670 | |
| 671 | 671 | $user_id = 0; |
| 672 | - if ( is_int( $user ) ) { |
|
| 672 | + if (is_int($user)) { |
|
| 673 | 673 | $user_id = $user; |
| 674 | - } else if ( is_email( $user ) && $user_data = get_user_by( 'email', $user ) ) { |
|
| 674 | + } else if (is_email($user) && $user_data = get_user_by('email', $user)) { |
|
| 675 | 675 | $user_id = $user_data->ID; |
| 676 | - } else if ( $user_data = get_user_by( 'login', $user ) ) { |
|
| 676 | + } else if ($user_data = get_user_by('login', $user)) { |
|
| 677 | 677 | $user_id = $user_data->ID; |
| 678 | 678 | } |
| 679 | 679 | |
| 680 | - if ( !$user_id ) { |
|
| 681 | - $query = array( 'user' => $user_id, 'limit' => false ); |
|
| 682 | - $payments = wpinv_get_invoices( $query ); // Get all payments with matching email |
|
| 680 | + if (!$user_id) { |
|
| 681 | + $query = array('user' => $user_id, 'limit' => false); |
|
| 682 | + $payments = wpinv_get_invoices($query); // Get all payments with matching email |
|
| 683 | 683 | } |
| 684 | 684 | |
| 685 | - if ( $payments ) { |
|
| 686 | - foreach ( $payments as $payment ) { |
|
| 687 | - if ( $payment->has_status( array( 'wpi-cancelled', 'wpi-failed' ) ) ) { |
|
| 685 | + if ($payments) { |
|
| 686 | + foreach ($payments as $payment) { |
|
| 687 | + if ($payment->has_status(array('wpi-cancelled', 'wpi-failed'))) { |
|
| 688 | 688 | continue; |
| 689 | 689 | } |
| 690 | 690 | |
| 691 | 691 | // Don't count discount used for current invoice chekcout. |
| 692 | - if ( !empty( $wpi_checkout_id ) && $wpi_checkout_id == $payment->ID ) { |
|
| 692 | + if (!empty($wpi_checkout_id) && $wpi_checkout_id == $payment->ID) { |
|
| 693 | 693 | continue; |
| 694 | 694 | } |
| 695 | 695 | |
| 696 | - $discounts = $payment->get_discounts( true ); |
|
| 697 | - if ( empty( $discounts ) ) { |
|
| 696 | + $discounts = $payment->get_discounts(true); |
|
| 697 | + if (empty($discounts)) { |
|
| 698 | 698 | continue; |
| 699 | 699 | } |
| 700 | 700 | |
| 701 | - $discounts = $discounts && !is_array( $discounts ) ? explode( ',', $discounts ) : $discounts; |
|
| 701 | + $discounts = $discounts && !is_array($discounts) ? explode(',', $discounts) : $discounts; |
|
| 702 | 702 | |
| 703 | - if ( !empty( $discounts ) && is_array( $discounts ) ) { |
|
| 704 | - if ( in_array( strtolower( $code ), array_map( 'strtolower', $discounts ) ) ) { |
|
| 705 | - wpinv_set_error( 'wpinv-discount-error', __( 'This discount has already been redeemed.', 'invoicing' ) ); |
|
| 703 | + if (!empty($discounts) && is_array($discounts)) { |
|
| 704 | + if (in_array(strtolower($code), array_map('strtolower', $discounts))) { |
|
| 705 | + wpinv_set_error('wpinv-discount-error', __('This discount has already been redeemed.', 'invoicing')); |
|
| 706 | 706 | $return = true; |
| 707 | 707 | break; |
| 708 | 708 | } |
@@ -711,61 +711,61 @@ discard block |
||
| 711 | 711 | } |
| 712 | 712 | } |
| 713 | 713 | |
| 714 | - return apply_filters( 'wpinv_is_discount_used', $return, $code, $user ); |
|
| 714 | + return apply_filters('wpinv_is_discount_used', $return, $code, $user); |
|
| 715 | 715 | } |
| 716 | 716 | |
| 717 | -function wpinv_is_discount_valid( $code = '', $user = '', $set_error = true ) { |
|
| 717 | +function wpinv_is_discount_valid($code = '', $user = '', $set_error = true) { |
|
| 718 | 718 | $return = false; |
| 719 | - $discount_id = wpinv_get_discount_id_by_code( $code ); |
|
| 720 | - $user = trim( $user ); |
|
| 719 | + $discount_id = wpinv_get_discount_id_by_code($code); |
|
| 720 | + $user = trim($user); |
|
| 721 | 721 | |
| 722 | - if ( wpinv_get_cart_contents() ) { |
|
| 723 | - if ( $discount_id ) { |
|
| 722 | + if (wpinv_get_cart_contents()) { |
|
| 723 | + if ($discount_id) { |
|
| 724 | 724 | if ( |
| 725 | - wpinv_is_discount_active( $discount_id ) && |
|
| 726 | - wpinv_check_discount_dates( $discount_id ) && |
|
| 727 | - !wpinv_is_discount_maxed_out( $discount_id ) && |
|
| 728 | - !wpinv_is_discount_used( $code, $user, $discount_id ) && |
|
| 729 | - wpinv_discount_is_min_met( $discount_id ) && |
|
| 730 | - wpinv_discount_is_max_met( $discount_id ) && |
|
| 731 | - wpinv_discount_item_reqs_met( $discount_id ) |
|
| 725 | + wpinv_is_discount_active($discount_id) && |
|
| 726 | + wpinv_check_discount_dates($discount_id) && |
|
| 727 | + !wpinv_is_discount_maxed_out($discount_id) && |
|
| 728 | + !wpinv_is_discount_used($code, $user, $discount_id) && |
|
| 729 | + wpinv_discount_is_min_met($discount_id) && |
|
| 730 | + wpinv_discount_is_max_met($discount_id) && |
|
| 731 | + wpinv_discount_item_reqs_met($discount_id) |
|
| 732 | 732 | ) { |
| 733 | 733 | $return = true; |
| 734 | 734 | } |
| 735 | - } elseif( $set_error ) { |
|
| 736 | - wpinv_set_error( 'wpinv-discount-error', __( 'This discount is invalid.', 'invoicing' ) ); |
|
| 735 | + } elseif ($set_error) { |
|
| 736 | + wpinv_set_error('wpinv-discount-error', __('This discount is invalid.', 'invoicing')); |
|
| 737 | 737 | } |
| 738 | 738 | } |
| 739 | 739 | |
| 740 | - return apply_filters( 'wpinv_is_discount_valid', $return, $discount_id, $code, $user ); |
|
| 740 | + return apply_filters('wpinv_is_discount_valid', $return, $discount_id, $code, $user); |
|
| 741 | 741 | } |
| 742 | 742 | |
| 743 | -function wpinv_get_discount_id_by_code( $code ) { |
|
| 744 | - $discount = wpinv_get_discount_by_code( $code ); |
|
| 745 | - if( $discount ) { |
|
| 743 | +function wpinv_get_discount_id_by_code($code) { |
|
| 744 | + $discount = wpinv_get_discount_by_code($code); |
|
| 745 | + if ($discount) { |
|
| 746 | 746 | return $discount->ID; |
| 747 | 747 | } |
| 748 | 748 | return false; |
| 749 | 749 | } |
| 750 | 750 | |
| 751 | -function wpinv_get_discounted_amount( $code, $base_price ) { |
|
| 751 | +function wpinv_get_discounted_amount($code, $base_price) { |
|
| 752 | 752 | $amount = $base_price; |
| 753 | - $discount_id = wpinv_get_discount_id_by_code( $code ); |
|
| 753 | + $discount_id = wpinv_get_discount_id_by_code($code); |
|
| 754 | 754 | |
| 755 | - if( $discount_id ) { |
|
| 756 | - $type = wpinv_get_discount_type( $discount_id ); |
|
| 757 | - $rate = wpinv_get_discount_amount( $discount_id ); |
|
| 755 | + if ($discount_id) { |
|
| 756 | + $type = wpinv_get_discount_type($discount_id); |
|
| 757 | + $rate = wpinv_get_discount_amount($discount_id); |
|
| 758 | 758 | |
| 759 | - if ( $type == 'flat' ) { |
|
| 759 | + if ($type == 'flat') { |
|
| 760 | 760 | // Set amount |
| 761 | 761 | $amount = $base_price - $rate; |
| 762 | - if ( $amount < 0 ) { |
|
| 762 | + if ($amount < 0) { |
|
| 763 | 763 | $amount = 0; |
| 764 | 764 | } |
| 765 | 765 | |
| 766 | 766 | } else { |
| 767 | 767 | // Percentage discount |
| 768 | - $amount = $base_price - ( $base_price * ( $rate / 100 ) ); |
|
| 768 | + $amount = $base_price - ($base_price * ($rate / 100)); |
|
| 769 | 769 | } |
| 770 | 770 | |
| 771 | 771 | } else { |
@@ -774,108 +774,108 @@ discard block |
||
| 774 | 774 | |
| 775 | 775 | } |
| 776 | 776 | |
| 777 | - return apply_filters( 'wpinv_discounted_amount', $amount ); |
|
| 777 | + return apply_filters('wpinv_discounted_amount', $amount); |
|
| 778 | 778 | } |
| 779 | 779 | |
| 780 | -function wpinv_increase_discount_usage( $code ) { |
|
| 780 | +function wpinv_increase_discount_usage($code) { |
|
| 781 | 781 | |
| 782 | - $id = wpinv_get_discount_id_by_code( $code ); |
|
| 783 | - $uses = wpinv_get_discount_uses( $id ); |
|
| 782 | + $id = wpinv_get_discount_id_by_code($code); |
|
| 783 | + $uses = wpinv_get_discount_uses($id); |
|
| 784 | 784 | |
| 785 | - if ( $uses ) { |
|
| 785 | + if ($uses) { |
|
| 786 | 786 | $uses++; |
| 787 | 787 | } else { |
| 788 | 788 | $uses = 1; |
| 789 | 789 | } |
| 790 | 790 | |
| 791 | - update_post_meta( $id, '_wpi_discount_uses', $uses ); |
|
| 791 | + update_post_meta($id, '_wpi_discount_uses', $uses); |
|
| 792 | 792 | |
| 793 | - do_action( 'wpinv_discount_increase_use_count', $uses, $id, $code ); |
|
| 793 | + do_action('wpinv_discount_increase_use_count', $uses, $id, $code); |
|
| 794 | 794 | |
| 795 | 795 | return $uses; |
| 796 | 796 | |
| 797 | 797 | } |
| 798 | 798 | |
| 799 | -function wpinv_decrease_discount_usage( $code ) { |
|
| 799 | +function wpinv_decrease_discount_usage($code) { |
|
| 800 | 800 | |
| 801 | - $id = wpinv_get_discount_id_by_code( $code ); |
|
| 802 | - $uses = wpinv_get_discount_uses( $id ); |
|
| 801 | + $id = wpinv_get_discount_id_by_code($code); |
|
| 802 | + $uses = wpinv_get_discount_uses($id); |
|
| 803 | 803 | |
| 804 | - if ( $uses ) { |
|
| 804 | + if ($uses) { |
|
| 805 | 805 | $uses--; |
| 806 | 806 | } |
| 807 | 807 | |
| 808 | - if ( $uses < 0 ) { |
|
| 808 | + if ($uses < 0) { |
|
| 809 | 809 | $uses = 0; |
| 810 | 810 | } |
| 811 | 811 | |
| 812 | - update_post_meta( $id, '_wpi_discount_uses', $uses ); |
|
| 812 | + update_post_meta($id, '_wpi_discount_uses', $uses); |
|
| 813 | 813 | |
| 814 | - do_action( 'wpinv_discount_decrease_use_count', $uses, $id, $code ); |
|
| 814 | + do_action('wpinv_discount_decrease_use_count', $uses, $id, $code); |
|
| 815 | 815 | |
| 816 | 816 | return $uses; |
| 817 | 817 | |
| 818 | 818 | } |
| 819 | 819 | |
| 820 | -function wpinv_format_discount_rate( $type, $amount ) { |
|
| 821 | - if ( $type == 'flat' ) { |
|
| 822 | - return wpinv_price( wpinv_format_amount( $amount ) ); |
|
| 820 | +function wpinv_format_discount_rate($type, $amount) { |
|
| 821 | + if ($type == 'flat') { |
|
| 822 | + return wpinv_price(wpinv_format_amount($amount)); |
|
| 823 | 823 | } else { |
| 824 | 824 | return $amount . '%'; |
| 825 | 825 | } |
| 826 | 826 | } |
| 827 | 827 | |
| 828 | -function wpinv_set_cart_discount( $code = '' ) { |
|
| 829 | - if ( wpinv_multiple_discounts_allowed() ) { |
|
| 828 | +function wpinv_set_cart_discount($code = '') { |
|
| 829 | + if (wpinv_multiple_discounts_allowed()) { |
|
| 830 | 830 | // Get all active cart discounts |
| 831 | 831 | $discounts = wpinv_get_cart_discounts(); |
| 832 | 832 | } else { |
| 833 | 833 | $discounts = false; // Only one discount allowed per purchase, so override any existing |
| 834 | 834 | } |
| 835 | 835 | |
| 836 | - if ( $discounts ) { |
|
| 837 | - $key = array_search( strtolower( $code ), array_map( 'strtolower', $discounts ) ); |
|
| 838 | - if( false !== $key ) { |
|
| 839 | - unset( $discounts[ $key ] ); // Can't set the same discount more than once |
|
| 836 | + if ($discounts) { |
|
| 837 | + $key = array_search(strtolower($code), array_map('strtolower', $discounts)); |
|
| 838 | + if (false !== $key) { |
|
| 839 | + unset($discounts[$key]); // Can't set the same discount more than once |
|
| 840 | 840 | } |
| 841 | 841 | $discounts[] = $code; |
| 842 | 842 | } else { |
| 843 | 843 | $discounts = array(); |
| 844 | 844 | $discounts[] = $code; |
| 845 | 845 | } |
| 846 | - $discounts = array_values( $discounts ); |
|
| 846 | + $discounts = array_values($discounts); |
|
| 847 | 847 | |
| 848 | 848 | $data = wpinv_get_checkout_session(); |
| 849 | - if ( empty( $data ) ) { |
|
| 849 | + if (empty($data)) { |
|
| 850 | 850 | $data = array(); |
| 851 | 851 | } else { |
| 852 | - if ( !empty( $data['invoice_id'] ) && $payment_meta = wpinv_get_invoice_meta( $data['invoice_id'] ) ) { |
|
| 853 | - $payment_meta['user_info']['discount'] = implode( ',', $discounts ); |
|
| 854 | - update_post_meta( $data['invoice_id'], '_wpinv_payment_meta', $payment_meta ); |
|
| 852 | + if (!empty($data['invoice_id']) && $payment_meta = wpinv_get_invoice_meta($data['invoice_id'])) { |
|
| 853 | + $payment_meta['user_info']['discount'] = implode(',', $discounts); |
|
| 854 | + update_post_meta($data['invoice_id'], '_wpinv_payment_meta', $payment_meta); |
|
| 855 | 855 | } |
| 856 | 856 | } |
| 857 | 857 | $data['cart_discounts'] = $discounts; |
| 858 | 858 | |
| 859 | - wpinv_set_checkout_session( $data ); |
|
| 859 | + wpinv_set_checkout_session($data); |
|
| 860 | 860 | |
| 861 | 861 | return $discounts; |
| 862 | 862 | } |
| 863 | 863 | |
| 864 | -function wpinv_unset_cart_discount( $code = '' ) { |
|
| 864 | +function wpinv_unset_cart_discount($code = '') { |
|
| 865 | 865 | $discounts = wpinv_get_cart_discounts(); |
| 866 | 866 | |
| 867 | - if ( $code && !empty( $discounts ) && in_array( $code, $discounts ) ) { |
|
| 868 | - $key = array_search( $code, $discounts ); |
|
| 869 | - unset( $discounts[ $key ] ); |
|
| 867 | + if ($code && !empty($discounts) && in_array($code, $discounts)) { |
|
| 868 | + $key = array_search($code, $discounts); |
|
| 869 | + unset($discounts[$key]); |
|
| 870 | 870 | |
| 871 | 871 | $data = wpinv_get_checkout_session(); |
| 872 | 872 | $data['cart_discounts'] = $discounts; |
| 873 | - if ( !empty( $data['invoice_id'] ) && $payment_meta = wpinv_get_invoice_meta( $data['invoice_id'] ) ) { |
|
| 874 | - $payment_meta['user_info']['discount'] = !empty( $discounts ) ? implode( ',', $discounts ) : ''; |
|
| 875 | - update_post_meta( $data['invoice_id'], '_wpinv_payment_meta', $payment_meta ); |
|
| 873 | + if (!empty($data['invoice_id']) && $payment_meta = wpinv_get_invoice_meta($data['invoice_id'])) { |
|
| 874 | + $payment_meta['user_info']['discount'] = !empty($discounts) ? implode(',', $discounts) : ''; |
|
| 875 | + update_post_meta($data['invoice_id'], '_wpinv_payment_meta', $payment_meta); |
|
| 876 | 876 | } |
| 877 | 877 | |
| 878 | - wpinv_set_checkout_session( $data ); |
|
| 878 | + wpinv_set_checkout_session($data); |
|
| 879 | 879 | } |
| 880 | 880 | |
| 881 | 881 | return $discounts; |
@@ -884,27 +884,27 @@ discard block |
||
| 884 | 884 | function wpinv_unset_all_cart_discounts() { |
| 885 | 885 | $data = wpinv_get_checkout_session(); |
| 886 | 886 | |
| 887 | - if ( !empty( $data ) && isset( $data['cart_discounts'] ) ) { |
|
| 888 | - unset( $data['cart_discounts'] ); |
|
| 887 | + if (!empty($data) && isset($data['cart_discounts'])) { |
|
| 888 | + unset($data['cart_discounts']); |
|
| 889 | 889 | |
| 890 | - wpinv_set_checkout_session( $data ); |
|
| 890 | + wpinv_set_checkout_session($data); |
|
| 891 | 891 | return true; |
| 892 | 892 | } |
| 893 | 893 | |
| 894 | 894 | return false; |
| 895 | 895 | } |
| 896 | 896 | |
| 897 | -function wpinv_get_cart_discounts( $items = array() ) { |
|
| 897 | +function wpinv_get_cart_discounts($items = array()) { |
|
| 898 | 898 | $session = wpinv_get_checkout_session(); |
| 899 | 899 | |
| 900 | - $discounts = !empty( $session['cart_discounts'] ) ? $session['cart_discounts'] : false; |
|
| 900 | + $discounts = !empty($session['cart_discounts']) ? $session['cart_discounts'] : false; |
|
| 901 | 901 | return $discounts; |
| 902 | 902 | } |
| 903 | 903 | |
| 904 | -function wpinv_cart_has_discounts( $items = array() ) { |
|
| 904 | +function wpinv_cart_has_discounts($items = array()) { |
|
| 905 | 905 | $ret = false; |
| 906 | 906 | |
| 907 | - if ( wpinv_get_cart_discounts( $items ) ) { |
|
| 907 | + if (wpinv_get_cart_discounts($items)) { |
|
| 908 | 908 | $ret = true; |
| 909 | 909 | } |
| 910 | 910 | |
@@ -915,131 +915,131 @@ discard block |
||
| 915 | 915 | } |
| 916 | 916 | */ |
| 917 | 917 | |
| 918 | - return apply_filters( 'wpinv_cart_has_discounts', $ret ); |
|
| 918 | + return apply_filters('wpinv_cart_has_discounts', $ret); |
|
| 919 | 919 | } |
| 920 | 920 | |
| 921 | -function wpinv_get_cart_discounted_amount( $items = array(), $discounts = false ) { |
|
| 921 | +function wpinv_get_cart_discounted_amount($items = array(), $discounts = false) { |
|
| 922 | 922 | $amount = 0.00; |
| 923 | - $items = !empty( $items ) ? $items : wpinv_get_cart_content_details(); |
|
| 923 | + $items = !empty($items) ? $items : wpinv_get_cart_content_details(); |
|
| 924 | 924 | |
| 925 | - if ( $items ) { |
|
| 926 | - $discounts = wp_list_pluck( $items, 'discount' ); |
|
| 925 | + if ($items) { |
|
| 926 | + $discounts = wp_list_pluck($items, 'discount'); |
|
| 927 | 927 | |
| 928 | - if ( is_array( $discounts ) ) { |
|
| 929 | - $discounts = array_map( 'floatval', $discounts ); |
|
| 930 | - $amount = array_sum( $discounts ); |
|
| 928 | + if (is_array($discounts)) { |
|
| 929 | + $discounts = array_map('floatval', $discounts); |
|
| 930 | + $amount = array_sum($discounts); |
|
| 931 | 931 | } |
| 932 | 932 | } |
| 933 | 933 | |
| 934 | - return apply_filters( 'wpinv_get_cart_discounted_amount', $amount ); |
|
| 934 | + return apply_filters('wpinv_get_cart_discounted_amount', $amount); |
|
| 935 | 935 | } |
| 936 | 936 | |
| 937 | -function wpinv_get_cart_items_discount_amount( $items = array(), $discount = false ) { |
|
| 938 | - $items = !empty( $items ) ? $items : wpinv_get_cart_content_details(); |
|
| 937 | +function wpinv_get_cart_items_discount_amount($items = array(), $discount = false) { |
|
| 938 | + $items = !empty($items) ? $items : wpinv_get_cart_content_details(); |
|
| 939 | 939 | |
| 940 | - if ( empty( $discount ) || empty( $items ) ) { |
|
| 940 | + if (empty($discount) || empty($items)) { |
|
| 941 | 941 | return 0; |
| 942 | 942 | } |
| 943 | 943 | |
| 944 | 944 | $amount = 0; |
| 945 | 945 | |
| 946 | - foreach ( $items as $item ) { |
|
| 947 | - $amount += wpinv_get_cart_item_discount_amount( $item, $discount ); |
|
| 946 | + foreach ($items as $item) { |
|
| 947 | + $amount += wpinv_get_cart_item_discount_amount($item, $discount); |
|
| 948 | 948 | } |
| 949 | 949 | |
| 950 | - $amount = wpinv_round_amount( $amount ); |
|
| 950 | + $amount = wpinv_round_amount($amount); |
|
| 951 | 951 | |
| 952 | 952 | return $amount; |
| 953 | 953 | } |
| 954 | 954 | |
| 955 | -function wpinv_get_cart_item_discount_amount( $item = array(), $discount = false ) { |
|
| 955 | +function wpinv_get_cart_item_discount_amount($item = array(), $discount = false) { |
|
| 956 | 956 | global $wpinv_is_last_cart_item, $wpinv_flat_discount_total; |
| 957 | 957 | |
| 958 | 958 | $amount = 0; |
| 959 | 959 | |
| 960 | - if ( empty( $item ) || empty( $item['id'] ) ) { |
|
| 960 | + if (empty($item) || empty($item['id'])) { |
|
| 961 | 961 | return $amount; |
| 962 | 962 | } |
| 963 | 963 | |
| 964 | - if ( empty( $item['quantity'] ) ) { |
|
| 964 | + if (empty($item['quantity'])) { |
|
| 965 | 965 | return $amount; |
| 966 | 966 | } |
| 967 | 967 | |
| 968 | - if ( empty( $item['options'] ) ) { |
|
| 968 | + if (empty($item['options'])) { |
|
| 969 | 969 | $item['options'] = array(); |
| 970 | 970 | } |
| 971 | 971 | |
| 972 | - $price = wpinv_get_cart_item_price( $item['id'], $item, $item['options'] ); |
|
| 972 | + $price = wpinv_get_cart_item_price($item['id'], $item, $item['options']); |
|
| 973 | 973 | $discounted_price = $price; |
| 974 | 974 | |
| 975 | 975 | $discounts = false === $discount ? wpinv_get_cart_discounts() : $discount; |
| 976 | - if ( empty( $discounts ) ) { |
|
| 976 | + if (empty($discounts)) { |
|
| 977 | 977 | return $amount; |
| 978 | 978 | } |
| 979 | 979 | |
| 980 | - if ( $discounts ) { |
|
| 981 | - if ( is_array( $discounts ) ) { |
|
| 982 | - $discounts = array_values( $discounts ); |
|
| 980 | + if ($discounts) { |
|
| 981 | + if (is_array($discounts)) { |
|
| 982 | + $discounts = array_values($discounts); |
|
| 983 | 983 | } else { |
| 984 | - $discounts = explode( ',', $discounts ); |
|
| 984 | + $discounts = explode(',', $discounts); |
|
| 985 | 985 | } |
| 986 | 986 | } |
| 987 | 987 | |
| 988 | - if( $discounts ) { |
|
| 989 | - foreach ( $discounts as $discount ) { |
|
| 990 | - $code_id = wpinv_get_discount_id_by_code( $discount ); |
|
| 988 | + if ($discounts) { |
|
| 989 | + foreach ($discounts as $discount) { |
|
| 990 | + $code_id = wpinv_get_discount_id_by_code($discount); |
|
| 991 | 991 | |
| 992 | 992 | // Check discount exists |
| 993 | - if( ! $code_id ) { |
|
| 993 | + if (!$code_id) { |
|
| 994 | 994 | continue; |
| 995 | 995 | } |
| 996 | 996 | |
| 997 | - $reqs = wpinv_get_discount_item_reqs( $code_id ); |
|
| 998 | - $excluded_items = wpinv_get_discount_excluded_items( $code_id ); |
|
| 997 | + $reqs = wpinv_get_discount_item_reqs($code_id); |
|
| 998 | + $excluded_items = wpinv_get_discount_excluded_items($code_id); |
|
| 999 | 999 | |
| 1000 | 1000 | // Make sure requirements are set and that this discount shouldn't apply to the whole cart |
| 1001 | - if ( !empty( $reqs ) && wpinv_is_discount_not_global( $code_id ) ) { |
|
| 1002 | - foreach ( $reqs as $item_id ) { |
|
| 1003 | - if ( $item_id == $item['id'] && ! in_array( $item['id'], $excluded_items ) ) { |
|
| 1004 | - $discounted_price -= $price - wpinv_get_discounted_amount( $discount, $price ); |
|
| 1001 | + if (!empty($reqs) && wpinv_is_discount_not_global($code_id)) { |
|
| 1002 | + foreach ($reqs as $item_id) { |
|
| 1003 | + if ($item_id == $item['id'] && !in_array($item['id'], $excluded_items)) { |
|
| 1004 | + $discounted_price -= $price - wpinv_get_discounted_amount($discount, $price); |
|
| 1005 | 1005 | } |
| 1006 | 1006 | } |
| 1007 | 1007 | } else { |
| 1008 | 1008 | // This is a global cart discount |
| 1009 | - if ( !in_array( $item['id'], $excluded_items ) ) { |
|
| 1010 | - if ( 'flat' === wpinv_get_discount_type( $code_id ) ) { |
|
| 1009 | + if (!in_array($item['id'], $excluded_items)) { |
|
| 1010 | + if ('flat' === wpinv_get_discount_type($code_id)) { |
|
| 1011 | 1011 | $items_subtotal = 0.00; |
| 1012 | 1012 | $cart_items = wpinv_get_cart_contents(); |
| 1013 | 1013 | |
| 1014 | - foreach ( $cart_items as $cart_item ) { |
|
| 1015 | - if ( ! in_array( $cart_item['id'], $excluded_items ) ) { |
|
| 1016 | - $options = !empty( $cart_item['options'] ) ? $cart_item['options'] : array(); |
|
| 1017 | - $item_price = wpinv_get_cart_item_price( $cart_item['id'], $cart_item, $options ); |
|
| 1014 | + foreach ($cart_items as $cart_item) { |
|
| 1015 | + if (!in_array($cart_item['id'], $excluded_items)) { |
|
| 1016 | + $options = !empty($cart_item['options']) ? $cart_item['options'] : array(); |
|
| 1017 | + $item_price = wpinv_get_cart_item_price($cart_item['id'], $cart_item, $options); |
|
| 1018 | 1018 | $items_subtotal += $item_price * $cart_item['quantity']; |
| 1019 | 1019 | } |
| 1020 | 1020 | } |
| 1021 | 1021 | |
| 1022 | - $subtotal_percent = ( ( $price * $item['quantity'] ) / $items_subtotal ); |
|
| 1023 | - $code_amount = wpinv_get_discount_amount( $code_id ); |
|
| 1022 | + $subtotal_percent = (($price * $item['quantity']) / $items_subtotal); |
|
| 1023 | + $code_amount = wpinv_get_discount_amount($code_id); |
|
| 1024 | 1024 | $discounted_amount = $code_amount * $subtotal_percent; |
| 1025 | 1025 | $discounted_price -= $discounted_amount; |
| 1026 | 1026 | |
| 1027 | - $wpinv_flat_discount_total += round( $discounted_amount, wpinv_currency_decimal_filter() ); |
|
| 1027 | + $wpinv_flat_discount_total += round($discounted_amount, wpinv_currency_decimal_filter()); |
|
| 1028 | 1028 | |
| 1029 | - if ( $wpinv_is_last_cart_item && $wpinv_flat_discount_total < $code_amount ) { |
|
| 1029 | + if ($wpinv_is_last_cart_item && $wpinv_flat_discount_total < $code_amount) { |
|
| 1030 | 1030 | $adjustment = $code_amount - $wpinv_flat_discount_total; |
| 1031 | 1031 | $discounted_price -= $adjustment; |
| 1032 | 1032 | } |
| 1033 | 1033 | } else { |
| 1034 | - $discounted_price -= $price - wpinv_get_discounted_amount( $discount, $price ); |
|
| 1034 | + $discounted_price -= $price - wpinv_get_discounted_amount($discount, $price); |
|
| 1035 | 1035 | } |
| 1036 | 1036 | } |
| 1037 | 1037 | } |
| 1038 | 1038 | } |
| 1039 | 1039 | |
| 1040 | - $amount = ( $price - apply_filters( 'wpinv_get_cart_item_discounted_amount', $discounted_price, $discounts, $item, $price ) ); |
|
| 1040 | + $amount = ($price - apply_filters('wpinv_get_cart_item_discounted_amount', $discounted_price, $discounts, $item, $price)); |
|
| 1041 | 1041 | |
| 1042 | - if ( 'flat' !== wpinv_get_discount_type( $code_id ) ) { |
|
| 1042 | + if ('flat' !== wpinv_get_discount_type($code_id)) { |
|
| 1043 | 1043 | $amount = $amount * $item['quantity']; |
| 1044 | 1044 | } |
| 1045 | 1045 | } |
@@ -1047,59 +1047,59 @@ discard block |
||
| 1047 | 1047 | return $amount; |
| 1048 | 1048 | } |
| 1049 | 1049 | |
| 1050 | -function wpinv_cart_discounts_html( $items = array() ) { |
|
| 1051 | - echo wpinv_get_cart_discounts_html( $items ); |
|
| 1050 | +function wpinv_cart_discounts_html($items = array()) { |
|
| 1051 | + echo wpinv_get_cart_discounts_html($items); |
|
| 1052 | 1052 | } |
| 1053 | 1053 | |
| 1054 | -function wpinv_get_cart_discounts_html( $items = array(), $discounts = false ) { |
|
| 1054 | +function wpinv_get_cart_discounts_html($items = array(), $discounts = false) { |
|
| 1055 | 1055 | global $wpi_cart_columns; |
| 1056 | 1056 | |
| 1057 | - $items = !empty( $items ) ? $items : wpinv_get_cart_content_details(); |
|
| 1057 | + $items = !empty($items) ? $items : wpinv_get_cart_content_details(); |
|
| 1058 | 1058 | |
| 1059 | - if ( !$discounts ) { |
|
| 1060 | - $discounts = wpinv_get_cart_discounts( $items ); |
|
| 1059 | + if (!$discounts) { |
|
| 1060 | + $discounts = wpinv_get_cart_discounts($items); |
|
| 1061 | 1061 | } |
| 1062 | 1062 | |
| 1063 | - if ( !$discounts ) { |
|
| 1063 | + if (!$discounts) { |
|
| 1064 | 1064 | return; |
| 1065 | 1065 | } |
| 1066 | 1066 | |
| 1067 | - $discounts = is_array( $discounts ) ? $discounts : array( $discounts ); |
|
| 1067 | + $discounts = is_array($discounts) ? $discounts : array($discounts); |
|
| 1068 | 1068 | |
| 1069 | 1069 | $html = ''; |
| 1070 | 1070 | |
| 1071 | - foreach ( $discounts as $discount ) { |
|
| 1072 | - $discount_id = wpinv_get_discount_id_by_code( $discount ); |
|
| 1073 | - $discount_value = wpinv_get_discount_amount( $discount_id ); |
|
| 1074 | - $rate = wpinv_format_discount_rate( wpinv_get_discount_type( $discount_id ), $discount_value ); |
|
| 1075 | - $amount = wpinv_get_cart_items_discount_amount( $items, $discount ); |
|
| 1076 | - $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> '; |
|
| 1071 | + foreach ($discounts as $discount) { |
|
| 1072 | + $discount_id = wpinv_get_discount_id_by_code($discount); |
|
| 1073 | + $discount_value = wpinv_get_discount_amount($discount_id); |
|
| 1074 | + $rate = wpinv_format_discount_rate(wpinv_get_discount_type($discount_id), $discount_value); |
|
| 1075 | + $amount = wpinv_get_cart_items_discount_amount($items, $discount); |
|
| 1076 | + $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> '; |
|
| 1077 | 1077 | |
| 1078 | 1078 | $html .= '<tr class="wpinv_cart_footer_row wpinv_cart_discount_row">'; |
| 1079 | 1079 | ob_start(); |
| 1080 | - do_action( 'wpinv_checkout_table_discount_first', $items ); |
|
| 1080 | + do_action('wpinv_checkout_table_discount_first', $items); |
|
| 1081 | 1081 | $html .= ob_get_clean(); |
| 1082 | - $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 | + $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>'; |
|
| 1083 | 1083 | ob_start(); |
| 1084 | - do_action( 'wpinv_checkout_table_discount_last', $items ); |
|
| 1084 | + do_action('wpinv_checkout_table_discount_last', $items); |
|
| 1085 | 1085 | $html .= ob_get_clean(); |
| 1086 | 1086 | $html .= '</tr>'; |
| 1087 | 1087 | } |
| 1088 | 1088 | |
| 1089 | - return apply_filters( 'wpinv_get_cart_discounts_html', $html, $discounts, $rate ); |
|
| 1089 | + return apply_filters('wpinv_get_cart_discounts_html', $html, $discounts, $rate); |
|
| 1090 | 1090 | } |
| 1091 | 1091 | |
| 1092 | -function wpinv_display_cart_discount( $formatted = false, $echo = false ) { |
|
| 1092 | +function wpinv_display_cart_discount($formatted = false, $echo = false) { |
|
| 1093 | 1093 | $discounts = wpinv_get_cart_discounts(); |
| 1094 | 1094 | |
| 1095 | - if ( empty( $discounts ) ) { |
|
| 1095 | + if (empty($discounts)) { |
|
| 1096 | 1096 | return false; |
| 1097 | 1097 | } |
| 1098 | 1098 | |
| 1099 | - $discount_id = wpinv_get_discount_id_by_code( $discounts[0] ); |
|
| 1100 | - $amount = wpinv_format_discount_rate( wpinv_get_discount_type( $discount_id ), wpinv_get_discount_amount( $discount_id ) ); |
|
| 1099 | + $discount_id = wpinv_get_discount_id_by_code($discounts[0]); |
|
| 1100 | + $amount = wpinv_format_discount_rate(wpinv_get_discount_type($discount_id), wpinv_get_discount_amount($discount_id)); |
|
| 1101 | 1101 | |
| 1102 | - if ( $echo ) { |
|
| 1102 | + if ($echo) { |
|
| 1103 | 1103 | echo $amount; |
| 1104 | 1104 | } |
| 1105 | 1105 | |
@@ -1107,133 +1107,133 @@ discard block |
||
| 1107 | 1107 | } |
| 1108 | 1108 | |
| 1109 | 1109 | function wpinv_remove_cart_discount() { |
| 1110 | - if ( !isset( $_GET['discount_id'] ) || ! isset( $_GET['discount_code'] ) ) { |
|
| 1110 | + if (!isset($_GET['discount_id']) || !isset($_GET['discount_code'])) { |
|
| 1111 | 1111 | return; |
| 1112 | 1112 | } |
| 1113 | 1113 | |
| 1114 | - do_action( 'wpinv_pre_remove_cart_discount', absint( $_GET['discount_id'] ) ); |
|
| 1114 | + do_action('wpinv_pre_remove_cart_discount', absint($_GET['discount_id'])); |
|
| 1115 | 1115 | |
| 1116 | - wpinv_unset_cart_discount( urldecode( $_GET['discount_code'] ) ); |
|
| 1116 | + wpinv_unset_cart_discount(urldecode($_GET['discount_code'])); |
|
| 1117 | 1117 | |
| 1118 | - do_action( 'wpinv_post_remove_cart_discount', absint( $_GET['discount_id'] ) ); |
|
| 1118 | + do_action('wpinv_post_remove_cart_discount', absint($_GET['discount_id'])); |
|
| 1119 | 1119 | |
| 1120 | - wp_redirect( wpinv_get_checkout_uri() ); wpinv_die(); |
|
| 1120 | + wp_redirect(wpinv_get_checkout_uri()); wpinv_die(); |
|
| 1121 | 1121 | } |
| 1122 | -add_action( 'wpinv_remove_cart_discount', 'wpinv_remove_cart_discount' ); |
|
| 1122 | +add_action('wpinv_remove_cart_discount', 'wpinv_remove_cart_discount'); |
|
| 1123 | 1123 | |
| 1124 | -function wpinv_maybe_remove_cart_discount( $cart_key = 0 ) { |
|
| 1124 | +function wpinv_maybe_remove_cart_discount($cart_key = 0) { |
|
| 1125 | 1125 | $discounts = wpinv_get_cart_discounts(); |
| 1126 | 1126 | |
| 1127 | - if ( !$discounts ) { |
|
| 1127 | + if (!$discounts) { |
|
| 1128 | 1128 | return; |
| 1129 | 1129 | } |
| 1130 | 1130 | |
| 1131 | - foreach ( $discounts as $discount ) { |
|
| 1132 | - if ( !wpinv_is_discount_valid( $discount ) ) { |
|
| 1133 | - wpinv_unset_cart_discount( $discount ); |
|
| 1131 | + foreach ($discounts as $discount) { |
|
| 1132 | + if (!wpinv_is_discount_valid($discount)) { |
|
| 1133 | + wpinv_unset_cart_discount($discount); |
|
| 1134 | 1134 | } |
| 1135 | 1135 | } |
| 1136 | 1136 | } |
| 1137 | -add_action( 'wpinv_post_remove_from_cart', 'wpinv_maybe_remove_cart_discount' ); |
|
| 1137 | +add_action('wpinv_post_remove_from_cart', 'wpinv_maybe_remove_cart_discount'); |
|
| 1138 | 1138 | |
| 1139 | 1139 | function wpinv_multiple_discounts_allowed() { |
| 1140 | - $ret = wpinv_get_option( 'allow_multiple_discounts', false ); |
|
| 1141 | - return (bool) apply_filters( 'wpinv_multiple_discounts_allowed', $ret ); |
|
| 1140 | + $ret = wpinv_get_option('allow_multiple_discounts', false); |
|
| 1141 | + return (bool)apply_filters('wpinv_multiple_discounts_allowed', $ret); |
|
| 1142 | 1142 | } |
| 1143 | 1143 | |
| 1144 | 1144 | function wpinv_listen_for_cart_discount() { |
| 1145 | 1145 | global $wpi_session; |
| 1146 | 1146 | |
| 1147 | - if ( empty( $_REQUEST['discount'] ) || is_array( $_REQUEST['discount'] ) ) { |
|
| 1147 | + if (empty($_REQUEST['discount']) || is_array($_REQUEST['discount'])) { |
|
| 1148 | 1148 | return; |
| 1149 | 1149 | } |
| 1150 | 1150 | |
| 1151 | - $code = preg_replace('/[^a-zA-Z0-9-_]+/', '', $_REQUEST['discount'] ); |
|
| 1151 | + $code = preg_replace('/[^a-zA-Z0-9-_]+/', '', $_REQUEST['discount']); |
|
| 1152 | 1152 | |
| 1153 | - $wpi_session->set( 'preset_discount', $code ); |
|
| 1153 | + $wpi_session->set('preset_discount', $code); |
|
| 1154 | 1154 | } |
| 1155 | 1155 | //add_action( 'init', 'wpinv_listen_for_cart_discount', 0 ); |
| 1156 | 1156 | |
| 1157 | 1157 | function wpinv_apply_preset_discount() { |
| 1158 | 1158 | global $wpi_session; |
| 1159 | 1159 | |
| 1160 | - $code = $wpi_session->get( 'preset_discount' ); |
|
| 1160 | + $code = $wpi_session->get('preset_discount'); |
|
| 1161 | 1161 | |
| 1162 | - if ( !$code ) { |
|
| 1162 | + if (!$code) { |
|
| 1163 | 1163 | return; |
| 1164 | 1164 | } |
| 1165 | 1165 | |
| 1166 | - if ( !wpinv_is_discount_valid( $code, '', false ) ) { |
|
| 1166 | + if (!wpinv_is_discount_valid($code, '', false)) { |
|
| 1167 | 1167 | return; |
| 1168 | 1168 | } |
| 1169 | 1169 | |
| 1170 | - $code = apply_filters( 'wpinv_apply_preset_discount', $code ); |
|
| 1170 | + $code = apply_filters('wpinv_apply_preset_discount', $code); |
|
| 1171 | 1171 | |
| 1172 | - wpinv_set_cart_discount( $code ); |
|
| 1172 | + wpinv_set_cart_discount($code); |
|
| 1173 | 1173 | |
| 1174 | - $wpi_session->set( 'preset_discount', null ); |
|
| 1174 | + $wpi_session->set('preset_discount', null); |
|
| 1175 | 1175 | } |
| 1176 | 1176 | //add_action( 'init', 'wpinv_apply_preset_discount', 999 ); |
| 1177 | 1177 | |
| 1178 | -function wpinv_get_discount_label( $code, $echo = true ) { |
|
| 1179 | - $label = wp_sprintf( __( 'Discount%1$s', 'invoicing' ), ( $code != '' && $code != 'none' ? ' (<code>' . $code . '</code>)': '' ) ); |
|
| 1180 | - $label = apply_filters( 'wpinv_get_discount_label', $label, $code ); |
|
| 1178 | +function wpinv_get_discount_label($code, $echo = true) { |
|
| 1179 | + $label = wp_sprintf(__('Discount%1$s', 'invoicing'), ($code != '' && $code != 'none' ? ' (<code>' . $code . '</code>)' : '')); |
|
| 1180 | + $label = apply_filters('wpinv_get_discount_label', $label, $code); |
|
| 1181 | 1181 | |
| 1182 | - if ( $echo ) { |
|
| 1182 | + if ($echo) { |
|
| 1183 | 1183 | echo $label; |
| 1184 | 1184 | } else { |
| 1185 | 1185 | return $label; |
| 1186 | 1186 | } |
| 1187 | 1187 | } |
| 1188 | 1188 | |
| 1189 | -function wpinv_cart_discount_label( $code, $rate, $echo = true ) { |
|
| 1190 | - $label = wp_sprintf( __( '%1$s Discount: %2$s', 'invoicing' ), $rate, $code ); |
|
| 1191 | - $label = apply_filters( 'wpinv_cart_discount_label', $label, $code, $rate ); |
|
| 1189 | +function wpinv_cart_discount_label($code, $rate, $echo = true) { |
|
| 1190 | + $label = wp_sprintf(__('%1$s Discount: %2$s', 'invoicing'), $rate, $code); |
|
| 1191 | + $label = apply_filters('wpinv_cart_discount_label', $label, $code, $rate); |
|
| 1192 | 1192 | |
| 1193 | - if ( $echo ) { |
|
| 1193 | + if ($echo) { |
|
| 1194 | 1194 | echo $label; |
| 1195 | 1195 | } else { |
| 1196 | 1196 | return $label; |
| 1197 | 1197 | } |
| 1198 | 1198 | } |
| 1199 | 1199 | |
| 1200 | -function wpinv_check_delete_discount( $check, $post, $force_delete ) { |
|
| 1201 | - if ( $post->post_type == 'wpi_discount' && wpinv_get_discount_uses( $post->ID ) > 0 ) { |
|
| 1200 | +function wpinv_check_delete_discount($check, $post, $force_delete) { |
|
| 1201 | + if ($post->post_type == 'wpi_discount' && wpinv_get_discount_uses($post->ID) > 0) { |
|
| 1202 | 1202 | return true; |
| 1203 | 1203 | } |
| 1204 | 1204 | |
| 1205 | 1205 | return $check; |
| 1206 | 1206 | } |
| 1207 | -add_filter( 'pre_delete_post', 'wpinv_check_delete_discount', 10, 3 ); |
|
| 1207 | +add_filter('pre_delete_post', 'wpinv_check_delete_discount', 10, 3); |
|
| 1208 | 1208 | |
| 1209 | 1209 | function wpinv_checkout_form_validate_discounts() { |
| 1210 | 1210 | $discounts = wpinv_get_cart_discounts(); |
| 1211 | 1211 | |
| 1212 | - if ( !empty( $discounts ) ) { |
|
| 1212 | + if (!empty($discounts)) { |
|
| 1213 | 1213 | $invalid = false; |
| 1214 | 1214 | |
| 1215 | - foreach ( $discounts as $key => $code ) { |
|
| 1216 | - if ( !wpinv_is_discount_valid( $code, get_current_user_id() ) ) { |
|
| 1215 | + foreach ($discounts as $key => $code) { |
|
| 1216 | + if (!wpinv_is_discount_valid($code, get_current_user_id())) { |
|
| 1217 | 1217 | $invalid = true; |
| 1218 | 1218 | |
| 1219 | - wpinv_unset_cart_discount( $code ); |
|
| 1219 | + wpinv_unset_cart_discount($code); |
|
| 1220 | 1220 | } |
| 1221 | 1221 | } |
| 1222 | 1222 | |
| 1223 | - if ( $invalid ) { |
|
| 1223 | + if ($invalid) { |
|
| 1224 | 1224 | $errors = wpinv_get_errors(); |
| 1225 | - $error = !empty( $errors['wpinv-discount-error'] ) ? $errors['wpinv-discount-error'] . ' ' : ''; |
|
| 1226 | - $error .= __( 'The discount has been removed from cart.', 'invoicing' ); |
|
| 1227 | - wpinv_set_error( 'wpinv-discount-error', $error ); |
|
| 1225 | + $error = !empty($errors['wpinv-discount-error']) ? $errors['wpinv-discount-error'] . ' ' : ''; |
|
| 1226 | + $error .= __('The discount has been removed from cart.', 'invoicing'); |
|
| 1227 | + wpinv_set_error('wpinv-discount-error', $error); |
|
| 1228 | 1228 | |
| 1229 | - wpinv_recalculate_tax( true ); |
|
| 1229 | + wpinv_recalculate_tax(true); |
|
| 1230 | 1230 | } |
| 1231 | 1231 | } |
| 1232 | 1232 | } |
| 1233 | -add_action( 'wpinv_before_checkout_form', 'wpinv_checkout_form_validate_discounts', -10 ); |
|
| 1233 | +add_action('wpinv_before_checkout_form', 'wpinv_checkout_form_validate_discounts', -10); |
|
| 1234 | 1234 | |
| 1235 | 1235 | function wpinv_discount_amount() { |
| 1236 | 1236 | $output = 0.00; |
| 1237 | 1237 | |
| 1238 | - return apply_filters( 'wpinv_discount_amount', $output ); |
|
| 1238 | + return apply_filters('wpinv_discount_amount', $output); |
|
| 1239 | 1239 | } |
| 1240 | 1240 | \ No newline at end of file |
@@ -176,6 +176,9 @@ discard block |
||
| 176 | 176 | return $date_created; |
| 177 | 177 | } |
| 178 | 178 | |
| 179 | +/** |
|
| 180 | + * @return string |
|
| 181 | + */ |
|
| 179 | 182 | function wpinv_get_invoice_date( $invoice_id = 0, $format = '' ) { |
| 180 | 183 | $invoice = new WPInv_Invoice( $invoice_id ); |
| 181 | 184 | |
@@ -1375,6 +1378,9 @@ discard block |
||
| 1375 | 1378 | return $display; |
| 1376 | 1379 | } |
| 1377 | 1380 | |
| 1381 | +/** |
|
| 1382 | + * @return integer |
|
| 1383 | + */ |
|
| 1378 | 1384 | function wpinv_get_invoice_id_by_key( $key ) { |
| 1379 | 1385 | global $wpdb; |
| 1380 | 1386 | |
@@ -215,7 +215,7 @@ discard block |
||
| 215 | 215 | } |
| 216 | 216 | |
| 217 | 217 | function wpinv_get_payment_key( $invoice_id = 0 ) { |
| 218 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
| 218 | + $invoice = new WPInv_Invoice( $invoice_id ); |
|
| 219 | 219 | return $invoice->get_key(); |
| 220 | 220 | } |
| 221 | 221 | |
@@ -731,20 +731,20 @@ discard block |
||
| 731 | 731 | } |
| 732 | 732 | |
| 733 | 733 | function wpinv_checkout_get_cc_info() { |
| 734 | - $cc_info = array(); |
|
| 735 | - $cc_info['card_name'] = isset( $_POST['card_name'] ) ? sanitize_text_field( $_POST['card_name'] ) : ''; |
|
| 736 | - $cc_info['card_number'] = isset( $_POST['card_number'] ) ? sanitize_text_field( $_POST['card_number'] ) : ''; |
|
| 737 | - $cc_info['card_cvc'] = isset( $_POST['card_cvc'] ) ? sanitize_text_field( $_POST['card_cvc'] ) : ''; |
|
| 738 | - $cc_info['card_exp_month'] = isset( $_POST['card_exp_month'] ) ? sanitize_text_field( $_POST['card_exp_month'] ) : ''; |
|
| 739 | - $cc_info['card_exp_year'] = isset( $_POST['card_exp_year'] ) ? sanitize_text_field( $_POST['card_exp_year'] ) : ''; |
|
| 740 | - $cc_info['card_address'] = isset( $_POST['wpinv_address'] ) ? sanitize_text_field( $_POST['wpinv_address'] ) : ''; |
|
| 741 | - $cc_info['card_city'] = isset( $_POST['wpinv_city'] ) ? sanitize_text_field( $_POST['wpinv_city'] ) : ''; |
|
| 742 | - $cc_info['card_state'] = isset( $_POST['wpinv_state'] ) ? sanitize_text_field( $_POST['wpinv_state'] ) : ''; |
|
| 743 | - $cc_info['card_country'] = isset( $_POST['wpinv_country'] ) ? sanitize_text_field( $_POST['wpinv_country'] ) : ''; |
|
| 744 | - $cc_info['card_zip'] = isset( $_POST['wpinv_zip'] ) ? sanitize_text_field( $_POST['wpinv_zip'] ) : ''; |
|
| 745 | - |
|
| 746 | - // Return cc info |
|
| 747 | - return $cc_info; |
|
| 734 | + $cc_info = array(); |
|
| 735 | + $cc_info['card_name'] = isset( $_POST['card_name'] ) ? sanitize_text_field( $_POST['card_name'] ) : ''; |
|
| 736 | + $cc_info['card_number'] = isset( $_POST['card_number'] ) ? sanitize_text_field( $_POST['card_number'] ) : ''; |
|
| 737 | + $cc_info['card_cvc'] = isset( $_POST['card_cvc'] ) ? sanitize_text_field( $_POST['card_cvc'] ) : ''; |
|
| 738 | + $cc_info['card_exp_month'] = isset( $_POST['card_exp_month'] ) ? sanitize_text_field( $_POST['card_exp_month'] ) : ''; |
|
| 739 | + $cc_info['card_exp_year'] = isset( $_POST['card_exp_year'] ) ? sanitize_text_field( $_POST['card_exp_year'] ) : ''; |
|
| 740 | + $cc_info['card_address'] = isset( $_POST['wpinv_address'] ) ? sanitize_text_field( $_POST['wpinv_address'] ) : ''; |
|
| 741 | + $cc_info['card_city'] = isset( $_POST['wpinv_city'] ) ? sanitize_text_field( $_POST['wpinv_city'] ) : ''; |
|
| 742 | + $cc_info['card_state'] = isset( $_POST['wpinv_state'] ) ? sanitize_text_field( $_POST['wpinv_state'] ) : ''; |
|
| 743 | + $cc_info['card_country'] = isset( $_POST['wpinv_country'] ) ? sanitize_text_field( $_POST['wpinv_country'] ) : ''; |
|
| 744 | + $cc_info['card_zip'] = isset( $_POST['wpinv_zip'] ) ? sanitize_text_field( $_POST['wpinv_zip'] ) : ''; |
|
| 745 | + |
|
| 746 | + // Return cc info |
|
| 747 | + return $cc_info; |
|
| 748 | 748 | } |
| 749 | 749 | |
| 750 | 750 | function wpinv_checkout_validate_cc_zip( $zip = 0, $country_code = '' ) { |
@@ -942,7 +942,7 @@ discard block |
||
| 942 | 942 | $required_fields = wpinv_checkout_required_fields(); |
| 943 | 943 | |
| 944 | 944 | // Loop through required fields and show error messages |
| 945 | - if ( !empty( $required_fields ) ) { |
|
| 945 | + if ( !empty( $required_fields ) ) { |
|
| 946 | 946 | foreach ( $required_fields as $field_name => $value ) { |
| 947 | 947 | if ( in_array( $value, $required_fields ) && empty( $_POST[ 'wpinv_' . $field_name ] ) ) { |
| 948 | 948 | wpinv_set_error( $value['error_id'], $value['error_message'] ); |
@@ -1025,7 +1025,7 @@ discard block |
||
| 1025 | 1025 | } |
| 1026 | 1026 | |
| 1027 | 1027 | function wpinv_get_checkout_session() { |
| 1028 | - global $wpi_session; |
|
| 1028 | + global $wpi_session; |
|
| 1029 | 1029 | |
| 1030 | 1030 | return $wpi_session->get( 'wpinv_checkout' ); |
| 1031 | 1031 | } |
@@ -1376,47 +1376,47 @@ discard block |
||
| 1376 | 1376 | } |
| 1377 | 1377 | |
| 1378 | 1378 | function wpinv_get_invoice_id_by_key( $key ) { |
| 1379 | - global $wpdb; |
|
| 1379 | + global $wpdb; |
|
| 1380 | 1380 | |
| 1381 | - $invoice_id = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_key' AND meta_value = %s LIMIT 1", $key ) ); |
|
| 1381 | + $invoice_id = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_key' AND meta_value = %s LIMIT 1", $key ) ); |
|
| 1382 | 1382 | |
| 1383 | - if ( $invoice_id != NULL ) |
|
| 1384 | - return $invoice_id; |
|
| 1383 | + if ( $invoice_id != NULL ) |
|
| 1384 | + return $invoice_id; |
|
| 1385 | 1385 | |
| 1386 | - return 0; |
|
| 1386 | + return 0; |
|
| 1387 | 1387 | } |
| 1388 | 1388 | |
| 1389 | 1389 | function wpinv_can_view_receipt( $invoice_key = '' ) { |
| 1390 | - $return = false; |
|
| 1390 | + $return = false; |
|
| 1391 | 1391 | |
| 1392 | - if ( empty( $invoice_key ) ) { |
|
| 1393 | - return $return; |
|
| 1394 | - } |
|
| 1392 | + if ( empty( $invoice_key ) ) { |
|
| 1393 | + return $return; |
|
| 1394 | + } |
|
| 1395 | 1395 | |
| 1396 | - global $wpinv_receipt_args; |
|
| 1396 | + global $wpinv_receipt_args; |
|
| 1397 | 1397 | |
| 1398 | - $wpinv_receipt_args['id'] = wpinv_get_invoice_id_by_key( $invoice_key ); |
|
| 1399 | - if ( isset( $_GET['invoice-id'] ) ) { |
|
| 1400 | - $wpinv_receipt_args['id'] = $invoice_key == wpinv_get_payment_key( (int)$_GET['invoice-id'] ) ? (int)$_GET['invoice-id'] : 0; |
|
| 1401 | - } |
|
| 1398 | + $wpinv_receipt_args['id'] = wpinv_get_invoice_id_by_key( $invoice_key ); |
|
| 1399 | + if ( isset( $_GET['invoice-id'] ) ) { |
|
| 1400 | + $wpinv_receipt_args['id'] = $invoice_key == wpinv_get_payment_key( (int)$_GET['invoice-id'] ) ? (int)$_GET['invoice-id'] : 0; |
|
| 1401 | + } |
|
| 1402 | 1402 | |
| 1403 | - $user_id = (int) wpinv_get_user_id( $wpinv_receipt_args['id'] ); |
|
| 1403 | + $user_id = (int) wpinv_get_user_id( $wpinv_receipt_args['id'] ); |
|
| 1404 | 1404 | $invoice_meta = wpinv_get_invoice_meta( $wpinv_receipt_args['id'] ); |
| 1405 | 1405 | |
| 1406 | - if ( is_user_logged_in() ) { |
|
| 1407 | - if ( $user_id === (int) get_current_user_id() ) { |
|
| 1408 | - $return = true; |
|
| 1409 | - } |
|
| 1410 | - } |
|
| 1406 | + if ( is_user_logged_in() ) { |
|
| 1407 | + if ( $user_id === (int) get_current_user_id() ) { |
|
| 1408 | + $return = true; |
|
| 1409 | + } |
|
| 1410 | + } |
|
| 1411 | 1411 | |
| 1412 | - $session = wpinv_get_checkout_session(); |
|
| 1413 | - if ( ! empty( $session ) && ! is_user_logged_in() ) { |
|
| 1414 | - if ( $session['invoice_key'] === $invoice_meta['key'] ) { |
|
| 1415 | - $return = true; |
|
| 1416 | - } |
|
| 1417 | - } |
|
| 1412 | + $session = wpinv_get_checkout_session(); |
|
| 1413 | + if ( ! empty( $session ) && ! is_user_logged_in() ) { |
|
| 1414 | + if ( $session['invoice_key'] === $invoice_meta['key'] ) { |
|
| 1415 | + $return = true; |
|
| 1416 | + } |
|
| 1417 | + } |
|
| 1418 | 1418 | |
| 1419 | - return (bool) apply_filters( 'wpinv_can_view_receipt', $return, $invoice_key ); |
|
| 1419 | + return (bool) apply_filters( 'wpinv_can_view_receipt', $return, $invoice_key ); |
|
| 1420 | 1420 | } |
| 1421 | 1421 | |
| 1422 | 1422 | function wpinv_pay_for_invoice() { |
@@ -311,8 +311,9 @@ discard block |
||
| 311 | 311 | |
| 312 | 312 | $invoice_id = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_transaction_id' AND meta_value = %s LIMIT 1", $key ) ); |
| 313 | 313 | |
| 314 | - if ( $invoice_id != NULL ) |
|
| 315 | - return $invoice_id; |
|
| 314 | + if ( $invoice_id != NULL ) { |
|
| 315 | + return $invoice_id; |
|
| 316 | + } |
|
| 316 | 317 | |
| 317 | 318 | return 0; |
| 318 | 319 | } |
@@ -992,8 +993,9 @@ discard block |
||
| 992 | 993 | function wpinv_checkout_validate_cc_zip( $zip = 0, $country_code = '' ) { |
| 993 | 994 | $ret = false; |
| 994 | 995 | |
| 995 | - if ( empty( $zip ) || empty( $country_code ) ) |
|
| 996 | - return $ret; |
|
| 996 | + if ( empty( $zip ) || empty( $country_code ) ) { |
|
| 997 | + return $ret; |
|
| 998 | + } |
|
| 997 | 999 | |
| 998 | 1000 | $country_code = strtoupper( $country_code ); |
| 999 | 1001 | |
@@ -1155,8 +1157,9 @@ discard block |
||
| 1155 | 1157 | "ZM" => "\d{5}" |
| 1156 | 1158 | ); |
| 1157 | 1159 | |
| 1158 | - if ( ! isset ( $zip_regex[ $country_code ] ) || preg_match( "/" . $zip_regex[ $country_code ] . "/i", $zip ) ) |
|
| 1159 | - $ret = true; |
|
| 1160 | + if ( ! isset ( $zip_regex[ $country_code ] ) || preg_match( "/" . $zip_regex[ $country_code ] . "/i", $zip ) ) { |
|
| 1161 | + $ret = true; |
|
| 1162 | + } |
|
| 1160 | 1163 | |
| 1161 | 1164 | return apply_filters( 'wpinv_is_zip_valid', $ret, $zip, $country_code ); |
| 1162 | 1165 | } |
@@ -1482,14 +1485,15 @@ discard block |
||
| 1482 | 1485 | |
| 1483 | 1486 | $wpinv_cpt = isset( $_REQUEST[ 'wpinv-cpt' ] ) ? $_REQUEST[ 'wpinv-cpt' ] : ''; |
| 1484 | 1487 | |
| 1485 | - if ( get_query_var( 'paged' ) && 'wpi_invoice' == $wpinv_cpt ) |
|
| 1486 | - $args['page'] = get_query_var('paged'); |
|
| 1487 | - else if ( get_query_var( 'page' ) && 'wpi_invoice' == $wpinv_cpt ) |
|
| 1488 | - $args['page'] = get_query_var( 'page' ); |
|
| 1489 | - else if ( !empty( $args[ 'page' ] ) ) |
|
| 1490 | - $args['page'] = $args[ 'page' ]; |
|
| 1491 | - else |
|
| 1492 | - $args['page'] = 1; |
|
| 1488 | + if ( get_query_var( 'paged' ) && 'wpi_invoice' == $wpinv_cpt ) { |
|
| 1489 | + $args['page'] = get_query_var('paged'); |
|
| 1490 | + } else if ( get_query_var( 'page' ) && 'wpi_invoice' == $wpinv_cpt ) { |
|
| 1491 | + $args['page'] = get_query_var( 'page' ); |
|
| 1492 | + } else if ( !empty( $args[ 'page' ] ) ) { |
|
| 1493 | + $args['page'] = $args[ 'page' ]; |
|
| 1494 | + } else { |
|
| 1495 | + $args['page'] = 1; |
|
| 1496 | + } |
|
| 1493 | 1497 | |
| 1494 | 1498 | /** |
| 1495 | 1499 | * Generate WP_Query args. This logic will change if orders are moved to |
@@ -1624,8 +1628,9 @@ discard block |
||
| 1624 | 1628 | |
| 1625 | 1629 | $invoice_id = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_key' AND meta_value = %s LIMIT 1", $key ) ); |
| 1626 | 1630 | |
| 1627 | - if ( $invoice_id != NULL ) |
|
| 1628 | - return $invoice_id; |
|
| 1631 | + if ( $invoice_id != NULL ) { |
|
| 1632 | + return $invoice_id; |
|
| 1633 | + } |
|
| 1629 | 1634 | |
| 1630 | 1635 | return 0; |
| 1631 | 1636 | } |
@@ -7,40 +7,40 @@ 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_invoice_cart_id() { |
| 15 | 15 | $wpinv_checkout = wpinv_get_checkout_session(); |
| 16 | 16 | |
| 17 | - if ( !empty( $wpinv_checkout['invoice_id'] ) ) { |
|
| 17 | + if (!empty($wpinv_checkout['invoice_id'])) { |
|
| 18 | 18 | return $wpinv_checkout['invoice_id']; |
| 19 | 19 | } |
| 20 | 20 | |
| 21 | 21 | return NULL; |
| 22 | 22 | } |
| 23 | 23 | |
| 24 | -function wpinv_insert_invoice( $invoice_data = array(), $wp_error = false ) { |
|
| 25 | - if ( empty( $invoice_data ) ) { |
|
| 24 | +function wpinv_insert_invoice($invoice_data = array(), $wp_error = false) { |
|
| 25 | + if (empty($invoice_data)) { |
|
| 26 | 26 | return false; |
| 27 | 27 | } |
| 28 | 28 | |
| 29 | - if ( !( !empty( $invoice_data['cart_details'] ) && is_array( $invoice_data['cart_details'] ) ) ) { |
|
| 30 | - return $wp_error ? new WP_Error( 'wpinv_invalid_items', __( 'Invoice must have atleast on item.', 'invoicing' ) ) : 0; |
|
| 29 | + if (!(!empty($invoice_data['cart_details']) && is_array($invoice_data['cart_details']))) { |
|
| 30 | + return $wp_error ? new WP_Error('wpinv_invalid_items', __('Invoice must have atleast on item.', 'invoicing')) : 0; |
|
| 31 | 31 | } |
| 32 | 32 | |
| 33 | - if ( empty( $invoice_data['user_id'] ) ) { |
|
| 33 | + if (empty($invoice_data['user_id'])) { |
|
| 34 | 34 | $invoice_data['user_id'] = get_current_user_id(); |
| 35 | 35 | } |
| 36 | 36 | |
| 37 | - $invoice_data['invoice_id'] = !empty( $invoice_data['invoice_id'] ) ? (int)$invoice_data['invoice_id'] : 0; |
|
| 37 | + $invoice_data['invoice_id'] = !empty($invoice_data['invoice_id']) ? (int)$invoice_data['invoice_id'] : 0; |
|
| 38 | 38 | |
| 39 | - if ( empty( $invoice_data['status'] ) ) { |
|
| 39 | + if (empty($invoice_data['status'])) { |
|
| 40 | 40 | $invoice_data['status'] = 'pending'; |
| 41 | 41 | } |
| 42 | 42 | |
| 43 | - if ( empty( $invoice_data['ip'] ) ) { |
|
| 43 | + if (empty($invoice_data['ip'])) { |
|
| 44 | 44 | $invoice_data['ip'] = wpinv_get_ip(); |
| 45 | 45 | } |
| 46 | 46 | |
@@ -51,12 +51,12 @@ discard block |
||
| 51 | 51 | 'status' => $invoice_data['status'], |
| 52 | 52 | ); |
| 53 | 53 | |
| 54 | - $invoice = wpinv_create_invoice( $default_args, $invoice_data, true ); |
|
| 55 | - if ( is_wp_error( $invoice ) ) { |
|
| 54 | + $invoice = wpinv_create_invoice($default_args, $invoice_data, true); |
|
| 55 | + if (is_wp_error($invoice)) { |
|
| 56 | 56 | return $wp_error ? $invoice : 0; |
| 57 | 57 | } |
| 58 | 58 | |
| 59 | - if ( empty( $invoice_data['invoice_id'] ) ) { |
|
| 59 | + if (empty($invoice_data['invoice_id'])) { |
|
| 60 | 60 | //$invoice->add_note( wp_sprintf( __( 'Invoice is created with status %s.', 'invoicing' ), wpinv_status_nicename( $invoice->status ) ) ); |
| 61 | 61 | } |
| 62 | 62 | |
@@ -79,24 +79,24 @@ discard block |
||
| 79 | 79 | 'discount' => array(), |
| 80 | 80 | ); |
| 81 | 81 | |
| 82 | - if ( $user_id = (int)$invoice->get_user_id() ) { |
|
| 83 | - if ( $user_address = wpinv_get_user_address( $user_id ) ) { |
|
| 84 | - $default_user_info = wp_parse_args( $user_address, $default_user_info ); |
|
| 82 | + if ($user_id = (int)$invoice->get_user_id()) { |
|
| 83 | + if ($user_address = wpinv_get_user_address($user_id)) { |
|
| 84 | + $default_user_info = wp_parse_args($user_address, $default_user_info); |
|
| 85 | 85 | } |
| 86 | 86 | } |
| 87 | 87 | |
| 88 | - if ( empty( $invoice_data['user_info'] ) ) { |
|
| 88 | + if (empty($invoice_data['user_info'])) { |
|
| 89 | 89 | $invoice_data['user_info'] = array(); |
| 90 | 90 | } |
| 91 | 91 | |
| 92 | - $user_info = wp_parse_args( $invoice_data['user_info'], $default_user_info ); |
|
| 92 | + $user_info = wp_parse_args($invoice_data['user_info'], $default_user_info); |
|
| 93 | 93 | |
| 94 | - if ( empty( $user_info['first_name'] ) ) { |
|
| 94 | + if (empty($user_info['first_name'])) { |
|
| 95 | 95 | $user_info['first_name'] = $default_user_info['first_name']; |
| 96 | 96 | $user_info['last_name'] = $default_user_info['last_name']; |
| 97 | 97 | } |
| 98 | 98 | |
| 99 | - if ( empty( $user_info['country'] ) ) { |
|
| 99 | + if (empty($user_info['country'])) { |
|
| 100 | 100 | $user_info['country'] = $default_user_info['country']; |
| 101 | 101 | $user_info['state'] = $default_user_info['state']; |
| 102 | 102 | $user_info['city'] = $default_user_info['city']; |
@@ -105,13 +105,13 @@ discard block |
||
| 105 | 105 | $user_info['phone'] = $default_user_info['phone']; |
| 106 | 106 | } |
| 107 | 107 | |
| 108 | - if ( !empty( $user_info['discount'] ) && !is_array( $user_info['discount'] ) ) { |
|
| 108 | + if (!empty($user_info['discount']) && !is_array($user_info['discount'])) { |
|
| 109 | 109 | $user_info['discount'] = (array)$user_info['discount']; |
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | // Payment details |
| 113 | 113 | $payment_details = array(); |
| 114 | - if ( !empty( $invoice_data['payment_details'] ) ) { |
|
| 114 | + if (!empty($invoice_data['payment_details'])) { |
|
| 115 | 115 | $default_payment_details = array( |
| 116 | 116 | 'gateway' => 'manual', |
| 117 | 117 | 'gateway_title' => '', |
@@ -119,59 +119,59 @@ discard block |
||
| 119 | 119 | 'transaction_id' => '', |
| 120 | 120 | ); |
| 121 | 121 | |
| 122 | - $payment_details = wp_parse_args( $invoice_data['payment_details'], $default_payment_details ); |
|
| 122 | + $payment_details = wp_parse_args($invoice_data['payment_details'], $default_payment_details); |
|
| 123 | 123 | |
| 124 | - if ( empty( $payment_details['gateway'] ) ) { |
|
| 124 | + if (empty($payment_details['gateway'])) { |
|
| 125 | 125 | $payment_details['gateway'] = 'manual'; |
| 126 | 126 | } |
| 127 | 127 | |
| 128 | - if ( empty( $payment_details['currency'] ) ) { |
|
| 128 | + if (empty($payment_details['currency'])) { |
|
| 129 | 129 | $payment_details['currency'] = geodir_get_currency_type(); |
| 130 | 130 | } |
| 131 | 131 | |
| 132 | - if ( empty( $payment_details['gateway_title'] ) ) { |
|
| 133 | - $payment_details['gateway_title'] = wpinv_get_gateway_checkout_label( $payment_details['gateway'] ); |
|
| 132 | + if (empty($payment_details['gateway_title'])) { |
|
| 133 | + $payment_details['gateway_title'] = wpinv_get_gateway_checkout_label($payment_details['gateway']); |
|
| 134 | 134 | } |
| 135 | 135 | } |
| 136 | 136 | |
| 137 | - $invoice->set( 'status', ( !empty( $invoice_data['status'] ) ? $invoice_data['status'] : 'pending' ) ); |
|
| 138 | - |
|
| 139 | - if ( !empty( $payment_details ) ) { |
|
| 140 | - $invoice->set( 'currency', $payment_details['currency'] ); |
|
| 141 | - $invoice->set( 'gateway', $payment_details['gateway'] ); |
|
| 142 | - $invoice->set( 'gateway_title', $payment_details['gateway_title'] ); |
|
| 143 | - $invoice->set( 'transaction_id', $payment_details['transaction_id'] ); |
|
| 144 | - } |
|
| 145 | - |
|
| 146 | - $invoice->set( 'user_info', $user_info ); |
|
| 147 | - $invoice->set( 'first_name', $user_info['first_name'] ); |
|
| 148 | - $invoice->set( 'last_name', $user_info['last_name'] ); |
|
| 149 | - $invoice->set( 'address', $user_info['address'] ); |
|
| 150 | - $invoice->set( 'company', $user_info['company'] ); |
|
| 151 | - $invoice->set( 'vat_number', $user_info['vat_number'] ); |
|
| 152 | - $invoice->set( 'phone', $user_info['phone'] ); |
|
| 153 | - $invoice->set( 'city', $user_info['city'] ); |
|
| 154 | - $invoice->set( 'country', $user_info['country'] ); |
|
| 155 | - $invoice->set( 'state', $user_info['state'] ); |
|
| 156 | - $invoice->set( 'zip', $user_info['zip'] ); |
|
| 157 | - $invoice->set( 'discounts', $user_info['discount'] ); |
|
| 158 | - $invoice->set( 'ip', ( !empty( $invoice_data['ip'] ) ? $invoice_data['ip'] : wpinv_get_ip() ) ); |
|
| 159 | - if ( !empty( $invoice_data['invoice_key'] ) ) { |
|
| 160 | - $invoice->set( 'key', $invoice_data['invoice_key'] ); |
|
| 161 | - } |
|
| 162 | - $invoice->set( 'mode', ( wpinv_is_test_mode() ? 'test' : 'live' ) ); |
|
| 163 | - $invoice->set( 'parent_invoice', ( !empty( $invoice_data['parent'] ) ? absint( $invoice_data['parent'] ) : '' ) ); |
|
| 164 | - |
|
| 165 | - if ( !empty( $invoice_data['cart_details'] ) && is_array( $invoice_data['cart_details'] ) ) { |
|
| 166 | - foreach ( $invoice_data['cart_details'] as $key => $item ) { |
|
| 167 | - $item_id = !empty( $item['id'] ) ? $item['id'] : 0; |
|
| 168 | - $quantity = !empty( $item['quantity'] ) ? $item['quantity'] : 1; |
|
| 169 | - $name = !empty( $item['name'] ) ? $item['name'] : ''; |
|
| 170 | - $item_price = isset( $item['item_price'] ) ? $item['item_price'] : ''; |
|
| 137 | + $invoice->set('status', (!empty($invoice_data['status']) ? $invoice_data['status'] : 'pending')); |
|
| 138 | + |
|
| 139 | + if (!empty($payment_details)) { |
|
| 140 | + $invoice->set('currency', $payment_details['currency']); |
|
| 141 | + $invoice->set('gateway', $payment_details['gateway']); |
|
| 142 | + $invoice->set('gateway_title', $payment_details['gateway_title']); |
|
| 143 | + $invoice->set('transaction_id', $payment_details['transaction_id']); |
|
| 144 | + } |
|
| 145 | + |
|
| 146 | + $invoice->set('user_info', $user_info); |
|
| 147 | + $invoice->set('first_name', $user_info['first_name']); |
|
| 148 | + $invoice->set('last_name', $user_info['last_name']); |
|
| 149 | + $invoice->set('address', $user_info['address']); |
|
| 150 | + $invoice->set('company', $user_info['company']); |
|
| 151 | + $invoice->set('vat_number', $user_info['vat_number']); |
|
| 152 | + $invoice->set('phone', $user_info['phone']); |
|
| 153 | + $invoice->set('city', $user_info['city']); |
|
| 154 | + $invoice->set('country', $user_info['country']); |
|
| 155 | + $invoice->set('state', $user_info['state']); |
|
| 156 | + $invoice->set('zip', $user_info['zip']); |
|
| 157 | + $invoice->set('discounts', $user_info['discount']); |
|
| 158 | + $invoice->set('ip', (!empty($invoice_data['ip']) ? $invoice_data['ip'] : wpinv_get_ip())); |
|
| 159 | + if (!empty($invoice_data['invoice_key'])) { |
|
| 160 | + $invoice->set('key', $invoice_data['invoice_key']); |
|
| 161 | + } |
|
| 162 | + $invoice->set('mode', (wpinv_is_test_mode() ? 'test' : 'live')); |
|
| 163 | + $invoice->set('parent_invoice', (!empty($invoice_data['parent']) ? absint($invoice_data['parent']) : '')); |
|
| 164 | + |
|
| 165 | + if (!empty($invoice_data['cart_details']) && is_array($invoice_data['cart_details'])) { |
|
| 166 | + foreach ($invoice_data['cart_details'] as $key => $item) { |
|
| 167 | + $item_id = !empty($item['id']) ? $item['id'] : 0; |
|
| 168 | + $quantity = !empty($item['quantity']) ? $item['quantity'] : 1; |
|
| 169 | + $name = !empty($item['name']) ? $item['name'] : ''; |
|
| 170 | + $item_price = isset($item['item_price']) ? $item['item_price'] : ''; |
|
| 171 | 171 | |
| 172 | - $post_item = new WPInv_Item( $item_id ); |
|
| 173 | - if ( !empty( $post_item ) ) { |
|
| 174 | - $name = !empty( $name ) ? $name : $post_item->get_name(); |
|
| 172 | + $post_item = new WPInv_Item($item_id); |
|
| 173 | + if (!empty($post_item)) { |
|
| 174 | + $name = !empty($name) ? $name : $post_item->get_name(); |
|
| 175 | 175 | $item_price = $item_price !== '' ? $item_price : $post_item->get_price(); |
| 176 | 176 | } else { |
| 177 | 177 | continue; |
@@ -181,495 +181,495 @@ discard block |
||
| 181 | 181 | 'name' => $name, |
| 182 | 182 | 'quantity' => $quantity, |
| 183 | 183 | 'item_price' => $item_price, |
| 184 | - 'custom_price' => isset( $item['custom_price'] ) ? $item['custom_price'] : '', |
|
| 185 | - 'tax' => !empty( $item['tax'] ) ? $item['tax'] : 0.00, |
|
| 186 | - 'discount' => isset( $item['discount'] ) ? $item['discount'] : 0, |
|
| 187 | - 'meta' => isset( $item['meta'] ) ? $item['meta'] : array(), |
|
| 188 | - 'fees' => isset( $item['fees'] ) ? $item['fees'] : array(), |
|
| 184 | + 'custom_price' => isset($item['custom_price']) ? $item['custom_price'] : '', |
|
| 185 | + 'tax' => !empty($item['tax']) ? $item['tax'] : 0.00, |
|
| 186 | + 'discount' => isset($item['discount']) ? $item['discount'] : 0, |
|
| 187 | + 'meta' => isset($item['meta']) ? $item['meta'] : array(), |
|
| 188 | + 'fees' => isset($item['fees']) ? $item['fees'] : array(), |
|
| 189 | 189 | ); |
| 190 | 190 | |
| 191 | - $invoice->add_item( $item_id, $args ); |
|
| 191 | + $invoice->add_item($item_id, $args); |
|
| 192 | 192 | } |
| 193 | 193 | } |
| 194 | 194 | |
| 195 | - $invoice->increase_tax( wpinv_get_cart_fee_tax() ); |
|
| 195 | + $invoice->increase_tax(wpinv_get_cart_fee_tax()); |
|
| 196 | 196 | |
| 197 | - if ( isset( $invoice_data['post_date'] ) ) { |
|
| 198 | - $invoice->set( 'date', $invoice_data['post_date'] ); |
|
| 197 | + if (isset($invoice_data['post_date'])) { |
|
| 198 | + $invoice->set('date', $invoice_data['post_date']); |
|
| 199 | 199 | } |
| 200 | 200 | |
| 201 | 201 | // Invoice due date |
| 202 | - if ( isset( $invoice_data['due_date'] ) ) { |
|
| 203 | - $invoice->set( 'due_date', $invoice_data['due_date'] ); |
|
| 202 | + if (isset($invoice_data['due_date'])) { |
|
| 203 | + $invoice->set('due_date', $invoice_data['due_date']); |
|
| 204 | 204 | } |
| 205 | 205 | |
| 206 | 206 | $invoice->save(); |
| 207 | 207 | |
| 208 | 208 | // Add notes |
| 209 | - if ( !empty( $invoice_data['private_note'] ) ) { |
|
| 210 | - $invoice->add_note( $invoice_data['private_note'] ); |
|
| 209 | + if (!empty($invoice_data['private_note'])) { |
|
| 210 | + $invoice->add_note($invoice_data['private_note']); |
|
| 211 | 211 | } |
| 212 | - if ( !empty( $invoice_data['user_note'] ) ) { |
|
| 213 | - $invoice->add_note( $invoice_data['user_note'], true ); |
|
| 212 | + if (!empty($invoice_data['user_note'])) { |
|
| 213 | + $invoice->add_note($invoice_data['user_note'], true); |
|
| 214 | 214 | } |
| 215 | 215 | |
| 216 | - do_action( 'wpinv_insert_invoice', $invoice->ID, $invoice_data ); |
|
| 216 | + do_action('wpinv_insert_invoice', $invoice->ID, $invoice_data); |
|
| 217 | 217 | |
| 218 | - if ( ! empty( $invoice->ID ) ) { |
|
| 218 | + if (!empty($invoice->ID)) { |
|
| 219 | 219 | global $wpi_userID, $wpinv_ip_address_country; |
| 220 | 220 | |
| 221 | 221 | $checkout_session = wpinv_get_checkout_session(); |
| 222 | 222 | |
| 223 | 223 | $data_session = array(); |
| 224 | 224 | $data_session['invoice_id'] = $invoice->ID; |
| 225 | - $data_session['cart_discounts'] = $invoice->get_discounts( true ); |
|
| 225 | + $data_session['cart_discounts'] = $invoice->get_discounts(true); |
|
| 226 | 226 | |
| 227 | - wpinv_set_checkout_session( $data_session ); |
|
| 227 | + wpinv_set_checkout_session($data_session); |
|
| 228 | 228 | |
| 229 | 229 | $wpi_userID = (int)$invoice->get_user_id(); |
| 230 | 230 | |
| 231 | - $_POST['country'] = !empty( $invoice->country ) ? $invoice->country : wpinv_get_default_country(); |
|
| 231 | + $_POST['country'] = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country(); |
|
| 232 | 232 | $_POST['state'] = $invoice->state; |
| 233 | 233 | |
| 234 | - $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) ); |
|
| 235 | - $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) ); |
|
| 234 | + $invoice->set('country', sanitize_text_field($_POST['country'])); |
|
| 235 | + $invoice->set('state', sanitize_text_field($_POST['state'])); |
|
| 236 | 236 | |
| 237 | 237 | $wpinv_ip_address_country = $invoice->country; |
| 238 | 238 | |
| 239 | - $invoice = $invoice->recalculate_totals( true ); |
|
| 239 | + $invoice = $invoice->recalculate_totals(true); |
|
| 240 | 240 | |
| 241 | - wpinv_set_checkout_session( $checkout_session ); |
|
| 241 | + wpinv_set_checkout_session($checkout_session); |
|
| 242 | 242 | |
| 243 | 243 | return $invoice; |
| 244 | 244 | } |
| 245 | 245 | |
| 246 | - if ( $wp_error ) { |
|
| 247 | - if ( is_wp_error( $invoice ) ) { |
|
| 246 | + if ($wp_error) { |
|
| 247 | + if (is_wp_error($invoice)) { |
|
| 248 | 248 | return $invoice; |
| 249 | 249 | } else { |
| 250 | - return new WP_Error( 'wpinv_insert_invoice_error', __( 'Error in insert invoice.', 'invoicing' ) ); |
|
| 250 | + return new WP_Error('wpinv_insert_invoice_error', __('Error in insert invoice.', 'invoicing')); |
|
| 251 | 251 | } |
| 252 | 252 | } else { |
| 253 | 253 | return 0; |
| 254 | 254 | } |
| 255 | 255 | } |
| 256 | 256 | |
| 257 | -function wpinv_get_invoice( $invoice_id = 0, $cart = false ) { |
|
| 258 | - if ( $cart && empty( $invoice_id ) ) { |
|
| 257 | +function wpinv_get_invoice($invoice_id = 0, $cart = false) { |
|
| 258 | + if ($cart && empty($invoice_id)) { |
|
| 259 | 259 | $invoice_id = (int)wpinv_get_invoice_cart_id(); |
| 260 | 260 | } |
| 261 | 261 | |
| 262 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
| 262 | + $invoice = new WPInv_Invoice($invoice_id); |
|
| 263 | 263 | return $invoice; |
| 264 | 264 | } |
| 265 | 265 | |
| 266 | -function wpinv_get_invoice_cart( $invoice_id = 0 ) { |
|
| 267 | - return wpinv_get_invoice( $invoice_id, true ); |
|
| 266 | +function wpinv_get_invoice_cart($invoice_id = 0) { |
|
| 267 | + return wpinv_get_invoice($invoice_id, true); |
|
| 268 | 268 | } |
| 269 | 269 | |
| 270 | -function wpinv_get_invoice_description( $invoice_id = 0 ) { |
|
| 271 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
| 270 | +function wpinv_get_invoice_description($invoice_id = 0) { |
|
| 271 | + $invoice = new WPInv_Invoice($invoice_id); |
|
| 272 | 272 | return $invoice->get_description(); |
| 273 | 273 | } |
| 274 | 274 | |
| 275 | -function wpinv_get_invoice_currency_code( $invoice_id = 0 ) { |
|
| 276 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
| 275 | +function wpinv_get_invoice_currency_code($invoice_id = 0) { |
|
| 276 | + $invoice = new WPInv_Invoice($invoice_id); |
|
| 277 | 277 | return $invoice->get_currency(); |
| 278 | 278 | } |
| 279 | 279 | |
| 280 | -function wpinv_get_payment_user_email( $invoice_id ) { |
|
| 281 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
| 280 | +function wpinv_get_payment_user_email($invoice_id) { |
|
| 281 | + $invoice = new WPInv_Invoice($invoice_id); |
|
| 282 | 282 | return $invoice->get_email(); |
| 283 | 283 | } |
| 284 | 284 | |
| 285 | -function wpinv_get_user_id( $invoice_id ) { |
|
| 286 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
| 285 | +function wpinv_get_user_id($invoice_id) { |
|
| 286 | + $invoice = new WPInv_Invoice($invoice_id); |
|
| 287 | 287 | return $invoice->get_user_id(); |
| 288 | 288 | } |
| 289 | 289 | |
| 290 | -function wpinv_get_invoice_status( $invoice_id, $return_label = false ) { |
|
| 291 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
| 290 | +function wpinv_get_invoice_status($invoice_id, $return_label = false) { |
|
| 291 | + $invoice = new WPInv_Invoice($invoice_id); |
|
| 292 | 292 | |
| 293 | - return $invoice->get_status( $return_label ); |
|
| 293 | + return $invoice->get_status($return_label); |
|
| 294 | 294 | } |
| 295 | 295 | |
| 296 | -function wpinv_get_payment_gateway( $invoice_id, $return_label = false ) { |
|
| 297 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
| 296 | +function wpinv_get_payment_gateway($invoice_id, $return_label = false) { |
|
| 297 | + $invoice = new WPInv_Invoice($invoice_id); |
|
| 298 | 298 | |
| 299 | - return $invoice->get_gateway( $return_label ); |
|
| 299 | + return $invoice->get_gateway($return_label); |
|
| 300 | 300 | } |
| 301 | 301 | |
| 302 | -function wpinv_get_payment_gateway_name( $invoice_id ) { |
|
| 303 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
| 302 | +function wpinv_get_payment_gateway_name($invoice_id) { |
|
| 303 | + $invoice = new WPInv_Invoice($invoice_id); |
|
| 304 | 304 | |
| 305 | 305 | return $invoice->get_gateway_title(); |
| 306 | 306 | } |
| 307 | 307 | |
| 308 | -function wpinv_get_payment_transaction_id( $invoice_id ) { |
|
| 309 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
| 308 | +function wpinv_get_payment_transaction_id($invoice_id) { |
|
| 309 | + $invoice = new WPInv_Invoice($invoice_id); |
|
| 310 | 310 | |
| 311 | 311 | return $invoice->get_transaction_id(); |
| 312 | 312 | } |
| 313 | 313 | |
| 314 | -function wpinv_get_id_by_transaction_id( $key ) { |
|
| 314 | +function wpinv_get_id_by_transaction_id($key) { |
|
| 315 | 315 | global $wpdb; |
| 316 | 316 | |
| 317 | - $invoice_id = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_transaction_id' AND meta_value = %s LIMIT 1", $key ) ); |
|
| 317 | + $invoice_id = $wpdb->get_var($wpdb->prepare("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_transaction_id' AND meta_value = %s LIMIT 1", $key)); |
|
| 318 | 318 | |
| 319 | - if ( $invoice_id != NULL ) |
|
| 319 | + if ($invoice_id != NULL) |
|
| 320 | 320 | return $invoice_id; |
| 321 | 321 | |
| 322 | 322 | return 0; |
| 323 | 323 | } |
| 324 | 324 | |
| 325 | -function wpinv_get_invoice_meta( $invoice_id = 0, $meta_key = '_wpinv_payment_meta', $single = true ) { |
|
| 326 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
| 325 | +function wpinv_get_invoice_meta($invoice_id = 0, $meta_key = '_wpinv_payment_meta', $single = true) { |
|
| 326 | + $invoice = new WPInv_Invoice($invoice_id); |
|
| 327 | 327 | |
| 328 | - return $invoice->get_meta( $meta_key, $single ); |
|
| 328 | + return $invoice->get_meta($meta_key, $single); |
|
| 329 | 329 | } |
| 330 | 330 | |
| 331 | -function wpinv_update_invoice_meta( $invoice_id = 0, $meta_key = '', $meta_value = '', $prev_value = '' ) { |
|
| 332 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
| 331 | +function wpinv_update_invoice_meta($invoice_id = 0, $meta_key = '', $meta_value = '', $prev_value = '') { |
|
| 332 | + $invoice = new WPInv_Invoice($invoice_id); |
|
| 333 | 333 | |
| 334 | - return $invoice->update_meta( $meta_key, $meta_value, $prev_value ); |
|
| 334 | + return $invoice->update_meta($meta_key, $meta_value, $prev_value); |
|
| 335 | 335 | } |
| 336 | 336 | |
| 337 | -function wpinv_get_items( $invoice_id = 0 ) { |
|
| 338 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
| 337 | +function wpinv_get_items($invoice_id = 0) { |
|
| 338 | + $invoice = wpinv_get_invoice($invoice_id); |
|
| 339 | 339 | |
| 340 | 340 | $items = $invoice->get_items(); |
| 341 | 341 | $invoice_currency = $invoice->get_currency(); |
| 342 | 342 | |
| 343 | - if ( !empty( $items ) && is_array( $items ) ) { |
|
| 344 | - foreach ( $items as $key => $item ) { |
|
| 343 | + if (!empty($items) && is_array($items)) { |
|
| 344 | + foreach ($items as $key => $item) { |
|
| 345 | 345 | $items[$key]['currency'] = $invoice_currency; |
| 346 | 346 | |
| 347 | - if ( !isset( $cart_item['subtotal'] ) ) { |
|
| 347 | + if (!isset($cart_item['subtotal'])) { |
|
| 348 | 348 | $items[$key]['subtotal'] = $items[$key]['amount'] * 1; |
| 349 | 349 | } |
| 350 | 350 | } |
| 351 | 351 | } |
| 352 | 352 | |
| 353 | - return apply_filters( 'wpinv_get_items', $items, $invoice_id ); |
|
| 353 | + return apply_filters('wpinv_get_items', $items, $invoice_id); |
|
| 354 | 354 | } |
| 355 | 355 | |
| 356 | -function wpinv_get_fees( $invoice_id = 0 ) { |
|
| 357 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
| 356 | +function wpinv_get_fees($invoice_id = 0) { |
|
| 357 | + $invoice = wpinv_get_invoice($invoice_id); |
|
| 358 | 358 | $fees = $invoice->get_fees(); |
| 359 | 359 | |
| 360 | - return apply_filters( 'wpinv_get_fees', $fees, $invoice_id ); |
|
| 360 | + return apply_filters('wpinv_get_fees', $fees, $invoice_id); |
|
| 361 | 361 | } |
| 362 | 362 | |
| 363 | -function wpinv_get_invoice_ip( $invoice_id ) { |
|
| 364 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
| 363 | +function wpinv_get_invoice_ip($invoice_id) { |
|
| 364 | + $invoice = new WPInv_Invoice($invoice_id); |
|
| 365 | 365 | return $invoice->get_ip(); |
| 366 | 366 | } |
| 367 | 367 | |
| 368 | -function wpinv_get_invoice_user_info( $invoice_id ) { |
|
| 369 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
| 368 | +function wpinv_get_invoice_user_info($invoice_id) { |
|
| 369 | + $invoice = new WPInv_Invoice($invoice_id); |
|
| 370 | 370 | return $invoice->get_user_info(); |
| 371 | 371 | } |
| 372 | 372 | |
| 373 | -function wpinv_subtotal( $invoice_id = 0, $currency = false ) { |
|
| 374 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
| 373 | +function wpinv_subtotal($invoice_id = 0, $currency = false) { |
|
| 374 | + $invoice = new WPInv_Invoice($invoice_id); |
|
| 375 | 375 | |
| 376 | - return $invoice->get_subtotal( $currency ); |
|
| 376 | + return $invoice->get_subtotal($currency); |
|
| 377 | 377 | } |
| 378 | 378 | |
| 379 | -function wpinv_tax( $invoice_id = 0, $currency = false ) { |
|
| 380 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
| 379 | +function wpinv_tax($invoice_id = 0, $currency = false) { |
|
| 380 | + $invoice = new WPInv_Invoice($invoice_id); |
|
| 381 | 381 | |
| 382 | - return $invoice->get_tax( $currency ); |
|
| 382 | + return $invoice->get_tax($currency); |
|
| 383 | 383 | } |
| 384 | 384 | |
| 385 | -function wpinv_discount( $invoice_id = 0, $currency = false, $dash = false ) { |
|
| 386 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
| 385 | +function wpinv_discount($invoice_id = 0, $currency = false, $dash = false) { |
|
| 386 | + $invoice = wpinv_get_invoice($invoice_id); |
|
| 387 | 387 | |
| 388 | - return $invoice->get_discount( $currency, $dash ); |
|
| 388 | + return $invoice->get_discount($currency, $dash); |
|
| 389 | 389 | } |
| 390 | 390 | |
| 391 | -function wpinv_discount_code( $invoice_id = 0 ) { |
|
| 392 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
| 391 | +function wpinv_discount_code($invoice_id = 0) { |
|
| 392 | + $invoice = new WPInv_Invoice($invoice_id); |
|
| 393 | 393 | |
| 394 | 394 | return $invoice->get_discount_code(); |
| 395 | 395 | } |
| 396 | 396 | |
| 397 | -function wpinv_payment_total( $invoice_id = 0, $currency = false ) { |
|
| 398 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
| 397 | +function wpinv_payment_total($invoice_id = 0, $currency = false) { |
|
| 398 | + $invoice = new WPInv_Invoice($invoice_id); |
|
| 399 | 399 | |
| 400 | - return $invoice->get_total( $currency ); |
|
| 400 | + return $invoice->get_total($currency); |
|
| 401 | 401 | } |
| 402 | 402 | |
| 403 | -function wpinv_get_date_created( $invoice_id = 0 ) { |
|
| 404 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
| 403 | +function wpinv_get_date_created($invoice_id = 0) { |
|
| 404 | + $invoice = new WPInv_Invoice($invoice_id); |
|
| 405 | 405 | |
| 406 | 406 | $date_created = $invoice->get_created_date(); |
| 407 | - $date_created = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? date_i18n( get_option( 'date_format' ), strtotime( $date_created ) ) : ''; |
|
| 407 | + $date_created = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? date_i18n(get_option('date_format'), strtotime($date_created)) : ''; |
|
| 408 | 408 | |
| 409 | 409 | return $date_created; |
| 410 | 410 | } |
| 411 | 411 | |
| 412 | -function wpinv_get_invoice_date( $invoice_id = 0, $format = '' ) { |
|
| 413 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
| 412 | +function wpinv_get_invoice_date($invoice_id = 0, $format = '') { |
|
| 413 | + $invoice = new WPInv_Invoice($invoice_id); |
|
| 414 | 414 | |
| 415 | - $format = !empty( $format ) ? $format : get_option( 'date_format' ); |
|
| 415 | + $format = !empty($format) ? $format : get_option('date_format'); |
|
| 416 | 416 | $date_completed = $invoice->get_completed_date(); |
| 417 | - $invoice_date = $date_completed != '' && $date_completed != '0000-00-00 00:00:00' ? date_i18n( $format, strtotime( $date_completed ) ) : ''; |
|
| 418 | - if ( $invoice_date == '' ) { |
|
| 417 | + $invoice_date = $date_completed != '' && $date_completed != '0000-00-00 00:00:00' ? date_i18n($format, strtotime($date_completed)) : ''; |
|
| 418 | + if ($invoice_date == '') { |
|
| 419 | 419 | $date_created = $invoice->get_created_date(); |
| 420 | - $invoice_date = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? date_i18n( $format, strtotime( $date_created ) ) : ''; |
|
| 420 | + $invoice_date = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? date_i18n($format, strtotime($date_created)) : ''; |
|
| 421 | 421 | } |
| 422 | 422 | |
| 423 | 423 | return $invoice_date; |
| 424 | 424 | } |
| 425 | 425 | |
| 426 | -function wpinv_get_invoice_vat_number( $invoice_id = 0 ) { |
|
| 427 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
| 426 | +function wpinv_get_invoice_vat_number($invoice_id = 0) { |
|
| 427 | + $invoice = new WPInv_Invoice($invoice_id); |
|
| 428 | 428 | |
| 429 | 429 | return $invoice->vat_number; |
| 430 | 430 | } |
| 431 | 431 | |
| 432 | -function wpinv_insert_payment_note( $invoice_id = 0, $note = '', $user_type = false, $added_by_user = false ) { |
|
| 433 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
| 432 | +function wpinv_insert_payment_note($invoice_id = 0, $note = '', $user_type = false, $added_by_user = false) { |
|
| 433 | + $invoice = new WPInv_Invoice($invoice_id); |
|
| 434 | 434 | |
| 435 | - return $invoice->add_note( $note, $user_type, $added_by_user ); |
|
| 435 | + return $invoice->add_note($note, $user_type, $added_by_user); |
|
| 436 | 436 | } |
| 437 | 437 | |
| 438 | -function wpinv_get_invoice_notes( $invoice_id = 0, $type = '' ) { |
|
| 438 | +function wpinv_get_invoice_notes($invoice_id = 0, $type = '') { |
|
| 439 | 439 | global $invoicing; |
| 440 | 440 | |
| 441 | - if ( empty( $invoice_id ) ) { |
|
| 441 | + if (empty($invoice_id)) { |
|
| 442 | 442 | return NULL; |
| 443 | 443 | } |
| 444 | 444 | |
| 445 | - $notes = $invoicing->notes->get_invoice_notes( $invoice_id, $type ); |
|
| 445 | + $notes = $invoicing->notes->get_invoice_notes($invoice_id, $type); |
|
| 446 | 446 | |
| 447 | - return apply_filters( 'wpinv_invoice_notes', $notes, $invoice_id, $type ); |
|
| 447 | + return apply_filters('wpinv_invoice_notes', $notes, $invoice_id, $type); |
|
| 448 | 448 | } |
| 449 | 449 | |
| 450 | -function wpinv_get_payment_key( $invoice_id = 0 ) { |
|
| 451 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
| 450 | +function wpinv_get_payment_key($invoice_id = 0) { |
|
| 451 | + $invoice = new WPInv_Invoice($invoice_id); |
|
| 452 | 452 | return $invoice->get_key(); |
| 453 | 453 | } |
| 454 | 454 | |
| 455 | -function wpinv_get_invoice_number( $invoice_id = 0 ) { |
|
| 456 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
| 455 | +function wpinv_get_invoice_number($invoice_id = 0) { |
|
| 456 | + $invoice = new WPInv_Invoice($invoice_id); |
|
| 457 | 457 | return $invoice->get_number(); |
| 458 | 458 | } |
| 459 | 459 | |
| 460 | -function wpinv_get_cart_discountable_subtotal( $code_id ) { |
|
| 460 | +function wpinv_get_cart_discountable_subtotal($code_id) { |
|
| 461 | 461 | $cart_items = wpinv_get_cart_content_details(); |
| 462 | 462 | $items = array(); |
| 463 | 463 | |
| 464 | - $excluded_items = wpinv_get_discount_excluded_items( $code_id ); |
|
| 464 | + $excluded_items = wpinv_get_discount_excluded_items($code_id); |
|
| 465 | 465 | |
| 466 | - if( $cart_items ) { |
|
| 466 | + if ($cart_items) { |
|
| 467 | 467 | |
| 468 | - foreach( $cart_items as $item ) { |
|
| 468 | + foreach ($cart_items as $item) { |
|
| 469 | 469 | |
| 470 | - if( ! in_array( $item['id'], $excluded_items ) ) { |
|
| 471 | - $items[] = $item; |
|
| 470 | + if (!in_array($item['id'], $excluded_items)) { |
|
| 471 | + $items[] = $item; |
|
| 472 | 472 | } |
| 473 | 473 | } |
| 474 | 474 | } |
| 475 | 475 | |
| 476 | - $subtotal = wpinv_get_cart_items_subtotal( $items ); |
|
| 476 | + $subtotal = wpinv_get_cart_items_subtotal($items); |
|
| 477 | 477 | |
| 478 | - return apply_filters( 'wpinv_get_cart_discountable_subtotal', $subtotal ); |
|
| 478 | + return apply_filters('wpinv_get_cart_discountable_subtotal', $subtotal); |
|
| 479 | 479 | } |
| 480 | 480 | |
| 481 | -function wpinv_get_cart_items_subtotal( $items ) { |
|
| 481 | +function wpinv_get_cart_items_subtotal($items) { |
|
| 482 | 482 | $subtotal = 0.00; |
| 483 | 483 | |
| 484 | - if ( is_array( $items ) && ! empty( $items ) ) { |
|
| 485 | - $prices = wp_list_pluck( $items, 'subtotal' ); |
|
| 484 | + if (is_array($items) && !empty($items)) { |
|
| 485 | + $prices = wp_list_pluck($items, 'subtotal'); |
|
| 486 | 486 | |
| 487 | - if( is_array( $prices ) ) { |
|
| 488 | - $subtotal = array_sum( $prices ); |
|
| 487 | + if (is_array($prices)) { |
|
| 488 | + $subtotal = array_sum($prices); |
|
| 489 | 489 | } else { |
| 490 | 490 | $subtotal = 0.00; |
| 491 | 491 | } |
| 492 | 492 | |
| 493 | - if( $subtotal < 0 ) { |
|
| 493 | + if ($subtotal < 0) { |
|
| 494 | 494 | $subtotal = 0.00; |
| 495 | 495 | } |
| 496 | 496 | } |
| 497 | 497 | |
| 498 | - return apply_filters( 'wpinv_get_cart_items_subtotal', $subtotal ); |
|
| 498 | + return apply_filters('wpinv_get_cart_items_subtotal', $subtotal); |
|
| 499 | 499 | } |
| 500 | 500 | |
| 501 | -function wpinv_get_cart_subtotal( $items = array() ) { |
|
| 502 | - $items = !empty( $items ) ? $items : wpinv_get_cart_content_details(); |
|
| 503 | - $subtotal = wpinv_get_cart_items_subtotal( $items ); |
|
| 501 | +function wpinv_get_cart_subtotal($items = array()) { |
|
| 502 | + $items = !empty($items) ? $items : wpinv_get_cart_content_details(); |
|
| 503 | + $subtotal = wpinv_get_cart_items_subtotal($items); |
|
| 504 | 504 | |
| 505 | - return apply_filters( 'wpinv_get_cart_subtotal', $subtotal ); |
|
| 505 | + return apply_filters('wpinv_get_cart_subtotal', $subtotal); |
|
| 506 | 506 | } |
| 507 | 507 | |
| 508 | -function wpinv_cart_subtotal( $items = array() ) { |
|
| 509 | - $price = wpinv_price( wpinv_format_amount( wpinv_get_cart_subtotal( $items ) ) ); |
|
| 508 | +function wpinv_cart_subtotal($items = array()) { |
|
| 509 | + $price = wpinv_price(wpinv_format_amount(wpinv_get_cart_subtotal($items))); |
|
| 510 | 510 | |
| 511 | 511 | return $price; |
| 512 | 512 | } |
| 513 | 513 | |
| 514 | -function wpinv_get_cart_total( $items = array(), $discounts = false, $invoice = array() ) { |
|
| 515 | - $subtotal = (float)wpinv_get_cart_subtotal( $items ); |
|
| 516 | - $discounts = (float)wpinv_get_cart_discounted_amount( $items ); |
|
| 517 | - $cart_tax = (float)wpinv_get_cart_tax( $items ); |
|
| 514 | +function wpinv_get_cart_total($items = array(), $discounts = false, $invoice = array()) { |
|
| 515 | + $subtotal = (float)wpinv_get_cart_subtotal($items); |
|
| 516 | + $discounts = (float)wpinv_get_cart_discounted_amount($items); |
|
| 517 | + $cart_tax = (float)wpinv_get_cart_tax($items); |
|
| 518 | 518 | $fees = (float)wpinv_get_cart_fee_total(); |
| 519 | - if ( !empty( $invoice ) && $invoice->is_free_trial() ) { |
|
| 519 | + if (!empty($invoice) && $invoice->is_free_trial()) { |
|
| 520 | 520 | $total = 0; |
| 521 | 521 | } else { |
| 522 | - $total = $subtotal - $discounts + $cart_tax + $fees; |
|
| 522 | + $total = $subtotal - $discounts + $cart_tax + $fees; |
|
| 523 | 523 | } |
| 524 | 524 | |
| 525 | - if ( $total < 0 ) { |
|
| 525 | + if ($total < 0) { |
|
| 526 | 526 | $total = 0.00; |
| 527 | 527 | } |
| 528 | 528 | |
| 529 | - $total = (float)apply_filters( 'wpinv_get_cart_total', $total, $items ); |
|
| 529 | + $total = (float)apply_filters('wpinv_get_cart_total', $total, $items); |
|
| 530 | 530 | |
| 531 | - return wpinv_sanitize_amount( $total ); |
|
| 531 | + return wpinv_sanitize_amount($total); |
|
| 532 | 532 | } |
| 533 | 533 | |
| 534 | -function wpinv_cart_total( $cart_items = array(), $echo = true, $invoice = array() ) { |
|
| 534 | +function wpinv_cart_total($cart_items = array(), $echo = true, $invoice = array()) { |
|
| 535 | 535 | global $cart_total; |
| 536 | - $total = wpinv_price( wpinv_format_amount( wpinv_get_cart_total( $cart_items, NULL, $invoice ) ) ); |
|
| 537 | - $total = apply_filters( 'wpinv_cart_total', $total, $cart_items, $invoice ); |
|
| 536 | + $total = wpinv_price(wpinv_format_amount(wpinv_get_cart_total($cart_items, NULL, $invoice))); |
|
| 537 | + $total = apply_filters('wpinv_cart_total', $total, $cart_items, $invoice); |
|
| 538 | 538 | |
| 539 | 539 | $cart_total = $total; |
| 540 | 540 | |
| 541 | - if ( !$echo ) { |
|
| 541 | + if (!$echo) { |
|
| 542 | 542 | return $total; |
| 543 | 543 | } |
| 544 | 544 | |
| 545 | 545 | echo $total; |
| 546 | 546 | } |
| 547 | 547 | |
| 548 | -function wpinv_get_cart_tax( $items = array() ) { |
|
| 548 | +function wpinv_get_cart_tax($items = array()) { |
|
| 549 | 549 | $cart_tax = 0; |
| 550 | - $items = !empty( $items ) ? $items : wpinv_get_cart_content_details(); |
|
| 550 | + $items = !empty($items) ? $items : wpinv_get_cart_content_details(); |
|
| 551 | 551 | |
| 552 | - if ( $items ) { |
|
| 553 | - $taxes = wp_list_pluck( $items, 'tax' ); |
|
| 552 | + if ($items) { |
|
| 553 | + $taxes = wp_list_pluck($items, 'tax'); |
|
| 554 | 554 | |
| 555 | - if( is_array( $taxes ) ) { |
|
| 556 | - $cart_tax = array_sum( $taxes ); |
|
| 555 | + if (is_array($taxes)) { |
|
| 556 | + $cart_tax = array_sum($taxes); |
|
| 557 | 557 | } |
| 558 | 558 | } |
| 559 | 559 | |
| 560 | 560 | $cart_tax += wpinv_get_cart_fee_tax(); |
| 561 | 561 | |
| 562 | - return apply_filters( 'wpinv_get_cart_tax', wpinv_sanitize_amount( $cart_tax ) ); |
|
| 562 | + return apply_filters('wpinv_get_cart_tax', wpinv_sanitize_amount($cart_tax)); |
|
| 563 | 563 | } |
| 564 | 564 | |
| 565 | -function wpinv_cart_tax( $items = array(), $echo = false ) { |
|
| 566 | - $cart_tax = wpinv_get_cart_tax( $items ); |
|
| 567 | - $cart_tax = wpinv_price( wpinv_format_amount( $cart_tax ) ); |
|
| 565 | +function wpinv_cart_tax($items = array(), $echo = false) { |
|
| 566 | + $cart_tax = wpinv_get_cart_tax($items); |
|
| 567 | + $cart_tax = wpinv_price(wpinv_format_amount($cart_tax)); |
|
| 568 | 568 | |
| 569 | - $tax = apply_filters( 'wpinv_cart_tax', $cart_tax, $items ); |
|
| 569 | + $tax = apply_filters('wpinv_cart_tax', $cart_tax, $items); |
|
| 570 | 570 | |
| 571 | - if ( !$echo ) { |
|
| 571 | + if (!$echo) { |
|
| 572 | 572 | return $tax; |
| 573 | 573 | } |
| 574 | 574 | |
| 575 | 575 | echo $tax; |
| 576 | 576 | } |
| 577 | 577 | |
| 578 | -function wpinv_get_cart_discount_code( $items = array() ) { |
|
| 578 | +function wpinv_get_cart_discount_code($items = array()) { |
|
| 579 | 579 | $invoice = wpinv_get_invoice_cart(); |
| 580 | - $cart_discount_code = !empty( $invoice ) ? $invoice->get_discount_code() : ''; |
|
| 580 | + $cart_discount_code = !empty($invoice) ? $invoice->get_discount_code() : ''; |
|
| 581 | 581 | |
| 582 | - return apply_filters( 'wpinv_get_cart_discount_code', $cart_discount_code ); |
|
| 582 | + return apply_filters('wpinv_get_cart_discount_code', $cart_discount_code); |
|
| 583 | 583 | } |
| 584 | 584 | |
| 585 | -function wpinv_cart_discount_code( $items = array(), $echo = false ) { |
|
| 586 | - $cart_discount_code = wpinv_get_cart_discount_code( $items ); |
|
| 585 | +function wpinv_cart_discount_code($items = array(), $echo = false) { |
|
| 586 | + $cart_discount_code = wpinv_get_cart_discount_code($items); |
|
| 587 | 587 | |
| 588 | - if ( $cart_discount_code != '' ) { |
|
| 588 | + if ($cart_discount_code != '') { |
|
| 589 | 589 | $cart_discount_code = ' (' . $cart_discount_code . ')'; |
| 590 | 590 | } |
| 591 | 591 | |
| 592 | - $discount_code = apply_filters( 'wpinv_cart_discount_code', $cart_discount_code, $items ); |
|
| 592 | + $discount_code = apply_filters('wpinv_cart_discount_code', $cart_discount_code, $items); |
|
| 593 | 593 | |
| 594 | - if ( !$echo ) { |
|
| 594 | + if (!$echo) { |
|
| 595 | 595 | return $discount_code; |
| 596 | 596 | } |
| 597 | 597 | |
| 598 | 598 | echo $discount_code; |
| 599 | 599 | } |
| 600 | 600 | |
| 601 | -function wpinv_get_cart_discount( $items = array() ) { |
|
| 601 | +function wpinv_get_cart_discount($items = array()) { |
|
| 602 | 602 | $invoice = wpinv_get_invoice_cart(); |
| 603 | - $cart_discount = !empty( $invoice ) ? $invoice->get_discount() : 0; |
|
| 603 | + $cart_discount = !empty($invoice) ? $invoice->get_discount() : 0; |
|
| 604 | 604 | |
| 605 | - return apply_filters( 'wpinv_get_cart_discount', wpinv_sanitize_amount( $cart_discount ), $items ); |
|
| 605 | + return apply_filters('wpinv_get_cart_discount', wpinv_sanitize_amount($cart_discount), $items); |
|
| 606 | 606 | } |
| 607 | 607 | |
| 608 | -function wpinv_cart_discount( $items = array(), $echo = false ) { |
|
| 609 | - $cart_discount = wpinv_get_cart_discount( $items ); |
|
| 610 | - $cart_discount = wpinv_price( wpinv_format_amount( $cart_discount ) ); |
|
| 608 | +function wpinv_cart_discount($items = array(), $echo = false) { |
|
| 609 | + $cart_discount = wpinv_get_cart_discount($items); |
|
| 610 | + $cart_discount = wpinv_price(wpinv_format_amount($cart_discount)); |
|
| 611 | 611 | |
| 612 | - $discount = apply_filters( 'wpinv_cart_discount', $cart_discount, $items ); |
|
| 612 | + $discount = apply_filters('wpinv_cart_discount', $cart_discount, $items); |
|
| 613 | 613 | |
| 614 | - if ( !$echo ) { |
|
| 614 | + if (!$echo) { |
|
| 615 | 615 | return $discount; |
| 616 | 616 | } |
| 617 | 617 | |
| 618 | 618 | echo $discount; |
| 619 | 619 | } |
| 620 | 620 | |
| 621 | -function wpinv_get_cart_fees( $type = 'all', $item_id = 0 ) { |
|
| 622 | - $item = new WPInv_Item( $item_id ); |
|
| 621 | +function wpinv_get_cart_fees($type = 'all', $item_id = 0) { |
|
| 622 | + $item = new WPInv_Item($item_id); |
|
| 623 | 623 | |
| 624 | - return $item->get_fees( $type, $item_id ); |
|
| 624 | + return $item->get_fees($type, $item_id); |
|
| 625 | 625 | } |
| 626 | 626 | |
| 627 | 627 | function wpinv_get_cart_fee_total() { |
| 628 | - $total = 0; |
|
| 628 | + $total = 0; |
|
| 629 | 629 | $fees = wpinv_get_cart_fees(); |
| 630 | 630 | |
| 631 | - if ( $fees ) { |
|
| 632 | - foreach ( $fees as $fee_id => $fee ) { |
|
| 631 | + if ($fees) { |
|
| 632 | + foreach ($fees as $fee_id => $fee) { |
|
| 633 | 633 | $total += $fee['amount']; |
| 634 | 634 | } |
| 635 | 635 | } |
| 636 | 636 | |
| 637 | - return apply_filters( 'wpinv_get_cart_fee_total', $total ); |
|
| 637 | + return apply_filters('wpinv_get_cart_fee_total', $total); |
|
| 638 | 638 | } |
| 639 | 639 | |
| 640 | 640 | function wpinv_get_cart_fee_tax() { |
| 641 | 641 | $tax = 0; |
| 642 | 642 | $fees = wpinv_get_cart_fees(); |
| 643 | 643 | |
| 644 | - if ( $fees ) { |
|
| 645 | - foreach ( $fees as $fee_id => $fee ) { |
|
| 646 | - if( ! empty( $fee['no_tax'] ) ) { |
|
| 644 | + if ($fees) { |
|
| 645 | + foreach ($fees as $fee_id => $fee) { |
|
| 646 | + if (!empty($fee['no_tax'])) { |
|
| 647 | 647 | continue; |
| 648 | 648 | } |
| 649 | 649 | |
| 650 | - $tax += wpinv_calculate_tax( $fee['amount'] ); |
|
| 650 | + $tax += wpinv_calculate_tax($fee['amount']); |
|
| 651 | 651 | } |
| 652 | 652 | } |
| 653 | 653 | |
| 654 | - return apply_filters( 'wpinv_get_cart_fee_tax', $tax ); |
|
| 654 | + return apply_filters('wpinv_get_cart_fee_tax', $tax); |
|
| 655 | 655 | } |
| 656 | 656 | |
| 657 | 657 | function wpinv_cart_has_recurring_item() { |
| 658 | 658 | $cart_items = wpinv_get_cart_contents(); |
| 659 | 659 | |
| 660 | - if ( empty( $cart_items ) ) { |
|
| 660 | + if (empty($cart_items)) { |
|
| 661 | 661 | return false; |
| 662 | 662 | } |
| 663 | 663 | |
| 664 | 664 | $has_subscription = false; |
| 665 | - foreach( $cart_items as $cart_item ) { |
|
| 666 | - if ( !empty( $cart_item['id'] ) && wpinv_is_recurring_item( $cart_item['id'] ) ) { |
|
| 665 | + foreach ($cart_items as $cart_item) { |
|
| 666 | + if (!empty($cart_item['id']) && wpinv_is_recurring_item($cart_item['id'])) { |
|
| 667 | 667 | $has_subscription = true; |
| 668 | 668 | break; |
| 669 | 669 | } |
| 670 | 670 | } |
| 671 | 671 | |
| 672 | - return apply_filters( 'wpinv_cart_has_recurring_item', $has_subscription, $cart_items ); |
|
| 672 | + return apply_filters('wpinv_cart_has_recurring_item', $has_subscription, $cart_items); |
|
| 673 | 673 | } |
| 674 | 674 | |
| 675 | 675 | function wpinv_cart_has_free_trial() { |
@@ -677,94 +677,94 @@ discard block |
||
| 677 | 677 | |
| 678 | 678 | $free_trial = false; |
| 679 | 679 | |
| 680 | - if ( !empty( $invoice ) && $invoice->is_free_trial() ) { |
|
| 680 | + if (!empty($invoice) && $invoice->is_free_trial()) { |
|
| 681 | 681 | $free_trial = true; |
| 682 | 682 | } |
| 683 | 683 | |
| 684 | - return apply_filters( 'wpinv_cart_has_free_trial', $free_trial, $invoice ); |
|
| 684 | + return apply_filters('wpinv_cart_has_free_trial', $free_trial, $invoice); |
|
| 685 | 685 | } |
| 686 | 686 | |
| 687 | 687 | function wpinv_get_cart_contents() { |
| 688 | 688 | $cart_details = wpinv_get_cart_details(); |
| 689 | 689 | |
| 690 | - return apply_filters( 'wpinv_get_cart_contents', $cart_details ); |
|
| 690 | + return apply_filters('wpinv_get_cart_contents', $cart_details); |
|
| 691 | 691 | } |
| 692 | 692 | |
| 693 | 693 | function wpinv_get_cart_content_details() { |
| 694 | 694 | global $wpinv_euvat, $wpi_current_id, $wpi_item_id, $wpinv_is_last_cart_item, $wpinv_flat_discount_total; |
| 695 | 695 | $cart_items = wpinv_get_cart_contents(); |
| 696 | 696 | |
| 697 | - if ( empty( $cart_items ) ) { |
|
| 697 | + if (empty($cart_items)) { |
|
| 698 | 698 | return false; |
| 699 | 699 | } |
| 700 | 700 | $invoice = wpinv_get_invoice_cart(); |
| 701 | 701 | |
| 702 | 702 | $details = array(); |
| 703 | - $length = count( $cart_items ) - 1; |
|
| 703 | + $length = count($cart_items) - 1; |
|
| 704 | 704 | |
| 705 | - if ( empty( $_POST['country'] ) ) { |
|
| 705 | + if (empty($_POST['country'])) { |
|
| 706 | 706 | $_POST['country'] = $invoice->country; |
| 707 | 707 | } |
| 708 | - if ( !isset( $_POST['state'] ) ) { |
|
| 708 | + if (!isset($_POST['state'])) { |
|
| 709 | 709 | $_POST['state'] = $invoice->state; |
| 710 | 710 | } |
| 711 | 711 | |
| 712 | - foreach( $cart_items as $key => $item ) { |
|
| 713 | - $item_id = isset( $item['id'] ) ? sanitize_text_field( $item['id'] ) : ''; |
|
| 714 | - if ( empty( $item_id ) ) { |
|
| 712 | + foreach ($cart_items as $key => $item) { |
|
| 713 | + $item_id = isset($item['id']) ? sanitize_text_field($item['id']) : ''; |
|
| 714 | + if (empty($item_id)) { |
|
| 715 | 715 | continue; |
| 716 | 716 | } |
| 717 | 717 | |
| 718 | 718 | $wpi_current_id = $invoice->ID; |
| 719 | 719 | $wpi_item_id = $item_id; |
| 720 | 720 | |
| 721 | - if ( isset( $item['custom_price'] ) && $item['custom_price'] !== '' ) { |
|
| 721 | + if (isset($item['custom_price']) && $item['custom_price'] !== '') { |
|
| 722 | 722 | $item_price = $item['custom_price']; |
| 723 | 723 | } else { |
| 724 | - if ( isset( $item['item_price'] ) && $item['item_price'] !== '' && $item['item_price'] !== false ) { |
|
| 724 | + if (isset($item['item_price']) && $item['item_price'] !== '' && $item['item_price'] !== false) { |
|
| 725 | 725 | $item_price = $item['item_price']; |
| 726 | 726 | } else { |
| 727 | - $item_price = wpinv_get_item_price( $item_id ); |
|
| 727 | + $item_price = wpinv_get_item_price($item_id); |
|
| 728 | 728 | } |
| 729 | 729 | } |
| 730 | - $discount = wpinv_get_cart_item_discount_amount( $item ); |
|
| 731 | - $discount = apply_filters( 'wpinv_get_cart_content_details_item_discount_amount', $discount, $item ); |
|
| 732 | - $quantity = wpinv_get_cart_item_quantity( $item ); |
|
| 733 | - $fees = wpinv_get_cart_fees( 'fee', $item_id ); |
|
| 730 | + $discount = wpinv_get_cart_item_discount_amount($item); |
|
| 731 | + $discount = apply_filters('wpinv_get_cart_content_details_item_discount_amount', $discount, $item); |
|
| 732 | + $quantity = wpinv_get_cart_item_quantity($item); |
|
| 733 | + $fees = wpinv_get_cart_fees('fee', $item_id); |
|
| 734 | 734 | |
| 735 | 735 | $subtotal = $item_price * $quantity; |
| 736 | - $tax_rate = wpinv_get_tax_rate( $_POST['country'], $_POST['state'], $wpi_item_id ); |
|
| 737 | - $tax_class = $wpinv_euvat->get_item_class( $item_id ); |
|
| 738 | - $tax = wpinv_get_cart_item_tax( $item_id, $subtotal - $discount ); |
|
| 736 | + $tax_rate = wpinv_get_tax_rate($_POST['country'], $_POST['state'], $wpi_item_id); |
|
| 737 | + $tax_class = $wpinv_euvat->get_item_class($item_id); |
|
| 738 | + $tax = wpinv_get_cart_item_tax($item_id, $subtotal - $discount); |
|
| 739 | 739 | |
| 740 | - if ( wpinv_prices_include_tax() ) { |
|
| 741 | - $subtotal -= wpinv_round_amount( $tax ); |
|
| 740 | + if (wpinv_prices_include_tax()) { |
|
| 741 | + $subtotal -= wpinv_round_amount($tax); |
|
| 742 | 742 | } |
| 743 | 743 | |
| 744 | - $total = $subtotal - $discount + $tax; |
|
| 744 | + $total = $subtotal - $discount + $tax; |
|
| 745 | 745 | |
| 746 | 746 | // Do not allow totals to go negatve |
| 747 | - if( $total < 0 ) { |
|
| 747 | + if ($total < 0) { |
|
| 748 | 748 | $total = 0; |
| 749 | 749 | } |
| 750 | 750 | |
| 751 | - $details[ $key ] = array( |
|
| 751 | + $details[$key] = array( |
|
| 752 | 752 | 'id' => $item_id, |
| 753 | - 'name' => !empty($item['name']) ? $item['name'] : get_the_title( $item_id ), |
|
| 754 | - 'item_price' => wpinv_round_amount( $item_price ), |
|
| 755 | - 'custom_price' => isset( $item['custom_price'] ) ? $item['custom_price'] : '', |
|
| 753 | + 'name' => !empty($item['name']) ? $item['name'] : get_the_title($item_id), |
|
| 754 | + 'item_price' => wpinv_round_amount($item_price), |
|
| 755 | + 'custom_price' => isset($item['custom_price']) ? $item['custom_price'] : '', |
|
| 756 | 756 | 'quantity' => $quantity, |
| 757 | - 'discount' => wpinv_round_amount( $discount ), |
|
| 758 | - 'subtotal' => wpinv_round_amount( $subtotal ), |
|
| 759 | - 'tax' => wpinv_round_amount( $tax ), |
|
| 760 | - 'price' => wpinv_round_amount( $total ), |
|
| 757 | + 'discount' => wpinv_round_amount($discount), |
|
| 758 | + 'subtotal' => wpinv_round_amount($subtotal), |
|
| 759 | + 'tax' => wpinv_round_amount($tax), |
|
| 760 | + 'price' => wpinv_round_amount($total), |
|
| 761 | 761 | 'vat_rates_class' => $tax_class, |
| 762 | 762 | 'vat_rate' => $tax_rate, |
| 763 | - 'meta' => isset( $item['meta'] ) ? $item['meta'] : array(), |
|
| 763 | + 'meta' => isset($item['meta']) ? $item['meta'] : array(), |
|
| 764 | 764 | 'fees' => $fees, |
| 765 | 765 | ); |
| 766 | 766 | |
| 767 | - if ( $wpinv_is_last_cart_item ) { |
|
| 767 | + if ($wpinv_is_last_cart_item) { |
|
| 768 | 768 | $wpinv_is_last_cart_item = false; |
| 769 | 769 | $wpinv_flat_discount_total = 0.00; |
| 770 | 770 | } |
@@ -773,60 +773,60 @@ discard block |
||
| 773 | 773 | return $details; |
| 774 | 774 | } |
| 775 | 775 | |
| 776 | -function wpinv_get_cart_details( $invoice_id = 0 ) { |
|
| 776 | +function wpinv_get_cart_details($invoice_id = 0) { |
|
| 777 | 777 | global $ajax_cart_details; |
| 778 | 778 | |
| 779 | - $invoice = wpinv_get_invoice_cart( $invoice_id ); |
|
| 780 | - $cart_details = !empty( $ajax_cart_details ) ? $ajax_cart_details : $invoice->cart_details; |
|
| 779 | + $invoice = wpinv_get_invoice_cart($invoice_id); |
|
| 780 | + $cart_details = !empty($ajax_cart_details) ? $ajax_cart_details : $invoice->cart_details; |
|
| 781 | 781 | |
| 782 | 782 | $invoice_currency = $invoice->currency; |
| 783 | 783 | |
| 784 | - if ( ! empty( $cart_details ) && is_array( $cart_details ) ) { |
|
| 785 | - foreach ( $cart_details as $key => $cart_item ) { |
|
| 786 | - $cart_details[ $key ]['currency'] = $invoice_currency; |
|
| 784 | + if (!empty($cart_details) && is_array($cart_details)) { |
|
| 785 | + foreach ($cart_details as $key => $cart_item) { |
|
| 786 | + $cart_details[$key]['currency'] = $invoice_currency; |
|
| 787 | 787 | |
| 788 | - if ( ! isset( $cart_item['subtotal'] ) ) { |
|
| 789 | - $cart_details[ $key ]['subtotal'] = $cart_item['price']; |
|
| 788 | + if (!isset($cart_item['subtotal'])) { |
|
| 789 | + $cart_details[$key]['subtotal'] = $cart_item['price']; |
|
| 790 | 790 | } |
| 791 | 791 | } |
| 792 | 792 | } |
| 793 | 793 | |
| 794 | - return apply_filters( 'wpinv_get_cart_details', $cart_details, $invoice_id ); |
|
| 794 | + return apply_filters('wpinv_get_cart_details', $cart_details, $invoice_id); |
|
| 795 | 795 | } |
| 796 | 796 | |
| 797 | -function wpinv_record_status_change( $invoice_id, $new_status, $old_status ) { |
|
| 798 | - if ( 'wpi_invoice' != get_post_type( $invoice_id ) ) { |
|
| 797 | +function wpinv_record_status_change($invoice_id, $new_status, $old_status) { |
|
| 798 | + if ('wpi_invoice' != get_post_type($invoice_id)) { |
|
| 799 | 799 | return; |
| 800 | 800 | } |
| 801 | 801 | |
| 802 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
| 802 | + $invoice = wpinv_get_invoice($invoice_id); |
|
| 803 | 803 | |
| 804 | - $old_status = wpinv_status_nicename( $old_status ); |
|
| 805 | - $new_status = wpinv_status_nicename( $new_status ); |
|
| 804 | + $old_status = wpinv_status_nicename($old_status); |
|
| 805 | + $new_status = wpinv_status_nicename($new_status); |
|
| 806 | 806 | |
| 807 | - $status_change = sprintf( __( 'Invoice status changed from %s to %s', 'invoicing' ), $old_status, $new_status ); |
|
| 807 | + $status_change = sprintf(__('Invoice status changed from %s to %s', 'invoicing'), $old_status, $new_status); |
|
| 808 | 808 | |
| 809 | 809 | // Add note |
| 810 | - return $invoice->add_note( $status_change, false, false, true ); |
|
| 810 | + return $invoice->add_note($status_change, false, false, true); |
|
| 811 | 811 | } |
| 812 | -add_action( 'wpinv_update_status', 'wpinv_record_status_change', 100, 3 ); |
|
| 812 | +add_action('wpinv_update_status', 'wpinv_record_status_change', 100, 3); |
|
| 813 | 813 | |
| 814 | -function wpinv_complete_payment( $invoice_id, $new_status, $old_status ) { |
|
| 814 | +function wpinv_complete_payment($invoice_id, $new_status, $old_status) { |
|
| 815 | 815 | global $wpi_has_free_trial; |
| 816 | 816 | |
| 817 | 817 | $wpi_has_free_trial = false; |
| 818 | 818 | |
| 819 | - if ( $old_status == 'publish' ) { |
|
| 819 | + if ($old_status == 'publish') { |
|
| 820 | 820 | return; // Make sure that payments are only paid once |
| 821 | 821 | } |
| 822 | 822 | |
| 823 | 823 | // Make sure the payment completion is only processed when new status is paid |
| 824 | - if ( $new_status != 'publish' ) { |
|
| 824 | + if ($new_status != 'publish') { |
|
| 825 | 825 | return; |
| 826 | 826 | } |
| 827 | 827 | |
| 828 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
| 829 | - if ( empty( $invoice ) ) { |
|
| 828 | + $invoice = new WPInv_Invoice($invoice_id); |
|
| 829 | + if (empty($invoice)) { |
|
| 830 | 830 | return; |
| 831 | 831 | } |
| 832 | 832 | |
@@ -834,58 +834,58 @@ discard block |
||
| 834 | 834 | $completed_date = $invoice->completed_date; |
| 835 | 835 | $cart_details = $invoice->cart_details; |
| 836 | 836 | |
| 837 | - do_action( 'wpinv_pre_complete_payment', $invoice_id ); |
|
| 837 | + do_action('wpinv_pre_complete_payment', $invoice_id); |
|
| 838 | 838 | |
| 839 | - if ( is_array( $cart_details ) ) { |
|
| 839 | + if (is_array($cart_details)) { |
|
| 840 | 840 | // Increase purchase count and earnings |
| 841 | - foreach ( $cart_details as $cart_index => $item ) { |
|
| 841 | + foreach ($cart_details as $cart_index => $item) { |
|
| 842 | 842 | // Ensure these actions only run once, ever |
| 843 | - if ( empty( $completed_date ) ) { |
|
| 844 | - do_action( 'wpinv_complete_item_payment', $item['id'], $invoice_id, $item, $cart_index ); |
|
| 843 | + if (empty($completed_date)) { |
|
| 844 | + do_action('wpinv_complete_item_payment', $item['id'], $invoice_id, $item, $cart_index); |
|
| 845 | 845 | } |
| 846 | 846 | } |
| 847 | 847 | } |
| 848 | 848 | |
| 849 | 849 | // Check for discount codes and increment their use counts |
| 850 | - if ( $discounts = $invoice->get_discounts( true ) ) { |
|
| 851 | - if( ! empty( $discounts ) ) { |
|
| 852 | - foreach( $discounts as $code ) { |
|
| 853 | - wpinv_increase_discount_usage( $code ); |
|
| 850 | + if ($discounts = $invoice->get_discounts(true)) { |
|
| 851 | + if (!empty($discounts)) { |
|
| 852 | + foreach ($discounts as $code) { |
|
| 853 | + wpinv_increase_discount_usage($code); |
|
| 854 | 854 | } |
| 855 | 855 | } |
| 856 | 856 | } |
| 857 | 857 | |
| 858 | 858 | // Ensure this action only runs once ever |
| 859 | - if( empty( $completed_date ) ) { |
|
| 859 | + if (empty($completed_date)) { |
|
| 860 | 860 | // Save the completed date |
| 861 | - $invoice->set( 'completed_date', current_time( 'mysql', 0 ) ); |
|
| 861 | + $invoice->set('completed_date', current_time('mysql', 0)); |
|
| 862 | 862 | $invoice->save(); |
| 863 | 863 | |
| 864 | - do_action( 'wpinv_complete_payment', $invoice_id ); |
|
| 864 | + do_action('wpinv_complete_payment', $invoice_id); |
|
| 865 | 865 | } |
| 866 | 866 | |
| 867 | 867 | // Empty the shopping cart |
| 868 | 868 | wpinv_empty_cart(); |
| 869 | 869 | } |
| 870 | -add_action( 'wpinv_update_status', 'wpinv_complete_payment', 100, 3 ); |
|
| 870 | +add_action('wpinv_update_status', 'wpinv_complete_payment', 100, 3); |
|
| 871 | 871 | |
| 872 | -function wpinv_update_payment_status( $invoice_id, $new_status = 'publish' ) { |
|
| 873 | - $invoice = !empty( $invoice_id ) && is_object( $invoice_id ) ? $invoice_id : wpinv_get_invoice( (int)$invoice_id ); |
|
| 872 | +function wpinv_update_payment_status($invoice_id, $new_status = 'publish') { |
|
| 873 | + $invoice = !empty($invoice_id) && is_object($invoice_id) ? $invoice_id : wpinv_get_invoice((int)$invoice_id); |
|
| 874 | 874 | |
| 875 | - if ( empty( $invoice ) ) { |
|
| 875 | + if (empty($invoice)) { |
|
| 876 | 876 | return false; |
| 877 | 877 | } |
| 878 | 878 | |
| 879 | - return $invoice->update_status( $new_status ); |
|
| 879 | + return $invoice->update_status($new_status); |
|
| 880 | 880 | } |
| 881 | 881 | |
| 882 | -function wpinv_cart_has_fees( $type = 'all' ) { |
|
| 882 | +function wpinv_cart_has_fees($type = 'all') { |
|
| 883 | 883 | return false; |
| 884 | 884 | } |
| 885 | 885 | |
| 886 | 886 | function wpinv_validate_checkout_fields() { |
| 887 | 887 | // Check if there is $_POST |
| 888 | - if ( empty( $_POST ) ) { |
|
| 888 | + if (empty($_POST)) { |
|
| 889 | 889 | return false; |
| 890 | 890 | } |
| 891 | 891 | |
@@ -897,11 +897,11 @@ discard block |
||
| 897 | 897 | ); |
| 898 | 898 | |
| 899 | 899 | // Validate agree to terms |
| 900 | - if ( wpinv_get_option( 'show_agree_to_terms', false ) ) { |
|
| 900 | + if (wpinv_get_option('show_agree_to_terms', false)) { |
|
| 901 | 901 | wpinv_checkout_validate_agree_to_terms(); |
| 902 | 902 | } |
| 903 | 903 | |
| 904 | - $valid_data['logged_in_user'] = wpinv_checkout_validate_logged_in_user(); |
|
| 904 | + $valid_data['logged_in_user'] = wpinv_checkout_validate_logged_in_user(); |
|
| 905 | 905 | |
| 906 | 906 | // Return collected data |
| 907 | 907 | return $valid_data; |
@@ -912,26 +912,26 @@ discard block |
||
| 912 | 912 | |
| 913 | 913 | $invoice = wpinv_get_invoice_cart(); |
| 914 | 914 | $has_subscription = $invoice->is_recurring(); |
| 915 | - if ( empty( $invoice ) ) { |
|
| 916 | - wpinv_set_error( 'invalid_invoice', __( 'Your cart is empty.', 'invoicing' ) ); |
|
| 915 | + if (empty($invoice)) { |
|
| 916 | + wpinv_set_error('invalid_invoice', __('Your cart is empty.', 'invoicing')); |
|
| 917 | 917 | return $gateway; |
| 918 | 918 | } |
| 919 | 919 | |
| 920 | 920 | // Check if a gateway value is present |
| 921 | - if ( !empty( $_REQUEST['wpi-gateway'] ) ) { |
|
| 922 | - $gateway = sanitize_text_field( $_REQUEST['wpi-gateway'] ); |
|
| 921 | + if (!empty($_REQUEST['wpi-gateway'])) { |
|
| 922 | + $gateway = sanitize_text_field($_REQUEST['wpi-gateway']); |
|
| 923 | 923 | |
| 924 | - if ( $invoice->is_free() ) { |
|
| 924 | + if ($invoice->is_free()) { |
|
| 925 | 925 | $gateway = 'manual'; |
| 926 | - } elseif ( !wpinv_is_gateway_active( $gateway ) ) { |
|
| 927 | - wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway is not enabled', 'invoicing' ) ); |
|
| 928 | - } elseif ( $has_subscription && !wpinv_gateway_support_subscription( $gateway ) ) { |
|
| 929 | - wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway doesnot support subscription payment', 'invoicing' ) ); |
|
| 926 | + } elseif (!wpinv_is_gateway_active($gateway)) { |
|
| 927 | + wpinv_set_error('invalid_gateway', __('The selected payment gateway is not enabled', 'invoicing')); |
|
| 928 | + } elseif ($has_subscription && !wpinv_gateway_support_subscription($gateway)) { |
|
| 929 | + wpinv_set_error('invalid_gateway', __('The selected payment gateway doesnot support subscription payment', 'invoicing')); |
|
| 930 | 930 | } |
| 931 | 931 | } |
| 932 | 932 | |
| 933 | - if ( $has_subscription && count( wpinv_get_cart_contents() ) > 1 ) { |
|
| 934 | - wpinv_set_error( 'subscription_invalid', __( 'Only one subscription may be purchased through payment per checkout.', 'invoicing' ) ); |
|
| 933 | + if ($has_subscription && count(wpinv_get_cart_contents()) > 1) { |
|
| 934 | + wpinv_set_error('subscription_invalid', __('Only one subscription may be purchased through payment per checkout.', 'invoicing')); |
|
| 935 | 935 | } |
| 936 | 936 | |
| 937 | 937 | return $gateway; |
@@ -943,10 +943,10 @@ discard block |
||
| 943 | 943 | |
| 944 | 944 | $error = false; |
| 945 | 945 | // If we have discounts, loop through them |
| 946 | - if ( ! empty( $discounts ) ) { |
|
| 947 | - foreach ( $discounts as $discount ) { |
|
| 946 | + if (!empty($discounts)) { |
|
| 947 | + foreach ($discounts as $discount) { |
|
| 948 | 948 | // Check if valid |
| 949 | - if ( !wpinv_is_discount_valid( $discount, get_current_user_id() ) ) { |
|
| 949 | + if (!wpinv_is_discount_valid($discount, get_current_user_id())) { |
|
| 950 | 950 | // Discount is not valid |
| 951 | 951 | $error = true; |
| 952 | 952 | } |
@@ -956,20 +956,20 @@ discard block |
||
| 956 | 956 | return NULL; |
| 957 | 957 | } |
| 958 | 958 | |
| 959 | - if ( $error && !wpinv_get_errors() ) { |
|
| 960 | - wpinv_set_error( 'invalid_discount', __( 'Discount code you entered is invalid', 'invoicing' ) ); |
|
| 959 | + if ($error && !wpinv_get_errors()) { |
|
| 960 | + wpinv_set_error('invalid_discount', __('Discount code you entered is invalid', 'invoicing')); |
|
| 961 | 961 | } |
| 962 | 962 | |
| 963 | - return implode( ',', $discounts ); |
|
| 963 | + return implode(',', $discounts); |
|
| 964 | 964 | } |
| 965 | 965 | |
| 966 | 966 | function wpinv_checkout_validate_cc() { |
| 967 | 967 | $card_data = wpinv_checkout_get_cc_info(); |
| 968 | 968 | |
| 969 | 969 | // Validate the card zip |
| 970 | - if ( !empty( $card_data['wpinv_zip'] ) ) { |
|
| 971 | - if ( !wpinv_checkout_validate_cc_zip( $card_data['wpinv_zip'], $card_data['wpinv_country'] ) ) { |
|
| 972 | - wpinv_set_error( 'invalid_cc_zip', __( 'The zip / postcode you entered for your billing address is invalid', 'invoicing' ) ); |
|
| 970 | + if (!empty($card_data['wpinv_zip'])) { |
|
| 971 | + if (!wpinv_checkout_validate_cc_zip($card_data['wpinv_zip'], $card_data['wpinv_country'])) { |
|
| 972 | + wpinv_set_error('invalid_cc_zip', __('The zip / postcode you entered for your billing address is invalid', 'invoicing')); |
|
| 973 | 973 | } |
| 974 | 974 | } |
| 975 | 975 | |
@@ -979,28 +979,28 @@ discard block |
||
| 979 | 979 | |
| 980 | 980 | function wpinv_checkout_get_cc_info() { |
| 981 | 981 | $cc_info = array(); |
| 982 | - $cc_info['card_name'] = isset( $_POST['card_name'] ) ? sanitize_text_field( $_POST['card_name'] ) : ''; |
|
| 983 | - $cc_info['card_number'] = isset( $_POST['card_number'] ) ? sanitize_text_field( $_POST['card_number'] ) : ''; |
|
| 984 | - $cc_info['card_cvc'] = isset( $_POST['card_cvc'] ) ? sanitize_text_field( $_POST['card_cvc'] ) : ''; |
|
| 985 | - $cc_info['card_exp_month'] = isset( $_POST['card_exp_month'] ) ? sanitize_text_field( $_POST['card_exp_month'] ) : ''; |
|
| 986 | - $cc_info['card_exp_year'] = isset( $_POST['card_exp_year'] ) ? sanitize_text_field( $_POST['card_exp_year'] ) : ''; |
|
| 987 | - $cc_info['card_address'] = isset( $_POST['wpinv_address'] ) ? sanitize_text_field( $_POST['wpinv_address'] ) : ''; |
|
| 988 | - $cc_info['card_city'] = isset( $_POST['wpinv_city'] ) ? sanitize_text_field( $_POST['wpinv_city'] ) : ''; |
|
| 989 | - $cc_info['card_state'] = isset( $_POST['wpinv_state'] ) ? sanitize_text_field( $_POST['wpinv_state'] ) : ''; |
|
| 990 | - $cc_info['card_country'] = isset( $_POST['wpinv_country'] ) ? sanitize_text_field( $_POST['wpinv_country'] ) : ''; |
|
| 991 | - $cc_info['card_zip'] = isset( $_POST['wpinv_zip'] ) ? sanitize_text_field( $_POST['wpinv_zip'] ) : ''; |
|
| 982 | + $cc_info['card_name'] = isset($_POST['card_name']) ? sanitize_text_field($_POST['card_name']) : ''; |
|
| 983 | + $cc_info['card_number'] = isset($_POST['card_number']) ? sanitize_text_field($_POST['card_number']) : ''; |
|
| 984 | + $cc_info['card_cvc'] = isset($_POST['card_cvc']) ? sanitize_text_field($_POST['card_cvc']) : ''; |
|
| 985 | + $cc_info['card_exp_month'] = isset($_POST['card_exp_month']) ? sanitize_text_field($_POST['card_exp_month']) : ''; |
|
| 986 | + $cc_info['card_exp_year'] = isset($_POST['card_exp_year']) ? sanitize_text_field($_POST['card_exp_year']) : ''; |
|
| 987 | + $cc_info['card_address'] = isset($_POST['wpinv_address']) ? sanitize_text_field($_POST['wpinv_address']) : ''; |
|
| 988 | + $cc_info['card_city'] = isset($_POST['wpinv_city']) ? sanitize_text_field($_POST['wpinv_city']) : ''; |
|
| 989 | + $cc_info['card_state'] = isset($_POST['wpinv_state']) ? sanitize_text_field($_POST['wpinv_state']) : ''; |
|
| 990 | + $cc_info['card_country'] = isset($_POST['wpinv_country']) ? sanitize_text_field($_POST['wpinv_country']) : ''; |
|
| 991 | + $cc_info['card_zip'] = isset($_POST['wpinv_zip']) ? sanitize_text_field($_POST['wpinv_zip']) : ''; |
|
| 992 | 992 | |
| 993 | 993 | // Return cc info |
| 994 | 994 | return $cc_info; |
| 995 | 995 | } |
| 996 | 996 | |
| 997 | -function wpinv_checkout_validate_cc_zip( $zip = 0, $country_code = '' ) { |
|
| 997 | +function wpinv_checkout_validate_cc_zip($zip = 0, $country_code = '') { |
|
| 998 | 998 | $ret = false; |
| 999 | 999 | |
| 1000 | - if ( empty( $zip ) || empty( $country_code ) ) |
|
| 1000 | + if (empty($zip) || empty($country_code)) |
|
| 1001 | 1001 | return $ret; |
| 1002 | 1002 | |
| 1003 | - $country_code = strtoupper( $country_code ); |
|
| 1003 | + $country_code = strtoupper($country_code); |
|
| 1004 | 1004 | |
| 1005 | 1005 | $zip_regex = array( |
| 1006 | 1006 | "AD" => "AD\d{3}", |
@@ -1160,17 +1160,17 @@ discard block |
||
| 1160 | 1160 | "ZM" => "\d{5}" |
| 1161 | 1161 | ); |
| 1162 | 1162 | |
| 1163 | - if ( ! isset ( $zip_regex[ $country_code ] ) || preg_match( "/" . $zip_regex[ $country_code ] . "/i", $zip ) ) |
|
| 1163 | + if (!isset ($zip_regex[$country_code]) || preg_match("/" . $zip_regex[$country_code] . "/i", $zip)) |
|
| 1164 | 1164 | $ret = true; |
| 1165 | 1165 | |
| 1166 | - return apply_filters( 'wpinv_is_zip_valid', $ret, $zip, $country_code ); |
|
| 1166 | + return apply_filters('wpinv_is_zip_valid', $ret, $zip, $country_code); |
|
| 1167 | 1167 | } |
| 1168 | 1168 | |
| 1169 | 1169 | function wpinv_checkout_validate_agree_to_terms() { |
| 1170 | 1170 | // Validate agree to terms |
| 1171 | - if ( ! isset( $_POST['wpi_agree_to_terms'] ) || $_POST['wpi_agree_to_terms'] != 1 ) { |
|
| 1171 | + if (!isset($_POST['wpi_agree_to_terms']) || $_POST['wpi_agree_to_terms'] != 1) { |
|
| 1172 | 1172 | // User did not agree |
| 1173 | - wpinv_set_error( 'agree_to_terms', apply_filters( 'wpinv_agree_to_terms_text', __( 'You must agree to the terms of use', 'invoicing' ) ) ); |
|
| 1173 | + wpinv_set_error('agree_to_terms', apply_filters('wpinv_agree_to_terms_text', __('You must agree to the terms of use', 'invoicing'))); |
|
| 1174 | 1174 | } |
| 1175 | 1175 | } |
| 1176 | 1176 | |
@@ -1183,36 +1183,36 @@ discard block |
||
| 1183 | 1183 | ); |
| 1184 | 1184 | |
| 1185 | 1185 | // Verify there is a user_ID |
| 1186 | - if ( $user_ID > 0 ) { |
|
| 1186 | + if ($user_ID > 0) { |
|
| 1187 | 1187 | // Get the logged in user data |
| 1188 | - $user_data = get_userdata( $user_ID ); |
|
| 1189 | - $required_fields = wpinv_checkout_required_fields(); |
|
| 1188 | + $user_data = get_userdata($user_ID); |
|
| 1189 | + $required_fields = wpinv_checkout_required_fields(); |
|
| 1190 | 1190 | |
| 1191 | 1191 | // Loop through required fields and show error messages |
| 1192 | - if ( !empty( $required_fields ) ) { |
|
| 1193 | - foreach ( $required_fields as $field_name => $value ) { |
|
| 1194 | - if ( in_array( $value, $required_fields ) && empty( $_POST[ 'wpinv_' . $field_name ] ) ) { |
|
| 1195 | - wpinv_set_error( $value['error_id'], $value['error_message'] ); |
|
| 1192 | + if (!empty($required_fields)) { |
|
| 1193 | + foreach ($required_fields as $field_name => $value) { |
|
| 1194 | + if (in_array($value, $required_fields) && empty($_POST['wpinv_' . $field_name])) { |
|
| 1195 | + wpinv_set_error($value['error_id'], $value['error_message']); |
|
| 1196 | 1196 | } |
| 1197 | 1197 | } |
| 1198 | 1198 | } |
| 1199 | 1199 | |
| 1200 | 1200 | // Verify data |
| 1201 | - if ( $user_data ) { |
|
| 1201 | + if ($user_data) { |
|
| 1202 | 1202 | // Collected logged in user data |
| 1203 | 1203 | $valid_user_data = array( |
| 1204 | 1204 | 'user_id' => $user_ID, |
| 1205 | - 'email' => isset( $_POST['wpinv_email'] ) ? sanitize_email( $_POST['wpinv_email'] ) : $user_data->user_email, |
|
| 1206 | - 'first_name' => isset( $_POST['wpinv_first_name'] ) && ! empty( $_POST['wpinv_first_name'] ) ? sanitize_text_field( $_POST['wpinv_first_name'] ) : $user_data->first_name, |
|
| 1207 | - 'last_name' => isset( $_POST['wpinv_last_name'] ) && ! empty( $_POST['wpinv_last_name'] ) ? sanitize_text_field( $_POST['wpinv_last_name'] ) : $user_data->last_name, |
|
| 1205 | + 'email' => isset($_POST['wpinv_email']) ? sanitize_email($_POST['wpinv_email']) : $user_data->user_email, |
|
| 1206 | + 'first_name' => isset($_POST['wpinv_first_name']) && !empty($_POST['wpinv_first_name']) ? sanitize_text_field($_POST['wpinv_first_name']) : $user_data->first_name, |
|
| 1207 | + 'last_name' => isset($_POST['wpinv_last_name']) && !empty($_POST['wpinv_last_name']) ? sanitize_text_field($_POST['wpinv_last_name']) : $user_data->last_name, |
|
| 1208 | 1208 | ); |
| 1209 | 1209 | |
| 1210 | - if ( !empty( $_POST[ 'wpinv_email' ] ) && !is_email( $_POST[ 'wpinv_email' ] ) ) { |
|
| 1211 | - wpinv_set_error( 'invalid_email', __( 'Please enter a valid email address', 'invoicing' ) ); |
|
| 1210 | + if (!empty($_POST['wpinv_email']) && !is_email($_POST['wpinv_email'])) { |
|
| 1211 | + wpinv_set_error('invalid_email', __('Please enter a valid email address', 'invoicing')); |
|
| 1212 | 1212 | } |
| 1213 | 1213 | } else { |
| 1214 | 1214 | // Set invalid user error |
| 1215 | - wpinv_set_error( 'invalid_user', __( 'The user billing information is invalid', 'invoicing' ) ); |
|
| 1215 | + wpinv_set_error('invalid_user', __('The user billing information is invalid', 'invoicing')); |
|
| 1216 | 1216 | } |
| 1217 | 1217 | } |
| 1218 | 1218 | |
@@ -1220,21 +1220,21 @@ discard block |
||
| 1220 | 1220 | return $valid_user_data; |
| 1221 | 1221 | } |
| 1222 | 1222 | |
| 1223 | -function wpinv_checkout_form_get_user( $valid_data = array() ) { |
|
| 1223 | +function wpinv_checkout_form_get_user($valid_data = array()) { |
|
| 1224 | 1224 | // Initialize user |
| 1225 | 1225 | $user = false; |
| 1226 | - $is_ajax = defined( 'DOING_AJAX' ) && DOING_AJAX; |
|
| 1226 | + $is_ajax = defined('DOING_AJAX') && DOING_AJAX; |
|
| 1227 | 1227 | |
| 1228 | 1228 | /*if ( $is_ajax ) { |
| 1229 | 1229 | // Do not create or login the user during the ajax submission (check for errors only) |
| 1230 | 1230 | return true; |
| 1231 | - } else */if ( is_user_logged_in() ) { |
|
| 1231 | + } else */if (is_user_logged_in()) { |
|
| 1232 | 1232 | // Set the valid user as the logged in collected data |
| 1233 | 1233 | $user = $valid_data['logged_in_user']; |
| 1234 | 1234 | } |
| 1235 | 1235 | |
| 1236 | 1236 | // Verify we have an user |
| 1237 | - if ( false === $user || empty( $user ) ) { |
|
| 1237 | + if (false === $user || empty($user)) { |
|
| 1238 | 1238 | // Return false |
| 1239 | 1239 | return false; |
| 1240 | 1240 | } |
@@ -1253,11 +1253,11 @@ discard block |
||
| 1253 | 1253 | 'zip', |
| 1254 | 1254 | ); |
| 1255 | 1255 | |
| 1256 | - foreach ( $address_fields as $field ) { |
|
| 1257 | - $user[$field] = !empty( $_POST['wpinv_' . $field] ) ? sanitize_text_field( $_POST['wpinv_' . $field] ) : false; |
|
| 1256 | + foreach ($address_fields as $field) { |
|
| 1257 | + $user[$field] = !empty($_POST['wpinv_' . $field]) ? sanitize_text_field($_POST['wpinv_' . $field]) : false; |
|
| 1258 | 1258 | |
| 1259 | - if ( !empty( $user['user_id'] ) ) { |
|
| 1260 | - update_user_meta( $user['user_id'], '_wpinv_' . $field, $user[$field] ); |
|
| 1259 | + if (!empty($user['user_id'])) { |
|
| 1260 | + update_user_meta($user['user_id'], '_wpinv_' . $field, $user[$field]); |
|
| 1261 | 1261 | } |
| 1262 | 1262 | } |
| 1263 | 1263 | |
@@ -1265,28 +1265,28 @@ discard block |
||
| 1265 | 1265 | return $user; |
| 1266 | 1266 | } |
| 1267 | 1267 | |
| 1268 | -function wpinv_set_checkout_session( $invoice_data = array() ) { |
|
| 1268 | +function wpinv_set_checkout_session($invoice_data = array()) { |
|
| 1269 | 1269 | global $wpi_session; |
| 1270 | 1270 | |
| 1271 | - return $wpi_session->set( 'wpinv_checkout', $invoice_data ); |
|
| 1271 | + return $wpi_session->set('wpinv_checkout', $invoice_data); |
|
| 1272 | 1272 | } |
| 1273 | 1273 | |
| 1274 | 1274 | function wpinv_get_checkout_session() { |
| 1275 | 1275 | global $wpi_session; |
| 1276 | 1276 | |
| 1277 | - return $wpi_session->get( 'wpinv_checkout' ); |
|
| 1277 | + return $wpi_session->get('wpinv_checkout'); |
|
| 1278 | 1278 | } |
| 1279 | 1279 | |
| 1280 | 1280 | function wpinv_empty_cart() { |
| 1281 | 1281 | global $wpi_session; |
| 1282 | 1282 | |
| 1283 | 1283 | // Remove cart contents |
| 1284 | - $wpi_session->set( 'wpinv_checkout', NULL ); |
|
| 1284 | + $wpi_session->set('wpinv_checkout', NULL); |
|
| 1285 | 1285 | |
| 1286 | 1286 | // Remove all cart fees |
| 1287 | - $wpi_session->set( 'wpi_cart_fees', NULL ); |
|
| 1287 | + $wpi_session->set('wpi_cart_fees', NULL); |
|
| 1288 | 1288 | |
| 1289 | - do_action( 'wpinv_empty_cart' ); |
|
| 1289 | + do_action('wpinv_empty_cart'); |
|
| 1290 | 1290 | } |
| 1291 | 1291 | |
| 1292 | 1292 | function wpinv_process_checkout() { |
@@ -1298,42 +1298,42 @@ discard block |
||
| 1298 | 1298 | |
| 1299 | 1299 | $wpi_checkout_id = $invoice->ID; |
| 1300 | 1300 | |
| 1301 | - do_action( 'wpinv_pre_process_checkout' ); |
|
| 1301 | + do_action('wpinv_pre_process_checkout'); |
|
| 1302 | 1302 | |
| 1303 | - if ( !wpinv_get_cart_contents() ) { // Make sure the cart isn't empty |
|
| 1303 | + if (!wpinv_get_cart_contents()) { // Make sure the cart isn't empty |
|
| 1304 | 1304 | $valid_data = false; |
| 1305 | - wpinv_set_error( 'empty_cart', __( 'Your cart is empty', 'invoicing' ) ); |
|
| 1305 | + wpinv_set_error('empty_cart', __('Your cart is empty', 'invoicing')); |
|
| 1306 | 1306 | } else { |
| 1307 | 1307 | // Validate the form $_POST data |
| 1308 | 1308 | $valid_data = wpinv_validate_checkout_fields(); |
| 1309 | 1309 | |
| 1310 | 1310 | // Allow themes and plugins to hook to errors |
| 1311 | - do_action( 'wpinv_checkout_error_checks', $valid_data, $_POST ); |
|
| 1311 | + do_action('wpinv_checkout_error_checks', $valid_data, $_POST); |
|
| 1312 | 1312 | } |
| 1313 | 1313 | |
| 1314 | - $is_ajax = defined( 'DOING_AJAX' ) && DOING_AJAX; |
|
| 1314 | + $is_ajax = defined('DOING_AJAX') && DOING_AJAX; |
|
| 1315 | 1315 | |
| 1316 | 1316 | // Validate the user |
| 1317 | - $user = wpinv_checkout_form_get_user( $valid_data ); |
|
| 1317 | + $user = wpinv_checkout_form_get_user($valid_data); |
|
| 1318 | 1318 | |
| 1319 | 1319 | // Let extensions validate fields after user is logged in if user has used login/registration form |
| 1320 | - do_action( 'wpinv_checkout_user_error_checks', $user, $valid_data, $_POST ); |
|
| 1320 | + do_action('wpinv_checkout_user_error_checks', $user, $valid_data, $_POST); |
|
| 1321 | 1321 | |
| 1322 | - if ( false === $valid_data || wpinv_get_errors() || ! $user ) { |
|
| 1323 | - if ( $is_ajax ) { |
|
| 1324 | - do_action( 'wpinv_ajax_checkout_errors' ); |
|
| 1322 | + if (false === $valid_data || wpinv_get_errors() || !$user) { |
|
| 1323 | + if ($is_ajax) { |
|
| 1324 | + do_action('wpinv_ajax_checkout_errors'); |
|
| 1325 | 1325 | die(); |
| 1326 | 1326 | } else { |
| 1327 | 1327 | return false; |
| 1328 | 1328 | } |
| 1329 | 1329 | } |
| 1330 | 1330 | |
| 1331 | - if ( $is_ajax ) { |
|
| 1331 | + if ($is_ajax) { |
|
| 1332 | 1332 | // Save address fields. |
| 1333 | - $address_fields = array( 'first_name', 'last_name', 'phone', 'address', 'city', 'country', 'state', 'zip', 'company' ); |
|
| 1334 | - foreach ( $address_fields as $field ) { |
|
| 1335 | - if ( isset( $user[$field] ) ) { |
|
| 1336 | - $invoice->set( $field, $user[$field] ); |
|
| 1333 | + $address_fields = array('first_name', 'last_name', 'phone', 'address', 'city', 'country', 'state', 'zip', 'company'); |
|
| 1334 | + foreach ($address_fields as $field) { |
|
| 1335 | + if (isset($user[$field])) { |
|
| 1336 | + $invoice->set($field, $user[$field]); |
|
| 1337 | 1337 | } |
| 1338 | 1338 | |
| 1339 | 1339 | $invoice->save(); |
@@ -1341,15 +1341,15 @@ discard block |
||
| 1341 | 1341 | |
| 1342 | 1342 | $response['success'] = true; |
| 1343 | 1343 | $response['data']['subtotal'] = $invoice->get_subtotal(); |
| 1344 | - $response['data']['subtotalf'] = $invoice->get_subtotal( true ); |
|
| 1344 | + $response['data']['subtotalf'] = $invoice->get_subtotal(true); |
|
| 1345 | 1345 | $response['data']['discount'] = $invoice->get_discount(); |
| 1346 | - $response['data']['discountf'] = $invoice->get_discount( true ); |
|
| 1346 | + $response['data']['discountf'] = $invoice->get_discount(true); |
|
| 1347 | 1347 | $response['data']['tax'] = $invoice->get_tax(); |
| 1348 | - $response['data']['taxf'] = $invoice->get_tax( true ); |
|
| 1348 | + $response['data']['taxf'] = $invoice->get_tax(true); |
|
| 1349 | 1349 | $response['data']['total'] = $invoice->get_total(); |
| 1350 | - $response['data']['totalf'] = $invoice->get_total( true ); |
|
| 1350 | + $response['data']['totalf'] = $invoice->get_total(true); |
|
| 1351 | 1351 | |
| 1352 | - wp_send_json( $response ); |
|
| 1352 | + wp_send_json($response); |
|
| 1353 | 1353 | } |
| 1354 | 1354 | |
| 1355 | 1355 | $user_info = array( |
@@ -1371,42 +1371,42 @@ discard block |
||
| 1371 | 1371 | |
| 1372 | 1372 | // Setup invoice information |
| 1373 | 1373 | $invoice_data = array( |
| 1374 | - 'invoice_id' => !empty( $invoice ) ? $invoice->ID : 0, |
|
| 1374 | + 'invoice_id' => !empty($invoice) ? $invoice->ID : 0, |
|
| 1375 | 1375 | 'items' => $cart_items, |
| 1376 | 1376 | 'cart_discounts' => $discounts, |
| 1377 | - 'fees' => wpinv_get_cart_fees(), // Any arbitrary fees that have been added to the cart |
|
| 1378 | - 'subtotal' => wpinv_get_cart_subtotal( $cart_items ), // Amount before taxes and discounts |
|
| 1379 | - 'discount' => wpinv_get_cart_items_discount_amount( $cart_items, $discounts ), // Discounted amount |
|
| 1380 | - 'tax' => wpinv_get_cart_tax( $cart_items ), // Taxed amount |
|
| 1381 | - 'price' => wpinv_get_cart_total( $cart_items, $discounts ), // Amount after taxes |
|
| 1377 | + 'fees' => wpinv_get_cart_fees(), // Any arbitrary fees that have been added to the cart |
|
| 1378 | + 'subtotal' => wpinv_get_cart_subtotal($cart_items), // Amount before taxes and discounts |
|
| 1379 | + 'discount' => wpinv_get_cart_items_discount_amount($cart_items, $discounts), // Discounted amount |
|
| 1380 | + 'tax' => wpinv_get_cart_tax($cart_items), // Taxed amount |
|
| 1381 | + 'price' => wpinv_get_cart_total($cart_items, $discounts), // Amount after taxes |
|
| 1382 | 1382 | 'invoice_key' => $invoice->get_key() ? $invoice->get_key() : $invoice->generate_key(), |
| 1383 | 1383 | 'user_email' => $user['email'], |
| 1384 | - 'date' => date( 'Y-m-d H:i:s', current_time( 'timestamp' ) ), |
|
| 1385 | - 'user_info' => stripslashes_deep( $user_info ), |
|
| 1384 | + 'date' => date('Y-m-d H:i:s', current_time('timestamp')), |
|
| 1385 | + 'user_info' => stripslashes_deep($user_info), |
|
| 1386 | 1386 | 'post_data' => $_POST, |
| 1387 | 1387 | 'cart_details' => $cart_items, |
| 1388 | 1388 | 'gateway' => $valid_data['gateway'], |
| 1389 | 1389 | 'card_info' => $valid_data['cc_info'] |
| 1390 | 1390 | ); |
| 1391 | 1391 | |
| 1392 | - $vat_info = $wpinv_euvat->current_vat_data(); |
|
| 1393 | - if ( is_array( $vat_info ) ) { |
|
| 1392 | + $vat_info = $wpinv_euvat->current_vat_data(); |
|
| 1393 | + if (is_array($vat_info)) { |
|
| 1394 | 1394 | $invoice_data['user_info']['vat_number'] = $vat_info['number']; |
| 1395 | 1395 | $invoice_data['user_info']['vat_rate'] = wpinv_get_tax_rate($invoice_data['user_info']['country'], $invoice_data['user_info']['state']); |
| 1396 | - $invoice_data['user_info']['adddress_confirmed'] = isset($vat_info['adddress_confirmed']) ? $vat_info['adddress_confirmed'] : false; |
|
| 1396 | + $invoice_data['user_info']['adddress_confirmed'] = isset($vat_info['adddress_confirmed']) ? $vat_info['adddress_confirmed'] : false; |
|
| 1397 | 1397 | |
| 1398 | 1398 | // Add the VAT rate to each item in the cart |
| 1399 | - foreach( $invoice_data['cart_details'] as $key => $item_data) { |
|
| 1399 | + foreach ($invoice_data['cart_details'] as $key => $item_data) { |
|
| 1400 | 1400 | $rate = wpinv_get_tax_rate($invoice_data['user_info']['country'], $invoice_data['user_info']['state'], $item_data['id']); |
| 1401 | - $invoice_data['cart_details'][$key]['vat_rate'] = wpinv_round_amount( $rate, 4 ); |
|
| 1401 | + $invoice_data['cart_details'][$key]['vat_rate'] = wpinv_round_amount($rate, 4); |
|
| 1402 | 1402 | } |
| 1403 | 1403 | } |
| 1404 | 1404 | |
| 1405 | 1405 | // Save vat fields. |
| 1406 | - $address_fields = array( 'vat_number', 'vat_rate', 'adddress_confirmed' ); |
|
| 1407 | - foreach ( $address_fields as $field ) { |
|
| 1408 | - if ( isset( $invoice_data['user_info'][$field] ) ) { |
|
| 1409 | - $invoice->set( $field, $invoice_data['user_info'][$field] ); |
|
| 1406 | + $address_fields = array('vat_number', 'vat_rate', 'adddress_confirmed'); |
|
| 1407 | + foreach ($address_fields as $field) { |
|
| 1408 | + if (isset($invoice_data['user_info'][$field])) { |
|
| 1409 | + $invoice->set($field, $invoice_data['user_info'][$field]); |
|
| 1410 | 1410 | } |
| 1411 | 1411 | |
| 1412 | 1412 | $invoice->save(); |
@@ -1416,49 +1416,49 @@ discard block |
||
| 1416 | 1416 | $valid_data['user'] = $user; |
| 1417 | 1417 | |
| 1418 | 1418 | // Allow themes and plugins to hook before the gateway |
| 1419 | - do_action( 'wpinv_checkout_before_gateway', $_POST, $user_info, $valid_data ); |
|
| 1419 | + do_action('wpinv_checkout_before_gateway', $_POST, $user_info, $valid_data); |
|
| 1420 | 1420 | |
| 1421 | 1421 | // If the total amount in the cart is 0, send to the manual gateway. This emulates a free invoice |
| 1422 | - if ( !$invoice_data['price'] ) { |
|
| 1422 | + if (!$invoice_data['price']) { |
|
| 1423 | 1423 | // Revert to manual |
| 1424 | 1424 | $invoice_data['gateway'] = 'manual'; |
| 1425 | 1425 | $_POST['wpi-gateway'] = 'manual'; |
| 1426 | 1426 | } |
| 1427 | 1427 | |
| 1428 | 1428 | // Allow the invoice data to be modified before it is sent to the gateway |
| 1429 | - $invoice_data = apply_filters( 'wpinv_data_before_gateway', $invoice_data, $valid_data ); |
|
| 1429 | + $invoice_data = apply_filters('wpinv_data_before_gateway', $invoice_data, $valid_data); |
|
| 1430 | 1430 | |
| 1431 | 1431 | // Setup the data we're storing in the purchase session |
| 1432 | 1432 | $session_data = $invoice_data; |
| 1433 | 1433 | // Make sure credit card numbers are never stored in sessions |
| 1434 | - if ( !empty( $session_data['card_info']['card_number'] ) ) { |
|
| 1435 | - unset( $session_data['card_info']['card_number'] ); |
|
| 1434 | + if (!empty($session_data['card_info']['card_number'])) { |
|
| 1435 | + unset($session_data['card_info']['card_number']); |
|
| 1436 | 1436 | } |
| 1437 | 1437 | |
| 1438 | 1438 | // Used for showing item links to non logged-in users after purchase, and for other plugins needing purchase data. |
| 1439 | - wpinv_set_checkout_session( $invoice_data ); |
|
| 1439 | + wpinv_set_checkout_session($invoice_data); |
|
| 1440 | 1440 | |
| 1441 | 1441 | // Set gateway |
| 1442 | - $invoice->update_meta( '_wpinv_gateway', $invoice_data['gateway'] ); |
|
| 1443 | - $invoice->update_meta( '_wpinv_mode', ( wpinv_is_test_mode( $invoice_data['gateway'] ) ? 'test' : 'live' ) ); |
|
| 1444 | - $invoice->update_meta( '_wpinv_checkout', true ); |
|
| 1442 | + $invoice->update_meta('_wpinv_gateway', $invoice_data['gateway']); |
|
| 1443 | + $invoice->update_meta('_wpinv_mode', (wpinv_is_test_mode($invoice_data['gateway']) ? 'test' : 'live')); |
|
| 1444 | + $invoice->update_meta('_wpinv_checkout', true); |
|
| 1445 | 1445 | |
| 1446 | - do_action( 'wpinv_checkout_before_send_to_gateway', $invoice, $invoice_data ); |
|
| 1446 | + do_action('wpinv_checkout_before_send_to_gateway', $invoice, $invoice_data); |
|
| 1447 | 1447 | |
| 1448 | 1448 | // Send info to the gateway for payment processing |
| 1449 | - wpinv_send_to_gateway( $invoice_data['gateway'], $invoice_data ); |
|
| 1449 | + wpinv_send_to_gateway($invoice_data['gateway'], $invoice_data); |
|
| 1450 | 1450 | die(); |
| 1451 | 1451 | } |
| 1452 | -add_action( 'wpinv_payment', 'wpinv_process_checkout' ); |
|
| 1452 | +add_action('wpinv_payment', 'wpinv_process_checkout'); |
|
| 1453 | 1453 | |
| 1454 | -function wpinv_get_invoices( $args ) { |
|
| 1455 | - $args = wp_parse_args( $args, array( |
|
| 1456 | - 'status' => array_keys( wpinv_get_invoice_statuses() ), |
|
| 1454 | +function wpinv_get_invoices($args) { |
|
| 1455 | + $args = wp_parse_args($args, array( |
|
| 1456 | + 'status' => array_keys(wpinv_get_invoice_statuses()), |
|
| 1457 | 1457 | 'type' => 'wpi_invoice', |
| 1458 | 1458 | 'parent' => null, |
| 1459 | 1459 | 'user' => null, |
| 1460 | 1460 | 'email' => '', |
| 1461 | - 'limit' => get_option( 'posts_per_page' ), |
|
| 1461 | + 'limit' => get_option('posts_per_page'), |
|
| 1462 | 1462 | 'offset' => null, |
| 1463 | 1463 | 'page' => 1, |
| 1464 | 1464 | 'exclude' => array(), |
@@ -1466,7 +1466,7 @@ discard block |
||
| 1466 | 1466 | 'order' => 'DESC', |
| 1467 | 1467 | 'return' => 'objects', |
| 1468 | 1468 | 'paginate' => false, |
| 1469 | - ) ); |
|
| 1469 | + )); |
|
| 1470 | 1470 | |
| 1471 | 1471 | // Handle some BW compatibility arg names where wp_query args differ in naming. |
| 1472 | 1472 | $map_legacy = array( |
@@ -1479,20 +1479,20 @@ discard block |
||
| 1479 | 1479 | 'paged' => 'page', |
| 1480 | 1480 | ); |
| 1481 | 1481 | |
| 1482 | - foreach ( $map_legacy as $from => $to ) { |
|
| 1483 | - if ( isset( $args[ $from ] ) ) { |
|
| 1484 | - $args[ $to ] = $args[ $from ]; |
|
| 1482 | + foreach ($map_legacy as $from => $to) { |
|
| 1483 | + if (isset($args[$from])) { |
|
| 1484 | + $args[$to] = $args[$from]; |
|
| 1485 | 1485 | } |
| 1486 | 1486 | } |
| 1487 | 1487 | |
| 1488 | - $wpinv_cpt = isset( $_REQUEST[ 'wpinv-cpt' ] ) ? $_REQUEST[ 'wpinv-cpt' ] : ''; |
|
| 1488 | + $wpinv_cpt = isset($_REQUEST['wpinv-cpt']) ? $_REQUEST['wpinv-cpt'] : ''; |
|
| 1489 | 1489 | |
| 1490 | - if ( get_query_var( 'paged' ) && 'wpi_invoice' == $wpinv_cpt ) |
|
| 1490 | + if (get_query_var('paged') && 'wpi_invoice' == $wpinv_cpt) |
|
| 1491 | 1491 | $args['page'] = get_query_var('paged'); |
| 1492 | - else if ( get_query_var( 'page' ) && 'wpi_invoice' == $wpinv_cpt ) |
|
| 1493 | - $args['page'] = get_query_var( 'page' ); |
|
| 1494 | - else if ( !empty( $args[ 'page' ] ) ) |
|
| 1495 | - $args['page'] = $args[ 'page' ]; |
|
| 1492 | + else if (get_query_var('page') && 'wpi_invoice' == $wpinv_cpt) |
|
| 1493 | + $args['page'] = get_query_var('page'); |
|
| 1494 | + else if (!empty($args['page'])) |
|
| 1495 | + $args['page'] = $args['page']; |
|
| 1496 | 1496 | else |
| 1497 | 1497 | $args['page'] = 1; |
| 1498 | 1498 | |
@@ -1505,47 +1505,47 @@ discard block |
||
| 1505 | 1505 | 'post_status' => $args['status'], |
| 1506 | 1506 | 'posts_per_page' => $args['limit'], |
| 1507 | 1507 | 'meta_query' => array(), |
| 1508 | - 'date_query' => !empty( $args['date_query'] ) ? $args['date_query'] : array(), |
|
| 1508 | + 'date_query' => !empty($args['date_query']) ? $args['date_query'] : array(), |
|
| 1509 | 1509 | 'fields' => 'ids', |
| 1510 | 1510 | 'orderby' => $args['orderby'], |
| 1511 | 1511 | 'order' => $args['order'], |
| 1512 | 1512 | ); |
| 1513 | 1513 | |
| 1514 | - if ( !empty( $args['user'] ) ) { |
|
| 1515 | - $wp_query_args['author'] = absint( $args['user'] ); |
|
| 1514 | + if (!empty($args['user'])) { |
|
| 1515 | + $wp_query_args['author'] = absint($args['user']); |
|
| 1516 | 1516 | } |
| 1517 | 1517 | |
| 1518 | - if ( ! is_null( $args['parent'] ) ) { |
|
| 1519 | - $wp_query_args['post_parent'] = absint( $args['parent'] ); |
|
| 1518 | + if (!is_null($args['parent'])) { |
|
| 1519 | + $wp_query_args['post_parent'] = absint($args['parent']); |
|
| 1520 | 1520 | } |
| 1521 | 1521 | |
| 1522 | - if ( ! is_null( $args['offset'] ) ) { |
|
| 1523 | - $wp_query_args['offset'] = absint( $args['offset'] ); |
|
| 1522 | + if (!is_null($args['offset'])) { |
|
| 1523 | + $wp_query_args['offset'] = absint($args['offset']); |
|
| 1524 | 1524 | } else { |
| 1525 | - $wp_query_args['paged'] = absint( $args['page'] ); |
|
| 1525 | + $wp_query_args['paged'] = absint($args['page']); |
|
| 1526 | 1526 | } |
| 1527 | 1527 | |
| 1528 | - if ( ! empty( $args['exclude'] ) ) { |
|
| 1529 | - $wp_query_args['post__not_in'] = array_map( 'absint', $args['exclude'] ); |
|
| 1528 | + if (!empty($args['exclude'])) { |
|
| 1529 | + $wp_query_args['post__not_in'] = array_map('absint', $args['exclude']); |
|
| 1530 | 1530 | } |
| 1531 | 1531 | |
| 1532 | - if ( ! $args['paginate' ] ) { |
|
| 1532 | + if (!$args['paginate']) { |
|
| 1533 | 1533 | $wp_query_args['no_found_rows'] = true; |
| 1534 | 1534 | } |
| 1535 | 1535 | |
| 1536 | 1536 | // Get results. |
| 1537 | - $invoices = new WP_Query( $wp_query_args ); |
|
| 1537 | + $invoices = new WP_Query($wp_query_args); |
|
| 1538 | 1538 | |
| 1539 | - if ( 'objects' === $args['return'] ) { |
|
| 1540 | - $return = array_map( 'wpinv_get_invoice', $invoices->posts ); |
|
| 1541 | - } elseif ( 'self' === $args['return'] ) { |
|
| 1539 | + if ('objects' === $args['return']) { |
|
| 1540 | + $return = array_map('wpinv_get_invoice', $invoices->posts); |
|
| 1541 | + } elseif ('self' === $args['return']) { |
|
| 1542 | 1542 | return $invoices; |
| 1543 | 1543 | } else { |
| 1544 | 1544 | $return = $invoices->posts; |
| 1545 | 1545 | } |
| 1546 | 1546 | |
| 1547 | - if ( $args['paginate' ] ) { |
|
| 1548 | - return (object) array( |
|
| 1547 | + if ($args['paginate']) { |
|
| 1548 | + return (object)array( |
|
| 1549 | 1549 | 'invoices' => $return, |
| 1550 | 1550 | 'total' => $invoices->found_posts, |
| 1551 | 1551 | 'max_num_pages' => $invoices->max_num_pages, |
@@ -1557,21 +1557,21 @@ discard block |
||
| 1557 | 1557 | |
| 1558 | 1558 | function wpinv_get_user_invoices_columns() { |
| 1559 | 1559 | $columns = array( |
| 1560 | - 'invoice-number' => array( 'title' => __( 'ID', 'invoicing' ), 'class' => 'text-left' ), |
|
| 1561 | - 'invoice-date' => array( 'title' => __( 'Date', 'invoicing' ), 'class' => 'text-left' ), |
|
| 1562 | - 'invoice-status' => array( 'title' => __( 'Status', 'invoicing' ), 'class' => 'text-center' ), |
|
| 1563 | - 'invoice-total' => array( 'title' => __( 'Total', 'invoicing' ), 'class' => 'text-right' ), |
|
| 1564 | - 'invoice-actions' => array( 'title' => ' ', 'class' => 'text-center' ), |
|
| 1560 | + 'invoice-number' => array('title' => __('ID', 'invoicing'), 'class' => 'text-left'), |
|
| 1561 | + 'invoice-date' => array('title' => __('Date', 'invoicing'), 'class' => 'text-left'), |
|
| 1562 | + 'invoice-status' => array('title' => __('Status', 'invoicing'), 'class' => 'text-center'), |
|
| 1563 | + 'invoice-total' => array('title' => __('Total', 'invoicing'), 'class' => 'text-right'), |
|
| 1564 | + 'invoice-actions' => array('title' => ' ', 'class' => 'text-center'), |
|
| 1565 | 1565 | ); |
| 1566 | 1566 | |
| 1567 | - return apply_filters( 'wpinv_user_invoices_columns', $columns ); |
|
| 1567 | + return apply_filters('wpinv_user_invoices_columns', $columns); |
|
| 1568 | 1568 | } |
| 1569 | 1569 | |
| 1570 | -function wpinv_payment_receipt( $atts, $content = null ) { |
|
| 1570 | +function wpinv_payment_receipt($atts, $content = null) { |
|
| 1571 | 1571 | global $wpinv_receipt_args; |
| 1572 | 1572 | |
| 1573 | - $wpinv_receipt_args = shortcode_atts( array( |
|
| 1574 | - 'error' => __( 'Sorry, trouble retrieving payment receipt.', 'invoicing' ), |
|
| 1573 | + $wpinv_receipt_args = shortcode_atts(array( |
|
| 1574 | + 'error' => __('Sorry, trouble retrieving payment receipt.', 'invoicing'), |
|
| 1575 | 1575 | 'price' => true, |
| 1576 | 1576 | 'discount' => true, |
| 1577 | 1577 | 'items' => true, |
@@ -1580,185 +1580,185 @@ discard block |
||
| 1580 | 1580 | 'invoice_key' => false, |
| 1581 | 1581 | 'payment_method' => true, |
| 1582 | 1582 | 'invoice_id' => true |
| 1583 | - ), $atts, 'wpinv_receipt' ); |
|
| 1583 | + ), $atts, 'wpinv_receipt'); |
|
| 1584 | 1584 | |
| 1585 | 1585 | $session = wpinv_get_checkout_session(); |
| 1586 | - if ( isset( $_GET['invoice_key'] ) ) { |
|
| 1587 | - $invoice_key = urldecode( $_GET['invoice_key'] ); |
|
| 1588 | - } else if ( $session && isset( $session['invoice_key'] ) ) { |
|
| 1586 | + if (isset($_GET['invoice_key'])) { |
|
| 1587 | + $invoice_key = urldecode($_GET['invoice_key']); |
|
| 1588 | + } else if ($session && isset($session['invoice_key'])) { |
|
| 1589 | 1589 | $invoice_key = $session['invoice_key']; |
| 1590 | - } elseif ( isset( $wpinv_receipt_args['invoice_key'] ) && $wpinv_receipt_args['invoice_key'] ) { |
|
| 1590 | + } elseif (isset($wpinv_receipt_args['invoice_key']) && $wpinv_receipt_args['invoice_key']) { |
|
| 1591 | 1591 | $invoice_key = $wpinv_receipt_args['invoice_key']; |
| 1592 | - } else if ( isset( $_GET['invoice-id'] ) ) { |
|
| 1593 | - $invoice_key = wpinv_get_payment_key( (int)$_GET['invoice-id'] ); |
|
| 1592 | + } else if (isset($_GET['invoice-id'])) { |
|
| 1593 | + $invoice_key = wpinv_get_payment_key((int)$_GET['invoice-id']); |
|
| 1594 | 1594 | } |
| 1595 | 1595 | |
| 1596 | 1596 | // No key found |
| 1597 | - if ( ! isset( $invoice_key ) ) { |
|
| 1597 | + if (!isset($invoice_key)) { |
|
| 1598 | 1598 | return '<p class="alert alert-error">' . $wpinv_receipt_args['error'] . '</p>'; |
| 1599 | 1599 | } |
| 1600 | 1600 | |
| 1601 | - $invoice_id = wpinv_get_invoice_id_by_key( $invoice_key ); |
|
| 1602 | - $user_can_view = wpinv_can_view_receipt( $invoice_key ); |
|
| 1603 | - if ( $user_can_view && isset( $_GET['invoice-id'] ) ) { |
|
| 1601 | + $invoice_id = wpinv_get_invoice_id_by_key($invoice_key); |
|
| 1602 | + $user_can_view = wpinv_can_view_receipt($invoice_key); |
|
| 1603 | + if ($user_can_view && isset($_GET['invoice-id'])) { |
|
| 1604 | 1604 | $invoice_id = (int)$_GET['invoice-id']; |
| 1605 | - $user_can_view = $invoice_key == wpinv_get_payment_key( (int)$_GET['invoice-id'] ) ? true : false; |
|
| 1605 | + $user_can_view = $invoice_key == wpinv_get_payment_key((int)$_GET['invoice-id']) ? true : false; |
|
| 1606 | 1606 | } |
| 1607 | 1607 | |
| 1608 | 1608 | // Key was provided, but user is logged out. Offer them the ability to login and view the receipt |
| 1609 | - if ( ! $user_can_view && ! empty( $invoice_key ) && ! is_user_logged_in() ) { |
|
| 1609 | + if (!$user_can_view && !empty($invoice_key) && !is_user_logged_in()) { |
|
| 1610 | 1610 | // login redirect |
| 1611 | - return '<p class="alert alert-error">' . __( 'You are not allowed to access this section', 'invoicing' ) . '</p>'; |
|
| 1611 | + return '<p class="alert alert-error">' . __('You are not allowed to access this section', 'invoicing') . '</p>'; |
|
| 1612 | 1612 | } |
| 1613 | 1613 | |
| 1614 | - if ( ! apply_filters( 'wpinv_user_can_view_receipt', $user_can_view, $wpinv_receipt_args ) ) { |
|
| 1614 | + if (!apply_filters('wpinv_user_can_view_receipt', $user_can_view, $wpinv_receipt_args)) { |
|
| 1615 | 1615 | return '<p class="alert alert-error">' . $wpinv_receipt_args['error'] . '</p>'; |
| 1616 | 1616 | } |
| 1617 | 1617 | |
| 1618 | 1618 | ob_start(); |
| 1619 | 1619 | |
| 1620 | - wpinv_get_template_part( 'wpinv-invoice-receipt' ); |
|
| 1620 | + wpinv_get_template_part('wpinv-invoice-receipt'); |
|
| 1621 | 1621 | |
| 1622 | 1622 | $display = ob_get_clean(); |
| 1623 | 1623 | |
| 1624 | 1624 | return $display; |
| 1625 | 1625 | } |
| 1626 | 1626 | |
| 1627 | -function wpinv_get_invoice_id_by_key( $key ) { |
|
| 1627 | +function wpinv_get_invoice_id_by_key($key) { |
|
| 1628 | 1628 | global $wpdb; |
| 1629 | 1629 | |
| 1630 | - $invoice_id = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_key' AND meta_value = %s LIMIT 1", $key ) ); |
|
| 1630 | + $invoice_id = $wpdb->get_var($wpdb->prepare("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_key' AND meta_value = %s LIMIT 1", $key)); |
|
| 1631 | 1631 | |
| 1632 | - if ( $invoice_id != NULL ) |
|
| 1632 | + if ($invoice_id != NULL) |
|
| 1633 | 1633 | return $invoice_id; |
| 1634 | 1634 | |
| 1635 | 1635 | return 0; |
| 1636 | 1636 | } |
| 1637 | 1637 | |
| 1638 | -function wpinv_can_view_receipt( $invoice_key = '' ) { |
|
| 1638 | +function wpinv_can_view_receipt($invoice_key = '') { |
|
| 1639 | 1639 | $return = false; |
| 1640 | 1640 | |
| 1641 | - if ( empty( $invoice_key ) ) { |
|
| 1641 | + if (empty($invoice_key)) { |
|
| 1642 | 1642 | return $return; |
| 1643 | 1643 | } |
| 1644 | 1644 | |
| 1645 | 1645 | global $wpinv_receipt_args; |
| 1646 | 1646 | |
| 1647 | - $wpinv_receipt_args['id'] = wpinv_get_invoice_id_by_key( $invoice_key ); |
|
| 1648 | - if ( isset( $_GET['invoice-id'] ) ) { |
|
| 1649 | - $wpinv_receipt_args['id'] = $invoice_key == wpinv_get_payment_key( (int)$_GET['invoice-id'] ) ? (int)$_GET['invoice-id'] : 0; |
|
| 1647 | + $wpinv_receipt_args['id'] = wpinv_get_invoice_id_by_key($invoice_key); |
|
| 1648 | + if (isset($_GET['invoice-id'])) { |
|
| 1649 | + $wpinv_receipt_args['id'] = $invoice_key == wpinv_get_payment_key((int)$_GET['invoice-id']) ? (int)$_GET['invoice-id'] : 0; |
|
| 1650 | 1650 | } |
| 1651 | 1651 | |
| 1652 | - $user_id = (int) wpinv_get_user_id( $wpinv_receipt_args['id'] ); |
|
| 1653 | - $invoice_meta = wpinv_get_invoice_meta( $wpinv_receipt_args['id'] ); |
|
| 1652 | + $user_id = (int)wpinv_get_user_id($wpinv_receipt_args['id']); |
|
| 1653 | + $invoice_meta = wpinv_get_invoice_meta($wpinv_receipt_args['id']); |
|
| 1654 | 1654 | |
| 1655 | - if ( is_user_logged_in() ) { |
|
| 1656 | - if ( $user_id === (int) get_current_user_id() ) { |
|
| 1655 | + if (is_user_logged_in()) { |
|
| 1656 | + if ($user_id === (int)get_current_user_id()) { |
|
| 1657 | 1657 | $return = true; |
| 1658 | 1658 | } |
| 1659 | 1659 | } |
| 1660 | 1660 | |
| 1661 | 1661 | $session = wpinv_get_checkout_session(); |
| 1662 | - if ( ! empty( $session ) && ! is_user_logged_in() ) { |
|
| 1663 | - if ( $session['invoice_key'] === $invoice_meta['key'] ) { |
|
| 1662 | + if (!empty($session) && !is_user_logged_in()) { |
|
| 1663 | + if ($session['invoice_key'] === $invoice_meta['key']) { |
|
| 1664 | 1664 | $return = true; |
| 1665 | 1665 | } |
| 1666 | 1666 | } |
| 1667 | 1667 | |
| 1668 | - return (bool) apply_filters( 'wpinv_can_view_receipt', $return, $invoice_key ); |
|
| 1668 | + return (bool)apply_filters('wpinv_can_view_receipt', $return, $invoice_key); |
|
| 1669 | 1669 | } |
| 1670 | 1670 | |
| 1671 | 1671 | function wpinv_pay_for_invoice() { |
| 1672 | 1672 | global $wpinv_euvat; |
| 1673 | 1673 | |
| 1674 | - if ( isset( $_GET['invoice_key'] ) ) { |
|
| 1674 | + if (isset($_GET['invoice_key'])) { |
|
| 1675 | 1675 | $checkout_uri = wpinv_get_checkout_uri(); |
| 1676 | - $invoice_key = sanitize_text_field( $_GET['invoice_key'] ); |
|
| 1676 | + $invoice_key = sanitize_text_field($_GET['invoice_key']); |
|
| 1677 | 1677 | |
| 1678 | - if ( empty( $invoice_key ) ) { |
|
| 1679 | - wpinv_set_error( 'invalid_invoice', __( 'Invoice not found', 'invoicing' ) ); |
|
| 1680 | - wp_redirect( $checkout_uri ); |
|
| 1678 | + if (empty($invoice_key)) { |
|
| 1679 | + wpinv_set_error('invalid_invoice', __('Invoice not found', 'invoicing')); |
|
| 1680 | + wp_redirect($checkout_uri); |
|
| 1681 | 1681 | wpinv_die(); |
| 1682 | 1682 | } |
| 1683 | 1683 | |
| 1684 | - do_action( 'wpinv_check_pay_for_invoice', $invoice_key ); |
|
| 1684 | + do_action('wpinv_check_pay_for_invoice', $invoice_key); |
|
| 1685 | 1685 | |
| 1686 | - $invoice_id = wpinv_get_invoice_id_by_key( $invoice_key ); |
|
| 1687 | - $user_can_view = wpinv_can_view_receipt( $invoice_key ); |
|
| 1688 | - if ( $user_can_view && isset( $_GET['invoice-id'] ) ) { |
|
| 1686 | + $invoice_id = wpinv_get_invoice_id_by_key($invoice_key); |
|
| 1687 | + $user_can_view = wpinv_can_view_receipt($invoice_key); |
|
| 1688 | + if ($user_can_view && isset($_GET['invoice-id'])) { |
|
| 1689 | 1689 | $invoice_id = (int)$_GET['invoice-id']; |
| 1690 | - $user_can_view = $invoice_key == wpinv_get_payment_key( (int)$_GET['invoice-id'] ) ? true : false; |
|
| 1690 | + $user_can_view = $invoice_key == wpinv_get_payment_key((int)$_GET['invoice-id']) ? true : false; |
|
| 1691 | 1691 | } |
| 1692 | 1692 | |
| 1693 | - if ( $invoice_id && $user_can_view && ( $invoice = wpinv_get_invoice( $invoice_id ) ) ) { |
|
| 1694 | - if ( $invoice->needs_payment() ) { |
|
| 1693 | + if ($invoice_id && $user_can_view && ($invoice = wpinv_get_invoice($invoice_id))) { |
|
| 1694 | + if ($invoice->needs_payment()) { |
|
| 1695 | 1695 | $data = array(); |
| 1696 | 1696 | $data['invoice_id'] = $invoice_id; |
| 1697 | - $data['cart_discounts'] = $invoice->get_discounts( true ); |
|
| 1697 | + $data['cart_discounts'] = $invoice->get_discounts(true); |
|
| 1698 | 1698 | |
| 1699 | - wpinv_set_checkout_session( $data ); |
|
| 1699 | + wpinv_set_checkout_session($data); |
|
| 1700 | 1700 | |
| 1701 | - if ( wpinv_get_option( 'vat_ip_country_default' ) ) { |
|
| 1701 | + if (wpinv_get_option('vat_ip_country_default')) { |
|
| 1702 | 1702 | $_POST['country'] = $wpinv_euvat->get_country_by_ip(); |
| 1703 | 1703 | $_POST['state'] = $_POST['country'] == $invoice->country ? $invoice->state : ''; |
| 1704 | 1704 | |
| 1705 | - wpinv_recalculate_tax( true ); |
|
| 1705 | + wpinv_recalculate_tax(true); |
|
| 1706 | 1706 | } |
| 1707 | 1707 | |
| 1708 | 1708 | } else { |
| 1709 | 1709 | $checkout_uri = $invoice->get_view_url(); |
| 1710 | 1710 | } |
| 1711 | 1711 | } else { |
| 1712 | - wpinv_set_error( 'invalid_invoice', __( 'You are not allowed to view this invoice', 'invoicing' ) ); |
|
| 1712 | + wpinv_set_error('invalid_invoice', __('You are not allowed to view this invoice', 'invoicing')); |
|
| 1713 | 1713 | |
| 1714 | - $checkout_uri = is_user_logged_in() ? wpinv_get_history_page_uri() : wp_login_url( get_permalink() ); |
|
| 1714 | + $checkout_uri = is_user_logged_in() ? wpinv_get_history_page_uri() : wp_login_url(get_permalink()); |
|
| 1715 | 1715 | } |
| 1716 | 1716 | |
| 1717 | - wp_redirect( $checkout_uri ); |
|
| 1717 | + wp_redirect($checkout_uri); |
|
| 1718 | 1718 | wpinv_die(); |
| 1719 | 1719 | } |
| 1720 | 1720 | } |
| 1721 | -add_action( 'wpinv_pay_for_invoice', 'wpinv_pay_for_invoice' ); |
|
| 1721 | +add_action('wpinv_pay_for_invoice', 'wpinv_pay_for_invoice'); |
|
| 1722 | 1722 | |
| 1723 | -function wpinv_handle_pay_via_invoice_link( $invoice_key ) { |
|
| 1724 | - if ( !empty( $invoice_key ) && !empty( $_REQUEST['_wpipay'] ) && !is_user_logged_in() && $invoice_id = wpinv_get_invoice_id_by_key( $invoice_key ) ) { |
|
| 1725 | - if ( $invoice = wpinv_get_invoice( $invoice_id ) ) { |
|
| 1723 | +function wpinv_handle_pay_via_invoice_link($invoice_key) { |
|
| 1724 | + if (!empty($invoice_key) && !empty($_REQUEST['_wpipay']) && !is_user_logged_in() && $invoice_id = wpinv_get_invoice_id_by_key($invoice_key)) { |
|
| 1725 | + if ($invoice = wpinv_get_invoice($invoice_id)) { |
|
| 1726 | 1726 | $user_id = $invoice->get_user_id(); |
| 1727 | - $secret = sanitize_text_field( $_GET['_wpipay'] ); |
|
| 1727 | + $secret = sanitize_text_field($_GET['_wpipay']); |
|
| 1728 | 1728 | |
| 1729 | - if ( $secret === md5( $user_id . '::' . $invoice->get_email() . '::' . $invoice_key ) ) { // valid invoice link |
|
| 1730 | - $redirect_to = remove_query_arg( '_wpipay', get_permalink() ); |
|
| 1729 | + if ($secret === md5($user_id . '::' . $invoice->get_email() . '::' . $invoice_key)) { // valid invoice link |
|
| 1730 | + $redirect_to = remove_query_arg('_wpipay', get_permalink()); |
|
| 1731 | 1731 | |
| 1732 | - wpinv_guest_redirect( $redirect_to, $user_id ); |
|
| 1732 | + wpinv_guest_redirect($redirect_to, $user_id); |
|
| 1733 | 1733 | wpinv_die(); |
| 1734 | 1734 | } |
| 1735 | 1735 | } |
| 1736 | 1736 | } |
| 1737 | 1737 | } |
| 1738 | -add_action( 'wpinv_check_pay_for_invoice', 'wpinv_handle_pay_via_invoice_link' ); |
|
| 1738 | +add_action('wpinv_check_pay_for_invoice', 'wpinv_handle_pay_via_invoice_link'); |
|
| 1739 | 1739 | |
| 1740 | -function wpinv_set_payment_transaction_id( $invoice_id = 0, $transaction_id = '' ) { |
|
| 1741 | - $invoice_id = is_object( $invoice_id ) && !empty( $invoice_id->ID ) ? $invoice_id : $invoice_id; |
|
| 1740 | +function wpinv_set_payment_transaction_id($invoice_id = 0, $transaction_id = '') { |
|
| 1741 | + $invoice_id = is_object($invoice_id) && !empty($invoice_id->ID) ? $invoice_id : $invoice_id; |
|
| 1742 | 1742 | |
| 1743 | - if ( empty( $invoice_id ) && $invoice_id > 0 ) { |
|
| 1743 | + if (empty($invoice_id) && $invoice_id > 0) { |
|
| 1744 | 1744 | return false; |
| 1745 | 1745 | } |
| 1746 | 1746 | |
| 1747 | - if ( empty( $transaction_id ) ) { |
|
| 1747 | + if (empty($transaction_id)) { |
|
| 1748 | 1748 | $transaction_id = $invoice_id; |
| 1749 | 1749 | } |
| 1750 | 1750 | |
| 1751 | - $transaction_id = apply_filters( 'wpinv_set_payment_transaction_id', $transaction_id, $invoice_id ); |
|
| 1751 | + $transaction_id = apply_filters('wpinv_set_payment_transaction_id', $transaction_id, $invoice_id); |
|
| 1752 | 1752 | |
| 1753 | - return wpinv_update_invoice_meta( $invoice_id, '_wpinv_transaction_id', $transaction_id ); |
|
| 1753 | + return wpinv_update_invoice_meta($invoice_id, '_wpinv_transaction_id', $transaction_id); |
|
| 1754 | 1754 | } |
| 1755 | 1755 | |
| 1756 | -function wpinv_invoice_status_label( $status, $status_display = '' ) { |
|
| 1757 | - if ( empty( $status_display ) ) { |
|
| 1758 | - $status_display = wpinv_status_nicename( $status ); |
|
| 1756 | +function wpinv_invoice_status_label($status, $status_display = '') { |
|
| 1757 | + if (empty($status_display)) { |
|
| 1758 | + $status_display = wpinv_status_nicename($status); |
|
| 1759 | 1759 | } |
| 1760 | 1760 | |
| 1761 | - switch ( $status ) { |
|
| 1761 | + switch ($status) { |
|
| 1762 | 1762 | case 'publish' : |
| 1763 | 1763 | case 'wpi-renewal' : |
| 1764 | 1764 | $class = 'label-success'; |
@@ -1783,129 +1783,129 @@ discard block |
||
| 1783 | 1783 | |
| 1784 | 1784 | $label = '<span class="label label-inv-' . $status . ' ' . $class . '">' . $status_display . '</span>'; |
| 1785 | 1785 | |
| 1786 | - return apply_filters( 'wpinv_invoice_status_label', $label, $status, $status_display ); |
|
| 1786 | + return apply_filters('wpinv_invoice_status_label', $label, $status, $status_display); |
|
| 1787 | 1787 | } |
| 1788 | 1788 | |
| 1789 | -function wpinv_format_invoice_number( $number ) { |
|
| 1790 | - $padd = wpinv_get_option( 'invoice_number_padd' ); |
|
| 1789 | +function wpinv_format_invoice_number($number) { |
|
| 1790 | + $padd = wpinv_get_option('invoice_number_padd'); |
|
| 1791 | 1791 | |
| 1792 | 1792 | // TODO maintain old invoice numbers if invoice number settings not saved. Should be removed before stable release. |
| 1793 | - if ( $padd === '' || $padd === false || $padd === NULL ) { |
|
| 1794 | - return wp_sprintf( __( 'WPINV-%d', 'invoicing' ), $number ); |
|
| 1793 | + if ($padd === '' || $padd === false || $padd === NULL) { |
|
| 1794 | + return wp_sprintf(__('WPINV-%d', 'invoicing'), $number); |
|
| 1795 | 1795 | } |
| 1796 | 1796 | |
| 1797 | - $prefix = wpinv_get_option( 'invoice_number_prefix' ); |
|
| 1798 | - $postfix = wpinv_get_option( 'invoice_number_postfix' ); |
|
| 1797 | + $prefix = wpinv_get_option('invoice_number_prefix'); |
|
| 1798 | + $postfix = wpinv_get_option('invoice_number_postfix'); |
|
| 1799 | 1799 | |
| 1800 | - $padd = absint( $padd ); |
|
| 1801 | - $formatted_number = absint( $number ); |
|
| 1800 | + $padd = absint($padd); |
|
| 1801 | + $formatted_number = absint($number); |
|
| 1802 | 1802 | |
| 1803 | - if ( $padd > 0 ) { |
|
| 1804 | - $formatted_number = zeroise( $formatted_number, $padd ); |
|
| 1803 | + if ($padd > 0) { |
|
| 1804 | + $formatted_number = zeroise($formatted_number, $padd); |
|
| 1805 | 1805 | } |
| 1806 | 1806 | |
| 1807 | 1807 | $formatted_number = $prefix . $formatted_number . $postfix; |
| 1808 | 1808 | |
| 1809 | - return apply_filters( 'wpinv_format_invoice_number', $formatted_number, $number, $prefix, $postfix, $padd ); |
|
| 1809 | + return apply_filters('wpinv_format_invoice_number', $formatted_number, $number, $prefix, $postfix, $padd); |
|
| 1810 | 1810 | } |
| 1811 | 1811 | |
| 1812 | 1812 | function wpinv_get_next_invoice_number() { |
| 1813 | - if ( ! wpinv_get_option( 'sequential_invoice_number' ) ) { |
|
| 1813 | + if (!wpinv_get_option('sequential_invoice_number')) { |
|
| 1814 | 1814 | return false; |
| 1815 | 1815 | } |
| 1816 | 1816 | |
| 1817 | - $number = get_option( 'wpinv_last_invoice_number' ); |
|
| 1818 | - $start = wpinv_get_option( 'invoice_sequence_start', 1 ); |
|
| 1817 | + $number = get_option('wpinv_last_invoice_number'); |
|
| 1818 | + $start = wpinv_get_option('invoice_sequence_start', 1); |
|
| 1819 | 1819 | $increment_number = true; |
| 1820 | 1820 | |
| 1821 | - if ( false !== $number ) { |
|
| 1822 | - if ( empty( $number ) ) { |
|
| 1821 | + if (false !== $number) { |
|
| 1822 | + if (empty($number)) { |
|
| 1823 | 1823 | $number = $start; |
| 1824 | 1824 | $increment_number = false; |
| 1825 | 1825 | } |
| 1826 | 1826 | } else { |
| 1827 | - $last_invoice = wpinv_get_invoices( array( 'limit' => 1, 'order' => 'DESC', 'orderby' => 'ID', 'return' => 'posts', 'fields' => 'ids', 'status' => 'any' ) ); |
|
| 1827 | + $last_invoice = wpinv_get_invoices(array('limit' => 1, 'order' => 'DESC', 'orderby' => 'ID', 'return' => 'posts', 'fields' => 'ids', 'status' => 'any')); |
|
| 1828 | 1828 | |
| 1829 | - if ( ! empty( $last_invoice[0] ) ) { |
|
| 1830 | - $number = wpinv_get_invoice_number( $last_invoice[0] ); |
|
| 1829 | + if (!empty($last_invoice[0])) { |
|
| 1830 | + $number = wpinv_get_invoice_number($last_invoice[0]); |
|
| 1831 | 1831 | } |
| 1832 | 1832 | |
| 1833 | - if ( ! empty( $number ) && ! empty( $last_invoice[0] ) && $number !== (int) $last_invoice[0] ) { |
|
| 1834 | - $number = wpinv_clean_invoice_number( $number ); |
|
| 1833 | + if (!empty($number) && !empty($last_invoice[0]) && $number !== (int)$last_invoice[0]) { |
|
| 1834 | + $number = wpinv_clean_invoice_number($number); |
|
| 1835 | 1835 | } else { |
| 1836 | 1836 | $number = $start; |
| 1837 | 1837 | $increment_number = false; |
| 1838 | 1838 | } |
| 1839 | 1839 | } |
| 1840 | 1840 | |
| 1841 | - $increment_number = apply_filters( 'wpinv_increment_payment_number', $increment_number, $number ); |
|
| 1841 | + $increment_number = apply_filters('wpinv_increment_payment_number', $increment_number, $number); |
|
| 1842 | 1842 | |
| 1843 | - if ( $increment_number ) { |
|
| 1843 | + if ($increment_number) { |
|
| 1844 | 1844 | $number++; |
| 1845 | 1845 | } |
| 1846 | 1846 | |
| 1847 | - return apply_filters( 'wpinv_get_next_invoice_number', $number ); |
|
| 1847 | + return apply_filters('wpinv_get_next_invoice_number', $number); |
|
| 1848 | 1848 | } |
| 1849 | 1849 | |
| 1850 | -function wpinv_clean_invoice_number( $number ) { |
|
| 1851 | - $prefix = wpinv_get_option( 'invoice_number_prefix' ); |
|
| 1852 | - $postfix = wpinv_get_option( 'invoice_number_postfix' ); |
|
| 1850 | +function wpinv_clean_invoice_number($number) { |
|
| 1851 | + $prefix = wpinv_get_option('invoice_number_prefix'); |
|
| 1852 | + $postfix = wpinv_get_option('invoice_number_postfix'); |
|
| 1853 | 1853 | |
| 1854 | - $number = preg_replace( '/' . $prefix . '/', '', $number, 1 ); |
|
| 1854 | + $number = preg_replace('/' . $prefix . '/', '', $number, 1); |
|
| 1855 | 1855 | |
| 1856 | - $length = strlen( $number ); |
|
| 1857 | - $postfix_pos = strrpos( $number, $postfix ); |
|
| 1856 | + $length = strlen($number); |
|
| 1857 | + $postfix_pos = strrpos($number, $postfix); |
|
| 1858 | 1858 | |
| 1859 | - if ( false !== $postfix_pos ) { |
|
| 1860 | - $number = substr_replace( $number, '', $postfix_pos, $length ); |
|
| 1859 | + if (false !== $postfix_pos) { |
|
| 1860 | + $number = substr_replace($number, '', $postfix_pos, $length); |
|
| 1861 | 1861 | } |
| 1862 | 1862 | |
| 1863 | - $number = intval( $number ); |
|
| 1863 | + $number = intval($number); |
|
| 1864 | 1864 | |
| 1865 | - return apply_filters( 'wpinv_clean_invoice_number', $number, $prefix, $postfix ); |
|
| 1865 | + return apply_filters('wpinv_clean_invoice_number', $number, $prefix, $postfix); |
|
| 1866 | 1866 | } |
| 1867 | 1867 | |
| 1868 | -function wpinv_save_number_post_saved( $post_ID, $post, $update ) { |
|
| 1868 | +function wpinv_save_number_post_saved($post_ID, $post, $update) { |
|
| 1869 | 1869 | global $wpdb; |
| 1870 | 1870 | |
| 1871 | - if ( !$update && !get_post_meta( $post_ID, '_wpinv_number', true ) ) { |
|
| 1872 | - wpinv_update_invoice_number( $post_ID, $post->post_status != 'auto-draft' ); |
|
| 1871 | + if (!$update && !get_post_meta($post_ID, '_wpinv_number', true)) { |
|
| 1872 | + wpinv_update_invoice_number($post_ID, $post->post_status != 'auto-draft'); |
|
| 1873 | 1873 | } |
| 1874 | 1874 | |
| 1875 | - if ( !$update ) { |
|
| 1876 | - $wpdb->update( $wpdb->posts, array( 'post_name' => 'inv-' . $post_ID ), array( 'ID' => $post_ID ) ); |
|
| 1877 | - clean_post_cache( $post_ID ); |
|
| 1875 | + if (!$update) { |
|
| 1876 | + $wpdb->update($wpdb->posts, array('post_name' => 'inv-' . $post_ID), array('ID' => $post_ID)); |
|
| 1877 | + clean_post_cache($post_ID); |
|
| 1878 | 1878 | } |
| 1879 | 1879 | } |
| 1880 | -add_action( 'save_post_wpi_invoice', 'wpinv_save_number_post_saved', 1, 3 ); |
|
| 1880 | +add_action('save_post_wpi_invoice', 'wpinv_save_number_post_saved', 1, 3); |
|
| 1881 | 1881 | |
| 1882 | -function wpinv_save_number_post_updated( $post_ID, $post_after, $post_before ) { |
|
| 1883 | - if ( !empty( $post_after->post_type ) && $post_after->post_type == 'wpi_invoice' && $post_before->post_status == 'auto-draft' && $post_after->post_status != $post_before->post_status ) { |
|
| 1884 | - wpinv_update_invoice_number( $post_ID, true ); |
|
| 1882 | +function wpinv_save_number_post_updated($post_ID, $post_after, $post_before) { |
|
| 1883 | + if (!empty($post_after->post_type) && $post_after->post_type == 'wpi_invoice' && $post_before->post_status == 'auto-draft' && $post_after->post_status != $post_before->post_status) { |
|
| 1884 | + wpinv_update_invoice_number($post_ID, true); |
|
| 1885 | 1885 | } |
| 1886 | 1886 | } |
| 1887 | -add_action( 'post_updated', 'wpinv_save_number_post_updated', 1, 3 ); |
|
| 1887 | +add_action('post_updated', 'wpinv_save_number_post_updated', 1, 3); |
|
| 1888 | 1888 | |
| 1889 | -function wpinv_update_invoice_number( $post_ID, $save_sequential = false ) { |
|
| 1889 | +function wpinv_update_invoice_number($post_ID, $save_sequential = false) { |
|
| 1890 | 1890 | global $wpdb; |
| 1891 | 1891 | |
| 1892 | - if ( wpinv_get_option( 'sequential_invoice_number' ) ) { |
|
| 1892 | + if (wpinv_get_option('sequential_invoice_number')) { |
|
| 1893 | 1893 | $number = wpinv_get_next_invoice_number(); |
| 1894 | 1894 | |
| 1895 | - if ( $save_sequential ) { |
|
| 1896 | - update_option( 'wpinv_last_invoice_number', $number ); |
|
| 1895 | + if ($save_sequential) { |
|
| 1896 | + update_option('wpinv_last_invoice_number', $number); |
|
| 1897 | 1897 | } |
| 1898 | 1898 | } else { |
| 1899 | 1899 | $number = $post_ID; |
| 1900 | 1900 | } |
| 1901 | 1901 | |
| 1902 | - $number = wpinv_format_invoice_number( $number ); |
|
| 1902 | + $number = wpinv_format_invoice_number($number); |
|
| 1903 | 1903 | |
| 1904 | - update_post_meta( $post_ID, '_wpinv_number', $number ); |
|
| 1904 | + update_post_meta($post_ID, '_wpinv_number', $number); |
|
| 1905 | 1905 | |
| 1906 | - $wpdb->update( $wpdb->posts, array( 'post_title' => $number ), array( 'ID' => $post_ID ) ); |
|
| 1906 | + $wpdb->update($wpdb->posts, array('post_title' => $number), array('ID' => $post_ID)); |
|
| 1907 | 1907 | |
| 1908 | - clean_post_cache( $post_ID ); |
|
| 1908 | + clean_post_cache($post_ID); |
|
| 1909 | 1909 | |
| 1910 | 1910 | return $number; |
| 1911 | 1911 | } |
| 1912 | 1912 | \ No newline at end of file |
@@ -529,6 +529,9 @@ |
||
| 529 | 529 | return apply_filters( 'wpinv_get_cart_item_price_name', $name, $item['id'], $price_id, $item ); |
| 530 | 530 | } |
| 531 | 531 | |
| 532 | +/** |
|
| 533 | + * @return string |
|
| 534 | + */ |
|
| 532 | 535 | function wpinv_get_cart_item_name( $item = array() ) { |
| 533 | 536 | $item_title = !empty( $item['name'] ) ? $item['name'] : get_the_title( $item['id'] ); |
| 534 | 537 | |
@@ -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 | function wpinv_get_item_by( $field = '', $value = '', $type = '' ) { |
| 6 | 8 | if( empty( $field ) || empty( $value ) ) { |
@@ -118,8 +120,9 @@ discard block |
||
| 118 | 120 | function wpinv_get_item( $item = 0 ) { |
| 119 | 121 | if ( is_numeric( $item ) ) { |
| 120 | 122 | $item = get_post( $item ); |
| 121 | - if ( ! $item || 'wpi_item' !== $item->post_type ) |
|
| 122 | - return null; |
|
| 123 | + if ( ! $item || 'wpi_item' !== $item->post_type ) { |
|
| 124 | + return null; |
|
| 125 | + } |
|
| 123 | 126 | return $item; |
| 124 | 127 | } |
| 125 | 128 | |
@@ -283,8 +286,9 @@ discard block |
||
| 283 | 286 | } |
| 284 | 287 | |
| 285 | 288 | function wpinv_remove_item_logs_on_delete( $item_id = 0 ) { |
| 286 | - if ( 'wpi_item' !== get_post_type( $item_id ) ) |
|
| 287 | - return; |
|
| 289 | + if ( 'wpi_item' !== get_post_type( $item_id ) ) { |
|
| 290 | + return; |
|
| 291 | + } |
|
| 288 | 292 | |
| 289 | 293 | global $wpinv_logs; |
| 290 | 294 | |
@@ -1,19 +1,19 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | // Exit if accessed directly |
| 3 | -if ( ! defined( 'ABSPATH' ) ) exit; |
|
| 3 | +if (!defined('ABSPATH')) exit; |
|
| 4 | 4 | |
| 5 | -function wpinv_get_item_by( $field = '', $value = '', $type = '' ) { |
|
| 6 | - if( empty( $field ) || empty( $value ) ) { |
|
| 5 | +function wpinv_get_item_by($field = '', $value = '', $type = '') { |
|
| 6 | + if (empty($field) || empty($value)) { |
|
| 7 | 7 | return false; |
| 8 | 8 | } |
| 9 | 9 | |
| 10 | 10 | $posts = array(); |
| 11 | 11 | |
| 12 | - switch( strtolower( $field ) ) { |
|
| 12 | + switch (strtolower($field)) { |
|
| 13 | 13 | case 'id': |
| 14 | - $item = get_post( $value ); |
|
| 14 | + $item = get_post($value); |
|
| 15 | 15 | |
| 16 | - if( get_post_type( $item ) != 'wpi_item' ) { |
|
| 16 | + if (get_post_type($item) != 'wpi_item') { |
|
| 17 | 17 | return false; |
| 18 | 18 | } |
| 19 | 19 | |
@@ -21,16 +21,16 @@ discard block |
||
| 21 | 21 | |
| 22 | 22 | case 'slug': |
| 23 | 23 | case 'name': |
| 24 | - $posts = get_posts( array( |
|
| 24 | + $posts = get_posts(array( |
|
| 25 | 25 | 'post_type' => 'wpi_item', |
| 26 | 26 | 'name' => $value, |
| 27 | 27 | 'posts_per_page' => 1, |
| 28 | 28 | 'post_status' => 'any' |
| 29 | - ) ); |
|
| 29 | + )); |
|
| 30 | 30 | |
| 31 | 31 | break; |
| 32 | 32 | case 'custom_id': |
| 33 | - if ( empty( $value ) || empty( $type ) ) { |
|
| 33 | + if (empty($value) || empty($type)) { |
|
| 34 | 34 | return false; |
| 35 | 35 | } |
| 36 | 36 | |
@@ -50,10 +50,10 @@ discard block |
||
| 50 | 50 | 'post_status' => 'any', |
| 51 | 51 | 'orderby' => 'ID', |
| 52 | 52 | 'order' => 'ASC', |
| 53 | - 'meta_query' => array( $meta_query ) |
|
| 53 | + 'meta_query' => array($meta_query) |
|
| 54 | 54 | ); |
| 55 | 55 | |
| 56 | - $posts = get_posts( $args ); |
|
| 56 | + $posts = get_posts($args); |
|
| 57 | 57 | |
| 58 | 58 | break; |
| 59 | 59 | |
@@ -61,17 +61,17 @@ discard block |
||
| 61 | 61 | return false; |
| 62 | 62 | } |
| 63 | 63 | |
| 64 | - if ( !empty( $posts[0] ) ) { |
|
| 65 | - return new WPInv_Item( $posts[0]->ID ); |
|
| 64 | + if (!empty($posts[0])) { |
|
| 65 | + return new WPInv_Item($posts[0]->ID); |
|
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | return false; |
| 69 | 69 | } |
| 70 | 70 | |
| 71 | -function wpinv_get_item( $item = 0 ) { |
|
| 72 | - if ( is_numeric( $item ) ) { |
|
| 73 | - $item = get_post( $item ); |
|
| 74 | - if ( ! $item || 'wpi_item' !== $item->post_type ) |
|
| 71 | +function wpinv_get_item($item = 0) { |
|
| 72 | + if (is_numeric($item)) { |
|
| 73 | + $item = get_post($item); |
|
| 74 | + if (!$item || 'wpi_item' !== $item->post_type) |
|
| 75 | 75 | return null; |
| 76 | 76 | return $item; |
| 77 | 77 | } |
@@ -84,150 +84,150 @@ discard block |
||
| 84 | 84 | |
| 85 | 85 | $item = get_posts($args); |
| 86 | 86 | |
| 87 | - if ( $item ) { |
|
| 87 | + if ($item) { |
|
| 88 | 88 | return $item[0]; |
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | return null; |
| 92 | 92 | } |
| 93 | 93 | |
| 94 | -function wpinv_is_free_item( $item_id = 0 ) { |
|
| 95 | - if( empty( $item_id ) ) { |
|
| 94 | +function wpinv_is_free_item($item_id = 0) { |
|
| 95 | + if (empty($item_id)) { |
|
| 96 | 96 | return false; |
| 97 | 97 | } |
| 98 | 98 | |
| 99 | - $item = new WPInv_Item( $item_id ); |
|
| 99 | + $item = new WPInv_Item($item_id); |
|
| 100 | 100 | |
| 101 | 101 | return $item->is_free(); |
| 102 | 102 | } |
| 103 | 103 | |
| 104 | -function wpinv_item_is_editable( $item = 0 ) { |
|
| 105 | - if ( !empty( $item ) && is_a( $item, 'WP_Post' ) ) { |
|
| 104 | +function wpinv_item_is_editable($item = 0) { |
|
| 105 | + if (!empty($item) && is_a($item, 'WP_Post')) { |
|
| 106 | 106 | $item = $item->ID; |
| 107 | 107 | } |
| 108 | 108 | |
| 109 | - if ( empty( $item ) ) { |
|
| 109 | + if (empty($item)) { |
|
| 110 | 110 | return true; |
| 111 | 111 | } |
| 112 | 112 | |
| 113 | - $item = new WPInv_Item( $item ); |
|
| 113 | + $item = new WPInv_Item($item); |
|
| 114 | 114 | |
| 115 | - return (bool) $item->is_editable(); |
|
| 115 | + return (bool)$item->is_editable(); |
|
| 116 | 116 | } |
| 117 | 117 | |
| 118 | -function wpinv_get_item_price( $item_id = 0 ) { |
|
| 119 | - if( empty( $item_id ) ) { |
|
| 118 | +function wpinv_get_item_price($item_id = 0) { |
|
| 119 | + if (empty($item_id)) { |
|
| 120 | 120 | return false; |
| 121 | 121 | } |
| 122 | 122 | |
| 123 | - $item = new WPInv_Item( $item_id ); |
|
| 123 | + $item = new WPInv_Item($item_id); |
|
| 124 | 124 | |
| 125 | 125 | return $item->get_price(); |
| 126 | 126 | } |
| 127 | 127 | |
| 128 | -function wpinv_is_recurring_item( $item_id = 0 ) { |
|
| 129 | - if( empty( $item_id ) ) { |
|
| 128 | +function wpinv_is_recurring_item($item_id = 0) { |
|
| 129 | + if (empty($item_id)) { |
|
| 130 | 130 | return false; |
| 131 | 131 | } |
| 132 | 132 | |
| 133 | - $item = new WPInv_Item( $item_id ); |
|
| 133 | + $item = new WPInv_Item($item_id); |
|
| 134 | 134 | |
| 135 | 135 | return $item->is_recurring(); |
| 136 | 136 | } |
| 137 | 137 | |
| 138 | -function wpinv_item_price( $item_id = 0 ) { |
|
| 139 | - if( empty( $item_id ) ) { |
|
| 138 | +function wpinv_item_price($item_id = 0) { |
|
| 139 | + if (empty($item_id)) { |
|
| 140 | 140 | return false; |
| 141 | 141 | } |
| 142 | 142 | |
| 143 | - $price = wpinv_get_item_price( $item_id ); |
|
| 144 | - $price = wpinv_price( wpinv_format_amount( $price ) ); |
|
| 143 | + $price = wpinv_get_item_price($item_id); |
|
| 144 | + $price = wpinv_price(wpinv_format_amount($price)); |
|
| 145 | 145 | |
| 146 | - return apply_filters( 'wpinv_item_price', $price, $item_id ); |
|
| 146 | + return apply_filters('wpinv_item_price', $price, $item_id); |
|
| 147 | 147 | } |
| 148 | 148 | |
| 149 | -function wpinv_item_show_price( $item_id = 0, $echo = true ) { |
|
| 150 | - if ( empty( $item_id ) ) { |
|
| 149 | +function wpinv_item_show_price($item_id = 0, $echo = true) { |
|
| 150 | + if (empty($item_id)) { |
|
| 151 | 151 | $item_id = get_the_ID(); |
| 152 | 152 | } |
| 153 | 153 | |
| 154 | - $price = wpinv_item_price( $item_id ); |
|
| 154 | + $price = wpinv_item_price($item_id); |
|
| 155 | 155 | |
| 156 | - $price = apply_filters( 'wpinv_item_price', wpinv_sanitize_amount( $price ), $item_id ); |
|
| 156 | + $price = apply_filters('wpinv_item_price', wpinv_sanitize_amount($price), $item_id); |
|
| 157 | 157 | $formatted_price = '<span class="wpinv_price" id="wpinv_item_' . $item_id . '">' . $price . '</span>'; |
| 158 | - $formatted_price = apply_filters( 'wpinv_item_price_after_html', $formatted_price, $item_id, $price ); |
|
| 158 | + $formatted_price = apply_filters('wpinv_item_price_after_html', $formatted_price, $item_id, $price); |
|
| 159 | 159 | |
| 160 | - if ( $echo ) { |
|
| 160 | + if ($echo) { |
|
| 161 | 161 | echo $formatted_price; |
| 162 | 162 | } else { |
| 163 | 163 | return $formatted_price; |
| 164 | 164 | } |
| 165 | 165 | } |
| 166 | 166 | |
| 167 | -function wpinv_get_item_final_price( $item_id = 0, $amount_override = null ) { |
|
| 168 | - if ( is_null( $amount_override ) ) { |
|
| 169 | - $original_price = get_post_meta( $item_id, '_wpinv_price', true ); |
|
| 167 | +function wpinv_get_item_final_price($item_id = 0, $amount_override = null) { |
|
| 168 | + if (is_null($amount_override)) { |
|
| 169 | + $original_price = get_post_meta($item_id, '_wpinv_price', true); |
|
| 170 | 170 | } else { |
| 171 | 171 | $original_price = $amount_override; |
| 172 | 172 | } |
| 173 | 173 | |
| 174 | 174 | $price = $original_price; |
| 175 | 175 | |
| 176 | - return apply_filters( 'wpinv_get_item_final_price', $price, $item_id ); |
|
| 176 | + return apply_filters('wpinv_get_item_final_price', $price, $item_id); |
|
| 177 | 177 | } |
| 178 | 178 | |
| 179 | -function wpinv_item_custom_singular_name( $item_id ) { |
|
| 180 | - if( empty( $item_id ) ) { |
|
| 179 | +function wpinv_item_custom_singular_name($item_id) { |
|
| 180 | + if (empty($item_id)) { |
|
| 181 | 181 | return false; |
| 182 | 182 | } |
| 183 | 183 | |
| 184 | - $item = new WPInv_Item( $item_id ); |
|
| 184 | + $item = new WPInv_Item($item_id); |
|
| 185 | 185 | |
| 186 | 186 | return $item->get_custom_singular_name(); |
| 187 | 187 | } |
| 188 | 188 | |
| 189 | 189 | function wpinv_get_item_types() { |
| 190 | 190 | $item_types = array( |
| 191 | - 'custom' => __( 'Standard', 'invoicing' ), |
|
| 192 | - 'fee' => __( 'Fee', 'invoicing' ), |
|
| 191 | + 'custom' => __('Standard', 'invoicing'), |
|
| 192 | + 'fee' => __('Fee', 'invoicing'), |
|
| 193 | 193 | ); |
| 194 | - return apply_filters( 'wpinv_get_item_types', $item_types ); |
|
| 194 | + return apply_filters('wpinv_get_item_types', $item_types); |
|
| 195 | 195 | } |
| 196 | 196 | |
| 197 | 197 | function wpinv_item_types() { |
| 198 | 198 | $item_types = wpinv_get_item_types(); |
| 199 | 199 | |
| 200 | - return ( !empty( $item_types ) ? array_keys( $item_types ) : array() ); |
|
| 200 | + return (!empty($item_types) ? array_keys($item_types) : array()); |
|
| 201 | 201 | } |
| 202 | 202 | |
| 203 | -function wpinv_get_item_type( $item_id ) { |
|
| 204 | - if( empty( $item_id ) ) { |
|
| 203 | +function wpinv_get_item_type($item_id) { |
|
| 204 | + if (empty($item_id)) { |
|
| 205 | 205 | return false; |
| 206 | 206 | } |
| 207 | 207 | |
| 208 | - $item = new WPInv_Item( $item_id ); |
|
| 208 | + $item = new WPInv_Item($item_id); |
|
| 209 | 209 | |
| 210 | 210 | return $item->get_type(); |
| 211 | 211 | } |
| 212 | 212 | |
| 213 | -function wpinv_item_type( $item_id ) { |
|
| 213 | +function wpinv_item_type($item_id) { |
|
| 214 | 214 | $item_types = wpinv_get_item_types(); |
| 215 | 215 | |
| 216 | - $item_type = wpinv_get_item_type( $item_id ); |
|
| 216 | + $item_type = wpinv_get_item_type($item_id); |
|
| 217 | 217 | |
| 218 | - if ( empty( $item_type ) ) { |
|
| 218 | + if (empty($item_type)) { |
|
| 219 | 219 | $item_type = '-'; |
| 220 | 220 | } |
| 221 | 221 | |
| 222 | - $item_type = isset( $item_types[$item_type] ) ? $item_types[$item_type] : __( $item_type, 'invoicing' ); |
|
| 222 | + $item_type = isset($item_types[$item_type]) ? $item_types[$item_type] : __($item_type, 'invoicing'); |
|
| 223 | 223 | |
| 224 | - return apply_filters( 'wpinv_item_type', $item_type, $item_id ); |
|
| 224 | + return apply_filters('wpinv_item_type', $item_type, $item_id); |
|
| 225 | 225 | } |
| 226 | 226 | |
| 227 | -function wpinv_record_item_in_log( $item_id = 0, $file_id, $user_info, $ip, $invoice_id ) { |
|
| 227 | +function wpinv_record_item_in_log($item_id = 0, $file_id, $user_info, $ip, $invoice_id) { |
|
| 228 | 228 | global $wpinv_logs; |
| 229 | 229 | |
| 230 | - if ( empty( $wpinv_logs ) ) { |
|
| 230 | + if (empty($wpinv_logs)) { |
|
| 231 | 231 | return false; |
| 232 | 232 | } |
| 233 | 233 | |
@@ -236,7 +236,7 @@ discard block |
||
| 236 | 236 | 'log_type' => 'wpi_item' |
| 237 | 237 | ); |
| 238 | 238 | |
| 239 | - $user_id = isset( $user_info['user_id'] ) ? $user_info['user_id'] : (int) -1; |
|
| 239 | + $user_id = isset($user_info['user_id']) ? $user_info['user_id'] : (int) -1; |
|
| 240 | 240 | |
| 241 | 241 | $log_meta = array( |
| 242 | 242 | 'user_info' => $user_info, |
@@ -246,253 +246,253 @@ discard block |
||
| 246 | 246 | 'invoice_id'=> $invoice_id, |
| 247 | 247 | ); |
| 248 | 248 | |
| 249 | - $wpinv_logs->insert_log( $log_data, $log_meta ); |
|
| 249 | + $wpinv_logs->insert_log($log_data, $log_meta); |
|
| 250 | 250 | } |
| 251 | 251 | |
| 252 | -function wpinv_remove_item_logs_on_delete( $item_id = 0 ) { |
|
| 253 | - if ( 'wpi_item' !== get_post_type( $item_id ) ) |
|
| 252 | +function wpinv_remove_item_logs_on_delete($item_id = 0) { |
|
| 253 | + if ('wpi_item' !== get_post_type($item_id)) |
|
| 254 | 254 | return; |
| 255 | 255 | |
| 256 | 256 | global $wpinv_logs; |
| 257 | 257 | |
| 258 | - if ( empty( $wpinv_logs ) ) { |
|
| 258 | + if (empty($wpinv_logs)) { |
|
| 259 | 259 | return false; |
| 260 | 260 | } |
| 261 | 261 | |
| 262 | 262 | // Remove all log entries related to this item |
| 263 | - $wpinv_logs->delete_logs( $item_id ); |
|
| 263 | + $wpinv_logs->delete_logs($item_id); |
|
| 264 | 264 | } |
| 265 | -add_action( 'delete_post', 'wpinv_remove_item_logs_on_delete' ); |
|
| 265 | +add_action('delete_post', 'wpinv_remove_item_logs_on_delete'); |
|
| 266 | 266 | |
| 267 | -function wpinv_get_random_item( $post_ids = true ) { |
|
| 268 | - wpinv_get_random_items( 1, $post_ids ); |
|
| 267 | +function wpinv_get_random_item($post_ids = true) { |
|
| 268 | + wpinv_get_random_items(1, $post_ids); |
|
| 269 | 269 | } |
| 270 | 270 | |
| 271 | -function wpinv_get_random_items( $num = 3, $post_ids = true ) { |
|
| 272 | - if ( $post_ids ) { |
|
| 273 | - $args = array( 'post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num, 'fields' => 'ids' ); |
|
| 271 | +function wpinv_get_random_items($num = 3, $post_ids = true) { |
|
| 272 | + if ($post_ids) { |
|
| 273 | + $args = array('post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num, 'fields' => 'ids'); |
|
| 274 | 274 | } else { |
| 275 | - $args = array( 'post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num ); |
|
| 275 | + $args = array('post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num); |
|
| 276 | 276 | } |
| 277 | 277 | |
| 278 | - $args = apply_filters( 'wpinv_get_random_items', $args ); |
|
| 278 | + $args = apply_filters('wpinv_get_random_items', $args); |
|
| 279 | 279 | |
| 280 | - return get_posts( $args ); |
|
| 280 | + return get_posts($args); |
|
| 281 | 281 | } |
| 282 | 282 | |
| 283 | -function wpinv_get_item_token( $url = '' ) { |
|
| 283 | +function wpinv_get_item_token($url = '') { |
|
| 284 | 284 | $args = array(); |
| 285 | - $hash = apply_filters( 'wpinv_get_url_token_algorithm', 'sha256' ); |
|
| 286 | - $secret = apply_filters( 'wpinv_get_url_token_secret', hash( $hash, wp_salt() ) ); |
|
| 285 | + $hash = apply_filters('wpinv_get_url_token_algorithm', 'sha256'); |
|
| 286 | + $secret = apply_filters('wpinv_get_url_token_secret', hash($hash, wp_salt())); |
|
| 287 | 287 | |
| 288 | - $parts = parse_url( $url ); |
|
| 288 | + $parts = parse_url($url); |
|
| 289 | 289 | $options = array(); |
| 290 | 290 | |
| 291 | - if ( isset( $parts['query'] ) ) { |
|
| 292 | - wp_parse_str( $parts['query'], $query_args ); |
|
| 291 | + if (isset($parts['query'])) { |
|
| 292 | + wp_parse_str($parts['query'], $query_args); |
|
| 293 | 293 | |
| 294 | - if ( ! empty( $query_args['o'] ) ) { |
|
| 295 | - $options = explode( ':', rawurldecode( $query_args['o'] ) ); |
|
| 294 | + if (!empty($query_args['o'])) { |
|
| 295 | + $options = explode(':', rawurldecode($query_args['o'])); |
|
| 296 | 296 | |
| 297 | - if ( in_array( 'ip', $options ) ) { |
|
| 297 | + if (in_array('ip', $options)) { |
|
| 298 | 298 | $args['ip'] = wpinv_get_ip(); |
| 299 | 299 | } |
| 300 | 300 | |
| 301 | - if ( in_array( 'ua', $options ) ) { |
|
| 301 | + if (in_array('ua', $options)) { |
|
| 302 | 302 | $ua = wpinv_get_user_agent(); |
| 303 | - $args['user_agent'] = rawurlencode( $ua ); |
|
| 303 | + $args['user_agent'] = rawurlencode($ua); |
|
| 304 | 304 | } |
| 305 | 305 | } |
| 306 | 306 | } |
| 307 | 307 | |
| 308 | - $args = apply_filters( 'wpinv_get_url_token_args', $args, $url, $options ); |
|
| 308 | + $args = apply_filters('wpinv_get_url_token_args', $args, $url, $options); |
|
| 309 | 309 | |
| 310 | 310 | $args['secret'] = $secret; |
| 311 | 311 | $args['token'] = false; |
| 312 | 312 | |
| 313 | - $url = add_query_arg( $args, $url ); |
|
| 314 | - $parts = parse_url( $url ); |
|
| 313 | + $url = add_query_arg($args, $url); |
|
| 314 | + $parts = parse_url($url); |
|
| 315 | 315 | |
| 316 | - if ( ! isset( $parts['path'] ) ) { |
|
| 316 | + if (!isset($parts['path'])) { |
|
| 317 | 317 | $parts['path'] = ''; |
| 318 | 318 | } |
| 319 | 319 | |
| 320 | - $token = md5( $parts['path'] . '?' . $parts['query'] ); |
|
| 320 | + $token = md5($parts['path'] . '?' . $parts['query']); |
|
| 321 | 321 | |
| 322 | 322 | return $token; |
| 323 | 323 | } |
| 324 | 324 | |
| 325 | -function wpinv_validate_url_token( $url = '' ) { |
|
| 325 | +function wpinv_validate_url_token($url = '') { |
|
| 326 | 326 | $ret = false; |
| 327 | - $parts = parse_url( $url ); |
|
| 327 | + $parts = parse_url($url); |
|
| 328 | 328 | |
| 329 | - if ( isset( $parts['query'] ) ) { |
|
| 330 | - wp_parse_str( $parts['query'], $query_args ); |
|
| 329 | + if (isset($parts['query'])) { |
|
| 330 | + wp_parse_str($parts['query'], $query_args); |
|
| 331 | 331 | |
| 332 | - $allowed = apply_filters( 'wpinv_url_token_allowed_params', array( |
|
| 332 | + $allowed = apply_filters('wpinv_url_token_allowed_params', array( |
|
| 333 | 333 | 'item', |
| 334 | 334 | 'ttl', |
| 335 | 335 | 'token' |
| 336 | - ) ); |
|
| 336 | + )); |
|
| 337 | 337 | |
| 338 | 338 | $remove = array(); |
| 339 | 339 | |
| 340 | - foreach( $query_args as $key => $value ) { |
|
| 341 | - if( false === in_array( $key, $allowed ) ) { |
|
| 340 | + foreach ($query_args as $key => $value) { |
|
| 341 | + if (false === in_array($key, $allowed)) { |
|
| 342 | 342 | $remove[] = $key; |
| 343 | 343 | } |
| 344 | 344 | } |
| 345 | 345 | |
| 346 | - if( ! empty( $remove ) ) { |
|
| 347 | - $url = remove_query_arg( $remove, $url ); |
|
| 346 | + if (!empty($remove)) { |
|
| 347 | + $url = remove_query_arg($remove, $url); |
|
| 348 | 348 | } |
| 349 | 349 | |
| 350 | - if ( isset( $query_args['ttl'] ) && current_time( 'timestamp' ) > $query_args['ttl'] ) { |
|
| 351 | - wp_die( apply_filters( 'wpinv_item_link_expired_text', __( 'Sorry but your item link has expired.', 'invoicing' ) ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
| 350 | + if (isset($query_args['ttl']) && current_time('timestamp') > $query_args['ttl']) { |
|
| 351 | + wp_die(apply_filters('wpinv_item_link_expired_text', __('Sorry but your item link has expired.', 'invoicing')), __('Error', 'invoicing'), array('response' => 403)); |
|
| 352 | 352 | } |
| 353 | 353 | |
| 354 | - if ( isset( $query_args['token'] ) && $query_args['token'] == wpinv_get_item_token( $url ) ) { |
|
| 354 | + if (isset($query_args['token']) && $query_args['token'] == wpinv_get_item_token($url)) { |
|
| 355 | 355 | $ret = true; |
| 356 | 356 | } |
| 357 | 357 | |
| 358 | 358 | } |
| 359 | 359 | |
| 360 | - return apply_filters( 'wpinv_validate_url_token', $ret, $url, $query_args ); |
|
| 360 | + return apply_filters('wpinv_validate_url_token', $ret, $url, $query_args); |
|
| 361 | 361 | } |
| 362 | 362 | |
| 363 | -function wpinv_item_in_cart( $item_id = 0, $options = array() ) { |
|
| 363 | +function wpinv_item_in_cart($item_id = 0, $options = array()) { |
|
| 364 | 364 | $cart_items = wpinv_get_cart_contents(); |
| 365 | 365 | |
| 366 | 366 | $ret = false; |
| 367 | 367 | |
| 368 | - if ( is_array( $cart_items ) ) { |
|
| 369 | - foreach ( $cart_items as $item ) { |
|
| 370 | - if ( $item['id'] == $item_id ) { |
|
| 368 | + if (is_array($cart_items)) { |
|
| 369 | + foreach ($cart_items as $item) { |
|
| 370 | + if ($item['id'] == $item_id) { |
|
| 371 | 371 | $ret = true; |
| 372 | 372 | break; |
| 373 | 373 | } |
| 374 | 374 | } |
| 375 | 375 | } |
| 376 | 376 | |
| 377 | - return (bool) apply_filters( 'wpinv_item_in_cart', $ret, $item_id, $options ); |
|
| 377 | + return (bool)apply_filters('wpinv_item_in_cart', $ret, $item_id, $options); |
|
| 378 | 378 | } |
| 379 | 379 | |
| 380 | -function wpinv_get_cart_item_tax( $item_id = 0, $subtotal = '', $options = array() ) { |
|
| 380 | +function wpinv_get_cart_item_tax($item_id = 0, $subtotal = '', $options = array()) { |
|
| 381 | 381 | $tax = 0; |
| 382 | - if ( ! wpinv_item_is_tax_exclusive( $item_id ) ) { |
|
| 383 | - $country = !empty( $_POST['country'] ) ? $_POST['country'] : false; |
|
| 384 | - $state = isset( $_POST['state'] ) ? $_POST['state'] : ''; |
|
| 382 | + if (!wpinv_item_is_tax_exclusive($item_id)) { |
|
| 383 | + $country = !empty($_POST['country']) ? $_POST['country'] : false; |
|
| 384 | + $state = isset($_POST['state']) ? $_POST['state'] : ''; |
|
| 385 | 385 | |
| 386 | - $tax = wpinv_calculate_tax( $subtotal, $country, $state, $item_id ); |
|
| 386 | + $tax = wpinv_calculate_tax($subtotal, $country, $state, $item_id); |
|
| 387 | 387 | } |
| 388 | 388 | |
| 389 | - return apply_filters( 'wpinv_get_cart_item_tax', $tax, $item_id, $subtotal, $options ); |
|
| 389 | + return apply_filters('wpinv_get_cart_item_tax', $tax, $item_id, $subtotal, $options); |
|
| 390 | 390 | } |
| 391 | 391 | |
| 392 | -function wpinv_cart_item_price( $item ) { |
|
| 392 | +function wpinv_cart_item_price($item) { |
|
| 393 | 393 | $use_taxes = wpinv_use_taxes(); |
| 394 | - $item_id = isset( $item['id'] ) ? $item['id'] : 0; |
|
| 395 | - $price = isset( $item['item_price'] ) ? wpinv_round_amount( $item['item_price'] ) : 0; |
|
| 396 | - $options = isset( $item['options'] ) ? $item['options'] : array(); |
|
| 397 | - $price_id = isset( $options['price_id'] ) ? $options['price_id'] : false; |
|
| 398 | - $tax = wpinv_price( wpinv_format_amount( $item['tax'] ) ); |
|
| 399 | - |
|
| 400 | - if ( !wpinv_is_free_item( $item_id, $price_id ) && !wpinv_item_is_tax_exclusive( $item_id ) ) { |
|
| 401 | - if ( wpinv_prices_show_tax_on_checkout() && !wpinv_prices_include_tax() ) { |
|
| 394 | + $item_id = isset($item['id']) ? $item['id'] : 0; |
|
| 395 | + $price = isset($item['item_price']) ? wpinv_round_amount($item['item_price']) : 0; |
|
| 396 | + $options = isset($item['options']) ? $item['options'] : array(); |
|
| 397 | + $price_id = isset($options['price_id']) ? $options['price_id'] : false; |
|
| 398 | + $tax = wpinv_price(wpinv_format_amount($item['tax'])); |
|
| 399 | + |
|
| 400 | + if (!wpinv_is_free_item($item_id, $price_id) && !wpinv_item_is_tax_exclusive($item_id)) { |
|
| 401 | + if (wpinv_prices_show_tax_on_checkout() && !wpinv_prices_include_tax()) { |
|
| 402 | 402 | $price += $tax; |
| 403 | 403 | } |
| 404 | 404 | |
| 405 | - if( !wpinv_prices_show_tax_on_checkout() && wpinv_prices_include_tax() ) { |
|
| 405 | + if (!wpinv_prices_show_tax_on_checkout() && wpinv_prices_include_tax()) { |
|
| 406 | 406 | $price -= $tax; |
| 407 | 407 | } |
| 408 | 408 | } |
| 409 | 409 | |
| 410 | - $price = wpinv_price( wpinv_format_amount( $price ) ); |
|
| 410 | + $price = wpinv_price(wpinv_format_amount($price)); |
|
| 411 | 411 | |
| 412 | - return apply_filters( 'wpinv_cart_item_price_label', $price, $item ); |
|
| 412 | + return apply_filters('wpinv_cart_item_price_label', $price, $item); |
|
| 413 | 413 | } |
| 414 | 414 | |
| 415 | -function wpinv_cart_item_subtotal( $item ) { |
|
| 416 | - $subtotal = isset( $item['subtotal'] ) ? $item['subtotal'] : 0; |
|
| 417 | - $subtotal = wpinv_price( wpinv_format_amount( $subtotal ) ); |
|
| 415 | +function wpinv_cart_item_subtotal($item) { |
|
| 416 | + $subtotal = isset($item['subtotal']) ? $item['subtotal'] : 0; |
|
| 417 | + $subtotal = wpinv_price(wpinv_format_amount($subtotal)); |
|
| 418 | 418 | |
| 419 | - return apply_filters( 'wpinv_cart_item_subtotal_label', $subtotal, $item ); |
|
| 419 | + return apply_filters('wpinv_cart_item_subtotal_label', $subtotal, $item); |
|
| 420 | 420 | } |
| 421 | 421 | |
| 422 | -function wpinv_cart_item_tax( $item ) { |
|
| 422 | +function wpinv_cart_item_tax($item) { |
|
| 423 | 423 | $tax = ''; |
| 424 | 424 | $tax_rate = ''; |
| 425 | 425 | |
| 426 | - if ( isset( $item['tax'] ) && $item['tax'] > 0 && $item['subtotal'] > 0 ) { |
|
| 427 | - $tax = wpinv_price( wpinv_format_amount( $item['tax'] ) ); |
|
| 428 | - $tax_rate = !empty( $item['vat_rate'] ) ? $item['vat_rate'] : ( $item['tax'] / $item['subtotal'] ) * 100; |
|
| 429 | - $tax_rate = $tax_rate > 0 ? (float)wpinv_round_amount( $tax_rate, 4 ) : ''; |
|
| 426 | + if (isset($item['tax']) && $item['tax'] > 0 && $item['subtotal'] > 0) { |
|
| 427 | + $tax = wpinv_price(wpinv_format_amount($item['tax'])); |
|
| 428 | + $tax_rate = !empty($item['vat_rate']) ? $item['vat_rate'] : ($item['tax'] / $item['subtotal']) * 100; |
|
| 429 | + $tax_rate = $tax_rate > 0 ? (float)wpinv_round_amount($tax_rate, 4) : ''; |
|
| 430 | 430 | $tax_rate = $tax_rate != '' ? ' <small class="tax-rate normal small">(' . $tax_rate . '%)</small>' : ''; |
| 431 | 431 | } |
| 432 | 432 | |
| 433 | - $tax = $tax . $tax_rate; |
|
| 433 | + $tax = $tax . $tax_rate; |
|
| 434 | 434 | |
| 435 | - if ( $tax === '' ) { |
|
| 435 | + if ($tax === '') { |
|
| 436 | 436 | $tax = 0; // Zero tax |
| 437 | 437 | } |
| 438 | 438 | |
| 439 | - return apply_filters( 'wpinv_cart_item_tax_label', $tax, $item ); |
|
| 439 | + return apply_filters('wpinv_cart_item_tax_label', $tax, $item); |
|
| 440 | 440 | } |
| 441 | 441 | |
| 442 | -function wpinv_get_cart_item_price( $item_id = 0, $cart_item = array(), $options = array(), $remove_tax_from_inclusive = false ) { |
|
| 442 | +function wpinv_get_cart_item_price($item_id = 0, $cart_item = array(), $options = array(), $remove_tax_from_inclusive = false) { |
|
| 443 | 443 | $price = 0; |
| 444 | 444 | |
| 445 | 445 | // Set custom price |
| 446 | - if ( isset( $cart_item['custom_price'] ) && $cart_item['custom_price'] !== '' ) { |
|
| 446 | + if (isset($cart_item['custom_price']) && $cart_item['custom_price'] !== '') { |
|
| 447 | 447 | $price = $cart_item['custom_price']; |
| 448 | 448 | } else { |
| 449 | - $variable_prices = wpinv_has_variable_prices( $item_id ); |
|
| 449 | + $variable_prices = wpinv_has_variable_prices($item_id); |
|
| 450 | 450 | |
| 451 | - if ( $variable_prices ) { |
|
| 452 | - $prices = wpinv_get_variable_prices( $item_id ); |
|
| 451 | + if ($variable_prices) { |
|
| 452 | + $prices = wpinv_get_variable_prices($item_id); |
|
| 453 | 453 | |
| 454 | - if ( $prices ) { |
|
| 455 | - if( ! empty( $options ) ) { |
|
| 456 | - $price = isset( $prices[ $options['price_id'] ] ) ? $prices[ $options['price_id'] ]['amount'] : false; |
|
| 454 | + if ($prices) { |
|
| 455 | + if (!empty($options)) { |
|
| 456 | + $price = isset($prices[$options['price_id']]) ? $prices[$options['price_id']]['amount'] : false; |
|
| 457 | 457 | } else { |
| 458 | 458 | $price = false; |
| 459 | 459 | } |
| 460 | 460 | } |
| 461 | 461 | } |
| 462 | 462 | |
| 463 | - if( ! $variable_prices || false === $price ) { |
|
| 463 | + if (!$variable_prices || false === $price) { |
|
| 464 | 464 | // Get the standard Item price if not using variable prices |
| 465 | - $price = wpinv_get_item_price( $item_id ); |
|
| 465 | + $price = wpinv_get_item_price($item_id); |
|
| 466 | 466 | } |
| 467 | 467 | } |
| 468 | 468 | |
| 469 | - if ( $remove_tax_from_inclusive && wpinv_prices_include_tax() ) { |
|
| 470 | - $price -= wpinv_get_cart_item_tax( $item_id, $price, $options ); |
|
| 469 | + if ($remove_tax_from_inclusive && wpinv_prices_include_tax()) { |
|
| 470 | + $price -= wpinv_get_cart_item_tax($item_id, $price, $options); |
|
| 471 | 471 | } |
| 472 | 472 | |
| 473 | - return apply_filters( 'wpinv_cart_item_price', $price, $item_id, $cart_item, $options, $remove_tax_from_inclusive ); |
|
| 473 | + return apply_filters('wpinv_cart_item_price', $price, $item_id, $cart_item, $options, $remove_tax_from_inclusive); |
|
| 474 | 474 | } |
| 475 | 475 | |
| 476 | -function wpinv_get_cart_item_price_id( $item = array() ) { |
|
| 477 | - if( isset( $item['item_number'] ) ) { |
|
| 478 | - $price_id = isset( $item['item_number']['options']['price_id'] ) ? $item['item_number']['options']['price_id'] : null; |
|
| 476 | +function wpinv_get_cart_item_price_id($item = array()) { |
|
| 477 | + if (isset($item['item_number'])) { |
|
| 478 | + $price_id = isset($item['item_number']['options']['price_id']) ? $item['item_number']['options']['price_id'] : null; |
|
| 479 | 479 | } else { |
| 480 | - $price_id = isset( $item['options']['price_id'] ) ? $item['options']['price_id'] : null; |
|
| 480 | + $price_id = isset($item['options']['price_id']) ? $item['options']['price_id'] : null; |
|
| 481 | 481 | } |
| 482 | 482 | return $price_id; |
| 483 | 483 | } |
| 484 | 484 | |
| 485 | -function wpinv_get_cart_item_price_name( $item = array() ) { |
|
| 486 | - $price_id = (int)wpinv_get_cart_item_price_id( $item ); |
|
| 487 | - $prices = wpinv_get_variable_prices( $item['id'] ); |
|
| 488 | - $name = ! empty( $prices[ $price_id ] ) ? $prices[ $price_id ]['name'] : ''; |
|
| 489 | - return apply_filters( 'wpinv_get_cart_item_price_name', $name, $item['id'], $price_id, $item ); |
|
| 485 | +function wpinv_get_cart_item_price_name($item = array()) { |
|
| 486 | + $price_id = (int)wpinv_get_cart_item_price_id($item); |
|
| 487 | + $prices = wpinv_get_variable_prices($item['id']); |
|
| 488 | + $name = !empty($prices[$price_id]) ? $prices[$price_id]['name'] : ''; |
|
| 489 | + return apply_filters('wpinv_get_cart_item_price_name', $name, $item['id'], $price_id, $item); |
|
| 490 | 490 | } |
| 491 | 491 | |
| 492 | -function wpinv_get_cart_item_name( $item = array() ) { |
|
| 493 | - $item_title = !empty( $item['name'] ) ? $item['name'] : get_the_title( $item['id'] ); |
|
| 492 | +function wpinv_get_cart_item_name($item = array()) { |
|
| 493 | + $item_title = !empty($item['name']) ? $item['name'] : get_the_title($item['id']); |
|
| 494 | 494 | |
| 495 | - if ( empty( $item_title ) ) { |
|
| 495 | + if (empty($item_title)) { |
|
| 496 | 496 | $item_title = $item['id']; |
| 497 | 497 | } |
| 498 | 498 | |
@@ -502,23 +502,23 @@ discard block |
||
| 502 | 502 | } |
| 503 | 503 | */ |
| 504 | 504 | |
| 505 | - return apply_filters( 'wpinv_get_cart_item_name', $item_title, $item['id'], $item ); |
|
| 505 | + return apply_filters('wpinv_get_cart_item_name', $item_title, $item['id'], $item); |
|
| 506 | 506 | } |
| 507 | 507 | |
| 508 | -function wpinv_has_variable_prices( $item_id = 0 ) { |
|
| 508 | +function wpinv_has_variable_prices($item_id = 0) { |
|
| 509 | 509 | return false; |
| 510 | 510 | } |
| 511 | 511 | |
| 512 | -function wpinv_get_item_position_in_cart( $item_id = 0, $options = array() ) { |
|
| 512 | +function wpinv_get_item_position_in_cart($item_id = 0, $options = array()) { |
|
| 513 | 513 | $cart_items = wpinv_get_cart_contents(); |
| 514 | 514 | |
| 515 | - if ( !is_array( $cart_items ) ) { |
|
| 515 | + if (!is_array($cart_items)) { |
|
| 516 | 516 | return false; // Empty cart |
| 517 | 517 | } else { |
| 518 | - foreach ( $cart_items as $position => $item ) { |
|
| 519 | - if ( $item['id'] == $item_id ) { |
|
| 520 | - if ( isset( $options['price_id'] ) && isset( $item['options']['price_id'] ) ) { |
|
| 521 | - if ( (int) $options['price_id'] == (int) $item['options']['price_id'] ) { |
|
| 518 | + foreach ($cart_items as $position => $item) { |
|
| 519 | + if ($item['id'] == $item_id) { |
|
| 520 | + if (isset($options['price_id']) && isset($item['options']['price_id'])) { |
|
| 521 | + if ((int)$options['price_id'] == (int)$item['options']['price_id']) { |
|
| 522 | 522 | return $position; |
| 523 | 523 | } |
| 524 | 524 | } else { |
@@ -531,80 +531,80 @@ discard block |
||
| 531 | 531 | return false; // Not found |
| 532 | 532 | } |
| 533 | 533 | |
| 534 | -function wpinv_get_cart_item_quantity( $item ) { |
|
| 535 | - if ( wpinv_item_quantities_enabled() ) { |
|
| 536 | - $quantity = !empty( $item['quantity'] ) && (int)$item['quantity'] > 0 ? absint( $item['quantity'] ) : 1; |
|
| 534 | +function wpinv_get_cart_item_quantity($item) { |
|
| 535 | + if (wpinv_item_quantities_enabled()) { |
|
| 536 | + $quantity = !empty($item['quantity']) && (int)$item['quantity'] > 0 ? absint($item['quantity']) : 1; |
|
| 537 | 537 | } else { |
| 538 | 538 | $quantity = 1; |
| 539 | 539 | } |
| 540 | 540 | |
| 541 | - if ( $quantity < 1 ) { |
|
| 541 | + if ($quantity < 1) { |
|
| 542 | 542 | $quantity = 1; |
| 543 | 543 | } |
| 544 | 544 | |
| 545 | - return apply_filters( 'wpinv_get_cart_item_quantity', $quantity, $item ); |
|
| 545 | + return apply_filters('wpinv_get_cart_item_quantity', $quantity, $item); |
|
| 546 | 546 | } |
| 547 | 547 | |
| 548 | -function wpinv_get_item_suffix( $item, $html = true ) { |
|
| 549 | - if ( empty( $item ) ) { |
|
| 548 | +function wpinv_get_item_suffix($item, $html = true) { |
|
| 549 | + if (empty($item)) { |
|
| 550 | 550 | return NULL; |
| 551 | 551 | } |
| 552 | 552 | |
| 553 | - if ( is_int( $item ) ) { |
|
| 554 | - $item = new WPInv_Item( $item ); |
|
| 553 | + if (is_int($item)) { |
|
| 554 | + $item = new WPInv_Item($item); |
|
| 555 | 555 | } |
| 556 | 556 | |
| 557 | - if ( !( is_object( $item ) && is_a( $item, 'WPInv_Item' ) ) ) { |
|
| 557 | + if (!(is_object($item) && is_a($item, 'WPInv_Item'))) { |
|
| 558 | 558 | return NULL; |
| 559 | 559 | } |
| 560 | 560 | |
| 561 | - $suffix = $item->is_recurring() ? ' <span class="wpi-suffix">' . __( '(r)', 'invoicing' ) . '</span>' : ''; |
|
| 561 | + $suffix = $item->is_recurring() ? ' <span class="wpi-suffix">' . __('(r)', 'invoicing') . '</span>' : ''; |
|
| 562 | 562 | |
| 563 | - if ( !$html && $suffix ) { |
|
| 564 | - $suffix = strip_tags( $suffix ); |
|
| 563 | + if (!$html && $suffix) { |
|
| 564 | + $suffix = strip_tags($suffix); |
|
| 565 | 565 | } |
| 566 | 566 | |
| 567 | - return apply_filters( 'wpinv_get_item_suffix', $suffix, $item, $html ); |
|
| 567 | + return apply_filters('wpinv_get_item_suffix', $suffix, $item, $html); |
|
| 568 | 568 | } |
| 569 | 569 | |
| 570 | -function wpinv_remove_item( $item = 0, $force_delete = false ) { |
|
| 571 | - if ( empty( $item ) ) { |
|
| 570 | +function wpinv_remove_item($item = 0, $force_delete = false) { |
|
| 571 | + if (empty($item)) { |
|
| 572 | 572 | return NULL; |
| 573 | 573 | } |
| 574 | 574 | |
| 575 | - if ( is_int( $item ) ) { |
|
| 576 | - $item = new WPInv_Item( $item ); |
|
| 575 | + if (is_int($item)) { |
|
| 576 | + $item = new WPInv_Item($item); |
|
| 577 | 577 | } |
| 578 | 578 | |
| 579 | - if ( !( is_object( $item ) && is_a( $item, 'WPInv_Item' ) ) ) { |
|
| 579 | + if (!(is_object($item) && is_a($item, 'WPInv_Item'))) { |
|
| 580 | 580 | return NULL; |
| 581 | 581 | } |
| 582 | 582 | |
| 583 | - do_action( 'wpinv_pre_delete_item', $item ); |
|
| 583 | + do_action('wpinv_pre_delete_item', $item); |
|
| 584 | 584 | |
| 585 | - wp_delete_post( $item->ID, $force_delete ); |
|
| 585 | + wp_delete_post($item->ID, $force_delete); |
|
| 586 | 586 | |
| 587 | - do_action( 'wpinv_post_delete_item', $item ); |
|
| 587 | + do_action('wpinv_post_delete_item', $item); |
|
| 588 | 588 | } |
| 589 | 589 | |
| 590 | -function wpinv_can_delete_item( $post_id ) { |
|
| 591 | - $return = current_user_can( 'manage_options' ) ? true : false; |
|
| 590 | +function wpinv_can_delete_item($post_id) { |
|
| 591 | + $return = current_user_can('manage_options') ? true : false; |
|
| 592 | 592 | |
| 593 | - if ( $return && wpinv_item_in_use( $post_id ) ) { |
|
| 593 | + if ($return && wpinv_item_in_use($post_id)) { |
|
| 594 | 594 | $return = false; // Don't delete item already use in invoices. |
| 595 | 595 | } |
| 596 | 596 | |
| 597 | - return apply_filters( 'wpinv_can_delete_item', $return, $post_id ); |
|
| 597 | + return apply_filters('wpinv_can_delete_item', $return, $post_id); |
|
| 598 | 598 | } |
| 599 | 599 | |
| 600 | 600 | function wpinv_admin_action_delete() { |
| 601 | 601 | $screen = get_current_screen(); |
| 602 | 602 | |
| 603 | - if ( !empty( $screen->post_type ) && $screen->post_type == 'wpi_item' && !empty( $_REQUEST['post'] ) && is_array( $_REQUEST['post'] ) ) { |
|
| 603 | + if (!empty($screen->post_type) && $screen->post_type == 'wpi_item' && !empty($_REQUEST['post']) && is_array($_REQUEST['post'])) { |
|
| 604 | 604 | $post_ids = array(); |
| 605 | 605 | |
| 606 | - foreach ( $_REQUEST['post'] as $post_id ) { |
|
| 607 | - if ( !wpinv_can_delete_item( $post_id ) ) { |
|
| 606 | + foreach ($_REQUEST['post'] as $post_id) { |
|
| 607 | + if (!wpinv_can_delete_item($post_id)) { |
|
| 608 | 608 | continue; |
| 609 | 609 | } |
| 610 | 610 | |
@@ -614,81 +614,81 @@ discard block |
||
| 614 | 614 | $_REQUEST['post'] = $post_ids; |
| 615 | 615 | } |
| 616 | 616 | } |
| 617 | -add_action( 'admin_action_trash', 'wpinv_admin_action_delete', -10 ); |
|
| 618 | -add_action( 'admin_action_delete', 'wpinv_admin_action_delete', -10 ); |
|
| 617 | +add_action('admin_action_trash', 'wpinv_admin_action_delete', -10); |
|
| 618 | +add_action('admin_action_delete', 'wpinv_admin_action_delete', -10); |
|
| 619 | 619 | |
| 620 | -function wpinv_check_delete_item( $check, $post, $force_delete ) { |
|
| 621 | - if ( $post->post_type == 'wpi_item' ) { |
|
| 622 | - if ( $force_delete && !wpinv_can_delete_item( $post->ID ) ) { |
|
| 620 | +function wpinv_check_delete_item($check, $post, $force_delete) { |
|
| 621 | + if ($post->post_type == 'wpi_item') { |
|
| 622 | + if ($force_delete && !wpinv_can_delete_item($post->ID)) { |
|
| 623 | 623 | return true; |
| 624 | 624 | } |
| 625 | 625 | } |
| 626 | 626 | |
| 627 | 627 | return $check; |
| 628 | 628 | } |
| 629 | -add_filter( 'pre_delete_post', 'wpinv_check_delete_item', 10, 3 ); |
|
| 629 | +add_filter('pre_delete_post', 'wpinv_check_delete_item', 10, 3); |
|
| 630 | 630 | |
| 631 | -function wpinv_item_in_use( $item_id ) { |
|
| 631 | +function wpinv_item_in_use($item_id) { |
|
| 632 | 632 | global $wpdb, $wpi_items_in_use; |
| 633 | 633 | |
| 634 | - if ( !$item_id > 0 ) { |
|
| 634 | + if (!$item_id > 0) { |
|
| 635 | 635 | return false; |
| 636 | 636 | } |
| 637 | 637 | |
| 638 | - if ( !empty( $wpi_items_in_use ) ) { |
|
| 639 | - if ( isset( $wpi_items_in_use[$item_id] ) ) { |
|
| 638 | + if (!empty($wpi_items_in_use)) { |
|
| 639 | + if (isset($wpi_items_in_use[$item_id])) { |
|
| 640 | 640 | return $wpi_items_in_use[$item_id]; |
| 641 | 641 | } |
| 642 | 642 | } else { |
| 643 | 643 | $wpi_items_in_use = array(); |
| 644 | 644 | } |
| 645 | 645 | |
| 646 | - $statuses = array_keys( wpinv_get_invoice_statuses( true ) ); |
|
| 646 | + $statuses = array_keys(wpinv_get_invoice_statuses(true)); |
|
| 647 | 647 | |
| 648 | - $query = "SELECT p.ID FROM " . $wpdb->posts . " AS p INNER JOIN " . $wpdb->postmeta . " AS pm ON p.ID = pm.post_id WHERE p.post_type = 'wpi_invoice' AND p.post_status IN( '" . implode( "','", $statuses ) . "' ) AND pm.meta_key = '_wpinv_item_ids' AND FIND_IN_SET( '" . (int)$item_id . "', pm.meta_value )"; |
|
| 649 | - $in_use = $wpdb->get_var( $query ) > 0 ? true : false; |
|
| 648 | + $query = "SELECT p.ID FROM " . $wpdb->posts . " AS p INNER JOIN " . $wpdb->postmeta . " AS pm ON p.ID = pm.post_id WHERE p.post_type = 'wpi_invoice' AND p.post_status IN( '" . implode("','", $statuses) . "' ) AND pm.meta_key = '_wpinv_item_ids' AND FIND_IN_SET( '" . (int)$item_id . "', pm.meta_value )"; |
|
| 649 | + $in_use = $wpdb->get_var($query) > 0 ? true : false; |
|
| 650 | 650 | |
| 651 | 651 | $wpi_items_in_use[$item_id] = $in_use; |
| 652 | 652 | |
| 653 | 653 | return $in_use; |
| 654 | 654 | } |
| 655 | 655 | |
| 656 | -function wpinv_create_item( $args = array(), $wp_error = false, $force_update = false ) { |
|
| 656 | +function wpinv_create_item($args = array(), $wp_error = false, $force_update = false) { |
|
| 657 | 657 | // Set some defaults |
| 658 | 658 | $defaults = array( |
| 659 | - 'type' => 'custom', // Optional. Item type. Default 'custom'. |
|
| 660 | - 'title' => '', // Required. Item title. |
|
| 661 | - 'custom_id' => 0, // Optional. Any integer or non numeric id. Must be unique within item type. |
|
| 662 | - 'price' => '0.00', // Optional. Item price. Default '0.00'. |
|
| 663 | - 'status' => 'pending', // Optional. pending, publish |
|
| 664 | - 'custom_name' => '', // Optional. Plural sub title for item. |
|
| 665 | - 'custom_singular_name' => '', // Optional. Singular sub title for item. |
|
| 666 | - 'vat_rule' => 'digital', // Optional. digital => Digital item, physical => Physical item |
|
| 667 | - 'editable' => true, // Optional. Item editable from Items list page? Default true. |
|
| 668 | - 'excerpt' => '', // Optional. Item short description |
|
| 659 | + 'type' => 'custom', // Optional. Item type. Default 'custom'. |
|
| 660 | + 'title' => '', // Required. Item title. |
|
| 661 | + 'custom_id' => 0, // Optional. Any integer or non numeric id. Must be unique within item type. |
|
| 662 | + 'price' => '0.00', // Optional. Item price. Default '0.00'. |
|
| 663 | + 'status' => 'pending', // Optional. pending, publish |
|
| 664 | + 'custom_name' => '', // Optional. Plural sub title for item. |
|
| 665 | + 'custom_singular_name' => '', // Optional. Singular sub title for item. |
|
| 666 | + 'vat_rule' => 'digital', // Optional. digital => Digital item, physical => Physical item |
|
| 667 | + 'editable' => true, // Optional. Item editable from Items list page? Default true. |
|
| 668 | + 'excerpt' => '', // Optional. Item short description |
|
| 669 | 669 | /* Recurring item fields */ |
| 670 | - 'is_recurring' => 0, // Optional. 1 => Allow recurring or 0 => Don't allow recurring |
|
| 671 | - 'recurring_period' => 'M', // Optional. D => Daily, W => Weekly, M => Monthly, Y => Yearly |
|
| 672 | - 'recurring_interval' => 0, // Optional. Integer value between 1 - 90. |
|
| 673 | - 'recurring_limit' => 0, // Optional. Any integer number. 0 for recurring forever until cancelled. |
|
| 674 | - 'free_trial' => 0, // Optional. 1 => Allow free trial or 0 => Don't free trial |
|
| 675 | - 'trial_period' => 'M', // Optional. D => Daily, W => Weekly, M => Monthly, Y => Yearly |
|
| 676 | - 'trial_interval' => 0, // Optional. Any integer number. |
|
| 670 | + 'is_recurring' => 0, // Optional. 1 => Allow recurring or 0 => Don't allow recurring |
|
| 671 | + 'recurring_period' => 'M', // Optional. D => Daily, W => Weekly, M => Monthly, Y => Yearly |
|
| 672 | + 'recurring_interval' => 0, // Optional. Integer value between 1 - 90. |
|
| 673 | + 'recurring_limit' => 0, // Optional. Any integer number. 0 for recurring forever until cancelled. |
|
| 674 | + 'free_trial' => 0, // Optional. 1 => Allow free trial or 0 => Don't free trial |
|
| 675 | + 'trial_period' => 'M', // Optional. D => Daily, W => Weekly, M => Monthly, Y => Yearly |
|
| 676 | + 'trial_interval' => 0, // Optional. Any integer number. |
|
| 677 | 677 | ); |
| 678 | 678 | |
| 679 | - $data = wp_parse_args( $args, $defaults ); |
|
| 679 | + $data = wp_parse_args($args, $defaults); |
|
| 680 | 680 | |
| 681 | - if ( empty( $data['type'] ) ) { |
|
| 681 | + if (empty($data['type'])) { |
|
| 682 | 682 | $data['type'] = 'custom'; |
| 683 | 683 | } |
| 684 | 684 | |
| 685 | - if ( !empty( $data['custom_id'] ) ) { |
|
| 686 | - $item = wpinv_get_item_by( 'custom_id', $data['custom_id'], $data['type'] ); |
|
| 685 | + if (!empty($data['custom_id'])) { |
|
| 686 | + $item = wpinv_get_item_by('custom_id', $data['custom_id'], $data['type']); |
|
| 687 | 687 | } else { |
| 688 | 688 | $item = NULL; |
| 689 | 689 | } |
| 690 | 690 | |
| 691 | - if ( !$force_update && !empty( $item ) ) { |
|
| 691 | + if (!$force_update && !empty($item)) { |
|
| 692 | 692 | return $item; |
| 693 | 693 | } |
| 694 | 694 | |
@@ -697,19 +697,19 @@ discard block |
||
| 697 | 697 | $meta['custom_id'] = $data['custom_id']; |
| 698 | 698 | $meta['custom_singular_name'] = $data['custom_singular_name']; |
| 699 | 699 | $meta['custom_name'] = $data['custom_name']; |
| 700 | - $meta['price'] = wpinv_round_amount( $data['price'] ); |
|
| 700 | + $meta['price'] = wpinv_round_amount($data['price']); |
|
| 701 | 701 | $meta['editable'] = (int)$data['editable']; |
| 702 | 702 | $meta['vat_rule'] = $data['vat_rule']; |
| 703 | 703 | $meta['vat_class'] = '_standard'; |
| 704 | 704 | |
| 705 | - if ( !empty( $data['is_recurring'] ) ) { |
|
| 705 | + if (!empty($data['is_recurring'])) { |
|
| 706 | 706 | $meta['is_recurring'] = $data['is_recurring']; |
| 707 | 707 | $meta['recurring_period'] = $data['recurring_period']; |
| 708 | - $meta['recurring_interval'] = absint( $data['recurring_interval'] ); |
|
| 709 | - $meta['recurring_limit'] = absint( $data['recurring_limit'] ); |
|
| 708 | + $meta['recurring_interval'] = absint($data['recurring_interval']); |
|
| 709 | + $meta['recurring_limit'] = absint($data['recurring_limit']); |
|
| 710 | 710 | $meta['free_trial'] = $data['free_trial']; |
| 711 | 711 | $meta['trial_period'] = $data['trial_period']; |
| 712 | - $meta['trial_interval'] = absint( $data['trial_interval'] ); |
|
| 712 | + $meta['trial_interval'] = absint($data['trial_interval']); |
|
| 713 | 713 | } else { |
| 714 | 714 | $meta['is_recurring'] = 0; |
| 715 | 715 | $meta['recurring_period'] = ''; |
@@ -720,18 +720,18 @@ discard block |
||
| 720 | 720 | $meta['trial_interval'] = ''; |
| 721 | 721 | } |
| 722 | 722 | |
| 723 | - $post_data = array( |
|
| 723 | + $post_data = array( |
|
| 724 | 724 | 'post_title' => $data['title'], |
| 725 | 725 | 'post_excerpt' => $data['excerpt'], |
| 726 | 726 | 'post_status' => $data['status'], |
| 727 | 727 | 'meta' => $meta |
| 728 | 728 | ); |
| 729 | 729 | |
| 730 | - if ( !empty( $item ) ) { |
|
| 731 | - $item->update( $post_data, $wp_error ); |
|
| 730 | + if (!empty($item)) { |
|
| 731 | + $item->update($post_data, $wp_error); |
|
| 732 | 732 | } else { |
| 733 | 733 | $item = new WPInv_Item(); |
| 734 | - $item->create( $post_data, $wp_error ); |
|
| 734 | + $item->create($post_data, $wp_error); |
|
| 735 | 735 | } |
| 736 | 736 | |
| 737 | 737 | return $item; |
@@ -194,6 +194,9 @@ |
||
| 194 | 194 | return apply_filters( 'wpinv_is_tax_exclusive', $ret, $item_id ); |
| 195 | 195 | } |
| 196 | 196 | |
| 197 | +/** |
|
| 198 | + * @return integer |
|
| 199 | + */ |
|
| 197 | 200 | function wpinv_currency_decimal_filter( $decimals = 2 ) { |
| 198 | 201 | $currency = wpinv_get_currency(); |
| 199 | 202 | |
@@ -70,8 +70,9 @@ discard block |
||
| 70 | 70 | if( !empty( $tax_rates ) ) { |
| 71 | 71 | // Locate the tax rate for this country / state, if it exists |
| 72 | 72 | foreach( $tax_rates as $key => $tax_rate ) { |
| 73 | - if( $country != $tax_rate['country'] ) |
|
| 74 | - continue; |
|
| 73 | + if( $country != $tax_rate['country'] ) { |
|
| 74 | + continue; |
|
| 75 | + } |
|
| 75 | 76 | |
| 76 | 77 | if( !empty( $tax_rate['global'] ) ) { |
| 77 | 78 | if( !empty( $tax_rate['rate'] ) ) { |
@@ -79,8 +80,9 @@ discard block |
||
| 79 | 80 | } |
| 80 | 81 | } else { |
| 81 | 82 | |
| 82 | - if( empty( $tax_rate['state'] ) || strtolower( $state ) != strtolower( $tax_rate['state'] ) ) |
|
| 83 | - continue; |
|
| 83 | + if( empty( $tax_rate['state'] ) || strtolower( $state ) != strtolower( $tax_rate['state'] ) ) { |
|
| 84 | + continue; |
|
| 85 | + } |
|
| 84 | 86 | |
| 85 | 87 | $state_rate = $tax_rate['rate']; |
| 86 | 88 | if( 0 !== $state_rate || !empty( $state_rate ) ) { |
@@ -183,8 +185,9 @@ discard block |
||
| 183 | 185 | } |
| 184 | 186 | |
| 185 | 187 | function wpinv_cart_needs_tax_address_fields() { |
| 186 | - if( !wpinv_is_cart_taxed() ) |
|
| 187 | - return false; |
|
| 188 | + if( !wpinv_is_cart_taxed() ) { |
|
| 189 | + return false; |
|
| 190 | + } |
|
| 188 | 191 | |
| 189 | 192 | return ! did_action( 'wpinv_after_cc_fields', 'wpinv_default_cc_address_fields' ); |
| 190 | 193 | } |
@@ -1,121 +1,121 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | // MUST have WordPress. |
| 3 | -if ( !defined( 'WPINC' ) ) { |
|
| 4 | - exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) ); |
|
| 3 | +if (!defined('WPINC')) { |
|
| 4 | + exit('Do NOT access this file directly: ' . basename(__FILE__)); |
|
| 5 | 5 | } |
| 6 | 6 | |
| 7 | 7 | function wpinv_use_taxes() { |
| 8 | - $ret = wpinv_get_option( 'enable_taxes', false ); |
|
| 8 | + $ret = wpinv_get_option('enable_taxes', false); |
|
| 9 | 9 | |
| 10 | - return (bool) apply_filters( 'wpinv_use_taxes', $ret ); |
|
| 10 | + return (bool)apply_filters('wpinv_use_taxes', $ret); |
|
| 11 | 11 | } |
| 12 | 12 | |
| 13 | 13 | function wpinv_get_tax_rates() { |
| 14 | - $rates = get_option( 'wpinv_tax_rates', array() ); |
|
| 14 | + $rates = get_option('wpinv_tax_rates', array()); |
|
| 15 | 15 | |
| 16 | - return apply_filters( 'wpinv_get_tax_rates', $rates ); |
|
| 16 | + return apply_filters('wpinv_get_tax_rates', $rates); |
|
| 17 | 17 | } |
| 18 | 18 | |
| 19 | -function wpinv_get_tax_rate( $country = false, $state = false, $item_id = 0 ) { |
|
| 19 | +function wpinv_get_tax_rate($country = false, $state = false, $item_id = 0) { |
|
| 20 | 20 | global $wpinv_euvat, $wpi_tax_rates, $wpi_userID; |
| 21 | - $wpi_tax_rates = !empty( $wpi_tax_rates ) ? $wpi_tax_rates : array(); |
|
| 21 | + $wpi_tax_rates = !empty($wpi_tax_rates) ? $wpi_tax_rates : array(); |
|
| 22 | 22 | |
| 23 | - if ( !empty( $wpi_tax_rates ) && !empty( $item_id ) && isset( $wpi_tax_rates[$item_id] ) ) { |
|
| 23 | + if (!empty($wpi_tax_rates) && !empty($item_id) && isset($wpi_tax_rates[$item_id])) { |
|
| 24 | 24 | return $wpi_tax_rates[$item_id]; |
| 25 | 25 | } |
| 26 | 26 | |
| 27 | - if ( !$wpinv_euvat->item_is_taxable( $item_id, $country, $state ) ) { |
|
| 27 | + if (!$wpinv_euvat->item_is_taxable($item_id, $country, $state)) { |
|
| 28 | 28 | $wpi_tax_rates[$item_id] = 0; |
| 29 | 29 | return 0; |
| 30 | 30 | } |
| 31 | 31 | |
| 32 | 32 | $is_global = false; |
| 33 | - if ( $item_id == 'global' ) { |
|
| 33 | + if ($item_id == 'global') { |
|
| 34 | 34 | $is_global = true; |
| 35 | 35 | $item_id = 0; |
| 36 | 36 | } |
| 37 | 37 | |
| 38 | - $rate = (float)wpinv_get_option( 'tax_rate', 0 ); |
|
| 39 | - $user_address = wpinv_get_user_address( $wpi_userID ); |
|
| 38 | + $rate = (float)wpinv_get_option('tax_rate', 0); |
|
| 39 | + $user_address = wpinv_get_user_address($wpi_userID); |
|
| 40 | 40 | |
| 41 | - if( empty( $country ) ) { |
|
| 42 | - if( !empty( $_POST['wpinv_country'] ) ) { |
|
| 41 | + if (empty($country)) { |
|
| 42 | + if (!empty($_POST['wpinv_country'])) { |
|
| 43 | 43 | $country = $_POST['wpinv_country']; |
| 44 | - } elseif( !empty( $_POST['wpinv_country'] ) ) { |
|
| 44 | + } elseif (!empty($_POST['wpinv_country'])) { |
|
| 45 | 45 | $country = $_POST['wpinv_country']; |
| 46 | - } elseif( !empty( $_POST['country'] ) ) { |
|
| 46 | + } elseif (!empty($_POST['country'])) { |
|
| 47 | 47 | $country = $_POST['country']; |
| 48 | - } elseif( is_user_logged_in() && !empty( $user_address ) ) { |
|
| 48 | + } elseif (is_user_logged_in() && !empty($user_address)) { |
|
| 49 | 49 | $country = $user_address['country']; |
| 50 | 50 | } |
| 51 | - $country = !empty( $country ) ? $country : wpinv_get_default_country(); |
|
| 51 | + $country = !empty($country) ? $country : wpinv_get_default_country(); |
|
| 52 | 52 | } |
| 53 | 53 | |
| 54 | - if( empty( $state ) ) { |
|
| 55 | - if( !empty( $_POST['wpinv_state'] ) ) { |
|
| 54 | + if (empty($state)) { |
|
| 55 | + if (!empty($_POST['wpinv_state'])) { |
|
| 56 | 56 | $state = $_POST['wpinv_state']; |
| 57 | - } elseif( !empty( $_POST['wpinv_state'] ) ) { |
|
| 57 | + } elseif (!empty($_POST['wpinv_state'])) { |
|
| 58 | 58 | $state = $_POST['wpinv_state']; |
| 59 | - } elseif( !empty( $_POST['state'] ) ) { |
|
| 59 | + } elseif (!empty($_POST['state'])) { |
|
| 60 | 60 | $state = $_POST['state']; |
| 61 | - } elseif( is_user_logged_in() && !empty( $user_address ) ) { |
|
| 61 | + } elseif (is_user_logged_in() && !empty($user_address)) { |
|
| 62 | 62 | $state = $user_address['state']; |
| 63 | 63 | } |
| 64 | - $state = !empty( $state ) ? $state : wpinv_get_default_state(); |
|
| 64 | + $state = !empty($state) ? $state : wpinv_get_default_state(); |
|
| 65 | 65 | } |
| 66 | 66 | |
| 67 | - if( !empty( $country ) ) { |
|
| 68 | - $tax_rates = wpinv_get_tax_rates(); |
|
| 67 | + if (!empty($country)) { |
|
| 68 | + $tax_rates = wpinv_get_tax_rates(); |
|
| 69 | 69 | |
| 70 | - if( !empty( $tax_rates ) ) { |
|
| 70 | + if (!empty($tax_rates)) { |
|
| 71 | 71 | // Locate the tax rate for this country / state, if it exists |
| 72 | - foreach( $tax_rates as $key => $tax_rate ) { |
|
| 73 | - if( $country != $tax_rate['country'] ) |
|
| 72 | + foreach ($tax_rates as $key => $tax_rate) { |
|
| 73 | + if ($country != $tax_rate['country']) |
|
| 74 | 74 | continue; |
| 75 | 75 | |
| 76 | - if( !empty( $tax_rate['global'] ) ) { |
|
| 77 | - if( !empty( $tax_rate['rate'] ) ) { |
|
| 78 | - $rate = number_format( $tax_rate['rate'], 4 ); |
|
| 76 | + if (!empty($tax_rate['global'])) { |
|
| 77 | + if (!empty($tax_rate['rate'])) { |
|
| 78 | + $rate = number_format($tax_rate['rate'], 4); |
|
| 79 | 79 | } |
| 80 | 80 | } else { |
| 81 | 81 | |
| 82 | - if( empty( $tax_rate['state'] ) || strtolower( $state ) != strtolower( $tax_rate['state'] ) ) |
|
| 82 | + if (empty($tax_rate['state']) || strtolower($state) != strtolower($tax_rate['state'])) |
|
| 83 | 83 | continue; |
| 84 | 84 | |
| 85 | 85 | $state_rate = $tax_rate['rate']; |
| 86 | - if( 0 !== $state_rate || !empty( $state_rate ) ) { |
|
| 87 | - $rate = number_format( $state_rate, 4 ); |
|
| 86 | + if (0 !== $state_rate || !empty($state_rate)) { |
|
| 87 | + $rate = number_format($state_rate, 4); |
|
| 88 | 88 | } |
| 89 | 89 | } |
| 90 | 90 | } |
| 91 | 91 | } |
| 92 | 92 | } |
| 93 | 93 | |
| 94 | - $rate = apply_filters( 'wpinv_tax_rate', $rate, $country, $state, $item_id ); |
|
| 94 | + $rate = apply_filters('wpinv_tax_rate', $rate, $country, $state, $item_id); |
|
| 95 | 95 | |
| 96 | - if ( !empty( $item_id ) ) { |
|
| 96 | + if (!empty($item_id)) { |
|
| 97 | 97 | $wpi_tax_rates[$item_id] = $rate; |
| 98 | - } else if ( $is_global ) { |
|
| 98 | + } else if ($is_global) { |
|
| 99 | 99 | $wpi_tax_rates['global'] = $rate; |
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | return $rate; |
| 103 | 103 | } |
| 104 | 104 | |
| 105 | -function wpinv_get_formatted_tax_rate( $country = false, $state = false, $item_id ) { |
|
| 106 | - $rate = wpinv_get_tax_rate( $country, $state, $item_id ); |
|
| 107 | - $rate = round( $rate, 4 ); |
|
| 105 | +function wpinv_get_formatted_tax_rate($country = false, $state = false, $item_id) { |
|
| 106 | + $rate = wpinv_get_tax_rate($country, $state, $item_id); |
|
| 107 | + $rate = round($rate, 4); |
|
| 108 | 108 | $formatted = $rate .= '%'; |
| 109 | - return apply_filters( 'wpinv_formatted_tax_rate', $formatted, $rate, $country, $state, $item_id ); |
|
| 109 | + return apply_filters('wpinv_formatted_tax_rate', $formatted, $rate, $country, $state, $item_id); |
|
| 110 | 110 | } |
| 111 | 111 | |
| 112 | -function wpinv_calculate_tax( $amount = 0, $country = false, $state = false, $item_id = 0 ) { |
|
| 113 | - $rate = wpinv_get_tax_rate( $country, $state, $item_id ); |
|
| 112 | +function wpinv_calculate_tax($amount = 0, $country = false, $state = false, $item_id = 0) { |
|
| 113 | + $rate = wpinv_get_tax_rate($country, $state, $item_id); |
|
| 114 | 114 | $tax = 0.00; |
| 115 | 115 | |
| 116 | - if ( wpinv_use_taxes() ) { |
|
| 117 | - if ( wpinv_prices_include_tax() ) { |
|
| 118 | - $pre_tax = ( $amount / ( ( 1 + $rate ) * 0.01 ) ); |
|
| 116 | + if (wpinv_use_taxes()) { |
|
| 117 | + if (wpinv_prices_include_tax()) { |
|
| 118 | + $pre_tax = ($amount / ((1 + $rate) * 0.01)); |
|
| 119 | 119 | $tax = $amount - $pre_tax; |
| 120 | 120 | } else { |
| 121 | 121 | $tax = $amount * $rate * 0.01; |
@@ -123,46 +123,46 @@ discard block |
||
| 123 | 123 | |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | - return apply_filters( 'wpinv_taxed_amount', $tax, $rate, $country, $state, $item_id ); |
|
| 126 | + return apply_filters('wpinv_taxed_amount', $tax, $rate, $country, $state, $item_id); |
|
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | function wpinv_prices_include_tax() { |
| 130 | 130 | return false; // TODO |
| 131 | - $ret = ( wpinv_get_option( 'prices_include_tax', false ) == 'yes' && wpinv_use_taxes() ); |
|
| 131 | + $ret = (wpinv_get_option('prices_include_tax', false) == 'yes' && wpinv_use_taxes()); |
|
| 132 | 132 | |
| 133 | - return apply_filters( 'wpinv_prices_include_tax', $ret ); |
|
| 133 | + return apply_filters('wpinv_prices_include_tax', $ret); |
|
| 134 | 134 | } |
| 135 | 135 | |
| 136 | -function wpinv_sales_tax_for_year( $year = null ) { |
|
| 137 | - return wpinv_price( wpinv_format_amount( wpinv_get_sales_tax_for_year( $year ) ) ); |
|
| 136 | +function wpinv_sales_tax_for_year($year = null) { |
|
| 137 | + return wpinv_price(wpinv_format_amount(wpinv_get_sales_tax_for_year($year))); |
|
| 138 | 138 | } |
| 139 | 139 | |
| 140 | -function wpinv_get_sales_tax_for_year( $year = null ) { |
|
| 140 | +function wpinv_get_sales_tax_for_year($year = null) { |
|
| 141 | 141 | global $wpdb; |
| 142 | 142 | |
| 143 | 143 | // Start at zero |
| 144 | 144 | $tax = 0; |
| 145 | 145 | |
| 146 | - if ( ! empty( $year ) ) { |
|
| 146 | + if (!empty($year)) { |
|
| 147 | 147 | $args = array( |
| 148 | 148 | 'post_type' => 'wpi_invoice', |
| 149 | - 'post_status' => array( 'publish' ), |
|
| 149 | + 'post_status' => array('publish'), |
|
| 150 | 150 | 'posts_per_page' => -1, |
| 151 | 151 | 'year' => $year, |
| 152 | 152 | 'fields' => 'ids' |
| 153 | 153 | ); |
| 154 | 154 | |
| 155 | - $payments = get_posts( $args ); |
|
| 156 | - $payment_ids = implode( ',', $payments ); |
|
| 155 | + $payments = get_posts($args); |
|
| 156 | + $payment_ids = implode(',', $payments); |
|
| 157 | 157 | |
| 158 | - if ( count( $payments ) > 0 ) { |
|
| 158 | + if (count($payments) > 0) { |
|
| 159 | 159 | $sql = "SELECT SUM( meta_value ) FROM $wpdb->postmeta WHERE meta_key = '_wpinv_tax' AND post_id IN( $payment_ids )"; |
| 160 | - $tax = $wpdb->get_var( $sql ); |
|
| 160 | + $tax = $wpdb->get_var($sql); |
|
| 161 | 161 | } |
| 162 | 162 | |
| 163 | 163 | } |
| 164 | 164 | |
| 165 | - return apply_filters( 'wpinv_get_sales_tax_for_year', $tax, $year ); |
|
| 165 | + return apply_filters('wpinv_get_sales_tax_for_year', $tax, $year); |
|
| 166 | 166 | } |
| 167 | 167 | |
| 168 | 168 | function wpinv_is_cart_taxed() { |
@@ -171,33 +171,33 @@ discard block |
||
| 171 | 171 | |
| 172 | 172 | function wpinv_prices_show_tax_on_checkout() { |
| 173 | 173 | return false; // TODO |
| 174 | - $ret = ( wpinv_get_option( 'checkout_include_tax', false ) == 'yes' && wpinv_use_taxes() ); |
|
| 174 | + $ret = (wpinv_get_option('checkout_include_tax', false) == 'yes' && wpinv_use_taxes()); |
|
| 175 | 175 | |
| 176 | - return apply_filters( 'wpinv_taxes_on_prices_on_checkout', $ret ); |
|
| 176 | + return apply_filters('wpinv_taxes_on_prices_on_checkout', $ret); |
|
| 177 | 177 | } |
| 178 | 178 | |
| 179 | 179 | function wpinv_display_tax_rate() { |
| 180 | - $ret = wpinv_use_taxes() && wpinv_get_option( 'display_tax_rate', false ); |
|
| 180 | + $ret = wpinv_use_taxes() && wpinv_get_option('display_tax_rate', false); |
|
| 181 | 181 | |
| 182 | - return apply_filters( 'wpinv_display_tax_rate', $ret ); |
|
| 182 | + return apply_filters('wpinv_display_tax_rate', $ret); |
|
| 183 | 183 | } |
| 184 | 184 | |
| 185 | 185 | function wpinv_cart_needs_tax_address_fields() { |
| 186 | - if( !wpinv_is_cart_taxed() ) |
|
| 186 | + if (!wpinv_is_cart_taxed()) |
|
| 187 | 187 | return false; |
| 188 | 188 | |
| 189 | - return ! did_action( 'wpinv_after_cc_fields', 'wpinv_default_cc_address_fields' ); |
|
| 189 | + return !did_action('wpinv_after_cc_fields', 'wpinv_default_cc_address_fields'); |
|
| 190 | 190 | } |
| 191 | 191 | |
| 192 | -function wpinv_item_is_tax_exclusive( $item_id = 0 ) { |
|
| 193 | - $ret = (bool)get_post_meta( $item_id, '_wpinv_tax_exclusive', false ); |
|
| 194 | - return apply_filters( 'wpinv_is_tax_exclusive', $ret, $item_id ); |
|
| 192 | +function wpinv_item_is_tax_exclusive($item_id = 0) { |
|
| 193 | + $ret = (bool)get_post_meta($item_id, '_wpinv_tax_exclusive', false); |
|
| 194 | + return apply_filters('wpinv_is_tax_exclusive', $ret, $item_id); |
|
| 195 | 195 | } |
| 196 | 196 | |
| 197 | -function wpinv_currency_decimal_filter( $decimals = 2 ) { |
|
| 197 | +function wpinv_currency_decimal_filter($decimals = 2) { |
|
| 198 | 198 | $currency = wpinv_get_currency(); |
| 199 | 199 | |
| 200 | - switch ( $currency ) { |
|
| 200 | + switch ($currency) { |
|
| 201 | 201 | case 'RIAL' : |
| 202 | 202 | case 'JPY' : |
| 203 | 203 | case 'TWD' : |
@@ -206,48 +206,48 @@ discard block |
||
| 206 | 206 | break; |
| 207 | 207 | } |
| 208 | 208 | |
| 209 | - return apply_filters( 'wpinv_currency_decimal_count', $decimals, $currency ); |
|
| 209 | + return apply_filters('wpinv_currency_decimal_count', $decimals, $currency); |
|
| 210 | 210 | } |
| 211 | 211 | |
| 212 | 212 | function wpinv_tax_amount() { |
| 213 | 213 | $output = 0.00; |
| 214 | 214 | |
| 215 | - return apply_filters( 'wpinv_tax_amount', $output ); |
|
| 215 | + return apply_filters('wpinv_tax_amount', $output); |
|
| 216 | 216 | } |
| 217 | 217 | |
| 218 | 218 | function wpinv_recalculated_tax() { |
| 219 | - define( 'WPINV_RECALCTAX', true ); |
|
| 219 | + define('WPINV_RECALCTAX', true); |
|
| 220 | 220 | } |
| 221 | -add_action( 'wp_ajax_wpinv_recalculate_tax', 'wpinv_recalculated_tax', 1 ); |
|
| 221 | +add_action('wp_ajax_wpinv_recalculate_tax', 'wpinv_recalculated_tax', 1); |
|
| 222 | 222 | |
| 223 | -function wpinv_recalculate_tax( $return = false ) { |
|
| 223 | +function wpinv_recalculate_tax($return = false) { |
|
| 224 | 224 | $invoice_id = (int)wpinv_get_invoice_cart_id(); |
| 225 | - if ( empty( $invoice_id ) ) { |
|
| 225 | + if (empty($invoice_id)) { |
|
| 226 | 226 | return false; |
| 227 | 227 | } |
| 228 | 228 | |
| 229 | - $invoice = wpinv_get_invoice_cart( $invoice_id ); |
|
| 229 | + $invoice = wpinv_get_invoice_cart($invoice_id); |
|
| 230 | 230 | |
| 231 | - if ( empty( $invoice ) ) { |
|
| 231 | + if (empty($invoice)) { |
|
| 232 | 232 | return false; |
| 233 | 233 | } |
| 234 | 234 | |
| 235 | - if ( empty( $_POST['country'] ) ) { |
|
| 235 | + if (empty($_POST['country'])) { |
|
| 236 | 236 | $_POST['country'] = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country(); |
| 237 | 237 | } |
| 238 | 238 | |
| 239 | 239 | $invoice->country = sanitize_text_field($_POST['country']); |
| 240 | - $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) ); |
|
| 240 | + $invoice->set('country', sanitize_text_field($_POST['country'])); |
|
| 241 | 241 | if (isset($_POST['state'])) { |
| 242 | 242 | $invoice->state = sanitize_text_field($_POST['state']); |
| 243 | - $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) ); |
|
| 243 | + $invoice->set('state', sanitize_text_field($_POST['state'])); |
|
| 244 | 244 | } |
| 245 | 245 | |
| 246 | 246 | $invoice->cart_details = wpinv_get_cart_content_details(); |
| 247 | 247 | |
| 248 | - $subtotal = wpinv_get_cart_subtotal( $invoice->cart_details ); |
|
| 249 | - $tax = wpinv_get_cart_tax( $invoice->cart_details ); |
|
| 250 | - $total = wpinv_get_cart_total( $invoice->cart_details ); |
|
| 248 | + $subtotal = wpinv_get_cart_subtotal($invoice->cart_details); |
|
| 249 | + $tax = wpinv_get_cart_tax($invoice->cart_details); |
|
| 250 | + $total = wpinv_get_cart_total($invoice->cart_details); |
|
| 251 | 251 | |
| 252 | 252 | $invoice->tax = $tax; |
| 253 | 253 | $invoice->subtotal = $subtotal; |
@@ -255,61 +255,61 @@ discard block |
||
| 255 | 255 | |
| 256 | 256 | $invoice->save(); |
| 257 | 257 | |
| 258 | - if ( $invoice->is_free_trial() ) { |
|
| 258 | + if ($invoice->is_free_trial()) { |
|
| 259 | 259 | $total = 0; |
| 260 | 260 | } |
| 261 | 261 | |
| 262 | 262 | $response = array( |
| 263 | - 'total' => html_entity_decode( wpinv_price( wpinv_format_amount( $total ) ), ENT_COMPAT, 'UTF-8' ), |
|
| 263 | + 'total' => html_entity_decode(wpinv_price(wpinv_format_amount($total)), ENT_COMPAT, 'UTF-8'), |
|
| 264 | 264 | 'total_raw' => $total, |
| 265 | - 'free' => !( (float)$total > 0 ) && $invoice->is_free() ? true : false, |
|
| 266 | - 'html' => wpinv_checkout_cart( $invoice->cart_details, false ), |
|
| 265 | + 'free' => !((float)$total > 0) && $invoice->is_free() ? true : false, |
|
| 266 | + 'html' => wpinv_checkout_cart($invoice->cart_details, false), |
|
| 267 | 267 | ); |
| 268 | 268 | |
| 269 | - if ( $return ) { |
|
| 269 | + if ($return) { |
|
| 270 | 270 | return $response; |
| 271 | 271 | } |
| 272 | 272 | |
| 273 | - wp_send_json( $response ); |
|
| 273 | + wp_send_json($response); |
|
| 274 | 274 | } |
| 275 | -add_action( 'wp_ajax_wpinv_recalculate_tax', 'wpinv_recalculate_tax' ); |
|
| 276 | -add_action( 'wp_ajax_nopriv_wpinv_recalculate_tax', 'wpinv_recalculate_tax' ); |
|
| 275 | +add_action('wp_ajax_wpinv_recalculate_tax', 'wpinv_recalculate_tax'); |
|
| 276 | +add_action('wp_ajax_nopriv_wpinv_recalculate_tax', 'wpinv_recalculate_tax'); |
|
| 277 | 277 | |
| 278 | 278 | // VAT Settings |
| 279 | -function wpinv_vat_rate_add_callback( $args ) { |
|
| 279 | +function wpinv_vat_rate_add_callback($args) { |
|
| 280 | 280 | ?> |
| 281 | - <p class="wpi-vat-rate-actions"><input id="wpi_vat_rate_add" type="button" value="<?php esc_attr_e( 'Add', 'invoicing' );?>" class="button button-primary" /> <i style="display:none;" class="fa fa-refresh fa-spin"></i></p> |
|
| 281 | + <p class="wpi-vat-rate-actions"><input id="wpi_vat_rate_add" type="button" value="<?php esc_attr_e('Add', 'invoicing'); ?>" class="button button-primary" /> <i style="display:none;" class="fa fa-refresh fa-spin"></i></p> |
|
| 282 | 282 | <?php |
| 283 | 283 | } |
| 284 | 284 | |
| 285 | -function wpinv_vat_rate_delete_callback( $args ) { |
|
| 285 | +function wpinv_vat_rate_delete_callback($args) { |
|
| 286 | 286 | global $wpinv_euvat; |
| 287 | 287 | |
| 288 | 288 | $vat_classes = $wpinv_euvat->get_rate_classes(); |
| 289 | - $vat_class = isset( $_REQUEST['wpi_sub'] ) && $_REQUEST['wpi_sub'] !== '' && isset( $vat_classes[$_REQUEST['wpi_sub']] )? sanitize_text_field( $_REQUEST['wpi_sub'] ) : ''; |
|
| 290 | - if ( isset( $vat_classes[$vat_class] ) ) { |
|
| 289 | + $vat_class = isset($_REQUEST['wpi_sub']) && $_REQUEST['wpi_sub'] !== '' && isset($vat_classes[$_REQUEST['wpi_sub']]) ? sanitize_text_field($_REQUEST['wpi_sub']) : ''; |
|
| 290 | + if (isset($vat_classes[$vat_class])) { |
|
| 291 | 291 | ?> |
| 292 | - <p class="wpi-vat-rate-actions"><input id="wpi_vat_rate_delete" type="button" value="<?php echo wp_sprintf( esc_attr__( 'Delete class "%s"', 'invoicing' ), $vat_classes[$vat_class] );?>" class="button button-primary" /> <i style="display:none;" class="fa fa-refresh fa-spin"></i></p> |
|
| 292 | + <p class="wpi-vat-rate-actions"><input id="wpi_vat_rate_delete" type="button" value="<?php echo wp_sprintf(esc_attr__('Delete class "%s"', 'invoicing'), $vat_classes[$vat_class]); ?>" class="button button-primary" /> <i style="display:none;" class="fa fa-refresh fa-spin"></i></p> |
|
| 293 | 293 | <?php |
| 294 | 294 | } |
| 295 | 295 | } |
| 296 | 296 | |
| 297 | -function wpinv_vat_rates_callback( $args ) { |
|
| 297 | +function wpinv_vat_rates_callback($args) { |
|
| 298 | 298 | global $wpinv_euvat; |
| 299 | 299 | |
| 300 | 300 | $vat_classes = $wpinv_euvat->get_rate_classes(); |
| 301 | - $vat_class = isset( $_REQUEST['wpi_sub'] ) && $_REQUEST['wpi_sub'] !== '' && isset( $vat_classes[$_REQUEST['wpi_sub']] )? sanitize_text_field( $_REQUEST['wpi_sub'] ) : '_standard'; |
|
| 301 | + $vat_class = isset($_REQUEST['wpi_sub']) && $_REQUEST['wpi_sub'] !== '' && isset($vat_classes[$_REQUEST['wpi_sub']]) ? sanitize_text_field($_REQUEST['wpi_sub']) : '_standard'; |
|
| 302 | 302 | |
| 303 | 303 | $eu_states = $wpinv_euvat->get_eu_states(); |
| 304 | 304 | $countries = wpinv_get_country_list(); |
| 305 | 305 | $vat_groups = $wpinv_euvat->get_vat_groups(); |
| 306 | - $rates = $wpinv_euvat->get_vat_rates( $vat_class ); |
|
| 306 | + $rates = $wpinv_euvat->get_vat_rates($vat_class); |
|
| 307 | 307 | ob_start(); |
| 308 | 308 | ?> |
| 309 | 309 | </td><tr> |
| 310 | 310 | <td colspan="2" class="wpinv_vat_tdbox"> |
| 311 | - <input type="hidden" name="wpi_vat_class" value="<?php echo $vat_class;?>" /> |
|
| 312 | - <p><?php echo ( isset( $args['desc'] ) ? $args['desc'] : '' ); ?></p> |
|
| 311 | + <input type="hidden" name="wpi_vat_class" value="<?php echo $vat_class; ?>" /> |
|
| 312 | + <p><?php echo (isset($args['desc']) ? $args['desc'] : ''); ?></p> |
|
| 313 | 313 | <table id="wpinv_vat_rates" class="wp-list-table widefat fixed posts"> |
| 314 | 314 | <colgroup> |
| 315 | 315 | <col width="50px" /> |
@@ -321,43 +321,43 @@ discard block |
||
| 321 | 321 | </colgroup> |
| 322 | 322 | <thead> |
| 323 | 323 | <tr> |
| 324 | - <th scope="col" colspan="2" class="wpinv_vat_country_name"><?php _e( 'Country', 'invoicing' ); ?></th> |
|
| 325 | - <th scope="col" class="wpinv_vat_global" title="<?php esc_attr_e( 'Apply rate to whole country', 'invoicing' ); ?>"><?php _e( 'Country Wide', 'invoicing' ); ?></th> |
|
| 326 | - <th scope="col" class="wpinv_vat_rate"><?php _e( 'Rate %', 'invoicing' ); ?></th> |
|
| 327 | - <th scope="col" class="wpinv_vat_name"><?php _e( 'VAT Name', 'invoicing' ); ?></th> |
|
| 328 | - <th scope="col" class="wpinv_vat_group"><?php _e( 'Tax Group', 'invoicing' ); ?></th> |
|
| 324 | + <th scope="col" colspan="2" class="wpinv_vat_country_name"><?php _e('Country', 'invoicing'); ?></th> |
|
| 325 | + <th scope="col" class="wpinv_vat_global" title="<?php esc_attr_e('Apply rate to whole country', 'invoicing'); ?>"><?php _e('Country Wide', 'invoicing'); ?></th> |
|
| 326 | + <th scope="col" class="wpinv_vat_rate"><?php _e('Rate %', 'invoicing'); ?></th> |
|
| 327 | + <th scope="col" class="wpinv_vat_name"><?php _e('VAT Name', 'invoicing'); ?></th> |
|
| 328 | + <th scope="col" class="wpinv_vat_group"><?php _e('Tax Group', 'invoicing'); ?></th> |
|
| 329 | 329 | </tr> |
| 330 | 330 | </thead> |
| 331 | 331 | <tbody> |
| 332 | - <?php if( !empty( $eu_states ) ) { ?> |
|
| 332 | + <?php if (!empty($eu_states)) { ?> |
|
| 333 | 333 | <?php |
| 334 | - foreach ( $eu_states as $state ) { |
|
| 335 | - $country_name = isset( $countries[$state] ) ? $countries[$state] : ''; |
|
| 334 | + foreach ($eu_states as $state) { |
|
| 335 | + $country_name = isset($countries[$state]) ? $countries[$state] : ''; |
|
| 336 | 336 | |
| 337 | 337 | // Filter the rate for each country |
| 338 | - $country_rate = array_filter( $rates, function( $rate ) use( $state ) { return $rate['country'] === $state; } ); |
|
| 338 | + $country_rate = array_filter($rates, function($rate) use($state) { return $rate['country'] === $state; } ); |
|
| 339 | 339 | |
| 340 | 340 | // If one does not exist create a default |
| 341 | - $country_rate = is_array( $country_rate ) && count( $country_rate ) > 0 ? reset( $country_rate ) : array(); |
|
| 341 | + $country_rate = is_array($country_rate) && count($country_rate) > 0 ? reset($country_rate) : array(); |
|
| 342 | 342 | |
| 343 | - $vat_global = isset( $country_rate['global'] ) ? !empty( $country_rate['global'] ) : true; |
|
| 344 | - $vat_rate = isset( $country_rate['rate'] ) ? $country_rate['rate'] : ''; |
|
| 345 | - $vat_name = !empty( $country_rate['name'] ) ? esc_attr( stripslashes( $country_rate['name'] ) ) : ''; |
|
| 346 | - $vat_group = !empty( $country_rate['group'] ) ? $country_rate['group'] : ( $vat_class === '_standard' ? 'standard' : 'reduced' ); |
|
| 343 | + $vat_global = isset($country_rate['global']) ? !empty($country_rate['global']) : true; |
|
| 344 | + $vat_rate = isset($country_rate['rate']) ? $country_rate['rate'] : ''; |
|
| 345 | + $vat_name = !empty($country_rate['name']) ? esc_attr(stripslashes($country_rate['name'])) : ''; |
|
| 346 | + $vat_group = !empty($country_rate['group']) ? $country_rate['group'] : ($vat_class === '_standard' ? 'standard' : 'reduced'); |
|
| 347 | 347 | ?> |
| 348 | 348 | <tr> |
| 349 | 349 | <td class="wpinv_vat_country"><?php echo $state; ?><input type="hidden" name="vat_rates[<?php echo $state; ?>][country]" value="<?php echo $state; ?>" /><input type="hidden" name="vat_rates[<?php echo $state; ?>][state]" value="" /></td> |
| 350 | 350 | <td class="wpinv_vat_country_name"><?php echo $country_name; ?></td> |
| 351 | 351 | <td class="wpinv_vat_global"> |
| 352 | - <input type="checkbox" name="vat_rates[<?php echo $state;?>][global]" id="vat_rates[<?php echo $state;?>][global]" value="1" <?php checked( true, $vat_global );?> disabled="disabled" /> |
|
| 353 | - <label for="tax_rates[<?php echo $state;?>][global]"><?php _e( 'Apply to whole country', 'invoicing' ); ?></label> |
|
| 354 | - <input type="hidden" name="vat_rates[<?php echo $state;?>][global]" value="1" checked="checked" /> |
|
| 352 | + <input type="checkbox" name="vat_rates[<?php echo $state; ?>][global]" id="vat_rates[<?php echo $state; ?>][global]" value="1" <?php checked(true, $vat_global); ?> disabled="disabled" /> |
|
| 353 | + <label for="tax_rates[<?php echo $state; ?>][global]"><?php _e('Apply to whole country', 'invoicing'); ?></label> |
|
| 354 | + <input type="hidden" name="vat_rates[<?php echo $state; ?>][global]" value="1" checked="checked" /> |
|
| 355 | 355 | </td> |
| 356 | - <td class="wpinv_vat_rate"><input type="number" class="small-text" step="any" min="0" max="99" name="vat_rates[<?php echo $state;?>][rate]" value="<?php echo $vat_rate; ?>" /></td> |
|
| 357 | - <td class="wpinv_vat_name"><input type="text" class="regular-text" name="vat_rates[<?php echo $state;?>][name]" value="<?php echo $vat_name; ?>" /></td> |
|
| 356 | + <td class="wpinv_vat_rate"><input type="number" class="small-text" step="any" min="0" max="99" name="vat_rates[<?php echo $state; ?>][rate]" value="<?php echo $vat_rate; ?>" /></td> |
|
| 357 | + <td class="wpinv_vat_name"><input type="text" class="regular-text" name="vat_rates[<?php echo $state; ?>][name]" value="<?php echo $vat_name; ?>" /></td> |
|
| 358 | 358 | <td class="wpinv_vat_group"> |
| 359 | 359 | <?php |
| 360 | - echo wpinv_html_select( array( |
|
| 360 | + echo wpinv_html_select(array( |
|
| 361 | 361 | 'name' => 'vat_rates[' . $state . '][group]', |
| 362 | 362 | 'selected' => $vat_group, |
| 363 | 363 | 'id' => 'vat_rates[' . $state . '][group]', |
@@ -367,14 +367,14 @@ discard block |
||
| 367 | 367 | 'chosen' => false, |
| 368 | 368 | 'show_option_all' => false, |
| 369 | 369 | 'show_option_none' => false |
| 370 | - ) ); |
|
| 370 | + )); |
|
| 371 | 371 | ?> |
| 372 | 372 | </td> |
| 373 | 373 | </tr> |
| 374 | 374 | <?php } ?> |
| 375 | 375 | <tr> |
| 376 | 376 | <td colspan="6" style="background-color:#fafafa;"> |
| 377 | - <span><input id="wpi_vat_get_rates_group" type="button" class="button-secondary" value="<?php esc_attr_e( 'Update EU VAT Rates', 'invoicing' ); ?>" /> <i style="display:none" class="fa fa-refresh fa-spin"></i></span><span id="wpinv-rates-error-wrap" class="wpinv_errors" style="display:none;"></span> |
|
| 377 | + <span><input id="wpi_vat_get_rates_group" type="button" class="button-secondary" value="<?php esc_attr_e('Update EU VAT Rates', 'invoicing'); ?>" /> <i style="display:none" class="fa fa-refresh fa-spin"></i></span><span id="wpinv-rates-error-wrap" class="wpinv_errors" style="display:none;"></span> |
|
| 378 | 378 | </td> |
| 379 | 379 | </tr> |
| 380 | 380 | <?php } ?> |
@@ -386,35 +386,35 @@ discard block |
||
| 386 | 386 | echo $content; |
| 387 | 387 | } |
| 388 | 388 | |
| 389 | -function wpinv_vat_number_callback( $args ) { |
|
| 389 | +function wpinv_vat_number_callback($args) { |
|
| 390 | 390 | global $wpinv_euvat; |
| 391 | 391 | |
| 392 | 392 | $vat_number = $wpinv_euvat->get_vat_number(); |
| 393 | 393 | $vat_valid = $wpinv_euvat->is_vat_validated(); |
| 394 | 394 | |
| 395 | - $size = ( isset( $args['size'] ) && !is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
| 396 | - $validated_text = $vat_valid ? __( 'VAT number validated', 'invoicing' ) : __( 'VAT number not validated', 'invoicing' ); |
|
| 395 | + $size = (isset($args['size']) && !is_null($args['size'])) ? $args['size'] : 'regular'; |
|
| 396 | + $validated_text = $vat_valid ? __('VAT number validated', 'invoicing') : __('VAT number not validated', 'invoicing'); |
|
| 397 | 397 | $disabled = $vat_valid ? 'disabled="disabled"' : " "; |
| 398 | 398 | |
| 399 | - $html = '<input type="text" class="' . $size . '-text" id="wpinv_settings[' . $args['id'] . ']" name="wpinv_settings[' . $args['id'] . ']" placeholder="GB123456789" value="' . esc_attr( stripslashes( $vat_number ) ) . '"/>'; |
|
| 400 | - $html .= '<span> <input type="button" id="wpinv_vat_validate" class="wpinv_validate_vat_button button-secondary" ' . $disabled . ' value="' . esc_attr__( 'Validate VAT Number', 'invoicing' ) . '" /></span>'; |
|
| 399 | + $html = '<input type="text" class="' . $size . '-text" id="wpinv_settings[' . $args['id'] . ']" name="wpinv_settings[' . $args['id'] . ']" placeholder="GB123456789" value="' . esc_attr(stripslashes($vat_number)) . '"/>'; |
|
| 400 | + $html .= '<span> <input type="button" id="wpinv_vat_validate" class="wpinv_validate_vat_button button-secondary" ' . $disabled . ' value="' . esc_attr__('Validate VAT Number', 'invoicing') . '" /></span>'; |
|
| 401 | 401 | $html .= '<span class="wpinv-vat-stat wpinv-vat-stat-' . (int)$vat_valid . '"><i class="fa"></i> <font>' . $validated_text . '</font></span>'; |
| 402 | - $html .= '<label for="wpinv_settings[' . $args['id'] . ']">' . '<p>' . __( 'Enter your VAT number including country identifier, eg: GB123456789 (Settings must be saved after validation)', 'invoicing' ).'</p>' . '</label>'; |
|
| 403 | - $html .= '<input type="hidden" name="_wpi_nonce" value="' . wp_create_nonce( 'vat_validation' ) . '">'; |
|
| 402 | + $html .= '<label for="wpinv_settings[' . $args['id'] . ']">' . '<p>' . __('Enter your VAT number including country identifier, eg: GB123456789 (Settings must be saved after validation)', 'invoicing') . '</p>' . '</label>'; |
|
| 403 | + $html .= '<input type="hidden" name="_wpi_nonce" value="' . wp_create_nonce('vat_validation') . '">'; |
|
| 404 | 404 | |
| 405 | 405 | echo $html; |
| 406 | 406 | } |
| 407 | 407 | |
| 408 | -function wpinv_eu_fallback_rate_callback( $args ) { |
|
| 408 | +function wpinv_eu_fallback_rate_callback($args) { |
|
| 409 | 409 | global $wpinv_options; |
| 410 | 410 | |
| 411 | - $value = isset( $wpinv_options[$args['id']] ) ? $wpinv_options[ $args['id'] ] : ( isset( $args['std'] ) ? $args['std'] : '' ); |
|
| 412 | - $size = ( isset( $args['size'] ) && !is_null( $args['size'] ) ) ? $args['size'] : 'small'; |
|
| 411 | + $value = isset($wpinv_options[$args['id']]) ? $wpinv_options[$args['id']] : (isset($args['std']) ? $args['std'] : ''); |
|
| 412 | + $size = (isset($args['size']) && !is_null($args['size'])) ? $args['size'] : 'small'; |
|
| 413 | 413 | |
| 414 | - $html = '<input type="number" min="0" max="99" step="any" class="' . $size . '-text" id="wpinv_settings_' . $args['section'] . '_' . $args['id'] . '" name="wpinv_settings[' . $args['id'] . ']" value="' . esc_attr( stripslashes( $value ) ) . '" />'; |
|
| 415 | - $html .= '<span> <input id="wpi_add_eu_states" type="button" class="button-secondary" value="' . esc_attr__( 'Add EU Member States', 'invoicing' ) . '" /></span>'; |
|
| 416 | - $html .= '<span> <input id="wpi_remove_eu_states" type="button" class="button-secondary" value="' . esc_attr__( 'Remove EU Member States', 'invoicing' ) . '" /></span>'; |
|
| 417 | - $html .= '<span> <input id="wpi_vat_get_rates" type="button" class="button-secondary" value="' . esc_attr__( 'Update EU VAT Rates', 'invoicing' ) . '" /> <i style="display:none" class="fa fa-refresh fa-spin"></i></span>'; |
|
| 414 | + $html = '<input type="number" min="0" max="99" step="any" class="' . $size . '-text" id="wpinv_settings_' . $args['section'] . '_' . $args['id'] . '" name="wpinv_settings[' . $args['id'] . ']" value="' . esc_attr(stripslashes($value)) . '" />'; |
|
| 415 | + $html .= '<span> <input id="wpi_add_eu_states" type="button" class="button-secondary" value="' . esc_attr__('Add EU Member States', 'invoicing') . '" /></span>'; |
|
| 416 | + $html .= '<span> <input id="wpi_remove_eu_states" type="button" class="button-secondary" value="' . esc_attr__('Remove EU Member States', 'invoicing') . '" /></span>'; |
|
| 417 | + $html .= '<span> <input id="wpi_vat_get_rates" type="button" class="button-secondary" value="' . esc_attr__('Update EU VAT Rates', 'invoicing') . '" /> <i style="display:none" class="fa fa-refresh fa-spin"></i></span>'; |
|
| 418 | 418 | $html .= '<p><label for="wpinv_settings_' . $args['section'] . '_' . $args['id'] . '">' . $args['desc'] . '</label></p>'; |
| 419 | 419 | echo $html; |
| 420 | 420 | ?> |
@@ -422,36 +422,36 @@ discard block |
||
| 422 | 422 | <?php |
| 423 | 423 | } |
| 424 | 424 | |
| 425 | -function wpinv_vat_ip_lookup_callback( $args ) { |
|
| 425 | +function wpinv_vat_ip_lookup_callback($args) { |
|
| 426 | 426 | global $wpinv_options, $wpinv_euvat; |
| 427 | 427 | |
| 428 | - $value = isset( $wpinv_options[ $args['id'] ] ) ? $wpinv_options[ $args['id'] ] : ( isset( $args['std'] ) ? $args['std'] : 'default' ); |
|
| 428 | + $value = isset($wpinv_options[$args['id']]) ? $wpinv_options[$args['id']] : (isset($args['std']) ? $args['std'] : 'default'); |
|
| 429 | 429 | |
| 430 | 430 | $options = array(); |
| 431 | - if ( function_exists( 'geoip_country_code_by_name' ) ) { |
|
| 432 | - $options['geoip'] = __( 'PHP GeoIP extension', 'invoicing' ); |
|
| 431 | + if (function_exists('geoip_country_code_by_name')) { |
|
| 432 | + $options['geoip'] = __('PHP GeoIP extension', 'invoicing'); |
|
| 433 | 433 | } |
| 434 | 434 | |
| 435 | 435 | $geoip2_database = $wpinv_euvat->geoip2_country_dbfile(); |
| 436 | 436 | |
| 437 | - if ( !function_exists( 'bcadd' ) ) { |
|
| 438 | - $geoip2_message = __( 'GeoIP2 service requires the BC Math PHP extension, it is not loaded in your version of PHP!', 'invoicing' ); |
|
| 437 | + if (!function_exists('bcadd')) { |
|
| 438 | + $geoip2_message = __('GeoIP2 service requires the BC Math PHP extension, it is not loaded in your version of PHP!', 'invoicing'); |
|
| 439 | 439 | } else { |
| 440 | - $geoip2_message = ini_get('safe_mode') ? __( 'GeoIP2 is not supported with PHP safe mode enabled!', 'invoicing' ) : ''; |
|
| 440 | + $geoip2_message = ini_get('safe_mode') ? __('GeoIP2 is not supported with PHP safe mode enabled!', 'invoicing') : ''; |
|
| 441 | 441 | } |
| 442 | 442 | |
| 443 | - if ( $geoip2_database !== false && empty( $geoip2_message ) ) { |
|
| 444 | - $options['geoip2'] = __( 'GeoIP2 Database', 'invoicing' ); |
|
| 443 | + if ($geoip2_database !== false && empty($geoip2_message)) { |
|
| 444 | + $options['geoip2'] = __('GeoIP2 Database', 'invoicing'); |
|
| 445 | 445 | } |
| 446 | 446 | |
| 447 | - if ( function_exists( 'simplexml_load_file' ) ) { |
|
| 448 | - $options['geoplugin'] = __( 'geoPlugin Web Service', 'invoicing' ); |
|
| 447 | + if (function_exists('simplexml_load_file')) { |
|
| 448 | + $options['geoplugin'] = __('geoPlugin Web Service', 'invoicing'); |
|
| 449 | 449 | } |
| 450 | 450 | |
| 451 | - $options['site'] = __( 'Use default country', 'invoicing' ); |
|
| 452 | - $options['default'] = __( 'Auto', 'invoicing' ); |
|
| 451 | + $options['site'] = __('Use default country', 'invoicing'); |
|
| 452 | + $options['default'] = __('Auto', 'invoicing'); |
|
| 453 | 453 | |
| 454 | - $html = wpinv_html_select( array( |
|
| 454 | + $html = wpinv_html_select(array( |
|
| 455 | 455 | 'name' => "wpinv_settings[{$args['id']}]", |
| 456 | 456 | 'selected' => $value, |
| 457 | 457 | 'id' => "wpinv_settings[{$args['id']}]", |
@@ -464,23 +464,23 @@ discard block |
||
| 464 | 464 | )); |
| 465 | 465 | |
| 466 | 466 | $desc = '<label for="wpinv_settings[' . $args['id'] . ']">'; |
| 467 | - $desc .= __( 'Select the option Invoicing should use to determine the country from the IP address of the user.', 'invoicing' ); |
|
| 467 | + $desc .= __('Select the option Invoicing should use to determine the country from the IP address of the user.', 'invoicing'); |
|
| 468 | 468 | $desc .= '<p>'; |
| 469 | - if ( empty( $geoip2_message ) ) { |
|
| 470 | - if ( $geoip2_database ) { |
|
| 469 | + if (empty($geoip2_message)) { |
|
| 470 | + if ($geoip2_database) { |
|
| 471 | 471 | $last_updated = ''; |
| 472 | - if ( $time_updated = wpinv_get_option( 'wpinv_geoip2_date_updated' ) ) { |
|
| 473 | - $date_updated = date_i18n( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), $time_updated ); |
|
| 474 | - $last_updated = '<br>' . sprintf( __( 'The GeoIP2 database was last updated on: <b>%s</b>', 'invoicing' ), $date_updated ); |
|
| 472 | + if ($time_updated = wpinv_get_option('wpinv_geoip2_date_updated')) { |
|
| 473 | + $date_updated = date_i18n(get_option('date_format') . ' ' . get_option('time_format'), $time_updated); |
|
| 474 | + $last_updated = '<br>' . sprintf(__('The GeoIP2 database was last updated on: <b>%s</b>', 'invoicing'), $date_updated); |
|
| 475 | 475 | } |
| 476 | - $desc .= __( 'GeoIP2 database exists:', 'invoicing' ) . $last_updated . ' <input type="button" id="wpi_geoip2" action="update" class="wpinv-refresh-geoip2-btn button-secondary" value="' . __( 'Update GeoIP2 database now (~55MB)', 'invoicing' ) . '"></input>'; |
|
| 476 | + $desc .= __('GeoIP2 database exists:', 'invoicing') . $last_updated . ' <input type="button" id="wpi_geoip2" action="update" class="wpinv-refresh-geoip2-btn button-secondary" value="' . __('Update GeoIP2 database now (~55MB)', 'invoicing') . '"></input>'; |
|
| 477 | 477 | } else { |
| 478 | - $desc .= __( 'GeoIP2 database does not exist:', 'invoicing' ) . ' <input type="button" id="wpi_geoip2" action="download" class="wpinv-download-geoip2-btn button-secondary" value="' . __( 'Download GeoIP2 database now', 'invoicing' ) . ' (~53MB)"></input><br>' . __( 'After downloading the GeoIP2 database the GeoIP2 lookup option will show.', 'invoicing' ); |
|
| 478 | + $desc .= __('GeoIP2 database does not exist:', 'invoicing') . ' <input type="button" id="wpi_geoip2" action="download" class="wpinv-download-geoip2-btn button-secondary" value="' . __('Download GeoIP2 database now', 'invoicing') . ' (~53MB)"></input><br>' . __('After downloading the GeoIP2 database the GeoIP2 lookup option will show.', 'invoicing'); |
|
| 479 | 479 | } |
| 480 | 480 | } else { |
| 481 | 481 | $desc .= $geoip2_message; |
| 482 | 482 | } |
| 483 | - $desc .= '</p><p>'. __( 'GeoPlugin is a great free service please consider supporting them: ', 'invoicing' ) . ' <a href="http://www.geoplugin.com/" target="_blank">GeoPlugin.com</a></p>'; |
|
| 483 | + $desc .= '</p><p>' . __('GeoPlugin is a great free service please consider supporting them: ', 'invoicing') . ' <a href="http://www.geoplugin.com/" target="_blank">GeoPlugin.com</a></p>'; |
|
| 484 | 484 | $desc .= '</label>'; |
| 485 | 485 | |
| 486 | 486 | $html .= $desc; |
@@ -136,6 +136,9 @@ discard block |
||
| 136 | 136 | do_action( 'wpinv_after_template_part', $template_name, $template_path, $located, $args ); |
| 137 | 137 | } |
| 138 | 138 | |
| 139 | +/** |
|
| 140 | + * @param string $template_name |
|
| 141 | + */ |
|
| 139 | 142 | function wpinv_get_template_html( $template_name, $args = array(), $template_path = '', $default_path = '' ) { |
| 140 | 143 | ob_start(); |
| 141 | 144 | wpinv_get_template( $template_name, $args, $template_path, $default_path ); |
@@ -168,6 +171,10 @@ discard block |
||
| 168 | 171 | return apply_filters( 'wpinv_locate_template', $template, $template_name, $template_path ); |
| 169 | 172 | } |
| 170 | 173 | |
| 174 | +/** |
|
| 175 | + * @param string $slug |
|
| 176 | + * @param boolean $name |
|
| 177 | + */ |
|
| 171 | 178 | function wpinv_get_template_part( $slug, $name = null, $load = true ) { |
| 172 | 179 | do_action( 'get_template_part_' . $slug, $slug, $name ); |
| 173 | 180 | |
@@ -867,6 +874,9 @@ discard block |
||
| 867 | 874 | return apply_filters( 'wpinv_get_watermark', $output, $id ); |
| 868 | 875 | } |
| 869 | 876 | |
| 877 | +/** |
|
| 878 | + * @param integer $id |
|
| 879 | + */ |
|
| 870 | 880 | function wpinv_get_watermark( $id ) { |
| 871 | 881 | if ( !$id > 0 ) { |
| 872 | 882 | return NULL; |
@@ -70,7 +70,10 @@ discard block |
||
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | function wpinv_invoice_display_right_actions( $invoice ) { |
| 73 | - if ( empty( $invoice ) ) return; //Exit if invoice is not set. |
|
| 73 | + if ( empty( $invoice ) ) { |
|
| 74 | + return; |
|
| 75 | + } |
|
| 76 | + //Exit if invoice is not set. |
|
| 74 | 77 | |
| 75 | 78 | if($invoice->post_type == 'wpi_invoice'){ |
| 76 | 79 | $user_id = (int)$invoice->get_user_id(); |
@@ -177,8 +180,9 @@ discard block |
||
| 177 | 180 | |
| 178 | 181 | // Setup possible parts |
| 179 | 182 | $templates = array(); |
| 180 | - if ( isset( $name ) ) |
|
| 181 | - $templates[] = $slug . '-' . $name . '.php'; |
|
| 183 | + if ( isset( $name ) ) { |
|
| 184 | + $templates[] = $slug . '-' . $name . '.php'; |
|
| 185 | + } |
|
| 182 | 186 | $templates[] = $slug . '.php'; |
| 183 | 187 | |
| 184 | 188 | // Allow template parts to be filtered |
@@ -196,8 +200,9 @@ discard block |
||
| 196 | 200 | foreach ( (array)$template_names as $template_name ) { |
| 197 | 201 | |
| 198 | 202 | // Continue if template is empty |
| 199 | - if ( empty( $template_name ) ) |
|
| 200 | - continue; |
|
| 203 | + if ( empty( $template_name ) ) { |
|
| 204 | + continue; |
|
| 205 | + } |
|
| 201 | 206 | |
| 202 | 207 | // Trim off any slashes from the template name |
| 203 | 208 | $template_name = ltrim( $template_name, '/' ); |
@@ -216,8 +221,9 @@ discard block |
||
| 216 | 221 | } |
| 217 | 222 | } |
| 218 | 223 | |
| 219 | - if ( ( true == $load ) && ! empty( $located ) ) |
|
| 220 | - load_template( $located, $require_once ); |
|
| 224 | + if ( ( true == $load ) && ! empty( $located ) ) { |
|
| 225 | + load_template( $located, $require_once ); |
|
| 226 | + } |
|
| 221 | 227 | |
| 222 | 228 | return $located; |
| 223 | 229 | } |
@@ -293,8 +299,9 @@ discard block |
||
| 293 | 299 | function wpinv_html_dropdown( $name = 'wpinv_discounts', $selected = 0, $status = '' ) { |
| 294 | 300 | $args = array( 'nopaging' => true ); |
| 295 | 301 | |
| 296 | - if ( ! empty( $status ) ) |
|
| 297 | - $args['post_status'] = $status; |
|
| 302 | + if ( ! empty( $status ) ) { |
|
| 303 | + $args['post_status'] = $status; |
|
| 304 | + } |
|
| 298 | 305 | |
| 299 | 306 | $discounts = wpinv_get_discounts( $args ); |
| 300 | 307 | $options = array(); |
@@ -898,8 +905,11 @@ discard block |
||
| 898 | 905 | |
| 899 | 906 | $invoice_status = wpinv_get_invoice_status( $invoice_id ); |
| 900 | 907 | |
| 901 | - if($invoice->post_type == 'wpi_invoice') $type = 'Invoice'; |
|
| 902 | - elseif($invoice->post_type == 'wpi_quote') $type = 'Quote'; |
|
| 908 | + if($invoice->post_type == 'wpi_invoice') { |
|
| 909 | + $type = 'Invoice'; |
|
| 910 | + } elseif($invoice->post_type == 'wpi_quote') { |
|
| 911 | + $type = 'Quote'; |
|
| 912 | + } |
|
| 903 | 913 | ?> |
| 904 | 914 | <table class="table table-bordered table-sm"> |
| 905 | 915 | <?php if ( $invoice_number = wpinv_get_invoice_number( $invoice_id ) ) { ?> |
@@ -1466,17 +1476,19 @@ discard block |
||
| 1466 | 1476 | add_action( 'wpinv_cart_empty', 'wpinv_empty_checkout_cart' ); |
| 1467 | 1477 | |
| 1468 | 1478 | function wpinv_save_cart_button() { |
| 1469 | - if ( wpinv_is_cart_saving_disabled() ) |
|
| 1470 | - return; |
|
| 1471 | -?> |
|
| 1479 | + if ( wpinv_is_cart_saving_disabled() ) { |
|
| 1480 | + return; |
|
| 1481 | + } |
|
| 1482 | + ?> |
|
| 1472 | 1483 | <a class="wpinv-cart-saving-button wpinv-submit button" id="wpinv-save-cart-button" href="<?php echo esc_url( add_query_arg( 'wpi_action', 'save_cart' ) ); ?>"><?php _e( 'Save Cart', 'invoicing' ); ?></a> |
| 1473 | 1484 | <?php |
| 1474 | 1485 | } |
| 1475 | 1486 | |
| 1476 | 1487 | function wpinv_update_cart_button() { |
| 1477 | - if ( !wpinv_item_quantities_enabled() ) |
|
| 1478 | - return; |
|
| 1479 | -?> |
|
| 1488 | + if ( !wpinv_item_quantities_enabled() ) { |
|
| 1489 | + return; |
|
| 1490 | + } |
|
| 1491 | + ?> |
|
| 1480 | 1492 | <input type="submit" name="wpinv_update_cart_submit" class="wpinv-submit wpinv-no-js button" value="<?php _e( 'Update Cart', 'invoicing' ); ?>"/> |
| 1481 | 1493 | <input type="hidden" name="wpi_action" value="update_cart"/> |
| 1482 | 1494 | <?php |
@@ -1615,7 +1627,7 @@ discard block |
||
| 1615 | 1627 | </div> |
| 1616 | 1628 | <?php |
| 1617 | 1629 | } |
| 1618 | - }else{ |
|
| 1630 | + } else{ |
|
| 1619 | 1631 | echo '<div class="alert alert-warning">'. __('No payment gateway active','invoicing') .'</div>'; |
| 1620 | 1632 | } |
| 1621 | 1633 | |
@@ -121,29 +121,29 @@ discard block |
||
| 121 | 121 | |
| 122 | 122 | function wpinv_get_template( $template_name, $args = array(), $template_path = '', $default_path = '' ) { |
| 123 | 123 | if ( ! empty( $args ) && is_array( $args ) ) { |
| 124 | - extract( $args ); |
|
| 125 | - } |
|
| 124 | + extract( $args ); |
|
| 125 | + } |
|
| 126 | 126 | |
| 127 | - $located = wpinv_locate_template( $template_name, $template_path, $default_path ); |
|
| 128 | - // Allow 3rd party plugin filter template file from their plugin. |
|
| 129 | - $located = apply_filters( 'wpinv_get_template', $located, $template_name, $args, $template_path, $default_path ); |
|
| 127 | + $located = wpinv_locate_template( $template_name, $template_path, $default_path ); |
|
| 128 | + // Allow 3rd party plugin filter template file from their plugin. |
|
| 129 | + $located = apply_filters( 'wpinv_get_template', $located, $template_name, $args, $template_path, $default_path ); |
|
| 130 | 130 | |
| 131 | - if ( ! file_exists( $located ) ) { |
|
| 131 | + if ( ! file_exists( $located ) ) { |
|
| 132 | 132 | _doing_it_wrong( __FUNCTION__, sprintf( '<code>%s</code> does not exist.', $located ), '2.1' ); |
| 133 | - return; |
|
| 134 | - } |
|
| 133 | + return; |
|
| 134 | + } |
|
| 135 | 135 | |
| 136 | - do_action( 'wpinv_before_template_part', $template_name, $template_path, $located, $args ); |
|
| 136 | + do_action( 'wpinv_before_template_part', $template_name, $template_path, $located, $args ); |
|
| 137 | 137 | |
| 138 | - include( $located ); |
|
| 138 | + include( $located ); |
|
| 139 | 139 | |
| 140 | - do_action( 'wpinv_after_template_part', $template_name, $template_path, $located, $args ); |
|
| 140 | + do_action( 'wpinv_after_template_part', $template_name, $template_path, $located, $args ); |
|
| 141 | 141 | } |
| 142 | 142 | |
| 143 | 143 | function wpinv_get_template_html( $template_name, $args = array(), $template_path = '', $default_path = '' ) { |
| 144 | - ob_start(); |
|
| 145 | - wpinv_get_template( $template_name, $args, $template_path, $default_path ); |
|
| 146 | - return ob_get_clean(); |
|
| 144 | + ob_start(); |
|
| 145 | + wpinv_get_template( $template_name, $args, $template_path, $default_path ); |
|
| 146 | + return ob_get_clean(); |
|
| 147 | 147 | } |
| 148 | 148 | |
| 149 | 149 | function wpinv_locate_template( $template_name, $template_path = '', $default_path = '' ) { |
@@ -173,120 +173,120 @@ discard block |
||
| 173 | 173 | } |
| 174 | 174 | |
| 175 | 175 | function wpinv_get_template_part( $slug, $name = null, $load = true ) { |
| 176 | - do_action( 'get_template_part_' . $slug, $slug, $name ); |
|
| 176 | + do_action( 'get_template_part_' . $slug, $slug, $name ); |
|
| 177 | 177 | |
| 178 | - // Setup possible parts |
|
| 179 | - $templates = array(); |
|
| 180 | - if ( isset( $name ) ) |
|
| 181 | - $templates[] = $slug . '-' . $name . '.php'; |
|
| 182 | - $templates[] = $slug . '.php'; |
|
| 178 | + // Setup possible parts |
|
| 179 | + $templates = array(); |
|
| 180 | + if ( isset( $name ) ) |
|
| 181 | + $templates[] = $slug . '-' . $name . '.php'; |
|
| 182 | + $templates[] = $slug . '.php'; |
|
| 183 | 183 | |
| 184 | - // Allow template parts to be filtered |
|
| 185 | - $templates = apply_filters( 'wpinv_get_template_part', $templates, $slug, $name ); |
|
| 184 | + // Allow template parts to be filtered |
|
| 185 | + $templates = apply_filters( 'wpinv_get_template_part', $templates, $slug, $name ); |
|
| 186 | 186 | |
| 187 | - // Return the part that is found |
|
| 188 | - return wpinv_locate_tmpl( $templates, $load, false ); |
|
| 187 | + // Return the part that is found |
|
| 188 | + return wpinv_locate_tmpl( $templates, $load, false ); |
|
| 189 | 189 | } |
| 190 | 190 | |
| 191 | 191 | function wpinv_locate_tmpl( $template_names, $load = false, $require_once = true ) { |
| 192 | - // No file found yet |
|
| 193 | - $located = false; |
|
| 192 | + // No file found yet |
|
| 193 | + $located = false; |
|
| 194 | 194 | |
| 195 | - // Try to find a template file |
|
| 196 | - foreach ( (array)$template_names as $template_name ) { |
|
| 195 | + // Try to find a template file |
|
| 196 | + foreach ( (array)$template_names as $template_name ) { |
|
| 197 | 197 | |
| 198 | - // Continue if template is empty |
|
| 199 | - if ( empty( $template_name ) ) |
|
| 200 | - continue; |
|
| 198 | + // Continue if template is empty |
|
| 199 | + if ( empty( $template_name ) ) |
|
| 200 | + continue; |
|
| 201 | 201 | |
| 202 | - // Trim off any slashes from the template name |
|
| 203 | - $template_name = ltrim( $template_name, '/' ); |
|
| 202 | + // Trim off any slashes from the template name |
|
| 203 | + $template_name = ltrim( $template_name, '/' ); |
|
| 204 | 204 | |
| 205 | - // try locating this template file by looping through the template paths |
|
| 206 | - foreach( wpinv_get_theme_template_paths() as $template_path ) { |
|
| 205 | + // try locating this template file by looping through the template paths |
|
| 206 | + foreach( wpinv_get_theme_template_paths() as $template_path ) { |
|
| 207 | 207 | |
| 208 | - if( file_exists( $template_path . $template_name ) ) { |
|
| 209 | - $located = $template_path . $template_name; |
|
| 210 | - break; |
|
| 211 | - } |
|
| 212 | - } |
|
| 208 | + if( file_exists( $template_path . $template_name ) ) { |
|
| 209 | + $located = $template_path . $template_name; |
|
| 210 | + break; |
|
| 211 | + } |
|
| 212 | + } |
|
| 213 | 213 | |
| 214 | - if( !empty( $located ) ) { |
|
| 215 | - break; |
|
| 216 | - } |
|
| 217 | - } |
|
| 214 | + if( !empty( $located ) ) { |
|
| 215 | + break; |
|
| 216 | + } |
|
| 217 | + } |
|
| 218 | 218 | |
| 219 | - if ( ( true == $load ) && ! empty( $located ) ) |
|
| 220 | - load_template( $located, $require_once ); |
|
| 219 | + if ( ( true == $load ) && ! empty( $located ) ) |
|
| 220 | + load_template( $located, $require_once ); |
|
| 221 | 221 | |
| 222 | - return $located; |
|
| 222 | + return $located; |
|
| 223 | 223 | } |
| 224 | 224 | |
| 225 | 225 | function wpinv_get_theme_template_paths() { |
| 226 | - $template_dir = wpinv_get_theme_template_dir_name(); |
|
| 226 | + $template_dir = wpinv_get_theme_template_dir_name(); |
|
| 227 | 227 | |
| 228 | - $file_paths = array( |
|
| 229 | - 1 => trailingslashit( get_stylesheet_directory() ) . $template_dir, |
|
| 230 | - 10 => trailingslashit( get_template_directory() ) . $template_dir, |
|
| 231 | - 100 => wpinv_get_templates_dir() |
|
| 232 | - ); |
|
| 228 | + $file_paths = array( |
|
| 229 | + 1 => trailingslashit( get_stylesheet_directory() ) . $template_dir, |
|
| 230 | + 10 => trailingslashit( get_template_directory() ) . $template_dir, |
|
| 231 | + 100 => wpinv_get_templates_dir() |
|
| 232 | + ); |
|
| 233 | 233 | |
| 234 | - $file_paths = apply_filters( 'wpinv_template_paths', $file_paths ); |
|
| 234 | + $file_paths = apply_filters( 'wpinv_template_paths', $file_paths ); |
|
| 235 | 235 | |
| 236 | - // sort the file paths based on priority |
|
| 237 | - ksort( $file_paths, SORT_NUMERIC ); |
|
| 236 | + // sort the file paths based on priority |
|
| 237 | + ksort( $file_paths, SORT_NUMERIC ); |
|
| 238 | 238 | |
| 239 | - return array_map( 'trailingslashit', $file_paths ); |
|
| 239 | + return array_map( 'trailingslashit', $file_paths ); |
|
| 240 | 240 | } |
| 241 | 241 | |
| 242 | 242 | function wpinv_get_theme_template_dir_name() { |
| 243 | - return trailingslashit( apply_filters( 'wpinv_templates_dir', 'wpinv_templates' ) ); |
|
| 243 | + return trailingslashit( apply_filters( 'wpinv_templates_dir', 'wpinv_templates' ) ); |
|
| 244 | 244 | } |
| 245 | 245 | |
| 246 | 246 | function wpinv_checkout_meta_tags() { |
| 247 | 247 | |
| 248 | - $pages = array(); |
|
| 249 | - $pages[] = wpinv_get_option( 'success_page' ); |
|
| 250 | - $pages[] = wpinv_get_option( 'failure_page' ); |
|
| 251 | - $pages[] = wpinv_get_option( 'invoice_history_page' ); |
|
| 248 | + $pages = array(); |
|
| 249 | + $pages[] = wpinv_get_option( 'success_page' ); |
|
| 250 | + $pages[] = wpinv_get_option( 'failure_page' ); |
|
| 251 | + $pages[] = wpinv_get_option( 'invoice_history_page' ); |
|
| 252 | 252 | |
| 253 | - if( !wpinv_is_checkout() && !is_page( $pages ) ) { |
|
| 254 | - return; |
|
| 255 | - } |
|
| 253 | + if( !wpinv_is_checkout() && !is_page( $pages ) ) { |
|
| 254 | + return; |
|
| 255 | + } |
|
| 256 | 256 | |
| 257 | - echo '<meta name="robots" content="noindex,nofollow" />' . "\n"; |
|
| 257 | + echo '<meta name="robots" content="noindex,nofollow" />' . "\n"; |
|
| 258 | 258 | } |
| 259 | 259 | add_action( 'wp_head', 'wpinv_checkout_meta_tags' ); |
| 260 | 260 | |
| 261 | 261 | function wpinv_add_body_classes( $class ) { |
| 262 | - $classes = (array)$class; |
|
| 262 | + $classes = (array)$class; |
|
| 263 | 263 | |
| 264 | - if( wpinv_is_checkout() ) { |
|
| 265 | - $classes[] = 'wpinv-checkout'; |
|
| 266 | - $classes[] = 'wpinv-page'; |
|
| 267 | - } |
|
| 264 | + if( wpinv_is_checkout() ) { |
|
| 265 | + $classes[] = 'wpinv-checkout'; |
|
| 266 | + $classes[] = 'wpinv-page'; |
|
| 267 | + } |
|
| 268 | 268 | |
| 269 | - if( wpinv_is_success_page() ) { |
|
| 270 | - $classes[] = 'wpinv-success'; |
|
| 271 | - $classes[] = 'wpinv-page'; |
|
| 272 | - } |
|
| 269 | + if( wpinv_is_success_page() ) { |
|
| 270 | + $classes[] = 'wpinv-success'; |
|
| 271 | + $classes[] = 'wpinv-page'; |
|
| 272 | + } |
|
| 273 | 273 | |
| 274 | - if( wpinv_is_failed_transaction_page() ) { |
|
| 275 | - $classes[] = 'wpinv-failed-transaction'; |
|
| 276 | - $classes[] = 'wpinv-page'; |
|
| 277 | - } |
|
| 274 | + if( wpinv_is_failed_transaction_page() ) { |
|
| 275 | + $classes[] = 'wpinv-failed-transaction'; |
|
| 276 | + $classes[] = 'wpinv-page'; |
|
| 277 | + } |
|
| 278 | 278 | |
| 279 | - if( wpinv_is_invoice_history_page() ) { |
|
| 280 | - $classes[] = 'wpinv-history'; |
|
| 281 | - $classes[] = 'wpinv-page'; |
|
| 282 | - } |
|
| 279 | + if( wpinv_is_invoice_history_page() ) { |
|
| 280 | + $classes[] = 'wpinv-history'; |
|
| 281 | + $classes[] = 'wpinv-page'; |
|
| 282 | + } |
|
| 283 | 283 | |
| 284 | - if( wpinv_is_test_mode() ) { |
|
| 285 | - $classes[] = 'wpinv-test-mode'; |
|
| 286 | - $classes[] = 'wpinv-page'; |
|
| 287 | - } |
|
| 284 | + if( wpinv_is_test_mode() ) { |
|
| 285 | + $classes[] = 'wpinv-test-mode'; |
|
| 286 | + $classes[] = 'wpinv-page'; |
|
| 287 | + } |
|
| 288 | 288 | |
| 289 | - return array_unique( $classes ); |
|
| 289 | + return array_unique( $classes ); |
|
| 290 | 290 | } |
| 291 | 291 | add_filter( 'body_class', 'wpinv_add_body_classes' ); |
| 292 | 292 | |
@@ -1451,7 +1451,7 @@ discard block |
||
| 1451 | 1451 | add_action( 'wpinv_checkout_cart', 'wpinv_checkout_cart', 10 ); |
| 1452 | 1452 | |
| 1453 | 1453 | function wpinv_empty_cart_message() { |
| 1454 | - return apply_filters( 'wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __( 'Your cart is empty.', 'invoicing' ) . '</span>' ); |
|
| 1454 | + return apply_filters( 'wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __( 'Your cart is empty.', 'invoicing' ) . '</span>' ); |
|
| 1455 | 1455 | } |
| 1456 | 1456 | |
| 1457 | 1457 | /** |
@@ -1461,7 +1461,7 @@ discard block |
||
| 1461 | 1461 | * @return void |
| 1462 | 1462 | */ |
| 1463 | 1463 | function wpinv_empty_checkout_cart() { |
| 1464 | - echo wpinv_empty_cart_message(); |
|
| 1464 | + echo wpinv_empty_cart_message(); |
|
| 1465 | 1465 | } |
| 1466 | 1466 | add_action( 'wpinv_cart_empty', 'wpinv_empty_checkout_cart' ); |
| 1467 | 1467 | |
@@ -1598,11 +1598,11 @@ discard block |
||
| 1598 | 1598 | do_action( 'wpinv_payment_mode_before_gateways' ); |
| 1599 | 1599 | |
| 1600 | 1600 | if(!empty($gateways)){ |
| 1601 | - foreach ( $gateways as $gateway_id => $gateway ) { |
|
| 1602 | - $checked = checked( $gateway_id, $chosen_gateway, false ); |
|
| 1603 | - $button_label = wpinv_get_gateway_button_label( $gateway_id ); |
|
| 1604 | - $description = wpinv_get_gateway_description( $gateway_id ); |
|
| 1605 | - ?> |
|
| 1601 | + foreach ( $gateways as $gateway_id => $gateway ) { |
|
| 1602 | + $checked = checked( $gateway_id, $chosen_gateway, false ); |
|
| 1603 | + $button_label = wpinv_get_gateway_button_label( $gateway_id ); |
|
| 1604 | + $description = wpinv_get_gateway_description( $gateway_id ); |
|
| 1605 | + ?> |
|
| 1606 | 1606 | <div class="list-group-item"> |
| 1607 | 1607 | <div class="radio"> |
| 1608 | 1608 | <label><input type="radio" data-button-text="<?php echo esc_attr( $button_label );?>" value="<?php echo esc_attr( $gateway_id ) ;?>" <?php echo $checked ;?> id="wpi_gateway_<?php echo esc_attr( $gateway_id );?>" name="wpi-gateway" class="wpi-pmethod"><?php echo esc_html( $gateway['checkout_label'] ); ?></label> |
@@ -1615,9 +1615,9 @@ discard block |
||
| 1615 | 1615 | </div> |
| 1616 | 1616 | </div> |
| 1617 | 1617 | <?php |
| 1618 | - } |
|
| 1618 | + } |
|
| 1619 | 1619 | }else{ |
| 1620 | - echo '<div class="alert alert-warning">'. __('No payment gateway active','invoicing') .'</div>'; |
|
| 1620 | + echo '<div class="alert alert-warning">'. __('No payment gateway active','invoicing') .'</div>'; |
|
| 1621 | 1621 | } |
| 1622 | 1622 | |
| 1623 | 1623 | do_action( 'wpinv_payment_mode_after_gateways' ); |
@@ -7,109 +7,109 @@ discard block |
||
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | 9 | // MUST have WordPress. |
| 10 | -if ( !defined( 'WPINC' ) ) { |
|
| 11 | - exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) ); |
|
| 10 | +if (!defined('WPINC')) { |
|
| 11 | + exit('Do NOT access this file directly: ' . basename(__FILE__)); |
|
| 12 | 12 | } |
| 13 | 13 | |
| 14 | -if ( !is_admin() ) { |
|
| 15 | - add_filter( 'template_include', 'wpinv_template', 10, 1 ); |
|
| 16 | - add_action( 'wpinv_invoice_print_body_start', 'wpinv_display_invoice_top_bar' ); |
|
| 17 | - add_action( 'wpinv_invoice_top_bar_left', 'wpinv_invoice_display_left_actions' ); |
|
| 18 | - add_action( 'wpinv_invoice_top_bar_right', 'wpinv_invoice_display_right_actions' ); |
|
| 14 | +if (!is_admin()) { |
|
| 15 | + add_filter('template_include', 'wpinv_template', 10, 1); |
|
| 16 | + add_action('wpinv_invoice_print_body_start', 'wpinv_display_invoice_top_bar'); |
|
| 17 | + add_action('wpinv_invoice_top_bar_left', 'wpinv_invoice_display_left_actions'); |
|
| 18 | + add_action('wpinv_invoice_top_bar_right', 'wpinv_invoice_display_right_actions'); |
|
| 19 | 19 | } |
| 20 | 20 | |
| 21 | 21 | function wpinv_template_path() { |
| 22 | - return apply_filters( 'wpinv_template_path', 'invoicing/' ); |
|
| 22 | + return apply_filters('wpinv_template_path', 'invoicing/'); |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | -function wpinv_post_class( $classes, $class, $post_id ) { |
|
| 25 | +function wpinv_post_class($classes, $class, $post_id) { |
|
| 26 | 26 | global $pagenow, $typenow; |
| 27 | 27 | |
| 28 | - if ( $pagenow == 'edit.php' && $typenow == 'wpi_item' && get_post_type( $post_id ) == $typenow && get_post_meta( $post_id, '_wpinv_type', true ) == 'package' ) { |
|
| 28 | + if ($pagenow == 'edit.php' && $typenow == 'wpi_item' && get_post_type($post_id) == $typenow && get_post_meta($post_id, '_wpinv_type', true) == 'package') { |
|
| 29 | 29 | $classes[] = 'wpi-gd-package'; |
| 30 | 30 | } |
| 31 | 31 | return $classes; |
| 32 | 32 | } |
| 33 | -add_filter( 'post_class', 'wpinv_post_class', 10, 3 ); |
|
| 33 | +add_filter('post_class', 'wpinv_post_class', 10, 3); |
|
| 34 | 34 | |
| 35 | -function wpinv_display_invoice_top_bar( $invoice ) { |
|
| 36 | - if ( empty( $invoice ) ) { |
|
| 35 | +function wpinv_display_invoice_top_bar($invoice) { |
|
| 36 | + if (empty($invoice)) { |
|
| 37 | 37 | return; |
| 38 | 38 | } |
| 39 | 39 | ?> |
| 40 | 40 | <div class="row wpinv-top-bar no-print"> |
| 41 | 41 | <div class="container"> |
| 42 | 42 | <div class="col-xs-6"> |
| 43 | - <?php do_action( 'wpinv_invoice_top_bar_left', $invoice );?> |
|
| 43 | + <?php do_action('wpinv_invoice_top_bar_left', $invoice); ?> |
|
| 44 | 44 | </div> |
| 45 | 45 | <div class="col-xs-6 text-right"> |
| 46 | - <?php do_action( 'wpinv_invoice_top_bar_right', $invoice );?> |
|
| 46 | + <?php do_action('wpinv_invoice_top_bar_right', $invoice); ?> |
|
| 47 | 47 | </div> |
| 48 | 48 | </div> |
| 49 | 49 | </div> |
| 50 | 50 | <?php |
| 51 | 51 | } |
| 52 | 52 | |
| 53 | -function wpinv_invoice_display_left_actions( $invoice ) { |
|
| 54 | - if ( empty( $invoice ) ) { |
|
| 53 | +function wpinv_invoice_display_left_actions($invoice) { |
|
| 54 | + if (empty($invoice)) { |
|
| 55 | 55 | return; |
| 56 | 56 | } |
| 57 | 57 | |
| 58 | - if($invoice->post_type == 'wpi_invoice'){ |
|
| 58 | + if ($invoice->post_type == 'wpi_invoice') { |
|
| 59 | 59 | |
| 60 | 60 | $user_id = (int)$invoice->get_user_id(); |
| 61 | 61 | $current_user_id = (int)get_current_user_id(); |
| 62 | 62 | |
| 63 | - if ( $user_id > 0 && $user_id == $current_user_id && $invoice->needs_payment() ) { |
|
| 63 | + if ($user_id > 0 && $user_id == $current_user_id && $invoice->needs_payment()) { |
|
| 64 | 64 | ?> |
| 65 | - <a class="btn btn-success btn-sm" title="<?php esc_attr_e( 'Pay This Invoice', 'invoicing' ); ?>" href="<?php echo esc_url( $invoice->get_checkout_payment_url() ); ?>"><?php _e( 'Pay For Invoice', 'invoicing' ); ?></a> |
|
| 65 | + <a class="btn btn-success btn-sm" title="<?php esc_attr_e('Pay This Invoice', 'invoicing'); ?>" href="<?php echo esc_url($invoice->get_checkout_payment_url()); ?>"><?php _e('Pay For Invoice', 'invoicing'); ?></a> |
|
| 66 | 66 | <?php |
| 67 | 67 | } |
| 68 | 68 | } |
| 69 | 69 | do_action('wpinv_invoice_display_left_actions', $invoice); |
| 70 | 70 | } |
| 71 | 71 | |
| 72 | -function wpinv_invoice_display_right_actions( $invoice ) { |
|
| 73 | - if ( empty( $invoice ) ) return; //Exit if invoice is not set. |
|
| 72 | +function wpinv_invoice_display_right_actions($invoice) { |
|
| 73 | + if (empty($invoice)) return; //Exit if invoice is not set. |
|
| 74 | 74 | |
| 75 | - if($invoice->post_type == 'wpi_invoice'){ |
|
| 75 | + if ($invoice->post_type == 'wpi_invoice') { |
|
| 76 | 76 | $user_id = (int)$invoice->get_user_id(); |
| 77 | 77 | $current_user_id = (int)get_current_user_id(); |
| 78 | 78 | |
| 79 | - if ( $user_id > 0 && $user_id == $current_user_id ) { |
|
| 79 | + if ($user_id > 0 && $user_id == $current_user_id) { |
|
| 80 | 80 | ?> |
| 81 | - <a class="btn btn-primary btn-sm" onclick="window.print();" href="javascript:void(0)"><?php _e( 'Print Invoice', 'invoicing' ); ?></a> |
|
| 82 | - <a class="btn btn-warning btn-sm" href="<?php echo esc_url( wpinv_get_history_page_uri() ); ?>"><?php _e( 'Invoice History', 'invoicing' ); ?></a> |
|
| 81 | + <a class="btn btn-primary btn-sm" onclick="window.print();" href="javascript:void(0)"><?php _e('Print Invoice', 'invoicing'); ?></a> |
|
| 82 | + <a class="btn btn-warning btn-sm" href="<?php echo esc_url(wpinv_get_history_page_uri()); ?>"><?php _e('Invoice History', 'invoicing'); ?></a> |
|
| 83 | 83 | <?php } |
| 84 | 84 | } |
| 85 | 85 | do_action('wpinv_invoice_display_right_actions', $invoice); |
| 86 | 86 | } |
| 87 | 87 | |
| 88 | -function wpinv_before_invoice_content( $content ) { |
|
| 88 | +function wpinv_before_invoice_content($content) { |
|
| 89 | 89 | global $post; |
| 90 | 90 | |
| 91 | - if ( !empty( $post ) && $post->post_type == 'wpi_invoice' && is_singular( 'wpi_invoice' ) && is_main_query() ) { |
|
| 91 | + if (!empty($post) && $post->post_type == 'wpi_invoice' && is_singular('wpi_invoice') && is_main_query()) { |
|
| 92 | 92 | ob_start(); |
| 93 | - do_action( 'wpinv_before_invoice_content', $post->ID ); |
|
| 93 | + do_action('wpinv_before_invoice_content', $post->ID); |
|
| 94 | 94 | $content = ob_get_clean() . $content; |
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | return $content; |
| 98 | 98 | } |
| 99 | -add_filter( 'the_content', 'wpinv_before_invoice_content' ); |
|
| 99 | +add_filter('the_content', 'wpinv_before_invoice_content'); |
|
| 100 | 100 | |
| 101 | -function wpinv_after_invoice_content( $content ) { |
|
| 101 | +function wpinv_after_invoice_content($content) { |
|
| 102 | 102 | global $post; |
| 103 | 103 | |
| 104 | - if ( !empty( $post ) && $post->post_type == 'wpi_invoice' && is_singular( 'wpi_invoice' ) && is_main_query() ) { |
|
| 104 | + if (!empty($post) && $post->post_type == 'wpi_invoice' && is_singular('wpi_invoice') && is_main_query()) { |
|
| 105 | 105 | ob_start(); |
| 106 | - do_action( 'wpinv_after_invoice_content', $post->ID ); |
|
| 106 | + do_action('wpinv_after_invoice_content', $post->ID); |
|
| 107 | 107 | $content .= ob_get_clean(); |
| 108 | 108 | } |
| 109 | 109 | |
| 110 | 110 | return $content; |
| 111 | 111 | } |
| 112 | -add_filter( 'the_content', 'wpinv_after_invoice_content' ); |
|
| 112 | +add_filter('the_content', 'wpinv_after_invoice_content'); |
|
| 113 | 113 | |
| 114 | 114 | function wpinv_get_templates_dir() { |
| 115 | 115 | return WPINV_PLUGIN_DIR . 'templates'; |
@@ -119,105 +119,105 @@ discard block |
||
| 119 | 119 | return WPINV_PLUGIN_URL . 'templates'; |
| 120 | 120 | } |
| 121 | 121 | |
| 122 | -function wpinv_get_template( $template_name, $args = array(), $template_path = '', $default_path = '' ) { |
|
| 123 | - if ( ! empty( $args ) && is_array( $args ) ) { |
|
| 124 | - extract( $args ); |
|
| 122 | +function wpinv_get_template($template_name, $args = array(), $template_path = '', $default_path = '') { |
|
| 123 | + if (!empty($args) && is_array($args)) { |
|
| 124 | + extract($args); |
|
| 125 | 125 | } |
| 126 | 126 | |
| 127 | - $located = wpinv_locate_template( $template_name, $template_path, $default_path ); |
|
| 127 | + $located = wpinv_locate_template($template_name, $template_path, $default_path); |
|
| 128 | 128 | // Allow 3rd party plugin filter template file from their plugin. |
| 129 | - $located = apply_filters( 'wpinv_get_template', $located, $template_name, $args, $template_path, $default_path ); |
|
| 129 | + $located = apply_filters('wpinv_get_template', $located, $template_name, $args, $template_path, $default_path); |
|
| 130 | 130 | |
| 131 | - if ( ! file_exists( $located ) ) { |
|
| 132 | - _doing_it_wrong( __FUNCTION__, sprintf( '<code>%s</code> does not exist.', $located ), '2.1' ); |
|
| 131 | + if (!file_exists($located)) { |
|
| 132 | + _doing_it_wrong(__FUNCTION__, sprintf('<code>%s</code> does not exist.', $located), '2.1'); |
|
| 133 | 133 | return; |
| 134 | 134 | } |
| 135 | 135 | |
| 136 | - do_action( 'wpinv_before_template_part', $template_name, $template_path, $located, $args ); |
|
| 136 | + do_action('wpinv_before_template_part', $template_name, $template_path, $located, $args); |
|
| 137 | 137 | |
| 138 | - include( $located ); |
|
| 138 | + include($located); |
|
| 139 | 139 | |
| 140 | - do_action( 'wpinv_after_template_part', $template_name, $template_path, $located, $args ); |
|
| 140 | + do_action('wpinv_after_template_part', $template_name, $template_path, $located, $args); |
|
| 141 | 141 | } |
| 142 | 142 | |
| 143 | -function wpinv_get_template_html( $template_name, $args = array(), $template_path = '', $default_path = '' ) { |
|
| 143 | +function wpinv_get_template_html($template_name, $args = array(), $template_path = '', $default_path = '') { |
|
| 144 | 144 | ob_start(); |
| 145 | - wpinv_get_template( $template_name, $args, $template_path, $default_path ); |
|
| 145 | + wpinv_get_template($template_name, $args, $template_path, $default_path); |
|
| 146 | 146 | return ob_get_clean(); |
| 147 | 147 | } |
| 148 | 148 | |
| 149 | -function wpinv_locate_template( $template_name, $template_path = '', $default_path = '' ) { |
|
| 150 | - if ( ! $template_path ) { |
|
| 149 | +function wpinv_locate_template($template_name, $template_path = '', $default_path = '') { |
|
| 150 | + if (!$template_path) { |
|
| 151 | 151 | $template_path = wpinv_template_path(); |
| 152 | 152 | } |
| 153 | 153 | |
| 154 | - if ( ! $default_path ) { |
|
| 154 | + if (!$default_path) { |
|
| 155 | 155 | $default_path = WPINV_PLUGIN_DIR . 'templates/'; |
| 156 | 156 | } |
| 157 | 157 | |
| 158 | 158 | // Look within passed path within the theme - this is priority. |
| 159 | 159 | $template = locate_template( |
| 160 | 160 | array( |
| 161 | - trailingslashit( $template_path ) . $template_name, |
|
| 161 | + trailingslashit($template_path) . $template_name, |
|
| 162 | 162 | $template_name |
| 163 | 163 | ) |
| 164 | 164 | ); |
| 165 | 165 | |
| 166 | 166 | // Get default templates/ |
| 167 | - if ( !$template && $default_path ) { |
|
| 168 | - $template = trailingslashit( $default_path ) . $template_name; |
|
| 167 | + if (!$template && $default_path) { |
|
| 168 | + $template = trailingslashit($default_path) . $template_name; |
|
| 169 | 169 | } |
| 170 | 170 | |
| 171 | 171 | // Return what we found. |
| 172 | - return apply_filters( 'wpinv_locate_template', $template, $template_name, $template_path ); |
|
| 172 | + return apply_filters('wpinv_locate_template', $template, $template_name, $template_path); |
|
| 173 | 173 | } |
| 174 | 174 | |
| 175 | -function wpinv_get_template_part( $slug, $name = null, $load = true ) { |
|
| 176 | - do_action( 'get_template_part_' . $slug, $slug, $name ); |
|
| 175 | +function wpinv_get_template_part($slug, $name = null, $load = true) { |
|
| 176 | + do_action('get_template_part_' . $slug, $slug, $name); |
|
| 177 | 177 | |
| 178 | 178 | // Setup possible parts |
| 179 | 179 | $templates = array(); |
| 180 | - if ( isset( $name ) ) |
|
| 180 | + if (isset($name)) |
|
| 181 | 181 | $templates[] = $slug . '-' . $name . '.php'; |
| 182 | 182 | $templates[] = $slug . '.php'; |
| 183 | 183 | |
| 184 | 184 | // Allow template parts to be filtered |
| 185 | - $templates = apply_filters( 'wpinv_get_template_part', $templates, $slug, $name ); |
|
| 185 | + $templates = apply_filters('wpinv_get_template_part', $templates, $slug, $name); |
|
| 186 | 186 | |
| 187 | 187 | // Return the part that is found |
| 188 | - return wpinv_locate_tmpl( $templates, $load, false ); |
|
| 188 | + return wpinv_locate_tmpl($templates, $load, false); |
|
| 189 | 189 | } |
| 190 | 190 | |
| 191 | -function wpinv_locate_tmpl( $template_names, $load = false, $require_once = true ) { |
|
| 191 | +function wpinv_locate_tmpl($template_names, $load = false, $require_once = true) { |
|
| 192 | 192 | // No file found yet |
| 193 | 193 | $located = false; |
| 194 | 194 | |
| 195 | 195 | // Try to find a template file |
| 196 | - foreach ( (array)$template_names as $template_name ) { |
|
| 196 | + foreach ((array)$template_names as $template_name) { |
|
| 197 | 197 | |
| 198 | 198 | // Continue if template is empty |
| 199 | - if ( empty( $template_name ) ) |
|
| 199 | + if (empty($template_name)) |
|
| 200 | 200 | continue; |
| 201 | 201 | |
| 202 | 202 | // Trim off any slashes from the template name |
| 203 | - $template_name = ltrim( $template_name, '/' ); |
|
| 203 | + $template_name = ltrim($template_name, '/'); |
|
| 204 | 204 | |
| 205 | 205 | // try locating this template file by looping through the template paths |
| 206 | - foreach( wpinv_get_theme_template_paths() as $template_path ) { |
|
| 206 | + foreach (wpinv_get_theme_template_paths() as $template_path) { |
|
| 207 | 207 | |
| 208 | - if( file_exists( $template_path . $template_name ) ) { |
|
| 208 | + if (file_exists($template_path . $template_name)) { |
|
| 209 | 209 | $located = $template_path . $template_name; |
| 210 | 210 | break; |
| 211 | 211 | } |
| 212 | 212 | } |
| 213 | 213 | |
| 214 | - if( !empty( $located ) ) { |
|
| 214 | + if (!empty($located)) { |
|
| 215 | 215 | break; |
| 216 | 216 | } |
| 217 | 217 | } |
| 218 | 218 | |
| 219 | - if ( ( true == $load ) && ! empty( $located ) ) |
|
| 220 | - load_template( $located, $require_once ); |
|
| 219 | + if ((true == $load) && !empty($located)) |
|
| 220 | + load_template($located, $require_once); |
|
| 221 | 221 | |
| 222 | 222 | return $located; |
| 223 | 223 | } |
@@ -226,143 +226,143 @@ discard block |
||
| 226 | 226 | $template_dir = wpinv_get_theme_template_dir_name(); |
| 227 | 227 | |
| 228 | 228 | $file_paths = array( |
| 229 | - 1 => trailingslashit( get_stylesheet_directory() ) . $template_dir, |
|
| 230 | - 10 => trailingslashit( get_template_directory() ) . $template_dir, |
|
| 229 | + 1 => trailingslashit(get_stylesheet_directory()) . $template_dir, |
|
| 230 | + 10 => trailingslashit(get_template_directory()) . $template_dir, |
|
| 231 | 231 | 100 => wpinv_get_templates_dir() |
| 232 | 232 | ); |
| 233 | 233 | |
| 234 | - $file_paths = apply_filters( 'wpinv_template_paths', $file_paths ); |
|
| 234 | + $file_paths = apply_filters('wpinv_template_paths', $file_paths); |
|
| 235 | 235 | |
| 236 | 236 | // sort the file paths based on priority |
| 237 | - ksort( $file_paths, SORT_NUMERIC ); |
|
| 237 | + ksort($file_paths, SORT_NUMERIC); |
|
| 238 | 238 | |
| 239 | - return array_map( 'trailingslashit', $file_paths ); |
|
| 239 | + return array_map('trailingslashit', $file_paths); |
|
| 240 | 240 | } |
| 241 | 241 | |
| 242 | 242 | function wpinv_get_theme_template_dir_name() { |
| 243 | - return trailingslashit( apply_filters( 'wpinv_templates_dir', 'wpinv_templates' ) ); |
|
| 243 | + return trailingslashit(apply_filters('wpinv_templates_dir', 'wpinv_templates')); |
|
| 244 | 244 | } |
| 245 | 245 | |
| 246 | 246 | function wpinv_checkout_meta_tags() { |
| 247 | 247 | |
| 248 | 248 | $pages = array(); |
| 249 | - $pages[] = wpinv_get_option( 'success_page' ); |
|
| 250 | - $pages[] = wpinv_get_option( 'failure_page' ); |
|
| 251 | - $pages[] = wpinv_get_option( 'invoice_history_page' ); |
|
| 249 | + $pages[] = wpinv_get_option('success_page'); |
|
| 250 | + $pages[] = wpinv_get_option('failure_page'); |
|
| 251 | + $pages[] = wpinv_get_option('invoice_history_page'); |
|
| 252 | 252 | |
| 253 | - if( !wpinv_is_checkout() && !is_page( $pages ) ) { |
|
| 253 | + if (!wpinv_is_checkout() && !is_page($pages)) { |
|
| 254 | 254 | return; |
| 255 | 255 | } |
| 256 | 256 | |
| 257 | 257 | echo '<meta name="robots" content="noindex,nofollow" />' . "\n"; |
| 258 | 258 | } |
| 259 | -add_action( 'wp_head', 'wpinv_checkout_meta_tags' ); |
|
| 259 | +add_action('wp_head', 'wpinv_checkout_meta_tags'); |
|
| 260 | 260 | |
| 261 | -function wpinv_add_body_classes( $class ) { |
|
| 261 | +function wpinv_add_body_classes($class) { |
|
| 262 | 262 | $classes = (array)$class; |
| 263 | 263 | |
| 264 | - if( wpinv_is_checkout() ) { |
|
| 264 | + if (wpinv_is_checkout()) { |
|
| 265 | 265 | $classes[] = 'wpinv-checkout'; |
| 266 | 266 | $classes[] = 'wpinv-page'; |
| 267 | 267 | } |
| 268 | 268 | |
| 269 | - if( wpinv_is_success_page() ) { |
|
| 269 | + if (wpinv_is_success_page()) { |
|
| 270 | 270 | $classes[] = 'wpinv-success'; |
| 271 | 271 | $classes[] = 'wpinv-page'; |
| 272 | 272 | } |
| 273 | 273 | |
| 274 | - if( wpinv_is_failed_transaction_page() ) { |
|
| 274 | + if (wpinv_is_failed_transaction_page()) { |
|
| 275 | 275 | $classes[] = 'wpinv-failed-transaction'; |
| 276 | 276 | $classes[] = 'wpinv-page'; |
| 277 | 277 | } |
| 278 | 278 | |
| 279 | - if( wpinv_is_invoice_history_page() ) { |
|
| 279 | + if (wpinv_is_invoice_history_page()) { |
|
| 280 | 280 | $classes[] = 'wpinv-history'; |
| 281 | 281 | $classes[] = 'wpinv-page'; |
| 282 | 282 | } |
| 283 | 283 | |
| 284 | - if( wpinv_is_test_mode() ) { |
|
| 284 | + if (wpinv_is_test_mode()) { |
|
| 285 | 285 | $classes[] = 'wpinv-test-mode'; |
| 286 | 286 | $classes[] = 'wpinv-page'; |
| 287 | 287 | } |
| 288 | 288 | |
| 289 | - return array_unique( $classes ); |
|
| 289 | + return array_unique($classes); |
|
| 290 | 290 | } |
| 291 | -add_filter( 'body_class', 'wpinv_add_body_classes' ); |
|
| 291 | +add_filter('body_class', 'wpinv_add_body_classes'); |
|
| 292 | 292 | |
| 293 | -function wpinv_html_dropdown( $name = 'wpinv_discounts', $selected = 0, $status = '' ) { |
|
| 294 | - $args = array( 'nopaging' => true ); |
|
| 293 | +function wpinv_html_dropdown($name = 'wpinv_discounts', $selected = 0, $status = '') { |
|
| 294 | + $args = array('nopaging' => true); |
|
| 295 | 295 | |
| 296 | - if ( ! empty( $status ) ) |
|
| 296 | + if (!empty($status)) |
|
| 297 | 297 | $args['post_status'] = $status; |
| 298 | 298 | |
| 299 | - $discounts = wpinv_get_discounts( $args ); |
|
| 299 | + $discounts = wpinv_get_discounts($args); |
|
| 300 | 300 | $options = array(); |
| 301 | 301 | |
| 302 | - if ( $discounts ) { |
|
| 303 | - foreach ( $discounts as $discount ) { |
|
| 304 | - $options[ absint( $discount->ID ) ] = esc_html( get_the_title( $discount->ID ) ); |
|
| 302 | + if ($discounts) { |
|
| 303 | + foreach ($discounts as $discount) { |
|
| 304 | + $options[absint($discount->ID)] = esc_html(get_the_title($discount->ID)); |
|
| 305 | 305 | } |
| 306 | 306 | } else { |
| 307 | - $options[0] = __( 'No discounts found', 'invoicing' ); |
|
| 307 | + $options[0] = __('No discounts found', 'invoicing'); |
|
| 308 | 308 | } |
| 309 | 309 | |
| 310 | - $output = wpinv_html_select( array( |
|
| 310 | + $output = wpinv_html_select(array( |
|
| 311 | 311 | 'name' => $name, |
| 312 | 312 | 'selected' => $selected, |
| 313 | 313 | 'options' => $options, |
| 314 | 314 | 'show_option_all' => false, |
| 315 | 315 | 'show_option_none' => false, |
| 316 | - ) ); |
|
| 316 | + )); |
|
| 317 | 317 | |
| 318 | 318 | return $output; |
| 319 | 319 | } |
| 320 | 320 | |
| 321 | -function wpinv_html_year_dropdown( $name = 'year', $selected = 0, $years_before = 5, $years_after = 0 ) { |
|
| 322 | - $current = date( 'Y' ); |
|
| 323 | - $start_year = $current - absint( $years_before ); |
|
| 324 | - $end_year = $current + absint( $years_after ); |
|
| 325 | - $selected = empty( $selected ) ? date( 'Y' ) : $selected; |
|
| 321 | +function wpinv_html_year_dropdown($name = 'year', $selected = 0, $years_before = 5, $years_after = 0) { |
|
| 322 | + $current = date('Y'); |
|
| 323 | + $start_year = $current - absint($years_before); |
|
| 324 | + $end_year = $current + absint($years_after); |
|
| 325 | + $selected = empty($selected) ? date('Y') : $selected; |
|
| 326 | 326 | $options = array(); |
| 327 | 327 | |
| 328 | - while ( $start_year <= $end_year ) { |
|
| 329 | - $options[ absint( $start_year ) ] = $start_year; |
|
| 328 | + while ($start_year <= $end_year) { |
|
| 329 | + $options[absint($start_year)] = $start_year; |
|
| 330 | 330 | $start_year++; |
| 331 | 331 | } |
| 332 | 332 | |
| 333 | - $output = wpinv_html_select( array( |
|
| 333 | + $output = wpinv_html_select(array( |
|
| 334 | 334 | 'name' => $name, |
| 335 | 335 | 'selected' => $selected, |
| 336 | 336 | 'options' => $options, |
| 337 | 337 | 'show_option_all' => false, |
| 338 | 338 | 'show_option_none' => false |
| 339 | - ) ); |
|
| 339 | + )); |
|
| 340 | 340 | |
| 341 | 341 | return $output; |
| 342 | 342 | } |
| 343 | 343 | |
| 344 | -function wpinv_html_month_dropdown( $name = 'month', $selected = 0 ) { |
|
| 344 | +function wpinv_html_month_dropdown($name = 'month', $selected = 0) { |
|
| 345 | 345 | $month = 1; |
| 346 | 346 | $options = array(); |
| 347 | - $selected = empty( $selected ) ? date( 'n' ) : $selected; |
|
| 347 | + $selected = empty($selected) ? date('n') : $selected; |
|
| 348 | 348 | |
| 349 | - while ( $month <= 12 ) { |
|
| 350 | - $options[ absint( $month ) ] = wpinv_month_num_to_name( $month ); |
|
| 349 | + while ($month <= 12) { |
|
| 350 | + $options[absint($month)] = wpinv_month_num_to_name($month); |
|
| 351 | 351 | $month++; |
| 352 | 352 | } |
| 353 | 353 | |
| 354 | - $output = wpinv_html_select( array( |
|
| 354 | + $output = wpinv_html_select(array( |
|
| 355 | 355 | 'name' => $name, |
| 356 | 356 | 'selected' => $selected, |
| 357 | 357 | 'options' => $options, |
| 358 | 358 | 'show_option_all' => false, |
| 359 | 359 | 'show_option_none' => false |
| 360 | - ) ); |
|
| 360 | + )); |
|
| 361 | 361 | |
| 362 | 362 | return $output; |
| 363 | 363 | } |
| 364 | 364 | |
| 365 | -function wpinv_html_select( $args = array() ) { |
|
| 365 | +function wpinv_html_select($args = array()) { |
|
| 366 | 366 | $defaults = array( |
| 367 | 367 | 'options' => array(), |
| 368 | 368 | 'name' => null, |
@@ -372,8 +372,8 @@ discard block |
||
| 372 | 372 | 'chosen' => false, |
| 373 | 373 | 'placeholder' => null, |
| 374 | 374 | 'multiple' => false, |
| 375 | - 'show_option_all' => _x( 'All', 'all dropdown items', 'invoicing' ), |
|
| 376 | - 'show_option_none' => _x( 'None', 'no dropdown items', 'invoicing' ), |
|
| 375 | + 'show_option_all' => _x('All', 'all dropdown items', 'invoicing'), |
|
| 376 | + 'show_option_none' => _x('None', 'no dropdown items', 'invoicing'), |
|
| 377 | 377 | 'data' => array(), |
| 378 | 378 | 'onchange' => null, |
| 379 | 379 | 'required' => false, |
@@ -381,78 +381,78 @@ discard block |
||
| 381 | 381 | 'readonly' => false, |
| 382 | 382 | ); |
| 383 | 383 | |
| 384 | - $args = wp_parse_args( $args, $defaults ); |
|
| 384 | + $args = wp_parse_args($args, $defaults); |
|
| 385 | 385 | |
| 386 | 386 | $data_elements = ''; |
| 387 | - foreach ( $args['data'] as $key => $value ) { |
|
| 388 | - $data_elements .= ' data-' . esc_attr( $key ) . '="' . esc_attr( $value ) . '"'; |
|
| 387 | + foreach ($args['data'] as $key => $value) { |
|
| 388 | + $data_elements .= ' data-' . esc_attr($key) . '="' . esc_attr($value) . '"'; |
|
| 389 | 389 | } |
| 390 | 390 | |
| 391 | - if( $args['multiple'] ) { |
|
| 391 | + if ($args['multiple']) { |
|
| 392 | 392 | $multiple = ' MULTIPLE'; |
| 393 | 393 | } else { |
| 394 | 394 | $multiple = ''; |
| 395 | 395 | } |
| 396 | 396 | |
| 397 | - if( $args['chosen'] ) { |
|
| 397 | + if ($args['chosen']) { |
|
| 398 | 398 | $args['class'] .= ' wpinv-select-chosen'; |
| 399 | 399 | } |
| 400 | 400 | |
| 401 | - if( $args['placeholder'] ) { |
|
| 401 | + if ($args['placeholder']) { |
|
| 402 | 402 | $placeholder = $args['placeholder']; |
| 403 | 403 | } else { |
| 404 | 404 | $placeholder = ''; |
| 405 | 405 | } |
| 406 | 406 | |
| 407 | 407 | $options = ''; |
| 408 | - if( !empty( $args['onchange'] ) ) { |
|
| 409 | - $options .= ' onchange="' . esc_attr( $args['onchange'] ) . '"'; |
|
| 408 | + if (!empty($args['onchange'])) { |
|
| 409 | + $options .= ' onchange="' . esc_attr($args['onchange']) . '"'; |
|
| 410 | 410 | } |
| 411 | 411 | |
| 412 | - if( !empty( $args['required'] ) ) { |
|
| 412 | + if (!empty($args['required'])) { |
|
| 413 | 413 | $options .= ' required="required"'; |
| 414 | 414 | } |
| 415 | 415 | |
| 416 | - if( !empty( $args['disabled'] ) ) { |
|
| 416 | + if (!empty($args['disabled'])) { |
|
| 417 | 417 | $options .= ' disabled'; |
| 418 | 418 | } |
| 419 | 419 | |
| 420 | - if( !empty( $args['readonly'] ) ) { |
|
| 420 | + if (!empty($args['readonly'])) { |
|
| 421 | 421 | $options .= ' readonly'; |
| 422 | 422 | } |
| 423 | 423 | |
| 424 | - $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) ); |
|
| 425 | - $output = '<select name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['id'] ) . '" class="wpinv-select ' . $class . '"' . $multiple . ' data-placeholder="' . $placeholder . '" ' . trim( $options ) . $data_elements . '>'; |
|
| 424 | + $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class']))); |
|
| 425 | + $output = '<select name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['id']) . '" class="wpinv-select ' . $class . '"' . $multiple . ' data-placeholder="' . $placeholder . '" ' . trim($options) . $data_elements . '>'; |
|
| 426 | 426 | |
| 427 | - if ( $args['show_option_all'] ) { |
|
| 428 | - if( $args['multiple'] ) { |
|
| 429 | - $selected = selected( true, in_array( 0, $args['selected'] ), false ); |
|
| 427 | + if ($args['show_option_all']) { |
|
| 428 | + if ($args['multiple']) { |
|
| 429 | + $selected = selected(true, in_array(0, $args['selected']), false); |
|
| 430 | 430 | } else { |
| 431 | - $selected = selected( $args['selected'], 0, false ); |
|
| 431 | + $selected = selected($args['selected'], 0, false); |
|
| 432 | 432 | } |
| 433 | - $output .= '<option value="all"' . $selected . '>' . esc_html( $args['show_option_all'] ) . '</option>'; |
|
| 433 | + $output .= '<option value="all"' . $selected . '>' . esc_html($args['show_option_all']) . '</option>'; |
|
| 434 | 434 | } |
| 435 | 435 | |
| 436 | - if ( !empty( $args['options'] ) ) { |
|
| 436 | + if (!empty($args['options'])) { |
|
| 437 | 437 | |
| 438 | - if ( $args['show_option_none'] ) { |
|
| 439 | - if( $args['multiple'] ) { |
|
| 440 | - $selected = selected( true, in_array( "", $args['selected'] ), false ); |
|
| 438 | + if ($args['show_option_none']) { |
|
| 439 | + if ($args['multiple']) { |
|
| 440 | + $selected = selected(true, in_array("", $args['selected']), false); |
|
| 441 | 441 | } else { |
| 442 | - $selected = selected( $args['selected'] === "", true, false ); |
|
| 442 | + $selected = selected($args['selected'] === "", true, false); |
|
| 443 | 443 | } |
| 444 | - $output .= '<option value=""' . $selected . '>' . esc_html( $args['show_option_none'] ) . '</option>'; |
|
| 444 | + $output .= '<option value=""' . $selected . '>' . esc_html($args['show_option_none']) . '</option>'; |
|
| 445 | 445 | } |
| 446 | 446 | |
| 447 | - foreach( $args['options'] as $key => $option ) { |
|
| 447 | + foreach ($args['options'] as $key => $option) { |
|
| 448 | 448 | |
| 449 | - if( $args['multiple'] && is_array( $args['selected'] ) ) { |
|
| 450 | - $selected = selected( true, (bool)in_array( $key, $args['selected'] ), false ); |
|
| 449 | + if ($args['multiple'] && is_array($args['selected'])) { |
|
| 450 | + $selected = selected(true, (bool)in_array($key, $args['selected']), false); |
|
| 451 | 451 | } else { |
| 452 | - $selected = selected( $args['selected'], $key, false ); |
|
| 452 | + $selected = selected($args['selected'], $key, false); |
|
| 453 | 453 | } |
| 454 | 454 | |
| 455 | - $output .= '<option value="' . esc_attr( $key ) . '"' . $selected . '>' . esc_html( $option ) . '</option>'; |
|
| 455 | + $output .= '<option value="' . esc_attr($key) . '"' . $selected . '>' . esc_html($option) . '</option>'; |
|
| 456 | 456 | } |
| 457 | 457 | } |
| 458 | 458 | |
@@ -461,7 +461,7 @@ discard block |
||
| 461 | 461 | return $output; |
| 462 | 462 | } |
| 463 | 463 | |
| 464 | -function wpinv_item_dropdown( $args = array() ) { |
|
| 464 | +function wpinv_item_dropdown($args = array()) { |
|
| 465 | 465 | $defaults = array( |
| 466 | 466 | 'name' => 'wpi_item', |
| 467 | 467 | 'id' => 'wpi_item', |
@@ -470,15 +470,15 @@ discard block |
||
| 470 | 470 | 'selected' => 0, |
| 471 | 471 | 'chosen' => false, |
| 472 | 472 | 'number' => 100, |
| 473 | - 'placeholder' => __( 'Choose a item', 'invoicing' ), |
|
| 474 | - 'data' => array( 'search-type' => 'item' ), |
|
| 473 | + 'placeholder' => __('Choose a item', 'invoicing'), |
|
| 474 | + 'data' => array('search-type' => 'item'), |
|
| 475 | 475 | 'show_option_all' => false, |
| 476 | 476 | 'show_option_none' => false, |
| 477 | 477 | 'with_packages' => true, |
| 478 | 478 | 'show_recurring' => false, |
| 479 | 479 | ); |
| 480 | 480 | |
| 481 | - $args = wp_parse_args( $args, $defaults ); |
|
| 481 | + $args = wp_parse_args($args, $defaults); |
|
| 482 | 482 | |
| 483 | 483 | $item_args = array( |
| 484 | 484 | 'post_type' => 'wpi_item', |
@@ -487,7 +487,7 @@ discard block |
||
| 487 | 487 | 'posts_per_page' => $args['number'] |
| 488 | 488 | ); |
| 489 | 489 | |
| 490 | - if ( !$args['with_packages'] ) { |
|
| 490 | + if (!$args['with_packages']) { |
|
| 491 | 491 | $item_args['meta_query'] = array( |
| 492 | 492 | array( |
| 493 | 493 | 'key' => '_wpinv_type', |
@@ -497,42 +497,42 @@ discard block |
||
| 497 | 497 | ); |
| 498 | 498 | } |
| 499 | 499 | |
| 500 | - $items = get_posts( $item_args ); |
|
| 500 | + $items = get_posts($item_args); |
|
| 501 | 501 | $options = array(); |
| 502 | - if ( $items ) { |
|
| 503 | - foreach ( $items as $item ) { |
|
| 504 | - $title = esc_html( $item->post_title ); |
|
| 502 | + if ($items) { |
|
| 503 | + foreach ($items as $item) { |
|
| 504 | + $title = esc_html($item->post_title); |
|
| 505 | 505 | |
| 506 | - if ( !empty( $args['show_recurring'] ) ) { |
|
| 507 | - $title .= wpinv_get_item_suffix( $item->ID, false ); |
|
| 506 | + if (!empty($args['show_recurring'])) { |
|
| 507 | + $title .= wpinv_get_item_suffix($item->ID, false); |
|
| 508 | 508 | } |
| 509 | 509 | |
| 510 | - $options[ absint( $item->ID ) ] = $title; |
|
| 510 | + $options[absint($item->ID)] = $title; |
|
| 511 | 511 | } |
| 512 | 512 | } |
| 513 | 513 | |
| 514 | 514 | // This ensures that any selected items are included in the drop down |
| 515 | - if( is_array( $args['selected'] ) ) { |
|
| 516 | - foreach( $args['selected'] as $item ) { |
|
| 517 | - if( ! in_array( $item, $options ) ) { |
|
| 518 | - $title = get_the_title( $item ); |
|
| 519 | - if ( !empty( $args['show_recurring'] ) ) { |
|
| 520 | - $title .= wpinv_get_item_suffix( $item, false ); |
|
| 515 | + if (is_array($args['selected'])) { |
|
| 516 | + foreach ($args['selected'] as $item) { |
|
| 517 | + if (!in_array($item, $options)) { |
|
| 518 | + $title = get_the_title($item); |
|
| 519 | + if (!empty($args['show_recurring'])) { |
|
| 520 | + $title .= wpinv_get_item_suffix($item, false); |
|
| 521 | 521 | } |
| 522 | 522 | $options[$item] = $title; |
| 523 | 523 | } |
| 524 | 524 | } |
| 525 | - } elseif ( is_numeric( $args['selected'] ) && $args['selected'] !== 0 ) { |
|
| 526 | - if ( ! in_array( $args['selected'], $options ) ) { |
|
| 527 | - $title = get_the_title( $args['selected'] ); |
|
| 528 | - if ( !empty( $args['show_recurring'] ) ) { |
|
| 529 | - $title .= wpinv_get_item_suffix( $args['selected'], false ); |
|
| 525 | + } elseif (is_numeric($args['selected']) && $args['selected'] !== 0) { |
|
| 526 | + if (!in_array($args['selected'], $options)) { |
|
| 527 | + $title = get_the_title($args['selected']); |
|
| 528 | + if (!empty($args['show_recurring'])) { |
|
| 529 | + $title .= wpinv_get_item_suffix($args['selected'], false); |
|
| 530 | 530 | } |
| 531 | - $options[$args['selected']] = get_the_title( $args['selected'] ); |
|
| 531 | + $options[$args['selected']] = get_the_title($args['selected']); |
|
| 532 | 532 | } |
| 533 | 533 | } |
| 534 | 534 | |
| 535 | - $output = wpinv_html_select( array( |
|
| 535 | + $output = wpinv_html_select(array( |
|
| 536 | 536 | 'name' => $args['name'], |
| 537 | 537 | 'selected' => $args['selected'], |
| 538 | 538 | 'id' => $args['id'], |
@@ -544,12 +544,12 @@ discard block |
||
| 544 | 544 | 'show_option_all' => $args['show_option_all'], |
| 545 | 545 | 'show_option_none' => $args['show_option_none'], |
| 546 | 546 | 'data' => $args['data'], |
| 547 | - ) ); |
|
| 547 | + )); |
|
| 548 | 548 | |
| 549 | 549 | return $output; |
| 550 | 550 | } |
| 551 | 551 | |
| 552 | -function wpinv_html_checkbox( $args = array() ) { |
|
| 552 | +function wpinv_html_checkbox($args = array()) { |
|
| 553 | 553 | $defaults = array( |
| 554 | 554 | 'name' => null, |
| 555 | 555 | 'current' => null, |
@@ -560,38 +560,38 @@ discard block |
||
| 560 | 560 | ) |
| 561 | 561 | ); |
| 562 | 562 | |
| 563 | - $args = wp_parse_args( $args, $defaults ); |
|
| 563 | + $args = wp_parse_args($args, $defaults); |
|
| 564 | 564 | |
| 565 | - $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) ); |
|
| 565 | + $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class']))); |
|
| 566 | 566 | $options = ''; |
| 567 | - if ( ! empty( $args['options']['disabled'] ) ) { |
|
| 567 | + if (!empty($args['options']['disabled'])) { |
|
| 568 | 568 | $options .= ' disabled="disabled"'; |
| 569 | - } elseif ( ! empty( $args['options']['readonly'] ) ) { |
|
| 569 | + } elseif (!empty($args['options']['readonly'])) { |
|
| 570 | 570 | $options .= ' readonly'; |
| 571 | 571 | } |
| 572 | 572 | |
| 573 | - $output = '<input type="checkbox"' . $options . ' name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['name'] ) . '" class="' . $class . ' ' . esc_attr( $args['name'] ) . '" ' . checked( 1, $args['current'], false ) . ' />'; |
|
| 573 | + $output = '<input type="checkbox"' . $options . ' name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['name']) . '" class="' . $class . ' ' . esc_attr($args['name']) . '" ' . checked(1, $args['current'], false) . ' />'; |
|
| 574 | 574 | |
| 575 | 575 | return $output; |
| 576 | 576 | } |
| 577 | 577 | |
| 578 | -function wpinv_html_text( $args = array() ) { |
|
| 578 | +function wpinv_html_text($args = array()) { |
|
| 579 | 579 | // Backwards compatibility |
| 580 | - if ( func_num_args() > 1 ) { |
|
| 580 | + if (func_num_args() > 1) { |
|
| 581 | 581 | $args = func_get_args(); |
| 582 | 582 | |
| 583 | 583 | $name = $args[0]; |
| 584 | - $value = isset( $args[1] ) ? $args[1] : ''; |
|
| 585 | - $label = isset( $args[2] ) ? $args[2] : ''; |
|
| 586 | - $desc = isset( $args[3] ) ? $args[3] : ''; |
|
| 584 | + $value = isset($args[1]) ? $args[1] : ''; |
|
| 585 | + $label = isset($args[2]) ? $args[2] : ''; |
|
| 586 | + $desc = isset($args[3]) ? $args[3] : ''; |
|
| 587 | 587 | } |
| 588 | 588 | |
| 589 | 589 | $defaults = array( |
| 590 | 590 | 'id' => '', |
| 591 | - 'name' => isset( $name ) ? $name : 'text', |
|
| 592 | - 'value' => isset( $value ) ? $value : null, |
|
| 593 | - 'label' => isset( $label ) ? $label : null, |
|
| 594 | - 'desc' => isset( $desc ) ? $desc : null, |
|
| 591 | + 'name' => isset($name) ? $name : 'text', |
|
| 592 | + 'value' => isset($value) ? $value : null, |
|
| 593 | + 'label' => isset($label) ? $label : null, |
|
| 594 | + 'desc' => isset($desc) ? $desc : null, |
|
| 595 | 595 | 'placeholder' => '', |
| 596 | 596 | 'class' => 'regular-text', |
| 597 | 597 | 'disabled' => false, |
@@ -601,51 +601,51 @@ discard block |
||
| 601 | 601 | 'data' => false |
| 602 | 602 | ); |
| 603 | 603 | |
| 604 | - $args = wp_parse_args( $args, $defaults ); |
|
| 604 | + $args = wp_parse_args($args, $defaults); |
|
| 605 | 605 | |
| 606 | - $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) ); |
|
| 606 | + $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class']))); |
|
| 607 | 607 | $options = ''; |
| 608 | - if( $args['required'] ) { |
|
| 608 | + if ($args['required']) { |
|
| 609 | 609 | $options .= ' required="required"'; |
| 610 | 610 | } |
| 611 | - if( $args['readonly'] ) { |
|
| 611 | + if ($args['readonly']) { |
|
| 612 | 612 | $options .= ' readonly'; |
| 613 | 613 | } |
| 614 | - if( $args['readonly'] ) { |
|
| 614 | + if ($args['readonly']) { |
|
| 615 | 615 | $options .= ' readonly'; |
| 616 | 616 | } |
| 617 | 617 | |
| 618 | 618 | $data = ''; |
| 619 | - if ( !empty( $args['data'] ) ) { |
|
| 620 | - foreach ( $args['data'] as $key => $value ) { |
|
| 621 | - $data .= 'data-' . wpinv_sanitize_key( $key ) . '="' . esc_attr( $value ) . '" '; |
|
| 619 | + if (!empty($args['data'])) { |
|
| 620 | + foreach ($args['data'] as $key => $value) { |
|
| 621 | + $data .= 'data-' . wpinv_sanitize_key($key) . '="' . esc_attr($value) . '" '; |
|
| 622 | 622 | } |
| 623 | 623 | } |
| 624 | 624 | |
| 625 | - $output = '<span id="wpinv-' . wpinv_sanitize_key( $args['name'] ) . '-wrap">'; |
|
| 626 | - $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key( $args['id'] ) . '">' . esc_html( $args['label'] ) . '</label>'; |
|
| 627 | - if ( ! empty( $args['desc'] ) ) { |
|
| 628 | - $output .= '<span class="wpinv-description">' . esc_html( $args['desc'] ) . '</span>'; |
|
| 625 | + $output = '<span id="wpinv-' . wpinv_sanitize_key($args['name']) . '-wrap">'; |
|
| 626 | + $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key($args['id']) . '">' . esc_html($args['label']) . '</label>'; |
|
| 627 | + if (!empty($args['desc'])) { |
|
| 628 | + $output .= '<span class="wpinv-description">' . esc_html($args['desc']) . '</span>'; |
|
| 629 | 629 | } |
| 630 | 630 | |
| 631 | - $output .= '<input type="text" name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['id'] ) . '" autocomplete="' . esc_attr( $args['autocomplete'] ) . '" value="' . esc_attr( $args['value'] ) . '" placeholder="' . esc_attr( $args['placeholder'] ) . '" class="' . $class . '" ' . $data . ' ' . trim( $options ) . '/>'; |
|
| 631 | + $output .= '<input type="text" name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['id']) . '" autocomplete="' . esc_attr($args['autocomplete']) . '" value="' . esc_attr($args['value']) . '" placeholder="' . esc_attr($args['placeholder']) . '" class="' . $class . '" ' . $data . ' ' . trim($options) . '/>'; |
|
| 632 | 632 | |
| 633 | 633 | $output .= '</span>'; |
| 634 | 634 | |
| 635 | 635 | return $output; |
| 636 | 636 | } |
| 637 | 637 | |
| 638 | -function wpinv_html_date_field( $args = array() ) { |
|
| 639 | - if( empty( $args['class'] ) ) { |
|
| 638 | +function wpinv_html_date_field($args = array()) { |
|
| 639 | + if (empty($args['class'])) { |
|
| 640 | 640 | $args['class'] = 'wpiDatepicker'; |
| 641 | - } elseif( ! strpos( $args['class'], 'wpiDatepicker' ) ) { |
|
| 641 | + } elseif (!strpos($args['class'], 'wpiDatepicker')) { |
|
| 642 | 642 | $args['class'] .= ' wpiDatepicker'; |
| 643 | 643 | } |
| 644 | 644 | |
| 645 | - return wpinv_html_text( $args ); |
|
| 645 | + return wpinv_html_text($args); |
|
| 646 | 646 | } |
| 647 | 647 | |
| 648 | -function wpinv_html_textarea( $args = array() ) { |
|
| 648 | +function wpinv_html_textarea($args = array()) { |
|
| 649 | 649 | $defaults = array( |
| 650 | 650 | 'name' => 'textarea', |
| 651 | 651 | 'value' => null, |
@@ -655,31 +655,31 @@ discard block |
||
| 655 | 655 | 'disabled' => false |
| 656 | 656 | ); |
| 657 | 657 | |
| 658 | - $args = wp_parse_args( $args, $defaults ); |
|
| 658 | + $args = wp_parse_args($args, $defaults); |
|
| 659 | 659 | |
| 660 | - $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) ); |
|
| 660 | + $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class']))); |
|
| 661 | 661 | $disabled = ''; |
| 662 | - if( $args['disabled'] ) { |
|
| 662 | + if ($args['disabled']) { |
|
| 663 | 663 | $disabled = ' disabled="disabled"'; |
| 664 | 664 | } |
| 665 | 665 | |
| 666 | - $output = '<span id="wpinv-' . wpinv_sanitize_key( $args['name'] ) . '-wrap">'; |
|
| 667 | - $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key( $args['name'] ) . '">' . esc_html( $args['label'] ) . '</label>'; |
|
| 668 | - $output .= '<textarea name="' . esc_attr( $args['name'] ) . '" id="' . wpinv_sanitize_key( $args['name'] ) . '" class="' . $class . '"' . $disabled . '>' . esc_attr( $args['value'] ) . '</textarea>'; |
|
| 666 | + $output = '<span id="wpinv-' . wpinv_sanitize_key($args['name']) . '-wrap">'; |
|
| 667 | + $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key($args['name']) . '">' . esc_html($args['label']) . '</label>'; |
|
| 668 | + $output .= '<textarea name="' . esc_attr($args['name']) . '" id="' . wpinv_sanitize_key($args['name']) . '" class="' . $class . '"' . $disabled . '>' . esc_attr($args['value']) . '</textarea>'; |
|
| 669 | 669 | |
| 670 | - if ( ! empty( $args['desc'] ) ) { |
|
| 671 | - $output .= '<span class="wpinv-description">' . esc_html( $args['desc'] ) . '</span>'; |
|
| 670 | + if (!empty($args['desc'])) { |
|
| 671 | + $output .= '<span class="wpinv-description">' . esc_html($args['desc']) . '</span>'; |
|
| 672 | 672 | } |
| 673 | 673 | $output .= '</span>'; |
| 674 | 674 | |
| 675 | 675 | return $output; |
| 676 | 676 | } |
| 677 | 677 | |
| 678 | -function wpinv_html_ajax_user_search( $args = array() ) { |
|
| 678 | +function wpinv_html_ajax_user_search($args = array()) { |
|
| 679 | 679 | $defaults = array( |
| 680 | 680 | 'name' => 'user_id', |
| 681 | 681 | 'value' => null, |
| 682 | - 'placeholder' => __( 'Enter username', 'invoicing' ), |
|
| 682 | + 'placeholder' => __('Enter username', 'invoicing'), |
|
| 683 | 683 | 'label' => null, |
| 684 | 684 | 'desc' => null, |
| 685 | 685 | 'class' => '', |
@@ -688,13 +688,13 @@ discard block |
||
| 688 | 688 | 'data' => false |
| 689 | 689 | ); |
| 690 | 690 | |
| 691 | - $args = wp_parse_args( $args, $defaults ); |
|
| 691 | + $args = wp_parse_args($args, $defaults); |
|
| 692 | 692 | |
| 693 | 693 | $args['class'] = 'wpinv-ajax-user-search ' . $args['class']; |
| 694 | 694 | |
| 695 | 695 | $output = '<span class="wpinv_user_search_wrap">'; |
| 696 | - $output .= wpinv_html_text( $args ); |
|
| 697 | - $output .= '<span class="wpinv_user_search_results hidden"><a class="wpinv-ajax-user-cancel" title="' . __( 'Cancel', 'invoicing' ) . '" aria-label="' . __( 'Cancel', 'invoicing' ) . '" href="#">x</a><span></span></span>'; |
|
| 696 | + $output .= wpinv_html_text($args); |
|
| 697 | + $output .= '<span class="wpinv_user_search_results hidden"><a class="wpinv-ajax-user-cancel" title="' . __('Cancel', 'invoicing') . '" aria-label="' . __('Cancel', 'invoicing') . '" href="#">x</a><span></span></span>'; |
|
| 698 | 698 | $output .= '</span>'; |
| 699 | 699 | |
| 700 | 700 | return $output; |
@@ -703,7 +703,7 @@ discard block |
||
| 703 | 703 | function wpinv_ip_geolocation() { |
| 704 | 704 | global $wpinv_euvat; |
| 705 | 705 | |
| 706 | - $ip = !empty( $_GET['ip'] ) ? sanitize_text_field( $_GET['ip'] ) : ''; |
|
| 706 | + $ip = !empty($_GET['ip']) ? sanitize_text_field($_GET['ip']) : ''; |
|
| 707 | 707 | $content = ''; |
| 708 | 708 | $iso = ''; |
| 709 | 709 | $country = ''; |
@@ -714,69 +714,69 @@ discard block |
||
| 714 | 714 | $credit = ''; |
| 715 | 715 | $address = ''; |
| 716 | 716 | |
| 717 | - if ( wpinv_get_option( 'vat_ip_lookup' ) == 'geoip2' && $geoip2_city = $wpinv_euvat->geoip2_city_record( $ip ) ) { |
|
| 717 | + if (wpinv_get_option('vat_ip_lookup') == 'geoip2' && $geoip2_city = $wpinv_euvat->geoip2_city_record($ip)) { |
|
| 718 | 718 | try { |
| 719 | 719 | $iso = $geoip2_city->country->isoCode; |
| 720 | 720 | $country = $geoip2_city->country->name; |
| 721 | - $region = !empty( $geoip2_city->subdivisions ) && !empty( $geoip2_city->subdivisions[0]->name ) ? $geoip2_city->subdivisions[0]->name : ''; |
|
| 721 | + $region = !empty($geoip2_city->subdivisions) && !empty($geoip2_city->subdivisions[0]->name) ? $geoip2_city->subdivisions[0]->name : ''; |
|
| 722 | 722 | $city = $geoip2_city->city->name; |
| 723 | 723 | $longitude = $geoip2_city->location->longitude; |
| 724 | 724 | $latitude = $geoip2_city->location->latitude; |
| 725 | - $credit = __( 'Geolocated using the information by MaxMind, available from <a href="http://www.maxmind.com" target="_blank">www.maxmind.com</a>', 'invoicing' ); |
|
| 726 | - } catch( Exception $e ) { } |
|
| 725 | + $credit = __('Geolocated using the information by MaxMind, available from <a href="http://www.maxmind.com" target="_blank">www.maxmind.com</a>', 'invoicing'); |
|
| 726 | + } catch (Exception $e) { } |
|
| 727 | 727 | } |
| 728 | 728 | |
| 729 | - if ( !( $iso && $longitude && $latitude ) && function_exists( 'simplexml_load_file' ) ) { |
|
| 729 | + if (!($iso && $longitude && $latitude) && function_exists('simplexml_load_file')) { |
|
| 730 | 730 | try { |
| 731 | - $load_xml = simplexml_load_file( 'http://www.geoplugin.net/xml.gp?ip=' . $ip ); |
|
| 731 | + $load_xml = simplexml_load_file('http://www.geoplugin.net/xml.gp?ip=' . $ip); |
|
| 732 | 732 | |
| 733 | - if ( !empty( $load_xml ) && isset( $load_xml->geoplugin_countryCode ) && !empty( $load_xml->geoplugin_latitude ) && !empty( $load_xml->geoplugin_longitude ) ) { |
|
| 733 | + if (!empty($load_xml) && isset($load_xml->geoplugin_countryCode) && !empty($load_xml->geoplugin_latitude) && !empty($load_xml->geoplugin_longitude)) { |
|
| 734 | 734 | $iso = $load_xml->geoplugin_countryCode; |
| 735 | 735 | $country = $load_xml->geoplugin_countryName; |
| 736 | - $region = !empty( $load_xml->geoplugin_regionName ) ? $load_xml->geoplugin_regionName : ''; |
|
| 737 | - $city = !empty( $load_xml->geoplugin_city ) ? $load_xml->geoplugin_city : ''; |
|
| 736 | + $region = !empty($load_xml->geoplugin_regionName) ? $load_xml->geoplugin_regionName : ''; |
|
| 737 | + $city = !empty($load_xml->geoplugin_city) ? $load_xml->geoplugin_city : ''; |
|
| 738 | 738 | $longitude = $load_xml->geoplugin_longitude; |
| 739 | 739 | $latitude = $load_xml->geoplugin_latitude; |
| 740 | 740 | $credit = $load_xml->geoplugin_credit; |
| 741 | - $credit = __( 'Geolocated using the information by geoPlugin, available from <a href="http://www.geoplugin.com" target="_blank">www.geoplugin.com</a>', 'invoicing' ) . '<br>' . $load_xml->geoplugin_credit; |
|
| 741 | + $credit = __('Geolocated using the information by geoPlugin, available from <a href="http://www.geoplugin.com" target="_blank">www.geoplugin.com</a>', 'invoicing') . '<br>' . $load_xml->geoplugin_credit; |
|
| 742 | 742 | } |
| 743 | - } catch( Exception $e ) { } |
|
| 743 | + } catch (Exception $e) { } |
|
| 744 | 744 | } |
| 745 | 745 | |
| 746 | - if ( $iso && $longitude && $latitude ) { |
|
| 747 | - if ( $city ) { |
|
| 746 | + if ($iso && $longitude && $latitude) { |
|
| 747 | + if ($city) { |
|
| 748 | 748 | $address .= $city . ', '; |
| 749 | 749 | } |
| 750 | 750 | |
| 751 | - if ( $region ) { |
|
| 751 | + if ($region) { |
|
| 752 | 752 | $address .= $region . ', '; |
| 753 | 753 | } |
| 754 | 754 | |
| 755 | 755 | $address .= $country . ' (' . $iso . ')'; |
| 756 | - $content = '<p>'. sprintf( __( '<b>Address:</b> %s', 'invoicing' ), $address ) . '</p>'; |
|
| 757 | - $content .= '<p>'. $credit . '</p>'; |
|
| 756 | + $content = '<p>' . sprintf(__('<b>Address:</b> %s', 'invoicing'), $address) . '</p>'; |
|
| 757 | + $content .= '<p>' . $credit . '</p>'; |
|
| 758 | 758 | } else { |
| 759 | - $content = '<p>'. sprintf( __( 'Unable to find geolocation for the IP address: %s', 'invoicing' ), $ip ) . '</p>'; |
|
| 759 | + $content = '<p>' . sprintf(__('Unable to find geolocation for the IP address: %s', 'invoicing'), $ip) . '</p>'; |
|
| 760 | 760 | } |
| 761 | 761 | ?> |
| 762 | 762 | <!DOCTYPE html> |
| 763 | -<html><head><title><?php echo sprintf( __( 'IP: %s', 'invoicing' ), $ip );?></title><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"><link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/leaflet/1.0.0-rc.1/leaflet.css" /><style>html,body{height:100%;margin:0;padding:0;width:100%}body{text-align:center;background:#fff;color:#222;font-size:small;}body,p{font-family: arial,sans-serif}#map{margin:auto;width:100%;height:calc(100% - 120px);min-height:240px}</style></head> |
|
| 763 | +<html><head><title><?php echo sprintf(__('IP: %s', 'invoicing'), $ip); ?></title><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"><link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/leaflet/1.0.0-rc.1/leaflet.css" /><style>html,body{height:100%;margin:0;padding:0;width:100%}body{text-align:center;background:#fff;color:#222;font-size:small;}body,p{font-family: arial,sans-serif}#map{margin:auto;width:100%;height:calc(100% - 120px);min-height:240px}</style></head> |
|
| 764 | 764 | <body> |
| 765 | - <?php if ( $latitude && $latitude ) { ?> |
|
| 765 | + <?php if ($latitude && $latitude) { ?> |
|
| 766 | 766 | <div id="map"></div> |
| 767 | 767 | <script src="//cdnjs.cloudflare.com/ajax/libs/leaflet/1.0.0-rc.1/leaflet.js"></script> |
| 768 | 768 | <script type="text/javascript"> |
| 769 | 769 | var osmUrl = 'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', |
| 770 | 770 | osmAttrib = '© <a href="http://openstreetmap.org/copyright">OpenStreetMap</a> contributors', |
| 771 | 771 | osm = L.tileLayer(osmUrl, {maxZoom: 18, attribution: osmAttrib}), |
| 772 | - latlng = new L.LatLng(<?php echo $latitude;?>, <?php echo $longitude;?>); |
|
| 772 | + latlng = new L.LatLng(<?php echo $latitude; ?>, <?php echo $longitude; ?>); |
|
| 773 | 773 | |
| 774 | 774 | var map = new L.Map('map', {center: latlng, zoom: 12, layers: [osm]}); |
| 775 | 775 | |
| 776 | 776 | var marker = new L.Marker(latlng); |
| 777 | 777 | map.addLayer(marker); |
| 778 | 778 | |
| 779 | - marker.bindPopup("<p><?php esc_attr_e( $address );?></p>"); |
|
| 779 | + marker.bindPopup("<p><?php esc_attr_e($address); ?></p>"); |
|
| 780 | 780 | </script> |
| 781 | 781 | <?php } ?> |
| 782 | 782 | <div style="height:100px"><?php echo $content; ?></div> |
@@ -784,31 +784,31 @@ discard block |
||
| 784 | 784 | <?php |
| 785 | 785 | exit; |
| 786 | 786 | } |
| 787 | -add_action( 'wp_ajax_wpinv_ip_geolocation', 'wpinv_ip_geolocation' ); |
|
| 788 | -add_action( 'wp_ajax_nopriv_wpinv_ip_geolocation', 'wpinv_ip_geolocation' ); |
|
| 787 | +add_action('wp_ajax_wpinv_ip_geolocation', 'wpinv_ip_geolocation'); |
|
| 788 | +add_action('wp_ajax_nopriv_wpinv_ip_geolocation', 'wpinv_ip_geolocation'); |
|
| 789 | 789 | |
| 790 | 790 | // Set up the template for the invoice. |
| 791 | -function wpinv_template( $template ) { |
|
| 791 | +function wpinv_template($template) { |
|
| 792 | 792 | global $post, $wp_query; |
| 793 | 793 | |
| 794 | - if ( ( is_single() || is_404() ) && !empty( $post->ID ) && (get_post_type( $post->ID ) == 'wpi_invoice' or get_post_type( $post->ID ) == 'wpi_quote')) { |
|
| 795 | - if ( wpinv_user_can_print_invoice( $post->ID ) ) { |
|
| 796 | - $template = wpinv_get_template_part( 'wpinv-invoice-print', false, false ); |
|
| 794 | + if ((is_single() || is_404()) && !empty($post->ID) && (get_post_type($post->ID) == 'wpi_invoice' or get_post_type($post->ID) == 'wpi_quote')) { |
|
| 795 | + if (wpinv_user_can_print_invoice($post->ID)) { |
|
| 796 | + $template = wpinv_get_template_part('wpinv-invoice-print', false, false); |
|
| 797 | 797 | } else { |
| 798 | - if ( !is_user_logged_in() && !empty( $_REQUEST['_wpipay'] ) && $invoice = wpinv_get_invoice( $post->ID ) ) { |
|
| 798 | + if (!is_user_logged_in() && !empty($_REQUEST['_wpipay']) && $invoice = wpinv_get_invoice($post->ID)) { |
|
| 799 | 799 | $user_id = $invoice->get_user_id(); |
| 800 | - $secret = sanitize_text_field( $_GET['_wpipay'] ); |
|
| 800 | + $secret = sanitize_text_field($_GET['_wpipay']); |
|
| 801 | 801 | |
| 802 | - if ( $secret === md5( $user_id . '::' . $invoice->get_email() . '::' . $invoice->get_key() ) ) { // valid invoice link |
|
| 803 | - $redirect_to = remove_query_arg( '_wpipay', get_permalink() ); |
|
| 802 | + if ($secret === md5($user_id . '::' . $invoice->get_email() . '::' . $invoice->get_key())) { // valid invoice link |
|
| 803 | + $redirect_to = remove_query_arg('_wpipay', get_permalink()); |
|
| 804 | 804 | |
| 805 | - wpinv_guest_redirect( $redirect_to, $user_id ); |
|
| 805 | + wpinv_guest_redirect($redirect_to, $user_id); |
|
| 806 | 806 | wpinv_die(); |
| 807 | 807 | } |
| 808 | 808 | } |
| 809 | - $redirect_to = is_user_logged_in() ? wpinv_get_history_page_uri() : wp_login_url( get_permalink() ); |
|
| 809 | + $redirect_to = is_user_logged_in() ? wpinv_get_history_page_uri() : wp_login_url(get_permalink()); |
|
| 810 | 810 | |
| 811 | - wp_redirect( $redirect_to ); |
|
| 811 | + wp_redirect($redirect_to); |
|
| 812 | 812 | wpinv_die(); |
| 813 | 813 | } |
| 814 | 814 | } |
@@ -818,7 +818,7 @@ discard block |
||
| 818 | 818 | |
| 819 | 819 | function wpinv_get_business_address() { |
| 820 | 820 | $business_address = wpinv_store_address(); |
| 821 | - $business_address = !empty( $business_address ) ? wpautop( wp_kses_post( $business_address ) ) : ''; |
|
| 821 | + $business_address = !empty($business_address) ? wpautop(wp_kses_post($business_address)) : ''; |
|
| 822 | 822 | |
| 823 | 823 | /* |
| 824 | 824 | $default_country = wpinv_get_default_country(); |
@@ -842,7 +842,7 @@ discard block |
||
| 842 | 842 | |
| 843 | 843 | $business_address = $business_address ? '<div class="address">' . $business_address . '</div>' : ''; |
| 844 | 844 | |
| 845 | - return apply_filters( 'wpinv_get_business_address', $business_address ); |
|
| 845 | + return apply_filters('wpinv_get_business_address', $business_address); |
|
| 846 | 846 | } |
| 847 | 847 | |
| 848 | 848 | function wpinv_display_from_address() { |
@@ -852,185 +852,185 @@ discard block |
||
| 852 | 852 | if (empty($from_name)) { |
| 853 | 853 | $from_name = wpinv_get_business_name(); |
| 854 | 854 | } |
| 855 | - ?><div class="from col-xs-2"><strong><?php _e( 'From:', 'invoicing' ) ?></strong></div> |
|
| 855 | + ?><div class="from col-xs-2"><strong><?php _e('From:', 'invoicing') ?></strong></div> |
|
| 856 | 856 | <div class="wrapper col-xs-10"> |
| 857 | - <div class="name"><?php echo esc_html( $from_name ); ?></div> |
|
| 858 | - <?php if ( $address = wpinv_get_business_address() ) { ?> |
|
| 859 | - <div class="address"><?php echo wpautop( wp_kses_post( $address ) );?></div> |
|
| 857 | + <div class="name"><?php echo esc_html($from_name); ?></div> |
|
| 858 | + <?php if ($address = wpinv_get_business_address()) { ?> |
|
| 859 | + <div class="address"><?php echo wpautop(wp_kses_post($address)); ?></div> |
|
| 860 | 860 | <?php } ?> |
| 861 | - <?php if ( $email_from = wpinv_mail_get_from_address() ) { ?> |
|
| 862 | - <div class="email_from"><?php echo wp_sprintf( __( 'Email: %s' ), $email_from );?></div> |
|
| 861 | + <?php if ($email_from = wpinv_mail_get_from_address()) { ?> |
|
| 862 | + <div class="email_from"><?php echo wp_sprintf(__('Email: %s'), $email_from); ?></div> |
|
| 863 | 863 | <?php } ?> |
| 864 | 864 | </div> |
| 865 | 865 | <?php |
| 866 | 866 | } |
| 867 | 867 | |
| 868 | -function wpinv_watermark( $id = 0 ) { |
|
| 869 | - $output = wpinv_get_watermark( $id ); |
|
| 868 | +function wpinv_watermark($id = 0) { |
|
| 869 | + $output = wpinv_get_watermark($id); |
|
| 870 | 870 | |
| 871 | - return apply_filters( 'wpinv_get_watermark', $output, $id ); |
|
| 871 | + return apply_filters('wpinv_get_watermark', $output, $id); |
|
| 872 | 872 | } |
| 873 | 873 | |
| 874 | -function wpinv_get_watermark( $id ) { |
|
| 875 | - if ( !$id > 0 ) { |
|
| 874 | +function wpinv_get_watermark($id) { |
|
| 875 | + if (!$id > 0) { |
|
| 876 | 876 | return NULL; |
| 877 | 877 | } |
| 878 | - $invoice = wpinv_get_invoice( $id ); |
|
| 878 | + $invoice = wpinv_get_invoice($id); |
|
| 879 | 879 | |
| 880 | - if ( !empty( $invoice ) && "wpi_invoice" === $invoice->post_type ) { |
|
| 881 | - if ( $invoice->is_paid() ) { |
|
| 882 | - return __( 'Paid', 'invoicing' ); |
|
| 880 | + if (!empty($invoice) && "wpi_invoice" === $invoice->post_type) { |
|
| 881 | + if ($invoice->is_paid()) { |
|
| 882 | + return __('Paid', 'invoicing'); |
|
| 883 | 883 | } |
| 884 | - if ( $invoice->has_status( array( 'wpi-cancelled' ) ) ) { |
|
| 885 | - return __( 'Cancelled', 'invoicing' ); |
|
| 884 | + if ($invoice->has_status(array('wpi-cancelled'))) { |
|
| 885 | + return __('Cancelled', 'invoicing'); |
|
| 886 | 886 | } |
| 887 | 887 | } |
| 888 | 888 | |
| 889 | 889 | return NULL; |
| 890 | 890 | } |
| 891 | 891 | |
| 892 | -function wpinv_display_invoice_details( $invoice ) { |
|
| 892 | +function wpinv_display_invoice_details($invoice) { |
|
| 893 | 893 | global $wpinv_euvat; |
| 894 | 894 | |
| 895 | 895 | $invoice_id = $invoice->ID; |
| 896 | 896 | $vat_name = $wpinv_euvat->get_vat_name(); |
| 897 | 897 | $use_taxes = wpinv_use_taxes(); |
| 898 | 898 | |
| 899 | - $invoice_status = wpinv_get_invoice_status( $invoice_id ); |
|
| 899 | + $invoice_status = wpinv_get_invoice_status($invoice_id); |
|
| 900 | 900 | |
| 901 | - if($invoice->post_type == 'wpi_invoice') $type = 'Invoice'; |
|
| 902 | - elseif($invoice->post_type == 'wpi_quote') $type = 'Quote'; |
|
| 901 | + if ($invoice->post_type == 'wpi_invoice') $type = 'Invoice'; |
|
| 902 | + elseif ($invoice->post_type == 'wpi_quote') $type = 'Quote'; |
|
| 903 | 903 | ?> |
| 904 | 904 | <table class="table table-bordered table-sm"> |
| 905 | - <?php if ( $invoice_number = wpinv_get_invoice_number( $invoice_id ) ) { ?> |
|
| 905 | + <?php if ($invoice_number = wpinv_get_invoice_number($invoice_id)) { ?> |
|
| 906 | 906 | <tr class="wpi-row-number"> |
| 907 | - <th><?php echo sprintf(__( '%s Number', 'invoicing' ), $type); ?></th> |
|
| 908 | - <td><?php echo esc_html( $invoice_number ); ?></td> |
|
| 907 | + <th><?php echo sprintf(__('%s Number', 'invoicing'), $type); ?></th> |
|
| 908 | + <td><?php echo esc_html($invoice_number); ?></td> |
|
| 909 | 909 | </tr> |
| 910 | 910 | <?php } ?> |
| 911 | 911 | <tr class="wpi-row-status"> |
| 912 | - <th><?php echo wp_sprintf(__( '%s Status', 'invoicing' ), $type); ?></th> |
|
| 913 | - <td><?php echo wpinv_invoice_status_label( $invoice_status, wpinv_get_invoice_status( $invoice_id, true ) ); ?></td> |
|
| 912 | + <th><?php echo wp_sprintf(__('%s Status', 'invoicing'), $type); ?></th> |
|
| 913 | + <td><?php echo wpinv_invoice_status_label($invoice_status, wpinv_get_invoice_status($invoice_id, true)); ?></td> |
|
| 914 | 914 | </tr> |
| 915 | - <?php if ( $invoice->is_renewal() ) { ?> |
|
| 915 | + <?php if ($invoice->is_renewal()) { ?> |
|
| 916 | 916 | <tr class="wpi-row-parent"> |
| 917 | - <th><?php echo wp_sprintf(__( 'Parent %s', 'invoicing' ), $type); ?></th> |
|
| 918 | - <td><?php echo wpinv_invoice_link( $invoice->parent_invoice ); ?></td> |
|
| 917 | + <th><?php echo wp_sprintf(__('Parent %s', 'invoicing'), $type); ?></th> |
|
| 918 | + <td><?php echo wpinv_invoice_link($invoice->parent_invoice); ?></td> |
|
| 919 | 919 | </tr> |
| 920 | 920 | <?php } ?> |
| 921 | 921 | <tr class="wpi-row-gateway"> |
| 922 | - <th><?php _e( 'Payment Method', 'invoicing' ); ?></th> |
|
| 923 | - <td><?php echo wpinv_get_payment_gateway_name( $invoice_id ); ?></td> |
|
| 922 | + <th><?php _e('Payment Method', 'invoicing'); ?></th> |
|
| 923 | + <td><?php echo wpinv_get_payment_gateway_name($invoice_id); ?></td> |
|
| 924 | 924 | </tr> |
| 925 | - <?php if ( $invoice_date = wpinv_get_invoice_date( $invoice_id ) ) { ?> |
|
| 925 | + <?php if ($invoice_date = wpinv_get_invoice_date($invoice_id)) { ?> |
|
| 926 | 926 | <tr class="wpi-row-date"> |
| 927 | - <th><?php echo wp_sprintf(__( '%s Date', 'invoicing' ), $type); ?></th> |
|
| 927 | + <th><?php echo wp_sprintf(__('%s Date', 'invoicing'), $type); ?></th> |
|
| 928 | 928 | <td><?php echo $invoice_date; ?></td> |
| 929 | 929 | </tr> |
| 930 | 930 | <?php } ?> |
| 931 | - <?php if ( wpinv_get_option( 'overdue_active' ) && $invoice->needs_payment() && ( $due_date = $invoice->get_due_date( true ) ) ) { ?> |
|
| 931 | + <?php if (wpinv_get_option('overdue_active') && $invoice->needs_payment() && ($due_date = $invoice->get_due_date(true))) { ?> |
|
| 932 | 932 | <tr class="wpi-row-date"> |
| 933 | - <th><?php _e( 'Due Date', 'invoicing' ); ?></th> |
|
| 933 | + <th><?php _e('Due Date', 'invoicing'); ?></th> |
|
| 934 | 934 | <td><?php echo $due_date; ?></td> |
| 935 | 935 | </tr> |
| 936 | 936 | <?php } ?> |
| 937 | - <?php if ( $owner_vat_number = $wpinv_euvat->get_vat_number() ) { ?> |
|
| 937 | + <?php if ($owner_vat_number = $wpinv_euvat->get_vat_number()) { ?> |
|
| 938 | 938 | <tr class="wpi-row-ovatno"> |
| 939 | - <th><?php echo wp_sprintf( __( 'Owner %s Number', 'invoicing' ), $vat_name ); ?></th> |
|
| 939 | + <th><?php echo wp_sprintf(__('Owner %s Number', 'invoicing'), $vat_name); ?></th> |
|
| 940 | 940 | <td><?php echo $owner_vat_number; ?></td> |
| 941 | 941 | </tr> |
| 942 | 942 | <?php } ?> |
| 943 | - <?php if ( $use_taxes && $user_vat_number = wpinv_get_invoice_vat_number( $invoice_id ) ) { ?> |
|
| 943 | + <?php if ($use_taxes && $user_vat_number = wpinv_get_invoice_vat_number($invoice_id)) { ?> |
|
| 944 | 944 | <tr class="wpi-row-uvatno"> |
| 945 | - <th><?php echo wp_sprintf( __( 'Your %s Number', 'invoicing' ), $vat_name ); ?></th> |
|
| 945 | + <th><?php echo wp_sprintf(__('Your %s Number', 'invoicing'), $vat_name); ?></th> |
|
| 946 | 946 | <td><?php echo $user_vat_number; ?></td> |
| 947 | 947 | </tr> |
| 948 | 948 | <?php } ?> |
| 949 | 949 | <tr class="table-active tr-total wpi-row-total"> |
| 950 | - <th><strong><?php _e( 'Total Amount', 'invoicing' ) ?></strong></th> |
|
| 951 | - <td><strong><?php echo wpinv_payment_total( $invoice_id, true ); ?></strong></td> |
|
| 950 | + <th><strong><?php _e('Total Amount', 'invoicing') ?></strong></th> |
|
| 951 | + <td><strong><?php echo wpinv_payment_total($invoice_id, true); ?></strong></td> |
|
| 952 | 952 | </tr> |
| 953 | 953 | </table> |
| 954 | 954 | <?php |
| 955 | 955 | } |
| 956 | 956 | |
| 957 | -function wpinv_display_to_address( $invoice_id = 0 ) { |
|
| 958 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
| 957 | +function wpinv_display_to_address($invoice_id = 0) { |
|
| 958 | + $invoice = wpinv_get_invoice($invoice_id); |
|
| 959 | 959 | |
| 960 | - if ( empty( $invoice ) ) { |
|
| 960 | + if (empty($invoice)) { |
|
| 961 | 961 | return NULL; |
| 962 | 962 | } |
| 963 | 963 | |
| 964 | 964 | $billing_details = $invoice->get_user_info(); |
| 965 | - $output = '<div class="to col-xs-2"><strong>' . __( 'To:', 'invoicing' ) . '</strong></div>'; |
|
| 965 | + $output = '<div class="to col-xs-2"><strong>' . __('To:', 'invoicing') . '</strong></div>'; |
|
| 966 | 966 | $output .= '<div class="wrapper col-xs-10">'; |
| 967 | 967 | |
| 968 | 968 | ob_start(); |
| 969 | - do_action( 'wpinv_display_to_address_top', $invoice ); |
|
| 969 | + do_action('wpinv_display_to_address_top', $invoice); |
|
| 970 | 970 | $output .= ob_get_clean(); |
| 971 | 971 | |
| 972 | - $output .= '<div class="name">' . esc_html( trim( $billing_details['first_name'] . ' ' . $billing_details['last_name'] ) ) . '</div>'; |
|
| 973 | - if ( $company = $billing_details['company'] ) { |
|
| 974 | - $output .= '<div class="company">' . wpautop( wp_kses_post( $company ) ) . '</div>'; |
|
| 972 | + $output .= '<div class="name">' . esc_html(trim($billing_details['first_name'] . ' ' . $billing_details['last_name'])) . '</div>'; |
|
| 973 | + if ($company = $billing_details['company']) { |
|
| 974 | + $output .= '<div class="company">' . wpautop(wp_kses_post($company)) . '</div>'; |
|
| 975 | 975 | } |
| 976 | 976 | $address_row = ''; |
| 977 | - if ( $address = $billing_details['address'] ) { |
|
| 978 | - $address_row .= wpautop( wp_kses_post( $address ) ); |
|
| 977 | + if ($address = $billing_details['address']) { |
|
| 978 | + $address_row .= wpautop(wp_kses_post($address)); |
|
| 979 | 979 | } |
| 980 | 980 | |
| 981 | 981 | $address_fields = array(); |
| 982 | - if ( !empty( $billing_details['city'] ) ) { |
|
| 982 | + if (!empty($billing_details['city'])) { |
|
| 983 | 983 | $address_fields[] = $billing_details['city']; |
| 984 | 984 | } |
| 985 | 985 | |
| 986 | - $billing_country = !empty( $billing_details['country'] ) ? $billing_details['country'] : ''; |
|
| 987 | - if ( !empty( $billing_details['state'] ) ) { |
|
| 988 | - $address_fields[] = wpinv_state_name( $billing_details['state'], $billing_country ); |
|
| 986 | + $billing_country = !empty($billing_details['country']) ? $billing_details['country'] : ''; |
|
| 987 | + if (!empty($billing_details['state'])) { |
|
| 988 | + $address_fields[] = wpinv_state_name($billing_details['state'], $billing_country); |
|
| 989 | 989 | } |
| 990 | 990 | |
| 991 | - if ( !empty( $billing_country ) ) { |
|
| 992 | - $address_fields[] = wpinv_country_name( $billing_country ); |
|
| 991 | + if (!empty($billing_country)) { |
|
| 992 | + $address_fields[] = wpinv_country_name($billing_country); |
|
| 993 | 993 | } |
| 994 | 994 | |
| 995 | - if ( !empty( $address_fields ) ) { |
|
| 996 | - $address_fields = implode( ", ", $address_fields ); |
|
| 995 | + if (!empty($address_fields)) { |
|
| 996 | + $address_fields = implode(", ", $address_fields); |
|
| 997 | 997 | |
| 998 | - if ( !empty( $billing_details['zip'] ) ) { |
|
| 998 | + if (!empty($billing_details['zip'])) { |
|
| 999 | 999 | $address_fields .= ' ' . $billing_details['zip']; |
| 1000 | 1000 | } |
| 1001 | 1001 | |
| 1002 | - $address_row .= wpautop( wp_kses_post( $address_fields ) ); |
|
| 1002 | + $address_row .= wpautop(wp_kses_post($address_fields)); |
|
| 1003 | 1003 | } |
| 1004 | 1004 | |
| 1005 | - if ( $address_row ) { |
|
| 1005 | + if ($address_row) { |
|
| 1006 | 1006 | $output .= '<div class="address">' . $address_row . '</div>'; |
| 1007 | 1007 | } |
| 1008 | 1008 | |
| 1009 | - if ( $phone = $invoice->get_phone() ) { |
|
| 1010 | - $output .= '<div class="phone">' . wp_sprintf( __( 'Phone: %s' ), esc_html( $phone ) ) . '</div>'; |
|
| 1009 | + if ($phone = $invoice->get_phone()) { |
|
| 1010 | + $output .= '<div class="phone">' . wp_sprintf(__('Phone: %s'), esc_html($phone)) . '</div>'; |
|
| 1011 | 1011 | } |
| 1012 | - if ( $email = $invoice->get_email() ) { |
|
| 1013 | - $output .= '<div class="email">' . wp_sprintf( __( 'Email: %s' ), esc_html( $email ) ) . '</div>'; |
|
| 1012 | + if ($email = $invoice->get_email()) { |
|
| 1013 | + $output .= '<div class="email">' . wp_sprintf(__('Email: %s'), esc_html($email)) . '</div>'; |
|
| 1014 | 1014 | } |
| 1015 | 1015 | |
| 1016 | 1016 | ob_start(); |
| 1017 | - do_action( 'wpinv_display_to_address_bottom', $invoice ); |
|
| 1017 | + do_action('wpinv_display_to_address_bottom', $invoice); |
|
| 1018 | 1018 | $output .= ob_get_clean(); |
| 1019 | 1019 | |
| 1020 | 1020 | $output .= '</div>'; |
| 1021 | - $output = apply_filters( 'wpinv_display_to_address', $output, $invoice ); |
|
| 1021 | + $output = apply_filters('wpinv_display_to_address', $output, $invoice); |
|
| 1022 | 1022 | |
| 1023 | 1023 | echo $output; |
| 1024 | 1024 | } |
| 1025 | 1025 | |
| 1026 | -function wpinv_display_line_items( $invoice_id = 0 ) { |
|
| 1026 | +function wpinv_display_line_items($invoice_id = 0) { |
|
| 1027 | 1027 | global $wpinv_euvat, $ajax_cart_details; |
| 1028 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
| 1028 | + $invoice = wpinv_get_invoice($invoice_id); |
|
| 1029 | 1029 | $quantities_enabled = wpinv_item_quantities_enabled(); |
| 1030 | 1030 | $use_taxes = wpinv_use_taxes(); |
| 1031 | 1031 | $zero_tax = !(float)$invoice->get_tax() > 0 ? true : false; |
| 1032 | - $tax_label = $use_taxes && $invoice->has_vat() ? $wpinv_euvat->get_vat_name() : __( 'Tax', 'invoicing' ); |
|
| 1033 | - $tax_title = !$zero_tax && $use_taxes ? ( wpinv_prices_include_tax() ? wp_sprintf( __( '(%s Incl.)', 'invoicing' ), $tax_label ) : wp_sprintf( __( '(%s Excl.)', 'invoicing' ), $tax_label ) ) : ''; |
|
| 1032 | + $tax_label = $use_taxes && $invoice->has_vat() ? $wpinv_euvat->get_vat_name() : __('Tax', 'invoicing'); |
|
| 1033 | + $tax_title = !$zero_tax && $use_taxes ? (wpinv_prices_include_tax() ? wp_sprintf(__('(%s Incl.)', 'invoicing'), $tax_label) : wp_sprintf(__('(%s Excl.)', 'invoicing'), $tax_label)) : ''; |
|
| 1034 | 1034 | |
| 1035 | 1035 | $cart_details = $invoice->get_cart_details(); |
| 1036 | 1036 | $ajax_cart_details = $cart_details; |
@@ -1039,68 +1039,68 @@ discard block |
||
| 1039 | 1039 | <table class="table table-sm table-bordered table-responsive"> |
| 1040 | 1040 | <thead> |
| 1041 | 1041 | <tr> |
| 1042 | - <th class="name"><strong><?php _e( "Item Name", "invoicing" );?></strong></th> |
|
| 1043 | - <th class="rate"><strong><?php _e( "Price", "invoicing" );?></strong></th> |
|
| 1042 | + <th class="name"><strong><?php _e("Item Name", "invoicing"); ?></strong></th> |
|
| 1043 | + <th class="rate"><strong><?php _e("Price", "invoicing"); ?></strong></th> |
|
| 1044 | 1044 | <?php if ($quantities_enabled) { ?> |
| 1045 | - <th class="qty"><strong><?php _e( "Qty", "invoicing" );?></strong></th> |
|
| 1045 | + <th class="qty"><strong><?php _e("Qty", "invoicing"); ?></strong></th> |
|
| 1046 | 1046 | <?php } ?> |
| 1047 | 1047 | <?php if ($use_taxes && !$zero_tax) { ?> |
| 1048 | 1048 | <th class="tax"><strong><?php echo $tax_label . ' <span class="normal small">(%)</span>'; ?></strong></th> |
| 1049 | 1049 | <?php } ?> |
| 1050 | - <th class="total"><strong><?php echo __( "Item Total", "invoicing" ) . ' <span class="normal small">' . $tax_title . '<span>';?></strong></th> |
|
| 1050 | + <th class="total"><strong><?php echo __("Item Total", "invoicing") . ' <span class="normal small">' . $tax_title . '<span>'; ?></strong></th> |
|
| 1051 | 1051 | </tr> |
| 1052 | 1052 | </thead> |
| 1053 | 1053 | <tbody> |
| 1054 | 1054 | <?php |
| 1055 | - if ( !empty( $cart_details ) ) { |
|
| 1056 | - do_action( 'wpinv_display_line_items_start', $invoice ); |
|
| 1055 | + if (!empty($cart_details)) { |
|
| 1056 | + do_action('wpinv_display_line_items_start', $invoice); |
|
| 1057 | 1057 | |
| 1058 | 1058 | $count = 0; |
| 1059 | 1059 | $cols = 3; |
| 1060 | - foreach ( $cart_details as $key => $cart_item ) { |
|
| 1061 | - $item_id = !empty($cart_item['id']) ? absint( $cart_item['id'] ) : ''; |
|
| 1062 | - $item_price = isset($cart_item["item_price"]) ? wpinv_round_amount( $cart_item["item_price"] ) : 0; |
|
| 1063 | - $line_total = isset($cart_item["subtotal"]) ? wpinv_round_amount( $cart_item["subtotal"] ) : 0; |
|
| 1064 | - $quantity = !empty($cart_item['quantity']) && (int)$cart_item['quantity'] > 0 ? absint( $cart_item['quantity'] ) : 1; |
|
| 1060 | + foreach ($cart_details as $key => $cart_item) { |
|
| 1061 | + $item_id = !empty($cart_item['id']) ? absint($cart_item['id']) : ''; |
|
| 1062 | + $item_price = isset($cart_item["item_price"]) ? wpinv_round_amount($cart_item["item_price"]) : 0; |
|
| 1063 | + $line_total = isset($cart_item["subtotal"]) ? wpinv_round_amount($cart_item["subtotal"]) : 0; |
|
| 1064 | + $quantity = !empty($cart_item['quantity']) && (int)$cart_item['quantity'] > 0 ? absint($cart_item['quantity']) : 1; |
|
| 1065 | 1065 | |
| 1066 | - $item = $item_id ? new WPInv_Item( $item_id ) : NULL; |
|
| 1066 | + $item = $item_id ? new WPInv_Item($item_id) : NULL; |
|
| 1067 | 1067 | $summary = ''; |
| 1068 | 1068 | $cols = 3; |
| 1069 | - if ( !empty($item) ) { |
|
| 1069 | + if (!empty($item)) { |
|
| 1070 | 1070 | $item_name = $item->get_name(); |
| 1071 | 1071 | $summary = $item->get_summary(); |
| 1072 | 1072 | } |
| 1073 | - $item_name = !empty($cart_item['name']) ? $cart_item['name'] : $item_name; |
|
| 1073 | + $item_name = !empty($cart_item['name']) ? $cart_item['name'] : $item_name; |
|
| 1074 | 1074 | |
| 1075 | 1075 | if (!empty($item) && $item->is_package() && !empty($cart_item['meta']['post_id'])) { |
| 1076 | - $post_link = '<a href="' . get_edit_post_link( $cart_item['meta']['post_id'] ) .'" target="_blank">' . (!empty($cart_item['meta']['invoice_title']) ? $cart_item['meta']['invoice_title'] : get_the_title( $cart_item['meta']['post_id']) ) . '</a>'; |
|
| 1077 | - $summary = wp_sprintf( __( '%s: %s', 'invoicing' ), $item->get_custom_singular_name(), $post_link ); |
|
| 1076 | + $post_link = '<a href="' . get_edit_post_link($cart_item['meta']['post_id']) . '" target="_blank">' . (!empty($cart_item['meta']['invoice_title']) ? $cart_item['meta']['invoice_title'] : get_the_title($cart_item['meta']['post_id'])) . '</a>'; |
|
| 1077 | + $summary = wp_sprintf(__('%s: %s', 'invoicing'), $item->get_custom_singular_name(), $post_link); |
|
| 1078 | 1078 | } |
| 1079 | - $summary = apply_filters( 'wpinv_print_invoice_line_item_summary', $summary, $cart_item, $item, $invoice ); |
|
| 1079 | + $summary = apply_filters('wpinv_print_invoice_line_item_summary', $summary, $cart_item, $item, $invoice); |
|
| 1080 | 1080 | |
| 1081 | 1081 | $item_tax = ''; |
| 1082 | 1082 | $tax_rate = ''; |
| 1083 | - if ( $use_taxes && $cart_item['tax'] > 0 && $cart_item['subtotal'] > 0 ) { |
|
| 1084 | - $item_tax = wpinv_price( wpinv_format_amount( $cart_item['tax'] ) ); |
|
| 1085 | - $tax_rate = !empty( $cart_item['vat_rate'] ) ? $cart_item['vat_rate'] : ( $cart_item['tax'] / $cart_item['subtotal'] ) * 100; |
|
| 1086 | - $tax_rate = $tax_rate > 0 ? (float)wpinv_round_amount( $tax_rate, 4 ) : ''; |
|
| 1083 | + if ($use_taxes && $cart_item['tax'] > 0 && $cart_item['subtotal'] > 0) { |
|
| 1084 | + $item_tax = wpinv_price(wpinv_format_amount($cart_item['tax'])); |
|
| 1085 | + $tax_rate = !empty($cart_item['vat_rate']) ? $cart_item['vat_rate'] : ($cart_item['tax'] / $cart_item['subtotal']) * 100; |
|
| 1086 | + $tax_rate = $tax_rate > 0 ? (float)wpinv_round_amount($tax_rate, 4) : ''; |
|
| 1087 | 1087 | $tax_rate = $tax_rate != '' ? ' <small class="tax-rate">(' . $tax_rate . '%)</small>' : ''; |
| 1088 | 1088 | } |
| 1089 | 1089 | |
| 1090 | 1090 | $line_item_tax = $item_tax . $tax_rate; |
| 1091 | 1091 | |
| 1092 | - if ( $line_item_tax === '' ) { |
|
| 1092 | + if ($line_item_tax === '') { |
|
| 1093 | 1093 | $line_item_tax = 0; // Zero tax |
| 1094 | 1094 | } |
| 1095 | 1095 | |
| 1096 | - $line_item = '<tr class="row-' . ( ($count % 2 == 0) ? 'even' : 'odd' ) . ' wpinv-item">'; |
|
| 1097 | - $line_item .= '<td class="name">' . esc_html__( $item_name, 'invoicing' ) . wpinv_get_item_suffix( $item ); |
|
| 1098 | - if ( $summary !== '' ) { |
|
| 1099 | - $line_item .= '<br/><small class="meta">' . wpautop( wp_kses_post( $summary ) ) . '</small>'; |
|
| 1096 | + $line_item = '<tr class="row-' . (($count % 2 == 0) ? 'even' : 'odd') . ' wpinv-item">'; |
|
| 1097 | + $line_item .= '<td class="name">' . esc_html__($item_name, 'invoicing') . wpinv_get_item_suffix($item); |
|
| 1098 | + if ($summary !== '') { |
|
| 1099 | + $line_item .= '<br/><small class="meta">' . wpautop(wp_kses_post($summary)) . '</small>'; |
|
| 1100 | 1100 | } |
| 1101 | 1101 | $line_item .= '</td>'; |
| 1102 | 1102 | |
| 1103 | - $line_item .= '<td class="rate">' . esc_html__( wpinv_price( wpinv_format_amount( $item_price ), $invoice->get_currency() ) ) . '</td>'; |
|
| 1103 | + $line_item .= '<td class="rate">' . esc_html__(wpinv_price(wpinv_format_amount($item_price), $invoice->get_currency())) . '</td>'; |
|
| 1104 | 1104 | if ($quantities_enabled) { |
| 1105 | 1105 | $cols++; |
| 1106 | 1106 | $line_item .= '<td class="qty">' . $quantity . '</td>'; |
@@ -1109,55 +1109,55 @@ discard block |
||
| 1109 | 1109 | $cols++; |
| 1110 | 1110 | $line_item .= '<td class="tax">' . $line_item_tax . '</td>'; |
| 1111 | 1111 | } |
| 1112 | - $line_item .= '<td class="total">' . esc_html__( wpinv_price( wpinv_format_amount( $line_total ), $invoice->get_currency() ) ) . '</td>'; |
|
| 1112 | + $line_item .= '<td class="total">' . esc_html__(wpinv_price(wpinv_format_amount($line_total), $invoice->get_currency())) . '</td>'; |
|
| 1113 | 1113 | $line_item .= '</tr>'; |
| 1114 | 1114 | |
| 1115 | - echo apply_filters( 'wpinv_display_line_item', $line_item, $cart_item, $invoice, $cols ); |
|
| 1115 | + echo apply_filters('wpinv_display_line_item', $line_item, $cart_item, $invoice, $cols); |
|
| 1116 | 1116 | |
| 1117 | 1117 | $count++; |
| 1118 | 1118 | } |
| 1119 | 1119 | |
| 1120 | - do_action( 'wpinv_display_before_subtotal', $invoice, $cols ); |
|
| 1120 | + do_action('wpinv_display_before_subtotal', $invoice, $cols); |
|
| 1121 | 1121 | ?> |
| 1122 | 1122 | <tr class="row-sub-total row_odd"> |
| 1123 | - <td class="rate" colspan="<?php echo ( $cols - 1 ); ?>"><?php echo apply_filters( 'wpinv_print_cart_subtotal_label', '<strong>' . __( 'Sub Total', 'invoicing' ) . ':</strong>', $invoice ); ?></td> |
|
| 1124 | - <td class="total"><strong><?php _e( wpinv_subtotal( $invoice_id, true ) ) ?></strong></td> |
|
| 1123 | + <td class="rate" colspan="<?php echo ($cols - 1); ?>"><?php echo apply_filters('wpinv_print_cart_subtotal_label', '<strong>' . __('Sub Total', 'invoicing') . ':</strong>', $invoice); ?></td> |
|
| 1124 | + <td class="total"><strong><?php _e(wpinv_subtotal($invoice_id, true)) ?></strong></td> |
|
| 1125 | 1125 | </tr> |
| 1126 | 1126 | <?php |
| 1127 | - do_action( 'wpinv_display_after_subtotal', $invoice, $cols ); |
|
| 1127 | + do_action('wpinv_display_after_subtotal', $invoice, $cols); |
|
| 1128 | 1128 | |
| 1129 | - if ( wpinv_discount( $invoice_id, false ) > 0 ) { |
|
| 1130 | - do_action( 'wpinv_display_before_discount', $invoice, $cols ); |
|
| 1129 | + if (wpinv_discount($invoice_id, false) > 0) { |
|
| 1130 | + do_action('wpinv_display_before_discount', $invoice, $cols); |
|
| 1131 | 1131 | ?> |
| 1132 | 1132 | <tr class="row-discount"> |
| 1133 | - <td class="rate" colspan="<?php echo ( $cols - 1 ); ?>"><?php wpinv_get_discount_label( wpinv_discount_code( $invoice_id ) ); ?>:</td> |
|
| 1134 | - <td class="total"><?php echo wpinv_discount( $invoice_id, true, true ); ?></td> |
|
| 1133 | + <td class="rate" colspan="<?php echo ($cols - 1); ?>"><?php wpinv_get_discount_label(wpinv_discount_code($invoice_id)); ?>:</td> |
|
| 1134 | + <td class="total"><?php echo wpinv_discount($invoice_id, true, true); ?></td> |
|
| 1135 | 1135 | </tr> |
| 1136 | 1136 | <?php |
| 1137 | - do_action( 'wpinv_display_after_discount', $invoice, $cols ); |
|
| 1137 | + do_action('wpinv_display_after_discount', $invoice, $cols); |
|
| 1138 | 1138 | } |
| 1139 | 1139 | |
| 1140 | - if ( $use_taxes ) { |
|
| 1141 | - do_action( 'wpinv_display_before_tax', $invoice, $cols ); |
|
| 1140 | + if ($use_taxes) { |
|
| 1141 | + do_action('wpinv_display_before_tax', $invoice, $cols); |
|
| 1142 | 1142 | ?> |
| 1143 | 1143 | <tr class="row-tax"> |
| 1144 | - <td class="rate" colspan="<?php echo ( $cols - 1 ); ?>"><?php echo apply_filters( 'wpinv_print_cart_tax_label', '<strong>' . $tax_label . ':</strong>', $invoice ); ?></td> |
|
| 1145 | - <td class="total"><?php _e( wpinv_tax( $invoice_id, true ) ) ?></td> |
|
| 1144 | + <td class="rate" colspan="<?php echo ($cols - 1); ?>"><?php echo apply_filters('wpinv_print_cart_tax_label', '<strong>' . $tax_label . ':</strong>', $invoice); ?></td> |
|
| 1145 | + <td class="total"><?php _e(wpinv_tax($invoice_id, true)) ?></td> |
|
| 1146 | 1146 | </tr> |
| 1147 | 1147 | <?php |
| 1148 | - do_action( 'wpinv_display_after_tax', $invoice, $cols ); |
|
| 1148 | + do_action('wpinv_display_after_tax', $invoice, $cols); |
|
| 1149 | 1149 | } |
| 1150 | 1150 | |
| 1151 | - do_action( 'wpinv_display_before_total', $invoice, $cols ); |
|
| 1151 | + do_action('wpinv_display_before_total', $invoice, $cols); |
|
| 1152 | 1152 | ?> |
| 1153 | 1153 | <tr class="table-active row-total"> |
| 1154 | - <td class="rate" colspan="<?php echo ( $cols - 1 ); ?>"><?php echo apply_filters( 'wpinv_print_cart_total_label', '<strong>' . __( 'Total', 'invoicing' ) . ':</strong>', $invoice ); ?></td> |
|
| 1155 | - <td class="total"><strong><?php _e( wpinv_payment_total( $invoice_id, true ) ) ?></strong></td> |
|
| 1154 | + <td class="rate" colspan="<?php echo ($cols - 1); ?>"><?php echo apply_filters('wpinv_print_cart_total_label', '<strong>' . __('Total', 'invoicing') . ':</strong>', $invoice); ?></td> |
|
| 1155 | + <td class="total"><strong><?php _e(wpinv_payment_total($invoice_id, true)) ?></strong></td> |
|
| 1156 | 1156 | </tr> |
| 1157 | 1157 | <?php |
| 1158 | - do_action( 'wpinv_display_after_total', $invoice, $cols ); |
|
| 1158 | + do_action('wpinv_display_after_total', $invoice, $cols); |
|
| 1159 | 1159 | |
| 1160 | - do_action( 'wpinv_display_line_end', $invoice, $cols ); |
|
| 1160 | + do_action('wpinv_display_line_end', $invoice, $cols); |
|
| 1161 | 1161 | } |
| 1162 | 1162 | ?> |
| 1163 | 1163 | </tbody> |
@@ -1166,35 +1166,35 @@ discard block |
||
| 1166 | 1166 | echo ob_get_clean(); |
| 1167 | 1167 | } |
| 1168 | 1168 | |
| 1169 | -function wpinv_display_invoice_totals( $invoice_id = 0 ) { |
|
| 1169 | +function wpinv_display_invoice_totals($invoice_id = 0) { |
|
| 1170 | 1170 | $use_taxes = wpinv_use_taxes(); |
| 1171 | 1171 | |
| 1172 | - do_action( 'wpinv_before_display_totals_table', $invoice_id ); |
|
| 1172 | + do_action('wpinv_before_display_totals_table', $invoice_id); |
|
| 1173 | 1173 | ?> |
| 1174 | 1174 | <table class="table table-sm table-bordered table-responsive"> |
| 1175 | 1175 | <tbody> |
| 1176 | - <?php do_action( 'wpinv_before_display_totals' ); ?> |
|
| 1176 | + <?php do_action('wpinv_before_display_totals'); ?> |
|
| 1177 | 1177 | <tr class="row-sub-total"> |
| 1178 | - <td class="rate"><strong><?php _e( 'Sub Total', 'invoicing' ); ?></strong></td> |
|
| 1179 | - <td class="total"><strong><?php _e( wpinv_subtotal( $invoice_id, true ) ) ?></strong></td> |
|
| 1178 | + <td class="rate"><strong><?php _e('Sub Total', 'invoicing'); ?></strong></td> |
|
| 1179 | + <td class="total"><strong><?php _e(wpinv_subtotal($invoice_id, true)) ?></strong></td> |
|
| 1180 | 1180 | </tr> |
| 1181 | - <?php do_action( 'wpinv_after_display_totals' ); ?> |
|
| 1182 | - <?php if ( wpinv_discount( $invoice_id, false ) > 0 ) { ?> |
|
| 1181 | + <?php do_action('wpinv_after_display_totals'); ?> |
|
| 1182 | + <?php if (wpinv_discount($invoice_id, false) > 0) { ?> |
|
| 1183 | 1183 | <tr class="row-discount"> |
| 1184 | - <td class="rate"><?php wpinv_get_discount_label( wpinv_discount_code( $invoice_id ) ); ?></td> |
|
| 1185 | - <td class="total"><?php echo wpinv_discount( $invoice_id, true, true ); ?></td> |
|
| 1184 | + <td class="rate"><?php wpinv_get_discount_label(wpinv_discount_code($invoice_id)); ?></td> |
|
| 1185 | + <td class="total"><?php echo wpinv_discount($invoice_id, true, true); ?></td> |
|
| 1186 | 1186 | </tr> |
| 1187 | - <?php do_action( 'wpinv_after_display_discount' ); ?> |
|
| 1187 | + <?php do_action('wpinv_after_display_discount'); ?> |
|
| 1188 | 1188 | <?php } ?> |
| 1189 | - <?php if ( $use_taxes ) { ?> |
|
| 1189 | + <?php if ($use_taxes) { ?> |
|
| 1190 | 1190 | <tr class="row-tax"> |
| 1191 | - <td class="rate"><?php _e( 'Tax', 'invoicing' ); ?></td> |
|
| 1192 | - <td class="total"><?php _e( wpinv_tax( $invoice_id, true ) ) ?></td> |
|
| 1191 | + <td class="rate"><?php _e('Tax', 'invoicing'); ?></td> |
|
| 1192 | + <td class="total"><?php _e(wpinv_tax($invoice_id, true)) ?></td> |
|
| 1193 | 1193 | </tr> |
| 1194 | - <?php do_action( 'wpinv_after_display_tax' ); ?> |
|
| 1194 | + <?php do_action('wpinv_after_display_tax'); ?> |
|
| 1195 | 1195 | <?php } ?> |
| 1196 | - <?php if ( $fees = wpinv_get_fees( $invoice_id ) ) { ?> |
|
| 1197 | - <?php foreach ( $fees as $fee ) { ?> |
|
| 1196 | + <?php if ($fees = wpinv_get_fees($invoice_id)) { ?> |
|
| 1197 | + <?php foreach ($fees as $fee) { ?> |
|
| 1198 | 1198 | <tr class="row-fee"> |
| 1199 | 1199 | <td class="rate"><?php echo $fee['label']; ?></td> |
| 1200 | 1200 | <td class="total"><?php echo $fee['amount_display']; ?></td> |
@@ -1202,72 +1202,72 @@ discard block |
||
| 1202 | 1202 | <?php } ?> |
| 1203 | 1203 | <?php } ?> |
| 1204 | 1204 | <tr class="table-active row-total"> |
| 1205 | - <td class="rate"><strong><?php _e( 'Total', 'invoicing' ) ?></strong></td> |
|
| 1206 | - <td class="total"><strong><?php _e( wpinv_payment_total( $invoice_id, true ) ) ?></strong></td> |
|
| 1205 | + <td class="rate"><strong><?php _e('Total', 'invoicing') ?></strong></td> |
|
| 1206 | + <td class="total"><strong><?php _e(wpinv_payment_total($invoice_id, true)) ?></strong></td> |
|
| 1207 | 1207 | </tr> |
| 1208 | - <?php do_action( 'wpinv_after_totals' ); ?> |
|
| 1208 | + <?php do_action('wpinv_after_totals'); ?> |
|
| 1209 | 1209 | </tbody> |
| 1210 | 1210 | |
| 1211 | 1211 | </table> |
| 1212 | 1212 | |
| 1213 | - <?php do_action( 'wpinv_after_totals_table' ); |
|
| 1213 | + <?php do_action('wpinv_after_totals_table'); |
|
| 1214 | 1214 | } |
| 1215 | 1215 | |
| 1216 | -function wpinv_display_payments_info( $invoice_id = 0, $echo = true ) { |
|
| 1217 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
| 1216 | +function wpinv_display_payments_info($invoice_id = 0, $echo = true) { |
|
| 1217 | + $invoice = wpinv_get_invoice($invoice_id); |
|
| 1218 | 1218 | |
| 1219 | 1219 | ob_start(); |
| 1220 | - do_action( 'wpinv_before_display_payments_info', $invoice_id ); |
|
| 1221 | - if ( ( $gateway_title = $invoice->get_gateway_title() ) || $invoice->is_paid() ) { |
|
| 1220 | + do_action('wpinv_before_display_payments_info', $invoice_id); |
|
| 1221 | + if (($gateway_title = $invoice->get_gateway_title()) || $invoice->is_paid()) { |
|
| 1222 | 1222 | ?> |
| 1223 | 1223 | <div class="wpi-payment-info"> |
| 1224 | - <p class="wpi-payment-gateway"><?php echo wp_sprintf( __( 'Payment via %s', 'invoicing' ), $gateway_title ? $gateway_title : __( 'Manually', 'invoicing' ) ); ?></p> |
|
| 1225 | - <?php if ( $gateway_title ) { ?> |
|
| 1226 | - <p class="wpi-payment-transid"><?php echo wp_sprintf( __( 'Transaction ID: %s', 'invoicing' ), $invoice->get_transaction_id() ); ?></p> |
|
| 1224 | + <p class="wpi-payment-gateway"><?php echo wp_sprintf(__('Payment via %s', 'invoicing'), $gateway_title ? $gateway_title : __('Manually', 'invoicing')); ?></p> |
|
| 1225 | + <?php if ($gateway_title) { ?> |
|
| 1226 | + <p class="wpi-payment-transid"><?php echo wp_sprintf(__('Transaction ID: %s', 'invoicing'), $invoice->get_transaction_id()); ?></p> |
|
| 1227 | 1227 | <?php } ?> |
| 1228 | 1228 | </div> |
| 1229 | 1229 | <?php |
| 1230 | 1230 | } |
| 1231 | - do_action( 'wpinv_after_display_payments_info', $invoice_id ); |
|
| 1231 | + do_action('wpinv_after_display_payments_info', $invoice_id); |
|
| 1232 | 1232 | $outout = ob_get_clean(); |
| 1233 | 1233 | |
| 1234 | - if ( $echo ) { |
|
| 1234 | + if ($echo) { |
|
| 1235 | 1235 | echo $outout; |
| 1236 | 1236 | } else { |
| 1237 | 1237 | return $outout; |
| 1238 | 1238 | } |
| 1239 | 1239 | } |
| 1240 | 1240 | |
| 1241 | -function wpinv_display_style( $invoice ) { |
|
| 1242 | - wp_register_style( 'wpinv-single-style', WPINV_PLUGIN_URL . 'assets/css/invoice.css', array(), WPINV_VERSION ); |
|
| 1241 | +function wpinv_display_style($invoice) { |
|
| 1242 | + wp_register_style('wpinv-single-style', WPINV_PLUGIN_URL . 'assets/css/invoice.css', array(), WPINV_VERSION); |
|
| 1243 | 1243 | |
| 1244 | - wp_print_styles( 'open-sans' ); |
|
| 1245 | - wp_print_styles( 'wpinv-single-style' ); |
|
| 1244 | + wp_print_styles('open-sans'); |
|
| 1245 | + wp_print_styles('wpinv-single-style'); |
|
| 1246 | 1246 | } |
| 1247 | -add_action( 'wpinv_invoice_print_head', 'wpinv_display_style' ); |
|
| 1247 | +add_action('wpinv_invoice_print_head', 'wpinv_display_style'); |
|
| 1248 | 1248 | |
| 1249 | 1249 | function wpinv_checkout_billing_details() { |
| 1250 | 1250 | $invoice_id = (int)wpinv_get_invoice_cart_id(); |
| 1251 | 1251 | if (empty($invoice_id)) { |
| 1252 | - wpinv_error_log( 'Invoice id not found', 'ERROR', __FILE__, __LINE__ ); |
|
| 1252 | + wpinv_error_log('Invoice id not found', 'ERROR', __FILE__, __LINE__); |
|
| 1253 | 1253 | return null; |
| 1254 | 1254 | } |
| 1255 | 1255 | |
| 1256 | - $invoice = wpinv_get_invoice_cart( $invoice_id ); |
|
| 1256 | + $invoice = wpinv_get_invoice_cart($invoice_id); |
|
| 1257 | 1257 | if (empty($invoice)) { |
| 1258 | - wpinv_error_log( 'Invoice not found', 'ERROR', __FILE__, __LINE__ ); |
|
| 1258 | + wpinv_error_log('Invoice not found', 'ERROR', __FILE__, __LINE__); |
|
| 1259 | 1259 | return null; |
| 1260 | 1260 | } |
| 1261 | 1261 | $user_id = $invoice->get_user_id(); |
| 1262 | 1262 | $user_info = $invoice->get_user_info(); |
| 1263 | - $address_info = wpinv_get_user_address( $user_id ); |
|
| 1263 | + $address_info = wpinv_get_user_address($user_id); |
|
| 1264 | 1264 | |
| 1265 | - if ( empty( $user_info['first_name'] ) && !empty( $user_info['first_name'] ) ) { |
|
| 1265 | + if (empty($user_info['first_name']) && !empty($user_info['first_name'])) { |
|
| 1266 | 1266 | $user_info['first_name'] = $user_info['first_name']; |
| 1267 | 1267 | $user_info['last_name'] = $user_info['last_name']; |
| 1268 | 1268 | } |
| 1269 | 1269 | |
| 1270 | - if ( ( ( empty( $user_info['country'] ) && !empty( $address_info['country'] ) ) || ( empty( $user_info['state'] ) && !empty( $address_info['state'] ) && $user_info['country'] == $address_info['country'] ) ) ) { |
|
| 1270 | + if (((empty($user_info['country']) && !empty($address_info['country'])) || (empty($user_info['state']) && !empty($address_info['state']) && $user_info['country'] == $address_info['country']))) { |
|
| 1271 | 1271 | $user_info['country'] = $address_info['country']; |
| 1272 | 1272 | $user_info['state'] = $address_info['state']; |
| 1273 | 1273 | $user_info['city'] = $address_info['city']; |
@@ -1283,103 +1283,103 @@ discard block |
||
| 1283 | 1283 | 'address' |
| 1284 | 1284 | ); |
| 1285 | 1285 | |
| 1286 | - foreach ( $address_fields as $field ) { |
|
| 1287 | - if ( empty( $user_info[$field] ) ) { |
|
| 1286 | + foreach ($address_fields as $field) { |
|
| 1287 | + if (empty($user_info[$field])) { |
|
| 1288 | 1288 | $user_info[$field] = $address_info[$field]; |
| 1289 | 1289 | } |
| 1290 | 1290 | } |
| 1291 | 1291 | |
| 1292 | - return apply_filters( 'wpinv_checkout_billing_details', $user_info, $invoice ); |
|
| 1292 | + return apply_filters('wpinv_checkout_billing_details', $user_info, $invoice); |
|
| 1293 | 1293 | } |
| 1294 | 1294 | |
| 1295 | 1295 | function wpinv_admin_get_line_items($invoice = array()) { |
| 1296 | 1296 | $item_quantities = wpinv_item_quantities_enabled(); |
| 1297 | 1297 | $use_taxes = wpinv_use_taxes(); |
| 1298 | 1298 | |
| 1299 | - if ( empty( $invoice ) ) { |
|
| 1299 | + if (empty($invoice)) { |
|
| 1300 | 1300 | return NULL; |
| 1301 | 1301 | } |
| 1302 | 1302 | |
| 1303 | 1303 | $cart_items = $invoice->get_cart_details(); |
| 1304 | - if ( empty( $cart_items ) ) { |
|
| 1304 | + if (empty($cart_items)) { |
|
| 1305 | 1305 | return NULL; |
| 1306 | 1306 | } |
| 1307 | 1307 | ob_start(); |
| 1308 | 1308 | |
| 1309 | - do_action( 'wpinv_admin_before_line_items', $cart_items, $invoice ); |
|
| 1309 | + do_action('wpinv_admin_before_line_items', $cart_items, $invoice); |
|
| 1310 | 1310 | |
| 1311 | 1311 | $count = 0; |
| 1312 | - foreach ( $cart_items as $key => $cart_item ) { |
|
| 1312 | + foreach ($cart_items as $key => $cart_item) { |
|
| 1313 | 1313 | $item_id = $cart_item['id']; |
| 1314 | - $wpi_item = $item_id > 0 ? new WPInv_Item( $item_id ) : NULL; |
|
| 1314 | + $wpi_item = $item_id > 0 ? new WPInv_Item($item_id) : NULL; |
|
| 1315 | 1315 | |
| 1316 | 1316 | if (empty($wpi_item)) { |
| 1317 | 1317 | continue; |
| 1318 | 1318 | } |
| 1319 | 1319 | |
| 1320 | - $item_price = wpinv_price( wpinv_format_amount( $cart_item['item_price'] ) ); |
|
| 1321 | - $quantity = !empty( $cart_item['quantity'] ) && $cart_item['quantity'] > 0 ? $cart_item['quantity'] : 1; |
|
| 1322 | - $item_subtotal = wpinv_price( wpinv_format_amount( $cart_item['subtotal'] ) ); |
|
| 1320 | + $item_price = wpinv_price(wpinv_format_amount($cart_item['item_price'])); |
|
| 1321 | + $quantity = !empty($cart_item['quantity']) && $cart_item['quantity'] > 0 ? $cart_item['quantity'] : 1; |
|
| 1322 | + $item_subtotal = wpinv_price(wpinv_format_amount($cart_item['subtotal'])); |
|
| 1323 | 1323 | $can_remove = true; |
| 1324 | 1324 | |
| 1325 | 1325 | $summary = ''; |
| 1326 | 1326 | if ($wpi_item->is_package() && !empty($cart_item['meta']['post_id'])) { |
| 1327 | - $post_link = '<a href="' . get_edit_post_link( $cart_item['meta']['post_id'] ) .'" target="_blank">' . (!empty($cart_item['meta']['invoice_title']) ? $cart_item['meta']['invoice_title'] : get_the_title( $cart_item['meta']['post_id']) ) . '</a>'; |
|
| 1328 | - $summary = wp_sprintf( __( '%s: %s', 'invoicing' ), $wpi_item->get_custom_singular_name(), $post_link ); |
|
| 1327 | + $post_link = '<a href="' . get_edit_post_link($cart_item['meta']['post_id']) . '" target="_blank">' . (!empty($cart_item['meta']['invoice_title']) ? $cart_item['meta']['invoice_title'] : get_the_title($cart_item['meta']['post_id'])) . '</a>'; |
|
| 1328 | + $summary = wp_sprintf(__('%s: %s', 'invoicing'), $wpi_item->get_custom_singular_name(), $post_link); |
|
| 1329 | 1329 | } |
| 1330 | - $summary = apply_filters( 'wpinv_admin_invoice_line_item_summary', $summary, $cart_item, $wpi_item, $invoice ); |
|
| 1330 | + $summary = apply_filters('wpinv_admin_invoice_line_item_summary', $summary, $cart_item, $wpi_item, $invoice); |
|
| 1331 | 1331 | |
| 1332 | 1332 | $item_tax = ''; |
| 1333 | 1333 | $tax_rate = ''; |
| 1334 | - if ( $cart_item['tax'] > 0 && $cart_item['subtotal'] > 0 ) { |
|
| 1335 | - $item_tax = wpinv_price( wpinv_format_amount( $cart_item['tax'] ) ); |
|
| 1336 | - $tax_rate = !empty( $cart_item['vat_rate'] ) ? $cart_item['vat_rate'] : ( $cart_item['tax'] / $cart_item['subtotal'] ) * 100; |
|
| 1337 | - $tax_rate = $tax_rate > 0 ? (float)wpinv_round_amount( $tax_rate, 4 ) : ''; |
|
| 1334 | + if ($cart_item['tax'] > 0 && $cart_item['subtotal'] > 0) { |
|
| 1335 | + $item_tax = wpinv_price(wpinv_format_amount($cart_item['tax'])); |
|
| 1336 | + $tax_rate = !empty($cart_item['vat_rate']) ? $cart_item['vat_rate'] : ($cart_item['tax'] / $cart_item['subtotal']) * 100; |
|
| 1337 | + $tax_rate = $tax_rate > 0 ? (float)wpinv_round_amount($tax_rate, 4) : ''; |
|
| 1338 | 1338 | $tax_rate = $tax_rate != '' ? ' <span class="tax-rate">(' . $tax_rate . '%)</span>' : ''; |
| 1339 | 1339 | } |
| 1340 | 1340 | $line_item_tax = $item_tax . $tax_rate; |
| 1341 | 1341 | |
| 1342 | - if ( $line_item_tax === '' ) { |
|
| 1342 | + if ($line_item_tax === '') { |
|
| 1343 | 1343 | $line_item_tax = 0; // Zero tax |
| 1344 | 1344 | } |
| 1345 | 1345 | |
| 1346 | - $line_item = '<tr class="item item-' . ( ($count % 2 == 0) ? 'even' : 'odd' ) . '" data-item-id="' . $item_id . '">'; |
|
| 1346 | + $line_item = '<tr class="item item-' . (($count % 2 == 0) ? 'even' : 'odd') . '" data-item-id="' . $item_id . '">'; |
|
| 1347 | 1347 | $line_item .= '<td class="id">' . $item_id . '</td>'; |
| 1348 | - $line_item .= '<td class="title"><a href="' . get_edit_post_link( $item_id ) . '" target="_blank">' . $cart_item['name'] . '</a>' . wpinv_get_item_suffix( $wpi_item ); |
|
| 1349 | - if ( $summary !== '' ) { |
|
| 1350 | - $line_item .= '<span class="meta">' . wpautop( wp_kses_post( $summary ) ) . '</span>'; |
|
| 1348 | + $line_item .= '<td class="title"><a href="' . get_edit_post_link($item_id) . '" target="_blank">' . $cart_item['name'] . '</a>' . wpinv_get_item_suffix($wpi_item); |
|
| 1349 | + if ($summary !== '') { |
|
| 1350 | + $line_item .= '<span class="meta">' . wpautop(wp_kses_post($summary)) . '</span>'; |
|
| 1351 | 1351 | } |
| 1352 | 1352 | $line_item .= '</td>'; |
| 1353 | 1353 | $line_item .= '<td class="price">' . $item_price . '</td>'; |
| 1354 | 1354 | |
| 1355 | - if ( $item_quantities ) { |
|
| 1356 | - if ( count( $cart_items ) == 1 && $quantity <= 1 ) { |
|
| 1355 | + if ($item_quantities) { |
|
| 1356 | + if (count($cart_items) == 1 && $quantity <= 1) { |
|
| 1357 | 1357 | $can_remove = false; |
| 1358 | 1358 | } |
| 1359 | 1359 | $line_item .= '<td class="qty" data-quantity="' . $quantity . '"> × ' . $quantity . '</td>'; |
| 1360 | 1360 | } else { |
| 1361 | - if ( count( $cart_items ) == 1 ) { |
|
| 1361 | + if (count($cart_items) == 1) { |
|
| 1362 | 1362 | $can_remove = false; |
| 1363 | 1363 | } |
| 1364 | 1364 | } |
| 1365 | 1365 | $line_item .= '<td class="total">' . $item_subtotal . '</td>'; |
| 1366 | 1366 | |
| 1367 | - if ( $use_taxes ) { |
|
| 1367 | + if ($use_taxes) { |
|
| 1368 | 1368 | $line_item .= '<td class="tax">' . $line_item_tax . '</td>'; |
| 1369 | 1369 | } |
| 1370 | 1370 | $line_item .= '<td class="action">'; |
| 1371 | - if ( !$invoice->is_paid() && $can_remove ) { |
|
| 1371 | + if (!$invoice->is_paid() && $can_remove) { |
|
| 1372 | 1372 | $line_item .= '<i class="fa fa-remove wpinv-item-remove"></i>'; |
| 1373 | 1373 | } |
| 1374 | 1374 | $line_item .= '</td>'; |
| 1375 | 1375 | $line_item .= '</tr>'; |
| 1376 | 1376 | |
| 1377 | - echo apply_filters( 'wpinv_admin_line_item', $line_item, $cart_item, $invoice ); |
|
| 1377 | + echo apply_filters('wpinv_admin_line_item', $line_item, $cart_item, $invoice); |
|
| 1378 | 1378 | |
| 1379 | 1379 | $count++; |
| 1380 | 1380 | } |
| 1381 | 1381 | |
| 1382 | - do_action( 'wpinv_admin_after_line_items', $cart_items, $invoice ); |
|
| 1382 | + do_action('wpinv_admin_after_line_items', $cart_items, $invoice); |
|
| 1383 | 1383 | |
| 1384 | 1384 | return ob_get_clean(); |
| 1385 | 1385 | } |
@@ -1390,35 +1390,35 @@ discard block |
||
| 1390 | 1390 | // Set current invoice id. |
| 1391 | 1391 | $wpi_checkout_id = wpinv_get_invoice_cart_id(); |
| 1392 | 1392 | |
| 1393 | - $form_action = esc_url( wpinv_get_checkout_uri() ); |
|
| 1393 | + $form_action = esc_url(wpinv_get_checkout_uri()); |
|
| 1394 | 1394 | |
| 1395 | 1395 | ob_start(); |
| 1396 | 1396 | echo '<div id="wpinv_checkout_wrap">'; |
| 1397 | 1397 | |
| 1398 | - if ( wpinv_get_cart_contents() || wpinv_cart_has_fees() ) { |
|
| 1398 | + if (wpinv_get_cart_contents() || wpinv_cart_has_fees()) { |
|
| 1399 | 1399 | ?> |
| 1400 | 1400 | <div id="wpinv_checkout_form_wrap" class="wpinv_clearfix table-responsive"> |
| 1401 | - <?php do_action( 'wpinv_before_checkout_form' ); ?> |
|
| 1401 | + <?php do_action('wpinv_before_checkout_form'); ?> |
|
| 1402 | 1402 | <form id="wpinv_checkout_form" class="wpi-form" action="<?php echo $form_action; ?>" method="POST"> |
| 1403 | 1403 | <?php |
| 1404 | - do_action( 'wpinv_checkout_form_top' ); |
|
| 1405 | - do_action( 'wpinv_checkout_billing_info' ); |
|
| 1406 | - do_action( 'wpinv_checkout_cart' ); |
|
| 1407 | - do_action( 'wpinv_payment_mode_select' ); |
|
| 1408 | - do_action( 'wpinv_checkout_form_bottom' ) |
|
| 1404 | + do_action('wpinv_checkout_form_top'); |
|
| 1405 | + do_action('wpinv_checkout_billing_info'); |
|
| 1406 | + do_action('wpinv_checkout_cart'); |
|
| 1407 | + do_action('wpinv_payment_mode_select'); |
|
| 1408 | + do_action('wpinv_checkout_form_bottom') |
|
| 1409 | 1409 | ?> |
| 1410 | 1410 | </form> |
| 1411 | - <?php do_action( 'wpinv_after_purchase_form' ); ?> |
|
| 1411 | + <?php do_action('wpinv_after_purchase_form'); ?> |
|
| 1412 | 1412 | </div><!--end #wpinv_checkout_form_wrap--> |
| 1413 | 1413 | <?php |
| 1414 | 1414 | } else { |
| 1415 | - do_action( 'wpinv_cart_empty' ); |
|
| 1415 | + do_action('wpinv_cart_empty'); |
|
| 1416 | 1416 | } |
| 1417 | 1417 | echo '</div><!--end #wpinv_checkout_wrap-->'; |
| 1418 | 1418 | return ob_get_clean(); |
| 1419 | 1419 | } |
| 1420 | 1420 | |
| 1421 | -function wpinv_checkout_cart( $cart_details = array(), $echo = true ) { |
|
| 1421 | +function wpinv_checkout_cart($cart_details = array(), $echo = true) { |
|
| 1422 | 1422 | global $ajax_cart_details; |
| 1423 | 1423 | $ajax_cart_details = $cart_details; |
| 1424 | 1424 | /* |
@@ -1433,25 +1433,25 @@ discard block |
||
| 1433 | 1433 | } |
| 1434 | 1434 | */ |
| 1435 | 1435 | ob_start(); |
| 1436 | - do_action( 'wpinv_before_checkout_cart' ); |
|
| 1436 | + do_action('wpinv_before_checkout_cart'); |
|
| 1437 | 1437 | echo '<div id="wpinv_checkout_cart_form" method="post">'; |
| 1438 | 1438 | echo '<div id="wpinv_checkout_cart_wrap">'; |
| 1439 | - wpinv_get_template_part( 'wpinv-checkout-cart' ); |
|
| 1439 | + wpinv_get_template_part('wpinv-checkout-cart'); |
|
| 1440 | 1440 | echo '</div>'; |
| 1441 | 1441 | echo '</div>'; |
| 1442 | - do_action( 'wpinv_after_checkout_cart' ); |
|
| 1442 | + do_action('wpinv_after_checkout_cart'); |
|
| 1443 | 1443 | $content = ob_get_clean(); |
| 1444 | 1444 | |
| 1445 | - if ( $echo ) { |
|
| 1445 | + if ($echo) { |
|
| 1446 | 1446 | echo $content; |
| 1447 | 1447 | } else { |
| 1448 | 1448 | return $content; |
| 1449 | 1449 | } |
| 1450 | 1450 | } |
| 1451 | -add_action( 'wpinv_checkout_cart', 'wpinv_checkout_cart', 10 ); |
|
| 1451 | +add_action('wpinv_checkout_cart', 'wpinv_checkout_cart', 10); |
|
| 1452 | 1452 | |
| 1453 | 1453 | function wpinv_empty_cart_message() { |
| 1454 | - return apply_filters( 'wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __( 'Your cart is empty.', 'invoicing' ) . '</span>' ); |
|
| 1454 | + return apply_filters('wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __('Your cart is empty.', 'invoicing') . '</span>'); |
|
| 1455 | 1455 | } |
| 1456 | 1456 | |
| 1457 | 1457 | /** |
@@ -1463,91 +1463,91 @@ discard block |
||
| 1463 | 1463 | function wpinv_empty_checkout_cart() { |
| 1464 | 1464 | echo wpinv_empty_cart_message(); |
| 1465 | 1465 | } |
| 1466 | -add_action( 'wpinv_cart_empty', 'wpinv_empty_checkout_cart' ); |
|
| 1466 | +add_action('wpinv_cart_empty', 'wpinv_empty_checkout_cart'); |
|
| 1467 | 1467 | |
| 1468 | 1468 | function wpinv_save_cart_button() { |
| 1469 | - if ( wpinv_is_cart_saving_disabled() ) |
|
| 1469 | + if (wpinv_is_cart_saving_disabled()) |
|
| 1470 | 1470 | return; |
| 1471 | 1471 | ?> |
| 1472 | - <a class="wpinv-cart-saving-button wpinv-submit button" id="wpinv-save-cart-button" href="<?php echo esc_url( add_query_arg( 'wpi_action', 'save_cart' ) ); ?>"><?php _e( 'Save Cart', 'invoicing' ); ?></a> |
|
| 1472 | + <a class="wpinv-cart-saving-button wpinv-submit button" id="wpinv-save-cart-button" href="<?php echo esc_url(add_query_arg('wpi_action', 'save_cart')); ?>"><?php _e('Save Cart', 'invoicing'); ?></a> |
|
| 1473 | 1473 | <?php |
| 1474 | 1474 | } |
| 1475 | 1475 | |
| 1476 | 1476 | function wpinv_update_cart_button() { |
| 1477 | - if ( !wpinv_item_quantities_enabled() ) |
|
| 1477 | + if (!wpinv_item_quantities_enabled()) |
|
| 1478 | 1478 | return; |
| 1479 | 1479 | ?> |
| 1480 | - <input type="submit" name="wpinv_update_cart_submit" class="wpinv-submit wpinv-no-js button" value="<?php _e( 'Update Cart', 'invoicing' ); ?>"/> |
|
| 1480 | + <input type="submit" name="wpinv_update_cart_submit" class="wpinv-submit wpinv-no-js button" value="<?php _e('Update Cart', 'invoicing'); ?>"/> |
|
| 1481 | 1481 | <input type="hidden" name="wpi_action" value="update_cart"/> |
| 1482 | 1482 | <?php |
| 1483 | 1483 | } |
| 1484 | 1484 | |
| 1485 | 1485 | function wpinv_checkout_cart_columns() { |
| 1486 | 1486 | $default = 3; |
| 1487 | - if ( wpinv_item_quantities_enabled() ) { |
|
| 1487 | + if (wpinv_item_quantities_enabled()) { |
|
| 1488 | 1488 | $default++; |
| 1489 | 1489 | } |
| 1490 | 1490 | |
| 1491 | - if ( wpinv_use_taxes() ) { |
|
| 1491 | + if (wpinv_use_taxes()) { |
|
| 1492 | 1492 | $default++; |
| 1493 | 1493 | } |
| 1494 | 1494 | |
| 1495 | - return apply_filters( 'wpinv_checkout_cart_columns', $default ); |
|
| 1495 | + return apply_filters('wpinv_checkout_cart_columns', $default); |
|
| 1496 | 1496 | } |
| 1497 | 1497 | |
| 1498 | 1498 | function wpinv_display_cart_messages() { |
| 1499 | 1499 | global $wpi_session; |
| 1500 | 1500 | |
| 1501 | - $messages = $wpi_session->get( 'wpinv_cart_messages' ); |
|
| 1501 | + $messages = $wpi_session->get('wpinv_cart_messages'); |
|
| 1502 | 1502 | |
| 1503 | - if ( $messages ) { |
|
| 1504 | - foreach ( $messages as $message_id => $message ) { |
|
| 1503 | + if ($messages) { |
|
| 1504 | + foreach ($messages as $message_id => $message) { |
|
| 1505 | 1505 | // Try and detect what type of message this is |
| 1506 | - if ( strpos( strtolower( $message ), 'error' ) ) { |
|
| 1506 | + if (strpos(strtolower($message), 'error')) { |
|
| 1507 | 1507 | $type = 'error'; |
| 1508 | - } elseif ( strpos( strtolower( $message ), 'success' ) ) { |
|
| 1508 | + } elseif (strpos(strtolower($message), 'success')) { |
|
| 1509 | 1509 | $type = 'success'; |
| 1510 | 1510 | } else { |
| 1511 | 1511 | $type = 'info'; |
| 1512 | 1512 | } |
| 1513 | 1513 | |
| 1514 | - $classes = apply_filters( 'wpinv_' . $type . '_class', array( 'wpinv_errors', 'wpinv-alert', 'wpinv-alert-' . $type ) ); |
|
| 1514 | + $classes = apply_filters('wpinv_' . $type . '_class', array('wpinv_errors', 'wpinv-alert', 'wpinv-alert-' . $type)); |
|
| 1515 | 1515 | |
| 1516 | - echo '<div class="' . implode( ' ', $classes ) . '">'; |
|
| 1516 | + echo '<div class="' . implode(' ', $classes) . '">'; |
|
| 1517 | 1517 | // Loop message codes and display messages |
| 1518 | 1518 | echo '<p class="wpinv_error" id="wpinv_msg_' . $message_id . '">' . $message . '</p>'; |
| 1519 | 1519 | echo '</div>'; |
| 1520 | 1520 | } |
| 1521 | 1521 | |
| 1522 | 1522 | // Remove all of the cart saving messages |
| 1523 | - $wpi_session->set( 'wpinv_cart_messages', null ); |
|
| 1523 | + $wpi_session->set('wpinv_cart_messages', null); |
|
| 1524 | 1524 | } |
| 1525 | 1525 | } |
| 1526 | -add_action( 'wpinv_before_checkout_cart', 'wpinv_display_cart_messages' ); |
|
| 1526 | +add_action('wpinv_before_checkout_cart', 'wpinv_display_cart_messages'); |
|
| 1527 | 1527 | |
| 1528 | 1528 | function wpinv_discount_field() { |
| 1529 | - if ( isset( $_GET['wpi-gateway'] ) && wpinv_is_ajax_disabled() ) { |
|
| 1529 | + if (isset($_GET['wpi-gateway']) && wpinv_is_ajax_disabled()) { |
|
| 1530 | 1530 | return; // Only show before a payment method has been selected if ajax is disabled |
| 1531 | 1531 | } |
| 1532 | 1532 | |
| 1533 | - if ( !wpinv_is_checkout() ) { |
|
| 1533 | + if (!wpinv_is_checkout()) { |
|
| 1534 | 1534 | return; |
| 1535 | 1535 | } |
| 1536 | 1536 | |
| 1537 | - if ( wpinv_has_active_discounts() && wpinv_get_cart_total() ) { |
|
| 1537 | + if (wpinv_has_active_discounts() && wpinv_get_cart_total()) { |
|
| 1538 | 1538 | ?> |
| 1539 | 1539 | <div id="wpinv-discount-field" class="panel panel-default"> |
| 1540 | 1540 | <div class="panel-body"> |
| 1541 | 1541 | <p> |
| 1542 | - <label class="wpinv-label" for="wpinv_discount_code"><strong><?php _e( 'Discount', 'invoicing' ); ?></strong></label> |
|
| 1543 | - <span class="wpinv-description"><?php _e( 'Enter a discount code if you have one.', 'invoicing' ); ?></span> |
|
| 1542 | + <label class="wpinv-label" for="wpinv_discount_code"><strong><?php _e('Discount', 'invoicing'); ?></strong></label> |
|
| 1543 | + <span class="wpinv-description"><?php _e('Enter a discount code if you have one.', 'invoicing'); ?></span> |
|
| 1544 | 1544 | </p> |
| 1545 | 1545 | <div class="form-group row"> |
| 1546 | 1546 | <div class="col-sm-4"> |
| 1547 | - <input class="wpinv-input form-control" type="text" id="wpinv_discount_code" name="wpinv_discount_code" placeholder="<?php _e( 'Enter discount code', 'invoicing' ); ?>"/> |
|
| 1547 | + <input class="wpinv-input form-control" type="text" id="wpinv_discount_code" name="wpinv_discount_code" placeholder="<?php _e('Enter discount code', 'invoicing'); ?>"/> |
|
| 1548 | 1548 | </div> |
| 1549 | 1549 | <div class="col-sm-3"> |
| 1550 | - <button id="wpi-apply-discount" type="button" class="btn btn-success btn-sm"><?php _e( 'Apply Discount', 'invoicing' ); ?></button> |
|
| 1550 | + <button id="wpi-apply-discount" type="button" class="btn btn-success btn-sm"><?php _e('Apply Discount', 'invoicing'); ?></button> |
|
| 1551 | 1551 | </div> |
| 1552 | 1552 | <div style="clear:both"></div> |
| 1553 | 1553 | <div class="col-sm-12 wpinv-discount-msg"> |
@@ -1560,10 +1560,10 @@ discard block |
||
| 1560 | 1560 | <?php |
| 1561 | 1561 | } |
| 1562 | 1562 | } |
| 1563 | -add_action( 'wpinv_after_checkout_cart', 'wpinv_discount_field', -10 ); |
|
| 1563 | +add_action('wpinv_after_checkout_cart', 'wpinv_discount_field', -10); |
|
| 1564 | 1564 | |
| 1565 | 1565 | function wpinv_agree_to_terms_js() { |
| 1566 | - if ( wpinv_get_option( 'show_agree_to_terms', false ) ) { |
|
| 1566 | + if (wpinv_get_option('show_agree_to_terms', false)) { |
|
| 1567 | 1567 | ?> |
| 1568 | 1568 | <script type="text/javascript"> |
| 1569 | 1569 | jQuery(document).ready(function($){ |
@@ -1578,126 +1578,126 @@ discard block |
||
| 1578 | 1578 | <?php |
| 1579 | 1579 | } |
| 1580 | 1580 | } |
| 1581 | -add_action( 'wpinv_checkout_form_top', 'wpinv_agree_to_terms_js' ); |
|
| 1581 | +add_action('wpinv_checkout_form_top', 'wpinv_agree_to_terms_js'); |
|
| 1582 | 1582 | |
| 1583 | 1583 | function wpinv_payment_mode_select() { |
| 1584 | - $gateways = wpinv_get_enabled_payment_gateways( true ); |
|
| 1585 | - $gateways = apply_filters( 'wpinv_payment_gateways_on_cart', $gateways ); |
|
| 1584 | + $gateways = wpinv_get_enabled_payment_gateways(true); |
|
| 1585 | + $gateways = apply_filters('wpinv_payment_gateways_on_cart', $gateways); |
|
| 1586 | 1586 | $page_URL = wpinv_get_current_page_url(); |
| 1587 | - $invoice = wpinv_get_invoice( 0, true ); |
|
| 1587 | + $invoice = wpinv_get_invoice(0, true); |
|
| 1588 | 1588 | |
| 1589 | 1589 | do_action('wpinv_payment_mode_top'); |
| 1590 | 1590 | $invoice_id = (int)$invoice->ID; |
| 1591 | - $chosen_gateway = wpinv_get_chosen_gateway( $invoice_id ); |
|
| 1591 | + $chosen_gateway = wpinv_get_chosen_gateway($invoice_id); |
|
| 1592 | 1592 | ?> |
| 1593 | - <div id="wpinv_payment_mode_select" data-gateway="<?php echo $chosen_gateway; ?>" <?php echo ( $invoice->is_free() ? 'style="display:none;"' : '' ); ?>> |
|
| 1594 | - <?php do_action( 'wpinv_payment_mode_before_gateways_wrap' ); ?> |
|
| 1593 | + <div id="wpinv_payment_mode_select" data-gateway="<?php echo $chosen_gateway; ?>" <?php echo ($invoice->is_free() ? 'style="display:none;"' : ''); ?>> |
|
| 1594 | + <?php do_action('wpinv_payment_mode_before_gateways_wrap'); ?> |
|
| 1595 | 1595 | <div id="wpinv-payment-mode-wrap" class="panel panel-default"> |
| 1596 | - <div class="panel-heading"><h3 class="panel-title"><?php _e( 'Select Payment Method', 'invoicing' ); ?></h3></div> |
|
| 1596 | + <div class="panel-heading"><h3 class="panel-title"><?php _e('Select Payment Method', 'invoicing'); ?></h3></div> |
|
| 1597 | 1597 | <div class="panel-body list-group wpi-payment_methods"> |
| 1598 | 1598 | <?php |
| 1599 | - do_action( 'wpinv_payment_mode_before_gateways' ); |
|
| 1599 | + do_action('wpinv_payment_mode_before_gateways'); |
|
| 1600 | 1600 | |
| 1601 | - if(!empty($gateways)){ |
|
| 1602 | - foreach ( $gateways as $gateway_id => $gateway ) { |
|
| 1603 | - $checked = checked( $gateway_id, $chosen_gateway, false ); |
|
| 1604 | - $button_label = wpinv_get_gateway_button_label( $gateway_id ); |
|
| 1605 | - $description = wpinv_get_gateway_description( $gateway_id ); |
|
| 1601 | + if (!empty($gateways)) { |
|
| 1602 | + foreach ($gateways as $gateway_id => $gateway) { |
|
| 1603 | + $checked = checked($gateway_id, $chosen_gateway, false); |
|
| 1604 | + $button_label = wpinv_get_gateway_button_label($gateway_id); |
|
| 1605 | + $description = wpinv_get_gateway_description($gateway_id); |
|
| 1606 | 1606 | ?> |
| 1607 | 1607 | <div class="list-group-item"> |
| 1608 | 1608 | <div class="radio"> |
| 1609 | - <label><input type="radio" data-button-text="<?php echo esc_attr( $button_label );?>" value="<?php echo esc_attr( $gateway_id ) ;?>" <?php echo $checked ;?> id="wpi_gateway_<?php echo esc_attr( $gateway_id );?>" name="wpi-gateway" class="wpi-pmethod"><?php echo esc_html( $gateway['checkout_label'] ); ?></label> |
|
| 1609 | + <label><input type="radio" data-button-text="<?php echo esc_attr($button_label); ?>" value="<?php echo esc_attr($gateway_id); ?>" <?php echo $checked; ?> id="wpi_gateway_<?php echo esc_attr($gateway_id); ?>" name="wpi-gateway" class="wpi-pmethod"><?php echo esc_html($gateway['checkout_label']); ?></label> |
|
| 1610 | 1610 | </div> |
| 1611 | - <div style="display:none;" class="payment_box wpi_gateway_<?php echo esc_attr( $gateway_id );?>" role="alert"> |
|
| 1612 | - <?php if ( !empty( $description ) ) { ?> |
|
| 1613 | - <div class="wpi-gateway-desc alert alert-info"><?php echo $description;?></div> |
|
| 1611 | + <div style="display:none;" class="payment_box wpi_gateway_<?php echo esc_attr($gateway_id); ?>" role="alert"> |
|
| 1612 | + <?php if (!empty($description)) { ?> |
|
| 1613 | + <div class="wpi-gateway-desc alert alert-info"><?php echo $description; ?></div> |
|
| 1614 | 1614 | <?php } ?> |
| 1615 | - <?php do_action( 'wpinv_' . $gateway_id . '_cc_form', $invoice_id ) ;?> |
|
| 1615 | + <?php do_action('wpinv_' . $gateway_id . '_cc_form', $invoice_id); ?> |
|
| 1616 | 1616 | </div> |
| 1617 | 1617 | </div> |
| 1618 | 1618 | <?php |
| 1619 | 1619 | } |
| 1620 | - }else{ |
|
| 1621 | - echo '<div class="alert alert-warning">'. __('No payment gateway active','invoicing') .'</div>'; |
|
| 1620 | + } else { |
|
| 1621 | + echo '<div class="alert alert-warning">' . __('No payment gateway active', 'invoicing') . '</div>'; |
|
| 1622 | 1622 | } |
| 1623 | 1623 | |
| 1624 | - do_action( 'wpinv_payment_mode_after_gateways' ); |
|
| 1624 | + do_action('wpinv_payment_mode_after_gateways'); |
|
| 1625 | 1625 | ?> |
| 1626 | 1626 | </div> |
| 1627 | 1627 | </div> |
| 1628 | - <?php do_action( 'wpinv_payment_mode_after_gateways_wrap' ); ?> |
|
| 1628 | + <?php do_action('wpinv_payment_mode_after_gateways_wrap'); ?> |
|
| 1629 | 1629 | </div> |
| 1630 | 1630 | <?php |
| 1631 | 1631 | do_action('wpinv_payment_mode_bottom'); |
| 1632 | 1632 | } |
| 1633 | -add_action( 'wpinv_payment_mode_select', 'wpinv_payment_mode_select' ); |
|
| 1633 | +add_action('wpinv_payment_mode_select', 'wpinv_payment_mode_select'); |
|
| 1634 | 1634 | |
| 1635 | 1635 | function wpinv_checkout_billing_info() { |
| 1636 | - if ( wpinv_is_checkout() ) { |
|
| 1636 | + if (wpinv_is_checkout()) { |
|
| 1637 | 1637 | $logged_in = is_user_logged_in(); |
| 1638 | 1638 | $billing_details = wpinv_checkout_billing_details(); |
| 1639 | - $selected_country = !empty( $billing_details['country'] ) ? $billing_details['country'] : wpinv_default_billing_country(); |
|
| 1639 | + $selected_country = !empty($billing_details['country']) ? $billing_details['country'] : wpinv_default_billing_country(); |
|
| 1640 | 1640 | ?> |
| 1641 | 1641 | <div id="wpinv-fields" class="clearfix"> |
| 1642 | 1642 | <div id="wpi-billing" class="wpi-billing clearfix panel panel-default"> |
| 1643 | - <div class="panel-heading"><h3 class="panel-title"><?php _e( 'Billing Details', 'invoicing' );?></h3></div> |
|
| 1643 | + <div class="panel-heading"><h3 class="panel-title"><?php _e('Billing Details', 'invoicing'); ?></h3></div> |
|
| 1644 | 1644 | <div id="wpinv-fields-box" class="panel-body"> |
| 1645 | - <?php do_action( 'wpinv_checkout_billing_fields_first', $billing_details ); ?> |
|
| 1645 | + <?php do_action('wpinv_checkout_billing_fields_first', $billing_details); ?> |
|
| 1646 | 1646 | <p class="wpi-cart-field wpi-col2 wpi-colf"> |
| 1647 | - <label for="wpinv_first_name" class="wpi-label"><?php _e( 'First Name', 'invoicing' );?><?php if ( wpinv_get_option( 'fname_mandatory' ) ) { echo '<span class="wpi-required">*</span>'; } ?></label> |
|
| 1647 | + <label for="wpinv_first_name" class="wpi-label"><?php _e('First Name', 'invoicing'); ?><?php if (wpinv_get_option('fname_mandatory')) { echo '<span class="wpi-required">*</span>'; } ?></label> |
|
| 1648 | 1648 | <?php |
| 1649 | - echo wpinv_html_text( array( |
|
| 1649 | + echo wpinv_html_text(array( |
|
| 1650 | 1650 | 'id' => 'wpinv_first_name', |
| 1651 | 1651 | 'name' => 'wpinv_first_name', |
| 1652 | 1652 | 'value' => $billing_details['first_name'], |
| 1653 | 1653 | 'class' => 'wpi-input form-control required', |
| 1654 | - 'placeholder' => __( 'First name', 'invoicing' ), |
|
| 1655 | - 'required' => (bool)wpinv_get_option( 'fname_mandatory' ), |
|
| 1656 | - ) ); |
|
| 1654 | + 'placeholder' => __('First name', 'invoicing'), |
|
| 1655 | + 'required' => (bool)wpinv_get_option('fname_mandatory'), |
|
| 1656 | + )); |
|
| 1657 | 1657 | ?> |
| 1658 | 1658 | </p> |
| 1659 | 1659 | <p class="wpi-cart-field wpi-col2 wpi-coll"> |
| 1660 | - <label for="wpinv_last_name" class="wpi-label"><?php _e( 'Last Name', 'invoicing' );?><?php if ( wpinv_get_option( 'lname_mandatory' ) ) { echo '<span class="wpi-required">*</span>'; } ?></label> |
|
| 1660 | + <label for="wpinv_last_name" class="wpi-label"><?php _e('Last Name', 'invoicing'); ?><?php if (wpinv_get_option('lname_mandatory')) { echo '<span class="wpi-required">*</span>'; } ?></label> |
|
| 1661 | 1661 | <?php |
| 1662 | - echo wpinv_html_text( array( |
|
| 1662 | + echo wpinv_html_text(array( |
|
| 1663 | 1663 | 'id' => 'wpinv_last_name', |
| 1664 | 1664 | 'name' => 'wpinv_last_name', |
| 1665 | 1665 | 'value' => $billing_details['last_name'], |
| 1666 | 1666 | 'class' => 'wpi-input form-control', |
| 1667 | - 'placeholder' => __( 'Last name', 'invoicing' ), |
|
| 1668 | - 'required' => (bool)wpinv_get_option( 'lname_mandatory' ), |
|
| 1669 | - ) ); |
|
| 1667 | + 'placeholder' => __('Last name', 'invoicing'), |
|
| 1668 | + 'required' => (bool)wpinv_get_option('lname_mandatory'), |
|
| 1669 | + )); |
|
| 1670 | 1670 | ?> |
| 1671 | 1671 | </p> |
| 1672 | 1672 | <p class="wpi-cart-field wpi-col2 wpi-colf"> |
| 1673 | - <label for="wpinv_address" class="wpi-label"><?php _e( 'Address', 'invoicing' );?><?php if ( wpinv_get_option( 'address_mandatory' ) ) { echo '<span class="wpi-required">*</span>'; } ?></label> |
|
| 1673 | + <label for="wpinv_address" class="wpi-label"><?php _e('Address', 'invoicing'); ?><?php if (wpinv_get_option('address_mandatory')) { echo '<span class="wpi-required">*</span>'; } ?></label> |
|
| 1674 | 1674 | <?php |
| 1675 | - echo wpinv_html_text( array( |
|
| 1675 | + echo wpinv_html_text(array( |
|
| 1676 | 1676 | 'id' => 'wpinv_address', |
| 1677 | 1677 | 'name' => 'wpinv_address', |
| 1678 | 1678 | 'value' => $billing_details['address'], |
| 1679 | 1679 | 'class' => 'wpi-input form-control required', |
| 1680 | - 'placeholder' => __( 'Address', 'invoicing' ), |
|
| 1681 | - 'required' => (bool)wpinv_get_option( 'address_mandatory' ), |
|
| 1682 | - ) ); |
|
| 1680 | + 'placeholder' => __('Address', 'invoicing'), |
|
| 1681 | + 'required' => (bool)wpinv_get_option('address_mandatory'), |
|
| 1682 | + )); |
|
| 1683 | 1683 | ?> |
| 1684 | 1684 | </p> |
| 1685 | 1685 | <p class="wpi-cart-field wpi-col2 wpi-coll"> |
| 1686 | - <label for="wpinv_city" class="wpi-label"><?php _e( 'City', 'invoicing' );?><?php if ( wpinv_get_option( 'city_mandatory' ) ) { echo '<span class="wpi-required">*</span>'; } ?></label> |
|
| 1686 | + <label for="wpinv_city" class="wpi-label"><?php _e('City', 'invoicing'); ?><?php if (wpinv_get_option('city_mandatory')) { echo '<span class="wpi-required">*</span>'; } ?></label> |
|
| 1687 | 1687 | <?php |
| 1688 | - echo wpinv_html_text( array( |
|
| 1688 | + echo wpinv_html_text(array( |
|
| 1689 | 1689 | 'id' => 'wpinv_city', |
| 1690 | 1690 | 'name' => 'wpinv_city', |
| 1691 | 1691 | 'value' => $billing_details['city'], |
| 1692 | 1692 | 'class' => 'wpi-input form-control required', |
| 1693 | - 'placeholder' => __( 'City', 'invoicing' ), |
|
| 1694 | - 'required' => (bool)wpinv_get_option( 'city_mandatory' ), |
|
| 1695 | - ) ); |
|
| 1693 | + 'placeholder' => __('City', 'invoicing'), |
|
| 1694 | + 'required' => (bool)wpinv_get_option('city_mandatory'), |
|
| 1695 | + )); |
|
| 1696 | 1696 | ?> |
| 1697 | 1697 | </p> |
| 1698 | 1698 | <p id="wpinv_country_box" class="wpi-cart-field wpi-col2 wpi-colf"> |
| 1699 | - <label for="wpinv_country" class="wpi-label"><?php _e( 'Country', 'invoicing' );?><?php if ( wpinv_get_option( 'country_mandatory' ) ) { echo '<span class="wpi-required">*</span>'; } ?></label> |
|
| 1700 | - <?php echo wpinv_html_select( array( |
|
| 1699 | + <label for="wpinv_country" class="wpi-label"><?php _e('Country', 'invoicing'); ?><?php if (wpinv_get_option('country_mandatory')) { echo '<span class="wpi-required">*</span>'; } ?></label> |
|
| 1700 | + <?php echo wpinv_html_select(array( |
|
| 1701 | 1701 | 'options' => wpinv_get_country_list(), |
| 1702 | 1702 | 'name' => 'wpinv_country', |
| 1703 | 1703 | 'id' => 'wpinv_country', |
@@ -1705,16 +1705,16 @@ discard block |
||
| 1705 | 1705 | 'show_option_all' => false, |
| 1706 | 1706 | 'show_option_none' => false, |
| 1707 | 1707 | 'class' => 'wpi-input form-control required', |
| 1708 | - 'placeholder' => __( 'Choose a country', 'invoicing' ), |
|
| 1709 | - 'required' => (bool)wpinv_get_option( 'country_mandatory' ), |
|
| 1710 | - ) ); ?> |
|
| 1708 | + 'placeholder' => __('Choose a country', 'invoicing'), |
|
| 1709 | + 'required' => (bool)wpinv_get_option('country_mandatory'), |
|
| 1710 | + )); ?> |
|
| 1711 | 1711 | </p> |
| 1712 | 1712 | <p id="wpinv_state_box" class="wpi-cart-field wpi-col2 wpi-coll"> |
| 1713 | - <label for="wpinv_state" class="wpi-label"><?php _e( 'State / Province', 'invoicing' );?><?php if ( wpinv_get_option( 'state_mandatory' ) ) { echo '<span class="wpi-required">*</span>'; } ?></label> |
|
| 1713 | + <label for="wpinv_state" class="wpi-label"><?php _e('State / Province', 'invoicing'); ?><?php if (wpinv_get_option('state_mandatory')) { echo '<span class="wpi-required">*</span>'; } ?></label> |
|
| 1714 | 1714 | <?php |
| 1715 | - $states = wpinv_get_country_states( $selected_country ); |
|
| 1716 | - if( !empty( $states ) ) { |
|
| 1717 | - echo wpinv_html_select( array( |
|
| 1715 | + $states = wpinv_get_country_states($selected_country); |
|
| 1716 | + if (!empty($states)) { |
|
| 1717 | + echo wpinv_html_select(array( |
|
| 1718 | 1718 | 'options' => $states, |
| 1719 | 1719 | 'name' => 'wpinv_state', |
| 1720 | 1720 | 'id' => 'wpinv_state', |
@@ -1722,61 +1722,61 @@ discard block |
||
| 1722 | 1722 | 'show_option_all' => false, |
| 1723 | 1723 | 'show_option_none' => false, |
| 1724 | 1724 | 'class' => 'wpi-input form-control required', |
| 1725 | - 'placeholder' => __( 'Choose a state', 'invoicing' ), |
|
| 1726 | - 'required' => (bool)wpinv_get_option( 'state_mandatory' ), |
|
| 1727 | - ) ); |
|
| 1725 | + 'placeholder' => __('Choose a state', 'invoicing'), |
|
| 1726 | + 'required' => (bool)wpinv_get_option('state_mandatory'), |
|
| 1727 | + )); |
|
| 1728 | 1728 | } else { |
| 1729 | - echo wpinv_html_text( array( |
|
| 1729 | + echo wpinv_html_text(array( |
|
| 1730 | 1730 | 'name' => 'wpinv_state', |
| 1731 | 1731 | 'value' => $billing_details['state'], |
| 1732 | 1732 | 'id' => 'wpinv_state', |
| 1733 | 1733 | 'class' => 'wpi-input form-control required', |
| 1734 | - 'placeholder' => __( 'State / Province', 'invoicing' ), |
|
| 1735 | - 'required' => (bool)wpinv_get_option( 'state_mandatory' ), |
|
| 1736 | - ) ); |
|
| 1734 | + 'placeholder' => __('State / Province', 'invoicing'), |
|
| 1735 | + 'required' => (bool)wpinv_get_option('state_mandatory'), |
|
| 1736 | + )); |
|
| 1737 | 1737 | } |
| 1738 | 1738 | ?> |
| 1739 | 1739 | </p> |
| 1740 | 1740 | <p class="wpi-cart-field wpi-col2 wpi-colf"> |
| 1741 | - <label for="wpinv_zip" class="wpi-label"><?php _e( 'ZIP / Postcode', 'invoicing' );?><?php if ( wpinv_get_option( 'zip_mandatory' ) ) { echo '<span class="wpi-required">*</span>'; } ?></label> |
|
| 1741 | + <label for="wpinv_zip" class="wpi-label"><?php _e('ZIP / Postcode', 'invoicing'); ?><?php if (wpinv_get_option('zip_mandatory')) { echo '<span class="wpi-required">*</span>'; } ?></label> |
|
| 1742 | 1742 | <?php |
| 1743 | - echo wpinv_html_text( array( |
|
| 1743 | + echo wpinv_html_text(array( |
|
| 1744 | 1744 | 'name' => 'wpinv_zip', |
| 1745 | 1745 | 'value' => $billing_details['zip'], |
| 1746 | 1746 | 'id' => 'wpinv_zip', |
| 1747 | 1747 | 'class' => 'wpi-input form-control', |
| 1748 | - 'placeholder' => __( 'ZIP / Postcode', 'invoicing' ), |
|
| 1749 | - 'required' => (bool)wpinv_get_option( 'zip_mandatory' ), |
|
| 1750 | - ) ); |
|
| 1748 | + 'placeholder' => __('ZIP / Postcode', 'invoicing'), |
|
| 1749 | + 'required' => (bool)wpinv_get_option('zip_mandatory'), |
|
| 1750 | + )); |
|
| 1751 | 1751 | ?> |
| 1752 | 1752 | </p> |
| 1753 | 1753 | <p class="wpi-cart-field wpi-col2 wpi-coll"> |
| 1754 | - <label for="wpinv_phone" class="wpi-label"><?php _e( 'Phone', 'invoicing' );?><?php if ( wpinv_get_option( 'phone_mandatory' ) ) { echo '<span class="wpi-required">*</span>'; } ?></label> |
|
| 1754 | + <label for="wpinv_phone" class="wpi-label"><?php _e('Phone', 'invoicing'); ?><?php if (wpinv_get_option('phone_mandatory')) { echo '<span class="wpi-required">*</span>'; } ?></label> |
|
| 1755 | 1755 | <?php |
| 1756 | - echo wpinv_html_text( array( |
|
| 1756 | + echo wpinv_html_text(array( |
|
| 1757 | 1757 | 'id' => 'wpinv_phone', |
| 1758 | 1758 | 'name' => 'wpinv_phone', |
| 1759 | 1759 | 'value' => $billing_details['phone'], |
| 1760 | 1760 | 'class' => 'wpi-input form-control', |
| 1761 | - 'placeholder' => __( 'Phone', 'invoicing' ), |
|
| 1762 | - 'required' => (bool)wpinv_get_option( 'phone_mandatory' ), |
|
| 1763 | - ) ); |
|
| 1761 | + 'placeholder' => __('Phone', 'invoicing'), |
|
| 1762 | + 'required' => (bool)wpinv_get_option('phone_mandatory'), |
|
| 1763 | + )); |
|
| 1764 | 1764 | ?> |
| 1765 | 1765 | </p> |
| 1766 | - <?php do_action( 'wpinv_checkout_billing_fields_last', $billing_details ); ?> |
|
| 1766 | + <?php do_action('wpinv_checkout_billing_fields_last', $billing_details); ?> |
|
| 1767 | 1767 | <div class="clearfix"></div> |
| 1768 | 1768 | </div> |
| 1769 | 1769 | </div> |
| 1770 | - <?php do_action( 'wpinv_after_billing_fields', $billing_details ); ?> |
|
| 1770 | + <?php do_action('wpinv_after_billing_fields', $billing_details); ?> |
|
| 1771 | 1771 | </div> |
| 1772 | 1772 | <?php |
| 1773 | 1773 | } |
| 1774 | 1774 | } |
| 1775 | -add_action( 'wpinv_checkout_billing_info', 'wpinv_checkout_billing_info' ); |
|
| 1775 | +add_action('wpinv_checkout_billing_info', 'wpinv_checkout_billing_info'); |
|
| 1776 | 1776 | |
| 1777 | 1777 | function wpinv_checkout_hidden_fields() { |
| 1778 | 1778 | ?> |
| 1779 | - <?php if ( is_user_logged_in() ) { ?> |
|
| 1779 | + <?php if (is_user_logged_in()) { ?> |
|
| 1780 | 1780 | <input type="hidden" name="wpinv_user_id" value="<?php echo get_current_user_id(); ?>"/> |
| 1781 | 1781 | <?php } ?> |
| 1782 | 1782 | <input type="hidden" name="wpi_action" value="payment" /> |
@@ -1786,9 +1786,9 @@ discard block |
||
| 1786 | 1786 | function wpinv_checkout_button_purchase() { |
| 1787 | 1787 | ob_start(); |
| 1788 | 1788 | ?> |
| 1789 | - <input type="submit" class="btn btn-success wpinv-submit" id="wpinv-payment-button" data-value="<?php esc_attr_e( 'Proceed to Pay', 'invoicing' ) ?>" name="wpinv_payment" value="<?php esc_attr_e( 'Proceed to Pay', 'invoicing' ) ?>"/> |
|
| 1789 | + <input type="submit" class="btn btn-success wpinv-submit" id="wpinv-payment-button" data-value="<?php esc_attr_e('Proceed to Pay', 'invoicing') ?>" name="wpinv_payment" value="<?php esc_attr_e('Proceed to Pay', 'invoicing') ?>"/> |
|
| 1790 | 1790 | <?php |
| 1791 | - return apply_filters( 'wpinv_checkout_button_purchase', ob_get_clean() ); |
|
| 1791 | + return apply_filters('wpinv_checkout_button_purchase', ob_get_clean()); |
|
| 1792 | 1792 | } |
| 1793 | 1793 | |
| 1794 | 1794 | function wpinv_checkout_total() { |
@@ -1797,96 +1797,96 @@ discard block |
||
| 1797 | 1797 | <div id="wpinv_checkout_total" class="panel panel-info"> |
| 1798 | 1798 | <div class="panel-body"> |
| 1799 | 1799 | <?php |
| 1800 | - do_action( 'wpinv_purchase_form_before_checkout_total' ); |
|
| 1800 | + do_action('wpinv_purchase_form_before_checkout_total'); |
|
| 1801 | 1801 | ?> |
| 1802 | - <strong><?php _e( 'Invoice Total:', 'invoicing' ) ?></strong> <span class="wpinv-chdeckout-total"><?php echo $cart_total;?></span> |
|
| 1802 | + <strong><?php _e('Invoice Total:', 'invoicing') ?></strong> <span class="wpinv-chdeckout-total"><?php echo $cart_total; ?></span> |
|
| 1803 | 1803 | <?php |
| 1804 | - do_action( 'wpinv_purchase_form_after_checkout_total' ); |
|
| 1804 | + do_action('wpinv_purchase_form_after_checkout_total'); |
|
| 1805 | 1805 | ?> |
| 1806 | 1806 | </div> |
| 1807 | 1807 | </div> |
| 1808 | 1808 | <?php |
| 1809 | 1809 | } |
| 1810 | -add_action( 'wpinv_checkout_form_bottom', 'wpinv_checkout_total', 9998 ); |
|
| 1810 | +add_action('wpinv_checkout_form_bottom', 'wpinv_checkout_total', 9998); |
|
| 1811 | 1811 | |
| 1812 | 1812 | function wpinv_checkout_submit() { |
| 1813 | 1813 | ?> |
| 1814 | 1814 | <div id="wpinv_purchase_submit" class="panel panel-success"> |
| 1815 | 1815 | <div class="panel-body text-center"> |
| 1816 | 1816 | <?php |
| 1817 | - do_action( 'wpinv_purchase_form_before_submit' ); |
|
| 1817 | + do_action('wpinv_purchase_form_before_submit'); |
|
| 1818 | 1818 | wpinv_checkout_hidden_fields(); |
| 1819 | 1819 | echo wpinv_checkout_button_purchase(); |
| 1820 | - do_action( 'wpinv_purchase_form_after_submit' ); |
|
| 1820 | + do_action('wpinv_purchase_form_after_submit'); |
|
| 1821 | 1821 | ?> |
| 1822 | 1822 | </div> |
| 1823 | 1823 | </div> |
| 1824 | 1824 | <?php |
| 1825 | 1825 | } |
| 1826 | -add_action( 'wpinv_checkout_form_bottom', 'wpinv_checkout_submit', 9999 ); |
|
| 1826 | +add_action('wpinv_checkout_form_bottom', 'wpinv_checkout_submit', 9999); |
|
| 1827 | 1827 | |
| 1828 | -function wpinv_receipt_billing_address( $invoice_id = 0 ) { |
|
| 1829 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
| 1828 | +function wpinv_receipt_billing_address($invoice_id = 0) { |
|
| 1829 | + $invoice = wpinv_get_invoice($invoice_id); |
|
| 1830 | 1830 | |
| 1831 | - if ( empty( $invoice ) ) { |
|
| 1831 | + if (empty($invoice)) { |
|
| 1832 | 1832 | return NULL; |
| 1833 | 1833 | } |
| 1834 | 1834 | |
| 1835 | 1835 | $billing_details = $invoice->get_user_info(); |
| 1836 | 1836 | $address_row = ''; |
| 1837 | - if ( $address = $billing_details['address'] ) { |
|
| 1838 | - $address_row .= wpautop( wp_kses_post( $address ) ); |
|
| 1837 | + if ($address = $billing_details['address']) { |
|
| 1838 | + $address_row .= wpautop(wp_kses_post($address)); |
|
| 1839 | 1839 | } |
| 1840 | 1840 | |
| 1841 | 1841 | $address_fields = array(); |
| 1842 | - if ( !empty( $billing_details['city'] ) ) { |
|
| 1842 | + if (!empty($billing_details['city'])) { |
|
| 1843 | 1843 | $address_fields[] = $billing_details['city']; |
| 1844 | 1844 | } |
| 1845 | 1845 | |
| 1846 | - $billing_country = !empty( $billing_details['country'] ) ? $billing_details['country'] : ''; |
|
| 1847 | - if ( !empty( $billing_details['state'] ) ) { |
|
| 1848 | - $address_fields[] = wpinv_state_name( $billing_details['state'], $billing_country ); |
|
| 1846 | + $billing_country = !empty($billing_details['country']) ? $billing_details['country'] : ''; |
|
| 1847 | + if (!empty($billing_details['state'])) { |
|
| 1848 | + $address_fields[] = wpinv_state_name($billing_details['state'], $billing_country); |
|
| 1849 | 1849 | } |
| 1850 | 1850 | |
| 1851 | - if ( !empty( $billing_country ) ) { |
|
| 1852 | - $address_fields[] = wpinv_country_name( $billing_country ); |
|
| 1851 | + if (!empty($billing_country)) { |
|
| 1852 | + $address_fields[] = wpinv_country_name($billing_country); |
|
| 1853 | 1853 | } |
| 1854 | 1854 | |
| 1855 | - if ( !empty( $address_fields ) ) { |
|
| 1856 | - $address_fields = implode( ", ", $address_fields ); |
|
| 1855 | + if (!empty($address_fields)) { |
|
| 1856 | + $address_fields = implode(", ", $address_fields); |
|
| 1857 | 1857 | |
| 1858 | - if ( !empty( $billing_details['zip'] ) ) { |
|
| 1858 | + if (!empty($billing_details['zip'])) { |
|
| 1859 | 1859 | $address_fields .= ' ' . $billing_details['zip']; |
| 1860 | 1860 | } |
| 1861 | 1861 | |
| 1862 | - $address_row .= wpautop( wp_kses_post( $address_fields ) ); |
|
| 1862 | + $address_row .= wpautop(wp_kses_post($address_fields)); |
|
| 1863 | 1863 | } |
| 1864 | 1864 | ob_start(); |
| 1865 | 1865 | ?> |
| 1866 | 1866 | <table class="table table-bordered table-sm wpi-billing-details"> |
| 1867 | 1867 | <tbody> |
| 1868 | 1868 | <tr class="wpi-receipt-name"> |
| 1869 | - <th class="text-left"><?php _e( 'Name', 'invoicing' ); ?></th> |
|
| 1870 | - <td><?php echo esc_html( trim( $billing_details['first_name'] . ' ' . $billing_details['last_name'] ) ) ;?></td> |
|
| 1869 | + <th class="text-left"><?php _e('Name', 'invoicing'); ?></th> |
|
| 1870 | + <td><?php echo esc_html(trim($billing_details['first_name'] . ' ' . $billing_details['last_name'])); ?></td> |
|
| 1871 | 1871 | </tr> |
| 1872 | 1872 | <tr class="wpi-receipt-email"> |
| 1873 | - <th class="text-left"><?php _e( 'Email', 'invoicing' ); ?></th> |
|
| 1874 | - <td><?php echo $billing_details['email'] ;?></td> |
|
| 1873 | + <th class="text-left"><?php _e('Email', 'invoicing'); ?></th> |
|
| 1874 | + <td><?php echo $billing_details['email']; ?></td> |
|
| 1875 | 1875 | </tr> |
| 1876 | - <?php if ( $billing_details['company'] ) { ?> |
|
| 1876 | + <?php if ($billing_details['company']) { ?> |
|
| 1877 | 1877 | <tr class="wpi-receipt-company"> |
| 1878 | - <th class="text-left"><?php _e( 'Company', 'invoicing' ); ?></th> |
|
| 1879 | - <td><?php echo esc_html( $billing_details['company'] ) ;?></td> |
|
| 1878 | + <th class="text-left"><?php _e('Company', 'invoicing'); ?></th> |
|
| 1879 | + <td><?php echo esc_html($billing_details['company']); ?></td> |
|
| 1880 | 1880 | </tr> |
| 1881 | 1881 | <?php } ?> |
| 1882 | 1882 | <tr class="wpi-receipt-address"> |
| 1883 | - <th class="text-left"><?php _e( 'Address', 'invoicing' ); ?></th> |
|
| 1884 | - <td><?php echo $address_row ;?></td> |
|
| 1883 | + <th class="text-left"><?php _e('Address', 'invoicing'); ?></th> |
|
| 1884 | + <td><?php echo $address_row; ?></td> |
|
| 1885 | 1885 | </tr> |
| 1886 | - <?php if ( $billing_details['phone'] ) { ?> |
|
| 1886 | + <?php if ($billing_details['phone']) { ?> |
|
| 1887 | 1887 | <tr class="wpi-receipt-phone"> |
| 1888 | - <th class="text-left"><?php _e( 'Phone', 'invoicing' ); ?></th> |
|
| 1889 | - <td><?php echo esc_html( $billing_details['phone'] ) ;?></td> |
|
| 1888 | + <th class="text-left"><?php _e('Phone', 'invoicing'); ?></th> |
|
| 1889 | + <td><?php echo esc_html($billing_details['phone']); ?></td> |
|
| 1890 | 1890 | </tr> |
| 1891 | 1891 | <?php } ?> |
| 1892 | 1892 | </tbody> |
@@ -1894,98 +1894,98 @@ discard block |
||
| 1894 | 1894 | <?php |
| 1895 | 1895 | $output = ob_get_clean(); |
| 1896 | 1896 | |
| 1897 | - $output = apply_filters( 'wpinv_receipt_billing_address', $output, $invoice_id ); |
|
| 1897 | + $output = apply_filters('wpinv_receipt_billing_address', $output, $invoice_id); |
|
| 1898 | 1898 | |
| 1899 | 1899 | echo $output; |
| 1900 | 1900 | } |
| 1901 | 1901 | |
| 1902 | -function wpinv_filter_success_page_content( $content ) { |
|
| 1903 | - if ( isset( $_GET['payment-confirm'] ) && wpinv_is_success_page() ) { |
|
| 1904 | - if ( has_filter( 'wpinv_payment_confirm_' . sanitize_text_field( $_GET['payment-confirm'] ) ) ) { |
|
| 1905 | - $content = apply_filters( 'wpinv_payment_confirm_' . sanitize_text_field( $_GET['payment-confirm'] ), $content ); |
|
| 1902 | +function wpinv_filter_success_page_content($content) { |
|
| 1903 | + if (isset($_GET['payment-confirm']) && wpinv_is_success_page()) { |
|
| 1904 | + if (has_filter('wpinv_payment_confirm_' . sanitize_text_field($_GET['payment-confirm']))) { |
|
| 1905 | + $content = apply_filters('wpinv_payment_confirm_' . sanitize_text_field($_GET['payment-confirm']), $content); |
|
| 1906 | 1906 | } |
| 1907 | 1907 | } |
| 1908 | 1908 | |
| 1909 | 1909 | return $content; |
| 1910 | 1910 | } |
| 1911 | -add_filter( 'the_content', 'wpinv_filter_success_page_content', 99999 ); |
|
| 1911 | +add_filter('the_content', 'wpinv_filter_success_page_content', 99999); |
|
| 1912 | 1912 | |
| 1913 | -function wpinv_receipt_actions( $invoice ) { |
|
| 1914 | - if ( !empty( $invoice ) ) { |
|
| 1913 | +function wpinv_receipt_actions($invoice) { |
|
| 1914 | + if (!empty($invoice)) { |
|
| 1915 | 1915 | $actions = array( |
| 1916 | 1916 | 'print' => array( |
| 1917 | 1917 | 'url' => $invoice->get_view_url(), |
| 1918 | - 'name' => __( 'Print Invoice', 'invoicing' ), |
|
| 1918 | + 'name' => __('Print Invoice', 'invoicing'), |
|
| 1919 | 1919 | 'class' => 'btn-primary', |
| 1920 | 1920 | ), |
| 1921 | 1921 | 'history' => array( |
| 1922 | 1922 | 'url' => wpinv_get_history_page_uri(), |
| 1923 | - 'name' => __( 'Invoice History', 'invoicing' ), |
|
| 1923 | + 'name' => __('Invoice History', 'invoicing'), |
|
| 1924 | 1924 | 'class' => 'btn-warning', |
| 1925 | 1925 | ) |
| 1926 | 1926 | ); |
| 1927 | 1927 | |
| 1928 | - $actions = apply_filters( 'wpinv_invoice_receipt_actions', $actions, $invoice ); |
|
| 1928 | + $actions = apply_filters('wpinv_invoice_receipt_actions', $actions, $invoice); |
|
| 1929 | 1929 | |
| 1930 | - if ( !empty( $actions ) ) { |
|
| 1930 | + if (!empty($actions)) { |
|
| 1931 | 1931 | ?> |
| 1932 | 1932 | <div class="wpinv-receipt-actions text-right"> |
| 1933 | - <?php foreach ( $actions as $key => $action ) { $class = !empty($action['class']) ? sanitize_html_class( $action['class'] ) : ''; ?> |
|
| 1934 | - <a href="<?php echo esc_url( $action['url'] );?>" class="btn btn-sm <?php echo $class . ' ' . sanitize_html_class( $key );?>" <?php echo ( !empty($action['attrs']) ? $action['attrs'] : '' ) ;?>><?php echo esc_html( $action['name'] );?></a> |
|
| 1933 | + <?php foreach ($actions as $key => $action) { $class = !empty($action['class']) ? sanitize_html_class($action['class']) : ''; ?> |
|
| 1934 | + <a href="<?php echo esc_url($action['url']); ?>" class="btn btn-sm <?php echo $class . ' ' . sanitize_html_class($key); ?>" <?php echo (!empty($action['attrs']) ? $action['attrs'] : ''); ?>><?php echo esc_html($action['name']); ?></a> |
|
| 1935 | 1935 | <?php } ?> |
| 1936 | 1936 | </div> |
| 1937 | 1937 | <?php |
| 1938 | 1938 | } |
| 1939 | 1939 | } |
| 1940 | 1940 | } |
| 1941 | -add_action( 'wpinv_receipt_start', 'wpinv_receipt_actions', -10, 1 ); |
|
| 1941 | +add_action('wpinv_receipt_start', 'wpinv_receipt_actions', -10, 1); |
|
| 1942 | 1942 | |
| 1943 | -function wpinv_invoice_link( $invoice_id ) { |
|
| 1944 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
| 1943 | +function wpinv_invoice_link($invoice_id) { |
|
| 1944 | + $invoice = wpinv_get_invoice($invoice_id); |
|
| 1945 | 1945 | |
| 1946 | - if ( empty( $invoice ) ) { |
|
| 1946 | + if (empty($invoice)) { |
|
| 1947 | 1947 | return NULL; |
| 1948 | 1948 | } |
| 1949 | 1949 | |
| 1950 | - $invoice_link = '<a href="' . esc_url( $invoice->get_view_url() ) . '">' . $invoice->get_number() . '</a>'; |
|
| 1950 | + $invoice_link = '<a href="' . esc_url($invoice->get_view_url()) . '">' . $invoice->get_number() . '</a>'; |
|
| 1951 | 1951 | |
| 1952 | - return apply_filters( 'wpinv_get_invoice_link', $invoice_link, $invoice ); |
|
| 1952 | + return apply_filters('wpinv_get_invoice_link', $invoice_link, $invoice); |
|
| 1953 | 1953 | } |
| 1954 | 1954 | |
| 1955 | -function wpinv_invoice_subscription_details( $invoice ) { |
|
| 1956 | - if ( !empty( $invoice ) && $invoice->is_recurring() && !wpinv_is_subscription_payment( $invoice ) ) { |
|
| 1955 | +function wpinv_invoice_subscription_details($invoice) { |
|
| 1956 | + if (!empty($invoice) && $invoice->is_recurring() && !wpinv_is_subscription_payment($invoice)) { |
|
| 1957 | 1957 | $total_payments = (int)$invoice->get_total_payments(); |
| 1958 | 1958 | $payments = $invoice->get_child_payments(); |
| 1959 | 1959 | |
| 1960 | 1960 | $subscription = $invoice->get_subscription_data(); |
| 1961 | 1961 | |
| 1962 | - if ( !( !empty( $subscription ) && !empty( $subscription['item_id'] ) ) ) { |
|
| 1962 | + if (!(!empty($subscription) && !empty($subscription['item_id']))) { |
|
| 1963 | 1963 | return; |
| 1964 | 1964 | } |
| 1965 | 1965 | |
| 1966 | - $billing_cycle = wpinv_get_billing_cycle( $subscription['initial_amount'], $subscription['recurring_amount'], $subscription['period'], $subscription['interval'], $subscription['bill_times'], $subscription['trial_period'], $subscription['trial_interval'], $invoice->get_currency() ); |
|
| 1967 | - $times_billed = $total_payments . ' / ' . ( ( (int)$subscription['bill_times'] == 0 ) ? __( 'Until cancelled', 'invoicing' ) : $subscription['bill_times'] ); |
|
| 1966 | + $billing_cycle = wpinv_get_billing_cycle($subscription['initial_amount'], $subscription['recurring_amount'], $subscription['period'], $subscription['interval'], $subscription['bill_times'], $subscription['trial_period'], $subscription['trial_interval'], $invoice->get_currency()); |
|
| 1967 | + $times_billed = $total_payments . ' / ' . (((int)$subscription['bill_times'] == 0) ? __('Until cancelled', 'invoicing') : $subscription['bill_times']); |
|
| 1968 | 1968 | |
| 1969 | 1969 | $subscription_status = $invoice->get_subscription_status(); |
| 1970 | 1970 | |
| 1971 | 1971 | $status_desc = ''; |
| 1972 | - if ( $subscription_status == 'trialing' && $trial_end_date = $invoice->get_trial_end_date() ) { |
|
| 1973 | - $status_desc = wp_sprintf( __( 'Until: %s', 'invoicing' ), $trial_end_date ); |
|
| 1974 | - } else if ( $subscription_status == 'cancelled' && $cancelled_date = $invoice->get_cancelled_date() ) { |
|
| 1975 | - $status_desc = wp_sprintf( __( 'On: %s', 'invoicing' ), $cancelled_date ); |
|
| 1972 | + if ($subscription_status == 'trialing' && $trial_end_date = $invoice->get_trial_end_date()) { |
|
| 1973 | + $status_desc = wp_sprintf(__('Until: %s', 'invoicing'), $trial_end_date); |
|
| 1974 | + } else if ($subscription_status == 'cancelled' && $cancelled_date = $invoice->get_cancelled_date()) { |
|
| 1975 | + $status_desc = wp_sprintf(__('On: %s', 'invoicing'), $cancelled_date); |
|
| 1976 | 1976 | } |
| 1977 | 1977 | $status_desc = $status_desc != '' ? '<span class="meta">' . $status_desc . '</span>' : ''; |
| 1978 | 1978 | ?> |
| 1979 | 1979 | <div class="wpinv-subscriptions-details"> |
| 1980 | - <h3 class="wpinv-subscriptions-t"><?php echo apply_filters( 'wpinv_subscription_details_title', __( 'Subscription Details', 'invoicing' ) ); ?></h3> |
|
| 1980 | + <h3 class="wpinv-subscriptions-t"><?php echo apply_filters('wpinv_subscription_details_title', __('Subscription Details', 'invoicing')); ?></h3> |
|
| 1981 | 1981 | <table class="table"> |
| 1982 | 1982 | <thead> |
| 1983 | 1983 | <tr> |
| 1984 | - <th><?php _e( 'Billing Cycle', 'invoicing' ) ;?></th> |
|
| 1985 | - <th><?php _e( 'Start Date', 'invoicing' ) ;?></th> |
|
| 1986 | - <th><?php _e( 'Expiration Date', 'invoicing' ) ;?></th> |
|
| 1987 | - <th class="text-center"><?php _e( 'Times Billed', 'invoicing' ) ;?></th> |
|
| 1988 | - <th class="text-center"><?php _e( 'Status', 'invoicing' ) ;?></th> |
|
| 1984 | + <th><?php _e('Billing Cycle', 'invoicing'); ?></th> |
|
| 1985 | + <th><?php _e('Start Date', 'invoicing'); ?></th> |
|
| 1986 | + <th><?php _e('Expiration Date', 'invoicing'); ?></th> |
|
| 1987 | + <th class="text-center"><?php _e('Times Billed', 'invoicing'); ?></th> |
|
| 1988 | + <th class="text-center"><?php _e('Status', 'invoicing'); ?></th> |
|
| 1989 | 1989 | </tr> |
| 1990 | 1990 | </thead> |
| 1991 | 1991 | <tbody> |
@@ -1994,32 +1994,32 @@ discard block |
||
| 1994 | 1994 | <td><?php echo $invoice->get_subscription_start(); ?></td> |
| 1995 | 1995 | <td><?php echo $invoice->get_subscription_end(); ?></td> |
| 1996 | 1996 | <td class="text-center"><?php echo $times_billed; ?></td> |
| 1997 | - <td class="text-center wpi-sub-status"><?php echo $invoice->get_subscription_status_label() ;?> |
|
| 1997 | + <td class="text-center wpi-sub-status"><?php echo $invoice->get_subscription_status_label(); ?> |
|
| 1998 | 1998 | <?php echo $status_desc; ?> |
| 1999 | 1999 | </td> |
| 2000 | 2000 | </tr> |
| 2001 | 2001 | </tbody> |
| 2002 | 2002 | </table> |
| 2003 | 2003 | </div> |
| 2004 | - <?php if ( !empty( $payments ) ) { ?> |
|
| 2004 | + <?php if (!empty($payments)) { ?> |
|
| 2005 | 2005 | <div class="wpinv-renewal-payments"> |
| 2006 | - <h3 class="wpinv-renewals-t"><?php echo apply_filters( 'wpinv_renewal_payments_title', __( 'Renewal Payments', 'invoicing' ) ); ?></h3> |
|
| 2006 | + <h3 class="wpinv-renewals-t"><?php echo apply_filters('wpinv_renewal_payments_title', __('Renewal Payments', 'invoicing')); ?></h3> |
|
| 2007 | 2007 | <table class="table"> |
| 2008 | 2008 | <thead> |
| 2009 | 2009 | <tr> |
| 2010 | 2010 | <th>#</th> |
| 2011 | - <th><?php _e( 'Invoice', 'invoicing' ) ;?></th> |
|
| 2012 | - <th><?php _e( 'Date', 'invoicing' ) ;?></th> |
|
| 2013 | - <th class="text-right"><?php _e( 'Amount', 'invoicing' ) ;?></th> |
|
| 2011 | + <th><?php _e('Invoice', 'invoicing'); ?></th> |
|
| 2012 | + <th><?php _e('Date', 'invoicing'); ?></th> |
|
| 2013 | + <th class="text-right"><?php _e('Amount', 'invoicing'); ?></th> |
|
| 2014 | 2014 | </tr> |
| 2015 | 2015 | </thead> |
| 2016 | 2016 | <tbody> |
| 2017 | - <?php foreach ( $payments as $key => $invoice_id ) { ?> |
|
| 2017 | + <?php foreach ($payments as $key => $invoice_id) { ?> |
|
| 2018 | 2018 | <tr> |
| 2019 | - <th scope="row"><?php echo ( $key + 1 );?></th> |
|
| 2020 | - <td><?php echo wpinv_invoice_link( $invoice_id ) ;?></td> |
|
| 2021 | - <td><?php echo wpinv_get_invoice_date( $invoice_id ); ?></td> |
|
| 2022 | - <td class="text-right"><?php echo wpinv_payment_total( $invoice_id, true ); ?></td> |
|
| 2019 | + <th scope="row"><?php echo ($key + 1); ?></th> |
|
| 2020 | + <td><?php echo wpinv_invoice_link($invoice_id); ?></td> |
|
| 2021 | + <td><?php echo wpinv_get_invoice_date($invoice_id); ?></td> |
|
| 2022 | + <td class="text-right"><?php echo wpinv_payment_total($invoice_id, true); ?></td> |
|
| 2023 | 2023 | </tr> |
| 2024 | 2024 | <?php } ?> |
| 2025 | 2025 | <tr><td colspan="4" style="padding:0"></td></tr> |
@@ -2031,52 +2031,52 @@ discard block |
||
| 2031 | 2031 | } |
| 2032 | 2032 | } |
| 2033 | 2033 | |
| 2034 | -function wpinv_cart_total_label( $label, $invoice ) { |
|
| 2035 | - if ( empty( $invoice ) ) { |
|
| 2034 | +function wpinv_cart_total_label($label, $invoice) { |
|
| 2035 | + if (empty($invoice)) { |
|
| 2036 | 2036 | return $label; |
| 2037 | 2037 | } |
| 2038 | 2038 | |
| 2039 | 2039 | $prefix_label = ''; |
| 2040 | - if ( $invoice->is_parent() && $item_id = $invoice->get_recurring() ) { |
|
| 2041 | - $prefix_label = '<span class="label label-primary label-recurring">' . __( 'Recurring Payment', 'invoicing' ) . '</span> ' . wpinv_subscription_payment_desc( $invoice ); |
|
| 2042 | - } else if ( $invoice->is_renewal() ) { |
|
| 2043 | - $prefix_label = '<span class="label label-primary label-renewal">' . __( 'Renewal Payment', 'invoicing' ) . '</span> '; |
|
| 2040 | + if ($invoice->is_parent() && $item_id = $invoice->get_recurring()) { |
|
| 2041 | + $prefix_label = '<span class="label label-primary label-recurring">' . __('Recurring Payment', 'invoicing') . '</span> ' . wpinv_subscription_payment_desc($invoice); |
|
| 2042 | + } else if ($invoice->is_renewal()) { |
|
| 2043 | + $prefix_label = '<span class="label label-primary label-renewal">' . __('Renewal Payment', 'invoicing') . '</span> '; |
|
| 2044 | 2044 | } |
| 2045 | 2045 | |
| 2046 | - if ( $prefix_label != '' ) { |
|
| 2047 | - $label = '<span class="wpinv-cart-sub-desc">' . $prefix_label . '</span> ' . $label; |
|
| 2046 | + if ($prefix_label != '') { |
|
| 2047 | + $label = '<span class="wpinv-cart-sub-desc">' . $prefix_label . '</span> ' . $label; |
|
| 2048 | 2048 | } |
| 2049 | 2049 | |
| 2050 | 2050 | return $label; |
| 2051 | 2051 | } |
| 2052 | -add_filter( 'wpinv_cart_total_label', 'wpinv_cart_total_label', 10, 2 ); |
|
| 2053 | -add_filter( 'wpinv_email_cart_total_label', 'wpinv_cart_total_label', 10, 2 ); |
|
| 2054 | -add_filter( 'wpinv_print_cart_total_label', 'wpinv_cart_total_label', 10, 2 ); |
|
| 2052 | +add_filter('wpinv_cart_total_label', 'wpinv_cart_total_label', 10, 2); |
|
| 2053 | +add_filter('wpinv_email_cart_total_label', 'wpinv_cart_total_label', 10, 2); |
|
| 2054 | +add_filter('wpinv_print_cart_total_label', 'wpinv_cart_total_label', 10, 2); |
|
| 2055 | 2055 | |
| 2056 | -add_action( 'wpinv_invoice_print_middle', 'wpinv_invoice_subscription_details', 10, 1 ); |
|
| 2056 | +add_action('wpinv_invoice_print_middle', 'wpinv_invoice_subscription_details', 10, 1); |
|
| 2057 | 2057 | |
| 2058 | -function wpinv_invoice_print_description( $invoice ) { |
|
| 2059 | - if ( empty( $invoice ) ) { |
|
| 2058 | +function wpinv_invoice_print_description($invoice) { |
|
| 2059 | + if (empty($invoice)) { |
|
| 2060 | 2060 | return NULL; |
| 2061 | 2061 | } |
| 2062 | - if ( $description = wpinv_get_invoice_description( $invoice->ID ) ) { |
|
| 2062 | + if ($description = wpinv_get_invoice_description($invoice->ID)) { |
|
| 2063 | 2063 | ?> |
| 2064 | 2064 | <div class="row wpinv-lower"> |
| 2065 | 2065 | <div class="col-sm-12 wpinv-description"> |
| 2066 | - <?php echo wpautop( $description ); ?> |
|
| 2066 | + <?php echo wpautop($description); ?> |
|
| 2067 | 2067 | </div> |
| 2068 | 2068 | </div> |
| 2069 | 2069 | <?php |
| 2070 | 2070 | } |
| 2071 | 2071 | } |
| 2072 | -add_action( 'wpinv_invoice_print_middle', 'wpinv_invoice_print_description', 10.1, 1 ); |
|
| 2072 | +add_action('wpinv_invoice_print_middle', 'wpinv_invoice_print_description', 10.1, 1); |
|
| 2073 | 2073 | |
| 2074 | -function wpinv_invoice_print_payment_info( $invoice ) { |
|
| 2075 | - if ( empty( $invoice ) ) { |
|
| 2074 | +function wpinv_invoice_print_payment_info($invoice) { |
|
| 2075 | + if (empty($invoice)) { |
|
| 2076 | 2076 | return NULL; |
| 2077 | 2077 | } |
| 2078 | 2078 | |
| 2079 | - if ( $payments_info = wpinv_display_payments_info( $invoice->ID, false ) ) { |
|
| 2079 | + if ($payments_info = wpinv_display_payments_info($invoice->ID, false)) { |
|
| 2080 | 2080 | ?> |
| 2081 | 2081 | <div class="row wpinv-payments"> |
| 2082 | 2082 | <div class="col-sm-12"> |
@@ -2088,43 +2088,43 @@ discard block |
||
| 2088 | 2088 | } |
| 2089 | 2089 | // add_action( 'wpinv_invoice_print_after_line_items', 'wpinv_invoice_print_payment_info', 10, 1 ); |
| 2090 | 2090 | |
| 2091 | -function wpinv_get_invoice_note_line_item( $note, $echo = true ) { |
|
| 2092 | - if ( empty( $note ) ) { |
|
| 2091 | +function wpinv_get_invoice_note_line_item($note, $echo = true) { |
|
| 2092 | + if (empty($note)) { |
|
| 2093 | 2093 | return NULL; |
| 2094 | 2094 | } |
| 2095 | 2095 | |
| 2096 | - if ( is_int( $note ) ) { |
|
| 2097 | - $note = get_comment( $note ); |
|
| 2096 | + if (is_int($note)) { |
|
| 2097 | + $note = get_comment($note); |
|
| 2098 | 2098 | } |
| 2099 | 2099 | |
| 2100 | - if ( !( is_object( $note ) && is_a( $note, 'WP_Comment' ) ) ) { |
|
| 2100 | + if (!(is_object($note) && is_a($note, 'WP_Comment'))) { |
|
| 2101 | 2101 | return NULL; |
| 2102 | 2102 | } |
| 2103 | 2103 | |
| 2104 | - $note_classes = array( 'note' ); |
|
| 2105 | - $note_classes[] = get_comment_meta( $note->comment_ID, '_wpi_customer_note', true ) ? 'customer-note' : ''; |
|
| 2106 | - $note_classes[] = $note->comment_author === __( 'System', 'invoicing' ) ? 'system-note' : ''; |
|
| 2107 | - $note_classes = apply_filters( 'wpinv_invoice_note_class', array_filter( $note_classes ), $note ); |
|
| 2108 | - $note_classes = !empty( $note_classes ) ? implode( ' ', $note_classes ) : ''; |
|
| 2104 | + $note_classes = array('note'); |
|
| 2105 | + $note_classes[] = get_comment_meta($note->comment_ID, '_wpi_customer_note', true) ? 'customer-note' : ''; |
|
| 2106 | + $note_classes[] = $note->comment_author === __('System', 'invoicing') ? 'system-note' : ''; |
|
| 2107 | + $note_classes = apply_filters('wpinv_invoice_note_class', array_filter($note_classes), $note); |
|
| 2108 | + $note_classes = !empty($note_classes) ? implode(' ', $note_classes) : ''; |
|
| 2109 | 2109 | |
| 2110 | 2110 | ob_start(); |
| 2111 | 2111 | ?> |
| 2112 | - <li rel="<?php echo absint( $note->comment_ID ) ; ?>" class="<?php echo esc_attr( $note_classes ); ?>"> |
|
| 2112 | + <li rel="<?php echo absint($note->comment_ID); ?>" class="<?php echo esc_attr($note_classes); ?>"> |
|
| 2113 | 2113 | <div class="note_content"> |
| 2114 | - <?php echo wpautop( wptexturize( wp_kses_post( $note->comment_content ) ) ); ?> |
|
| 2114 | + <?php echo wpautop(wptexturize(wp_kses_post($note->comment_content))); ?> |
|
| 2115 | 2115 | </div> |
| 2116 | 2116 | <p class="meta"> |
| 2117 | - <abbr class="exact-date" title="<?php echo $note->comment_date; ?>"><?php printf( __( '%1$s - %2$s at %3$s', 'invoicing' ), $note->comment_author, date_i18n( get_option( 'date_format' ), strtotime( $note->comment_date ) ), date_i18n( get_option( 'time_format' ), strtotime( $note->comment_date ) ) ); ?></abbr> |
|
| 2118 | - <?php if($note->comment_author !== 'System') {?> |
|
| 2119 | - <a href="#" class="delete_note"><?php _e( 'Delete note', 'invoicing' ); ?></a> |
|
| 2117 | + <abbr class="exact-date" title="<?php echo $note->comment_date; ?>"><?php printf(__('%1$s - %2$s at %3$s', 'invoicing'), $note->comment_author, date_i18n(get_option('date_format'), strtotime($note->comment_date)), date_i18n(get_option('time_format'), strtotime($note->comment_date))); ?></abbr> |
|
| 2118 | + <?php if ($note->comment_author !== 'System') {?> |
|
| 2119 | + <a href="#" class="delete_note"><?php _e('Delete note', 'invoicing'); ?></a> |
|
| 2120 | 2120 | <?php } ?> |
| 2121 | 2121 | </p> |
| 2122 | 2122 | </li> |
| 2123 | 2123 | <?php |
| 2124 | 2124 | $note_content = ob_get_clean(); |
| 2125 | - $note_content = apply_filters( 'wpinv_get_invoice_note_line_item', $note_content, $note, $echo ); |
|
| 2125 | + $note_content = apply_filters('wpinv_get_invoice_note_line_item', $note_content, $note, $echo); |
|
| 2126 | 2126 | |
| 2127 | - if ( $echo ) { |
|
| 2127 | + if ($echo) { |
|
| 2128 | 2128 | echo $note_content; |
| 2129 | 2129 | } else { |
| 2130 | 2130 | return $note_content; |
@@ -161,6 +161,9 @@ |
||
| 161 | 161 | wp_redirect( $redirect_to ); |
| 162 | 162 | } |
| 163 | 163 | |
| 164 | +/** |
|
| 165 | + * @param integer $user_id |
|
| 166 | + */ |
|
| 164 | 167 | function wpinv_login_user( $user_id ) { |
| 165 | 168 | if ( is_user_logged_in() ) { |
| 166 | 169 | return true; |
@@ -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 | function wpinv_user_invoices( $current_page = 1 ) { |
| 6 | 8 | global $current_page; |
@@ -17,12 +19,13 @@ discard block |
||
| 17 | 19 | } |
| 18 | 20 | |
| 19 | 21 | if ( $pagination ) { |
| 20 | - if ( get_query_var( 'paged' ) ) |
|
| 21 | - $paged = get_query_var('paged'); |
|
| 22 | - else if ( get_query_var( 'page' ) ) |
|
| 23 | - $paged = get_query_var( 'page' ); |
|
| 24 | - else |
|
| 25 | - $paged = 1; |
|
| 22 | + if ( get_query_var( 'paged' ) ) { |
|
| 23 | + $paged = get_query_var('paged'); |
|
| 24 | + } else if ( get_query_var( 'page' ) ) { |
|
| 25 | + $paged = get_query_var( 'page' ); |
|
| 26 | + } else { |
|
| 27 | + $paged = 1; |
|
| 28 | + } |
|
| 26 | 29 | } |
| 27 | 30 | |
| 28 | 31 | $args = array( |
@@ -37,8 +40,9 @@ discard block |
||
| 37 | 40 | $invoices = get_posts( $args ); |
| 38 | 41 | |
| 39 | 42 | // No invoices |
| 40 | - if ( ! $invoices ) |
|
| 41 | - return false; |
|
| 43 | + if ( ! $invoices ) { |
|
| 44 | + return false; |
|
| 45 | + } |
|
| 42 | 46 | |
| 43 | 47 | return $invoices; |
| 44 | 48 | } |
@@ -1,28 +1,28 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | // Exit if accessed directly |
| 3 | -if ( ! defined( 'ABSPATH' ) ) exit; |
|
| 3 | +if (!defined('ABSPATH')) exit; |
|
| 4 | 4 | |
| 5 | -function wpinv_user_invoices( $current_page = 1 ) { |
|
| 5 | +function wpinv_user_invoices($current_page = 1) { |
|
| 6 | 6 | global $current_page; |
| 7 | - do_action( 'wpinv_before_user_invoices_template', $current_page ); |
|
| 8 | - wpinv_get_template_part( 'wpinv-invoice-history' ); |
|
| 9 | - do_action( 'wpinv_after_user_invoices_template', $current_page ); |
|
| 7 | + do_action('wpinv_before_user_invoices_template', $current_page); |
|
| 8 | + wpinv_get_template_part('wpinv-invoice-history'); |
|
| 9 | + do_action('wpinv_after_user_invoices_template', $current_page); |
|
| 10 | 10 | } |
| 11 | 11 | |
| 12 | -function wpinv_get_users_invoices( $user = 0, $number = 20, $pagination = false, $status = 'publish' ) { |
|
| 13 | - if ( empty( $user ) ) { |
|
| 12 | +function wpinv_get_users_invoices($user = 0, $number = 20, $pagination = false, $status = 'publish') { |
|
| 13 | + if (empty($user)) { |
|
| 14 | 14 | $user = get_current_user_id(); |
| 15 | 15 | } |
| 16 | 16 | |
| 17 | - if ( 0 === $user ) { |
|
| 17 | + if (0 === $user) { |
|
| 18 | 18 | return false; |
| 19 | 19 | } |
| 20 | 20 | |
| 21 | - if ( $pagination ) { |
|
| 22 | - if ( get_query_var( 'paged' ) ) |
|
| 21 | + if ($pagination) { |
|
| 22 | + if (get_query_var('paged')) |
|
| 23 | 23 | $paged = get_query_var('paged'); |
| 24 | - else if ( get_query_var( 'page' ) ) |
|
| 25 | - $paged = get_query_var( 'page' ); |
|
| 24 | + else if (get_query_var('page')) |
|
| 25 | + $paged = get_query_var('page'); |
|
| 26 | 26 | else |
| 27 | 27 | $paged = 1; |
| 28 | 28 | } |
@@ -31,21 +31,21 @@ discard block |
||
| 31 | 31 | 'post_type' => 'wpi_invoice', |
| 32 | 32 | 'posts_per_page' => 20, |
| 33 | 33 | 'paged' => null, |
| 34 | - 'post_status' => array( 'publish', 'pending' ), |
|
| 34 | + 'post_status' => array('publish', 'pending'), |
|
| 35 | 35 | 'user' => $user, |
| 36 | 36 | 'order' => 'date', |
| 37 | 37 | ); |
| 38 | 38 | |
| 39 | - $invoices = get_posts( $args ); |
|
| 39 | + $invoices = get_posts($args); |
|
| 40 | 40 | |
| 41 | 41 | // No invoices |
| 42 | - if ( ! $invoices ) |
|
| 42 | + if (!$invoices) |
|
| 43 | 43 | return false; |
| 44 | 44 | |
| 45 | 45 | return $invoices; |
| 46 | 46 | } |
| 47 | 47 | |
| 48 | -function wpinv_dropdown_users( $args = '' ) { |
|
| 48 | +function wpinv_dropdown_users($args = '') { |
|
| 49 | 49 | $defaults = array( |
| 50 | 50 | 'show_option_all' => '', 'show_option_none' => '', 'hide_if_only_one_author' => '', |
| 51 | 51 | 'orderby' => 'display_name', 'order' => 'ASC', |
@@ -56,18 +56,18 @@ discard block |
||
| 56 | 56 | 'option_none_value' => -1 |
| 57 | 57 | ); |
| 58 | 58 | |
| 59 | - $defaults['selected'] = is_author() ? get_query_var( 'author' ) : 0; |
|
| 59 | + $defaults['selected'] = is_author() ? get_query_var('author') : 0; |
|
| 60 | 60 | |
| 61 | - $r = wp_parse_args( $args, $defaults ); |
|
| 61 | + $r = wp_parse_args($args, $defaults); |
|
| 62 | 62 | |
| 63 | - $query_args = wp_array_slice_assoc( $r, array( 'blog_id', 'include', 'exclude', 'orderby', 'order', 'who' ) ); |
|
| 63 | + $query_args = wp_array_slice_assoc($r, array('blog_id', 'include', 'exclude', 'orderby', 'order', 'who')); |
|
| 64 | 64 | |
| 65 | - $fields = array( 'ID', 'user_login', 'user_email' ); |
|
| 65 | + $fields = array('ID', 'user_login', 'user_email'); |
|
| 66 | 66 | |
| 67 | - $show = ! empty( $r['show'] ) ? $r['show'] : 'display_name'; |
|
| 68 | - if ( 'display_name_with_login' === $show ) { |
|
| 67 | + $show = !empty($r['show']) ? $r['show'] : 'display_name'; |
|
| 68 | + if ('display_name_with_login' === $show) { |
|
| 69 | 69 | $fields[] = 'display_name'; |
| 70 | - } else if ( 'display_name_with_email' === $show ) { |
|
| 70 | + } else if ('display_name_with_email' === $show) { |
|
| 71 | 71 | $fields[] = 'display_name'; |
| 72 | 72 | } else { |
| 73 | 73 | $fields[] = $show; |
@@ -79,99 +79,99 @@ discard block |
||
| 79 | 79 | $show_option_none = $r['show_option_none']; |
| 80 | 80 | $option_none_value = $r['option_none_value']; |
| 81 | 81 | |
| 82 | - $query_args = apply_filters( 'wpinv_dropdown_users_args', $query_args, $r ); |
|
| 82 | + $query_args = apply_filters('wpinv_dropdown_users_args', $query_args, $r); |
|
| 83 | 83 | |
| 84 | - $users = get_users( $query_args ); |
|
| 84 | + $users = get_users($query_args); |
|
| 85 | 85 | |
| 86 | 86 | $output = ''; |
| 87 | - if ( ! empty( $users ) && ( empty( $r['hide_if_only_one_author'] ) || count( $users ) > 1 ) ) { |
|
| 88 | - $name = esc_attr( $r['name'] ); |
|
| 89 | - if ( $r['multi'] && ! $r['id'] ) { |
|
| 87 | + if (!empty($users) && (empty($r['hide_if_only_one_author']) || count($users) > 1)) { |
|
| 88 | + $name = esc_attr($r['name']); |
|
| 89 | + if ($r['multi'] && !$r['id']) { |
|
| 90 | 90 | $id = ''; |
| 91 | 91 | } else { |
| 92 | - $id = $r['id'] ? " id='" . esc_attr( $r['id'] ) . "'" : " id='$name'"; |
|
| 92 | + $id = $r['id'] ? " id='" . esc_attr($r['id']) . "'" : " id='$name'"; |
|
| 93 | 93 | } |
| 94 | 94 | $output = "<select name='{$name}'{$id} class='" . $r['class'] . "'>\n"; |
| 95 | 95 | |
| 96 | - if ( $show_option_all ) { |
|
| 96 | + if ($show_option_all) { |
|
| 97 | 97 | $output .= "\t<option value='0'>$show_option_all</option>\n"; |
| 98 | 98 | } |
| 99 | 99 | |
| 100 | - if ( $show_option_none ) { |
|
| 101 | - $_selected = selected( $option_none_value, $r['selected'], false ); |
|
| 102 | - $output .= "\t<option value='" . esc_attr( $option_none_value ) . "'$_selected>$show_option_none</option>\n"; |
|
| 100 | + if ($show_option_none) { |
|
| 101 | + $_selected = selected($option_none_value, $r['selected'], false); |
|
| 102 | + $output .= "\t<option value='" . esc_attr($option_none_value) . "'$_selected>$show_option_none</option>\n"; |
|
| 103 | 103 | } |
| 104 | 104 | |
| 105 | - if ( $r['include_selected'] && ( $r['selected'] > 0 ) ) { |
|
| 105 | + if ($r['include_selected'] && ($r['selected'] > 0)) { |
|
| 106 | 106 | $found_selected = false; |
| 107 | - $r['selected'] = (int) $r['selected']; |
|
| 108 | - foreach ( (array) $users as $user ) { |
|
| 109 | - $user->ID = (int) $user->ID; |
|
| 110 | - if ( $user->ID === $r['selected'] ) { |
|
| 107 | + $r['selected'] = (int)$r['selected']; |
|
| 108 | + foreach ((array)$users as $user) { |
|
| 109 | + $user->ID = (int)$user->ID; |
|
| 110 | + if ($user->ID === $r['selected']) { |
|
| 111 | 111 | $found_selected = true; |
| 112 | 112 | } |
| 113 | 113 | } |
| 114 | 114 | |
| 115 | - if ( ! $found_selected ) { |
|
| 116 | - $users[] = get_userdata( $r['selected'] ); |
|
| 115 | + if (!$found_selected) { |
|
| 116 | + $users[] = get_userdata($r['selected']); |
|
| 117 | 117 | } |
| 118 | 118 | } |
| 119 | 119 | |
| 120 | - foreach ( (array) $users as $user ) { |
|
| 121 | - if ( 'display_name_with_login' === $show ) { |
|
| 120 | + foreach ((array)$users as $user) { |
|
| 121 | + if ('display_name_with_login' === $show) { |
|
| 122 | 122 | /* translators: 1: display name, 2: user_login */ |
| 123 | - $display = sprintf( _x( '%1$s (%2$s)', 'user dropdown' ), $user->display_name, $user->user_login ); |
|
| 124 | - } elseif ( 'display_name_with_email' === $show ) { |
|
| 123 | + $display = sprintf(_x('%1$s (%2$s)', 'user dropdown'), $user->display_name, $user->user_login); |
|
| 124 | + } elseif ('display_name_with_email' === $show) { |
|
| 125 | 125 | /* translators: 1: display name, 2: user_email */ |
| 126 | - if ( $user->display_name == $user->user_email ) { |
|
| 126 | + if ($user->display_name == $user->user_email) { |
|
| 127 | 127 | $display = $user->display_name; |
| 128 | 128 | } else { |
| 129 | - $display = sprintf( _x( '%1$s (%2$s)', 'user dropdown' ), $user->display_name, $user->user_email ); |
|
| 129 | + $display = sprintf(_x('%1$s (%2$s)', 'user dropdown'), $user->display_name, $user->user_email); |
|
| 130 | 130 | } |
| 131 | - } elseif ( ! empty( $user->$show ) ) { |
|
| 131 | + } elseif (!empty($user->$show)) { |
|
| 132 | 132 | $display = $user->$show; |
| 133 | 133 | } else { |
| 134 | 134 | $display = '(' . $user->user_login . ')'; |
| 135 | 135 | } |
| 136 | 136 | |
| 137 | - $_selected = selected( $user->ID, $r['selected'], false ); |
|
| 138 | - $output .= "\t<option value='$user->ID'$_selected>" . esc_html( $display ) . "</option>\n"; |
|
| 137 | + $_selected = selected($user->ID, $r['selected'], false); |
|
| 138 | + $output .= "\t<option value='$user->ID'$_selected>" . esc_html($display) . "</option>\n"; |
|
| 139 | 139 | } |
| 140 | 140 | |
| 141 | 141 | $output .= "</select>"; |
| 142 | 142 | } |
| 143 | 143 | |
| 144 | - $html = apply_filters( 'wpinv_dropdown_users', $output ); |
|
| 144 | + $html = apply_filters('wpinv_dropdown_users', $output); |
|
| 145 | 145 | |
| 146 | - if ( $r['echo'] ) { |
|
| 146 | + if ($r['echo']) { |
|
| 147 | 147 | echo $html; |
| 148 | 148 | } |
| 149 | 149 | return $html; |
| 150 | 150 | } |
| 151 | 151 | |
| 152 | -function wpinv_guest_redirect( $redirect_to, $user_id = 0 ) { |
|
| 153 | - if ( (int)wpinv_get_option( 'guest_checkout' ) && $user_id > 0 ) { |
|
| 154 | - wpinv_login_user( $user_id ); |
|
| 152 | +function wpinv_guest_redirect($redirect_to, $user_id = 0) { |
|
| 153 | + if ((int)wpinv_get_option('guest_checkout') && $user_id > 0) { |
|
| 154 | + wpinv_login_user($user_id); |
|
| 155 | 155 | } else { |
| 156 | - $redirect_to = wp_login_url( $redirect_to ); |
|
| 156 | + $redirect_to = wp_login_url($redirect_to); |
|
| 157 | 157 | } |
| 158 | 158 | |
| 159 | - $redirect_to = apply_filters( 'wpinv_invoice_link_guest_redirect', $redirect_to, $user_id ); |
|
| 159 | + $redirect_to = apply_filters('wpinv_invoice_link_guest_redirect', $redirect_to, $user_id); |
|
| 160 | 160 | |
| 161 | - wp_redirect( $redirect_to ); |
|
| 161 | + wp_redirect($redirect_to); |
|
| 162 | 162 | } |
| 163 | 163 | |
| 164 | -function wpinv_login_user( $user_id ) { |
|
| 165 | - if ( is_user_logged_in() ) { |
|
| 164 | +function wpinv_login_user($user_id) { |
|
| 165 | + if (is_user_logged_in()) { |
|
| 166 | 166 | return true; |
| 167 | 167 | } |
| 168 | 168 | |
| 169 | - $user = get_user_by( 'id', $user_id ); |
|
| 169 | + $user = get_user_by('id', $user_id); |
|
| 170 | 170 | |
| 171 | - if ( !empty( $user ) && !is_wp_error( $user ) && !empty( $user->user_login ) ) { |
|
| 172 | - wp_set_current_user( $user_id, $user->user_login ); |
|
| 173 | - wp_set_auth_cookie( $user_id ); |
|
| 174 | - do_action( 'wp_login', $user->user_login ); |
|
| 171 | + if (!empty($user) && !is_wp_error($user) && !empty($user->user_login)) { |
|
| 172 | + wp_set_current_user($user_id, $user->user_login); |
|
| 173 | + wp_set_auth_cookie($user_id); |
|
| 174 | + do_action('wp_login', $user->user_login); |
|
| 175 | 175 | |
| 176 | 176 | return true; |
| 177 | 177 | } |
@@ -9,6 +9,6 @@ |
||
| 9 | 9 | */ |
| 10 | 10 | |
| 11 | 11 | // If uninstall not called from WordPress, then exit. |
| 12 | -if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) { |
|
| 12 | +if (!defined('WP_UNINSTALL_PLUGIN')) { |
|
| 13 | 13 | exit; |
| 14 | 14 | } |