| @@ 2447-2472 (lines=26) @@ | ||
| 2444 | /** |
|
| 2445 | * Increase applied coupon counts. |
|
| 2446 | */ |
|
| 2447 | public function increase_coupon_usage_counts() { |
|
| 2448 | if ( 'yes' == get_post_meta( $this->id, '_recorded_coupon_usage_counts', true ) ) { |
|
| 2449 | return; |
|
| 2450 | } |
|
| 2451 | ||
| 2452 | if ( sizeof( $this->get_used_coupons() ) > 0 ) { |
|
| 2453 | ||
| 2454 | foreach ( $this->get_used_coupons() as $code ) { |
|
| 2455 | if ( ! $code ) { |
|
| 2456 | continue; |
|
| 2457 | } |
|
| 2458 | ||
| 2459 | $coupon = new WC_Coupon( $code ); |
|
| 2460 | ||
| 2461 | $used_by = $this->get_user_id(); |
|
| 2462 | ||
| 2463 | if ( ! $used_by ) { |
|
| 2464 | $used_by = $this->billing_email; |
|
| 2465 | } |
|
| 2466 | ||
| 2467 | $coupon->inc_usage_count( $used_by ); |
|
| 2468 | } |
|
| 2469 | ||
| 2470 | update_post_meta( $this->id, '_recorded_coupon_usage_counts', 'yes' ); |
|
| 2471 | } |
|
| 2472 | } |
|
| 2473 | ||
| 2474 | ||
| 2475 | /** |
|
| @@ 2478-2504 (lines=27) @@ | ||
| 2475 | /** |
|
| 2476 | * Decrease applied coupon counts. |
|
| 2477 | */ |
|
| 2478 | public function decrease_coupon_usage_counts() { |
|
| 2479 | ||
| 2480 | if ( 'yes' != get_post_meta( $this->id, '_recorded_coupon_usage_counts', true ) ) { |
|
| 2481 | return; |
|
| 2482 | } |
|
| 2483 | ||
| 2484 | if ( sizeof( $this->get_used_coupons() ) > 0 ) { |
|
| 2485 | ||
| 2486 | foreach ( $this->get_used_coupons() as $code ) { |
|
| 2487 | ||
| 2488 | if ( ! $code ) { |
|
| 2489 | continue; |
|
| 2490 | } |
|
| 2491 | ||
| 2492 | $coupon = new WC_Coupon( $code ); |
|
| 2493 | ||
| 2494 | $used_by = $this->get_user_id(); |
|
| 2495 | if ( ! $used_by ) { |
|
| 2496 | $used_by = $this->billing_email; |
|
| 2497 | } |
|
| 2498 | ||
| 2499 | $coupon->dcr_usage_count( $used_by ); |
|
| 2500 | } |
|
| 2501 | ||
| 2502 | delete_post_meta( $this->id, '_recorded_coupon_usage_counts' ); |
|
| 2503 | } |
|
| 2504 | } |
|
| 2505 | ||
| 2506 | /** |
|
| 2507 | * Reduce stock levels for all line items in the order. |
|