| Total Complexity | 109 |
| Total Lines | 778 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Complex classes like WPInv_Discount often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use WPInv_Discount, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 16 | class WPInv_Discount { |
||
| 17 | |||
| 18 | /** |
||
| 19 | * Discount ID. |
||
| 20 | * |
||
| 21 | * @since 1.0.14 |
||
| 22 | * @var array |
||
| 23 | */ |
||
| 24 | public $ID = null; |
||
| 25 | |||
| 26 | /** |
||
| 27 | * Old discount status. |
||
| 28 | * |
||
| 29 | * @since 1.0.14 |
||
| 30 | * @var string |
||
| 31 | */ |
||
| 32 | public $old_status = 'draft'; |
||
| 33 | |||
| 34 | /** |
||
| 35 | * Data array, with defaults. |
||
| 36 | * |
||
| 37 | * @since 1.0.14 |
||
| 38 | * @var array |
||
| 39 | */ |
||
| 40 | protected $data = array(); |
||
| 41 | |||
| 42 | /** |
||
| 43 | * Discount constructor. |
||
| 44 | * |
||
| 45 | * @param int|array|string|WPInv_Discount $discount discount data, object, ID or code. |
||
| 46 | * @since 1.0.14 |
||
| 47 | */ |
||
| 48 | public function __construct( $discount = array() ) { |
||
| 49 | |||
| 50 | // If the discount is an instance of this class... |
||
| 51 | if ( $discount instanceof WPInv_Discount ) { |
||
| 52 | $this->init( $discount->data ); |
||
| 53 | return; |
||
| 54 | } |
||
| 55 | |||
| 56 | // If the discount is an array of discount details... |
||
| 57 | if ( is_array( $discount ) ) { |
||
| 58 | $this->init( $discount ); |
||
| 59 | return; |
||
| 60 | } |
||
| 61 | |||
| 62 | // Try fetching the discount by its post id. |
||
| 63 | $data = false; |
||
| 64 | |||
| 65 | if ( ! empty( $discount ) && is_numeric( $discount ) ) { |
||
| 66 | $discount = absint( $discount ); |
||
| 67 | $data = self::get_data_by( 'id', $discount ); |
||
| 68 | } |
||
| 69 | |||
| 70 | if ( $data ) { |
||
| 71 | $this->init( $data ); |
||
| 72 | return; |
||
| 73 | } |
||
| 74 | |||
| 75 | // Try fetching the discount by its discount code. |
||
| 76 | if ( ! empty( $discount ) && is_string( $discount ) ) { |
||
| 77 | $data = self::get_data_by( 'discount_code', $discount ); |
||
| 78 | } |
||
| 79 | |||
| 80 | if ( $data ) { |
||
| 81 | $this->init( $data ); |
||
| 82 | return; |
||
| 83 | } |
||
| 84 | |||
| 85 | // If we are here then the discount does not exist. |
||
| 86 | $this->init( array() ); |
||
| 87 | } |
||
| 88 | |||
| 89 | /** |
||
| 90 | * Sets up object properties |
||
| 91 | * |
||
| 92 | * @since 1.0.14 |
||
| 93 | * @param array $data An array containing the discount's data |
||
| 94 | */ |
||
| 95 | public function init( $data ) { |
||
| 100 | } |
||
| 101 | |||
| 102 | /** |
||
| 103 | * Fetch a discount from the db/cache |
||
| 104 | * |
||
| 105 | * |
||
| 106 | * @static |
||
| 107 | * |
||
| 108 | * |
||
| 109 | * @param string $field The field to query against: 'ID', 'discount_code' |
||
| 110 | * @param string|int $value The field value |
||
| 111 | * @since 1.0.14 |
||
| 112 | * @return array|false array of discount details on success. False otherwise. |
||
| 113 | */ |
||
| 114 | public static function get_data_by( $field, $value ) { |
||
| 207 | } |
||
| 208 | |||
| 209 | /** |
||
| 210 | * Sanitizes discount data |
||
| 211 | * |
||
| 212 | * @static |
||
| 213 | * @since 1.0.14 |
||
| 214 | * @access public |
||
| 215 | * |
||
| 216 | * @return array the sanitized data |
||
| 217 | */ |
||
| 218 | public static function sanitize_discount_data( $data ) { |
||
| 219 | |||
| 220 | $allowed_discount_types = array_keys( wpinv_get_discount_types() ); |
||
| 221 | |||
| 222 | $return = array( |
||
| 223 | 'ID' => null, |
||
| 224 | 'code' => '', |
||
| 225 | 'amount' => 0, |
||
| 226 | 'date_created' => current_time('mysql'), |
||
| 227 | 'date_modified' => current_time('mysql'), |
||
| 228 | 'expiration' => null, |
||
| 229 | 'start' => current_time('mysql'), |
||
| 230 | 'status' => 'draft', |
||
| 231 | 'type' => 'percent', |
||
| 232 | 'description' => '', |
||
| 233 | 'uses' => 0, |
||
| 234 | 'is_single_use' => false, |
||
| 235 | 'items' => array(), |
||
| 236 | 'excluded_items' => array(), |
||
| 237 | 'max_uses' => 0, |
||
| 238 | 'is_recurring' => false, |
||
| 239 | 'min_total' => '', |
||
| 240 | 'max_total' => '', |
||
| 241 | ); |
||
| 242 | |||
| 243 | |||
| 244 | // Arrays only please. |
||
| 245 | if (! is_array( $data ) ) { |
||
| 246 | return $return; |
||
| 247 | } |
||
| 248 | |||
| 249 | // If an id is provided, ensure it is a valid discount. |
||
| 250 | if (! empty( $data['ID'] ) && is_numeric( $data['ID'] ) && 'wpi_discount' !== get_post_type( $data['ID'] ) ) { |
||
| 251 | return $return; |
||
| 252 | } |
||
| 253 | |||
| 254 | $return = wp_parse_args( $data, $return ); |
||
| 255 | |||
| 256 | // Sanitize some keys. |
||
| 257 | $return['amount'] = wpinv_sanitize_amount( $return['amount'] ); |
||
| 258 | $return['is_single_use'] = (bool) $return['is_single_use']; |
||
| 259 | $return['is_recurring'] = (bool) $return['is_recurring']; |
||
| 260 | $return['uses'] = (int) $return['uses']; |
||
| 261 | $return['max_uses'] = (int) $return['max_uses']; |
||
| 262 | $return['min_total'] = wpinv_sanitize_amount( $return['min_total'] ); |
||
| 263 | $return['max_total'] = wpinv_sanitize_amount( $return['max_total'] ); |
||
| 264 | |||
| 265 | // Trim all values. |
||
| 266 | $return = wpinv_clean( $return ); |
||
| 267 | |||
| 268 | // Ensure the discount type is supported. |
||
| 269 | if ( ! in_array( $return['type'], $allowed_discount_types, true ) ) { |
||
| 270 | $return['type'] = 'percent'; |
||
| 271 | } |
||
| 272 | $return['type_name'] = wpinv_get_discount_type_name( $return['type'] ); |
||
| 273 | |||
| 274 | // Do not offer more than a 100% discount. |
||
| 275 | if ( $return['type'] == 'percent' && (float) $return['amount'] > 100 ) { |
||
| 276 | $return['amount'] = 100; |
||
| 277 | } |
||
| 278 | |||
| 279 | // Format dates. |
||
| 280 | foreach( wpinv_parse_list( 'date_created date_modified expiration start') as $prop ) { |
||
| 281 | if( ! empty( $return[$prop] ) ) { |
||
| 282 | $return[$prop] = date_i18n( 'Y-m-d H:i:s', strtotime( $return[$prop] ) ); |
||
| 283 | } |
||
| 284 | } |
||
| 285 | |||
| 286 | // Formart items. |
||
| 287 | foreach( wpinv_parse_list( 'excluded_items items') as $prop ) { |
||
| 288 | |||
| 289 | if( ! empty( $return[$prop] ) ) { |
||
| 290 | // Ensure that the property is an array of non-empty integers. |
||
| 291 | $return[$prop] = array_filter( array_map( 'intval', wpinv_parse_list( $return[$prop] ) ) ); |
||
| 292 | } else { |
||
| 293 | $return[$prop] = array(); |
||
| 294 | } |
||
| 295 | |||
| 296 | } |
||
| 297 | |||
| 298 | return apply_filters( 'sanitize_discount_data', $return, $data ); |
||
| 299 | } |
||
| 300 | |||
| 301 | /** |
||
| 302 | * Magic method for checking the existence of a certain custom field. |
||
| 303 | * |
||
| 304 | * @since 1.0.14 |
||
| 305 | * @access public |
||
| 306 | * |
||
| 307 | * @return bool Whether the given discount field is set. |
||
| 308 | */ |
||
| 309 | public function __isset( $key ){ |
||
| 310 | return isset( $this->data[$key] ); |
||
| 311 | } |
||
| 312 | |||
| 313 | /** |
||
| 314 | * Magic method for accessing discount properties. |
||
| 315 | * |
||
| 316 | * @since 1.0.14 |
||
| 317 | * @access public |
||
| 318 | * |
||
| 319 | * @param string $key Discount data to retrieve |
||
| 320 | * @return mixed Value of the given discount property (if set). |
||
| 321 | */ |
||
| 322 | public function __get( $key ) { |
||
| 323 | |||
| 324 | if ( $key == 'id' ) { |
||
| 325 | $key = 'ID'; |
||
| 326 | } |
||
| 327 | |||
| 328 | if( method_exists( $this, "get_$key") ) { |
||
| 329 | $value = call_user_func( array( $this, "get_$key" ) ); |
||
| 330 | } else if( isset( $this->data[$key] ) ) { |
||
| 331 | $value = $this->data[$key]; |
||
| 332 | } else { |
||
| 333 | $value = null; |
||
| 334 | } |
||
| 335 | |||
| 336 | return apply_filters( "wpinv_get_discount_{$key}", $value, $this->ID, $this, $this->data['code'], $this->data ); |
||
| 337 | |||
| 338 | } |
||
| 339 | |||
| 340 | /** |
||
| 341 | * Magic method for setting discount fields. |
||
| 342 | * |
||
| 343 | * This method does not update custom fields in the database. |
||
| 344 | * |
||
| 345 | * @since 1.0.14 |
||
| 346 | * @access public |
||
| 347 | * |
||
| 348 | */ |
||
| 349 | public function __set( $key, $value ) { |
||
| 350 | |||
| 351 | if ( 'id' == strtolower( $key ) ) { |
||
| 352 | |||
| 353 | $this->ID = $value; |
||
| 354 | $this->data['ID'] = $value; |
||
| 355 | return; |
||
| 356 | |||
| 357 | } |
||
| 358 | |||
| 359 | $value = apply_filters( "wpinv_set_discount_{$key}", $value, $this->ID, $this, $this->code, $this->data ); |
||
| 360 | $this->data[$key] = $value; |
||
| 361 | |||
| 362 | } |
||
| 363 | |||
| 364 | /** |
||
| 365 | * Saves (or updates) a discount to the database |
||
| 366 | * |
||
| 367 | * @since 1.0.14 |
||
| 368 | * @access public |
||
| 369 | * @return bool |
||
| 370 | * |
||
| 371 | */ |
||
| 372 | public function save(){ |
||
| 373 | |||
| 374 | $data = self::sanitize_discount_data( $this->data ); |
||
| 375 | |||
| 376 | // Should we create a new post? |
||
| 377 | if(! $data[ 'ID' ] ) { |
||
| 378 | |||
| 379 | $id = wp_insert_post( array( |
||
| 380 | 'post_status' => $data['status'], |
||
| 381 | 'post_type' => 'wpi_discount', |
||
| 382 | 'post_excerpt' => $data['description'], |
||
| 383 | ) ); |
||
| 384 | |||
| 385 | if( empty( $id ) ) { |
||
| 386 | return false; |
||
| 387 | } |
||
| 388 | |||
| 389 | $data[ 'ID' ] = $id; |
||
| 390 | $this->ID = $id; |
||
| 391 | $this->data['ID'] = $id; |
||
| 392 | |||
| 393 | } else { |
||
| 394 | $this->update_status( $data['post_status'] ); |
||
| 395 | } |
||
| 396 | |||
| 397 | $meta = apply_filters( 'wpinv_update_discount', $data, $this->ID, $this ); |
||
| 398 | |||
| 399 | do_action( 'wpinv_pre_update_discount', $meta, $this->ID, $this ); |
||
| 400 | |||
| 401 | foreach( wpinv_parse_list( 'ID date_created date_modified status description type_name' ) as $prop ) { |
||
| 402 | unset( $meta[$prop] ); |
||
| 403 | } |
||
| 404 | |||
| 405 | if( empty( $meta['uses'] ) ) { |
||
| 406 | unset( $meta['uses'] ); |
||
| 407 | } |
||
| 408 | |||
| 409 | // Save the metadata |
||
| 410 | foreach( $meta as $key => $value ) { |
||
| 411 | update_post_meta( $this->ID, "_wpi_discount_$key", $value ); |
||
| 412 | } |
||
| 413 | |||
| 414 | // Empty the cache for this discount. |
||
| 415 | wp_cache_delete( $this->ID, 'WPInv_Discounts' ); |
||
| 416 | wp_cache_delete( $data['code'], 'WPInv_Discount_Codes' ); |
||
| 417 | |||
| 418 | do_action( 'wpinv_post_update_discount', $meta, $this->ID, $this ); |
||
| 419 | |||
| 420 | $data = self::get_data_by( 'id', $this->ID ); |
||
| 421 | $this->init( $data ); |
||
| 422 | |||
| 423 | return true; |
||
| 424 | } |
||
| 425 | |||
| 426 | /** |
||
| 427 | * Saves (or updates) a discount to the database |
||
| 428 | * |
||
| 429 | * @since 1.0.14 |
||
| 430 | * @access public |
||
| 431 | * @return bool |
||
| 432 | * |
||
| 433 | */ |
||
| 434 | public function update_status( $status = 'publish' ){ |
||
| 435 | |||
| 436 | |||
| 437 | if( $this->exists() && $this->old_status != $status ) { |
||
| 438 | |||
| 439 | do_action( 'wpinv_pre_update_discount_status', $this->ID, $this->old_status, $status ); |
||
| 440 | $updated = wp_update_post( array( 'ID' => $this->ID, 'post_status' => $status ) ); |
||
| 441 | do_action( 'wpinv_post_update_discount_status', $this->ID, $this->old_status, $status ); |
||
| 442 | |||
| 443 | wp_cache_delete( $this->ID, 'WPInv_Discounts' ); |
||
| 444 | wp_cache_delete( $this->code, 'WPInv_Discount_Codes' ); |
||
| 445 | |||
| 446 | return $updated !== 0; |
||
| 447 | |||
| 448 | } |
||
| 449 | |||
| 450 | return false; |
||
| 451 | } |
||
| 452 | |||
| 453 | |||
| 454 | /** |
||
| 455 | * Checks whether a discount exists in the database or not |
||
| 456 | * |
||
| 457 | * @since 1.0.14 |
||
| 458 | */ |
||
| 459 | public function exists(){ |
||
| 460 | return ! empty( $this->ID ); |
||
| 461 | } |
||
| 462 | |||
| 463 | // Boolean methods |
||
| 464 | |||
| 465 | /** |
||
| 466 | * Checks the discount type. |
||
| 467 | * |
||
| 468 | * |
||
| 469 | * @param string $type the discount type to check against |
||
| 470 | * @since 1.0.14 |
||
| 471 | * @return bool |
||
| 472 | */ |
||
| 473 | public function is_type( $type ) { |
||
| 474 | return $this->type == $type; |
||
| 475 | } |
||
| 476 | |||
| 477 | /** |
||
| 478 | * Checks whether the discount is published or not |
||
| 479 | * |
||
| 480 | * @since 1.0.14 |
||
| 481 | * @return bool |
||
| 482 | */ |
||
| 483 | public function is_active() { |
||
| 484 | return $this->post_status == 'publish'; |
||
| 485 | } |
||
| 486 | |||
| 487 | /** |
||
| 488 | * Checks whether the discount is has exided the usage limit or not |
||
| 489 | * |
||
| 490 | * @since 1.0.14 |
||
| 491 | * @return bool |
||
| 492 | */ |
||
| 493 | public function has_exceeded_limit() { |
||
| 494 | if( empty( $this->max_uses ) || empty( $this->uses ) ) { |
||
| 495 | return false ; |
||
| 496 | } |
||
| 497 | |||
| 498 | $exceeded = $this->uses >= $this->max_uses; |
||
| 499 | return apply_filters( 'wpinv_is_discount_maxed_out', $exceeded, $this->ID, $this, $this->code ); |
||
| 500 | } |
||
| 501 | |||
| 502 | /** |
||
| 503 | * Checks if the discount is expired |
||
| 504 | * |
||
| 505 | * @since 1.0.14 |
||
| 506 | * @return bool |
||
| 507 | */ |
||
| 508 | public function is_expired() { |
||
| 511 | } |
||
| 512 | |||
| 513 | /** |
||
| 514 | * Checks the discount start date. |
||
| 515 | * |
||
| 516 | * @since 1.0.14 |
||
| 517 | * @return bool |
||
| 518 | */ |
||
| 519 | public function has_started() { |
||
| 520 | $started = empty ( $this->start ) ? true : current_time( 'timestamp' ) > strtotime( $this->start ); |
||
| 521 | return apply_filters( 'wpinv_is_discount_started', $started, $this->ID, $this, $this->code ); |
||
| 522 | } |
||
| 523 | |||
| 524 | /** |
||
| 525 | * Check if a discount is valid for a given item id. |
||
| 526 | * |
||
| 527 | * @param int|array $item_ids |
||
| 528 | * @since 1.0.14 |
||
| 529 | * @return boolean |
||
| 530 | */ |
||
| 531 | public function is_valid_for_items( $item_ids ) { |
||
| 532 | |||
| 533 | $item_ids = wpinv_parse_list( $item_ids ); |
||
| 534 | $included = array_intersect( $item_ids, $this->items ); |
||
| 535 | $excluded = array_intersect( $item_ids, $this->excluded_items ); |
||
| 536 | |||
| 537 | if( ! empty( $this->excluded_items ) && ! empty( $excluded ) ) { |
||
| 538 | return false; |
||
| 539 | } |
||
| 540 | |||
| 541 | if( ! empty( $this->included_items ) && empty( $included ) ) { |
||
| 542 | return false; |
||
| 543 | } |
||
| 544 | return true; |
||
| 545 | } |
||
| 546 | |||
| 547 | /** |
||
| 548 | * Check if a discount is valid for the given amount |
||
| 549 | * |
||
| 550 | * @param float $amount The amount to check against |
||
| 551 | * @since 1.0.14 |
||
| 552 | * @return boolean |
||
| 553 | */ |
||
| 554 | public function is_valid_for_amount( $amount ) { |
||
| 555 | |||
| 556 | // Amount passed is not valid; |
||
| 557 | if(! is_numeric ( $amount ) ) { |
||
| 558 | return false; |
||
| 559 | } |
||
| 560 | |||
| 561 | $amount = floatval( $amount ); |
||
| 562 | |||
| 563 | // check if it meets the minimum amount valid. |
||
| 564 | if( $this->min_total > 0 && $amount < $this->min_total ) { |
||
| 565 | return false; |
||
| 566 | } |
||
| 567 | |||
| 568 | // check if it meets the maximum amount valid. |
||
| 569 | if( $this->max_total > 0 && $amount > $this->max_total ) { |
||
| 570 | return false; |
||
| 571 | } |
||
| 572 | |||
| 573 | return true; |
||
| 574 | } |
||
| 575 | |||
| 576 | /** |
||
| 577 | * Checks if the minimum amount is met |
||
| 578 | * |
||
| 579 | * @param float $amount The amount to check against |
||
| 580 | * @since 1.0.14 |
||
| 581 | * @return boolean |
||
| 582 | */ |
||
| 583 | public function is_minimum_amount_met( $amount ) { |
||
| 584 | |||
| 585 | // Amount passed is not valid; |
||
| 586 | if(! is_numeric ( $amount ) ) { |
||
| 587 | return false; |
||
| 588 | } |
||
| 589 | |||
| 590 | $amount = floatval( $amount ); |
||
| 591 | $min_met= ! ( $this->min_total > 0 && $amount < $this->min_total ); |
||
| 592 | return apply_filters( 'wpinv_is_discount_min_met', $min_met, $this->ID, $this, $this->code, $amount ); |
||
| 593 | } |
||
| 594 | |||
| 595 | /** |
||
| 596 | * Checks if the maximum amount is met |
||
| 597 | * |
||
| 598 | * @param float $amount The amount to check against |
||
| 599 | * @since 1.0.14 |
||
| 600 | * @return boolean |
||
| 601 | */ |
||
| 602 | public function is_maximum_amount_met( $amount ) { |
||
| 603 | |||
| 604 | // Amount passed is not valid; |
||
| 605 | if(! is_numeric ( $amount ) ) { |
||
| 606 | return false; |
||
| 607 | } |
||
| 608 | |||
| 609 | $amount = floatval( $amount ); |
||
| 610 | $max_met= ! ( $this->max_total > 0 && $amount > $this->max_total ); |
||
| 611 | return apply_filters( 'wpinv_is_discount_max_met', $max_met, $this->ID, $this, $this->code, $amount ); |
||
| 612 | } |
||
| 613 | |||
| 614 | /** |
||
| 615 | * Check if a discount is valid for the given user |
||
| 616 | * |
||
| 617 | * @param int|string $user |
||
| 618 | * @since 1.0.14 |
||
| 619 | * @return boolean |
||
| 620 | */ |
||
| 621 | public function is_valid_for_user( $user ) { |
||
| 670 | } |
||
| 671 | |||
| 672 | /** |
||
| 673 | * Deletes the discount from the database |
||
| 674 | * |
||
| 675 | * @since 1.0.14 |
||
| 676 | * @return boolean |
||
| 677 | */ |
||
| 678 | public function remove() { |
||
| 679 | |||
| 680 | if( empty( $this->ID ) ) { |
||
| 681 | return true; |
||
| 682 | } |
||
| 683 | |||
| 684 | do_action( 'wpinv_pre_delete_discount', $this->ID ); |
||
| 685 | wp_cache_delete( $this->ID, 'WPInv_Discounts' ); |
||
| 686 | wp_delete_post( $this->ID, true ); |
||
| 687 | wp_cache_delete( $this->code, 'WPInv_Discount_Codes' ); |
||
| 688 | do_action( 'wpinv_post_delete_discount', $this->ID ); |
||
| 689 | |||
| 690 | $this->ID = null; |
||
| 691 | $this->data['id'] = null; |
||
| 692 | return true; |
||
| 693 | } |
||
| 694 | |||
| 695 | /** |
||
| 696 | * Increases a discount's usage. |
||
| 697 | * |
||
| 698 | * @since 1.0.14 |
||
| 699 | * @param int $by The number of usages to increas by. |
||
| 700 | * @return bool |
||
| 701 | */ |
||
| 702 | public function increase_usage( $by = 1 ) { |
||
| 703 | |||
| 704 | $this->uses = $this->uses + $by; |
||
| 705 | |||
| 706 | if( $this->uses < 0 ) { |
||
| 707 | $this->uses = 0; |
||
| 708 | } |
||
| 709 | |||
| 710 | $this->save(); |
||
| 711 | |||
| 712 | if( $by > 0 ) { |
||
| 713 | do_action( 'wpinv_discount_increase_use_count', $this->uses, $this->ID, $this->code, $by ); |
||
| 714 | } else { |
||
| 715 | do_action( 'wpinv_discount_decrease_use_count', $this->uses, $this->ID, $this->code, absint( $by ) ); |
||
| 716 | } |
||
| 717 | |||
| 718 | return $this->uses; |
||
| 719 | } |
||
| 720 | |||
| 721 | /** |
||
| 722 | * Retrieves discount data |
||
| 723 | * |
||
| 724 | * @since 1.0.14 |
||
| 725 | * @return array |
||
| 726 | */ |
||
| 727 | public function get_data() { |
||
| 733 | } |
||
| 734 | |||
| 735 | /** |
||
| 736 | * Retrieves discount data as json |
||
| 737 | * |
||
| 738 | * @since 1.0.14 |
||
| 739 | * @return string |
||
| 740 | */ |
||
| 741 | public function get_data_as_json() { |
||
| 742 | return wp_json_encode( $this->get_data() ); |
||
| 743 | } |
||
| 744 | |||
| 745 | /** |
||
| 746 | * Checks if a discount can only be used once per user. |
||
| 747 | * |
||
| 748 | * @since 1.0.14 |
||
| 749 | * @return bool |
||
| 750 | */ |
||
| 751 | public function get_is_single_use() { |
||
| 753 | } |
||
| 754 | |||
| 755 | /** |
||
| 756 | * Checks if a discount is recurring. |
||
| 757 | * |
||
| 758 | * @since 1.0.14 |
||
| 759 | * @return bool |
||
| 760 | */ |
||
| 761 | public function get_is_recurring() { |
||
| 763 | } |
||
| 764 | |||
| 765 | /** |
||
| 766 | * Returns a discount's included items. |
||
| 767 | * |
||
| 768 | * @since 1.0.14 |
||
| 769 | * @return array |
||
| 770 | */ |
||
| 771 | public function get_items() { |
||
| 772 | return wpinv_parse_list( apply_filters( 'wpinv_get_discount_item_reqs', $this->data['items'], $this->ID, $this, $this->code ) ); |
||
| 773 | } |
||
| 774 | |||
| 775 | /** |
||
| 776 | * Returns a discount's discounted amount. |
||
| 777 | * |
||
| 778 | * @since 1.0.14 |
||
| 779 | * @return float |
||
| 780 | */ |
||
| 781 | public function get_discounted_amount( $amount ) { |
||
| 794 | } |
||
| 795 | |||
| 796 | } |
||
| 797 |