wc-extras.php ➔ add_custom_price()   B
last analyzed

Complexity

Conditions 7
Paths 5

Size

Total Lines 29

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
nc 5
nop 1
dl 0
loc 29
rs 8.5226
c 0
b 0
f 0
1
<?php
2
/**
3
 * woocommerece-specific functions and definitions.
4
 *
5
 * This file is centrally included from ``.
6
 *
7
 * @package podium
8
 */
9
10
// Discount related to quantity
11
function add_custom_price($cart_object)
12
{
13
14
    foreach ($cart_object->cart_contents as $key => $value) {
15
16
        if ($value['quantity'] >= 2 && $value['quantity'] < 5) {
17
18
            $discount             = $value['data']->price * 0.02;
19
            $value['data']->price = $value['data']->price - $discount;
20
21
        } elseif ($value['quantity'] >= 5 && $value['quantity'] < 10) {
22
23
            $discount             = $value['data']->price * 0.05;
24
            $value['data']->price = $value['data']->price - $discount;
25
26
        } elseif ($value['quantity'] >= 10) {
27
28
            $discount             = $value['data']->price * 0.10;
29
            $value['data']->price = $value['data']->price - $discount;
30
31
        } else {
32
33
            '';
34
35
        }
36
37
    }
38
39
}
40
41
// add_action('woocommerce_before_calculate_totals', 'add_custom_price');
42