@@ -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_Item { |
| 6 | 6 | public $ID = 0; |
@@ -47,26 +47,26 @@ discard block |
||
| 47 | 47 | public $filter; |
| 48 | 48 | |
| 49 | 49 | |
| 50 | - public function __construct( $_id = false, $_args = array() ) { |
|
| 51 | - $item = WP_Post::get_instance( $_id ); |
|
| 52 | - return $this->setup_item( $item ); |
|
| 50 | + public function __construct($_id = false, $_args = array()) { |
|
| 51 | + $item = WP_Post::get_instance($_id); |
|
| 52 | + return $this->setup_item($item); |
|
| 53 | 53 | } |
| 54 | 54 | |
| 55 | - private function setup_item( $item ) { |
|
| 56 | - if( ! is_object( $item ) ) { |
|
| 55 | + private function setup_item($item) { |
|
| 56 | + if (!is_object($item)) { |
|
| 57 | 57 | return false; |
| 58 | 58 | } |
| 59 | 59 | |
| 60 | - if( ! is_a( $item, 'WP_Post' ) ) { |
|
| 60 | + if (!is_a($item, 'WP_Post')) { |
|
| 61 | 61 | return false; |
| 62 | 62 | } |
| 63 | 63 | |
| 64 | - if( 'wpi_item' !== $item->post_type ) { |
|
| 64 | + if ('wpi_item' !== $item->post_type) { |
|
| 65 | 65 | return false; |
| 66 | 66 | } |
| 67 | 67 | |
| 68 | - foreach ( $item as $key => $value ) { |
|
| 69 | - switch ( $key ) { |
|
| 68 | + foreach ($item as $key => $value) { |
|
| 69 | + switch ($key) { |
|
| 70 | 70 | default: |
| 71 | 71 | $this->$key = $value; |
| 72 | 72 | break; |
@@ -76,38 +76,38 @@ discard block |
||
| 76 | 76 | return true; |
| 77 | 77 | } |
| 78 | 78 | |
| 79 | - public function __get( $key ) { |
|
| 80 | - if ( method_exists( $this, 'get_' . $key ) ) { |
|
| 81 | - return call_user_func( array( $this, 'get_' . $key ) ); |
|
| 79 | + public function __get($key) { |
|
| 80 | + if (method_exists($this, 'get_' . $key)) { |
|
| 81 | + return call_user_func(array($this, 'get_' . $key)); |
|
| 82 | 82 | } else { |
| 83 | - return new WP_Error( 'wpinv-item-invalid-property', sprintf( __( 'Can\'t get property %s', 'invoicing' ), $key ) ); |
|
| 83 | + return new WP_Error('wpinv-item-invalid-property', sprintf(__('Can\'t get property %s', 'invoicing'), $key)); |
|
| 84 | 84 | } |
| 85 | 85 | } |
| 86 | 86 | |
| 87 | - public function create( $data = array(), $wp_error = false ) { |
|
| 88 | - if ( $this->ID != 0 ) { |
|
| 87 | + public function create($data = array(), $wp_error = false) { |
|
| 88 | + if ($this->ID != 0) { |
|
| 89 | 89 | return false; |
| 90 | 90 | } |
| 91 | 91 | |
| 92 | 92 | $defaults = array( |
| 93 | 93 | 'post_type' => 'wpi_item', |
| 94 | 94 | 'post_status' => 'draft', |
| 95 | - 'post_title' => __( 'New Invoice Item', 'invoicing' ) |
|
| 95 | + 'post_title' => __('New Invoice Item', 'invoicing') |
|
| 96 | 96 | ); |
| 97 | 97 | |
| 98 | - $args = wp_parse_args( $data, $defaults ); |
|
| 98 | + $args = wp_parse_args($data, $defaults); |
|
| 99 | 99 | |
| 100 | - do_action( 'wpinv_item_pre_create', $args ); |
|
| 100 | + do_action('wpinv_item_pre_create', $args); |
|
| 101 | 101 | |
| 102 | - $id = wp_insert_post( $args, $wp_error ); |
|
| 102 | + $id = wp_insert_post($args, $wp_error); |
|
| 103 | 103 | if ($wp_error && is_wp_error($id)) { |
| 104 | 104 | return $id; |
| 105 | 105 | } |
| 106 | - if ( !$id ) { |
|
| 106 | + if (!$id) { |
|
| 107 | 107 | return false; |
| 108 | 108 | } |
| 109 | 109 | |
| 110 | - $item = WP_Post::get_instance( $id ); |
|
| 110 | + $item = WP_Post::get_instance($id); |
|
| 111 | 111 | |
| 112 | 112 | if (!empty($item) && !empty($data['meta'])) { |
| 113 | 113 | $this->ID = $item->ID; |
@@ -115,47 +115,47 @@ discard block |
||
| 115 | 115 | } |
| 116 | 116 | |
| 117 | 117 | // Set custom id if not set. |
| 118 | - if ( empty( $data['meta']['custom_id'] ) && !$this->get_custom_id() ) { |
|
| 119 | - $this->save_metas( array( 'custom_id' => $id ) ); |
|
| 118 | + if (empty($data['meta']['custom_id']) && !$this->get_custom_id()) { |
|
| 119 | + $this->save_metas(array('custom_id' => $id)); |
|
| 120 | 120 | } |
| 121 | 121 | |
| 122 | - do_action( 'wpinv_item_create', $id, $args ); |
|
| 122 | + do_action('wpinv_item_create', $id, $args); |
|
| 123 | 123 | |
| 124 | - return $this->setup_item( $item ); |
|
| 124 | + return $this->setup_item($item); |
|
| 125 | 125 | } |
| 126 | 126 | |
| 127 | - public function update( $data = array(), $wp_error = false ) { |
|
| 128 | - if ( !$this->ID > 0 ) { |
|
| 127 | + public function update($data = array(), $wp_error = false) { |
|
| 128 | + if (!$this->ID > 0) { |
|
| 129 | 129 | return false; |
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | $data['ID'] = $this->ID; |
| 133 | 133 | |
| 134 | - do_action( 'wpinv_item_pre_update', $data ); |
|
| 134 | + do_action('wpinv_item_pre_update', $data); |
|
| 135 | 135 | |
| 136 | - $id = wp_update_post( $data, $wp_error ); |
|
| 136 | + $id = wp_update_post($data, $wp_error); |
|
| 137 | 137 | if ($wp_error && is_wp_error($id)) { |
| 138 | 138 | return $id; |
| 139 | 139 | } |
| 140 | 140 | |
| 141 | - if ( !$id ) { |
|
| 141 | + if (!$id) { |
|
| 142 | 142 | return false; |
| 143 | 143 | } |
| 144 | 144 | |
| 145 | - $item = WP_Post::get_instance( $id ); |
|
| 145 | + $item = WP_Post::get_instance($id); |
|
| 146 | 146 | if (!empty($item) && !empty($data['meta'])) { |
| 147 | 147 | $this->ID = $item->ID; |
| 148 | 148 | $this->save_metas($data['meta']); |
| 149 | 149 | } |
| 150 | 150 | |
| 151 | 151 | // Set custom id if not set. |
| 152 | - if ( empty( $data['meta']['custom_id'] ) && !$this->get_custom_id() ) { |
|
| 153 | - $this->save_metas( array( 'custom_id' => $id ) ); |
|
| 152 | + if (empty($data['meta']['custom_id']) && !$this->get_custom_id()) { |
|
| 153 | + $this->save_metas(array('custom_id' => $id)); |
|
| 154 | 154 | } |
| 155 | 155 | |
| 156 | - do_action( 'wpinv_item_update', $id, $data ); |
|
| 156 | + do_action('wpinv_item_update', $id, $data); |
|
| 157 | 157 | |
| 158 | - return $this->setup_item( $item ); |
|
| 158 | + return $this->setup_item($item); |
|
| 159 | 159 | } |
| 160 | 160 | |
| 161 | 161 | public function get_ID() { |
@@ -163,120 +163,120 @@ discard block |
||
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | public function get_name() { |
| 166 | - return get_the_title( $this->ID ); |
|
| 166 | + return get_the_title($this->ID); |
|
| 167 | 167 | } |
| 168 | 168 | |
| 169 | 169 | public function get_title() { |
| 170 | - return get_the_title( $this->ID ); |
|
| 170 | + return get_the_title($this->ID); |
|
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | public function get_status() { |
| 174 | - return get_post_status( $this->ID ); |
|
| 174 | + return get_post_status($this->ID); |
|
| 175 | 175 | } |
| 176 | 176 | |
| 177 | 177 | public function get_summary() { |
| 178 | - $post = get_post( $this->ID ); |
|
| 179 | - return !empty( $post->post_excerpt ) ? $post->post_excerpt : ''; |
|
| 178 | + $post = get_post($this->ID); |
|
| 179 | + return !empty($post->post_excerpt) ? $post->post_excerpt : ''; |
|
| 180 | 180 | } |
| 181 | 181 | |
| 182 | 182 | public function get_price() { |
| 183 | - if ( ! isset( $this->price ) ) { |
|
| 184 | - $this->price = get_post_meta( $this->ID, '_wpinv_price', true ); |
|
| 183 | + if (!isset($this->price)) { |
|
| 184 | + $this->price = get_post_meta($this->ID, '_wpinv_price', true); |
|
| 185 | 185 | |
| 186 | - if ( $this->price ) { |
|
| 187 | - $this->price = wpinv_sanitize_amount( $this->price ); |
|
| 186 | + if ($this->price) { |
|
| 187 | + $this->price = wpinv_sanitize_amount($this->price); |
|
| 188 | 188 | } else { |
| 189 | 189 | $this->price = 0; |
| 190 | 190 | } |
| 191 | 191 | } |
| 192 | 192 | |
| 193 | - return apply_filters( 'wpinv_get_item_price', $this->price, $this->ID ); |
|
| 193 | + return apply_filters('wpinv_get_item_price', $this->price, $this->ID); |
|
| 194 | 194 | } |
| 195 | 195 | |
| 196 | 196 | public function get_vat_rule() { |
| 197 | 197 | global $wpinv_euvat; |
| 198 | 198 | |
| 199 | - if( !isset( $this->vat_rule ) ) { |
|
| 200 | - $this->vat_rule = get_post_meta( $this->ID, '_wpinv_vat_rule', true ); |
|
| 199 | + if (!isset($this->vat_rule)) { |
|
| 200 | + $this->vat_rule = get_post_meta($this->ID, '_wpinv_vat_rule', true); |
|
| 201 | 201 | |
| 202 | - if ( empty( $this->vat_rule ) ) { |
|
| 202 | + if (empty($this->vat_rule)) { |
|
| 203 | 203 | $this->vat_rule = $wpinv_euvat->allow_vat_rules() ? 'digital' : 'physical'; |
| 204 | 204 | } |
| 205 | 205 | } |
| 206 | 206 | |
| 207 | - return apply_filters( 'wpinv_get_item_vat_rule', $this->vat_rule, $this->ID ); |
|
| 207 | + return apply_filters('wpinv_get_item_vat_rule', $this->vat_rule, $this->ID); |
|
| 208 | 208 | } |
| 209 | 209 | |
| 210 | 210 | public function get_vat_class() { |
| 211 | - if( !isset( $this->vat_class ) ) { |
|
| 212 | - $this->vat_class = get_post_meta( $this->ID, '_wpinv_vat_class', true ); |
|
| 211 | + if (!isset($this->vat_class)) { |
|
| 212 | + $this->vat_class = get_post_meta($this->ID, '_wpinv_vat_class', true); |
|
| 213 | 213 | |
| 214 | - if ( empty( $this->vat_class ) ) { |
|
| 214 | + if (empty($this->vat_class)) { |
|
| 215 | 215 | $this->vat_class = '_standard'; |
| 216 | 216 | } |
| 217 | 217 | } |
| 218 | 218 | |
| 219 | - return apply_filters( 'wpinv_get_item_vat_class', $this->vat_class, $this->ID ); |
|
| 219 | + return apply_filters('wpinv_get_item_vat_class', $this->vat_class, $this->ID); |
|
| 220 | 220 | } |
| 221 | 221 | |
| 222 | 222 | public function get_type() { |
| 223 | - if( ! isset( $this->type ) ) { |
|
| 224 | - $this->type = get_post_meta( $this->ID, '_wpinv_type', true ); |
|
| 223 | + if (!isset($this->type)) { |
|
| 224 | + $this->type = get_post_meta($this->ID, '_wpinv_type', true); |
|
| 225 | 225 | |
| 226 | - if ( empty( $this->type ) ) { |
|
| 226 | + if (empty($this->type)) { |
|
| 227 | 227 | $this->type = 'custom'; |
| 228 | 228 | } |
| 229 | 229 | } |
| 230 | 230 | |
| 231 | - return apply_filters( 'wpinv_get_item_type', $this->type, $this->ID ); |
|
| 231 | + return apply_filters('wpinv_get_item_type', $this->type, $this->ID); |
|
| 232 | 232 | } |
| 233 | 233 | |
| 234 | 234 | public function get_custom_id() { |
| 235 | - $custom_id = get_post_meta( $this->ID, '_wpinv_custom_id', true ); |
|
| 235 | + $custom_id = get_post_meta($this->ID, '_wpinv_custom_id', true); |
|
| 236 | 236 | |
| 237 | - return apply_filters( 'wpinv_get_item_custom_id', $custom_id, $this->ID ); |
|
| 237 | + return apply_filters('wpinv_get_item_custom_id', $custom_id, $this->ID); |
|
| 238 | 238 | } |
| 239 | 239 | |
| 240 | 240 | public function get_custom_name() { |
| 241 | - $custom_name = get_post_meta( $this->ID, '_wpinv_custom_name', true ); |
|
| 241 | + $custom_name = get_post_meta($this->ID, '_wpinv_custom_name', true); |
|
| 242 | 242 | |
| 243 | - return apply_filters( 'wpinv_get_item_custom_name', $custom_name, $this->ID ); |
|
| 243 | + return apply_filters('wpinv_get_item_custom_name', $custom_name, $this->ID); |
|
| 244 | 244 | } |
| 245 | 245 | |
| 246 | 246 | public function get_custom_singular_name() { |
| 247 | - $custom_singular_name = get_post_meta( $this->ID, '_wpinv_custom_singular_name', true ); |
|
| 247 | + $custom_singular_name = get_post_meta($this->ID, '_wpinv_custom_singular_name', true); |
|
| 248 | 248 | |
| 249 | - return apply_filters( 'wpinv_get_item_custom_singular_name', $custom_singular_name, $this->ID ); |
|
| 249 | + return apply_filters('wpinv_get_item_custom_singular_name', $custom_singular_name, $this->ID); |
|
| 250 | 250 | } |
| 251 | 251 | |
| 252 | 252 | public function get_editable() { |
| 253 | - $editable = get_post_meta( $this->ID, '_wpinv_editable', true ); |
|
| 253 | + $editable = get_post_meta($this->ID, '_wpinv_editable', true); |
|
| 254 | 254 | |
| 255 | - return apply_filters( 'wpinv_item_get_editable', $editable, $this->ID ); |
|
| 255 | + return apply_filters('wpinv_item_get_editable', $editable, $this->ID); |
|
| 256 | 256 | } |
| 257 | 257 | |
| 258 | 258 | public function get_excerpt() { |
| 259 | - $excerpt = get_the_excerpt( $this->ID ); |
|
| 259 | + $excerpt = get_the_excerpt($this->ID); |
|
| 260 | 260 | |
| 261 | - return apply_filters( 'wpinv_item_get_excerpt', $excerpt, $this->ID ); |
|
| 261 | + return apply_filters('wpinv_item_get_excerpt', $excerpt, $this->ID); |
|
| 262 | 262 | } |
| 263 | 263 | |
| 264 | 264 | public function get_is_recurring() { |
| 265 | - $is_recurring = get_post_meta( $this->ID, '_wpinv_is_recurring', true ); |
|
| 265 | + $is_recurring = get_post_meta($this->ID, '_wpinv_is_recurring', true); |
|
| 266 | 266 | |
| 267 | - return apply_filters( 'wpinv_item_get_is_recurring', $is_recurring, $this->ID ); |
|
| 267 | + return apply_filters('wpinv_item_get_is_recurring', $is_recurring, $this->ID); |
|
| 268 | 268 | |
| 269 | 269 | } |
| 270 | 270 | |
| 271 | - public function get_recurring_period( $full = false ) { |
|
| 272 | - $period = get_post_meta( $this->ID, '_wpinv_recurring_period', true ); |
|
| 271 | + public function get_recurring_period($full = false) { |
|
| 272 | + $period = get_post_meta($this->ID, '_wpinv_recurring_period', true); |
|
| 273 | 273 | |
| 274 | - if ( !in_array( $period, array( 'D', 'W', 'M', 'Y' ) ) ) { |
|
| 274 | + if (!in_array($period, array('D', 'W', 'M', 'Y'))) { |
|
| 275 | 275 | $period = 'D'; |
| 276 | 276 | } |
| 277 | 277 | |
| 278 | - if ( $full ) { |
|
| 279 | - switch( $period ) { |
|
| 278 | + if ($full) { |
|
| 279 | + switch ($period) { |
|
| 280 | 280 | case 'D': |
| 281 | 281 | $period = 'day'; |
| 282 | 282 | break; |
@@ -292,40 +292,40 @@ discard block |
||
| 292 | 292 | } |
| 293 | 293 | } |
| 294 | 294 | |
| 295 | - return apply_filters( 'wpinv_item_recurring_period', $period, $full, $this->ID ); |
|
| 295 | + return apply_filters('wpinv_item_recurring_period', $period, $full, $this->ID); |
|
| 296 | 296 | } |
| 297 | 297 | |
| 298 | 298 | public function get_recurring_interval() { |
| 299 | - $interval = (int)get_post_meta( $this->ID, '_wpinv_recurring_interval', true ); |
|
| 299 | + $interval = (int)get_post_meta($this->ID, '_wpinv_recurring_interval', true); |
|
| 300 | 300 | |
| 301 | - if ( !$interval > 0 ) { |
|
| 301 | + if (!$interval > 0) { |
|
| 302 | 302 | $interval = 1; |
| 303 | 303 | } |
| 304 | 304 | |
| 305 | - return apply_filters( 'wpinv_item_recurring_interval', $interval, $this->ID ); |
|
| 305 | + return apply_filters('wpinv_item_recurring_interval', $interval, $this->ID); |
|
| 306 | 306 | } |
| 307 | 307 | |
| 308 | 308 | public function get_recurring_limit() { |
| 309 | - $limit = get_post_meta( $this->ID, '_wpinv_recurring_limit', true ); |
|
| 309 | + $limit = get_post_meta($this->ID, '_wpinv_recurring_limit', true); |
|
| 310 | 310 | |
| 311 | - return (int)apply_filters( 'wpinv_item_recurring_limit', $limit, $this->ID ); |
|
| 311 | + return (int)apply_filters('wpinv_item_recurring_limit', $limit, $this->ID); |
|
| 312 | 312 | } |
| 313 | 313 | |
| 314 | 314 | public function get_free_trial() { |
| 315 | - $free_trial = get_post_meta( $this->ID, '_wpinv_free_trial', true ); |
|
| 315 | + $free_trial = get_post_meta($this->ID, '_wpinv_free_trial', true); |
|
| 316 | 316 | |
| 317 | - return apply_filters( 'wpinv_item_get_free_trial', $free_trial, $this->ID ); |
|
| 317 | + return apply_filters('wpinv_item_get_free_trial', $free_trial, $this->ID); |
|
| 318 | 318 | } |
| 319 | 319 | |
| 320 | - public function get_trial_period( $full = false ) { |
|
| 321 | - $period = get_post_meta( $this->ID, '_wpinv_trial_period', true ); |
|
| 320 | + public function get_trial_period($full = false) { |
|
| 321 | + $period = get_post_meta($this->ID, '_wpinv_trial_period', true); |
|
| 322 | 322 | |
| 323 | - if ( !in_array( $period, array( 'D', 'W', 'M', 'Y' ) ) ) { |
|
| 323 | + if (!in_array($period, array('D', 'W', 'M', 'Y'))) { |
|
| 324 | 324 | $period = 'D'; |
| 325 | 325 | } |
| 326 | 326 | |
| 327 | - if ( $full ) { |
|
| 328 | - switch( $period ) { |
|
| 327 | + if ($full) { |
|
| 328 | + switch ($period) { |
|
| 329 | 329 | case 'D': |
| 330 | 330 | $period = 'day'; |
| 331 | 331 | break; |
@@ -341,47 +341,47 @@ discard block |
||
| 341 | 341 | } |
| 342 | 342 | } |
| 343 | 343 | |
| 344 | - return apply_filters( 'wpinv_item_trial_period', $period, $full, $this->ID ); |
|
| 344 | + return apply_filters('wpinv_item_trial_period', $period, $full, $this->ID); |
|
| 345 | 345 | } |
| 346 | 346 | |
| 347 | 347 | public function get_trial_interval() { |
| 348 | - $interval = absint( get_post_meta( $this->ID, '_wpinv_trial_interval', true ) ); |
|
| 348 | + $interval = absint(get_post_meta($this->ID, '_wpinv_trial_interval', true)); |
|
| 349 | 349 | |
| 350 | - if ( !$interval > 0 ) { |
|
| 350 | + if (!$interval > 0) { |
|
| 351 | 351 | $interval = 1; |
| 352 | 352 | } |
| 353 | 353 | |
| 354 | - return apply_filters( 'wpinv_item_trial_interval', $interval, $this->ID ); |
|
| 354 | + return apply_filters('wpinv_item_trial_interval', $interval, $this->ID); |
|
| 355 | 355 | } |
| 356 | 356 | |
| 357 | 357 | public function get_the_price() { |
| 358 | - $item_price = wpinv_price( wpinv_format_amount( $this->price ) ); |
|
| 358 | + $item_price = wpinv_price(wpinv_format_amount($this->price)); |
|
| 359 | 359 | |
| 360 | - return apply_filters( 'wpinv_get_the_item_price', $item_price, $this->ID ); |
|
| 360 | + return apply_filters('wpinv_get_the_item_price', $item_price, $this->ID); |
|
| 361 | 361 | } |
| 362 | 362 | |
| 363 | 363 | public function is_recurring() { |
| 364 | 364 | $is_recurring = $this->get_is_recurring(); |
| 365 | 365 | |
| 366 | - return (bool)apply_filters( 'wpinv_is_recurring_item', $is_recurring, $this->ID ); |
|
| 366 | + return (bool)apply_filters('wpinv_is_recurring_item', $is_recurring, $this->ID); |
|
| 367 | 367 | } |
| 368 | 368 | |
| 369 | 369 | public function has_free_trial() { |
| 370 | 370 | $free_trial = $this->is_recurring() && $this->get_free_trial() ? true : false; |
| 371 | 371 | |
| 372 | - return (bool)apply_filters( 'wpinv_item_has_free_trial', $free_trial, $this->ID ); |
|
| 372 | + return (bool)apply_filters('wpinv_item_has_free_trial', $free_trial, $this->ID); |
|
| 373 | 373 | } |
| 374 | 374 | |
| 375 | 375 | public function is_free() { |
| 376 | 376 | $is_free = false; |
| 377 | 377 | |
| 378 | - $price = get_post_meta( $this->ID, '_wpinv_price', true ); |
|
| 378 | + $price = get_post_meta($this->ID, '_wpinv_price', true); |
|
| 379 | 379 | |
| 380 | - if ( (float)$price == 0 ) { |
|
| 380 | + if ((float)$price == 0) { |
|
| 381 | 381 | $is_free = true; |
| 382 | 382 | } |
| 383 | 383 | |
| 384 | - return (bool) apply_filters( 'wpinv_is_free_item', $is_free, $this->ID ); |
|
| 384 | + return (bool)apply_filters('wpinv_is_free_item', $is_free, $this->ID); |
|
| 385 | 385 | |
| 386 | 386 | } |
| 387 | 387 | |
@@ -390,15 +390,15 @@ discard block |
||
| 390 | 390 | |
| 391 | 391 | $is_editable = $editable === 0 || $editable === '0' ? false : true; |
| 392 | 392 | |
| 393 | - return (bool) apply_filters( 'wpinv_item_is_editable', $is_editable, $this->ID ); |
|
| 393 | + return (bool)apply_filters('wpinv_item_is_editable', $is_editable, $this->ID); |
|
| 394 | 394 | } |
| 395 | 395 | |
| 396 | - public function save_metas( $metas = array() ) { |
|
| 397 | - if ( empty( $metas ) ) { |
|
| 396 | + public function save_metas($metas = array()) { |
|
| 397 | + if (empty($metas)) { |
|
| 398 | 398 | return false; |
| 399 | 399 | } |
| 400 | 400 | |
| 401 | - foreach ( $metas as $meta_key => $meta_value ) { |
|
| 401 | + foreach ($metas as $meta_key => $meta_value) { |
|
| 402 | 402 | $meta_key = strpos($meta_key, '_wpinv_') !== 0 ? '_wpinv_' . $meta_key : $meta_key; |
| 403 | 403 | |
| 404 | 404 | $this->update_meta($meta_key, $meta_value); |
@@ -407,66 +407,66 @@ discard block |
||
| 407 | 407 | return true; |
| 408 | 408 | } |
| 409 | 409 | |
| 410 | - public function update_meta( $meta_key = '', $meta_value = '', $prev_value = '' ) { |
|
| 411 | - if ( empty( $meta_key ) ) { |
|
| 410 | + public function update_meta($meta_key = '', $meta_value = '', $prev_value = '') { |
|
| 411 | + if (empty($meta_key)) { |
|
| 412 | 412 | return false; |
| 413 | 413 | } |
| 414 | 414 | |
| 415 | - $meta_value = apply_filters( 'wpinv_update_item_meta_' . $meta_key, $meta_value, $this->ID ); |
|
| 415 | + $meta_value = apply_filters('wpinv_update_item_meta_' . $meta_key, $meta_value, $this->ID); |
|
| 416 | 416 | |
| 417 | - return update_post_meta( $this->ID, $meta_key, $meta_value, $prev_value ); |
|
| 417 | + return update_post_meta($this->ID, $meta_key, $meta_value, $prev_value); |
|
| 418 | 418 | } |
| 419 | 419 | |
| 420 | - public function get_fees( $type = 'fee', $item_id = 0 ) { |
|
| 420 | + public function get_fees($type = 'fee', $item_id = 0) { |
|
| 421 | 421 | global $wpi_session; |
| 422 | 422 | |
| 423 | - $fees = $wpi_session->get( 'wpi_cart_fees' ); |
|
| 423 | + $fees = $wpi_session->get('wpi_cart_fees'); |
|
| 424 | 424 | |
| 425 | - if ( ! wpinv_get_cart_contents() ) { |
|
| 425 | + if (!wpinv_get_cart_contents()) { |
|
| 426 | 426 | // We can only get item type fees when the cart is empty |
| 427 | 427 | $type = 'custom'; |
| 428 | 428 | } |
| 429 | 429 | |
| 430 | - if ( ! empty( $fees ) && ! empty( $type ) && 'all' !== $type ) { |
|
| 431 | - foreach( $fees as $key => $fee ) { |
|
| 432 | - if( ! empty( $fee['type'] ) && $type != $fee['type'] ) { |
|
| 433 | - unset( $fees[ $key ] ); |
|
| 430 | + if (!empty($fees) && !empty($type) && 'all' !== $type) { |
|
| 431 | + foreach ($fees as $key => $fee) { |
|
| 432 | + if (!empty($fee['type']) && $type != $fee['type']) { |
|
| 433 | + unset($fees[$key]); |
|
| 434 | 434 | } |
| 435 | 435 | } |
| 436 | 436 | } |
| 437 | 437 | |
| 438 | - if ( ! empty( $fees ) && ! empty( $item_id ) ) { |
|
| 438 | + if (!empty($fees) && !empty($item_id)) { |
|
| 439 | 439 | // Remove fees that don't belong to the specified Item |
| 440 | - foreach ( $fees as $key => $fee ) { |
|
| 441 | - if ( (int) $item_id !== (int)$fee['custom_id'] ) { |
|
| 442 | - unset( $fees[ $key ] ); |
|
| 440 | + foreach ($fees as $key => $fee) { |
|
| 441 | + if ((int)$item_id !== (int)$fee['custom_id']) { |
|
| 442 | + unset($fees[$key]); |
|
| 443 | 443 | } |
| 444 | 444 | } |
| 445 | 445 | } |
| 446 | 446 | |
| 447 | - if ( ! empty( $fees ) ) { |
|
| 447 | + if (!empty($fees)) { |
|
| 448 | 448 | // Remove fees that belong to a specific item but are not in the cart |
| 449 | - foreach( $fees as $key => $fee ) { |
|
| 450 | - if( empty( $fee['custom_id'] ) ) { |
|
| 449 | + foreach ($fees as $key => $fee) { |
|
| 450 | + if (empty($fee['custom_id'])) { |
|
| 451 | 451 | continue; |
| 452 | 452 | } |
| 453 | 453 | |
| 454 | - if ( !wpinv_item_in_cart( $fee['custom_id'] ) ) { |
|
| 455 | - unset( $fees[ $key ] ); |
|
| 454 | + if (!wpinv_item_in_cart($fee['custom_id'])) { |
|
| 455 | + unset($fees[$key]); |
|
| 456 | 456 | } |
| 457 | 457 | } |
| 458 | 458 | } |
| 459 | 459 | |
| 460 | - return ! empty( $fees ) ? $fees : array(); |
|
| 460 | + return !empty($fees) ? $fees : array(); |
|
| 461 | 461 | } |
| 462 | 462 | |
| 463 | 463 | public function can_purchase() { |
| 464 | 464 | $can_purchase = true; |
| 465 | 465 | |
| 466 | - if ( !current_user_can( 'edit_post', $this->ID ) && $this->post_status != 'publish' ) { |
|
| 466 | + if (!current_user_can('edit_post', $this->ID) && $this->post_status != 'publish') { |
|
| 467 | 467 | $can_purchase = false; |
| 468 | 468 | } |
| 469 | 469 | |
| 470 | - return (bool)apply_filters( 'wpinv_can_purchase_item', $can_purchase, $this ); |
|
| 470 | + return (bool)apply_filters('wpinv_can_purchase_item', $can_purchase, $this); |
|
| 471 | 471 | } |
| 472 | 472 | } |